sdcc:
[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.5
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://sdcc.svn.sourceforge.net/svnroot/
948 sdcc/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 SDCC Distributed Compile
1418  Farm.
1419
1420 \layout Standard
1421 See the examples, how to pass the Win32 settings to 'configure'.
1422  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1423  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1424  for Win32.
1425 \newline
1426
1427 \newline
1428 These defaults are:
1429 \newline
1430
1431
1432 \layout Standard
1433 \align center
1434 \begin_inset Tabular
1435 <lyxtabular version="3" rows="9" columns="3">
1436 <features>
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" width="0in">
1439 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1440 <row topline="true" bottomline="true">
1441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1442 \begin_inset Text
1443
1444 \layout Standard
1445 Variable
1446
1447 \end_inset
1448 </cell>
1449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1450 \begin_inset Text
1451
1452 \layout Standard
1453 default
1454
1455 \end_inset
1456 </cell>
1457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1458 \begin_inset Text
1459
1460 \layout Standard
1461 Win32 builds
1462
1463 \end_inset
1464 </cell>
1465 </row>
1466 <row topline="true">
1467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1468 \begin_inset Text
1469
1470 \layout Standard
1471
1472 \emph on
1473 PREFIX
1474
1475 \end_inset
1476 </cell>
1477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1478 \begin_inset Text
1479
1480 \layout Standard
1481 /usr/local
1482
1483 \end_inset
1484 </cell>
1485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1486 \begin_inset Text
1487
1488 \layout Standard
1489
1490 \backslash
1491 sdcc
1492
1493 \end_inset
1494 </cell>
1495 </row>
1496 <row topline="true">
1497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1498 \begin_inset Text
1499
1500 \layout Standard
1501
1502 \emph on
1503 EXEC_PREFIX
1504
1505 \end_inset
1506 </cell>
1507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1508 \begin_inset Text
1509
1510 \layout Standard
1511
1512 \emph on
1513 $PREFIX
1514
1515 \end_inset
1516 </cell>
1517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1518 \begin_inset Text
1519
1520 \layout Standard
1521
1522 \emph on
1523 $PREFIX
1524
1525 \end_inset
1526 </cell>
1527 </row>
1528 <row topline="true">
1529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1530 \begin_inset Text
1531
1532 \layout Standard
1533
1534 \emph on
1535 BINDIR
1536
1537 \end_inset
1538 </cell>
1539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1540 \begin_inset Text
1541
1542 \layout Standard
1543
1544 \emph on
1545 $EXEC_PREFIX
1546 \emph default
1547 /bin
1548
1549 \end_inset
1550 </cell>
1551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1552 \begin_inset Text
1553
1554 \layout Standard
1555
1556 \emph on
1557 $EXEC_PREFIX
1558 \emph default
1559
1560 \backslash
1561 bin
1562
1563 \end_inset
1564 </cell>
1565 </row>
1566 <row topline="true">
1567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1568 \begin_inset Text
1569
1570 \layout Standard
1571
1572 \emph on
1573 DATADIR
1574
1575 \end_inset
1576 </cell>
1577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1578 \begin_inset Text
1579
1580 \layout Standard
1581
1582 \emph on
1583 $DATAROOTDIR
1584
1585 \end_inset
1586 </cell>
1587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1588 \begin_inset Text
1589
1590 \layout Standard
1591
1592 \emph on
1593 $DATAROOTDIR
1594
1595 \end_inset
1596 </cell>
1597 </row>
1598 <row topline="true">
1599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1600 \begin_inset Text
1601
1602 \layout Standard
1603
1604 \emph on
1605 DATAROOTDIR
1606
1607 \end_inset
1608 </cell>
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1610 \begin_inset Text
1611
1612 \layout Standard
1613
1614 \emph on
1615 $PREFIX
1616 \emph default
1617 /share
1618
1619 \end_inset
1620 </cell>
1621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1622 \begin_inset Text
1623
1624 \layout Standard
1625
1626 \emph on
1627 $PREFIX
1628
1629 \end_inset
1630 </cell>
1631 </row>
1632 <row topline="true">
1633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1634 \begin_inset Text
1635
1636 \layout Standard
1637
1638 \emph on
1639 DOCDIR
1640
1641 \end_inset
1642 </cell>
1643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1644 \begin_inset Text
1645
1646 \layout Standard
1647
1648 \emph on
1649 $DATAROOTDIR
1650 \emph default
1651 /sdcc/doc
1652
1653 \end_inset
1654 </cell>
1655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1656 \begin_inset Text
1657
1658 \layout Standard
1659
1660 \emph on
1661 $DATAROOTDIR
1662 \emph default
1663
1664 \backslash
1665 doc
1666
1667 \end_inset
1668 </cell>
1669 </row>
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1672 \begin_inset Text
1673
1674 \layout Standard
1675
1676 \emph on
1677 INCLUDE_DIR_SUFFIX
1678
1679 \end_inset
1680 </cell>
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_inset Text
1683
1684 \layout Standard
1685 sdcc/include
1686
1687 \end_inset
1688 </cell>
1689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1690 \begin_inset Text
1691
1692 \layout Standard
1693 include
1694
1695 \end_inset
1696 </cell>
1697 </row>
1698 <row topline="true" bottomline="true">
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1700 \begin_inset Text
1701
1702 \layout Standard
1703
1704 \emph on
1705 LIB_DIR_SUFFIX
1706
1707 \end_inset
1708 </cell>
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713 sdcc/lib
1714
1715 \end_inset
1716 </cell>
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1718 \begin_inset Text
1719
1720 \layout Standard
1721 lib
1722
1723 \end_inset
1724 </cell>
1725 </row>
1726 </lyxtabular>
1727
1728 \end_inset
1729
1730
1731 \newline
1732
1733
1734 \layout Standard
1735 \noindent
1736 'configure' also computes relative paths.
1737  This is needed for full relocatability of a binary package and to complete
1738  search paths (see section search paths below):
1739 \newline
1740  
1741
1742 \layout Standard
1743 \align center
1744 \begin_inset Tabular
1745 <lyxtabular version="3" rows="4" columns="3">
1746 <features>
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" width="0in">
1749 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1750 <row topline="true" bottomline="true">
1751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1752 \begin_inset Text
1753
1754 \layout Standard
1755 Variable (computed)
1756
1757 \end_inset
1758 </cell>
1759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1760 \begin_inset Text
1761
1762 \layout Standard
1763 default
1764
1765 \end_inset
1766 </cell>
1767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1768 \begin_inset Text
1769
1770 \layout Standard
1771 Win32 builds
1772
1773 \end_inset
1774 </cell>
1775 </row>
1776 <row topline="true" bottomline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1778 \begin_inset Text
1779
1780 \layout Standard
1781
1782 \emph on
1783 BIN2DATA_DIR
1784
1785 \end_inset
1786 </cell>
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1788 \begin_inset Text
1789
1790 \layout Standard
1791 ../share
1792
1793 \end_inset
1794 </cell>
1795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1796 \begin_inset Text
1797
1798 \layout Standard
1799 ..
1800
1801 \end_inset
1802 </cell>
1803 </row>
1804 <row bottomline="true">
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 \begin_inset Text
1807
1808 \layout Standard
1809
1810 \emph on
1811 PREFIX2BIN_DIR
1812
1813 \end_inset
1814 </cell>
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_inset Text
1817
1818 \layout Standard
1819 bin
1820
1821 \end_inset
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \layout Standard
1827 bin
1828
1829 \end_inset
1830 </cell>
1831 </row>
1832 <row bottomline="true">
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1834 \begin_inset Text
1835
1836 \layout Standard
1837
1838 \emph on
1839 PREFIX2DATA_DIR
1840
1841 \end_inset
1842 </cell>
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \layout Standard
1847 share/sdcc
1848
1849 \end_inset
1850 </cell>
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1852 \begin_inset Text
1853
1854 \layout Standard
1855
1856
1857 \end_inset
1858 </cell>
1859 </row>
1860 </lyxtabular>
1861
1862 \end_inset
1863
1864
1865 \newline
1866
1867
1868 \layout Standard
1869 \noindent
1870 Examples:
1871
1872 \layout LyX-Code
1873 ./configure
1874 \newline
1875 ./configure -
1876 \begin_inset ERT
1877 status Collapsed
1878
1879 \layout Standard
1880
1881
1882 \backslash
1883 /
1884
1885 \end_inset
1886
1887 -prefix=
1888 \begin_inset Quotes srd
1889 \end_inset
1890
1891 /usr/bin
1892 \begin_inset Quotes srd
1893 \end_inset
1894
1895  -
1896 \begin_inset ERT
1897 status Collapsed
1898
1899 \layout Standard
1900
1901
1902 \backslash
1903 /
1904
1905 \end_inset
1906
1907 -datarootdir=
1908 \begin_inset Quotes srd
1909 \end_inset
1910
1911 /usr/share
1912 \begin_inset Quotes srd
1913 \end_inset
1914
1915
1916 \newline
1917 ./configure -
1918 \begin_inset ERT
1919 status Collapsed
1920
1921 \layout Standard
1922
1923
1924 \backslash
1925 /
1926
1927 \end_inset
1928
1929 -disable-avr-port -
1930 \begin_inset ERT
1931 status Collapsed
1932
1933 \layout Standard
1934
1935
1936 \backslash
1937 /
1938
1939 \end_inset
1940
1941 -disable-xa51-port
1942
1943 \layout Standard
1944 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1945 32'):
1946
1947 \layout LyX-Code
1948 ./configure 
1949 \backslash
1950
1951 \newline
1952 CC=
1953 \begin_inset Quotes srd
1954 \end_inset
1955
1956 i586-mingw32msvc-gcc
1957 \begin_inset Quotes srd
1958 \end_inset
1959
1960  CXX=
1961 \begin_inset Quotes srd
1962 \end_inset
1963
1964 i586-mingw32msvc-g++
1965 \begin_inset Quotes srd
1966 \end_inset
1967
1968  
1969 \backslash
1970  
1971 \newline
1972 RANLIB=
1973 \begin_inset Quotes srd
1974 \end_inset
1975
1976 i586-mingw32msvc-ranlib
1977 \begin_inset Quotes srd
1978 \end_inset
1979
1980  
1981 \backslash
1982
1983 \newline
1984 STRIP=
1985 \begin_inset Quotes srd
1986 \end_inset
1987
1988 i586-mingw32msvc-strip
1989 \begin_inset Quotes srd
1990 \end_inset
1991
1992  
1993 \backslash
1994
1995 \newline
1996 -
1997 \begin_inset ERT
1998 status Collapsed
1999
2000 \layout Standard
2001
2002
2003 \backslash
2004 /
2005
2006 \end_inset
2007
2008 -prefix=
2009 \begin_inset Quotes srd
2010 \end_inset
2011
2012 /sdcc
2013 \begin_inset Quotes srd
2014 \end_inset
2015
2016  
2017 \backslash
2018
2019 \newline
2020 -
2021 \begin_inset ERT
2022 status Collapsed
2023
2024 \layout Standard
2025
2026
2027 \backslash
2028 /
2029
2030 \end_inset
2031
2032 -datarootdir=
2033 \begin_inset Quotes srd
2034 \end_inset
2035
2036 /sdcc
2037 \begin_inset Quotes srd
2038 \end_inset
2039
2040  
2041 \backslash
2042
2043 \newline
2044 docdir=
2045 \begin_inset Quotes srd
2046 \end_inset
2047
2048
2049 \backslash
2050 ${datarootdir}/doc
2051 \begin_inset Quotes srd
2052 \end_inset
2053
2054  
2055 \backslash
2056
2057 \newline
2058 include_dir_suffix=
2059 \begin_inset Quotes srd
2060 \end_inset
2061
2062 include
2063 \begin_inset Quotes srd
2064 \end_inset
2065
2066  
2067 \backslash
2068
2069 \newline
2070 lib_dir_suffix=
2071 \begin_inset Quotes srd
2072 \end_inset
2073
2074 lib
2075 \begin_inset Quotes srd
2076 \end_inset
2077
2078  
2079 \backslash
2080
2081 \newline
2082 sdccconf_h_dir_separator=
2083 \begin_inset Quotes srd
2084 \end_inset
2085
2086
2087 \backslash
2088
2089 \backslash
2090
2091 \backslash
2092
2093 \backslash
2094
2095 \begin_inset Quotes srd
2096 \end_inset
2097
2098  
2099 \backslash
2100
2101 \newline
2102 -
2103 \begin_inset ERT
2104 status Collapsed
2105
2106 \layout Standard
2107
2108
2109 \backslash
2110 /
2111
2112 \end_inset
2113
2114 -disable-device-lib
2115 \backslash
2116
2117 \newline
2118 -
2119 \begin_inset ERT
2120 status Collapsed
2121
2122 \layout Standard
2123
2124
2125 \backslash
2126 /
2127
2128 \end_inset
2129
2130 -host=i586-mingw32msvc
2131 \backslash
2132
2133 \newline
2134 -
2135 \begin_inset ERT
2136 status Collapsed
2137
2138 \layout Standard
2139
2140
2141 \backslash
2142 /
2143
2144 \end_inset
2145
2146 -build=unknown-unknown-linux-gnu
2147
2148 \layout Standard
2149 To 
2150 \begin_inset Quotes sld
2151 \end_inset
2152
2153 cross
2154 \begin_inset Quotes srd
2155 \end_inset
2156
2157 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2158 ):
2159
2160 \layout LyX-Code
2161 ./configure -C 
2162 \backslash
2163
2164 \newline
2165 -
2166 \begin_inset ERT
2167 status Collapsed
2168
2169 \layout Standard
2170
2171
2172 \backslash
2173 /
2174
2175 \end_inset
2176
2177 -prefix=
2178 \begin_inset Quotes srd
2179 \end_inset
2180
2181 /sdcc
2182 \begin_inset Quotes srd
2183 \end_inset
2184
2185  
2186 \backslash
2187
2188 \newline
2189 -
2190 \begin_inset ERT
2191 status Collapsed
2192
2193 \layout Standard
2194
2195
2196 \backslash
2197 /
2198
2199 \end_inset
2200
2201 -datarootdir=
2202 \begin_inset Quotes srd
2203 \end_inset
2204
2205 /sdcc
2206 \begin_inset Quotes srd
2207 \end_inset
2208
2209  
2210 \backslash
2211
2212 \newline
2213 docdir=
2214 \begin_inset Quotes srd
2215 \end_inset
2216
2217
2218 \backslash
2219 ${datarootdir}/doc
2220 \begin_inset Quotes srd
2221 \end_inset
2222
2223  
2224 \backslash
2225  
2226 \newline
2227 include_dir_suffix=
2228 \begin_inset Quotes srd
2229 \end_inset
2230
2231 include
2232 \begin_inset Quotes srd
2233 \end_inset
2234
2235  
2236 \backslash
2237
2238 \newline
2239 lib_dir_suffix=
2240 \begin_inset Quotes srd
2241 \end_inset
2242
2243 lib
2244 \begin_inset Quotes srd
2245 \end_inset
2246
2247  
2248 \backslash
2249
2250 \newline
2251 sdccconf_h_dir_separator=
2252 \begin_inset Quotes srd
2253 \end_inset
2254
2255
2256 \backslash
2257
2258 \backslash
2259
2260 \backslash
2261
2262 \backslash
2263
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267  
2268 \backslash
2269
2270 \newline
2271 CC=
2272 \begin_inset Quotes srd
2273 \end_inset
2274
2275 gcc -mno-cygwin
2276 \begin_inset Quotes srd
2277 \end_inset
2278
2279  
2280 \backslash
2281
2282 \newline
2283 CXX=
2284 \begin_inset Quotes srd
2285 \end_inset
2286
2287 g++ -mno-cygwin
2288 \begin_inset Quotes srd
2289 \end_inset
2290
2291  
2292
2293 \layout Standard
2294 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2295  The option '-
2296 \begin_inset ERT
2297 status Collapsed
2298
2299 \layout Standard
2300
2301
2302 \backslash
2303 /
2304
2305 \end_inset
2306
2307 -C' turns on caching, which gives a little bit extra speed.
2308  However if options are changed, it can be necessary to delete the config.cache
2309  file.
2310
2311 \layout Section
2312 Install paths
2313 \added_space_bottom medskip 
2314 \begin_inset LatexCommand \label{sub:Install-paths}
2315
2316 \end_inset
2317
2318
2319 \begin_inset LatexCommand \index{Install paths}
2320
2321 \end_inset
2322
2323
2324
2325
2326 \layout Standard
2327 \align center
2328 \begin_inset Tabular
2329 <lyxtabular version="3" rows="5" columns="4">
2330 <features>
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" width="0">
2334 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2335 <row topline="true" bottomline="true">
2336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_inset Text
2338
2339 \layout Standard
2340
2341 \series bold
2342 Description
2343
2344 \end_inset
2345 </cell>
2346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2347 \begin_inset Text
2348
2349 \layout Standard
2350
2351 \series bold
2352 Path
2353
2354 \end_inset
2355 </cell>
2356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2357 \begin_inset Text
2358
2359 \layout Standard
2360
2361 \series bold
2362 Default
2363
2364 \end_inset
2365 </cell>
2366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2367 \begin_inset Text
2368
2369 \layout Standard
2370
2371 \series bold
2372 Win32 builds
2373
2374 \end_inset
2375 </cell>
2376 </row>
2377 <row topline="true">
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2379 \begin_inset Text
2380
2381 \layout Standard
2382 Binary files*
2383
2384 \end_inset
2385 </cell>
2386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2387 \begin_inset Text
2388
2389 \layout Standard
2390
2391 \emph on
2392 $EXEC_PREFIX
2393
2394 \end_inset
2395 </cell>
2396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_inset Text
2398
2399 \layout Standard
2400 /usr/local/bin
2401
2402 \end_inset
2403 </cell>
2404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2405 \begin_inset Text
2406
2407 \layout Standard
2408
2409 \backslash
2410 sdcc
2411 \backslash
2412 bin
2413
2414 \end_inset
2415 </cell>
2416 </row>
2417 <row topline="true">
2418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2419 \begin_inset Text
2420
2421 \layout Standard
2422 Include files
2423
2424 \end_inset
2425 </cell>
2426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2427 \begin_inset Text
2428
2429 \layout Standard
2430
2431 \emph on
2432 $DATADIR/ $INCLUDE_DIR_SUFFIX
2433
2434 \end_inset
2435 </cell>
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2437 \begin_inset Text
2438
2439 \layout Standard
2440 /usr/local/share/sdcc/include
2441
2442 \end_inset
2443 </cell>
2444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2445 \begin_inset Text
2446
2447 \layout Standard
2448
2449 \backslash
2450 sdcc
2451 \backslash
2452 include
2453
2454 \end_inset
2455 </cell>
2456 </row>
2457 <row topline="true">
2458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2459 \begin_inset Text
2460
2461 \layout Standard
2462 Library file**
2463
2464 \end_inset
2465 </cell>
2466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2467 \begin_inset Text
2468
2469 \layout Standard
2470
2471 \emph on
2472 $DATADIR/$LIB_DIR_SUFFIX
2473
2474 \end_inset
2475 </cell>
2476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2477 \begin_inset Text
2478
2479 \layout Standard
2480 /usr/local/share/sdcc/lib
2481
2482 \end_inset
2483 </cell>
2484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2485 \begin_inset Text
2486
2487 \layout Standard
2488
2489 \backslash
2490 sdcc
2491 \backslash
2492 lib
2493
2494 \end_inset
2495 </cell>
2496 </row>
2497 <row topline="true" bottomline="true">
2498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2499 \begin_inset Text
2500
2501 \layout Standard
2502 Documentation
2503
2504 \end_inset
2505 </cell>
2506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2507 \begin_inset Text
2508
2509 \layout Standard
2510
2511 \emph on
2512 $DOCDIR
2513
2514 \end_inset
2515 </cell>
2516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2517 \begin_inset Text
2518
2519 \layout Standard
2520 /usr/local/share/sdcc/doc
2521
2522 \end_inset
2523 </cell>
2524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2525 \begin_inset Text
2526
2527 \layout Standard
2528
2529 \backslash
2530 sdcc
2531 \backslash
2532 doc
2533
2534 \end_inset
2535 </cell>
2536 </row>
2537 </lyxtabular>
2538
2539 \end_inset
2540
2541
2542
2543 \layout Verse
2544
2545 \size footnotesize
2546 *compiler, preprocessor, assembler, and linker
2547 \newline
2548 **the 
2549 \shape italic
2550 model
2551 \shape default
2552  is auto-appended by the compiler, e.g.
2553  small, large, z80, ds390 etc
2554
2555 \layout Standard
2556 \noindent
2557 The install paths can still be changed during `make install` with e.g.:
2558
2559 \layout LyX-Code
2560 make install prefix=$(HOME)/local/sdcc
2561
2562 \layout Standard
2563 Of course this doesn't change the search paths compiled into the binaries.
2564 \newline
2565
2566 \newline
2567 Moreove
2568 r the install path can be changed by defining DESTDIR
2569 \begin_inset LatexCommand \index{DESTDIR}
2570
2571 \end_inset
2572
2573 :
2574
2575 \layout LyX-Code
2576 make install DESTDIR=$(HOME)/sdcc.rpm/
2577
2578 \layout Standard
2579 Please note that DESTDIR must have a trailing slash!
2580
2581 \layout Section
2582 Search Paths
2583 \begin_inset LatexCommand \label{sub:Search-Paths}
2584
2585 \end_inset
2586
2587
2588 \begin_inset LatexCommand \index{Search path}
2589
2590 \end_inset
2591
2592
2593
2594 \layout Standard
2595 Some search paths or parts of them are determined by configure variables
2596  (in 
2597 \emph on
2598 italics
2599 \emph default
2600 , see section above).
2601  Further search paths are determined by environment variables during runtime.
2602  
2603 \newline
2604 The paths searched when running the compiler are as follows (the first
2605  catch wins):
2606 \newline
2607
2608 \newline
2609 1.
2610  Binary files (preprocessor, assembler and linker)
2611 \newline
2612
2613
2614 \layout Standard
2615 \align center
2616 \begin_inset Tabular
2617 <lyxtabular version="3" rows="4" columns="3">
2618 <features>
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" width="0in">
2621 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2622 <row topline="true" bottomline="true">
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627 Search path
2628
2629 \end_inset
2630 </cell>
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635 default
2636
2637 \end_inset
2638 </cell>
2639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2640 \begin_inset Text
2641
2642 \layout Standard
2643 Win32 builds
2644
2645 \end_inset
2646 </cell>
2647 </row>
2648 <row topline="true">
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_inset Text
2651
2652 \layout Standard
2653 $SDCC_HOME/
2654 \emph on
2655 $PPREFIX2BIN_DIR
2656
2657 \end_inset
2658 </cell>
2659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2660 \begin_inset Text
2661
2662 \layout Standard
2663 $SDCC_HOME/bin
2664
2665 \end_inset
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \layout Standard
2671 $SDCC_HOME
2672 \backslash
2673 bin
2674
2675 \end_inset
2676 </cell>
2677 </row>
2678 <row topline="true">
2679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2680 \begin_inset Text
2681
2682 \layout Standard
2683 Path of argv[0] (if available)
2684
2685 \end_inset
2686 </cell>
2687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2688 \begin_inset Text
2689
2690 \layout Standard
2691 Path of argv[0]
2692
2693 \end_inset
2694 </cell>
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2696 \begin_inset Text
2697
2698 \layout Standard
2699 Path of argv[0]
2700
2701 \end_inset
2702 </cell>
2703 </row>
2704 <row topline="true" bottomline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 \begin_inset Text
2707
2708 \layout Standard
2709 $PATH
2710
2711 \end_inset
2712 </cell>
2713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_inset Text
2715
2716 \layout Standard
2717 $PATH
2718
2719 \end_inset
2720 </cell>
2721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2722 \begin_inset Text
2723
2724 \layout Standard
2725 $PATH
2726
2727 \end_inset
2728 </cell>
2729 </row>
2730 </lyxtabular>
2731
2732 \end_inset
2733
2734  
2735 \newline
2736
2737
2738 \layout Standard
2739 \noindent
2740 2.
2741  Include files
2742 \newline
2743
2744
2745 \layout Standard
2746 \align center
2747 \begin_inset Tabular
2748 <lyxtabular version="3" rows="6" columns="3">
2749 <features>
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2752 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2753 <row topline="true" bottomline="true">
2754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2755 \begin_inset Text
2756
2757 \layout Standard
2758 Search path
2759
2760 \end_inset
2761 </cell>
2762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2763 \begin_inset Text
2764
2765 \layout Standard
2766 default
2767
2768 \end_inset
2769 </cell>
2770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2771 \begin_inset Text
2772
2773 \layout Standard
2774 Win32 builds
2775
2776 \end_inset
2777 </cell>
2778 </row>
2779 <row topline="true">
2780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2781 \begin_inset Text
2782
2783 \layout Standard
2784 -
2785 \begin_inset ERT
2786 status Collapsed
2787
2788 \layout Standard
2789
2790
2791 \backslash
2792 /
2793
2794 \end_inset
2795
2796 -I dir
2797
2798 \end_inset
2799 </cell>
2800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2801 \begin_inset Text
2802
2803 \layout Standard
2804 -
2805 \begin_inset ERT
2806 status Collapsed
2807
2808 \layout Standard
2809
2810
2811 \backslash
2812 /
2813
2814 \end_inset
2815
2816 -I dir
2817
2818 \end_inset
2819 </cell>
2820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2821 \begin_inset Text
2822
2823 \layout Standard
2824 -
2825 \begin_inset ERT
2826 status Collapsed
2827
2828 \layout Standard
2829
2830
2831 \backslash
2832 /
2833
2834 \end_inset
2835
2836 -I dir
2837
2838 \end_inset
2839 </cell>
2840 </row>
2841 <row topline="true">
2842 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2843 \begin_inset Text
2844
2845 \layout Standard
2846 $SDCC_INCLUDE
2847
2848 \end_inset
2849 </cell>
2850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2851 \begin_inset Text
2852
2853 \layout Standard
2854 $SDCC_INCLUDE
2855
2856 \end_inset
2857 </cell>
2858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2859 \begin_inset Text
2860
2861 \layout Standard
2862 $SDCC_INCLUDE
2863
2864 \end_inset
2865 </cell>
2866 </row>
2867 <row topline="true">
2868 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2869 \begin_inset Text
2870
2871 \layout Standard
2872 $SDCC_HOME/
2873 \newline
2874
2875 \emph on
2876 $PREFIX2DATA_DIR/
2877 \newline
2878 $INCLUDE_DIR_SUFFIX
2879
2880 \end_inset
2881 </cell>
2882 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2883 \begin_inset Text
2884
2885 \layout Standard
2886 $SDCC_ HOME/
2887 \newline
2888 share/sdcc/
2889 \newline
2890 include
2891
2892 \end_inset
2893 </cell>
2894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2895 \begin_inset Text
2896
2897 \layout Standard
2898 $SDCC_HOME
2899 \backslash
2900 include
2901
2902 \end_inset
2903 </cell>
2904 </row>
2905 <row topline="true">
2906 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2907 \begin_inset Text
2908
2909 \layout Standard
2910 path(argv[0])/
2911 \newline
2912
2913 \emph on
2914 $BIN2DATADIR/
2915 \emph default
2916
2917 \newline
2918
2919 \emph on
2920 $INCLUDE_DIR_SUFFIX
2921
2922 \end_inset
2923 </cell>
2924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2925 \begin_inset Text
2926
2927 \layout Standard
2928 path(argv[0])/
2929 \newline
2930 ../sdcc/include
2931 \newline
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 \SpecialChar ~
2970
2971
2972 \end_inset
2973 </cell>
2974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2975 \begin_inset Text
2976
2977 \layout Standard
2978 path(argv[0])
2979 \backslash
2980 ..
2981 \backslash
2982 include
2983
2984 \end_inset
2985 </cell>
2986 </row>
2987 <row topline="true" bottomline="true">
2988 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_inset Text
2990
2991 \layout Standard
2992
2993 \emph on
2994 $DATADIR/
2995 \emph default
2996
2997 \newline
2998
2999 \emph on
3000 $INCLUDE_DIR_SUFFIX
3001
3002 \end_inset
3003 </cell>
3004 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3005 \begin_inset Text
3006
3007 \layout Standard
3008 /usr/local/share/sdcc/
3009 \newline
3010 include
3011
3012 \end_inset
3013 </cell>
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3015 \begin_inset Text
3016
3017 \layout Standard
3018 (not on Win32)
3019
3020 \end_inset
3021 </cell>
3022 </row>
3023 </lyxtabular>
3024
3025 \end_inset
3026
3027  
3028 \newline
3029
3030
3031 \layout Standard
3032 \noindent
3033 The option -
3034 \begin_inset ERT
3035 status Collapsed
3036
3037 \layout Standard
3038
3039
3040 \backslash
3041 /
3042
3043 \end_inset
3044
3045 -nostdinc disables the last two search paths.
3046 \newline
3047
3048 \newline
3049 3.
3050  Library files 
3051 \newline
3052
3053
3054 \layout Standard
3055 With the exception of 
3056 \begin_inset Quotes sld
3057 \end_inset
3058
3059 -
3060 \begin_inset ERT
3061 status Collapsed
3062
3063 \layout Standard
3064
3065
3066 \backslash
3067 /
3068
3069 \end_inset
3070
3071 -L dir
3072 \begin_inset Quotes srd
3073 \end_inset
3074
3075  the 
3076 \shape italic
3077 model
3078 \shape default
3079  is auto-appended by the compiler (e.g.
3080  small, large, z80, ds390 etc.).
3081  
3082 \newline
3083
3084
3085 \layout Standard
3086 \align center
3087 \begin_inset Tabular
3088 <lyxtabular version="3" rows="6" columns="3">
3089 <features>
3090 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3091 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3092 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3093 <row topline="true" bottomline="true">
3094 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3095 \begin_inset Text
3096
3097 \layout Standard
3098 Search path
3099
3100 \end_inset
3101 </cell>
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \layout Standard
3106 default
3107
3108 \end_inset
3109 </cell>
3110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3111 \begin_inset Text
3112
3113 \layout Standard
3114 Win32 builds
3115
3116 \end_inset
3117 </cell>
3118 </row>
3119 <row topline="true">
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_inset Text
3122
3123 \layout Standard
3124 -
3125 \begin_inset ERT
3126 status Collapsed
3127
3128 \layout Standard
3129
3130
3131 \backslash
3132 /
3133
3134 \end_inset
3135
3136 -L dir
3137
3138 \end_inset
3139 </cell>
3140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3141 \begin_inset Text
3142
3143 \layout Standard
3144 -
3145 \begin_inset ERT
3146 status Collapsed
3147
3148 \layout Standard
3149
3150
3151 \backslash
3152 /
3153
3154 \end_inset
3155
3156 -L dir
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \layout Standard
3164 -
3165 \begin_inset ERT
3166 status Collapsed
3167
3168 \layout Standard
3169
3170
3171 \backslash
3172 /
3173
3174 \end_inset
3175
3176 -L dir
3177
3178 \end_inset
3179 </cell>
3180 </row>
3181 <row topline="true">
3182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3183 \begin_inset Text
3184
3185 \layout Standard
3186 $SDCC_LIB/
3187 \newline
3188
3189 \emph on
3190 <model>
3191
3192 \end_inset
3193 </cell>
3194 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3195 \begin_inset Text
3196
3197 \layout Standard
3198 $SDCC_LIB/
3199 \newline
3200
3201 \emph on
3202 <model>
3203
3204 \end_inset
3205 </cell>
3206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3207 \begin_inset Text
3208
3209 \layout Standard
3210 $SDCC_LIB
3211 \backslash
3212
3213 \newline
3214
3215 \emph on
3216 <model>
3217
3218 \end_inset
3219 </cell>
3220 </row>
3221 <row topline="true">
3222 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3223 \begin_inset Text
3224
3225 \layout Standard
3226 $SDCC_HOME/
3227 \newline
3228
3229 \emph on
3230 $PREFIX2DATA_DIR/
3231 \newline
3232 $LIB_DIR_SUFFIX/<model>
3233
3234 \end_inset
3235 </cell>
3236 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3237 \begin_inset Text
3238
3239 \layout Standard
3240 $SDCC_HOME/
3241 \newline
3242 share/sdcc/
3243 \newline
3244 lib/
3245 \emph on
3246 <model>
3247
3248 \end_inset
3249 </cell>
3250 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3251 \begin_inset Text
3252
3253 \layout Standard
3254 $SDCC_HOME
3255 \backslash
3256 lib
3257 \backslash
3258
3259 \emph on
3260
3261 \newline
3262 <model>
3263
3264 \end_inset
3265 </cell>
3266 </row>
3267 <row topline="true">
3268 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3269 \begin_inset Text
3270
3271 \layout Standard
3272 path(argv[0])/
3273 \newline
3274
3275 \emph on
3276 $BIN2DATADIR/
3277 \emph default
3278
3279 \newline
3280
3281 \emph on
3282 $LIB_DIR_SUFFIX/<model>
3283
3284 \end_inset
3285 </cell>
3286 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3287 \begin_inset Text
3288
3289 \layout Standard
3290 path(argv[0])/
3291 \newline
3292 ../sdcc/lib/
3293 \emph on
3294 <model>
3295 \newline
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 \SpecialChar ~
3335
3336
3337 \end_inset
3338 </cell>
3339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3340 \begin_inset Text
3341
3342 \layout Standard
3343 path(argv[0])
3344 \backslash
3345
3346 \newline
3347 ..
3348 \backslash
3349 lib
3350 \backslash
3351
3352 \emph on
3353 <model>
3354 \newline
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 \SpecialChar ~
3390
3391
3392 \end_inset
3393 </cell>
3394 </row>
3395 <row topline="true" bottomline="true">
3396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3397 \begin_inset Text
3398
3399 \layout Standard
3400
3401 \emph on
3402 $DATADIR/
3403 \newline
3404 $LIB_DIR_SUFFIX/<model>
3405
3406 \end_inset
3407 </cell>
3408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3409 \begin_inset Text
3410
3411 \layout Standard
3412 /usr/local/share/sdcc/
3413 \newline
3414 lib/
3415 \emph on
3416 <model>
3417
3418 \end_inset
3419 </cell>
3420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3421 \begin_inset Text
3422
3423 \layout Standard
3424 (not on Win32)
3425
3426 \end_inset
3427 </cell>
3428 </row>
3429 </lyxtabular>
3430
3431 \end_inset
3432
3433
3434 \newline
3435
3436
3437 \layout Standard
3438 \begin_inset Note
3439 collapsed true
3440
3441 \layout Standard
3442 Don't delete any of the stray spaces in the table above without checking
3443  the HTML output (last line)!
3444
3445 \end_inset
3446
3447
3448
3449 \layout Standard
3450 \SpecialChar ~
3451
3452 \newline
3453 The option -
3454 \begin_inset ERT
3455 status Collapsed
3456
3457 \layout Standard
3458
3459
3460 \backslash
3461 /
3462
3463 \end_inset
3464
3465 -nostdlib disables the last two search paths.
3466
3467 \layout Section
3468 Building SDCC
3469 \begin_inset LatexCommand \index{Building SDCC}
3470
3471 \end_inset
3472
3473
3474
3475 \layout Subsection
3476 Building SDCC on Linux
3477 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3478
3479 \end_inset
3480
3481
3482
3483 \layout Enumerate
3484
3485 \series medium
3486 Download the source package
3487 \series default
3488  either from the SDCC Subversion repository or from snapshot builds
3489 \series medium
3490 , it will be named something like sdcc
3491 \series default
3492 -src
3493 \series medium
3494 -yyyymmdd-rrrr.t
3495 \series default
3496 ar.
3497 \series medium
3498 bz2
3499 \series default
3500  
3501 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3502
3503 \end_inset
3504
3505 .
3506
3507 \layout Enumerate
3508
3509 \series medium
3510 Bring up a command line terminal, such as xterm.
3511
3512 \layout Enumerate
3513
3514 \series medium
3515 Unpack the file using a command like: 
3516 \family sans
3517 \series bold
3518 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3519 \begin_inset Quotes srd
3520 \end_inset
3521
3522
3523 \family default
3524 \series medium
3525 , this will create a sub-directory called sdcc with all of the sources.
3526
3527 \layout Enumerate
3528 Change directory into the main SDCC directory, for example type: 
3529 \family sans
3530 \series bold
3531 "cd sdcc
3532 \series default
3533 ".
3534
3535 \layout Enumerate
3536
3537 \series medium
3538 Type 
3539 \family sans
3540 \series bold
3541 "./configure
3542 \family default
3543 \series default
3544 ".
3545  This configures the package for compilation on your system.
3546
3547 \layout Enumerate
3548
3549 \series medium
3550 Type 
3551 \family sans
3552 \series bold
3553 "make
3554 \family default
3555 \series default
3556 "
3557 \series medium
3558 .
3559
3560 \series default
3561  All of the source packages will compile, this can take a while.
3562
3563 \layout Enumerate
3564
3565 \series medium
3566 Type 
3567 \family sans
3568 \series bold
3569 "make install"
3570 \family default
3571 \series default
3572  as root
3573 \series medium
3574 .
3575
3576 \series default
3577  This copies the binary executables, the include files, the libraries and
3578  the documentation to the install directories.
3579  Proceed with section 
3580 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3581
3582 \end_inset
3583
3584 .
3585
3586 \layout Subsection
3587 Building SDCC on OSX 2.x
3588
3589 \layout Standard
3590 Follow the instruction for Linux.
3591 \newline
3592
3593 \newline
3594 On OSX 2.x it was reported, that the default
3595  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3596  Fortunately there's also gcc 2.9.x installed, which works fine.
3597  This compiler can be selected by running 'configure' with:
3598
3599 \layout LyX-Code
3600 ./configure CC=gcc2 CXX=g++2
3601
3602 \layout Subsection
3603 Cross compiling SDCC on Linux for Windows
3604
3605 \layout Standard
3606 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3607  See section 'Configure Options'.
3608
3609 \layout Subsection
3610 Building SDCC using Cygwin and Mingw32
3611
3612 \layout Standard
3613 For building and installing a Cygwin executable follow the instructions
3614  for Linux.
3615 \newline
3616
3617 \newline
3618 On Cygwin a 
3619 \begin_inset Quotes sld
3620 \end_inset
3621
3622 native
3623 \begin_inset Quotes srd
3624 \end_inset
3625
3626  Win32-binary can be built, which will not need the Cygwin-DLL.
3627  For the necessary 'configure' options see section 'configure options' or
3628  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3629 \newline
3630
3631 \newline
3632 In order to install
3633  Cygwin on Windows download setup.exe from 
3634 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3635
3636 \end_inset
3637
3638 .
3639  Run it, set the 
3640 \begin_inset Quotes sld
3641 \end_inset
3642
3643 default text file type
3644 \begin_inset Quotes srd
3645 \end_inset
3646
3647  to 
3648 \begin_inset Quotes sld
3649 \end_inset
3650
3651 unix
3652 \begin_inset Quotes srd
3653 \end_inset
3654
3655  and download/install at least the following packages.
3656  Some packages are selected by default, others will be automatically selected
3657  because of dependencies with the manually selected packages.
3658  Never deselect these packages!
3659
3660 \layout Itemize
3661 flex
3662
3663 \layout Itemize
3664 bison
3665
3666 \layout Itemize
3667 gcc ; version 3.x is fine, no need to use the old 2.9x
3668
3669 \layout Itemize
3670 binutils ; selected with gcc
3671
3672 \layout Itemize
3673 make
3674
3675 \layout Itemize
3676 rxvt ; a nice console, which makes life much easier under windoze (see below)
3677
3678 \layout Itemize
3679 man ; not really needed for building SDCC, but you'll miss it sooner or
3680  later
3681
3682 \layout Itemize
3683 less ; not really needed for building SDCC, but you'll miss it sooner or
3684  later
3685
3686 \layout Itemize
3687 svn ; only if you use Subversion access
3688
3689 \layout Standard
3690 If you want to develop something you'll need:
3691
3692 \layout Itemize
3693 python ; for the regression tests
3694
3695 \layout Itemize
3696 gdb ; the gnu debugger, together with the nice GUI 
3697 \begin_inset Quotes sld
3698 \end_inset
3699
3700 insight
3701 \begin_inset Quotes srd
3702 \end_inset
3703
3704
3705
3706 \layout Itemize
3707 openssh ; to access the CF or commit changes
3708
3709 \layout Itemize
3710 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3711  use autoconf-stable!
3712
3713 \layout Standard
3714 rxvt is a nice console with history.
3715  Replace in your cygwin.bat the line
3716
3717 \layout LyX-Code
3718 bash -
3719 \begin_inset ERT
3720 status Collapsed
3721
3722 \layout Standard
3723
3724
3725 \backslash
3726 /
3727
3728 \end_inset
3729
3730 -login -i 
3731
3732 \layout Standard
3733 with (one line):
3734
3735 \layout LyX-Code
3736 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3737
3738 \layout LyX-Code
3739      -bg black -fg white -geometry 100x65 -e bash -
3740 \begin_inset ERT
3741 status Collapsed
3742
3743 \layout Standard
3744
3745
3746 \backslash
3747 /
3748
3749 \end_inset
3750
3751 -login
3752
3753 \layout Standard
3754 Text selected with the mouse is automatically copied to the clipboard, pasting
3755  works with shift-insert.
3756 \newline
3757
3758 \newline
3759 The other good tip is to make sure you have no //c/-styl
3760 e paths anywhere, use /cygdrive/c/ instead.
3761  Using // invokes a network lookup which is very slow.
3762  If you think 
3763 \begin_inset Quotes sld
3764 \end_inset
3765
3766 cygdrive
3767 \begin_inset Quotes srd
3768 \end_inset
3769
3770  is too long, you can change it with e.g.
3771
3772 \layout LyX-Code
3773 mount -s -u -c /mnt
3774
3775 \layout Standard
3776 SDCC sources use the unix line ending LF.
3777  Life is much easier, if you store the source tree on a drive which is mounted
3778  in binary mode.
3779  And use an editor which can handle LF-only line endings.
3780  Make sure not to commit files with windows line endings.
3781  The tabulator spacing
3782 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3783
3784 \end_inset
3785
3786  used in the project is 8.
3787  Although a tabulator spacing of 8 is a sensible choice for programmers
3788  (it's a power of 2 and allows to display 8/16 bit signed variables without
3789  loosing columns) the plan is to move towards using only spaces in the source.
3790
3791 \layout Subsection
3792 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3793
3794 \layout Standard
3795
3796 \series medium
3797 Download the source package
3798 \series default
3799  either from the SDCC Subversion repository or from the 
3800 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
3801
3802 \end_inset
3803
3804
3805 \series medium
3806 , it will be named something like sdcc
3807 \series default
3808 -src
3809 \series medium
3810 -yyyymmdd-rrrr.tar.bz2.
3811
3812 \series default
3813  SDCC is distributed with all the projects, workspaces, and files you need
3814  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3815  The workspace name is 'sdcc.dsw'.
3816  Please note that as it is now, all the executables are created in a folder
3817  called sdcc
3818 \backslash
3819 bin_vc.
3820  Once built you need to copy the executables from sdcc
3821 \backslash
3822 bin_vc to sdcc
3823 \backslash
3824 bin before running SDCC.
3825  
3826 \newline
3827
3828 \newline
3829 WARNING: Visual studio is very picky with line terminations; it expects
3830  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3831  When using the Subversion repository it's easiest to configure the svn
3832  client to convert automatically for you.
3833  If however you are getting a message such as "This makefile was not generated
3834  by Developer Studio etc.
3835  etc.
3836 \begin_inset Quotes srd
3837 \end_inset
3838
3839  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3840  need to convert the Unix style line endings to DOS style line endings.
3841  To do so you can use the 
3842 \begin_inset Quotes sld
3843 \end_inset
3844
3845 unix2dos
3846 \begin_inset Quotes srd
3847 \end_inset
3848
3849  utility freely available on the internet.
3850  Doug Hawkins reported in the sdcc-user list that this works:
3851 \newline
3852
3853 \newline
3854 C:
3855 \backslash
3856 Programming
3857 \backslash
3858 SDCC> unix2dos sdcc.dsw
3859 \newline
3860 C:
3861 \backslash
3862 Programming
3863 \backslash
3864 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3865 \newline
3866
3867 \newline
3868 In order to build SDCC with MSVC
3869  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3870  One good place to get them is 
3871 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3872
3873 \end_inset
3874
3875
3876 \newline
3877
3878 \newline
3879 Download the file UnxUtils
3880 \begin_inset LatexCommand \index{UnxUtils}
3881
3882 \end_inset
3883
3884 .zip.
3885  Now you have to install the utilities and setup MSVC so it can locate the
3886  required programs.
3887  Here there are two alternatives (choose one!):
3888
3889 \layout Enumerate
3890 The easy way:
3891 \newline
3892
3893 \newline
3894 a) Extract UnxUtils.zip to your C:
3895 \backslash
3896  hard disk PRESERVING the original paths, otherwise bison won't work.
3897  (If you are using WinZip make certain that 'Use folder names' is selected)
3898 \newline
3899
3900 \newline
3901 b)
3902  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3903  'Show directories for:' select 'Executable files', and in the directories
3904  window add a new path: 'C:
3905 \backslash
3906 user
3907 \backslash
3908 local
3909 \backslash
3910 wbin', click ok.
3911 \newline
3912
3913 \newline
3914 (As a side effect, you get a bunch of Unix utilities that
3915  could be useful, such as diff and patch.)
3916
3917 \layout Enumerate
3918 A more compact way:
3919 \newline
3920
3921 \newline
3922 This one avoids extracting a bunch of files you may not
3923  use, but requires some extra work:
3924 \newline
3925
3926 \newline
3927 a) Create a directory were to put the
3928  tools needed, or use a directory already present.
3929  Say for example 'C:
3930 \backslash
3931 util'.
3932 \newline
3933
3934 \newline
3935 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3936  gawk.exe to such directory WITHOUT preserving the original paths.
3937  (If you are using WinZip make certain that 'Use folder names' is not selected)
3938 \newline
3939
3940 \newline
3941 c
3942 ) Rename bison.exe to '_bison.exe'.
3943 \newline
3944
3945 \newline
3946 d) Create a batch file 'bison.bat' in 'C:
3947 \backslash
3948 util
3949 \backslash
3950 ' and add these lines: 
3951 \newline
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 set BISON_SIMPLE=C:
3955 \backslash
3956 util
3957 \backslash
3958 bison.simple 
3959 \newline
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 set BISON_HAIRY=C:
3963 \backslash
3964 util
3965 \backslash
3966 bison.hairy
3967 \newline
3968 \SpecialChar ~
3969 \SpecialChar ~
3970 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3971 \newline
3972
3973 \newline
3974 Steps 'c' and 'd' are needed
3975  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3976  reside in some weird Unix directory, '/usr/local/share/' I think.
3977  So it is necessary to tell bison where those files are located if they
3978  are not in such directory.
3979  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3980 \newline
3981
3982 \newline
3983 e
3984 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3985  in 'Show directories for:' select 'Executable files', and in the directories
3986  window add a new path: 'c:
3987 \backslash
3988 util', click ok.
3989  Note that you can use any other path instead of 'c:
3990 \backslash
3991 util', even the path where the Visual C++ tools are, probably: 'C:
3992 \backslash
3993 Program Files
3994 \backslash
3995 Microsoft Visual Studio
3996 \backslash
3997 Common
3998 \backslash
3999 Tools'.
4000  So you don't have to execute step 'e' :)
4001
4002 \layout Standard
4003 That is it.
4004  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4005  the executables from sdcc
4006 \backslash
4007 bin_vc to sdcc
4008 \backslash
4009 bin, and you can compile using SDCC.
4010
4011 \layout Subsection
4012 Building SDCC Using Borland
4013
4014 \layout Enumerate
4015 From the sdcc directory, run the command "make -f Makefile.bcc".
4016  This should regenerate all the .exe files in the bin directory except for
4017  SDCDB and ucSim.
4018
4019 \layout Enumerate
4020 If you modify any source files and need to rebuild, be aware that the dependenci
4021 es may not be correctly calculated.
4022  The safest option is to delete all .obj files and run the build again.
4023  From a Cygwin BASH prompt, this can easily be done with the command (be
4024  sure you are in the sdcc directory):
4025 \newline
4026
4027 \newline
4028
4029 \family sans
4030 \series bold
4031 find .
4032  
4033 \backslash
4034 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4035 \backslash
4036 ) -print -exec rm {} 
4037 \backslash
4038 ;
4039 \family default
4040 \series default
4041
4042 \newline
4043
4044 \newline
4045 or on Windows NT/2000/XP from the command prompt with the command:
4046 \newline
4047
4048 \family sans
4049 \series bold
4050
4051 \newline
4052 del /s *.obj *.lib *.rul
4053 \family default
4054 \series default
4055  from the sdcc directory.
4056
4057 \layout Subsection
4058 Windows Install Using a ZIP Package
4059
4060 \layout Enumerate
4061 Download the binary zip package from 
4062 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4063
4064 \end_inset
4065
4066  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4067  This should unpack to a group of sub-directories.
4068  An example directory structure after unpacking the mingw32 package is:
4069  c:
4070 \backslash
4071 sdcc
4072 \backslash
4073 bin for the executables, c:
4074 \backslash
4075 sdcc
4076 \backslash
4077 include and c:
4078 \backslash
4079 sdcc
4080 \backslash
4081 lib for the include and libraries.
4082
4083 \layout Enumerate
4084 Adjust your environment variable PATH to include the location of the bin
4085  directory or start sdcc using the full path.
4086
4087 \layout Subsection
4088 Windows Install Using the Setup Program
4089 \begin_inset LatexCommand \label{sub:Windows-Install}
4090
4091 \end_inset
4092
4093
4094
4095 \layout Standard
4096 Download the setup program 
4097 \emph on
4098 sdcc-x.y.z-setup.exe
4099 \emph default
4100  for an official release from 
4101 \newline
4102
4103 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4104
4105 \end_inset
4106
4107  or a setup program for one of the snapshots 
4108 \emph on
4109 sdcc-yyyymmdd-xxxx-setup.exe
4110 \emph default
4111  from 
4112 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4113
4114 \end_inset
4115
4116  and execute it.
4117  A windows typical installer will guide you through the installation process.
4118
4119 \layout Subsection
4120 VPATH
4121 \begin_inset LatexCommand \index{VPATH}
4122
4123 \end_inset
4124
4125  feature
4126
4127 \layout Standard
4128 SDCC supports the VPATH feature provided by configure and make.
4129  It allows to separate the source and build trees.
4130  Here's an example:
4131
4132 \layout Standard
4133
4134 \family typewriter
4135 cd ~\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 \SpecialChar ~
4154 \SpecialChar ~
4155 \SpecialChar ~
4156 # cd $HOME
4157
4158 \layout Standard
4159
4160 \family typewriter
4161 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4162 # extract source to directory sdcc
4163
4164 \layout Standard
4165
4166 \family typewriter
4167 mkdir sdcc.build\SpecialChar ~
4168 \SpecialChar ~
4169 \SpecialChar ~
4170 \SpecialChar ~
4171 \SpecialChar ~
4172 \SpecialChar ~
4173 \SpecialChar ~
4174 \SpecialChar ~
4175 \SpecialChar ~
4176 # put output in sdcc.build
4177
4178 \layout Standard
4179
4180 \family typewriter
4181 cd sdcc.build
4182
4183 \layout Standard
4184
4185 \family typewriter
4186 ../sdcc/configure\SpecialChar ~
4187 \SpecialChar ~
4188 \SpecialChar ~
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 \SpecialChar ~
4192 \SpecialChar ~
4193 \SpecialChar ~
4194 # configure is doing all the magic!
4195
4196 \layout Standard
4197
4198 \family typewriter
4199 make
4200
4201 \layout Standard
4202 \noindent
4203 That's it! 
4204 \series bold
4205 configure
4206 \series default
4207  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4208  It automagically computes the variables srcdir, top_srcdir and top_buildir
4209  for each directory.
4210  After running 
4211 \series bold
4212 make
4213 \series default
4214  the generated files will be in ~/sdcc.build, while the source files stay
4215  in ~/sdcc.
4216 \newline
4217 This is not only usefull for building different binaries, e.g.
4218  when cross compiling.
4219  It also gives you a much better overview in the source tree when all the
4220  generated files are not scattered between the source files.
4221  And the best thing is: if you want to change a file you can leave the original
4222  file untouched in the source directory.
4223  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4224  Makefile.dep` and `make`.
4225  
4226 \series bold
4227 make
4228 \series default
4229  will do the rest for you!
4230
4231 \layout Section
4232 Building the Documentation
4233
4234 \layout Standard
4235 Add -
4236 \begin_inset ERT
4237 status Collapsed
4238
4239 \layout Standard
4240
4241
4242 \backslash
4243 /
4244
4245 \end_inset
4246
4247 -enable-doc to the configure arguments to build the documentation together
4248  with all the other stuff.
4249  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4250  dvips and makeindex) to get the job done.
4251  Another possibility is to change to the doc directory and to type 
4252 \family sans
4253 \series bold
4254
4255 \begin_inset Quotes srd
4256 \end_inset
4257
4258 make
4259 \begin_inset Quotes srd
4260 \end_inset
4261
4262
4263 \family default
4264 \series default
4265  there.
4266  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4267 x).
4268  Using LyX 
4269 \begin_inset LatexCommand \url{http://www.lyx.org}
4270
4271 \end_inset
4272
4273  as editor is straightforward.
4274  Prebuilt documentation in html and pdf format is available from 
4275 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4276
4277 \end_inset
4278
4279 .
4280
4281 \layout Section
4282 Reading the Documentation
4283 \begin_inset LatexCommand \index{Documentation}
4284
4285 \end_inset
4286
4287
4288
4289 \layout Standard
4290 Currently reading the document in pdf format is recommended, as for unknown
4291  reason the hyperlinks are working there whereas in the html version they
4292  are not
4293 \begin_inset Foot
4294 collapsed false
4295
4296 \layout Standard
4297 If you should know why please drop us a note
4298
4299 \end_inset
4300
4301 .
4302  
4303 \newline
4304 You'll find the pdf version
4305 \begin_inset LatexCommand \index{PDF version of this document}
4306
4307 \end_inset
4308
4309  at 
4310 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4311
4312 \end_inset
4313
4314 .
4315  
4316 \newline
4317 A html version
4318 \begin_inset LatexCommand \index{HTML version of this document}
4319
4320 \end_inset
4321
4322  should be online at 
4323 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4324
4325 \end_inset
4326
4327 .
4328 \newline
4329 This documentation is in some aspects different from a commercial documentation:
4330  
4331
4332 \layout Itemize
4333 It tries to document SDCC for several processor architectures in one document
4334  (commercially these probably would be separate documents/products).
4335  This document
4336 \begin_inset LatexCommand \index{Status of documentation}
4337
4338 \end_inset
4339
4340  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4341 on about f.e.
4342  Z80, PIC14, PIC16 and HC08.
4343
4344 \layout Itemize
4345 There are many references pointing away from this documentation.
4346  Don't let this distract you.
4347  If there f.e.
4348  was a reference like 
4349 \begin_inset LatexCommand \url{http://www.opencores.org}
4350
4351 \end_inset
4352
4353  together with a statement 
4354 \begin_inset Quotes sld
4355 \end_inset
4356
4357 some processors which are targetted by SDCC can be implemented in a 
4358 \emph on
4359 f
4360 \emph default
4361 ield 
4362 \emph on
4363 p
4364 \emph default
4365 rogrammable 
4366 \emph on
4367 g
4368 \emph default
4369 ate 
4370 \emph on
4371 a
4372 \emph default
4373 rray
4374 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4375
4376 \end_inset
4377
4378
4379 \begin_inset Quotes srd
4380 \end_inset
4381
4382  or 
4383 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4384
4385 \end_inset
4386
4387
4388 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4389
4390 \end_inset
4391
4392  
4393 \begin_inset Quotes sld
4394 \end_inset
4395
4396 have you ever heard of an open source compiler that compiles a subset of
4397  C for an FPGA?
4398 \begin_inset Quotes srd
4399 \end_inset
4400
4401  we expect you to have a quick look there and come back.
4402  If you read this you are on the right track.
4403
4404 \layout Itemize
4405 Some sections attribute more space to problems, restrictions and warnings
4406  than to the solution.
4407
4408 \layout Itemize
4409 The installation section and the section about the debugger is intimidating.
4410
4411 \layout Itemize
4412 There are still lots of typos and there are more different writing styles
4413  than pictures.
4414
4415 \layout Section
4416 Testing the SDCC Compiler
4417 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4418
4419 \end_inset
4420
4421
4422
4423 \layout Standard
4424 The first thing you should do after installing your SDCC compiler is to
4425  see if it runs.
4426  Type 
4427 \family sans
4428 \series bold
4429 "sdcc -
4430 \begin_inset ERT
4431 status Collapsed
4432
4433 \layout Standard
4434
4435
4436 \backslash
4437 /
4438
4439 \end_inset
4440
4441 -version"
4442 \begin_inset LatexCommand \index{version}
4443
4444 \end_inset
4445
4446
4447 \family default
4448 \series default
4449  at the prompt, and the program should run and output its version like:
4450  
4451 \newline
4452
4453 \family typewriter
4454 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4455  (UNIX)
4456
4457 \layout Standard
4458 If it doesn't run, or gives a message about not finding sdcc program, then
4459  you need to check over your installation.
4460  Make sure that the sdcc bin directory is in your executable search path
4461  defined by the PATH environment setting (
4462 \series medium
4463 see 
4464 \series default
4465 section 
4466 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4467
4468 \end_inset
4469
4470 \SpecialChar ~
4471
4472 \series medium
4473 Install trouble-shooting for suggestions
4474 \series default
4475 ).
4476  Make sure that the sdcc program is in the bin folder, if not perhaps something
4477  did not install correctly.
4478 \newline
4479
4480 \newline
4481
4482 \series medium
4483 SDCC 
4484 \series default
4485 is commonly installed as described in section 
4486 \begin_inset Quotes sld
4487 \end_inset
4488
4489 Install and search paths
4490 \begin_inset Quotes srd
4491 \end_inset
4492
4493 .
4494 \newline
4495
4496 \newline
4497
4498 \series medium
4499 Make sure the compiler works on a very simple example.
4500  Type in the following test.c program using your favorite 
4501 \series default
4502 ASCII 
4503 \series medium
4504 editor:
4505
4506 \layout Verse
4507
4508 \family typewriter
4509 char test;
4510 \newline
4511
4512 \newline
4513 void main(void) {
4514 \newline
4515 \SpecialChar ~
4516 \SpecialChar ~
4517 \SpecialChar ~
4518 \SpecialChar ~
4519 test=0;
4520 \newline
4521 }
4522
4523 \layout Standard
4524
4525 \series medium
4526 Compile this using the following command: 
4527 \family sans
4528 \series bold
4529 "sdcc -c test.c".
4530
4531 \family default
4532 \series default
4533  
4534 \series medium
4535 If all goes well, the compiler will generate a test.asm and test.rel file.
4536  Congratulations, you've just compiled your first program with SDCC.
4537  We used the -c option to tell SDCC not to link the generated code, just
4538  to keep things simple for this step.
4539 \series default
4540
4541 \newline
4542
4543 \newline
4544
4545 \series medium
4546 The next step is to try it with the linker.
4547  Type in 
4548 \family sans
4549 \series bold
4550 "sdcc test.c
4551 \family default
4552 \series default
4553 "
4554 \series medium
4555 .
4556  If all goes well the compiler will link with the libraries and produce
4557  a test.ihx output file.
4558  If this step fails
4559 \series default
4560  
4561 \series medium
4562 (no test.ihx, and the linker generates warnings), then the problem is most
4563  likely that 
4564 \series default
4565 SDCC
4566 \series medium
4567  cannot find the 
4568 \series default
4569 /
4570 \series medium
4571 usr/local/share/sdcc/lib directory
4572 \series default
4573  
4574 \series medium
4575 (see 
4576 \series default
4577 section 
4578 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4579
4580 \end_inset
4581
4582 \SpecialChar ~
4583
4584 \series medium
4585 Install trouble-shooting for suggestions).
4586 \series default
4587
4588 \newline
4589
4590 \newline
4591
4592 \series medium
4593 The final test is to ensure 
4594 \series default
4595 SDCC
4596 \series medium
4597  can use the 
4598 \series default
4599 standard
4600 \series medium
4601  header files and libraries.
4602  Edit test.c and change it to the following:
4603
4604 \layout Verse
4605
4606 \family typewriter
4607 #include <string.h>
4608 \newline
4609
4610 \newline
4611 char str1[10];
4612 \newline
4613
4614 \newline
4615 void main(void) {
4616 \newline
4617 \SpecialChar ~
4618 \SpecialChar ~
4619 strcpy(str1, "testing");
4620 \newline
4621 }
4622
4623 \layout Standard
4624
4625 \series medium
4626 Compile this by typing 
4627 \family sans
4628 \series bold
4629 "sdcc test.c"
4630 \family default
4631 \series medium
4632 .
4633  This should generate a test.ihx output file, and it should give no warnings
4634  such as not finding the string.h file.
4635  If it cannot find the string.h file, then the problem is that 
4636 \series default
4637 SDCC
4638 \series medium
4639  cannot find the /usr/local/share/sdcc/include directory
4640 \series default
4641  
4642 \series medium
4643 (see the 
4644 \series default
4645 section 
4646 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4647
4648 \end_inset
4649
4650 \SpecialChar ~
4651
4652 \series medium
4653 Install trouble-shooting section for suggestions).
4654
4655 \series default
4656  Use option 
4657 \series bold
4658 -
4659 \begin_inset ERT
4660 status Collapsed
4661
4662 \layout Standard
4663
4664
4665 \backslash
4666 /
4667
4668 \end_inset
4669
4670 -print-search-dirs
4671 \series default
4672
4673 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4674
4675 \end_inset
4676
4677  to find exactly where SDCC is looking for the include and lib files.
4678
4679 \layout Section
4680 Install Trouble-shooting
4681 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4682
4683 \end_inset
4684
4685
4686 \begin_inset LatexCommand \index{Install trouble-shooting}
4687
4688 \end_inset
4689
4690
4691
4692 \layout Subsection
4693 If SDCC does not build correctly
4694
4695 \layout Standard
4696 A thing to try is starting from scratch by unpacking the .tgz source package
4697  again in an empty directory.
4698  Configure it like:
4699 \newline
4700
4701 \newline
4702
4703 \family sans
4704 \series bold
4705 ./configure 2>&1 | tee configure.log
4706 \family default
4707 \series default
4708
4709 \newline
4710
4711 \newline
4712 and build it like:
4713 \newline
4714
4715 \newline
4716
4717 \family sans
4718 \series bold
4719 make 2>&1 | tee make.log
4720 \family default
4721 \series default
4722
4723 \newline
4724
4725 \newline
4726 If anything goes wrong, you can review the log files to locate the problem.
4727  Or a relevant part of this can be attached to an email that could be helpful
4728  when requesting help from the mailing list.
4729
4730 \layout Subsection
4731 What the 
4732 \begin_inset Quotes sld
4733 \end_inset
4734
4735 ./configure
4736 \begin_inset Quotes srd
4737 \end_inset
4738
4739  does
4740
4741 \layout Standard
4742 The 
4743 \begin_inset Quotes sld
4744 \end_inset
4745
4746 ./configure
4747 \begin_inset Quotes srd
4748 \end_inset
4749
4750  command is a script that analyzes your system and performs some configuration
4751  to ensure the source package compiles on your system.
4752  It will take a few minutes to run, and will compile a few tests to determine
4753  what compiler features are installed.
4754
4755 \layout Subsection
4756 What the 
4757 \begin_inset Quotes sld
4758 \end_inset
4759
4760 make
4761 \begin_inset Quotes srd
4762 \end_inset
4763
4764  does
4765
4766 \layout Standard
4767 This runs the GNU make tool, which automatically compiles all the source
4768  packages into the final installed binary executables.
4769
4770 \layout Subsection
4771 What the 
4772 \begin_inset Quotes sld
4773 \end_inset
4774
4775 make install
4776 \begin_inset Quotes erd
4777 \end_inset
4778
4779  command does.
4780
4781 \layout Standard
4782 This will install the compiler, other executables libraries and include
4783  files into the appropriate directories.
4784  See sections 
4785 \begin_inset LatexCommand \ref{sub:Install-paths}
4786
4787 \end_inset
4788
4789 ,\SpecialChar ~
4790
4791 \begin_inset LatexCommand \ref{sub:Search-Paths}
4792
4793 \end_inset
4794
4795 \SpecialChar ~
4796 about install and search paths.
4797 \newline
4798 On most systems you will need super-user privilege
4799 s to do this.
4800
4801 \layout Section
4802 Components of SDCC
4803
4804 \layout Standard
4805 SDCC is not just a compiler, but a collection of tools by various developers.
4806  These include linkers, assemblers, simulators and other components.
4807  Here is a summary of some of the components.
4808  Note that the included simulator and assembler have separate documentation
4809  which you can find in the source package in their respective directories.
4810  As SDCC grows to include support for other processors, other packages from
4811  various developers are included and may have their own sets of documentation.
4812 \newline
4813
4814 \newline
4815 You
4816  might want to look at the files which are installed in <installdir>.
4817  At the time of this writing, we find the following programs for gcc-builds:
4818 \newline
4819
4820  
4821 \newline
4822 In <installdir>/bin:
4823
4824 \layout Itemize
4825 sdcc - The compiler.
4826
4827 \layout Itemize
4828 sdcpp - The C preprocessor.
4829
4830 \layout Itemize
4831 asx8051 - The assembler for 8051 type processors.
4832
4833 \layout Itemize
4834 as-z80
4835 \series bold
4836
4837 \series default
4838 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4839
4840 \layout Itemize
4841 aslink -The linker for 8051 type processors.
4842
4843 \layout Itemize
4844 link-z80
4845 \series bold
4846
4847 \series default
4848 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4849
4850 \layout Itemize
4851 s51 - The ucSim 8051 simulator.
4852
4853 \layout Itemize
4854 sdcdb - The source debugger.
4855
4856 \layout Itemize
4857 packihx - A tool to pack (compress) Intel hex files.
4858
4859 \layout Standard
4860 In <installdir>/share/sdcc/include
4861
4862 \layout Itemize
4863 the include files
4864
4865 \layout Standard
4866 In <installdir>/share/sdcc/lib
4867
4868 \layout Itemize
4869 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4870  relocatables.
4871
4872 \layout Standard
4873 In <installdir>/share/sdcc/doc
4874
4875 \layout Itemize
4876 the documentation
4877
4878 \layout Standard
4879 As development for other processors proceeds, this list will expand to include
4880  executables to support processors like AVR, PIC, etc.
4881
4882 \layout Subsection
4883 sdcc - The Compiler
4884
4885 \layout Standard
4886 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4887  the assembler and linkage editor.
4888
4889 \layout Subsection
4890 sdcpp - The C-Preprocessor
4891
4892 \layout Standard
4893 The preprocessor
4894 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4895
4896 \end_inset
4897
4898  is a modified version of the GNU cpp
4899 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4900
4901 \end_inset
4902
4903  preprocessor 
4904 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4905
4906 \end_inset
4907
4908 .
4909  The C preprocessor is used to pull in #include sources, process #ifdef
4910  statements, #defines and so on.
4911
4912 \layout Subsection
4913 as
4914 \emph on
4915 xxxx
4916 \emph default
4917 , aslink, link-
4918 \emph on
4919 xxx
4920 \emph default
4921  - The Assemblers and Linkage Editors
4922
4923 \layout Standard
4924 This is retargettable assembler & linkage editor, it was developed by Alan
4925  Baldwin.
4926  John Hartman created the version for 8051, and I (Sandeep) have made some
4927  enhancements and bug fixes for it to work properly with SDCC.
4928
4929 \layout Subsection
4930 s51 - The Simulator
4931
4932 \layout Standard
4933 S51
4934 \begin_inset LatexCommand \index{s51}
4935
4936 \end_inset
4937
4938  is a freeware, opensource simulator developed by Daniel Drotos.
4939  The simulator is built as part of the build process.
4940  For more information visit Daniel's web site at: 
4941 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4942
4943 \end_inset
4944
4945 .
4946  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4947  XA51 family.
4948
4949 \layout Subsection
4950 sdcdb - Source Level Debugger
4951
4952 \layout Standard
4953 SDCDB
4954 \begin_inset LatexCommand \index{SDCDB (debugger)}
4955
4956 \end_inset
4957
4958  is the companion source level debugger.
4959  More about SDCDB in section 
4960 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4961
4962 \end_inset
4963
4964 .
4965  The current version of the debugger uses Daniel's Simulator S51
4966 \begin_inset LatexCommand \index{s51}
4967
4968 \end_inset
4969
4970 , but can be easily changed to use other simulators.
4971
4972 \layout Chapter
4973 Using SDCC
4974
4975 \layout Section
4976 Compiling
4977
4978 \layout Subsection
4979 Single Source File Projects
4980
4981 \layout Standard
4982 For single source file 8051 projects the process is very simple.
4983  Compile your programs with the following command 
4984 \family sans
4985 \series bold
4986 "sdcc sourcefile.c".
4987
4988 \family default
4989 \series default
4990  This will compile, assemble and link your source file.
4991  Output files are as follows:
4992
4993 \layout Itemize
4994 sourcefile.asm
4995 \begin_inset LatexCommand \index{<file>.asm}
4996
4997 \end_inset
4998
4999  - Assembler source
5000 \begin_inset LatexCommand \index{Assembler source}
5001
5002 \end_inset
5003
5004  file created by the compiler
5005
5006 \layout Itemize
5007 sourcefile.lst
5008 \begin_inset LatexCommand \index{<file>.lst}
5009
5010 \end_inset
5011
5012  - Assembler listing
5013 \begin_inset LatexCommand \index{Assembler listing}
5014
5015 \end_inset
5016
5017  file created by the Assembler
5018
5019 \layout Itemize
5020 sourcefile.rst
5021 \begin_inset LatexCommand \index{<file>.rst}
5022
5023 \end_inset
5024
5025  - Assembler listing
5026 \begin_inset LatexCommand \index{Assembler listing}
5027
5028 \end_inset
5029
5030  file updated with linkedit information, created by linkage editor
5031
5032 \layout Itemize
5033 sourcefile.sym
5034 \begin_inset LatexCommand \index{<file>.sym}
5035
5036 \end_inset
5037
5038  - symbol listing
5039 \begin_inset LatexCommand \index{Symbol listing}
5040
5041 \end_inset
5042
5043  for the sourcefile, created by the assembler
5044
5045 \layout Itemize
5046 sourcefile.rel
5047 \begin_inset LatexCommand \index{<file>.rel}
5048
5049 \end_inset
5050
5051  or sourcefile.o
5052 \begin_inset LatexCommand \index{<file>.o}
5053
5054 \end_inset
5055
5056  - Object file
5057 \begin_inset LatexCommand \index{Object file}
5058
5059 \end_inset
5060
5061  created by the assembler, input to Linkage editor
5062
5063 \layout Itemize
5064 sourcefile.map
5065 \begin_inset LatexCommand \index{<file>.map}
5066
5067 \end_inset
5068
5069  - The memory map
5070 \begin_inset LatexCommand \index{Memory map}
5071
5072 \end_inset
5073
5074  for the load module, created by the Linker
5075
5076 \layout Itemize
5077 sourcefile.mem
5078 \begin_inset LatexCommand \index{<file>.mem}
5079
5080 \end_inset
5081
5082  - A file with a summary of the memory usage
5083
5084 \layout Itemize
5085 sourcefile.ihx
5086 \begin_inset LatexCommand \index{<file>.ihx}
5087
5088 \end_inset
5089
5090  - The load module in Intel hex format
5091 \begin_inset LatexCommand \index{Intel hex format}
5092
5093 \end_inset
5094
5095  (you can select the Motorola S19 format
5096 \begin_inset LatexCommand \index{Motorola S19 format}
5097
5098 \end_inset
5099
5100  with -
5101 \begin_inset ERT
5102 status Collapsed
5103
5104 \layout Standard
5105
5106
5107 \backslash
5108 /
5109
5110 \end_inset
5111
5112 -out-fmt-s19
5113 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5114
5115 \end_inset
5116
5117 .
5118  If you need another format you might want to use 
5119 \family sans
5120 \shape italic
5121 objdump
5122 \family default
5123 \shape default
5124
5125 \begin_inset LatexCommand \index{objdump (tool)}
5126
5127 \end_inset
5128
5129  or
5130 \family sans
5131 \shape italic
5132  srecord
5133 \family default
5134 \shape default
5135
5136 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5137
5138 \end_inset
5139
5140 ).
5141  Both formats are documented in the documentation of srecord
5142 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5143
5144 \end_inset
5145
5146
5147
5148 \layout Itemize
5149 sourcefile.adb
5150 \begin_inset LatexCommand \index{<file>.adb}
5151
5152 \end_inset
5153
5154  - An intermediate file containing debug information needed to create the
5155  .cdb file (with -
5156 \begin_inset ERT
5157 status Collapsed
5158
5159 \layout Standard
5160
5161
5162 \backslash
5163 /
5164
5165 \end_inset
5166
5167 -debug
5168 \begin_inset LatexCommand \index{-\/-debug}
5169
5170 \end_inset
5171
5172
5173
5174 \layout Itemize
5175 sourcefile.cdb
5176 \begin_inset LatexCommand \index{<file>.cdb}
5177
5178 \end_inset
5179
5180  - An optional file (with -
5181 \begin_inset ERT
5182 status Collapsed
5183
5184 \layout Standard
5185
5186
5187 \backslash
5188 /
5189
5190 \end_inset
5191
5192 -debug) containing debug information.
5193  The format is documented in cdbfileformat.pdf
5194
5195 \layout Itemize
5196 sourcefile.
5197  - (no extension)
5198 \begin_inset LatexCommand \index{<file> (no extension)}
5199
5200 \end_inset
5201
5202  An optional AOMF or AOMF51
5203 \begin_inset LatexCommand \index{AOMF, AOMF51}
5204
5205 \end_inset
5206
5207  
5208 \begin_inset LatexCommand \label{OMF file}
5209
5210 \end_inset
5211
5212 file containing debug information (generated with option -
5213 \begin_inset ERT
5214 status Collapsed
5215
5216 \layout Standard
5217
5218
5219 \backslash
5220 /
5221
5222 \end_inset
5223
5224 -debug).
5225  The (Intel)
5226 \emph on
5227  a
5228 \emph default
5229 bsolute 
5230 \emph on
5231 o
5232 \emph default
5233 bject 
5234 \emph on
5235 m
5236 \emph default
5237 odule 
5238 \emph on
5239 f
5240 \emph default
5241 ormat is commonly used by third party tools (debuggers
5242 \begin_inset LatexCommand \index{Debugger}
5243
5244 \end_inset
5245
5246 , simulators, emulators)
5247
5248 \layout Itemize
5249 sourcefile.dump*
5250 \begin_inset LatexCommand \index{<file>.dump*}
5251
5252 \end_inset
5253
5254  - Dump file to debug the compiler it self (generated with option -
5255 \begin_inset ERT
5256 status Collapsed
5257
5258 \layout Standard
5259
5260
5261 \backslash
5262 /
5263
5264 \end_inset
5265
5266 -dumpall) (see section 
5267 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5268
5269 \end_inset
5270
5271 \SpecialChar ~
5272  and section 
5273 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5274
5275 \end_inset
5276
5277 \SpecialChar ~
5278
5279 \begin_inset Quotes sld
5280 \end_inset
5281
5282 Anatomy of the compiler
5283 \begin_inset Quotes srd
5284 \end_inset
5285
5286 ).
5287
5288 \layout Subsection
5289 Postprocessing the Intel Hex
5290 \begin_inset LatexCommand \index{Intel hex format}
5291
5292 \end_inset
5293
5294  file
5295
5296 \layout Standard
5297 In most cases this won't be needed but the Intel Hex file
5298 \begin_inset LatexCommand \index{<file>.ihx}
5299
5300 \end_inset
5301
5302  which is generated by SDCC might include lines of varying length and the
5303  addresses within the file are not guaranteed to be strictly ascending.
5304  If your toolchain or a bootloader does not like this you can use the tool
5305  
5306 \family typewriter
5307 packihx
5308 \family default
5309
5310 \begin_inset LatexCommand \index{packihx (tool)}
5311
5312 \end_inset
5313
5314  which is part of the SDCC distribution: 
5315 \newline
5316
5317 \newline
5318
5319 \family sans
5320 \series bold
5321  packihx sourcefile.ihx >sourcefile.hex
5322 \family default
5323 \series default
5324
5325 \newline
5326
5327 \newline
5328 The separately available
5329 \emph on
5330  srecord
5331 \emph default
5332
5333 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5334
5335 \end_inset
5336
5337  package additionally allows to set undefined locations to a predefined
5338  value, to insert checksums
5339 \begin_inset LatexCommand \index{checksum}
5340
5341 \end_inset
5342
5343  of various flavours (crc, add, xor) and to perform other manipulations
5344  (convert, split, crop, offset, ...).
5345  
5346 \newline
5347
5348 \newline
5349
5350 \family sans
5351 \series bold
5352 srec_cat\SpecialChar ~
5353 \SpecialChar ~
5354 sourcefile.ihx -intel\SpecialChar ~
5355 \SpecialChar ~
5356 -o sourcefile.hex -intel
5357 \newline
5358
5359 \newline
5360
5361 \family default
5362 \series default
5363 An example for a more complex command line
5364 \begin_inset Foot
5365 collapsed false
5366
5367 \layout Standard
5368 the command backfills
5369 \begin_inset LatexCommand \index{backfill unused memory}
5370
5371 \end_inset
5372
5373  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5374  block is zero.
5375  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5376  will be interpreted as an 
5377 \family typewriter
5378 lcall
5379 \family default
5380  to address 
5381 \family typewriter
5382 0x1212
5383 \family default
5384  (where an emergency routine could sit).
5385
5386 \end_inset
5387
5388  could look like:
5389 \newline
5390
5391 \newline
5392
5393 \family sans
5394 \series bold
5395 \size footnotesize
5396 srec_cat\SpecialChar ~
5397 sourcefile.ihx -intel\SpecialChar ~
5398 \SpecialChar ~
5399 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5400 -little-endian-checksum-nega
5401 tive 0xfffe 0x02 0x02\SpecialChar ~
5402 \SpecialChar ~
5403 -o sourcefile.hex -intel
5404 \size default
5405
5406 \newline
5407
5408 \newline
5409
5410 \family default
5411 \series default
5412 The srecord package is available at 
5413 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5414
5415 \end_inset
5416
5417  .
5418
5419 \layout Subsection
5420 Projects with Multiple Source Files
5421
5422 \layout Standard
5423 SDCC can compile only ONE file at a time.
5424  Let us for example assume that you have a project containing the following
5425  files:
5426 \newline
5427
5428 \newline
5429 foo1.c (contains some functions)
5430 \newline
5431 foo2.c (contains some more functions)
5432 \newline
5433 foomai
5434 n.c (contains more functions and the function main)
5435 \newline
5436
5437 \size footnotesize
5438
5439 \newline
5440
5441 \size default
5442 The first two files will need to be compiled separately with the commands:
5443 \size footnotesize
5444  
5445 \size default
5446
5447 \newline
5448
5449 \newline
5450
5451 \family sans
5452 \series bold
5453 sdcc\SpecialChar ~
5454 -c\SpecialChar ~
5455 foo1.c
5456 \family default
5457 \series default
5458 \size footnotesize
5459
5460 \newline
5461
5462 \family sans
5463 \series bold
5464 \size default
5465 sdcc\SpecialChar ~
5466 -c\SpecialChar ~
5467 foo2.c
5468 \family default
5469 \series default
5470
5471 \newline
5472
5473 \newline
5474 Then compile the source file containing the 
5475 \emph on
5476 main()
5477 \emph default
5478  function and link
5479 \begin_inset LatexCommand \index{Linker}
5480
5481 \end_inset
5482
5483  the files together with the following command: 
5484 \newline
5485
5486 \newline
5487
5488 \family sans
5489 \series bold
5490 sdcc\SpecialChar ~
5491 foomain.c\SpecialChar ~
5492 foo1.rel\SpecialChar ~
5493 foo2.rel
5494 \family default
5495 \series default
5496
5497 \begin_inset LatexCommand \index{<file>.rel}
5498
5499 \end_inset
5500
5501
5502 \newline
5503
5504 \newline
5505 Alternatively, 
5506 \emph on
5507 foomain.c 
5508 \emph default
5509 can be separately compiled as well: 
5510 \family sans
5511 \series bold
5512
5513 \newline
5514
5515 \newline
5516 sdcc\SpecialChar ~
5517 -c\SpecialChar ~
5518 foomain.c
5519 \newline
5520 sdcc foomain.rel foo1.rel foo2.rel
5521 \newline
5522
5523 \newline
5524
5525 \family default
5526 \series default
5527 The file containing the 
5528 \emph on
5529 main()
5530 \emph default
5531  function
5532 \emph on
5533  
5534 \emph default
5535 \noun on
5536 must
5537 \noun default
5538  be the 
5539 \noun on
5540 first
5541 \noun default
5542  file specified in the command line, since the linkage editor processes
5543  file in the order they are presented to it.
5544  The linker is invoked from SDCC using a script file with extension .lnk
5545 \begin_inset LatexCommand \index{<file>.lnk}
5546
5547 \end_inset
5548
5549 .
5550  You can view this file to troubleshoot linking problems such as those arising
5551  from missing libraries.
5552
5553 \layout Subsection
5554 Projects with Additional Libraries
5555 \begin_inset LatexCommand \index{Libraries}
5556
5557 \end_inset
5558
5559
5560
5561 \layout Standard
5562 Some reusable routines may be compiled into a library, see the documentation
5563  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5564  for how to create a 
5565 \emph on
5566 .lib
5567 \begin_inset LatexCommand \index{<file>.lib}
5568
5569 \end_inset
5570
5571
5572 \emph default
5573  library file.
5574  Libraries created in this manner can be included in the command line.
5575  Make sure you include the -L <library-path> option to tell the linker where
5576  to look for these files if they are not in the current directory.
5577  Here is an example, assuming you have the source file 
5578 \emph on
5579 foomain.c
5580 \emph default
5581  and a library
5582 \emph on
5583  foolib.lib
5584 \emph default
5585  in the directory 
5586 \emph on
5587 mylib
5588 \emph default
5589  (if that is not the same as your current project):
5590 \newline
5591
5592 \newline
5593
5594 \family sans
5595 \series bold
5596 sdcc foomain.c foolib.lib -L mylib
5597 \newline
5598
5599 \newline
5600
5601 \family default
5602 \series default
5603 Note here that
5604 \emph on
5605  mylib
5606 \emph default
5607  must be an absolute path name.
5608 \newline
5609
5610 \newline
5611 The most efficient way to use libraries is
5612  to keep separate modules in separate source files.
5613  The lib file now should name all the modules.rel
5614 \begin_inset LatexCommand \index{<file>.rel}
5615
5616 \end_inset
5617
5618  files.
5619  For an example see the standard library file 
5620 \emph on
5621 libsdcc.lib
5622 \emph default
5623  in the directory <installdir>/share/lib/small.
5624
5625 \layout Subsection
5626 Using sdcclib to Create and Manage Libraries
5627 \begin_inset LatexCommand \index{sdcclib}
5628
5629 \end_inset
5630
5631
5632
5633 \layout Standard
5634 Alternatively, instead of having a .rel file for each entry on the library
5635  file as described in the preceding section, sdcclib can be used to embed
5636  all the modules belonging to such library in the library file itself.
5637  This results in a larger library file, but it greatly reduces the number
5638  of disk files accessed by the linker.
5639   Additionally, the packed library file contains an index of all include
5640  modules and symbols that significantly speeds up the linking process.
5641  To display a list of options supported by sdcclib type:
5642 \newline
5643
5644
5645 \layout Standard
5646
5647 \family sans
5648 \series bold
5649 sdcclib -?
5650 \begin_inset LatexCommand \index{sdcclib}
5651
5652 \end_inset
5653
5654
5655 \newline
5656
5657 \newline
5658
5659 \family default
5660 \series default
5661 To create a new library file, start by compiling all the required modules.
5662  For example:
5663 \newline
5664
5665
5666 \layout Standard
5667
5668 \family sans
5669 \series bold
5670 sdcc -c _divsint.c
5671
5672 \layout Standard
5673
5674 \family sans
5675 \series bold
5676 sdcc -c _divuint.c
5677
5678 \layout Standard
5679
5680 \family sans
5681 \series bold
5682 sdcc -c _modsint.c
5683
5684 \layout Standard
5685
5686 \family sans
5687 \series bold
5688 sdcc -c _moduint.c
5689
5690 \layout Standard
5691
5692 \family sans
5693 \series bold
5694 sdcc -c _mulint.c
5695 \newline
5696
5697
5698 \layout Standard
5699 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5700  and _mulint.rel.
5701  The next step is to add the .rel files to the library file:
5702 \newline
5703
5704
5705 \layout Standard
5706
5707 \family sans
5708 \series bold
5709 sdcclib libint.lib _divsint.rel
5710 \family default
5711
5712 \begin_inset LatexCommand \index{sdcclib}
5713
5714 \end_inset
5715
5716
5717
5718 \layout Standard
5719
5720 \family sans
5721 \series bold
5722 sdcclib libint.lib _divuint.rel
5723
5724 \layout Standard
5725
5726 \family sans
5727 \series bold
5728 sdcclib libint.lib _modsint.rel
5729
5730 \layout Standard
5731
5732 \family sans
5733 \series bold
5734 sdcclib libint.lib _moduint.rel
5735
5736 \layout Standard
5737
5738 \family sans
5739 \series bold
5740 sdcclib libint.lib _mulint.rel
5741 \series default
5742
5743 \newline
5744
5745
5746 \layout Standard
5747 If the file already exists in the library, it will be replaced.
5748  To see what modules and symbols are included in the library, options -s
5749  and -m are available.
5750  For example:
5751 \newline
5752
5753 \newline
5754
5755 \family sans
5756 \series bold
5757 sdcclib -s libint.lib
5758 \family default
5759
5760 \begin_inset LatexCommand \index{sdcclib}
5761
5762 \end_inset
5763
5764
5765 \newline
5766
5767 \family typewriter
5768 \series default
5769 _divsint.rel:
5770
5771 \layout Standard
5772
5773 \family typewriter
5774 __divsint_a_1_1
5775
5776 \layout Standard
5777
5778 \family typewriter
5779 __divsint_PARM_2
5780
5781 \layout Standard
5782
5783 \family typewriter
5784 __divsint
5785 \newline
5786 _divuint.rel:
5787
5788 \layout Standard
5789
5790 \family typewriter
5791 __divuint_a_1_1
5792
5793 \layout Standard
5794
5795 \family typewriter
5796 __divuint_PARM_2
5797
5798 \layout Standard
5799
5800 \family typewriter
5801 __divuint_reste_1_1
5802
5803 \layout Standard
5804
5805 \family typewriter
5806 __divuint_count_1_1
5807
5808 \layout Standard
5809
5810 \family typewriter
5811 __divuint
5812 \newline
5813 _modsint.rel:
5814
5815 \layout Standard
5816
5817 \family typewriter
5818 __modsint_a_1_1
5819
5820 \layout Standard
5821
5822 \family typewriter
5823 __modsint_PARM_2
5824
5825 \layout Standard
5826
5827 \family typewriter
5828 __modsint
5829 \newline
5830 _moduint.rel:
5831
5832 \layout Standard
5833
5834 \family typewriter
5835 __moduint_a_1_1
5836
5837 \layout Standard
5838
5839 \family typewriter
5840 __moduint_PARM_2
5841
5842 \layout Standard
5843
5844 \family typewriter
5845 __moduint_count_1_1
5846
5847 \layout Standard
5848
5849 \family typewriter
5850 __moduint
5851 \newline
5852 _mulint.rel:
5853
5854 \layout Standard
5855
5856 \family typewriter
5857 __mulint_PARM_2
5858
5859 \layout Standard
5860
5861 \family typewriter
5862 __mulint
5863 \family default
5864 \series bold
5865
5866 \newline
5867
5868
5869 \layout Standard
5870 \added_space_bottom bigskip 
5871 If the source files are compiled using -
5872 \begin_inset ERT
5873 status Collapsed
5874
5875 \layout Standard
5876
5877
5878 \backslash
5879 /
5880
5881 \end_inset
5882
5883 -debug
5884 \begin_inset LatexCommand \index{-\/-debug}
5885
5886 \end_inset
5887
5888 , the corresponding debug information file .adb will be include in the library
5889  file as well.
5890  The library files created with sdcclib are plain text files, so they can
5891  be viewed with a text editor.
5892  It is not recomended to modify a library file created with sdcclib using
5893  a text editor, as there are file indexes numbers located accross the file
5894  used by the linker to quickly locate the required module to link.
5895  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5896  it can be safely deleted, since all the information required for linking
5897  is embedded in the library file itself.
5898  Library files created using sdcclib are used as described in the preceding
5899  sections.
5900
5901
5902
5903 \layout Section
5904 Command Line Options
5905 \begin_inset LatexCommand \index{Command Line Options}
5906
5907 \end_inset
5908
5909
5910
5911 \layout Subsection
5912 Processor Selection Options
5913 \begin_inset LatexCommand \index{Options processor selection}
5914
5915 \end_inset
5916
5917
5918 \begin_inset LatexCommand \index{Processor selection options}
5919
5920 \end_inset
5921
5922
5923
5924 \layout List
5925 \labelwidthstring 00.00.0000
5926
5927 \series bold
5928 -mmcs51
5929 \begin_inset LatexCommand \index{-mmcs51}
5930
5931 \end_inset
5932
5933
5934 \series default
5935  Generate code for the Intel MCS51
5936 \begin_inset LatexCommand \index{MCS51}
5937
5938 \end_inset
5939
5940  family of processors.
5941  This is the default processor target.
5942
5943 \layout List
5944 \labelwidthstring 00.00.0000
5945
5946 \series bold
5947 -mds390
5948 \begin_inset LatexCommand \index{-mds390}
5949
5950 \end_inset
5951
5952
5953 \series default
5954  Generate code for the Dallas DS80C390
5955 \begin_inset LatexCommand \index{DS80C390}
5956
5957 \end_inset
5958
5959  processor.
5960
5961 \layout List
5962 \labelwidthstring 00.00.0000
5963
5964 \series bold
5965 -mds400
5966 \begin_inset LatexCommand \index{-mds400}
5967
5968 \end_inset
5969
5970
5971 \series default
5972  Generate code for the Dallas DS80C400
5973 \begin_inset LatexCommand \index{DS80C400}
5974
5975 \end_inset
5976
5977  processor.
5978
5979 \layout List
5980 \labelwidthstring 00.00.0000
5981
5982 \series bold
5983 -mhc08
5984 \begin_inset LatexCommand \index{-mhc08}
5985
5986 \end_inset
5987
5988
5989 \series default
5990  Generate code for the Freescale/Motorola HC08
5991 \begin_inset LatexCommand \index{HC08}
5992
5993 \end_inset
5994
5995  family of processors.
5996
5997 \layout List
5998 \labelwidthstring 00.00.0000
5999
6000 \series bold
6001 -mz80
6002 \begin_inset LatexCommand \index{-mz80}
6003
6004 \end_inset
6005
6006
6007 \series default
6008  Generate code for the Zilog Z80
6009 \begin_inset LatexCommand \index{Z80}
6010
6011 \end_inset
6012
6013  family of processors.
6014
6015 \layout List
6016 \labelwidthstring 00.00.0000
6017
6018 \series bold
6019 -mgbz80
6020 \begin_inset LatexCommand \index{-mgbz80}
6021
6022 \end_inset
6023
6024
6025 \series default
6026  Generate code for the GameBoy Z80
6027 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6028
6029 \end_inset
6030
6031  processor (Not actively maintained).
6032
6033 \layout List
6034 \labelwidthstring 00.00.0000
6035
6036 \series bold
6037 -mavr
6038 \begin_inset LatexCommand \index{-mavr}
6039
6040 \end_inset
6041
6042
6043 \series default
6044  Generate code for the Atmel AVR
6045 \begin_inset LatexCommand \index{AVR}
6046
6047 \end_inset
6048
6049  processor (Not maintained, not complete).
6050  AVR users should probably have a look at winavr 
6051 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6052
6053 \end_inset
6054
6055  or 
6056 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6057
6058 \end_inset
6059
6060 .
6061
6062 \layout Standard
6063 \begin_inset Note
6064 collapsed true
6065
6066 \layout Standard
6067 I think it is fair to direct users there for now.
6068  Open source is also about avoiding unnecessary work .
6069  But I didn't find the 'official' link.
6070
6071 \end_inset
6072
6073
6074
6075 \layout List
6076 \labelwidthstring 00.00.0000
6077
6078 \series bold
6079 -mpic14
6080 \begin_inset LatexCommand \index{-mpic14}
6081
6082 \end_inset
6083
6084
6085 \series default
6086  Generate code for the Microchip PIC 14
6087 \begin_inset LatexCommand \index{PIC14}
6088
6089 \end_inset
6090
6091 -bit processors (p16f84 and variants.
6092  In development, not complete).
6093
6094 \layout Standard
6095 \begin_inset Note
6096 collapsed true
6097
6098 \layout Standard
6099 p16f627 p16f628 p16f84 p16f873 p16f877?
6100
6101 \end_inset
6102
6103
6104
6105 \layout List
6106 \labelwidthstring 00.00.0000
6107
6108 \series bold
6109 -mpic16
6110 \begin_inset LatexCommand \index{-mpic16}
6111
6112 \end_inset
6113
6114
6115 \series default
6116  Generate code for the Microchip PIC 16
6117 \begin_inset LatexCommand \index{PIC16}
6118
6119 \end_inset
6120
6121 -bit processors (p18f452 and variants.
6122  In development, not complete).
6123
6124 \layout List
6125 \labelwidthstring 00.00.0000
6126
6127 \series bold
6128 -mtlcs900h
6129 \series default
6130  Generate code for the Toshiba TLCS-900H
6131 \begin_inset LatexCommand \index{TLCS-900H}
6132
6133 \end_inset
6134
6135  processor (Not maintained, not complete).
6136
6137 \layout List
6138 \labelwidthstring 00.00.0000
6139 \added_space_bottom bigskip 
6140
6141 \series bold
6142 -mxa51
6143 \begin_inset LatexCommand \index{-mxa51}
6144
6145 \end_inset
6146
6147
6148 \series default
6149  Generate code for the Phillips XA51
6150 \begin_inset LatexCommand \index{XA51}
6151
6152 \end_inset
6153
6154  processor (Not maintained, not complete).
6155
6156
6157 \layout Subsection
6158 Preprocessor Options
6159 \begin_inset LatexCommand \index{Options preprocessor}
6160
6161 \end_inset
6162
6163
6164 \begin_inset LatexCommand \index{Preprocessor options}
6165
6166 \end_inset
6167
6168
6169 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6170
6171 \end_inset
6172
6173
6174
6175 \layout List
6176 \labelwidthstring 00.00.0000
6177
6178 \series bold
6179 -I<path>
6180 \begin_inset LatexCommand \index{-I<path>}
6181
6182 \end_inset
6183
6184
6185 \series default
6186  The additional location where the pre processor will look for <..h> or 
6187 \begin_inset Quotes eld
6188 \end_inset
6189
6190 ..h
6191 \begin_inset Quotes erd
6192 \end_inset
6193
6194  files.
6195
6196 \layout List
6197 \labelwidthstring 00.00.0000
6198
6199 \series bold
6200 -D<macro[=value]>
6201 \begin_inset LatexCommand \index{-D<macro[=value]>}
6202
6203 \end_inset
6204
6205
6206 \series default
6207  Command line definition of macros.
6208  Passed to the preprocessor.
6209
6210 \layout List
6211 \labelwidthstring 00.00.0000
6212
6213 \series bold
6214 -M
6215 \begin_inset LatexCommand \index{-M}
6216
6217 \end_inset
6218
6219
6220 \series default
6221  Tell the preprocessor to output a rule suitable for make describing the
6222  dependencies of each object file.
6223  For each source file, the preprocessor outputs one make-rule whose target
6224  is the object file name for that source file and whose dependencies are
6225  all the files `#include'd in it.
6226  This rule may be a single line or may be continued with `
6227 \backslash
6228 '-newline if it is long.
6229  The list of rules is printed on standard output instead of the preprocessed
6230  C program.
6231  `-M' implies `-E
6232 \begin_inset LatexCommand \index{-E}
6233
6234 \end_inset
6235
6236 '.
6237
6238 \layout List
6239 \labelwidthstring 00.00.0000
6240
6241 \series bold
6242 -C
6243 \begin_inset LatexCommand \index{-C}
6244
6245 \end_inset
6246
6247
6248 \series default
6249  Tell the preprocessor not to discard comments.
6250  Used with the `-E' option.
6251
6252 \layout List
6253 \labelwidthstring 00.00.0000
6254
6255 \series bold
6256 -MM
6257 \begin_inset LatexCommand \index{-MM}
6258
6259 \end_inset
6260
6261
6262 \size large
6263 \bar under
6264  
6265 \series default
6266 \size default
6267 \bar default
6268 Like `-M' but the output mentions only the user header files included with
6269  `#include 
6270 \begin_inset Quotes eld
6271 \end_inset
6272
6273 file"'.
6274  System header files included with `#include <file>' are omitted.
6275
6276 \layout List
6277 \labelwidthstring 00.00.0000
6278
6279 \series bold
6280 -Aquestion(answer)
6281 \begin_inset LatexCommand \index{-Aquestion(answer)}
6282
6283 \end_inset
6284
6285
6286 \series default
6287  Assert the answer answer for question, in case it is tested with a preprocessor
6288  conditional such as `#if #question(answer)'.
6289  `-A-' disables the standard assertions that normally describe the target
6290  machine.
6291
6292 \layout List
6293 \labelwidthstring 00.00.0000
6294
6295 \series bold
6296 -Umacro
6297 \begin_inset LatexCommand \index{-Umacro}
6298
6299 \end_inset
6300
6301
6302 \series default
6303  Undefine macro macro.
6304  `-U' options are evaluated after all `-D' options, but before any `-include'
6305  and `-imacros' options.
6306
6307 \layout List
6308 \labelwidthstring 00.00.0000
6309
6310 \series bold
6311 -dM
6312 \begin_inset LatexCommand \index{-dM}
6313
6314 \end_inset
6315
6316
6317 \series default
6318  Tell the preprocessor to output only a list of the macro definitions that
6319  are in effect at the end of preprocessing.
6320  Used with the `-E' option.
6321
6322 \layout List
6323 \labelwidthstring 00.00.0000
6324
6325 \series bold
6326 -dD
6327 \begin_inset LatexCommand \index{-dD}
6328
6329 \end_inset
6330
6331
6332 \series default
6333  Tell the preprocessor to pass all macro definitions into the output, in
6334  their proper sequence in the rest of the output.
6335
6336 \layout List
6337 \labelwidthstring 00.00.0000
6338
6339 \series bold
6340 -dN
6341 \begin_inset LatexCommand \index{-dN}
6342
6343 \end_inset
6344
6345
6346 \size large
6347 \bar under
6348  
6349 \series default
6350 \size default
6351 \bar default
6352 Like `-dD' except that the macro arguments and contents are omitted.
6353  Only `#define name' is included in the output.
6354
6355 \layout List
6356 \labelwidthstring 00.00.0000
6357
6358 \series bold
6359 -pedantic-parse-number
6360 \begin_inset LatexCommand \index{-pedantic-parse-number}
6361
6362 \end_inset
6363
6364
6365 \size large
6366 \bar under
6367  
6368 \series default
6369 \size default
6370 \bar default
6371 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6372  and the macro LO_B(3) gets expanded.
6373  See also #pragma pedantic_parse_number in section
6374 \begin_inset LatexCommand \ref{sec:Pragmas}
6375
6376 \end_inset
6377
6378  
6379 \emph on
6380 Note: this functionality is not in conformance with standard!
6381
6382 \layout List
6383 \labelwidthstring 00.00.0000
6384 \added_space_bottom bigskip 
6385
6386 \series bold
6387 -Wp\SpecialChar ~
6388 preprocessorOption[,preprocessorOption]
6389 \series default
6390
6391 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6392
6393 \end_inset
6394
6395 ...
6396  Pass the preprocessorOption to the preprocessor 
6397 \family typewriter
6398 sdcpp
6399 \family default
6400
6401 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6402
6403 \end_inset
6404
6405 .
6406  SDCC uses an adapted version of the preprocessor 
6407 \emph on
6408 cpp
6409 \emph default
6410  of the GNU Compiler Collection
6411 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6412
6413 \end_inset
6414
6415  (
6416 \emph on
6417 gcc
6418 \emph default
6419  
6420 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6421
6422 \end_inset
6423
6424 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6425 4.1.1\SpecialChar ~
6426 CPP\SpecialChar ~
6427 Manual
6428  at 
6429 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6430
6431 \end_inset
6432
6433 .
6434
6435
6436 \layout Subsection
6437 Linker Options
6438 \begin_inset LatexCommand \index{Options linker}
6439
6440 \end_inset
6441
6442
6443 \begin_inset LatexCommand \index{Linker options}
6444
6445 \end_inset
6446
6447
6448
6449 \layout List
6450 \labelwidthstring 00.00.0000
6451
6452 \series bold
6453 -L\SpecialChar ~
6454 -
6455 \series default
6456
6457 \begin_inset ERT
6458 status Collapsed
6459
6460 \layout Standard
6461
6462
6463 \backslash
6464 /
6465
6466 \end_inset
6467
6468
6469 \series bold
6470 -lib-path
6471 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6472
6473 \end_inset
6474
6475
6476 \begin_inset LatexCommand \index{-L -\/-lib-path}
6477
6478 \end_inset
6479
6480
6481 \series default
6482 \SpecialChar ~
6483 <absolute path to additional libraries> This option is passed to the linkage
6484  editor's additional libraries
6485 \begin_inset LatexCommand \index{Libraries}
6486
6487 \end_inset
6488
6489  search path.
6490  The path name must be absolute.
6491  Additional library files may be specified in the command line.
6492  See section Compiling programs for more details.
6493
6494 \layout List
6495 \labelwidthstring 00.00.0000
6496
6497 \series bold
6498 -
6499 \begin_inset ERT
6500 status Collapsed
6501
6502 \layout Standard
6503
6504
6505 \backslash
6506 /
6507
6508 \end_inset
6509
6510 -xram-loc
6511 \series default
6512
6513 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6514
6515 \end_inset
6516
6517 \SpecialChar ~
6518 <Value> The start location of the external ram
6519 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6520
6521 \end_inset
6522
6523 , default value is 0.
6524  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6525 \begin_inset ERT
6526 status Collapsed
6527
6528 \layout Standard
6529
6530
6531 \backslash
6532 /
6533
6534 \end_inset
6535
6536 -xram-loc 0x8000 or -
6537 \begin_inset ERT
6538 status Collapsed
6539
6540 \layout Standard
6541
6542
6543 \backslash
6544 /
6545
6546 \end_inset
6547
6548 -xram-loc 32768.
6549
6550 \layout List
6551 \labelwidthstring 00.00.0000
6552
6553 \series bold
6554 -
6555 \begin_inset ERT
6556 status Collapsed
6557
6558 \layout Standard
6559
6560
6561 \backslash
6562 /
6563
6564 \end_inset
6565
6566 -code-loc
6567 \series default
6568
6569 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6570
6571 \end_inset
6572
6573 \SpecialChar ~
6574 <Value> The start location of the code
6575 \begin_inset LatexCommand \index{code}
6576
6577 \end_inset
6578
6579  segment, default value 0.
6580  Note when this option is used the interrupt vector table
6581 \begin_inset LatexCommand \index{interrupt vector table}
6582
6583 \end_inset
6584
6585  is also relocated to the given address.
6586  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6587 \begin_inset ERT
6588 status Collapsed
6589
6590 \layout Standard
6591
6592
6593 \backslash
6594 /
6595
6596 \end_inset
6597
6598 -code-loc 0x8000 or -
6599 \begin_inset ERT
6600 status Collapsed
6601
6602 \layout Standard
6603
6604
6605 \backslash
6606 /
6607
6608 \end_inset
6609
6610 -code-loc 32768.
6611
6612 \layout List
6613 \labelwidthstring 00.00.0000
6614
6615 \series bold
6616 -
6617 \begin_inset ERT
6618 status Collapsed
6619
6620 \layout Standard
6621
6622
6623 \backslash
6624 /
6625
6626 \end_inset
6627
6628 -stack-loc
6629 \series default
6630
6631 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6632
6633 \end_inset
6634
6635 \SpecialChar ~
6636 <Value> By default the stack
6637 \begin_inset LatexCommand \index{stack}
6638
6639 \end_inset
6640
6641  is placed after the data segment.
6642  Using this option the stack can be placed anywhere in the internal memory
6643  space of the 8051.
6644  The value entered can be in Hexadecimal or Decimal format, e.g.
6645  -
6646 \begin_inset ERT
6647 status Collapsed
6648
6649 \layout Standard
6650
6651
6652 \backslash
6653 /
6654
6655 \end_inset
6656
6657 -stack-loc 0x20 or -
6658 \begin_inset ERT
6659 status Collapsed
6660
6661 \layout Standard
6662
6663
6664 \backslash
6665 /
6666
6667 \end_inset
6668
6669 -stack-loc 32.
6670  Since the sp register is incremented before a push or call, the initial
6671  sp will be set to one byte prior the provided value.
6672  The provided value should not overlap any other memory areas such as used
6673  register banks or the data segment and with enough space for the current
6674  application.
6675  The 
6676 \series bold
6677 -
6678 \begin_inset ERT
6679 status Collapsed
6680
6681 \layout Standard
6682
6683
6684 \backslash
6685 /
6686
6687 \end_inset
6688
6689 -pack-iram
6690 \series default
6691 \SpecialChar ~
6692
6693 \begin_inset LatexCommand \index{-\/-pack-iram}
6694
6695 \end_inset
6696
6697  option (which is now a default setting) will override this setting, so
6698  you should also specify the 
6699 \series bold
6700 -
6701 \begin_inset ERT
6702 status Collapsed
6703
6704 \layout Standard
6705
6706
6707 \backslash
6708 /
6709
6710 \end_inset
6711
6712 -no-pack-iram
6713 \series default
6714 \SpecialChar ~
6715
6716 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6717
6718 \end_inset
6719
6720  option if you need to manually place the stack.
6721
6722 \layout List
6723 \labelwidthstring 00.00.0000
6724
6725 \series bold
6726 -
6727 \begin_inset ERT
6728 status Collapsed
6729
6730 \layout Standard
6731
6732
6733 \backslash
6734 /
6735
6736 \end_inset
6737
6738 -xstack-loc
6739 \series default
6740
6741 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6742
6743 \end_inset
6744
6745 \SpecialChar ~
6746 <Value> By default the external stack
6747 \begin_inset LatexCommand \index{xstack}
6748
6749 \end_inset
6750
6751  is placed after the pdata
6752 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6753
6754 \end_inset
6755
6756  segment.
6757  Using this option the xstack can be placed anywhere in the external memory
6758  space of the 8051.
6759  The value entered can be in Hexadecimal or Decimal format, e.g.
6760  -
6761 \begin_inset ERT
6762 status Collapsed
6763
6764 \layout Standard
6765
6766
6767 \backslash
6768 /
6769
6770 \end_inset
6771
6772 -xstack-loc 0x8000 or -
6773 \begin_inset ERT
6774 status Collapsed
6775
6776 \layout Standard
6777
6778
6779 \backslash
6780 /
6781
6782 \end_inset
6783
6784 -stack-loc 32768.
6785  The provided value should not overlap any other memory areas such as the
6786  pdata or xdata segment and with enough space for the current application.
6787
6788 \layout List
6789 \labelwidthstring 00.00.0000
6790
6791 \series bold
6792 -
6793 \begin_inset ERT
6794 status Collapsed
6795
6796 \layout Standard
6797
6798
6799 \backslash
6800 /
6801
6802 \end_inset
6803
6804 -data-loc
6805 \series default
6806
6807 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6808
6809 \end_inset
6810
6811 \SpecialChar ~
6812 <Value> The start location of the internal ram data
6813 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6814
6815 \end_inset
6816
6817  segment.
6818  The value entered can be in Hexadecimal or Decimal format, eg.
6819  -
6820 \begin_inset ERT
6821 status Collapsed
6822
6823 \layout Standard
6824
6825
6826 \backslash
6827 /
6828
6829 \end_inset
6830
6831 -data-loc 0x20 or -
6832 \begin_inset ERT
6833 status Collapsed
6834
6835 \layout Standard
6836
6837
6838 \backslash
6839 /
6840
6841 \end_inset
6842
6843 -data-loc 32.
6844  (By default, the start location of the internal ram data segment  is set
6845  as low as possible in memory, taking into account the used register banks
6846  and the bit segment at address 0x20.
6847  For example if register banks 0 and 1 are used without bit variables, the
6848  data segment will be set, if -
6849 \begin_inset ERT
6850 status Collapsed
6851
6852 \layout Standard
6853
6854
6855 \backslash
6856 /
6857
6858 \end_inset
6859
6860 -data-loc is not used, to location 0x10.)
6861
6862 \layout List
6863 \labelwidthstring 00.00.0000
6864
6865 \series bold
6866 -
6867 \begin_inset ERT
6868 status Collapsed
6869
6870 \layout Standard
6871
6872
6873 \backslash
6874 /
6875
6876 \end_inset
6877
6878 -idata-loc
6879 \series default
6880
6881 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6882
6883 \end_inset
6884
6885 \SpecialChar ~
6886 <Value> The start location of the indirectly addressable internal ram
6887 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6888
6889 \end_inset
6890
6891  of the 8051, default value is 0x80.
6892  The value entered can be in Hexadecimal or Decimal format, eg.
6893  -
6894 \begin_inset ERT
6895 status Collapsed
6896
6897 \layout Standard
6898
6899
6900 \backslash
6901 /
6902
6903 \end_inset
6904
6905 -idata-loc 0x88 or -
6906 \begin_inset ERT
6907 status Collapsed
6908
6909 \layout Standard
6910
6911
6912 \backslash
6913 /
6914
6915 \end_inset
6916
6917 -idata-loc 136.
6918
6919 \layout List
6920 \labelwidthstring 00.00.0000
6921
6922 \series bold
6923 -
6924 \begin_inset ERT
6925 status Collapsed
6926
6927 \layout Standard
6928
6929
6930 \backslash
6931 /
6932
6933 \end_inset
6934
6935 -bit-loc
6936 \series default
6937 \SpecialChar ~
6938 <Value> The start location of the bit
6939 \begin_inset LatexCommand \index{bit}
6940
6941 \end_inset
6942
6943  addressable internal ram of the 8051.
6944  This is 
6945 \emph on
6946 not
6947 \emph default
6948  implemented yet.
6949  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6950 -bBSEG=<Value>.
6951
6952 \layout List
6953 \labelwidthstring 00.00.0000
6954
6955 \series bold
6956 -
6957 \begin_inset ERT
6958 status Collapsed
6959
6960 \layout Standard
6961
6962
6963 \backslash
6964 /
6965
6966 \end_inset
6967
6968 -out-fmt-ihx
6969 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6970
6971 \end_inset
6972
6973
6974 \bar under
6975  
6976 \series default
6977 \bar default
6978 The linker output (final object code) is in Intel Hex format.
6979 \begin_inset LatexCommand \index{Intel hex format}
6980
6981 \end_inset
6982
6983  This is the default option.
6984  The format itself is documented in the documentation of srecord
6985 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6986
6987 \end_inset
6988
6989 .
6990
6991 \layout List
6992 \labelwidthstring 00.00.0000
6993
6994 \series bold
6995 -
6996 \begin_inset ERT
6997 status Collapsed
6998
6999 \layout Standard
7000
7001
7002 \backslash
7003 /
7004
7005 \end_inset
7006
7007 -out-fmt-s19
7008 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7009
7010 \end_inset
7011
7012
7013 \bar under
7014  
7015 \series default
7016 \bar default
7017 The linker output (final object code) is in Motorola S19 format
7018 \begin_inset LatexCommand \index{Motorola S19 format}
7019
7020 \end_inset
7021
7022 .
7023  The format itself is documented in the documentation of srecord.
7024
7025 \layout List
7026 \labelwidthstring 00.00.0000
7027
7028 \series bold
7029 -
7030 \begin_inset ERT
7031 status Collapsed
7032
7033 \layout Standard
7034
7035
7036 \backslash
7037 /
7038
7039 \end_inset
7040
7041 -out-fmt-elf
7042 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7043
7044 \end_inset
7045
7046
7047 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7048
7049 \end_inset
7050
7051
7052 \bar under
7053  
7054 \series default
7055 \bar default
7056 The linker output (final object code) is in ELF format
7057 \begin_inset LatexCommand \index{ELF format}
7058
7059 \end_inset
7060
7061 .
7062  (Currently only supported for the HC08
7063 \begin_inset LatexCommand \index{HC08}
7064
7065 \end_inset
7066
7067  processors)
7068
7069 \layout List
7070 \labelwidthstring 00.00.0000
7071 \added_space_bottom bigskip 
7072
7073 \series bold
7074 -Wl\SpecialChar ~
7075 linkOption[,linkOption]
7076 \series default
7077
7078 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7079
7080 \end_inset
7081
7082 ...
7083  Pass the linkOption to the linker.
7084  If a bootloader is used an option like 
7085 \begin_inset Quotes sld
7086 \end_inset
7087
7088 -Wl\SpecialChar ~
7089 -bCSEG=0x1000
7090 \begin_inset Quotes srd
7091 \end_inset
7092
7093  would be typical to set the start of the code segment.
7094  See also #pragma constseg and #pragma codeseg in section 
7095 \begin_inset LatexCommand \ref{sec:Pragmas}
7096
7097 \end_inset
7098
7099  .
7100  File sdcc/as/doc/asxhtm.html has more on linker options.
7101
7102
7103 \layout Subsection
7104 MCS51 Options
7105 \begin_inset LatexCommand \index{Options MCS51}
7106
7107 \end_inset
7108
7109
7110 \begin_inset LatexCommand \index{MCS51 options}
7111
7112 \end_inset
7113
7114
7115
7116 \layout List
7117 \labelwidthstring 00.00.0000
7118
7119 \series bold
7120 -
7121 \begin_inset ERT
7122 status Collapsed
7123
7124 \layout Standard
7125
7126
7127 \backslash
7128 /
7129
7130 \end_inset
7131
7132 -model-small
7133 \begin_inset LatexCommand \index{-\/-model-small}
7134
7135 \end_inset
7136
7137
7138 \series default
7139 \size large
7140 \emph on
7141  
7142 \size default
7143 \emph default
7144 Generate code for Small Model programs, see section Memory Models for more
7145  details.
7146  This is the default model.
7147
7148 \layout List
7149 \labelwidthstring 00.00.0000
7150
7151 \series bold
7152 -
7153 \begin_inset ERT
7154 status Collapsed
7155
7156 \layout Standard
7157
7158
7159 \backslash
7160 /
7161
7162 \end_inset
7163
7164 -model-medium
7165 \begin_inset LatexCommand \index{-\/-model-medium}
7166
7167 \end_inset
7168
7169
7170 \series default
7171  Generate code for Medium model programs, see section Memory Models for
7172  more details.
7173  If this option is used all source files in the project have to be compiled
7174  with this option.
7175  It must also be used when invoking the linker.
7176
7177 \layout List
7178 \labelwidthstring 00.00.0000
7179
7180 \series bold
7181 -
7182 \begin_inset ERT
7183 status Collapsed
7184
7185 \layout Standard
7186
7187
7188 \backslash
7189 /
7190
7191 \end_inset
7192
7193 -model-large
7194 \begin_inset LatexCommand \index{-\/-model-large}
7195
7196 \end_inset
7197
7198
7199 \series default
7200  Generate code for Large model programs, see section Memory Models for more
7201  details.
7202  If this option is used all source files in the project have to be compiled
7203  with this option.
7204  It must also be used when invoking the linker.
7205
7206 \layout List
7207 \labelwidthstring 00.00.0000
7208
7209 \series bold
7210 -
7211 \begin_inset ERT
7212 status Collapsed
7213
7214 \layout Standard
7215
7216
7217 \backslash
7218 /
7219
7220 \end_inset
7221
7222 -xstack
7223 \begin_inset LatexCommand \index{-\/-xstack}
7224
7225 \end_inset
7226
7227
7228 \series default
7229  Uses a pseudo stack in the pdata
7230 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7231
7232 \end_inset
7233
7234  area (usually the first 256 bytes in the external ram) for allocating variables
7235  and passing parameters.
7236  See section 
7237 \begin_inset LatexCommand \ref{sub:External-Stack}
7238
7239 \end_inset
7240
7241 \SpecialChar ~
7242  External Stack for more details.
7243
7244 \layout List
7245 \labelwidthstring 00.00.0000
7246
7247 \series bold
7248 -
7249 \begin_inset ERT
7250 status Collapsed
7251
7252 \layout Standard
7253
7254
7255 \backslash
7256 /
7257
7258 \end_inset
7259
7260 -iram-size
7261 \series default
7262 \SpecialChar ~
7263 <Value>
7264 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7265
7266 \end_inset
7267
7268  Causes the linker to check if the internal ram usage is within limits of
7269  the given value.
7270
7271 \layout List
7272 \labelwidthstring 00.00.0000
7273
7274 \series bold
7275 -
7276 \begin_inset ERT
7277 status Collapsed
7278
7279 \layout Standard
7280
7281
7282 \backslash
7283 /
7284
7285 \end_inset
7286
7287 -xram-size
7288 \series default
7289 \SpecialChar ~
7290 <Value>
7291 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7292
7293 \end_inset
7294
7295  Causes the linker to check if the external ram usage is within limits of
7296  the given value.
7297
7298 \layout List
7299 \labelwidthstring 00.00.0000
7300
7301 \series bold
7302 -
7303 \begin_inset ERT
7304 status Collapsed
7305
7306 \layout Standard
7307
7308
7309 \backslash
7310 /
7311
7312 \end_inset
7313
7314 -code-size
7315 \series default
7316 \SpecialChar ~
7317 <Value>
7318 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7319
7320 \end_inset
7321
7322  Causes the linker to check if the code memory usage is within limits of
7323  the given value.
7324
7325 \layout List
7326 \labelwidthstring 00.00.0000
7327
7328 \series bold
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335
7336 \backslash
7337 /
7338
7339 \end_inset
7340
7341 -stack-size
7342 \series default
7343 \SpecialChar ~
7344 <Value>
7345 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7346
7347 \end_inset
7348
7349  Causes the linker to check if there is at minimum <Value> bytes for stack.
7350
7351 \layout List
7352 \labelwidthstring 00.00.0000
7353
7354 \series bold
7355 -
7356 \begin_inset ERT
7357 status Collapsed
7358
7359 \layout Standard
7360
7361
7362 \backslash
7363 /
7364
7365 \end_inset
7366
7367 -pack-iram
7368 \series default
7369 \SpecialChar ~
7370
7371 \begin_inset LatexCommand \index{-\/-pack-iram}
7372
7373 \end_inset
7374
7375  Causes the linker to use unused register banks for data variables and pack
7376  data, idata and stack together.
7377  This is the default now.
7378
7379 \layout List
7380 \labelwidthstring 00.00.0000
7381 \added_space_bottom bigskip 
7382
7383 \series bold
7384 -
7385 \begin_inset ERT
7386 status Collapsed
7387
7388 \layout Standard
7389
7390
7391 \backslash
7392 /
7393
7394 \end_inset
7395
7396 -no-pack-iram
7397 \series default
7398 \SpecialChar ~
7399
7400 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7401
7402 \end_inset
7403
7404  Causes the linker to use old style for allocating memory areas.
7405
7406
7407 \layout Subsection
7408 DS390 / DS400 Options
7409 \begin_inset LatexCommand \index{Options DS390}
7410
7411 \end_inset
7412
7413
7414 \begin_inset LatexCommand \index{DS390}
7415
7416 \end_inset
7417
7418
7419
7420 \layout List
7421 \labelwidthstring 00.00.0000
7422
7423 \series bold
7424 -
7425 \begin_inset ERT
7426 status Collapsed
7427
7428 \layout Standard
7429
7430
7431 \backslash
7432 /
7433
7434 \end_inset
7435
7436 -model-flat24
7437 \series default
7438
7439 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7440
7441 \end_inset
7442
7443
7444 \size large
7445 \emph on
7446  
7447 \size default
7448 \emph default
7449 Generate 24-bit flat mode code.
7450  This is the one and only that the ds390 code generator supports right now
7451  and is default when using 
7452 \emph on
7453 -mds390
7454 \emph default
7455 .
7456  See section Memory Models for more details.
7457
7458 \layout List
7459 \labelwidthstring 00.00.0000
7460
7461 \series bold
7462 -
7463 \begin_inset ERT
7464 status Collapsed
7465
7466 \layout Standard
7467
7468
7469 \backslash
7470 /
7471
7472 \end_inset
7473
7474 -protect-sp-update
7475 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7476
7477 \end_inset
7478
7479
7480 \series default
7481  disable interrupts during ESP:SP updates.
7482
7483 \layout List
7484 \labelwidthstring 00.00.0000
7485
7486 \series bold
7487 -
7488 \begin_inset ERT
7489 status Collapsed
7490
7491 \layout Standard
7492
7493
7494 \backslash
7495 /
7496
7497 \end_inset
7498
7499 -stack-10bit
7500 \series default
7501
7502 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7503
7504 \end_inset
7505
7506  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7507  This is the one and only that the ds390 code generator supports right now
7508  and is default when using 
7509 \emph on
7510 -mds390
7511 \emph default
7512 .
7513  In this mode, the stack is located in the lower 1K of the internal RAM,
7514  which is mapped to 0x400000.
7515  Note that the support is incomplete, since it still uses a single byte
7516  as the stack pointer.
7517  This means that only the lower 256 bytes of the potential 1K stack space
7518  will actually be used.
7519  However, this does allow you to reclaim the precious 256 bytes of low RAM
7520  for use for the DATA and IDATA segments.
7521  The compiler will not generate any code to put the processor into 10 bit
7522  stack mode.
7523  It is important to ensure that the processor is in this mode before calling
7524  any re-entrant functions compiled with this option.
7525  In principle, this should work with the 
7526 \emph on
7527 -
7528 \begin_inset ERT
7529 status Collapsed
7530
7531 \layout Standard
7532
7533
7534 \backslash
7535 /
7536
7537 \end_inset
7538
7539 -stack-auto
7540 \begin_inset LatexCommand \index{-\/-stack-auto}
7541
7542 \end_inset
7543
7544
7545 \emph default
7546  option, but that has not been tested.
7547  It is incompatible with the 
7548 \emph on
7549 -
7550 \begin_inset ERT
7551 status Collapsed
7552
7553 \layout Standard
7554
7555
7556 \backslash
7557 /
7558
7559 \end_inset
7560
7561 -xstack
7562 \begin_inset LatexCommand \index{-\/-xstack}
7563
7564 \end_inset
7565
7566
7567 \emph default
7568  option.
7569  It also only makes sense if the processor is in 24 bit contiguous addressing
7570  mode (see the 
7571 \emph on
7572 -
7573 \begin_inset ERT
7574 status Collapsed
7575
7576 \layout Standard
7577
7578
7579 \backslash
7580 /
7581
7582 \end_inset
7583
7584 -model-flat24 option
7585 \emph default
7586 ).
7587
7588 \layout List
7589 \labelwidthstring 00.00.0000
7590
7591 \series bold
7592 -
7593 \begin_inset ERT
7594 status Collapsed
7595
7596 \layout Standard
7597
7598
7599 \backslash
7600 /
7601
7602 \end_inset
7603
7604 -stack-probe
7605 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7606
7607 \end_inset
7608
7609
7610 \series default
7611  insert call to function __stack_probe at each function prologue.
7612
7613 \layout List
7614 \labelwidthstring 00.00.0000
7615
7616 \series bold
7617 -
7618 \begin_inset ERT
7619 status Collapsed
7620
7621 \layout Standard
7622
7623
7624 \backslash
7625 /
7626
7627 \end_inset
7628
7629 -tini-libid
7630 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7631
7632 \end_inset
7633
7634
7635 \series default
7636  <nnnn> LibraryID used in -mTININative.
7637  
7638
7639 \layout List
7640 \labelwidthstring 00.00.0000
7641 \added_space_bottom bigskip 
7642
7643 \series bold
7644 -
7645 \begin_inset ERT
7646 status Collapsed
7647
7648 \layout Standard
7649
7650
7651 \backslash
7652 /
7653
7654 \end_inset
7655
7656 -use-accelerator
7657 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7658
7659 \end_inset
7660
7661
7662 \series default
7663  generate code for DS390 Arithmetic Accelerator.
7664  
7665
7666
7667 \layout Subsection
7668 Z80 Options
7669 \begin_inset LatexCommand \index{Options Z80}
7670
7671 \end_inset
7672
7673
7674 \begin_inset LatexCommand \index{Z80}
7675
7676 \end_inset
7677
7678
7679
7680 \layout List
7681 \labelwidthstring 00.00.0000
7682
7683 \series bold
7684 -
7685 \begin_inset ERT
7686 status Collapsed
7687
7688 \layout Standard
7689
7690
7691 \backslash
7692 /
7693
7694 \end_inset
7695
7696 -callee-saves-bc
7697 \series default
7698
7699 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7700
7701 \end_inset
7702
7703
7704 \size large
7705 \emph on
7706  
7707 \size default
7708 \emph default
7709 Force a called function to always save BC.
7710
7711 \layout List
7712 \labelwidthstring 00.00.0000
7713 \added_space_bottom bigskip 
7714
7715 \series bold
7716 -
7717 \begin_inset ERT
7718 status Collapsed
7719
7720 \layout Standard
7721
7722
7723 \backslash
7724 /
7725
7726 \end_inset
7727
7728 -no-std-crt0
7729 \series default
7730
7731 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7732
7733 \end_inset
7734
7735  When linking, skip the standard crt0.o object file.
7736  You must provide your own crt0.o for your system when linking.
7737  
7738
7739
7740 \layout Subsection
7741 Optimization Options
7742 \begin_inset LatexCommand \index{Options optimization}
7743
7744 \end_inset
7745
7746
7747 \begin_inset LatexCommand \index{Optimization options}
7748
7749 \end_inset
7750
7751
7752
7753 \layout List
7754 \labelwidthstring 00.00.0000
7755
7756 \series bold
7757 -
7758 \begin_inset ERT
7759 status Collapsed
7760
7761 \layout Standard
7762
7763
7764 \backslash
7765 /
7766
7767 \end_inset
7768
7769 -nogcse
7770 \begin_inset LatexCommand \index{-\/-nogcse}
7771
7772 \end_inset
7773
7774
7775 \series default
7776  Will not do global subexpression elimination, this option may be used when
7777  the compiler creates undesirably large stack/data spaces to store compiler
7778  temporaries (
7779 \emph on
7780 s
7781 \emph default
7782 pill 
7783 \emph on
7784 loc
7785 \emph default
7786 ations, sloc
7787 \begin_inset LatexCommand \index{sloc (spill location)}
7788
7789 \end_inset
7790
7791 ).
7792  A warning message will be generated when this happens and the compiler
7793  will indicate the number of extra bytes it allocated.
7794  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7795 nogcse
7796 \begin_inset LatexCommand \index{\#pragma nogcse}
7797
7798 \end_inset
7799
7800  can be used to turn off global subexpression elimination
7801 \begin_inset LatexCommand \index{Subexpression elimination}
7802
7803 \end_inset
7804
7805  for a given function only.
7806
7807 \layout List
7808 \labelwidthstring 00.00.0000
7809
7810 \series bold
7811 -
7812 \begin_inset ERT
7813 status Collapsed
7814
7815 \layout Standard
7816
7817
7818 \backslash
7819 /
7820
7821 \end_inset
7822
7823 -noinvariant
7824 \begin_inset LatexCommand \index{-\/-noinvariant}
7825
7826 \end_inset
7827
7828
7829 \series default
7830  Will not do loop invariant optimizations, this may be turned off for reasons
7831  explained for the previous option.
7832  For more details of loop optimizations performed see Loop Invariants in
7833  section 
7834 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7835
7836 \end_inset
7837
7838 .
7839  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7840 noinvariant
7841 \begin_inset LatexCommand \index{\#pragma noinvariant}
7842
7843 \end_inset
7844
7845  can be used to turn off invariant optimizations for a given function only.
7846
7847 \layout List
7848 \labelwidthstring 00.00.0000
7849
7850 \series bold
7851 -
7852 \begin_inset ERT
7853 status Collapsed
7854
7855 \layout Standard
7856
7857
7858 \backslash
7859 /
7860
7861 \end_inset
7862
7863 -noinduction
7864 \begin_inset LatexCommand \index{-\/-noinduction}
7865
7866 \end_inset
7867
7868
7869 \series default
7870  Will not do loop induction optimizations, see section strength reduction
7871  for more details.
7872  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7873 noinduction
7874 \begin_inset LatexCommand \index{\#pragma noinduction}
7875
7876 \end_inset
7877
7878  can be used to turn off induction optimizations for a given function only.
7879
7880 \layout List
7881 \labelwidthstring 00.00.0000
7882
7883 \series bold
7884 -
7885 \begin_inset ERT
7886 status Collapsed
7887
7888 \layout Standard
7889
7890
7891 \backslash
7892 /
7893
7894 \end_inset
7895
7896 -nojtbound
7897 \begin_inset LatexCommand \index{-\/-nojtbound}
7898
7899 \end_inset
7900
7901
7902 \size large
7903 \bar under
7904  
7905 \series default
7906 \size default
7907 \bar default
7908  Will not generate boundary condition check when switch statements
7909 \begin_inset LatexCommand \index{switch statement}
7910
7911 \end_inset
7912
7913  are implemented using jump-tables.
7914  See section 
7915 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7916
7917 \end_inset
7918
7919 \SpecialChar ~
7920 Switch Statements for more details.
7921  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7922 nojtbound
7923 \begin_inset LatexCommand \index{\#pragma nojtbound}
7924
7925 \end_inset
7926
7927  can be used to turn off boundary checking for jump tables for a given function
7928  only.
7929
7930 \layout List
7931 \labelwidthstring 00.00.0000
7932
7933 \series bold
7934 -
7935 \begin_inset ERT
7936 status Collapsed
7937
7938 \layout Standard
7939
7940
7941 \backslash
7942 /
7943
7944 \end_inset
7945
7946 -noloopreverse
7947 \begin_inset LatexCommand \index{-\/-noloopreverse}
7948
7949 \end_inset
7950
7951
7952 \series default
7953 \size large
7954  
7955 \size default
7956 Will not do loop reversal 
7957 \begin_inset LatexCommand \index{Loop reversing}
7958
7959 \end_inset
7960
7961 optimization.
7962
7963 \layout List
7964 \labelwidthstring 00.00.0000
7965 -
7966 \begin_inset ERT
7967 status Collapsed
7968
7969 \layout Standard
7970
7971
7972 \backslash
7973 /
7974
7975 \end_inset
7976
7977 -
7978 \series bold
7979 nolabelopt
7980 \series default
7981  
7982 \begin_inset LatexCommand \index{-\/-nolabelopt }
7983
7984 \end_inset
7985
7986 Will not optimize labels (makes the dumpfiles more readable).
7987
7988 \layout List
7989 \labelwidthstring 00.00.0000
7990
7991 \series bold
7992 -
7993 \begin_inset ERT
7994 status Collapsed
7995
7996 \layout Standard
7997
7998
7999 \backslash
8000 /
8001
8002 \end_inset
8003
8004 -no-xinit-opt
8005 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8006
8007 \end_inset
8008
8009
8010 \series default
8011  Will not memcpy initialized data from code space into xdata space.
8012  This saves a few bytes in code space if you don't have initialized data
8013 \begin_inset LatexCommand \index{Variable initialization}
8014
8015 \end_inset
8016
8017 .
8018
8019 \layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -
8024 \begin_inset ERT
8025 status Collapsed
8026
8027 \layout Standard
8028
8029
8030 \backslash
8031 /
8032
8033 \end_inset
8034
8035 -nooverlay
8036 \begin_inset LatexCommand \index{-\/-nooverlay}
8037
8038 \end_inset
8039
8040
8041 \series default
8042   The compiler will not overlay parameters and local variables of any function,
8043  see section Parameters and local variables for more details.
8044
8045 \layout List
8046 \labelwidthstring 00.00.0000
8047
8048 \series bold
8049 -
8050 \begin_inset ERT
8051 status Collapsed
8052
8053 \layout Standard
8054
8055
8056 \backslash
8057 /
8058
8059 \end_inset
8060
8061 -no-peep
8062 \begin_inset LatexCommand \index{-\/-no-peep}
8063
8064 \end_inset
8065
8066
8067 \series default
8068  Disable peep-hole optimization with built-in rules.
8069
8070 \layout List
8071 \labelwidthstring 00.00.0000
8072
8073 \series bold
8074 -
8075 \begin_inset ERT
8076 status Collapsed
8077
8078 \layout Standard
8079
8080
8081 \backslash
8082 /
8083
8084 \end_inset
8085
8086 -peep-file
8087 \series default
8088
8089 \begin_inset LatexCommand \index{-\/-peep-file}
8090
8091 \end_inset
8092
8093 \SpecialChar ~
8094 <filename> This option can be used to use additional rules to be used by
8095  the peep hole optimizer.
8096  See section 
8097 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8098
8099 \end_inset
8100
8101 \SpecialChar ~
8102 Peep Hole optimizations for details on how to write these rules.
8103
8104 \layout List
8105 \labelwidthstring 00.00.0000
8106
8107 \series bold
8108 -
8109 \begin_inset ERT
8110 status Collapsed
8111
8112 \layout Standard
8113
8114
8115 \backslash
8116 /
8117
8118 \end_inset
8119
8120 -peep-asm
8121 \begin_inset LatexCommand \index{-\/-peep-asm}
8122
8123 \end_inset
8124
8125
8126 \series default
8127  Pass the inline assembler code through the peep hole optimizer.
8128  This can cause unexpected changes to inline assembler code, please go through
8129  the peephole optimizer
8130 \begin_inset LatexCommand \index{Peephole optimizer}
8131
8132 \end_inset
8133
8134  rules defined in the source file tree '<target>/peeph.def' before using
8135  this option.
8136
8137 \layout List
8138 \labelwidthstring 00.00.0000
8139
8140 \series bold
8141 -
8142 \begin_inset ERT
8143 status Collapsed
8144
8145 \layout Standard
8146
8147
8148 \backslash
8149 /
8150
8151 \end_inset
8152
8153 -opt-code-speed
8154 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8155
8156 \end_inset
8157
8158
8159 \series default
8160  The compiler will optimize code generation towards fast code, possibly
8161  at the expense of code size.
8162
8163 \layout List
8164 \labelwidthstring 00.00.0000
8165 \added_space_bottom bigskip 
8166
8167 \series bold
8168 -
8169 \begin_inset ERT
8170 status Collapsed
8171
8172 \layout Standard
8173
8174
8175 \backslash
8176 /
8177
8178 \end_inset
8179
8180 -opt-code-size
8181 \begin_inset LatexCommand \index{-\/-opt-code-size}
8182
8183 \end_inset
8184
8185
8186 \series default
8187  The compiler will optimize code generation towards compact code, possibly
8188  at the expense of code speed.
8189
8190
8191 \layout Subsection
8192 Other Options
8193 \begin_inset LatexCommand \index{Options other}
8194
8195 \end_inset
8196
8197
8198
8199 \layout List
8200 \labelwidthstring 00.00.0000
8201
8202 \series bold
8203 -c\SpecialChar ~
8204 -
8205 \begin_inset ERT
8206 status Collapsed
8207
8208 \layout Standard
8209
8210
8211 \backslash
8212 /
8213
8214 \end_inset
8215
8216 -compile-only
8217 \begin_inset LatexCommand \index{-\/-compile-only}
8218
8219 \end_inset
8220
8221
8222 \begin_inset LatexCommand \index{-c -\/-compile-only}
8223
8224 \end_inset
8225
8226
8227 \series default
8228  will compile and assemble the source, but will not call the linkage editor.
8229
8230 \layout List
8231 \labelwidthstring 00.00.0000
8232
8233 \series bold
8234 -
8235 \series default
8236
8237 \begin_inset ERT
8238 status Collapsed
8239
8240 \layout Standard
8241
8242
8243 \backslash
8244 /
8245
8246 \end_inset
8247
8248
8249 \series bold
8250 -c1mode
8251 \begin_inset LatexCommand \index{-\/-c1mode}
8252
8253 \end_inset
8254
8255
8256 \series default
8257  reads the preprocessed source from standard input and compiles it.
8258  The file name for the assembler output must be specified using the -o option.
8259
8260 \layout List
8261 \labelwidthstring 00.00.0000
8262
8263 \series bold
8264 -E
8265 \begin_inset LatexCommand \index{-E}
8266
8267 \end_inset
8268
8269
8270 \series default
8271  Run only the C preprocessor.
8272  Preprocess all the C source files specified and output the results to standard
8273  output.
8274
8275 \layout List
8276 \labelwidthstring 00.00.0000
8277
8278 \series bold
8279 -o\SpecialChar ~
8280 <path/file>
8281 \begin_inset LatexCommand \index{-o <path/file>}
8282
8283 \end_inset
8284
8285  
8286 \series default
8287 The output path resp.
8288  file where everything will be placed.
8289  If the parameter is a path, it must have a trailing slash (or backslash
8290  for the Windows binaries) to be recognized as a path.
8291  
8292
8293 \layout List
8294 \labelwidthstring 00.00.0000
8295
8296 \series bold
8297 -
8298 \begin_inset ERT
8299 status Collapsed
8300
8301 \layout Standard
8302
8303
8304 \backslash
8305 /
8306
8307 \end_inset
8308
8309 -stack-auto
8310 \begin_inset LatexCommand \index{-\/-stack-auto}
8311
8312 \end_inset
8313
8314
8315 \series default
8316 \size large
8317 \emph on
8318  
8319 \size default
8320 \emph default
8321 All functions in the source file will be compiled as 
8322 \emph on
8323 reentrant
8324 \emph default
8325
8326 \begin_inset LatexCommand \index{reentrant}
8327
8328 \end_inset
8329
8330 , i.e.
8331  the parameters and local variables will be allocated on the stack
8332 \begin_inset LatexCommand \index{stack}
8333
8334 \end_inset
8335
8336 .
8337  See section 
8338 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8339
8340 \end_inset
8341
8342  Parameters and Local Variables for more details.
8343  If this option is used all source files in the project should be compiled
8344  with this option.
8345  It automatically implies --int-long-reent and --float-reent.
8346  
8347
8348 \layout List
8349 \labelwidthstring 00.00.0000
8350
8351 \series bold
8352 -
8353 \begin_inset ERT
8354 status Collapsed
8355
8356 \layout Standard
8357
8358
8359 \backslash
8360 /
8361
8362 \end_inset
8363
8364 -callee-saves
8365 \begin_inset LatexCommand \index{-\/-callee-saves}
8366
8367 \end_inset
8368
8369  function1[,function2][,function3]....
8370
8371 \series default
8372  The compiler by default uses a caller saves convention for register saving
8373  across function calls, however this can cause unnecessary register pushing
8374  & popping when calling small functions from larger functions.
8375  This option can be used to switch the register saving convention for the
8376  function names specified.
8377  The compiler will not save registers when calling these functions, no extra
8378  code will be generated at the entry & exit (function prologue
8379 \series bold
8380
8381 \begin_inset LatexCommand \index{function prologue}
8382
8383 \end_inset
8384
8385
8386 \series default
8387  & epilogue
8388 \series bold
8389
8390 \begin_inset LatexCommand \index{function epilogue}
8391
8392 \end_inset
8393
8394
8395 \series default
8396 ) for these functions to save & restore the registers used by these functions,
8397  this can SUBSTANTIALLY reduce code & improve run time performance of the
8398  generated code.
8399  In the future the compiler (with inter procedural analysis) will be able
8400  to determine the appropriate scheme to use for each function call.
8401  DO NOT use this option for built-in functions such as _mulint..., if this
8402  option is used for a library function the appropriate library function
8403  needs to be recompiled with the same option.
8404  If the project consists of multiple source files then all the source file
8405  should be compiled with the same -
8406 \begin_inset ERT
8407 status Collapsed
8408
8409 \layout Standard
8410
8411
8412 \backslash
8413 /
8414
8415 \end_inset
8416
8417 -callee-saves option string.
8418  Also see #pragma\SpecialChar ~
8419 callee_saves
8420 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8421
8422 \end_inset
8423
8424 .
8425
8426 \layout List
8427 \labelwidthstring 00.00.0000
8428
8429 \series bold
8430 -
8431 \begin_inset ERT
8432 status Collapsed
8433
8434 \layout Standard
8435
8436
8437 \backslash
8438 /
8439
8440 \end_inset
8441
8442 -debug
8443 \begin_inset LatexCommand \index{-\/-debug}
8444
8445 \end_inset
8446
8447
8448 \bar under
8449  
8450 \series default
8451 \bar default
8452 When this option is used the compiler will generate debug information.
8453  The debug information collected in a file with .cdb extension can be used
8454  with the SDCDB.
8455  For more information see documentation for SDCDB.
8456  Another file with no extension contains debug information in AOMF or AOMF51
8457 \begin_inset LatexCommand \index{AOMF, AOMF51}
8458
8459 \end_inset
8460
8461  format which is commonly used by third party tools.
8462
8463 \layout List
8464 \labelwidthstring 00.00.0000
8465
8466 \series bold
8467 -S
8468 \begin_inset LatexCommand \index{-S}
8469
8470 \end_inset
8471
8472
8473 \size large
8474 \bar under
8475  
8476 \series default
8477 \size default
8478 \bar default
8479 Stop after the stage of compilation proper; do not assemble.
8480  The output is an assembler code file for the input file specified.
8481
8482 \layout List
8483 \labelwidthstring 00.00.0000
8484
8485 \series bold
8486 -
8487 \begin_inset ERT
8488 status Collapsed
8489
8490 \layout Standard
8491
8492
8493 \backslash
8494 /
8495
8496 \end_inset
8497
8498 -int-long-reent
8499 \begin_inset LatexCommand \index{-\/-int-long-reent}
8500
8501 \end_inset
8502
8503
8504 \series default
8505  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8506  Note by default these libraries are compiled as non-reentrant.
8507  See section Installation for more details.
8508
8509 \layout List
8510 \labelwidthstring 00.00.0000
8511
8512 \series bold
8513 -
8514 \begin_inset ERT
8515 status Collapsed
8516
8517 \layout Standard
8518
8519
8520 \backslash
8521 /
8522
8523 \end_inset
8524
8525 -cyclomatic
8526 \begin_inset LatexCommand \index{-\/-cyclomatic}
8527
8528 \end_inset
8529
8530
8531 \bar under
8532  
8533 \series default
8534 \bar default
8535 This option will cause the compiler to generate an information message for
8536  each function in the source file.
8537  The message contains some 
8538 \emph on
8539 important
8540 \emph default
8541  information about the function.
8542  The number of edges and nodes the compiler detected in the control flow
8543  graph of the function, and most importantly the 
8544 \emph on
8545 cyclomatic complexity
8546 \begin_inset LatexCommand \index{Cyclomatic complexity}
8547
8548 \end_inset
8549
8550
8551 \emph default
8552  see section on Cyclomatic Complexity for more details.
8553
8554 \layout List
8555 \labelwidthstring 00.00.0000
8556
8557 \series bold
8558 -
8559 \begin_inset ERT
8560 status Collapsed
8561
8562 \layout Standard
8563
8564
8565 \backslash
8566 /
8567
8568 \end_inset
8569
8570 -float-reent
8571 \begin_inset LatexCommand \index{-\/-float-reent}
8572
8573 \end_inset
8574
8575
8576 \series default
8577  Floating point library is compiled as reentrant
8578 \begin_inset LatexCommand \index{reentrant}
8579
8580 \end_inset
8581
8582 .
8583  See section Installation for more details.
8584
8585 \layout List
8586 \labelwidthstring 00.00.0000
8587
8588 \series bold
8589 -
8590 \begin_inset ERT
8591 status Collapsed
8592
8593 \layout Standard
8594
8595
8596 \backslash
8597 /
8598
8599 \end_inset
8600
8601 -funsigned-char
8602 \begin_inset LatexCommand \index{-\/-funsigned-char}
8603
8604 \end_inset
8605
8606
8607 \series default
8608  The default signedness for every type is
8609 \family typewriter
8610  signed
8611 \family default
8612 .
8613  In some embedded environments the default signedness of
8614 \family typewriter
8615  char
8616 \family default
8617  is
8618 \family typewriter
8619  unsigned
8620 \family default
8621 .
8622  To set the signess for characters to unsigned, use the option --funsigned-char.
8623  If this option is set and no signedness keyword (unsigned/signed) is given,
8624  a char will be signed.
8625  All other types are unaffected.
8626
8627 \layout List
8628 \labelwidthstring 00.00.0000
8629
8630 \series bold
8631 -
8632 \begin_inset ERT
8633 status Collapsed
8634
8635 \layout Standard
8636
8637
8638 \backslash
8639 /
8640
8641 \end_inset
8642
8643 -main-return
8644 \begin_inset LatexCommand \index{-\/-main-return}
8645
8646 \end_inset
8647
8648
8649 \series default
8650  This option can be used if the code generated is called by a monitor program
8651  or if the main routine includes an endless loop.
8652  This option results in slightly smaller code and saves two bytes of stack
8653  space.
8654  The return from the 'main'
8655 \begin_inset LatexCommand \index{main return}
8656
8657 \end_inset
8658
8659  function will return to the function calling main.
8660  The default setting is to lock up i.e.
8661  generate a '
8662 \family typewriter
8663 sjmp .
8664 \family default
8665 '.
8666
8667 \layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status Collapsed
8674
8675 \layout Standard
8676
8677
8678 \backslash
8679 /
8680
8681 \end_inset
8682
8683 -nostdinc
8684 \begin_inset LatexCommand \index{-\/-nostdinc}
8685
8686 \end_inset
8687
8688
8689 \series default
8690  This will prevent the compiler from passing on the default include path
8691  to the preprocessor.
8692
8693 \layout List
8694 \labelwidthstring 00.00.0000
8695
8696 \series bold
8697 -
8698 \begin_inset ERT
8699 status Collapsed
8700
8701 \layout Standard
8702
8703
8704 \backslash
8705 /
8706
8707 \end_inset
8708
8709 -nostdlib
8710 \begin_inset LatexCommand \index{-\/-nostdlib}
8711
8712 \end_inset
8713
8714
8715 \series default
8716  This will prevent the compiler from passing on the default library
8717 \begin_inset LatexCommand \index{Libraries}
8718
8719 \end_inset
8720
8721  path to the linker.
8722
8723 \layout List
8724 \labelwidthstring 00.00.0000
8725
8726 \series bold
8727 -
8728 \begin_inset ERT
8729 status Collapsed
8730
8731 \layout Standard
8732
8733
8734 \backslash
8735 /
8736
8737 \end_inset
8738
8739 -verbose
8740 \begin_inset LatexCommand \index{-\/-verbose}
8741
8742 \end_inset
8743
8744
8745 \series default
8746  Shows the various actions the compiler is performing.
8747
8748 \layout List
8749 \labelwidthstring 00.00.0000
8750
8751 \series bold
8752 -V
8753 \begin_inset LatexCommand \index{-V}
8754
8755 \end_inset
8756
8757
8758 \series default
8759  Shows the actual commands the compiler is executing.
8760
8761 \layout List
8762 \labelwidthstring 00.00.0000
8763
8764 \series bold
8765 -
8766 \begin_inset ERT
8767 status Collapsed
8768
8769 \layout Standard
8770
8771
8772 \backslash
8773 /
8774
8775 \end_inset
8776
8777 -no-c-code-in-asm
8778 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8779
8780 \end_inset
8781
8782
8783 \series default
8784  Hides your ugly and inefficient c-code from the asm file, so you can always
8785  blame the compiler :)
8786
8787 \layout List
8788 \labelwidthstring 00.00.0000
8789
8790 \series bold
8791 -
8792 \begin_inset ERT
8793 status Collapsed
8794
8795 \layout Standard
8796
8797
8798 \backslash
8799 /
8800
8801 \end_inset
8802
8803 -no-peep-comments
8804 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8805
8806 \end_inset
8807
8808
8809 \series default
8810  Will not include peep-hole comments in the generated files.
8811
8812 \layout List
8813 \labelwidthstring 00.00.0000
8814
8815 \series bold
8816 -
8817 \begin_inset ERT
8818 status Collapsed
8819
8820 \layout Standard
8821
8822
8823 \backslash
8824 /
8825
8826 \end_inset
8827
8828 -no-gen-comments
8829 \begin_inset LatexCommand \index{-\/-no-gen-comments}
8830
8831 \end_inset
8832
8833
8834 \series default
8835  Will not include code generator comments in the generated files.
8836
8837 \layout List
8838 \labelwidthstring 00.00.0000
8839
8840 \series bold
8841 -
8842 \begin_inset ERT
8843 status Collapsed
8844
8845 \layout Standard
8846
8847
8848 \backslash
8849 /
8850
8851 \end_inset
8852
8853 -i-code-in-asm
8854 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8855
8856 \end_inset
8857
8858
8859 \series default
8860  Include i-codes in the asm file.
8861  Sounds like noise but is most helpful for debugging the compiler itself.
8862
8863 \layout List
8864 \labelwidthstring 00.00.0000
8865
8866 \series bold
8867 -
8868 \begin_inset ERT
8869 status Collapsed
8870
8871 \layout Standard
8872
8873
8874 \backslash
8875 /
8876
8877 \end_inset
8878
8879 -less-pedantic
8880 \begin_inset LatexCommand \index{-\/-less-pedantic}
8881
8882 \end_inset
8883
8884
8885 \series default
8886  Disable some of the more pedantic warnings
8887 \begin_inset LatexCommand \index{Warnings}
8888
8889 \end_inset
8890
8891  (jwk burps: please be more specific here, please!).
8892
8893 \layout List
8894 \labelwidthstring 00.00.0000
8895
8896 \series bold
8897 -
8898 \begin_inset ERT
8899 status Collapsed
8900
8901 \layout Standard
8902
8903
8904 \backslash
8905 /
8906
8907 \end_inset
8908
8909 -disable-warning\SpecialChar ~
8910 <nnnn>
8911 \begin_inset LatexCommand \index{-\/-disable-warning}
8912
8913 \end_inset
8914
8915
8916 \series default
8917  Disable specific warning with number <nnnn>.
8918
8919 \layout List
8920 \labelwidthstring 00.00.0000
8921
8922 \series bold
8923 -
8924 \begin_inset ERT
8925 status Collapsed
8926
8927 \layout Standard
8928
8929
8930 \backslash
8931 /
8932
8933 \end_inset
8934
8935 -print-search-dirs
8936 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8937
8938 \end_inset
8939
8940
8941 \series default
8942  Display the directories in the compiler's search path
8943
8944 \layout List
8945 \labelwidthstring 00.00.0000
8946
8947 \series bold
8948 -
8949 \begin_inset ERT
8950 status Collapsed
8951
8952 \layout Standard
8953
8954
8955 \backslash
8956 /
8957
8958 \end_inset
8959
8960 -vc
8961 \begin_inset LatexCommand \index{-\/-vc}
8962
8963 \end_inset
8964
8965
8966 \series default
8967  Display errors and warnings using MSVC style, so you can use SDCC with
8968  the visual studio IDE
8969 \begin_inset LatexCommand \index{IDE}
8970
8971 \end_inset
8972
8973 .
8974  With SDCC both offering a GCC-like (the default) and a MSVC-like
8975 \begin_inset LatexCommand \index{MSVC output style}
8976
8977 \end_inset
8978
8979  output style, integration into most programming editors should be straightforwa
8980 rd.
8981
8982 \layout List
8983 \labelwidthstring 00.00.0000
8984
8985 \series bold
8986 -
8987 \begin_inset ERT
8988 status Collapsed
8989
8990 \layout Standard
8991
8992
8993 \backslash
8994 /
8995
8996 \end_inset
8997
8998 -use-stdout
8999 \begin_inset LatexCommand \index{-\/-use-stdout}
9000
9001 \end_inset
9002
9003
9004 \series default
9005  Send errors and warnings to stdout instead of stderr.
9006
9007 \layout List
9008 \labelwidthstring 00.00.0000
9009
9010 \series bold
9011 -Wa\SpecialChar ~
9012 asmOption[,asmOption]
9013 \series default
9014
9015 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9016
9017 \end_inset
9018
9019 ...
9020  Pass the asmOption to the assembler
9021 \begin_inset LatexCommand \index{Options assembler}
9022
9023 \end_inset
9024
9025
9026 \begin_inset LatexCommand \index{Assembler options}
9027
9028 \end_inset
9029
9030 .
9031  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9032
9033 \layout List
9034 \labelwidthstring 00.00.0000
9035
9036 \series bold
9037 -
9038 \begin_inset ERT
9039 status Collapsed
9040
9041 \layout Standard
9042
9043
9044 \backslash
9045 /
9046
9047 \end_inset
9048
9049 -std-sdcc89
9050 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9051
9052 \end_inset
9053
9054
9055 \series default
9056  Generally follow the C89 standard, but allow SDCC features that conflict
9057  with the standard (default).
9058
9059 \layout List
9060 \labelwidthstring 00.00.0000
9061
9062 \series bold
9063 -
9064 \begin_inset ERT
9065 status Collapsed
9066
9067 \layout Standard
9068
9069
9070 \backslash
9071 /
9072
9073 \end_inset
9074
9075 -std-c89
9076 \begin_inset LatexCommand \index{-\/-std-c89}
9077
9078 \end_inset
9079
9080
9081 \series default
9082  Follow the C89 standard and disable SDCC features that conflict with the
9083  standard.
9084
9085 \layout List
9086 \labelwidthstring 00.00.0000
9087
9088 \series bold
9089 -
9090 \begin_inset ERT
9091 status Collapsed
9092
9093 \layout Standard
9094
9095
9096 \backslash
9097 /
9098
9099 \end_inset
9100
9101 -std-sdcc99
9102 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9103
9104 \end_inset
9105
9106
9107 \series default
9108  Generally follow the C99 standard, but allow SDCC features that conflict
9109  with the standard (incomplete support).
9110
9111 \layout List
9112 \labelwidthstring 00.00.0000
9113
9114 \series bold
9115 -
9116 \begin_inset ERT
9117 status Collapsed
9118
9119 \layout Standard
9120
9121
9122 \backslash
9123 /
9124
9125 \end_inset
9126
9127 -std-c99
9128 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9129
9130 \end_inset
9131
9132
9133 \series default
9134  Follow the C99 standard and disable SDCC features that conflict with the
9135  standard (incomplete support).
9136
9137 \layout List
9138 \labelwidthstring 00.00.0000
9139
9140 \series bold
9141 -
9142 \begin_inset ERT
9143 status Collapsed
9144
9145 \layout Standard
9146
9147
9148 \backslash
9149 /
9150
9151 \end_inset
9152
9153 -codeseg
9154 \series default
9155
9156 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9157
9158 \end_inset
9159
9160 \SpecialChar ~
9161 <Name> The name to be used for the code
9162 \begin_inset LatexCommand \index{code}
9163
9164 \end_inset
9165
9166  segment, default CSEG.
9167  This is useful if you need to tell the compiler to put the code in a special
9168  segment so you can later on tell the linker to put this segment in a special
9169  place in memory.
9170  Can be used for instance when using bank switching to put the code in a
9171  bank.
9172
9173 \layout List
9174 \labelwidthstring 00.00.0000
9175
9176 \series bold
9177 -
9178 \begin_inset ERT
9179 status Collapsed
9180
9181 \layout Standard
9182
9183
9184 \backslash
9185 /
9186
9187 \end_inset
9188
9189 -constseg
9190 \series default
9191
9192 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9193
9194 \end_inset
9195
9196 \SpecialChar ~
9197 <Name> The name to be used for the const
9198 \begin_inset LatexCommand \index{code}
9199
9200 \end_inset
9201
9202  segment, default CONST.
9203  This is useful if you need to tell the compiler to put the const data in
9204  a special segment so you can later on tell the linker to put this segment
9205  in a special place in memory.
9206  Can be used for instance when using bank switching to put the const data
9207  in a bank.
9208
9209 \layout List
9210 \labelwidthstring 00.00.0000
9211
9212 \series bold
9213 -
9214 \begin_inset ERT
9215 status Collapsed
9216
9217 \layout Standard
9218
9219
9220 \backslash
9221 /
9222
9223 \end_inset
9224
9225 -fdollars-in-identifiers
9226 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9227
9228 \end_inset
9229
9230
9231 \series default
9232  Permit '$' as an identifier character
9233
9234 \layout List
9235 \labelwidthstring 00.00.0000
9236 \added_space_bottom bigskip 
9237
9238 \series bold
9239 more-pedantic
9240 \series default
9241  Actually this is 
9242 \series bold
9243 \emph on
9244 not
9245 \series default
9246 \emph default
9247  a SDCC compiler option but if you want 
9248 \emph on
9249 more
9250 \emph default
9251  warnings you can use a separate tool dedicated to syntax checking like
9252  splint
9253 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9254
9255 \end_inset
9256
9257
9258 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9259
9260 \end_inset
9261
9262  
9263 \begin_inset LatexCommand \url{http://www.splint.org}
9264
9265 \end_inset
9266
9267 .
9268  To make your source files parseable by splint you will have to include
9269  
9270 \family sans
9271 lint.h
9272 \family default
9273
9274 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9275
9276 \end_inset
9277
9278  in your source file and add brackets around extended keywords (like 
9279 \family sans
9280
9281 \begin_inset Quotes sld
9282 \end_inset
9283
9284 __at\SpecialChar ~
9285
9286 \series bold
9287 (
9288 \series default
9289 0xab
9290 \series bold
9291 )
9292 \series default
9293
9294 \begin_inset Quotes srd
9295 \end_inset
9296
9297
9298 \family default
9299  and 
9300 \family sans
9301
9302 \begin_inset Quotes sld
9303 \end_inset
9304
9305 __interrupt\SpecialChar ~
9306 (2)
9307 \begin_inset Quotes srd
9308 \end_inset
9309
9310
9311 \family default
9312 ).
9313  
9314 \newline
9315 Splint has an excellent on line manual at 
9316 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9317
9318 \end_inset
9319
9320  and it's capabilities go beyond pure syntax checking.
9321  You'll need to tell splint the location of SDCC's include files so a typical
9322  command line could look like this: 
9323 \newline
9324
9325 \family sans
9326 splint\SpecialChar ~
9327 -I\SpecialChar ~
9328 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9329 \SpecialChar ~
9330 myprogram.c
9331
9332
9333 \layout Subsection
9334 Intermediate Dump Options
9335 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9336
9337 \end_inset
9338
9339
9340 \begin_inset LatexCommand \index{Options intermediate dump}
9341
9342 \end_inset
9343
9344
9345 \begin_inset LatexCommand \index{Intermediate dump options}
9346
9347 \end_inset
9348
9349
9350
9351 \layout Standard
9352 The following options are provided for the purpose of retargetting and debugging
9353  the compiler.
9354  They provide a means to dump the intermediate code (iCode
9355 \begin_inset LatexCommand \index{iCode}
9356
9357 \end_inset
9358
9359 ) generated by the compiler in human readable form at various stages of
9360  the compilation process.
9361  More on iCodes see chapter 
9362 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9363
9364 \end_inset
9365
9366  
9367 \begin_inset Quotes srd
9368 \end_inset
9369
9370 The anatomy of the compiler
9371 \begin_inset Quotes srd
9372 \end_inset
9373
9374 .
9375
9376 \layout List
9377 \labelwidthstring 00.00.0000
9378
9379 \series bold
9380 -
9381 \begin_inset ERT
9382 status Collapsed
9383
9384 \layout Standard
9385
9386
9387 \backslash
9388 /
9389
9390 \end_inset
9391
9392 -dumpraw
9393 \begin_inset LatexCommand \index{-\/-dumpraw}
9394
9395 \end_inset
9396
9397
9398 \series default
9399  This option will cause the compiler to dump the intermediate code into
9400  a file of named 
9401 \emph on
9402 <source filename>.dumpraw
9403 \emph default
9404  just after the intermediate code has been generated for a function, i.e.
9405  before any optimizations are done.
9406  The basic blocks
9407 \begin_inset LatexCommand \index{Basic blocks}
9408
9409 \end_inset
9410
9411  at this stage ordered in the depth first number, so they may not be in
9412  sequence of execution.
9413
9414 \layout List
9415 \labelwidthstring 00.00.0000
9416
9417 \series bold
9418 -
9419 \begin_inset ERT
9420 status Collapsed
9421
9422 \layout Standard
9423
9424
9425 \backslash
9426 /
9427
9428 \end_inset
9429
9430 -dumpgcse
9431 \begin_inset LatexCommand \index{-\/-dumpgcse}
9432
9433 \end_inset
9434
9435
9436 \series default
9437  Will create a dump of iCode's, after global subexpression elimination
9438 \begin_inset LatexCommand \index{Global subexpression elimination}
9439
9440 \end_inset
9441
9442 , into a file named 
9443 \emph on
9444 <source filename>.dumpgcse.
9445
9446 \layout List
9447 \labelwidthstring 00.00.0000
9448
9449 \series bold
9450 -
9451 \begin_inset ERT
9452 status Collapsed
9453
9454 \layout Standard
9455
9456
9457 \backslash
9458 /
9459
9460 \end_inset
9461
9462 -dumpdeadcode
9463 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9464
9465 \end_inset
9466
9467
9468 \series default
9469  Will create a dump of iCode's, after deadcode elimination
9470 \begin_inset LatexCommand \index{Dead-code elimination}
9471
9472 \end_inset
9473
9474 , into a file named 
9475 \emph on
9476 <source filename>.dumpdeadcode.
9477
9478 \layout List
9479 \labelwidthstring 00.00.0000
9480
9481 \series bold
9482 -
9483 \begin_inset ERT
9484 status Collapsed
9485
9486 \layout Standard
9487
9488
9489 \backslash
9490 /
9491
9492 \end_inset
9493
9494 -dumploop
9495 \begin_inset LatexCommand \index{-\/-dumploop}
9496
9497 \end_inset
9498
9499
9500 \series default
9501 \size large
9502  
9503 \size default
9504 Will create a dump of iCode's, after loop optimizations
9505 \begin_inset LatexCommand \index{Loop optimization}
9506
9507 \end_inset
9508
9509 , into a file named 
9510 \emph on
9511 <source filename>.dumploop.
9512
9513 \layout List
9514 \labelwidthstring 00.00.0000
9515
9516 \series bold
9517 -
9518 \begin_inset ERT
9519 status Collapsed
9520
9521 \layout Standard
9522
9523
9524 \backslash
9525 /
9526
9527 \end_inset
9528
9529 -dumprange
9530 \begin_inset LatexCommand \index{-\/-dumprange}
9531
9532 \end_inset
9533
9534
9535 \series default
9536 \size large
9537  
9538 \size default
9539 Will create a dump of iCode's, after live range analysis
9540 \begin_inset LatexCommand \index{Live range analysis}
9541
9542 \end_inset
9543
9544 , into a file named 
9545 \emph on
9546 <source filename>.dumprange.
9547
9548 \layout List
9549 \labelwidthstring 00.00.0000
9550
9551 \series bold
9552 -
9553 \begin_inset ERT
9554 status Collapsed
9555
9556 \layout Standard
9557
9558
9559 \backslash
9560 /
9561
9562 \end_inset
9563
9564 -dumlrange
9565 \begin_inset LatexCommand \index{-\/-dumlrange}
9566
9567 \end_inset
9568
9569
9570 \series default
9571  Will dump the life ranges
9572 \begin_inset LatexCommand \index{Live range analysis}
9573
9574 \end_inset
9575
9576  for all symbols.
9577
9578 \layout List
9579 \labelwidthstring 00.00.0000
9580
9581 \series bold
9582 -
9583 \begin_inset ERT
9584 status Collapsed
9585
9586 \layout Standard
9587
9588
9589 \backslash
9590 /
9591
9592 \end_inset
9593
9594 -dumpregassign
9595 \begin_inset LatexCommand \index{-\/-dumpregassign}
9596
9597 \end_inset
9598
9599
9600 \bar under
9601  
9602 \series default
9603 \bar default
9604 Will create a dump of iCode's, after register assignment
9605 \begin_inset LatexCommand \index{Register assignment}
9606
9607 \end_inset
9608
9609 , into a file named 
9610 \emph on
9611 <source filename>.dumprassgn.
9612
9613 \layout List
9614 \labelwidthstring 00.00.0000
9615
9616 \series bold
9617 -
9618 \begin_inset ERT
9619 status Collapsed
9620
9621 \layout Standard
9622
9623
9624 \backslash
9625 /
9626
9627 \end_inset
9628
9629 -dumplrange
9630 \begin_inset LatexCommand \index{-\/-dumplrange}
9631
9632 \end_inset
9633
9634
9635 \series default
9636  Will create a dump of the live ranges of iTemp's
9637
9638 \layout List
9639 \labelwidthstring 00.00.0000
9640 \added_space_bottom bigskip 
9641
9642 \series bold
9643 -
9644 \begin_inset ERT
9645 status Collapsed
9646
9647 \layout Standard
9648
9649
9650 \backslash
9651 /
9652
9653 \end_inset
9654
9655 -dumpall
9656 \begin_inset LatexCommand \index{-\/-dumpall}
9657
9658 \end_inset
9659
9660
9661 \size large
9662 \bar under
9663  
9664 \series default
9665 \size default
9666 \bar default
9667 Will cause all the above mentioned dumps to be created.
9668
9669
9670 \layout Subsection
9671 Redirecting output on Windows Shells
9672
9673 \layout Standard
9674 \added_space_bottom bigskip 
9675 By default SDCC writes it's error messages to 
9676 \begin_inset Quotes sld
9677 \end_inset
9678
9679 standard error
9680 \begin_inset Quotes srd
9681 \end_inset
9682
9683 .
9684  To force all messages to 
9685 \begin_inset Quotes sld
9686 \end_inset
9687
9688 standard output
9689 \begin_inset Quotes srd
9690 \end_inset
9691
9692  use 
9693 \series bold
9694 -
9695 \series default
9696 \emph on
9697
9698 \begin_inset ERT
9699 status Collapsed
9700
9701 \layout Standard
9702
9703
9704 \backslash
9705 /
9706
9707 \end_inset
9708
9709
9710 \series bold
9711 \emph default
9712 -
9713 \series default
9714 use-stdout
9715 \begin_inset LatexCommand \index{-\/-use-stdout}
9716
9717 \end_inset
9718
9719 .
9720  Additionally, if you happen to have visual studio installed in your windows
9721  machine, you can use it to compile your sources using a custom build and
9722  the SDCC -
9723 \emph on
9724
9725 \begin_inset ERT
9726 status Collapsed
9727
9728 \layout Standard
9729
9730
9731 \backslash
9732 /
9733
9734 \end_inset
9735
9736
9737 \emph default
9738 -vc
9739 \begin_inset LatexCommand \index{-\/-vc}
9740
9741 \end_inset
9742
9743  option.
9744  Something like this should work:
9745 \newline
9746
9747 \newline
9748
9749 \series bold
9750 c:
9751 \backslash
9752 sdcc
9753 \backslash
9754 bin
9755 \backslash
9756 sdcc.exe -
9757 \series default
9758 \emph on
9759
9760 \begin_inset ERT
9761 status Collapsed
9762
9763 \layout Standard
9764
9765
9766 \backslash
9767 /
9768
9769 \end_inset
9770
9771
9772 \series bold
9773 \emph default
9774 -vc -
9775 \series default
9776 \emph on
9777
9778 \begin_inset ERT
9779 status Collapsed
9780
9781 \layout Standard
9782
9783
9784 \backslash
9785 /
9786
9787 \end_inset
9788
9789
9790 \series bold
9791 \emph default
9792 -model-large -c $(InputPath)
9793 \series default
9794
9795
9796
9797
9798 \layout Section
9799 Environment variables
9800 \begin_inset LatexCommand \index{Environment variables}
9801
9802 \end_inset
9803
9804
9805
9806 \layout Standard
9807 SDCC recognizes the following environment variables:
9808
9809 \layout List
9810 \labelwidthstring 00.00.0000
9811
9812 \series bold
9813 SDCC_LEAVE_SIGNALS
9814 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9815
9816 \end_inset
9817
9818
9819 \series default
9820  SDCC installs a signal handler
9821 \begin_inset LatexCommand \index{signal handler}
9822
9823 \end_inset
9824
9825  to be able to delete temporary files after an user break (^C) or an exception.
9826  If this environment variable is set, SDCC won't install the signal handler
9827  in order to be able to debug SDCC.
9828
9829 \layout List
9830 \labelwidthstring 00.00.0000
9831
9832 \series bold
9833 TMP,\SpecialChar ~
9834 TEMP,\SpecialChar ~
9835 TMPDIR
9836 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9837
9838 \end_inset
9839
9840
9841 \series default
9842  Path, where temporary files will be created.
9843  The order of the variables is the search order.
9844  In a standard *nix environment these variables are not set, and there's
9845  no need to set them.
9846  On Windows it's recommended to set one of them.
9847
9848 \layout List
9849 \labelwidthstring 00.00.0000
9850
9851 \series bold
9852 SDCC_HOME
9853 \begin_inset LatexCommand \index{SDCC\_HOME}
9854
9855 \end_inset
9856
9857
9858 \series default
9859  Path, see section 
9860 \begin_inset LatexCommand \ref{sub:Install-paths}
9861
9862 \end_inset
9863
9864 \SpecialChar ~
9865
9866 \begin_inset Quotes sld
9867 \end_inset
9868
9869  Install Paths
9870 \begin_inset Quotes srd
9871 \end_inset
9872
9873 .
9874
9875 \layout List
9876 \labelwidthstring 00.00.0000
9877
9878 \series bold
9879 SDCC_INCLUDE
9880 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9881
9882 \end_inset
9883
9884
9885 \series default
9886  Path, see section 
9887 \begin_inset LatexCommand \ref{sub:Search-Paths}
9888
9889 \end_inset
9890
9891 \SpecialChar ~
9892
9893 \begin_inset Quotes sld
9894 \end_inset
9895
9896 Search Paths
9897 \begin_inset Quotes srd
9898 \end_inset
9899
9900 .
9901
9902 \layout List
9903 \labelwidthstring 00.00.0000
9904
9905 \series bold
9906 SDCC_LIB
9907 \begin_inset LatexCommand \index{SDCC\_LIB}
9908
9909 \end_inset
9910
9911
9912 \series default
9913  Path, see section 
9914 \begin_inset LatexCommand \ref{sub:Search-Paths}
9915
9916 \end_inset
9917
9918 \SpecialChar ~
9919
9920 \begin_inset Quotes sld
9921 \end_inset
9922
9923 Search Paths
9924 \begin_inset Quotes srd
9925 \end_inset
9926
9927 ..
9928
9929 \layout Standard
9930 \added_space_bottom bigskip 
9931 There are some more environment variables recognized by SDCC, but these
9932  are solely used for debugging purposes.
9933  They can change or disappear very quickly, and will never be documented.
9934
9935
9936
9937 \layout Section
9938 Storage Class Language Extensions
9939
9940 \layout Subsection
9941 MCS51/DS390 Storage Class
9942 \begin_inset LatexCommand \index{Storage class}
9943
9944 \end_inset
9945
9946  Language Extensions
9947
9948 \layout Standard
9949 In addition to the ANSI storage classes SDCC allows the following MCS51
9950  specific storage classes:
9951
9952 \layout Subsubsection
9953 data
9954 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9955
9956 \end_inset
9957
9958
9959 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9960
9961 \end_inset
9962
9963  / near
9964 \begin_inset LatexCommand \index{near (storage class)}
9965
9966 \end_inset
9967
9968
9969 \begin_inset LatexCommand \index{\_\_near (storage class)}
9970
9971 \end_inset
9972
9973
9974
9975 \layout Standard
9976 This is the 
9977 \series bold
9978 default
9979 \series default
9980  storage class for the Small Memory model (
9981 \emph on
9982 data
9983 \emph default
9984  and 
9985 \emph on
9986 near
9987 \emph default
9988  or the more ANSI-C compliant forms 
9989 \emph on
9990 __data
9991 \emph default
9992  and 
9993 \emph on
9994 __near
9995 \emph default
9996  can be used synonymously).
9997  Variables declared with this storage class will be allocated in the directly
9998  addressable portion of the internal RAM of a 8051, e.g.:
9999
10000 \layout Verse
10001
10002 \family typewriter
10003 __data unsigned char test_data;
10004
10005 \layout Standard
10006 Writing 0x01 to this variable generates the assembly code:
10007
10008 \layout Verse
10009
10010 \family typewriter
10011 75*00 01\SpecialChar ~
10012 \SpecialChar ~
10013 \SpecialChar ~
10014 mov\SpecialChar ~
10015 \SpecialChar ~
10016 _test_data,#0x01
10017
10018 \layout Subsubsection
10019 xdata
10020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10021
10022 \end_inset
10023
10024
10025 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10026
10027 \end_inset
10028
10029  / far
10030 \begin_inset LatexCommand \index{far (storage class)}
10031
10032 \end_inset
10033
10034
10035 \begin_inset LatexCommand \index{\_\_far (storage class)}
10036
10037 \end_inset
10038
10039
10040
10041 \layout Standard
10042 Variables declared with this storage class will be placed in the external
10043  RAM.
10044  This is the 
10045 \series bold
10046 default
10047 \series default
10048  storage class for the Large Memory model, e.g.:
10049
10050 \layout Verse
10051
10052 \family typewriter
10053 __xdata unsigned char test_xdata;
10054
10055 \layout Standard
10056 Writing 0x01 to this variable generates the assembly code:
10057
10058 \layout Verse
10059
10060 \family typewriter
10061 90s00r00\SpecialChar ~
10062 \SpecialChar ~
10063 \SpecialChar ~
10064 mov\SpecialChar ~
10065 \SpecialChar ~
10066 dptr,#_test_xdata 
10067 \newline
10068 74\SpecialChar ~
10069 01\SpecialChar ~
10070 \SpecialChar ~
10071 \SpecialChar ~
10072 \SpecialChar ~
10073 \SpecialChar ~
10074 \SpecialChar ~
10075 mov\SpecialChar ~
10076 \SpecialChar ~
10077 a,#0x01 
10078 \newline
10079 F0\SpecialChar ~
10080 \SpecialChar ~
10081 \SpecialChar ~
10082 \SpecialChar ~
10083 \SpecialChar ~
10084 \SpecialChar ~
10085 \SpecialChar ~
10086 \SpecialChar ~
10087 \SpecialChar ~
10088 movx\SpecialChar ~
10089 @dptr,a 
10090
10091 \layout Subsubsection
10092 idata
10093 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10094
10095 \end_inset
10096
10097
10098 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10099
10100 \end_inset
10101
10102
10103
10104 \layout Standard
10105 Variables declared with this storage class will be allocated into the indirectly
10106  addressable portion of the internal ram of a 8051, e.g.:
10107
10108 \layout Verse
10109
10110 \family typewriter
10111 __idata unsigned char test_idata;
10112
10113 \layout Standard
10114 Writing 0x01 to this variable generates the assembly code:
10115
10116 \layout Verse
10117
10118 \family typewriter
10119 78r00\SpecialChar ~
10120 \SpecialChar ~
10121 \SpecialChar ~
10122 \SpecialChar ~
10123 \SpecialChar ~
10124 \SpecialChar ~
10125 \SpecialChar ~
10126 mov\SpecialChar ~
10127 \SpecialChar ~
10128 r0,#_test_idata
10129 \newline
10130 76\SpecialChar ~
10131 01\SpecialChar ~
10132 \SpecialChar ~
10133 \SpecialChar ~
10134 \SpecialChar ~
10135 \SpecialChar ~
10136 \SpecialChar ~
10137 \SpecialChar ~
10138 mov\SpecialChar ~
10139 \SpecialChar ~
10140 @r0,#0x01
10141
10142 \layout Standard
10143 Please note, the first 128 byte of idata physically access the same RAM
10144  as the data memory.
10145  The original 8051 had 128 byte idata memory, nowadays most devices have
10146  256 byte idata memory.
10147  The stack
10148 \begin_inset LatexCommand \index{stack}
10149
10150 \end_inset
10151
10152  is located in idata memory.
10153
10154 \layout Subsubsection
10155 pdata
10156 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10157
10158 \end_inset
10159
10160
10161 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10162
10163 \end_inset
10164
10165
10166
10167 \layout Standard
10168 Paged xdata access is just as straightforward as using the other addressing
10169  modes of a 8051.
10170  It is typically located at the start of xdata and has a maximum size of
10171  256 bytes.
10172  The following example writes 0x01 to the pdata variable.
10173  Please note, pdata access physically accesses xdata memory.
10174  The high byte of the address is determined by port P2 
10175 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10176
10177 \end_inset
10178
10179 (or in case of some 8051 variants by a separate Special Function Register,
10180  see section 
10181 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10182
10183 \end_inset
10184
10185 ).
10186  This is the 
10187 \series bold
10188 default
10189 \series default
10190  storage class for the Medium Memory model, e.g.:
10191
10192 \layout Verse
10193
10194 \family typewriter
10195 __pdata unsigned char test_pdata;
10196
10197 \layout Standard
10198 Writing 0x01 to this variable generates the assembly code:
10199
10200 \layout Verse
10201
10202 \family typewriter
10203 78r00\SpecialChar ~
10204 \SpecialChar ~
10205 \SpecialChar ~
10206 \SpecialChar ~
10207 \SpecialChar ~
10208 \SpecialChar ~
10209 mov r0,#_test_pdata
10210 \newline
10211 74 01\SpecialChar ~
10212 \SpecialChar ~
10213 \SpecialChar ~
10214 \SpecialChar ~
10215 \SpecialChar ~
10216 \SpecialChar ~
10217 mov a,#0x01 
10218 \newline
10219 F2\SpecialChar ~
10220 \SpecialChar ~
10221 \SpecialChar ~
10222 \SpecialChar ~
10223 \SpecialChar ~
10224 \SpecialChar ~
10225 \SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 movx @r0,a
10229
10230 \layout Standard
10231 If the -
10232 \begin_inset ERT
10233 status Collapsed
10234
10235 \layout Standard
10236
10237
10238 \backslash
10239 /
10240
10241 \end_inset
10242
10243 -xstack
10244 \begin_inset LatexCommand \index{-\/-xstack}
10245
10246 \end_inset
10247
10248  option is used the pdata memory area is followed by the xstack memory area
10249  and the sum of their sizes is limited to 256 bytes.
10250
10251 \layout Subsubsection
10252 code
10253 \begin_inset LatexCommand \index{code}
10254
10255 \end_inset
10256
10257
10258 \begin_inset LatexCommand \index{\_\_code}
10259
10260 \end_inset
10261
10262
10263
10264 \layout Standard
10265 'Variables' declared with this storage class will be placed in the code
10266  memory:
10267
10268 \layout Verse
10269
10270 \family typewriter
10271 __code unsigned char test_code;
10272
10273 \layout Standard
10274 Read access to this variable generates the assembly code:
10275
10276 \layout Verse
10277
10278 \family typewriter
10279 90s00r6F\SpecialChar ~
10280 \SpecialChar ~
10281 \SpecialChar ~
10282 mov dptr,#_test_code
10283 \newline
10284 E4\SpecialChar ~
10285 \SpecialChar ~
10286 \SpecialChar ~
10287 \SpecialChar ~
10288 \SpecialChar ~
10289 \SpecialChar ~
10290 \SpecialChar ~
10291 \SpecialChar ~
10292 \SpecialChar ~
10293 clr a
10294 \newline
10295 93\SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 \SpecialChar ~
10302 \SpecialChar ~
10303 \SpecialChar ~
10304 movc a,@a+dptr 
10305
10306 \layout Standard
10307
10308 \family typewriter
10309 char
10310 \family default
10311  indexed arrays of characters in code memory can be accessed efficiently:
10312
10313 \layout Verse
10314
10315 \family typewriter
10316 __code char test_array[] = {'c','h','e','a','p'}; 
10317
10318 \layout Standard
10319 Read access to this array using an 8-bit unsigned index generates the assembly
10320  code:
10321
10322 \layout Verse
10323
10324 \family typewriter
10325 E5*00\SpecialChar ~
10326 \SpecialChar ~
10327 \SpecialChar ~
10328 \SpecialChar ~
10329 \SpecialChar ~
10330 \SpecialChar ~
10331 mov a,_index 
10332
10333 \layout Verse
10334
10335 \family typewriter
10336 90s00r41\SpecialChar ~
10337 \SpecialChar ~
10338 \SpecialChar ~
10339 mov dptr,#_test_array
10340
10341 \layout Verse
10342
10343 \family typewriter
10344 93\SpecialChar ~
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 \SpecialChar ~
10349 \SpecialChar ~
10350 \SpecialChar ~
10351 \SpecialChar ~
10352 \SpecialChar ~
10353 movc a,@a+dptr 
10354
10355 \layout Subsubsection
10356 bit
10357 \begin_inset LatexCommand \index{bit}
10358
10359 \end_inset
10360
10361
10362 \begin_inset LatexCommand \index{\_\_bit}
10363
10364 \end_inset
10365
10366
10367
10368 \layout Standard
10369 This is a data-type and a storage class specifier.
10370  When a variable is declared as a bit, it is allocated into the bit addressable
10371  memory of 8051, e.g.:
10372
10373 \layout Verse
10374
10375 \family typewriter
10376 __bit test_bit;
10377
10378 \layout Standard
10379 Writing 1 to this variable generates the assembly code:
10380
10381 \layout Verse
10382
10383 \family typewriter
10384 D2*00\SpecialChar ~
10385 \SpecialChar ~
10386 \SpecialChar ~
10387 \SpecialChar ~
10388 \SpecialChar ~
10389 \SpecialChar ~
10390 \SpecialChar ~
10391 setb\SpecialChar ~
10392 _test_bit
10393
10394 \layout Standard
10395 The bit addressable memory consists of 128 bits which are located from 0x20
10396  to 0x2f in data memory.
10397  
10398 \newline
10399 Apart from this 8051 specific storage class most architectures support
10400  ANSI-C bitfields
10401 \begin_inset LatexCommand \index{bitfields}
10402
10403 \end_inset
10404
10405
10406 \begin_inset Foot
10407 collapsed false
10408
10409 \layout Standard
10410 Not really meant as examples, but nevertheless showing what bitfields are
10411  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10412
10413 \end_inset
10414
10415 .
10416  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10417  signed modifier are implemented as unsigned.
10418
10419 \layout Subsubsection
10420 sfr
10421 \begin_inset LatexCommand \index{sfr}
10422
10423 \end_inset
10424
10425
10426 \begin_inset LatexCommand \index{\_\_sfr}
10427
10428 \end_inset
10429
10430  / sfr16
10431 \begin_inset LatexCommand \index{sfr16}
10432
10433 \end_inset
10434
10435
10436 \begin_inset LatexCommand \index{\_\_sfr16}
10437
10438 \end_inset
10439
10440  / sfr32
10441 \begin_inset LatexCommand \index{sfr32}
10442
10443 \end_inset
10444
10445
10446 \begin_inset LatexCommand \index{\_\_sfr32}
10447
10448 \end_inset
10449
10450  / sbit
10451 \begin_inset LatexCommand \index{\_\_sbit}
10452
10453 \end_inset
10454
10455
10456 \begin_inset LatexCommand \index{sbit}
10457
10458 \end_inset
10459
10460
10461
10462 \layout Standard
10463 Like the bit keyword, 
10464 \emph on
10465 sfr / sfr16 / sfr32 / sbit 
10466 \emph default
10467 signify both a data-type and storage class, they are used to describe the
10468  
10469 \emph on
10470 s
10471 \emph default
10472 pecial 
10473 \emph on
10474 f
10475 \emph default
10476 unction 
10477 \emph on
10478 r
10479 \emph default
10480 egisters and 
10481 \emph on
10482 s
10483 \emph default
10484 pecial 
10485 \emph on
10486 bit
10487 \emph default
10488  variables of a 8051, eg:
10489
10490 \layout Verse
10491
10492 \family typewriter
10493 __sfr __at
10494 \begin_inset LatexCommand \index{at}
10495
10496 \end_inset
10497
10498
10499 \begin_inset LatexCommand \index{\_\_at}
10500
10501 \end_inset
10502
10503  (0x80) P0;\SpecialChar ~
10504  /* special function register P0 at location 0x80 */
10505 \newline
10506
10507 \newline
10508 /* 16 bit
10509  special function register combination for timer 0
10510 \newline
10511 \SpecialChar ~
10512 \SpecialChar ~
10513  with the high byte at
10514  location 0x8C and the low byte at location 0x8A */
10515 \newline
10516 __sfr16 __at (0x8C8A)
10517  TMR0;
10518 \newline
10519
10520 \newline
10521 __sbit __at
10522 \begin_inset LatexCommand \index{at}
10523
10524 \end_inset
10525
10526
10527 \begin_inset LatexCommand \index{\_\_at}
10528
10529 \end_inset
10530
10531  (0xd7) CY;\SpecialChar ~
10532  /* CY (Carry Flag
10533 \begin_inset LatexCommand \index{Flags}
10534
10535 \end_inset
10536
10537
10538 \begin_inset LatexCommand \index{Carry flag}
10539
10540 \end_inset
10541
10542 ) */
10543
10544 \layout Standard
10545 Special function registers which are located on an address dividable by
10546  8 are bit-addressable, an
10547 \emph on
10548  sbit
10549 \emph default
10550  addresses a specific bit within these sfr.
10551 \newline
10552 16 Bit and 32 bit special function
10553  register combinations which require a certain access order are better not
10554  declared using 
10555 \emph on
10556 sfr16
10557 \emph default
10558  or 
10559 \emph on
10560 sfr32.
10561
10562 \emph default
10563  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10564  this is not guaranteed.
10565 \newline
10566
10567
10568 \layout Standard
10569 Please note, if you use a header file which was written for another compiler
10570  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10571  likely be 
10572 \emph on
10573 not 
10574 \emph default
10575 compatible.
10576  Specifically the syntax 
10577 \family typewriter
10578 \SpecialChar ~
10579 sfr P0 = 0x80;\SpecialChar ~
10580
10581 \family default
10582  is compiled 
10583 \emph on
10584 without warning
10585 \emph default
10586  by SDCC to an assignment of 0x80 to a variable called P0 
10587 \family typewriter
10588
10589 \begin_inset Marginal
10590 collapsed true
10591
10592 \layout Standard
10593
10594 \series bold
10595 \SpecialChar ~
10596 !
10597
10598 \end_inset
10599
10600 .
10601  
10602 \family default
10603 Nevertheless it is possible to write header files
10604 \begin_inset LatexCommand \index{Header files}
10605
10606 \end_inset
10607
10608
10609 \begin_inset LatexCommand \index{Include files}
10610
10611 \end_inset
10612
10613  which can be shared among different compilers (see section 
10614 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10615
10616 \end_inset
10617
10618 ).
10619  
10620
10621 \layout Subsubsection
10622 Pointers
10623 \begin_inset LatexCommand \index{Pointer}
10624
10625 \end_inset
10626
10627  to MCS51/DS390 specific memory spaces
10628
10629 \layout Standard
10630 SDCC allows (via language extensions) pointers to explicitly point to any
10631  of the memory spaces
10632 \begin_inset LatexCommand \index{Memory model}
10633
10634 \end_inset
10635
10636  of the 8051.
10637  In addition to the explicit pointers, the compiler uses (by default) generic
10638  pointers which can be used to point to any of the memory spaces.
10639 \newline
10640
10641 \newline
10642 Pointer
10643  declaration examples:
10644
10645 \layout Verse
10646
10647 \family typewriter
10648 /* pointer physically in internal ram pointing to object in external ram
10649  */ 
10650 \newline
10651 __xdata unsigned char * __data p;
10652 \newline
10653
10654 \newline
10655 /* pointer physically in external ram
10656  pointing to object in internal ram */ 
10657 \newline
10658 __data unsigned char * __xdata p;
10659 \newline
10660
10661 \newline
10662 /*
10663  pointer physically in code rom pointing to data in xdata space */ 
10664 \newline
10665 __xdata
10666  unsigned char * __code p;
10667 \newline
10668
10669 \newline
10670 /* pointer physically in code space pointing to
10671  data in code space */ 
10672 \newline
10673 __code unsigned char * __code p;
10674 \newline
10675
10676 \newline
10677 /* generic pointer
10678  physically located in xdata space */
10679 \newline
10680 unsigned char * __xdata p;
10681 \newline
10682
10683 \newline
10684 /* generic
10685  pointer physically located in default memory space */
10686 \newline
10687 unsigned char * p;
10688 \newline
10689
10690 \newline
10691 /*
10692  the following is a function pointer
10693 \begin_inset LatexCommand \index{function pointer}
10694
10695 \end_inset
10696
10697  physically located in data space */
10698 \newline
10699 char (* __data fp)(void);
10700
10701 \layout Standard
10702 Well you get the idea.
10703  
10704 \newline
10705
10706 \newline
10707 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10708 \emph on
10709 generic
10710 \emph default
10711  pointers.
10712  
10713 \size small
10714
10715 \newline
10716
10717 \newline
10718
10719 \size default
10720 The highest order byte of the 
10721 \emph on
10722 generic
10723 \emph default
10724  pointers contains the data space information.
10725  Assembler support routines are called whenever data is stored or retrieved
10726  using 
10727 \emph on
10728 generic
10729 \emph default
10730  pointers.
10731  These are useful for developing reusable library
10732 \begin_inset LatexCommand \index{Libraries}
10733
10734 \end_inset
10735
10736  routines.
10737  Explicitly specifying the pointer
10738 \begin_inset LatexCommand \index{pointer}
10739
10740 \end_inset
10741
10742  type will generate the most efficient code.
10743
10744 \layout Subsubsection
10745 Notes on MCS51 memory
10746 \begin_inset LatexCommand \index{MCS51 memory}
10747
10748 \end_inset
10749
10750  layout
10751
10752 \layout Standard
10753 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10754  RAM memory which is structured as follows:
10755 \newline
10756
10757 \newline
10758 - Bytes 00-1F - 32 bytes to hold
10759  up to 4 banks of the registers R0 to R7, 
10760 \newline
10761 - Bytes 20-2F - 16 bytes to hold
10762  128 bit
10763 \begin_inset LatexCommand \index{bit}
10764
10765 \end_inset
10766
10767  variables and, 
10768 \newline
10769 - Bytes 30-7F - 80 bytes for general purpose use.
10770 \newline
10771
10772
10773 \layout Standard
10774 Additionally some members of the MCS51 family may have up to 128 bytes of
10775  additional, indirectly addressable, internal RAM memory (
10776 \emph on
10777 idata
10778 \emph default
10779
10780 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10781
10782 \end_inset
10783
10784
10785 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10786
10787 \end_inset
10788
10789 ).
10790  Furthermore, some chips may have some built in external memory (
10791 \emph on
10792 xdata
10793 \emph default
10794
10795 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10796
10797 \end_inset
10798
10799
10800 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10801
10802 \end_inset
10803
10804 ) which should not be confused with the internal, directly addressable RAM
10805  memory (
10806 \emph on
10807 data
10808 \emph default
10809
10810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10811
10812 \end_inset
10813
10814
10815 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10816
10817 \end_inset
10818
10819 ).
10820  Sometimes this built in 
10821 \emph on
10822 xdata
10823 \emph default
10824  memory has to be activated before using it (you can probably find this
10825  information on the datasheet of the microcontroller your are using, see
10826  also section 
10827 \begin_inset LatexCommand \ref{sub:Startup-Code}
10828
10829 \end_inset
10830
10831 \SpecialChar ~
10832 Startup-Code).
10833
10834 \layout Standard
10835 Normally SDCC will only use the first bank
10836 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10837
10838 \end_inset
10839
10840  of registers (register bank 0), but it is possible to specify that other
10841  banks of registers (keyword 
10842 \emph on
10843 using
10844 \emph default
10845  
10846 \emph on
10847
10848 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10849
10850 \end_inset
10851
10852
10853 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10854
10855 \end_inset
10856
10857
10858 \emph default
10859 ) should be used in interrupt
10860 \begin_inset LatexCommand \index{interrupt}
10861
10862 \end_inset
10863
10864
10865 \begin_inset LatexCommand \index{\_\_interrupt}
10866
10867 \end_inset
10868
10869  routines.
10870  By default, the compiler will place the stack after the last byte of allocated
10871  memory for variables.
10872  For example, if the first 2 banks of registers are used, and only four
10873  bytes are used for 
10874 \emph on
10875 data
10876 \emph default
10877  variables, it will position the base of the internal stack at address 20
10878  (0x14).
10879  This implies that as the stack
10880 \begin_inset LatexCommand \index{stack}
10881
10882 \end_inset
10883
10884  grows, it will use up the remaining register banks, and the 16 bytes used
10885  by the 128 bit variables, and 80 bytes for general purpose use.
10886  If any bit variables are used, the data variables will be placed in unused
10887  register banks and after the byte holding the last bit variable.
10888  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10889  (two bytes used), 
10890 \emph on
10891 data
10892 \emph default
10893  variables will be placed starting from address 0x10 to 0x20 and continue
10894  at address 0x22.
10895  You can also use -
10896 \begin_inset ERT
10897 status Collapsed
10898
10899 \layout Standard
10900
10901
10902 \backslash
10903 /
10904
10905 \end_inset
10906
10907 -data-loc
10908 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10909
10910 \end_inset
10911
10912  to specify the start address of the 
10913 \emph on
10914 data
10915 \emph default
10916  and -
10917 \begin_inset ERT
10918 status Collapsed
10919
10920 \layout Standard
10921
10922
10923 \backslash
10924 /
10925
10926 \end_inset
10927
10928 -iram-size
10929 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10930
10931 \end_inset
10932
10933  to specify the size of the total internal RAM (
10934 \emph on
10935 data
10936 \emph default
10937 +
10938 \emph on
10939 idata
10940 \emph default
10941 ).
10942  
10943 \newline
10944
10945
10946 \layout Standard
10947 By default the 8051 linker will place the stack after the last byte of (i)data
10948  variables.
10949  Option -
10950 \begin_inset ERT
10951 status Collapsed
10952
10953 \layout Standard
10954
10955
10956 \backslash
10957 /
10958
10959 \end_inset
10960
10961 -stack-loc
10962 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10963
10964 \end_inset
10965
10966  allows you to specify the start of the stack, i.e.
10967  you could start it after any data in the general purpose area.
10968  If your microcontroller has additional indirectly addressable internal
10969  RAM (
10970 \emph on
10971 idata
10972 \emph default
10973 ) you can place the stack on it.
10974  You may also need to use -
10975 \begin_inset ERT
10976 status Collapsed
10977
10978 \layout Standard
10979
10980
10981 \backslash
10982 /
10983
10984 \end_inset
10985
10986 -xdata-loc
10987 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10988
10989 \end_inset
10990
10991  to set the start address of the external RAM (
10992 \emph on
10993 xdata
10994 \emph default
10995 ) and -
10996 \begin_inset ERT
10997 status Collapsed
10998
10999 \layout Standard
11000
11001
11002 \backslash
11003 /
11004
11005 \end_inset
11006
11007 -xram-size
11008 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11009
11010 \end_inset
11011
11012  to specify its size.
11013  Same goes for the code memory, using -
11014 \begin_inset ERT
11015 status Collapsed
11016
11017 \layout Standard
11018
11019
11020 \backslash
11021 /
11022
11023 \end_inset
11024
11025 -code-loc
11026 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11027
11028 \end_inset
11029
11030  and -
11031 \begin_inset ERT
11032 status Collapsed
11033
11034 \layout Standard
11035
11036
11037 \backslash
11038 /
11039
11040 \end_inset
11041
11042 -code-size
11043 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11044
11045 \end_inset
11046
11047 .
11048  If in doubt, don't specify any options and see if the resulting memory
11049  layout is appropriate, then you can adjust it.
11050
11051 \layout Standard
11052 \added_space_bottom bigskip 
11053 The linker generates two files with memory allocation information.
11054  The first, with extension .map
11055 \begin_inset LatexCommand \index{<file>.map}
11056
11057 \end_inset
11058
11059  shows all the variables and segments.
11060  The second with extension .mem
11061 \begin_inset LatexCommand \index{<file>.mem}
11062
11063 \end_inset
11064
11065  shows the final memory layout.
11066  The linker will complain either if memory segments overlap, there is not
11067  enough memory, or there is not enough space for stack.
11068  If you get any linking warnings and/or errors related to stack or segments
11069  allocation, take a look at either the .map or .mem files to find out what
11070  the problem is.
11071  The .mem file may even suggest a solution to the problem.
11072
11073
11074
11075 \layout Subsection
11076 Z80/Z180 Storage Class
11077 \begin_inset LatexCommand \index{Z80!Storage class}
11078
11079 \end_inset
11080
11081  Language Extensions
11082
11083 \layout Subsubsection
11084 sfr
11085 \begin_inset LatexCommand \index{sfr}
11086
11087 \end_inset
11088
11089
11090 \begin_inset LatexCommand \index{\_\_sfr}
11091
11092 \end_inset
11093
11094  (in/out to 8-bit addresses)
11095
11096 \layout Standard
11097 The Z80
11098 \begin_inset LatexCommand \index{Z80}
11099
11100 \end_inset
11101
11102  family has separate address spaces for memory and 
11103 \emph on
11104 i
11105 \emph default
11106 nput/
11107 \emph on
11108 o
11109 \emph default
11110 utput memory.
11111  I/O memory
11112 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11113
11114 \end_inset
11115
11116
11117 \begin_inset LatexCommand \index{Z80!I/O memory}
11118
11119 \end_inset
11120
11121
11122 \begin_inset LatexCommand \index{Z180!I/O memory}
11123
11124 \end_inset
11125
11126  is accessed with special instructions, e.g.:
11127
11128 \layout Verse
11129
11130 \family typewriter
11131 sfr at 0x78 IoPort;\SpecialChar ~
11132 \SpecialChar ~
11133 /* define a var in I/O space at 78h called IoPort */
11134  
11135
11136 \layout Standard
11137 Writing 0x01 to this variable generates the assembly code:
11138
11139 \layout Verse
11140
11141 \family typewriter
11142 3E 01\SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 ld a,#0x01
11149 \newline
11150 D3 78\SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 out (_IoPort),a 
11157
11158 \layout Subsubsection
11159 banked sfr
11160 \begin_inset LatexCommand \index{sfr}
11161
11162 \end_inset
11163
11164
11165 \begin_inset LatexCommand \index{\_\_sfr}
11166
11167 \end_inset
11168
11169  (in/out to 16-bit addresses)
11170
11171 \layout Standard
11172 The keyword 
11173 \emph on
11174 banked
11175 \emph default
11176  is used to support 16 bit addresses in I/O memory e.g.:
11177
11178 \layout Verse
11179
11180 \family typewriter
11181 sfr banked at
11182 \begin_inset LatexCommand \index{at}
11183
11184 \end_inset
11185
11186
11187 \begin_inset LatexCommand \index{\_\_at}
11188
11189 \end_inset
11190
11191  0x123 IoPort; 
11192
11193 \layout Standard
11194 Writing 0x01 to this variable generates the assembly code:
11195
11196 \layout Verse
11197
11198 \family typewriter
11199 01 23 01\SpecialChar ~
11200 \SpecialChar ~
11201 \SpecialChar ~
11202 ld bc,#_IoPort
11203 \newline
11204 3E 01\SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 ld a,#0x01 
11211 \newline
11212 ED 79\SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 \SpecialChar ~
11217 \SpecialChar ~
11218 out (c),a 
11219
11220 \layout Subsubsection
11221 sfr
11222 \begin_inset LatexCommand \index{sfr}
11223
11224 \end_inset
11225
11226
11227 \begin_inset LatexCommand \index{\_\_sfr}
11228
11229 \end_inset
11230
11231  (in0/out0 to 8 bit addresses on Z180
11232 \begin_inset LatexCommand \index{Z180}
11233
11234 \end_inset
11235
11236 /HD64180
11237 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11238
11239 \end_inset
11240
11241 )
11242
11243 \layout Standard
11244 \added_space_bottom bigskip 
11245 The compiler option -
11246 \begin_inset ERT
11247 status Collapsed
11248
11249 \layout Standard
11250
11251
11252 \backslash
11253 /
11254
11255 \end_inset
11256
11257 -portmode
11258 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11259
11260 \end_inset
11261
11262 =180 (80) and a compiler #pragma\SpecialChar ~
11263 portmode
11264 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11265
11266 \end_inset
11267
11268  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11269 ns 
11270 \family typewriter
11271 in0/out0
11272 \family default
11273  instead of 
11274 \family typewriter
11275 in/out
11276 \family default
11277 .
11278  If you include the file z180.h this will be set automatically.
11279
11280
11281
11282 \layout Subsection
11283 HC08 Storage Class
11284 \begin_inset LatexCommand \index{HC08!Storage class}
11285
11286 \end_inset
11287
11288  Language Extensions
11289
11290 \layout Subsubsection
11291 data
11292 \begin_inset LatexCommand \index{data (hc08 storage class)}
11293
11294 \end_inset
11295
11296
11297 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11298
11299 \end_inset
11300
11301  
11302
11303 \layout Standard
11304 The data storage class declares a variable that resides in the first 256
11305  bytes of memory (the direct page).
11306  The HC08
11307 \begin_inset LatexCommand \index{HC08}
11308
11309 \end_inset
11310
11311  is most efficient at accessing variables (especially pointers) stored here.
11312
11313 \layout Subsubsection
11314 xdata
11315 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11316
11317 \end_inset
11318
11319
11320 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11321
11322 \end_inset
11323
11324  
11325
11326 \layout Standard
11327 \added_space_bottom bigskip 
11328 The xdata storage class declares a variable that can reside anywhere in
11329  memory.
11330  This is the default if no storage class is specified.
11331  
11332
11333
11334
11335 \layout Section
11336 Absolute Addressing
11337 \begin_inset LatexCommand \index{Absolute addressing}
11338
11339 \end_inset
11340
11341
11342
11343 \layout Standard
11344 Data items can be assigned an absolute address with the 
11345 \emph on
11346 at
11347 \begin_inset LatexCommand \index{at}
11348
11349 \end_inset
11350
11351
11352 \begin_inset LatexCommand \index{\_\_at}
11353
11354 \end_inset
11355
11356  <address>
11357 \emph default
11358  keyword, in addition to a storage class, e.g.:
11359
11360 \layout Verse
11361
11362 \family typewriter
11363 xdata
11364 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11365
11366 \end_inset
11367
11368
11369 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11370
11371 \end_inset
11372
11373  at
11374 \begin_inset LatexCommand \index{at}
11375
11376 \end_inset
11377
11378
11379 \begin_inset LatexCommand \index{\_\_at}
11380
11381 \end_inset
11382
11383  0x7ffe unsigned int chksum;
11384
11385 \layout Standard
11386 or, better conforming to ISO/IEC 9899 C:
11387
11388 \layout Verse
11389
11390 \family typewriter
11391 __xdata __at (0x7ffe) unsigned int chksum;
11392
11393 \layout Standard
11394 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11395  of the external ram.
11396  The compiler does 
11397 \emph on
11398 not
11399 \emph default
11400  reserve any space for variables declared in this way
11401 \begin_inset Marginal
11402 collapsed true
11403
11404 \layout Standard
11405
11406 \series bold
11407 \SpecialChar ~
11408 !
11409
11410 \end_inset
11411
11412  (they are implemented with an equate in the assembler).
11413  Thus it is left to the programmer to make sure there are no overlaps with
11414  other variables that are declared without the absolute address.
11415  The assembler listing file (.lst
11416 \begin_inset LatexCommand \index{<file>.lst}
11417
11418 \end_inset
11419
11420 ) and the linker output files (.rst
11421 \begin_inset LatexCommand \index{<file>.rst}
11422
11423 \end_inset
11424
11425 ) and (.map
11426 \begin_inset LatexCommand \index{<file>.map}
11427
11428 \end_inset
11429
11430 ) are good places to look for such overlaps.
11431  Variables with an absolute address are 
11432 \emph on
11433 not
11434 \begin_inset Marginal
11435 collapsed true
11436
11437 \layout Standard
11438
11439 \series bold
11440 \SpecialChar ~
11441 !
11442
11443 \end_inset
11444
11445
11446 \emph default
11447  initialized
11448 \begin_inset LatexCommand \index{Variable initialization}
11449
11450 \end_inset
11451
11452 .
11453
11454 \layout Standard
11455 In case of memory mapped I/O devices the keyword 
11456 \emph on
11457 volatile
11458 \emph default
11459  has to be used to tell the compiler that accesses might not be removed:
11460
11461 \layout Verse
11462
11463 \family typewriter
11464 volatile
11465 \begin_inset LatexCommand \index{volatile}
11466
11467 \end_inset
11468
11469  __xdata
11470 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11471
11472 \end_inset
11473
11474  __at
11475 \begin_inset LatexCommand \index{at}
11476
11477 \end_inset
11478
11479  (0x8000) unsigned char PORTA_8255;
11480
11481 \layout Standard
11482 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11483 r) array
11484 \family typewriter
11485 \size footnotesize
11486
11487 \begin_inset LatexCommand \index{Aligned array}
11488
11489 \end_inset
11490
11491
11492 \family default
11493 \size default
11494  starts at a block (256 byte) boundary
11495 \begin_inset LatexCommand \index{block boundary}
11496
11497 \end_inset
11498
11499  (section 
11500 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11501
11502 \end_inset
11503
11504  has an example).
11505 \newline
11506 Absolute addresses can be specified for variables in all
11507  storage classes, e.g.:
11508
11509 \layout Verse
11510
11511 \family typewriter
11512 __bit
11513 \begin_inset LatexCommand \index{bit}
11514
11515 \end_inset
11516
11517  __at
11518 \begin_inset LatexCommand \index{at}
11519
11520 \end_inset
11521
11522  (0x02) bvar;
11523
11524 \layout Standard
11525 The above example will allocate the variable at offset 0x02 in the bit-addressab
11526 le space.
11527  There is no real advantage to assigning absolute addresses to variables
11528  in this manner, unless you want strict control over all the variables allocated.
11529  One possible use would be to write hardware portable code.
11530  For example, if you have a routine that uses one or more of the microcontroller
11531  I/O pins, and such pins are different for two different hardwares, you
11532  can declare the I/O pins in your routine using:
11533
11534 \layout Verse
11535
11536 \family typewriter
11537 extern volatile
11538 \begin_inset LatexCommand \index{volatile}
11539
11540 \end_inset
11541
11542  __bit MOSI;\SpecialChar ~
11543 \SpecialChar ~
11544 \SpecialChar ~
11545 \SpecialChar ~
11546 /* master out, slave in */
11547 \newline
11548 extern volatile __bit MISO;\SpecialChar ~
11549 \SpecialChar ~
11550 \SpecialChar ~
11551 \SpecialChar ~
11552 /* master
11553  in, slave out */
11554 \newline
11555 extern volatile __bit MCLK;\SpecialChar ~
11556 \SpecialChar ~
11557 \SpecialChar ~
11558 \SpecialChar ~
11559 /* master clock */
11560 \newline
11561
11562 \newline
11563 /* Input and
11564  Output of a byte on a 3-wire serial bus.
11565 \newline
11566 \SpecialChar ~
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 If needed adapt polarity of clock,
11570  polarity of data and bit order
11571 \newline
11572 \SpecialChar ~
11573 */
11574 \newline
11575 unsigned char spi_io(unsigned char out_byte)
11576  
11577 \newline
11578
11579 \newline
11580 \SpecialChar ~
11581 \SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 unsigned char i=8;
11585 \newline
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 \SpecialChar ~
11590 do { 
11591 \newline
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 \SpecialChar ~
11596 \SpecialChar ~
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 MOSI = out_byte & 0x80; 
11601 \newline
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 \SpecialChar ~
11606 \SpecialChar ~
11607 \SpecialChar ~
11608 \SpecialChar ~
11609 \SpecialChar ~
11610 out_byte <<= 1;
11611 \newline
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 \SpecialChar ~
11618 \SpecialChar ~
11619 \SpecialChar ~
11620 MCLK =
11621  1; 
11622 \newline
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 /* _asm nop _endasm; */\SpecialChar ~
11632 \SpecialChar ~
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 /* for slow peripherals */
11640 \newline
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 \SpecialChar ~
11648 \SpecialChar ~
11649 if(MISO) 
11650 \newline
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 \SpecialChar ~
11656 \SpecialChar ~
11657 \SpecialChar ~
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 \SpecialChar ~
11662 \SpecialChar ~
11663 out_byte +=
11664  1; 
11665 \newline
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 MCLK = 0; 
11675 \newline
11676 \SpecialChar ~
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 } while(--i);
11681 \newline
11682 \SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 return out_byte; 
11687 \newline
11688 }
11689
11690 \layout Standard
11691 Then, someplace in the code for the first hardware you would use
11692
11693 \layout Verse
11694
11695 \family typewriter
11696 __bit __at
11697 \begin_inset LatexCommand \index{at}
11698
11699 \end_inset
11700
11701
11702 \begin_inset LatexCommand \index{\_\_at}
11703
11704 \end_inset
11705
11706  (0x80) MOSI;\SpecialChar ~
11707 \SpecialChar ~
11708 \SpecialChar ~
11709 \SpecialChar ~
11710 /* I/O port 0, bit 0 */
11711 \newline
11712 __bit __at (0x81) MISO;\SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716 /* I/O port 0,
11717  bit 1 */
11718 \newline
11719 __bit __at (0x82) MCLK;\SpecialChar ~
11720 \SpecialChar ~
11721 \SpecialChar ~
11722 \SpecialChar ~
11723 /* I/O port 0, bit 2 */
11724
11725 \layout Standard
11726 Similarly, for the second hardware you would use
11727
11728 \layout Verse
11729
11730 \family typewriter
11731 __bit __at (0x83) MOSI;\SpecialChar ~
11732 \SpecialChar ~
11733 \SpecialChar ~
11734 \SpecialChar ~
11735 /* I/O port 0, bit 3 */
11736 \newline
11737 __bit __at (0x91) MISO;\SpecialChar ~
11738 \SpecialChar ~
11739 \SpecialChar ~
11740 \SpecialChar ~
11741 /*
11742  I/O port 1, bit 1 */
11743 \newline
11744 __bit
11745 \begin_inset LatexCommand \index{bit}
11746
11747 \end_inset
11748
11749  __at (0x92) MCLK;\SpecialChar ~
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 /* I/O port 1, bit 2 */
11754
11755 \layout Standard
11756 \added_space_bottom bigskip 
11757 and you can use the same hardware dependent routine without changes, as
11758  for example in a library.
11759  This is somehow similar to sbit, but only one absolute address has to be
11760  specified in the whole project.
11761
11762
11763
11764 \layout Section
11765 Parameters
11766 \begin_inset LatexCommand \index{Parameters}
11767
11768 \end_inset
11769
11770
11771 \begin_inset LatexCommand \index{function parameter}
11772
11773 \end_inset
11774
11775  & Local Variables
11776 \begin_inset LatexCommand \index{local variables}
11777
11778 \end_inset
11779
11780
11781 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11782
11783 \end_inset
11784
11785
11786
11787 \layout Standard
11788 Automatic (local) variables and parameters to functions can either be placed
11789  on the stack or in data-space.
11790  The default action of the compiler is to place these variables in the internal
11791  RAM (for small model) or external RAM (for large model).
11792  This in fact makes them similar to 
11793 \emph on
11794 static
11795 \begin_inset LatexCommand \index{static}
11796
11797 \end_inset
11798
11799
11800 \emph default
11801  so by default functions are non-reentrant
11802 \begin_inset LatexCommand \index{reentrant}
11803
11804 \end_inset
11805
11806 .
11807  
11808 \newline
11809
11810 \newline
11811 They can be placed on the stack
11812 \begin_inset LatexCommand \index{stack}
11813
11814 \end_inset
11815
11816  by using the
11817 \emph on
11818  -
11819 \begin_inset ERT
11820 status Collapsed
11821
11822 \layout Standard
11823
11824
11825 \backslash
11826 /
11827
11828 \end_inset
11829
11830 -stack-auto
11831 \begin_inset LatexCommand \index{-\/-stack-auto}
11832
11833 \end_inset
11834
11835
11836 \emph default
11837  option, by using 
11838 \emph on
11839 #pragma\SpecialChar ~
11840 stackauto
11841 \emph default
11842
11843 \begin_inset LatexCommand \index{\#pragma stackauto}
11844
11845 \end_inset
11846
11847  or by using the 
11848 \emph on
11849 reentrant
11850 \begin_inset LatexCommand \index{reentrant}
11851
11852 \end_inset
11853
11854
11855 \emph default
11856  keyword in the function declaration, e.g.:
11857
11858 \layout Verse
11859
11860 \family typewriter
11861 unsigned char foo(char i) __reentrant 
11862 \newline
11863
11864 \newline
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 ...
11870  
11871 \newline
11872 }
11873
11874 \layout Standard
11875 Since stack space on 8051 is limited, the 
11876 \emph on
11877 reentrant 
11878 \emph default
11879 keyword or the
11880 \emph on
11881  -
11882 \begin_inset ERT
11883 status Collapsed
11884
11885 \layout Standard
11886
11887
11888 \backslash
11889 /
11890
11891 \end_inset
11892
11893 -stack-auto
11894 \emph default
11895  option should be used sparingly.
11896  Note that the reentrant keyword just means that the parameters & local
11897  variables will be allocated to the stack, it 
11898 \emph on
11899 does not
11900 \emph default
11901  mean that the function is register bank
11902 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11903
11904 \end_inset
11905
11906  independent.
11907 \newline
11908
11909 \newline
11910 Local variables
11911 \begin_inset LatexCommand \index{local variables}
11912
11913 \end_inset
11914
11915  can be assigned storage classes and absolute
11916 \begin_inset LatexCommand \index{Absolute addressing}
11917
11918 \end_inset
11919
11920  addresses, e.g.: 
11921
11922 \layout Verse
11923
11924 \family typewriter
11925 unsigned char foo() 
11926 \newline
11927 {
11928 \newline
11929 \SpecialChar ~
11930 \SpecialChar ~
11931 \SpecialChar ~
11932 \SpecialChar ~
11933 __xdata unsigned char i;
11934 \newline
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 __bit bvar;
11940 \newline
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 \SpecialChar ~
11944 \SpecialChar ~
11945 __data __at
11946 \begin_inset LatexCommand \index{at}
11947
11948 \end_inset
11949
11950  (0x31) unsigned char j;
11951 \newline
11952 \SpecialChar ~
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 ...
11957  
11958 \newline
11959 }
11960
11961 \layout Standard
11962 In the above example the variable 
11963 \emph on
11964 i
11965 \emph default
11966  will be allocated in the external ram, 
11967 \emph on
11968 bvar
11969 \emph default
11970  in bit addressable space and
11971 \emph on
11972  j
11973 \emph default
11974  in internal ram.
11975  When compiled with 
11976 \emph on
11977 -
11978 \begin_inset ERT
11979 status Collapsed
11980
11981 \layout Standard
11982
11983
11984 \backslash
11985 /
11986
11987 \end_inset
11988
11989 -stack-auto
11990 \emph default
11991  or when a function is declared as 
11992 \emph on
11993 reentrant
11994 \emph default
11995  this should only be done for static variables.
11996
11997 \layout Standard
11998 Parameters
11999 \begin_inset LatexCommand \index{function parameter}
12000
12001 \end_inset
12002
12003  however are not allowed any storage class
12004 \begin_inset LatexCommand \index{Storage class}
12005
12006 \end_inset
12007
12008 , (storage classes for parameters will be ignored), their allocation is
12009  governed by the memory model in use, and the reentrancy options.
12010
12011 \layout Standard
12012 It is however allowed to use bit parameters in reentrant functions and also
12013  non-static local bit variables are supported.
12014  Efficient use is limited to 8 semi-bitregisters in bit space.
12015  They are pushed and popped to stack
12016 \begin_inset LatexCommand \index{stack}
12017
12018 \end_inset
12019
12020  as a single byte just like the normal registers.
12021
12022 \layout Section
12023 Overlaying
12024 \begin_inset LatexCommand \label{sub:Overlaying}
12025
12026 \end_inset
12027
12028
12029 \begin_inset LatexCommand \index{Overlaying}
12030
12031 \end_inset
12032
12033
12034
12035 \layout Standard
12036 For non-reentrant
12037 \begin_inset LatexCommand \index{reentrant}
12038
12039 \end_inset
12040
12041  functions SDCC will try to reduce internal ram space usage by overlaying
12042  parameters and local variables of a function (if possible).
12043  Parameters and local variables
12044 \begin_inset LatexCommand \index{local variables}
12045
12046 \end_inset
12047
12048  of a function will be allocated to an overlayable segment if the function
12049  has 
12050 \emph on
12051 no other function calls and the function is non-reentrant and the memory
12052  model
12053 \begin_inset LatexCommand \index{Memory model}
12054
12055 \end_inset
12056
12057  is small.
12058
12059 \emph default
12060  If an explicit storage class
12061 \begin_inset LatexCommand \index{Storage class}
12062
12063 \end_inset
12064
12065  is specified for a local variable, it will NOT be overlayed.
12066
12067 \layout Standard
12068 Note that the compiler (not the linkage editor) makes the decision for overlayin
12069 g the data items.
12070  Functions that are called from an interrupt service routine
12071 \begin_inset Marginal
12072 collapsed true
12073
12074 \layout Standard
12075
12076 \series bold
12077 !
12078
12079 \end_inset
12080
12081  should be preceded by a #pragma\SpecialChar ~
12082 nooverlay
12083 \begin_inset LatexCommand \index{\#pragma nooverlay}
12084
12085 \end_inset
12086
12087  if they are not reentrant.
12088
12089 \layout Standard
12090 Also note that the compiler does not do any processing of inline assembler
12091  code, so the compiler might incorrectly assign local variables and parameters
12092  of a function into the overlay segment if the inline assembler code calls
12093  other c-functions that might use the overlay.
12094  In that case the #pragma\SpecialChar ~
12095 nooverlay should be used.
12096
12097 \layout Standard
12098 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12099 tion
12100 \begin_inset LatexCommand \index{Multiplication}
12101
12102 \end_inset
12103
12104  or division
12105 \begin_inset LatexCommand \index{Division}
12106
12107 \end_inset
12108
12109  will NOT be overlayed since these are implemented using external functions,
12110  e.g.:
12111
12112 \layout Verse
12113
12114 \family typewriter
12115 #pragma save 
12116 \newline
12117 #pragma nooverlay
12118 \begin_inset LatexCommand \index{\#pragma nooverlay}
12119
12120 \end_inset
12121
12122  
12123 \newline
12124 void set_error(unsigned char errcd) 
12125 \newline
12126 {
12127 \newline
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 P3 = errcd;
12133 \newline
12134
12135 \newline
12136 #pragma restore 
12137 \newline
12138
12139 \newline
12140 void
12141  some_isr () __interrupt
12142 \begin_inset LatexCommand \index{interrupt}
12143
12144 \end_inset
12145
12146  (2)
12147 \newline
12148 {
12149 \newline
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 ...
12155 \newline
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 set_error(10);
12161 \newline
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 ...
12167  
12168 \newline
12169 }
12170
12171 \layout Standard
12172 \added_space_bottom bigskip 
12173 In the above example the parameter 
12174 \emph on
12175 errcd
12176 \emph default
12177  for the function 
12178 \emph on
12179 set_error
12180 \emph default
12181  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12182 nooverlay was
12183  not present, this could cause unpredictable runtime behavior when called
12184  from an interrupt service routine.
12185  The #pragma\SpecialChar ~
12186 nooverlay ensures that the parameters and local variables for
12187  the function are NOT overlayed.
12188
12189
12190
12191 \layout Section
12192 Interrupt Service Routines
12193 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12194
12195 \end_inset
12196
12197
12198
12199 \layout Subsection
12200 General Information
12201
12202 \layout Standard
12203 SDCC allows 
12204 \emph on
12205 i
12206 \emph default
12207 nterrupt 
12208 \emph on
12209 s
12210 \emph default
12211 ervice 
12212 \emph on
12213 r
12214 \emph default
12215 outines to be coded in C, with some extended keywords.
12216
12217 \layout Verse
12218
12219 \family typewriter
12220 void timer_isr (void) __interrupt (1) __using (1) 
12221 \newline
12222
12223 \newline
12224 \SpecialChar ~
12225 \SpecialChar ~
12226 \SpecialChar ~
12227 \SpecialChar ~
12228 ...
12229  
12230 \newline
12231 }
12232
12233 \layout Standard
12234 The optional number following the 
12235 \emph on
12236 interrupt
12237 \begin_inset LatexCommand \index{interrupt}
12238
12239 \end_inset
12240
12241
12242 \begin_inset LatexCommand \index{\_\_interrupt}
12243
12244 \end_inset
12245
12246
12247 \emph default
12248  keyword is the interrupt number this routine will service.
12249  When present, the compiler will insert a call to this routine in the interrupt
12250  vector table
12251 \begin_inset LatexCommand \index{interrupt vector table}
12252
12253 \end_inset
12254
12255  for the interrupt number specified.
12256  If you have multiple source files in your project, interrupt service routines
12257  can be present in any of them, but a prototype of the isr MUST be present
12258  or included in the file that contains the function 
12259 \emph on
12260 main
12261 \emph default
12262 .
12263  The optional (8051 specific) keyword 
12264 \emph on
12265 using
12266 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12267
12268 \end_inset
12269
12270
12271 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12272
12273 \end_inset
12274
12275
12276 \emph default
12277  can be used to tell the compiler to use the specified register bank when
12278  generating code for this function.
12279  
12280 \newline
12281 Interrupt service routines open the door for some very interesting bugs:
12282
12283 \layout Subsubsection
12284 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12285
12286 \end_inset
12287
12288 Common interrupt pitfall: variable not declared 
12289 \emph on
12290 volatile
12291
12292 \layout Standard
12293 If an interrupt service routine changes variables which are accessed by
12294  other functions these variables have to be declared 
12295 \emph on
12296 volatile
12297 \emph default
12298
12299 \begin_inset LatexCommand \index{volatile}
12300
12301 \end_inset
12302
12303 .
12304  See 
12305 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12306
12307 \end_inset
12308
12309  .
12310
12311 \layout Subsubsection
12312 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12313
12314 \end_inset
12315
12316 Common interrupt pitfall: 
12317 \emph on
12318 non-atomic access
12319
12320 \layout Standard
12321 If the access to these variables is not 
12322 \emph on
12323 atomic
12324 \begin_inset LatexCommand \index{atomic}
12325
12326 \end_inset
12327
12328
12329 \emph default
12330  (i.e.
12331  the processor needs more than one instruction for the access and could
12332  be interrupted while accessing the variable) the interrupt must be disabled
12333  during the access to avoid inconsistent data.
12334  
12335 \newline
12336 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12337  and should be protected by disabling interrupts.
12338  You're not automatically on the safe side if you use 8 bit variables though.
12339  We need an example here: f.e.
12340  on the 8051 the harmless looking 
12341 \begin_inset Quotes srd
12342 \end_inset
12343
12344
12345 \family typewriter
12346 flags\SpecialChar ~
12347 |=\SpecialChar ~
12348 0x80;
12349 \family default
12350
12351 \begin_inset Quotes sld
12352 \end_inset
12353
12354  is not atomic if 
12355 \family typewriter
12356 flags
12357 \family default
12358  resides in xdata.
12359  Setting 
12360 \begin_inset Quotes srd
12361 \end_inset
12362
12363
12364 \family typewriter
12365 flags\SpecialChar ~
12366 |=\SpecialChar ~
12367 0x40;
12368 \family default
12369
12370 \begin_inset Quotes sld
12371 \end_inset
12372
12373  from within an interrupt routine might get lost if the interrupt occurs
12374  at the wrong time.
12375  
12376 \begin_inset Quotes sld
12377 \end_inset
12378
12379
12380 \family typewriter
12381 counter\SpecialChar ~
12382 +=\SpecialChar ~
12383 8;
12384 \family default
12385
12386 \begin_inset Quotes srd
12387 \end_inset
12388
12389  is not atomic on the 8051 even if 
12390 \family typewriter
12391 counter
12392 \family default
12393  is located in data memory.
12394 \newline
12395 Bugs like these are hard to reproduce and can
12396  cause a lot of trouble.
12397  
12398
12399 \layout Subsubsection
12400 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12401
12402 \end_inset
12403
12404 Common interrupt pitfall: 
12405 \emph on
12406 stack overflow
12407
12408 \layout Standard
12409 The return address and the registers used in the interrupt service routine
12410  are saved on the stack
12411 \begin_inset LatexCommand \index{stack}
12412
12413 \end_inset
12414
12415  so there must be sufficient stack space.
12416  If there isn't variables or registers (or even the return address itself)
12417  will be corrupted.
12418  This 
12419 \emph on
12420 stack overflow
12421 \emph default
12422
12423 \begin_inset LatexCommand \index{stack overflow}
12424
12425 \end_inset
12426
12427  is most likely to happen if the interrupt occurs during the 
12428 \begin_inset Quotes sld
12429 \end_inset
12430
12431 deepest
12432 \begin_inset Quotes srd
12433 \end_inset
12434
12435  subroutine when the stack is already in use for f.e.
12436  many return addresses.
12437
12438 \layout Subsubsection
12439 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12440
12441 \end_inset
12442
12443 Common interrupt pitfall: 
12444 \emph on
12445 use of non-reentrant functions
12446
12447 \layout Standard
12448 A special note here, int (16 bit) and long (32 bit) integer division
12449 \begin_inset LatexCommand \index{Division}
12450
12451 \end_inset
12452
12453 , multiplication
12454 \begin_inset LatexCommand \index{Multiplication}
12455
12456 \end_inset
12457
12458  & modulus
12459 \begin_inset LatexCommand \index{Modulus}
12460
12461 \end_inset
12462
12463  and floating-point
12464 \begin_inset LatexCommand \index{Floating point support}
12465
12466 \end_inset
12467
12468  operations are implemented using external support routines.
12469  If an interrupt service routine needs to do any of these operations then
12470  the support routines (as mentioned in a following section) will have to
12471  be recompiled using the
12472 \emph on
12473  -
12474 \begin_inset ERT
12475 status Collapsed
12476
12477 \layout Standard
12478
12479
12480 \backslash
12481 /
12482
12483 \end_inset
12484
12485 -stack-auto
12486 \begin_inset LatexCommand \index{-\/-stack-auto}
12487
12488 \end_inset
12489
12490
12491 \emph default
12492  option and the source file will need to be compiled using the 
12493 \emph on
12494 -
12495 \begin_inset ERT
12496 status Collapsed
12497
12498 \layout Standard
12499
12500
12501 \backslash
12502 /
12503
12504 \end_inset
12505
12506 -int-long-reent
12507 \emph default
12508
12509 \begin_inset LatexCommand \index{-\/-int-long-reent}
12510
12511 \end_inset
12512
12513  compiler option.
12514  
12515 \newline
12516 Note, the type promotion
12517 \begin_inset LatexCommand \index{type promotion}
12518
12519 \end_inset
12520
12521  required by ANSI C can cause 16 bit routines to be used
12522 \begin_inset Marginal
12523 collapsed true
12524
12525 \layout Standard
12526
12527 \series bold
12528 \SpecialChar ~
12529 !
12530
12531 \end_inset
12532
12533  without the programmer being aware of it.
12534  See f.e.
12535  the cast 
12536 \family typewriter
12537 (unsigned char)(tail-1)
12538 \family default
12539  within the if clause in section 
12540 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12541
12542 \end_inset
12543
12544 .
12545
12546 \layout Standard
12547 \added_space_bottom bigskip 
12548 Calling other functions from an interrupt service routine is not recommended,
12549  avoid it if possible.
12550  Note that when some function is called from an interrupt service routine
12551  it should be preceded by a #pragma\SpecialChar ~
12552 nooverlay
12553 \begin_inset LatexCommand \index{\#pragma nooverlay}
12554
12555 \end_inset
12556
12557  if it is not reentrant.
12558  Furthermore nonreentrant functions should not be called from the main program
12559  while the interrupt service routine might be active.
12560  They also must not be called from low priority interrupt service routines
12561  while a high priority interrupt service routine might be active.
12562  You could use semaphores or make the function
12563 \emph on
12564  critical
12565 \emph default
12566  if all parameters are passed in registers.
12567 \newline
12568  Also see section 
12569 \begin_inset LatexCommand \ref{sub:Overlaying}
12570
12571 \end_inset
12572
12573 \SpecialChar ~
12574 about Overlaying and section 
12575 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12576
12577 \end_inset
12578
12579 \SpecialChar ~
12580 about Functions using private register banks.
12581
12582
12583
12584 \layout Subsection
12585 MCS51/DS390 Interrupt Service Routines
12586
12587 \layout Standard
12588 Interrupt
12589 \begin_inset LatexCommand \index{interrupt}
12590
12591 \end_inset
12592
12593  numbers and the corresponding address & descriptions for the Standard 8051/8052
12594  are listed below.
12595  SDCC will automatically adjust the 
12596 \begin_inset LatexCommand \index{interrupt vector table}
12597
12598 \end_inset
12599
12600  to the maximum interrupt number specified.
12601 \newline
12602
12603
12604 \layout Standard
12605 \align center
12606 \begin_inset Tabular
12607 <lyxtabular version="3" rows="9" columns="3">
12608 <features>
12609 <column alignment="center" valignment="top" leftline="true" width="0in">
12610 <column alignment="left" valignment="top" leftline="true" width="0in">
12611 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12612 <row topline="true" bottomline="true">
12613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12614 \begin_inset Text
12615
12616 \layout Standard
12617 Interrupt #
12618
12619 \end_inset
12620 </cell>
12621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12622 \begin_inset Text
12623
12624 \layout Standard
12625 Description
12626
12627 \end_inset
12628 </cell>
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12630 \begin_inset Text
12631
12632 \layout Standard
12633 Vector Address
12634
12635 \end_inset
12636 </cell>
12637 </row>
12638 <row topline="true">
12639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12640 \begin_inset Text
12641
12642 \layout Standard
12643 0
12644
12645 \end_inset
12646 </cell>
12647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12648 \begin_inset Text
12649
12650 \layout Standard
12651 External 0
12652
12653 \end_inset
12654 </cell>
12655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12656 \begin_inset Text
12657
12658 \layout Standard
12659 0x0003
12660
12661 \end_inset
12662 </cell>
12663 </row>
12664 <row topline="true">
12665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12666 \begin_inset Text
12667
12668 \layout Standard
12669 1
12670
12671 \end_inset
12672 </cell>
12673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12674 \begin_inset Text
12675
12676 \layout Standard
12677 Timer 0
12678
12679 \end_inset
12680 </cell>
12681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12682 \begin_inset Text
12683
12684 \layout Standard
12685 0x000b
12686
12687 \end_inset
12688 </cell>
12689 </row>
12690 <row topline="true">
12691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12692 \begin_inset Text
12693
12694 \layout Standard
12695 2
12696
12697 \end_inset
12698 </cell>
12699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12700 \begin_inset Text
12701
12702 \layout Standard
12703 External 1
12704
12705 \end_inset
12706 </cell>
12707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12708 \begin_inset Text
12709
12710 \layout Standard
12711 0x0013
12712
12713 \end_inset
12714 </cell>
12715 </row>
12716 <row topline="true">
12717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12718 \begin_inset Text
12719
12720 \layout Standard
12721 3
12722
12723 \end_inset
12724 </cell>
12725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12726 \begin_inset Text
12727
12728 \layout Standard
12729 Timer 1
12730
12731 \end_inset
12732 </cell>
12733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12734 \begin_inset Text
12735
12736 \layout Standard
12737 0x001b
12738
12739 \end_inset
12740 </cell>
12741 </row>
12742 <row topline="true">
12743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12744 \begin_inset Text
12745
12746 \layout Standard
12747 4
12748
12749 \end_inset
12750 </cell>
12751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12752 \begin_inset Text
12753
12754 \layout Standard
12755 Serial
12756
12757 \end_inset
12758 </cell>
12759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12760 \begin_inset Text
12761
12762 \layout Standard
12763 0x0023
12764
12765 \end_inset
12766 </cell>
12767 </row>
12768 <row topline="true">
12769 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12770 \begin_inset Text
12771
12772 \layout Standard
12773 5
12774
12775 \end_inset
12776 </cell>
12777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12778 \begin_inset Text
12779
12780 \layout Standard
12781 Timer 2 (8052)
12782
12783 \end_inset
12784 </cell>
12785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12786 \begin_inset Text
12787
12788 \layout Standard
12789 0x002b
12790
12791 \end_inset
12792 </cell>
12793 </row>
12794 <row topline="true">
12795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12796 \begin_inset Text
12797
12798 \layout Standard
12799 ...
12800
12801 \end_inset
12802 </cell>
12803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12804 \begin_inset Text
12805
12806 \layout Standard
12807
12808
12809 \end_inset
12810 </cell>
12811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12812 \begin_inset Text
12813
12814 \layout Standard
12815 ...
12816
12817 \end_inset
12818 </cell>
12819 </row>
12820 <row topline="true" bottomline="true">
12821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12822 \begin_inset Text
12823
12824 \layout Standard
12825 n
12826
12827 \end_inset
12828 </cell>
12829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12830 \begin_inset Text
12831
12832 \layout Standard
12833
12834
12835 \end_inset
12836 </cell>
12837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12838 \begin_inset Text
12839
12840 \layout Standard
12841 0x0003 + 8*n
12842
12843 \end_inset
12844 </cell>
12845 </row>
12846 </lyxtabular>
12847
12848 \end_inset
12849
12850
12851 \newline
12852
12853
12854 \layout Standard
12855 If the interrupt service routine is defined without 
12856 \emph on
12857 using
12858 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12859
12860 \end_inset
12861
12862
12863 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12864
12865 \end_inset
12866
12867
12868 \emph default
12869  a register bank or with register bank 0 (
12870 \emph on
12871 using
12872 \emph default
12873  0), the compiler will save the registers used by itself on the stack upon
12874  entry and restore them at exit, however if such an interrupt service routine
12875  calls another function then the entire register bank will be saved on the
12876  stack.
12877  This scheme may be advantageous for small interrupt service routines which
12878  have low register usage.
12879
12880 \layout Standard
12881 \added_space_bottom bigskip 
12882 If the interrupt service routine is defined to be using a specific register
12883  bank then only 
12884 \emph on
12885 a, b, dptr
12886 \emph default
12887  & psw are saved and restored, if such an interrupt service routine calls
12888  another function (using another register bank) then the entire register
12889  bank of the called function will be saved on the stack
12890 \begin_inset LatexCommand \index{stack}
12891
12892 \end_inset
12893
12894 .
12895  This scheme is recommended for larger interrupt service routines.
12896
12897
12898
12899 \layout Subsection
12900 HC08
12901 \begin_inset LatexCommand \index{HC08}
12902
12903 \end_inset
12904
12905  Interrupt Service Routines
12906
12907 \layout Standard
12908 \added_space_bottom bigskip 
12909 Since the number of interrupts
12910 \begin_inset LatexCommand \index{HC08!interrupt}
12911
12912 \end_inset
12913
12914  available is chip specific and the interrupt vector table always ends at
12915  the last byte of memory, the interrupt numbers corresponds to the interrupt
12916  vectors in reverse order of address.
12917  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12918  2 will use the interrupt vector at 0xfffa, and so on.
12919  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12920  this way; instead see section 
12921 \begin_inset LatexCommand \ref{sub:Startup-Code}
12922
12923 \end_inset
12924
12925  for details on customizing startup.
12926
12927
12928
12929 \layout Subsection
12930 Z80 Interrupt Service Routines
12931
12932 \layout Standard
12933 The Z80
12934 \begin_inset LatexCommand \index{Z80}
12935
12936 \end_inset
12937
12938  uses several different methods for determining the correct interrupt
12939 \begin_inset LatexCommand \index{Z80!interrupt}
12940
12941 \end_inset
12942
12943  vector depending on the hardware implementation.
12944  Therefore, SDCC ignores the optional interrupt number and does not attempt
12945  to generate an interrupt vector table.
12946
12947 \layout Standard
12948 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12949  instruction to return from the interrupt.
12950  To write an interrupt handler for the non-maskable interrupt, which needs
12951  a RETN instruction instead, add the 
12952 \emph on
12953 critical
12954 \emph default
12955  keyword:
12956
12957 \layout Verse
12958
12959 \family typewriter
12960 void nmi_isr (void) critical interrupt
12961 \newline
12962
12963 \newline
12964 \SpecialChar ~
12965 \SpecialChar ~
12966 \SpecialChar ~
12967 \SpecialChar ~
12968 ...
12969  
12970 \newline
12971 }
12972
12973 \layout Standard
12974 \added_space_bottom bigskip 
12975 However if you need to create a non-interruptable interrupt service routine
12976  you would also require the 
12977 \emph on
12978 critical
12979 \emph default
12980  keyword.
12981  To distinguish between this and an nmi_isr you must provide an interrupt
12982  number.
12983
12984
12985
12986 \layout Section
12987 Enabling and Disabling Interrupts
12988
12989 \layout Subsection
12990 Critical Functions and Critical Statements
12991
12992 \layout Standard
12993 A special keyword may be associated with a block or a function declaring
12994  it as 
12995 \emph on
12996 critical
12997 \emph default
12998 .
12999  SDCC will generate code to disable all interrupts
13000 \begin_inset LatexCommand \index{interrupt}
13001
13002 \end_inset
13003
13004  upon entry to a critical function and restore the interrupt enable to the
13005  previous state before returning.
13006  Nesting critical functions will need one additional byte on the stack
13007 \begin_inset LatexCommand \index{stack}
13008
13009 \end_inset
13010
13011  for each call.
13012
13013 \layout Verse
13014
13015 \family typewriter
13016 int foo () __critical
13017 \begin_inset LatexCommand \index{critical}
13018
13019 \end_inset
13020
13021
13022 \begin_inset LatexCommand \index{\_\_critical}
13023
13024 \end_inset
13025
13026  
13027 \newline
13028
13029 \newline
13030 \SpecialChar ~
13031 \SpecialChar ~
13032 \SpecialChar ~
13033 \SpecialChar ~
13034 ...
13035  
13036 \newline
13037 \SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 \SpecialChar ~
13041 ...
13042  
13043 \newline
13044 }
13045
13046 \layout Standard
13047 The critical attribute maybe used with other attributes like 
13048 \emph on
13049 reentrant.
13050 \emph default
13051
13052 \newline
13053 The keyword 
13054 \emph on
13055 critical
13056 \emph default
13057  may also be used to disable interrupts more locally:
13058
13059 \layout Verse
13060
13061 \family typewriter
13062 __critical{ i++; }
13063
13064 \layout Standard
13065 More than one statement could have been included in the block.
13066
13067 \layout Subsection
13068 Enabling and Disabling Interrupts directly
13069
13070 \layout Standard
13071 Interrupts
13072 \begin_inset LatexCommand \index{interrupt}
13073
13074 \end_inset
13075
13076  can also be disabled and enabled directly (8051):
13077
13078 \layout Verse
13079
13080 \family typewriter
13081 EA = 0;\SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 \SpecialChar ~
13085 \SpecialChar ~
13086 \SpecialChar ~
13087 \SpecialChar ~
13088 \SpecialChar ~
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 or:\SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 \SpecialChar ~
13101 \SpecialChar ~
13102 \SpecialChar ~
13103 \SpecialChar ~
13104 EA_SAVE = EA;
13105
13106 \layout Verse
13107
13108 \family typewriter
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 \SpecialChar ~
13137 \SpecialChar ~
13138 \SpecialChar ~
13139 EA = 0;
13140
13141 \layout Verse
13142
13143 \family typewriter
13144 EA = 1;\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 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 ...
13171
13172 \layout Verse
13173
13174 \family typewriter
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 \SpecialChar ~
13206 \SpecialChar ~
13207 \SpecialChar ~
13208 EA = EA_SAVE;
13209
13210 \layout Standard
13211 On other architectures which have seperate opcodes for enabling and disabling
13212  interrupts you might want to make use of defines with inline assembly
13213 \begin_inset LatexCommand \index{Assembler routines}
13214
13215 \end_inset
13216
13217  (HC08
13218 \begin_inset LatexCommand \index{HC08!interrupt}
13219
13220 \end_inset
13221
13222 ):
13223
13224 \layout Verse
13225
13226 \family typewriter
13227 #define CLI _asm
13228 \begin_inset LatexCommand \index{\_asm}
13229
13230 \end_inset
13231
13232 \SpecialChar ~
13233 \SpecialChar ~
13234 cli\SpecialChar ~
13235 \SpecialChar ~
13236 _endasm
13237 \begin_inset LatexCommand \index{\_endasm}
13238
13239 \end_inset
13240
13241
13242
13243 \layout Verse
13244
13245 \family typewriter
13246 #define SEI _asm\SpecialChar ~
13247 \SpecialChar ~
13248 sei\SpecialChar ~
13249 \SpecialChar ~
13250 _endasm; 
13251
13252 \layout Verse
13253
13254 \family typewriter
13255 ...
13256
13257 \layout Standard
13258 Note: it is sometimes sufficient to disable only a specific interrupt source
13259  like f.e.
13260  a timer or serial interrupt by manipulating an 
13261 \emph on
13262 interrupt mask
13263 \begin_inset LatexCommand \index{interrupt mask}
13264
13265 \end_inset
13266
13267
13268 \emph default
13269  register.
13270  
13271
13272 \layout Standard
13273 Usually the time during which interrupts are disabled should be kept as
13274  short as possible.
13275  This minimizes both 
13276 \emph on
13277 interrupt latency
13278 \emph default
13279
13280 \begin_inset LatexCommand \index{interrupt latency}
13281
13282 \end_inset
13283
13284  (the time between the occurrence of the interrupt and the execution of
13285  the first code in the interrupt routine) and 
13286 \emph on
13287 interrupt jitter
13288 \emph default
13289
13290 \begin_inset LatexCommand \index{interrupt jitter}
13291
13292 \end_inset
13293
13294  (the difference between the shortest and the longest interrupt latency).
13295  These really are something different, f.e.
13296  a serial interrupt has to be served before its buffer overruns so it cares
13297  for the maximum interrupt latency, whereas it does not care about jitter.
13298  On a loudspeaker driven via a digital to analog converter which is fed
13299  by an interrupt a latency of a few milliseconds might be tolerable, whereas
13300  a much smaller jitter will be very audible.
13301
13302 \layout Standard
13303 You can reenable interrupts within an interrupt routine and on some architecture
13304 s you can make use of two (or more) levels of 
13305 \emph on
13306 interrupt priorities
13307 \emph default
13308
13309 \begin_inset LatexCommand \index{interrupt priority}
13310
13311 \end_inset
13312
13313 .
13314  On some architectures which don't support interrupt priorities these can
13315  be implemented by manipulating the interrupt mask and reenabling interrupts
13316  within the interrupt routine.
13317  Check there is sufficient space on the stack
13318 \begin_inset LatexCommand \index{stack}
13319
13320 \end_inset
13321
13322  and don't add complexity unless you have to.
13323  
13324
13325 \layout Subsection
13326 Semaphore
13327 \begin_inset LatexCommand \index{semaphore}
13328
13329 \end_inset
13330
13331  locking (mcs51/ds390)
13332
13333 \layout Standard
13334 Some architectures (mcs51/ds390) have an atomic
13335 \begin_inset LatexCommand \index{atomic}
13336
13337 \end_inset
13338
13339  bit test and
13340 \emph on
13341  
13342 \emph default
13343 clear
13344 \emph on
13345  
13346 \emph default
13347 instruction.
13348  These type of instructions are typically used in preemptive multitasking
13349  systems, where a routine f.e.
13350  claims the use of a data structure ('acquires a lock
13351 \begin_inset LatexCommand \index{lock}
13352
13353 \end_inset
13354
13355  on it'), makes some modifications and then releases the lock when the data
13356  structure is consistent again.
13357  The instruction may also be used if interrupt and non-interrupt code have
13358  to compete for a resource.
13359  With the atomic bit test and clear instruction interrupts
13360 \begin_inset LatexCommand \index{interrupt}
13361
13362 \end_inset
13363
13364  don't have to be disabled for the locking operation.
13365  
13366
13367 \layout Standard
13368 SDCC generates this instruction if the source follows this pattern:
13369
13370 \layout Verse
13371
13372 \family typewriter
13373 volatile
13374 \begin_inset LatexCommand \index{volatile}
13375
13376 \end_inset
13377
13378  bit resource_is_free; 
13379 \newline
13380
13381 \newline
13382 if (resource_is_free) 
13383 \newline
13384 \SpecialChar ~
13385 \SpecialChar ~
13386
13387 \newline
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 resource_is_free=0; 
13393 \newline
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 \SpecialChar ~
13398 ...
13399  
13400 \newline
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 resource_is_free=1;
13406 \newline
13407 \SpecialChar ~
13408 \SpecialChar ~
13409
13410
13411 \layout Standard
13412 Note, mcs51 and ds390 support only an atomic
13413 \begin_inset LatexCommand \index{atomic}
13414
13415 \end_inset
13416
13417  bit test and 
13418 \emph on
13419 clear
13420 \emph default
13421  instruction (as opposed to atomic bit test and 
13422 \emph on
13423 set).
13424
13425 \layout Section
13426 Functions using private register banks
13427 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13428
13429 \end_inset
13430
13431  (mcs51/ds390)
13432
13433 \layout Standard
13434 Some architectures have support for quickly changing register sets.
13435  SDCC supports this feature with the 
13436 \emph on
13437 using
13438 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13439
13440 \end_inset
13441
13442
13443 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13444
13445 \end_inset
13446
13447
13448 \emph default
13449  attribute (which tells the compiler to use a register bank
13450 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13451
13452 \end_inset
13453
13454  other than the default bank zero).
13455  It should only be applied to 
13456 \emph on
13457 interrupt
13458 \begin_inset LatexCommand \index{interrupt}
13459
13460 \end_inset
13461
13462
13463 \emph default
13464  functions (see footnote below).
13465  This will in most circumstances make the generated ISR code more efficient
13466  since it will not have to save registers on the stack.
13467
13468 \layout Standard
13469 The 
13470 \emph on
13471 using
13472 \emph default
13473  attribute will have no effect on the generated code for a 
13474 \emph on
13475 non-interrupt
13476 \emph default
13477  function (but may occasionally be useful anyway
13478 \begin_inset Foot
13479 collapsed false
13480
13481 \layout Standard
13482 possible exception: if a function is called ONLY from 'interrupt' functions
13483  using a particular bank, it can be declared with the same 'using' attribute
13484  as the calling 'interrupt' functions.
13485  For instance, if you have several ISRs using bank one, and all of them
13486  call memcpy(), it might make sense to create a specialized version of memcpy()
13487  'using 1', since this would prevent the ISR from having to save bank zero
13488  to the stack on entry and switch to bank zero before calling the function
13489
13490 \end_inset
13491
13492 ).
13493 \newline
13494
13495 \emph on
13496 (pending: Note, nowadays the 
13497 \emph default
13498 using
13499 \emph on
13500  attribute has an effect on
13501 \emph default
13502  
13503 \emph on
13504 the generated code for a 
13505 \emph default
13506 non-interrupt
13507 \emph on
13508  function
13509 \emph default
13510 .
13511 \emph on
13512 )
13513
13514 \layout Standard
13515 An 
13516 \emph on
13517 interrupt
13518 \emph default
13519  function using a non-zero bank will assume that it can trash that register
13520  bank, and will not save it.
13521  Since high-priority interrupts
13522 \begin_inset LatexCommand \index{interrupts}
13523
13524 \end_inset
13525
13526
13527 \begin_inset LatexCommand \index{interrupt priority}
13528
13529 \end_inset
13530
13531  can interrupt low-priority ones on the 8051 and friends, this means that
13532  if a high-priority ISR 
13533 \emph on
13534 using
13535 \emph default
13536  a particular bank occurs while processing a low-priority ISR 
13537 \emph on
13538 using
13539 \emph default
13540  the same bank, terrible and bad things can happen.
13541  To prevent this, no single register bank should be 
13542 \emph on
13543 used
13544 \emph default
13545  by both a high priority and a low priority ISR.
13546  This is probably most easily done by having all high priority ISRs use
13547  one bank and all low priority ISRs use another.
13548  If you have an ISR which can change priority at runtime, you're on your
13549  own: I suggest using the default bank zero and taking the small performance
13550  hit.
13551
13552 \layout Standard
13553 \added_space_bottom bigskip 
13554 It is most efficient if your ISR calls no other functions.
13555  If your ISR must call other functions, it is most efficient if those functions
13556  use the same bank as the ISR (see note 1 below); the next best is if the
13557  called functions use bank zero.
13558  It is very inefficient to call a function using a different, non-zero bank
13559  from an ISR.
13560  
13561
13562
13563
13564 \layout Section
13565 Startup Code
13566 \begin_inset LatexCommand \label{sub:Startup-Code}
13567
13568 \end_inset
13569
13570
13571 \begin_inset LatexCommand \index{Startup code}
13572
13573 \end_inset
13574
13575
13576
13577 \layout Subsection
13578 MCS51/DS390 Startup Code
13579
13580 \layout Standard
13581 The compiler triggers the linker to link certain initialization modules
13582  from the runtime library
13583 \begin_inset LatexCommand \index{Runtime library}
13584
13585 \end_inset
13586
13587  called crt<something>.
13588  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13589  GSINIT5) is not linked unless the --xstack option is used.
13590  These modules are highly entangled by the use of special segments/areas,
13591  but a common layout is shown below:
13592
13593 \layout Verse
13594
13595 \family typewriter
13596 \series bold
13597 \size footnotesize
13598 (main.asm)
13599
13600 \layout Verse
13601
13602 \family typewriter
13603 \size footnotesize
13604 \SpecialChar ~
13605 \SpecialChar ~
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 .area HOME (CODE)
13613 \newline
13614 __interrupt_vect:
13615 \newline
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 \SpecialChar ~
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 ljmp __sdcc_gsinit_startup
13625
13626 \layout Verse
13627
13628 \family typewriter
13629 \series bold
13630 \size footnotesize
13631 (crtstart.asm)
13632
13633 \layout Verse
13634
13635 \family typewriter
13636 \size footnotesize
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 .area GSINIT0 (CODE)
13646 \newline
13647 __sdcc_gsinit_startup::
13648 \newline
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 \SpecialChar ~
13652 \SpecialChar ~
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 \SpecialChar ~
13656 \SpecialChar ~
13657 mov sp,#__start__stack - 1
13658
13659 \layout Verse
13660
13661 \family typewriter
13662 \series bold
13663 \size footnotesize
13664 (crtxstack.asm)
13665
13666 \layout Verse
13667
13668 \family typewriter
13669 \size footnotesize
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 \SpecialChar ~
13675 \SpecialChar ~
13676 \SpecialChar ~
13677 \SpecialChar ~
13678 .area GSINIT1 (CODE)
13679 \newline
13680 __sdcc_init_xstack::
13681 \newline
13682 ; Need to initialize in GSINIT1 in
13683  case the user's __sdcc_external_startup uses the xstack.
13684 \newline
13685 \SpecialChar ~
13686 \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 mov __XPAGE,#(__start__x
13694 stack >> 8)
13695 \newline
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 \SpecialChar ~
13704 mov _spx,#__start__xstack
13705
13706 \layout Verse
13707
13708 \family typewriter
13709 \series bold
13710 \size footnotesize
13711 (crtstart.asm)
13712
13713 \layout Verse
13714
13715 \family typewriter
13716 \size footnotesize
13717 \SpecialChar ~
13718 \SpecialChar ~
13719 \SpecialChar ~
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 .area GSINIT2 (CODE)
13726 \newline
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 \SpecialChar ~
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 lcall __sdcc_external_startup
13736 \newline
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 \SpecialChar ~
13741 \SpecialChar ~
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 mov a,dpl
13746 \newline
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 \SpecialChar ~
13751 \SpecialChar ~
13752 \SpecialChar ~
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 jz __sdcc_init_data
13756 \newline
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 \SpecialChar ~
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 ljmp
13766  __sdcc_program_startup
13767 \newline
13768 __sdcc_init_data:
13769
13770 \layout Verse
13771
13772 \family typewriter
13773 \series bold
13774 \size footnotesize
13775 (crtxinit.asm)
13776
13777 \layout Verse
13778
13779 \family typewriter
13780 \size footnotesize
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 \SpecialChar ~
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 .area GSINIT3 (CODE)
13790 \newline
13791 __mcs51_genXINIT::
13792 \newline
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 mov r1,#l_XINIT
13802 \newline
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 mov a,r1
13812 \newline
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 orl a,#(l_XINIT
13822  >> 8)
13823 \newline
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 \SpecialChar ~
13829 \SpecialChar ~
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 jz 00003$
13833 \newline
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 \SpecialChar ~
13839 \SpecialChar ~
13840 \SpecialChar ~
13841 \SpecialChar ~
13842 mov r2,#((l_XINIT+255) >> 8)
13843 \newline
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 \SpecialChar ~
13850 \SpecialChar ~
13851 \SpecialChar ~
13852 mov dptr,#s_XINIT
13853 \newline
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 \SpecialChar ~
13862 mov r0,#s_XISEG
13863 \newline
13864 \SpecialChar ~
13865 \SpecialChar ~
13866 \SpecialChar ~
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 \SpecialChar ~
13870 \SpecialChar ~
13871 \SpecialChar ~
13872 mov
13873  __XPAGE,#(s_XISEG >> 8)
13874 \newline
13875 00001$:\SpecialChar ~
13876 clr a
13877 \newline
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 \SpecialChar ~
13881 \SpecialChar ~
13882 \SpecialChar ~
13883 \SpecialChar ~
13884 \SpecialChar ~
13885 \SpecialChar ~
13886 movc a,@a+dptr
13887 \newline
13888 \SpecialChar ~
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 \SpecialChar ~
13892 \SpecialChar ~
13893 \SpecialChar ~
13894 \SpecialChar ~
13895 \SpecialChar ~
13896 movx @r0,a
13897 \newline
13898 \SpecialChar ~
13899 \SpecialChar ~
13900 \SpecialChar ~
13901 \SpecialChar ~
13902 \SpecialChar ~
13903 \SpecialChar ~
13904 \SpecialChar ~
13905 \SpecialChar ~
13906 inc dptr
13907 \newline
13908 \SpecialChar ~
13909 \SpecialChar ~
13910 \SpecialChar ~
13911 \SpecialChar ~
13912 \SpecialChar ~
13913 \SpecialChar ~
13914 \SpecialChar ~
13915 \SpecialChar ~
13916 inc
13917  r0
13918 \newline
13919 \SpecialChar ~
13920 \SpecialChar ~
13921 \SpecialChar ~
13922 \SpecialChar ~
13923 \SpecialChar ~
13924 \SpecialChar ~
13925 \SpecialChar ~
13926 \SpecialChar ~
13927 cjne r0,#0,00002$
13928 \newline
13929 \SpecialChar ~
13930 \SpecialChar ~
13931 \SpecialChar ~
13932 \SpecialChar ~
13933 \SpecialChar ~
13934 \SpecialChar ~
13935 \SpecialChar ~
13936 \SpecialChar ~
13937 inc __XPAGE
13938 \newline
13939 00002$:\SpecialChar ~
13940 djnz r1,00001$
13941 \newline
13942 \SpecialChar ~
13943 \SpecialChar ~
13944 \SpecialChar ~
13945 \SpecialChar ~
13946 \SpecialChar ~
13947 \SpecialChar ~
13948 \SpecialChar ~
13949 \SpecialChar ~
13950 djnz r2,00001$
13951 \newline
13952 \SpecialChar ~
13953 \SpecialChar ~
13954 \SpecialChar ~
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 \SpecialChar ~
13958 \SpecialChar ~
13959 \SpecialChar ~
13960 mov __XPAGE,#0
13961 xFF
13962 \newline
13963 00003$:
13964
13965 \layout Verse
13966
13967 \family typewriter
13968 \series bold
13969 \size footnotesize
13970 (crtclear.asm)
13971
13972 \layout Verse
13973
13974 \family typewriter
13975 \size footnotesize
13976 \SpecialChar ~
13977 \SpecialChar ~
13978 \SpecialChar ~
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 \SpecialChar ~
13984 .area GSINIT4 (CODE)
13985 \newline
13986 __mcs51_genRAMCLEAR::
13987 \newline
13988 \SpecialChar ~
13989 \SpecialChar ~
13990 \SpecialChar ~
13991 \SpecialChar ~
13992 \SpecialChar ~
13993 \SpecialChar ~
13994 \SpecialChar ~
13995 \SpecialChar ~
13996 clr a
13997 \newline
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 \SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 mov r0,#(l_IRAM-1)
14007 \newline
14008 00004$:\SpecialChar ~
14009 mov
14010  @r0,a
14011 \newline
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 \SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 \SpecialChar ~
14019 \SpecialChar ~
14020 djnz r0,00004$
14021 \newline
14022 ; _mcs51_genRAMCLEAR() end
14023
14024 \layout Verse
14025
14026 \family typewriter
14027 \series bold
14028 \size footnotesize
14029 (crtxclear.asm)
14030
14031 \layout Verse
14032
14033 \family typewriter
14034 \size footnotesize
14035 \SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 \SpecialChar ~
14040 \SpecialChar ~
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 .area GSINIT4 (CODE)
14044 \newline
14045 __mcs51_genXRAMCLEAR::
14046 \newline
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 \SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 \SpecialChar ~
14054 \SpecialChar ~
14055 mov r0,#l_PSEG
14056 \newline
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 \SpecialChar ~
14064 \SpecialChar ~
14065 mov a,r0
14066 \newline
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 \SpecialChar ~
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 \SpecialChar ~
14075 jz 00006$
14076 \newline
14077 \SpecialChar ~
14078 \SpecialChar ~
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 \SpecialChar ~
14085 mov
14086  r1,#s_PSEG
14087 \newline
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 \SpecialChar ~
14095 \SpecialChar ~
14096 mov __XPAGE,#(s_PSEG >> 8)
14097 \newline
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 \SpecialChar ~
14106 clr a
14107 \newline
14108 00005$:\SpecialChar ~
14109 movx @r1,a
14110 \newline
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 \SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 inc r1
14120 \newline
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 \SpecialChar ~
14126 \SpecialChar ~
14127 \SpecialChar ~
14128 \SpecialChar ~
14129 djnz r0,00005$
14130 \newline
14131 0
14132 0006$:
14133 \newline
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 \SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 \SpecialChar ~
14142 mov r0,#l_XSEG
14143 \newline
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 mov a,r0
14153 \newline
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 \SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 orl a,#(l_XSEG >> 8)
14163 \newline
14164 \SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 \SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 jz 00008$
14173 \newline
14174 \SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 \SpecialChar ~
14181 \SpecialChar ~
14182 mov r1,#((l_XSEG
14183  + 255) >> 8)
14184 \newline
14185 \SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 \SpecialChar ~
14192 \SpecialChar ~
14193 mov dptr,#s_XSEG
14194 \newline
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 \SpecialChar ~
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 clr a
14204 \newline
14205 00007$:\SpecialChar ~
14206 movx @dptr,a
14207 \newline
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 \SpecialChar ~
14215 \SpecialChar ~
14216 inc dptr
14217 \newline
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 \SpecialChar ~
14226 djnz r0,00007$
14227 \newline
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 \SpecialChar ~
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 djnz
14237  r1,00007$
14238 \newline
14239 00008$:
14240
14241 \layout Verse
14242
14243 \family typewriter
14244 \series bold
14245 \size footnotesize
14246 (crtxstack.asm)
14247
14248 \layout Verse
14249
14250 \family typewriter
14251 \size footnotesize
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 .area GSINIT5 (CODE)
14261 \newline
14262 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
14263  modifies __XPAGE
14264 \newline
14265 ; and __mcs51_genRAMCLEAR modifies _spx.
14266 \newline
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 \SpecialChar ~
14275 mov __XPAGE,#(__start__x
14276 stack >> 8)
14277 \newline
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 \SpecialChar ~
14286 mov _spx,#__start__xstack
14287
14288 \layout Verse
14289
14290 \family typewriter
14291 \series bold
14292 \size footnotesize
14293 (application modules)
14294
14295 \layout Verse
14296
14297 \family typewriter
14298 \size footnotesize
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 .area GSINIT (CODE)
14308
14309 \layout Verse
14310
14311 \family typewriter
14312 \series bold
14313 \size footnotesize
14314 (main.asm)
14315
14316 \layout Verse
14317
14318 \family typewriter
14319 \size footnotesize
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 \SpecialChar ~
14328 .area GSFINAL (CODE)
14329 \newline
14330 \SpecialChar ~
14331 \SpecialChar ~
14332 \SpecialChar ~
14333 \SpecialChar ~
14334 \SpecialChar ~
14335 \SpecialChar ~
14336 \SpecialChar ~
14337 \SpecialChar ~
14338 ljmp __sdcc_program_startup
14339 \newline
14340 ;---------------------------------
14341 -----------------------
14342 \newline
14343 ; Home
14344 \newline
14345 ;--------------------------------------------------
14346 ------
14347 \newline
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 \SpecialChar ~
14351 \SpecialChar ~
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 \SpecialChar ~
14356 .area HOME (CODE)
14357 \newline
14358 \SpecialChar ~
14359 \SpecialChar ~
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 \SpecialChar ~
14366 .area CSEG (CODE)
14367 \newline
14368 __sdcc_program_startup:
14369 \newline
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 \SpecialChar ~
14373 \SpecialChar ~
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 lcall _main
14379 \newline
14380 ;
14381  return from main will lock up
14382 \newline
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 \SpecialChar ~
14389 \SpecialChar ~
14390 \SpecialChar ~
14391 sjmp .
14392
14393 \layout Standard
14394 One of these modules (crtstart.asm) contains a call to the C routine 
14395 \emph on
14396 _sdcc_external_startup()
14397 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14398
14399 \end_inset
14400
14401
14402 \series bold
14403 \emph default
14404  
14405 \series default
14406 at the start of the CODE area.
14407  This routine is also in the runtime library
14408 \begin_inset LatexCommand \index{Runtime library}
14409
14410 \end_inset
14411
14412  and returns 0 by default.
14413  If this routine returns a non-zero value, the static & global variable
14414  initialization will be skipped and the function main will be invoked.
14415  Otherwise static & global variables will be initialized before the function
14416  main is invoked.
14417  You could add an 
14418 \emph on
14419 _sdcc_external_startup()
14420 \emph default
14421  routine to your program to override the default if you need to setup hardware
14422  or perform some other critical operation prior to static & global variable
14423  initialization
14424 \begin_inset LatexCommand \index{Variable initialization}
14425
14426 \end_inset
14427
14428 .
14429  On some mcs51 variants xdata
14430 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14431
14432 \end_inset
14433
14434  memory has to be explicitly enabled before it can be accessed or if the
14435  watchdog
14436 \begin_inset LatexCommand \index{watchdog}
14437
14438 \end_inset
14439
14440  needs to be disabled, this is the place to do it.
14441  The startup code clears all internal data memory, 256 bytes by default,
14442  but from 0 to n-1 if 
14443 \emph on
14444 -
14445 \begin_inset ERT
14446 status Collapsed
14447
14448 \layout Standard
14449
14450
14451 \backslash
14452 /
14453
14454 \end_inset
14455
14456 -iram-size
14457 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14458
14459 \end_inset
14460
14461 n
14462 \emph default
14463  is used.
14464  (recommended for Chipcon CC1010).
14465
14466 \layout Standard
14467 \added_space_bottom bigskip 
14468 See also the compiler options 
14469 \emph on
14470 -
14471 \begin_inset ERT
14472 status Collapsed
14473
14474 \layout Standard
14475
14476
14477 \backslash
14478 /
14479
14480 \end_inset
14481
14482 -no-xinit
14483 \emph default
14484 -
14485 \emph on
14486 opt
14487 \emph default
14488
14489 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14490
14491 \end_inset
14492
14493
14494 \emph on
14495 -
14496 \begin_inset ERT
14497 status Collapsed
14498
14499 \layout Standard
14500
14501
14502 \backslash
14503 /
14504
14505 \end_inset
14506
14507 -main-return
14508 \emph default
14509
14510 \begin_inset LatexCommand \index{-\/-main-return}
14511
14512 \end_inset
14513
14514  and section 
14515 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14516
14517 \end_inset
14518
14519  about MCS51-variants.
14520
14521
14522
14523 \layout Subsection
14524 HC08 Startup Code
14525
14526 \layout Standard
14527 \added_space_bottom bigskip 
14528 The HC08
14529 \begin_inset LatexCommand \index{HC08}
14530
14531 \end_inset
14532
14533  startup code follows the same scheme as the MCS51 startup code.
14534
14535
14536
14537 \layout Subsection
14538 Z80 Startup Code
14539
14540 \layout Standard
14541 \added_space_bottom bigskip 
14542 On the Z80
14543 \begin_inset LatexCommand \index{Z80}
14544
14545 \end_inset
14546
14547  the startup code is inserted by linking with crt0.o which is generated from
14548  sdcc/device/lib/z80/crt0.s.
14549  If you need a different startup code you can use the compiler option 
14550 \emph on
14551 -
14552 \series bold
14553 \emph default
14554
14555 \begin_inset ERT
14556 status Collapsed
14557
14558 \layout Standard
14559
14560
14561 \backslash
14562 /
14563
14564 \end_inset
14565
14566
14567 \series default
14568 \emph on
14569 -no-std-crt0
14570 \emph default
14571
14572 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14573
14574 \end_inset
14575
14576  and provide your own crt0.o.
14577  
14578
14579
14580
14581 \layout Section
14582 Inline Assembler Code
14583 \begin_inset LatexCommand \index{Assembler routines}
14584
14585 \end_inset
14586
14587
14588
14589 \layout Subsection
14590 A Step by Step Introduction
14591 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14592
14593 \end_inset
14594
14595
14596
14597 \layout Standard
14598 Starting from a small snippet of c-code this example shows for the MCS51
14599  how to use inline assembly, access variables, a function parameter and
14600  an array in xdata memory.
14601  The example uses an MCS51 here but is easily adapted for other architectures.
14602  This is a buffer routine which should be optimized:
14603
14604 \layout Verse
14605
14606 \family typewriter
14607 \size footnotesize
14608 unsigned char __far
14609 \begin_inset LatexCommand \index{far (storage class)}
14610
14611 \end_inset
14612
14613
14614 \begin_inset LatexCommand \index{\_\_far (storage class)}
14615
14616 \end_inset
14617
14618  __at
14619 \begin_inset LatexCommand \index{at}
14620
14621 \end_inset
14622
14623
14624 \begin_inset LatexCommand \index{\_\_at}
14625
14626 \end_inset
14627
14628 (0x7f00) buf[0x100];
14629 \begin_inset LatexCommand \index{Aligned array}
14630
14631 \end_inset
14632
14633
14634 \newline
14635 unsigned char head, tail;\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 \SpecialChar ~
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 /* if interrupts
14653 \begin_inset LatexCommand \index{interrupt}
14654
14655 \end_inset
14656
14657  are involved see
14658 \newline
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 \SpecialChar ~
14702 \SpecialChar ~
14703 \SpecialChar ~
14704 section 
14705 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14706
14707 \end_inset
14708
14709  about
14710 \series bold
14711  volatile
14712 \series default
14713  */
14714 \newline
14715
14716 \newline
14717 void to_buffer( unsigned char c ) 
14718 \newline
14719 {
14720 \newline
14721 \SpecialChar ~
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 if( head != (unsigned char)(tail-1)
14726  )\SpecialChar ~
14727 /* cast 
14728 \series bold
14729 needed
14730 \series default
14731  to avoid promotion
14732 \begin_inset LatexCommand \index{promotion to signed int}
14733
14734 \end_inset
14735
14736
14737 \begin_inset LatexCommand \index{type promotion}
14738
14739 \end_inset
14740
14741  to integer */
14742 \begin_inset Marginal
14743 collapsed true
14744
14745 \layout Standard
14746
14747 \series bold
14748 \SpecialChar ~
14749 !
14750
14751 \end_inset
14752
14753
14754 \newline
14755 \SpecialChar ~
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 \SpecialChar ~
14763 buf[ head++ ] = c;\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 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 /* access to a 256 byte aligned array */
14780 \newline
14781
14782
14783 \layout Standard
14784 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14785  then a corresponding buffer.asm file is generated.
14786  We define a new function 
14787 \family typewriter
14788 to_buffer_asm()
14789 \family default
14790  in file buffer.c in which we cut and paste the generated code, removing
14791  unwanted comments and some ':'.
14792  Then add 
14793 \begin_inset Quotes sld
14794 \end_inset
14795
14796 _asm
14797 \begin_inset Quotes srd
14798 \end_inset
14799
14800  and 
14801 \begin_inset Quotes sld
14802 \end_inset
14803
14804 _endasm;
14805 \begin_inset Quotes srd
14806 \end_inset
14807
14808  to the beginning and the end of the function body:
14809
14810 \layout Verse
14811
14812 \family typewriter
14813 \size footnotesize
14814 /* With a cut and paste from the .asm file, we have something to start with.
14815 \newline
14816 \SpecialChar ~
14817 \SpecialChar ~
14818 \SpecialChar ~
14819 The
14820  function is not yet OK! (registers aren't saved) */ 
14821 \newline
14822 void to_buffer_asm(
14823  unsigned char c ) 
14824 \newline
14825
14826 \newline
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 \SpecialChar ~
14830 \SpecialChar ~
14831 _asm
14832 \begin_inset LatexCommand \index{\_asm}
14833
14834 \end_inset
14835
14836
14837 \begin_inset LatexCommand \index{\_\_asm}
14838
14839 \end_inset
14840
14841
14842 \newline
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 mov\SpecialChar ~
14848 \SpecialChar ~
14849 r2,dpl 
14850 \newline
14851 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14852 /* cast 
14853 \series bold
14854 needed
14855 \series default
14856  to avoid promotion
14857 \begin_inset LatexCommand \index{promotion to signed int}
14858
14859 \end_inset
14860
14861
14862 \begin_inset LatexCommand \index{type promotion}
14863
14864 \end_inset
14865
14866  to integer */
14867 \newline
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 mov\SpecialChar ~
14873 \SpecialChar ~
14874 a,_tail 
14875 \newline
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 dec\SpecialChar ~
14881 \SpecialChar ~
14882
14883 \newline
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 mov\SpecialChar ~
14889 \SpecialChar ~
14890 r3,a 
14891 \newline
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 \SpecialChar ~
14896 mov\SpecialChar ~
14897 \SpecialChar ~
14898 a,_head 
14899 \newline
14900 \SpecialChar ~
14901 \SpecialChar ~
14902 \SpecialChar ~
14903 \SpecialChar ~
14904 cjne a,ar3,00106$ 
14905 \newline
14906 \SpecialChar ~
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 ret
14911 \newline
14912 00106$:
14913  
14914 \newline
14915 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14916 \begin_inset LatexCommand \index{Aligned array}
14917
14918 \end_inset
14919
14920
14921 \newline
14922 \SpecialChar ~
14923 \SpecialChar ~
14924 \SpecialChar ~
14925 \SpecialChar ~
14926 mov\SpecialChar ~
14927 \SpecialChar ~
14928 r3,_head 
14929 \newline
14930 \SpecialChar ~
14931 \SpecialChar ~
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 inc\SpecialChar ~
14935 \SpecialChar ~
14936 _head 
14937 \newline
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 \SpecialChar ~
14942 mov\SpecialChar ~
14943 \SpecialChar ~
14944 dpl,r3 
14945 \newline
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 \SpecialChar ~
14949 \SpecialChar ~
14950 mov\SpecialChar ~
14951 \SpecialChar ~
14952 dph,#(_buf >> 8) 
14953 \newline
14954 \SpecialChar ~
14955 \SpecialChar ~
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 mov\SpecialChar ~
14959 \SpecialChar ~
14960 a,r2 
14961 \newline
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 movx @dptr,a
14967  
14968 \newline
14969 00103$: 
14970 \newline
14971 \SpecialChar ~
14972 \SpecialChar ~
14973 \SpecialChar ~
14974 \SpecialChar ~
14975 ret
14976 \newline
14977 \SpecialChar ~
14978 \SpecialChar ~
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 _endasm
14982 \begin_inset LatexCommand \index{\_endasm}
14983
14984 \end_inset
14985
14986
14987 \begin_inset LatexCommand \index{\_\_endasm}
14988
14989 \end_inset
14990
14991 ;
14992 \newline
14993
14994
14995 \layout Standard
14996 The new file buffer.c should compile with only one warning about the unreferenced
14997  function argument 'c'.
14998  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14999  (1) and finally have:
15000
15001 \layout Verse
15002
15003 \family typewriter
15004 \size footnotesize
15005 unsigned char __far __at(0x7f00) buf[0x100];
15006 \newline
15007 unsigned char head, tail;
15008 \newline
15009 #define
15010  USE_ASSEMBLY (1)
15011 \newline
15012
15013 \newline
15014 #if !USE_ASSEMBLY
15015 \newline
15016
15017 \newline
15018 void to_buffer( unsigned char c )
15019 \newline
15020 {
15021 \newline
15022 \SpecialChar ~
15023 \SpecialChar ~
15024 \SpecialChar ~
15025 \SpecialChar ~
15026 if(
15027  head != (unsigned char)(tail-1) )
15028 \newline
15029 \SpecialChar ~
15030 \SpecialChar ~
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 \SpecialChar ~
15035 \SpecialChar ~
15036 \SpecialChar ~
15037 buf[ head++ ] = c;
15038 \newline
15039 }
15040 \newline
15041
15042 \newline
15043 #else
15044 \newline
15045
15046 \newline
15047 void to_buffer(
15048  unsigned char c )
15049 \newline
15050 {
15051 \newline
15052 \SpecialChar ~
15053 \SpecialChar ~
15054 \SpecialChar ~
15055 \SpecialChar ~
15056 c; // to avoid warning: unreferenced function argument
15057 \newline
15058 \SpecialChar ~
15059 \SpecialChar ~
15060 \SpecialChar ~
15061 \SpecialChar ~
15062 _asm
15063 \begin_inset LatexCommand \index{\_asm}
15064
15065 \end_inset
15066
15067
15068 \begin_inset LatexCommand \index{\_\_asm}
15069
15070 \end_inset
15071
15072
15073 \newline
15074 \SpecialChar ~
15075 \SpecialChar ~
15076 \SpecialChar ~
15077 \SpecialChar ~
15078 \SpecialChar ~
15079 \SpecialChar ~
15080 \SpecialChar ~
15081 \SpecialChar ~
15082 ; save used registers here.
15083  
15084 \newline
15085 \SpecialChar ~
15086 \SpecialChar ~
15087 \SpecialChar ~
15088 \SpecialChar ~
15089 \SpecialChar ~
15090 \SpecialChar ~
15091 \SpecialChar ~
15092 \SpecialChar ~
15093 ; If we were still using r2,r3 we would have to push them here.
15094  
15095 \newline
15096 ; if( head != (unsigned char)(tail-1) )
15097 \newline
15098 \SpecialChar ~
15099 \SpecialChar ~
15100 \SpecialChar ~
15101 \SpecialChar ~
15102 \SpecialChar ~
15103 \SpecialChar ~
15104 \SpecialChar ~
15105 \SpecialChar ~
15106 mov\SpecialChar ~
15107  a,_tail
15108 \newline
15109 \SpecialChar ~
15110 \SpecialChar ~
15111 \SpecialChar ~
15112 \SpecialChar ~
15113 \SpecialChar ~
15114 \SpecialChar ~
15115 \SpecialChar ~
15116 \SpecialChar ~
15117 dec\SpecialChar ~
15118  a
15119 \newline
15120 \SpecialChar ~
15121 \SpecialChar ~
15122 \SpecialChar ~
15123 \SpecialChar ~
15124 \SpecialChar ~
15125 \SpecialChar ~
15126 \SpecialChar ~
15127 \SpecialChar ~
15128 xrl\SpecialChar ~
15129  a,_head
15130 \newline
15131 \SpecialChar ~
15132 \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 \SpecialChar ~
15138 \SpecialChar ~
15139 ; we
15140  could do an ANL a,#0x0f here to use a smaller buffer (see below)
15141 \newline
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 \SpecialChar ~
15146 \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 jz\SpecialChar ~
15151 \SpecialChar ~
15152  t_b_end$
15153 \newline
15154 \SpecialChar ~
15155 \SpecialChar ~
15156 \SpecialChar ~
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 \SpecialChar ~
15160 \SpecialChar ~
15161 \SpecialChar ~
15162 ;
15163 \newline
15164 ;
15165  buf[ head++ ] = c;
15166 \newline
15167 \SpecialChar ~
15168 \SpecialChar ~
15169 \SpecialChar ~
15170 \SpecialChar ~
15171 \SpecialChar ~
15172 \SpecialChar ~
15173 \SpecialChar ~
15174 \SpecialChar ~
15175 mov\SpecialChar ~
15176  a,dpl \SpecialChar ~
15177 \SpecialChar ~
15178 \SpecialChar ~
15179 \SpecialChar ~
15180 \SpecialChar ~
15181 \SpecialChar ~
15182 \SpecialChar ~
15183 ; dpl holds lower byte of function argument
15184 \newline
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 \SpecialChar ~
15190 \SpecialChar ~
15191 \SpecialChar ~
15192 \SpecialChar ~
15193 mov\SpecialChar ~
15194
15195  dpl,_head \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 ; buf is 0x100 byte aligned so head can be used directly
15199 \newline
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 \SpecialChar ~
15203 \SpecialChar ~
15204 \SpecialChar ~
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 mov\SpecialChar ~
15209  dph,#(_bu
15210 f>>8)
15211 \newline
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 \SpecialChar ~
15220 movx @dptr,a
15221 \newline
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 \SpecialChar ~
15226 \SpecialChar ~
15227 \SpecialChar ~
15228 \SpecialChar ~
15229 \SpecialChar ~
15230 inc \SpecialChar ~
15231 _head
15232 \newline
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 ; we could do an ANL _head,#0x0f here to use a
15242  smaller buffer (see above)
15243 \newline
15244 t_b_end$:
15245 \newline
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 \SpecialChar ~
15251 \SpecialChar ~
15252 \SpecialChar ~
15253 \SpecialChar ~
15254 ; restore used registers here 
15255 \newline
15256 \SpecialChar ~
15257 \SpecialChar ~
15258 \SpecialChar ~
15259 \SpecialChar ~
15260 _endasm
15261 \begin_inset LatexCommand \index{\_endasm}
15262
15263 \end_inset
15264
15265
15266 \begin_inset LatexCommand \index{\_\_endasm}
15267
15268 \end_inset
15269
15270 ;
15271 \newline
15272 }
15273 \newline
15274 #endif
15275
15276 \layout Standard
15277 The inline assembler code can contain any valid code understood by the assembler
15278 , this includes any assembler directives and comment lines.
15279  The assembler does not like some characters like ':' or ''' in comments.
15280  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15281 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15282
15283 \end_inset
15284
15285
15286 \begin_inset LatexCommand \index{Assembler documentation}
15287
15288 \end_inset
15289
15290  or online at 
15291 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15292
15293 \end_inset
15294
15295 \SpecialChar ~
15296 .
15297
15298 \layout Standard
15299 The compiler does not do any validation of the code within the 
15300 \family typewriter
15301 _asm
15302 \begin_inset LatexCommand \index{\_asm}
15303
15304 \end_inset
15305
15306
15307 \begin_inset LatexCommand \index{\_\_asm}
15308
15309 \end_inset
15310
15311  ...
15312  _endasm
15313 \size footnotesize
15314
15315 \begin_inset LatexCommand \index{\_endasm}
15316
15317 \end_inset
15318
15319
15320 \begin_inset LatexCommand \index{\_\_endasm}
15321
15322 \end_inset
15323
15324
15325 \size default
15326 ;
15327 \family default
15328  keyword pair.
15329  Specifically it will not know which registers are used and thus register
15330  pushing/popping
15331 \begin_inset LatexCommand \index{push/pop}
15332
15333 \end_inset
15334
15335  has to be done manually.
15336  
15337
15338 \layout Standard
15339 It is recommended that each assembly instruction (including labels) be placed
15340  in a separate line (as the example shows).
15341  When the -
15342 \begin_inset ERT
15343 status Collapsed
15344
15345 \layout Standard
15346
15347
15348 \backslash
15349 /
15350
15351 \end_inset
15352
15353 -
15354 \emph on
15355 peep-asm
15356 \begin_inset LatexCommand \index{-\/-peep-asm}
15357
15358 \end_inset
15359
15360
15361 \emph default
15362  command line option is used, the inline assembler code will be passed through
15363  the peephole optimizer
15364 \begin_inset LatexCommand \index{Peephole optimizer}
15365
15366 \end_inset
15367
15368 .
15369  There are only a few (if any) cases where this option makes sense, it might
15370  cause some unexpected changes in the inline assembler code.
15371  Please go through the peephole optimizer rules defined in file 
15372 \emph on
15373 SDCCpeeph.def
15374 \emph default
15375  before using this option.
15376
15377 \layout Subsection
15378 Naked Functions
15379 \begin_inset LatexCommand \label{sub:Naked-Functions}
15380
15381 \end_inset
15382
15383
15384 \begin_inset LatexCommand \index{Naked functions}
15385
15386 \end_inset
15387
15388
15389
15390 \layout Standard
15391 A special keyword may be associated with a function declaring it as 
15392 \emph on
15393 _naked
15394 \begin_inset LatexCommand \index{\_naked}
15395
15396 \end_inset
15397
15398
15399 \begin_inset LatexCommand \index{\_\_naked}
15400
15401 \end_inset
15402
15403 .
15404  
15405 \emph default
15406 The 
15407 \emph on
15408 _naked
15409 \emph default
15410  function modifier attribute prevents the compiler from generating prologue
15411 \begin_inset LatexCommand \index{function prologue}
15412
15413 \end_inset
15414
15415  and epilogue
15416 \begin_inset LatexCommand \index{function epilogue}
15417
15418 \end_inset
15419
15420  code for that function.
15421  This means that the user is entirely responsible for such things as saving
15422  any registers that may need to be preserved, selecting the proper register
15423  bank, generating the 
15424 \emph on
15425 return
15426 \emph default
15427  instruction at the end, etc.
15428  Practically, this means that the contents of the function must be written
15429  in inline assembler.
15430  This is particularly useful for interrupt functions, which can have a large
15431  (and often unnecessary) prologue/epilogue.
15432  For example, compare the code generated by these two functions:
15433
15434 \layout Verse
15435
15436 \family typewriter
15437 volatile
15438 \begin_inset LatexCommand \index{volatile}
15439
15440 \end_inset
15441
15442  data unsigned char counter;
15443 \newline
15444
15445 \newline
15446 void simpleInterrupt(void) __interrupt
15447 \begin_inset LatexCommand \index{interrupt}
15448
15449 \end_inset
15450
15451
15452 \begin_inset LatexCommand \index{\_\_interrupt}
15453
15454 \end_inset
15455
15456  (1)
15457 \newline
15458 {
15459 \newline
15460 \SpecialChar ~
15461 \SpecialChar ~
15462 \SpecialChar ~
15463 \SpecialChar ~
15464 counter++;
15465 \newline
15466 }
15467 \newline
15468
15469 \newline
15470 void nakedInterrupt(void) __interrupt (2) __naked
15471 \newline
15472 {
15473 \newline
15474 \SpecialChar ~
15475 \SpecialChar ~
15476 \SpecialChar ~
15477 \SpecialChar ~
15478 _asm
15479 \begin_inset LatexCommand \index{\_asm}
15480
15481 \end_inset
15482
15483
15484 \begin_inset LatexCommand \index{\_\_asm}
15485
15486 \end_inset
15487
15488
15489 \newline
15490 \SpecialChar ~
15491 \SpecialChar ~
15492 \SpecialChar ~
15493 \SpecialChar ~
15494 \SpecialChar ~
15495 \SpecialChar ~
15496 inc\SpecialChar ~
15497 \SpecialChar ~
15498 \SpecialChar ~
15499 \SpecialChar ~
15500 \SpecialChar ~
15501 _counter ; does not change flags, no need to save psw
15502 \newline
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 \SpecialChar ~
15506 \SpecialChar ~
15507 \SpecialChar ~
15508 \SpecialChar ~
15509 reti\SpecialChar ~
15510 \SpecialChar ~
15511 \SpecialChar ~
15512 \SpecialChar ~
15513 ; MUST explicitly
15514  include ret or reti in _naked function.
15515 \newline
15516 \SpecialChar ~
15517 \SpecialChar ~
15518 \SpecialChar ~
15519 \SpecialChar ~
15520 _endasm
15521 \begin_inset LatexCommand \index{\_endasm}
15522
15523 \end_inset
15524
15525
15526 \begin_inset LatexCommand \index{\_\_endasm}
15527
15528 \end_inset
15529
15530 ;
15531 \newline
15532 }
15533
15534 \layout Standard
15535 For an 8051 target, the generated simpleInterrupt looks like:
15536
15537 \layout Verse
15538
15539 \family typewriter
15540 Note, this is an 
15541 \emph on
15542 outdated
15543 \emph default
15544  example, recent versions of SDCC generate
15545 \newline
15546 the 
15547 \emph on
15548 same
15549 \emph default
15550  code for simpleInterrupt() and nakedInterrupt()!
15551 \newline
15552
15553 \newline
15554 _simpleInterrupt:
15555 \newline
15556 \SpecialChar ~
15557 \SpecialChar ~
15558 \SpecialChar ~
15559 \SpecialChar ~
15560 push\SpecialChar ~
15561 \SpecialChar ~
15562 \SpecialChar ~
15563 \SpecialChar ~
15564 acc
15565 \newline
15566 \SpecialChar ~
15567 \SpecialChar ~
15568 \SpecialChar ~
15569 \SpecialChar ~
15570 push\SpecialChar ~
15571 \SpecialChar ~
15572 \SpecialChar ~
15573 \SpecialChar ~
15574 b
15575 \newline
15576 \SpecialChar ~
15577 \SpecialChar ~
15578 \SpecialChar ~
15579 \SpecialChar ~
15580 pu
15581 sh\SpecialChar ~
15582 \SpecialChar ~
15583 \SpecialChar ~
15584 \SpecialChar ~
15585 dpl
15586 \newline
15587 \SpecialChar ~
15588 \SpecialChar ~
15589 \SpecialChar ~
15590 \SpecialChar ~
15591 push\SpecialChar ~
15592 \SpecialChar ~
15593 \SpecialChar ~
15594 \SpecialChar ~
15595 dph
15596 \newline
15597 \SpecialChar ~
15598 \SpecialChar ~
15599 \SpecialChar ~
15600 \SpecialChar ~
15601 push\SpecialChar ~
15602 \SpecialChar ~
15603 \SpecialChar ~
15604 \SpecialChar ~
15605 psw
15606 \newline
15607 \SpecialChar ~
15608 \SpecialChar ~
15609 \SpecialChar ~
15610 \SpecialChar ~
15611 mov\SpecialChar ~
15612 \SpecialChar ~
15613 \SpecialChar ~
15614 \SpecialChar ~
15615 \SpecialChar ~
15616 psw,#0x00
15617 \newline
15618 \SpecialChar ~
15619 \SpecialChar ~
15620 \SpecialChar ~
15621 \SpecialChar ~
15622 inc\SpecialChar ~
15623 \SpecialChar ~
15624 \SpecialChar ~
15625 \SpecialChar ~
15626 \SpecialChar ~
15627 _counter
15628 \newline
15629 \SpecialChar ~
15630 \SpecialChar ~
15631 \SpecialChar ~
15632 \SpecialChar ~
15633 pop\SpecialChar ~
15634 \SpecialChar ~
15635 \SpecialChar ~
15636 \SpecialChar ~
15637 \SpecialChar ~
15638 psw
15639 \newline
15640 \SpecialChar ~
15641 \SpecialChar ~
15642 \SpecialChar ~
15643 \SpecialChar ~
15644 pop\SpecialChar ~
15645 \SpecialChar ~
15646 \SpecialChar ~
15647 \SpecialChar ~
15648 \SpecialChar ~
15649 dph
15650 \newline
15651 \SpecialChar ~
15652 \SpecialChar ~
15653 \SpecialChar ~
15654 \SpecialChar ~
15655 pop\SpecialChar ~
15656 \SpecialChar ~
15657 \SpecialChar ~
15658 \SpecialChar ~
15659 \SpecialChar ~
15660 dpl
15661 \newline
15662 \SpecialChar ~
15663 \SpecialChar ~
15664 \SpecialChar ~
15665 \SpecialChar ~
15666 pop\SpecialChar ~
15667 \SpecialChar ~
15668 \SpecialChar ~
15669 \SpecialChar ~
15670 \SpecialChar ~
15671 b
15672 \newline
15673 \SpecialChar ~
15674 \SpecialChar ~
15675 \SpecialChar ~
15676 \SpecialChar ~
15677 pop\SpecialChar ~
15678 \SpecialChar ~
15679 \SpecialChar ~
15680 \SpecialChar ~
15681 \SpecialChar ~
15682 acc
15683 \newline
15684 \SpecialChar ~
15685 \SpecialChar ~
15686 \SpecialChar ~
15687 \SpecialChar ~
15688 reti
15689
15690 \layout Standard
15691 whereas nakedInterrupt looks like:
15692
15693 \layout Verse
15694
15695 \family typewriter
15696 _nakedInterrupt:
15697 \newline
15698 \SpecialChar ~
15699 \SpecialChar ~
15700 \SpecialChar ~
15701 \SpecialChar ~
15702 inc\SpecialChar ~
15703 \SpecialChar ~
15704 \SpecialChar ~
15705 \SpecialChar ~
15706 _counter ; does not change flags, no need to save psw
15707 \newline
15708 \SpecialChar ~
15709 \SpecialChar ~
15710 \SpecialChar ~
15711 \SpecialChar ~
15712 reti\SpecialChar ~
15713 \SpecialChar ~
15714 \SpecialChar ~
15715 \SpecialChar ~
15716 \SpecialChar ~
15717 \SpecialChar ~
15718 \SpecialChar ~
15719 \SpecialChar ~
15720 \SpecialChar ~
15721 \SpecialChar ~
15722 \SpecialChar ~
15723 \SpecialChar ~
15724 ;
15725  MUST explicitly include ret or reti in _naked function
15726
15727 \layout Standard
15728 The related directive #pragma exclude
15729 \begin_inset LatexCommand \index{\#pragma exclude}
15730
15731 \end_inset
15732
15733  allows a more fine grained control over pushing & popping
15734 \begin_inset LatexCommand \index{push/pop}
15735
15736 \end_inset
15737
15738  the registers.
15739
15740 \layout Standard
15741 While there is nothing preventing you from writing C code inside a 
15742 \family typewriter
15743 _naked
15744 \family default
15745  function, there are many ways to shoot yourself in the foot doing this,
15746  and it is recommended that you stick to inline assembler.
15747
15748 \layout Subsection
15749 Use of Labels within Inline Assembler
15750
15751 \layout Standard
15752 SDCC allows the use of in-line assembler with a few restrictions regarding
15753  labels.
15754  In older versions of the compiler all labels defined within inline assembler
15755  code 
15756 \emph on
15757 had to be
15758 \emph default
15759  of the form 
15760 \emph on
15761 nnnnn$
15762 \emph default
15763  where nnnn is a number less than 100 (which implies a limit of utmost 100
15764  inline assembler labels 
15765 \emph on
15766 per function
15767 \emph default
15768 \noun on
15769 )
15770 \noun default
15771 .
15772  
15773
15774 \layout Verse
15775
15776 \family typewriter
15777 _asm
15778 \begin_inset LatexCommand \index{\_asm}
15779
15780 \end_inset
15781
15782
15783 \begin_inset LatexCommand \index{\_\_asm}
15784
15785 \end_inset
15786
15787  
15788 \newline
15789 \SpecialChar ~
15790 \SpecialChar ~
15791 \SpecialChar ~
15792 \SpecialChar ~
15793 mov\SpecialChar ~
15794 \SpecialChar ~
15795 \SpecialChar ~
15796 \SpecialChar ~
15797 \SpecialChar ~
15798 b,#10 
15799 \newline
15800 00001$: 
15801 \newline
15802 \SpecialChar ~
15803 \SpecialChar ~
15804 \SpecialChar ~
15805 \SpecialChar ~
15806 djnz\SpecialChar ~
15807 \SpecialChar ~
15808 \SpecialChar ~
15809 \SpecialChar ~
15810 b,00001$ 
15811 \newline
15812 _endasm
15813 \begin_inset LatexCommand \index{\_endasm}
15814
15815 \end_inset
15816
15817
15818 \begin_inset LatexCommand \index{\_\_endasm}
15819
15820 \end_inset
15821
15822  ;
15823
15824 \layout Standard
15825 Inline assembler code cannot reference any C-Labels, however it can reference
15826  labels
15827 \begin_inset LatexCommand \index{Labels}
15828
15829 \end_inset
15830
15831  defined by the inline assembler, e.g.:
15832
15833 \layout Verse
15834
15835 \family typewriter
15836 foo() { 
15837 \newline
15838 \SpecialChar ~
15839 \SpecialChar ~
15840 \SpecialChar ~
15841 \SpecialChar ~
15842 /* some c code */ 
15843 \newline
15844 \SpecialChar ~
15845 \SpecialChar ~
15846 \SpecialChar ~
15847 \SpecialChar ~
15848 _asm 
15849 \newline
15850 \SpecialChar ~
15851 \SpecialChar ~
15852 \SpecialChar ~
15853 \SpecialChar ~
15854 \SpecialChar ~
15855 \SpecialChar ~
15856 ; some assembler code 
15857 \newline
15858 \SpecialChar ~
15859 \SpecialChar ~
15860 \SpecialChar ~
15861 \SpecialChar ~
15862 \SpecialChar ~
15863 \SpecialChar ~
15864 ljmp $0003 
15865 \newline
15866 \SpecialChar ~
15867 \SpecialChar ~
15868 \SpecialChar ~
15869 \SpecialChar ~
15870 _endasm;
15871  
15872 \newline
15873 \SpecialChar ~
15874 \SpecialChar ~
15875 \SpecialChar ~
15876 \SpecialChar ~
15877 /* some more c code */ 
15878 \newline
15879 clabel:\SpecialChar ~
15880 \SpecialChar ~
15881 /* inline assembler cannot reference this
15882  label */ 
15883 \newline
15884 \SpecialChar ~
15885 \SpecialChar ~
15886 \SpecialChar ~
15887 \SpecialChar ~
15888 _asm
15889 \newline
15890 \SpecialChar ~
15891 \SpecialChar ~
15892 \SpecialChar ~
15893 \SpecialChar ~
15894 $0003: ;label (can be referenced by inline assembler only)
15895  
15896 \newline
15897 \SpecialChar ~
15898 \SpecialChar ~
15899 \SpecialChar ~
15900 \SpecialChar ~
15901 _endasm
15902 \begin_inset LatexCommand \index{\_endasm}
15903
15904 \end_inset
15905
15906
15907 \begin_inset LatexCommand \index{\_\_endasm}
15908
15909 \end_inset
15910
15911  ; 
15912 \newline
15913 \SpecialChar ~
15914 \SpecialChar ~
15915 \SpecialChar ~
15916 \SpecialChar ~
15917 /* some more c code */
15918 \newline
15919 }
15920
15921 \layout Standard
15922 In other words inline assembly code can access labels defined in inline
15923  assembly within the scope of the function.
15924  The same goes the other way, i.e.
15925  labels defines in inline assembly can not be accessed by C statements.
15926
15927 \layout Section
15928 Interfacing with Assembler Code
15929 \begin_inset LatexCommand \index{Assembler routines}
15930
15931 \end_inset
15932
15933
15934
15935 \layout Subsection
15936 Global Registers used for Parameter Passing
15937 \begin_inset LatexCommand \index{Parameter passing}
15938
15939 \end_inset
15940
15941
15942
15943 \layout Standard
15944 The compiler always uses the global registers 
15945 \emph on
15946 DPL, DPH
15947 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15948
15949 \end_inset
15950
15951
15952 \begin_inset LatexCommand \index{DPTR}
15953
15954 \end_inset
15955
15956 , B
15957 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15958
15959 \end_inset
15960
15961  
15962 \emph default
15963 and
15964 \emph on
15965  ACC
15966 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15967
15968 \end_inset
15969
15970
15971 \emph default
15972  to pass the first parameter to a routine.
15973  The second parameter onwards is either allocated on the stack (for reentrant
15974  routines or if -
15975 \begin_inset ERT
15976 status Collapsed
15977
15978 \layout Standard
15979
15980
15981 \backslash
15982 /
15983
15984 \end_inset
15985
15986 -stack-auto is used) or in data / xdata memory (depending on the memory
15987  model).
15988  
15989
15990 \layout Subsection
15991 Assembler Routine (non-reentrant)
15992
15993 \layout Standard
15994 In the following example
15995 \begin_inset LatexCommand \index{reentrant}
15996
15997 \end_inset
15998
15999
16000 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
16001
16002 \end_inset
16003
16004  the function c_func calls an assembler routine asm_func, which takes two
16005  parameters
16006 \begin_inset LatexCommand \index{function parameter}
16007
16008 \end_inset
16009
16010 .
16011
16012 \layout Verse
16013
16014 \family typewriter
16015 extern int asm_func(unsigned char, unsigned char);
16016 \newline
16017
16018 \newline
16019 int c_func (unsigned char
16020  i, unsigned char j)
16021 \newline
16022 {
16023 \newline
16024 \SpecialChar ~
16025 \SpecialChar ~
16026 \SpecialChar ~
16027 \SpecialChar ~
16028 return asm_func(i,j);
16029 \newline
16030 }
16031 \newline
16032
16033 \newline
16034 int main()
16035 \newline
16036 {
16037 \newline
16038 \SpecialChar ~
16039 \SpecialChar ~
16040 \SpecialChar ~
16041 \SpecialChar ~
16042 return c_func(10,9);
16043 \newline
16044 }
16045
16046 \layout Standard
16047 The corresponding assembler function is:
16048
16049 \layout Verse
16050
16051 \family typewriter
16052 .globl _asm_func_PARM_2 
16053 \newline
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 \SpecialChar ~
16058 \SpecialChar ~
16059 \SpecialChar ~
16060 \SpecialChar ~
16061 \SpecialChar ~
16062 .globl _asm_func 
16063 \newline
16064 \SpecialChar ~
16065 \SpecialChar ~
16066 \SpecialChar ~
16067 \SpecialChar ~
16068 \SpecialChar ~
16069 \SpecialChar ~
16070 \SpecialChar ~
16071 \SpecialChar ~
16072 .area OSEG 
16073 \newline
16074 _asm_func_PARM_2:
16075 \newline
16076 \SpecialChar ~
16077 \SpecialChar ~
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 \SpecialChar ~
16082 \SpecialChar ~
16083 \SpecialChar ~
16084 .ds   
16085  1 
16086 \newline
16087 \SpecialChar ~
16088 \SpecialChar ~
16089 \SpecialChar ~
16090 \SpecialChar ~
16091 \SpecialChar ~
16092 \SpecialChar ~
16093 \SpecialChar ~
16094 \SpecialChar ~
16095 .area CSEG 
16096 \newline
16097 _asm_func: 
16098 \newline
16099 \SpecialChar ~
16100 \SpecialChar ~
16101 \SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104 \SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 mov\SpecialChar ~
16108 \SpecialChar ~
16109 \SpecialChar ~
16110 \SpecialChar ~
16111 a,dpl 
16112 \newline
16113 \SpecialChar ~
16114 \SpecialChar ~
16115 \SpecialChar ~
16116 \SpecialChar ~
16117 \SpecialChar ~
16118 \SpecialChar ~
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 add\SpecialChar ~
16122 \SpecialChar ~
16123 \SpecialChar ~
16124 \SpecialChar ~
16125 a,_asm_func_PARM_2 
16126 \newline
16127 \SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 \SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 mov\SpecialChar ~
16136 \SpecialChar ~
16137 \SpecialChar ~
16138 \SpecialChar ~
16139 dpl,a 
16140 \newline
16141 \SpecialChar ~
16142 \SpecialChar ~
16143 \SpecialChar ~
16144 \SpecialChar ~
16145 \SpecialChar ~
16146 \SpecialChar ~
16147 \SpecialChar ~
16148 \SpecialChar ~
16149 mov\SpecialChar ~
16150 \SpecialChar ~
16151 \SpecialChar ~
16152 \SpecialChar ~
16153 dph
16154 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16155
16156 \end_inset
16157
16158 ,#0x00 
16159 \newline
16160 \SpecialChar ~
16161 \SpecialChar ~
16162 \SpecialChar ~
16163 \SpecialChar ~
16164 \SpecialChar ~
16165 \SpecialChar ~
16166 \SpecialChar ~
16167 \SpecialChar ~
16168 ret
16169
16170 \layout Standard
16171 Note here that the return values
16172 \begin_inset LatexCommand \index{return value}
16173
16174 \end_inset
16175
16176  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16177  two byte values.
16178  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16179 b' & 'acc' for four byte values.
16180
16181 \layout Standard
16182 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16183  the parameter number starting from 1, and counting from the left.
16184  The first parameter is passed in 
16185 \begin_inset Quotes eld
16186 \end_inset
16187
16188 dpl
16189 \begin_inset Quotes erd
16190 \end_inset
16191
16192  for a one byte parameter, 
16193 \begin_inset Quotes eld
16194 \end_inset
16195
16196 dptr
16197 \begin_inset Quotes erd
16198 \end_inset
16199
16200  for two bytes, 
16201 \begin_inset Quotes eld
16202 \end_inset
16203
16204 b,dptr
16205 \begin_inset Quotes erd
16206 \end_inset
16207
16208  for three bytes and 
16209 \begin_inset Quotes eld
16210 \end_inset
16211
16212 acc,b,dptr
16213 \begin_inset Quotes erd
16214 \end_inset
16215
16216  for a four bytes parameter.
16217  The variable name for the second parameter will be _<function_name>_PARM_2.
16218 \newline
16219
16220 \newline
16221 Assem
16222 ble the assembler routine with the following command:
16223 \newline
16224
16225 \newline
16226
16227 \family sans
16228 \series bold
16229 asx8051 -losg asmfunc.asm
16230 \newline
16231
16232 \newline
16233
16234 \family default
16235 \series default
16236 Then compile and link the assembler routine to the C source file with the
16237  following command:
16238 \newline
16239
16240 \newline
16241
16242 \family sans
16243 \series bold
16244 sdcc cfunc.c asmfunc.rel
16245
16246 \layout Subsection
16247 Assembler Routine (reentrant)
16248
16249 \layout Standard
16250 In this case
16251 \begin_inset LatexCommand \index{reentrant}
16252
16253 \end_inset
16254
16255
16256 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16257
16258 \end_inset
16259
16260  the second parameter
16261 \begin_inset LatexCommand \index{function parameter}
16262
16263 \end_inset
16264
16265  onwards will be passed on the stack, the parameters are pushed from right
16266  to left i.e.
16267  after the call the leftmost parameter will be on the top of the stack.
16268  Here is an example:
16269
16270 \layout Verse
16271
16272 \family typewriter
16273 extern int asm_func(unsigned char, unsigned char);
16274 \newline
16275
16276 \newline
16277 int c_func (unsigned char
16278  i, unsigned char j) reentrant 
16279 \newline
16280
16281 \newline
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 \SpecialChar ~
16286 return asm_func(i,j); 
16287 \newline
16288
16289 \newline
16290
16291 \newline
16292 int main() 
16293 \newline
16294
16295 \newline
16296 \SpecialChar ~
16297 \SpecialChar ~
16298 \SpecialChar ~
16299 \SpecialChar ~
16300 return
16301  c_func(10,9); 
16302 \newline
16303 }
16304
16305 \layout Standard
16306 The corresponding assembler routine is:
16307
16308 \layout Verse
16309
16310 \family typewriter
16311 .globl _asm_func 
16312 \newline
16313 _asm_func: 
16314 \newline
16315 \SpecialChar ~
16316 \SpecialChar ~
16317 \SpecialChar ~
16318 \SpecialChar ~
16319 push  _bp 
16320 \newline
16321 \SpecialChar ~
16322 \SpecialChar ~
16323 \SpecialChar ~
16324 \SpecialChar ~
16325 mov _bp,sp 
16326 \newline
16327 \SpecialChar ~
16328 \SpecialChar ~
16329 \SpecialChar ~
16330 \SpecialChar ~
16331 mov r2,dpl
16332 \newline
16333 \SpecialChar ~
16334 \SpecialChar ~
16335 \SpecialChar ~
16336 \SpecialChar ~
16337 mov a,_bp 
16338 \newline
16339 \SpecialChar ~
16340 \SpecialChar ~
16341 \SpecialChar ~
16342 \SpecialChar ~
16343 add
16344  a,#0xfd 
16345 \newline
16346 \SpecialChar ~
16347 \SpecialChar ~
16348 \SpecialChar ~
16349 \SpecialChar ~
16350 mov r0,a 
16351 \newline
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 \SpecialChar ~
16356 add  a,#0xfc ;?
16357 \newline
16358 \SpecialChar ~
16359 \SpecialChar ~
16360 \SpecialChar ~
16361 \SpecialChar ~
16362 mov  r1,a 
16363 \newline
16364 \SpecialChar ~
16365 \SpecialChar ~
16366 \SpecialChar ~
16367 \SpecialChar ~
16368 mov  a,@r0 
16369 \newline
16370 \SpecialChar ~
16371 \SpecialChar ~
16372 \SpecialChar ~
16373 \SpecialChar ~
16374 add  a,r2 ;?
16375 \newline
16376 \SpecialChar ~
16377 \SpecialChar ~
16378 \SpecialChar ~
16379 \SpecialChar ~
16380 mov  dpl,a
16381  
16382 \newline
16383 \SpecialChar ~
16384 \SpecialChar ~
16385 \SpecialChar ~
16386 \SpecialChar ~
16387 mov  dph,#0x00 
16388 \newline
16389 \SpecialChar ~
16390 \SpecialChar ~
16391 \SpecialChar ~
16392 \SpecialChar ~
16393 mov  sp,_bp 
16394 \newline
16395 \SpecialChar ~
16396 \SpecialChar ~
16397 \SpecialChar ~
16398 \SpecialChar ~
16399 pop  _bp 
16400 \newline
16401 \SpecialChar ~
16402 \SpecialChar ~
16403 \SpecialChar ~
16404 \SpecialChar ~
16405 ret
16406
16407 \layout Standard
16408 \added_space_bottom bigskip 
16409 The compiling and linking procedure remains the same, however note the extra
16410  entry & exit linkage required for the assembler code, _bp is the stack
16411  frame pointer and is used to compute the offset into the stack for parameters
16412  and local variables.
16413
16414
16415
16416 \layout Section
16417 int (16 bit)
16418 \begin_inset LatexCommand \index{int (16 bit)}
16419
16420 \end_inset
16421
16422  and long (32 bit)
16423 \begin_inset LatexCommand \index{long (32 bit)}
16424
16425 \end_inset
16426
16427  Support
16428
16429 \layout Standard
16430 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16431  multiplication and modulus operations are implemented by support routines.
16432  These support routines are all developed in ANSI-C to facilitate porting
16433  to other MCUs, although some model specific assembler optimizations are
16434  used.
16435  The following files contain the described routines, all of them can be
16436  found in <installdir>/share/sdcc/lib.
16437 \newline
16438
16439
16440 \layout Standard
16441 \align center
16442 \begin_inset Tabular
16443 <lyxtabular version="3" rows="11" columns="2">
16444 <features>
16445 <column alignment="left" valignment="top" leftline="true" width="0">
16446 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16447 <row topline="true" bottomline="true">
16448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16449 \begin_inset Text
16450
16451 \layout Standard
16452
16453 \series bold
16454 Function
16455
16456 \end_inset
16457 </cell>
16458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16459 \begin_inset Text
16460
16461 \layout Standard
16462
16463 \series bold
16464 Description
16465
16466 \end_inset
16467 </cell>
16468 </row>
16469 <row topline="true">
16470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16471 \begin_inset Text
16472
16473 \layout Standard
16474 _mulint.c 
16475
16476 \end_inset
16477 </cell>
16478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16479 \begin_inset Text
16480
16481 \layout Standard
16482 16 bit multiplication
16483
16484 \end_inset
16485 </cell>
16486 </row>
16487 <row topline="true">
16488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16489 \begin_inset Text
16490
16491 \layout Standard
16492 _divsint.c 
16493
16494 \end_inset
16495 </cell>
16496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16497 \begin_inset Text
16498
16499 \layout Standard
16500  signed 16 bit division (calls _divuint)
16501
16502 \end_inset
16503 </cell>
16504 </row>
16505 <row topline="true">
16506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16507 \begin_inset Text
16508
16509 \layout Standard
16510 _divuint.c 
16511
16512 \end_inset
16513 </cell>
16514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16515 \begin_inset Text
16516
16517 \layout Standard
16518  unsigned 16 bit division
16519
16520 \end_inset
16521 </cell>
16522 </row>
16523 <row topline="true">
16524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16525 \begin_inset Text
16526
16527 \layout Standard
16528 _modsint.c
16529
16530 \end_inset
16531 </cell>
16532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16533 \begin_inset Text
16534
16535 \layout Standard
16536 signed 16 bit modulus (calls _moduint)
16537
16538 \end_inset
16539 </cell>
16540 </row>
16541 <row topline="true">
16542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16543 \begin_inset Text
16544
16545 \layout Standard
16546 _moduint.c
16547
16548 \end_inset
16549 </cell>
16550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16551 \begin_inset Text
16552
16553 \layout Standard
16554 unsigned 16 bit modulus
16555
16556 \end_inset
16557 </cell>
16558 </row>
16559 <row topline="true">
16560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16561 \begin_inset Text
16562
16563 \layout Standard
16564 _mullong.c
16565
16566 \end_inset
16567 </cell>
16568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16569 \begin_inset Text
16570
16571 \layout Standard
16572 32 bit multiplication
16573
16574 \end_inset
16575 </cell>
16576 </row>
16577 <row topline="true">
16578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16579 \begin_inset Text
16580
16581 \layout Standard
16582 _divslong.c 
16583
16584 \end_inset
16585 </cell>
16586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16587 \begin_inset Text
16588
16589 \layout Standard
16590  signed 32 division (calls _divulong)
16591
16592 \end_inset
16593 </cell>
16594 </row>
16595 <row topline="true">
16596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16597 \begin_inset Text
16598
16599 \layout Standard
16600 _divulong.c 
16601
16602 \end_inset
16603 </cell>
16604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16605 \begin_inset Text
16606
16607 \layout Standard
16608 unsigned 32 division
16609
16610 \end_inset
16611 </cell>
16612 </row>
16613 <row topline="true">
16614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16615 \begin_inset Text
16616
16617 \layout Standard
16618 _modslong.c
16619
16620 \end_inset
16621 </cell>
16622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16623 \begin_inset Text
16624
16625 \layout Standard
16626  signed 32 bit modulus (calls _modulong)
16627
16628 \end_inset
16629 </cell>
16630 </row>
16631 <row topline="true" bottomline="true">
16632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16633 \begin_inset Text
16634
16635 \layout Standard
16636 _modulong.c
16637
16638 \end_inset
16639 </cell>
16640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16641 \begin_inset Text
16642
16643 \layout Standard
16644 unsigned 32 bit modulus
16645
16646 \end_inset
16647 </cell>
16648 </row>
16649 </lyxtabular>
16650
16651 \end_inset
16652
16653
16654 \newline
16655
16656
16657 \layout Standard
16658 Since they are compiled as 
16659 \emph on
16660 non-reentrant
16661 \emph default
16662
16663 \begin_inset LatexCommand \index{reentrant}
16664
16665 \end_inset
16666
16667 , interrupt
16668 \begin_inset LatexCommand \index{interrupt}
16669
16670 \end_inset
16671
16672  service routines should not do any of the above operations.
16673  If this is unavoidable then the above routines will need to be compiled
16674  with the 
16675 \emph on
16676 -
16677 \begin_inset ERT
16678 status Collapsed
16679
16680 \layout Standard
16681
16682
16683 \backslash
16684 /
16685
16686 \end_inset
16687
16688 -stack-auto
16689 \begin_inset LatexCommand \index{-\/-stack-auto}
16690
16691 \end_inset
16692
16693
16694 \emph default
16695  option, after which the source program will have to be compiled with 
16696 \emph on
16697 -
16698 \begin_inset ERT
16699 status Collapsed
16700
16701 \layout Standard
16702
16703
16704 \backslash
16705 /
16706
16707 \end_inset
16708
16709 -int-long-reent
16710 \begin_inset LatexCommand \index{-\/-int-long-reent}
16711
16712 \end_inset
16713
16714
16715 \emph default
16716  option.
16717  Notice that you don't have to call these routines directly.
16718  The compiler will use them automatically every time an integer operation
16719  is required.
16720
16721 \layout Section
16722 Floating Point Support
16723 \begin_inset LatexCommand \index{Floating point support}
16724
16725 \end_inset
16726
16727
16728
16729 \layout Standard
16730 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16731  The floating point support routines are derived from gcc's floatlib.c and
16732  consist of the following routines:
16733 \newline
16734
16735
16736 \layout Standard
16737 \align center
16738
16739 \size footnotesize
16740 \begin_inset Tabular
16741 <lyxtabular version="3" rows="17" columns="2">
16742 <features>
16743 <column alignment="left" valignment="top" leftline="true" width="0">
16744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16745 <row topline="true" bottomline="true">
16746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16747 \begin_inset Text
16748
16749 \layout Standard
16750
16751 \family roman
16752 \series medium
16753 \shape up
16754 \size normal
16755 \emph off
16756 \bar no
16757 \noun off
16758 \color none
16759 Function 
16760
16761 \end_inset
16762 </cell>
16763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16764 \begin_inset Text
16765
16766 \layout Standard
16767 Description
16768
16769 \end_inset
16770 </cell>
16771 </row>
16772 <row topline="true">
16773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16774 \begin_inset Text
16775
16776 \layout Standard
16777
16778 \family roman
16779 \series medium
16780 \shape up
16781 \size normal
16782 \emph off
16783 \bar no
16784 \noun off
16785 \color none
16786 _fsadd.c
16787
16788 \end_inset
16789 </cell>
16790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16791 \begin_inset Text
16792
16793 \layout Standard
16794
16795 \family roman
16796 \series medium
16797 \shape up
16798 \size normal
16799 \emph off
16800 \bar no
16801 \noun off
16802 \color none
16803 add floating point numbers
16804
16805 \end_inset
16806 </cell>
16807 </row>
16808 <row topline="true">
16809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16810 \begin_inset Text
16811
16812 \layout Standard
16813
16814 \family roman
16815 \series medium
16816 \shape up
16817 \size normal
16818 \emph off
16819 \bar no
16820 \noun off
16821 \color none
16822 _fssub.c 
16823
16824 \end_inset
16825 </cell>
16826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16827 \begin_inset Text
16828
16829 \layout Standard
16830
16831 \family roman
16832 \series medium
16833 \shape up
16834 \size normal
16835 \emph off
16836 \bar no
16837 \noun off
16838 \color none
16839 subtract floating point numbers 
16840
16841 \end_inset
16842 </cell>
16843 </row>
16844 <row topline="true">
16845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16846 \begin_inset Text
16847
16848 \layout Standard
16849
16850 \family roman
16851 \series medium
16852 \shape up
16853 \size normal
16854 \emph off
16855 \bar no
16856 \noun off
16857 \color none
16858 _fsdiv.c 
16859
16860 \end_inset
16861 </cell>
16862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16863 \begin_inset Text
16864
16865 \layout Standard
16866
16867 \family roman
16868 \series medium
16869 \shape up
16870 \size normal
16871 \emph off
16872 \bar no
16873 \noun off
16874 \color none
16875 divide floating point numbers 
16876
16877 \end_inset
16878 </cell>
16879 </row>
16880 <row topline="true">
16881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16882 \begin_inset Text
16883
16884 \layout Standard
16885
16886 \family roman
16887 \series medium
16888 \shape up
16889 \size normal
16890 \emph off
16891 \bar no
16892 \noun off
16893 \color none
16894 _fsmul.c 
16895
16896 \end_inset
16897 </cell>
16898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16899 \begin_inset Text
16900
16901 \layout Standard
16902
16903 \family roman
16904 \series medium
16905 \shape up
16906 \size normal
16907 \emph off
16908 \bar no
16909 \noun off
16910 \color none
16911 multiply floating point numbers 
16912
16913 \end_inset
16914 </cell>
16915 </row>
16916 <row topline="true">
16917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16918 \begin_inset Text
16919
16920 \layout Standard
16921
16922 \family roman
16923 \series medium
16924 \shape up
16925 \size normal
16926 \emph off
16927 \bar no
16928 \noun off
16929 \color none
16930 _fs2uchar.c
16931
16932 \end_inset
16933 </cell>
16934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16935 \begin_inset Text
16936
16937 \layout Standard
16938
16939 \family roman
16940 \series medium
16941 \shape up
16942 \size normal
16943 \emph off
16944 \bar no
16945 \noun off
16946 \color none
16947 convert floating point to unsigned char
16948
16949 \end_inset
16950 </cell>
16951 </row>
16952 <row topline="true">
16953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16954 \begin_inset Text
16955
16956 \layout Standard
16957
16958 \family roman
16959 \series medium
16960 \shape up
16961 \size normal
16962 \emph off
16963 \bar no
16964 \noun off
16965 \color none
16966 _fs2char.c
16967
16968 \end_inset
16969 </cell>
16970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16971 \begin_inset Text
16972
16973 \layout Standard
16974
16975 \family roman
16976 \series medium
16977 \shape up
16978 \size normal
16979 \emph off
16980 \bar no
16981 \noun off
16982 \color none
16983 convert floating point to signed char
16984
16985 \end_inset
16986 </cell>
16987 </row>
16988 <row topline="true">
16989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16990 \begin_inset Text
16991
16992 \layout Standard
16993
16994 \family roman
16995 \series medium
16996 \shape up
16997 \size normal
16998 \emph off
16999 \bar no
17000 \noun off
17001 \color none
17002 _fs2uint.c
17003
17004 \end_inset
17005 </cell>
17006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17007 \begin_inset Text
17008
17009 \layout Standard
17010
17011 \family roman
17012 \series medium
17013 \shape up
17014 \size normal
17015 \emph off
17016 \bar no
17017 \noun off
17018 \color none
17019 convert floating point to unsigned int
17020
17021 \end_inset
17022 </cell>
17023 </row>
17024 <row topline="true">
17025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17026 \begin_inset Text
17027
17028 \layout Standard
17029
17030 \family roman
17031 \series medium
17032 \shape up
17033 \size normal
17034 \emph off
17035 \bar no
17036 \noun off
17037 \color none
17038 _fs2int.c
17039
17040 \end_inset
17041 </cell>
17042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17043 \begin_inset Text
17044
17045 \layout Standard
17046
17047 \family roman
17048 \series medium
17049 \shape up
17050 \size normal
17051 \emph off
17052 \bar no
17053 \noun off
17054 \color none
17055 convert floating point to signed int
17056
17057 \end_inset
17058 </cell>
17059 </row>
17060 <row topline="true">
17061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17062 \begin_inset Text
17063
17064 \layout Standard
17065
17066 \family roman
17067 \series medium
17068 \shape up
17069 \size normal
17070 \emph off
17071 \bar no
17072 \noun off
17073 \color none
17074 _fs2ulong.
17075 \family default
17076 \series default
17077 \shape default
17078 \size default
17079 \emph default
17080 \bar default
17081 \noun default
17082 c
17083
17084 \end_inset
17085 </cell>
17086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17087 \begin_inset Text
17088
17089 \layout Standard
17090
17091 \family roman
17092 \series medium
17093 \shape up
17094 \size normal
17095 \emph off
17096 \bar no
17097 \noun off
17098 \color none
17099 convert floating point to unsigned long
17100
17101 \end_inset
17102 </cell>
17103 </row>
17104 <row topline="true">
17105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17106 \begin_inset Text
17107
17108 \layout Standard
17109
17110 \family roman
17111 \series medium
17112 \shape up
17113 \size normal
17114 \emph off
17115 \bar no
17116 \noun off
17117 \color none
17118 _fs2long.c
17119
17120 \end_inset
17121 </cell>
17122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17123 \begin_inset Text
17124
17125 \layout Standard
17126
17127 \family roman
17128 \series medium
17129 \shape up
17130 \size normal
17131 \emph off
17132 \bar no
17133 \noun off
17134 \color none
17135 convert floating point to signed long
17136
17137 \end_inset
17138 </cell>
17139 </row>
17140 <row topline="true">
17141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17142 \begin_inset Text
17143
17144 \layout Standard
17145
17146 \family roman
17147 \series medium
17148 \shape up
17149 \size normal
17150 \emph off
17151 \bar no
17152 \noun off
17153 \color none
17154 _uchar2fs.c
17155
17156 \end_inset
17157 </cell>
17158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17159 \begin_inset Text
17160
17161 \layout Standard
17162
17163 \family roman
17164 \series medium
17165 \shape up
17166 \size normal
17167 \emph off
17168 \bar no
17169 \noun off
17170 \color none
17171 convert unsigned char to floating point
17172
17173 \end_inset
17174 </cell>
17175 </row>
17176 <row topline="true">
17177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17178 \begin_inset Text
17179
17180 \layout Standard
17181
17182 \family roman
17183 \series medium
17184 \shape up
17185 \size normal
17186 \emph off
17187 \bar no
17188 \noun off
17189 \color none
17190 _char2fs.c
17191
17192 \end_inset
17193 </cell>
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17195 \begin_inset Text
17196
17197 \layout Standard
17198
17199 \family roman
17200 \series medium
17201 \shape up
17202 \size normal
17203 \emph off
17204 \bar no
17205 \noun off
17206 \color none
17207 convert char to floating point number
17208
17209 \end_inset
17210 </cell>
17211 </row>
17212 <row topline="true">
17213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17214 \begin_inset Text
17215
17216 \layout Standard
17217
17218 \family roman
17219 \series medium
17220 \shape up
17221 \size normal
17222 \emph off
17223 \bar no
17224 \noun off
17225 \color none
17226 _uint2fs.c
17227
17228 \end_inset
17229 </cell>
17230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17231 \begin_inset Text
17232
17233 \layout Standard
17234
17235 \family roman
17236 \series medium
17237 \shape up
17238 \size normal
17239 \emph off
17240 \bar no
17241 \noun off
17242 \color none
17243 convert unsigned int to floating point
17244
17245 \end_inset
17246 </cell>
17247 </row>
17248 <row topline="true">
17249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17250 \begin_inset Text
17251
17252 \layout Standard
17253
17254 \family roman
17255 \series medium
17256 \shape up
17257 \size normal
17258 \emph off
17259 \bar no
17260 \noun off
17261 \color none
17262 _int2fs.c
17263
17264 \end_inset
17265 </cell>
17266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17267 \begin_inset Text
17268
17269 \layout Standard
17270
17271 \family roman
17272 \series medium
17273 \shape up
17274 \size normal
17275 \emph off
17276 \bar no
17277 \noun off
17278 \color none
17279 convert int to floating point numbers
17280
17281 \end_inset
17282 </cell>
17283 </row>
17284 <row topline="true">
17285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17286 \begin_inset Text
17287
17288 \layout Standard
17289
17290 \family roman
17291 \series medium
17292 \shape up
17293 \size normal
17294 \emph off
17295 \bar no
17296 \noun off
17297 \color none
17298 _ulong2fs.c
17299
17300 \end_inset
17301 </cell>
17302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17303 \begin_inset Text
17304
17305 \layout Standard
17306
17307 \family roman
17308 \series medium
17309 \shape up
17310 \size normal
17311 \emph off
17312 \bar no
17313 \noun off
17314 \color none
17315 convert unsigned long to floating point number
17316
17317 \end_inset
17318 </cell>
17319 </row>
17320 <row topline="true" bottomline="true">
17321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17322 \begin_inset Text
17323
17324 \layout Standard
17325
17326 \family roman
17327 \series medium
17328 \shape up
17329 \size normal
17330 \emph off
17331 \bar no
17332 \noun off
17333 \color none
17334 _long2fs.c
17335
17336 \end_inset
17337 </cell>
17338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17339 \begin_inset Text
17340
17341 \layout Standard
17342
17343 \family roman
17344 \series medium
17345 \shape up
17346 \size normal
17347 \emph off
17348 \bar no
17349 \noun off
17350 \color none
17351 convert long to floating point number
17352
17353 \end_inset
17354 </cell>
17355 </row>
17356 </lyxtabular>
17357
17358 \end_inset
17359
17360
17361 \newline
17362
17363
17364 \layout Standard
17365 \added_space_bottom bigskip 
17366 These support routines are developed in ANSI-C so there is room for space
17367  and speed improvement
17368 \begin_inset Foot
17369 collapsed false
17370
17371 \layout Standard
17372 These floating point routines (
17373 \emph on
17374 not
17375 \emph default
17376  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17377  
17378
17379 \end_inset
17380
17381 .
17382  Note if all these routines are used simultaneously the data space might
17383  overflow.
17384  For serious floating point usage the large model might be needed.
17385  Also notice that you don't have to call this routines directly.
17386  The compiler will use them automatically every time a floating point operation
17387  is required.
17388
17389
17390
17391 \layout Section
17392 Library Routines
17393 \begin_inset LatexCommand \index{Libraries}
17394
17395 \end_inset
17396
17397
17398
17399 \layout Standard
17400
17401 \emph on
17402 <pending: this is messy and incomplete - a little more information is in
17403  sdcc/doc/libdoc.txt
17404 \emph default
17405  >
17406
17407 \layout Subsection
17408 Compiler support routines (_gptrget, _mulint etc.)
17409
17410 \layout Subsection
17411 Stdclib functions (puts, printf, strcat etc.)
17412
17413 \layout Subsubsection
17414 <stdio.h>
17415
17416 \layout Paragraph
17417 getchar(), putchar()
17418
17419 \layout Standard
17420 \begin_inset LatexCommand \index{<stdio.h>}
17421
17422 \end_inset
17423
17424 As usual on embedded systems you have to provide your own 
17425 \family typewriter
17426 getchar()
17427 \begin_inset LatexCommand \index{getchar()}
17428
17429 \end_inset
17430
17431  
17432 \family default
17433 and 
17434 \family typewriter
17435 putchar()
17436 \begin_inset LatexCommand \index{putchar()}
17437
17438 \end_inset
17439
17440
17441 \family default
17442  routines.
17443  SDCC does not know whether the system connects to a serial line with or
17444  without handshake, LCD, keyboard or other device.
17445  And whether a 
17446 \family typewriter
17447 lf
17448 \family default
17449  to 
17450 \family typewriter
17451 crlf
17452 \family default
17453  conversion within 
17454 \family typewriter
17455 putchar()
17456 \family default
17457  is intended.
17458  You'll find examples for serial routines f.e.
17459  in sdcc/device/lib.
17460  For the mcs51 this minimalistic polling 
17461 \family typewriter
17462 putchar()
17463 \family default
17464  routine might be a start:
17465
17466 \layout Verse
17467
17468 \family typewriter
17469 void putchar (char c) { 
17470 \newline
17471 \SpecialChar ~
17472 \SpecialChar ~
17473 \SpecialChar ~
17474 \SpecialChar ~
17475 while (!TI)\SpecialChar ~
17476 \SpecialChar ~
17477 \SpecialChar ~
17478  /* assumes UART is initialized */
17479 \newline
17480 \SpecialChar ~
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 \SpecialChar ~
17484 \SpecialChar ~
17485 \SpecialChar ~
17486 \SpecialChar ~
17487 \SpecialChar ~
17488 ;
17489 \newline
17490 \SpecialChar ~
17491 \SpecialChar ~
17492 \SpecialChar ~
17493 \SpecialChar ~
17494 TI
17495  = 0;
17496 \newline
17497 \SpecialChar ~
17498 \SpecialChar ~
17499 \SpecialChar ~
17500 \SpecialChar ~
17501 SBUF = c;
17502 \newline
17503 }
17504
17505 \layout Paragraph
17506 printf()
17507
17508 \layout Standard
17509 The default
17510 \family typewriter
17511  printf()
17512 \begin_inset LatexCommand \index{printf()}
17513
17514 \end_inset
17515
17516
17517 \family default
17518  implementation in
17519 \family typewriter
17520  printf_large.c
17521 \family default
17522  does not support float (except on ds390).
17523  To enable this recompile it with the option 
17524 \emph on
17525 -
17526 \begin_inset ERT
17527 status Collapsed
17528
17529 \layout Standard
17530
17531
17532 \backslash
17533 /
17534
17535 \end_inset
17536
17537 DUSE_FLOATS=1
17538 \begin_inset LatexCommand \index{USE\_FLOATS}
17539
17540 \end_inset
17541
17542
17543 \emph default
17544  on the command line.
17545  Use
17546 \emph on
17547  -
17548 \begin_inset ERT
17549 status Collapsed
17550
17551 \layout Standard
17552
17553
17554 \backslash
17555 /
17556
17557 \end_inset
17558
17559 -model-large
17560 \begin_inset LatexCommand \index{-\/-model-large}
17561
17562 \end_inset
17563
17564
17565 \emph default
17566  for the mcs51 port, since this uses a lot of memory.
17567
17568 \layout Standard
17569 If you're short on code memory you might want to use 
17570 \family typewriter
17571 printf_small()
17572 \begin_inset LatexCommand \index{printf\_small()}
17573
17574 \end_inset
17575
17576
17577 \family default
17578  
17579 \emph on
17580 instead
17581 \emph default
17582  of
17583 \family typewriter
17584  printf().
17585
17586 \family default
17587  For the mcs51 there additionally are assembly versions 
17588 \family typewriter
17589 printf_tiny()
17590 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17591
17592 \end_inset
17593
17594
17595 \family default
17596  (subset of printf using less than 270 bytes) and 
17597 \family typewriter
17598 printf_fast()
17599 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17600
17601 \end_inset
17602
17603  
17604 \family default
17605 and
17606 \family typewriter
17607  printf_fast_f()
17608 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17609
17610 \end_inset
17611
17612
17613 \family default
17614  (floating-point aware version of printf_fast) which should fit the requirements
17615  of many embedded systems (printf_fast() can be customized by unsetting
17616  #defines to 
17617 \emph on
17618 not
17619 \emph default
17620  support long variables and field widths).
17621  Be sure to use only one of these printf options within a project.
17622 \newline
17623
17624
17625 \layout Standard
17626 Feature matrix of different 
17627 \emph on
17628 printf
17629 \emph default
17630  options on mcs51.
17631
17632 \layout Standard
17633 \begin_inset Tabular
17634 <lyxtabular version="3" rows="14" columns="7">
17635 <features islongtable="true">
17636 <column alignment="left" valignment="center" leftline="true" width="14col%">
17637 <column alignment="center" valignment="top" leftline="true" width="0">
17638 <column alignment="center" valignment="top" leftline="true" width="12col%">
17639 <column alignment="center" valignment="top" leftline="true" width="10col%">
17640 <column alignment="center" valignment="top" leftline="true" width="0">
17641 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17642 <column alignment="center" valignment="top" rightline="true" width="0">
17643 <row topline="true" bottomline="true" endhead="true">
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17645 \begin_inset Text
17646
17647 \layout Standard
17648
17649 \series bold
17650 \size large
17651 mcs51
17652
17653 \end_inset
17654 </cell>
17655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17656 \begin_inset Text
17657
17658 \layout Standard
17659 printf
17660 \begin_inset LatexCommand \index{printf}
17661
17662 \end_inset
17663
17664
17665
17666 \end_inset
17667 </cell>
17668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17669 \begin_inset Text
17670
17671 \layout Standard
17672 printf 
17673 \size scriptsize
17674 USE_FLOATS=1
17675
17676 \end_inset
17677 </cell>
17678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17679 \begin_inset Text
17680
17681 \layout Standard
17682 printf_small
17683
17684 \end_inset
17685 </cell>
17686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17687 \begin_inset Text
17688
17689 \layout Standard
17690 printf_fast
17691
17692 \end_inset
17693 </cell>
17694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17695 \begin_inset Text
17696
17697 \layout Standard
17698 printf_fast_f
17699
17700 \end_inset
17701 </cell>
17702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17703 \begin_inset Text
17704
17705 \layout Standard
17706 printf_tiny
17707
17708 \end_inset
17709 </cell>
17710 </row>
17711 <row topline="true" endhead="true">
17712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17713 \begin_inset Text
17714
17715 \layout Standard
17716 filename
17717
17718 \end_inset
17719 </cell>
17720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17721 \begin_inset Text
17722
17723 \layout Standard
17724
17725 \size scriptsize
17726 printf_large.c
17727
17728 \end_inset
17729 </cell>
17730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17731 \begin_inset Text
17732
17733 \layout Standard
17734
17735 \size scriptsize
17736 printf_large.c
17737
17738 \end_inset
17739 </cell>
17740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17741 \begin_inset Text
17742
17743 \layout Standard
17744
17745 \size scriptsize
17746 printfl.c
17747
17748 \end_inset
17749 </cell>
17750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17751 \begin_inset Text
17752
17753 \layout Standard
17754
17755 \size scriptsize
17756 printf_fast.c
17757
17758 \end_inset
17759 </cell>
17760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17761 \begin_inset Text
17762
17763 \layout Standard
17764
17765 \size scriptsize
17766 printf_fast_f.c
17767
17768 \end_inset
17769 </cell>
17770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17771 \begin_inset Text
17772
17773 \layout Standard
17774
17775 \size scriptsize
17776 printf_tiny.c
17777
17778 \end_inset
17779 </cell>
17780 </row>
17781 <row topline="true" endhead="true">
17782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17783 \begin_inset Text
17784
17785 \layout Standard
17786 \begin_inset Quotes sld
17787 \end_inset
17788
17789 Hello World
17790 \begin_inset Quotes srd
17791 \end_inset
17792
17793  size
17794
17795 \layout Standard
17796 small / large
17797
17798 \end_inset
17799 </cell>
17800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17801 \begin_inset Text
17802
17803 \layout Standard
17804 1.7k / 2.4k
17805
17806 \end_inset
17807 </cell>
17808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17809 \begin_inset Text
17810
17811 \layout Standard
17812 4.3k / 5.6k
17813
17814 \end_inset
17815 </cell>
17816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17817 \begin_inset Text
17818
17819 \layout Standard
17820 1.2k / 1.8k
17821
17822 \end_inset
17823 </cell>
17824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17825 \begin_inset Text
17826
17827 \layout Standard
17828 1.3k / 1.3k
17829
17830 \end_inset
17831 </cell>
17832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17833 \begin_inset Text
17834
17835 \layout Standard
17836 1.9k / 1.9k
17837
17838 \end_inset
17839 </cell>
17840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17841 \begin_inset Text
17842
17843 \layout Standard
17844 0.44k / 0.44k
17845
17846 \end_inset
17847 </cell>
17848 </row>
17849 <row topline="true" endhead="true">
17850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17851 \begin_inset Text
17852
17853 \layout Standard
17854 code size
17855
17856 \layout Standard
17857 small / large
17858
17859 \end_inset
17860 </cell>
17861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17862 \begin_inset Text
17863
17864 \layout Standard
17865 1.4k / 2.0k
17866
17867 \end_inset
17868 </cell>
17869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17870 \begin_inset Text
17871
17872 \layout Standard
17873 2.8k / 3.7k
17874
17875 \end_inset
17876 </cell>
17877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17878 \begin_inset Text
17879
17880 \layout Standard
17881 0.45k / 0.47k (+ _ltoa)
17882
17883 \end_inset
17884 </cell>
17885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17886 \begin_inset Text
17887
17888 \layout Standard
17889 1.2k / 1.2k
17890
17891 \end_inset
17892 </cell>
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17894 \begin_inset Text
17895
17896 \layout Standard
17897 1.6k / 1.6k
17898
17899 \end_inset
17900 </cell>
17901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17902 \begin_inset Text
17903
17904 \layout Standard
17905 0.26k / 0.26k
17906
17907 \end_inset
17908 </cell>
17909 </row>
17910 <row topline="true">
17911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17912 \begin_inset Text
17913
17914 \layout Standard
17915 formats
17916
17917 \end_inset
17918 </cell>
17919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17920 \begin_inset Text
17921
17922 \layout Standard
17923 cdi
17924 \emph on
17925 o
17926 \emph default
17927 psux
17928
17929 \end_inset
17930 </cell>
17931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17932 \begin_inset Text
17933
17934 \layout Standard
17935
17936 \family roman
17937 \series medium
17938 \shape up
17939 \size normal
17940 \emph off
17941 \bar no
17942 \noun off
17943 \color none
17944 cd
17945 \family default
17946 \series default
17947 \shape default
17948 \size default
17949 \emph default
17950 \bar default
17951 \noun default
17952 f
17953 \family roman
17954 \series medium
17955 \shape up
17956 \size normal
17957 \emph off
17958 \bar no
17959 \noun off
17960 i
17961 \family default
17962 \series default
17963 \shape default
17964 \size default
17965 \emph on
17966 \bar default
17967 \noun default
17968 o
17969 \family roman
17970 \series medium
17971 \shape up
17972 \size normal
17973 \emph off
17974 \bar no
17975 \noun off
17976 psux
17977
17978 \end_inset
17979 </cell>
17980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17981 \begin_inset Text
17982
17983 \layout Standard
17984 c
17985 \family roman
17986 \series medium
17987 \shape up
17988 \size normal
17989 \emph off
17990 \bar no
17991 \noun off
17992 \color none
17993 d
17994 \family default
17995 \series default
17996 \shape default
17997 \size default
17998 \emph on
17999 \bar default
18000 \noun default
18001 o
18002 \family roman
18003 \series medium
18004 \shape up
18005 \size normal
18006 \emph off
18007 \bar no
18008 \noun off
18009 s
18010 \family default
18011 \series default
18012 \shape default
18013 \size default
18014 \emph default
18015 \bar default
18016 \noun default
18017 x
18018
18019 \end_inset
18020 </cell>
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \layout Standard
18025 cdsux
18026
18027 \end_inset
18028 </cell>
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18030 \begin_inset Text
18031
18032 \layout Standard
18033 cdfsux
18034
18035 \end_inset
18036 </cell>
18037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18038 \begin_inset Text
18039
18040 \layout Standard
18041 cdsux
18042
18043 \end_inset
18044 </cell>
18045 </row>
18046 <row topline="true">
18047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18048 \begin_inset Text
18049
18050 \layout Standard
18051 long (32 bit) support
18052
18053 \end_inset
18054 </cell>
18055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18056 \begin_inset Text
18057
18058 \layout Standard
18059 x
18060
18061 \end_inset
18062 </cell>
18063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18064 \begin_inset Text
18065
18066 \layout Standard
18067 x
18068
18069 \end_inset
18070 </cell>
18071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18072 \begin_inset Text
18073
18074 \layout Standard
18075 x
18076
18077 \end_inset
18078 </cell>
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18080 \begin_inset Text
18081
18082 \layout Standard
18083 x
18084
18085 \end_inset
18086 </cell>
18087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18088 \begin_inset Text
18089
18090 \layout Standard
18091
18092 \family roman
18093 \series medium
18094 \shape up
18095 \size normal
18096 \emph off
18097 \bar no
18098 \noun off
18099 \color none
18100 x
18101
18102 \end_inset
18103 </cell>
18104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18105 \begin_inset Text
18106
18107 \layout Standard
18108 -
18109
18110 \end_inset
18111 </cell>
18112 </row>
18113 <row topline="true">
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18115 \begin_inset Text
18116
18117 \layout Standard
18118 byte arguments on stack
18119
18120 \end_inset
18121 </cell>
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18123 \begin_inset Text
18124
18125 \layout Standard
18126 b
18127
18128 \end_inset
18129 </cell>
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18131 \begin_inset Text
18132
18133 \layout Standard
18134 b
18135
18136 \end_inset
18137 </cell>
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18139 \begin_inset Text
18140
18141 \layout Standard
18142 -
18143
18144 \end_inset
18145 </cell>
18146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18147 \begin_inset Text
18148
18149 \layout Standard
18150 -
18151
18152 \end_inset
18153 </cell>
18154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18155 \begin_inset Text
18156
18157 \layout Standard
18158 -
18159
18160 \end_inset
18161 </cell>
18162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18163 \begin_inset Text
18164
18165 \layout Standard
18166 -
18167
18168 \end_inset
18169 </cell>
18170 </row>
18171 <row topline="true">
18172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18173 \begin_inset Text
18174
18175 \layout Standard
18176 float format
18177 \begin_inset LatexCommand \index{Floating point support}
18178
18179 \end_inset
18180
18181
18182
18183 \end_inset
18184 </cell>
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18186 \begin_inset Text
18187
18188 \layout Standard
18189 -
18190
18191 \end_inset
18192 </cell>
18193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18194 \begin_inset Text
18195
18196 \layout Standard
18197 %f
18198
18199 \end_inset
18200 </cell>
18201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18202 \begin_inset Text
18203
18204 \layout Standard
18205 -
18206
18207 \end_inset
18208 </cell>
18209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18210 \begin_inset Text
18211
18212 \layout Standard
18213 -
18214
18215 \end_inset
18216 </cell>
18217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18218 \begin_inset Text
18219
18220 \layout Standard
18221 %f
18222 \begin_inset Foot
18223 collapsed true
18224
18225 \layout Standard
18226 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18227
18228 \end_inset
18229
18230
18231
18232 \end_inset
18233 </cell>
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18235 \begin_inset Text
18236
18237 \layout Standard
18238 -
18239
18240 \end_inset
18241 </cell>
18242 </row>
18243 <row topline="true">
18244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18245 \begin_inset Text
18246
18247 \layout Standard
18248 float formats %e %g
18249
18250 \end_inset
18251 </cell>
18252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18253 \begin_inset Text
18254
18255 \layout Standard
18256 -
18257
18258 \end_inset
18259 </cell>
18260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18261 \begin_inset Text
18262
18263 \layout Standard
18264 -
18265
18266 \end_inset
18267 </cell>
18268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18269 \begin_inset Text
18270
18271 \layout Standard
18272 -
18273
18274 \end_inset
18275 </cell>
18276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18277 \begin_inset Text
18278
18279 \layout Standard
18280 -
18281
18282 \end_inset
18283 </cell>
18284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18285 \begin_inset Text
18286
18287 \layout Standard
18288 -
18289
18290 \end_inset
18291 </cell>
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18293 \begin_inset Text
18294
18295 \layout Standard
18296 -
18297
18298 \end_inset
18299 </cell>
18300 </row>
18301 <row topline="true" bottomline="true">
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18303 \begin_inset Text
18304
18305 \layout Standard
18306 field width
18307
18308 \end_inset
18309 </cell>
18310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18311 \begin_inset Text
18312
18313 \layout Standard
18314 x
18315
18316 \end_inset
18317 </cell>
18318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18319 \begin_inset Text
18320
18321 \layout Standard
18322 x
18323
18324 \end_inset
18325 </cell>
18326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18327 \begin_inset Text
18328
18329 \layout Standard
18330 -
18331
18332 \end_inset
18333 </cell>
18334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18335 \begin_inset Text
18336
18337 \layout Standard
18338 x
18339
18340 \end_inset
18341 </cell>
18342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18343 \begin_inset Text
18344
18345 \layout Standard
18346 x
18347
18348 \end_inset
18349 </cell>
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \layout Standard
18354 -
18355
18356 \end_inset
18357 </cell>
18358 </row>
18359 <row bottomline="true">
18360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18361 \begin_inset Text
18362
18363 \layout Standard
18364 string speed
18365 \begin_inset Foot
18366 collapsed true
18367
18368 \layout Standard
18369 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18370 \backslash
18371 r', '
18372 \backslash
18373 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18374
18375 \end_inset
18376
18377 ,
18378
18379 \layout Standard
18380 small / large
18381
18382 \end_inset
18383 </cell>
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18385 \begin_inset Text
18386
18387 \layout Standard
18388 1.52 / 2.59 ms
18389
18390 \end_inset
18391 </cell>
18392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18393 \begin_inset Text
18394
18395 \layout Standard
18396 1.53 / 2.62 ms
18397
18398 \end_inset
18399 </cell>
18400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18401 \begin_inset Text
18402
18403 \layout Standard
18404 0.92 / 0.93 ms
18405
18406 \end_inset
18407 </cell>
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \layout Standard
18412 0.45 / 0.45 ms
18413
18414 \end_inset
18415 </cell>
18416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18417 \begin_inset Text
18418
18419 \layout Standard
18420 0.46 / 0.46 ms
18421
18422 \end_inset
18423 </cell>
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18425 \begin_inset Text
18426
18427 \layout Standard
18428 0.45 / 0.45 ms
18429
18430 \end_inset
18431 </cell>
18432 </row>
18433 <row bottomline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18435 \begin_inset Text
18436
18437 \layout Standard
18438 int speed
18439 \begin_inset Foot
18440 collapsed true
18441
18442 \layout Standard
18443 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18444  putchar()
18445
18446 \end_inset
18447
18448 ,
18449
18450 \layout Standard
18451 small / large
18452
18453 \end_inset
18454 </cell>
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \layout Standard
18459 3.01 / 3.61 ms
18460
18461 \end_inset
18462 </cell>
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \layout Standard
18467 3.01 / 3.61 ms
18468
18469 \end_inset
18470 </cell>
18471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18472 \begin_inset Text
18473
18474 \layout Standard
18475 3.51 / 18.13 ms
18476
18477 \end_inset
18478 </cell>
18479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18480 \begin_inset Text
18481
18482 \layout Standard
18483 0.22 / 0.22 ms
18484
18485 \end_inset
18486 </cell>
18487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18488 \begin_inset Text
18489
18490 \layout Standard
18491 0.23 / 0.23 ms
18492
18493 \end_inset
18494 </cell>
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18496 \begin_inset Text
18497
18498 \layout Standard
18499 0.25 / 0.25 ms
18500 \begin_inset Foot
18501 collapsed true
18502
18503 \layout Standard
18504 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18505
18506 \end_inset
18507
18508
18509
18510 \end_inset
18511 </cell>
18512 </row>
18513 <row bottomline="true">
18514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18515 \begin_inset Text
18516
18517 \layout Standard
18518 long speed
18519 \begin_inset Foot
18520 collapsed true
18521
18522 \layout Standard
18523 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18524  empty putchar()
18525
18526 \end_inset
18527
18528 ,
18529
18530 \layout Standard
18531 small / large
18532
18533 \end_inset
18534 </cell>
18535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18536 \begin_inset Text
18537
18538 \layout Standard
18539 5.37 / 6.31 ms
18540
18541 \end_inset
18542 </cell>
18543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18544 \begin_inset Text
18545
18546 \layout Standard
18547 5.37 / 6.31 ms
18548
18549 \end_inset
18550 </cell>
18551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18552 \begin_inset Text
18553
18554 \layout Standard
18555 8.71 / 40.65 ms
18556
18557 \end_inset
18558 </cell>
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18560 \begin_inset Text
18561
18562 \layout Standard
18563 0.40 / 0.40 ms
18564
18565 \end_inset
18566 </cell>
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18568 \begin_inset Text
18569
18570 \layout Standard
18571 0.40 / 0.40 ms
18572
18573 \end_inset
18574 </cell>
18575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18576 \begin_inset Text
18577
18578 \layout Standard
18579 -
18580
18581 \end_inset
18582 </cell>
18583 </row>
18584 <row bottomline="true">
18585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18586 \begin_inset Text
18587
18588 \layout Standard
18589 float speed
18590 \begin_inset Foot
18591 collapsed true
18592
18593 \layout Standard
18594 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18595  empty putchar()
18596
18597 \end_inset
18598
18599 ,
18600
18601 \layout Standard
18602 small / large
18603
18604 \end_inset
18605 </cell>
18606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18607 \begin_inset Text
18608
18609 \layout Standard
18610 -
18611
18612 \end_inset
18613 </cell>
18614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18615 \begin_inset Text
18616
18617 \layout Standard
18618 7.49 / 22.47 ms
18619
18620 \end_inset
18621 </cell>
18622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18623 \begin_inset Text
18624
18625 \layout Standard
18626 -
18627
18628 \end_inset
18629 </cell>
18630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18631 \begin_inset Text
18632
18633 \layout Standard
18634 -
18635
18636 \end_inset
18637 </cell>
18638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18639 \begin_inset Text
18640
18641 \layout Standard
18642 1.04 / 1.04 ms
18643
18644 \end_inset
18645 </cell>
18646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18647 \begin_inset Text
18648
18649 \layout Standard
18650 -
18651
18652 \end_inset
18653 </cell>
18654 </row>
18655 </lyxtabular>
18656
18657 \end_inset
18658
18659
18660
18661 \layout Subsubsection
18662 <malloc.h>
18663 \begin_inset LatexCommand \index{malloc.h}
18664
18665 \end_inset
18666
18667
18668
18669 \layout Standard
18670 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18671  using dynamic memory allocation
18672 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18673
18674 \end_inset
18675
18676  and a default heap
18677 \begin_inset LatexCommand \index{heap (malloc)}
18678
18679 \end_inset
18680
18681  space of 1024 bytes is provided for malloc to allocate memory from.
18682  If you need a different heap size you need to recompile _heap.c with the
18683  required size defined in HEAP_SIZE.
18684  It is recommended to make a copy of this file into your project directory
18685  and compile it there with:
18686
18687 \layout Verse
18688
18689 \family typewriter
18690 sdcc -c _heap.c -D HEAD_SIZE=2048
18691
18692 \layout Standard
18693 And then link it with:
18694
18695 \layout Verse
18696
18697 \family typewriter
18698 sdcc main.rel _heap.rel
18699
18700 \layout Subsection
18701 Math functions (sinf, powf, sqrtf etc.)
18702
18703 \layout Subsubsection
18704 <math.h>
18705
18706 \layout Standard
18707 See definitions in file <math.h>.
18708
18709 \layout Subsection
18710 Other libraries
18711
18712 \layout Standard
18713 Libraries
18714 \begin_inset LatexCommand \index{Libraries}
18715
18716 \end_inset
18717
18718  included in SDCC should have a license at least as liberal as the GNU Lesser
18719  General Public License
18720 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18721
18722 \end_inset
18723
18724  
18725 \emph on
18726 LGPL
18727 \emph default
18728 .
18729
18730 \layout Standard
18731 \begin_inset Note
18732 collapsed true
18733
18734 \layout Standard
18735 license statements for the libraries are missing.
18736  sdcc/device/lib/ser_ir.c
18737
18738 \layout Standard
18739 or _decdptr f.e.
18740  come with a GPL (as opposed to LGPL) License - this will not be liberal
18741  enough for many embedded programmers.
18742
18743 \end_inset
18744
18745
18746
18747 \layout Standard
18748 If you have ported some library or want to share experience about some code
18749  which f.e.
18750  falls into any of these categories Busses (I
18751 \begin_inset Formula $^{\textrm{2}}$
18752 \end_inset
18753
18754 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18755  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18756  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
18757 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18758
18759 \end_inset
18760
18761 \SpecialChar ~
18762 would certainly like to hear about it.
18763
18764 \layout Standard
18765 \added_space_bottom bigskip 
18766 Programmers coding for embedded systems are not especially famous for being
18767  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18768 e these references are very valuable.
18769  Let's help to create a climate where information is shared.
18770
18771
18772
18773 \layout Section
18774 Memory Models
18775
18776 \layout Subsection
18777 MCS51 Memory Models
18778 \begin_inset LatexCommand \index{Memory model}
18779
18780 \end_inset
18781
18782
18783 \begin_inset LatexCommand \index{MCS51 memory model}
18784
18785 \end_inset
18786
18787
18788
18789 \layout Subsubsection
18790 Small, Medium and Large
18791
18792 \layout Standard
18793 SDCC allows three memory models for MCS51 code, 
18794 \shape slanted
18795 small, medium
18796 \shape default
18797  and 
18798 \shape slanted
18799 large
18800 \shape default
18801 .
18802  Modules compiled with different memory models should 
18803 \emph on
18804 never
18805 \emph default
18806  be combined together or the results would be unpredictable.
18807  The library routines supplied with the compiler are compiled as small,
18808  medium and large.
18809  The compiled library modules are contained in separate directories as small,
18810  medium and large so that you can link to the appropriate set.
18811
18812 \layout Standard
18813 When the medium or large model is used all variables declared without a
18814  storage class will be allocated into the external ram, this includes all
18815  parameters and local variables (for non-reentrant
18816 \begin_inset LatexCommand \index{reentrant}
18817
18818 \end_inset
18819
18820  functions).
18821  When the small model is used variables without storage class are allocated
18822  in the internal ram.
18823
18824 \layout Standard
18825 Judicious usage of the processor specific storage classes
18826 \begin_inset LatexCommand \index{Storage class}
18827
18828 \end_inset
18829
18830  and the 'reentrant' function type will yield much more efficient code,
18831  than using the large model.
18832  Several optimizations are disabled when the program is compiled using the
18833  large model, it is therefore recommended that the small model be used unless
18834  absolutely required.
18835
18836 \layout Subsubsection
18837 External Stack
18838 \begin_inset LatexCommand \label{sub:External-Stack}
18839
18840 \end_inset
18841
18842
18843 \begin_inset LatexCommand \index{stack}
18844
18845 \end_inset
18846
18847
18848 \begin_inset LatexCommand \index{External stack (mcs51)}
18849
18850 \end_inset
18851
18852
18853
18854 \layout Standard
18855 The external stack (-
18856 \begin_inset ERT
18857 status Collapsed
18858
18859 \layout Standard
18860
18861
18862 \backslash
18863 /
18864
18865 \end_inset
18866
18867 -xstack option
18868 \begin_inset LatexCommand \index{-\/-xstack}
18869
18870 \end_inset
18871
18872 ) is located in pdata
18873 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18874
18875 \end_inset
18876
18877  memory (usually at the start of the external ram segment) and uses all
18878  unused space in pdata (max.
18879  256 bytes).
18880  When -
18881 \begin_inset ERT
18882 status Collapsed
18883
18884 \layout Standard
18885
18886
18887 \backslash
18888 /
18889
18890 \end_inset
18891
18892 -xstack option is used to compile the program, the parameters and local
18893  variables
18894 \begin_inset LatexCommand \index{local variables}
18895
18896 \end_inset
18897
18898  of all reentrant functions are allocated in this area.
18899  This option is provided for programs with large stack space requirements.
18900  When used with the -
18901 \begin_inset ERT
18902 status Collapsed
18903
18904 \layout Standard
18905
18906
18907 \backslash
18908 /
18909
18910 \end_inset
18911
18912 -stack-auto
18913 \begin_inset LatexCommand \index{-\/-stack-auto}
18914
18915 \end_inset
18916
18917  option, all parameters and local variables are allocated on the external
18918  stack (note: support libraries will need to be recompiled with the same
18919  options.
18920  There is a predefined target in the library makefile).
18921
18922 \layout Standard
18923 The compiler outputs the higher order address byte of the external ram segment
18924  into port P2
18925 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18926
18927 \end_inset
18928
18929  (see also section 
18930 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18931
18932 \end_inset
18933
18934 ), therefore when using the External Stack option, this port 
18935 \emph on
18936 may not
18937 \emph default
18938  be used by the application program.
18939
18940 \layout Subsection
18941 DS390 Memory Model
18942 \begin_inset LatexCommand \index{Memory model}
18943
18944 \end_inset
18945
18946
18947 \begin_inset LatexCommand \index{DS390 memory model}
18948
18949 \end_inset
18950
18951
18952
18953 \layout Standard
18954 The only model supported is Flat 24
18955 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18956
18957 \end_inset
18958
18959 .
18960  This generates code for the 24 bit contiguous addressing mode of the Dallas
18961  DS80C390 part.
18962  In this mode, up to four meg of external RAM or code space can be directly
18963  addressed.
18964  See the data sheets at www.dalsemi.com for further information on this part.
18965 \newline
18966
18967 \newline
18968 Note
18969  that the compiler does not generate any code to place the processor into
18970  24 bitmode (although 
18971 \emph on
18972 tinibios
18973 \emph default
18974  in the ds390 libraries will do that for you).
18975  If you don't use 
18976 \emph on
18977 tinibios
18978 \emph default
18979
18980 \begin_inset LatexCommand \index{Tinibios (DS390)}
18981
18982 \end_inset
18983
18984 , the boot loader or similar code must ensure that the processor is in 24
18985  bit contiguous addressing mode before calling the SDCC startup code.
18986 \newline
18987
18988 \newline
18989 Like
18990  the 
18991 \emph on
18992 -
18993 \begin_inset ERT
18994 status Collapsed
18995
18996 \layout Standard
18997
18998
18999 \backslash
19000 /
19001
19002 \end_inset
19003
19004 -model-large
19005 \emph default
19006  option, variables will by default be placed into the XDATA segment.
19007  
19008 \newline
19009
19010 \newline
19011 Segments may be placed anywhere in the 4 meg address space using the usual
19012  -
19013 \begin_inset ERT
19014 status Collapsed
19015
19016 \layout Standard
19017
19018
19019 \backslash
19020 /
19021
19022 \end_inset
19023
19024 -*-loc options.
19025  Note that if any segments are located above 64K, the -r flag must be passed
19026  to the linker to generate the proper segment relocations, and the Intel
19027  HEX output format must be used.
19028  The -r flag can be passed to the linker by using the option 
19029 \emph on
19030 -Wl-r
19031 \emph default
19032  on the SDCC command line.
19033  However, currently the linker can not handle code segments > 64k.
19034
19035 \layout Section
19036 Pragmas
19037 \begin_inset LatexCommand \label{sec:Pragmas}
19038
19039 \end_inset
19040
19041
19042 \begin_inset LatexCommand \index{Pragmas}
19043
19044 \end_inset
19045
19046
19047
19048 \layout Standard
19049 SDCC supports the following #pragma directives:
19050
19051 \layout Itemize
19052
19053 \series bold
19054 save
19055 \series default
19056
19057 \begin_inset LatexCommand \index{\#pragma save}
19058
19059 \end_inset
19060
19061  - this will save most current options to the save/restore stack.
19062  See #pragma\SpecialChar ~
19063 restore.
19064
19065 \layout Itemize
19066
19067 \series bold
19068 restore
19069 \series default
19070
19071 \begin_inset LatexCommand \index{\#pragma restore}
19072
19073 \end_inset
19074
19075  - will restore saved options from the last save.
19076  saves & restores can be nested.
19077  SDCC uses a save/restore stack: save pushes current options to the stack,
19078  restore pulls current options from the stack.
19079  See #pragma\SpecialChar ~
19080 save.
19081 \newline
19082
19083
19084 \layout Itemize
19085
19086 \series bold
19087 callee_saves
19088 \series default
19089
19090 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19091
19092 \end_inset
19093
19094
19095 \begin_inset LatexCommand \index{function prologue}
19096
19097 \end_inset
19098
19099  function1[,function2[,function3...]] - The compiler by default uses a caller
19100  saves convention for register saving across function calls, however this
19101  can cause unnecessary register pushing & popping
19102 \begin_inset LatexCommand \index{push/pop}
19103
19104 \end_inset
19105
19106  when calling small functions from larger functions.
19107  This option can be used to switch off the register saving convention for
19108  the function names specified.
19109  The compiler will not save registers when calling these functions, extra
19110  code need to be manually inserted at the entry & exit for these functions
19111  to save & restore the registers used by these functions, this can SUBSTANTIALLY
19112  reduce code & improve run time performance of the generated code.
19113  In the future the compiler (with inter procedural analysis) may be able
19114  to determine the appropriate scheme to use for each function call.
19115  If -
19116 \begin_inset ERT
19117 status Collapsed
19118
19119 \layout Standard
19120
19121
19122 \backslash
19123 /
19124
19125 \end_inset
19126
19127 -callee-saves command line option is used, the function names specified
19128  in #pragma\SpecialChar ~
19129 callee_saves
19130 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19131
19132 \end_inset
19133
19134  is appended to the list of functions specified in the command line.
19135
19136 \layout Itemize
19137
19138 \series bold
19139 exclude
19140 \series default
19141
19142 \begin_inset LatexCommand \index{\#pragma exclude}
19143
19144 \end_inset
19145
19146  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19147  of pairs of push/pop
19148 \begin_inset LatexCommand \index{push/pop}
19149
19150 \end_inset
19151
19152  instructions in 
19153 \emph on
19154 I
19155 \emph default
19156 nterrupt
19157 \begin_inset LatexCommand \index{interrupt}
19158
19159 \end_inset
19160
19161  
19162 \emph on
19163 S
19164 \emph default
19165 ervice 
19166 \emph on
19167 R
19168 \emph default
19169 outines.
19170  The directive should be placed immediately before the ISR function definition
19171  and it affects ALL ISR functions following it.
19172  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
19173 exclude\SpecialChar ~
19174 none
19175 \begin_inset LatexCommand \index{\#pragma exclude}
19176
19177 \end_inset
19178
19179 .
19180  See also the related keyword _naked
19181 \begin_inset LatexCommand \index{\_naked}
19182
19183 \end_inset
19184
19185
19186 \begin_inset LatexCommand \index{\_\_naked}
19187
19188 \end_inset
19189
19190 .
19191
19192 \layout Itemize
19193
19194 \series bold
19195 less_pedantic
19196 \series default
19197
19198 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19199
19200 \end_inset
19201
19202  - the compiler will not warn you anymore for obvious mistakes, you'r on
19203  your own now ;-(
19204
19205 \layout Itemize
19206
19207 \series bold
19208 disable_warning
19209 \series default
19210  <nnnn>
19211 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19212
19213 \end_inset
19214
19215  - the compiler will not warn you anymore about warning number <nnnn>.
19216
19217 \layout Itemize
19218
19219 \series bold
19220 nogcse
19221 \series default
19222
19223 \begin_inset LatexCommand \index{\#pragma nogcse}
19224
19225 \end_inset
19226
19227  - will stop global common subexpression elimination.
19228
19229 \layout Itemize
19230
19231 \series bold
19232 noinduction
19233 \series default
19234
19235 \begin_inset LatexCommand \index{\#pragma noinduction}
19236
19237 \end_inset
19238
19239  - will stop loop induction optimizations.
19240
19241 \layout Itemize
19242
19243 \series bold
19244 noinvariant
19245 \series default
19246
19247 \begin_inset LatexCommand \index{\#pragma noinvariant}
19248
19249 \end_inset
19250
19251  - will not do loop invariant optimizations.
19252  For more details see Loop Invariants in section
19253 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19254
19255 \end_inset
19256
19257 .
19258
19259 \layout Itemize
19260
19261 \series bold
19262 noiv
19263 \series default
19264
19265 \begin_inset LatexCommand \index{\#pragma noiv}
19266
19267 \end_inset
19268
19269  - Do not generate interrupt
19270 \begin_inset LatexCommand \index{interrupt}
19271
19272 \end_inset
19273
19274  vector table
19275 \begin_inset LatexCommand \index{interrupt vector table}
19276
19277 \end_inset
19278
19279  entries for all ISR functions defined after the pragma.
19280  This is useful in cases where the interrupt vector table must be defined
19281  manually, or when there is a secondary, manually defined interrupt vector
19282  table (e.g.
19283  for the autovector feature of the Cypress EZ-USB FX2).
19284  More elegantly this can be achieved by obmitting the optional interrupt
19285  number after the interrupt keyword, see section 
19286 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19287
19288 \end_inset
19289
19290 \SpecialChar ~
19291 about interrupts.
19292
19293 \layout Itemize
19294
19295 \series bold
19296 nojtbound
19297 \series default
19298
19299 \begin_inset LatexCommand \index{\#pragma nojtbound}
19300
19301 \end_inset
19302
19303  - will not generate code for boundary value checking, when switch statements
19304  are turned into jump-tables (dangerous).
19305  For more details see section 
19306 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19307
19308 \end_inset
19309
19310 .
19311
19312 \layout Itemize
19313
19314 \series bold
19315 noloopreverse
19316 \series default
19317
19318 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19319
19320 \end_inset
19321
19322  - Will not do loop reversal optimization
19323
19324 \layout Itemize
19325
19326 \series bold
19327 nooverlay
19328 \series default
19329
19330 \begin_inset LatexCommand \index{\#pragma nooverlay}
19331
19332 \end_inset
19333
19334  - the compiler will not overlay the parameters and local variables of a
19335  function.
19336
19337 \layout Itemize
19338
19339 \series bold
19340 stackauto
19341 \series default
19342
19343 \begin_inset LatexCommand \index{\#pragma stackauto}
19344
19345 \end_inset
19346
19347 - See option -
19348 \begin_inset ERT
19349 status Collapsed
19350
19351 \layout Standard
19352
19353
19354 \backslash
19355 /
19356
19357 \end_inset
19358
19359 -stack-auto
19360 \begin_inset LatexCommand \index{-\/-stack-auto}
19361
19362 \end_inset
19363
19364  and section 
19365 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19366
19367 \end_inset
19368
19369  Parameters and Local Variables.
19370
19371 \layout Itemize
19372
19373 \series bold
19374 opt_code_speed
19375 \series default
19376  
19377 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19378
19379 \end_inset
19380
19381 - The compiler will optimize code generation towards fast code, possibly
19382  at the expense of code size.
19383  Currently this has little effect.
19384
19385 \layout Itemize
19386
19387 \series bold
19388 opt_code_size
19389 \series default
19390  
19391 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19392
19393 \end_inset
19394
19395 - The compiler will optimize code generation towards compact code, possibly
19396  at the expense of code speed.
19397  Currently this has little effect.
19398
19399 \layout Itemize
19400
19401 \series bold
19402 opt_code_balanced
19403 \series default
19404  
19405 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19406
19407 \end_inset
19408
19409 - The compiler will attempt to generate code that is both compact and fast,
19410  as long as meeting one goal is not a detriment to the other (this is the
19411  default).
19412  
19413
19414 \layout Itemize
19415
19416 \series bold
19417 std_sdcc89
19418 \series default
19419  
19420 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19421
19422 \end_inset
19423
19424 - Generally follow the C89 standard, but allow SDCC features that conflict
19425  with the standard (default).
19426
19427 \layout Itemize
19428
19429 \series bold
19430 std_c89
19431 \series default
19432  
19433 \begin_inset LatexCommand \index{\#pragma std\_c89}
19434
19435 \end_inset
19436
19437 - Follow the C89 standard and disable SDCC features that conflict with the
19438  standard.
19439
19440 \layout Itemize
19441
19442 \series bold
19443 std_sdcc99
19444 \series default
19445  
19446 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19447
19448 \end_inset
19449
19450 - Generally follow the C99 standard, but allow SDCC features that conflict
19451  with the standard (incomplete support).
19452
19453 \layout Itemize
19454
19455 \series bold
19456 std_c99
19457 \series default
19458  
19459 \begin_inset LatexCommand \index{\#pragma std\_c99}
19460
19461 \end_inset
19462
19463 - Follow the C99 standard and disable SDCC features that conflict with the
19464  standard (incomplete support).
19465
19466 \layout Itemize
19467
19468 \series bold
19469 codeseg
19470 \series default
19471  <name>
19472 \begin_inset LatexCommand \index{\#pragma codeseg}
19473
19474 \end_inset
19475
19476 - Use this name (max.
19477  8 characters) for the code segment.
19478  See option -
19479 \begin_inset ERT
19480 status Collapsed
19481
19482 \layout Standard
19483
19484
19485 \backslash
19486 /
19487
19488 \end_inset
19489
19490 -codeseg.
19491
19492 \layout Itemize
19493
19494 \series bold
19495 constseg
19496 \series default
19497  <name>
19498 \begin_inset LatexCommand \index{\#pragma constseg}
19499
19500 \end_inset
19501
19502 - Use this name (max.
19503  8 characters) for the const segment.
19504  See option -
19505 \begin_inset ERT
19506 status Collapsed
19507
19508 \layout Standard
19509
19510
19511 \backslash
19512 /
19513
19514 \end_inset
19515
19516 -constseg.
19517
19518 \layout Standard
19519 The preprocessor SDCPP
19520 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19521
19522 \end_inset
19523
19524  supports the following #pragma directives:
19525
19526 \layout Itemize
19527
19528 \series bold
19529 pedantic_parse_number
19530 \series default
19531
19532 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19533
19534 \end_inset
19535
19536  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19537  parsed properly and the macro LO_B(3) gets expanded.
19538  Default is off.
19539  Below is an example on how to use this pragma.
19540
19541 \emph on
19542  Note: this functionality is not in conformance with standard!
19543
19544 \layout Verse
19545
19546 \family typewriter
19547 #pragma pedantic_parse_number +
19548 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19549
19550 \end_inset
19551
19552
19553 \newline
19554
19555 \newline
19556 #define LO_B(x) ((x) & 0xff)
19557 \newline
19558
19559 \newline
19560 unsigned char foo(void)
19561 \newline
19562 {
19563 \newline
19564 \SpecialChar ~
19565 \SpecialChar ~
19566 \SpecialChar ~
19567 unsigned char c=0xfe-LO_B(3)
19568 ;
19569 \newline
19570
19571 \newline
19572 \SpecialChar ~
19573 \SpecialChar ~
19574 \SpecialChar ~
19575 return c;
19576 \newline
19577 }
19578 \newline
19579
19580
19581 \layout Itemize
19582
19583 \series bold
19584 preproc_asm
19585 \series default
19586
19587 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19588
19589 \end_inset
19590
19591  (+ | -) - switch _asm _endasm block preprocessing on / off.
19592  Default is on.
19593  You use this prama to define multilines of assembly code.
19594  This will prevent the preprocessor from changing the formating required
19595  by assembly code.
19596  Below is an example on how to use this pragma.
19597
19598 \layout Verse
19599
19600 \family typewriter
19601 #pragma preproc_asm -
19602 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19603
19604 \end_inset
19605
19606
19607 \newline
19608 #define MYDELAY _asm
19609 \newline
19610 \SpecialChar ~
19611 \SpecialChar ~
19612 \SpecialChar ~
19613 nop ;my assembly comment...
19614 \newline
19615 \SpecialChar ~
19616 \SpecialChar ~
19617 \SpecialChar ~
19618 nop
19619 \newline
19620 \SpecialChar ~
19621 \SpecialChar ~
19622 \SpecialChar ~
19623 nop
19624 \newline
19625 _endasm
19626 \newline
19627 #pragma preproc_asm
19628  +
19629 \newline
19630
19631 \newline
19632 void foo (void) 
19633 \newline
19634
19635 \newline
19636 \SpecialChar ~
19637 \SpecialChar ~
19638 \SpecialChar ~
19639  ...
19640  
19641 \newline
19642 \SpecialChar ~
19643 \SpecialChar ~
19644 \SpecialChar ~
19645  MYDELAY;
19646 \newline
19647 \SpecialChar ~
19648 \SpecialChar ~
19649 \SpecialChar ~
19650  ...
19651  
19652 \newline
19653
19654 \newline
19655
19656
19657 \layout Itemize
19658
19659 \series bold
19660 sdcc_hash
19661 \series default
19662
19663 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19664
19665 \end_inset
19666
19667  (+ | -) - Allow "naked" hash in macro definition, for example:
19668 \newline
19669
19670 \family typewriter
19671 #define DIR_LO(x) #(x & 0xff)
19672 \family default
19673
19674 \newline
19675 Default is off.
19676  Below is an example on how to use this pragma.
19677
19678 \layout Verse
19679
19680 \family typewriter
19681 #pragma preproc_asm +
19682 \newline
19683 #pragma sdcc_hash +
19684 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19685
19686 \end_inset
19687
19688
19689 \newline
19690
19691 \newline
19692 #define ROMCALL(x) 
19693 \backslash
19694
19695 \newline
19696 \SpecialChar ~
19697 \SpecialChar ~
19698 \SpecialChar ~
19699 mov R6_B3, #(x & 0xff) 
19700 \backslash
19701
19702 \newline
19703 \SpecialChar ~
19704 \SpecialChar ~
19705 \SpecialChar ~
19706 mov R7_B3, #((x >> 8) & 0xff) 
19707 \backslash
19708
19709 \newline
19710 \SpecialChar ~
19711 \SpecialChar ~
19712 \SpecialChar ~
19713 lcall __romcall
19714 \newline
19715
19716 \newline
19717 ...
19718 \newline
19719 _asm
19720 \newline
19721 ROMCALL(72)
19722 \newline
19723 _endasm;
19724 \newline
19725 ...
19726 \newline
19727
19728
19729 \layout Standard
19730 The pragma's are intended to be used to turn-on or off certain optimizations
19731  which might cause the compiler to generate extra stack / data space to
19732  store compiler generated temporary variables.
19733  This usually happens in large functions.
19734  Pragma directives should be used as shown in the following example, they
19735  are used to control options & optimizations for a given function; pragmas
19736  should be placed before and/or after a function, placing pragma's inside
19737  a function body could have unpredictable results.
19738
19739 \layout Verse
19740
19741 \family typewriter
19742 #pragma save
19743 \begin_inset LatexCommand \index{\#pragma save}
19744
19745 \end_inset
19746
19747  \SpecialChar ~
19748 \SpecialChar ~
19749 \SpecialChar ~
19750 \SpecialChar ~
19751 \SpecialChar ~
19752 \SpecialChar ~
19753 \SpecialChar ~
19754 /* save the current settings */ 
19755 \newline
19756 #pragma nogcse
19757 \begin_inset LatexCommand \index{\#pragma nogcse}
19758
19759 \end_inset
19760
19761  \SpecialChar ~
19762 \SpecialChar ~
19763 \SpecialChar ~
19764 \SpecialChar ~
19765 \SpecialChar ~
19766 /* turnoff global subexpression elimination */ 
19767 \newline
19768 #pragma noinduction
19769 \begin_inset LatexCommand \index{\#pragma noinduction}
19770
19771 \end_inset
19772
19773  /* turn off induction optimizations */ 
19774 \newline
19775 int foo () 
19776 \newline
19777
19778 \newline
19779 \SpecialChar ~
19780  \SpecialChar ~
19781  ...
19782  
19783 \newline
19784 \SpecialChar ~
19785  \SpecialChar ~
19786  /* large code */ 
19787 \newline
19788 \SpecialChar ~
19789  \SpecialChar ~
19790  ...
19791  
19792 \newline
19793
19794 \newline
19795 #pragma restore
19796 \begin_inset LatexCommand \index{\#pragma restore}
19797
19798 \end_inset
19799
19800  /* turn the optimizations back on */
19801
19802 \layout Standard
19803 The compiler will generate a warning message when extra space is allocated.
19804  It is strongly recommended that the save and restore pragma's be used when
19805  changing options for a function.
19806 \newline
19807
19808 \newline
19809
19810 \newline
19811
19812
19813 \layout Section
19814 Defines Created by the Compiler
19815
19816 \layout Standard
19817 The compiler creates the following #defines
19818 \begin_inset LatexCommand \index{\#defines}
19819
19820 \end_inset
19821
19822
19823 \begin_inset LatexCommand \index{Defines created by the compiler}
19824
19825 \end_inset
19826
19827 :
19828 \newline
19829
19830
19831 \layout Standard
19832 \begin_inset Tabular
19833 <lyxtabular version="3" rows="11" columns="2">
19834 <features>
19835 <column alignment="left" valignment="top" leftline="true" width="3in">
19836 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19837 <row topline="true" bottomline="true">
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19839 \begin_inset Text
19840
19841 \layout Standard
19842
19843 \series bold
19844 #define
19845
19846 \end_inset
19847 </cell>
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19849 \begin_inset Text
19850
19851 \layout Standard
19852
19853 \series bold
19854 Description
19855
19856 \end_inset
19857 </cell>
19858 </row>
19859 <row topline="true">
19860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19861 \begin_inset Text
19862
19863 \layout Standard
19864 SDCC
19865 \begin_inset LatexCommand \index{SDCC}
19866
19867 \end_inset
19868
19869  
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \layout Standard
19877 Always defined.
19878  Since version 2.5.6 the version number as an int (ex.
19879  256)
19880
19881 \end_inset
19882 </cell>
19883 </row>
19884 <row topline="true">
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19886 \begin_inset Text
19887
19888 \layout Standard
19889 SDCC_mcs51
19890 \begin_inset LatexCommand \index{SDCC\_mcs51}
19891
19892 \end_inset
19893
19894  or SDCC_ds390
19895 \begin_inset LatexCommand \index{SDCC\_ds390}
19896
19897 \end_inset
19898
19899  or SDCC_z80
19900 \begin_inset LatexCommand \index{SDCC\_z80}
19901
19902 \end_inset
19903
19904 , etc.
19905
19906 \end_inset
19907 </cell>
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19909 \begin_inset Text
19910
19911 \layout Standard
19912 depending on the model used (e.g.: -mds390)
19913
19914 \end_inset
19915 </cell>
19916 </row>
19917 <row topline="true">
19918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19919 \begin_inset Text
19920
19921 \layout Standard
19922 __mcs51
19923 \begin_inset LatexCommand \index{\_\_mcs51}
19924
19925 \end_inset
19926
19927 , __ds390
19928 \begin_inset LatexCommand \index{\_\_ds390}
19929
19930 \end_inset
19931
19932 , __hc08
19933 \begin_inset LatexCommand \index{\_\_hc08}
19934
19935 \end_inset
19936
19937 , __z80
19938 \begin_inset LatexCommand \index{\_\_z80}
19939
19940 \end_inset
19941
19942 , etc
19943
19944 \end_inset
19945 </cell>
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19947 \begin_inset Text
19948
19949 \layout Standard
19950 depending on the model used (e.g.
19951  -mz80)
19952
19953 \end_inset
19954 </cell>
19955 </row>
19956 <row topline="true">
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \layout Standard
19961 SDCC_STACK_AUTO
19962 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19963
19964 \end_inset
19965
19966
19967
19968 \end_inset
19969 </cell>
19970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19971 \begin_inset Text
19972
19973 \layout Standard
19974 when 
19975 \emph on
19976 -
19977 \begin_inset ERT
19978 status Collapsed
19979
19980 \layout Standard
19981
19982
19983 \backslash
19984 /
19985
19986 \end_inset
19987
19988 -stack-auto
19989 \emph default
19990  option is used
19991
19992 \end_inset
19993 </cell>
19994 </row>
19995 <row topline="true">
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19997 \begin_inset Text
19998
19999 \layout Standard
20000 SDCC_MODEL_SMALL
20001 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20002
20003 \end_inset
20004
20005
20006
20007 \end_inset
20008 </cell>
20009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20010 \begin_inset Text
20011
20012 \layout Standard
20013 when 
20014 \emph on
20015 -
20016 \begin_inset ERT
20017 status Collapsed
20018
20019 \layout Standard
20020
20021
20022 \backslash
20023 /
20024
20025 \end_inset
20026
20027 -model-small
20028 \emph default
20029  is used
20030
20031 \end_inset
20032 </cell>
20033 </row>
20034 <row topline="true">
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20036 \begin_inset Text
20037
20038 \layout Standard
20039 SDCC_MODEL_MEDIUM
20040 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20041
20042 \end_inset
20043
20044
20045
20046 \end_inset
20047 </cell>
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20049 \begin_inset Text
20050
20051 \layout Standard
20052 when 
20053 \emph on
20054 -
20055 \begin_inset ERT
20056 status Collapsed
20057
20058 \layout Standard
20059
20060
20061 \backslash
20062 /
20063
20064 \end_inset
20065
20066 -model-medium
20067 \emph default
20068  is used
20069
20070 \end_inset
20071 </cell>
20072 </row>
20073 <row topline="true">
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20075 \begin_inset Text
20076
20077 \layout Standard
20078 SDCC_MODEL_LARGE
20079 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20080
20081 \end_inset
20082
20083
20084
20085 \end_inset
20086 </cell>
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20088 \begin_inset Text
20089
20090 \layout Standard
20091 when 
20092 \emph on
20093 -
20094 \begin_inset ERT
20095 status Collapsed
20096
20097 \layout Standard
20098
20099
20100 \backslash
20101 /
20102
20103 \end_inset
20104
20105 -model-large
20106 \emph default
20107  is used
20108
20109 \end_inset
20110 </cell>
20111 </row>
20112 <row topline="true">
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20114 \begin_inset Text
20115
20116 \layout Standard
20117 SDCC_USE_XSTACK
20118 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20119
20120 \end_inset
20121
20122
20123
20124 \end_inset
20125 </cell>
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20127 \begin_inset Text
20128
20129 \layout Standard
20130 when 
20131 \emph on
20132 -
20133 \begin_inset ERT
20134 status Collapsed
20135
20136 \layout Standard
20137
20138
20139 \backslash
20140 /
20141
20142 \end_inset
20143
20144 -xstack
20145 \emph default
20146  option is used
20147
20148 \end_inset
20149 </cell>
20150 </row>
20151 <row topline="true">
20152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20153 \begin_inset Text
20154
20155 \layout Standard
20156 SDCC_STACK_TENBIT
20157 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20158
20159 \end_inset
20160
20161  
20162
20163 \end_inset
20164 </cell>
20165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20166 \begin_inset Text
20167
20168 \layout Standard
20169 when 
20170 \emph on
20171 -mds390
20172 \emph default
20173  is used
20174
20175 \end_inset
20176 </cell>
20177 </row>
20178 <row topline="true" bottomline="true">
20179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20180 \begin_inset Text
20181
20182 \layout Standard
20183 SDCC_MODEL_FLAT24
20184 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20185
20186 \end_inset
20187
20188
20189
20190 \end_inset
20191 </cell>
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20193 \begin_inset Text
20194
20195 \layout Standard
20196 when 
20197 \emph on
20198 -mds390
20199 \emph default
20200  is used
20201
20202 \end_inset
20203 </cell>
20204 </row>
20205 </lyxtabular>
20206
20207 \end_inset
20208
20209
20210
20211 \layout Chapter
20212 Notes on supported Processors
20213
20214 \layout Section
20215 MCS51 variants
20216 \begin_inset LatexCommand \label{sub:MCS51-variants}
20217
20218 \end_inset
20219
20220
20221 \begin_inset LatexCommand \index{MCS51 variants}
20222
20223 \end_inset
20224
20225
20226
20227 \layout Standard
20228 MCS51 processors are available from many vendors and come in many different
20229  flavours.
20230  While they might differ considerably in respect to Special Function Registers
20231  the core MCS51 is usually not modified or is kept compatible.
20232  
20233
20234 \layout Subsection
20235 pdata access by SFR 
20236
20237 \layout Standard
20238 With the upcome of devices with internal xdata and flash memory devices
20239  using port P2
20240 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20241
20242 \end_inset
20243
20244  as dedicated I/O port is becoming more popular.
20245  Switching the high byte for pdata
20246 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20247
20248 \end_inset
20249
20250  access which was formerly done by port P2 is then achieved by a Special
20251  Function Register
20252 \begin_inset LatexCommand \index{sfr}
20253
20254 \end_inset
20255
20256 .
20257  In well-established MCS51 tradition the address of this 
20258 \emph on
20259 sfr
20260 \emph default
20261  is where the chip designers decided to put it.
20262  Needless to say that they didn't agree on a common name either.
20263  So that the startup code can correctly initialize xdata variables, you
20264  should define an sfr with the name _XPAGE
20265 \family typewriter
20266
20267 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20268
20269 \end_inset
20270
20271
20272 \family default
20273  at the appropriate location if the default, port P2, is not used for this.
20274  Some examples are:
20275
20276 \layout Verse
20277
20278 \family typewriter
20279 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
20280  MPAGE */
20281
20282 \layout Verse
20283
20284 \family typewriter
20285 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
20286  a.k.a.
20287  MPAGE */
20288
20289 \layout Verse
20290
20291 \family typewriter
20292 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
20293  XPAGE */
20294
20295 \layout Verse
20296
20297 \family typewriter
20298 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20299  EMI0CN */
20300
20301 \layout Verse
20302
20303 \family typewriter
20304 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20305  EMI0CN */
20306
20307 \layout Standard
20308 For more exotic implementations further customizations may be needed.
20309  See section 
20310 \begin_inset LatexCommand \ref{sub:Startup-Code}
20311
20312 \end_inset
20313
20314  for other possibilities.
20315
20316 \layout Subsection
20317 Other Features available by SFR
20318
20319 \layout Standard
20320 \added_space_bottom bigskip 
20321 Some MCS51 variants offer features like Double DPTR
20322 \begin_inset LatexCommand \index{DPTR}
20323
20324 \end_inset
20325
20326 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20327  These are currently not used for the MCS51 port.
20328  If you absolutely need them you can fall back to inline assembly or submit
20329  a patch to SDCC.
20330
20331
20332
20333 \layout Section
20334 DS400 port
20335
20336 \layout Standard
20337 \added_space_bottom bigskip 
20338 The DS80C400
20339 \begin_inset LatexCommand \index{DS80C400}
20340
20341 \end_inset
20342
20343
20344 \begin_inset LatexCommand \index{DS400}
20345
20346 \end_inset
20347
20348  microcontroller has a rich set of peripherals.
20349  In its built-in ROM library it includes functions to access some of the
20350  features, among them is a TCP stack with IP4 and IP6 support.
20351  Library headers (currently in beta status) and other files are provided
20352  at 
20353 \size footnotesize
20354
20355 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20356
20357 \end_inset
20358
20359 .
20360  
20361
20362
20363
20364 \layout Section
20365 The Z80 and gbz80 port
20366
20367 \layout Standard
20368 SDCC can target both the Zilog Z80
20369 \begin_inset LatexCommand \index{Z80}
20370
20371 \end_inset
20372
20373  and the Nintendo Gameboy's Z80-like gbz80
20374 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20375
20376 \end_inset
20377
20378 .
20379  The Z80 port is passed through the same 
20380 \emph on
20381 regressions tests
20382 \begin_inset LatexCommand \index{Regression test}
20383
20384 \end_inset
20385
20386
20387 \emph default
20388  (see section 
20389 \begin_inset LatexCommand \ref{sec:Quality-control}
20390
20391 \end_inset
20392
20393 ) as the MCS51 and DS390 ports, so floating point support, support for long
20394  variables and bitfield support is fine.
20395  See mailing lists and forums about interrupt routines.
20396
20397 \layout Standard
20398 \added_space_bottom bigskip 
20399 As always, the code is the authoritative reference - see z80/ralloc.c and
20400  z80/gen.c.
20401  The stack
20402 \begin_inset LatexCommand \index{Z80!stack}
20403
20404 \end_inset
20405
20406  frame is similar to that generated by the IAR Z80 compiler.
20407  IX is used as the base pointer, HL and IY are used as a temporary registers,
20408  and BC and DE are available for holding variables.
20409  Return values
20410 \begin_inset LatexCommand \index{Z80!return value}
20411
20412 \end_inset
20413
20414  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20415  bytes).
20416  The gbz80 port use the same set of registers for the return values, but
20417  in a different order of significance: E (one byte), DE (two bytes), or
20418  HLDE (four bytes).
20419
20420
20421
20422 \layout Section
20423 The HC08 port
20424
20425 \layout Standard
20426 The port to the Freescale/Motorola HC08
20427 \begin_inset LatexCommand \index{HC08}
20428
20429 \end_inset
20430
20431  family has been added in October 2003, and is still undergoing some basic
20432  development.
20433  The code generator is complete, but the register allocation is still quite
20434  unoptimized.
20435  Some of the SDCC's standard C library functions have embedded non-HC08
20436  inline assembly and so are not yet usable.
20437
20438 \layout Standard
20439 \pagebreak_bottom 
20440 \added_space_bottom bigskip 
20441 The HC08 port passes the regression test suite (see section 
20442 \begin_inset LatexCommand \ref{sec:Quality-control}
20443
20444 \end_inset
20445
20446 ).
20447
20448
20449
20450
20451 \layout Section
20452 The PIC14 port
20453
20454 \layout Standard
20455 The 14bit PIC
20456 \begin_inset LatexCommand \index{PIC14}
20457
20458 \end_inset
20459
20460  port still requires a major effort from the development community.
20461  However it can work for simple code.
20462  It passes its (smaller set of) regression tests
20463 \begin_inset LatexCommand \index{Regression test (PIC14)}
20464
20465 \end_inset
20466
20467  in the directory 
20468 \shape italic
20469 sdcc/src/regression
20470 \shape default
20471 .
20472
20473 \layout Subsection
20474 C code and 14bit PIC code page
20475 \begin_inset LatexCommand \index{code page (pic14)}
20476
20477 \end_inset
20478
20479  and RAM banks
20480 \begin_inset LatexCommand \index{RAM bank (pic14)}
20481
20482 \end_inset
20483
20484
20485
20486 \layout Standard
20487 The linker organizes allocation for the code page and RAM banks.
20488  It does not have intimate knowledge of the code flow.
20489  It will put all the code section of a single asm file into a single code
20490  page.
20491  In order to make use of multiple code pages, separate asm files must be
20492  used.
20493  The compiler treats all functions of a single C file as being in the same
20494  code page unless it is non static.
20495 \newline
20496
20497 \newline
20498 To get the best follow these guide lines:
20499
20500 \layout Enumerate
20501 Make local functions static, as non static functions require code page selection
20502  overhead.
20503
20504 \layout Enumerate
20505 For devices that have multiple code pages it is more efficient to use the
20506  same number of files as pages, i.e.
20507  for the 16F877 use 4 separate files and i.e.
20508  for the 16F874 use 2 separate files.
20509  This way the linker can put the code for each file into different code
20510  pages and there's less page selection overhead.
20511
20512 \layout Enumerate
20513 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20514  instruction set), use 'unsigned char' whereever possible instead of 'int'.
20515
20516 \layout Subsection
20517 Creating a device include file 
20518
20519 \layout Standard
20520 For generating a device include file
20521 \begin_inset LatexCommand \index{PIC14!Header files}
20522
20523 \end_inset
20524
20525  use the support perl script inc2h.pl kept in directory support/script.
20526
20527 \layout Subsection
20528 Interrupt code
20529
20530 \layout Standard
20531 For the interrupt function, use the keyword '__interrupt'
20532 \begin_inset LatexCommand \index{PIC14!interrupt}
20533
20534 \end_inset
20535
20536  with level number of 0 (PIC14 only has 1 interrupt so this number is only
20537  there to avoid a syntax error - it ought to be fixed).
20538  E.g.:
20539
20540 \layout Verse
20541
20542 \family typewriter
20543 void Intr(void) __interrupt 0
20544 \newline
20545 {
20546 \newline
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 T0IF = 0; /* Clear timer interrupt */
20550 \newline
20551 }
20552
20553 \layout Subsection
20554 Linking and assembling
20555
20556 \layout Standard
20557 For assembling you can use either GPUTILS'
20558 \begin_inset LatexCommand \index{gputils (pic tools)}
20559
20560 \end_inset
20561
20562  gpasm.exe or MPLAB's mpasmwin.exe.
20563  GPUTILS is available from 
20564 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20565
20566 \end_inset
20567
20568 .
20569  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
20570  If you use MPLAB and an interrupt function then the linker script file
20571  vectors section will need to be enlarged to link with mplink.
20572 \newline
20573
20574 \newline
20575 Here is a 
20576 \family typewriter
20577 Makefile
20578 \family default
20579  using GPUTILS:
20580
20581 \layout Verse
20582
20583 \family typewriter
20584 .c.o:
20585 \newline
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 sdcc -S -V -mpic14 -p16F877 $< 
20595 \newline
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604 gpasm -c $*.asm
20605 \newline
20606
20607 \newline
20608 $(PRJ).hex: $(OBJS) 
20609 \newline
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 \SpecialChar ~
20616 \SpecialChar ~
20617 \SpecialChar ~
20618 gplink
20619  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20620
20621 \layout Standard
20622 Here is a 
20623 \family typewriter
20624 Makefile
20625 \family default
20626  using MPLAB:
20627
20628 \layout Verse
20629
20630 \family typewriter
20631 .c.o: 
20632 \newline
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 \SpecialChar ~
20641 sdcc -S -V -mpic14 -p16F877 $< 
20642 \newline
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646 \SpecialChar ~
20647 \SpecialChar ~
20648 \SpecialChar ~
20649 \SpecialChar ~
20650 \SpecialChar ~
20651 mpasmwin /q /o $*.asm
20652 \newline
20653
20654 \newline
20655 $(PRJ).hex: $(OBJS)
20656  
20657 \newline
20658 \SpecialChar ~
20659 \SpecialChar ~
20660 \SpecialChar ~
20661 \SpecialChar ~
20662 \SpecialChar ~
20663 \SpecialChar ~
20664 \SpecialChar ~
20665 \SpecialChar ~
20666 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20667
20668 \layout Standard
20669 Please note that indentations within a
20670 \family typewriter
20671  Makefile
20672 \family default
20673  have to be done with a tabulator character.
20674
20675 \layout Subsection
20676 Command-line options
20677
20678 \layout Standard
20679 Besides the switches common to all SDCC backends, the PIC14 port accepts
20680  the following options (for an updated list see sdcc -
20681 \begin_inset ERT
20682 status Collapsed
20683
20684 \layout Standard
20685
20686
20687 \backslash
20688 /
20689
20690 \end_inset
20691
20692 -help):
20693
20694 \layout List
20695 \labelwidthstring 00.00.0000
20696 -
20697 \begin_inset ERT
20698 status Collapsed
20699
20700 \layout Standard
20701
20702
20703 \backslash
20704 /
20705
20706 \end_inset
20707
20708 -debug-extra
20709 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20710
20711 \end_inset
20712
20713  emit debug info in assembly output
20714
20715 \layout List
20716 \labelwidthstring 00.00.0000
20717 -
20718 \begin_inset ERT
20719 status Collapsed
20720
20721 \layout Standard
20722
20723
20724 \backslash
20725 /
20726
20727 \end_inset
20728
20729 -no-pcode-opt
20730 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20731
20732 \end_inset
20733
20734  disable (slightly faulty) optimization on pCode
20735
20736 \layout List
20737 \labelwidthstring 00.00.0000
20738 -
20739 \begin_inset ERT
20740 status Collapsed
20741
20742 \layout Standard
20743
20744
20745 \backslash
20746 /
20747
20748 \end_inset
20749
20750 -stack-loc
20751 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20752
20753 \end_inset
20754
20755  sets the lowest address of the argument passing stack (defaults to a suitably
20756  large shared databank to reduce BANKSEL overhead)
20757
20758 \layout List
20759 \labelwidthstring 00.00.0000
20760 -
20761 \begin_inset ERT
20762 status Collapsed
20763
20764 \layout Standard
20765
20766
20767 \backslash
20768 /
20769
20770 \end_inset
20771
20772 -stack-size
20773 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20774
20775 \end_inset
20776
20777  sets the size if the argument passing stack (default: 16, minimum: 4)
20778
20779 \layout Subsection
20780 The library
20781
20782 \layout Subsubsection
20783 error: missing definition for symbol 
20784 \begin_inset Quotes sld
20785 \end_inset
20786
20787 __gptrget1
20788 \begin_inset Quotes srd
20789 \end_inset
20790
20791
20792
20793 \layout Standard
20794 The PIC14 port uses library routines to provide more complex operations
20795  like multiplication, division/modulus and (generic) pointer dereferencing.
20796  In order to add these routines to your project, you must link with PIC14's
20797  
20798 \family typewriter
20799 libsdcc.lib
20800 \family default
20801 .
20802  For single source file projects this is done automatically, more complex
20803  projects must add 
20804 \family typewriter
20805 libsdcc.lib
20806 \family default
20807  to the linker's arguments.
20808  Make sure you also add an include path for the library (using the -I switch
20809  to the linker)!
20810
20811 \layout Subsubsection
20812 Processor mismatch in file 
20813 \begin_inset Quotes sld
20814 \end_inset
20815
20816 XXX
20817 \begin_inset Quotes srd
20818 \end_inset
20819
20820 .
20821
20822 \layout Standard
20823 This warning can usually be ignored due to the very good compatibility amongst
20824  14 bit PIC
20825 \begin_inset LatexCommand \index{PIC14}
20826
20827 \end_inset
20828
20829  devices.
20830
20831 \layout Standard
20832 You might also consider recompiling the library for your specific device
20833  by changing the ARCH=p16f877 (default target) entry in 
20834 \family typewriter
20835 device/lib/pic/Makefile.in
20836 \family default
20837  and 
20838 \family typewriter
20839 device/lib/pic/Makefile
20840 \family default
20841  to reflect your device.
20842  This might even improve performance for smaller devices as unneccesary
20843  BANKSELs migth be removed.
20844
20845 \layout Subsection
20846 Known bugs
20847
20848 \layout Subsubsection
20849 initialized data
20850
20851 \layout Standard
20852 \pagebreak_bottom 
20853 Currently, data can only be initialized if it resides in the source file
20854  together with 
20855 \emph on
20856 main()
20857 \emph default
20858 .
20859  Data in other source files will silently 
20860 \series bold
20861 not
20862 \series default
20863  be initialized.
20864 \family typewriter
20865 \size footnotesize
20866
20867 \begin_inset Marginal
20868 collapsed true
20869
20870 \layout Standard
20871
20872 \series bold
20873 \SpecialChar ~
20874 !
20875
20876 \end_inset
20877
20878
20879 \family default
20880
20881
20882
20883 \layout Section
20884 The PIC16
20885 \begin_inset LatexCommand \index{PIC16}
20886
20887 \end_inset
20888
20889  port
20890
20891 \layout Standard
20892 The PIC16
20893 \begin_inset LatexCommand \index{PIC16}
20894
20895 \end_inset
20896
20897  port is the portion of SDCC that is responsible to produce code for the
20898  Microchip
20899 \begin_inset LatexCommand \index{Microchip}
20900
20901 \end_inset
20902
20903 (TM) microcontrollers with 16 bit core.
20904  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20905  Currently supported devices are:
20906
20907 \layout Standard
20908 \align center
20909 \begin_inset Tabular
20910 <lyxtabular version="3" rows="4" columns="6">
20911 <features>
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" width="0">
20915 <column alignment="center" valignment="top" leftline="true" width="0">
20916 <column alignment="center" valignment="top" leftline="true" width="0">
20917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20918 <row topline="true">
20919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20920 \begin_inset Text
20921
20922 \layout Standard
20923 18F242
20924
20925 \end_inset
20926 </cell>
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20928 \begin_inset Text
20929
20930 \layout Standard
20931 18F248
20932
20933 \end_inset
20934 </cell>
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \layout Standard
20939 18F252
20940
20941 \end_inset
20942 </cell>
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20944 \begin_inset Text
20945
20946 \layout Standard
20947 18F258
20948
20949 \end_inset
20950 </cell>
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20952 \begin_inset Text
20953
20954 \layout Standard
20955 18F442
20956
20957 \end_inset
20958 </cell>
20959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20960 \begin_inset Text
20961
20962 \layout Standard
20963 18F448
20964
20965 \end_inset
20966 </cell>
20967 </row>
20968 <row topline="true">
20969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20970 \begin_inset Text
20971
20972 \layout Standard
20973 18F452
20974
20975 \end_inset
20976 </cell>
20977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20978 \begin_inset Text
20979
20980 \layout Standard
20981 18F458
20982
20983 \end_inset
20984 </cell>
20985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20986 \begin_inset Text
20987
20988 \layout Standard
20989 18F1220
20990
20991 \end_inset
20992 </cell>
20993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20994 \begin_inset Text
20995
20996 \layout Standard
20997 18F2220
20998
20999 \end_inset
21000 </cell>
21001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21002 \begin_inset Text
21003
21004 \layout Standard
21005 18F2550
21006
21007 \end_inset
21008 </cell>
21009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21010 \begin_inset Text
21011
21012 \layout Standard
21013 18F4331
21014
21015 \end_inset
21016 </cell>
21017 </row>
21018 <row topline="true">
21019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21020 \begin_inset Text
21021
21022 \layout Standard
21023 18F4455
21024
21025 \end_inset
21026 </cell>
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \layout Standard
21031 18F6520
21032
21033 \end_inset
21034 </cell>
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \layout Standard
21039 18F6620
21040
21041 \end_inset
21042 </cell>
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21044 \begin_inset Text
21045
21046 \layout Standard
21047 18F6680
21048
21049 \end_inset
21050 </cell>
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21052 \begin_inset Text
21053
21054 \layout Standard
21055 18F6720
21056
21057 \end_inset
21058 </cell>
21059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21060 \begin_inset Text
21061
21062 \layout Standard
21063 18F8520
21064
21065 \end_inset
21066 </cell>
21067 </row>
21068 <row topline="true" bottomline="true">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \layout Standard
21073 18F8620
21074
21075 \end_inset
21076 </cell>
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21078 \begin_inset Text
21079
21080 \layout Standard
21081 18F8680
21082
21083 \end_inset
21084 </cell>
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21086 \begin_inset Text
21087
21088 \layout Standard
21089 18F8720
21090
21091 \end_inset
21092 </cell>
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \layout Standard
21097
21098
21099 \end_inset
21100 </cell>
21101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21102 \begin_inset Text
21103
21104 \layout Standard
21105
21106
21107 \end_inset
21108 </cell>
21109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21110 \begin_inset Text
21111
21112 \layout Standard
21113
21114
21115 \end_inset
21116 </cell>
21117 </row>
21118 </lyxtabular>
21119
21120 \end_inset
21121
21122
21123
21124 \layout Subsection
21125 Global Options
21126
21127 \layout Standard
21128 PIC16 port supports the standard command line arguments as supposed, with
21129  the exception of certain cases that will be mentioned in the following
21130  list:
21131
21132 \layout List
21133 \labelwidthstring 00.00.0000
21134 -
21135 \begin_inset ERT
21136 status Collapsed
21137
21138 \layout Standard
21139
21140
21141 \backslash
21142 /
21143
21144 \end_inset
21145
21146 -callee-saves
21147 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21148
21149 \end_inset
21150
21151  See -
21152 \begin_inset ERT
21153 status Collapsed
21154
21155 \layout Standard
21156
21157
21158 \backslash
21159 /
21160
21161 \end_inset
21162
21163 -all-callee-saves
21164
21165 \layout List
21166 \labelwidthstring 00.00.0000
21167 -
21168 \begin_inset ERT
21169 status Collapsed
21170
21171 \layout Standard
21172
21173
21174 \backslash
21175 /
21176
21177 \end_inset
21178
21179 -all-callee-saves
21180 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21181
21182 \end_inset
21183
21184  All function arguments are passed on stack by default.
21185  
21186 \emph on
21187 There is no need to specify this in the command line.
21188
21189 \layout List
21190 \labelwidthstring 00.00.0000
21191 -
21192 \begin_inset ERT
21193 status Collapsed
21194
21195 \layout Standard
21196
21197
21198 \backslash
21199 /
21200
21201 \end_inset
21202
21203 -fommit-frame-pointer
21204 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21205
21206 \end_inset
21207
21208  Frame pointer will be omitted when the function uses no local variables.
21209
21210 \layout Subsection
21211 Port Specific Options
21212 \begin_inset LatexCommand \index{Options PIC16}
21213
21214 \end_inset
21215
21216
21217
21218 \layout Standard
21219 The port specific options appear after the global options in the sdcc --help
21220  output.
21221
21222 \layout Subsubsection
21223 General Options
21224
21225 \layout Standard
21226 General options enable certain port features and optimizations.
21227
21228 \layout List
21229 \labelwidthstring 00.00.0000
21230 -
21231 \begin_inset ERT
21232 status Collapsed
21233
21234 \layout Standard
21235
21236
21237 \backslash
21238 /
21239
21240 \end_inset
21241
21242 -pstack-model=[model] Used in conjuction with the command above.
21243  Defines the stack model to be used, valid stack models are : 
21244
21245 \begin_deeper
21246 \layout List
21247 \labelwidthstring 00.00.0000
21248
21249 \emph on
21250 small
21251 \emph default
21252  Selects small stack model.
21253  8 bit stack and frame pointers.
21254  Supports 256 bytes stack size.
21255
21256 \layout List
21257 \labelwidthstring 00.00.0000
21258
21259 \emph on
21260 large
21261 \emph default
21262  Selects large stack model.
21263  16 bit stack and frame pointers.
21264  Supports 65536 bytes stack size.
21265
21266 \end_deeper
21267 \layout List
21268 \labelwidthstring 00.00.0000
21269 -
21270 \begin_inset ERT
21271 status Collapsed
21272
21273 \layout Standard
21274
21275
21276 \backslash
21277 /
21278
21279 \end_inset
21280
21281 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21282  unitialized data variables with [kword].
21283  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21284
21285 \layout List
21286 \labelwidthstring 00.00.0000
21287 -
21288 \begin_inset ERT
21289 status Collapsed
21290
21291 \layout Standard
21292
21293
21294 \backslash
21295 /
21296
21297 \end_inset
21298
21299 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21300  Useful for bootloaders.
21301
21302 \layout List
21303 \labelwidthstring 00.00.0000
21304 -
21305 \begin_inset ERT
21306 status Collapsed
21307
21308 \layout Standard
21309
21310
21311 \backslash
21312 /
21313
21314 \end_inset
21315
21316 -asm= sets the full path and name of an external assembler to call.
21317
21318 \layout List
21319 \labelwidthstring 00.00.0000
21320 -
21321 \begin_inset ERT
21322 status Collapsed
21323
21324 \layout Standard
21325
21326
21327 \backslash
21328 /
21329
21330 \end_inset
21331
21332 -link= sets the full path and name of an external linker to call.
21333
21334 \layout List
21335 \labelwidthstring 00.00.0000
21336 -
21337 \begin_inset ERT
21338 status Collapsed
21339
21340 \layout Standard
21341
21342
21343 \backslash
21344 /
21345
21346 \end_inset
21347
21348 -mplab-comp MPLAB
21349 \begin_inset LatexCommand \index{PIC16!MPLAB}
21350
21351 \end_inset
21352
21353  compatibility option.
21354  Currently only suppresses special gpasm directives.
21355
21356 \layout Subsubsection
21357 Optimization Options
21358
21359 \layout List
21360 \labelwidthstring 00.00.0000
21361 -
21362 \begin_inset ERT
21363 status Collapsed
21364
21365 \layout Standard
21366
21367
21368 \backslash
21369 /
21370
21371 \end_inset
21372
21373 -optimize-goto Try to use (conditional) BRA instead of GOTO
21374
21375 \layout List
21376 \labelwidthstring 00.00.0000
21377 -
21378 \begin_inset ERT
21379 status Collapsed
21380
21381 \layout Standard
21382
21383
21384 \backslash
21385 /
21386
21387 \end_inset
21388
21389 -optimize-cmp Try to optimize some compares.
21390
21391 \layout List
21392 \labelwidthstring 00.00.0000
21393 -
21394 \begin_inset ERT
21395 status Collapsed
21396
21397 \layout Standard
21398
21399
21400 \backslash
21401 /
21402
21403 \end_inset
21404
21405 -optimize-df Analyze the dataflow of the generated code and improve it.
21406
21407 \layout List
21408 \labelwidthstring 00.00.0000
21409 -
21410 \begin_inset ERT
21411 status Collapsed
21412
21413 \layout Standard
21414
21415
21416 \backslash
21417 /
21418
21419 \end_inset
21420
21421 -obanksel=nn Set optimization level for inserting BANKSELs.
21422 \newline
21423
21424
21425 \begin_deeper
21426 \layout List
21427 \labelwidthstring 00.00.0000
21428 0 no optimization
21429
21430 \layout List
21431 \labelwidthstring 00.00.0000
21432 1 checks previous used register and if it is the same then does not emit
21433  BANKSEL, accounts only for labels.
21434
21435 \layout List
21436 \labelwidthstring 00.00.0000
21437 2 tries to check the location of (even different) symbols and removes BANKSELs
21438  if they are in the same bank.
21439  
21440 \newline
21441
21442 \emph on
21443 Important: There might be problems if the linker script has data sections
21444  across bank borders!
21445
21446 \end_deeper
21447 \layout Subsubsection
21448 Linking Options
21449
21450 \layout List
21451 \labelwidthstring 00.00.0000
21452 -
21453 \begin_inset ERT
21454 status Collapsed
21455
21456 \layout Standard
21457
21458
21459 \backslash
21460 /
21461
21462 \end_inset
21463
21464 -nodefaultlibs do not link default libraries when linking
21465
21466 \layout List
21467 \labelwidthstring 00.00.0000
21468 -
21469 \begin_inset ERT
21470 status Collapsed
21471
21472 \layout Standard
21473
21474
21475 \backslash
21476 /
21477
21478 \end_inset
21479
21480 -no-crt Don't link the default run-time modules
21481
21482 \layout List
21483 \labelwidthstring 00.00.0000
21484 -
21485 \begin_inset ERT
21486 status Collapsed
21487
21488 \layout Standard
21489
21490
21491 \backslash
21492 /
21493
21494 \end_inset
21495
21496 -use-crt= Use a custom run-time module instead of the defaults.
21497
21498 \layout Subsubsection
21499 Debugging Options
21500
21501 \layout Standard
21502 Debugging options enable extra debugging information in the output files.
21503
21504 \layout List
21505 \labelwidthstring 00.00.0000
21506 -
21507 \begin_inset ERT
21508 status Collapsed
21509
21510 \layout Standard
21511
21512
21513 \backslash
21514 /
21515
21516 \end_inset
21517
21518 -debug-xtra Similar to -
21519 \begin_inset ERT
21520 status Collapsed
21521
21522 \layout Standard
21523
21524
21525 \backslash
21526 /
21527
21528 \end_inset
21529
21530 -debug
21531 \begin_inset LatexCommand \index{-\/-debug}
21532
21533 \end_inset
21534
21535 , but dumps more information.
21536
21537 \layout List
21538 \labelwidthstring 00.00.0000
21539 -
21540 \begin_inset ERT
21541 status Collapsed
21542
21543 \layout Standard
21544
21545
21546 \backslash
21547 /
21548
21549 \end_inset
21550
21551 -debug-ralloc Force register allocator to dump <source>.d file with debugging
21552  information.
21553  <source> is the name of the file compiled.
21554
21555 \layout List
21556 \labelwidthstring 00.00.0000
21557 -
21558 \begin_inset ERT
21559 status Collapsed
21560
21561 \layout Standard
21562
21563
21564 \backslash
21565 /
21566
21567 \end_inset
21568
21569 -pcode-verbose Enable pcode debugging information in translation.
21570
21571 \layout List
21572 \labelwidthstring 00.00.0000
21573 -
21574 \begin_inset ERT
21575 status Collapsed
21576
21577 \layout Standard
21578
21579
21580 \backslash
21581 /
21582
21583 \end_inset
21584
21585 -denable-peeps Force the usage of peepholes.
21586  Use with care.
21587
21588 \layout List
21589 \labelwidthstring 00.00.0000
21590 -
21591 \begin_inset ERT
21592 status Collapsed
21593
21594 \layout Standard
21595
21596
21597 \backslash
21598 /
21599
21600 \end_inset
21601
21602 -gstack Trace push/pops for stack pointer overflow
21603
21604 \layout List
21605 \labelwidthstring 00.00.0000
21606 -
21607 \begin_inset ERT
21608 status Collapsed
21609
21610 \layout Standard
21611
21612
21613 \backslash
21614 /
21615
21616 \end_inset
21617
21618 -call-tree dump call tree in .calltree file
21619
21620 \layout Subsection
21621 Enviromental Variables
21622
21623 \layout Standard
21624 There is a number of enviromental variables that can be used when running
21625  SDCC to enable certain optimizations or force a specific program behaviour.
21626  these variables are primarily for debugging purposes so they can be enabled/dis
21627 abled at will.
21628
21629 \layout Standard
21630 Currently there is only two such variables available:
21631
21632 \layout List
21633 \labelwidthstring 00.00.0000
21634 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
21635  bitfields is optimized by directly loading FSR0 with the address of the
21636  bitfield structure.
21637  Normally SDCC will cast the bitfield structure to a bitfield pointer and
21638  then load FSR0.
21639  This step saves data ram and code space for functions that perform heavy
21640  use of bitfields.
21641  (ie.
21642  80 bytes of code space are saved when compiling malloc.c with this option).
21643  
21644
21645 \layout List
21646 \labelwidthstring 00.00.0000
21647 NO_REG_OPT do not perform pCode registers optimization.
21648  This should be used for debugging purposes.
21649  In some where bugs in the pcode optimizer are found, users can benefit
21650  from temporarily disabling the optimizer until the bug is fixed.
21651
21652 \layout Subsection
21653 Preprocessor Macros
21654
21655 \layout Standard
21656 PIC16
21657 \begin_inset LatexCommand \index{PIC16}
21658
21659 \end_inset
21660
21661  port defines the following preprocessor macros while translating a source.
21662
21663 \layout Standard
21664 \align center
21665 \begin_inset Tabular
21666 <lyxtabular version="3" rows="6" columns="2">
21667 <features>
21668 <column alignment="center" valignment="top" leftline="true" width="0">
21669 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21670 <row topline="true" bottomline="true">
21671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21672 \begin_inset Text
21673
21674 \layout Standard
21675 Macro
21676
21677 \end_inset
21678 </cell>
21679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21680 \begin_inset Text
21681
21682 \layout Standard
21683 Description
21684
21685 \end_inset
21686 </cell>
21687 </row>
21688 <row topline="true">
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21690 \begin_inset Text
21691
21692 \layout Standard
21693 SDCC_pic16
21694
21695 \end_inset
21696 </cell>
21697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21698 \begin_inset Text
21699
21700 \layout Standard
21701 Port identification
21702
21703 \end_inset
21704 </cell>
21705 </row>
21706 <row topline="true">
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21708 \begin_inset Text
21709
21710 \layout Standard
21711 _
21712 \begin_inset ERT
21713 status Collapsed
21714
21715 \layout Standard
21716
21717
21718 \backslash
21719 /
21720
21721 \end_inset
21722
21723 _pic16
21724
21725 \end_inset
21726 </cell>
21727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21728 \begin_inset Text
21729
21730 \layout Standard
21731 Port identification (same as above)
21732
21733 \end_inset
21734 </cell>
21735 </row>
21736 <row topline="true">
21737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21738 \begin_inset Text
21739
21740 \layout Standard
21741 pic18fxxxx
21742
21743 \end_inset
21744 </cell>
21745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21746 \begin_inset Text
21747
21748 \layout Standard
21749 MCU Identification.
21750  
21751 \emph on
21752 xxxx
21753 \emph default
21754  is the microcontrol identification number, i.e.
21755  452, 6620, etc
21756
21757 \end_inset
21758 </cell>
21759 </row>
21760 <row topline="true">
21761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21762 \begin_inset Text
21763
21764 \layout Standard
21765 _
21766 \begin_inset ERT
21767 status Collapsed
21768
21769 \layout Standard
21770
21771
21772 \backslash
21773 /
21774
21775 \end_inset
21776
21777 _18Fxxxx
21778
21779 \end_inset
21780 </cell>
21781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21782 \begin_inset Text
21783
21784 \layout Standard
21785 MCU Identification (same as above)
21786
21787 \end_inset
21788 </cell>
21789 </row>
21790 <row topline="true" bottomline="true">
21791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21792 \begin_inset Text
21793
21794 \layout Standard
21795 STACK_MODEL_nnn
21796
21797 \end_inset
21798 </cell>
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21800 \begin_inset Text
21801
21802 \layout Standard
21803 nnn = SMALL or LARGE respectively according to the stack model used
21804
21805 \end_inset
21806 </cell>
21807 </row>
21808 </lyxtabular>
21809
21810 \end_inset
21811
21812
21813
21814 \layout Standard
21815 In addition the following macros are defined when calling assembler:
21816
21817 \layout Standard
21818 \align center
21819 \begin_inset Tabular
21820 <lyxtabular version="3" rows="4" columns="2">
21821 <features>
21822 <column alignment="center" valignment="top" leftline="true" width="0">
21823 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21824 <row topline="true" bottomline="true">
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21826 \begin_inset Text
21827
21828 \layout Standard
21829 Macro
21830
21831 \end_inset
21832 </cell>
21833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21834 \begin_inset Text
21835
21836 \layout Standard
21837 Description
21838
21839 \end_inset
21840 </cell>
21841 </row>
21842 <row topline="true">
21843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21844 \begin_inset Text
21845
21846 \layout Standard
21847 __18Fxxxx
21848
21849 \end_inset
21850 </cell>
21851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21852 \begin_inset Text
21853
21854 \layout Standard
21855 MCU Identification.
21856  
21857 \emph on
21858 xxxx
21859 \emph default
21860  is the microcontrol identification number, i.e.
21861  452, 6620, etc
21862
21863 \end_inset
21864 </cell>
21865 </row>
21866 <row topline="true">
21867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21868 \begin_inset Text
21869
21870 \layout Standard
21871 SDCC_MODEL_nnn
21872
21873 \end_inset
21874 </cell>
21875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21876 \begin_inset Text
21877
21878 \layout Standard
21879 nnn = SMALL or LARGE respectively according to the memory model used for
21880  SDCC
21881
21882 \end_inset
21883 </cell>
21884 </row>
21885 <row topline="true" bottomline="true">
21886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21887 \begin_inset Text
21888
21889 \layout Standard
21890 STACK_MODEL_nnn
21891
21892 \end_inset
21893 </cell>
21894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21895 \begin_inset Text
21896
21897 \layout Standard
21898 nnn = SMALL or LARGE respectively according to the stack model used
21899
21900 \end_inset
21901 </cell>
21902 </row>
21903 </lyxtabular>
21904
21905 \end_inset
21906
21907
21908
21909 \layout Subsection
21910 Directories
21911
21912 \layout Standard
21913 PIC16
21914 \begin_inset LatexCommand \index{PIC16}
21915
21916 \end_inset
21917
21918  port uses the following directories for searching header files and libraries.
21919
21920 \layout Standard
21921 \align center
21922 \begin_inset Tabular
21923 <lyxtabular version="3" rows="3" columns="4">
21924 <features>
21925 <column alignment="center" valignment="top" leftline="true" width="0">
21926 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21927 <column alignment="center" valignment="top" width="0">
21928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21929 <row topline="true" bottomline="true">
21930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21931 \begin_inset Text
21932
21933 \layout Standard
21934 Directory
21935
21936 \end_inset
21937 </cell>
21938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21939 \begin_inset Text
21940
21941 \layout Standard
21942 Description
21943
21944 \end_inset
21945 </cell>
21946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21947 \begin_inset Text
21948
21949 \layout Standard
21950 Target
21951
21952 \end_inset
21953 </cell>
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21955 \begin_inset Text
21956
21957 \layout Standard
21958 Command prefix
21959
21960 \end_inset
21961 </cell>
21962 </row>
21963 <row topline="true">
21964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21965 \begin_inset Text
21966
21967 \layout Standard
21968 PREFIX/sdcc/include/pic16
21969
21970 \end_inset
21971 </cell>
21972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21973 \begin_inset Text
21974
21975 \layout Standard
21976 PIC16 specific headers
21977
21978 \end_inset
21979 </cell>
21980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21981 \begin_inset Text
21982
21983 \layout Standard
21984 Compiler
21985
21986 \end_inset
21987 </cell>
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21989 \begin_inset Text
21990
21991 \layout Standard
21992 -I
21993
21994 \end_inset
21995 </cell>
21996 </row>
21997 <row topline="true" bottomline="true">
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21999 \begin_inset Text
22000
22001 \layout Standard
22002 PREFIX/sdcc/lib/pic16
22003
22004 \end_inset
22005 </cell>
22006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22007 \begin_inset Text
22008
22009 \layout Standard
22010 PIC16 specific libraries
22011
22012 \end_inset
22013 </cell>
22014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22015 \begin_inset Text
22016
22017 \layout Standard
22018 Linker
22019
22020 \end_inset
22021 </cell>
22022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22023 \begin_inset Text
22024
22025 \layout Standard
22026 -L
22027
22028 \end_inset
22029 </cell>
22030 </row>
22031 </lyxtabular>
22032
22033 \end_inset
22034
22035
22036
22037 \layout Subsection
22038 Pragmas
22039 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22040
22041 \end_inset
22042
22043
22044
22045 \layout Standard
22046 PIC16
22047 \begin_inset LatexCommand \index{PIC16}
22048
22049 \end_inset
22050
22051  port currently supports the following pragmas:
22052
22053 \layout List
22054 \labelwidthstring 00.00.0000
22055 stack
22056 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22057
22058 \end_inset
22059
22060  pragma stack
22061 \begin_inset LatexCommand \index{PIC16!stack}
22062
22063 \end_inset
22064
22065  forces the code generator to initialize the stack & frame pointers at a
22066  specific address.
22067  This is an adhoc solution for cases where no STACK directive is available
22068  in the linker script or gplink is not instructed to create a stack section.
22069 \newline
22070 The
22071  stack pragma should be used only once in a project.
22072  Multiple pragmas may result in indeterminate behaviour of the program.
22073 \begin_inset Foot
22074 collapsed false
22075
22076 \layout Standard
22077 The old format (ie.
22078  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22079  cross page boundaries (or even exceed the available data RAM) and crash
22080  the program.
22081  Make sure that stack does not cross page boundaries when using the SMALL
22082  stack model.
22083
22084 \end_inset
22085
22086
22087 \newline
22088 The format is as follows:
22089
22090 \layout LyX-Code
22091 #pragma stack bottom_address [stack_size]
22092
22093 \layout Standard
22094
22095 \emph on
22096 bottom_address
22097 \emph default
22098  is the lower bound of the stack section.
22099  The stack pointer initially will point at address (bottom_address+stack_size-1).
22100
22101 \layout LyX-Code
22102 Example:
22103
22104 \layout LyX-Code
22105
22106
22107 \layout LyX-Code
22108 /* initializes stack of 100 bytes at RAM address 0x200 */
22109
22110 \layout LyX-Code
22111 #pragma stack 0x200 100
22112
22113 \layout Standard
22114 If the stack_size field is omitted then a stack is created with the default
22115  size of 64.
22116  This size might be enough for most programs, but its not enough for operations
22117  with deep function nesting or excessive stack usage.
22118
22119 \layout List
22120 \labelwidthstring 00.00.0000
22121 code
22122 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22123
22124 \end_inset
22125
22126  place a function symbol at static FLASH address
22127
22128 \layout LyX-Code
22129 Example:
22130
22131 \layout LyX-Code
22132
22133
22134 \layout LyX-Code
22135 /* place function test_func at 0x4000 */
22136
22137 \layout LyX-Code
22138 #pragma code test_func 0x4000
22139
22140 \layout LyX-Code
22141
22142
22143 \layout List
22144 \labelwidthstring 00.00.0000
22145 library instructs the linker to use a library module.
22146 \newline
22147 Usage:
22148
22149 \layout LyX-Code
22150 #pragma library module_name
22151
22152 \layout Standard
22153
22154 \emph on
22155 module_name
22156 \emph default
22157  can be any library or object file (including its path).
22158  Note that there are four reserved keywords which have special meaning.
22159  These are:
22160
22161 \layout Standard
22162 \align center
22163 \begin_inset Tabular
22164 <lyxtabular version="3" rows="6" columns="3">
22165 <features>
22166 <column alignment="center" valignment="top" leftline="true" width="0">
22167 <column alignment="block" valignment="top" leftline="true" width="20page%">
22168 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22169 <row topline="true" bottomline="true">
22170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22171 \begin_inset Text
22172
22173 \layout Standard
22174 Keyword
22175
22176 \end_inset
22177 </cell>
22178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22179 \begin_inset Text
22180
22181 \layout Standard
22182 Description
22183
22184 \end_inset
22185 </cell>
22186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22187 \begin_inset Text
22188
22189 \layout Standard
22190 Module to link
22191
22192 \end_inset
22193 </cell>
22194 </row>
22195 <row topline="true">
22196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22197 \begin_inset Text
22198
22199 \layout Standard
22200
22201 \series bold
22202 ignore
22203
22204 \end_inset
22205 </cell>
22206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22207 \begin_inset Text
22208
22209 \layout Standard
22210 ignore all library pragmas
22211
22212 \end_inset
22213 </cell>
22214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22215 \begin_inset Text
22216
22217 \layout Standard
22218
22219 \emph on
22220 (none)
22221
22222 \end_inset
22223 </cell>
22224 </row>
22225 <row topline="true">
22226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22227 \begin_inset Text
22228
22229 \layout Standard
22230
22231 \series bold
22232 c
22233
22234 \end_inset
22235 </cell>
22236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22237 \begin_inset Text
22238
22239 \layout Standard
22240 link the C library
22241
22242 \end_inset
22243 </cell>
22244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22245 \begin_inset Text
22246
22247 \layout Standard
22248
22249 \emph on
22250 libc18f
22251 \emph default
22252 .lib
22253
22254 \end_inset
22255 </cell>
22256 </row>
22257 <row topline="true">
22258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22259 \begin_inset Text
22260
22261 \layout Standard
22262
22263 \series bold
22264 math
22265
22266 \end_inset
22267 </cell>
22268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22269 \begin_inset Text
22270
22271 \layout Standard
22272 link the Math libarary
22273
22274 \end_inset
22275 </cell>
22276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22277 \begin_inset Text
22278
22279 \layout Standard
22280
22281 \emph on
22282 libm18f
22283 \emph default
22284 .lib
22285
22286 \end_inset
22287 </cell>
22288 </row>
22289 <row topline="true">
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22291 \begin_inset Text
22292
22293 \layout Standard
22294
22295 \series bold
22296 io
22297
22298 \end_inset
22299 </cell>
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 \begin_inset Text
22302
22303 \layout Standard
22304 link the I/O library
22305
22306 \end_inset
22307 </cell>
22308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22309 \begin_inset Text
22310
22311 \layout Standard
22312
22313 \emph on
22314 libio18f*
22315 \emph default
22316 .lib
22317
22318 \end_inset
22319 </cell>
22320 </row>
22321 <row topline="true" bottomline="true">
22322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22323 \begin_inset Text
22324
22325 \layout Standard
22326
22327 \series bold
22328 debug
22329
22330 \end_inset
22331 </cell>
22332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22333 \begin_inset Text
22334
22335 \layout Standard
22336 link the debug library
22337
22338 \end_inset
22339 </cell>
22340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22341 \begin_inset Text
22342
22343 \layout Standard
22344
22345 \emph on
22346 libdebug
22347 \emph default
22348 .lib
22349
22350 \end_inset
22351 </cell>
22352 </row>
22353 </lyxtabular>
22354
22355 \end_inset
22356
22357
22358 \newline
22359 * is the device number, i.e.
22360  452 for PIC18F452 MCU.
22361
22362 \layout Standard
22363 This feature allows for linking with specific libraries withoug having to
22364  explicit name them in the command line.
22365  Note that the 
22366 \noun on
22367 ignore
22368 \noun default
22369  keyword will reject all modules specified by the library pragma.
22370
22371 \layout List
22372 \labelwidthstring 00.00.0000
22373 udata pragma udata instructs the compiler to emit code so that linker will
22374  place a variable at a specific memory bank
22375
22376 \layout LyX-Code
22377 Example:
22378
22379 \layout LyX-Code
22380
22381
22382 \layout LyX-Code
22383 /* places variable foo at bank2 */
22384
22385 \layout LyX-Code
22386 #pragma udata bank2 foo
22387
22388 \layout LyX-Code
22389 char foo;
22390
22391 \layout Standard
22392 In order for this pragma to work extra SECTION directives should be added
22393  in the .lkr script.
22394  In the following example a sample .lkr file is shown:
22395
22396 \layout LyX-Code
22397
22398
22399 \layout LyX-Code
22400 // Sample linker script for the PIC18F452 processor
22401
22402 \layout LyX-Code
22403 LIBPATH .
22404
22405 \layout LyX-Code
22406 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
22407
22408 \layout LyX-Code
22409 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
22410
22411 \layout LyX-Code
22412 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
22413
22414 \layout LyX-Code
22415 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
22416
22417 \layout LyX-Code
22418 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
22419
22420 \layout LyX-Code
22421 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
22422
22423 \layout LyX-Code
22424 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
22425
22426 \layout LyX-Code
22427
22428
22429 \layout LyX-Code
22430 DATABANK   NAME=gpr0       START=0x80           END=0xFF
22431
22432 \layout LyX-Code
22433 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
22434
22435 \layout LyX-Code
22436 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
22437
22438 \layout LyX-Code
22439 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
22440
22441 \layout LyX-Code
22442 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
22443
22444 \layout LyX-Code
22445 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
22446
22447 \layout LyX-Code
22448 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
22449
22450 \layout LyX-Code
22451
22452
22453 \layout LyX-Code
22454 SECTION    NAME=CONFIG     ROM=config
22455
22456 \layout LyX-Code
22457
22458
22459 \layout LyX-Code
22460 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
22461
22462 \layout LyX-Code
22463 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
22464
22465 \layout LyX-Code
22466 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
22467
22468 \layout LyX-Code
22469 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
22470
22471 \layout LyX-Code
22472 SECTION    NAME=bank4      RAM=gpr4
22473
22474 \layout LyX-Code
22475 SECTION    NAME=bank5      RAM=gpr5
22476
22477 \layout Standard
22478 The linker will recognise the section name set in the pragma statement and
22479  will position the variable at the memory bank set with the RAM field at
22480  the SECTION line in the linker script file.
22481
22482 \layout Subsection
22483 Header Files
22484 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
22485
22486 \end_inset
22487
22488
22489
22490 \layout Standard
22491 There is one main header file
22492 \begin_inset LatexCommand \index{PIC16!Header files}
22493
22494 \end_inset
22495
22496  that can be included to the source files using the pic16
22497 \begin_inset LatexCommand \index{PIC16}
22498
22499 \end_inset
22500
22501  port.
22502  That file is the 
22503 \series bold
22504 pic18fregs.h
22505 \series default
22506 .
22507  This header file contains the definitions for the processor special registers,
22508  so it is necessary if the source accesses them.
22509  It can be included by adding the following line in the beginning of the
22510  file:
22511
22512 \layout LyX-Code
22513 #include <pic18fregs.h>
22514
22515 \layout Standard
22516 The specific microcontroller is selected within the pic18fregs.h automatically,
22517  so the same source can be used with a variety of devices.
22518
22519 \layout Subsection
22520 Libraries
22521
22522 \layout Standard
22523 The libraries
22524 \begin_inset LatexCommand \index{PIC16!Libraries}
22525
22526 \end_inset
22527
22528  that PIC16
22529 \begin_inset LatexCommand \index{PIC16}
22530
22531 \end_inset
22532
22533  port depends on are the microcontroller device libraries which contain
22534  the symbol definitions for the microcontroller special function registers.
22535  These libraries have the format pic18fxxxx.lib, where 
22536 \emph on
22537 xxxx
22538 \emph default
22539  is the microcontroller identification number.
22540  The specific library is selected automatically by the compiler at link
22541  stage according to the selected device.
22542
22543 \layout Standard
22544 Libraries are created with gplib which is part of the gputils package 
22545 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22546
22547 \end_inset
22548
22549 .
22550
22551 \layout Subsubsection*
22552 Building the libraries
22553
22554 \layout Standard
22555 Before using SDCC/pic16 there are some libraries that need to be compiled.
22556  This process is not done automatically by SDCC since not all users use
22557  SDCC for pic16 projects.
22558  So each user should compile the libraries separately.
22559
22560 \layout Standard
22561 The steps to compile the pic16 libraries under Linux are:
22562
22563 \layout LyX-Code
22564 cd device/lib/pic16
22565
22566 \layout LyX-Code
22567 ./configure
22568
22569 \layout LyX-Code
22570 make
22571
22572 \layout LyX-Code
22573 cd ..
22574
22575 \layout LyX-Code
22576 make model-pic16
22577
22578 \layout LyX-Code
22579 su -c 'make install'     # install the libraries, you need the root password
22580
22581 \layout Standard
22582 If you need to install the headers too, do:
22583
22584 \layout LyX-Code
22585 cd device/include
22586
22587 \layout LyX-Code
22588 su -c 'make install'     # install the headers, you need the root password
22589
22590 \layout Standard
22591 There exist a special target to build the I/O libraries.
22592  This target is not automatically build because it will build the I/O library
22593  for 
22594 \emph on
22595 every
22596 \emph default
22597  supported device.
22598  This way building will take quite a lot of time.
22599  Users are advised to edit the 
22600 \series bold
22601 device/lib/pic16/pics.build
22602 \series default
22603  file and then execute:
22604
22605 \layout LyX-Code
22606 make lib-io
22607
22608 \layout Subsection
22609 Memory Models
22610
22611 \layout Standard
22612 The following memory models are supported by the PIC16 port:
22613
22614 \layout Itemize
22615 small model
22616
22617 \layout Itemize
22618 large model
22619
22620 \layout Standard
22621 Memory model affects the default size of pointers within the source.
22622  The sizes are shown in the next table:
22623
22624 \layout Standard
22625 \align center
22626 \begin_inset Tabular
22627 <lyxtabular version="3" rows="3" columns="3">
22628 <features>
22629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22630 <column alignment="center" valignment="top" leftline="true" width="0">
22631 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22632 <row topline="true" bottomline="true">
22633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22634 \begin_inset Text
22635
22636 \layout Standard
22637 Pointer sizes according to memory model
22638
22639 \end_inset
22640 </cell>
22641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22642 \begin_inset Text
22643
22644 \layout Standard
22645 small model
22646
22647 \end_inset
22648 </cell>
22649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22650 \begin_inset Text
22651
22652 \layout Standard
22653 large model
22654
22655 \end_inset
22656 </cell>
22657 </row>
22658 <row topline="true" bottomline="true">
22659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22660 \begin_inset Text
22661
22662 \layout Standard
22663 code pointers
22664
22665 \end_inset
22666 </cell>
22667 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22668 \begin_inset Text
22669
22670 \layout Standard
22671 16-bits
22672
22673 \end_inset
22674 </cell>
22675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22676 \begin_inset Text
22677
22678 \layout Standard
22679 24-bits
22680
22681 \end_inset
22682 </cell>
22683 </row>
22684 <row topline="true" bottomline="true">
22685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22686 \begin_inset Text
22687
22688 \layout Standard
22689 data pointers
22690
22691 \end_inset
22692 </cell>
22693 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22694 \begin_inset Text
22695
22696 \layout Standard
22697 16-bits
22698
22699 \end_inset
22700 </cell>
22701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22702 \begin_inset Text
22703
22704 \layout Standard
22705 16-bits
22706
22707 \end_inset
22708 </cell>
22709 </row>
22710 </lyxtabular>
22711
22712 \end_inset
22713
22714
22715
22716 \layout Standard
22717 It is advisable that all sources within a project are compiled with the
22718  same memory model.
22719  If one wants to override the default memory model, this can be done by
22720  declaring a pointer as 
22721 \series bold
22722 far
22723 \series default
22724  or 
22725 \series bold
22726 near
22727 \series default
22728 .
22729  Far selects large memory model's pointers, while near selects small memory
22730  model's pointers.
22731
22732 \layout Standard
22733 The standard device libraries (see 
22734 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22735
22736 \end_inset
22737
22738 ) contain no reference to pointers, so they can be used with both memory
22739  models.
22740
22741 \layout Subsection
22742 Stack
22743
22744 \layout Standard
22745 The stack
22746 \begin_inset LatexCommand \index{PIC16!stack}
22747
22748 \end_inset
22749
22750  implementation for the PIC16 port uses two indirect registers, FSR1 and
22751  FSR2.
22752
22753 \layout List
22754 \labelwidthstring 00.00.0000
22755 FSR1 is assigned as stack pointer
22756
22757 \layout List
22758 \labelwidthstring 00.00.0000
22759 FSR2 is assigned as frame pointer
22760
22761 \layout Standard
22762 The following stack models are supported by the PIC16 port
22763
22764 \layout Itemize
22765
22766 \noun on
22767 small
22768 \noun default
22769  model
22770
22771 \layout Itemize
22772
22773 \noun on
22774 large
22775 \noun default
22776  model
22777
22778 \layout Standard
22779
22780 \noun on
22781 Small
22782 \noun default
22783  model means that only the FSRxL byte is used to access stack and frame,
22784  while 
22785 \emph on
22786 \noun on
22787 large
22788 \emph default
22789 \noun default
22790  uses both FSRxL and FSRxH registers.
22791  The following table shows the stack/frame pointers sizes according to stack
22792  model and the maximum space they can address:
22793
22794 \layout Standard
22795 \align center
22796 \begin_inset Tabular
22797 <lyxtabular version="3" rows="3" columns="3">
22798 <features>
22799 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22800 <column alignment="center" valignment="top" leftline="true" width="0">
22801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22802 <row topline="true" bottomline="true">
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22804 \begin_inset Text
22805
22806 \layout Standard
22807 Stack & Frame pointer sizes according to stack model
22808
22809 \end_inset
22810 </cell>
22811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22812 \begin_inset Text
22813
22814 \layout Standard
22815 small
22816
22817 \end_inset
22818 </cell>
22819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22820 \begin_inset Text
22821
22822 \layout Standard
22823 large
22824
22825 \end_inset
22826 </cell>
22827 </row>
22828 <row topline="true">
22829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22830 \begin_inset Text
22831
22832 \layout Standard
22833 Stack pointer FSR1
22834
22835 \end_inset
22836 </cell>
22837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22838 \begin_inset Text
22839
22840 \layout Standard
22841 8-bits
22842
22843 \end_inset
22844 </cell>
22845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22846 \begin_inset Text
22847
22848 \layout Standard
22849 16-bits
22850
22851 \end_inset
22852 </cell>
22853 </row>
22854 <row topline="true" bottomline="true">
22855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22856 \begin_inset Text
22857
22858 \layout Standard
22859 Frame pointer FSR2
22860
22861 \end_inset
22862 </cell>
22863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22864 \begin_inset Text
22865
22866 \layout Standard
22867 8-bits
22868
22869 \end_inset
22870 </cell>
22871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22872 \begin_inset Text
22873
22874 \layout Standard
22875 16-bits
22876
22877 \end_inset
22878 </cell>
22879 </row>
22880 </lyxtabular>
22881
22882 \end_inset
22883
22884
22885
22886 \layout Standard
22887
22888 \noun on
22889 Large 
22890 \noun default
22891 stack model is currently not working properly throughout the code generator.
22892  So its use is not advised.
22893  Also there are some other points that need special care:
22894 \newline
22895
22896
22897 \layout Enumerate
22898 Do not create stack sections with size more than one physical bank (that
22899  is 256 bytes)
22900
22901 \layout Enumerate
22902 Stack sections should no cross physical bank limits (i.e.
22903  #pragma stack 0x50 0x100)
22904
22905 \layout Standard
22906 These limitations are caused by the fact that only FSRxL is modified when
22907  using SMALL stack model, so no more than 256 bytes of stack can be used.
22908  This problem will disappear after LARGE model is fully implemented.
22909
22910 \layout Subsection
22911 Functions
22912
22913 \layout Standard
22914 In addition to the standard SDCC function keywords, PIC16
22915 \begin_inset LatexCommand \index{PIC16}
22916
22917 \end_inset
22918
22919  port makes available two more:
22920
22921 \layout List
22922 \labelwidthstring 00.00.0000
22923 wparam
22924 \begin_inset LatexCommand \index{PIC16!wparam}
22925
22926 \end_inset
22927
22928  Use the WREG to pass one byte of the first function argument.
22929  This improves speed but you may not use this for functions with arguments
22930  that are called via function pointers, otherwise the first byte of the
22931  first parameter will get lost.
22932  Usage:
22933
22934 \layout LyX-Code
22935 void func_wparam(int a) wparam
22936
22937 \layout LyX-Code
22938 {
22939
22940 \layout LyX-Code
22941     /* WREG hold the lower part of a */
22942
22943 \layout LyX-Code
22944     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22945  */
22946
22947 \layout LyX-Code
22948 ...
22949
22950 \layout LyX-Code
22951 }
22952
22953 \layout List
22954 \labelwidthstring 00.00.0000
22955 shadowregs
22956 \begin_inset LatexCommand \index{PIC16!shadowregs}
22957
22958 \end_inset
22959
22960  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22961  hardware shadow registers which hold the values of WREG, STATUS and BSR
22962  registers.
22963  This can be done by adding the keyword 
22964 \emph on
22965 shadowregs
22966 \emph default
22967  before the 
22968 \emph on
22969 interrupt
22970 \emph default
22971  keyword in the function's header.
22972
22973 \layout LyX-Code
22974 void isr_shadow(void) shadowregs interrupt 1
22975
22976 \layout LyX-Code
22977 {
22978
22979 \layout LyX-Code
22980 ...
22981
22982 \layout LyX-Code
22983 }
22984
22985 \layout Standard
22986
22987 \emph on
22988 shadowregs
22989 \emph default
22990  instructs the code generator not to store/restore WREG, STATUS, BSR when
22991  entering/exiting the ISR.
22992
22993 \layout Subsection
22994 Function return values
22995
22996 \layout Standard
22997 Return values from functions are placed to the appropriate registers following
22998  a modified Microchip policy optimized for SDCC.
22999  The following table shows these registers:
23000
23001 \layout Standard
23002 \align center
23003 \begin_inset Tabular
23004 <lyxtabular version="3" rows="6" columns="2">
23005 <features>
23006 <column alignment="center" valignment="top" leftline="true" width="0">
23007 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23008 <row topline="true" bottomline="true">
23009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23010 \begin_inset Text
23011
23012 \layout Standard
23013 size
23014
23015 \end_inset
23016 </cell>
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23018 \begin_inset Text
23019
23020 \layout Standard
23021 destination register
23022
23023 \end_inset
23024 </cell>
23025 </row>
23026 <row topline="true">
23027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23028 \begin_inset Text
23029
23030 \layout Standard
23031 8 bits
23032
23033 \end_inset
23034 </cell>
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23036 \begin_inset Text
23037
23038 \layout Standard
23039 WREG
23040
23041 \end_inset
23042 </cell>
23043 </row>
23044 <row topline="true">
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23046 \begin_inset Text
23047
23048 \layout Standard
23049 16 bits
23050
23051 \end_inset
23052 </cell>
23053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23054 \begin_inset Text
23055
23056 \layout Standard
23057 PRODL:WREG
23058
23059 \end_inset
23060 </cell>
23061 </row>
23062 <row topline="true">
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23064 \begin_inset Text
23065
23066 \layout Standard
23067 24 bits
23068
23069 \end_inset
23070 </cell>
23071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23072 \begin_inset Text
23073
23074 \layout Standard
23075 PRODH:PRODL:WREG
23076
23077 \end_inset
23078 </cell>
23079 </row>
23080 <row topline="true">
23081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23082 \begin_inset Text
23083
23084 \layout Standard
23085 32 bits
23086
23087 \end_inset
23088 </cell>
23089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23090 \begin_inset Text
23091
23092 \layout Standard
23093 FSR0L:PRODH:PRODL:WREG
23094
23095 \end_inset
23096 </cell>
23097 </row>
23098 <row topline="true" bottomline="true">
23099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23100 \begin_inset Text
23101
23102 \layout Standard
23103 >32 bits
23104
23105 \end_inset
23106 </cell>
23107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23108 \begin_inset Text
23109
23110 \layout Standard
23111 on stack, FSR0 points to the beginning
23112
23113 \end_inset
23114 </cell>
23115 </row>
23116 </lyxtabular>
23117
23118 \end_inset
23119
23120
23121
23122 \layout Subsection
23123 Interrupts
23124
23125 \layout Standard
23126 An interrupt
23127 \begin_inset LatexCommand \index{PIC16!interrupt}
23128
23129 \end_inset
23130
23131  service routine (ISR) is declared using the 
23132 \emph on
23133 interrupt
23134 \emph default
23135  keyword.
23136
23137 \layout LyX-Code
23138 void isr(void) interrupt 
23139 \emph on
23140 n
23141
23142 \layout LyX-Code
23143 {
23144
23145 \layout LyX-Code
23146 ...
23147
23148 \layout LyX-Code
23149 }
23150
23151 \layout Standard
23152
23153 \emph on
23154 n
23155 \emph default
23156  is the interrupt number, which for PIC18F devices can be:
23157
23158 \layout Standard
23159 \align center
23160 \begin_inset Tabular
23161 <lyxtabular version="3" rows="4" columns="3">
23162 <features>
23163 <column alignment="center" valignment="top" leftline="true" width="0">
23164 <column alignment="center" valignment="top" leftline="true" width="0">
23165 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23166 <row topline="true" bottomline="true">
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23168 \begin_inset Text
23169
23170 \layout Standard
23171
23172 \emph on
23173 n
23174
23175 \end_inset
23176 </cell>
23177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23178 \begin_inset Text
23179
23180 \layout Standard
23181 Interrupt Vector
23182
23183 \end_inset
23184 </cell>
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23186 \begin_inset Text
23187
23188 \layout Standard
23189 Interrupt Vector Address
23190
23191 \end_inset
23192 </cell>
23193 </row>
23194 <row topline="true">
23195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23196 \begin_inset Text
23197
23198 \layout Standard
23199 0
23200
23201 \end_inset
23202 </cell>
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23204 \begin_inset Text
23205
23206 \layout Standard
23207 RESET vector
23208
23209 \end_inset
23210 </cell>
23211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23212 \begin_inset Text
23213
23214 \layout Standard
23215 0x000000
23216
23217 \end_inset
23218 </cell>
23219 </row>
23220 <row topline="true">
23221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23222 \begin_inset Text
23223
23224 \layout Standard
23225
23226 \family roman
23227 \series medium
23228 \shape up
23229 \size normal
23230 \emph off
23231 \bar no
23232 \noun off
23233 \color none
23234 1
23235
23236 \end_inset
23237 </cell>
23238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23239 \begin_inset Text
23240
23241 \layout Standard
23242
23243 \family roman
23244 \series medium
23245 \shape up
23246 \size normal
23247 \emph off
23248 \bar no
23249 \noun off
23250 \color none
23251 HIGH priority interrupts
23252
23253 \end_inset
23254 </cell>
23255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23256 \begin_inset Text
23257
23258 \layout Standard
23259 0x000008
23260
23261 \end_inset
23262 </cell>
23263 </row>
23264 <row topline="true" bottomline="true">
23265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23266 \begin_inset Text
23267
23268 \layout Standard
23269 2
23270
23271 \end_inset
23272 </cell>
23273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23274 \begin_inset Text
23275
23276 \layout Standard
23277 LOW priority interrupts
23278
23279 \end_inset
23280 </cell>
23281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23282 \begin_inset Text
23283
23284 \layout Standard
23285 0x000018
23286
23287 \end_inset
23288 </cell>
23289 </row>
23290 </lyxtabular>
23291
23292 \end_inset
23293
23294
23295
23296 \layout Standard
23297 When generating assembly code for ISR the code generator places a 
23298 \noun on
23299 goto 
23300 \noun default
23301 instruction at the 
23302 \emph on
23303 Interrupt Vector Address
23304 \emph default
23305  which points at the genetated ISR.
23306  This single GOTO instruction is part of an automatically generated 
23307 \emph on
23308 interrupt entry point
23309 \emph default
23310  function.
23311  The actuall ISR code is placed as normally would in the code space.
23312  Upon interrupt request, the GOTO instruction is executed which jumps to
23313  the ISR code.
23314  When declaring interrupt functions as _naked this GOTO instruction is 
23315 \series bold
23316 not
23317 \series default
23318  generated.
23319  The whole interrupt functions is therefore placed at the Interrupt Vector
23320  Address of the specific interrupt.
23321  This is not a problem for the LOW priority interrupts, but it is a problem
23322  for the RESET and the HIGH priority interrupts because code may be written
23323  at the next interrupt´s vector address and cause undeterminate program
23324  behaviour if that interrupt is raised.
23325 \begin_inset Foot
23326 collapsed false
23327
23328 \layout Standard
23329 This is not a problem when
23330
23331 \layout Enumerate
23332 this is a HIGH interrupt ISR and LOW interrupts are 
23333 \emph on
23334 disabled
23335 \emph default
23336  or not used.
23337
23338 \layout Enumerate
23339 when the ISR is small enough not to reach the next interrupt´s vector address.
23340
23341 \end_inset
23342
23343
23344
23345 \layout Standard
23346
23347 \emph on
23348 n
23349 \emph default
23350  is possible to be omitted.
23351  This way a function is generated similar to an ISR, but it is not assigned
23352  to any interrupt.
23353
23354 \layout Standard
23355 When entering an interrupt, currently the PIC16
23356 \begin_inset LatexCommand \index{PIC16}
23357
23358 \end_inset
23359
23360  port automatically saves the following registers:
23361
23362 \layout Itemize
23363 WREG
23364
23365 \layout Itemize
23366 STATUS
23367
23368 \layout Itemize
23369 BSR
23370
23371 \layout Itemize
23372 PROD (PRODL and PRODH)
23373
23374 \layout Itemize
23375 FSR0 (FSR0L and FSR0H)
23376
23377 \layout Standard
23378 These registers are restored upon return from the interrupt routine.
23379 \begin_inset Foot
23380 collapsed false
23381
23382 \layout Standard
23383 NOTE that when the _naked attribute is specified for an interrupt routine,
23384  then NO registers are stored or restored.
23385
23386 \end_inset
23387
23388
23389
23390 \layout Subsection
23391 Generic Pointers
23392
23393 \layout Standard
23394 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
23395  There are 3 types of generic pointers currently implemented data, code
23396  and eeprom pointers.
23397  They are differentiated by the value of the 7th and 6th bits of the upper
23398  byte:
23399
23400 \layout Standard
23401 \align center
23402 \begin_inset Tabular
23403 <lyxtabular version="3" rows="5" columns="5">
23404 <features>
23405 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23406 <column alignment="center" valignment="top" width="0">
23407 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23408 <column alignment="center" valignment="top" width="0">
23409 <column alignment="left" valignment="top" rightline="true" width="0">
23410 <row topline="true" bottomline="true">
23411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23412 \begin_inset Text
23413
23414 \layout Standard
23415 pointer type
23416
23417 \end_inset
23418 </cell>
23419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23420 \begin_inset Text
23421
23422 \layout Standard
23423 7th bit
23424
23425 \end_inset
23426 </cell>
23427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23428 \begin_inset Text
23429
23430 \layout Standard
23431 6th bit
23432
23433 \end_inset
23434 </cell>
23435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23436 \begin_inset Text
23437
23438 \layout Standard
23439 rest of the pointer
23440
23441 \end_inset
23442 </cell>
23443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23444 \begin_inset Text
23445
23446 \layout Standard
23447 description
23448
23449 \end_inset
23450 </cell>
23451 </row>
23452 <row topline="true" bottomline="true">
23453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23454 \begin_inset Text
23455
23456 \layout Standard
23457 data 
23458
23459 \end_inset
23460 </cell>
23461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23462 \begin_inset Text
23463
23464 \layout Standard
23465 1
23466
23467 \end_inset
23468 </cell>
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23470 \begin_inset Text
23471
23472 \layout Standard
23473 0
23474
23475 \end_inset
23476 </cell>
23477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23478 \begin_inset Text
23479
23480 \layout Standard
23481
23482 \family typewriter
23483 \shape slanted
23484 \emph on
23485 uuuuuu uuuuxxxx xxxxxxxx
23486
23487 \end_inset
23488 </cell>
23489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23490 \begin_inset Text
23491
23492 \layout Standard
23493 a 12-bit data pointer in data RAM memory
23494
23495 \end_inset
23496 </cell>
23497 </row>
23498 <row bottomline="true">
23499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23500 \begin_inset Text
23501
23502 \layout Standard
23503 code
23504
23505 \end_inset
23506 </cell>
23507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23508 \begin_inset Text
23509
23510 \layout Standard
23511 0
23512
23513 \end_inset
23514 </cell>
23515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23516 \begin_inset Text
23517
23518 \layout Standard
23519 0
23520
23521 \end_inset
23522 </cell>
23523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23524 \begin_inset Text
23525
23526 \layout Standard
23527
23528 \family typewriter
23529 \shape slanted
23530 \emph on
23531 uxxxxx xxxxxxxx xxxxxxxx
23532
23533 \end_inset
23534 </cell>
23535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23536 \begin_inset Text
23537
23538 \layout Standard
23539 a 21-bit code pointer in FLASH memory
23540
23541 \end_inset
23542 </cell>
23543 </row>
23544 <row bottomline="true">
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23546 \begin_inset Text
23547
23548 \layout Standard
23549 eeprom
23550
23551 \end_inset
23552 </cell>
23553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23554 \begin_inset Text
23555
23556 \layout Standard
23557 0
23558
23559 \end_inset
23560 </cell>
23561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23562 \begin_inset Text
23563
23564 \layout Standard
23565 1
23566
23567 \end_inset
23568 </cell>
23569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23570 \begin_inset Text
23571
23572 \layout Standard
23573
23574 \family typewriter
23575 \shape slanted
23576 \emph on
23577 uuuuuu uuuuuuxx xxxxxxxx
23578
23579 \end_inset
23580 </cell>
23581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23582 \begin_inset Text
23583
23584 \layout Standard
23585 a 10-bit eeprom pointer in EEPROM memory
23586
23587 \end_inset
23588 </cell>
23589 </row>
23590 <row bottomline="true">
23591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23592 \begin_inset Text
23593
23594 \layout Standard
23595 (unimplemented)
23596
23597 \end_inset
23598 </cell>
23599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23600 \begin_inset Text
23601
23602 \layout Standard
23603 1
23604
23605 \end_inset
23606 </cell>
23607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23608 \begin_inset Text
23609
23610 \layout Standard
23611 1
23612
23613 \end_inset
23614 </cell>
23615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23616 \begin_inset Text
23617
23618 \layout Standard
23619
23620 \family typewriter
23621 \shape slanted
23622 \emph on
23623 xxxxxx xxxxxxxx xxxxxxxx
23624
23625 \end_inset
23626 </cell>
23627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23628 \begin_inset Text
23629
23630 \layout Standard
23631 unimplemented pointer type
23632
23633 \end_inset
23634 </cell>
23635 </row>
23636 </lyxtabular>
23637
23638 \end_inset
23639
23640
23641
23642 \layout Standard
23643 Generic pointer are read and written with a set of library functions which
23644  read/write 1, 2, 3, 4 bytes.
23645
23646 \layout Subsection
23647 PIC16 C Libraries
23648
23649 \layout Subsubsection
23650 Standard I/O Streams
23651
23652 \layout Standard
23653 In the 
23654 \emph on
23655 stdio.h
23656 \emph default
23657  the type FILE is defined as:
23658
23659 \layout LyX-Code
23660 typedef char * FILE;
23661
23662 \layout Standard
23663 This type is the stream type implemented I/O in the PIC18F devices.
23664  Also the standard input and output streams are declared in stdio.h:
23665
23666 \layout LyX-Code
23667 extern FILE * stdin;
23668
23669 \layout LyX-Code
23670 extern FILE * stdout;
23671
23672 \layout Standard
23673 The FILE type is actually a generic pointer which defines one more type
23674  of generic pointers, the 
23675 \emph on
23676 stream 
23677 \emph default
23678 pointer.
23679  This new type has the format:
23680
23681 \layout Standard
23682 \align center
23683 \begin_inset Tabular
23684 <lyxtabular version="3" rows="2" columns="7">
23685 <features>
23686 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23687 <column alignment="center" valignment="top" width="0">
23688 <column alignment="center" valignment="top" leftline="true" width="0">
23689 <column alignment="center" valignment="top" leftline="true" width="0">
23690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23691 <column alignment="center" valignment="top" width="0">
23692 <column alignment="left" valignment="top" rightline="true" width="0">
23693 <row topline="true" bottomline="true">
23694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23695 \begin_inset Text
23696
23697 \layout Standard
23698 pointer type
23699
23700 \end_inset
23701 </cell>
23702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23703 \begin_inset Text
23704
23705 \layout Standard
23706 <7:6>
23707
23708 \end_inset
23709 </cell>
23710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23711 \begin_inset Text
23712
23713 \layout Standard
23714 <5>
23715
23716 \end_inset
23717 </cell>
23718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23719 \begin_inset Text
23720
23721 \layout Standard
23722 <4>
23723
23724 \end_inset
23725 </cell>
23726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23727 \begin_inset Text
23728
23729 \layout Standard
23730 <3:0>
23731
23732 \end_inset
23733 </cell>
23734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23735 \begin_inset Text
23736
23737 \layout Standard
23738 rest of the pointer
23739
23740 \end_inset
23741 </cell>
23742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23743 \begin_inset Text
23744
23745 \layout Standard
23746 descrption
23747
23748 \end_inset
23749 </cell>
23750 </row>
23751 <row topline="true" bottomline="true">
23752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23753 \begin_inset Text
23754
23755 \layout Standard
23756 stream
23757
23758 \end_inset
23759 </cell>
23760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23761 \begin_inset Text
23762
23763 \layout Standard
23764 00
23765
23766 \end_inset
23767 </cell>
23768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23769 \begin_inset Text
23770
23771 \layout Standard
23772 1
23773
23774 \end_inset
23775 </cell>
23776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23777 \begin_inset Text
23778
23779 \layout Standard
23780 0
23781
23782 \end_inset
23783 </cell>
23784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23785 \begin_inset Text
23786
23787 \layout Standard
23788 nnnn
23789
23790 \end_inset
23791 </cell>
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23793 \begin_inset Text
23794
23795 \layout Standard
23796
23797 \family typewriter
23798 \shape slanted
23799 \emph on
23800 uuuuuuuu uuuuuuuu
23801
23802 \end_inset
23803 </cell>
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23805 \begin_inset Text
23806
23807 \layout Standard
23808 upper byte high nubble is 0x2n, the rest are zeroes
23809
23810 \end_inset
23811 </cell>
23812 </row>
23813 </lyxtabular>
23814
23815 \end_inset
23816
23817
23818
23819 \layout Standard
23820 Currently implemented there are 3 types of streams defined:
23821
23822 \layout Standard
23823 \align center
23824 \begin_inset Tabular
23825 <lyxtabular version="3" rows="4" columns="4">
23826 <features>
23827 <column alignment="center" valignment="top" leftline="true" width="0">
23828 <column alignment="center" valignment="top" leftline="true" width="0">
23829 <column alignment="center" valignment="top" leftline="true" width="0">
23830 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23831 <row topline="true" bottomline="true">
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23833 \begin_inset Text
23834
23835 \layout Standard
23836 stream type
23837
23838 \end_inset
23839 </cell>
23840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23841 \begin_inset Text
23842
23843 \layout Standard
23844 value
23845
23846 \end_inset
23847 </cell>
23848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23849 \begin_inset Text
23850
23851 \layout Standard
23852 module
23853
23854 \end_inset
23855 </cell>
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23857 \begin_inset Text
23858
23859 \layout Standard
23860 description
23861
23862 \end_inset
23863 </cell>
23864 </row>
23865 <row topline="true">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23867 \begin_inset Text
23868
23869 \layout Standard
23870 STREAM_USART
23871
23872 \end_inset
23873 </cell>
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23875 \begin_inset Text
23876
23877 \layout Standard
23878
23879 \family typewriter
23880 0x200000UL
23881
23882 \end_inset
23883 </cell>
23884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23885 \begin_inset Text
23886
23887 \layout Standard
23888 USART
23889
23890 \end_inset
23891 </cell>
23892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23893 \begin_inset Text
23894
23895 \layout Standard
23896 Writes/Reads characters via the USART peripheral
23897
23898 \end_inset
23899 </cell>
23900 </row>
23901 <row topline="true">
23902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23903 \begin_inset Text
23904
23905 \layout Standard
23906 STREAM_MSSP
23907
23908 \end_inset
23909 </cell>
23910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23911 \begin_inset Text
23912
23913 \layout Standard
23914
23915 \family typewriter
23916 0x210000UL
23917
23918 \end_inset
23919 </cell>
23920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23921 \begin_inset Text
23922
23923 \layout Standard
23924 MSSP
23925
23926 \end_inset
23927 </cell>
23928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23929 \begin_inset Text
23930
23931 \layout Standard
23932 Writes/Reads characters via the MSSP peripheral
23933
23934 \end_inset
23935 </cell>
23936 </row>
23937 <row topline="true" bottomline="true">
23938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23939 \begin_inset Text
23940
23941 \layout Standard
23942 STREAM_USER
23943
23944 \end_inset
23945 </cell>
23946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23947 \begin_inset Text
23948
23949 \layout Standard
23950
23951 \family typewriter
23952 0x2f0000UL
23953
23954 \end_inset
23955 </cell>
23956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23957 \begin_inset Text
23958
23959 \layout Standard
23960 (none)
23961
23962 \end_inset
23963 </cell>
23964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23965 \begin_inset Text
23966
23967 \layout Standard
23968 Writes/Reads characters via used defined functions
23969
23970 \end_inset
23971 </cell>
23972 </row>
23973 </lyxtabular>
23974
23975 \end_inset
23976
23977
23978
23979 \layout Standard
23980 The stream identifiers are declared as macros in the stdio.h header.
23981
23982 \layout Standard
23983 In the libc library there exist the functions that are used to write to
23984  each of the above streams.
23985  These are
23986
23987 \layout List
23988 \labelwidthstring 00.00.0000
23989 _
23990 \begin_inset ERT
23991 status Collapsed
23992
23993 \layout Standard
23994
23995
23996 \backslash
23997 /
23998
23999 \end_inset
24000
24001 _stream_usart_putchar writes a character at the USART stream
24002
24003 \layout List
24004 \labelwidthstring 00.00.0000
24005 _
24006 \begin_inset ERT
24007 status Collapsed
24008
24009 \layout Standard
24010
24011
24012 \backslash
24013 /
24014
24015 \end_inset
24016
24017 _stream_mssp_putchar writes a character at the MSSP stream
24018
24019 \layout List
24020 \labelwidthstring 00.00.0000
24021 putchar dummy function.
24022  This writes a character to a user specified manner.
24023
24024 \layout Standard
24025 In order to increase performance 
24026 \emph on
24027 putchar 
24028 \emph default
24029 is declared in stdio.h as having its parameter in WREG (it has the wparam
24030  keyword).
24031  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24032  in a user-friendly way.
24033  
24034 \emph on
24035 arg
24036 \emph default
24037  is the name of the variable that holds the character to print.
24038  An example follows:
24039
24040 \layout LyX-Code
24041 #include <pic18fregs.h>
24042 \newline
24043 #include <stdio.h>
24044 \newline
24045
24046 \newline
24047 PUTCHAR( c )
24048
24049 \layout LyX-Code
24050 {
24051
24052 \layout LyX-Code
24053     PORTA = c;    /* dump character c to PORTA */
24054
24055 \layout LyX-Code
24056
24057 \newline
24058
24059 \newline
24060 void main(void)
24061
24062 \layout LyX-Code
24063 {
24064
24065 \layout LyX-Code
24066     stdout = STREAM_USER;    /* this is not necessary, since stdout points
24067
24068 \layout LyX-Code
24069                               * by default to STREAM_USER */
24070
24071 \layout LyX-Code
24072     printf (¨This is a printf test
24073 \backslash
24074 n¨);
24075
24076 \layout LyX-Code
24077 }
24078
24079 \layout LyX-Code
24080
24081
24082 \layout Subsubsection
24083 Printing functions
24084
24085 \layout Standard
24086 PIC16 contains an implementation of the printf-family of functions.
24087  There exist the following functions:
24088
24089 \layout LyX-Code
24090 extern unsigned int sprintf(char *buf, char *fmt, ...);
24091
24092 \layout LyX-Code
24093 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
24094
24095 \layout LyX-Code
24096
24097
24098 \layout LyX-Code
24099 extern unsigned int printf(char *fmt, ...);
24100
24101 \layout LyX-Code
24102 extern unsigned int vprintf(char *fmt, va_lista ap);
24103
24104 \layout LyX-Code
24105
24106
24107 \layout LyX-Code
24108 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
24109
24110 \layout LyX-Code
24111 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
24112
24113 \layout Standard
24114 For sprintf and vsprintf 
24115 \emph on
24116 buf 
24117 \emph default
24118 should normally be a data pointer where the resulting string will be placed.
24119  No range checking is done so the user should allocate the necessery buffer.
24120  For fprintf and vfprintf 
24121 \emph on
24122 fp
24123 \emph default
24124  should be a stream pointer (i.e.
24125  stdout, STREAM_MSSP, etc...).
24126
24127 \layout Subsubsection
24128 Signals
24129
24130 \layout Standard
24131 The PIC18F family of microcontrollers supports a number of interrupt sources.
24132  A list of these interrupts is shown in the following table:
24133
24134 \layout Standard
24135 \align center
24136 \begin_inset Tabular
24137 <lyxtabular version="3" rows="11" columns="4">
24138 <features>
24139 <column alignment="left" valignment="top" leftline="true" width="0">
24140 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24141 <column alignment="left" valignment="top" leftline="true" width="0">
24142 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24143 <row topline="true" bottomline="true">
24144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24145 \begin_inset Text
24146
24147 \layout Standard
24148 signal name
24149
24150 \end_inset
24151 </cell>
24152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24153 \begin_inset Text
24154
24155 \layout Standard
24156 description
24157
24158 \end_inset
24159 </cell>
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24161 \begin_inset Text
24162
24163 \layout Standard
24164 signal name
24165
24166 \end_inset
24167 </cell>
24168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24169 \begin_inset Text
24170
24171 \layout Standard
24172 descritpion
24173
24174 \end_inset
24175 </cell>
24176 </row>
24177 <row topline="true">
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24179 \begin_inset Text
24180
24181 \layout Standard
24182 SIG_RB
24183
24184 \end_inset
24185 </cell>
24186 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24187 \begin_inset Text
24188
24189 \layout Standard
24190 PORTB change interrupt
24191
24192 \end_inset
24193 </cell>
24194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24195 \begin_inset Text
24196
24197 \layout Standard
24198 SIG_EE
24199
24200 \end_inset
24201 </cell>
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24203 \begin_inset Text
24204
24205 \layout Standard
24206 EEPROM/FLASH write complete interrupt
24207
24208 \end_inset
24209 </cell>
24210 </row>
24211 <row topline="true">
24212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24213 \begin_inset Text
24214
24215 \layout Standard
24216 SIG_INT0
24217
24218 \end_inset
24219 </cell>
24220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24221 \begin_inset Text
24222
24223 \layout Standard
24224 INT0 external interrupt
24225
24226 \end_inset
24227 </cell>
24228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24229 \begin_inset Text
24230
24231 \layout Standard
24232 SIG_BCOL
24233
24234 \end_inset
24235 </cell>
24236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24237 \begin_inset Text
24238
24239 \layout Standard
24240 Bus collision interrupt
24241
24242 \end_inset
24243 </cell>
24244 </row>
24245 <row topline="true">
24246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24247 \begin_inset Text
24248
24249 \layout Standard
24250 SIG_INT1
24251
24252 \end_inset
24253 </cell>
24254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24255 \begin_inset Text
24256
24257 \layout Standard
24258 INT1 external interrupt
24259
24260 \end_inset
24261 </cell>
24262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24263 \begin_inset Text
24264
24265 \layout Standard
24266 SIG_LVD
24267
24268 \end_inset
24269 </cell>
24270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24271 \begin_inset Text
24272
24273 \layout Standard
24274 Low voltage detect interrupt
24275
24276 \end_inset
24277 </cell>
24278 </row>
24279 <row topline="true">
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24281 \begin_inset Text
24282
24283 \layout Standard
24284 SIG_INT2
24285
24286 \end_inset
24287 </cell>
24288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24289 \begin_inset Text
24290
24291 \layout Standard
24292 INT2 external interrupt
24293
24294 \end_inset
24295 </cell>
24296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24297 \begin_inset Text
24298
24299 \layout Standard
24300 SIG_PSP
24301
24302 \end_inset
24303 </cell>
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 \begin_inset Text
24306
24307 \layout Standard
24308 Parallel slave port interrupt
24309
24310 \end_inset
24311 </cell>
24312 </row>
24313 <row topline="true">
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24315 \begin_inset Text
24316
24317 \layout Standard
24318 SIG_CCP1
24319
24320 \end_inset
24321 </cell>
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24323 \begin_inset Text
24324
24325 \layout Standard
24326 CCP1 module interrupt
24327
24328 \end_inset
24329 </cell>
24330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24331 \begin_inset Text
24332
24333 \layout Standard
24334 SIG_AD
24335
24336 \end_inset
24337 </cell>
24338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24339 \begin_inset Text
24340
24341 \layout Standard
24342 AD convertion complete interrupt
24343
24344 \end_inset
24345 </cell>
24346 </row>
24347 <row topline="true">
24348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24349 \begin_inset Text
24350
24351 \layout Standard
24352 SIG_CCP2
24353
24354 \end_inset
24355 </cell>
24356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24357 \begin_inset Text
24358
24359 \layout Standard
24360 CCP2 module interrupt
24361
24362 \end_inset
24363 </cell>
24364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24365 \begin_inset Text
24366
24367 \layout Standard
24368 SIG_RC
24369
24370 \end_inset
24371 </cell>
24372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24373 \begin_inset Text
24374
24375 \layout Standard
24376 USART receive interrupt
24377
24378 \end_inset
24379 </cell>
24380 </row>
24381 <row topline="true">
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24383 \begin_inset Text
24384
24385 \layout Standard
24386 SIG_TMR0
24387
24388 \end_inset
24389 </cell>
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24391 \begin_inset Text
24392
24393 \layout Standard
24394 TMR0 overflow interrupt
24395
24396 \end_inset
24397 </cell>
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24399 \begin_inset Text
24400
24401 \layout Standard
24402 SIG_TX
24403
24404 \end_inset
24405 </cell>
24406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24407 \begin_inset Text
24408
24409 \layout Standard
24410 USART transmit interrupt
24411
24412 \end_inset
24413 </cell>
24414 </row>
24415 <row topline="true">
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24417 \begin_inset Text
24418
24419 \layout Standard
24420 SIG_TMR1
24421
24422 \end_inset
24423 </cell>
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24425 \begin_inset Text
24426
24427 \layout Standard
24428 TMR1 overflow interrupt
24429
24430 \end_inset
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \layout Standard
24436 SIG_MSSP
24437
24438 \end_inset
24439 </cell>
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24441 \begin_inset Text
24442
24443 \layout Standard
24444 SSP receive/transmit interrupt
24445
24446 \end_inset
24447 </cell>
24448 </row>
24449 <row topline="true">
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24451 \begin_inset Text
24452
24453 \layout Standard
24454 SIG_TMR2
24455
24456 \end_inset
24457 </cell>
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24459 \begin_inset Text
24460
24461 \layout Standard
24462 TMR2 matches PR2 interrupt
24463
24464 \end_inset
24465 </cell>
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24467 \begin_inset Text
24468
24469 \layout Standard
24470
24471
24472 \end_inset
24473 </cell>
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24475 \begin_inset Text
24476
24477 \layout Standard
24478
24479
24480 \end_inset
24481 </cell>
24482 </row>
24483 <row topline="true" bottomline="true">
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24485 \begin_inset Text
24486
24487 \layout Standard
24488 SIG_TMR3
24489
24490 \end_inset
24491 </cell>
24492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24493 \begin_inset Text
24494
24495 \layout Standard
24496 TMR3 overflow interrupt
24497
24498 \end_inset
24499 </cell>
24500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24501 \begin_inset Text
24502
24503 \layout Standard
24504
24505
24506 \end_inset
24507 </cell>
24508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24509 \begin_inset Text
24510
24511 \layout Standard
24512
24513
24514 \end_inset
24515 </cell>
24516 </row>
24517 </lyxtabular>
24518
24519 \end_inset
24520
24521
24522
24523 \layout Standard
24524 The prototypes for these names are defined in the header file 
24525 \emph on
24526 signal.h
24527 \emph default
24528  .
24529
24530 \layout Standard
24531 In order to simplify signal handling, a number of macros is provided:
24532
24533 \layout List
24534 \labelwidthstring 00.00.0000
24535 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
24536  high priority interrupts.
24537  
24538 \emph on
24539 name
24540 \emph default
24541  is the function name to use.
24542
24543 \layout List
24544 \labelwidthstring 00.00.0000
24545 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
24546  low priority interrupt.
24547  
24548 \emph on
24549 name
24550 \emph default
24551  is the function name to use.
24552
24553 \layout List
24554 \labelwidthstring 00.00.0000
24555 DEF_HANDLER(sig,handler) define a handler for signal 
24556 \emph on
24557 sig.
24558
24559 \layout List
24560 \labelwidthstring 00.00.0000
24561 END_DEF end the declaration of the dispatch table.
24562
24563 \layout Standard
24564 Additionally there are two more macros to simplify the declaration of the
24565  signal handler:
24566
24567 \layout List
24568 \labelwidthstring 00.00.0000
24569
24570 \series medium
24571 SIGHANDLER(handler) 
24572 \series default
24573 this declares the function prototype for the 
24574 \emph on
24575 handler
24576 \emph default
24577  function.
24578
24579 \layout List
24580 \labelwidthstring 00.00.0000
24581 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
24582
24583 \layout Standard
24584 An example of using the macros above is shown below:
24585
24586 \layout LyX-Code
24587 #include <pic18fregs.h>
24588
24589 \layout LyX-Code
24590 #include <signal.h>
24591 \newline
24592
24593 \newline
24594 DEF_INTHIGH(high_int)
24595
24596 \layout LyX-Code
24597 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
24598
24599 \layout LyX-Code
24600 DEF_HANDLER(SIG_BCOL, _bcol_handler)
24601
24602 \layout LyX-Code
24603 END_DEF
24604 \newline
24605
24606 \newline
24607 SIGHANDLER(_tmr0_handler)
24608
24609 \layout LyX-Code
24610 {
24611
24612 \layout LyX-Code
24613   /* action to be taken when timer 0 overflows */
24614
24615 \layout LyX-Code
24616 }
24617 \newline
24618
24619 \newline
24620 SIGHANDLERNAKED(_bcol_handler)
24621
24622 \layout LyX-Code
24623 {
24624
24625 \layout LyX-Code
24626   _asm
24627
24628 \layout LyX-Code
24629     /* action to be taken when bus collision occurs */
24630
24631 \layout LyX-Code
24632     retfie
24633
24634 \layout LyX-Code
24635  _endasm;
24636
24637 \layout LyX-Code
24638 }
24639
24640 \layout Standard
24641
24642 \series bold
24643 NOTES:
24644 \series default
24645  Special care should be taken when using the above scheme:
24646
24647 \layout Itemize
24648 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
24649
24650 \layout Itemize
24651 when declaring SIGHANDLERNAKED handler never forget to use 
24652 \emph on
24653 retfie
24654 \emph default
24655  for proper returning.
24656
24657 \layout Subsection
24658 PIC16 Port -- Tips
24659
24660 \layout Standard
24661 Here you can find some general tips for compiling programs with SDCC/pic16.
24662
24663 \layout Subsubsection
24664 Stack size
24665
24666 \layout Standard
24667 The default stack
24668 \begin_inset LatexCommand \index{PIC16!stack}
24669
24670 \end_inset
24671
24672  size (that is 64 bytes) probably is enough for many programs.
24673  One must take care that when there are many levels of function nesting,
24674  or there is excessive usage of stack, its size should be extended.
24675  An example of such a case is the printf/sprintf family of functions.
24676  If you encounter problems like not being able to print integers, then you
24677  need to set the stack size around the maximum (256 for small stack model).
24678  The following diagram shows what happens when calling printf to print an
24679  integer:
24680
24681 \layout LyX-Code
24682 printf () --> ltoa () --> ultoa () --> divschar ()
24683
24684 \layout Standard
24685 It is should be understood that stack is easily consumed when calling complicate
24686 d functions.
24687  Using command line arguments like -
24688 \begin_inset ERT
24689 status Collapsed
24690
24691 \layout Standard
24692
24693
24694 \backslash
24695 /
24696
24697 \end_inset
24698
24699 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24700  stack frames.
24701  Other ways to reduce stack usage may exist.
24702
24703 \layout Subsection
24704 Known bugs
24705
24706 \layout Standard
24707 The PIC16 Port currently does not pass SDCC's regression test
24708 \begin_inset LatexCommand \index{Regression test (PIC16)}
24709
24710 \end_inset
24711
24712  suite (see section 
24713 \begin_inset LatexCommand \ref{sec:Quality-control}
24714
24715 \end_inset
24716
24717 ) and thus the snapshot build regression tests for the PIC16 target are
24718  currently disabled for all hosts
24719 \emph on
24720 .
24721
24722 \layout Chapter
24723 Debugging
24724
24725 \layout Standard
24726 There are several approaches to debugging your code.
24727  This chapter is meant to show your options and to give detail on some of
24728  them:
24729 \newline
24730
24731 \newline
24732 When writing your code:
24733
24734 \layout Itemize
24735 write your code with debugging in mind (avoid duplicating code, put conceptually
24736  similar variables into structs, use structured code, have strategic points
24737  within your code where all variables are consistent, ...)
24738
24739 \layout Itemize
24740 run a syntax-checking tool like splint
24741 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24742
24743 \end_inset
24744
24745
24746 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24747
24748 \end_inset
24749
24750  (see -
24751 \begin_inset ERT
24752 status Collapsed
24753
24754 \layout Standard
24755
24756
24757 \backslash
24758 /
24759
24760 \end_inset
24761
24762 -more-pedantic 
24763 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24764
24765 \end_inset
24766
24767 ) over the code.
24768
24769 \layout Itemize
24770 for the high level code use a C-compiler (like f.e.
24771  GCC) to compile run and debug the code on your host.
24772  See (see -
24773 \begin_inset ERT
24774 status Collapsed
24775
24776 \layout Standard
24777
24778
24779 \backslash
24780 /
24781
24782 \end_inset
24783
24784 -more-pedantic 
24785 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24786
24787 \end_inset
24788
24789  ) on howto handle syntax extensions like __xdata, __at(), ...
24790  
24791
24792 \layout Itemize
24793 use another C-compiler to compile code for your target.
24794  Always an option but not recommended:) And not very likely to help you.
24795  If you seriously consider walking this path you should at least occasionally
24796  check portability of your code.
24797  Most commercial compiler vendors will offer an evaluation version so you
24798  can test compile your code or snippets of your code.
24799
24800 \layout Standard
24801 Debugging on a simulator:
24802
24803 \layout Itemize
24804 there is a separate section about SDCDB (section 
24805 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24806
24807 \end_inset
24808
24809 ) below.
24810
24811 \layout Itemize
24812 or (8051 specific) use a freeware/commercial simulator which interfaces
24813  to the AOMF
24814 \begin_inset LatexCommand \index{AOMF, AOMF51}
24815
24816 \end_inset
24817
24818  file (see 
24819 \begin_inset LatexCommand \ref{OMF file}
24820
24821 \end_inset
24822
24823 ) optionally generated by SDCC.
24824
24825 \layout Standard
24826 Debugging On-target: 
24827
24828 \layout Itemize
24829 use a MCU port pin to serially output debug data to the RS232 port of your
24830  host.
24831  You'll probably want some level shifting device typically involving a MAX232
24832  or similar IC.
24833  If the hardware serial port of the MCU is not available search for 'Software
24834  UART' in your favourite search machine.
24835
24836 \layout Itemize
24837 use an on-target monitor.
24838  In this context a monitor is a small program which usually accepts commands
24839  via a serial line and allows to set program counter, to single step through
24840  a program and read/write memory locations.
24841  For the 8051 good examples of monitors are paulmon and cmon51 (see section
24842  
24843 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24844
24845 \end_inset
24846
24847 ).
24848
24849 \layout Itemize
24850 toggle MCU port pins at strategic points within your code and use an oscilloscop
24851 e.
24852  A 
24853 \emph on
24854 digital oscilloscope
24855 \emph default
24856
24857 \begin_inset LatexCommand \index{Oscilloscope}
24858
24859 \end_inset
24860
24861  with deep trace memory is really helpful especially if you have to debug
24862  a realtime application.
24863  If you need to monitor more pins than your oscilloscope provides you can
24864  sometimes get away with a small R-2R network.
24865  On a single channel oscilloscope you could f.e.
24866  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24867 k
24868 \begin_inset Formula $\Omega$
24869 \end_inset
24870
24871  resistor and the other one by a 5\SpecialChar ~
24872 k
24873 \begin_inset Formula $\Omega$
24874 \end_inset
24875
24876  resistor to the oscilloscope probe (check output drive capability of the
24877  pins you want to monitor).
24878  If you need to monitor many more pins a 
24879 \emph on
24880 logic analyzer
24881 \emph default
24882  will be handy.
24883
24884 \layout Itemize
24885 use an ICE (
24886 \emph on
24887 i
24888 \emph default
24889
24890 \emph on
24891 c
24892 \emph default
24893 ircuit 
24894 \emph on
24895 e
24896 \emph default
24897 mulator
24898 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24899
24900 \end_inset
24901
24902 ).
24903  Usually very expensive.
24904  And very nice to have too.
24905  And usually locks you (for years...) to the devices the ICE can emulate.
24906  
24907
24908 \layout Itemize
24909 use a remote debugger.
24910  In most 8-bit systems the symbol information is not available on the target,
24911  and a complete debugger is too bulky for the target system.
24912  Therefore usually a debugger on the host system connects to an on-target
24913  debugging stub which accepts only primitive commands.
24914  
24915 \newline
24916 Terms to enter into your favourite search engine could be 'remote debugging',
24917  'gdb stub' or 'inferior debugger'.
24918  (is there one?)
24919
24920 \layout Itemize
24921 use an on target hardware debugger.
24922  Some of the more modern MCUs include hardware support for setting break
24923  points and monitoring/changing variables by using dedicated hardware pins.
24924  This facility doesn't require additional code to run on the target and
24925  
24926 \emph on
24927 usually
24928 \emph default
24929  doesn't affect runtime behaviour until a breakpoint is hit.
24930  For the mcs51 most hardware debuggers use the AOMF
24931 \begin_inset LatexCommand \index{AOMF, AOMF51}
24932
24933 \end_inset
24934
24935  file (see 
24936 \begin_inset LatexCommand \ref{OMF file}
24937
24938 \end_inset
24939
24940 ) as input file.
24941  
24942
24943 \layout Standard
24944 Last not least:
24945
24946 \layout Itemize
24947 if you are not familiar with any of the following terms you're likely to
24948  run into problems rather sooner than later: 
24949 \emph on
24950 volatile
24951 \emph default
24952
24953 \emph on
24954 atomic
24955 \emph default
24956
24957 \emph on
24958 memory map
24959 \emph default
24960
24961 \emph on
24962 overlay
24963 \emph default
24964 .
24965  As an embedded programmer you 
24966 \emph on
24967 have
24968 \emph default
24969  to know them so why not look them up 
24970 \emph on
24971 before
24972 \emph default
24973  you have problems?)
24974
24975 \layout Itemize
24976 tell someone else about your problem (actually this is a surprisingly effective
24977  means to hunt down the bug even if the listener is not familiar with your
24978  environment).
24979  As 'failure to communicate' is probably one of the job-induced deformations
24980  of an embedded programmer this is highly encouraged.
24981
24982 \layout Section
24983 Debugging with SDCDB
24984 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24985
24986 \end_inset
24987
24988
24989 \begin_inset LatexCommand \index{SDCDB (debugger)}
24990
24991 \end_inset
24992
24993  
24994
24995 \layout Standard
24996 SDCC is distributed with a source level debugger
24997 \begin_inset LatexCommand \index{Debugger}
24998
24999 \end_inset
25000
25001 .
25002  The debugger uses a command line interface, the command repertoire of the
25003  debugger has been kept as close to gdb
25004 \begin_inset LatexCommand \index{gdb}
25005
25006 \end_inset
25007
25008  (the GNU debugger) as possible.
25009  The configuration and build process is part of the standard compiler installati
25010 on, which also builds and installs the debugger in the target directory
25011  specified during configuration.
25012  The debugger allows you debug BOTH at the C source and at the ASM source
25013  level.
25014
25015 \layout Subsection
25016 Compiling for Debugging
25017
25018 \layout Standard
25019 The -
25020 \begin_inset ERT
25021 status Collapsed
25022
25023 \layout Standard
25024
25025
25026 \backslash
25027 /
25028
25029 \end_inset
25030
25031 -debug
25032 \begin_inset LatexCommand \index{-\/-debug}
25033
25034 \end_inset
25035
25036  option must be specified for all files for which debug information is to
25037  be generated.
25038  The compiler generates a .adb file for each of these files.
25039  The linker creates the .cdb
25040 \begin_inset LatexCommand \index{<file>.cdb}
25041
25042 \end_inset
25043
25044  file from the .adb
25045 \begin_inset LatexCommand \index{<file>.adb}
25046
25047 \end_inset
25048
25049  files and the address information.
25050  This .cdb is used by the debugger.
25051
25052 \layout Subsection
25053 How the Debugger Works
25054
25055 \layout Standard
25056 When the -
25057 \begin_inset ERT
25058 status Collapsed
25059
25060 \layout Standard
25061
25062
25063 \backslash
25064 /
25065
25066 \end_inset
25067
25068 -debug option is specified the compiler generates extra symbol information
25069  some of which are put into the assembler source and some are put into the
25070  .adb file.
25071  Then the linker creates the .cdb file from the individual .adb files with
25072  the address information for the symbols.
25073  The debugger reads the symbolic information generated by the compiler &
25074  the address information generated by the linker.
25075  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
25076  execution is controlled by the debugger.
25077  When a command is issued for the debugger, it translates it into appropriate
25078  commands for the simulator.
25079  (Currently SDCDM only connects to the simulator but 
25080 \emph on
25081 newcdb
25082 \emph default
25083  at 
25084 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
25085
25086 \end_inset
25087
25088  is an effort to connect directly to the hardware.) 
25089
25090 \layout Subsection
25091 Starting the Debugger SDCDB
25092
25093 \layout Standard
25094 The debugger can be started using the following command line.
25095  (Assume the file you are debugging has the file name foo).
25096 \newline
25097
25098 \newline
25099
25100 \family sans
25101 \series bold
25102 sdcdb foo
25103 \newline
25104
25105 \family default
25106 \series default
25107
25108 \newline
25109 The debugger will look for the following files.
25110
25111 \layout Itemize
25112 foo.c - the source file.
25113
25114 \layout Itemize
25115 foo.cdb - the debugger symbol information file.
25116
25117 \layout Itemize
25118 foo.ihx - the Intel hex format
25119 \begin_inset LatexCommand \index{Intel hex format}
25120
25121 \end_inset
25122
25123  object file.
25124
25125 \layout Subsection
25126 SDCDB Command Line Options
25127
25128 \layout Itemize
25129 -
25130 \begin_inset ERT
25131 status Collapsed
25132
25133 \layout Standard
25134
25135
25136 \backslash
25137 /
25138
25139 \end_inset
25140
25141 -directory=<source file directory> this option can used to specify the directory
25142  search list.
25143  The debugger will look into the directory list specified for source, cdb
25144  & ihx files.
25145  The items in the directory list must be separated by ':', e.g.
25146  if the source files can be in the directories /home/src1 and /home/src2,
25147  the -
25148 \begin_inset ERT
25149 status Collapsed
25150
25151 \layout Standard
25152
25153
25154 \backslash
25155 /
25156
25157 \end_inset
25158
25159 -directory option should be -
25160 \begin_inset ERT
25161 status Collapsed
25162
25163 \layout Standard
25164
25165
25166 \backslash
25167 /
25168
25169 \end_inset
25170
25171 -directory=/home/src1:/home/src2.
25172  Note there can be no spaces in the option.
25173  
25174
25175 \layout Itemize
25176 -cd <directory> - change to the <directory>.
25177
25178 \layout Itemize
25179 -fullname - used by GUI front ends.
25180
25181 \layout Itemize
25182 -cpu <cpu-type> - this argument is passed to the simulator please see the
25183  simulator docs for details.
25184
25185 \layout Itemize
25186 -X <Clock frequency > this options is passed to the simulator please see
25187  the simulator docs for details.
25188
25189 \layout Itemize
25190 -s <serial port file> passed to simulator see the simulator docs for details.
25191
25192 \layout Itemize
25193 -S <serial in,out> passed to simulator see the simulator docs for details.
25194
25195 \layout Itemize
25196 -k <port number> passed to simulator see the simulator docs for details.
25197
25198 \layout Subsection
25199 SDCDB Debugger Commands
25200
25201 \layout Standard
25202 As mentioned earlier the command interface for the debugger has been deliberatel
25203 y kept as close the GNU debugger gdb, as possible.
25204  This will help the integration with existing graphical user interfaces
25205  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
25206  If you use a graphical user interface for the debugger you can skip this
25207  section.
25208
25209 \layout Subsubsection*
25210 break [line | file:line | function | file:function]
25211
25212 \layout Standard
25213 Set breakpoint at specified line or function:
25214 \newline
25215
25216 \newline
25217
25218 \family sans
25219 \series bold
25220 sdcdb>break 100 
25221 \newline
25222 sdcdb>break foo.c:100
25223 \newline
25224 sdcdb>break funcfoo
25225 \newline
25226 sdcdb>break foo.c:funcfoo
25227
25228 \layout Subsubsection*
25229 clear [line | file:line | function | file:function ]
25230
25231 \layout Standard
25232 Clear breakpoint at specified line or function:
25233 \newline
25234
25235 \newline
25236
25237 \family sans
25238 \series bold
25239 sdcdb>clear 100
25240 \newline
25241 sdcdb>clear foo.c:100
25242 \newline
25243 sdcdb>clear funcfoo
25244 \newline
25245 sdcdb>clear foo.c:funcfoo
25246
25247 \layout Subsubsection*
25248 continue
25249
25250 \layout Standard
25251 Continue program being debugged, after breakpoint.
25252
25253 \layout Subsubsection*
25254 finish
25255
25256 \layout Standard
25257 Execute till the end of the current function.
25258
25259 \layout Subsubsection*
25260 delete [n]
25261
25262 \layout Standard
25263 Delete breakpoint number 'n'.
25264  If used without any option clear ALL user defined break points.
25265
25266 \layout Subsubsection*
25267 info [break | stack | frame | registers ]
25268
25269 \layout Itemize
25270 info break - list all breakpoints
25271
25272 \layout Itemize
25273 info stack - show the function call stack.
25274
25275 \layout Itemize
25276 info frame - show information about the current execution frame.
25277
25278 \layout Itemize
25279 info registers - show content of all registers.
25280
25281 \layout Subsubsection*
25282 step
25283
25284 \layout Standard
25285 Step program until it reaches a different source line.
25286  Note: pressing <return> repeats the last command.
25287
25288 \layout Subsubsection*
25289 next
25290
25291 \layout Standard
25292 Step program, proceeding through subroutine calls.
25293
25294 \layout Subsubsection*
25295 run
25296
25297 \layout Standard
25298 Start debugged program.
25299
25300 \layout Subsubsection*
25301 ptype variable 
25302
25303 \layout Standard
25304 Print type information of the variable.
25305
25306 \layout Subsubsection*
25307 print variable
25308
25309 \layout Standard
25310 print value of variable.
25311
25312 \layout Subsubsection*
25313 file filename
25314
25315 \layout Standard
25316 load the given file name.
25317  Note this is an alternate method of loading file for debugging.
25318
25319 \layout Subsubsection*
25320 frame
25321
25322 \layout Standard
25323 print information about current frame.
25324
25325 \layout Subsubsection*
25326 set srcmode
25327
25328 \layout Standard
25329 Toggle between C source & assembly source.
25330
25331 \layout Subsubsection*
25332 ! simulator command
25333
25334 \layout Standard
25335 Send the string following '!' to the simulator, the simulator response is
25336  displayed.
25337  Note the debugger does not interpret the command being sent to the simulator,
25338  so if a command like 'go' is sent the debugger can loose its execution
25339  context and may display incorrect values.
25340
25341 \layout Subsubsection*
25342 quit
25343
25344 \layout Standard
25345 "Watch me now.
25346  Iam going Down.
25347  My name is Bobby Brown"
25348
25349 \layout Subsection
25350 Interfacing SDCDB with DDD
25351
25352 \layout Standard
25353 \begin_inset Note
25354 collapsed true
25355
25356 \layout Standard
25357 The screenshot was converted from png to eps with: 
25358 \begin_inset Quotes sld
25359 \end_inset
25360
25361 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
25362 \begin_inset Quotes srd
25363 \end_inset
25364
25365  which produces a pretty compact eps file which is free from compression
25366  artifacts.
25367
25368 \layout Standard
25369 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
25370  as this broke the build system on Sourceforge (pdf-file was broken.
25371  pdflatex does not accept eps files).
25372
25373 \end_inset
25374
25375
25376
25377 \layout Standard
25378 The 
25379 \emph on
25380 p
25381 \emph default
25382 ortable 
25383 \emph on
25384 n
25385 \emph default
25386 etwork 
25387 \emph on
25388 g
25389 \emph default
25390 raphics File 
25391 \size footnotesize
25392
25393 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
25394
25395 \end_inset
25396
25397
25398 \size default
25399  shows a screenshot of a debugging session with DDD
25400 \begin_inset LatexCommand \index{DDD (debugger)}
25401
25402 \end_inset
25403
25404  (Unix only) on a simulated 8032.
25405  The debugging session might not run as smoothly as the screenshot suggests.
25406  The debugger allows setting of breakpoints, displaying and changing variables,
25407  single stepping through C and assembler code.
25408  
25409 \newline
25410 The source was compiled with 
25411 \family sans
25412 \series bold
25413
25414 \newline
25415
25416 \newline
25417 sdcc -
25418 \family default
25419 \series default
25420
25421 \begin_inset ERT
25422 status Collapsed
25423
25424 \layout Standard
25425
25426
25427 \backslash
25428 /
25429
25430 \end_inset
25431
25432
25433 \family sans
25434 \series bold
25435 -debug ddd_example.c
25436 \family default
25437 \series default
25438  
25439 \family sans
25440 \series bold
25441
25442 \newline
25443
25444 \family default
25445 \series default
25446
25447 \newline
25448 and DDD was invoked with 
25449 \family sans
25450 \series bold
25451
25452 \newline
25453
25454 \newline
25455 ddd -debugger "sdcdb -cpu 8032 ddd_example"
25456
25457 \layout Standard
25458 \begin_inset Note
25459 collapsed false
25460
25461 \layout Standard
25462 Check that the double quotes or an apostroph within the command line survive
25463  the LyX tool chain.
25464  Previously the apostrophs got slanted in the PDF output so a cut and paste
25465  did not work.
25466
25467 \end_inset
25468
25469
25470
25471 \layout Subsection
25472 Interfacing SDCDB with XEmacs
25473 \begin_inset LatexCommand \index{XEmacs}
25474
25475 \end_inset
25476
25477
25478 \begin_inset LatexCommand \index{Emacs}
25479
25480 \end_inset
25481
25482
25483
25484 \layout Standard
25485 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
25486  sdcdb.el and sdcdbsrc.el.
25487  These two files can be found in the $(prefix)/bin directory after the installat
25488 ion is complete.
25489  These files need to be loaded into XEmacs for the interface to work.
25490  This can be done at XEmacs startup time by inserting the following into
25491  your '.xemacs' file (which can be found in your HOME directory): 
25492 \newline
25493
25494 \newline
25495
25496 \family typewriter
25497 (load-file sdcdbsrc.el) 
25498 \family default
25499
25500 \newline
25501
25502 \newline
25503 .xemacs is a lisp file so the () around the command is REQUIRED.
25504  The files can also be loaded dynamically while XEmacs is running, set the
25505  environment variable 'EMACSLOADPATH' to the installation bin directory
25506  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
25507  To start the interface enter the following command: 
25508 \newline
25509
25510 \newline
25511
25512 \family sans
25513 \series bold
25514 ESC-x sdcdbsrc
25515 \family default
25516 \series default
25517
25518 \newline
25519
25520 \newline
25521 You will prompted to enter the file name to be debugged.
25522  
25523 \newline
25524
25525 \newline
25526 The command line options that are passed to the simulator directly are
25527  bound to default values in the file sdcdbsrc.el.
25528  The variables are listed below, these values maybe changed as required.
25529
25530 \layout Itemize
25531 sdcdbsrc-cpu-type '51
25532
25533 \layout Itemize
25534 sdcdbsrc-frequency '11059200
25535
25536 \layout Itemize
25537 sdcdbsrc-serial nil
25538
25539 \layout Standard
25540 The following is a list of key mapping for the debugger interface.
25541
25542 \layout Standard
25543 \pagebreak_bottom 
25544 \SpecialChar ~
25545
25546 \family typewriter
25547
25548 \newline
25549 ;;\SpecialChar ~
25550 Current Listing :: 
25551 \newline
25552 ;;key\SpecialChar ~
25553 \SpecialChar ~
25554 \SpecialChar ~
25555 \SpecialChar ~
25556 \SpecialChar ~
25557 \SpecialChar ~
25558 \SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 binding\SpecialChar ~
25567 \SpecialChar ~
25568 \SpecialChar ~
25569 \SpecialChar ~
25570 \SpecialChar ~
25571 \SpecialChar ~
25572 \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 Comment 
25589 \newline
25590 ;;---\SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 \SpecialChar ~
25595 \SpecialChar ~
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 -------
25627 \newline
25628 ;; 
25629 \newline
25630 ;;\SpecialChar ~
25631 n\SpecialChar ~
25632 \SpecialChar ~
25633 \SpecialChar ~
25634 \SpecialChar ~
25635 \SpecialChar ~
25636 \SpecialChar ~
25637 \SpecialChar ~
25638 \SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 sdcdb-next-fro
25647 m-src\SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 \SpecialChar ~
25653 \SpecialChar ~
25654 \SpecialChar ~
25655 \SpecialChar ~
25656 \SpecialChar ~
25657 SDCDB next command 
25658 \newline
25659 ;;\SpecialChar ~
25660 b\SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 \SpecialChar ~
25664 \SpecialChar ~
25665 \SpecialChar ~
25666 \SpecialChar ~
25667 \SpecialChar ~
25668 \SpecialChar ~
25669 \SpecialChar ~
25670 \SpecialChar ~
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 \SpecialChar ~
25675 sdcdb-back-from-src\SpecialChar ~
25676 \SpecialChar ~
25677 \SpecialChar ~
25678 \SpecialChar ~
25679 \SpecialChar ~
25680 \SpecialChar ~
25681 \SpecialChar ~
25682 \SpecialChar ~
25683 \SpecialChar ~
25684 \SpecialChar ~
25685 SDCDB back command 
25686 \newline
25687 ;;\SpecialChar ~
25688 c\SpecialChar ~
25689 \SpecialChar ~
25690 \SpecialChar ~
25691 \SpecialChar ~
25692 \SpecialChar ~
25693 \SpecialChar ~
25694 \SpecialChar ~
25695 \SpecialChar ~
25696 \SpecialChar ~
25697 \SpecialChar ~
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 \SpecialChar ~
25701 \SpecialChar ~
25702 \SpecialChar ~
25703 sdcdb-cont-f
25704 rom-src\SpecialChar ~
25705 \SpecialChar ~
25706 \SpecialChar ~
25707 \SpecialChar ~
25708 \SpecialChar ~
25709 \SpecialChar ~
25710 \SpecialChar ~
25711 \SpecialChar ~
25712 \SpecialChar ~
25713 \SpecialChar ~
25714 SDCDB continue command
25715 \newline
25716 ;;\SpecialChar ~
25717 s\SpecialChar ~
25718 \SpecialChar ~
25719 \SpecialChar ~
25720 \SpecialChar ~
25721 \SpecialChar ~
25722 \SpecialChar ~
25723 \SpecialChar ~
25724 \SpecialChar ~
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 \SpecialChar ~
25728 \SpecialChar ~
25729 \SpecialChar ~
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 sdcdb-step-from-src\SpecialChar ~
25733 \SpecialChar ~
25734 \SpecialChar ~
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738 \SpecialChar ~
25739 \SpecialChar ~
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 SDCDB step command 
25743 \newline
25744 ;;\SpecialChar ~
25745 ?\SpecialChar ~
25746 \SpecialChar ~
25747 \SpecialChar ~
25748 \SpecialChar ~
25749 \SpecialChar ~
25750 \SpecialChar ~
25751 \SpecialChar ~
25752 \SpecialChar ~
25753 \SpecialChar ~
25754 \SpecialChar ~
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 \SpecialChar ~
25758 \SpecialChar ~
25759 \SpecialChar ~
25760 sdcdb-w
25761 hatis-c-sexp\SpecialChar ~
25762 \SpecialChar ~
25763 \SpecialChar ~
25764 \SpecialChar ~
25765 \SpecialChar ~
25766 \SpecialChar ~
25767 \SpecialChar ~
25768 \SpecialChar ~
25769 \SpecialChar ~
25770 \SpecialChar ~
25771 SDCDB ptypecommand for data at 
25772 \newline
25773 ;;\SpecialChar ~
25774 \SpecialChar ~
25775 \SpecialChar ~
25776 \SpecialChar ~
25777 \SpecialChar ~
25778 \SpecialChar ~
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 buffer point 
25821 \newline
25822 ;;\SpecialChar ~
25823 x\SpecialChar ~
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 \SpecialChar ~
25827 \SpecialChar ~
25828 \SpecialChar ~
25829 \SpecialChar ~
25830 \SpecialChar ~
25831 \SpecialChar ~
25832 \SpecialChar ~
25833 \SpecialChar ~
25834 \SpecialChar ~
25835 \SpecialChar ~
25836 \SpecialChar ~
25837 \SpecialChar ~
25838 sdcdbsrc-delete\SpecialChar ~
25839 \SpecialChar ~
25840 \SpecialChar ~
25841 \SpecialChar ~
25842 \SpecialChar ~
25843 \SpecialChar ~
25844 \SpecialChar ~
25845 \SpecialChar ~
25846 \SpecialChar ~
25847 \SpecialChar ~
25848 \SpecialChar ~
25849 \SpecialChar ~
25850 \SpecialChar ~
25851 \SpecialChar ~
25852 SDCD
25853 B Delete all breakpoints if no arg 
25854 \newline
25855 ;;\SpecialChar ~
25856 \SpecialChar ~
25857 \SpecialChar ~
25858 \SpecialChar ~
25859 \SpecialChar ~
25860 \SpecialChar ~
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 given or delete arg (C-u arg x) 
25903 \newline
25904 ;;\SpecialChar ~
25905 m\SpecialChar ~
25906 \SpecialChar ~
25907 \SpecialChar ~
25908 \SpecialChar ~
25909 \SpecialChar ~
25910 \SpecialChar ~
25911 \SpecialChar ~
25912 \SpecialChar ~
25913 \SpecialChar ~
25914 \SpecialChar ~
25915 \SpecialChar ~
25916 \SpecialChar ~
25917 \SpecialChar ~
25918 \SpecialChar ~
25919 \SpecialChar ~
25920 sdcdbsrc
25921 -frame\SpecialChar ~
25922 \SpecialChar ~
25923 \SpecialChar ~
25924 \SpecialChar ~
25925 \SpecialChar ~
25926 \SpecialChar ~
25927 \SpecialChar ~
25928 \SpecialChar ~
25929 \SpecialChar ~
25930 \SpecialChar ~
25931 \SpecialChar ~
25932 \SpecialChar ~
25933 \SpecialChar ~
25934 \SpecialChar ~
25935 \SpecialChar ~
25936 SDCDB Display current frame if no arg, 
25937 \newline
25938 ;;\SpecialChar ~
25939 \SpecialChar ~
25940 \SpecialChar ~
25941 \SpecialChar ~
25942 \SpecialChar ~
25943 \SpecialChar ~
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 given or display frame arg
25986  
25987 \newline
25988 ;;\SpecialChar ~
25989 \SpecialChar ~
25990 \SpecialChar ~
25991 \SpecialChar ~
25992 \SpecialChar ~
25993 \SpecialChar ~
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 buffer point 
26036 \newline
26037 ;;\SpecialChar ~
26038 !\SpecialChar ~
26039 \SpecialChar ~
26040 \SpecialChar ~
26041 \SpecialChar ~
26042 \SpecialChar ~
26043 \SpecialChar ~
26044 \SpecialChar ~
26045 \SpecialChar ~
26046 \SpecialChar ~
26047 \SpecialChar ~
26048 \SpecialChar ~
26049 \SpecialChar ~
26050 \SpecialChar ~
26051 \SpecialChar ~
26052 \SpecialChar ~
26053 sdcdbsrc-goto-sdcdb\SpecialChar ~
26054 \SpecialChar ~
26055 \SpecialChar ~
26056 \SpecialChar ~
26057 \SpecialChar ~
26058 \SpecialChar ~
26059 \SpecialChar ~
26060 \SpecialChar ~
26061 \SpecialChar ~
26062 \SpecialChar ~
26063 Goto the SDCDB output buffer 
26064 \newline
26065 ;;\SpecialChar ~
26066 p\SpecialChar ~
26067 \SpecialChar ~
26068 \SpecialChar ~
26069 \SpecialChar ~
26070 \SpecialChar ~
26071 \SpecialChar ~
26072 \SpecialChar ~
26073 \SpecialChar ~
26074 \SpecialChar ~
26075 \SpecialChar ~
26076 \SpecialChar ~
26077 \SpecialChar ~
26078 \SpecialChar ~
26079 \SpecialChar ~
26080 \SpecialChar ~
26081 sdcdb-prin
26082 t-c-sexp\SpecialChar ~
26083 \SpecialChar ~
26084 \SpecialChar ~
26085 \SpecialChar ~
26086 \SpecialChar ~
26087 \SpecialChar ~
26088 \SpecialChar ~
26089 \SpecialChar ~
26090 \SpecialChar ~
26091 \SpecialChar ~
26092 \SpecialChar ~
26093 SDCDB print command for data at 
26094 \newline
26095 ;;\SpecialChar ~
26096 \SpecialChar ~
26097 \SpecialChar ~
26098 \SpecialChar ~
26099 \SpecialChar ~
26100 \SpecialChar ~
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 buffer point 
26143 \newline
26144 ;;\SpecialChar ~
26145 g\SpecialChar ~
26146 \SpecialChar ~
26147 \SpecialChar ~
26148 \SpecialChar ~
26149 \SpecialChar ~
26150 \SpecialChar ~
26151 \SpecialChar ~
26152 \SpecialChar ~
26153 \SpecialChar ~
26154 \SpecialChar ~
26155 \SpecialChar ~
26156 \SpecialChar ~
26157 \SpecialChar ~
26158 \SpecialChar ~
26159 \SpecialChar ~
26160 sdcdbsrc-goto-sdcdb\SpecialChar ~
26161 \SpecialChar ~
26162 \SpecialChar ~
26163 \SpecialChar ~
26164 \SpecialChar ~
26165 \SpecialChar ~
26166 \SpecialChar ~
26167 \SpecialChar ~
26168 \SpecialChar ~
26169 \SpecialChar ~
26170 Got
26171 o the SDCDB output buffer 
26172 \newline
26173 ;;\SpecialChar ~
26174 t\SpecialChar ~
26175 \SpecialChar ~
26176 \SpecialChar ~
26177 \SpecialChar ~
26178 \SpecialChar ~
26179 \SpecialChar ~
26180 \SpecialChar ~
26181 \SpecialChar ~
26182 \SpecialChar ~
26183 \SpecialChar ~
26184 \SpecialChar ~
26185 \SpecialChar ~
26186 \SpecialChar ~
26187 \SpecialChar ~
26188 \SpecialChar ~
26189 sdcdbsrc-mode\SpecialChar ~
26190 \SpecialChar ~
26191 \SpecialChar ~
26192 \SpecialChar ~
26193 \SpecialChar ~
26194 \SpecialChar ~
26195 \SpecialChar ~
26196 \SpecialChar ~
26197 \SpecialChar ~
26198 \SpecialChar ~
26199 \SpecialChar ~
26200 \SpecialChar ~
26201 \SpecialChar ~
26202 \SpecialChar ~
26203 \SpecialChar ~
26204 \SpecialChar ~
26205 Toggles Sdcdbsrc mode (turns it
26206  off) 
26207 \newline
26208 ;; 
26209 \newline
26210 ;;\SpecialChar ~
26211 C-c\SpecialChar ~
26212 C-f\SpecialChar ~
26213 \SpecialChar ~
26214 \SpecialChar ~
26215 \SpecialChar ~
26216 \SpecialChar ~
26217 \SpecialChar ~
26218 \SpecialChar ~
26219 \SpecialChar ~
26220 \SpecialChar ~
26221 sdcdb-finish-from-src\SpecialChar ~
26222 \SpecialChar ~
26223 \SpecialChar ~
26224 \SpecialChar ~
26225 \SpecialChar ~
26226 \SpecialChar ~
26227 \SpecialChar ~
26228 \SpecialChar ~
26229 SDCDB finish command 
26230 \newline
26231 ;; 
26232 \newline
26233 ;;\SpecialChar ~
26234 C-x\SpecialChar ~
26235 SPC\SpecialChar ~
26236 \SpecialChar ~
26237 \SpecialChar ~
26238 \SpecialChar ~
26239 \SpecialChar ~
26240 \SpecialChar ~
26241 \SpecialChar ~
26242 \SpecialChar ~
26243 \SpecialChar ~
26244 sdcdb-brea
26245 k\SpecialChar ~
26246 \SpecialChar ~
26247 \SpecialChar ~
26248 \SpecialChar ~
26249 \SpecialChar ~
26250 \SpecialChar ~
26251 \SpecialChar ~
26252 \SpecialChar ~
26253 \SpecialChar ~
26254 \SpecialChar ~
26255 \SpecialChar ~
26256 \SpecialChar ~
26257 \SpecialChar ~
26258 \SpecialChar ~
26259 \SpecialChar ~
26260 \SpecialChar ~
26261 \SpecialChar ~
26262 \SpecialChar ~
26263 Set break for line with point 
26264 \newline
26265 ;;\SpecialChar ~
26266 ESC\SpecialChar ~
26267 t\SpecialChar ~
26268 \SpecialChar ~
26269 \SpecialChar ~
26270 \SpecialChar ~
26271 \SpecialChar ~
26272 \SpecialChar ~
26273 \SpecialChar ~
26274 \SpecialChar ~
26275 \SpecialChar ~
26276 \SpecialChar ~
26277 \SpecialChar ~
26278 sdcdbsrc-mode\SpecialChar ~
26279 \SpecialChar ~
26280 \SpecialChar ~
26281 \SpecialChar ~
26282 \SpecialChar ~
26283 \SpecialChar ~
26284 \SpecialChar ~
26285 \SpecialChar ~
26286 \SpecialChar ~
26287 \SpecialChar ~
26288 \SpecialChar ~
26289 \SpecialChar ~
26290 \SpecialChar ~
26291 \SpecialChar ~
26292 \SpecialChar ~
26293 \SpecialChar ~
26294 Toggle Sdcdbsrc mode 
26295 \newline
26296 ;;\SpecialChar ~
26297 ESC\SpecialChar ~
26298 m\SpecialChar ~
26299 \SpecialChar ~
26300 \SpecialChar ~
26301 \SpecialChar ~
26302 \SpecialChar ~
26303 \SpecialChar ~
26304 \SpecialChar ~
26305 \SpecialChar ~
26306 \SpecialChar ~
26307 \SpecialChar ~
26308 \SpecialChar ~
26309 sdc
26310 dbsrc-srcmode\SpecialChar ~
26311 \SpecialChar ~
26312 \SpecialChar ~
26313 \SpecialChar ~
26314 \SpecialChar ~
26315 \SpecialChar ~
26316 \SpecialChar ~
26317 \SpecialChar ~
26318 \SpecialChar ~
26319 \SpecialChar ~
26320 \SpecialChar ~
26321 \SpecialChar ~
26322 \SpecialChar ~
26323 Toggle list mode 
26324 \newline
26325 ;; 
26326 \newline
26327
26328 \family default
26329
26330
26331
26332 \layout Chapter
26333 TIPS
26334
26335 \layout Standard
26336 Here are a few guidelines that will help the compiler generate more efficient
26337  code, some of the tips are specific to this compiler others are generally
26338  good programming practice.
26339
26340 \layout Itemize
26341 Use the smallest data type to represent your data-value.
26342  If it is known in advance that the value is going to be less than 256 then
26343  use an 'unsigned char' instead of a 'short' or 'int'.
26344  Please note, that ANSI C requires both signed and unsigned chars to be
26345  promoted to 'signed int'
26346 \begin_inset LatexCommand \index{promotion to signed int}
26347
26348 \end_inset
26349
26350
26351 \begin_inset Marginal
26352 collapsed true
26353
26354 \layout Standard
26355
26356 \series bold
26357 \SpecialChar ~
26358 !
26359
26360 \end_inset
26361
26362  before doing any operation.
26363  This promotion
26364 \begin_inset LatexCommand \index{type promotion}
26365
26366 \end_inset
26367
26368
26369 \begin_inset LatexCommand \label{type promotion}
26370
26371 \end_inset
26372
26373  can be omitted, if the result is the same.
26374  The effect of the promotion rules together with the sign-extension is often
26375  surprising:
26376
26377 \begin_deeper
26378 \layout Verse
26379
26380 \family typewriter
26381 unsigned char uc = 0xfe;
26382 \newline
26383 if (uc * uc < 0) /* this is true! */
26384 \newline
26385 {
26386 \newline
26387 \SpecialChar ~
26388 \SpecialChar ~
26389 \SpecialChar ~
26390 \SpecialChar ~
26391 ....
26392 \newline
26393 }
26394
26395 \layout Standard
26396
26397 \family typewriter
26398 uc * uc
26399 \family default
26400  is evaluated as 
26401 \family typewriter
26402 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
26403 \family default
26404 .
26405  
26406 \newline
26407 Another one:
26408
26409 \layout Verse
26410
26411 \family typewriter
26412 (unsigned char) -12 / (signed char) -3 = ...
26413
26414 \layout Standard
26415 No, the result is not 4:
26416
26417 \layout Verse
26418
26419 \family typewriter
26420 (int) (unsigned char) -12 / (int) (signed char) -3 =
26421 \newline
26422 (int) (unsigned char)
26423  0xf4 / (int) (signed char) 0xfd =
26424 \newline
26425 (int) 0x00f4 / (int) 0xfffd =
26426 \newline
26427 (int) 0x00f4
26428  / (int) 0xfffd =
26429 \newline
26430 (int) 244 / (int) -3 =
26431 \newline
26432 (int) -81 = (int) 0xffaf;
26433
26434 \layout Standard
26435 Don't complain, that gcc gives you a different result.
26436  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
26437  Therefore the results are different.
26438 \newline
26439 From 
26440 \begin_inset Quotes sld
26441 \end_inset
26442
26443 comp.lang.c FAQ
26444 \begin_inset Quotes srd
26445 \end_inset
26446
26447 :
26448
26449 \layout Quote
26450
26451 \emph on
26452 If well-defined overflow characteristics are important and negative values
26453  are not, or if you want to steer clear of sign-extension problems when
26454  manipulating bits or bytes, use one of the corresponding unsigned types.
26455  (Beware when mixing signed and unsigned values in expressions, though.)
26456 \newline
26457 Although
26458  character types (especially unsigned char) can be used as "tiny" integers,
26459  doing so is sometimes more trouble than it's worth, due to unpredictable
26460  sign extension and increased code size.
26461
26462 \end_deeper
26463 \layout Itemize
26464 Use unsigned when it is known in advance that the value is not going to
26465  be negative.
26466  This helps especially if you are doing division or multiplication, bit-shifting
26467  or are using an array index.
26468
26469 \layout Itemize
26470 NEVER jump into a LOOP.
26471
26472 \layout Itemize
26473 Declare the variables to be local
26474 \begin_inset LatexCommand \index{local variables}
26475
26476 \end_inset
26477
26478  whenever possible, especially loop control variables (induction).
26479
26480 \layout Itemize
26481 Have a look at the assembly listing to get a 
26482 \begin_inset Quotes sld
26483 \end_inset
26484
26485 feeling
26486 \begin_inset Quotes srd
26487 \end_inset
26488
26489  for the code generation.
26490
26491 \layout Section
26492 Porting code from or to other compilers
26493 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
26494
26495 \end_inset
26496
26497
26498
26499 \layout Itemize
26500 check whether endianness of the compilers differs and adapt where needed.
26501
26502 \layout Itemize
26503 check the device specific header files
26504 \begin_inset LatexCommand \index{Header files}
26505
26506 \end_inset
26507
26508
26509 \begin_inset LatexCommand \index{Include files}
26510
26511 \end_inset
26512
26513  for compiler specific syntax.
26514  Eventually include the file <compiler.h
26515 \begin_inset LatexCommand \index{compiler.h (include file)}
26516
26517 \end_inset
26518
26519
26520 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
26521
26522 \end_inset
26523
26524  to allow using common header files.
26525  (see f.e.
26526  cc2510fx.h 
26527 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
26528
26529 \end_inset
26530
26531 ).
26532
26533 \layout Itemize
26534 check whether the startup code contains the correct initialization (watchdog,
26535  peripherals).
26536
26537 \layout Itemize
26538 check whether the sizes of short, int, long match.
26539
26540 \layout Itemize
26541 check if some 16 or 32 bit hardware registers require a specific addressing
26542  order (least significant or most significant byte first) and adapt if needed
26543  (
26544 \emph on
26545 first
26546 \emph default
26547  and 
26548 \emph on
26549 last
26550 \emph default
26551  relate to time and not to lower/upper memory location here, so this is
26552  
26553 \emph on
26554 not
26555 \emph default
26556  the same as endianness).
26557
26558 \layout Itemize
26559 check whether the keyword 
26560 \emph on
26561 volatile
26562 \emph default
26563  is used where needed.
26564  The compilers might differ in their optimization characteristics (as different
26565  versions of the same compiler might also use more clever optimizations
26566  this is good idea anyway).
26567  See section 
26568 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
26569
26570 \end_inset
26571
26572 .
26573
26574 \layout Itemize
26575 check that the compilers are not told to supress warnings.
26576
26577 \layout Itemize
26578 check and convert compiler specific extensions (interrupts, memory areas,
26579  pragmas etc.).
26580
26581 \layout Itemize
26582 check for differences in type promotion.
26583  Especially check for math operations on 
26584 \family typewriter
26585 char
26586 \family default
26587  or 
26588 \family typewriter
26589 unsigned char
26590 \family default
26591  variables.
26592  For the sake of C99 compatibility SDCC will probably promote these to 
26593 \family typewriter
26594 int
26595 \family default
26596  more often than other compilers.
26597  Eventually insert explicit casts to 
26598 \family typewriter
26599 (char) 
26600 \family default
26601 or
26602 \family typewriter
26603  (unsigned char)
26604 \family default
26605 .
26606  Also check that the ~\SpecialChar ~
26607 operator
26608 \begin_inset LatexCommand \index{\~\/ Operator}
26609
26610 \end_inset
26611
26612  is not used on 
26613 \family typewriter
26614 bit
26615 \begin_inset LatexCommand \index{bit}
26616
26617 \end_inset
26618
26619
26620 \family default
26621  variables, use the !\SpecialChar ~
26622 operator instead.
26623  See sections 
26624 \begin_inset LatexCommand \ref{type promotion}
26625
26626 \end_inset
26627
26628  and 
26629 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26630
26631 \end_inset
26632
26633 .
26634
26635 \layout Itemize
26636 check the assembly code generated for interrupt routines (f.e.
26637  for calls to possibly non-reentrant library functions).
26638
26639 \layout Itemize
26640 check whether timing loops result in proper timing (or preferably consider
26641  a rewrite of the code with timer based delays instead).
26642
26643 \layout Itemize
26644 check for differences in printf parameters (some compilers push (va_arg
26645 \begin_inset LatexCommand \index{vararg, va\_arg}
26646
26647 \end_inset
26648
26649 ) char variables as 
26650 \family typewriter
26651 int
26652 \family default
26653  others push them as 
26654 \family typewriter
26655 char
26656 \family default
26657 .
26658  See section 
26659 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26660
26661 \end_inset
26662
26663 ).
26664
26665 \layout Itemize
26666 check the resulting memory map
26667 \begin_inset LatexCommand \index{Memory map}
26668
26669 \end_inset
26670
26671 .
26672  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
26673 ly idata, pdata, xdata).
26674  Eventually check if unexpected library functions are included.
26675
26676 \layout Section
26677 Tools
26678 \begin_inset LatexCommand \index{Tools}
26679
26680 \end_inset
26681
26682  included in the distribution
26683
26684 \layout Standard
26685 \align left
26686 \begin_inset Tabular
26687 <lyxtabular version="3" rows="12" columns="3">
26688 <features>
26689 <column alignment="left" valignment="top" leftline="true" width="0pt">
26690 <column alignment="left" valignment="top" leftline="true" width="0pt">
26691 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26692 <row topline="true" bottomline="true">
26693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26694 \begin_inset Text
26695
26696 \layout Standard
26697
26698 \series bold
26699 Name
26700
26701 \end_inset
26702 </cell>
26703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26704 \begin_inset Text
26705
26706 \layout Standard
26707
26708 \series bold
26709 Purpose
26710
26711 \end_inset
26712 </cell>
26713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26714 \begin_inset Text
26715
26716 \layout Standard
26717
26718 \series bold
26719 Directory
26720
26721 \end_inset
26722 </cell>
26723 </row>
26724 <row topline="true">
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26726 \begin_inset Text
26727
26728 \layout Standard
26729 uCsim
26730 \begin_inset LatexCommand \index{uCsim}
26731
26732 \end_inset
26733
26734
26735
26736 \end_inset
26737 </cell>
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26739 \begin_inset Text
26740
26741 \layout Standard
26742 Simulator for various architectures
26743
26744 \end_inset
26745 </cell>
26746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26747 \begin_inset Text
26748
26749 \layout Standard
26750 sdcc/sim/ucsim
26751
26752 \end_inset
26753 </cell>
26754 </row>
26755 <row topline="true">
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26757 \begin_inset Text
26758
26759 \layout Standard
26760 keil2sdcc.pl
26761
26762 \end_inset
26763 </cell>
26764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26765 \begin_inset Text
26766
26767 \layout Standard
26768 header file
26769 \begin_inset LatexCommand \index{Header files}
26770
26771 \end_inset
26772
26773
26774 \begin_inset LatexCommand \index{Include files}
26775
26776 \end_inset
26777
26778  conversion
26779
26780 \end_inset
26781 </cell>
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26783 \begin_inset Text
26784
26785 \layout Standard
26786 sdcc/support/scripts
26787
26788 \end_inset
26789 </cell>
26790 </row>
26791 <row topline="true">
26792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26793 \begin_inset Text
26794
26795 \layout Standard
26796 mh2h.c
26797
26798 \end_inset
26799 </cell>
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26801 \begin_inset Text
26802
26803 \layout Standard
26804 header file conversion
26805
26806 \end_inset
26807 </cell>
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26809 \begin_inset Text
26810
26811 \layout Standard
26812 sdcc/support/scripts
26813
26814 \end_inset
26815 </cell>
26816 </row>
26817 <row topline="true">
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \layout Standard
26822 as-gbz80
26823
26824 \end_inset
26825 </cell>
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26827 \begin_inset Text
26828
26829 \layout Standard
26830 Assembler
26831
26832 \end_inset
26833 </cell>
26834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26835 \begin_inset Text
26836
26837 \layout Standard
26838
26839 \family roman
26840 \series medium
26841 \shape up
26842 \size normal
26843 \emph off
26844 \bar no
26845 \noun off
26846 \color none
26847 sdcc/bin
26848
26849 \end_inset
26850 </cell>
26851 </row>
26852 <row topline="true">
26853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26854 \begin_inset Text
26855
26856 \layout Standard
26857 as-z80
26858
26859 \end_inset
26860 </cell>
26861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26862 \begin_inset Text
26863
26864 \layout Standard
26865 Assembler
26866
26867 \end_inset
26868 </cell>
26869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26870 \begin_inset Text
26871
26872 \layout Standard
26873
26874 \family roman
26875 \series medium
26876 \shape up
26877 \size normal
26878 \emph off
26879 \bar no
26880 \noun off
26881 \color none
26882 sdcc/bin
26883
26884 \end_inset
26885 </cell>
26886 </row>
26887 <row topline="true">
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26889 \begin_inset Text
26890
26891 \layout Standard
26892 asx8051
26893
26894 \end_inset
26895 </cell>
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \layout Standard
26900 Assembler
26901
26902 \end_inset
26903 </cell>
26904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26905 \begin_inset Text
26906
26907 \layout Standard
26908
26909 \family roman
26910 \series medium
26911 \shape up
26912 \size normal
26913 \emph off
26914 \bar no
26915 \noun off
26916 \color none
26917 sdcc/bin
26918
26919 \end_inset
26920 </cell>
26921 </row>
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \layout Standard
26927 SDCDB
26928
26929 \end_inset
26930 </cell>
26931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26932 \begin_inset Text
26933
26934 \layout Standard
26935 Simulator
26936
26937 \end_inset
26938 </cell>
26939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26940 \begin_inset Text
26941
26942 \layout Standard
26943
26944 \family roman
26945 \series medium
26946 \shape up
26947 \size normal
26948 \emph off
26949 \bar no
26950 \noun off
26951 \color none
26952 sdcc/bin
26953
26954 \end_inset
26955 </cell>
26956 </row>
26957 <row topline="true">
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26959 \begin_inset Text
26960
26961 \layout Standard
26962 aslink
26963
26964 \end_inset
26965 </cell>
26966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26967 \begin_inset Text
26968
26969 \layout Standard
26970 Linker
26971
26972 \end_inset
26973 </cell>
26974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26975 \begin_inset Text
26976
26977 \layout Standard
26978
26979 \family roman
26980 \series medium
26981 \shape up
26982 \size normal
26983 \emph off
26984 \bar no
26985 \noun off
26986 \color none
26987 sdcc/bin
26988
26989 \end_inset
26990 </cell>
26991 </row>
26992 <row topline="true">
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26994 \begin_inset Text
26995
26996 \layout Standard
26997 link-z80
26998
26999 \end_inset
27000 </cell>
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \layout Standard
27005 Linker
27006
27007 \end_inset
27008 </cell>
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27010 \begin_inset Text
27011
27012 \layout Standard
27013
27014 \family roman
27015 \series medium
27016 \shape up
27017 \size normal
27018 \emph off
27019 \bar no
27020 \noun off
27021 \color none
27022 sdcc/bin
27023
27024 \end_inset
27025 </cell>
27026 </row>
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \layout Standard
27032 link-gbz80
27033
27034 \end_inset
27035 </cell>
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27037 \begin_inset Text
27038
27039 \layout Standard
27040 Linker
27041
27042 \end_inset
27043 </cell>
27044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27045 \begin_inset Text
27046
27047 \layout Standard
27048
27049 \family roman
27050 \series medium
27051 \shape up
27052 \size normal
27053 \emph off
27054 \bar no
27055 \noun off
27056 \color none
27057 sdcc/bin
27058
27059 \end_inset
27060 </cell>
27061 </row>
27062 <row topline="true" bottomline="true">
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27064 \begin_inset Text
27065
27066 \layout Standard
27067 packihx
27068
27069 \end_inset
27070 </cell>
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 \begin_inset Text
27073
27074 \layout Standard
27075 Intel Hex packer 
27076 \begin_inset LatexCommand \index{packihx (tool)}
27077
27078 \end_inset
27079
27080
27081
27082 \end_inset
27083 </cell>
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27085 \begin_inset Text
27086
27087 \layout Standard
27088
27089 \family roman
27090 \series medium
27091 \shape up
27092 \size normal
27093 \emph off
27094 \bar no
27095 \noun off
27096 \color none
27097 sdcc/bin
27098
27099 \end_inset
27100 </cell>
27101 </row>
27102 </lyxtabular>
27103
27104 \end_inset
27105
27106
27107 \newline
27108
27109
27110 \layout Section
27111 Documentation
27112 \begin_inset LatexCommand \index{Documentation}
27113
27114 \end_inset
27115
27116  included in the distribution
27117
27118 \layout Standard
27119 \align left
27120 \begin_inset Tabular
27121 <lyxtabular version="3" rows="10" columns="2">
27122 <features>
27123 <column alignment="block" valignment="top" leftline="true" width="40col%">
27124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
27125 <row topline="true" bottomline="true" endhead="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27127 \begin_inset Text
27128
27129 \layout Standard
27130
27131 \series bold
27132 Subject / Title
27133
27134 \end_inset
27135 </cell>
27136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27137 \begin_inset Text
27138
27139 \layout Standard
27140
27141 \series bold
27142 Filename / Where to get
27143
27144 \end_inset
27145 </cell>
27146 </row>
27147 <row topline="true">
27148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27149 \begin_inset Text
27150
27151 \layout Standard
27152 SDCC Compiler User Guide
27153
27154 \end_inset
27155 </cell>
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27157 \begin_inset Text
27158
27159 \layout Standard
27160 You're reading it right now
27161 \emph on
27162  \SpecialChar ~
27163 \SpecialChar ~
27164 \SpecialChar ~
27165
27166 \hfill
27167 online at:
27168 \emph default
27169
27170 \newline
27171
27172 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
27173
27174 \end_inset
27175
27176
27177
27178 \end_inset
27179 </cell>
27180 </row>
27181 <row topline="true">
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27183 \begin_inset Text
27184
27185 \layout Standard
27186 Changelog of SDCC
27187
27188 \end_inset
27189 </cell>
27190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27191 \begin_inset Text
27192
27193 \layout Standard
27194 sdcc/Changelog
27195 \emph on
27196  \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199
27200 \hfill
27201 online at:
27202 \emph default
27203
27204 \newline
27205
27206 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
27207
27208 \end_inset
27209
27210
27211
27212 \end_inset
27213 </cell>
27214 </row>
27215 <row topline="true">
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27217 \begin_inset Text
27218
27219 \layout Standard
27220 ASXXXX
27221 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
27222
27223 \end_inset
27224
27225
27226 \begin_inset LatexCommand \index{Assembler documentation}
27227
27228 \end_inset
27229
27230  Assemblers and
27231 \newline
27232 ASLINK
27233 \begin_inset LatexCommand \index{aslink}
27234
27235 \end_inset
27236
27237
27238 \begin_inset LatexCommand \index{Linker documentation}
27239
27240 \end_inset
27241
27242  Relocating Linker
27243
27244 \end_inset
27245 </cell>
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27247 \begin_inset Text
27248
27249 \layout Standard
27250 sdcc/as/doc/asxhtm.html 
27251 \emph on
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255
27256 \hfill
27257 online at:
27258 \emph default
27259
27260 \newline
27261
27262 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
27263
27264 \end_inset
27265
27266
27267
27268 \end_inset
27269 </cell>
27270 </row>
27271 <row topline="true">
27272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27273 \begin_inset Text
27274
27275 \layout Standard
27276 SDCC regression test
27277 \begin_inset LatexCommand \index{Regression test}
27278
27279 \end_inset
27280
27281
27282
27283 \end_inset
27284 </cell>
27285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27286 \begin_inset Text
27287
27288 \layout Standard
27289 sdcc/doc/test_suite_spec.pdf 
27290 \emph on
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294
27295 \hfill
27296 online at:
27297 \emph default
27298
27299 \newline
27300
27301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27302
27303 \end_inset
27304
27305
27306
27307 \end_inset
27308 </cell>
27309 </row>
27310 <row topline="true">
27311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27312 \begin_inset Text
27313
27314 \layout Standard
27315 Various notes
27316
27317 \end_inset
27318 </cell>
27319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27320 \begin_inset Text
27321
27322 \layout Standard
27323 sdcc/doc/* 
27324 \emph on
27325 \SpecialChar ~
27326 \SpecialChar ~
27327 \SpecialChar ~
27328
27329 \hfill
27330 online at:
27331 \emph default
27332
27333 \newline
27334
27335 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
27336
27337 \end_inset
27338
27339
27340
27341 \end_inset
27342 </cell>
27343 </row>
27344 <row topline="true">
27345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27346 \begin_inset Text
27347
27348 \layout Standard
27349 Notes on debugging with SDCDB
27350 \begin_inset LatexCommand \index{SDCDB (debugger)}
27351
27352 \end_inset
27353
27354
27355
27356 \end_inset
27357 </cell>
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27359 \begin_inset Text
27360
27361 \layout Standard
27362 sdcc/debugger/README 
27363 \emph on
27364 \SpecialChar ~
27365 \SpecialChar ~
27366 \SpecialChar ~
27367
27368 \hfill
27369 online at
27370 \emph default
27371 :
27372 \newline
27373
27374 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
27375
27376 \end_inset
27377
27378
27379
27380 \end_inset
27381 </cell>
27382 </row>
27383 <row topline="true">
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27385 \begin_inset Text
27386
27387 \layout Standard
27388 uCsim
27389 \begin_inset LatexCommand \index{uCsim}
27390
27391 \end_inset
27392
27393  Software simulator for microcontrollers
27394
27395 \end_inset
27396 </cell>
27397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27398 \begin_inset Text
27399
27400 \layout Standard
27401
27402 \family roman
27403 \series medium
27404 \shape up
27405 \size normal
27406 \emph off
27407 \bar no
27408 \noun off
27409 \color none
27410 sdcc/sim/ucsim/doc
27411 \family default
27412 \series default
27413 \shape default
27414 \size default
27415 \emph default
27416 \bar default
27417 \noun default
27418 /index.html 
27419 \emph on
27420 \SpecialChar ~
27421 \SpecialChar ~
27422 \SpecialChar ~
27423
27424 \hfill
27425 online at:
27426 \emph default
27427
27428 \newline
27429
27430 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
27431
27432 \end_inset
27433
27434
27435
27436 \end_inset
27437 </cell>
27438 </row>
27439 <row topline="true">
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27441 \begin_inset Text
27442
27443 \layout Standard
27444 Temporary notes on the pic16
27445 \begin_inset LatexCommand \index{PIC16}
27446
27447 \end_inset
27448
27449  port
27450
27451 \end_inset
27452 </cell>
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27454 \begin_inset Text
27455
27456 \layout Standard
27457 sdcc/src/pic16/NOTES 
27458 \emph on
27459 \SpecialChar ~
27460 \SpecialChar ~
27461 \SpecialChar ~
27462
27463 \hfill
27464 online at:
27465 \newline
27466
27467 \emph default
27468
27469 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
27470
27471 \end_inset
27472
27473
27474
27475 \end_inset
27476 </cell>
27477 </row>
27478 <row topline="true" bottomline="true">
27479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27480 \begin_inset Text
27481
27482 \layout Standard
27483 SDCC internal documentation (debugging file format)
27484
27485 \end_inset
27486 </cell>
27487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27488 \begin_inset Text
27489
27490 \layout Standard
27491 sdcc/doc/
27492 \family roman
27493 \series medium
27494 \shape up
27495 \size normal
27496 \emph off
27497 \bar no
27498 \noun off
27499 \color none
27500 cdbfileformat.pd
27501 \family default
27502 \series default
27503 \shape default
27504 \size default
27505 \emph default
27506 \bar default
27507 \noun default
27508 f
27509 \emph on
27510  \SpecialChar ~
27511 \SpecialChar ~
27512 \SpecialChar ~
27513
27514 \hfill
27515 online at:
27516 \emph default
27517
27518 \newline
27519
27520 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
27521
27522 \end_inset
27523
27524
27525
27526 \end_inset
27527 </cell>
27528 </row>
27529 </lyxtabular>
27530
27531 \end_inset
27532
27533
27534 \newline
27535
27536
27537 \layout Section
27538 Related open source tools
27539 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
27540
27541 \end_inset
27542
27543
27544 \begin_inset LatexCommand \index{Related tools}
27545
27546 \end_inset
27547
27548
27549
27550 \layout Standard
27551 \align left
27552 \begin_inset Tabular
27553 <lyxtabular version="3" rows="14" columns="3">
27554 <features>
27555 <column alignment="left" valignment="top" leftline="true" width="0pt">
27556 <column alignment="block" valignment="top" leftline="true" width="30line%">
27557 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27558 <row topline="true" bottomline="true">
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27560 \begin_inset Text
27561
27562 \layout Standard
27563
27564 \series bold
27565 Name
27566
27567 \end_inset
27568 </cell>
27569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27570 \begin_inset Text
27571
27572 \layout Standard
27573
27574 \series bold
27575 Purpose
27576
27577 \end_inset
27578 </cell>
27579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27580 \begin_inset Text
27581
27582 \layout Standard
27583
27584 \series bold
27585 Where to get
27586
27587 \end_inset
27588 </cell>
27589 </row>
27590 <row topline="true">
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27592 \begin_inset Text
27593
27594 \layout Standard
27595 gpsim
27596 \begin_inset LatexCommand \index{gpsim (pic simulator)}
27597
27598 \end_inset
27599
27600
27601
27602 \end_inset
27603 </cell>
27604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27605 \begin_inset Text
27606
27607 \layout Standard
27608 PIC simulator
27609
27610 \end_inset
27611 </cell>
27612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27613 \begin_inset Text
27614
27615 \layout Standard
27616 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
27617
27618 \end_inset
27619
27620
27621
27622 \end_inset
27623 </cell>
27624 </row>
27625 <row topline="true">
27626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27627 \begin_inset Text
27628
27629 \layout Standard
27630 gputils
27631 \begin_inset LatexCommand \index{gputils (pic tools)}
27632
27633 \end_inset
27634
27635
27636
27637 \end_inset
27638 </cell>
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27640 \begin_inset Text
27641
27642 \layout Standard
27643 GNU PIC utilities
27644
27645 \end_inset
27646 </cell>
27647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27648 \begin_inset Text
27649
27650 \layout Standard
27651 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
27652
27653 \end_inset
27654
27655
27656
27657 \end_inset
27658 </cell>
27659 </row>
27660 <row topline="true">
27661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27662 \begin_inset Text
27663
27664 \layout Standard
27665 flP5
27666
27667 \end_inset
27668 </cell>
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27670 \begin_inset Text
27671
27672 \layout Standard
27673 PIC programmer
27674
27675 \end_inset
27676 </cell>
27677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27678 \begin_inset Text
27679
27680 \layout Standard
27681 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
27682
27683 \end_inset
27684
27685
27686
27687 \end_inset
27688 </cell>
27689 </row>
27690 <row topline="true">
27691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27692 \begin_inset Text
27693
27694 \layout Standard
27695 ec2drv/newcdb
27696
27697 \end_inset
27698 </cell>
27699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27700 \begin_inset Text
27701
27702 \layout Standard
27703 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27704  (Unix only)
27705
27706 \end_inset
27707 </cell>
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27709 \begin_inset Text
27710
27711 \layout Standard
27712 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27713
27714 \end_inset
27715
27716
27717
27718 \end_inset
27719 </cell>
27720 </row>
27721 <row topline="true">
27722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27723 \begin_inset Text
27724
27725 \layout Standard
27726 indent
27727 \begin_inset LatexCommand \index{indent (source formatting tool)}
27728
27729 \end_inset
27730
27731
27732
27733 \end_inset
27734 </cell>
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27736 \begin_inset Text
27737
27738 \layout Standard
27739 Formats C source - Master of the white spaces
27740
27741 \end_inset
27742 </cell>
27743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27744 \begin_inset Text
27745
27746 \layout Standard
27747 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27748
27749 \end_inset
27750
27751
27752
27753 \end_inset
27754 </cell>
27755 </row>
27756 <row topline="true">
27757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27758 \begin_inset Text
27759
27760 \layout Standard
27761 srecord
27762 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27763
27764 \end_inset
27765
27766
27767
27768 \end_inset
27769 </cell>
27770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27771 \begin_inset Text
27772
27773 \layout Standard
27774 Object file conversion, checksumming, ...
27775
27776 \end_inset
27777 </cell>
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27779 \begin_inset Text
27780
27781 \layout Standard
27782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27783
27784 \end_inset
27785
27786
27787
27788 \end_inset
27789 </cell>
27790 </row>
27791 <row topline="true">
27792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27793 \begin_inset Text
27794
27795 \layout Standard
27796 objdump
27797 \begin_inset LatexCommand \index{objdump (tool)}
27798
27799 \end_inset
27800
27801
27802
27803 \end_inset
27804 </cell>
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27806 \begin_inset Text
27807
27808 \layout Standard
27809 Object file conversion, ...
27810
27811 \end_inset
27812 </cell>
27813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27814 \begin_inset Text
27815
27816 \layout Standard
27817 Part of binutils (should be there anyway)
27818
27819 \end_inset
27820 </cell>
27821 </row>
27822 <row topline="true">
27823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27824 \begin_inset Text
27825
27826 \layout Standard
27827 cmon51
27828
27829 \end_inset
27830 </cell>
27831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27832 \begin_inset Text
27833
27834 \layout Standard
27835 8051 monitor (hex up-/download, single step, disassemble)
27836
27837 \end_inset
27838 </cell>
27839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27840 \begin_inset Text
27841
27842 \layout Standard
27843 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27844
27845 \end_inset
27846
27847
27848
27849 \end_inset
27850 </cell>
27851 </row>
27852 <row topline="true">
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27854 \begin_inset Text
27855
27856 \layout Standard
27857 doxygen
27858 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27859
27860 \end_inset
27861
27862
27863
27864 \end_inset
27865 </cell>
27866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27867 \begin_inset Text
27868
27869 \layout Standard
27870 Source code documentation system
27871
27872 \end_inset
27873 </cell>
27874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27875 \begin_inset Text
27876
27877 \layout Standard
27878 \begin_inset LatexCommand \url{http://www.doxygen.org}
27879
27880 \end_inset
27881
27882
27883
27884 \end_inset
27885 </cell>
27886 </row>
27887 <row topline="true">
27888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27889 \begin_inset Text
27890
27891 \layout Standard
27892 kdevelop
27893
27894 \end_inset
27895 </cell>
27896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27897 \begin_inset Text
27898
27899 \layout Standard
27900 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27901
27902 \end_inset
27903 </cell>
27904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27905 \begin_inset Text
27906
27907 \layout Standard
27908 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27909
27910 \end_inset
27911
27912
27913
27914 \end_inset
27915 </cell>
27916 </row>
27917 <row topline="true">
27918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27919 \begin_inset Text
27920
27921 \layout Standard
27922 paulmon
27923
27924 \end_inset
27925 </cell>
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27927 \begin_inset Text
27928
27929 \layout Standard
27930 8051 monitor (hex up-/download, single step, disassemble)
27931
27932 \end_inset
27933 </cell>
27934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27935 \begin_inset Text
27936
27937 \layout Standard
27938 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27939
27940 \end_inset
27941
27942
27943
27944 \end_inset
27945 </cell>
27946 </row>
27947 <row topline="true">
27948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27949 \begin_inset Text
27950
27951 \layout Standard
27952 splint
27953 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27954
27955 \end_inset
27956
27957
27958
27959 \end_inset
27960 </cell>
27961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27962 \begin_inset Text
27963
27964 \layout Standard
27965 Statically checks c sources (see 
27966 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27967
27968 \end_inset
27969
27970 )
27971
27972 \end_inset
27973 </cell>
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27975 \begin_inset Text
27976
27977 \layout Standard
27978 \begin_inset LatexCommand \url{http://www.splint.org}
27979
27980 \end_inset
27981
27982
27983
27984 \end_inset
27985 </cell>
27986 </row>
27987 <row topline="true" bottomline="true">
27988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27989 \begin_inset Text
27990
27991 \layout Standard
27992 ddd
27993 \begin_inset LatexCommand \index{DDD (debugger)}
27994
27995 \end_inset
27996
27997
27998
27999 \end_inset
28000 </cell>
28001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28002 \begin_inset Text
28003
28004 \layout Standard
28005 Debugger, serves nicely as GUI to SDCDB
28006 \begin_inset LatexCommand \index{SDCDB (debugger)}
28007
28008 \end_inset
28009
28010  (Unix only)
28011
28012 \end_inset
28013 </cell>
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28015 \begin_inset Text
28016
28017 \layout Standard
28018 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
28019
28020 \end_inset
28021
28022
28023
28024 \end_inset
28025 </cell>
28026 </row>
28027 </lyxtabular>
28028
28029 \end_inset
28030
28031
28032 \newline
28033
28034
28035 \layout Section
28036 Related documentation / recommended reading
28037
28038 \layout Standard
28039 \align left
28040 \begin_inset Tabular
28041 <lyxtabular version="3" rows="7" columns="3">
28042 <features>
28043 <column alignment="left" valignment="top" leftline="true" width="0pt">
28044 <column alignment="left" valignment="top" leftline="true" width="0">
28045 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28046 <row topline="true" bottomline="true">
28047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28048 \begin_inset Text
28049
28050 \layout Standard
28051
28052 \series bold
28053 Name
28054
28055 \end_inset
28056 </cell>
28057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28058 \begin_inset Text
28059
28060 \layout Standard
28061
28062 \series bold
28063 Subject / Title
28064
28065 \end_inset
28066 </cell>
28067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28068 \begin_inset Text
28069
28070 \layout Standard
28071
28072 \series bold
28073 Where to get
28074
28075 \end_inset
28076 </cell>
28077 </row>
28078 <row topline="true">
28079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28080 \begin_inset Text
28081
28082 \layout Standard
28083
28084 \family roman
28085 \series medium
28086 \shape up
28087 \size normal
28088 \emph off
28089 \bar no
28090 \noun off
28091 \color none
28092 c-refcard.pdf
28093
28094 \end_inset
28095 </cell>
28096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28097 \begin_inset Text
28098
28099 \layout Standard
28100 C Reference Card
28101 \begin_inset LatexCommand \index{C Reference card}
28102
28103 \end_inset
28104
28105 , 2 pages
28106
28107 \end_inset
28108 </cell>
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28110 \begin_inset Text
28111
28112 \layout Standard
28113 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
28114
28115 \end_inset
28116
28117
28118
28119 \end_inset
28120 </cell>
28121 </row>
28122 <row topline="true">
28123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28124 \begin_inset Text
28125
28126 \layout Standard
28127 c-faq
28128
28129 \end_inset
28130 </cell>
28131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28132 \begin_inset Text
28133
28134 \layout Standard
28135 C-FAQ
28136 \begin_inset LatexCommand \index{C FAQ}
28137
28138 \end_inset
28139
28140
28141
28142 \end_inset
28143 </cell>
28144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28145 \begin_inset Text
28146
28147 \layout Standard
28148 \begin_inset LatexCommand \url{http://www.c-faq.com}
28149
28150 \end_inset
28151
28152
28153
28154 \end_inset
28155 </cell>
28156 </row>
28157 <row topline="true">
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28159 \begin_inset Text
28160
28161 \layout Standard
28162 ISO/IEC 9899:TC2
28163
28164 \end_inset
28165 </cell>
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28167 \begin_inset Text
28168
28169 \layout Standard
28170 \begin_inset Quotes sld
28171 \end_inset
28172
28173 C-Standard
28174 \begin_inset Quotes srd
28175 \end_inset
28176
28177
28178
28179 \end_inset
28180 </cell>
28181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28182 \begin_inset Text
28183
28184 \layout Standard
28185
28186 \size footnotesize
28187 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
28188
28189 \end_inset
28190
28191
28192
28193 \end_inset
28194 </cell>
28195 </row>
28196 <row topline="true">
28197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28198 \begin_inset Text
28199
28200 \layout Standard
28201 ISO/IEC DTR 18037
28202
28203 \end_inset
28204 </cell>
28205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28206 \begin_inset Text
28207
28208 \layout Standard
28209 \begin_inset Quotes sld
28210 \end_inset
28211
28212 Extensions for Embedded C
28213 \begin_inset Quotes srd
28214 \end_inset
28215
28216
28217
28218 \end_inset
28219 </cell>
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_inset Text
28222
28223 \layout Standard
28224
28225 \size footnotesize
28226 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
28227
28228 \end_inset
28229
28230
28231
28232 \end_inset
28233 </cell>
28234 </row>
28235 <row topline="true">
28236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28237 \begin_inset Text
28238
28239 \layout Standard
28240
28241
28242 \end_inset
28243 </cell>
28244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28245 \begin_inset Text
28246
28247 \layout Standard
28248 Latest datasheet of target CPU
28249
28250 \end_inset
28251 </cell>
28252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28253 \begin_inset Text
28254
28255 \layout Standard
28256 vendor
28257
28258 \end_inset
28259 </cell>
28260 </row>
28261 <row topline="true" bottomline="true">
28262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28263 \begin_inset Text
28264
28265 \layout Standard
28266
28267
28268 \end_inset
28269 </cell>
28270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28271 \begin_inset Text
28272
28273 \layout Standard
28274 Revision history of datasheet
28275
28276 \end_inset
28277 </cell>
28278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28279 \begin_inset Text
28280
28281 \layout Standard
28282 vendor
28283
28284 \end_inset
28285 </cell>
28286 </row>
28287 </lyxtabular>
28288
28289 \end_inset
28290
28291
28292 \newline
28293
28294
28295 \layout Section
28296 Application notes specifically for SDCC
28297
28298 \layout Standard
28299 SDCC makes no claims about the completeness of this list and about up-to-datenes
28300 s or correctness of the application notes
28301 \begin_inset LatexCommand \index{Application notes}
28302
28303 \end_inset
28304
28305 .
28306
28307 \layout Standard
28308 \align left
28309
28310 \size footnotesize
28311 \begin_inset Tabular
28312 <lyxtabular version="3" rows="7" columns="3">
28313 <features>
28314 <column alignment="block" valignment="top" leftline="true" width="17col%">
28315 <column alignment="block" valignment="top" leftline="true" width="27col%">
28316 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
28317 <row topline="true" bottomline="true">
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28319 \begin_inset Text
28320
28321 \layout Standard
28322
28323 \series bold
28324 \size footnotesize
28325 Vendor
28326
28327 \end_inset
28328 </cell>
28329 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
28330 \begin_inset Text
28331
28332 \layout Standard
28333
28334 \series bold
28335 \size footnotesize
28336 Subject / Title
28337
28338 \end_inset
28339 </cell>
28340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28341 \begin_inset Text
28342
28343 \layout Standard
28344
28345 \series bold
28346 \size footnotesize
28347 Where to get
28348
28349 \end_inset
28350 </cell>
28351 </row>
28352 <row topline="true">
28353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28354 \begin_inset Text
28355
28356 \layout Standard
28357
28358 \size footnotesize
28359 Maxim / Dallas
28360
28361 \end_inset
28362 </cell>
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28364 \begin_inset Text
28365
28366 \layout Standard
28367
28368 \size footnotesize
28369 Using the SDCC Compiler for the DS80C400
28370 \begin_inset LatexCommand \index{DS80C400}
28371
28372 \end_inset
28373
28374
28375
28376 \end_inset
28377 </cell>
28378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28379 \begin_inset Text
28380
28381 \layout Standard
28382
28383 \size footnotesize
28384 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
28385
28386 \end_inset
28387
28388
28389
28390 \end_inset
28391 </cell>
28392 </row>
28393 <row topline="true">
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28395 \begin_inset Text
28396
28397 \layout Standard
28398
28399 \size footnotesize
28400 Maxim / Dallas
28401
28402 \end_inset
28403 </cell>
28404 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
28405 \begin_inset Text
28406
28407 \layout Standard
28408
28409 \size footnotesize
28410 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
28411 \begin_inset LatexCommand \index{DS89C4x0}
28412
28413 \end_inset
28414
28415  Family of Microcontrollers
28416
28417 \end_inset
28418 </cell>
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28420 \begin_inset Text
28421
28422 \layout Standard
28423
28424 \size footnotesize
28425 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
28426
28427 \end_inset
28428
28429
28430
28431 \end_inset
28432 </cell>
28433 </row>
28434 <row topline="true">
28435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28436 \begin_inset Text
28437
28438 \layout Standard
28439
28440 \size footnotesize
28441 Silicon Laboratories / Cygnal
28442
28443 \end_inset
28444 </cell>
28445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28446 \begin_inset Text
28447
28448 \layout Standard
28449
28450 \size footnotesize
28451 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
28452 \begin_inset LatexCommand \index{IDE}
28453
28454 \end_inset
28455
28456
28457
28458 \end_inset
28459 </cell>
28460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28461 \begin_inset Text
28462
28463 \layout Standard
28464
28465 \size footnotesize
28466 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
28467
28468 \end_inset
28469
28470
28471
28472 \end_inset
28473 </cell>
28474 </row>
28475 <row topline="true">
28476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28477 \begin_inset Text
28478
28479 \layout Standard
28480
28481 \size footnotesize
28482 Ramtron / Goal Semiconductor
28483
28484 \end_inset
28485 </cell>
28486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28487 \begin_inset Text
28488
28489 \layout Standard
28490
28491 \size footnotesize
28492 Interfacing SDCC to Syn and Textpad
28493
28494 \end_inset
28495 </cell>
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28497 \begin_inset Text
28498
28499 \layout Standard
28500
28501 \size footnotesize
28502 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28503
28504 \end_inset
28505
28506
28507
28508 \end_inset
28509 </cell>
28510 </row>
28511 <row topline="true">
28512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28513 \begin_inset Text
28514
28515 \layout Standard
28516
28517 \size footnotesize
28518 Ramtron / Goal Semiconductor
28519
28520 \end_inset
28521 </cell>
28522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28523 \begin_inset Text
28524
28525 \layout Standard
28526
28527 \size footnotesize
28528 Installing and Configuring SDCC and Crimson Editor 
28529
28530 \end_inset
28531 </cell>
28532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28533 \begin_inset Text
28534
28535 \layout Standard
28536
28537 \size footnotesize
28538 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28539
28540 \end_inset
28541
28542
28543
28544 \end_inset
28545 </cell>
28546 </row>
28547 <row topline="true" bottomline="true">
28548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28549 \begin_inset Text
28550
28551 \layout Standard
28552
28553 \size footnotesize
28554 Texas Instruments
28555
28556 \end_inset
28557 </cell>
28558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28559 \begin_inset Text
28560
28561 \layout Standard
28562
28563 \size footnotesize
28564 MSC12xx Programming with SDCC
28565
28566 \end_inset
28567 </cell>
28568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28569 \begin_inset Text
28570
28571 \layout Standard
28572
28573 \size footnotesize
28574 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
28575
28576 \end_inset
28577
28578
28579
28580 \end_inset
28581 </cell>
28582 </row>
28583 </lyxtabular>
28584
28585 \end_inset
28586
28587
28588
28589 \layout Section
28590 Some Questions
28591
28592 \layout Standard
28593 Some questions answered, some pointers given - it might be time to in turn
28594  ask 
28595 \emph on
28596 you
28597 \emph default
28598  some questions: 
28599
28600 \layout Itemize
28601 can you solve your project with the selected microcontroller? Would you
28602  find out early or rather late that your target is too small/slow/whatever?
28603  Can you switch to a slightly better device if it doesn't fit?
28604
28605 \layout Itemize
28606 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
28607  and/or another programming language be more adequate? Would an operating
28608  system on the target device help?
28609
28610 \layout Itemize
28611 if you solved the problem, will the marketing department be happy?
28612
28613 \layout Itemize
28614 if the marketing department is happy, will customers be happy?
28615
28616 \layout Itemize
28617 if you're the project manager, marketing department and maybe even the customer
28618  in one person, have you tried to see the project from the outside?
28619
28620 \layout Itemize
28621 is the project done if you think it is done? Or is just that other interface/pro
28622 tocol/feature/configuration/option missing? How about website, manual(s),
28623  internationali(z|s)ation, packaging, labels, 2nd source for components,
28624  electromagnetic compatability/interference, documentation for production,
28625  production test software, update mechanism, patent issues?
28626
28627 \layout Itemize
28628 is your project adequately positioned in that magic triangle: fame, fortune,
28629  fun?
28630
28631 \layout Standard
28632 Maybe not all answers to these questions are known and some answers may
28633  even be 
28634 \emph on
28635 no
28636 \emph default
28637 , nevertheless knowing these questions may help you to avoid burnout
28638 \begin_inset Foot
28639 collapsed false
28640
28641 \layout Standard
28642 burnout is bad for electronic devices, programmers and motorcycle tyres
28643
28644 \end_inset
28645
28646 .
28647  Chances are you didn't want to hear some of them...
28648
28649 \layout Chapter
28650 Support
28651 \begin_inset LatexCommand \index{Support}
28652
28653 \end_inset
28654
28655
28656
28657 \layout Standard
28658 SDCC has grown to be a large project.
28659  The compiler alone (without the preprocessor, assembler and linker) is
28660  well over 150,000 lines of code (blank stripped).
28661  The open source nature of this project is a key to its continued growth
28662  and support.
28663  You gain the benefit and support of many active software developers and
28664  end users.
28665  Is SDCC perfect? No, that's why we need your help.
28666  The developers take pride in fixing reported bugs.
28667  You can help by reporting the bugs and helping other SDCC users.
28668  There are lots of ways to contribute, and we encourage you to take part
28669  in making SDCC a great software package.
28670  
28671
28672 \layout Standard
28673 The SDCC project is hosted on the SDCC sourceforge site at 
28674 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
28675
28676 \end_inset
28677
28678 .
28679  You'll find the complete set of mailing lists
28680 \begin_inset LatexCommand \index{Mailing list(s)}
28681
28682 \end_inset
28683
28684 , forums, bug reporting system, patch submission
28685 \begin_inset LatexCommand \index{Patch submission}
28686
28687 \end_inset
28688
28689  system, download
28690 \begin_inset LatexCommand \index{download}
28691
28692 \end_inset
28693
28694  area and Subversion code repository
28695 \begin_inset LatexCommand \index{Subversion code repository}
28696
28697 \end_inset
28698
28699  there.
28700
28701 \layout Section
28702 Reporting Bugs
28703 \begin_inset LatexCommand \index{Bug reporting}
28704
28705 \end_inset
28706
28707
28708 \begin_inset LatexCommand \index{Reporting bugs}
28709
28710 \end_inset
28711
28712
28713
28714 \layout Standard
28715 The recommended way of reporting bugs is using the infrastructure of the
28716  sourceforge site.
28717  You can follow the status of bug reports there and have an overview about
28718  the known bugs.
28719
28720 \layout Standard
28721 Bug reports are automatically forwarded to the developer mailing list and
28722  will be fixed ASAP.
28723  When reporting a bug, it is very useful to include a small test program
28724  (the smaller the better) which reproduces the problem.
28725  If you can isolate the problem by looking at the generated assembly code,
28726  this can be very helpful.
28727  Compiling your program with the -
28728 \begin_inset ERT
28729 status Collapsed
28730
28731 \layout Standard
28732
28733
28734 \backslash
28735 /
28736
28737 \end_inset
28738
28739 -dumpall
28740 \begin_inset LatexCommand \index{-\/-dumpall}
28741
28742 \end_inset
28743
28744  option can sometimes be useful in locating optimization problems.
28745  When reporting a bug please make sure you:
28746
28747 \layout Enumerate
28748 Attach the code you are compiling with SDCC.
28749  
28750
28751 \layout Enumerate
28752 Specify the exact command you use to run SDCC, or attach your Makefile.
28753  
28754
28755 \layout Enumerate
28756 Specify the SDCC version (type "
28757 \family sans
28758 \series bold
28759 sdcc -v
28760 \family default
28761 \series default
28762 "), your platform, and operating system.
28763  
28764
28765 \layout Enumerate
28766 Provide an exact copy of any error message or incorrect output.
28767  
28768
28769 \layout Enumerate
28770 Put something meaningful in the subject of your message.
28771
28772 \layout Standard
28773 Please attempt to include these 5 important parts, as applicable, in all
28774  requests for support or when reporting any problems or bugs with SDCC.
28775  Though this will make your message lengthy, it will greatly improve your
28776  chance that SDCC users and developers will be able to help you.
28777  Some SDCC developers are frustrated by bug reports without code provided
28778  that they can use to reproduce and ultimately fix the problem, so please
28779  be sure to provide sample code if you are reporting a bug! 
28780
28781 \layout Standard
28782 Please have a short check that you are using a recent version of SDCC and
28783  the bug is not yet known.
28784  This is the link for reporting bugs: 
28785 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28786
28787 \end_inset
28788
28789 .
28790  With SDCC on average having more than 200 downloads
28791 \begin_inset LatexCommand \index{download}
28792
28793 \end_inset
28794
28795  on sourceforge per day
28796 \begin_inset Foot
28797 collapsed false
28798
28799 \layout Standard
28800 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28801  between 2002 and 2005.
28802  This does not include other methods of distribution.
28803
28804 \end_inset
28805
28806  there must be some users.
28807  So it's not exactly easy to find a new bug.
28808  If you find one we need it: 
28809 \emph on
28810 reporting bugs is good
28811 \emph default
28812 .
28813
28814 \layout Section
28815 Requesting Features
28816 \begin_inset LatexCommand \label{sub:Requesting-Features}
28817
28818 \end_inset
28819
28820
28821 \begin_inset LatexCommand \index{Feature request}
28822
28823 \end_inset
28824
28825
28826 \begin_inset LatexCommand \index{Requesting features}
28827
28828 \end_inset
28829
28830
28831
28832 \layout Standard
28833 Like bug reports feature requests are forwarded to the developer mailing
28834  list.
28835  This is the link for requesting features: 
28836 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28837
28838 \end_inset
28839
28840 .
28841
28842 \layout Section
28843 Submitting patches
28844
28845 \layout Standard
28846 Like bug reports contributed patches are forwarded to the developer mailing
28847  list.
28848  This is the link for submitting patches
28849 \begin_inset LatexCommand \index{Patch submission}
28850
28851 \end_inset
28852
28853
28854 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28855
28856 \end_inset
28857
28858 .
28859
28860 \layout Standard
28861 You need to specify some parameters to the 
28862 \family typewriter
28863 diff
28864 \family default
28865  command for the patches to be useful.
28866  If you modified more than one file a patch created f.e.
28867  with 
28868 \family sans
28869 \series bold
28870
28871 \begin_inset Quotes sld
28872 \end_inset
28873
28874 diff -Naur unmodified_directory modified_directory >my_changes.patch
28875 \begin_inset Quotes srd
28876 \end_inset
28877
28878
28879 \family default
28880 \series default
28881  will be fine, otherwise 
28882 \family sans
28883 \series bold
28884
28885 \begin_inset Quotes sld
28886 \end_inset
28887
28888 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28889 \begin_inset Quotes srd
28890 \end_inset
28891
28892
28893 \series default
28894  
28895 \family default
28896 will do.
28897
28898 \layout Section
28899 Getting Help
28900
28901 \layout Standard
28902 These links should take you directly to the 
28903 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28904
28905 \end_inset
28906
28907
28908 \begin_inset Foot
28909 collapsed false
28910
28911 \layout Standard
28912 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28913  automated messages (mid 2003)
28914
28915 \end_inset
28916
28917  and the 
28918 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28919
28920 \end_inset
28921
28922 , lists
28923 \begin_inset LatexCommand \index{Mailing list(s)}
28924
28925 \end_inset
28926
28927  and forums are archived and searchable so if you are lucky someone already
28928  had a similar problem.
28929  While mails to the lists themselves are delivered promptly their web front
28930  end on sourceforge sometimes shows a severe time lag (up to several weeks),
28931  if you're seriously using SDCC please consider subscribing to the lists.
28932
28933 \layout Section
28934 ChangeLog
28935
28936 \layout Standard
28937 You can follow the status of the Subversion version
28938 \begin_inset LatexCommand \index{version}
28939
28940 \end_inset
28941
28942  of SDCC by watching the Changelog
28943 \begin_inset LatexCommand \index{Changelog}
28944
28945 \end_inset
28946
28947  in the Subversion repository
28948 \size footnotesize
28949  
28950 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28951
28952 \end_inset
28953
28954 .
28955
28956 \layout Section
28957 Subversion Source Code Repository
28958
28959 \layout Standard
28960 The output of 
28961 \family sans
28962 \series bold
28963 sdcc --version
28964 \family default
28965 \series default
28966  or the filenames of the snapshot versions of SDCC include date and its
28967  Subversion
28968 \begin_inset LatexCommand \index{Subversion code repository}
28969
28970 \end_inset
28971
28972  number.
28973  Subversion allows to download the source of recent or previous versions
28974  
28975 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28976
28977 \end_inset
28978
28979  (by number or by date).
28980  An on-line source code browser and detailled instructions are also available
28981  there.
28982  SDCC versions starting from 1999 up to now are available (currently the
28983  versions prior to the conversion from cvs
28984 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28985
28986 \end_inset
28987
28988  to Subversion (April 2006) are either by accessible by Subversion or by
28989  cvs).
28990
28991 \layout Section
28992 Release policy
28993 \begin_inset LatexCommand \index{Release policy}
28994
28995 \end_inset
28996
28997
28998
28999 \layout Standard
29000 Historically there often were long delays between official releases and
29001  the sourceforge download area tends to get not updated at all.
29002  Excuses in the past might have referred to problems with live range analysis,
29003  but as this was fixed a while ago, the current problem is that another
29004  excuse has to be found.
29005  Kidding aside, we have to get better there! On the other hand there are
29006  daily snapshots available at 
29007 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
29008
29009 \end_inset
29010
29011 , and you can always build the very last version (hopefully with many bugs
29012  fixed, and features added) from the source code available at 
29013 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
29014
29015 \end_inset
29016
29017 .
29018  A release wiki
29019 \begin_inset LatexCommand \index{wiki}
29020
29021 \end_inset
29022
29023
29024 \begin_inset LatexCommand \index{Release wiki}
29025
29026 \end_inset
29027
29028  at 
29029 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
29030
29031 \end_inset
29032
29033  also holds some information about past and future releases.
29034
29035 \layout Section
29036 Examples
29037 \begin_inset LatexCommand \index{Examples}
29038
29039 \end_inset
29040
29041
29042
29043 \layout Standard
29044 You'll find some small examples in the directory 
29045 \emph on
29046 sdcc/device/examples/.
29047  
29048 \emph default
29049 More examples and libraries are available at
29050 \emph on
29051  The SDCC Open Knowledge Resource 
29052 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
29053
29054 \end_inset
29055
29056  
29057 \emph default
29058 web site or at 
29059 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
29060
29061 \end_inset
29062
29063 .
29064
29065 \layout Standard
29066 \begin_inset Note
29067 collapsed true
29068
29069 \layout Standard
29070 I did insert a reference to Paul's web site here although it seems rather
29071  dedicated to a specific 8032 board (I think it's okay because it f.e.
29072  shows LCD/Harddisc interface and has a free 8051 monitor.
29073  Independent 8032 board vendors face hard competition of heavily subsidized
29074  development boards anyway).
29075
29076 \layout Standard
29077 Maybe we should include some links to real world applications.
29078  Preferably pointer to pointers (one for each architecture) so this stays
29079  manageable here?
29080
29081 \end_inset
29082
29083
29084
29085 \layout Section
29086 Quality control
29087 \begin_inset LatexCommand \label{sec:Quality-control}
29088
29089 \end_inset
29090
29091
29092 \begin_inset LatexCommand \index{Quality control}
29093
29094 \end_inset
29095
29096
29097
29098 \layout Standard
29099 The compiler is passed through snaphot build compile and build checks.
29100  The so called 
29101 \shape italic
29102 regression tests
29103 \shape default
29104
29105 \begin_inset LatexCommand \index{Regression test}
29106
29107 \end_inset
29108
29109  check that SDCC itself compiles flawlessly on several host platforms (i386,
29110  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
29111  the quality of the code generated by SDCC by running the code for several
29112  target platforms through simulators.
29113  The regression test suite comprises more than 100 files which expand to
29114  more than 500 test cases which include more than 4500 tests.
29115  The results of these tests are published daily on SDCC's snapshot page
29116  (click on the red or green symbols on the right side of 
29117 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
29118
29119 \end_inset
29120
29121 ).
29122
29123 \layout Standard
29124 There is a separate document 
29125 \shape italic
29126 test_suite.pdf 
29127 \begin_inset LatexCommand \index{Test suite}
29128
29129 \end_inset
29130
29131
29132 \shape default
29133  
29134 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29135
29136 \end_inset
29137
29138  about the regression test suite.
29139
29140 \layout Standard
29141 You'll find the test code in the directory 
29142 \shape italic
29143 sdcc/support/regression
29144 \shape default
29145 .
29146  You can run these tests manually by running 
29147 \family sans
29148 make
29149 \family default
29150  in this directory (or f.e.
29151  
29152 \family sans
29153 \series bold
29154
29155 \begin_inset Quotes sld
29156 \end_inset
29157
29158 make test-mcs51
29159 \begin_inset Quotes srd
29160 \end_inset
29161
29162
29163 \family default
29164 \series default
29165  if you don't want to run the complete tests).
29166  The test code might also be interesting if you want to look for examples
29167 \begin_inset LatexCommand \index{Examples}
29168
29169 \end_inset
29170
29171  checking corner cases of SDCC or if you plan to submit patches
29172 \begin_inset LatexCommand \index{Patch submission}
29173
29174 \end_inset
29175
29176 .
29177
29178 \layout Standard
29179 The 14bit pic port uses a different set of regression tests 
29180 \begin_inset LatexCommand \index{Regression test (PIC14)}
29181
29182 \end_inset
29183
29184 , you'll find them in the directory 
29185 \shape italic
29186 sdcc/src/regression
29187 \shape default
29188 .
29189
29190 \layout Section
29191 Use of SDCC in Education
29192
29193 \layout Standard
29194 In short: 
29195 \emph on
29196 highly
29197 \emph default
29198  encouraged
29199 \begin_inset Foot
29200 collapsed false
29201
29202 \layout Standard
29203 the phrase "use in education" might evoke the association "
29204 \emph on
29205 only
29206 \emph default
29207  fit for use in education".
29208  This connotation is not intended but nevertheless risked as the licensing
29209  of SDCC makes it difficult to offer educational discounts
29210
29211 \end_inset
29212
29213 .
29214  If your rationales are to:
29215
29216 \layout Enumerate
29217 give students a chance to understand the 
29218 \emph on
29219 complete
29220 \emph default
29221  steps of code generation
29222
29223 \layout Enumerate
29224 have a curriculum that can be extended for years.
29225  Then you could use an fpga board as target and your curriculum will seamlessly
29226  extend from logic synthesis (
29227 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
29228
29229 \end_inset
29230
29231
29232 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
29233
29234 \end_inset
29235
29236 ), over assembly programming, to C to FPGA compilers (
29237 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
29238
29239 \end_inset
29240
29241 ) and to C.
29242
29243 \layout Enumerate
29244 be able to insert excursions about skills like using a revision control
29245  system, submitting/applying patches, using a type-setting (as opposed to
29246  word-processing) engine LyX/LaTeX, using 
29247 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
29248
29249 \end_inset
29250
29251 , following some 
29252 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
29253
29254 \end_inset
29255
29256 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
29257  Source Software, CPU simulation, compiler regression tests
29258 \begin_inset LatexCommand \index{Regression test}
29259
29260 \end_inset
29261
29262 .
29263  
29264 \newline
29265 And if there should be a shortage of ideas then you can always point students
29266  to the ever-growing feature request list 
29267 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
29268
29269 \end_inset
29270
29271 .
29272
29273 \layout Enumerate
29274 not tie students to a specific host platform and instead allow them to use
29275  a host platform of 
29276 \emph on
29277 their
29278 \emph default
29279  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
29280  eventually 
29281 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
29282
29283 \end_inset
29284
29285 )
29286
29287 \layout Enumerate
29288 not encourage students to use illegal copies of educational software
29289
29290 \layout Enumerate
29291 be immune to licensing/availability/price changes of the chosen tool chain
29292
29293 \layout Enumerate
29294 be able to change to a new target platform without having to adopt a new
29295  tool chain
29296
29297 \layout Enumerate
29298 have complete control over and insight into the tool chain
29299
29300 \layout Enumerate
29301 make your students aware about the pros and cons of open source software
29302  development
29303
29304 \layout Enumerate
29305 give back to the public as you are probably at least partially publically
29306  funded
29307
29308 \layout Enumerate
29309 give students a chance to publically prove their skills and to possibly
29310  see a world wide impact
29311
29312 \layout Standard
29313 \pagebreak_bottom 
29314 then SDCC is probably among the first choices.
29315  Well, probably SDCC might be the only choice.
29316
29317
29318 \layout Chapter
29319 SDCC Technical Data
29320
29321 \layout Section
29322 Optimizations
29323 \begin_inset LatexCommand \index{Optimizations}
29324
29325 \end_inset
29326
29327
29328
29329 \layout Standard
29330 SDCC performs a host of standard optimizations in addition to some MCU specific
29331  optimizations.
29332  
29333
29334 \layout Subsection
29335 Sub-expression Elimination
29336 \begin_inset LatexCommand \index{Subexpression elimination}
29337
29338 \end_inset
29339
29340
29341
29342 \layout Standard
29343 The compiler does local and 
29344 \emph on
29345 g
29346 \emph default
29347 lobal 
29348 \emph on
29349 c
29350 \emph default
29351 ommon 
29352 \emph on
29353 s
29354 \emph default
29355 ubexpression 
29356 \emph on
29357 e
29358 \emph default
29359 limination, e.g.: 
29360
29361 \layout Verse
29362
29363 \family typewriter
29364 i = x + y + 1; 
29365 \newline
29366 j = x + y;
29367
29368 \layout Standard
29369 will be translated to
29370
29371 \layout Verse
29372
29373 \family typewriter
29374 iTemp = x + y; 
29375 \newline
29376 i = iTemp + 1; 
29377 \newline
29378 j = iTemp;
29379
29380 \layout Standard
29381 Some subexpressions are not as obvious as the above example, e.g.:
29382
29383 \layout Verse
29384
29385 \family typewriter
29386 a->b[i].c = 10; 
29387 \newline
29388 a->b[i].d = 11;
29389
29390 \layout Standard
29391 In this case the address arithmetic a->b[i] will be computed only once;
29392  the equivalent code in C would be.
29393
29394 \layout Verse
29395
29396 \family typewriter
29397 iTemp = a->b[i]; 
29398 \newline
29399 iTemp.c = 10; 
29400 \newline
29401 iTemp.d = 11;
29402
29403 \layout Standard
29404 The compiler will try to keep these temporary variables in registers.
29405
29406 \layout Subsection
29407 Dead-Code Elimination
29408 \begin_inset LatexCommand \index{Dead-code elimination}
29409
29410 \end_inset
29411
29412
29413
29414 \layout Verse
29415
29416 \family typewriter
29417 int global;
29418 \newline
29419
29420 \newline
29421 void f () { 
29422 \newline
29423 \SpecialChar ~
29424 \SpecialChar ~
29425 int i; 
29426 \newline
29427 \SpecialChar ~
29428 \SpecialChar ~
29429 i = 1; \SpecialChar ~
29430 \SpecialChar ~
29431 \SpecialChar ~
29432 \SpecialChar ~
29433 \SpecialChar ~
29434 /* dead store */ 
29435 \newline
29436 \SpecialChar ~
29437 \SpecialChar ~
29438 global = 1;\SpecialChar ~
29439 /* dead
29440  store */ 
29441 \newline
29442 \SpecialChar ~
29443 \SpecialChar ~
29444 global = 2; 
29445 \newline
29446 \SpecialChar ~
29447 \SpecialChar ~
29448 return; 
29449 \newline
29450 \SpecialChar ~
29451 \SpecialChar ~
29452 global = 3;\SpecialChar ~
29453 /* unreachable */ 
29454 \newline
29455 }
29456
29457 \layout Standard
29458 will be changed to
29459
29460 \layout Verse
29461
29462 \family typewriter
29463 int global;
29464 \newline
29465
29466 \newline
29467 void f () {
29468 \newline
29469 \SpecialChar ~
29470 \SpecialChar ~
29471 global = 2; 
29472 \newline
29473 }
29474
29475 \layout Subsection
29476 Copy-Propagation
29477 \begin_inset LatexCommand \index{Copy propagation}
29478
29479 \end_inset
29480
29481
29482
29483 \layout Verse
29484
29485 \family typewriter
29486 int f() { 
29487 \newline
29488 \SpecialChar ~
29489 \SpecialChar ~
29490 int i, j; 
29491 \newline
29492 \SpecialChar ~
29493 \SpecialChar ~
29494 i = 10; 
29495 \newline
29496 \SpecialChar ~
29497 \SpecialChar ~
29498 j = i; 
29499 \newline
29500 \SpecialChar ~
29501 \SpecialChar ~
29502 return j; 
29503 \newline
29504 }
29505
29506 \layout Standard
29507 will be changed to 
29508
29509 \layout Verse
29510
29511 \family typewriter
29512 int f() { 
29513 \newline
29514 \SpecialChar ~
29515 \SpecialChar ~
29516 int i, j; 
29517 \newline
29518 \SpecialChar ~
29519 \SpecialChar ~
29520 i = 10; 
29521 \newline
29522 \SpecialChar ~
29523 \SpecialChar ~
29524 j = 10; 
29525 \newline
29526 \SpecialChar ~
29527 \SpecialChar ~
29528 return 10; 
29529 \newline
29530 }
29531
29532 \layout Standard
29533 Note: the dead stores created by this copy propagation will be eliminated
29534  by dead-code elimination.
29535
29536 \layout Subsection
29537 Loop Optimizations
29538 \begin_inset LatexCommand \index{Loop optimization}
29539
29540 \end_inset
29541
29542
29543 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
29544
29545 \end_inset
29546
29547
29548
29549 \layout Standard
29550 Two types of loop optimizations are done by SDCC 
29551 \emph on
29552 loop invariant
29553 \emph default
29554  lifting and
29555 \emph on
29556  strength reduction
29557 \emph default
29558  of loop induction variables.
29559  In addition to the strength reduction the optimizer marks the induction
29560  variables and the register allocator tries to keep the induction variables
29561  in registers for the duration of the loop.
29562  Because of this preference of the register allocator
29563 \begin_inset LatexCommand \index{Register allocation}
29564
29565 \end_inset
29566
29567 , loop induction optimization causes an increase in register pressure, which
29568  may cause unwanted spilling of other temporary variables into the stack
29569 \begin_inset LatexCommand \index{stack}
29570
29571 \end_inset
29572
29573  / data space.
29574  The compiler will generate a warning message when it is forced to allocate
29575  extra space either on the stack or data space.
29576  If this extra space allocation is undesirable then induction optimization
29577  can be eliminated either for the entire source file (with -
29578 \begin_inset ERT
29579 status Collapsed
29580
29581 \layout Standard
29582
29583
29584 \backslash
29585 /
29586
29587 \end_inset
29588
29589 -noinduction option) or for a given function only using #pragma\SpecialChar ~
29590 noinduction
29591 \begin_inset LatexCommand \index{\#pragma noinduction}
29592
29593 \end_inset
29594
29595 .
29596 \newline
29597
29598 \newline
29599 Loop Invariant:
29600
29601 \layout Verse
29602
29603 \family typewriter
29604 for (i = 0 ; i < 100 ; i ++) 
29605 \newline
29606 \SpecialChar ~
29607 \SpecialChar ~
29608 \SpecialChar ~
29609 \SpecialChar ~
29610 f += k + l;
29611
29612 \layout Standard
29613 changed to
29614
29615 \layout Verse
29616
29617 \family typewriter
29618 itemp = k + l; 
29619 \newline
29620 for (i = 0; i < 100; i++) 
29621 \newline
29622 \SpecialChar ~
29623 \SpecialChar ~
29624 \SpecialChar ~
29625 \SpecialChar ~
29626 f += itemp;
29627
29628 \layout Standard
29629 As mentioned previously some loop invariants are not as apparent, all static
29630  address computations are also moved out of the loop.
29631 \newline
29632
29633 \newline
29634 Strength Reduction
29635 \begin_inset LatexCommand \index{Strength reduction}
29636
29637 \end_inset
29638
29639 , this optimization substitutes an expression by a cheaper expression:
29640
29641 \layout Verse
29642
29643 \family typewriter
29644 for (i=0;i < 100; i++)
29645 \newline
29646 \SpecialChar ~
29647 \SpecialChar ~
29648 \SpecialChar ~
29649 \SpecialChar ~
29650 ar[i*5] = i*3;
29651
29652 \layout Standard
29653 changed to
29654
29655 \layout Verse
29656
29657 \family typewriter
29658 itemp1 = 0; 
29659 \newline
29660 itemp2 = 0; 
29661 \newline
29662 for (i=0;i< 100;i++) { 
29663 \newline
29664 \SpecialChar ~
29665 \SpecialChar ~
29666 \SpecialChar ~
29667 \SpecialChar ~
29668 ar[itemp1] = itemp2; 
29669 \newline
29670 \SpecialChar ~
29671 \SpecialChar ~
29672 \SpecialChar ~
29673 \SpecialChar ~
29674 itemp1
29675  += 5; 
29676 \newline
29677 \SpecialChar ~
29678 \SpecialChar ~
29679 \SpecialChar ~
29680 \SpecialChar ~
29681 itemp2 += 3; 
29682 \newline
29683 }
29684
29685 \layout Standard
29686 The more expensive multiplication
29687 \begin_inset LatexCommand \index{Multiplication}
29688
29689 \end_inset
29690
29691  is changed to a less expensive addition.
29692
29693 \layout Subsection
29694 Loop Reversing
29695 \begin_inset LatexCommand \index{Loop reversing}
29696
29697 \end_inset
29698
29699
29700
29701 \layout Standard
29702 This optimization is done to reduce the overhead of checking loop boundaries
29703  for every iteration.
29704  Some simple loops can be reversed and implemented using a 
29705 \begin_inset Quotes eld
29706 \end_inset
29707
29708 decrement and jump if not zero
29709 \begin_inset Quotes erd
29710 \end_inset
29711
29712  instruction.
29713  SDCC checks for the following criterion to determine if a loop is reversible
29714  (note: more sophisticated compilers use data-dependency analysis to make
29715  this determination, SDCC uses a more simple minded analysis).
29716
29717 \layout Itemize
29718 The 'for' loop is of the form 
29719 \newline
29720
29721 \newline
29722
29723 \family typewriter
29724 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29725  += 1])
29726 \newline
29727 \SpecialChar ~
29728 \SpecialChar ~
29729 \SpecialChar ~
29730 \SpecialChar ~
29731 <for body>
29732
29733 \layout Itemize
29734 The <for body> does not contain 
29735 \begin_inset Quotes eld
29736 \end_inset
29737
29738 continue
29739 \begin_inset Quotes erd
29740 \end_inset
29741
29742  or 'break
29743 \begin_inset Quotes erd
29744 \end_inset
29745
29746 .
29747
29748 \layout Itemize
29749 All goto's are contained within the loop.
29750
29751 \layout Itemize
29752 No function calls within the loop.
29753
29754 \layout Itemize
29755 The loop control variable <sym> is not assigned any value within the loop
29756
29757 \layout Itemize
29758 The loop control variable does NOT participate in any arithmetic operation
29759  within the loop.
29760
29761 \layout Itemize
29762 There are NO switch statements in the loop.
29763
29764 \layout Subsection
29765 Algebraic Simplifications
29766
29767 \layout Standard
29768 SDCC does numerous algebraic simplifications, the following is a small sub-set
29769  of these optimizations.
29770
29771 \layout Verse
29772
29773 \family typewriter
29774 i = j + 0;\SpecialChar ~
29775 \SpecialChar ~
29776 \SpecialChar ~
29777 \SpecialChar ~
29778  /* changed to: */\SpecialChar ~
29779 \SpecialChar ~
29780 \SpecialChar ~
29781 \SpecialChar ~
29782  i = j; 
29783 \newline
29784 i /= 2;\SpecialChar ~
29785 \SpecialChar ~
29786 \SpecialChar ~
29787 \SpecialChar ~
29788 \SpecialChar ~
29789 \SpecialChar ~
29790 \SpecialChar ~
29791  /* changed to: */\SpecialChar ~
29792 \SpecialChar ~
29793 \SpecialChar ~
29794 \SpecialChar ~
29795  i >>= 1; 
29796 \newline
29797 i
29798  = j - j;\SpecialChar ~
29799 \SpecialChar ~
29800 \SpecialChar ~
29801 \SpecialChar ~
29802  /* changed to: */\SpecialChar ~
29803 \SpecialChar ~
29804 \SpecialChar ~
29805 \SpecialChar ~
29806  i = 0; 
29807 \newline
29808 i = j / 1;\SpecialChar ~
29809 \SpecialChar ~
29810 \SpecialChar ~
29811 \SpecialChar ~
29812  /* changed to: */\SpecialChar ~
29813 \SpecialChar ~
29814 \SpecialChar ~
29815 \SpecialChar ~
29816  i = j;
29817
29818 \layout Standard
29819 Note the subexpressions
29820 \begin_inset LatexCommand \index{Subexpression}
29821
29822 \end_inset
29823
29824  given above are generally introduced by macro expansions or as a result
29825  of copy/constant propagation.
29826
29827 \layout Subsection
29828 'switch' Statements
29829 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29830
29831 \end_inset
29832
29833
29834 \begin_inset LatexCommand \index{switch statement}
29835
29836 \end_inset
29837
29838
29839
29840 \layout Standard
29841 SDCC can optimize switch statements to jump tables
29842 \begin_inset LatexCommand \index{jump tables}
29843
29844 \end_inset
29845
29846 .
29847  It makes the decision based on an estimate of the generated code size.
29848  SDCC is quite liberal in the requirements for jump table generation: 
29849
29850 \layout Itemize
29851 The labels need not be in order, and the starting number need not be one
29852  or zero, the case labels are in numerical sequence or not too many case
29853  labels are missing.
29854
29855 \begin_deeper
29856 \layout Verse
29857
29858 \family typewriter
29859 switch(i) {\SpecialChar ~
29860 \SpecialChar ~
29861 \SpecialChar ~
29862 \SpecialChar ~
29863 \SpecialChar ~
29864 \SpecialChar ~
29865 \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 switch (i) { 
29886 \newline
29887 \SpecialChar ~
29888 \SpecialChar ~
29889 \SpecialChar ~
29890 case 4: ...\SpecialChar ~
29891 \SpecialChar ~
29892 \SpecialChar ~
29893 \SpecialChar ~
29894 \SpecialChar ~
29895 \SpecialChar ~
29896 \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 case 0: ...
29917  
29918 \newline
29919 \SpecialChar ~
29920 \SpecialChar ~
29921 \SpecialChar ~
29922 case 5: ...\SpecialChar ~
29923 \SpecialChar ~
29924 \SpecialChar ~
29925 \SpecialChar ~
29926 \SpecialChar ~
29927 \SpecialChar ~
29928 \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 case 1: ...
29949  
29950 \newline
29951 \SpecialChar ~
29952 \SpecialChar ~
29953 \SpecialChar ~
29954 case 3: ...\SpecialChar ~
29955 \SpecialChar ~
29956 \SpecialChar ~
29957 \SpecialChar ~
29958 \SpecialChar ~
29959 \SpecialChar ~
29960 \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
29981 \newline
29982 \SpecialChar ~
29983 \SpecialChar ~
29984 \SpecialChar ~
29985 case 6: ...\SpecialChar ~
29986 \SpecialChar ~
29987 \SpecialChar ~
29988 \SpecialChar ~
29989 \SpecialChar ~
29990 \SpecialChar ~
29991 \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 case 3: ...
30012  
30013 \newline
30014 \SpecialChar ~
30015 \SpecialChar ~
30016 \SpecialChar ~
30017 case 7: ...\SpecialChar ~
30018 \SpecialChar ~
30019 \SpecialChar ~
30020 \SpecialChar ~
30021 \SpecialChar ~
30022 \SpecialChar ~
30023 \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 case 4: ...
30044  
30045 \newline
30046 \SpecialChar ~
30047 \SpecialChar ~
30048 \SpecialChar ~
30049 case 8: ...\SpecialChar ~
30050 \SpecialChar ~
30051 \SpecialChar ~
30052 \SpecialChar ~
30053 \SpecialChar ~
30054 \SpecialChar ~
30055 \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 case 5: ...
30076  
30077 \newline
30078 \SpecialChar ~
30079 \SpecialChar ~
30080 \SpecialChar ~
30081 case 9: ...\SpecialChar ~
30082 \SpecialChar ~
30083 \SpecialChar ~
30084 \SpecialChar ~
30085 \SpecialChar ~
30086 \SpecialChar ~
30087 \SpecialChar ~
30088 \SpecialChar ~
30089 \SpecialChar ~
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 \SpecialChar ~
30093 \SpecialChar ~
30094 \SpecialChar ~
30095 \SpecialChar ~
30096 \SpecialChar ~
30097 \SpecialChar ~
30098 \SpecialChar ~
30099 \SpecialChar ~
30100 \SpecialChar ~
30101 \SpecialChar ~
30102 \SpecialChar ~
30103 \SpecialChar ~
30104 \SpecialChar ~
30105 \SpecialChar ~
30106 \SpecialChar ~
30107 case 6: ...
30108  
30109 \newline
30110 \SpecialChar ~
30111 \SpecialChar ~
30112 \SpecialChar ~
30113 case 10: ...\SpecialChar ~
30114 \SpecialChar ~
30115 \SpecialChar ~
30116 \SpecialChar ~
30117 \SpecialChar ~
30118 \SpecialChar ~
30119 \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 case 7: ...
30139  
30140 \newline
30141 \SpecialChar ~
30142 \SpecialChar ~
30143 \SpecialChar ~
30144 case 11: ...\SpecialChar ~
30145 \SpecialChar ~
30146 \SpecialChar ~
30147 \SpecialChar ~
30148 \SpecialChar ~
30149 \SpecialChar ~
30150 \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 case 8: ...
30170  
30171 \newline
30172 }\SpecialChar ~
30173 \SpecialChar ~
30174 \SpecialChar ~
30175 \SpecialChar ~
30176 \SpecialChar ~
30177 \SpecialChar ~
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 }
30209
30210 \layout Standard
30211 Both the above switch statements will be implemented using a jump-table.
30212  The example to the right side is slightly more efficient as the check for
30213  the lower boundary of the jump-table is not needed.
30214
30215 \end_deeper
30216 \layout Itemize
30217 The number of case labels is not larger than supported by the target architectur
30218 e.
30219
30220 \layout Itemize
30221 If the case labels are not in numerical sequence ('gaps' between cases)
30222  SDCC checks whether a jump table with additionally inserted dummy cases
30223  is still attractive.
30224  
30225
30226 \layout Itemize
30227 If the starting number is not zero and a check for the lower boundary of
30228  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
30229  ...
30230  .
30231
30232 \layout Standard
30233 Switch statements which have large gaps in the numeric sequence or those
30234  that have too many case labels can be split into more than one switch statement
30235  for efficient code generation, e.g.:
30236
30237 \layout Verse
30238
30239 \family typewriter
30240 switch (i) { 
30241 \newline
30242 \SpecialChar ~
30243 \SpecialChar ~
30244 case 1: ...
30245  
30246 \newline
30247 \SpecialChar ~
30248 \SpecialChar ~
30249 case 2: ...
30250  
30251 \newline
30252 \SpecialChar ~
30253 \SpecialChar ~
30254 case 3: ...
30255  
30256 \newline
30257 \SpecialChar ~
30258 \SpecialChar ~
30259 case 4: ...
30260  
30261 \newline
30262 \SpecialChar ~
30263 \SpecialChar ~
30264 case 5: ...
30265  
30266 \newline
30267 \SpecialChar ~
30268 \SpecialChar ~
30269 case 6: ...
30270  
30271 \newline
30272 \SpecialChar ~
30273 \SpecialChar ~
30274 case 7: ...
30275  
30276 \newline
30277 \SpecialChar ~
30278 \SpecialChar ~
30279 case 101: ...
30280  
30281 \newline
30282 \SpecialChar ~
30283 \SpecialChar ~
30284 case 102: ...
30285  
30286 \newline
30287 \SpecialChar ~
30288 \SpecialChar ~
30289 case 103: ...
30290  
30291 \newline
30292 \SpecialChar ~
30293 \SpecialChar ~
30294 case 104: ...
30295  
30296 \newline
30297 \SpecialChar ~
30298 \SpecialChar ~
30299 case 105: ...
30300  
30301 \newline
30302 \SpecialChar ~
30303 \SpecialChar ~
30304 case 106: ...
30305  
30306 \newline
30307 \SpecialChar ~
30308 \SpecialChar ~
30309 case 107: ...
30310  
30311 \newline
30312 }
30313
30314 \layout Standard
30315 If the above switch statement is broken down into two switch statements
30316
30317 \layout Verse
30318
30319 \family typewriter
30320 switch (i) { 
30321 \newline
30322 \SpecialChar ~
30323 \SpecialChar ~
30324 case 1: ...
30325  
30326 \newline
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 case 2: ...
30330  
30331 \newline
30332 \SpecialChar ~
30333 \SpecialChar ~
30334 case 3: ...
30335  
30336 \newline
30337 \SpecialChar ~
30338 \SpecialChar ~
30339 case 4: ...
30340  
30341 \newline
30342 \SpecialChar ~
30343 \SpecialChar ~
30344 case 5: ...
30345  
30346 \newline
30347 \SpecialChar ~
30348 \SpecialChar ~
30349 case 6: ...
30350  
30351 \newline
30352 \SpecialChar ~
30353 \SpecialChar ~
30354 case 7: ...
30355  
30356 \newline
30357 }
30358
30359 \layout Standard
30360 and
30361
30362 \layout Verse
30363
30364 \family typewriter
30365 switch (i) { 
30366 \newline
30367 \SpecialChar ~
30368 \SpecialChar ~
30369 case 101: ...
30370  
30371 \newline
30372 \SpecialChar ~
30373 \SpecialChar ~
30374 case 102: ...
30375  
30376 \newline
30377 \SpecialChar ~
30378 \SpecialChar ~
30379 case 103: ...
30380  
30381 \newline
30382 \SpecialChar ~
30383 \SpecialChar ~
30384 case 104: ...
30385  
30386 \newline
30387 \SpecialChar ~
30388 \SpecialChar ~
30389 case 105: ...
30390  
30391 \newline
30392 \SpecialChar ~
30393 \SpecialChar ~
30394 case 106: ...
30395  
30396 \newline
30397 \SpecialChar ~
30398 \SpecialChar ~
30399 case 107: ...
30400  
30401 \newline
30402 }
30403
30404 \layout Standard
30405 then both the switch statements will be implemented using jump-tables whereas
30406  the unmodified switch statement will not be.
30407
30408 \layout Standard
30409 \begin_inset Note
30410 collapsed true
30411
30412 \layout Standard
30413 There might be reasons which SDCC cannot know about to either favour or
30414  not favour jump tables.
30415  If the target system has to be as quick for the last switch case as for
30416  the first (pro jump table), or if the switch argument is known to be zero
30417  in the majority of the cases (contra jump table).
30418
30419 \end_inset
30420
30421
30422
30423 \layout Standard
30424 The pragma nojtbound
30425 \begin_inset LatexCommand \index{\#pragma nojtbound}
30426
30427 \end_inset
30428
30429  can be used to turn off checking the 
30430 \emph on
30431 j
30432 \emph default
30433 ump 
30434 \emph on
30435 t
30436 \emph default
30437 able 
30438 \emph on
30439 bound
30440 \emph default
30441 aries.
30442  It has no effect if a default label is supplied.
30443  Use of this pragma is dangerous: if the switch
30444 \begin_inset LatexCommand \index{switch statement}
30445
30446 \end_inset
30447
30448  argument is not matched by a case statement the processor will happily
30449  jump into Nirvana.
30450
30451 \layout Subsection
30452 Bit-shifting Operations
30453 \begin_inset LatexCommand \index{Bit shifting}
30454
30455 \end_inset
30456
30457 .
30458
30459 \layout Standard
30460 Bit shifting is one of the most frequently used operation in embedded programmin
30461 g.
30462  SDCC tries to implement bit-shift operations in the most efficient way
30463  possible, e.g.:
30464
30465 \layout Verse
30466
30467 \family typewriter
30468 unsigned char i;
30469 \newline
30470 ...
30471  
30472 \newline
30473 i >>= 4; 
30474 \newline
30475 ...
30476
30477 \layout Standard
30478 generates the following code:
30479
30480 \layout Verse
30481
30482 \family typewriter
30483 mov\SpecialChar ~
30484  a,_i 
30485 \newline
30486 swap a 
30487 \newline
30488 anl\SpecialChar ~
30489  a,#0x0f 
30490 \newline
30491 mov\SpecialChar ~
30492  _i,a
30493
30494 \layout Standard
30495 In general SDCC will never setup a loop if the shift count is known.
30496  Another example:
30497
30498 \layout Verse
30499
30500 \family typewriter
30501 unsigned int i; 
30502 \newline
30503 ...
30504  
30505 \newline
30506 i >>= 9; 
30507 \newline
30508 ...
30509
30510 \layout Standard
30511 will generate:
30512
30513 \layout Verse
30514
30515 \family typewriter
30516 mov\SpecialChar ~
30517 \SpecialChar ~
30518 a,(_i + 1) 
30519 \newline
30520 mov\SpecialChar ~
30521 \SpecialChar ~
30522 (_i + 1),#0x00 
30523 \newline
30524 clr\SpecialChar ~
30525 \SpecialChar ~
30526
30527 \newline
30528 rrc\SpecialChar ~
30529 \SpecialChar ~
30530
30531 \newline
30532 mov\SpecialChar ~
30533 \SpecialChar ~
30534 _i,a
30535
30536 \layout Subsection
30537 Bit-rotation
30538 \begin_inset LatexCommand \index{Bit rotation}
30539
30540 \end_inset
30541
30542
30543
30544 \layout Standard
30545 A special case of the bit-shift operation is bit rotation
30546 \begin_inset LatexCommand \index{rotating bits}
30547
30548 \end_inset
30549
30550 , SDCC recognizes the following expression to be a left bit-rotation:
30551
30552 \layout Verse
30553
30554 \family typewriter
30555 \series bold
30556 unsigned
30557 \series default
30558 \SpecialChar ~
30559 \SpecialChar ~
30560 char i;\SpecialChar ~
30561 \SpecialChar ~
30562 \SpecialChar ~
30563 \SpecialChar ~
30564 \SpecialChar ~
30565 \SpecialChar ~
30566 \SpecialChar ~
30567 \SpecialChar ~
30568 \SpecialChar ~
30569 \SpecialChar ~
30570 \SpecialChar ~
30571 /* unsigned is needed for rotation */ 
30572 \newline
30573 ...
30574  
30575 \newline
30576 i = ((i << 1) | (i >> 7)); 
30577 \family default
30578
30579 \newline
30580
30581 \family typewriter
30582 ...
30583
30584 \layout Standard
30585 will generate the following code:
30586
30587 \layout Verse
30588
30589 \family typewriter
30590 mov\SpecialChar ~
30591 \SpecialChar ~
30592 a,_i 
30593 \newline
30594 rl\SpecialChar ~
30595 \SpecialChar ~
30596 \SpecialChar ~
30597
30598 \newline
30599 mov\SpecialChar ~
30600 \SpecialChar ~
30601 _i,a
30602
30603 \layout Standard
30604 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
30605 ns of this case will also be recognized as bit-rotation, i.e.: 
30606
30607 \layout Verse
30608
30609 \family typewriter
30610 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
30611
30612 \layout Subsection
30613 Nibble and Byte Swapping
30614
30615 \layout Standard
30616 Other special cases of the bit-shift operations are nibble or byte swapping
30617 \begin_inset LatexCommand \index{swapping nibbles/bytes}
30618
30619 \end_inset
30620
30621 , SDCC recognizes the following expressions:
30622
30623 \layout Verse
30624
30625 \family typewriter
30626 \series bold
30627 unsigned
30628 \series default
30629 \SpecialChar ~
30630 \SpecialChar ~
30631 char i; 
30632 \newline
30633
30634 \series bold
30635 unsigned
30636 \series default
30637 \SpecialChar ~
30638 \SpecialChar ~
30639 int j; 
30640 \newline
30641 ...
30642  
30643 \newline
30644 i = ((i << 4) | (i >> 4)); 
30645 \family default
30646
30647 \newline
30648
30649 \family typewriter
30650 j = ((j << 8) | (j >> 8)); 
30651
30652 \layout Standard
30653 and generates a swap instruction for the nibble swapping
30654 \begin_inset LatexCommand \index{Nibble swapping}
30655
30656 \end_inset
30657
30658  or move instructions for the byte swapping
30659 \begin_inset LatexCommand \index{Byte swapping}
30660
30661 \end_inset
30662
30663 .
30664  The 
30665 \begin_inset Quotes sld
30666 \end_inset
30667
30668 j
30669 \begin_inset Quotes srd
30670 \end_inset
30671
30672  example can be used to convert from little to big-endian or vice versa.
30673  If you want to change the endianness of a 
30674 \emph on
30675 signed
30676 \emph default
30677  integer you have to cast to 
30678 \family typewriter
30679 (unsigned int)
30680 \family default
30681  first.
30682
30683 \layout Standard
30684 Note that SDCC stores numbers in little-endian
30685 \begin_inset Foot
30686 collapsed false
30687
30688 \layout Standard
30689 Usually 8-bit processors don't care much about endianness.
30690  This is not the case for the standard 8051 which only has an instruction
30691  to increment its 
30692 \emph on
30693 dptr
30694 \emph default
30695
30696 \begin_inset LatexCommand \index{DPTR}
30697
30698 \end_inset
30699
30700 -datapointer
30701 \emph on
30702  
30703 \emph default
30704 so little-endian is the more efficient byte order.
30705
30706 \end_inset
30707
30708
30709 \begin_inset LatexCommand \index{little-endian}
30710
30711 \end_inset
30712
30713
30714 \begin_inset LatexCommand \index{Endianness}
30715
30716 \end_inset
30717
30718  format (i.e.
30719  lowest order first).
30720
30721 \layout Subsection
30722 Highest Order Bit
30723 \begin_inset LatexCommand \index{Highest Order Bit}
30724
30725 \end_inset
30726
30727  / Any Order Bit
30728 \begin_inset LatexCommand \index{Any Order Bit}
30729
30730 \end_inset
30731
30732
30733
30734 \layout Standard
30735 It is frequently required to obtain the highest order bit of an integral
30736  type (long, int, short or char types).
30737  Also obtaining any other order bit is not uncommon.
30738  SDCC recognizes the following expressions to yield the highest order bit
30739  and generates optimized code for it, e.g.:
30740
30741 \layout Verse
30742
30743 \family typewriter
30744 unsigned int gint; 
30745 \newline
30746
30747 \newline
30748 foo () { 
30749 \newline
30750 \SpecialChar ~
30751 \SpecialChar ~
30752 unsigned char hob1, aob1; 
30753 \newline
30754 \SpecialChar ~
30755 \SpecialChar ~
30756 bit hob2, hob3, aob2,
30757  aob3; 
30758 \newline
30759 \SpecialChar ~
30760 \SpecialChar ~
30761 ...
30762  
30763 \newline
30764 \SpecialChar ~
30765 \SpecialChar ~
30766 hob1 = (gint >> 15) & 1; 
30767 \newline
30768 \SpecialChar ~
30769 \SpecialChar ~
30770 hob2 = (gint >> 15) & 1; 
30771 \newline
30772 \SpecialChar ~
30773 \SpecialChar ~
30774 hob3 = gint & 0x8000;
30775  
30776 \newline
30777 \SpecialChar ~
30778 \SpecialChar ~
30779 aob1 = (gint >> 9) & 1; 
30780 \newline
30781 \SpecialChar ~
30782 \SpecialChar ~
30783 aob2 = (gint >> 8) & 1; 
30784 \newline
30785 \SpecialChar ~
30786 \SpecialChar ~
30787 aob3 = gint & 0x0800; 
30788 \newline
30789 \SpecialChar ~
30790 \SpecialChar ~
30791 ..
30792  
30793 \newline
30794 }
30795
30796 \layout Standard
30797 will generate the following code:
30798
30799 \layout Verse
30800
30801 \family typewriter
30802 \SpecialChar ~
30803 \SpecialChar ~
30804 \SpecialChar ~
30805 \SpecialChar ~
30806 \SpecialChar ~
30807 \SpecialChar ~
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  61 ;\SpecialChar ~
30828  hob.c 7 
30829 \newline
30830 000A E5*01\SpecialChar ~
30831 \SpecialChar ~
30832 \SpecialChar ~
30833 \SpecialChar ~
30834 \SpecialChar ~
30835 \SpecialChar ~
30836 \SpecialChar ~
30837 \SpecialChar ~
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 \SpecialChar ~
30841 \SpecialChar ~
30842 \SpecialChar ~
30843 \SpecialChar ~
30844 \SpecialChar ~
30845  62\SpecialChar ~
30846 \SpecialChar ~
30847 \SpecialChar ~
30848 \SpecialChar ~
30849 \SpecialChar ~
30850 \SpecialChar ~
30851 \SpecialChar ~
30852 \SpecialChar ~
30853  mov\SpecialChar ~
30854 \SpecialChar ~
30855  a,(_gint + 1) 
30856 \newline
30857 000C 23\SpecialChar ~
30858 \SpecialChar ~
30859 \SpecialChar ~
30860 \SpecialChar ~
30861 \SpecialChar ~
30862 \SpecialChar ~
30863 \SpecialChar ~
30864 \SpecialChar ~
30865 \SpecialChar ~
30866 \SpecialChar ~
30867 \SpecialChar ~
30868 \SpecialChar ~
30869 \SpecialChar ~
30870 \SpecialChar ~
30871 \SpecialChar ~
30872 \SpecialChar ~
30873 \SpecialChar ~
30874 \SpecialChar ~
30875  63\SpecialChar ~
30876 \SpecialChar ~
30877 \SpecialChar ~
30878 \SpecialChar ~
30879 \SpecialChar ~
30880 \SpecialChar ~
30881 \SpecialChar ~
30882 \SpecialChar ~
30883  rl\SpecialChar ~
30884 \SpecialChar ~
30885 \SpecialChar ~
30886  a 
30887 \newline
30888 000D 54 01\SpecialChar ~
30889 \SpecialChar ~
30890 \SpecialChar ~
30891 \SpecialChar ~
30892 \SpecialChar ~
30893 \SpecialChar ~
30894 \SpecialChar ~
30895 \SpecialChar ~
30896 \SpecialChar ~
30897 \SpecialChar ~
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 \SpecialChar ~
30901 \SpecialChar ~
30902 \SpecialChar ~
30903
30904  64\SpecialChar ~
30905 \SpecialChar ~
30906 \SpecialChar ~
30907 \SpecialChar ~
30908 \SpecialChar ~
30909 \SpecialChar ~
30910 \SpecialChar ~
30911 \SpecialChar ~
30912  anl\SpecialChar ~
30913 \SpecialChar ~
30914  a,#0x01 
30915 \newline
30916 000F F5*02\SpecialChar ~
30917 \SpecialChar ~
30918 \SpecialChar ~
30919 \SpecialChar ~
30920 \SpecialChar ~
30921 \SpecialChar ~
30922 \SpecialChar ~
30923 \SpecialChar ~
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 \SpecialChar ~
30927 \SpecialChar ~
30928 \SpecialChar ~
30929 \SpecialChar ~
30930 \SpecialChar ~
30931  65\SpecialChar ~
30932 \SpecialChar ~
30933 \SpecialChar ~
30934 \SpecialChar ~
30935 \SpecialChar ~
30936 \SpecialChar ~
30937 \SpecialChar ~
30938 \SpecialChar ~
30939  mov\SpecialChar ~
30940 \SpecialChar ~
30941  _foo_hob1_1_1,a 
30942 \newline
30943 \SpecialChar ~
30944 \SpecialChar ~
30945 \SpecialChar ~
30946 \SpecialChar ~
30947 \SpecialChar ~
30948 \SpecialChar ~
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  66 ;\SpecialChar ~
30969  hob.c 8 
30970 \newline
30971 0011 E5*01\SpecialChar ~
30972 \SpecialChar ~
30973 \SpecialChar ~
30974 \SpecialChar ~
30975 \SpecialChar ~
30976 \SpecialChar ~
30977 \SpecialChar ~
30978 \SpecialChar ~
30979 \SpecialChar ~
30980 \SpecialChar ~
30981 \SpecialChar ~
30982 \SpecialChar ~
30983 \SpecialChar ~
30984 \SpecialChar ~
30985 \SpecialChar ~
30986
30987  67\SpecialChar ~
30988 \SpecialChar ~
30989 \SpecialChar ~
30990 \SpecialChar ~
30991 \SpecialChar ~
30992 \SpecialChar ~
30993 \SpecialChar ~
30994 \SpecialChar ~
30995  mov\SpecialChar ~
30996 \SpecialChar ~
30997  a,(_gint + 1) 
30998 \newline
30999 0013 33\SpecialChar ~
31000 \SpecialChar ~
31001 \SpecialChar ~
31002 \SpecialChar ~
31003 \SpecialChar ~
31004 \SpecialChar ~
31005 \SpecialChar ~
31006 \SpecialChar ~
31007 \SpecialChar ~
31008 \SpecialChar ~
31009 \SpecialChar ~
31010 \SpecialChar ~
31011 \SpecialChar ~
31012 \SpecialChar ~
31013 \SpecialChar ~
31014 \SpecialChar ~
31015 \SpecialChar ~
31016 \SpecialChar ~
31017  68\SpecialChar ~
31018 \SpecialChar ~
31019 \SpecialChar ~
31020 \SpecialChar ~
31021 \SpecialChar ~
31022 \SpecialChar ~
31023 \SpecialChar ~
31024 \SpecialChar ~
31025  rlc\SpecialChar ~
31026 \SpecialChar ~
31027  a 
31028 \newline
31029 0014 92*00\SpecialChar ~
31030 \SpecialChar ~
31031 \SpecialChar ~
31032 \SpecialChar ~
31033 \SpecialChar ~
31034 \SpecialChar ~
31035 \SpecialChar ~
31036 \SpecialChar ~
31037 \SpecialChar ~
31038 \SpecialChar ~
31039 \SpecialChar ~
31040 \SpecialChar ~
31041 \SpecialChar ~
31042 \SpecialChar ~
31043 \SpecialChar ~
31044  69\SpecialChar ~
31045 \SpecialChar ~
31046 \SpecialChar ~
31047 \SpecialChar ~
31048 \SpecialChar ~
31049 \SpecialChar ~
31050 \SpecialChar ~
31051 \SpecialChar ~
31052  mov\SpecialChar ~
31053 \SpecialChar ~
31054  _foo_hob2_1_1,c
31055  
31056 \newline
31057 \SpecialChar ~
31058 \SpecialChar ~
31059 \SpecialChar ~
31060 \SpecialChar ~
31061 \SpecialChar ~
31062 \SpecialChar ~
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  66 ;\SpecialChar ~
31083  hob.c 9 
31084 \newline
31085 0016 E5*01\SpecialChar ~
31086 \SpecialChar ~
31087 \SpecialChar ~
31088 \SpecialChar ~
31089 \SpecialChar ~
31090 \SpecialChar ~
31091 \SpecialChar ~
31092 \SpecialChar ~
31093 \SpecialChar ~
31094 \SpecialChar ~
31095 \SpecialChar ~
31096 \SpecialChar ~
31097 \SpecialChar ~
31098 \SpecialChar ~
31099 \SpecialChar ~
31100  67\SpecialChar ~
31101 \SpecialChar ~
31102 \SpecialChar ~
31103 \SpecialChar ~
31104 \SpecialChar ~
31105 \SpecialChar ~
31106 \SpecialChar ~
31107 \SpecialChar ~
31108  mov\SpecialChar ~
31109 \SpecialChar ~
31110  a,(_gint + 1) 
31111 \newline
31112 0018 33\SpecialChar ~
31113 \SpecialChar ~
31114 \SpecialChar ~
31115 \SpecialChar ~
31116 \SpecialChar ~
31117 \SpecialChar ~
31118 \SpecialChar ~
31119 \SpecialChar ~
31120 \SpecialChar ~
31121 \SpecialChar ~
31122 \SpecialChar ~
31123 \SpecialChar ~
31124 \SpecialChar ~
31125 \SpecialChar ~
31126 \SpecialChar ~
31127 \SpecialChar ~
31128 \SpecialChar ~
31129 \SpecialChar ~
31130  68\SpecialChar ~
31131 \SpecialChar ~
31132 \SpecialChar ~
31133 \SpecialChar ~
31134 \SpecialChar ~
31135 \SpecialChar ~
31136 \SpecialChar ~
31137 \SpecialChar ~
31138  rlc\SpecialChar ~
31139 \SpecialChar ~
31140  a 
31141 \newline
31142 0019 92*01\SpecialChar ~
31143 \SpecialChar ~
31144 \SpecialChar ~
31145 \SpecialChar ~
31146 \SpecialChar ~
31147 \SpecialChar ~
31148 \SpecialChar ~
31149 \SpecialChar ~
31150 \SpecialChar ~
31151 \SpecialChar ~
31152 \SpecialChar ~
31153 \SpecialChar ~
31154 \SpecialChar ~
31155 \SpecialChar ~
31156 \SpecialChar ~
31157
31158  69\SpecialChar ~
31159 \SpecialChar ~
31160 \SpecialChar ~
31161 \SpecialChar ~
31162 \SpecialChar ~
31163 \SpecialChar ~
31164 \SpecialChar ~
31165 \SpecialChar ~
31166  mov\SpecialChar ~
31167 \SpecialChar ~
31168  _foo_hob3_1_1,c 
31169 \newline
31170 \SpecialChar ~
31171 \SpecialChar ~
31172 \SpecialChar ~
31173 \SpecialChar ~
31174 \SpecialChar ~
31175 \SpecialChar ~
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  70 ;\SpecialChar ~
31196  hob.c 10 
31197 \newline
31198 001B E5*01\SpecialChar ~
31199 \SpecialChar ~
31200 \SpecialChar ~
31201 \SpecialChar ~
31202 \SpecialChar ~
31203 \SpecialChar ~
31204 \SpecialChar ~
31205 \SpecialChar ~
31206 \SpecialChar ~
31207 \SpecialChar ~
31208 \SpecialChar ~
31209 \SpecialChar ~
31210 \SpecialChar ~
31211 \SpecialChar ~
31212 \SpecialChar ~
31213  71\SpecialChar ~
31214 \SpecialChar ~
31215 \SpecialChar ~
31216 \SpecialChar ~
31217 \SpecialChar ~
31218 \SpecialChar ~
31219 \SpecialChar ~
31220 \SpecialChar ~
31221  mov\SpecialChar ~
31222 \SpecialChar ~
31223  a,(_gint + 1) 
31224 \newline
31225 001D
31226  03\SpecialChar ~
31227 \SpecialChar ~
31228 \SpecialChar ~
31229 \SpecialChar ~
31230 \SpecialChar ~
31231 \SpecialChar ~
31232 \SpecialChar ~
31233 \SpecialChar ~
31234 \SpecialChar ~
31235 \SpecialChar ~
31236 \SpecialChar ~
31237 \SpecialChar ~
31238 \SpecialChar ~
31239 \SpecialChar ~
31240 \SpecialChar ~
31241 \SpecialChar ~
31242 \SpecialChar ~
31243 \SpecialChar ~
31244  72\SpecialChar ~
31245 \SpecialChar ~
31246 \SpecialChar ~
31247 \SpecialChar ~
31248 \SpecialChar ~
31249 \SpecialChar ~
31250 \SpecialChar ~
31251 \SpecialChar ~
31252  rr\SpecialChar ~
31253 \SpecialChar ~
31254 \SpecialChar ~
31255  a 
31256 \newline
31257 001E 54 01\SpecialChar ~
31258 \SpecialChar ~
31259 \SpecialChar ~
31260 \SpecialChar ~
31261 \SpecialChar ~
31262 \SpecialChar ~
31263 \SpecialChar ~
31264 \SpecialChar ~
31265 \SpecialChar ~
31266 \SpecialChar ~
31267 \SpecialChar ~
31268 \SpecialChar ~
31269 \SpecialChar ~
31270 \SpecialChar ~
31271 \SpecialChar ~
31272  73\SpecialChar ~
31273 \SpecialChar ~
31274 \SpecialChar ~
31275 \SpecialChar ~
31276 \SpecialChar ~
31277 \SpecialChar ~
31278 \SpecialChar ~
31279 \SpecialChar ~
31280  anl\SpecialChar ~
31281 \SpecialChar ~
31282  a,#0x01 
31283 \newline
31284 0020 F5*03\SpecialChar ~
31285 \SpecialChar ~
31286 \SpecialChar ~
31287 \SpecialChar ~
31288 \SpecialChar ~
31289 \SpecialChar ~
31290 \SpecialChar ~
31291 \SpecialChar ~
31292 \SpecialChar ~
31293 \SpecialChar ~
31294 \SpecialChar ~
31295 \SpecialChar ~
31296 \SpecialChar ~
31297 \SpecialChar ~
31298 \SpecialChar ~
31299  74\SpecialChar ~
31300 \SpecialChar ~
31301 \SpecialChar ~
31302 \SpecialChar ~
31303 \SpecialChar ~
31304 \SpecialChar ~
31305 \SpecialChar ~
31306 \SpecialChar ~
31307  mov\SpecialChar ~
31308 \SpecialChar ~
31309  _foo_aob1_1_1,a
31310  
31311 \newline
31312 \SpecialChar ~
31313 \SpecialChar ~
31314 \SpecialChar ~
31315 \SpecialChar ~
31316 \SpecialChar ~
31317 \SpecialChar ~
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  75 ;\SpecialChar ~
31338  hob.c 11 
31339 \newline
31340 0022 E5*01\SpecialChar ~
31341 \SpecialChar ~
31342 \SpecialChar ~
31343 \SpecialChar ~
31344 \SpecialChar ~
31345 \SpecialChar ~
31346 \SpecialChar ~
31347 \SpecialChar ~
31348 \SpecialChar ~
31349 \SpecialChar ~
31350 \SpecialChar ~
31351 \SpecialChar ~
31352 \SpecialChar ~
31353 \SpecialChar ~
31354 \SpecialChar ~
31355  76\SpecialChar ~
31356 \SpecialChar ~
31357 \SpecialChar ~
31358 \SpecialChar ~
31359 \SpecialChar ~
31360 \SpecialChar ~
31361 \SpecialChar ~
31362 \SpecialChar ~
31363  mov\SpecialChar ~
31364 \SpecialChar ~
31365  a,(_gint + 1) 
31366 \newline
31367 0024 13\SpecialChar ~
31368 \SpecialChar ~
31369 \SpecialChar ~
31370 \SpecialChar ~
31371 \SpecialChar ~
31372 \SpecialChar ~
31373 \SpecialChar ~
31374 \SpecialChar ~
31375 \SpecialChar ~
31376 \SpecialChar ~
31377 \SpecialChar ~
31378 \SpecialChar ~
31379 \SpecialChar ~
31380 \SpecialChar ~
31381 \SpecialChar ~
31382 \SpecialChar ~
31383 \SpecialChar ~
31384 \SpecialChar ~
31385  77\SpecialChar ~
31386 \SpecialChar ~
31387 \SpecialChar ~
31388 \SpecialChar ~
31389 \SpecialChar ~
31390 \SpecialChar ~
31391 \SpecialChar ~
31392 \SpecialChar ~
31393  rrc\SpecialChar ~
31394 \SpecialChar ~
31395  a 
31396 \newline
31397 0025 92*02\SpecialChar ~
31398 \SpecialChar ~
31399 \SpecialChar ~
31400 \SpecialChar ~
31401 \SpecialChar ~
31402 \SpecialChar ~
31403 \SpecialChar ~
31404 \SpecialChar ~
31405 \SpecialChar ~
31406 \SpecialChar ~
31407 \SpecialChar ~
31408 \SpecialChar ~
31409 \SpecialChar ~
31410 \SpecialChar ~
31411 \SpecialChar ~
31412
31413  78\SpecialChar ~
31414 \SpecialChar ~
31415 \SpecialChar ~
31416 \SpecialChar ~
31417 \SpecialChar ~
31418 \SpecialChar ~
31419 \SpecialChar ~
31420 \SpecialChar ~
31421  mov\SpecialChar ~
31422 \SpecialChar ~
31423  _foo_aob2_1_1,c 
31424 \newline
31425 \SpecialChar ~
31426 \SpecialChar ~
31427 \SpecialChar ~
31428 \SpecialChar ~
31429 \SpecialChar ~
31430 \SpecialChar ~
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  79 ;\SpecialChar ~
31451  hob.c 12 
31452 \newline
31453 0027 E5*01\SpecialChar ~
31454 \SpecialChar ~
31455 \SpecialChar ~
31456 \SpecialChar ~
31457 \SpecialChar ~
31458 \SpecialChar ~
31459 \SpecialChar ~
31460 \SpecialChar ~
31461 \SpecialChar ~
31462 \SpecialChar ~
31463 \SpecialChar ~
31464 \SpecialChar ~
31465 \SpecialChar ~
31466 \SpecialChar ~
31467 \SpecialChar ~
31468  80\SpecialChar ~
31469 \SpecialChar ~
31470 \SpecialChar ~
31471 \SpecialChar ~
31472 \SpecialChar ~
31473 \SpecialChar ~
31474 \SpecialChar ~
31475 \SpecialChar ~
31476  mov\SpecialChar ~
31477 \SpecialChar ~
31478  a,(_gint + 1) 
31479 \newline
31480 0029
31481  A2 E3\SpecialChar ~
31482 \SpecialChar ~
31483 \SpecialChar ~
31484 \SpecialChar ~
31485 \SpecialChar ~
31486 \SpecialChar ~
31487 \SpecialChar ~
31488 \SpecialChar ~
31489 \SpecialChar ~
31490 \SpecialChar ~
31491 \SpecialChar ~
31492 \SpecialChar ~
31493 \SpecialChar ~
31494 \SpecialChar ~
31495 \SpecialChar ~
31496  81\SpecialChar ~
31497 \SpecialChar ~
31498 \SpecialChar ~
31499 \SpecialChar ~
31500 \SpecialChar ~
31501 \SpecialChar ~
31502 \SpecialChar ~
31503 \SpecialChar ~
31504  mov\SpecialChar ~
31505 \SpecialChar ~
31506  c,acc[3] 
31507 \newline
31508 002B 92*03\SpecialChar ~
31509 \SpecialChar ~
31510 \SpecialChar ~
31511 \SpecialChar ~
31512 \SpecialChar ~
31513 \SpecialChar ~
31514 \SpecialChar ~
31515 \SpecialChar ~
31516 \SpecialChar ~
31517 \SpecialChar ~
31518 \SpecialChar ~
31519 \SpecialChar ~
31520 \SpecialChar ~
31521 \SpecialChar ~
31522 \SpecialChar ~
31523  82\SpecialChar ~
31524 \SpecialChar ~
31525 \SpecialChar ~
31526 \SpecialChar ~
31527 \SpecialChar ~
31528 \SpecialChar ~
31529 \SpecialChar ~
31530 \SpecialChar ~
31531  mov\SpecialChar ~
31532 \SpecialChar ~
31533  _foo_aob3_1_1,c 
31534
31535 \layout Standard
31536 Other variations of these cases however will 
31537 \emph on
31538 not
31539 \emph default
31540  be recognized.
31541  They are standard C expressions, so I heartily recommend these be the only
31542  way to get the highest order bit, (it is portable).
31543  Of course it will be recognized even if it is embedded in other expressions,
31544  e.g.:
31545
31546 \layout Verse
31547
31548 \family typewriter
31549 xyz = gint + ((gint >> 15) & 1);
31550
31551 \layout Standard
31552 will still be recognized.
31553
31554 \layout Subsection
31555 Higher Order Byte
31556 \begin_inset LatexCommand \index{Higher Order Byte}
31557
31558 \end_inset
31559
31560  / Higher Order Word
31561 \begin_inset LatexCommand \index{Higher Order Word}
31562
31563 \end_inset
31564
31565
31566
31567 \layout Standard
31568 It is also frequently required to obtain a higher order byte or word of
31569  a larger integral type (long, int or short types).
31570  SDCC recognizes the following expressions to yield the higher order byte
31571  or word and generates optimized code for it, e.g.:
31572
31573 \layout Verse
31574
31575 \family typewriter
31576 unsigned int gint; 
31577 \newline
31578 unsigned long int glong; 
31579 \newline
31580
31581 \newline
31582 foo () { 
31583 \newline
31584 \SpecialChar ~
31585 \SpecialChar ~
31586 unsigned char hob1,
31587  hob2; 
31588 \newline
31589 \SpecialChar ~
31590 \SpecialChar ~
31591 unsigned int how1, how2; 
31592 \newline
31593 \SpecialChar ~
31594 \SpecialChar ~
31595 ...
31596  
31597 \newline
31598 \SpecialChar ~
31599 \SpecialChar ~
31600 hob1 = (gint >> 8) & 0xFF; 
31601 \newline
31602 \SpecialChar ~
31603 \SpecialChar ~
31604 hob2 = glong >> 24; 
31605 \newline
31606 \SpecialChar ~
31607 \SpecialChar ~
31608 how1 = (glong >> 16) & 0xFFFF;
31609  
31610 \newline
31611 \SpecialChar ~
31612 \SpecialChar ~
31613 how2 = glong >> 8; 
31614 \newline
31615 \SpecialChar ~
31616 \SpecialChar ~
31617 ..
31618  
31619 \newline
31620 }
31621
31622 \layout Standard
31623 will generate the following code:
31624
31625 \layout Verse
31626
31627 \family typewriter
31628 \SpecialChar ~
31629 \SpecialChar ~
31630 \SpecialChar ~
31631 \SpecialChar ~
31632 \SpecialChar ~
31633 \SpecialChar ~
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  91 ;\SpecialChar ~
31654  hob.c 15 
31655 \newline
31656 0037 85*01*06\SpecialChar ~
31657 \SpecialChar ~
31658 \SpecialChar ~
31659 \SpecialChar ~
31660 \SpecialChar ~
31661 \SpecialChar ~
31662 \SpecialChar ~
31663 \SpecialChar ~
31664 \SpecialChar ~
31665 \SpecialChar ~
31666 \SpecialChar ~
31667 \SpecialChar ~
31668  92\SpecialChar ~
31669 \SpecialChar ~
31670 \SpecialChar ~
31671 \SpecialChar ~
31672 \SpecialChar ~
31673 \SpecialChar ~
31674 \SpecialChar ~
31675 \SpecialChar ~
31676  mov\SpecialChar ~
31677 \SpecialChar ~
31678  _foo_hob1_1_1,(_gint + 1) 
31679 \newline
31680 \SpecialChar ~
31681 \SpecialChar ~
31682 \SpecialChar ~
31683 \SpecialChar ~
31684 \SpecialChar ~
31685 \SpecialChar ~
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  93 ;\SpecialChar ~
31706  hob.c
31707  16 
31708 \newline
31709 003A 85*05*07\SpecialChar ~
31710 \SpecialChar ~
31711 \SpecialChar ~
31712 \SpecialChar ~
31713 \SpecialChar ~
31714 \SpecialChar ~
31715 \SpecialChar ~
31716 \SpecialChar ~
31717 \SpecialChar ~
31718 \SpecialChar ~
31719 \SpecialChar ~
31720 \SpecialChar ~
31721  94\SpecialChar ~
31722 \SpecialChar ~
31723 \SpecialChar ~
31724 \SpecialChar ~
31725 \SpecialChar ~
31726 \SpecialChar ~
31727 \SpecialChar ~
31728 \SpecialChar ~
31729  mov\SpecialChar ~
31730 \SpecialChar ~
31731  _foo_hob2_1_1,(_glong + 3) 
31732 \newline
31733 \SpecialChar ~
31734 \SpecialChar ~
31735 \SpecialChar ~
31736 \SpecialChar ~
31737 \SpecialChar ~
31738 \SpecialChar ~
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  95 ;\SpecialChar ~
31759  hob.c 17 
31760 \newline
31761 003D 85*04*08\SpecialChar ~
31762 \SpecialChar ~
31763 \SpecialChar ~
31764 \SpecialChar ~
31765 \SpecialChar ~
31766 \SpecialChar ~
31767 \SpecialChar ~
31768 \SpecialChar ~
31769 \SpecialChar ~
31770 \SpecialChar ~
31771 \SpecialChar ~
31772 \SpecialChar ~
31773
31774  96\SpecialChar ~
31775 \SpecialChar ~
31776 \SpecialChar ~
31777 \SpecialChar ~
31778 \SpecialChar ~
31779 \SpecialChar ~
31780 \SpecialChar ~
31781 \SpecialChar ~
31782  mov\SpecialChar ~
31783 \SpecialChar ~
31784  _foo_how1_1_1,(_glong + 2) 
31785 \newline
31786 0040 85*05*09\SpecialChar ~
31787 \SpecialChar ~
31788 \SpecialChar ~
31789 \SpecialChar ~
31790 \SpecialChar ~
31791 \SpecialChar ~
31792 \SpecialChar ~
31793 \SpecialChar ~
31794 \SpecialChar ~
31795 \SpecialChar ~
31796 \SpecialChar ~
31797 \SpecialChar ~
31798  97\SpecialChar ~
31799 \SpecialChar ~
31800 \SpecialChar ~
31801 \SpecialChar ~
31802 \SpecialChar ~
31803 \SpecialChar ~
31804 \SpecialChar ~
31805 \SpecialChar ~
31806  mov\SpecialChar ~
31807 \SpecialChar ~
31808  (_foo_how1_1_1 +
31809  1),(_glong + 3) 
31810 \newline
31811 0043 85*03*0A\SpecialChar ~
31812 \SpecialChar ~
31813 \SpecialChar ~
31814 \SpecialChar ~
31815 \SpecialChar ~
31816 \SpecialChar ~
31817 \SpecialChar ~
31818 \SpecialChar ~
31819 \SpecialChar ~
31820 \SpecialChar ~
31821 \SpecialChar ~
31822 \SpecialChar ~
31823  98\SpecialChar ~
31824 \SpecialChar ~
31825 \SpecialChar ~
31826 \SpecialChar ~
31827 \SpecialChar ~
31828 \SpecialChar ~
31829 \SpecialChar ~
31830 \SpecialChar ~
31831  mov\SpecialChar ~
31832 \SpecialChar ~
31833  _foo_how2_1_1,(_glong + 1) 
31834 \newline
31835 0046 85*04*0B\SpecialChar ~
31836 \SpecialChar ~
31837 \SpecialChar ~
31838 \SpecialChar ~
31839 \SpecialChar ~
31840 \SpecialChar ~
31841 \SpecialChar ~
31842 \SpecialChar ~
31843 \SpecialChar ~
31844 \SpecialChar ~
31845 \SpecialChar ~
31846 \SpecialChar ~
31847
31848  99\SpecialChar ~
31849 \SpecialChar ~
31850 \SpecialChar ~
31851 \SpecialChar ~
31852 \SpecialChar ~
31853 \SpecialChar ~
31854 \SpecialChar ~
31855 \SpecialChar ~
31856  mov\SpecialChar ~
31857 \SpecialChar ~
31858  (_foo_how2_1_1 + 1),(_glong + 2) 
31859
31860 \layout Standard
31861 Again, variations of these cases may 
31862 \emph on
31863 not
31864 \emph default
31865  be recognized.
31866  They are standard C expressions, so I heartily recommend these be the only
31867  way to get the higher order byte/word, (it is portable).
31868  Of course it will be recognized even if it is embedded in other expressions,
31869  e.g.:
31870
31871 \layout Verse
31872
31873 \family typewriter
31874 xyz = gint + ((gint >> 8) & 0xFF);
31875
31876 \layout Standard
31877 will still be recognized.
31878
31879 \layout Subsection
31880 Peephole Optimizer
31881 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31882
31883 \end_inset
31884
31885
31886 \begin_inset LatexCommand \index{Peephole optimizer}
31887
31888 \end_inset
31889
31890
31891
31892 \layout Standard
31893 The compiler uses a rule based, pattern matching and re-writing mechanism
31894  for peep-hole optimization.
31895  It is inspired by 
31896 \emph on
31897 copt
31898 \emph default
31899  a peep-hole optimizer by Christopher W.
31900  Fraser (cwfraser\SpecialChar ~
31901 @\SpecialChar ~
31902 microsoft.com).
31903  A default set of rules are compiled into the compiler, additional rules
31904  may be added with the 
31905 \emph on
31906 -
31907 \begin_inset ERT
31908 status Collapsed
31909
31910 \layout Standard
31911
31912
31913 \backslash
31914 /
31915
31916 \end_inset
31917
31918 -peep-file
31919 \begin_inset LatexCommand \index{-\/-peep-file}
31920
31921 \end_inset
31922
31923  <filename>
31924 \emph default
31925  option.
31926  The rule language is best illustrated with examples.
31927
31928 \layout Verse
31929
31930 \family typewriter
31931 replace { 
31932 \newline
31933 \SpecialChar ~
31934 \SpecialChar ~
31935 mov %1,a 
31936 \newline
31937 \SpecialChar ~
31938 \SpecialChar ~
31939 mov a,%1
31940 \newline
31941 } by {
31942 \newline
31943 \SpecialChar ~
31944 \SpecialChar ~
31945 mov %1,a
31946 \newline
31947 }
31948
31949 \layout Standard
31950 The above rule will change the following assembly
31951 \begin_inset LatexCommand \index{Assembler routines}
31952
31953 \end_inset
31954
31955  sequence:
31956
31957 \layout Verse
31958
31959 \family typewriter
31960 mov r1,a 
31961 \newline
31962 mov a,r1
31963
31964 \layout Standard
31965 to
31966
31967 \layout Verse
31968
31969 \family typewriter
31970 mov r1,a
31971
31972 \layout Standard
31973 Note: All occurrences of a 
31974 \emph on
31975 %n
31976 \emph default
31977  (pattern variable) must denote the same string.
31978  With the above rule, the assembly sequence:
31979
31980 \layout Verse
31981
31982 \family typewriter
31983 mov r1,a 
31984 \newline
31985 mov a,r2
31986
31987 \layout Standard
31988 will remain unmodified.
31989 \newline
31990
31991 \newline
31992 Other special case optimizations may be added by the
31993  user (via 
31994 \emph on
31995 -
31996 \begin_inset ERT
31997 status Collapsed
31998
31999 \layout Standard
32000
32001
32002 \backslash
32003 /
32004
32005 \end_inset
32006
32007 -peep-file option
32008 \emph default
32009 ).
32010  E.g.
32011  some variants of the 8051 MCU
32012 \begin_inset LatexCommand \index{MCS51 variants}
32013
32014 \end_inset
32015
32016  allow only 
32017 \family typewriter
32018 ajmp
32019 \family default
32020  and 
32021 \family typewriter
32022 acall
32023 \family default
32024 .
32025  The following two rules will change all 
32026 \family typewriter
32027 ljmp
32028 \family default
32029  and 
32030 \family typewriter
32031 lcall
32032 \family default
32033  to 
32034 \family typewriter
32035 ajmp
32036 \family default
32037  and 
32038 \family typewriter
32039 acall
32040
32041 \layout Verse
32042
32043 \family typewriter
32044 replace { lcall %1 } by { acall %1 } 
32045 \newline
32046 replace { ljmp %1 } by { ajmp %1 }
32047
32048 \layout Standard
32049 The 
32050 \emph on
32051 inline-assembler code
32052 \emph default
32053  is also passed through the peep hole optimizer, thus the peephole optimizer
32054  can also be used as an assembly level macro expander.
32055  The rules themselves are MCU dependent whereas the rule language infra-structur
32056 e is MCU independent.
32057  Peephole optimization rules for other MCU can be easily programmed using
32058  the rule language.
32059 \newline
32060
32061 \newline
32062 The syntax for a rule is as follows:
32063
32064 \layout Verse
32065
32066 \family typewriter
32067 rule := replace [ restart ] '{' <assembly sequence> '
32068 \backslash
32069 n' 
32070 \newline
32071 \SpecialChar ~
32072  \SpecialChar ~
32073  \SpecialChar ~
32074  \SpecialChar ~
32075  \SpecialChar ~
32076  \SpecialChar ~
32077  \SpecialChar ~
32078  \SpecialChar ~
32079  \SpecialChar ~
32080  \SpecialChar ~
32081  \SpecialChar ~
32082  \SpecialChar ~
32083  \SpecialChar ~
32084  \SpecialChar ~
32085  '}' by '{' '
32086 \backslash
32087 n' 
32088 \newline
32089 \SpecialChar ~
32090  \SpecialChar ~
32091  \SpecialChar ~
32092  \SpecialChar ~
32093  \SpecialChar ~
32094  \SpecialChar ~
32095  \SpecialChar ~
32096  \SpecialChar ~
32097  \SpecialChar ~
32098  \SpecialChar ~
32099  \SpecialChar ~
32100  \SpecialChar ~
32101  \SpecialChar ~
32102  \SpecialChar ~
32103  \SpecialChar ~
32104  \SpecialChar ~
32105  <assembly sequence> '
32106 \backslash
32107 n' 
32108 \newline
32109 \SpecialChar ~
32110  \SpecialChar ~
32111  \SpecialChar ~
32112  \SpecialChar ~
32113  \SpecialChar ~
32114  \SpecialChar ~
32115  \SpecialChar ~
32116  \SpecialChar ~
32117  \SpecialChar ~
32118  \SpecialChar ~
32119  \SpecialChar ~
32120  \SpecialChar ~
32121  \SpecialChar ~
32122  \SpecialChar ~
32123  '}' [if <functionName> ] '
32124 \backslash
32125 n' 
32126
32127 \layout Standard
32128 <assembly sequence> := assembly instruction (each instruction including
32129  labels must be on a separate line).
32130 \newline
32131
32132 \newline
32133 The optimizer will apply to the rules
32134  one by one from the top in the sequence of their appearance, it will terminate
32135  when all rules are exhausted.
32136  If the 'restart' option is specified, then the optimizer will start matching
32137  the rules again from the top, this option for a rule is expensive (performance)
32138 , it is intended to be used in situations where a transformation will trigger
32139  the same rule again.
32140  An example of this (not a good one, it has side effects) is the following
32141  rule:
32142
32143 \layout Verse
32144
32145 \family typewriter
32146 replace restart { 
32147 \newline
32148 \SpecialChar ~
32149 \SpecialChar ~
32150 pop %1 
32151 \newline
32152 \SpecialChar ~
32153 \SpecialChar ~
32154 push %1 } by { 
32155 \newline
32156 \SpecialChar ~
32157 \SpecialChar ~
32158 ; nop 
32159 \newline
32160 }
32161
32162 \layout Standard
32163 Note that the replace pattern cannot be a blank, but can be a comment line.
32164  Without the 'restart' option only the innermost 'pop' 'push' pair would
32165  be eliminated, i.e.:
32166
32167 \layout Verse
32168
32169 \family typewriter
32170 pop ar1 
32171 \newline
32172 pop ar2 
32173 \newline
32174 push ar2 
32175 \newline
32176 push ar1
32177
32178 \layout Standard
32179 would result in:
32180
32181 \layout Verse
32182
32183 \family typewriter
32184 pop ar1 
32185 \newline
32186 ; nop 
32187 \newline
32188 push ar1
32189
32190 \layout Standard
32191
32192 \emph on
32193 with
32194 \emph default
32195  the restart option the rule will be applied again to the resulting code
32196  and then all the pop-push pairs will be eliminated to yield:
32197
32198 \layout Verse
32199
32200 \family typewriter
32201 ; nop 
32202 \newline
32203 ; nop
32204
32205 \layout Standard
32206 A conditional function can be attached to a rule.
32207  Attaching rules are somewhat more involved, let me illustrate this with
32208  an example.
32209
32210 \layout Verse
32211
32212 \family typewriter
32213 replace { 
32214 \newline
32215 \SpecialChar ~
32216  \SpecialChar ~
32217  \SpecialChar ~
32218 ljmp %5 
32219 \newline
32220 %2:
32221 \newline
32222 } by { 
32223 \newline
32224 \SpecialChar ~
32225  \SpecialChar ~
32226  \SpecialChar ~
32227 sjmp %5 
32228 \newline
32229 %2:
32230 \newline
32231 } if labelInRange
32232
32233 \layout Standard
32234 The optimizer does a look-up of a function name table defined in function
32235  
32236 \emph on
32237 callFuncByName
32238 \emph default
32239  in the source file SDCCpeeph.c, with the name 
32240 \emph on
32241 labelInRange
32242 \emph default
32243 .
32244  If it finds a corresponding entry the function is called.
32245  Note there can be no parameters specified for these functions, in this
32246  case the use of 
32247 \emph on
32248 %5
32249 \emph default
32250  is crucial, since the function 
32251 \emph on
32252 labelInRange
32253 \emph default
32254  expects to find the label in that particular variable (the hash table containin
32255 g the variable bindings is passed as a parameter).
32256  If you want to code more such functions, take a close look at the function
32257  labelInRange and the calling mechanism in source file SDCCpeeph.c.
32258  Currently implemented are 
32259 \emph on
32260 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
32261  24bitMode, portIsDS390, 24bitModeAndPortDS390 
32262 \emph default
32263 and
32264 \emph on
32265  notVolatile
32266 \emph default
32267 .
32268
32269 \layout Standard
32270 I know this whole thing is a little kludgey, but maybe some day we will
32271  have some better means.
32272  If you are looking at this file, you will see the default rules that are
32273  compiled into the compiler, you can add your own rules in the default set
32274  there if you get tired of specifying the -
32275 \begin_inset ERT
32276 status Collapsed
32277
32278 \layout Standard
32279
32280
32281 \backslash
32282 /
32283
32284 \end_inset
32285
32286 -peep-file option.
32287
32288 \layout Section
32289 ANSI-Compliance
32290 \begin_inset LatexCommand \index{ANSI-compliance}
32291
32292 \end_inset
32293
32294
32295 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
32296
32297 \end_inset
32298
32299
32300
32301 \layout Standard
32302 The latest publically available version of the standard 
32303 \emph on
32304 ISO/IEC 9899 - Programming languages - C
32305 \emph default
32306  should be available at: 
32307 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32308
32309 \end_inset
32310
32311 .
32312 \newline
32313
32314
32315 \layout Standard
32316 Deviations from the compliance:
32317
32318 \layout Itemize
32319 functions are not reentrant
32320 \begin_inset LatexCommand \index{reentrant}
32321
32322 \end_inset
32323
32324  unless explicitly declared as such or the 
32325 \series bold
32326 -
32327 \begin_inset ERT
32328 status Collapsed
32329
32330 \layout Standard
32331
32332
32333 \backslash
32334 /
32335
32336 \end_inset
32337
32338 -stack-auto
32339 \begin_inset LatexCommand \index{-\/-stack-auto}
32340
32341 \end_inset
32342
32343
32344 \series default
32345  command line option is specified.
32346
32347 \layout Itemize
32348 structures
32349 \begin_inset LatexCommand \index{struct}
32350
32351 \end_inset
32352
32353  and unions
32354 \begin_inset LatexCommand \index{union}
32355
32356 \end_inset
32357
32358  cannot be assigned values directly, cannot be passed as function parameters
32359  or assigned to each other and cannot be a return value
32360 \begin_inset LatexCommand \index{return value}
32361
32362 \end_inset
32363
32364  from a function, e.g.:
32365
32366 \begin_deeper
32367 \layout Verse
32368
32369 \family typewriter
32370 struct s { ...
32371  }; 
32372 \newline
32373 struct s s1, s2; 
32374 \newline
32375 foo() 
32376 \newline
32377
32378 \newline
32379 \SpecialChar ~
32380 \SpecialChar ~
32381 \SpecialChar ~
32382 \SpecialChar ~
32383 ...
32384  
32385 \newline
32386 \SpecialChar ~
32387 \SpecialChar ~
32388 \SpecialChar ~
32389 \SpecialChar ~
32390 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
32391 \newline
32392 \SpecialChar ~
32393 \SpecialChar ~
32394 \SpecialChar ~
32395 \SpecialChar ~
32396 ...
32397  
32398 \newline
32399 }
32400 \newline
32401
32402 \series bold
32403 struct
32404 \series default
32405  s foo1 (
32406 \series bold
32407 struct
32408 \series default
32409  s parms) /* invalid in SDCC although allowed in ANSI */
32410 \newline
32411
32412 \newline
32413 \SpecialChar ~
32414 \SpecialChar ~
32415 \SpecialChar ~
32416 \SpecialChar ~
32417 struct s rets;
32418  
32419 \newline
32420 \SpecialChar ~
32421 \SpecialChar ~
32422 \SpecialChar ~
32423 \SpecialChar ~
32424 ...
32425  
32426 \newline
32427 \SpecialChar ~
32428 \SpecialChar ~
32429 \SpecialChar ~
32430 \SpecialChar ~
32431 return rets; /* is invalid in SDCC although allowed in ANSI */ 
32432 \newline
32433 }
32434
32435 \end_deeper
32436 \layout Itemize
32437 initialization of structure arrays must be fully braced.
32438
32439 \begin_deeper
32440 \layout Verse
32441
32442 \family typewriter
32443 struct s { char x } a[] = {1, 2};\SpecialChar ~
32444 \SpecialChar ~
32445 \SpecialChar ~
32446 \SpecialChar ~
32447 \SpecialChar ~
32448 /* invalid in SDCC */
32449 \newline
32450 struct s { char x
32451  } a[] = {{1}, {2}}; /* OK */
32452
32453 \end_deeper
32454 \layout Itemize
32455 'long long
32456 \begin_inset LatexCommand \index{long long (not supported)}
32457
32458 \end_inset
32459
32460 ' (64 bit integers
32461 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
32462
32463 \end_inset
32464
32465 ) not supported.
32466
32467 \layout Itemize
32468 'double
32469 \begin_inset LatexCommand \index{double (not supported)}
32470
32471 \end_inset
32472
32473 ' precision floating point 
32474 \begin_inset LatexCommand \index{Floating point support}
32475
32476 \end_inset
32477
32478 not supported.
32479
32480 \layout Itemize
32481 Old K&R style
32482 \begin_inset LatexCommand \index{K\&R style}
32483
32484 \end_inset
32485
32486  function declarations are NOT allowed.
32487
32488 \begin_deeper
32489 \layout Verse
32490
32491 \family typewriter
32492 foo(i,j) /* this old style of function declarations */ 
32493 \newline
32494 int i,j; /* are valid
32495  in ANSI but not valid in SDCC */ 
32496 \newline
32497
32498 \newline
32499 \SpecialChar ~
32500 \SpecialChar ~
32501 \SpecialChar ~
32502 \SpecialChar ~
32503 ...
32504  
32505 \newline
32506 }
32507
32508 \end_deeper
32509 \layout Itemize
32510 Most enhancements in C99 are not supported, f.e.:
32511
32512 \begin_deeper
32513 \layout Verse
32514
32515 \family typewriter
32516 \series bold
32517 inline
32518 \begin_inset LatexCommand \index{inline (not supported)}
32519
32520 \end_inset
32521
32522
32523 \series default
32524  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
32525  in C99.
32526  An empty define 
32527 \emph on
32528 #define inline
32529 \emph default
32530  can be used as a work around */
32531 \newline
32532
32533 \newline
32534 for (
32535 \series bold
32536 int
32537 \series default
32538  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
32539
32540 \end_deeper
32541 \layout Itemize
32542 Certain words that are valid identifiers in the standard may be reserved
32543  words in SDCC unless the 
32544 \series bold
32545 -
32546 \begin_inset ERT
32547 status Collapsed
32548
32549 \layout Standard
32550
32551
32552 \backslash
32553 /
32554
32555 \end_inset
32556
32557 -std-c89
32558 \begin_inset LatexCommand \index{-\/-std-c89}
32559
32560 \end_inset
32561
32562  or -
32563 \begin_inset ERT
32564 status Collapsed
32565
32566 \layout Standard
32567
32568
32569 \backslash
32570 /
32571
32572 \end_inset
32573
32574 -std-c99
32575 \begin_inset LatexCommand \index{-\/-std-c99}
32576
32577 \end_inset
32578
32579
32580 \series default
32581  command line options are used.
32582  These may include (depending on the selected processor): 'at', 'banked',
32583  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
32584 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
32585  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
32586  '_naked'.
32587  Compliant equivalents of these keywords are always available in a form
32588  that begin with two underscores
32589 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
32590
32591 \end_inset
32592
32593 , f.e.
32594  '__data' instead of 'data'.
32595
32596 \layout Section
32597 Cyclomatic Complexity
32598 \begin_inset LatexCommand \index{Cyclomatic complexity}
32599
32600 \end_inset
32601
32602
32603
32604 \layout Standard
32605 Cyclomatic complexity of a function is defined as the number of independent
32606  paths the program can take during execution of the function.
32607  This is an important number since it defines the number test cases you
32608  have to generate to validate the function.
32609  The accepted industry standard for complexity number is 10, if the cyclomatic
32610  complexity reported by SDCC exceeds 10 you should think about simplification
32611  of the function logic.
32612  Note that the complexity level is not related to the number of lines of
32613  code in a function.
32614  Large functions can have low complexity, and small functions can have large
32615  complexity levels.
32616  
32617 \newline
32618
32619 \newline
32620 SDCC uses the following formula to compute the complexity:
32621 \newline
32622
32623
32624 \layout Standard
32625 complexity = (number of edges in control flow graph) - (number of nodes
32626  in control flow graph) + 2;
32627 \newline
32628
32629 \newline
32630 Having said that the industry standard is 10,
32631  you should be aware that in some cases it be may unavoidable to have a
32632  complexity level of less than 10.
32633  For example if you have switch statement with more than 10 case labels,
32634  each case label adds one to the complexity level.
32635  The complexity level is by no means an absolute measure of the algorithmic
32636  complexity of the function, it does however provide a good starting point
32637  for which functions you might look at for further optimization.
32638
32639 \layout Section
32640 Retargetting for other Processors
32641
32642 \layout Standard
32643 The issues for retargetting the compiler are far too numerous to be covered
32644  by this document.
32645  What follows is a brief description of each of the seven phases of the
32646  compiler and its MCU dependency.
32647
32648 \layout Itemize
32649 Parsing the source and building the annotated parse tree.
32650  This phase is largely MCU independent (except for the language extensions).
32651  Syntax & semantic checks are also done in this phase, along with some initial
32652  optimizations like back patching labels and the pattern matching optimizations
32653  like bit-rotation etc.
32654
32655 \layout Itemize
32656 The second phase involves generating an intermediate code which can be easy
32657  manipulated during the later phases.
32658  This phase is entirely MCU independent.
32659  The intermediate code generation assumes the target machine has unlimited
32660  number of registers, and designates them with the name iTemp.
32661  The compiler can be made to dump a human readable form of the code generated
32662  by using the -
32663 \begin_inset ERT
32664 status Collapsed
32665
32666 \layout Standard
32667
32668
32669 \backslash
32670 /
32671
32672 \end_inset
32673
32674 -dumpraw option.
32675
32676 \layout Itemize
32677 This phase does the bulk of the standard optimizations and is also MCU independe
32678 nt.
32679  This phase can be broken down into several sub-phases:
32680 \newline
32681
32682 \newline
32683 Break down intermediate
32684  code (iCode) into basic blocks.
32685 \newline
32686 Do control flow & data flow analysis on the
32687  basic blocks.
32688 \newline
32689 Do local common subexpression elimination, then global subexpressio
32690 n elimination
32691 \newline
32692 Dead code elimination
32693 \newline
32694 Loop optimizations
32695 \newline
32696 If loop optimizations
32697  caused any changes then do 'global subexpression elimination' and 'dead
32698  code elimination' again.
32699
32700 \layout Itemize
32701 This phase determines the live-ranges; by live range I mean those iTemp
32702  variables defined by the compiler that still survive after all the optimization
32703 s.
32704  Live range analysis
32705 \begin_inset LatexCommand \index{Live range analysis}
32706
32707 \end_inset
32708
32709  is essential for register allocation, since these computation determines
32710  which of these iTemps will be assigned to registers, and for how long.
32711
32712 \layout Itemize
32713 Phase five is register allocation.
32714  There are two parts to this process.
32715 \newline
32716
32717 \newline
32718 The first part I call 'register packing'
32719  (for lack of a better term).
32720  In this case several MCU specific expression folding is done to reduce
32721  register pressure.
32722 \newline
32723
32724 \newline
32725 The second part is more MCU independent and deals with
32726  allocating registers to the remaining live ranges.
32727  A lot of MCU specific code does creep into this phase because of the limited
32728  number of index registers available in the 8051.
32729
32730 \layout Itemize
32731 The Code generation phase is (unhappily), entirely MCU dependent and very
32732  little (if any at all) of this code can be reused for other MCU.
32733  However the scheme for allocating a homogenized assembler operand for each
32734  iCode operand may be reused.
32735
32736 \layout Itemize
32737 As mentioned in the optimization section the peep-hole optimizer is rule
32738  based system, which can reprogrammed for other MCUs.
32739
32740 \layout Standard
32741 More information is available in a wiki
32742 \begin_inset LatexCommand \index{wiki}
32743
32744 \end_inset
32745
32746  (preliminary link 
32747 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32748
32749 \end_inset
32750
32751 ) and in the thread 
32752 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32753
32754 \end_inset
32755
32756  .
32757
32758 \layout Chapter
32759 Compiler internals
32760 \begin_inset LatexCommand \index{Compiler internals}
32761
32762 \end_inset
32763
32764
32765
32766 \layout Section
32767 The anatomy of the compiler
32768 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32769
32770 \end_inset
32771
32772
32773
32774 \layout Standard
32775
32776 \shape italic
32777 This is an excerpt from an article published in Circuit Cellar Magazine
32778  in 
32779 \series bold
32780 August 2000
32781 \series default
32782 .
32783  It's a little outdated (the compiler is much more efficient now and user/develo
32784 per friendly), but pretty well exposes the guts of it all.
32785 \shape default
32786
32787 \newline
32788
32789 \newline
32790 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32791  It is fairly easy to retarget for other 8-bit MCU.
32792  Here we take a look at some of the internals of the compiler.
32793  
32794
32795 \layout Paragraph*
32796 Parsing
32797 \begin_inset LatexCommand \index{Parsing}
32798
32799 \end_inset
32800
32801  
32802
32803 \layout Standard
32804 Parsing the input source file and creating an AST (Annotated Syntax Tree
32805 \begin_inset LatexCommand \index{Annotated syntax tree}
32806
32807 \end_inset
32808
32809 ).
32810  This phase also involves propagating types (annotating each node of the
32811  parse tree with type information) and semantic analysis.
32812  There are some MCU specific parsing rules.
32813  For example the storage classes, the extended storage classes are MCU specific
32814  while there may be a xdata storage class for 8051 there is no such storage
32815  class for z80 or Atmel AVR.
32816  SDCC allows MCU specific storage class extensions, i.e.
32817  xdata will be treated as a storage class specifier when parsing 8051 C
32818  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32819  C code.
32820
32821 \layout Paragraph*
32822 Generating iCode
32823 \begin_inset LatexCommand \index{iCode}
32824
32825 \end_inset
32826
32827
32828
32829 \layout Standard
32830 Intermediate code generation.
32831  In this phase the AST is broken down into three-operand form (iCode).
32832  These three operand forms are represented as doubly linked lists.
32833  ICode is the term given to the intermediate form generated by the compiler.
32834  ICode example section shows some examples of iCode generated for some simple
32835  C source functions.
32836
32837 \layout Paragraph*
32838 Optimizations
32839 \begin_inset LatexCommand \index{Optimizations}
32840
32841 \end_inset
32842
32843 .
32844
32845 \layout Standard
32846 Bulk of the target independent optimizations is performed in this phase.
32847  The optimizations include constant propagation, common sub-expression eliminati
32848 on, loop invariant code movement, strength reduction of loop induction variables
32849  and dead-code elimination.
32850
32851 \layout Paragraph*
32852 Live range analysis
32853 \begin_inset LatexCommand \index{Live range analysis}
32854
32855 \end_inset
32856
32857
32858
32859 \layout Standard
32860 During intermediate code generation phase, the compiler assumes the target
32861  machine has infinite number of registers and generates a lot of temporary
32862  variables.
32863  The live range computation determines the lifetime of each of these compiler-ge
32864 nerated temporaries.
32865  A picture speaks a thousand words.
32866  ICode example sections show the live range annotations for each of the
32867  operand.
32868  It is important to note here, each iCode is assigned a number in the order
32869  of its execution in the function.
32870  The live ranges are computed in terms of these numbers.
32871  The from number is the number of the iCode which first defines the operand
32872  and the to number signifies the iCode which uses this operand last.
32873
32874 \layout Paragraph*
32875 Register Allocation
32876 \begin_inset LatexCommand \index{Register allocation}
32877
32878 \end_inset
32879
32880
32881
32882 \layout Standard
32883 The register allocation determines the type and number of registers needed
32884  by each operand.
32885  In most MCUs only a few registers can be used for indirect addressing.
32886  In case of 8051 for example the registers R0 & R1 can be used to indirectly
32887  address the internal ram and DPTR to indirectly address the external ram.
32888  The compiler will try to allocate the appropriate register to pointer variables
32889  if it can.
32890  ICode example section shows the operands annotated with the registers assigned
32891  to them.
32892  The compiler will try to keep operands in registers as much as possible;
32893  there are several schemes the compiler uses to do achieve this.
32894  When the compiler runs out of registers the compiler will check to see
32895  if there are any live operands which is not used or defined in the current
32896  basic block being processed, if there are any found then it will push that
32897  operand and use the registers in this block, the operand will then be popped
32898  at the end of the basic block.
32899  
32900
32901 \layout Standard
32902 There are other MCU specific considerations in this phase.
32903  Some MCUs have an accumulator; very short-lived operands could be assigned
32904  to the accumulator instead of a general-purpose register.
32905
32906 \layout Paragraph*
32907 Code generation
32908
32909 \layout Standard
32910 Figure II gives a table of iCode
32911 \begin_inset LatexCommand \index{iCode}
32912
32913 \end_inset
32914
32915  operations supported by the compiler.
32916  The code generation involves translating these operations into corresponding
32917  assembly code for the processor.
32918  This sounds overly simple but that is the essence of code generation.
32919  Some of the iCode operations are generated on a MCU specific manner for
32920  example, the z80 port does not use registers to pass parameters so the
32921  SEND and RECV iCode operations will not be generated, and it also does
32922  not support JUMPTABLES.
32923  
32924 \newline
32925
32926
32927 \layout Standard
32928
32929 \size footnotesize
32930 Figure II 
32931 \begin_inset Tabular
32932 <lyxtabular version="3" rows="39" columns="4">
32933 <features islongtable="true" headBottomDL="true">
32934 <column alignment="block" valignment="top" leftline="true" width="13col%">
32935 <column alignment="left" valignment="top" leftline="true" width="13col%">
32936 <column alignment="block" valignment="top" leftline="true" width="22col%">
32937 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32938 <row topline="true" bottomline="true" endhead="true">
32939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32940 \begin_inset Text
32941
32942 \layout Standard
32943
32944 \series bold
32945 iCode
32946 \series default
32947
32948 \begin_inset LatexCommand \index{iCode}
32949
32950 \end_inset
32951
32952
32953
32954 \end_inset
32955 </cell>
32956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32957 \begin_inset Text
32958
32959 \layout Standard
32960
32961 \series bold
32962 Operands
32963
32964 \end_inset
32965 </cell>
32966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32967 \begin_inset Text
32968
32969 \layout Standard
32970
32971 \series bold
32972 Description
32973
32974 \end_inset
32975 </cell>
32976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32977 \begin_inset Text
32978
32979 \layout Standard
32980
32981 \series bold
32982 C Equivalent
32983
32984 \end_inset
32985 </cell>
32986 </row>
32987 <row topline="true">
32988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32989 \begin_inset Text
32990
32991 \layout Standard
32992
32993 \size footnotesize
32994 '!'
32995
32996 \end_inset
32997 </cell>
32998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32999 \begin_inset Text
33000
33001 \layout Standard
33002
33003 \size footnotesize
33004 IC_LEFT() IC_RESULT()
33005
33006 \end_inset
33007 </cell>
33008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33009 \begin_inset Text
33010
33011 \layout Standard
33012
33013 \size footnotesize
33014 NOT operation 
33015
33016 \end_inset
33017 </cell>
33018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33019 \begin_inset Text
33020
33021 \layout Standard
33022
33023 \size footnotesize
33024 IC_RESULT = ! IC_LEFT;
33025
33026 \end_inset
33027 </cell>
33028 </row>
33029 <row topline="true">
33030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33031 \begin_inset Text
33032
33033 \layout Standard
33034
33035 \size footnotesize
33036 '~'
33037
33038 \end_inset
33039 </cell>
33040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33041 \begin_inset Text
33042
33043 \layout Standard
33044
33045 \size footnotesize
33046 IC_LEFT() IC_RESULT()
33047
33048 \end_inset
33049 </cell>
33050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33051 \begin_inset Text
33052
33053 \layout Standard
33054
33055 \size footnotesize
33056 Bitwise complement of 
33057
33058 \end_inset
33059 </cell>
33060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33061 \begin_inset Text
33062
33063 \layout Standard
33064
33065 \size footnotesize
33066 IC_RESULT = ~IC_LEFT;
33067
33068 \end_inset
33069 </cell>
33070 </row>
33071 <row topline="true">
33072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33073 \begin_inset Text
33074
33075 \layout Standard
33076
33077 \size footnotesize
33078 RRC
33079
33080 \end_inset
33081 </cell>
33082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33083 \begin_inset Text
33084
33085 \layout Standard
33086
33087 \size footnotesize
33088 IC_LEFT() IC_RESULT()
33089
33090 \end_inset
33091 </cell>
33092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33093 \begin_inset Text
33094
33095 \layout Standard
33096
33097 \size footnotesize
33098 Rotate right with carry
33099
33100 \end_inset
33101 </cell>
33102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33103 \begin_inset Text
33104
33105 \layout Standard
33106
33107 \size footnotesize
33108 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
33109
33110 \end_inset
33111 </cell>
33112 </row>
33113 <row topline="true">
33114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33115 \begin_inset Text
33116
33117 \layout Standard
33118
33119 \size footnotesize
33120 RLC
33121
33122 \end_inset
33123 </cell>
33124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33125 \begin_inset Text
33126
33127 \layout Standard
33128
33129 \size footnotesize
33130 IC_LEFT() IC_RESULT()
33131
33132 \end_inset
33133 </cell>
33134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33135 \begin_inset Text
33136
33137 \layout Standard
33138
33139 \size footnotesize
33140 Rotate left with carry
33141
33142 \end_inset
33143 </cell>
33144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33145 \begin_inset Text
33146
33147 \layout Standard
33148
33149 \size footnotesize
33150 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
33151
33152 \end_inset
33153 </cell>
33154 </row>
33155 <row topline="true">
33156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33157 \begin_inset Text
33158
33159 \layout Standard
33160
33161 \size footnotesize
33162 GETHBIT
33163
33164 \end_inset
33165 </cell>
33166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33167 \begin_inset Text
33168
33169 \layout Standard
33170
33171 \size footnotesize
33172 IC_LEFT() IC_RESULT()
33173
33174 \end_inset
33175 </cell>
33176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33177 \begin_inset Text
33178
33179 \layout Standard
33180
33181 \size footnotesize
33182 Get the highest order bit of IC_LEFT
33183
33184 \end_inset
33185 </cell>
33186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33187 \begin_inset Text
33188
33189 \layout Standard
33190
33191 \size footnotesize
33192 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
33193
33194 \end_inset
33195 </cell>
33196 </row>
33197 <row topline="true">
33198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33199 \begin_inset Text
33200
33201 \layout Standard
33202
33203 \size footnotesize
33204 UNARYMINUS
33205
33206 \end_inset
33207 </cell>
33208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33209 \begin_inset Text
33210
33211 \layout Standard
33212
33213 \size footnotesize
33214 IC_LEFT() IC_RESULT()
33215
33216 \end_inset
33217 </cell>
33218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33219 \begin_inset Text
33220
33221 \layout Standard
33222
33223 \size footnotesize
33224 Unary minus
33225
33226 \end_inset
33227 </cell>
33228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33229 \begin_inset Text
33230
33231 \layout Standard
33232
33233 \size footnotesize
33234 IC_RESULT = - IC_LEFT;
33235
33236 \end_inset
33237 </cell>
33238 </row>
33239 <row topline="true">
33240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33241 \begin_inset Text
33242
33243 \layout Standard
33244
33245 \size footnotesize
33246 IPUSH
33247
33248 \end_inset
33249 </cell>
33250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33251 \begin_inset Text
33252
33253 \layout Standard
33254
33255 \size footnotesize
33256 IC_LEFT()
33257
33258 \end_inset
33259 </cell>
33260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33261 \begin_inset Text
33262
33263 \layout Standard
33264
33265 \size footnotesize
33266 Push the operand into stack
33267
33268 \end_inset
33269 </cell>
33270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33271 \begin_inset Text
33272
33273 \layout Standard
33274
33275 \size footnotesize
33276 NONE
33277
33278 \end_inset
33279 </cell>
33280 </row>
33281 <row topline="true">
33282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33283 \begin_inset Text
33284
33285 \layout Standard
33286
33287 \size footnotesize
33288 IPOP
33289
33290 \end_inset
33291 </cell>
33292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33293 \begin_inset Text
33294
33295 \layout Standard
33296
33297 \size footnotesize
33298 IC_LEFT()
33299
33300 \end_inset
33301 </cell>
33302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33303 \begin_inset Text
33304
33305 \layout Standard
33306
33307 \size footnotesize
33308 Pop the operand from the stack 
33309
33310 \end_inset
33311 </cell>
33312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33313 \begin_inset Text
33314
33315 \layout Standard
33316
33317 \size footnotesize
33318 NONE
33319
33320 \end_inset
33321 </cell>
33322 </row>
33323 <row topline="true">
33324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33325 \begin_inset Text
33326
33327 \layout Standard
33328
33329 \size footnotesize
33330 CALL
33331
33332 \end_inset
33333 </cell>
33334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33335 \begin_inset Text
33336
33337 \layout Standard
33338
33339 \size footnotesize
33340 IC_LEFT() IC_RESULT()
33341
33342 \end_inset
33343 </cell>
33344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33345 \begin_inset Text
33346
33347 \layout Standard
33348
33349 \size footnotesize
33350 Call the function represented by IC_LEFT 
33351
33352 \end_inset
33353 </cell>
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33355 \begin_inset Text
33356
33357 \layout Standard
33358
33359 \size footnotesize
33360 IC_RESULT = IC_LEFT();
33361
33362 \end_inset
33363 </cell>
33364 </row>
33365 <row topline="true">
33366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33367 \begin_inset Text
33368
33369 \layout Standard
33370
33371 \size footnotesize
33372 PCALL
33373
33374 \end_inset
33375 </cell>
33376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33377 \begin_inset Text
33378
33379 \layout Standard
33380
33381 \size footnotesize
33382 IC_LEFT() IC_RESULT()
33383
33384 \end_inset
33385 </cell>
33386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33387 \begin_inset Text
33388
33389 \layout Standard
33390
33391 \size footnotesize
33392 Call via function pointer
33393
33394 \end_inset
33395 </cell>
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33397 \begin_inset Text
33398
33399 \layout Standard
33400
33401 \size footnotesize
33402 IC_RESULT = (*IC_LEFT)();
33403
33404 \end_inset
33405 </cell>
33406 </row>
33407 <row topline="true">
33408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33409 \begin_inset Text
33410
33411 \layout Standard
33412
33413 \size footnotesize
33414 RETURN
33415
33416 \end_inset
33417 </cell>
33418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33419 \begin_inset Text
33420
33421 \layout Standard
33422
33423 \size footnotesize
33424 IC_LEFT()
33425
33426 \end_inset
33427 </cell>
33428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33429 \begin_inset Text
33430
33431 \layout Standard
33432
33433 \size footnotesize
33434 Return the value in operand IC_LEFT 
33435
33436 \end_inset
33437 </cell>
33438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33439 \begin_inset Text
33440
33441 \layout Standard
33442
33443 \size footnotesize
33444 return IC_LEFT;
33445
33446 \end_inset
33447 </cell>
33448 </row>
33449 <row topline="true">
33450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33451 \begin_inset Text
33452
33453 \layout Standard
33454
33455 \size footnotesize
33456 LABEL
33457
33458 \end_inset
33459 </cell>
33460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33461 \begin_inset Text
33462
33463 \layout Standard
33464
33465 \size footnotesize
33466 IC_LABEL() 
33467
33468 \end_inset
33469 </cell>
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33471 \begin_inset Text
33472
33473 \layout Standard
33474
33475 \size footnotesize
33476 Label
33477
33478 \end_inset
33479 </cell>
33480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33481 \begin_inset Text
33482
33483 \layout Standard
33484
33485 \size footnotesize
33486 IC_LABEL:
33487
33488 \end_inset
33489 </cell>
33490 </row>
33491 <row topline="true">
33492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33493 \begin_inset Text
33494
33495 \layout Standard
33496
33497 \size footnotesize
33498 GOTO
33499
33500 \end_inset
33501 </cell>
33502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33503 \begin_inset Text
33504
33505 \layout Standard
33506
33507 \size footnotesize
33508 IC_LABEL() 
33509
33510 \end_inset
33511 </cell>
33512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33513 \begin_inset Text
33514
33515 \layout Standard
33516
33517 \size footnotesize
33518 Goto label
33519
33520 \end_inset
33521 </cell>
33522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33523 \begin_inset Text
33524
33525 \layout Standard
33526
33527 \size footnotesize
33528 goto IC_LABEL();
33529
33530 \end_inset
33531 </cell>
33532 </row>
33533 <row topline="true">
33534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33535 \begin_inset Text
33536
33537 \layout Standard
33538
33539 \size footnotesize
33540 '+'
33541
33542 \end_inset
33543 </cell>
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33545 \begin_inset Text
33546
33547 \layout Standard
33548
33549 \size footnotesize
33550 IC_LEFT() IC_RIGHT() IC_RESULT()
33551
33552 \end_inset
33553 </cell>
33554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33555 \begin_inset Text
33556
33557 \layout Standard
33558
33559 \size footnotesize
33560 Addition
33561
33562 \end_inset
33563 </cell>
33564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33565 \begin_inset Text
33566
33567 \layout Standard
33568
33569 \size footnotesize
33570 IC_RESULT = IC_LEFT + IC_RIGHT
33571
33572 \end_inset
33573 </cell>
33574 </row>
33575 <row topline="true">
33576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33577 \begin_inset Text
33578
33579 \layout Standard
33580
33581 \size footnotesize
33582 '-'
33583
33584 \end_inset
33585 </cell>
33586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33587 \begin_inset Text
33588
33589 \layout Standard
33590
33591 \size footnotesize
33592 IC_LEFT() IC_RIGHT() IC_RESULT()
33593
33594 \end_inset
33595 </cell>
33596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33597 \begin_inset Text
33598
33599 \layout Standard
33600
33601 \size footnotesize
33602 Subtraction
33603
33604 \end_inset
33605 </cell>
33606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33607 \begin_inset Text
33608
33609 \layout Standard
33610
33611 \size footnotesize
33612 IC_RESULT = IC_LEFT - IC_RIGHT 
33613
33614 \end_inset
33615 </cell>
33616 </row>
33617 <row topline="true">
33618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33619 \begin_inset Text
33620
33621 \layout Standard
33622
33623 \size footnotesize
33624 '*'
33625
33626 \end_inset
33627 </cell>
33628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33629 \begin_inset Text
33630
33631 \layout Standard
33632
33633 \size footnotesize
33634 IC_LEFT() IC_RIGHT() IC_RESULT()
33635
33636 \end_inset
33637 </cell>
33638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33639 \begin_inset Text
33640
33641 \layout Standard
33642
33643 \size footnotesize
33644 Multiplication 
33645
33646 \end_inset
33647 </cell>
33648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33649 \begin_inset Text
33650
33651 \layout Standard
33652
33653 \size footnotesize
33654 IC_RESULT = IC_LEFT * IC_RIGHT;
33655
33656 \end_inset
33657 </cell>
33658 </row>
33659 <row topline="true">
33660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33661 \begin_inset Text
33662
33663 \layout Standard
33664
33665 \size footnotesize
33666 '/'
33667
33668 \end_inset
33669 </cell>
33670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33671 \begin_inset Text
33672
33673 \layout Standard
33674
33675 \size footnotesize
33676 IC_LEFT() IC_RIGHT() IC_RESULT()
33677
33678 \end_inset
33679 </cell>
33680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33681 \begin_inset Text
33682
33683 \layout Standard
33684
33685 \size footnotesize
33686 Division
33687
33688 \end_inset
33689 </cell>
33690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33691 \begin_inset Text
33692
33693 \layout Standard
33694
33695 \size footnotesize
33696 IC_RESULT = IC_LEFT / IC_RIGHT;
33697
33698 \end_inset
33699 </cell>
33700 </row>
33701 <row topline="true">
33702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33703 \begin_inset Text
33704
33705 \layout Standard
33706
33707 \size footnotesize
33708 '%'
33709
33710 \end_inset
33711 </cell>
33712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33713 \begin_inset Text
33714
33715 \layout Standard
33716
33717 \size footnotesize
33718 IC_LEFT() IC_RIGHT() IC_RESULT()
33719
33720 \end_inset
33721 </cell>
33722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33723 \begin_inset Text
33724
33725 \layout Standard
33726
33727 \size footnotesize
33728 Modulus
33729
33730 \end_inset
33731 </cell>
33732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33733 \begin_inset Text
33734
33735 \layout Standard
33736
33737 \size footnotesize
33738 IC_RESULT = IC_LEFT % IC_RIGHT;
33739
33740 \end_inset
33741 </cell>
33742 </row>
33743 <row topline="true">
33744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33745 \begin_inset Text
33746
33747 \layout Standard
33748
33749 \size footnotesize
33750 '<'
33751
33752 \end_inset
33753 </cell>
33754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33755 \begin_inset Text
33756
33757 \layout Standard
33758
33759 \size footnotesize
33760 IC_LEFT() IC_RIGHT() IC_RESULT()
33761
33762 \end_inset
33763 </cell>
33764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33765 \begin_inset Text
33766
33767 \layout Standard
33768
33769 \size footnotesize
33770 Less than
33771
33772 \end_inset
33773 </cell>
33774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33775 \begin_inset Text
33776
33777 \layout Standard
33778
33779 \size footnotesize
33780 IC_RESULT = IC_LEFT < IC_RIGHT;
33781
33782 \end_inset
33783 </cell>
33784 </row>
33785 <row topline="true">
33786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33787 \begin_inset Text
33788
33789 \layout Standard
33790
33791 \size footnotesize
33792 '>'
33793
33794 \end_inset
33795 </cell>
33796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33797 \begin_inset Text
33798
33799 \layout Standard
33800
33801 \size footnotesize
33802 IC_LEFT() IC_RIGHT() IC_RESULT()
33803
33804 \end_inset
33805 </cell>
33806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33807 \begin_inset Text
33808
33809 \layout Standard
33810
33811 \size footnotesize
33812 Greater than 
33813
33814 \end_inset
33815 </cell>
33816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33817 \begin_inset Text
33818
33819 \layout Standard
33820
33821 \size footnotesize
33822 IC_RESULT = IC_LEFT > IC_RIGHT;
33823
33824 \end_inset
33825 </cell>
33826 </row>
33827 <row topline="true">
33828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33829 \begin_inset Text
33830
33831 \layout Standard
33832
33833 \size footnotesize
33834 EQ_OP
33835
33836 \end_inset
33837 </cell>
33838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33839 \begin_inset Text
33840
33841 \layout Standard
33842
33843 \size footnotesize
33844 IC_LEFT() IC_RIGHT() IC_RESULT()
33845
33846 \end_inset
33847 </cell>
33848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33849 \begin_inset Text
33850
33851 \layout Standard
33852
33853 \size footnotesize
33854 Equal to 
33855
33856 \end_inset
33857 </cell>
33858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33859 \begin_inset Text
33860
33861 \layout Standard
33862
33863 \size footnotesize
33864 IC_RESULT = IC_LEFT == IC_RIGHT;
33865
33866 \end_inset
33867 </cell>
33868 </row>
33869 <row topline="true">
33870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33871 \begin_inset Text
33872
33873 \layout Standard
33874
33875 \size footnotesize
33876 AND_OP
33877
33878 \end_inset
33879 </cell>
33880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33881 \begin_inset Text
33882
33883 \layout Standard
33884
33885 \size footnotesize
33886 IC_LEFT() IC_RIGHT() IC_RESULT() 
33887
33888 \end_inset
33889 </cell>
33890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33891 \begin_inset Text
33892
33893 \layout Standard
33894
33895 \size footnotesize
33896 Logical and operation
33897
33898 \end_inset
33899 </cell>
33900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33901 \begin_inset Text
33902
33903 \layout Standard
33904
33905 \size footnotesize
33906 IC_RESULT = IC_LEFT && IC_RIGHT; 
33907
33908 \end_inset
33909 </cell>
33910 </row>
33911 <row topline="true">
33912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33913 \begin_inset Text
33914
33915 \layout Standard
33916
33917 \size footnotesize
33918 OR_OP
33919
33920 \end_inset
33921 </cell>
33922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33923 \begin_inset Text
33924
33925 \layout Standard
33926
33927 \size footnotesize
33928 IC_LEFT() IC_RIGHT() IC_RESULT() 
33929
33930 \end_inset
33931 </cell>
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33933 \begin_inset Text
33934
33935 \layout Standard
33936
33937 \size footnotesize
33938 Logical or operation 
33939
33940 \end_inset
33941 </cell>
33942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33943 \begin_inset Text
33944
33945 \layout Standard
33946
33947 \size footnotesize
33948 IC_RESULT = IC_LEFT || IC_RIGHT; 
33949
33950 \end_inset
33951 </cell>
33952 </row>
33953 <row topline="true">
33954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33955 \begin_inset Text
33956
33957 \layout Standard
33958
33959 \size footnotesize
33960 '^'
33961
33962 \end_inset
33963 </cell>
33964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33965 \begin_inset Text
33966
33967 \layout Standard
33968
33969 \size footnotesize
33970 IC_LEFT() IC_RIGHT() IC_RESULT() 
33971
33972 \end_inset
33973 </cell>
33974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33975 \begin_inset Text
33976
33977 \layout Standard
33978
33979 \size footnotesize
33980 Exclusive OR
33981
33982 \end_inset
33983 </cell>
33984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33985 \begin_inset Text
33986
33987 \layout Standard
33988
33989 \size footnotesize
33990 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33991
33992 \end_inset
33993 </cell>
33994 </row>
33995 <row topline="true">
33996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33997 \begin_inset Text
33998
33999 \layout Standard
34000
34001 \size footnotesize
34002 '|'
34003
34004 \end_inset
34005 </cell>
34006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34007 \begin_inset Text
34008
34009 \layout Standard
34010
34011 \size footnotesize
34012 IC_LEFT() IC_RIGHT() IC_RESULT() 
34013
34014 \end_inset
34015 </cell>
34016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34017 \begin_inset Text
34018
34019 \layout Standard
34020
34021 \size footnotesize
34022 Bitwise OR 
34023
34024 \end_inset
34025 </cell>
34026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34027 \begin_inset Text
34028
34029 \layout Standard
34030
34031 \size footnotesize
34032 IC_RESULT = IC_LEFT | IC_RIGHT;
34033
34034 \end_inset
34035 </cell>
34036 </row>
34037 <row topline="true">
34038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34039 \begin_inset Text
34040
34041 \layout Standard
34042
34043 \size footnotesize
34044 BITWISEAND
34045
34046 \end_inset
34047 </cell>
34048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34049 \begin_inset Text
34050
34051 \layout Standard
34052
34053 \size footnotesize
34054 IC_LEFT() IC_RIGHT() IC_RESULT()
34055
34056 \end_inset
34057 </cell>
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34059 \begin_inset Text
34060
34061 \layout Standard
34062
34063 \size footnotesize
34064 Bitwise AND 
34065
34066 \end_inset
34067 </cell>
34068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34069 \begin_inset Text
34070
34071 \layout Standard
34072
34073 \size footnotesize
34074 IC_RESULT = IC_LEFT & IC_RIGHT;
34075
34076 \end_inset
34077 </cell>
34078 </row>
34079 <row topline="true">
34080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34081 \begin_inset Text
34082
34083 \layout Standard
34084
34085 \size footnotesize
34086 LEFT_OP
34087
34088 \end_inset
34089 </cell>
34090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34091 \begin_inset Text
34092
34093 \layout Standard
34094
34095 \size footnotesize
34096 IC_LEFT() IC_RIGHT() IC_RESULT()
34097
34098 \end_inset
34099 </cell>
34100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34101 \begin_inset Text
34102
34103 \layout Standard
34104
34105 \size footnotesize
34106 Left shift 
34107
34108 \end_inset
34109 </cell>
34110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34111 \begin_inset Text
34112
34113 \layout Standard
34114
34115 \size footnotesize
34116 IC_RESULT = IC_LEFT << IC_RIGHT 
34117
34118 \end_inset
34119 </cell>
34120 </row>
34121 <row topline="true">
34122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34123 \begin_inset Text
34124
34125 \layout Standard
34126
34127 \size footnotesize
34128 RIGHT_OP
34129
34130 \end_inset
34131 </cell>
34132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34133 \begin_inset Text
34134
34135 \layout Standard
34136
34137 \size footnotesize
34138 IC_LEFT() IC_RIGHT() IC_RESULT()
34139
34140 \end_inset
34141 </cell>
34142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34143 \begin_inset Text
34144
34145 \layout Standard
34146
34147 \size footnotesize
34148 Right shift
34149
34150 \end_inset
34151 </cell>
34152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34153 \begin_inset Text
34154
34155 \layout Standard
34156
34157 \size footnotesize
34158 IC_RESULT = IC_LEFT >> IC_RIGHT 
34159
34160 \end_inset
34161 </cell>
34162 </row>
34163 <row topline="true">
34164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34165 \begin_inset Text
34166
34167 \layout Standard
34168
34169 \size footnotesize
34170 GET_VALUE_
34171 \newline
34172 AT_ ADDRESS
34173
34174 \end_inset
34175 </cell>
34176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34177 \begin_inset Text
34178
34179 \layout Standard
34180
34181 \size footnotesize
34182 IC_LEFT() IC_RESULT()
34183
34184 \end_inset
34185 </cell>
34186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34187 \begin_inset Text
34188
34189 \layout Standard
34190
34191 \size footnotesize
34192 Indirect fetch 
34193
34194 \end_inset
34195 </cell>
34196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34197 \begin_inset Text
34198
34199 \layout Standard
34200
34201 \size footnotesize
34202 IC_RESULT = (*IC_LEFT);
34203
34204 \end_inset
34205 </cell>
34206 </row>
34207 <row topline="true">
34208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34209 \begin_inset Text
34210
34211 \layout Standard
34212
34213 \size footnotesize
34214 POINTER_SET
34215
34216 \end_inset
34217 </cell>
34218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34219 \begin_inset Text
34220
34221 \layout Standard
34222
34223 \size footnotesize
34224 IC_RIGHT() IC_RESULT() 
34225
34226 \end_inset
34227 </cell>
34228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34229 \begin_inset Text
34230
34231 \layout Standard
34232
34233 \size footnotesize
34234 Indirect set
34235
34236 \end_inset
34237 </cell>
34238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34239 \begin_inset Text
34240
34241 \layout Standard
34242
34243 \size footnotesize
34244 (*IC_RESULT) = IC_RIGHT;
34245
34246 \end_inset
34247 </cell>
34248 </row>
34249 <row topline="true">
34250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34251 \begin_inset Text
34252
34253 \layout Standard
34254
34255 \size footnotesize
34256 '='
34257
34258 \end_inset
34259 </cell>
34260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34261 \begin_inset Text
34262
34263 \layout Standard
34264
34265 \size footnotesize
34266 IC_RIGHT() IC_RESULT()
34267
34268 \end_inset
34269 </cell>
34270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34271 \begin_inset Text
34272
34273 \layout Standard
34274
34275 \size footnotesize
34276 Assignment
34277
34278 \end_inset
34279 </cell>
34280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34281 \begin_inset Text
34282
34283 \layout Standard
34284
34285 \size footnotesize
34286 IC_RESULT = IC_RIGHT;
34287
34288 \end_inset
34289 </cell>
34290 </row>
34291 <row topline="true">
34292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34293 \begin_inset Text
34294
34295 \layout Standard
34296
34297 \size footnotesize
34298 IFX
34299
34300 \end_inset
34301 </cell>
34302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34303 \begin_inset Text
34304
34305 \layout Standard
34306
34307 \size footnotesize
34308 IC_COND IC_TRUE IC_LABEL
34309
34310 \end_inset
34311 </cell>
34312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34313 \begin_inset Text
34314
34315 \layout Standard
34316
34317 \size footnotesize
34318 Conditional jump.
34319  If true label is present then jump to true label if condition is true else
34320  jump to false label if condition is false 
34321
34322 \end_inset
34323 </cell>
34324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34325 \begin_inset Text
34326
34327 \layout Standard
34328
34329 \size footnotesize
34330 if (IC_COND) goto IC_TRUE; 
34331 \newline
34332 \SpecialChar ~
34333 \SpecialChar ~
34334 Or 
34335 \newline
34336 If (!IC_COND) goto IC_FALSE;
34337
34338 \end_inset
34339 </cell>
34340 </row>
34341 <row topline="true">
34342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34343 \begin_inset Text
34344
34345 \layout Standard
34346
34347 \size footnotesize
34348 ADDRESS_OF
34349
34350 \end_inset
34351 </cell>
34352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34353 \begin_inset Text
34354
34355 \layout Standard
34356
34357 \size footnotesize
34358 IC_LEFT() IC_RESULT()
34359
34360 \end_inset
34361 </cell>
34362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34363 \begin_inset Text
34364
34365 \layout Standard
34366
34367 \size footnotesize
34368 Address of 
34369
34370 \end_inset
34371 </cell>
34372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34373 \begin_inset Text
34374
34375 \layout Standard
34376
34377 \size footnotesize
34378 IC_RESULT = &IC_LEFT();
34379
34380 \end_inset
34381 </cell>
34382 </row>
34383 <row topline="true">
34384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34385 \begin_inset Text
34386
34387 \layout Standard
34388
34389 \size footnotesize
34390 JUMPTABLE
34391
34392 \end_inset
34393 </cell>
34394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34395 \begin_inset Text
34396
34397 \layout Standard
34398
34399 \size footnotesize
34400 IC_JTCOND IC_JTLABELS
34401
34402 \end_inset
34403 </cell>
34404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34405 \begin_inset Text
34406
34407 \layout Standard
34408
34409 \size footnotesize
34410 Jump to list of labels depending on the value of JTCOND
34411
34412 \end_inset
34413 </cell>
34414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34415 \begin_inset Text
34416
34417 \layout Standard
34418
34419 \size footnotesize
34420 Switch statement
34421
34422 \end_inset
34423 </cell>
34424 </row>
34425 <row topline="true">
34426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34427 \begin_inset Text
34428
34429 \layout Standard
34430
34431 \size footnotesize
34432 CAST
34433
34434 \end_inset
34435 </cell>
34436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34437 \begin_inset Text
34438
34439 \layout Standard
34440
34441 \size footnotesize
34442 IC_RIGHT() IC_LEFT() IC_RESULT()
34443
34444 \end_inset
34445 </cell>
34446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34447 \begin_inset Text
34448
34449 \layout Standard
34450
34451 \size footnotesize
34452 Cast types 
34453
34454 \end_inset
34455 </cell>
34456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34457 \begin_inset Text
34458
34459 \layout Standard
34460
34461 \size footnotesize
34462 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
34463
34464 \end_inset
34465 </cell>
34466 </row>
34467 <row topline="true">
34468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34469 \begin_inset Text
34470
34471 \layout Standard
34472
34473 \size footnotesize
34474 SEND
34475
34476 \end_inset
34477 </cell>
34478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34479 \begin_inset Text
34480
34481 \layout Standard
34482
34483 \size footnotesize
34484 IC_LEFT()
34485
34486 \end_inset
34487 </cell>
34488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34489 \begin_inset Text
34490
34491 \layout Standard
34492
34493 \size footnotesize
34494 This is used for passing parameters in registers; 
34495 \newline
34496 move IC_LEFT to the next
34497  available parameter register.
34498
34499 \end_inset
34500 </cell>
34501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34502 \begin_inset Text
34503
34504 \layout Standard
34505
34506 \size footnotesize
34507 None
34508
34509 \end_inset
34510 </cell>
34511 </row>
34512 <row topline="true">
34513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34514 \begin_inset Text
34515
34516 \layout Standard
34517
34518 \size footnotesize
34519 RECV
34520
34521 \end_inset
34522 </cell>
34523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34524 \begin_inset Text
34525
34526 \layout Standard
34527
34528 \size footnotesize
34529 IC_RESULT()
34530
34531 \end_inset
34532 </cell>
34533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34534 \begin_inset Text
34535
34536 \layout Standard
34537
34538 \size footnotesize
34539 This is used for receiving parameters passed in registers;
34540 \newline
34541 Move the values
34542  in the next parameter register to IC_RESULT 
34543
34544 \end_inset
34545 </cell>
34546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34547 \begin_inset Text
34548
34549 \layout Standard
34550
34551 \size footnotesize
34552 None
34553
34554 \end_inset
34555 </cell>
34556 </row>
34557 <row topline="true" bottomline="true">
34558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34559 \begin_inset Text
34560
34561 \layout Standard
34562
34563 \shape slanted
34564 \size footnotesize
34565 (some more have been added)
34566
34567 \end_inset
34568 </cell>
34569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34570 \begin_inset Text
34571
34572 \layout Standard
34573
34574
34575 \end_inset
34576 </cell>
34577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34578 \begin_inset Text
34579
34580 \layout Standard
34581
34582
34583 \end_inset
34584 </cell>
34585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34586 \begin_inset Text
34587
34588 \layout Standard
34589
34590 \shape slanted
34591 \size footnotesize
34592 see f.e.
34593  
34594 \family typewriter
34595 gen51Code()
34596 \family default
34597  in 
34598 \family typewriter
34599 src/mcs51/gen.c
34600
34601 \end_inset
34602 </cell>
34603 </row>
34604 </lyxtabular>
34605
34606 \end_inset
34607
34608
34609
34610 \layout Standard
34611 \begin_inset Note
34612 collapsed true
34613
34614 \layout Standard
34615 In the original article Figure II was announced to be downloadable on 
34616 \shape italic
34617 Circuit Cellar
34618 \shape default
34619 's web site.
34620  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
34621
34622 \end_inset
34623
34624
34625
34626 \layout Paragraph*
34627 ICode Example
34628 \begin_inset LatexCommand \index{iCode}
34629
34630 \end_inset
34631
34632
34633
34634 \layout Standard
34635 This section shows some details of iCode.
34636  The example C code does not do anything useful; it is used as an example
34637  to illustrate the intermediate code generated by the compiler.
34638
34639 \layout Verse
34640
34641 \family typewriter
34642 1.\SpecialChar ~
34643 xdata int * p;
34644 \newline
34645 2.\SpecialChar ~
34646 int gint;
34647 \newline
34648 3.\SpecialChar ~
34649 /* This function does nothing useful.
34650  It is used
34651 \newline
34652 4.\SpecialChar ~
34653 \SpecialChar ~
34654 \SpecialChar ~
34655 \SpecialChar ~
34656 for the purpose of explaining iCode */
34657 \newline
34658 5.\SpecialChar ~
34659 short function (data
34660  int *x)
34661 \newline
34662 6.\SpecialChar ~
34663 {
34664 \newline
34665 7.\SpecialChar ~
34666 \SpecialChar ~
34667 \SpecialChar ~
34668 short i=10; \SpecialChar ~
34669 \SpecialChar ~
34670 /* dead initialization eliminated */
34671 \newline
34672 8.\SpecialChar ~
34673 \SpecialChar ~
34674 \SpecialChar ~
34675 short sum=10;
34676  /* dead initialization eliminated */
34677 \newline
34678 9.\SpecialChar ~
34679 \SpecialChar ~
34680 \SpecialChar ~
34681 short mul;
34682 \newline
34683 10.\SpecialChar ~
34684 \SpecialChar ~
34685 int j ;
34686 \newline
34687 11.\SpecialChar ~
34688 \SpecialChar ~
34689 while (*x) *x++
34690  = *p++; 
34691 \newline
34692 12.\SpecialChar ~
34693 \SpecialChar ~
34694 \SpecialChar ~
34695 \SpecialChar ~
34696 sum = 0 ; 
34697 \newline
34698 13.\SpecialChar ~
34699 \SpecialChar ~
34700 mul = 0;
34701 \newline
34702 14.\SpecialChar ~
34703 \SpecialChar ~
34704 /* compiler detects i,j to be induction
34705  variables */
34706 \newline
34707 15.\SpecialChar ~
34708 \SpecialChar ~
34709 for (i = 0, j = 10 ; i < 10 ; i++, j
34710 \family default
34711 -
34712 \begin_inset ERT
34713 status Collapsed
34714
34715 \layout Standard
34716
34717
34718 \backslash
34719 /
34720
34721 \end_inset
34722
34723 -
34724 \family typewriter
34725 ) {
34726 \newline
34727 16.\SpecialChar ~
34728 \SpecialChar ~
34729 \SpecialChar ~
34730 \SpecialChar ~
34731 sum += i;
34732 \newline
34733 17.\SpecialChar ~
34734 \SpecialChar ~
34735 \SpecialChar ~
34736 \SpecialChar ~
34737 mul += i * 3; \SpecialChar ~
34738 \SpecialChar ~
34739 /* this multiplication remains */
34740 \newline
34741 18.\SpecialChar ~
34742 \SpecialChar ~
34743 \SpecialChar ~
34744 \SpecialChar ~
34745 gint +=
34746  j * 3;\SpecialChar ~
34747 \SpecialChar ~
34748 /* this multiplication changed to addition */
34749 \newline
34750 19.\SpecialChar ~
34751 \SpecialChar ~
34752 }
34753 \newline
34754 20.\SpecialChar ~
34755 \SpecialChar ~
34756 return sum+mul;
34757 \newline
34758 21.\SpecialChar ~
34759 }
34760
34761 \layout Standard
34762 In addition to the operands each iCode contains information about the filename
34763  and line it corresponds to in the source file.
34764  The first field in the listing should be interpreted as follows:
34765 \newline
34766
34767 \shape italic
34768 \size footnotesize
34769 Filename(linenumber: iCode Execution sequence number : ICode hash table
34770  key : loop depth of the iCode).
34771 \shape default
34772 \size default
34773
34774 \newline
34775 Then follows the human readable form of the ICode operation.
34776  Each operand of this triplet form can be of three basic types a) compiler
34777  generated temporary b) user defined variable c) a constant value.
34778  Note that local variables and parameters are replaced by compiler generated
34779  temporaries.
34780  Live ranges
34781 \begin_inset LatexCommand \index{Live range analysis}
34782
34783 \end_inset
34784
34785  are computed only for temporaries (i.e.
34786  live ranges are not computed for global variables).
34787  Registers
34788 \begin_inset LatexCommand \index{Register allocation}
34789
34790 \end_inset
34791
34792  are allocated for temporaries only.
34793  Operands are formatted in the following manner:
34794 \newline
34795
34796 \shape italic
34797 \size footnotesize
34798 Operand Name [lr live-from : live-to ] { type information } [ registers
34799  allocated ].
34800 \shape default
34801 \size default
34802
34803 \newline
34804 As mentioned earlier the live ranges are computed in terms of the execution
34805  sequence number of the iCodes, for example 
34806 \newline
34807 the iTemp0 is live from (i.e.
34808  first defined in iCode with execution sequence number 3, and is last used
34809  in the iCode with sequence number 5).
34810  For induction variables such as iTemp21 the live range computation extends
34811  the lifetime from the start to the end of the loop.
34812 \newline
34813 The register allocator
34814  used the live range information to allocate registers, the same registers
34815  may be used for different temporaries if their live ranges do not overlap,
34816  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
34817  ranges do not overlap.
34818  In addition the allocator also takes into consideration the type and usage
34819  of a temporary, for example itemp6 is a pointer to near space and is used
34820  as to fetch data from (i.e.
34821  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34822  Some short lived temporaries are allocated to special registers which have
34823  meaning to the code generator e.g.
34824  iTemp13 is allocated to a pseudo register CC which tells the back end that
34825  the temporary is used only for a conditional jump the code generation makes
34826  use of this information to optimize a compare and jump ICode.
34827 \newline
34828 There are several
34829  loop optimizations
34830 \begin_inset LatexCommand \index{Loop optimization}
34831
34832 \end_inset
34833
34834  performed by the compiler.
34835  It can detect induction variables iTemp21(i) and iTemp23(j).
34836  Also note the compiler does selective strength reduction
34837 \begin_inset LatexCommand \index{Strength reduction}
34838
34839 \end_inset
34840
34841 , i.e.
34842  the multiplication of an induction variable in line 18 (gint = j * 3) is
34843  changed to addition, a new temporary iTemp17 is allocated and assigned
34844  a initial value, a constant 3 is then added for each iteration of the loop.
34845  The compiler does not change the multiplication
34846 \begin_inset LatexCommand \index{Multiplication}
34847
34848 \end_inset
34849
34850  in line 17 however since the processor does support an 8 * 8 bit multiplication.
34851 \newline
34852
34853 Note the dead code elimination
34854 \begin_inset LatexCommand \index{Dead-code elimination}
34855
34856 \end_inset
34857
34858  optimization eliminated the dead assignments in line 7 & 8 to I and sum
34859  respectively.
34860 \newline
34861
34862
34863 \layout Standard
34864
34865 \size footnotesize
34866 Sample.c (5:1:0:0) _entry($9) :
34867
34868 \layout Standard
34869
34870 \size footnotesize
34871 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34872
34873 \layout Standard
34874
34875 \size footnotesize
34876 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
34877
34878 \layout Standard
34879
34880 \size footnotesize
34881 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34882
34883 \layout Standard
34884
34885 \size footnotesize
34886 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34887  * int}[r2]
34888
34889 \layout Standard
34890
34891 \size footnotesize
34892 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34893
34894 \layout Standard
34895
34896 \size footnotesize
34897 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34898  int}[r0]]
34899
34900 \layout Standard
34901
34902 \size footnotesize
34903 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34904
34905 \layout Standard
34906
34907 \size footnotesize
34908 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34909  * int}
34910
34911 \layout Standard
34912
34913 \size footnotesize
34914 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34915  {short}
34916
34917 \layout Standard
34918
34919 \size footnotesize
34920 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34921  * int}[DPTR]]
34922
34923 \layout Standard
34924
34925 \size footnotesize
34926 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34927 }[r2 r3]
34928
34929 \layout Standard
34930
34931 \size footnotesize
34932 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34933  * int}[r0] + 0x2 {short}
34934
34935 \layout Standard
34936
34937 \size footnotesize
34938 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34939
34940 \layout Standard
34941
34942 \size footnotesize
34943 Sample.c(11:17:21:0)_whilebreak_0($3) :
34944
34945 \layout Standard
34946
34947 \size footnotesize
34948 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34949
34950 \layout Standard
34951
34952 \size footnotesize
34953 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34954
34955 \layout Standard
34956
34957 \size footnotesize
34958 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34959
34960 \layout Standard
34961
34962 \size footnotesize
34963 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34964
34965 \layout Standard
34966
34967 \size footnotesize
34968 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34969
34970 \layout Standard
34971
34972 \size footnotesize
34973 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34974
34975 \layout Standard
34976
34977 \size footnotesize
34978 Sample.c(15:24:26:1)_forcond_0($4) :
34979
34980 \layout Standard
34981
34982 \size footnotesize
34983 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34984  < 0xa {short}
34985
34986 \layout Standard
34987
34988 \size footnotesize
34989 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34990
34991 \layout Standard
34992
34993 \size footnotesize
34994 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34995  + ITemp21 [lr21:38]{short}[r4]
34996
34997 \layout Standard
34998
34999 \size footnotesize
35000 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
35001  * 0x3 {short}
35002
35003 \layout Standard
35004
35005 \size footnotesize
35006 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
35007  + iTemp15 [lr29:30]{short}[r1]
35008
35009 \layout Standard
35010
35011 \size footnotesize
35012 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
35013  r0]- 0x3 {short}
35014
35015 \layout Standard
35016
35017 \size footnotesize
35018 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
35019 int}[r7 r0]
35020
35021 \layout Standard
35022
35023 \size footnotesize
35024 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
35025  + 0x1 {short}
35026
35027 \layout Standard
35028
35029 \size footnotesize
35030 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
35031  r6]- 0x1 {short}
35032
35033 \layout Standard
35034
35035 \size footnotesize
35036 Sample.c(19:38:47:1) goto _forcond_0($4)
35037
35038 \layout Standard
35039
35040 \size footnotesize
35041 Sample.c(19:39:48:0)_forbreak_0($7) :
35042
35043 \layout Standard
35044
35045 \size footnotesize
35046 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
35047  + ITemp11 [lr19:40]{short}[r3]
35048
35049 \layout Standard
35050
35051 \size footnotesize
35052 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
35053
35054 \layout Standard
35055
35056 \size footnotesize
35057 Sample.c(20:42:51:0)_return($8) :
35058
35059 \layout Standard
35060
35061 \size footnotesize
35062 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
35063 \size default
35064
35065 \newline
35066
35067 \newline
35068 Finally the code generated for this function:
35069 \newline
35070
35071
35072 \layout Standard
35073
35074 \size footnotesize
35075 .area DSEG (DATA)
35076
35077 \layout Standard
35078
35079 \size footnotesize
35080 _p::
35081
35082 \layout Standard
35083
35084 \size footnotesize
35085 \SpecialChar ~
35086 \SpecialChar ~
35087 .ds 2
35088
35089 \layout Standard
35090
35091 \size footnotesize
35092 _gint::
35093
35094 \layout Standard
35095
35096 \size footnotesize
35097 \SpecialChar ~
35098 \SpecialChar ~
35099 .ds 2
35100
35101 \layout Standard
35102
35103 \size footnotesize
35104 ; sample.c 5
35105
35106 \layout Standard
35107
35108 \size footnotesize
35109 ; ----------------------------------------------
35110
35111 \layout Standard
35112
35113 \size footnotesize
35114 ; function function
35115
35116 \layout Standard
35117
35118 \size footnotesize
35119 ; ----------------------------------------------
35120
35121 \layout Standard
35122
35123 \size footnotesize
35124 _function:
35125
35126 \layout Standard
35127
35128 \size footnotesize
35129 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
35130
35131 \layout Standard
35132
35133 \size footnotesize
35134 \SpecialChar ~
35135 \SpecialChar ~
35136 mov r2,dpl
35137
35138 \layout Standard
35139
35140 \size footnotesize
35141 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
35142
35143 \layout Standard
35144
35145 \size footnotesize
35146 \SpecialChar ~
35147 \SpecialChar ~
35148 mov ar0,r2
35149
35150 \layout Standard
35151
35152 \size footnotesize
35153 ;_whilecontinue_0($1) :
35154
35155 \layout Standard
35156
35157 \size footnotesize
35158 00101$:
35159
35160 \layout Standard
35161
35162 \size footnotesize
35163 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
35164
35165 \layout Standard
35166
35167 \size footnotesize
35168 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
35169
35170 \layout Standard
35171
35172 \size footnotesize
35173 \SpecialChar ~
35174 \SpecialChar ~
35175 mov ar2,@r0
35176
35177 \layout Standard
35178
35179 \size footnotesize
35180 \SpecialChar ~
35181 \SpecialChar ~
35182 inc r0
35183
35184 \layout Standard
35185
35186 \size footnotesize
35187 \SpecialChar ~
35188 \SpecialChar ~
35189 mov ar3,@r0
35190
35191 \layout Standard
35192
35193 \size footnotesize
35194 \SpecialChar ~
35195 \SpecialChar ~
35196 dec r0
35197
35198 \layout Standard
35199
35200 \size footnotesize
35201 \SpecialChar ~
35202 \SpecialChar ~
35203 mov a,r2
35204
35205 \layout Standard
35206
35207 \size footnotesize
35208 \SpecialChar ~
35209 \SpecialChar ~
35210 orl a,r3
35211
35212 \layout Standard
35213
35214 \size footnotesize
35215 \SpecialChar ~
35216 \SpecialChar ~
35217 jz 00103$
35218
35219 \layout Standard
35220
35221 \size footnotesize
35222 00114$:
35223
35224 \layout Standard
35225
35226 \size footnotesize
35227 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
35228
35229 \layout Standard
35230
35231 \size footnotesize
35232 \SpecialChar ~
35233 \SpecialChar ~
35234 mov dpl,_p
35235
35236 \layout Standard
35237
35238 \size footnotesize
35239 \SpecialChar ~
35240 \SpecialChar ~
35241 mov dph,(_p + 1)
35242
35243 \layout Standard
35244
35245 \size footnotesize
35246 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
35247
35248 \layout Standard
35249
35250 \size footnotesize
35251 \SpecialChar ~
35252 \SpecialChar ~
35253 mov a,#0x02
35254
35255 \layout Standard
35256
35257 \size footnotesize
35258 \SpecialChar ~
35259 \SpecialChar ~
35260 add a,_p
35261
35262 \layout Standard
35263
35264 \size footnotesize
35265 \SpecialChar ~
35266 \SpecialChar ~
35267 mov _p,a
35268
35269 \layout Standard
35270
35271 \size footnotesize
35272 \SpecialChar ~
35273 \SpecialChar ~
35274 clr a
35275
35276 \layout Standard
35277
35278 \size footnotesize
35279 \SpecialChar ~
35280 \SpecialChar ~
35281 addc a,(_p + 1)
35282
35283 \layout Standard
35284
35285 \size footnotesize
35286 \SpecialChar ~
35287 \SpecialChar ~
35288 mov (_p + 1),a
35289
35290 \layout Standard
35291
35292 \size footnotesize
35293 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
35294
35295 \layout Standard
35296
35297 \size footnotesize
35298 \SpecialChar ~
35299 \SpecialChar ~
35300 movx a,@dptr
35301
35302 \layout Standard
35303
35304 \size footnotesize
35305 \SpecialChar ~
35306 \SpecialChar ~
35307 mov r2,a
35308
35309 \layout Standard
35310
35311 \size footnotesize
35312 \SpecialChar ~
35313 \SpecialChar ~
35314 inc dptr
35315
35316 \layout Standard
35317
35318 \size footnotesize
35319 \SpecialChar ~
35320 \SpecialChar ~
35321 movx a,@dptr
35322
35323 \layout Standard
35324
35325 \size footnotesize
35326 \SpecialChar ~
35327 \SpecialChar ~
35328 mov r3,a
35329
35330 \layout Standard
35331
35332 \size footnotesize
35333 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
35334
35335 \layout Standard
35336
35337 \size footnotesize
35338 \SpecialChar ~
35339 \SpecialChar ~
35340 mov @r0,ar2
35341
35342 \layout Standard
35343
35344 \size footnotesize
35345 \SpecialChar ~
35346 \SpecialChar ~
35347 inc r0
35348
35349 \layout Standard
35350
35351 \size footnotesize
35352 \SpecialChar ~
35353 \SpecialChar ~
35354 mov @r0,ar3
35355
35356 \layout Standard
35357
35358 \size footnotesize
35359 ; iTemp6 [lr5:16]{_near * int}[r0] = 
35360
35361 \layout Standard
35362
35363 \size footnotesize
35364 ; iTemp6 [lr5:16]{_near * int}[r0] + 
35365
35366 \layout Standard
35367
35368 \size footnotesize
35369 ; 0x2 {short}
35370
35371 \layout Standard
35372
35373 \size footnotesize
35374 \SpecialChar ~
35375 \SpecialChar ~
35376 inc r0
35377
35378 \layout Standard
35379
35380 \size footnotesize
35381 ; goto _whilecontinue_0($1)
35382
35383 \layout Standard
35384
35385 \size footnotesize
35386 \SpecialChar ~
35387 \SpecialChar ~
35388 sjmp 00101$
35389
35390 \layout Standard
35391
35392 \size footnotesize
35393 ; _whilebreak_0($3) :
35394
35395 \layout Standard
35396
35397 \size footnotesize
35398 00103$:
35399
35400 \layout Standard
35401
35402 \size footnotesize
35403 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
35404
35405 \layout Standard
35406
35407 \size footnotesize
35408 \SpecialChar ~
35409 \SpecialChar ~
35410 mov r2,#0x00
35411
35412 \layout Standard
35413
35414 \size footnotesize
35415 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
35416
35417 \layout Standard
35418
35419 \size footnotesize
35420 \SpecialChar ~
35421 \SpecialChar ~
35422 mov r3,#0x00
35423
35424 \layout Standard
35425
35426 \size footnotesize
35427 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
35428
35429 \layout Standard
35430
35431 \size footnotesize
35432 \SpecialChar ~
35433 \SpecialChar ~
35434 mov r4,#0x00
35435
35436 \layout Standard
35437
35438 \size footnotesize
35439 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
35440
35441 \layout Standard
35442
35443 \size footnotesize
35444 \SpecialChar ~
35445 \SpecialChar ~
35446 mov r5,#0x0A
35447
35448 \layout Standard
35449
35450 \size footnotesize
35451 \SpecialChar ~
35452 \SpecialChar ~
35453 mov r6,#0x00
35454
35455 \layout Standard
35456
35457 \size footnotesize
35458 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
35459
35460 \layout Standard
35461
35462 \size footnotesize
35463 \SpecialChar ~
35464 \SpecialChar ~
35465 mov r7,#0x1E
35466
35467 \layout Standard
35468
35469 \size footnotesize
35470 \SpecialChar ~
35471 \SpecialChar ~
35472 mov r0,#0x00
35473
35474 \layout Standard
35475
35476 \size footnotesize
35477 ; _forcond_0($4) :
35478
35479 \layout Standard
35480
35481 \size footnotesize
35482 00104$:
35483
35484 \layout Standard
35485
35486 \size footnotesize
35487 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
35488
35489 \layout Standard
35490
35491 \size footnotesize
35492 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
35493
35494 \layout Standard
35495
35496 \size footnotesize
35497 \SpecialChar ~
35498 \SpecialChar ~
35499 clr c
35500
35501 \layout Standard
35502
35503 \size footnotesize
35504 \SpecialChar ~
35505 \SpecialChar ~
35506 mov a,r4
35507
35508 \layout Standard
35509
35510 \size footnotesize
35511 \SpecialChar ~
35512 \SpecialChar ~
35513 xrl a,#0x80
35514
35515 \layout Standard
35516
35517 \size footnotesize
35518 \SpecialChar ~
35519 \SpecialChar ~
35520 subb a,#0x8a
35521
35522 \layout Standard
35523
35524 \size footnotesize
35525 \SpecialChar ~
35526 \SpecialChar ~
35527 jnc 00107$
35528
35529 \layout Standard
35530
35531 \size footnotesize
35532 00115$:
35533
35534 \layout Standard
35535
35536 \size footnotesize
35537 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
35538
35539 \layout Standard
35540
35541 \size footnotesize
35542 ; iTemp21 [lr21:38]{short}[r4]
35543
35544 \layout Standard
35545
35546 \size footnotesize
35547 \SpecialChar ~
35548 \SpecialChar ~
35549 mov a,r4
35550
35551 \layout Standard
35552
35553 \size footnotesize
35554 \SpecialChar ~
35555 \SpecialChar ~
35556 add a,r2
35557
35558 \layout Standard
35559
35560 \size footnotesize
35561 \SpecialChar ~
35562 \SpecialChar ~
35563 mov r2,a
35564
35565 \layout Standard
35566
35567 \size footnotesize
35568 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
35569
35570 \layout Standard
35571
35572 \size footnotesize
35573 \SpecialChar ~
35574 \SpecialChar ~
35575 mov b,#0x03
35576
35577 \layout Standard
35578
35579 \size footnotesize
35580 \SpecialChar ~
35581 \SpecialChar ~
35582 mov a,r4
35583
35584 \layout Standard
35585
35586 \size footnotesize
35587 \SpecialChar ~
35588 \SpecialChar ~
35589 mul ab
35590
35591 \layout Standard
35592
35593 \size footnotesize
35594 \SpecialChar ~
35595 \SpecialChar ~
35596 mov r1,a
35597
35598 \layout Standard
35599
35600 \size footnotesize
35601 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
35602
35603 \layout Standard
35604
35605 \size footnotesize
35606 ; iTemp15 [lr29:30]{short}[r1]
35607
35608 \layout Standard
35609
35610 \size footnotesize
35611 \SpecialChar ~
35612 \SpecialChar ~
35613 add a,r3
35614
35615 \layout Standard
35616
35617 \size footnotesize
35618 \SpecialChar ~
35619 \SpecialChar ~
35620 mov r3,a
35621
35622 \layout Standard
35623
35624 \size footnotesize
35625 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
35626
35627 \layout Standard
35628
35629 \size footnotesize
35630 \SpecialChar ~
35631 \SpecialChar ~
35632 mov a,r7
35633
35634 \layout Standard
35635
35636 \size footnotesize
35637 \SpecialChar ~
35638 \SpecialChar ~
35639 add a,#0xfd
35640
35641 \layout Standard
35642
35643 \size footnotesize
35644 \SpecialChar ~
35645 \SpecialChar ~
35646 mov r7,a
35647
35648 \layout Standard
35649
35650 \size footnotesize
35651 \SpecialChar ~
35652 \SpecialChar ~
35653 mov a,r0
35654
35655 \layout Standard
35656
35657 \size footnotesize
35658 \SpecialChar ~
35659 \SpecialChar ~
35660 addc a,#0xff
35661
35662 \layout Standard
35663
35664 \size footnotesize
35665 \SpecialChar ~
35666 \SpecialChar ~
35667 mov r0,a
35668
35669 \layout Standard
35670
35671 \size footnotesize
35672 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
35673
35674 \layout Standard
35675
35676 \size footnotesize
35677 \SpecialChar ~
35678 \SpecialChar ~
35679 mov a,r7
35680
35681 \layout Standard
35682
35683 \size footnotesize
35684 \SpecialChar ~
35685 \SpecialChar ~
35686 add a,_gint
35687
35688 \layout Standard
35689
35690 \size footnotesize
35691 \SpecialChar ~
35692 \SpecialChar ~
35693 mov _gint,a
35694
35695 \layout Standard
35696
35697 \size footnotesize
35698 \SpecialChar ~
35699 \SpecialChar ~
35700 mov a,r0
35701
35702 \layout Standard
35703
35704 \size footnotesize
35705 \SpecialChar ~
35706 \SpecialChar ~
35707 addc a,(_gint + 1)
35708
35709 \layout Standard
35710
35711 \size footnotesize
35712 \SpecialChar ~
35713 \SpecialChar ~
35714 mov (_gint + 1),a
35715
35716 \layout Standard
35717
35718 \size footnotesize
35719 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
35720
35721 \layout Standard
35722
35723 \size footnotesize
35724 \SpecialChar ~
35725 \SpecialChar ~
35726 inc r4
35727
35728 \layout Standard
35729
35730 \size footnotesize
35731 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
35732
35733 \layout Standard
35734
35735 \size footnotesize
35736 \SpecialChar ~
35737 \SpecialChar ~
35738 dec r5
35739
35740 \layout Standard
35741
35742 \size footnotesize
35743 \SpecialChar ~
35744 \SpecialChar ~
35745 cjne r5,#0xff,00104$
35746
35747 \layout Standard
35748
35749 \size footnotesize
35750 \SpecialChar ~
35751 \SpecialChar ~
35752 dec r6
35753
35754 \layout Standard
35755
35756 \size footnotesize
35757 ; goto _forcond_0($4)
35758
35759 \layout Standard
35760
35761 \size footnotesize
35762 \SpecialChar ~
35763 \SpecialChar ~
35764 sjmp 00104$
35765
35766 \layout Standard
35767
35768 \size footnotesize
35769 ; _forbreak_0($7) :
35770
35771 \layout Standard
35772
35773 \size footnotesize
35774 00107$:
35775
35776 \layout Standard
35777
35778 \size footnotesize
35779 ; ret iTemp24 [lr40:41]{short}
35780
35781 \layout Standard
35782
35783 \size footnotesize
35784 \SpecialChar ~
35785 \SpecialChar ~
35786 mov a,r3
35787
35788 \layout Standard
35789
35790 \size footnotesize
35791 \SpecialChar ~
35792 \SpecialChar ~
35793 add a,r2
35794
35795 \layout Standard
35796
35797 \size footnotesize
35798 \SpecialChar ~
35799 \SpecialChar ~
35800 mov dpl,a
35801
35802 \layout Standard
35803
35804 \size footnotesize
35805 ; _return($8) :
35806
35807 \layout Standard
35808
35809 \size footnotesize
35810 00108$:
35811
35812 \layout Standard
35813
35814 \size footnotesize
35815 \SpecialChar ~
35816 \SpecialChar ~
35817 ret
35818 \newline
35819
35820
35821 \layout Section
35822 A few words about basic block successors, predecessors and dominators
35823
35824 \layout Standard
35825 Successors are basic blocks
35826 \begin_inset LatexCommand \index{Basic blocks}
35827
35828 \end_inset
35829
35830  that might execute after this basic block.
35831 \newline
35832 Predecessors are basic blocks
35833  that might execute before reaching this basic block.
35834 \newline
35835 Dominators are basic
35836  blocks that WILL execute before reaching this basic block.
35837 \newline
35838
35839
35840 \layout Standard
35841 [basic block 1]
35842
35843 \layout Standard
35844 if (something)
35845
35846 \layout Standard
35847 \SpecialChar ~
35848 \SpecialChar ~
35849 \SpecialChar ~
35850 \SpecialChar ~
35851 [basic block 2]
35852
35853 \layout Standard
35854 else
35855
35856 \layout Standard
35857 \SpecialChar ~
35858 \SpecialChar ~
35859 \SpecialChar ~
35860 \SpecialChar ~
35861 [basic block 3]
35862
35863 \layout Standard
35864 [basic block 4]
35865 \newline
35866
35867
35868 \layout Standard
35869 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35870
35871 \layout Standard
35872 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35873
35874 \layout Standard
35875 c) domVect of [BB4] = BB1 ...
35876  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35877  was executed.
35878
35879 \layout Chapter
35880 Acknowledgments
35881
35882 \layout Standard
35883 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35884
35885 \end_inset
35886
35887
35888 \newline
35889
35890 \newline
35891
35892 \emph on
35893 Thanks to all the other volunteer developers who have helped with coding,
35894  testing, web-page creation, distribution sets, etc.
35895  You know who you are :-)
35896 \emph default
35897
35898 \newline
35899
35900 \newline
35901
35902 \emph on
35903 Also thanks to Sourceforge 
35904 \begin_inset LatexCommand \url{http://www.sf.net}
35905
35906 \end_inset
35907
35908  which has hosted the project since 1999 and donates significant download
35909  bandwidth and probably more than 
35910 \begin_inset ERT
35911 status Collapsed
35912
35913 \layout Standard
35914
35915 $10^{13}$
35916
35917 \end_inset
35918
35919 CPU cycles per day.
35920 \newline
35921  
35922 \begin_inset Note
35923 collapsed false
35924
35925 \layout Standard
35926 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35927  minutes for (configure+make+regression test), and there is (i386, amd64,
35928  alpha, ppc64, (mingw32), sparc, macosx).
35929  
35930
35931 \end_inset
35932
35933
35934
35935 \layout Standard
35936 This document was initially written by Sandeep Dutta
35937
35938 \layout Standard
35939 All product names mentioned herein may be trademarks
35940 \begin_inset LatexCommand \index{Trademarks}
35941
35942 \end_inset
35943
35944  of their respective companies.
35945  
35946
35947 \layout Section*
35948 Alphabetical index
35949
35950 \layout Standard
35951 To avoid confusion, the installation and building options for SDCC itself
35952  (chapter 2) are not part of the index.
35953
35954 \layout Standard
35955 \begin_inset LatexCommand \printindex{}
35956
35957 \end_inset
35958
35959
35960
35961 \the_end