* configure.in,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   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},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.7.3
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
840 \begin_inset ERT
841 status collapsed
842
843 \begin_layout Standard
844
845
846 \backslash
847 /
848 \end_layout
849
850 \end_inset
851
852 -short-is-8bits commandline option (see 
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
854
855 \end_inset
856
857 ).
858 \end_layout
859
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862  files are stored is now in /usr/local/share.
863 \end_layout
864
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
868
869 \end_inset
870
871  functions are casted to int unless explicitly casted
872 \begin_inset Marginal
873 status collapsed
874
875 \begin_layout Standard
876
877 \series bold
878 \InsetSpace ~
879 !
880 \end_layout
881
882 \end_inset
883
884 , e.g.: 
885 \newline
886
887 \family typewriter
888 \InsetSpace ~
889 \InsetSpace ~
890 char a=3;
891 \newline
892 \InsetSpace ~
893 \InsetSpace ~
894 printf ("%d %c
895 \backslash
896 n", a, (char)a);
897 \family default
898
899 \newline
900  will push a as an int and as a char resp.
901 \end_layout
902
903 \begin_layout Itemize
904 option -
905 \begin_inset ERT
906 status collapsed
907
908 \begin_layout Standard
909
910
911 \backslash
912 /
913 \end_layout
914
915 \end_inset
916
917 -regextend has been removed.
918 \end_layout
919
920 \begin_layout Itemize
921 option -
922 \begin_inset ERT
923 status collapsed
924
925 \begin_layout Standard
926
927
928 \backslash
929 /
930 \end_layout
931
932 \end_inset
933
934 -noregparms has been removed.
935 \end_layout
936
937 \begin_layout Itemize
938 option -
939 \begin_inset ERT
940 status collapsed
941
942 \begin_layout Standard
943
944
945 \backslash
946 /
947 \end_layout
948
949 \end_inset
950
951 -stack-after-data has been removed.
952 \end_layout
953
954 \begin_layout Itemize
955 bit
956 \begin_inset LatexCommand \index{bit}
957
958 \end_inset
959
960  and sbit
961 \begin_inset LatexCommand \index{sbit}
962
963 \end_inset
964
965
966 \begin_inset LatexCommand \index{\_\_sbit}
967
968 \end_inset
969
970  types now consistently behave like the C99 _Bool type with respect to type
971  conversion
972 \begin_inset LatexCommand \index{type conversion}
973
974 \end_inset
975
976
977 \begin_inset LatexCommand \index{type promotion}
978
979 \end_inset
980
981 .
982  The most common incompatibility resulting from this change is related to
983  bit toggling
984 \begin_inset LatexCommand \index{Bit toggling}
985
986 \end_inset
987
988  idioms, e.g.:
989 \newline
990
991 \family typewriter
992 \InsetSpace ~
993 \InsetSpace ~
994 bit b;
995 \newline
996 \InsetSpace ~
997 \InsetSpace ~
998 b = ~
999 \begin_inset LatexCommand \index{\~\/ Operator}
1000
1001 \end_inset
1002
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1005 status collapsed
1006
1007 \begin_layout Standard
1008
1009 \series bold
1010 \InsetSpace ~
1011 !
1012 \end_layout
1013
1014 \end_inset
1015
1016
1017 \newline
1018 \InsetSpace ~
1019 \InsetSpace ~
1020 b = !b; /* toggles b */
1021 \newline
1022
1023 \family default
1024 In previous versions, both forms would have toggled the bit.
1025 \end_layout
1026
1027 \begin_layout Standard
1028
1029 \emph on
1030 <pending: more incompatibilities?>
1031 \end_layout
1032
1033 \begin_layout Section
1034 System Requirements
1035 \end_layout
1036
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039  a desire to compute.
1040  The preferred method of installation is to compile SDCC from source using
1041  GNU gcc and make.
1042  For Windows some pre-compiled binary distributions are available for your
1043  convenience.
1044  You should have some experience with command line tools and compiler use.
1045 \end_layout
1046
1047 \begin_layout Section
1048 Other Resources
1049 \end_layout
1050
1051 \begin_layout Standard
1052 The SDCC home page at 
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1054
1055 \end_inset
1056
1057  is a great place to find distribution sets.
1058  You can also find links to the user mailing lists that offer help or discuss
1059  SDCC with other SDCC users.
1060  Web links to other SDCC related sites can also be found here.
1061  This document can be found in the DOC directory of the source package as
1062  a text or HTML file.
1063  A pdf version of this document is available at 
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1065
1066 \end_inset
1067
1068 .
1069  Some of the other tools (simulator and assembler) included with SDCC contain
1070  their own documentation and can be found in the source distribution.
1071  If you want the latest unreleased software, the complete source package
1072  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1073 sdcc/trunk/sdcc.
1074 \end_layout
1075
1076 \begin_layout Section
1077 Wishes for the future
1078 \end_layout
1079
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082  Here are some I can think of:
1083 \newline
1084
1085 \end_layout
1086
1087 \begin_layout Standard
1088
1089 \family typewriter
1090 char KernelFunction3(char p) at 0x340;
1091 \newline
1092
1093 \end_layout
1094
1095 \begin_layout Standard
1096
1097 \family typewriter
1098 better code banking
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1100
1101 \end_inset
1102
1103  support for mcs51
1104 \newline
1105
1106 \newline
1107
1108 \family default
1109 If you can think of some more, please see the section 
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1111
1112 \end_inset
1113
1114  about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1116
1117 \end_inset
1118
1119
1120 \begin_inset LatexCommand \index{Feature request}
1121
1122 \end_inset
1123
1124 .
1125 \newline
1126
1127 \end_layout
1128
1129 \begin_layout Chapter
1130 Installing SDCC
1131 \begin_inset LatexCommand \index{Installation}
1132
1133 \end_inset
1134
1135
1136 \end_layout
1137
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section 
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1141
1142 \end_inset
1143
1144  (Unix) or section 
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1146
1147 \end_inset
1148
1149  (Windows).
1150  More detailed instructions follow below.
1151 \end_layout
1152
1153 \begin_layout Section
1154 Configure Options
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1156
1157 \end_inset
1158
1159
1160 \end_layout
1161
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1164  'configure'.
1165  The defaults can be overridden by:
1166 \end_layout
1167
1168 \begin_layout List
1169 \labelwidthstring 00.00.0000
1170 -
1171 \begin_inset ERT
1172 status collapsed
1173
1174 \begin_layout Standard
1175
1176
1177 \backslash
1178 /
1179 \end_layout
1180
1181 \end_inset
1182
1183 -prefix see table below
1184 \end_layout
1185
1186 \begin_layout List
1187 \labelwidthstring 00.00.0000
1188 -
1189 \begin_inset ERT
1190 status collapsed
1191
1192 \begin_layout Standard
1193
1194
1195 \backslash
1196 /
1197 \end_layout
1198
1199 \end_inset
1200
1201 -exec_prefix see table below
1202 \end_layout
1203
1204 \begin_layout List
1205 \labelwidthstring 00.00.0000
1206 -
1207 \begin_inset ERT
1208 status collapsed
1209
1210 \begin_layout Standard
1211
1212
1213 \backslash
1214 /
1215 \end_layout
1216
1217 \end_inset
1218
1219 -bindir see table below
1220 \end_layout
1221
1222 \begin_layout List
1223 \labelwidthstring 00.00.0000
1224 -
1225 \begin_inset ERT
1226 status collapsed
1227
1228 \begin_layout Standard
1229
1230
1231 \backslash
1232 /
1233 \end_layout
1234
1235 \end_inset
1236
1237 -datadir see table below
1238 \end_layout
1239
1240 \begin_layout List
1241 \labelwidthstring 00.00.0000
1242 -
1243 \begin_inset ERT
1244 status collapsed
1245
1246 \begin_layout Standard
1247
1248
1249 \backslash
1250 /
1251 \end_layout
1252
1253 \end_inset
1254
1255 -datarootdir see table below
1256 \newline
1257
1258 \end_layout
1259
1260 \begin_layout List
1261 \labelwidthstring 00.00.0000
1262 \InsetSpace ~
1263 \InsetSpace ~
1264 docdir environment variable, see table below
1265 \end_layout
1266
1267 \begin_layout List
1268 \labelwidthstring 00.00.0000
1269 \InsetSpace ~
1270 \InsetSpace ~
1271 include_dir_suffix environment variable, see table below
1272 \end_layout
1273
1274 \begin_layout List
1275 \labelwidthstring 00.00.0000
1276 \InsetSpace ~
1277 \InsetSpace ~
1278 lib_dir_suffix environment variable, see table below
1279 \end_layout
1280
1281 \begin_layout List
1282 \labelwidthstring 00.00.0000
1283 \InsetSpace ~
1284 \InsetSpace ~
1285 sdccconf_h_dir_separator environment variable, either / or 
1286 \backslash
1287
1288 \backslash
1289  makes sense here.
1290  This character will only be used in sdccconf.h; don't forget it's a C-header,
1291  therefore a double-backslash is needed there.
1292 \newline
1293
1294 \end_layout
1295
1296 \begin_layout List
1297 \labelwidthstring 00.00.0000
1298 -
1299 \begin_inset ERT
1300 status collapsed
1301
1302 \begin_layout Standard
1303
1304
1305 \backslash
1306 /
1307 \end_layout
1308
1309 \end_inset
1310
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1312 \end_layout
1313
1314 \begin_layout List
1315 \labelwidthstring 00.00.0000
1316 -
1317 \begin_inset ERT
1318 status collapsed
1319
1320 \begin_layout Standard
1321
1322
1323 \backslash
1324 /
1325 \end_layout
1326
1327 \end_inset
1328
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1330 \end_layout
1331
1332 \begin_layout List
1333 \labelwidthstring 00.00.0000
1334 -
1335 \begin_inset ERT
1336 status collapsed
1337
1338 \begin_layout Standard
1339
1340
1341 \backslash
1342 /
1343 \end_layout
1344
1345 \end_inset
1346
1347 -disable-z80-port Excludes the z80 port
1348 \end_layout
1349
1350 \begin_layout List
1351 \labelwidthstring 00.00.0000
1352 -
1353 \begin_inset ERT
1354 status collapsed
1355
1356 \begin_layout Standard
1357
1358
1359 \backslash
1360 /
1361 \end_layout
1362
1363 \end_inset
1364
1365 -disable-avr-port Excludes the AVR port
1366 \end_layout
1367
1368 \begin_layout List
1369 \labelwidthstring 00.00.0000
1370 -
1371 \begin_inset ERT
1372 status collapsed
1373
1374 \begin_layout Standard
1375
1376
1377 \backslash
1378 /
1379 \end_layout
1380
1381 \end_inset
1382
1383 -disable-ds390-port Excludes the DS390 port
1384 \end_layout
1385
1386 \begin_layout List
1387 \labelwidthstring 00.00.0000
1388 -
1389 \begin_inset ERT
1390 status collapsed
1391
1392 \begin_layout Standard
1393
1394
1395 \backslash
1396 /
1397 \end_layout
1398
1399 \end_inset
1400
1401 -disable-hc08-port Excludes the HC08 port
1402 \end_layout
1403
1404 \begin_layout List
1405 \labelwidthstring 00.00.0000
1406 -
1407 \begin_inset ERT
1408 status collapsed
1409
1410 \begin_layout Standard
1411
1412
1413 \backslash
1414 /
1415 \end_layout
1416
1417 \end_inset
1418
1419 -disable-pic-port Excludes the PIC14 port
1420 \end_layout
1421
1422 \begin_layout List
1423 \labelwidthstring 00.00.0000
1424 -
1425 \begin_inset ERT
1426 status collapsed
1427
1428 \begin_layout Standard
1429
1430
1431 \backslash
1432 /
1433 \end_layout
1434
1435 \end_inset
1436
1437 -disable-pic16-port Excludes the PIC16 port
1438 \end_layout
1439
1440 \begin_layout List
1441 \labelwidthstring 00.00.0000
1442 -
1443 \begin_inset ERT
1444 status collapsed
1445
1446 \begin_layout Standard
1447
1448
1449 \backslash
1450 /
1451 \end_layout
1452
1453 \end_inset
1454
1455 -disable-xa51-port Excludes the XA51 port
1456 \end_layout
1457
1458 \begin_layout List
1459 \labelwidthstring 00.00.0000
1460 -
1461 \begin_inset ERT
1462 status collapsed
1463
1464 \begin_layout Standard
1465
1466
1467 \backslash
1468 /
1469 \end_layout
1470
1471 \end_inset
1472
1473 -disable-ucsim Disables configuring and building of ucsim
1474 \end_layout
1475
1476 \begin_layout List
1477 \labelwidthstring 00.00.0000
1478 -
1479 \begin_inset ERT
1480 status collapsed
1481
1482 \begin_layout Standard
1483
1484
1485 \backslash
1486 /
1487 \end_layout
1488
1489 \end_inset
1490
1491 -disable-device-lib Disables automatically building device libraries
1492 \end_layout
1493
1494 \begin_layout List
1495 \labelwidthstring 00.00.0000
1496 -
1497 \begin_inset ERT
1498 status collapsed
1499
1500 \begin_layout Standard
1501
1502
1503 \backslash
1504 /
1505 \end_layout
1506
1507 \end_inset
1508
1509 -disable-packihx Disables building packihx
1510 \newline
1511
1512 \end_layout
1513
1514 \begin_layout List
1515 \labelwidthstring 00.00.0000
1516 -
1517 \begin_inset ERT
1518 status collapsed
1519
1520 \begin_layout Standard
1521
1522
1523 \backslash
1524 /
1525 \end_layout
1526
1527 \end_inset
1528
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1530 \end_layout
1531
1532 \begin_layout List
1533 \labelwidthstring 00.00.0000
1534 -
1535 \begin_inset ERT
1536 status collapsed
1537
1538 \begin_layout Standard
1539
1540
1541 \backslash
1542 /
1543 \end_layout
1544
1545 \end_inset
1546
1547 -enable-libgc Use the Bohem memory allocator.
1548  Lower runtime footprint.
1549 \end_layout
1550
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553  the tools and their arguments can be influenced.
1554  Please see `configure -
1555 \begin_inset ERT
1556 status collapsed
1557
1558 \begin_layout Standard
1559
1560
1561 \backslash
1562 /
1563 \end_layout
1564
1565 \end_inset
1566
1567 -help' and the man/info pages of `configure' for details.
1568 \newline
1569
1570 \newline
1571 The names of the
1572  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574  SDCC_LIB_NAME are defined by `configure' too.
1575  At the moment it's not possible to change the default settings (it was
1576  simply never required).
1577 \newline
1578
1579 \newline
1580 These configure options are compiled into the binaries,
1581  and can only be changed by rerunning 'configure' and recompiling SDCC.
1582  The configure options are written in 
1583 \emph on
1584 italics
1585 \emph default
1586  to distinguish them from run time environment variables (see section search
1587  paths).
1588 \newline
1589
1590 \newline
1591 The settings for 
1592 \begin_inset Quotes sld
1593 \end_inset
1594
1595 Win32 builds
1596 \begin_inset Quotes srd
1597 \end_inset
1598
1599  are used by the SDCC team to build the official Win32 binaries.
1600  The SDCC team uses Mingw32 to build the official Windows binaries, because
1601  it's
1602 \end_layout
1603
1604 \begin_layout Enumerate
1605 open source, 
1606 \end_layout
1607
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1610 \end_layout
1611
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1614  Farm.
1615 \end_layout
1616
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1621  for Win32.
1622 \newline
1623
1624 \newline
1625 These defaults are:
1626 \newline
1627
1628 \end_layout
1629
1630 \begin_layout Standard
1631 \align center
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1634 <features>
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 \begin_inset Text
1641
1642 \begin_layout Standard
1643 Variable
1644 \end_layout
1645
1646 \end_inset
1647 </cell>
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1649 \begin_inset Text
1650
1651 \begin_layout Standard
1652 default
1653 \end_layout
1654
1655 \end_inset
1656 </cell>
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1658 \begin_inset Text
1659
1660 \begin_layout Standard
1661 Win32 builds
1662 \end_layout
1663
1664 \end_inset
1665 </cell>
1666 </row>
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1669 \begin_inset Text
1670
1671 \begin_layout Standard
1672
1673 \emph on
1674 PREFIX
1675 \end_layout
1676
1677 \end_inset
1678 </cell>
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1680 \begin_inset Text
1681
1682 \begin_layout Standard
1683 /usr/local
1684 \end_layout
1685
1686 \end_inset
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \begin_layout Standard
1692
1693 \backslash
1694 sdcc
1695 \end_layout
1696
1697 \end_inset
1698 </cell>
1699 </row>
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \begin_layout Standard
1705
1706 \emph on
1707 EXEC_PREFIX
1708 \end_layout
1709
1710 \end_inset
1711 </cell>
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1713 \begin_inset Text
1714
1715 \begin_layout Standard
1716
1717 \emph on
1718 $PREFIX
1719 \end_layout
1720
1721 \end_inset
1722 </cell>
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1724 \begin_inset Text
1725
1726 \begin_layout Standard
1727
1728 \emph on
1729 $PREFIX
1730 \end_layout
1731
1732 \end_inset
1733 </cell>
1734 </row>
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_inset Text
1738
1739 \begin_layout Standard
1740
1741 \emph on
1742 BINDIR
1743 \end_layout
1744
1745 \end_inset
1746 </cell>
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \begin_layout Standard
1751
1752 \emph on
1753 $EXEC_PREFIX
1754 \emph default
1755 /bin
1756 \end_layout
1757
1758 \end_inset
1759 </cell>
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1761 \begin_inset Text
1762
1763 \begin_layout Standard
1764
1765 \emph on
1766 $EXEC_PREFIX
1767 \emph default
1768
1769 \backslash
1770 bin
1771 \end_layout
1772
1773 \end_inset
1774 </cell>
1775 </row>
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1778 \begin_inset Text
1779
1780 \begin_layout Standard
1781
1782 \emph on
1783 DATADIR
1784 \end_layout
1785
1786 \end_inset
1787 </cell>
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1789 \begin_inset Text
1790
1791 \begin_layout Standard
1792
1793 \emph on
1794 $DATAROOTDIR
1795 \end_layout
1796
1797 \end_inset
1798 </cell>
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1800 \begin_inset Text
1801
1802 \begin_layout Standard
1803
1804 \emph on
1805 $DATAROOTDIR
1806 \end_layout
1807
1808 \end_inset
1809 </cell>
1810 </row>
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1813 \begin_inset Text
1814
1815 \begin_layout Standard
1816
1817 \emph on
1818 DATAROOTDIR
1819 \end_layout
1820
1821 \end_inset
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \begin_layout Standard
1827
1828 \emph on
1829 $PREFIX
1830 \emph default
1831 /share
1832 \end_layout
1833
1834 \end_inset
1835 </cell>
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1837 \begin_inset Text
1838
1839 \begin_layout Standard
1840
1841 \emph on
1842 $PREFIX
1843 \end_layout
1844
1845 \end_inset
1846 </cell>
1847 </row>
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 \begin_inset Text
1851
1852 \begin_layout Standard
1853
1854 \emph on
1855 DOCDIR
1856 \end_layout
1857
1858 \end_inset
1859 </cell>
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1861 \begin_inset Text
1862
1863 \begin_layout Standard
1864
1865 \emph on
1866 $DATAROOTDIR
1867 \emph default
1868 /sdcc/doc
1869 \end_layout
1870
1871 \end_inset
1872 </cell>
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1874 \begin_inset Text
1875
1876 \begin_layout Standard
1877
1878 \emph on
1879 $DATAROOTDIR
1880 \emph default
1881
1882 \backslash
1883 doc
1884 \end_layout
1885
1886 \end_inset
1887 </cell>
1888 </row>
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1891 \begin_inset Text
1892
1893 \begin_layout Standard
1894
1895 \emph on
1896 INCLUDE_DIR_SUFFIX
1897 \end_layout
1898
1899 \end_inset
1900 </cell>
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1902 \begin_inset Text
1903
1904 \begin_layout Standard
1905 sdcc/include
1906 \end_layout
1907
1908 \end_inset
1909 </cell>
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1911 \begin_inset Text
1912
1913 \begin_layout Standard
1914 include
1915 \end_layout
1916
1917 \end_inset
1918 </cell>
1919 </row>
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1922 \begin_inset Text
1923
1924 \begin_layout Standard
1925
1926 \emph on
1927 LIB_DIR_SUFFIX
1928 \end_layout
1929
1930 \end_inset
1931 </cell>
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1933 \begin_inset Text
1934
1935 \begin_layout Standard
1936 sdcc/lib
1937 \end_layout
1938
1939 \end_inset
1940 </cell>
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1942 \begin_inset Text
1943
1944 \begin_layout Standard
1945 lib
1946 \end_layout
1947
1948 \end_inset
1949 </cell>
1950 </row>
1951 </lyxtabular>
1952
1953 \end_inset
1954
1955
1956 \newline
1957
1958 \end_layout
1959
1960 \begin_layout Standard
1961 \noindent
1962 'configure' also computes relative paths.
1963  This is needed for full relocatability of a binary package and to complete
1964  search paths (see section search paths below):
1965 \newline
1966  
1967 \end_layout
1968
1969 \begin_layout Standard
1970 \align center
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1973 <features>
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 \begin_inset Text
1980
1981 \begin_layout Standard
1982 Variable (computed)
1983 \end_layout
1984
1985 \end_inset
1986 </cell>
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1988 \begin_inset Text
1989
1990 \begin_layout Standard
1991 default
1992 \end_layout
1993
1994 \end_inset
1995 </cell>
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \begin_layout Standard
2000 Win32 builds
2001 \end_layout
2002
2003 \end_inset
2004 </cell>
2005 </row>
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 BIN2DATA_DIR
2014 \end_layout
2015
2016 \end_inset
2017 </cell>
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 \begin_inset Text
2020
2021 \begin_layout Standard
2022 ../share
2023 \end_layout
2024
2025 \end_inset
2026 </cell>
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2028 \begin_inset Text
2029
2030 \begin_layout Standard
2031 ..
2032 \end_layout
2033
2034 \end_inset
2035 </cell>
2036 </row>
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_inset Text
2040
2041 \begin_layout Standard
2042
2043 \emph on
2044 PREFIX2BIN_DIR
2045 \end_layout
2046
2047 \end_inset
2048 </cell>
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2050 \begin_inset Text
2051
2052 \begin_layout Standard
2053 bin
2054 \end_layout
2055
2056 \end_inset
2057 </cell>
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2059 \begin_inset Text
2060
2061 \begin_layout Standard
2062 bin
2063 \end_layout
2064
2065 \end_inset
2066 </cell>
2067 </row>
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2070 \begin_inset Text
2071
2072 \begin_layout Standard
2073
2074 \emph on
2075 PREFIX2DATA_DIR
2076 \end_layout
2077
2078 \end_inset
2079 </cell>
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2081 \begin_inset Text
2082
2083 \begin_layout Standard
2084 share/sdcc
2085 \end_layout
2086
2087 \end_inset
2088 </cell>
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2090 \begin_inset Text
2091
2092 \begin_layout Standard
2093
2094 \end_layout
2095
2096 \end_inset
2097 </cell>
2098 </row>
2099 </lyxtabular>
2100
2101 \end_inset
2102
2103
2104 \newline
2105
2106 \end_layout
2107
2108 \begin_layout Standard
2109 \noindent
2110 Examples:
2111 \end_layout
2112
2113 \begin_layout LyX-Code
2114 ./configure
2115 \newline
2116 ./configure -
2117 \begin_inset ERT
2118 status collapsed
2119
2120 \begin_layout Standard
2121
2122
2123 \backslash
2124 /
2125 \end_layout
2126
2127 \end_inset
2128
2129 -prefix=
2130 \begin_inset Quotes srd
2131 \end_inset
2132
2133 /usr/bin
2134 \begin_inset Quotes srd
2135 \end_inset
2136
2137  -
2138 \begin_inset ERT
2139 status collapsed
2140
2141 \begin_layout Standard
2142
2143
2144 \backslash
2145 /
2146 \end_layout
2147
2148 \end_inset
2149
2150 -datarootdir=
2151 \begin_inset Quotes srd
2152 \end_inset
2153
2154 /usr/share
2155 \begin_inset Quotes srd
2156 \end_inset
2157
2158
2159 \newline
2160 ./configure -
2161 \begin_inset ERT
2162 status collapsed
2163
2164 \begin_layout Standard
2165
2166
2167 \backslash
2168 /
2169 \end_layout
2170
2171 \end_inset
2172
2173 -disable-avr-port -
2174 \begin_inset ERT
2175 status collapsed
2176
2177 \begin_layout Standard
2178
2179
2180 \backslash
2181 /
2182 \end_layout
2183
2184 \end_inset
2185
2186 -disable-xa51-port
2187 \end_layout
2188
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2191 32'):
2192 \end_layout
2193
2194 \begin_layout LyX-Code
2195 ./configure 
2196 \backslash
2197
2198 \newline
2199 CC=
2200 \begin_inset Quotes srd
2201 \end_inset
2202
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2205 \end_inset
2206
2207  CXX=
2208 \begin_inset Quotes srd
2209 \end_inset
2210
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2213 \end_inset
2214
2215  
2216 \backslash
2217  
2218 \newline
2219 RANLIB=
2220 \begin_inset Quotes srd
2221 \end_inset
2222
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2225 \end_inset
2226
2227  
2228 \backslash
2229
2230 \newline
2231 STRIP=
2232 \begin_inset Quotes srd
2233 \end_inset
2234
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2237 \end_inset
2238
2239  
2240 \backslash
2241
2242 \newline
2243 -
2244 \begin_inset ERT
2245 status collapsed
2246
2247 \begin_layout Standard
2248
2249
2250 \backslash
2251 /
2252 \end_layout
2253
2254 \end_inset
2255
2256 -prefix=
2257 \begin_inset Quotes srd
2258 \end_inset
2259
2260 /sdcc
2261 \begin_inset Quotes srd
2262 \end_inset
2263
2264  
2265 \backslash
2266
2267 \newline
2268 -
2269 \begin_inset ERT
2270 status collapsed
2271
2272 \begin_layout Standard
2273
2274
2275 \backslash
2276 /
2277 \end_layout
2278
2279 \end_inset
2280
2281 -datarootdir=
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285 /sdcc
2286 \begin_inset Quotes srd
2287 \end_inset
2288
2289  
2290 \backslash
2291
2292 \newline
2293 docdir=
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297
2298 \backslash
2299 ${datarootdir}/doc
2300 \begin_inset Quotes srd
2301 \end_inset
2302
2303  
2304 \backslash
2305
2306 \newline
2307 include_dir_suffix=
2308 \begin_inset Quotes srd
2309 \end_inset
2310
2311 include
2312 \begin_inset Quotes srd
2313 \end_inset
2314
2315  
2316 \backslash
2317
2318 \newline
2319 lib_dir_suffix=
2320 \begin_inset Quotes srd
2321 \end_inset
2322
2323 lib
2324 \begin_inset Quotes srd
2325 \end_inset
2326
2327  
2328 \backslash
2329
2330 \newline
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2333 \end_inset
2334
2335
2336 \backslash
2337
2338 \backslash
2339
2340 \backslash
2341
2342 \backslash
2343
2344 \begin_inset Quotes srd
2345 \end_inset
2346
2347  
2348 \backslash
2349
2350 \newline
2351 -
2352 \begin_inset ERT
2353 status collapsed
2354
2355 \begin_layout Standard
2356
2357
2358 \backslash
2359 /
2360 \end_layout
2361
2362 \end_inset
2363
2364 -disable-device-lib
2365 \backslash
2366
2367 \newline
2368 -
2369 \begin_inset ERT
2370 status collapsed
2371
2372 \begin_layout Standard
2373
2374
2375 \backslash
2376 /
2377 \end_layout
2378
2379 \end_inset
2380
2381 -host=i586-mingw32msvc
2382 \backslash
2383
2384 \newline
2385 -
2386 \begin_inset ERT
2387 status collapsed
2388
2389 \begin_layout Standard
2390
2391
2392 \backslash
2393 /
2394 \end_layout
2395
2396 \end_inset
2397
2398 -build=unknown-unknown-linux-gnu
2399 \end_layout
2400
2401 \begin_layout Standard
2402 To 
2403 \begin_inset Quotes sld
2404 \end_inset
2405
2406 cross
2407 \begin_inset Quotes srd
2408 \end_inset
2409
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2411 ):
2412 \end_layout
2413
2414 \begin_layout LyX-Code
2415 ./configure -C 
2416 \backslash
2417
2418 \newline
2419 -
2420 \begin_inset ERT
2421 status collapsed
2422
2423 \begin_layout Standard
2424
2425
2426 \backslash
2427 /
2428 \end_layout
2429
2430 \end_inset
2431
2432 -prefix=
2433 \begin_inset Quotes srd
2434 \end_inset
2435
2436 /sdcc
2437 \begin_inset Quotes srd
2438 \end_inset
2439
2440  
2441 \backslash
2442
2443 \newline
2444 -
2445 \begin_inset ERT
2446 status collapsed
2447
2448 \begin_layout Standard
2449
2450
2451 \backslash
2452 /
2453 \end_layout
2454
2455 \end_inset
2456
2457 -datarootdir=
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461 /sdcc
2462 \begin_inset Quotes srd
2463 \end_inset
2464
2465  
2466 \backslash
2467
2468 \newline
2469 docdir=
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473
2474 \backslash
2475 ${datarootdir}/doc
2476 \begin_inset Quotes srd
2477 \end_inset
2478
2479  
2480 \backslash
2481  
2482 \newline
2483 include_dir_suffix=
2484 \begin_inset Quotes srd
2485 \end_inset
2486
2487 include
2488 \begin_inset Quotes srd
2489 \end_inset
2490
2491  
2492 \backslash
2493
2494 \newline
2495 lib_dir_suffix=
2496 \begin_inset Quotes srd
2497 \end_inset
2498
2499 lib
2500 \begin_inset Quotes srd
2501 \end_inset
2502
2503  
2504 \backslash
2505
2506 \newline
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2509 \end_inset
2510
2511
2512 \backslash
2513
2514 \backslash
2515
2516 \backslash
2517
2518 \backslash
2519
2520 \begin_inset Quotes srd
2521 \end_inset
2522
2523  
2524 \backslash
2525
2526 \newline
2527 CC=
2528 \begin_inset Quotes srd
2529 \end_inset
2530
2531 gcc -mno-cygwin
2532 \begin_inset Quotes srd
2533 \end_inset
2534
2535  
2536 \backslash
2537
2538 \newline
2539 CXX=
2540 \begin_inset Quotes srd
2541 \end_inset
2542
2543 g++ -mno-cygwin
2544 \begin_inset Quotes srd
2545 \end_inset
2546
2547  
2548 \end_layout
2549
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2552  The option '-
2553 \begin_inset ERT
2554 status collapsed
2555
2556 \begin_layout Standard
2557
2558
2559 \backslash
2560 /
2561 \end_layout
2562
2563 \end_inset
2564
2565 -C' turns on caching, which gives a little bit extra speed.
2566  However if options are changed, it can be necessary to delete the config.cache
2567  file.
2568 \end_layout
2569
2570 \begin_layout Section
2571 Install paths
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2573
2574 \end_inset
2575
2576
2577 \begin_inset LatexCommand \index{Install paths}
2578
2579 \end_inset
2580
2581
2582 \end_layout
2583
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2586 \end_inset
2587
2588
2589 \end_layout
2590
2591 \begin_layout Standard
2592 \align center
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2595 <features>
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2602 \begin_inset Text
2603
2604 \begin_layout Standard
2605
2606 \series bold
2607 Description
2608 \end_layout
2609
2610 \end_inset
2611 </cell>
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \begin_layout Standard
2616
2617 \series bold
2618 Path
2619 \end_layout
2620
2621 \end_inset
2622 </cell>
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \begin_layout Standard
2627
2628 \series bold
2629 Default
2630 \end_layout
2631
2632 \end_inset
2633 </cell>
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2635 \begin_inset Text
2636
2637 \begin_layout Standard
2638
2639 \series bold
2640 Win32 builds
2641 \end_layout
2642
2643 \end_inset
2644 </cell>
2645 </row>
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2648 \begin_inset Text
2649
2650 \begin_layout Standard
2651 Binary files*
2652 \end_layout
2653
2654 \end_inset
2655 </cell>
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2657 \begin_inset Text
2658
2659 \begin_layout Standard
2660
2661 \emph on
2662 $EXEC_PREFIX
2663 \end_layout
2664
2665 \end_inset
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \begin_layout Standard
2671 /usr/local/bin
2672 \end_layout
2673
2674 \end_inset
2675 </cell>
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2677 \begin_inset Text
2678
2679 \begin_layout Standard
2680
2681 \backslash
2682 sdcc
2683 \backslash
2684 bin
2685 \end_layout
2686
2687 \end_inset
2688 </cell>
2689 </row>
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2692 \begin_inset Text
2693
2694 \begin_layout Standard
2695 Include files
2696 \end_layout
2697
2698 \end_inset
2699 </cell>
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2701 \begin_inset Text
2702
2703 \begin_layout Standard
2704
2705 \emph on
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2707 \end_layout
2708
2709 \end_inset
2710 </cell>
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2712 \begin_inset Text
2713
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2716 \end_layout
2717
2718 \end_inset
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \begin_layout Standard
2724
2725 \backslash
2726 sdcc
2727 \backslash
2728 include
2729 \end_layout
2730
2731 \end_inset
2732 </cell>
2733 </row>
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739 Library file**
2740 \end_layout
2741
2742 \end_inset
2743 </cell>
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2745 \begin_inset Text
2746
2747 \begin_layout Standard
2748
2749 \emph on
2750 $DATADIR/$LIB_DIR_SUFFIX
2751 \end_layout
2752
2753 \end_inset
2754 </cell>
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2756 \begin_inset Text
2757
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2760 \end_layout
2761
2762 \end_inset
2763 </cell>
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2765 \begin_inset Text
2766
2767 \begin_layout Standard
2768
2769 \backslash
2770 sdcc
2771 \backslash
2772 lib
2773 \end_layout
2774
2775 \end_inset
2776 </cell>
2777 </row>
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2780 \begin_inset Text
2781
2782 \begin_layout Standard
2783 Documentation
2784 \end_layout
2785
2786 \end_inset
2787 </cell>
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2789 \begin_inset Text
2790
2791 \begin_layout Standard
2792
2793 \emph on
2794 $DOCDIR
2795 \end_layout
2796
2797 \end_inset
2798 </cell>
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_inset Text
2801
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2804 \end_layout
2805
2806 \end_inset
2807 </cell>
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2809 \begin_inset Text
2810
2811 \begin_layout Standard
2812
2813 \backslash
2814 sdcc
2815 \backslash
2816 doc
2817 \end_layout
2818
2819 \end_inset
2820 </cell>
2821 </row>
2822 </lyxtabular>
2823
2824 \end_inset
2825
2826
2827 \end_layout
2828
2829 \begin_layout Verse
2830
2831 \size footnotesize
2832 *compiler, preprocessor, assembler, and linker
2833 \newline
2834 **the 
2835 \shape italic
2836 model
2837 \shape default
2838  is auto-appended by the compiler, e.g.
2839  small, large, z80, ds390 etc
2840 \end_layout
2841
2842 \begin_layout Standard
2843 \noindent
2844 The install paths can still be changed during `make install' with e.g.:
2845 \end_layout
2846
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2849 \end_layout
2850
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2853 \newline
2854
2855 \newline
2856 Moreove
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2859
2860 \end_inset
2861
2862 :
2863 \end_layout
2864
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2867 \end_layout
2868
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2871 \end_layout
2872
2873 \begin_layout Section
2874 Search Paths
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2876
2877 \end_inset
2878
2879
2880 \begin_inset LatexCommand \index{Search path}
2881
2882 \end_inset
2883
2884
2885 \end_layout
2886
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2889  (in 
2890 \emph on
2891 italics
2892 \emph default
2893 , see section above).
2894  Further search paths are determined by environment variables during runtime.
2895  
2896 \newline
2897 The paths searched when running the compiler are as follows (the first
2898  catch wins):
2899 \newline
2900
2901 \newline
2902 1.
2903  Binary files (preprocessor, assembler and linker)
2904 \newline
2905
2906 \end_layout
2907
2908 \begin_layout Standard
2909 \align center
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2912 <features>
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2918 \begin_inset Text
2919
2920 \begin_layout Standard
2921 Search path
2922 \end_layout
2923
2924 \end_inset
2925 </cell>
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2927 \begin_inset Text
2928
2929 \begin_layout Standard
2930 default
2931 \end_layout
2932
2933 \end_inset
2934 </cell>
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2936 \begin_inset Text
2937
2938 \begin_layout Standard
2939 Win32 builds
2940 \end_layout
2941
2942 \end_inset
2943 </cell>
2944 </row>
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2947 \begin_inset Text
2948
2949 \begin_layout Standard
2950 $SDCC_HOME/
2951 \emph on
2952 $PPREFIX2BIN_DIR
2953 \end_layout
2954
2955 \end_inset
2956 </cell>
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2958 \begin_inset Text
2959
2960 \begin_layout Standard
2961 $SDCC_HOME/bin
2962 \end_layout
2963
2964 \end_inset
2965 </cell>
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2967 \begin_inset Text
2968
2969 \begin_layout Standard
2970 $SDCC_HOME
2971 \backslash
2972 bin
2973 \end_layout
2974
2975 \end_inset
2976 </cell>
2977 </row>
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_inset Text
2981
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2984 \end_layout
2985
2986 \end_inset
2987 </cell>
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_inset Text
2990
2991 \begin_layout Standard
2992 Path of argv[0]
2993 \end_layout
2994
2995 \end_inset
2996 </cell>
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2998 \begin_inset Text
2999
3000 \begin_layout Standard
3001 Path of argv[0]
3002 \end_layout
3003
3004 \end_inset
3005 </cell>
3006 </row>
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3009 \begin_inset Text
3010
3011 \begin_layout Standard
3012 $PATH
3013 \end_layout
3014
3015 \end_inset
3016 </cell>
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3018 \begin_inset Text
3019
3020 \begin_layout Standard
3021 $PATH
3022 \end_layout
3023
3024 \end_inset
3025 </cell>
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3027 \begin_inset Text
3028
3029 \begin_layout Standard
3030 $PATH
3031 \end_layout
3032
3033 \end_inset
3034 </cell>
3035 </row>
3036 </lyxtabular>
3037
3038 \end_inset
3039
3040  
3041 \newline
3042
3043 \end_layout
3044
3045 \begin_layout Standard
3046 \noindent
3047 2.
3048  Include files
3049 \newline
3050
3051 \end_layout
3052
3053 \begin_layout Standard
3054 \align center
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3057 <features>
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3063 \begin_inset Text
3064
3065 \begin_layout Standard
3066 Search path
3067 \end_layout
3068
3069 \end_inset
3070 </cell>
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_inset Text
3073
3074 \begin_layout Standard
3075 default
3076 \end_layout
3077
3078 \end_inset
3079 </cell>
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 Win32 builds
3085 \end_layout
3086
3087 \end_inset
3088 </cell>
3089 </row>
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 -
3096 \begin_inset ERT
3097 status collapsed
3098
3099 \begin_layout Standard
3100
3101
3102 \backslash
3103 /
3104 \end_layout
3105
3106 \end_inset
3107
3108 -I dir
3109 \end_layout
3110
3111 \end_inset
3112 </cell>
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 -
3118 \begin_inset ERT
3119 status collapsed
3120
3121 \begin_layout Standard
3122
3123
3124 \backslash
3125 /
3126 \end_layout
3127
3128 \end_inset
3129
3130 -I dir
3131 \end_layout
3132
3133 \end_inset
3134 </cell>
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3136 \begin_inset Text
3137
3138 \begin_layout Standard
3139 -
3140 \begin_inset ERT
3141 status collapsed
3142
3143 \begin_layout Standard
3144
3145
3146 \backslash
3147 /
3148 \end_layout
3149
3150 \end_inset
3151
3152 -I dir
3153 \end_layout
3154
3155 \end_inset
3156 </cell>
3157 </row>
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \begin_layout Standard
3163 $SDCC_INCLUDE
3164 \end_layout
3165
3166 \end_inset
3167 </cell>
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3169 \begin_inset Text
3170
3171 \begin_layout Standard
3172 $SDCC_INCLUDE
3173 \end_layout
3174
3175 \end_inset
3176 </cell>
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3178 \begin_inset Text
3179
3180 \begin_layout Standard
3181 $SDCC_INCLUDE
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 </row>
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3189 \begin_inset Text
3190
3191 \begin_layout Standard
3192 $SDCC_HOME/
3193 \newline
3194
3195 \emph on
3196 $PREFIX2DATA_DIR/
3197 \newline
3198 $INCLUDE_DIR_SUFFIX
3199 \end_layout
3200
3201 \end_inset
3202 </cell>
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3204 \begin_inset Text
3205
3206 \begin_layout Standard
3207 $SDCC_ HOME/
3208 \newline
3209 share/sdcc/
3210 \newline
3211 include
3212 \end_layout
3213
3214 \end_inset
3215 </cell>
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3217 \begin_inset Text
3218
3219 \begin_layout Standard
3220 $SDCC_HOME
3221 \backslash
3222 include
3223 \end_layout
3224
3225 \end_inset
3226 </cell>
3227 </row>
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3230 \begin_inset Text
3231
3232 \begin_layout Standard
3233 path(argv[0])/
3234 \newline
3235
3236 \emph on
3237 $BIN2DATADIR/
3238 \emph default
3239
3240 \newline
3241
3242 \emph on
3243 $INCLUDE_DIR_SUFFIX
3244 \end_layout
3245
3246 \end_inset
3247 </cell>
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3249 \begin_inset Text
3250
3251 \begin_layout Standard
3252 path(argv[0])/
3253 \newline
3254 ../sdcc/include
3255 \newline
3256 \InsetSpace ~
3257 \InsetSpace ~
3258 \InsetSpace ~
3259 \InsetSpace ~
3260 \InsetSpace ~
3261 \InsetSpace ~
3262 \InsetSpace ~
3263 \InsetSpace ~
3264 \InsetSpace ~
3265 \InsetSpace ~
3266 \InsetSpace ~
3267 \InsetSpace ~
3268 \InsetSpace ~
3269 \InsetSpace ~
3270 \InsetSpace ~
3271 \InsetSpace ~
3272 \InsetSpace ~
3273 \InsetSpace ~
3274 \InsetSpace ~
3275 \InsetSpace ~
3276 \InsetSpace ~
3277 \InsetSpace ~
3278 \InsetSpace ~
3279 \InsetSpace ~
3280 \InsetSpace ~
3281 \InsetSpace ~
3282 \InsetSpace ~
3283 \InsetSpace ~
3284 \InsetSpace ~
3285 \InsetSpace ~
3286 \InsetSpace ~
3287 \InsetSpace ~
3288 \InsetSpace ~
3289 \InsetSpace ~
3290 \InsetSpace ~
3291 \InsetSpace ~
3292 \InsetSpace ~
3293 \InsetSpace ~
3294
3295 \end_layout
3296
3297 \end_inset
3298 </cell>
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3300 \begin_inset Text
3301
3302 \begin_layout Standard
3303 path(argv[0])
3304 \backslash
3305 ..
3306 \backslash
3307 include
3308 \end_layout
3309
3310 \end_inset
3311 </cell>
3312 </row>
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3315 \begin_inset Text
3316
3317 \begin_layout Standard
3318
3319 \emph on
3320 $DATADIR/
3321 \emph default
3322
3323 \newline
3324
3325 \emph on
3326 $INCLUDE_DIR_SUFFIX
3327 \end_layout
3328
3329 \end_inset
3330 </cell>
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3332 \begin_inset Text
3333
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3336 \newline
3337 include
3338 \end_layout
3339
3340 \end_inset
3341 </cell>
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3343 \begin_inset Text
3344
3345 \begin_layout Standard
3346 (not on Win32)
3347 \end_layout
3348
3349 \end_inset
3350 </cell>
3351 </row>
3352 </lyxtabular>
3353
3354 \end_inset
3355
3356  
3357 \newline
3358
3359 \end_layout
3360
3361 \begin_layout Standard
3362 \noindent
3363 The option -
3364 \begin_inset ERT
3365 status collapsed
3366
3367 \begin_layout Standard
3368
3369
3370 \backslash
3371 /
3372 \end_layout
3373
3374 \end_inset
3375
3376 -nostdinc disables the last two search paths.
3377 \newline
3378
3379 \newline
3380 3.
3381  Library files 
3382 \newline
3383
3384 \end_layout
3385
3386 \begin_layout Standard
3387 With the exception of 
3388 \begin_inset Quotes sld
3389 \end_inset
3390
3391 -
3392 \begin_inset ERT
3393 status collapsed
3394
3395 \begin_layout Standard
3396
3397
3398 \backslash
3399 /
3400 \end_layout
3401
3402 \end_inset
3403
3404 -L dir
3405 \begin_inset Quotes srd
3406 \end_inset
3407
3408  the 
3409 \shape italic
3410 model
3411 \shape default
3412  is auto-appended by the compiler (e.g.
3413  small, large, z80, ds390 etc.).
3414  
3415 \newline
3416
3417 \end_layout
3418
3419 \begin_layout Standard
3420 \align center
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3423 <features>
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3429 \begin_inset Text
3430
3431 \begin_layout Standard
3432 Search path
3433 \end_layout
3434
3435 \end_inset
3436 </cell>
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3438 \begin_inset Text
3439
3440 \begin_layout Standard
3441 default
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3447 \begin_inset Text
3448
3449 \begin_layout Standard
3450 Win32 builds
3451 \end_layout
3452
3453 \end_inset
3454 </cell>
3455 </row>
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3458 \begin_inset Text
3459
3460 \begin_layout Standard
3461 -
3462 \begin_inset ERT
3463 status collapsed
3464
3465 \begin_layout Standard
3466
3467
3468 \backslash
3469 /
3470 \end_layout
3471
3472 \end_inset
3473
3474 -L dir
3475 \end_layout
3476
3477 \end_inset
3478 </cell>
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3480 \begin_inset Text
3481
3482 \begin_layout Standard
3483 -
3484 \begin_inset ERT
3485 status collapsed
3486
3487 \begin_layout Standard
3488
3489
3490 \backslash
3491 /
3492 \end_layout
3493
3494 \end_inset
3495
3496 -L dir
3497 \end_layout
3498
3499 \end_inset
3500 </cell>
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3502 \begin_inset Text
3503
3504 \begin_layout Standard
3505 -
3506 \begin_inset ERT
3507 status collapsed
3508
3509 \begin_layout Standard
3510
3511
3512 \backslash
3513 /
3514 \end_layout
3515
3516 \end_inset
3517
3518 -L dir
3519 \end_layout
3520
3521 \end_inset
3522 </cell>
3523 </row>
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3526 \begin_inset Text
3527
3528 \begin_layout Standard
3529 $SDCC_LIB/
3530 \newline
3531
3532 \emph on
3533 <model>
3534 \end_layout
3535
3536 \end_inset
3537 </cell>
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_LIB/
3543 \newline
3544
3545 \emph on
3546 <model>
3547 \end_layout
3548
3549 \end_inset
3550 </cell>
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3552 \begin_inset Text
3553
3554 \begin_layout Standard
3555 $SDCC_LIB
3556 \backslash
3557
3558 \newline
3559
3560 \emph on
3561 <model>
3562 \end_layout
3563
3564 \end_inset
3565 </cell>
3566 </row>
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 $SDCC_HOME/
3573 \newline
3574
3575 \emph on
3576 $PREFIX2DATA_DIR/
3577 \newline
3578 $LIB_DIR_SUFFIX/<model>
3579 \end_layout
3580
3581 \end_inset
3582 </cell>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3584 \begin_inset Text
3585
3586 \begin_layout Standard
3587 $SDCC_HOME/
3588 \newline
3589 share/sdcc/
3590 \newline
3591 lib/
3592 \emph on
3593 <model>
3594 \end_layout
3595
3596 \end_inset
3597 </cell>
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3599 \begin_inset Text
3600
3601 \begin_layout Standard
3602 $SDCC_HOME
3603 \backslash
3604 lib
3605 \backslash
3606
3607 \emph on
3608
3609 \newline
3610 <model>
3611 \end_layout
3612
3613 \end_inset
3614 </cell>
3615 </row>
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3618 \begin_inset Text
3619
3620 \begin_layout Standard
3621 path(argv[0])/
3622 \newline
3623
3624 \emph on
3625 $BIN2DATADIR/
3626 \emph default
3627
3628 \newline
3629
3630 \emph on
3631 $LIB_DIR_SUFFIX/<model>
3632 \end_layout
3633
3634 \end_inset
3635 </cell>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3637 \begin_inset Text
3638
3639 \begin_layout Standard
3640 path(argv[0])/
3641 \newline
3642 ../sdcc/lib/
3643 \emph on
3644 <model>
3645 \newline
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654 \InsetSpace ~
3655 \InsetSpace ~
3656 \InsetSpace ~
3657 \InsetSpace ~
3658 \InsetSpace ~
3659 \InsetSpace ~
3660 \InsetSpace ~
3661 \InsetSpace ~
3662 \InsetSpace ~
3663 \InsetSpace ~
3664 \InsetSpace ~
3665 \InsetSpace ~
3666 \InsetSpace ~
3667 \InsetSpace ~
3668 \InsetSpace ~
3669 \InsetSpace ~
3670 \InsetSpace ~
3671 \InsetSpace ~
3672 \InsetSpace ~
3673 \InsetSpace ~
3674 \InsetSpace ~
3675 \InsetSpace ~
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685
3686 \end_layout
3687
3688 \end_inset
3689 </cell>
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3691 \begin_inset Text
3692
3693 \begin_layout Standard
3694 path(argv[0])
3695 \backslash
3696
3697 \newline
3698 ..
3699 \backslash
3700 lib
3701 \backslash
3702
3703 \emph on
3704 <model>
3705 \newline
3706 \InsetSpace ~
3707 \InsetSpace ~
3708 \InsetSpace ~
3709 \InsetSpace ~
3710 \InsetSpace ~
3711 \InsetSpace ~
3712 \InsetSpace ~
3713 \InsetSpace ~
3714 \InsetSpace ~
3715 \InsetSpace ~
3716 \InsetSpace ~
3717 \InsetSpace ~
3718 \InsetSpace ~
3719 \InsetSpace ~
3720 \InsetSpace ~
3721 \InsetSpace ~
3722 \InsetSpace ~
3723 \InsetSpace ~
3724 \InsetSpace ~
3725 \InsetSpace ~
3726 \InsetSpace ~
3727 \InsetSpace ~
3728 \InsetSpace ~
3729 \InsetSpace ~
3730 \InsetSpace ~
3731 \InsetSpace ~
3732 \InsetSpace ~
3733 \InsetSpace ~
3734 \InsetSpace ~
3735 \InsetSpace ~
3736 \InsetSpace ~
3737 \InsetSpace ~
3738 \InsetSpace ~
3739 \InsetSpace ~
3740 \InsetSpace ~
3741
3742 \end_layout
3743
3744 \end_inset
3745 </cell>
3746 </row>
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3749 \begin_inset Text
3750
3751 \begin_layout Standard
3752
3753 \emph on
3754 $DATADIR/
3755 \newline
3756 $LIB_DIR_SUFFIX/<model>
3757 \end_layout
3758
3759 \end_inset
3760 </cell>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3762 \begin_inset Text
3763
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3766 \newline
3767 lib/
3768 \emph on
3769 <model>
3770 \end_layout
3771
3772 \end_inset
3773 </cell>
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3775 \begin_inset Text
3776
3777 \begin_layout Standard
3778 (not on Win32)
3779 \end_layout
3780
3781 \end_inset
3782 </cell>
3783 </row>
3784 </lyxtabular>
3785
3786 \end_inset
3787
3788
3789 \newline
3790
3791 \end_layout
3792
3793 \begin_layout Standard
3794 \begin_inset Note Note
3795 status collapsed
3796
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799  the HTML output (last line)!
3800 \end_layout
3801
3802 \end_inset
3803
3804
3805 \end_layout
3806
3807 \begin_layout Standard
3808 \InsetSpace ~
3809
3810 \newline
3811 The option -
3812 \begin_inset ERT
3813 status collapsed
3814
3815 \begin_layout Standard
3816
3817
3818 \backslash
3819 /
3820 \end_layout
3821
3822 \end_inset
3823
3824 -nostdlib disables the last two search paths.
3825 \end_layout
3826
3827 \begin_layout Section
3828 Building SDCC
3829 \begin_inset LatexCommand \index{Building SDCC}
3830
3831 \end_inset
3832
3833
3834 \end_layout
3835
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3839
3840 \end_inset
3841
3842
3843 \end_layout
3844
3845 \begin_layout Enumerate
3846
3847 \series medium
3848 Download the source package
3849 \series default
3850  either from the SDCC Subversion repository or from snapshot builds
3851 \series medium
3852 , it will be named something like sdcc
3853 \series default
3854 -src
3855 \series medium
3856 -yyyymmdd-rrrr.t
3857 \series default
3858 ar.
3859 \series medium
3860 bz2
3861 \series default
3862  
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3864
3865 \end_inset
3866
3867 .
3868 \end_layout
3869
3870 \begin_layout Enumerate
3871
3872 \series medium
3873 Bring up a command line terminal, such as xterm.
3874 \end_layout
3875
3876 \begin_layout Enumerate
3877
3878 \series medium
3879 Unpack the file using a command like: 
3880 \family sans
3881 \series bold
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3884 \end_inset
3885
3886
3887 \family default
3888 \series medium
3889 , this will create a sub-directory called sdcc with all of the sources.
3890 \end_layout
3891
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type: 
3894 \family sans
3895 \series bold
3896 "cd sdcc
3897 \series default
3898 ".
3899 \end_layout
3900
3901 \begin_layout Enumerate
3902
3903 \series medium
3904 Type 
3905 \family sans
3906 \series bold
3907 "./configure
3908 \family default
3909 \series default
3910 ".
3911  This configures the package for compilation on your system.
3912 \end_layout
3913
3914 \begin_layout Enumerate
3915
3916 \series medium
3917 Type 
3918 \family sans
3919 \series bold
3920 "make
3921 \family default
3922 \series default
3923 "
3924 \series medium
3925 .
3926
3927 \series default
3928  All of the source packages will compile, this can take a while.
3929 \end_layout
3930
3931 \begin_layout Enumerate
3932
3933 \series medium
3934 Type 
3935 \family sans
3936 \series bold
3937 "make install"
3938 \family default
3939 \series default
3940  as root
3941 \series medium
3942 .
3943
3944 \series default
3945  This copies the binary executables, the include files, the libraries and
3946  the documentation to the install directories.
3947  Proceed with section 
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3949
3950 \end_inset
3951
3952 .
3953 \end_layout
3954
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3957 \end_layout
3958
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3961 \newline
3962
3963 \newline
3964 On Mac OS X 10.2.x it was reported, that the
3965  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966  Fortunately there's also gcc 2.9.x installed, which works fine.
3967  This compiler can be selected by running 'configure' with:
3968 \end_layout
3969
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3972 \end_layout
3973
3974 \begin_layout Subsection
3975 Cross compiling SDCC on Linux for Windows
3976 \end_layout
3977
3978 \begin_layout Standard
3979 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3980  See section 'Configure Options'.
3981 \end_layout
3982
3983 \begin_layout Subsection
3984 Building SDCC using Cygwin and Mingw32
3985 \end_layout
3986
3987 \begin_layout Standard
3988 For building and installing a Cygwin executable follow the instructions
3989  for Linux.
3990 \newline
3991
3992 \newline
3993 On Cygwin a 
3994 \begin_inset Quotes sld
3995 \end_inset
3996
3997 native
3998 \begin_inset Quotes srd
3999 \end_inset
4000
4001  Win32-binary can be built, which will not need the Cygwin-DLL.
4002  For the necessary 'configure' options see section 'configure options' or
4003  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4004 \newline
4005
4006 \newline
4007 In order to install
4008  Cygwin on Windows download setup.exe from 
4009 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4010
4011 \end_inset
4012
4013 .
4014  Run it, set the 
4015 \begin_inset Quotes sld
4016 \end_inset
4017
4018 default text file type
4019 \begin_inset Quotes srd
4020 \end_inset
4021
4022  to 
4023 \begin_inset Quotes sld
4024 \end_inset
4025
4026 unix
4027 \begin_inset Quotes srd
4028 \end_inset
4029
4030  and download/install at least the following packages.
4031  Some packages are selected by default, others will be automatically selected
4032  because of dependencies with the manually selected packages.
4033  Never deselect these packages!
4034 \end_layout
4035
4036 \begin_layout Itemize
4037 flex
4038 \end_layout
4039
4040 \begin_layout Itemize
4041 bison
4042 \end_layout
4043
4044 \begin_layout Itemize
4045 gcc ; version 3.x is fine, no need to use the old 2.9x
4046 \end_layout
4047
4048 \begin_layout Itemize
4049 binutils ; selected with gcc
4050 \end_layout
4051
4052 \begin_layout Itemize
4053 make
4054 \end_layout
4055
4056 \begin_layout Itemize
4057 rxvt ; a nice console, which makes life much easier under windoze (see below)
4058 \end_layout
4059
4060 \begin_layout Itemize
4061 man ; not really needed for building SDCC, but you'll miss it sooner or
4062  later
4063 \end_layout
4064
4065 \begin_layout Itemize
4066 less ; not really needed for building SDCC, but you'll miss it sooner or
4067  later
4068 \end_layout
4069
4070 \begin_layout Itemize
4071 svn ; only if you use Subversion access
4072 \end_layout
4073
4074 \begin_layout Standard
4075 If you want to develop something you'll need:
4076 \end_layout
4077
4078 \begin_layout Itemize
4079 python ; for the regression tests
4080 \end_layout
4081
4082 \begin_layout Itemize
4083 gdb ; the gnu debugger, together with the nice GUI 
4084 \begin_inset Quotes sld
4085 \end_inset
4086
4087 insight
4088 \begin_inset Quotes srd
4089 \end_inset
4090
4091
4092 \end_layout
4093
4094 \begin_layout Itemize
4095 openssh ; to access the CF or commit changes
4096 \end_layout
4097
4098 \begin_layout Itemize
4099 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4100  use autoconf-stable!
4101 \end_layout
4102
4103 \begin_layout Standard
4104 rxvt is a nice console with history.
4105  Replace in your cygwin.bat the line
4106 \end_layout
4107
4108 \begin_layout LyX-Code
4109 bash -
4110 \begin_inset ERT
4111 status collapsed
4112
4113 \begin_layout Standard
4114
4115
4116 \backslash
4117 /
4118 \end_layout
4119
4120 \end_inset
4121
4122 -login -i 
4123 \end_layout
4124
4125 \begin_layout Standard
4126 with (one line):
4127 \end_layout
4128
4129 \begin_layout LyX-Code
4130 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4131 \end_layout
4132
4133 \begin_layout LyX-Code
4134      -bg black -fg white -geometry 100x65 -e bash -
4135 \begin_inset ERT
4136 status collapsed
4137
4138 \begin_layout Standard
4139
4140
4141 \backslash
4142 /
4143 \end_layout
4144
4145 \end_inset
4146
4147 -login
4148 \end_layout
4149
4150 \begin_layout Standard
4151 Text selected with the mouse is automatically copied to the clipboard, pasting
4152  works with shift-insert.
4153 \newline
4154
4155 \newline
4156 The other good tip is to make sure you have no //c/-styl
4157 e paths anywhere, use /cygdrive/c/ instead.
4158  Using // invokes a network lookup which is very slow.
4159  If you think 
4160 \begin_inset Quotes sld
4161 \end_inset
4162
4163 cygdrive
4164 \begin_inset Quotes srd
4165 \end_inset
4166
4167  is too long, you can change it with e.g.
4168 \end_layout
4169
4170 \begin_layout LyX-Code
4171 mount -s -u -c /mnt
4172 \end_layout
4173
4174 \begin_layout Standard
4175 SDCC sources use the unix line ending LF.
4176  Life is much easier, if you store the source tree on a drive which is mounted
4177  in binary mode.
4178  And use an editor which can handle LF-only line endings.
4179  Make sure not to commit files with windows line endings.
4180  The tabulator spacing
4181 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4182
4183 \end_inset
4184
4185  used in the project is 8.
4186  Although a tabulator spacing of 8 is a sensible choice for programmers
4187  (it's a power of 2 and allows to display 8/16 bit signed variables without
4188  loosing columns) the plan is to move towards using only spaces in the source.
4189 \end_layout
4190
4191 \begin_layout Subsection
4192 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4193 \end_layout
4194
4195 \begin_layout Standard
4196
4197 \series medium
4198 Download the source package
4199 \series default
4200  either from the SDCC Subversion repository or from the 
4201 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4202
4203 \end_inset
4204
4205
4206 \series medium
4207 , it will be named something like sdcc
4208 \series default
4209 -src
4210 \series medium
4211 -yyyymmdd-rrrr.tar.bz2.
4212
4213 \series default
4214  SDCC is distributed with all the projects, workspaces, and files you need
4215  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4216  The workspace name is 'sdcc.dsw'.
4217  Please note that as it is now, all the executables are created in a folder
4218  called sdcc
4219 \backslash
4220 bin_vc.
4221  Once built you need to copy the executables from sdcc
4222 \backslash
4223 bin_vc to sdcc
4224 \backslash
4225 bin before running SDCC.
4226  
4227 \newline
4228
4229 \newline
4230 WARNING: Visual studio is very picky with line terminations; it expects
4231  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4232  When using the Subversion repository it's easiest to configure the svn
4233  client to convert automatically for you.
4234  If however you are getting a message such as "This makefile was not generated
4235  by Developer Studio etc.
4236  etc.
4237 \begin_inset Quotes srd
4238 \end_inset
4239
4240  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4241  need to convert the Unix style line endings to DOS style line endings.
4242  To do so you can use the 
4243 \begin_inset Quotes sld
4244 \end_inset
4245
4246 unix2dos
4247 \begin_inset Quotes srd
4248 \end_inset
4249
4250  utility freely available on the internet.
4251  Doug Hawkins reported in the sdcc-user list that this works:
4252 \newline
4253
4254 \newline
4255 C:
4256 \backslash
4257 Programming
4258 \backslash
4259 SDCC> unix2dos sdcc.dsw
4260 \newline
4261 C:
4262 \backslash
4263 Programming
4264 \backslash
4265 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4266 \newline
4267
4268 \newline
4269 In order to build SDCC with MSVC
4270  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4271  One good place to get them is 
4272 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4273
4274 \end_inset
4275
4276
4277 \newline
4278
4279 \newline
4280 Download the file UnxUtils
4281 \begin_inset LatexCommand \index{UnxUtils}
4282
4283 \end_inset
4284
4285 .zip.
4286  Now you have to install the utilities and setup MSVC so it can locate the
4287  required programs.
4288  Here there are two alternatives (choose one!):
4289 \end_layout
4290
4291 \begin_layout Enumerate
4292 The easy way:
4293 \newline
4294
4295 \newline
4296 a) Extract UnxUtils.zip to your C:
4297 \backslash
4298  hard disk PRESERVING the original paths, otherwise bison won't work.
4299  (If you are using WinZip make certain that 'Use folder names' is selected)
4300 \newline
4301
4302 \newline
4303 b)
4304  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4305  'Show directories for:' select 'Executable files', and in the directories
4306  window add a new path: 'C:
4307 \backslash
4308 user
4309 \backslash
4310 local
4311 \backslash
4312 wbin', click ok.
4313 \newline
4314
4315 \newline
4316 (As a side effect, you get a bunch of Unix utilities that
4317  could be useful, such as diff and patch.)
4318 \end_layout
4319
4320 \begin_layout Enumerate
4321 A more compact way:
4322 \newline
4323
4324 \newline
4325 This one avoids extracting a bunch of files you may not
4326  use, but requires some extra work:
4327 \newline
4328
4329 \newline
4330 a) Create a directory were to put the
4331  tools needed, or use a directory already present.
4332  Say for example 'C:
4333 \backslash
4334 util'.
4335 \newline
4336
4337 \newline
4338 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4339  gawk.exe to such directory WITHOUT preserving the original paths.
4340  (If you are using WinZip make certain that 'Use folder names' is not selected)
4341 \newline
4342
4343 \newline
4344 c
4345 ) Rename bison.exe to '_bison.exe'.
4346 \newline
4347
4348 \newline
4349 d) Create a batch file 'bison.bat' in 'C:
4350 \backslash
4351 util
4352 \backslash
4353 ' and add these lines: 
4354 \newline
4355 \InsetSpace ~
4356 \InsetSpace ~
4357 set BISON_SIMPLE=C:
4358 \backslash
4359 util
4360 \backslash
4361 bison.simple 
4362 \newline
4363 \InsetSpace ~
4364 \InsetSpace ~
4365 set BISON_HAIRY=C:
4366 \backslash
4367 util
4368 \backslash
4369 bison.hairy
4370 \newline
4371 \InsetSpace ~
4372 \InsetSpace ~
4373 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4374 \newline
4375
4376 \newline
4377 Steps 'c' and 'd' are needed
4378  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4379  reside in some weird Unix directory, '/usr/local/share/' I think.
4380  So it is necessary to tell bison where those files are located if they
4381  are not in such directory.
4382  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4383 \newline
4384
4385 \newline
4386 e
4387 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4388  in 'Show directories for:' select 'Executable files', and in the directories
4389  window add a new path: 'c:
4390 \backslash
4391 util', click ok.
4392  Note that you can use any other path instead of 'c:
4393 \backslash
4394 util', even the path where the Visual C++ tools are, probably: 'C:
4395 \backslash
4396 Program Files
4397 \backslash
4398 Microsoft Visual Studio
4399 \backslash
4400 Common
4401 \backslash
4402 Tools'.
4403  So you don't have to execute step 'e' :)
4404 \end_layout
4405
4406 \begin_layout Standard
4407 That is it.
4408  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4409  the executables from sdcc
4410 \backslash
4411 bin_vc to sdcc
4412 \backslash
4413 bin, and you can compile using SDCC.
4414 \end_layout
4415
4416 \begin_layout Subsection
4417 Building SDCC Using Borland
4418 \end_layout
4419
4420 \begin_layout Enumerate
4421 From the sdcc directory, run the command "make -f Makefile.bcc".
4422  This should regenerate all the .exe files in the bin directory except for
4423  SDCDB and ucSim.
4424 \end_layout
4425
4426 \begin_layout Enumerate
4427 If you modify any source files and need to rebuild, be aware that the dependenci
4428 es may not be correctly calculated.
4429  The safest option is to delete all .obj files and run the build again.
4430  From a Cygwin BASH prompt, this can easily be done with the command (be
4431  sure you are in the sdcc directory):
4432 \newline
4433
4434 \newline
4435
4436 \family sans
4437 \series bold
4438 find .
4439  
4440 \backslash
4441 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4442 \backslash
4443 ) -print -exec rm {} 
4444 \backslash
4445 ;
4446 \family default
4447 \series default
4448
4449 \newline
4450
4451 \newline
4452 or on Windows NT/2000/XP from the command prompt with the command:
4453 \newline
4454
4455 \family sans
4456 \series bold
4457
4458 \newline
4459 del /s *.obj *.lib *.rul
4460 \family default
4461 \series default
4462  from the sdcc directory.
4463 \end_layout
4464
4465 \begin_layout Subsection
4466 Windows Install Using a ZIP Package
4467 \end_layout
4468
4469 \begin_layout Enumerate
4470 Download the binary zip package from 
4471 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4472
4473 \end_inset
4474
4475  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4476  This should unpack to a group of sub-directories.
4477  An example directory structure after unpacking the mingw32 package is:
4478  c:
4479 \backslash
4480 sdcc
4481 \backslash
4482 bin for the executables, c:
4483 \backslash
4484 sdcc
4485 \backslash
4486 include and c:
4487 \backslash
4488 sdcc
4489 \backslash
4490 lib for the include and libraries.
4491 \end_layout
4492
4493 \begin_layout Enumerate
4494 Adjust your environment variable PATH to include the location of the bin
4495  directory or start sdcc using the full path.
4496 \end_layout
4497
4498 \begin_layout Subsection
4499 Windows Install Using the Setup Program
4500 \begin_inset LatexCommand \label{sub:Windows-Install}
4501
4502 \end_inset
4503
4504
4505 \end_layout
4506
4507 \begin_layout Standard
4508 Download the setup program 
4509 \emph on
4510 sdcc-x.y.z-setup.exe
4511 \emph default
4512  for an official release from 
4513 \newline
4514
4515 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4516
4517 \end_inset
4518
4519  or a setup program for one of the snapshots 
4520 \emph on
4521 sdcc-yyyymmdd-xxxx-setup.exe
4522 \emph default
4523  from 
4524 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4525
4526 \end_inset
4527
4528  and execute it.
4529  A windows typical installer will guide you through the installation process.
4530 \end_layout
4531
4532 \begin_layout Subsection
4533 VPATH
4534 \begin_inset LatexCommand \index{VPATH}
4535
4536 \end_inset
4537
4538  feature
4539 \end_layout
4540
4541 \begin_layout Standard
4542 SDCC supports the VPATH feature provided by configure and make.
4543  It allows to separate the source and build trees.
4544  Here's an example:
4545 \end_layout
4546
4547 \begin_layout Standard
4548
4549 \family typewriter
4550 cd ~\InsetSpace ~
4551 \InsetSpace ~
4552 \InsetSpace ~
4553 \InsetSpace ~
4554 \InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 \InsetSpace ~
4563 \InsetSpace ~
4564 \InsetSpace ~
4565 \InsetSpace ~
4566 \InsetSpace ~
4567 \InsetSpace ~
4568 \InsetSpace ~
4569 \InsetSpace ~
4570 \InsetSpace ~
4571 # cd $HOME
4572 \end_layout
4573
4574 \begin_layout Standard
4575
4576 \family typewriter
4577 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4578 # extract source to directory sdcc
4579 \end_layout
4580
4581 \begin_layout Standard
4582
4583 \family typewriter
4584 mkdir sdcc.build\InsetSpace ~
4585 \InsetSpace ~
4586 \InsetSpace ~
4587 \InsetSpace ~
4588 \InsetSpace ~
4589 \InsetSpace ~
4590 \InsetSpace ~
4591 \InsetSpace ~
4592 \InsetSpace ~
4593 # put output in sdcc.build
4594 \end_layout
4595
4596 \begin_layout Standard
4597
4598 \family typewriter
4599 cd sdcc.build
4600 \end_layout
4601
4602 \begin_layout Standard
4603
4604 \family typewriter
4605 ../sdcc/configure\InsetSpace ~
4606 \InsetSpace ~
4607 \InsetSpace ~
4608 \InsetSpace ~
4609 \InsetSpace ~
4610 \InsetSpace ~
4611 \InsetSpace ~
4612 \InsetSpace ~
4613 # configure is doing all the magic!
4614 \end_layout
4615
4616 \begin_layout Standard
4617
4618 \family typewriter
4619 make
4620 \end_layout
4621
4622 \begin_layout Standard
4623 \noindent
4624 That's it! 
4625 \series bold
4626 configure
4627 \series default
4628  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4629  It automagically computes the variables srcdir, top_srcdir and top_buildir
4630  for each directory.
4631  After running 
4632 \series bold
4633 make
4634 \series default
4635  the generated files will be in ~/sdcc.build, while the source files stay
4636  in ~/sdcc.
4637 \newline
4638 This is not only usefull for building different binaries, e.g.
4639  when cross compiling.
4640  It also gives you a much better overview in the source tree when all the
4641  generated files are not scattered between the source files.
4642  And the best thing is: if you want to change a file you can leave the original
4643  file untouched in the source directory.
4644  Simply copy it to the build directory, edit it, enter `make clean', `rm
4645  Makefile.dep' and `make'.
4646  
4647 \series bold
4648 make
4649 \series default
4650  will do the rest for you!
4651 \end_layout
4652
4653 \begin_layout Section
4654 Building the Documentation
4655 \end_layout
4656
4657 \begin_layout Standard
4658 Add -
4659 \begin_inset ERT
4660 status collapsed
4661
4662 \begin_layout Standard
4663
4664
4665 \backslash
4666 /
4667 \end_layout
4668
4669 \end_inset
4670
4671 -enable-doc to the configure arguments to build the documentation together
4672  with all the other stuff.
4673  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4674  dvips and makeindex) to get the job done.
4675  Another possibility is to change to the doc directory and to type 
4676 \family sans
4677 \series bold
4678
4679 \begin_inset Quotes srd
4680 \end_inset
4681
4682 make
4683 \begin_inset Quotes srd
4684 \end_inset
4685
4686
4687 \family default
4688 \series default
4689  there.
4690  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4691 x).
4692  Using LyX 
4693 \begin_inset LatexCommand \url{http://www.lyx.org}
4694
4695 \end_inset
4696
4697  as editor is straightforward.
4698  Prebuilt documentation in html and pdf format is available from 
4699 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4700
4701 \end_inset
4702
4703 .
4704 \end_layout
4705
4706 \begin_layout Section
4707 Reading the Documentation
4708 \begin_inset LatexCommand \index{Documentation}
4709
4710 \end_inset
4711
4712
4713 \end_layout
4714
4715 \begin_layout Standard
4716 Currently reading the document in pdf format is recommended, as for unknown
4717  reason the hyperlinks are working there whereas in the html version they
4718  are not
4719 \begin_inset Foot
4720 status open
4721
4722 \begin_layout Standard
4723 If you should know why please drop us a note
4724 \end_layout
4725
4726 \end_inset
4727
4728 .
4729  
4730 \newline
4731 You'll find the pdf version
4732 \begin_inset LatexCommand \index{PDF version of this document}
4733
4734 \end_inset
4735
4736  at 
4737 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4738
4739 \end_inset
4740
4741 .
4742  
4743 \newline
4744 A html version
4745 \begin_inset LatexCommand \index{HTML version of this document}
4746
4747 \end_inset
4748
4749  should be online at 
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4751
4752 \end_inset
4753
4754 .
4755 \newline
4756 This documentation is in some aspects different from a commercial documentation:
4757  
4758 \end_layout
4759
4760 \begin_layout Itemize
4761 It tries to document SDCC for several processor architectures in one document
4762  (commercially these probably would be separate documents/products).
4763  This document
4764 \begin_inset LatexCommand \index{Status of documentation}
4765
4766 \end_inset
4767
4768  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4769 on about f.e.
4770  Z80, PIC14, PIC16 and HC08.
4771 \end_layout
4772
4773 \begin_layout Itemize
4774 There are many references pointing away from this documentation.
4775  Don't let this distract you.
4776  If there f.e.
4777  was a reference like 
4778 \begin_inset LatexCommand \url{http://www.opencores.org}
4779
4780 \end_inset
4781
4782  together with a statement 
4783 \begin_inset Quotes sld
4784 \end_inset
4785
4786 some processors which are targetted by SDCC can be implemented in a 
4787 \emph on
4788 f
4789 \emph default
4790 ield 
4791 \emph on
4792 p
4793 \emph default
4794 rogrammable 
4795 \emph on
4796 g
4797 \emph default
4798 ate 
4799 \emph on
4800 a
4801 \emph default
4802 rray
4803 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4804
4805 \end_inset
4806
4807
4808 \begin_inset Quotes srd
4809 \end_inset
4810
4811  or 
4812 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4813
4814 \end_inset
4815
4816
4817 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4818
4819 \end_inset
4820
4821  
4822 \begin_inset Quotes sld
4823 \end_inset
4824
4825 have you ever heard of an open source compiler that compiles a subset of
4826  C for an FPGA?
4827 \begin_inset Quotes srd
4828 \end_inset
4829
4830  we expect you to have a quick look there and come back.
4831  If you read this you are on the right track.
4832 \end_layout
4833
4834 \begin_layout Itemize
4835 Some sections attribute more space to problems, restrictions and warnings
4836  than to the solution.
4837 \end_layout
4838
4839 \begin_layout Itemize
4840 The installation section and the section about the debugger is intimidating.
4841 \end_layout
4842
4843 \begin_layout Itemize
4844 There are still lots of typos and there are more different writing styles
4845  than pictures.
4846 \end_layout
4847
4848 \begin_layout Section
4849 Testing the SDCC Compiler
4850 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4851
4852 \end_inset
4853
4854
4855 \end_layout
4856
4857 \begin_layout Standard
4858 The first thing you should do after installing your SDCC compiler is to
4859  see if it runs.
4860  Type 
4861 \family sans
4862 \series bold
4863 "sdcc -
4864 \begin_inset ERT
4865 status collapsed
4866
4867 \begin_layout Standard
4868
4869
4870 \backslash
4871 /
4872 \end_layout
4873
4874 \end_inset
4875
4876 -version"
4877 \begin_inset LatexCommand \index{version}
4878
4879 \end_inset
4880
4881
4882 \family default
4883 \series default
4884  at the prompt, and the program should run and output its version like:
4885  
4886 \newline
4887
4888 \family typewriter
4889 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4890  (UNIX)
4891 \end_layout
4892
4893 \begin_layout Standard
4894 If it doesn't run, or gives a message about not finding sdcc program, then
4895  you need to check over your installation.
4896  Make sure that the sdcc bin directory is in your executable search path
4897  defined by the PATH environment setting (
4898 \series medium
4899 see 
4900 \series default
4901 section 
4902 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4903
4904 \end_inset
4905
4906 \InsetSpace ~
4907
4908 \series medium
4909 Install trouble-shooting for suggestions
4910 \series default
4911 ).
4912  Make sure that the sdcc program is in the bin folder, if not perhaps something
4913  did not install correctly.
4914 \newline
4915
4916 \newline
4917
4918 \series medium
4919 SDCC 
4920 \series default
4921 is commonly installed as described in section 
4922 \begin_inset Quotes sld
4923 \end_inset
4924
4925 Install and search paths
4926 \begin_inset Quotes srd
4927 \end_inset
4928
4929 .
4930 \newline
4931
4932 \newline
4933
4934 \series medium
4935 Make sure the compiler works on a very simple example.
4936  Type in the following test.c program using your favorite 
4937 \series default
4938 ASCII 
4939 \series medium
4940 editor:
4941 \end_layout
4942
4943 \begin_layout Verse
4944
4945 \family typewriter
4946 char test;
4947 \newline
4948
4949 \newline
4950 void main(void) {
4951 \newline
4952 \InsetSpace ~
4953 \InsetSpace ~
4954 \InsetSpace ~
4955 \InsetSpace ~
4956 test=0;
4957 \newline
4958 }
4959 \end_layout
4960
4961 \begin_layout Standard
4962
4963 \series medium
4964 Compile this using the following command: 
4965 \family sans
4966 \series bold
4967 "sdcc -c test.c".
4968
4969 \family default
4970 \series default
4971  
4972 \series medium
4973 If all goes well, the compiler will generate a test.asm and test.rel file.
4974  Congratulations, you've just compiled your first program with SDCC.
4975  We used the -c option to tell SDCC not to link the generated code, just
4976  to keep things simple for this step.
4977 \series default
4978
4979 \newline
4980
4981 \newline
4982
4983 \series medium
4984 The next step is to try it with the linker.
4985  Type in 
4986 \family sans
4987 \series bold
4988 "sdcc test.c
4989 \family default
4990 \series default
4991 "
4992 \series medium
4993 .
4994  If all goes well the compiler will link with the libraries and produce
4995  a test.ihx output file.
4996  If this step fails
4997 \series default
4998  
4999 \series medium
5000 (no test.ihx, and the linker generates warnings), then the problem is most
5001  likely that 
5002 \series default
5003 SDCC
5004 \series medium
5005  cannot find the 
5006 \series default
5007 /
5008 \series medium
5009 usr/local/share/sdcc/lib directory
5010 \series default
5011  
5012 \series medium
5013 (see 
5014 \series default
5015 section 
5016 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5017
5018 \end_inset
5019
5020 \InsetSpace ~
5021
5022 \series medium
5023 Install trouble-shooting for suggestions).
5024 \series default
5025
5026 \newline
5027
5028 \newline
5029
5030 \series medium
5031 The final test is to ensure 
5032 \series default
5033 SDCC
5034 \series medium
5035  can use the 
5036 \series default
5037 standard
5038 \series medium
5039  header files and libraries.
5040  Edit test.c and change it to the following:
5041 \end_layout
5042
5043 \begin_layout Verse
5044
5045 \family typewriter
5046 #include <string.h>
5047 \newline
5048
5049 \newline
5050 char str1[10];
5051 \newline
5052
5053 \newline
5054 void main(void) {
5055 \newline
5056 \InsetSpace ~
5057 \InsetSpace ~
5058 strcpy(str1, "testing");
5059 \newline
5060 }
5061 \end_layout
5062
5063 \begin_layout Standard
5064
5065 \series medium
5066 Compile this by typing 
5067 \family sans
5068 \series bold
5069 "sdcc test.c"
5070 \family default
5071 \series medium
5072 .
5073  This should generate a test.ihx output file, and it should give no warnings
5074  such as not finding the string.h file.
5075  If it cannot find the string.h file, then the problem is that 
5076 \series default
5077 SDCC
5078 \series medium
5079  cannot find the /usr/local/share/sdcc/include directory
5080 \series default
5081  
5082 \series medium
5083 (see the 
5084 \series default
5085 section 
5086 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5087
5088 \end_inset
5089
5090 \InsetSpace ~
5091
5092 \series medium
5093 Install trouble-shooting section for suggestions).
5094
5095 \series default
5096  Use option 
5097 \series bold
5098 -
5099 \begin_inset ERT
5100 status collapsed
5101
5102 \begin_layout Standard
5103
5104
5105 \backslash
5106 /
5107 \end_layout
5108
5109 \end_inset
5110
5111 -print-search-dirs
5112 \series default
5113
5114 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5115
5116 \end_inset
5117
5118  to find exactly where SDCC is looking for the include and lib files.
5119 \end_layout
5120
5121 \begin_layout Section
5122 Install Trouble-shooting
5123 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5124
5125 \end_inset
5126
5127
5128 \begin_inset LatexCommand \index{Install trouble-shooting}
5129
5130 \end_inset
5131
5132
5133 \end_layout
5134
5135 \begin_layout Subsection
5136 If SDCC does not build correctly
5137 \end_layout
5138
5139 \begin_layout Standard
5140 A thing to try is starting from scratch by unpacking the .tgz source package
5141  again in an empty directory.
5142  Configure it like:
5143 \newline
5144
5145 \newline
5146
5147 \family sans
5148 \series bold
5149 ./configure 2>&1 | tee configure.log
5150 \family default
5151 \series default
5152
5153 \newline
5154
5155 \newline
5156 and build it like:
5157 \newline
5158
5159 \newline
5160
5161 \family sans
5162 \series bold
5163 make 2>&1 | tee make.log
5164 \family default
5165 \series default
5166
5167 \newline
5168
5169 \newline
5170 If anything goes wrong, you can review the log files to locate the problem.
5171  Or a relevant part of this can be attached to an email that could be helpful
5172  when requesting help from the mailing list.
5173 \end_layout
5174
5175 \begin_layout Subsection
5176 What the 
5177 \begin_inset Quotes sld
5178 \end_inset
5179
5180 ./configure
5181 \begin_inset Quotes srd
5182 \end_inset
5183
5184  does
5185 \end_layout
5186
5187 \begin_layout Standard
5188 The 
5189 \begin_inset Quotes sld
5190 \end_inset
5191
5192 ./configure
5193 \begin_inset Quotes srd
5194 \end_inset
5195
5196  command is a script that analyzes your system and performs some configuration
5197  to ensure the source package compiles on your system.
5198  It will take a few minutes to run, and will compile a few tests to determine
5199  what compiler features are installed.
5200 \end_layout
5201
5202 \begin_layout Subsection
5203 What the 
5204 \begin_inset Quotes sld
5205 \end_inset
5206
5207 make
5208 \begin_inset Quotes srd
5209 \end_inset
5210
5211  does
5212 \end_layout
5213
5214 \begin_layout Standard
5215 This runs the GNU make tool, which automatically compiles all the source
5216  packages into the final installed binary executables.
5217 \end_layout
5218
5219 \begin_layout Subsection
5220 What the 
5221 \begin_inset Quotes sld
5222 \end_inset
5223
5224 make install
5225 \begin_inset Quotes erd
5226 \end_inset
5227
5228  command does.
5229 \end_layout
5230
5231 \begin_layout Standard
5232 This will install the compiler, other executables libraries and include
5233  files into the appropriate directories.
5234  See sections 
5235 \begin_inset LatexCommand \ref{sub:Install-paths}
5236
5237 \end_inset
5238
5239 ,\InsetSpace ~
5240
5241 \begin_inset LatexCommand \ref{sub:Search-Paths}
5242
5243 \end_inset
5244
5245 \InsetSpace ~
5246 about install and search paths.
5247 \newline
5248 On most systems you will need super-user privilege
5249 s to do this.
5250 \end_layout
5251
5252 \begin_layout Section
5253 Components of SDCC
5254 \end_layout
5255
5256 \begin_layout Standard
5257 SDCC is not just a compiler, but a collection of tools by various developers.
5258  These include linkers, assemblers, simulators and other components.
5259  Here is a summary of some of the components.
5260  Note that the included simulator and assembler have separate documentation
5261  which you can find in the source package in their respective directories.
5262  As SDCC grows to include support for other processors, other packages from
5263  various developers are included and may have their own sets of documentation.
5264 \newline
5265
5266 \newline
5267 You
5268  might want to look at the files which are installed in <installdir>.
5269  At the time of this writing, we find the following programs for gcc-builds:
5270 \newline
5271
5272  
5273 \newline
5274 In <installdir>/bin:
5275 \end_layout
5276
5277 \begin_layout Itemize
5278 sdcc - The compiler.
5279 \end_layout
5280
5281 \begin_layout Itemize
5282 sdcpp - The C preprocessor.
5283 \end_layout
5284
5285 \begin_layout Itemize
5286 asx8051 - The assembler for 8051 type processors.
5287 \end_layout
5288
5289 \begin_layout Itemize
5290 as-z80
5291 \series bold
5292
5293 \series default
5294 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5295 \end_layout
5296
5297 \begin_layout Itemize
5298 aslink -The linker for 8051 type processors.
5299 \end_layout
5300
5301 \begin_layout Itemize
5302 link-z80
5303 \series bold
5304
5305 \series default
5306 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5307 \end_layout
5308
5309 \begin_layout Itemize
5310 s51 - The ucSim 8051 simulator.
5311 \end_layout
5312
5313 \begin_layout Itemize
5314 sdcdb - The source debugger.
5315 \end_layout
5316
5317 \begin_layout Itemize
5318 packihx - A tool to pack (compress) Intel hex files.
5319 \end_layout
5320
5321 \begin_layout Standard
5322 In <installdir>/share/sdcc/include
5323 \end_layout
5324
5325 \begin_layout Itemize
5326 the include files
5327 \end_layout
5328
5329 \begin_layout Standard
5330 In <installdir>/share/sdcc/lib
5331 \end_layout
5332
5333 \begin_layout Itemize
5334 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5335  relocatables.
5336 \end_layout
5337
5338 \begin_layout Standard
5339 In <installdir>/share/sdcc/doc
5340 \end_layout
5341
5342 \begin_layout Itemize
5343 the documentation
5344 \end_layout
5345
5346 \begin_layout Standard
5347 As development for other processors proceeds, this list will expand to include
5348  executables to support processors like AVR, PIC, etc.
5349 \end_layout
5350
5351 \begin_layout Subsection
5352 sdcc - The Compiler
5353 \end_layout
5354
5355 \begin_layout Standard
5356 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5357  the assembler and linkage editor.
5358 \end_layout
5359
5360 \begin_layout Subsection
5361 sdcpp - The C-Preprocessor
5362 \end_layout
5363
5364 \begin_layout Standard
5365 The preprocessor
5366 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5367
5368 \end_inset
5369
5370  is a modified version of the GNU cpp
5371 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5372
5373 \end_inset
5374
5375  preprocessor 
5376 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5377
5378 \end_inset
5379
5380 .
5381  The C preprocessor is used to pull in #include sources, process #ifdef
5382  statements, #defines and so on.
5383 \end_layout
5384
5385 \begin_layout Subsection
5386 as
5387 \emph on
5388 xxxx
5389 \emph default
5390 , aslink, link-
5391 \emph on
5392 xxx
5393 \emph default
5394  - The Assemblers and Linkage Editors
5395 \end_layout
5396
5397 \begin_layout Standard
5398 This is retargettable assembler & linkage editor, it was developed by Alan
5399  Baldwin.
5400  John Hartman created the version for 8051, and I (Sandeep) have made some
5401  enhancements and bug fixes for it to work properly with SDCC.
5402 \end_layout
5403
5404 \begin_layout Subsection
5405 s51 - The Simulator
5406 \end_layout
5407
5408 \begin_layout Standard
5409 S51
5410 \begin_inset LatexCommand \index{s51}
5411
5412 \end_inset
5413
5414  is a free open source simulator developed by Daniel Drotos.
5415  The simulator is built as part of the build process.
5416  For more information visit Daniel's web site at: 
5417 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5418
5419 \end_inset
5420
5421 .
5422  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5423  XA51 family.
5424 \end_layout
5425
5426 \begin_layout Subsection
5427 sdcdb - Source Level Debugger
5428 \end_layout
5429
5430 \begin_layout Standard
5431 SDCDB
5432 \begin_inset LatexCommand \index{SDCDB (debugger)}
5433
5434 \end_inset
5435
5436  is the companion source level debugger.
5437  More about SDCDB in section 
5438 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5439
5440 \end_inset
5441
5442 .
5443  The current version of the debugger uses Daniel's Simulator S51
5444 \begin_inset LatexCommand \index{s51}
5445
5446 \end_inset
5447
5448 , but can be easily changed to use other simulators.
5449 \end_layout
5450
5451 \begin_layout Chapter
5452 Using SDCC
5453 \end_layout
5454
5455 \begin_layout Section
5456 Compiling
5457 \end_layout
5458
5459 \begin_layout Subsection
5460 Single Source File Projects
5461 \end_layout
5462
5463 \begin_layout Standard
5464 For single source file 8051 projects the process is very simple.
5465  Compile your programs with the following command 
5466 \family sans
5467 \series bold
5468 "sdcc sourcefile.c".
5469
5470 \family default
5471 \series default
5472  This will compile, assemble and link your source file.
5473  Output files are as follows:
5474 \end_layout
5475
5476 \begin_layout Itemize
5477 sourcefile.asm
5478 \begin_inset LatexCommand \index{<file>.asm}
5479
5480 \end_inset
5481
5482  - Assembler source
5483 \begin_inset LatexCommand \index{Assembler source}
5484
5485 \end_inset
5486
5487  file created by the compiler
5488 \end_layout
5489
5490 \begin_layout Itemize
5491 sourcefile.lst
5492 \begin_inset LatexCommand \index{<file>.lst}
5493
5494 \end_inset
5495
5496  - Assembler listing
5497 \begin_inset LatexCommand \index{Assembler listing}
5498
5499 \end_inset
5500
5501  file created by the Assembler
5502 \end_layout
5503
5504 \begin_layout Itemize
5505 sourcefile.rst
5506 \begin_inset LatexCommand \index{<file>.rst}
5507
5508 \end_inset
5509
5510  - Assembler listing
5511 \begin_inset LatexCommand \index{Assembler listing}
5512
5513 \end_inset
5514
5515  file updated with linkedit information, created by linkage editor
5516 \end_layout
5517
5518 \begin_layout Itemize
5519 sourcefile.sym
5520 \begin_inset LatexCommand \index{<file>.sym}
5521
5522 \end_inset
5523
5524  - symbol listing
5525 \begin_inset LatexCommand \index{Symbol listing}
5526
5527 \end_inset
5528
5529  for the sourcefile, created by the assembler
5530 \end_layout
5531
5532 \begin_layout Itemize
5533 sourcefile.rel
5534 \begin_inset LatexCommand \index{<file>.rel}
5535
5536 \end_inset
5537
5538  or sourcefile.o
5539 \begin_inset LatexCommand \index{<file>.o}
5540
5541 \end_inset
5542
5543  - Object file
5544 \begin_inset LatexCommand \index{Object file}
5545
5546 \end_inset
5547
5548  created by the assembler, input to Linkage editor
5549 \end_layout
5550
5551 \begin_layout Itemize
5552 sourcefile.map
5553 \begin_inset LatexCommand \index{<file>.map}
5554
5555 \end_inset
5556
5557  - The memory map
5558 \begin_inset LatexCommand \index{Memory map}
5559
5560 \end_inset
5561
5562  for the load module, created by the Linker
5563 \end_layout
5564
5565 \begin_layout Itemize
5566 sourcefile.mem
5567 \begin_inset LatexCommand \index{<file>.mem}
5568
5569 \end_inset
5570
5571  - A file with a summary of the memory usage
5572 \end_layout
5573
5574 \begin_layout Itemize
5575 sourcefile.ihx
5576 \begin_inset LatexCommand \index{<file>.ihx}
5577
5578 \end_inset
5579
5580  - The load module in Intel hex format
5581 \begin_inset LatexCommand \index{Intel hex format}
5582
5583 \end_inset
5584
5585  (you can select the Motorola S19 format
5586 \begin_inset LatexCommand \index{Motorola S19 format}
5587
5588 \end_inset
5589
5590  with -
5591 \begin_inset ERT
5592 status collapsed
5593
5594 \begin_layout Standard
5595
5596
5597 \backslash
5598 /
5599 \end_layout
5600
5601 \end_inset
5602
5603 -out-fmt-s19
5604 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5605
5606 \end_inset
5607
5608 .
5609  If you need another format you might want to use 
5610 \family sans
5611 \shape italic
5612 objdump
5613 \family default
5614 \shape default
5615
5616 \begin_inset LatexCommand \index{objdump (tool)}
5617
5618 \end_inset
5619
5620  or
5621 \family sans
5622 \shape italic
5623  srecord
5624 \family default
5625 \shape default
5626
5627 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5628
5629 \end_inset
5630
5631
5632 \begin_inset Note Note
5633 status collapsed
5634
5635 \begin_layout Standard
5636 hyperlinks needed
5637 \end_layout
5638
5639 \end_inset
5640
5641  - see also section 
5642 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5643
5644 \end_inset
5645
5646 ).
5647  Both formats are documented in the documentation of srecord
5648 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5649
5650 \end_inset
5651
5652
5653 \end_layout
5654
5655 \begin_layout Itemize
5656 sourcefile.adb
5657 \begin_inset LatexCommand \index{<file>.adb}
5658
5659 \end_inset
5660
5661  - An intermediate file containing debug information needed to create the
5662  .cdb file (with -
5663 \begin_inset ERT
5664 status collapsed
5665
5666 \begin_layout Standard
5667
5668
5669 \backslash
5670 /
5671 \end_layout
5672
5673 \end_inset
5674
5675 -debug
5676 \begin_inset LatexCommand \index{-\/-debug}
5677
5678 \end_inset
5679
5680
5681 \end_layout
5682
5683 \begin_layout Itemize
5684 sourcefile.cdb
5685 \begin_inset LatexCommand \index{<file>.cdb}
5686
5687 \end_inset
5688
5689  - An optional file (with -
5690 \begin_inset ERT
5691 status collapsed
5692
5693 \begin_layout Standard
5694
5695
5696 \backslash
5697 /
5698 \end_layout
5699
5700 \end_inset
5701
5702 -debug) containing debug information.
5703  The format is documented in cdbfileformat.pdf
5704 \end_layout
5705
5706 \begin_layout Itemize
5707 sourcefile.
5708  - (no extension)
5709 \begin_inset LatexCommand \index{<file> (no extension)}
5710
5711 \end_inset
5712
5713  An optional AOMF or AOMF51
5714 \begin_inset LatexCommand \index{AOMF, AOMF51}
5715
5716 \end_inset
5717
5718  
5719 \begin_inset LatexCommand \label{OMF file}
5720
5721 \end_inset
5722
5723 file containing debug information (generated with option -
5724 \begin_inset ERT
5725 status collapsed
5726
5727 \begin_layout Standard
5728
5729
5730 \backslash
5731 /
5732 \end_layout
5733
5734 \end_inset
5735
5736 -debug).
5737  The (Intel)
5738 \emph on
5739  a
5740 \emph default
5741 bsolute 
5742 \emph on
5743 o
5744 \emph default
5745 bject 
5746 \emph on
5747 m
5748 \emph default
5749 odule 
5750 \emph on
5751 f
5752 \emph default
5753 ormat is a subformat of the OMF51 format and is commonly used by third party
5754  tools (debuggers
5755 \begin_inset LatexCommand \index{Debugger}
5756
5757 \end_inset
5758
5759 , simulators, emulators).
5760 \end_layout
5761
5762 \begin_layout Itemize
5763 sourcefile.dump*
5764 \begin_inset LatexCommand \index{<file>.dump*}
5765
5766 \end_inset
5767
5768  - Dump file to debug the compiler it self (generated with option -
5769 \begin_inset ERT
5770 status collapsed
5771
5772 \begin_layout Standard
5773
5774
5775 \backslash
5776 /
5777 \end_layout
5778
5779 \end_inset
5780
5781 -dumpall) (see section 
5782 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5783
5784 \end_inset
5785
5786 \InsetSpace ~
5787  and section 
5788 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5789
5790 \end_inset
5791
5792 \InsetSpace ~
5793
5794 \begin_inset Quotes sld
5795 \end_inset
5796
5797 Anatomy of the compiler
5798 \begin_inset Quotes srd
5799 \end_inset
5800
5801 ).
5802 \end_layout
5803
5804 \begin_layout Subsection
5805 Postprocessing the Intel Hex
5806 \begin_inset LatexCommand \index{Intel hex format}
5807
5808 \end_inset
5809
5810  file
5811 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5812
5813 \end_inset
5814
5815
5816 \end_layout
5817
5818 \begin_layout Standard
5819 In most cases this won't be needed but the Intel Hex file
5820 \begin_inset LatexCommand \index{<file>.ihx}
5821
5822 \end_inset
5823
5824  which is generated by SDCC might include lines of varying length and the
5825  addresses within the file are not guaranteed to be strictly ascending.
5826  If your toolchain or a bootloader does not like this you can use the tool
5827  
5828 \family typewriter
5829 packihx
5830 \family default
5831
5832 \begin_inset LatexCommand \index{packihx (tool)}
5833
5834 \end_inset
5835
5836  which is part of the SDCC distribution: 
5837 \newline
5838
5839 \newline
5840
5841 \family sans
5842 \series bold
5843  packihx sourcefile.ihx >sourcefile.hex
5844 \family default
5845 \series default
5846
5847 \newline
5848
5849 \newline
5850 The separately available
5851 \emph on
5852  srecord
5853 \emph default
5854
5855 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5856
5857 \end_inset
5858
5859  package additionally allows to set undefined locations to a predefined
5860  value, to insert checksums
5861 \begin_inset LatexCommand \index{checksum}
5862
5863 \end_inset
5864
5865  of various flavours (crc, add, xor) and to perform other manipulations
5866  (convert, split, crop, offset, ...).
5867  
5868 \newline
5869
5870 \newline
5871
5872 \family sans
5873 \series bold
5874 srec_cat\InsetSpace ~
5875 \InsetSpace ~
5876 sourcefile.ihx -intel\InsetSpace ~
5877 \InsetSpace ~
5878 -o sourcefile.hex -intel
5879 \newline
5880
5881 \newline
5882
5883 \family default
5884 \series default
5885 An example for a more complex command line
5886 \begin_inset Foot
5887 status open
5888
5889 \begin_layout Standard
5890 the command backfills
5891 \begin_inset LatexCommand \index{backfill unused memory}
5892
5893 \end_inset
5894
5895  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5896  block is zero.
5897  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5898  will be interpreted as an 
5899 \family typewriter
5900 lcall
5901 \family default
5902  to address 
5903 \family typewriter
5904 0x1212
5905 \family default
5906  (where an emergency routine could sit).
5907 \end_layout
5908
5909 \end_inset
5910
5911  could look like:
5912 \newline
5913
5914 \newline
5915
5916 \family sans
5917 \series bold
5918 \size footnotesize
5919 srec_cat\InsetSpace ~
5920 sourcefile.ihx -intel\InsetSpace ~
5921 \InsetSpace ~
5922 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5923 -little-endian-checksum-nega
5924 tive 0xfffe 0x02 0x02\InsetSpace ~
5925 \InsetSpace ~
5926 -o sourcefile.hex -intel
5927 \size default
5928
5929 \newline
5930
5931 \newline
5932
5933 \family default
5934 \series default
5935 The srecord package is available at 
5936 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5937
5938 \end_inset
5939
5940  .
5941 \end_layout
5942
5943 \begin_layout Subsection
5944 Projects with Multiple Source Files
5945 \end_layout
5946
5947 \begin_layout Standard
5948 SDCC can compile only ONE file at a time.
5949  Let us for example assume that you have a project containing the following
5950  files:
5951 \newline
5952
5953 \newline
5954 foo1.c (contains some functions)
5955 \newline
5956 foo2.c (contains some more functions)
5957 \newline
5958 foomai
5959 n.c (contains more functions and the function main)
5960 \newline
5961
5962 \size footnotesize
5963
5964 \newline
5965
5966 \size default
5967 The first two files will need to be compiled separately with the commands:
5968 \size footnotesize
5969  
5970 \size default
5971
5972 \newline
5973
5974 \newline
5975
5976 \family sans
5977 \series bold
5978 sdcc\InsetSpace ~
5979 -c\InsetSpace ~
5980 foo1.c
5981 \family default
5982 \series default
5983 \size footnotesize
5984
5985 \newline
5986
5987 \family sans
5988 \series bold
5989 \size default
5990 sdcc\InsetSpace ~
5991 -c\InsetSpace ~
5992 foo2.c
5993 \family default
5994 \series default
5995
5996 \newline
5997
5998 \newline
5999 Then compile the source file containing the 
6000 \emph on
6001 main()
6002 \emph default
6003  function and link
6004 \begin_inset LatexCommand \index{Linker}
6005
6006 \end_inset
6007
6008  the files together with the following command: 
6009 \newline
6010
6011 \newline
6012
6013 \family sans
6014 \series bold
6015 sdcc\InsetSpace ~
6016 foomain.c\InsetSpace ~
6017 foo1.rel\InsetSpace ~
6018 foo2.rel
6019 \family default
6020 \series default
6021
6022 \begin_inset LatexCommand \index{<file>.rel}
6023
6024 \end_inset
6025
6026
6027 \newline
6028
6029 \newline
6030 Alternatively, 
6031 \emph on
6032 foomain.c 
6033 \emph default
6034 can be separately compiled as well: 
6035 \family sans
6036 \series bold
6037
6038 \newline
6039
6040 \newline
6041 sdcc\InsetSpace ~
6042 -c\InsetSpace ~
6043 foomain.c
6044 \newline
6045 sdcc foomain.rel foo1.rel foo2.rel
6046 \newline
6047
6048 \newline
6049
6050 \family default
6051 \series default
6052 The file containing the 
6053 \emph on
6054 main()
6055 \emph default
6056  function
6057 \emph on
6058  
6059 \emph default
6060 \noun on
6061 must
6062 \noun default
6063  be the 
6064 \noun on
6065 first
6066 \noun default
6067  file specified in the command line, since the linkage editor processes
6068  file in the order they are presented to it.
6069  The linker is invoked from SDCC using a script file with extension .lnk
6070 \begin_inset LatexCommand \index{<file>.lnk}
6071
6072 \end_inset
6073
6074 .
6075  You can view this file to troubleshoot linking problems such as those arising
6076  from missing libraries.
6077 \end_layout
6078
6079 \begin_layout Subsection
6080 Projects with Additional Libraries
6081 \begin_inset LatexCommand \index{Libraries}
6082
6083 \end_inset
6084
6085
6086 \end_layout
6087
6088 \begin_layout Standard
6089 Some reusable routines may be compiled into a library, see the documentation
6090  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6091  for how to create a 
6092 \emph on
6093 .lib
6094 \begin_inset LatexCommand \index{<file>.lib}
6095
6096 \end_inset
6097
6098
6099 \emph default
6100  library file.
6101  Libraries created in this manner can be included in the command line.
6102  Make sure you include the -L <library-path> option to tell the linker where
6103  to look for these files if they are not in the current directory.
6104  Here is an example, assuming you have the source file 
6105 \emph on
6106 foomain.c
6107 \emph default
6108  and a library
6109 \emph on
6110  foolib.lib
6111 \emph default
6112  in the directory 
6113 \emph on
6114 mylib
6115 \emph default
6116  (if that is not the same as your current project):
6117 \newline
6118
6119 \newline
6120
6121 \family sans
6122 \series bold
6123 sdcc foomain.c foolib.lib -L mylib
6124 \newline
6125
6126 \newline
6127
6128 \family default
6129 \series default
6130 Note here that
6131 \emph on
6132  mylib
6133 \emph default
6134  must be an absolute path name.
6135 \newline
6136
6137 \newline
6138 The most efficient way to use libraries is
6139  to keep separate modules in separate source files.
6140  The lib file now should name all the modules.rel
6141 \begin_inset LatexCommand \index{<file>.rel}
6142
6143 \end_inset
6144
6145  files.
6146  For an example see the standard library file 
6147 \emph on
6148 libsdcc.lib
6149 \emph default
6150  in the directory <installdir>/share/lib/small.
6151 \end_layout
6152
6153 \begin_layout Subsection
6154 Using sdcclib to Create and Manage Libraries
6155 \begin_inset LatexCommand \index{sdcclib}
6156
6157 \end_inset
6158
6159
6160 \end_layout
6161
6162 \begin_layout Standard
6163 Alternatively, instead of having a .rel file for each entry on the library
6164  file as described in the preceding section, sdcclib can be used to embed
6165  all the modules belonging to such library in the library file itself.
6166  This results in a larger library file, but it greatly reduces the number
6167  of disk files accessed by the linker.
6168   Additionally, the packed library file contains an index of all include
6169  modules and symbols that significantly speeds up the linking process.
6170  To display a list of options supported by sdcclib type:
6171 \newline
6172
6173 \end_layout
6174
6175 \begin_layout Standard
6176
6177 \family sans
6178 \series bold
6179 sdcclib -?
6180 \begin_inset LatexCommand \index{sdcclib}
6181
6182 \end_inset
6183
6184
6185 \newline
6186
6187 \newline
6188
6189 \family default
6190 \series default
6191 To create a new library file, start by compiling all the required modules.
6192  For example:
6193 \newline
6194
6195 \end_layout
6196
6197 \begin_layout Standard
6198
6199 \family sans
6200 \series bold
6201 sdcc -c _divsint.c
6202 \end_layout
6203
6204 \begin_layout Standard
6205
6206 \family sans
6207 \series bold
6208 sdcc -c _divuint.c
6209 \end_layout
6210
6211 \begin_layout Standard
6212
6213 \family sans
6214 \series bold
6215 sdcc -c _modsint.c
6216 \end_layout
6217
6218 \begin_layout Standard
6219
6220 \family sans
6221 \series bold
6222 sdcc -c _moduint.c
6223 \end_layout
6224
6225 \begin_layout Standard
6226
6227 \family sans
6228 \series bold
6229 sdcc -c _mulint.c
6230 \newline
6231
6232 \end_layout
6233
6234 \begin_layout Standard
6235 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6236  and _mulint.rel.
6237  The next step is to add the .rel files to the library file:
6238 \newline
6239
6240 \end_layout
6241
6242 \begin_layout Standard
6243
6244 \family sans
6245 \series bold
6246 sdcclib libint.lib _divsint.rel
6247 \family default
6248
6249 \begin_inset LatexCommand \index{sdcclib}
6250
6251 \end_inset
6252
6253
6254 \end_layout
6255
6256 \begin_layout Standard
6257
6258 \family sans
6259 \series bold
6260 sdcclib libint.lib _divuint.rel
6261 \end_layout
6262
6263 \begin_layout Standard
6264
6265 \family sans
6266 \series bold
6267 sdcclib libint.lib _modsint.rel
6268 \end_layout
6269
6270 \begin_layout Standard
6271
6272 \family sans
6273 \series bold
6274 sdcclib libint.lib _moduint.rel
6275 \end_layout
6276
6277 \begin_layout Standard
6278
6279 \family sans
6280 \series bold
6281 sdcclib libint.lib _mulint.rel
6282 \series default
6283
6284 \newline
6285
6286 \end_layout
6287
6288 \begin_layout Standard
6289 If the file already exists in the library, it will be replaced.
6290  To see what modules and symbols are included in the library, options -s
6291  and -m are available.
6292  For example:
6293 \newline
6294
6295 \newline
6296
6297 \family sans
6298 \series bold
6299 sdcclib -s libint.lib
6300 \family default
6301
6302 \begin_inset LatexCommand \index{sdcclib}
6303
6304 \end_inset
6305
6306
6307 \newline
6308
6309 \family typewriter
6310 \series default
6311 _divsint.rel:
6312 \end_layout
6313
6314 \begin_layout Standard
6315
6316 \family typewriter
6317 __divsint_a_1_1
6318 \end_layout
6319
6320 \begin_layout Standard
6321
6322 \family typewriter
6323 __divsint_PARM_2
6324 \end_layout
6325
6326 \begin_layout Standard
6327
6328 \family typewriter
6329 __divsint
6330 \newline
6331 _divuint.rel:
6332 \end_layout
6333
6334 \begin_layout Standard
6335
6336 \family typewriter
6337 __divuint_a_1_1
6338 \end_layout
6339
6340 \begin_layout Standard
6341
6342 \family typewriter
6343 __divuint_PARM_2
6344 \end_layout
6345
6346 \begin_layout Standard
6347
6348 \family typewriter
6349 __divuint_reste_1_1
6350 \end_layout
6351
6352 \begin_layout Standard
6353
6354 \family typewriter
6355 __divuint_count_1_1
6356 \end_layout
6357
6358 \begin_layout Standard
6359
6360 \family typewriter
6361 __divuint
6362 \newline
6363 _modsint.rel:
6364 \end_layout
6365
6366 \begin_layout Standard
6367
6368 \family typewriter
6369 __modsint_a_1_1
6370 \end_layout
6371
6372 \begin_layout Standard
6373
6374 \family typewriter
6375 __modsint_PARM_2
6376 \end_layout
6377
6378 \begin_layout Standard
6379
6380 \family typewriter
6381 __modsint
6382 \newline
6383 _moduint.rel:
6384 \end_layout
6385
6386 \begin_layout Standard
6387
6388 \family typewriter
6389 __moduint_a_1_1
6390 \end_layout
6391
6392 \begin_layout Standard
6393
6394 \family typewriter
6395 __moduint_PARM_2
6396 \end_layout
6397
6398 \begin_layout Standard
6399
6400 \family typewriter
6401 __moduint_count_1_1
6402 \end_layout
6403
6404 \begin_layout Standard
6405
6406 \family typewriter
6407 __moduint
6408 \newline
6409 _mulint.rel:
6410 \end_layout
6411
6412 \begin_layout Standard
6413
6414 \family typewriter
6415 __mulint_PARM_2
6416 \end_layout
6417
6418 \begin_layout Standard
6419
6420 \family typewriter
6421 __mulint
6422 \family default
6423 \series bold
6424
6425 \newline
6426
6427 \end_layout
6428
6429 \begin_layout Standard
6430 If the source files are compiled using -
6431 \begin_inset ERT
6432 status collapsed
6433
6434 \begin_layout Standard
6435
6436
6437 \backslash
6438 /
6439 \end_layout
6440
6441 \end_inset
6442
6443 -debug
6444 \begin_inset LatexCommand \index{-\/-debug}
6445
6446 \end_inset
6447
6448 , the corresponding debug information file .adb will be include in the library
6449  file as well.
6450  The library files created with sdcclib are plain text files, so they can
6451  be viewed with a text editor.
6452  It is not recomended to modify a library file created with sdcclib using
6453  a text editor, as there are file indexes numbers located accross the file
6454  used by the linker to quickly locate the required module to link.
6455  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6456  it can be safely deleted, since all the information required for linking
6457  is embedded in the library file itself.
6458  Library files created using sdcclib are used as described in the preceding
6459  sections.
6460 \begin_inset VSpace bigskip
6461 \end_inset
6462
6463
6464 \end_layout
6465
6466 \begin_layout Section
6467 Command Line Options
6468 \begin_inset LatexCommand \index{Command Line Options}
6469
6470 \end_inset
6471
6472
6473 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6474
6475 \end_inset
6476
6477
6478 \end_layout
6479
6480 \begin_layout Subsection
6481 Processor Selection Options
6482 \begin_inset LatexCommand \index{Options processor selection}
6483
6484 \end_inset
6485
6486
6487 \begin_inset LatexCommand \index{Processor selection options}
6488
6489 \end_inset
6490
6491
6492 \end_layout
6493
6494 \begin_layout List
6495 \labelwidthstring 00.00.0000
6496
6497 \series bold
6498 -mmcs51
6499 \begin_inset LatexCommand \index{-mmcs51}
6500
6501 \end_inset
6502
6503
6504 \series default
6505  Generate code for the Intel MCS51
6506 \begin_inset LatexCommand \index{MCS51}
6507
6508 \end_inset
6509
6510  family of processors.
6511  This is the default processor target.
6512 \end_layout
6513
6514 \begin_layout List
6515 \labelwidthstring 00.00.0000
6516
6517 \series bold
6518 -mds390
6519 \begin_inset LatexCommand \index{-mds390}
6520
6521 \end_inset
6522
6523
6524 \series default
6525  Generate code for the Dallas DS80C390
6526 \begin_inset LatexCommand \index{DS80C390}
6527
6528 \end_inset
6529
6530  processor.
6531 \end_layout
6532
6533 \begin_layout List
6534 \labelwidthstring 00.00.0000
6535
6536 \series bold
6537 -mds400
6538 \begin_inset LatexCommand \index{-mds400}
6539
6540 \end_inset
6541
6542
6543 \series default
6544  Generate code for the Dallas DS80C400
6545 \begin_inset LatexCommand \index{DS80C400}
6546
6547 \end_inset
6548
6549  processor.
6550 \end_layout
6551
6552 \begin_layout List
6553 \labelwidthstring 00.00.0000
6554
6555 \series bold
6556 -mhc08
6557 \begin_inset LatexCommand \index{-mhc08}
6558
6559 \end_inset
6560
6561
6562 \series default
6563  Generate code for the Freescale/Motorola HC08
6564 \begin_inset LatexCommand \index{HC08}
6565
6566 \end_inset
6567
6568  family of processors.
6569 \end_layout
6570
6571 \begin_layout List
6572 \labelwidthstring 00.00.0000
6573
6574 \series bold
6575 -mz80
6576 \begin_inset LatexCommand \index{-mz80}
6577
6578 \end_inset
6579
6580
6581 \series default
6582  Generate code for the Zilog Z80
6583 \begin_inset LatexCommand \index{Z80}
6584
6585 \end_inset
6586
6587  family of processors.
6588 \end_layout
6589
6590 \begin_layout List
6591 \labelwidthstring 00.00.0000
6592
6593 \series bold
6594 -mgbz80
6595 \begin_inset LatexCommand \index{-mgbz80}
6596
6597 \end_inset
6598
6599
6600 \series default
6601  Generate code for the GameBoy Z80
6602 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6603
6604 \end_inset
6605
6606  processor (Not actively maintained).
6607 \end_layout
6608
6609 \begin_layout List
6610 \labelwidthstring 00.00.0000
6611
6612 \series bold
6613 -mavr
6614 \begin_inset LatexCommand \index{-mavr}
6615
6616 \end_inset
6617
6618
6619 \series default
6620  Generate code for the Atmel AVR
6621 \begin_inset LatexCommand \index{AVR}
6622
6623 \end_inset
6624
6625  processor (Not maintained, not complete).
6626  AVR users should probably have a look at winavr 
6627 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6628
6629 \end_inset
6630
6631  or 
6632 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6633
6634 \end_inset
6635
6636 , which is based on AVR-port of the gcc compiler.
6637 \end_layout
6638
6639 \begin_layout Standard
6640 \begin_inset Note Note
6641 status collapsed
6642
6643 \begin_layout Standard
6644 I think it is fair to direct users there for now.
6645  Open source is also about avoiding unnecessary work .
6646  But I didn't find the 'official' link.
6647 \end_layout
6648
6649 \end_inset
6650
6651
6652 \end_layout
6653
6654 \begin_layout List
6655 \labelwidthstring 00.00.0000
6656
6657 \series bold
6658 -mpic14
6659 \begin_inset LatexCommand \index{-mpic14}
6660
6661 \end_inset
6662
6663
6664 \series default
6665  Generate code for the Microchip PIC 14
6666 \begin_inset LatexCommand \index{PIC14}
6667
6668 \end_inset
6669
6670 -bit processors (p16f84 and variants.
6671  In development, not complete).
6672 \end_layout
6673
6674 \begin_layout Standard
6675 \begin_inset Note Note
6676 status collapsed
6677
6678 \begin_layout Standard
6679 p16f627 p16f628 p16f84 p16f873 p16f877?
6680 \end_layout
6681
6682 \end_inset
6683
6684
6685 \end_layout
6686
6687 \begin_layout List
6688 \labelwidthstring 00.00.0000
6689
6690 \series bold
6691 -mpic16
6692 \begin_inset LatexCommand \index{-mpic16}
6693
6694 \end_inset
6695
6696
6697 \series default
6698  Generate code for the Microchip PIC 16
6699 \begin_inset LatexCommand \index{PIC16}
6700
6701 \end_inset
6702
6703 -bit processors (p18f452 and variants.
6704  In development, not complete).
6705 \end_layout
6706
6707 \begin_layout List
6708 \labelwidthstring 00.00.0000
6709
6710 \series bold
6711 -mtlcs900h
6712 \series default
6713  Generate code for the Toshiba TLCS-900H
6714 \begin_inset LatexCommand \index{TLCS-900H}
6715
6716 \end_inset
6717
6718  processor (Not maintained, not complete).
6719 \end_layout
6720
6721 \begin_layout List
6722 \labelwidthstring 00.00.0000
6723
6724 \series bold
6725 -mxa51
6726 \begin_inset LatexCommand \index{-mxa51}
6727
6728 \end_inset
6729
6730
6731 \series default
6732  Generate code for the Phillips XA51
6733 \begin_inset LatexCommand \index{XA51}
6734
6735 \end_inset
6736
6737  processor (Not maintained, not complete).
6738 \end_layout
6739
6740 \begin_layout Standard
6741 \begin_inset VSpace bigskip
6742 \end_inset
6743
6744
6745 \end_layout
6746
6747 \begin_layout Subsection
6748 Preprocessor Options
6749 \begin_inset LatexCommand \index{Options preprocessor}
6750
6751 \end_inset
6752
6753
6754 \begin_inset LatexCommand \index{Preprocessor options}
6755
6756 \end_inset
6757
6758
6759 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6760
6761 \end_inset
6762
6763
6764 \end_layout
6765
6766 \begin_layout List
6767 \labelwidthstring 00.00.0000
6768
6769 \series bold
6770 -I<path>
6771 \begin_inset LatexCommand \index{-I<path>}
6772
6773 \end_inset
6774
6775
6776 \series default
6777  The additional location where the preprocessor will look for <..h> or 
6778 \begin_inset Quotes eld
6779 \end_inset
6780
6781 ..h
6782 \begin_inset Quotes erd
6783 \end_inset
6784
6785  files.
6786 \end_layout
6787
6788 \begin_layout List
6789 \labelwidthstring 00.00.0000
6790
6791 \series bold
6792 -D<macro[=value]>
6793 \begin_inset LatexCommand \index{-D<macro[=value]>}
6794
6795 \end_inset
6796
6797
6798 \series default
6799  Command line definition of macros.
6800  Passed to the preprocessor.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -M
6808 \begin_inset LatexCommand \index{-M}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Tell the preprocessor to output a rule suitable for make describing the
6815  dependencies of each object file.
6816  For each source file, the preprocessor outputs one make-rule whose target
6817  is the object file name for that source file and whose dependencies are
6818  all the files `#include'd in it.
6819  This rule may be a single line or may be continued with `
6820 \backslash
6821 '-newline if it is long.
6822  The list of rules is printed on standard output instead of the preprocessed
6823  C program.
6824  `-M' implies `-E
6825 \begin_inset LatexCommand \index{-E}
6826
6827 \end_inset
6828
6829 '.
6830 \end_layout
6831
6832 \begin_layout List
6833 \labelwidthstring 00.00.0000
6834
6835 \series bold
6836 -C
6837 \begin_inset LatexCommand \index{-C}
6838
6839 \end_inset
6840
6841
6842 \series default
6843  Tell the preprocessor not to discard comments.
6844  Used with the `-E' option.
6845 \end_layout
6846
6847 \begin_layout List
6848 \labelwidthstring 00.00.0000
6849
6850 \series bold
6851 -MM
6852 \begin_inset LatexCommand \index{-MM}
6853
6854 \end_inset
6855
6856
6857 \size large
6858 \bar under
6859  
6860 \series default
6861 \size default
6862 \bar default
6863 Like `-M' but the output mentions only the user header files included with
6864  `#include 
6865 \begin_inset Quotes eld
6866 \end_inset
6867
6868 file"'.
6869  System header files included with `#include <file>' are omitted.
6870 \end_layout
6871
6872 \begin_layout List
6873 \labelwidthstring 00.00.0000
6874
6875 \series bold
6876 -Aquestion(answer)
6877 \begin_inset LatexCommand \index{-Aquestion(answer)}
6878
6879 \end_inset
6880
6881
6882 \series default
6883  Assert the answer answer for question, in case it is tested with a preprocessor
6884  conditional such as `#if #question(answer)'.
6885  `-A-' disables the standard assertions that normally describe the target
6886  machine.
6887 \end_layout
6888
6889 \begin_layout List
6890 \labelwidthstring 00.00.0000
6891
6892 \series bold
6893 -Umacro
6894 \begin_inset LatexCommand \index{-Umacro}
6895
6896 \end_inset
6897
6898
6899 \series default
6900  Undefine macro macro.
6901  `-U' options are evaluated after all `-D' options, but before any `-include'
6902  and `-imacros' options.
6903 \end_layout
6904
6905 \begin_layout List
6906 \labelwidthstring 00.00.0000
6907
6908 \series bold
6909 -dM
6910 \begin_inset LatexCommand \index{-dM}
6911
6912 \end_inset
6913
6914
6915 \series default
6916  Tell the preprocessor to output only a list of the macro definitions that
6917  are in effect at the end of preprocessing.
6918  Used with the `-E' option.
6919 \end_layout
6920
6921 \begin_layout List
6922 \labelwidthstring 00.00.0000
6923
6924 \series bold
6925 -dD
6926 \begin_inset LatexCommand \index{-dD}
6927
6928 \end_inset
6929
6930
6931 \series default
6932  Tell the preprocessor to pass all macro definitions into the output, in
6933  their proper sequence in the rest of the output.
6934 \end_layout
6935
6936 \begin_layout List
6937 \labelwidthstring 00.00.0000
6938
6939 \series bold
6940 -dN
6941 \begin_inset LatexCommand \index{-dN}
6942
6943 \end_inset
6944
6945
6946 \size large
6947 \bar under
6948  
6949 \series default
6950 \size default
6951 \bar default
6952 Like `-dD' except that the macro arguments and contents are omitted.
6953  Only `#define name' is included in the output.
6954 \end_layout
6955
6956 \begin_layout List
6957 \labelwidthstring 00.00.0000
6958
6959 \series bold
6960 -pedantic-parse-number
6961 \begin_inset LatexCommand \index{pedantic}
6962
6963 \end_inset
6964
6965
6966 \begin_inset LatexCommand \index{-pedantic-parse-number}
6967
6968 \end_inset
6969
6970
6971 \size large
6972 \bar under
6973
6974 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6975
6976 \end_inset
6977
6978  
6979 \series default
6980 \size default
6981 \bar default
6982 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6983  and the macro LO_B(3) gets expanded.
6984  See also #pragma pedantic_parse_number 
6985 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6986
6987 \end_inset
6988
6989  in section
6990 \begin_inset LatexCommand \ref{sec:Pragmas}
6991
6992 \end_inset
6993
6994  
6995 \emph on
6996 Note: this functionality is not in conformance with C99 standard!
6997 \end_layout
6998
6999 \begin_layout List
7000 \labelwidthstring 00.00.0000
7001
7002 \series bold
7003 -Wp\InsetSpace ~
7004 preprocessorOption[,preprocessorOption]
7005 \series default
7006
7007 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7008
7009 \end_inset
7010
7011 ...
7012  Pass the preprocessorOption to the preprocessor 
7013 \family typewriter
7014 sdcpp
7015 \family default
7016
7017 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7018
7019 \end_inset
7020
7021 .
7022  SDCC uses an adapted version of the preprocessor 
7023 \emph on
7024 cpp
7025 \emph default
7026  of the GNU Compiler Collection
7027 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7028
7029 \end_inset
7030
7031  (
7032 \emph on
7033 gcc
7034 \emph default
7035  
7036 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7037
7038 \end_inset
7039
7040 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7041 4.1.1\InsetSpace ~
7042 CPP\InsetSpace ~
7043 Manual
7044  at 
7045 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7046
7047 \end_inset
7048
7049 .
7050 \end_layout
7051
7052 \begin_layout Standard
7053 \begin_inset VSpace bigskip
7054 \end_inset
7055
7056
7057 \end_layout
7058
7059 \begin_layout Subsection
7060 Linker Options
7061 \begin_inset LatexCommand \index{Options linker}
7062
7063 \end_inset
7064
7065
7066 \begin_inset LatexCommand \index{Linker options}
7067
7068 \end_inset
7069
7070
7071 \end_layout
7072
7073 \begin_layout List
7074 \labelwidthstring 00.00.0000
7075
7076 \series bold
7077 -L\InsetSpace ~
7078 -
7079 \series default
7080
7081 \begin_inset ERT
7082 status collapsed
7083
7084 \begin_layout Standard
7085
7086
7087 \backslash
7088 /
7089 \end_layout
7090
7091 \end_inset
7092
7093
7094 \series bold
7095 -lib-path
7096 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7097
7098 \end_inset
7099
7100
7101 \begin_inset LatexCommand \index{-L -\/-lib-path}
7102
7103 \end_inset
7104
7105
7106 \series default
7107 \InsetSpace ~
7108 <absolute path to additional libraries> This option is passed to the linkage
7109  editor's additional libraries
7110 \begin_inset LatexCommand \index{Libraries}
7111
7112 \end_inset
7113
7114  search path.
7115  The path name must be absolute.
7116  Additional library files may be specified in the command line.
7117  See section Compiling programs for more details.
7118 \end_layout
7119
7120 \begin_layout List
7121 \labelwidthstring 00.00.0000
7122
7123 \series bold
7124 -
7125 \begin_inset ERT
7126 status collapsed
7127
7128 \begin_layout Standard
7129
7130
7131 \backslash
7132 /
7133 \end_layout
7134
7135 \end_inset
7136
7137 -xram-loc
7138 \series default
7139
7140 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7141
7142 \end_inset
7143
7144 \InsetSpace ~
7145 <Value> The start location of the external ram
7146 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7147
7148 \end_inset
7149
7150 , default value is 0.
7151  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7152 \begin_inset ERT
7153 status collapsed
7154
7155 \begin_layout Standard
7156
7157
7158 \backslash
7159 /
7160 \end_layout
7161
7162 \end_inset
7163
7164 -xram-loc 0x8000 or -
7165 \begin_inset ERT
7166 status collapsed
7167
7168 \begin_layout Standard
7169
7170
7171 \backslash
7172 /
7173 \end_layout
7174
7175 \end_inset
7176
7177 -xram-loc 32768.
7178 \end_layout
7179
7180 \begin_layout List
7181 \labelwidthstring 00.00.0000
7182
7183 \series bold
7184 -
7185 \begin_inset ERT
7186 status collapsed
7187
7188 \begin_layout Standard
7189
7190
7191 \backslash
7192 /
7193 \end_layout
7194
7195 \end_inset
7196
7197 -code-loc
7198 \series default
7199
7200 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7201
7202 \end_inset
7203
7204 \InsetSpace ~
7205 <Value> The start location of the code
7206 \begin_inset LatexCommand \index{code}
7207
7208 \end_inset
7209
7210  segment, default value 0.
7211  Note when this option is used the interrupt vector table
7212 \begin_inset LatexCommand \index{interrupt vector table}
7213
7214 \end_inset
7215
7216  is also relocated to the given address.
7217  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7218 \begin_inset ERT
7219 status collapsed
7220
7221 \begin_layout Standard
7222
7223
7224 \backslash
7225 /
7226 \end_layout
7227
7228 \end_inset
7229
7230 -code-loc 0x8000 or -
7231 \begin_inset ERT
7232 status collapsed
7233
7234 \begin_layout Standard
7235
7236
7237 \backslash
7238 /
7239 \end_layout
7240
7241 \end_inset
7242
7243 -code-loc 32768.
7244 \end_layout
7245
7246 \begin_layout List
7247 \labelwidthstring 00.00.0000
7248
7249 \series bold
7250 -
7251 \begin_inset ERT
7252 status collapsed
7253
7254 \begin_layout Standard
7255
7256
7257 \backslash
7258 /
7259 \end_layout
7260
7261 \end_inset
7262
7263 -stack-loc
7264 \series default
7265
7266 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7267
7268 \end_inset
7269
7270 \InsetSpace ~
7271 <Value> By default the stack
7272 \begin_inset LatexCommand \index{stack}
7273
7274 \end_inset
7275
7276  is placed after the data segment.
7277  Using this option the stack can be placed anywhere in the internal memory
7278  space of the 8051.
7279  The value entered can be in Hexadecimal or Decimal format, e.g.
7280  -
7281 \begin_inset ERT
7282 status collapsed
7283
7284 \begin_layout Standard
7285
7286
7287 \backslash
7288 /
7289 \end_layout
7290
7291 \end_inset
7292
7293 -stack-loc 0x20 or -
7294 \begin_inset ERT
7295 status collapsed
7296
7297 \begin_layout Standard
7298
7299
7300 \backslash
7301 /
7302 \end_layout
7303
7304 \end_inset
7305
7306 -stack-loc 32.
7307  Since the sp register is incremented before a push or call, the initial
7308  sp will be set to one byte prior the provided value.
7309  The provided value should not overlap any other memory areas such as used
7310  register banks or the data segment and with enough space for the current
7311  application.
7312  The 
7313 \series bold
7314 -
7315 \begin_inset ERT
7316 status collapsed
7317
7318 \begin_layout Standard
7319
7320
7321 \backslash
7322 /
7323 \end_layout
7324
7325 \end_inset
7326
7327 -pack-iram
7328 \series default
7329 \InsetSpace ~
7330
7331 \begin_inset LatexCommand \index{-\/-pack-iram}
7332
7333 \end_inset
7334
7335  option (which is now a default setting) will override this setting, so
7336  you should also specify the 
7337 \series bold
7338 -
7339 \begin_inset ERT
7340 status collapsed
7341
7342 \begin_layout Standard
7343
7344
7345 \backslash
7346 /
7347 \end_layout
7348
7349 \end_inset
7350
7351 -no-pack-iram
7352 \series default
7353 \InsetSpace ~
7354
7355 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7356
7357 \end_inset
7358
7359  option if you need to manually place the stack.
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -
7367 \begin_inset ERT
7368 status collapsed
7369
7370 \begin_layout Standard
7371
7372
7373 \backslash
7374 /
7375 \end_layout
7376
7377 \end_inset
7378
7379 -xstack-loc
7380 \series default
7381
7382 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7383
7384 \end_inset
7385
7386 \InsetSpace ~
7387 <Value> By default the external stack
7388 \begin_inset LatexCommand \index{xstack}
7389
7390 \end_inset
7391
7392  is placed after the pdata
7393 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7394
7395 \end_inset
7396
7397  segment.
7398  Using this option the xstack can be placed anywhere in the external memory
7399  space of the 8051.
7400  The value entered can be in Hexadecimal or Decimal format, e.g.
7401  -
7402 \begin_inset ERT
7403 status collapsed
7404
7405 \begin_layout Standard
7406
7407
7408 \backslash
7409 /
7410 \end_layout
7411
7412 \end_inset
7413
7414 -xstack-loc 0x8000 or -
7415 \begin_inset ERT
7416 status collapsed
7417
7418 \begin_layout Standard
7419
7420
7421 \backslash
7422 /
7423 \end_layout
7424
7425 \end_inset
7426
7427 -stack-loc 32768.
7428  The provided value should not overlap any other memory areas such as the
7429  pdata or xdata segment and with enough space for the current application.
7430 \end_layout
7431
7432 \begin_layout List
7433 \labelwidthstring 00.00.0000
7434
7435 \series bold
7436 -
7437 \begin_inset ERT
7438 status collapsed
7439
7440 \begin_layout Standard
7441
7442
7443 \backslash
7444 /
7445 \end_layout
7446
7447 \end_inset
7448
7449 -data-loc
7450 \series default
7451
7452 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7453
7454 \end_inset
7455
7456 \InsetSpace ~
7457 <Value> The start location of the internal ram data
7458 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7459
7460 \end_inset
7461
7462  segment.
7463  The value entered can be in Hexadecimal or Decimal format, eg.
7464  -
7465 \begin_inset ERT
7466 status collapsed
7467
7468 \begin_layout Standard
7469
7470
7471 \backslash
7472 /
7473 \end_layout
7474
7475 \end_inset
7476
7477 -data-loc 0x20 or -
7478 \begin_inset ERT
7479 status collapsed
7480
7481 \begin_layout Standard
7482
7483
7484 \backslash
7485 /
7486 \end_layout
7487
7488 \end_inset
7489
7490 -data-loc 32.
7491  (By default, the start location of the internal ram data segment  is set
7492  as low as possible in memory, taking into account the used register banks
7493  and the bit segment at address 0x20.
7494  For example if register banks 0 and 1 are used without bit variables, the
7495  data segment will be set, if -
7496 \begin_inset ERT
7497 status collapsed
7498
7499 \begin_layout Standard
7500
7501
7502 \backslash
7503 /
7504 \end_layout
7505
7506 \end_inset
7507
7508 -data-loc is not used, to location 0x10.)
7509 \end_layout
7510
7511 \begin_layout List
7512 \labelwidthstring 00.00.0000
7513
7514 \series bold
7515 -
7516 \begin_inset ERT
7517 status collapsed
7518
7519 \begin_layout Standard
7520
7521
7522 \backslash
7523 /
7524 \end_layout
7525
7526 \end_inset
7527
7528 -idata-loc
7529 \series default
7530
7531 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7532
7533 \end_inset
7534
7535 \InsetSpace ~
7536 <Value> The start location of the indirectly addressable internal ram
7537 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7538
7539 \end_inset
7540
7541  of the 8051, default value is 0x80.
7542  The value entered can be in Hexadecimal or Decimal format, eg.
7543  -
7544 \begin_inset ERT
7545 status collapsed
7546
7547 \begin_layout Standard
7548
7549
7550 \backslash
7551 /
7552 \end_layout
7553
7554 \end_inset
7555
7556 -idata-loc 0x88 or -
7557 \begin_inset ERT
7558 status collapsed
7559
7560 \begin_layout Standard
7561
7562
7563 \backslash
7564 /
7565 \end_layout
7566
7567 \end_inset
7568
7569 -idata-loc 136.
7570 \end_layout
7571
7572 \begin_layout List
7573 \labelwidthstring 00.00.0000
7574
7575 \series bold
7576 -
7577 \begin_inset ERT
7578 status collapsed
7579
7580 \begin_layout Standard
7581
7582
7583 \backslash
7584 /
7585 \end_layout
7586
7587 \end_inset
7588
7589 -bit-loc
7590 \series default
7591 \InsetSpace ~
7592 <Value> The start location of the bit
7593 \begin_inset LatexCommand \index{bit}
7594
7595 \end_inset
7596
7597  addressable internal ram of the 8051.
7598  This is 
7599 \emph on
7600 not
7601 \emph default
7602  implemented yet.
7603  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7604 -bBSEG=<Value>.
7605 \end_layout
7606
7607 \begin_layout List
7608 \labelwidthstring 00.00.0000
7609
7610 \series bold
7611 -
7612 \begin_inset ERT
7613 status collapsed
7614
7615 \begin_layout Standard
7616
7617
7618 \backslash
7619 /
7620 \end_layout
7621
7622 \end_inset
7623
7624 -out-fmt-ihx
7625 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7626
7627 \end_inset
7628
7629
7630 \bar under
7631  
7632 \series default
7633 \bar default
7634 The linker output (final object code) is in Intel Hex format.
7635 \begin_inset LatexCommand \index{Intel hex format}
7636
7637 \end_inset
7638
7639  This is the default option.
7640  The format itself is documented in the documentation of srecord
7641 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7642
7643 \end_inset
7644
7645 .
7646 \end_layout
7647
7648 \begin_layout List
7649 \labelwidthstring 00.00.0000
7650
7651 \series bold
7652 -
7653 \begin_inset ERT
7654 status collapsed
7655
7656 \begin_layout Standard
7657
7658
7659 \backslash
7660 /
7661 \end_layout
7662
7663 \end_inset
7664
7665 -out-fmt-s19
7666 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7667
7668 \end_inset
7669
7670
7671 \bar under
7672  
7673 \series default
7674 \bar default
7675 The linker output (final object code) is in Motorola S19 format
7676 \begin_inset LatexCommand \index{Motorola S19 format}
7677
7678 \end_inset
7679
7680 .
7681  The format itself is documented in the documentation of srecord.
7682 \end_layout
7683
7684 \begin_layout List
7685 \labelwidthstring 00.00.0000
7686
7687 \series bold
7688 -
7689 \begin_inset ERT
7690 status collapsed
7691
7692 \begin_layout Standard
7693
7694
7695 \backslash
7696 /
7697 \end_layout
7698
7699 \end_inset
7700
7701 -out-fmt-elf
7702 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7703
7704 \end_inset
7705
7706
7707 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7708
7709 \end_inset
7710
7711
7712 \bar under
7713  
7714 \series default
7715 \bar default
7716 The linker output (final object code) is in ELF format
7717 \begin_inset LatexCommand \index{ELF format}
7718
7719 \end_inset
7720
7721 .
7722  (Currently only supported for the HC08
7723 \begin_inset LatexCommand \index{HC08}
7724
7725 \end_inset
7726
7727  processors)
7728 \end_layout
7729
7730 \begin_layout List
7731 \labelwidthstring 00.00.0000
7732
7733 \series bold
7734 -Wl\InsetSpace ~
7735 linkOption[,linkOption]
7736 \series default
7737
7738 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7739
7740 \end_inset
7741
7742 ...
7743  Pass the linkOption to the linker.
7744  If a bootloader is used an option like 
7745 \begin_inset Quotes sld
7746 \end_inset
7747
7748 -Wl\InsetSpace ~
7749 -bCSEG=0x1000
7750 \begin_inset Quotes srd
7751 \end_inset
7752
7753  would be typical to set the start of the code segment.
7754  See also #pragma constseg and #pragma codeseg in section 
7755 \begin_inset LatexCommand \ref{sec:Pragmas}
7756
7757 \end_inset
7758
7759  .
7760  File sdcc/as/doc/asxhtm.html has more on linker options.
7761 \end_layout
7762
7763 \begin_layout Standard
7764 \begin_inset VSpace bigskip
7765 \end_inset
7766
7767
7768 \end_layout
7769
7770 \begin_layout Subsection
7771 MCS51 Options
7772 \begin_inset LatexCommand \index{Options MCS51}
7773
7774 \end_inset
7775
7776
7777 \begin_inset LatexCommand \index{MCS51 options}
7778
7779 \end_inset
7780
7781
7782 \end_layout
7783
7784 \begin_layout List
7785 \labelwidthstring 00.00.0000
7786
7787 \series bold
7788 -
7789 \begin_inset ERT
7790 status collapsed
7791
7792 \begin_layout Standard
7793
7794
7795 \backslash
7796 /
7797 \end_layout
7798
7799 \end_inset
7800
7801 -model-small
7802 \begin_inset LatexCommand \index{-\/-model-small}
7803
7804 \end_inset
7805
7806
7807 \series default
7808 \size large
7809 \emph on
7810  
7811 \size default
7812 \emph default
7813 Generate code for Small Model programs, see section Memory Models for more
7814  details.
7815  This is the default model.
7816 \end_layout
7817
7818 \begin_layout List
7819 \labelwidthstring 00.00.0000
7820
7821 \series bold
7822 -
7823 \begin_inset ERT
7824 status collapsed
7825
7826 \begin_layout Standard
7827
7828
7829 \backslash
7830 /
7831 \end_layout
7832
7833 \end_inset
7834
7835 -model-medium
7836 \begin_inset LatexCommand \index{-\/-model-medium}
7837
7838 \end_inset
7839
7840
7841 \series default
7842  Generate code for Medium model programs, see section Memory Models for
7843  more details.
7844  If this option is used all source files in the project have to be compiled
7845  with this option.
7846  It must also be used when invoking the linker.
7847 \end_layout
7848
7849 \begin_layout List
7850 \labelwidthstring 00.00.0000
7851
7852 \series bold
7853 -
7854 \begin_inset ERT
7855 status collapsed
7856
7857 \begin_layout Standard
7858
7859
7860 \backslash
7861 /
7862 \end_layout
7863
7864 \end_inset
7865
7866 -model-large
7867 \begin_inset LatexCommand \index{-\/-model-large}
7868
7869 \end_inset
7870
7871
7872 \series default
7873  Generate code for Large model programs, see section Memory Models for more
7874  details.
7875  If this option is used all source files in the project have to be compiled
7876  with this option.
7877  It must also be used when invoking the linker.
7878 \end_layout
7879
7880 \begin_layout List
7881 \labelwidthstring 00.00.0000
7882
7883 \series bold
7884 -
7885 \begin_inset ERT
7886 status collapsed
7887
7888 \begin_layout Standard
7889
7890
7891 \backslash
7892 /
7893 \end_layout
7894
7895 \end_inset
7896
7897 -xstack
7898 \begin_inset LatexCommand \index{-\/-xstack}
7899
7900 \end_inset
7901
7902
7903 \series default
7904  Uses a pseudo stack in the pdata
7905 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7906
7907 \end_inset
7908
7909  area (usually the first 256 bytes in the external ram) for allocating variables
7910  and passing parameters.
7911  See section 
7912 \begin_inset LatexCommand \ref{sub:External-Stack}
7913
7914 \end_inset
7915
7916 \InsetSpace ~
7917  External Stack for more details.
7918 \end_layout
7919
7920 \begin_layout List
7921 \labelwidthstring 00.00.0000
7922
7923 \series bold
7924 -
7925 \begin_inset ERT
7926 status collapsed
7927
7928 \begin_layout Standard
7929
7930
7931 \backslash
7932 /
7933 \end_layout
7934
7935 \end_inset
7936
7937 -iram-size
7938 \series default
7939 \InsetSpace ~
7940 <Value>
7941 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7942
7943 \end_inset
7944
7945  Causes the linker to check if the internal ram usage is within limits of
7946  the given value.
7947 \end_layout
7948
7949 \begin_layout List
7950 \labelwidthstring 00.00.0000
7951
7952 \series bold
7953 -
7954 \begin_inset ERT
7955 status collapsed
7956
7957 \begin_layout Standard
7958
7959
7960 \backslash
7961 /
7962 \end_layout
7963
7964 \end_inset
7965
7966 -xram-size
7967 \series default
7968 \InsetSpace ~
7969 <Value>
7970 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7971
7972 \end_inset
7973
7974  Causes the linker to check if the external ram usage is within limits of
7975  the given value.
7976 \end_layout
7977
7978 \begin_layout List
7979 \labelwidthstring 00.00.0000
7980
7981 \series bold
7982 -
7983 \begin_inset ERT
7984 status collapsed
7985
7986 \begin_layout Standard
7987
7988
7989 \backslash
7990 /
7991 \end_layout
7992
7993 \end_inset
7994
7995 -code-size
7996 \series default
7997 \InsetSpace ~
7998 <Value>
7999 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8000
8001 \end_inset
8002
8003  Causes the linker to check if the code memory usage is within limits of
8004  the given value.
8005 \end_layout
8006
8007 \begin_layout List
8008 \labelwidthstring 00.00.0000
8009
8010 \series bold
8011 -
8012 \begin_inset ERT
8013 status collapsed
8014
8015 \begin_layout Standard
8016
8017
8018 \backslash
8019 /
8020 \end_layout
8021
8022 \end_inset
8023
8024 -stack-size
8025 \series default
8026 \InsetSpace ~
8027 <Value>
8028 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8029
8030 \end_inset
8031
8032  Causes the linker to check if there is at minimum <Value> bytes for stack.
8033 \end_layout
8034
8035 \begin_layout List
8036 \labelwidthstring 00.00.0000
8037
8038 \series bold
8039 -
8040 \begin_inset ERT
8041 status collapsed
8042
8043 \begin_layout Standard
8044
8045
8046 \backslash
8047 /
8048 \end_layout
8049
8050 \end_inset
8051
8052 -pack-iram
8053 \series default
8054 \InsetSpace ~
8055
8056 \begin_inset LatexCommand \index{-\/-pack-iram}
8057
8058 \end_inset
8059
8060  Causes the linker to use unused register banks for data variables and pack
8061  data, idata and stack together.
8062  This is the default now.
8063 \end_layout
8064
8065 \begin_layout List
8066 \labelwidthstring 00.00.0000
8067
8068 \series bold
8069 -
8070 \begin_inset ERT
8071 status collapsed
8072
8073 \begin_layout Standard
8074
8075
8076 \backslash
8077 /
8078 \end_layout
8079
8080 \end_inset
8081
8082 -no-pack-iram
8083 \series default
8084 \InsetSpace ~
8085
8086 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8087
8088 \end_inset
8089
8090  Causes the linker to use old style for allocating memory areas.
8091 \end_layout
8092
8093 \begin_layout Standard
8094 \begin_inset VSpace bigskip
8095 \end_inset
8096
8097
8098 \end_layout
8099
8100 \begin_layout Subsection
8101 DS390 / DS400 Options
8102 \begin_inset LatexCommand \index{Options DS390}
8103
8104 \end_inset
8105
8106
8107 \begin_inset LatexCommand \index{DS390}
8108
8109 \end_inset
8110
8111
8112 \end_layout
8113
8114 \begin_layout List
8115 \labelwidthstring 00.00.0000
8116
8117 \series bold
8118 -
8119 \begin_inset ERT
8120 status collapsed
8121
8122 \begin_layout Standard
8123
8124
8125 \backslash
8126 /
8127 \end_layout
8128
8129 \end_inset
8130
8131 -model-flat24
8132 \series default
8133
8134 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8135
8136 \end_inset
8137
8138
8139 \size large
8140 \emph on
8141  
8142 \size default
8143 \emph default
8144 Generate 24-bit flat mode code.
8145  This is the one and only that the ds390 code generator supports right now
8146  and is default when using 
8147 \emph on
8148 -mds390
8149 \emph default
8150 .
8151  See section Memory Models for more details.
8152 \end_layout
8153
8154 \begin_layout List
8155 \labelwidthstring 00.00.0000
8156
8157 \series bold
8158 -
8159 \begin_inset ERT
8160 status collapsed
8161
8162 \begin_layout Standard
8163
8164
8165 \backslash
8166 /
8167 \end_layout
8168
8169 \end_inset
8170
8171 -protect-sp-update
8172 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8173
8174 \end_inset
8175
8176
8177 \series default
8178  disable interrupts during ESP:SP updates.
8179 \end_layout
8180
8181 \begin_layout List
8182 \labelwidthstring 00.00.0000
8183
8184 \series bold
8185 -
8186 \begin_inset ERT
8187 status collapsed
8188
8189 \begin_layout Standard
8190
8191
8192 \backslash
8193 /
8194 \end_layout
8195
8196 \end_inset
8197
8198 -stack-10bit
8199 \series default
8200
8201 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8202
8203 \end_inset
8204
8205  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8206  This is the one and only that the ds390 code generator supports right now
8207  and is default when using 
8208 \emph on
8209 -mds390
8210 \emph default
8211 .
8212  In this mode, the stack is located in the lower 1K of the internal RAM,
8213  which is mapped to 0x400000.
8214  Note that the support is incomplete, since it still uses a single byte
8215  as the stack pointer.
8216  This means that only the lower 256 bytes of the potential 1K stack space
8217  will actually be used.
8218  However, this does allow you to reclaim the precious 256 bytes of low RAM
8219  for use for the DATA and IDATA segments.
8220  The compiler will not generate any code to put the processor into 10 bit
8221  stack mode.
8222  It is important to ensure that the processor is in this mode before calling
8223  any re-entrant functions compiled with this option.
8224  In principle, this should work with the 
8225 \emph on
8226 -
8227 \begin_inset ERT
8228 status collapsed
8229
8230 \begin_layout Standard
8231
8232
8233 \backslash
8234 /
8235 \end_layout
8236
8237 \end_inset
8238
8239 -stack-auto
8240 \begin_inset LatexCommand \index{-\/-stack-auto}
8241
8242 \end_inset
8243
8244
8245 \emph default
8246  option, but that has not been tested.
8247  It is incompatible with the 
8248 \emph on
8249 -
8250 \begin_inset ERT
8251 status collapsed
8252
8253 \begin_layout Standard
8254
8255
8256 \backslash
8257 /
8258 \end_layout
8259
8260 \end_inset
8261
8262 -xstack
8263 \begin_inset LatexCommand \index{-\/-xstack}
8264
8265 \end_inset
8266
8267
8268 \emph default
8269  option.
8270  It also only makes sense if the processor is in 24 bit contiguous addressing
8271  mode (see the 
8272 \emph on
8273 -
8274 \begin_inset ERT
8275 status collapsed
8276
8277 \begin_layout Standard
8278
8279
8280 \backslash
8281 /
8282 \end_layout
8283
8284 \end_inset
8285
8286 -model-flat24 option
8287 \emph default
8288 ).
8289 \series bold
8290
8291 \begin_inset Note Note
8292 status collapsed
8293
8294 \begin_layout List
8295 \labelwidthstring 00.00.0000
8296
8297 \series bold
8298 -
8299 \begin_inset ERT
8300 status open
8301
8302 \begin_layout Standard
8303
8304
8305 \backslash
8306 /
8307 \end_layout
8308
8309 \end_inset
8310
8311 -stack-8-bit - switches off the 10-bit mode
8312 \end_layout
8313
8314 \end_inset
8315
8316
8317 \end_layout
8318
8319 \begin_layout List
8320 \labelwidthstring 00.00.0000
8321
8322 \series bold
8323 -
8324 \begin_inset ERT
8325 status collapsed
8326
8327 \begin_layout Standard
8328
8329
8330 \backslash
8331 /
8332 \end_layout
8333
8334 \end_inset
8335
8336 -stack-probe
8337 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8338
8339 \end_inset
8340
8341
8342 \series default
8343  insert call to function __stack_probe at each function prologue.
8344 \end_layout
8345
8346 \begin_layout List
8347 \labelwidthstring 00.00.0000
8348
8349 \series bold
8350 -
8351 \begin_inset ERT
8352 status open
8353
8354 \begin_layout Standard
8355
8356
8357 \backslash
8358 /
8359 \end_layout
8360
8361 \end_inset
8362
8363 -tini-libid
8364 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8365
8366 \end_inset
8367
8368
8369 \series default
8370  <nnnn> LibraryID used in -mTININative.
8371  
8372 \end_layout
8373
8374 \begin_layout List
8375 \labelwidthstring 00.00.0000
8376
8377 \series bold
8378 -
8379 \begin_inset ERT
8380 status collapsed
8381
8382 \begin_layout Standard
8383
8384
8385 \backslash
8386 /
8387 \end_layout
8388
8389 \end_inset
8390
8391 -use-accelerator
8392 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8393
8394 \end_inset
8395
8396
8397 \series default
8398  generate code for DS390 Arithmetic Accelerator.
8399  
8400 \end_layout
8401
8402 \begin_layout Standard
8403 \begin_inset VSpace bigskip
8404 \end_inset
8405
8406
8407 \end_layout
8408
8409 \begin_layout Subsection
8410 Z80 Options
8411 \begin_inset LatexCommand \index{Options Z80}
8412
8413 \end_inset
8414
8415
8416 \begin_inset LatexCommand \index{Z80}
8417
8418 \end_inset
8419
8420
8421 \end_layout
8422
8423 \begin_layout List
8424 \labelwidthstring 00.00.0000
8425
8426 \series bold
8427 -
8428 \begin_inset ERT
8429 status collapsed
8430
8431 \begin_layout Standard
8432
8433
8434 \backslash
8435 /
8436 \end_layout
8437
8438 \end_inset
8439
8440 -callee-saves-bc
8441 \series default
8442
8443 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8444
8445 \end_inset
8446
8447
8448 \size large
8449 \emph on
8450  
8451 \size default
8452 \emph default
8453 Force a called function to always save BC.
8454 \end_layout
8455
8456 \begin_layout List
8457 \labelwidthstring 00.00.0000
8458
8459 \series bold
8460 -
8461 \begin_inset ERT
8462 status collapsed
8463
8464 \begin_layout Standard
8465
8466
8467 \backslash
8468 /
8469 \end_layout
8470
8471 \end_inset
8472
8473 -no-std-crt0
8474 \series default
8475
8476 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8477
8478 \end_inset
8479
8480  When linking, skip the standard crt0.o object file.
8481  You must provide your own crt0.o for your system when linking.
8482 \end_layout
8483
8484 \begin_layout List
8485 \labelwidthstring 00.00.0000
8486
8487 \series bold
8488 -
8489 \begin_inset ERT
8490 status collapsed
8491
8492 \begin_layout Standard
8493
8494
8495 \backslash
8496 /
8497 \end_layout
8498
8499 \end_inset
8500
8501 -portmode=
8502 \series default
8503 <Value>
8504 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8505
8506 \end_inset
8507
8508  Determinate PORT I/O mode (<Value> is z80 or z180).
8509 \end_layout
8510
8511 \begin_layout List
8512 \labelwidthstring 00.00.0000
8513
8514 \series bold
8515 -
8516 \begin_inset ERT
8517 status collapsed
8518
8519 \begin_layout Standard
8520
8521
8522 \backslash
8523 /
8524 \end_layout
8525
8526 \end_inset
8527
8528 -asm=
8529 \series default
8530 <Value>
8531 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8532
8533 \end_inset
8534
8535  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8536 \end_layout
8537
8538 \begin_layout List
8539 \labelwidthstring 00.00.0000
8540
8541 \series bold
8542 -
8543 \begin_inset ERT
8544 status collapsed
8545
8546 \begin_layout Standard
8547
8548
8549 \backslash
8550 /
8551 \end_layout
8552
8553 \end_inset
8554
8555 -codeseg
8556 \series default
8557 \InsetSpace ~
8558 <Value>
8559 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8560
8561 \end_inset
8562
8563  Use <Value> for the code segment name.
8564 \end_layout
8565
8566 \begin_layout List
8567 \labelwidthstring 00.00.0000
8568
8569 \series bold
8570 -
8571 \begin_inset ERT
8572 status collapsed
8573
8574 \begin_layout Standard
8575
8576
8577 \backslash
8578 /
8579 \end_layout
8580
8581 \end_inset
8582
8583 -constseg
8584 \series default
8585 \InsetSpace ~
8586 <Value>
8587 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8588
8589 \end_inset
8590
8591  Use <Value> for the const segment name.
8592 \end_layout
8593
8594 \begin_layout List
8595 \labelwidthstring 00.00.0000
8596 \begin_inset VSpace bigskip
8597 \end_inset
8598
8599
8600 \end_layout
8601
8602 \begin_layout Subsection
8603 GBZ80 Options
8604 \begin_inset LatexCommand \index{Options GBZ80}
8605
8606 \end_inset
8607
8608
8609 \begin_inset LatexCommand \index{GBZ80}
8610
8611 \end_inset
8612
8613
8614 \end_layout
8615
8616 \begin_layout List
8617 \labelwidthstring 00.00.0000
8618
8619 \series bold
8620 -
8621 \begin_inset ERT
8622 status collapsed
8623
8624 \begin_layout Standard
8625
8626
8627 \backslash
8628 /
8629 \end_layout
8630
8631 \end_inset
8632
8633 -callee-saves-bc
8634 \series default
8635
8636 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8637
8638 \end_inset
8639
8640
8641 \size large
8642 \emph on
8643  
8644 \size default
8645 \emph default
8646 Force a called function to always save BC.
8647 \end_layout
8648
8649 \begin_layout List
8650 \labelwidthstring 00.00.0000
8651
8652 \series bold
8653 -bo
8654 \series default
8655 \InsetSpace ~
8656 <Num>
8657 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8658
8659 \end_inset
8660
8661  Use code bank <Num>.
8662 \end_layout
8663
8664 \begin_layout List
8665 \labelwidthstring 00.00.0000
8666
8667 \series bold
8668 -ba
8669 \series default
8670 \InsetSpace ~
8671 <Num>
8672 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8673
8674 \end_inset
8675
8676  Use data bank <Num>.
8677 \end_layout
8678
8679 \begin_layout List
8680 \labelwidthstring 00.00.0000
8681
8682 \series bold
8683 -
8684 \begin_inset ERT
8685 status collapsed
8686
8687 \begin_layout Standard
8688
8689
8690 \backslash
8691 /
8692 \end_layout
8693
8694 \end_inset
8695
8696 -codeseg
8697 \series default
8698 \InsetSpace ~
8699 <Value>
8700 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8701
8702 \end_inset
8703
8704  Use <Value> for the code segment name.
8705 \end_layout
8706
8707 \begin_layout List
8708 \labelwidthstring 00.00.0000
8709
8710 \series bold
8711 -
8712 \begin_inset ERT
8713 status collapsed
8714
8715 \begin_layout Standard
8716
8717
8718 \backslash
8719 /
8720 \end_layout
8721
8722 \end_inset
8723
8724 -constseg
8725 \series default
8726 \InsetSpace ~
8727 <Value>
8728 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8729
8730 \end_inset
8731
8732  Use <Value> for the const segment name.
8733 \end_layout
8734
8735 \begin_layout Standard
8736 \begin_inset VSpace bigskip
8737 \end_inset
8738
8739
8740 \end_layout
8741
8742 \begin_layout Subsection
8743 Optimization Options
8744 \begin_inset LatexCommand \index{Options optimization}
8745
8746 \end_inset
8747
8748
8749 \begin_inset LatexCommand \index{Optimization options}
8750
8751 \end_inset
8752
8753
8754 \end_layout
8755
8756 \begin_layout List
8757 \labelwidthstring 00.00.0000
8758
8759 \series bold
8760 -
8761 \begin_inset ERT
8762 status collapsed
8763
8764 \begin_layout Standard
8765
8766
8767 \backslash
8768 /
8769 \end_layout
8770
8771 \end_inset
8772
8773 -nogcse
8774 \begin_inset LatexCommand \index{-\/-nogcse}
8775
8776 \end_inset
8777
8778
8779 \series default
8780  Will not do global subexpression elimination, this option may be used when
8781  the compiler creates undesirably large stack/data spaces to store compiler
8782  temporaries (
8783 \emph on
8784 s
8785 \emph default
8786 pill 
8787 \emph on
8788 loc
8789 \emph default
8790 ations, sloc
8791 \begin_inset LatexCommand \index{sloc (spill location)}
8792
8793 \end_inset
8794
8795 ).
8796  A warning message will be generated when this happens and the compiler
8797  will indicate the number of extra bytes it allocated.
8798  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8799 nogcse
8800 \begin_inset LatexCommand \index{\#pragma nogcse}
8801
8802 \end_inset
8803
8804  can be used to turn off global subexpression elimination
8805 \begin_inset LatexCommand \index{Subexpression elimination}
8806
8807 \end_inset
8808
8809  for a given function only.
8810 \end_layout
8811
8812 \begin_layout List
8813 \labelwidthstring 00.00.0000
8814
8815 \series bold
8816 -
8817 \begin_inset ERT
8818 status collapsed
8819
8820 \begin_layout Standard
8821
8822
8823 \backslash
8824 /
8825 \end_layout
8826
8827 \end_inset
8828
8829 -noinvariant
8830 \begin_inset LatexCommand \index{-\/-noinvariant}
8831
8832 \end_inset
8833
8834
8835 \series default
8836  Will not do loop invariant optimizations, this may be turned off for reasons
8837  explained for the previous option.
8838  For more details of loop optimizations performed see Loop Invariants in
8839  section 
8840 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8841
8842 \end_inset
8843
8844 .
8845  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8846 noinvariant
8847 \begin_inset LatexCommand \index{\#pragma noinvariant}
8848
8849 \end_inset
8850
8851  can be used to turn off invariant optimizations for a given function only.
8852 \end_layout
8853
8854 \begin_layout List
8855 \labelwidthstring 00.00.0000
8856
8857 \series bold
8858 -
8859 \begin_inset ERT
8860 status collapsed
8861
8862 \begin_layout Standard
8863
8864
8865 \backslash
8866 /
8867 \end_layout
8868
8869 \end_inset
8870
8871 -noinduction
8872 \begin_inset LatexCommand \index{-\/-noinduction}
8873
8874 \end_inset
8875
8876
8877 \series default
8878  Will not do loop induction optimizations, see section strength reduction
8879  for more details.
8880  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8881 noinduction
8882 \begin_inset LatexCommand \index{\#pragma noinduction}
8883
8884 \end_inset
8885
8886  can be used to turn off induction optimizations for a given function only.
8887 \end_layout
8888
8889 \begin_layout List
8890 \labelwidthstring 00.00.0000
8891
8892 \series bold
8893 -
8894 \begin_inset ERT
8895 status collapsed
8896
8897 \begin_layout Standard
8898
8899
8900 \backslash
8901 /
8902 \end_layout
8903
8904 \end_inset
8905
8906 -nojtbound
8907 \begin_inset LatexCommand \index{-\/-nojtbound}
8908
8909 \end_inset
8910
8911
8912 \size large
8913 \bar under
8914  
8915 \series default
8916 \size default
8917 \bar default
8918  Will not generate boundary condition check when switch statements
8919 \begin_inset LatexCommand \index{switch statement}
8920
8921 \end_inset
8922
8923  are implemented using jump-tables.
8924  See section 
8925 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8926
8927 \end_inset
8928
8929 \InsetSpace ~
8930 Switch Statements for more details.
8931  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8932 nojtbound
8933 \begin_inset LatexCommand \index{\#pragma nojtbound}
8934
8935 \end_inset
8936
8937  can be used to turn off boundary checking for jump tables for a given function
8938  only.
8939 \end_layout
8940
8941 \begin_layout List
8942 \labelwidthstring 00.00.0000
8943
8944 \series bold
8945 -
8946 \begin_inset ERT
8947 status collapsed
8948
8949 \begin_layout Standard
8950
8951
8952 \backslash
8953 /
8954 \end_layout
8955
8956 \end_inset
8957
8958 -noloopreverse
8959 \begin_inset LatexCommand \index{-\/-noloopreverse}
8960
8961 \end_inset
8962
8963
8964 \series default
8965 \size large
8966  
8967 \size default
8968 Will not do loop reversal 
8969 \begin_inset LatexCommand \index{Loop reversing}
8970
8971 \end_inset
8972
8973 optimization.
8974 \end_layout
8975
8976 \begin_layout List
8977 \labelwidthstring 00.00.0000
8978 -
8979 \begin_inset ERT
8980 status collapsed
8981
8982 \begin_layout Standard
8983
8984
8985 \backslash
8986 /
8987 \end_layout
8988
8989 \end_inset
8990
8991 -
8992 \series bold
8993 nolabelopt
8994 \series default
8995  
8996 \begin_inset LatexCommand \index{-\/-nolabelopt }
8997
8998 \end_inset
8999
9000 Will not optimize labels (makes the dumpfiles more readable).
9001 \end_layout
9002
9003 \begin_layout List
9004 \labelwidthstring 00.00.0000
9005
9006 \series bold
9007 -
9008 \begin_inset ERT
9009 status collapsed
9010
9011 \begin_layout Standard
9012
9013
9014 \backslash
9015 /
9016 \end_layout
9017
9018 \end_inset
9019
9020 -no-xinit-opt
9021 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9022
9023 \end_inset
9024
9025
9026 \series default
9027  Will not memcpy initialized data from code space into xdata space.
9028  This saves a few bytes in code space if you don't have initialized data
9029 \begin_inset LatexCommand \index{Variable initialization}
9030
9031 \end_inset
9032
9033 .
9034 \end_layout
9035
9036 \begin_layout List
9037 \labelwidthstring 00.00.0000
9038
9039 \series bold
9040 -
9041 \begin_inset ERT
9042 status collapsed
9043
9044 \begin_layout Standard
9045
9046
9047 \backslash
9048 /
9049 \end_layout
9050
9051 \end_inset
9052
9053 -nooverlay
9054 \begin_inset LatexCommand \index{-\/-nooverlay}
9055
9056 \end_inset
9057
9058
9059 \series default
9060   The compiler will not overlay parameters and local variables of any function,
9061  see section Parameters and local variables for more details.
9062 \end_layout
9063
9064 \begin_layout List
9065 \labelwidthstring 00.00.0000
9066
9067 \series bold
9068 -
9069 \begin_inset ERT
9070 status collapsed
9071
9072 \begin_layout Standard
9073
9074
9075 \backslash
9076 /
9077 \end_layout
9078
9079 \end_inset
9080
9081 -no-peep
9082 \begin_inset LatexCommand \index{-\/-no-peep}
9083
9084 \end_inset
9085
9086
9087 \series default
9088  Disable peep-hole optimization with built-in rules.
9089 \end_layout
9090
9091 \begin_layout List
9092 \labelwidthstring 00.00.0000
9093
9094 \series bold
9095 -
9096 \begin_inset ERT
9097 status collapsed
9098
9099 \begin_layout Standard
9100
9101
9102 \backslash
9103 /
9104 \end_layout
9105
9106 \end_inset
9107
9108 -peep-file
9109 \series default
9110
9111 \begin_inset LatexCommand \index{-\/-peep-file}
9112
9113 \end_inset
9114
9115 \InsetSpace ~
9116 <filename> This option can be used to use additional rules to be used by
9117  the peep hole optimizer.
9118  See section 
9119 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9120
9121 \end_inset
9122
9123 \InsetSpace ~
9124 Peep Hole optimizations for details on how to write these rules.
9125 \end_layout
9126
9127 \begin_layout List
9128 \labelwidthstring 00.00.0000
9129
9130 \series bold
9131 -
9132 \begin_inset ERT
9133 status collapsed
9134
9135 \begin_layout Standard
9136
9137
9138 \backslash
9139 /
9140 \end_layout
9141
9142 \end_inset
9143
9144 -peep-asm
9145 \begin_inset LatexCommand \index{-\/-peep-asm}
9146
9147 \end_inset
9148
9149
9150 \series default
9151  Pass the inline assembler code through the peep hole optimizer.
9152  This can cause unexpected changes to inline assembler code, please go through
9153  the peephole optimizer
9154 \begin_inset LatexCommand \index{Peephole optimizer}
9155
9156 \end_inset
9157
9158  rules defined in the source file tree '<target>/peeph.def' before using
9159  this option.
9160 \end_layout
9161
9162 \begin_layout List
9163 \labelwidthstring 00.00.0000
9164
9165 \series bold
9166 -
9167 \begin_inset ERT
9168 status collapsed
9169
9170 \begin_layout Standard
9171
9172
9173 \backslash
9174 /
9175 \end_layout
9176
9177 \end_inset
9178
9179 -opt-code-speed
9180 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9181
9182 \end_inset
9183
9184
9185 \series default
9186  The compiler will optimize code generation towards fast code, possibly
9187  at the expense of code size.
9188 \end_layout
9189
9190 \begin_layout List
9191 \labelwidthstring 00.00.0000
9192
9193 \series bold
9194 -
9195 \begin_inset ERT
9196 status collapsed
9197
9198 \begin_layout Standard
9199
9200
9201 \backslash
9202 /
9203 \end_layout
9204
9205 \end_inset
9206
9207 -opt-code-size
9208 \begin_inset LatexCommand \index{-\/-opt-code-size}
9209
9210 \end_inset
9211
9212
9213 \series default
9214  The compiler will optimize code generation towards compact code, possibly
9215  at the expense of code speed.
9216 \end_layout
9217
9218 \begin_layout Standard
9219 \begin_inset VSpace bigskip
9220 \end_inset
9221
9222
9223 \end_layout
9224
9225 \begin_layout Subsection
9226 Other Options
9227 \begin_inset LatexCommand \index{Options other}
9228
9229 \end_inset
9230
9231
9232 \end_layout
9233
9234 \begin_layout List
9235 \labelwidthstring 00.00.0000
9236
9237 \series bold
9238 -c\InsetSpace ~
9239 -
9240 \begin_inset ERT
9241 status collapsed
9242
9243 \begin_layout Standard
9244
9245
9246 \backslash
9247 /
9248 \end_layout
9249
9250 \end_inset
9251
9252 -compile-only
9253 \begin_inset LatexCommand \index{-\/-compile-only}
9254
9255 \end_inset
9256
9257
9258 \begin_inset LatexCommand \index{-c -\/-compile-only}
9259
9260 \end_inset
9261
9262
9263 \series default
9264  will compile and assemble the source, but will not call the linkage editor.
9265 \end_layout
9266
9267 \begin_layout List
9268 \labelwidthstring 00.00.0000
9269
9270 \series bold
9271 -
9272 \series default
9273
9274 \begin_inset ERT
9275 status collapsed
9276
9277 \begin_layout Standard
9278
9279
9280 \backslash
9281 /
9282 \end_layout
9283
9284 \end_inset
9285
9286
9287 \series bold
9288 -c1mode
9289 \begin_inset LatexCommand \index{-\/-c1mode}
9290
9291 \end_inset
9292
9293
9294 \series default
9295  reads the preprocessed source from standard input and compiles it.
9296  The file name for the assembler output must be specified using the -o option.
9297 \end_layout
9298
9299 \begin_layout List
9300 \labelwidthstring 00.00.0000
9301
9302 \series bold
9303 -E
9304 \begin_inset LatexCommand \index{-E}
9305
9306 \end_inset
9307
9308
9309 \series default
9310  Run only the C preprocessor.
9311  Preprocess all the C source files specified and output the results to standard
9312  output.
9313 \end_layout
9314
9315 \begin_layout List
9316 \labelwidthstring 00.00.0000
9317
9318 \series bold
9319 -o\InsetSpace ~
9320 <path/file>
9321 \begin_inset LatexCommand \index{-o <path/file>}
9322
9323 \end_inset
9324
9325  
9326 \series default
9327 The output path where everything will be placed or the file name used for
9328  all generated output files.
9329  If the parameter is a path, it must have a trailing slash (or backslash
9330  for the Windows binaries) to be recognized as a path.
9331
9332 \emph on
9333  
9334 \emph default
9335 Note for Windows users: if the path contains spaces, it should be surrounded
9336  by quotes.
9337  The trailing backslash should be doubled in order to prevent escaping the
9338  final quote, for example: 
9339 \emph on
9340 -o 
9341 \begin_inset Quotes sld
9342 \end_inset
9343
9344 F:
9345 \backslash
9346 Projects
9347 \backslash
9348 test3
9349 \backslash
9350 output 1
9351 \backslash
9352
9353 \backslash
9354
9355 \begin_inset Quotes srd
9356 \end_inset
9357
9358
9359 \emph default
9360  or put after the final quote, for example: 
9361 \emph on
9362 -o 
9363 \begin_inset Quotes sld
9364 \end_inset
9365
9366 F:
9367 \backslash
9368 Projects
9369 \backslash
9370 test3
9371 \backslash
9372 output 1
9373 \begin_inset Quotes srd
9374 \end_inset
9375
9376
9377 \backslash
9378
9379 \emph default
9380 .
9381  The path using slashes for directory delimiters can be used too, for example:
9382  
9383 \emph on
9384 -o 
9385 \begin_inset Quotes sld
9386 \end_inset
9387
9388 F:/Projects/test3/output 1/
9389 \begin_inset Quotes srd
9390 \end_inset
9391
9392
9393 \emph default
9394 .
9395 \end_layout
9396
9397 \begin_layout List
9398 \labelwidthstring 00.00.0000
9399
9400 \series bold
9401 -
9402 \begin_inset ERT
9403 status collapsed
9404
9405 \begin_layout Standard
9406
9407
9408 \backslash
9409 /
9410 \end_layout
9411
9412 \end_inset
9413
9414 -stack-auto
9415 \begin_inset LatexCommand \index{-\/-stack-auto}
9416
9417 \end_inset
9418
9419
9420 \series default
9421 \size large
9422 \emph on
9423  
9424 \size default
9425 \emph default
9426 All functions in the source file will be compiled as 
9427 \emph on
9428 reentrant
9429 \emph default
9430
9431 \begin_inset LatexCommand \index{reentrant}
9432
9433 \end_inset
9434
9435 , i.e.
9436  the parameters and local variables will be allocated on the stack
9437 \begin_inset LatexCommand \index{stack}
9438
9439 \end_inset
9440
9441 .
9442  See section 
9443 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9444
9445 \end_inset
9446
9447  Parameters and Local Variables for more details.
9448  If this option is used all source files in the project should be compiled
9449  with this option.
9450  It automatically implies -
9451 \series bold
9452
9453 \begin_inset ERT
9454 status open
9455
9456 \begin_layout Standard
9457
9458
9459 \backslash
9460 /
9461 \end_layout
9462
9463 \end_inset
9464
9465
9466 \series default
9467 -int-long-reent and -
9468 \series bold
9469
9470 \begin_inset ERT
9471 status open
9472
9473 \begin_layout Standard
9474
9475
9476 \backslash
9477 /
9478 \end_layout
9479
9480 \end_inset
9481
9482
9483 \series default
9484 -float-reent.
9485  
9486 \end_layout
9487
9488 \begin_layout List
9489 \labelwidthstring 00.00.0000
9490
9491 \series bold
9492 -
9493 \begin_inset ERT
9494 status collapsed
9495
9496 \begin_layout Standard
9497
9498
9499 \backslash
9500 /
9501 \end_layout
9502
9503 \end_inset
9504
9505 -callee-saves
9506 \begin_inset LatexCommand \index{-\/-callee-saves}
9507
9508 \end_inset
9509
9510  
9511 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9512
9513 \end_inset
9514
9515 function1[,function2][,function3]....
9516
9517 \series default
9518  The compiler by default uses a caller saves convention for register saving
9519  across function calls, however this can cause unnecessary register pushing
9520  and popping when calling small functions from larger functions.
9521  This option can be used to switch the register saving convention for the
9522  function names specified.
9523  The compiler will not save registers when calling these functions, no extra
9524  code will be generated at the entry and exit (function prologue
9525 \series bold
9526
9527 \begin_inset LatexCommand \index{function prologue}
9528
9529 \end_inset
9530
9531
9532 \series default
9533  and epilogue
9534 \series bold
9535
9536 \begin_inset LatexCommand \index{function epilogue}
9537
9538 \end_inset
9539
9540
9541 \series default
9542 ) for these functions to save and restore the registers used by these functions,
9543  this can SUBSTANTIALLY reduce code and improve run time performance of
9544  the generated code.
9545  In the future the compiler (with inter procedural analysis) will be able
9546  to determine the appropriate scheme to use for each function call.
9547  DO NOT use this option for built-in functions such as _mulint..., if this
9548  option is used for a library function the appropriate library function
9549  needs to be recompiled with the same option.
9550  If the project consists of multiple source files then all the source file
9551  should be compiled with the same -
9552 \begin_inset ERT
9553 status collapsed
9554
9555 \begin_layout Standard
9556
9557
9558 \backslash
9559 /
9560 \end_layout
9561
9562 \end_inset
9563
9564 -callee-saves option string.
9565  Also see #pragma\InsetSpace ~
9566 callee_saves 
9567 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9568
9569 \end_inset
9570
9571  
9572 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9573
9574 \end_inset
9575
9576 .
9577 \end_layout
9578
9579 \begin_layout List
9580 \labelwidthstring 00.00.0000
9581
9582 \series bold
9583 -
9584 \begin_inset ERT
9585 status collapsed
9586
9587 \begin_layout Standard
9588
9589
9590 \backslash
9591 /
9592 \end_layout
9593
9594 \end_inset
9595
9596 -all-callee-saves
9597 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9598
9599 \end_inset
9600
9601  
9602 \series default
9603 Function of
9604 \series bold
9605  
9606 \series default
9607 -
9608 \begin_inset ERT
9609 status collapsed
9610
9611 \begin_layout Standard
9612
9613
9614 \backslash
9615 /
9616 \end_layout
9617
9618 \end_inset
9619
9620 -callee-saves will be applied to all functions by default.
9621 \end_layout
9622
9623 \begin_layout List
9624 \labelwidthstring 00.00.0000
9625
9626 \series bold
9627 -
9628 \begin_inset ERT
9629 status collapsed
9630
9631 \begin_layout Standard
9632
9633
9634 \backslash
9635 /
9636 \end_layout
9637
9638 \end_inset
9639
9640 -debug
9641 \begin_inset LatexCommand \index{-\/-debug}
9642
9643 \end_inset
9644
9645
9646 \bar under
9647  
9648 \series default
9649 \bar default
9650 When this option is used the compiler will generate debug information.
9651  The debug information collected in a file with .cdb extension can be used
9652  with the SDCDB.
9653  For more information see documentation for SDCDB.
9654  Another file with no extension contains debug information in AOMF or AOMF51
9655 \begin_inset LatexCommand \index{AOMF, AOMF51}
9656
9657 \end_inset
9658
9659  format which is commonly used by third party tools.
9660 \end_layout
9661
9662 \begin_layout List
9663 \labelwidthstring 00.00.0000
9664
9665 \series bold
9666 -S
9667 \begin_inset LatexCommand \index{-S}
9668
9669 \end_inset
9670
9671
9672 \size large
9673 \bar under
9674  
9675 \series default
9676 \size default
9677 \bar default
9678 Stop after the stage of compilation proper; do not assemble.
9679  The output is an assembler code file for the input file specified.
9680 \end_layout
9681
9682 \begin_layout List
9683 \labelwidthstring 00.00.0000
9684
9685 \series bold
9686 -
9687 \begin_inset ERT
9688 status collapsed
9689
9690 \begin_layout Standard
9691
9692
9693 \backslash
9694 /
9695 \end_layout
9696
9697 \end_inset
9698
9699 -int-long-reent
9700 \begin_inset LatexCommand \index{-\/-int-long-reent}
9701
9702 \end_inset
9703
9704
9705 \series default
9706  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9707  Note by default these libraries are compiled as non-reentrant.
9708  See section Installation for more details.
9709 \end_layout
9710
9711 \begin_layout List
9712 \labelwidthstring 00.00.0000
9713
9714 \series bold
9715 -
9716 \begin_inset ERT
9717 status collapsed
9718
9719 \begin_layout Standard
9720
9721
9722 \backslash
9723 /
9724 \end_layout
9725
9726 \end_inset
9727
9728 -cyclomatic
9729 \begin_inset LatexCommand \index{-\/-cyclomatic}
9730
9731 \end_inset
9732
9733
9734 \bar under
9735  
9736 \series default
9737 \bar default
9738 This option will cause the compiler to generate an information message for
9739  each function in the source file.
9740  The message contains some 
9741 \emph on
9742 important
9743 \emph default
9744  information about the function.
9745  The number of edges and nodes the compiler detected in the control flow
9746  graph of the function, and most importantly the 
9747 \emph on
9748 cyclomatic complexity
9749 \begin_inset LatexCommand \index{Cyclomatic complexity}
9750
9751 \end_inset
9752
9753
9754 \emph default
9755  see section on Cyclomatic Complexity for more details.
9756 \end_layout
9757
9758 \begin_layout List
9759 \labelwidthstring 00.00.0000
9760
9761 \series bold
9762 -
9763 \begin_inset ERT
9764 status collapsed
9765
9766 \begin_layout Standard
9767
9768
9769 \backslash
9770 /
9771 \end_layout
9772
9773 \end_inset
9774
9775 -float-reent
9776 \begin_inset LatexCommand \index{-\/-float-reent}
9777
9778 \end_inset
9779
9780
9781 \series default
9782  Floating point library is compiled as reentrant
9783 \begin_inset LatexCommand \index{reentrant}
9784
9785 \end_inset
9786
9787 .
9788  See section Installation for more details.
9789 \end_layout
9790
9791 \begin_layout List
9792 \labelwidthstring 00.00.0000
9793
9794 \series bold
9795 -
9796 \begin_inset ERT
9797 status collapsed
9798
9799 \begin_layout Standard
9800
9801
9802 \backslash
9803 /
9804 \end_layout
9805
9806 \end_inset
9807
9808 -funsigned-char
9809 \begin_inset LatexCommand \index{-\/-funsigned-char}
9810
9811 \end_inset
9812
9813
9814 \series default
9815  The default signedness for every type is
9816 \family typewriter
9817  signed
9818 \family default
9819 .
9820  In some embedded environments the default signedness of
9821 \family typewriter
9822  char
9823 \family default
9824  is
9825 \family typewriter
9826  unsigned
9827 \family default
9828 .
9829  To set the signess for characters to unsigned, use the option -
9830 \series bold
9831
9832 \begin_inset ERT
9833 status open
9834
9835 \begin_layout Standard
9836
9837
9838 \backslash
9839 /
9840 \end_layout
9841
9842 \end_inset
9843
9844
9845 \series default
9846 -funsigned-char.
9847  If this option is set and no signedness keyword (unsigned/signed) is given,
9848  a char will be signed.
9849  All other types are unaffected.
9850 \end_layout
9851
9852 \begin_layout List
9853 \labelwidthstring 00.00.0000
9854
9855 \series bold
9856 -
9857 \begin_inset ERT
9858 status collapsed
9859
9860 \begin_layout Standard
9861
9862
9863 \backslash
9864 /
9865 \end_layout
9866
9867 \end_inset
9868
9869 -main-return
9870 \begin_inset LatexCommand \index{-\/-main-return}
9871
9872 \end_inset
9873
9874
9875 \series default
9876  This option can be used if the code generated is called by a monitor program
9877  or if the main routine includes an endless loop.
9878  This option results in slightly smaller code and saves two bytes of stack
9879  space.
9880  The return from the 'main'
9881 \begin_inset LatexCommand \index{main return}
9882
9883 \end_inset
9884
9885  function will return to the function calling main.
9886  The default setting is to lock up i.e.
9887  generate a '
9888 \family typewriter
9889 sjmp .
9890 \family default
9891 '.
9892 \end_layout
9893
9894 \begin_layout List
9895 \labelwidthstring 00.00.0000
9896
9897 \series bold
9898 -
9899 \begin_inset ERT
9900 status collapsed
9901
9902 \begin_layout Standard
9903
9904
9905 \backslash
9906 /
9907 \end_layout
9908
9909 \end_inset
9910
9911 -nostdinc
9912 \begin_inset LatexCommand \index{-\/-nostdinc}
9913
9914 \end_inset
9915
9916
9917 \series default
9918  This will prevent the compiler from passing on the default include path
9919  to the preprocessor.
9920 \end_layout
9921
9922 \begin_layout List
9923 \labelwidthstring 00.00.0000
9924
9925 \series bold
9926 -
9927 \begin_inset ERT
9928 status collapsed
9929
9930 \begin_layout Standard
9931
9932
9933 \backslash
9934 /
9935 \end_layout
9936
9937 \end_inset
9938
9939 -nostdlib
9940 \begin_inset LatexCommand \index{-\/-nostdlib}
9941
9942 \end_inset
9943
9944
9945 \series default
9946  This will prevent the compiler from passing on the default library
9947 \begin_inset LatexCommand \index{Libraries}
9948
9949 \end_inset
9950
9951  path to the linker.
9952 \end_layout
9953
9954 \begin_layout List
9955 \labelwidthstring 00.00.0000
9956
9957 \series bold
9958 -
9959 \begin_inset ERT
9960 status collapsed
9961
9962 \begin_layout Standard
9963
9964
9965 \backslash
9966 /
9967 \end_layout
9968
9969 \end_inset
9970
9971 -verbose
9972 \begin_inset LatexCommand \index{-\/-verbose}
9973
9974 \end_inset
9975
9976
9977 \series default
9978  Shows the various actions the compiler is performing.
9979 \end_layout
9980
9981 \begin_layout List
9982 \labelwidthstring 00.00.0000
9983
9984 \series bold
9985 -V
9986 \begin_inset LatexCommand \index{-V}
9987
9988 \end_inset
9989
9990
9991 \series default
9992  Shows the actual commands the compiler is executing.
9993 \end_layout
9994
9995 \begin_layout List
9996 \labelwidthstring 00.00.0000
9997
9998 \series bold
9999 -
10000 \begin_inset ERT
10001 status collapsed
10002
10003 \begin_layout Standard
10004
10005
10006 \backslash
10007 /
10008 \end_layout
10009
10010 \end_inset
10011
10012 -no-c-code-in-asm
10013 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10014
10015 \end_inset
10016
10017
10018 \series default
10019  Hides your ugly and inefficient c-code from the asm file, so you can always
10020  blame the compiler :)
10021 \end_layout
10022
10023 \begin_layout List
10024 \labelwidthstring 00.00.0000
10025
10026 \series bold
10027 -
10028 \begin_inset ERT
10029 status collapsed
10030
10031 \begin_layout Standard
10032
10033
10034 \backslash
10035 /
10036 \end_layout
10037
10038 \end_inset
10039
10040 -fverbose-asm
10041 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10042
10043 \end_inset
10044
10045
10046 \series default
10047  Include code generator and peep-hole comments in the generated asm files.
10048 \end_layout
10049
10050 \begin_layout List
10051 \labelwidthstring 00.00.0000
10052
10053 \series bold
10054 -
10055 \begin_inset ERT
10056 status collapsed
10057
10058 \begin_layout Standard
10059
10060
10061 \backslash
10062 /
10063 \end_layout
10064
10065 \end_inset
10066
10067 -no-peep-comments
10068 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10069
10070 \end_inset
10071
10072
10073 \series default
10074  Don't include peep-hole comments in the generated asm files even if -
10075 \series bold
10076
10077 \begin_inset ERT
10078 status open
10079
10080 \begin_layout Standard
10081
10082
10083 \backslash
10084 /
10085 \end_layout
10086
10087 \end_inset
10088
10089
10090 \series default
10091 -fverbose-asm option is specified.
10092 \end_layout
10093
10094 \begin_layout List
10095 \labelwidthstring 00.00.0000
10096
10097 \series bold
10098 -
10099 \begin_inset ERT
10100 status collapsed
10101
10102 \begin_layout Standard
10103
10104
10105 \backslash
10106 /
10107 \end_layout
10108
10109 \end_inset
10110
10111 -i-code-in-asm
10112 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10113
10114 \end_inset
10115
10116
10117 \series default
10118  Include i-codes in the asm file.
10119  Sounds like noise but is most helpful for debugging the compiler itself.
10120 \end_layout
10121
10122 \begin_layout List
10123 \labelwidthstring 00.00.0000
10124
10125 \series bold
10126 -
10127 \begin_inset ERT
10128 status collapsed
10129
10130 \begin_layout Standard
10131
10132
10133 \backslash
10134 /
10135 \end_layout
10136
10137 \end_inset
10138
10139 -less-pedantic
10140 \begin_inset LatexCommand \index{pedantic}
10141
10142 \end_inset
10143
10144
10145 \begin_inset LatexCommand \index{-\/-less-pedantic}
10146
10147 \end_inset
10148
10149
10150 \series default
10151
10152 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10153
10154 \end_inset
10155
10156  Disable some of the more pedantic warnings
10157 \begin_inset LatexCommand \index{Warnings}
10158
10159 \end_inset
10160
10161 .
10162  For more details, see the less_pedantic pragma 
10163 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10164
10165 \end_inset
10166
10167 .
10168 \end_layout
10169
10170 \begin_layout List
10171 \labelwidthstring 00.00.0000
10172
10173 \series bold
10174 -
10175 \begin_inset ERT
10176 status collapsed
10177
10178 \begin_layout Standard
10179
10180
10181 \backslash
10182 /
10183 \end_layout
10184
10185 \end_inset
10186
10187 -disable-warning\InsetSpace ~
10188 <nnnn>
10189 \begin_inset LatexCommand \index{-\/-disable-warning}
10190
10191 \end_inset
10192
10193
10194 \series default
10195  Disable specific warning with number <nnnn>.
10196 \end_layout
10197
10198 \begin_layout List
10199 \labelwidthstring 00.00.0000
10200
10201 \series bold
10202 -
10203 \begin_inset ERT
10204 status collapsed
10205
10206 \begin_layout Standard
10207
10208
10209 \backslash
10210 /
10211 \end_layout
10212
10213 \end_inset
10214
10215 -print-search-dirs
10216 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10217
10218 \end_inset
10219
10220
10221 \series default
10222  Display the directories in the compiler's search path
10223 \end_layout
10224
10225 \begin_layout List
10226 \labelwidthstring 00.00.0000
10227
10228 \series bold
10229 -
10230 \begin_inset ERT
10231 status collapsed
10232
10233 \begin_layout Standard
10234
10235
10236 \backslash
10237 /
10238 \end_layout
10239
10240 \end_inset
10241
10242 -vc
10243 \begin_inset LatexCommand \index{-\/-vc}
10244
10245 \end_inset
10246
10247
10248 \series default
10249  Display errors and warnings using MSVC style, so you can use SDCC with
10250  the visual studio IDE
10251 \begin_inset LatexCommand \index{IDE}
10252
10253 \end_inset
10254
10255 .
10256  With SDCC both offering a GCC-like (the default) and a MSVC-like
10257 \begin_inset LatexCommand \index{MSVC output style}
10258
10259 \end_inset
10260
10261  output style, integration into most programming editors should be straightforwa
10262 rd.
10263 \end_layout
10264
10265 \begin_layout List
10266 \labelwidthstring 00.00.0000
10267
10268 \series bold
10269 -
10270 \begin_inset ERT
10271 status collapsed
10272
10273 \begin_layout Standard
10274
10275
10276 \backslash
10277 /
10278 \end_layout
10279
10280 \end_inset
10281
10282 -use-stdout
10283 \begin_inset LatexCommand \index{-\/-use-stdout}
10284
10285 \end_inset
10286
10287
10288 \series default
10289  Send errors and warnings to stdout instead of stderr.
10290 \end_layout
10291
10292 \begin_layout List
10293 \labelwidthstring 00.00.0000
10294
10295 \series bold
10296 -Wa\InsetSpace ~
10297 asmOption[,asmOption]
10298 \series default
10299
10300 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10301
10302 \end_inset
10303
10304 ...
10305  Pass the asmOption to the assembler
10306 \begin_inset LatexCommand \index{Options assembler}
10307
10308 \end_inset
10309
10310
10311 \begin_inset LatexCommand \index{Assembler options}
10312
10313 \end_inset
10314
10315 .
10316  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10317 \end_layout
10318
10319 \begin_layout List
10320 \labelwidthstring 00.00.0000
10321
10322 \series bold
10323 -
10324 \begin_inset ERT
10325 status collapsed
10326
10327 \begin_layout Standard
10328
10329
10330 \backslash
10331 /
10332 \end_layout
10333
10334 \end_inset
10335
10336 -std-sdcc89
10337 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10338
10339 \end_inset
10340
10341
10342 \series default
10343  Generally follow the C89 standard, but allow SDCC features that conflict
10344  with the standard (default).
10345 \end_layout
10346
10347 \begin_layout List
10348 \labelwidthstring 00.00.0000
10349
10350 \series bold
10351 -
10352 \begin_inset ERT
10353 status collapsed
10354
10355 \begin_layout Standard
10356
10357
10358 \backslash
10359 /
10360 \end_layout
10361
10362 \end_inset
10363
10364 -std-c89
10365 \begin_inset LatexCommand \index{-\/-std-c89}
10366
10367 \end_inset
10368
10369
10370 \series default
10371  Follow the C89 standard and disable SDCC features that conflict with the
10372  standard.
10373 \end_layout
10374
10375 \begin_layout List
10376 \labelwidthstring 00.00.0000
10377
10378 \series bold
10379 -
10380 \begin_inset ERT
10381 status collapsed
10382
10383 \begin_layout Standard
10384
10385
10386 \backslash
10387 /
10388 \end_layout
10389
10390 \end_inset
10391
10392 -std-sdcc99
10393 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10394
10395 \end_inset
10396
10397
10398 \series default
10399  Generally follow the C99 standard, but allow SDCC features that conflict
10400  with the standard (incomplete support).
10401 \end_layout
10402
10403 \begin_layout List
10404 \labelwidthstring 00.00.0000
10405
10406 \series bold
10407 -
10408 \begin_inset ERT
10409 status collapsed
10410
10411 \begin_layout Standard
10412
10413
10414 \backslash
10415 /
10416 \end_layout
10417
10418 \end_inset
10419
10420 -std-c99
10421 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10422
10423 \end_inset
10424
10425
10426 \series default
10427  Follow the C99 standard and disable SDCC features that conflict with the
10428  standard (incomplete support).
10429 \end_layout
10430
10431 \begin_layout List
10432 \labelwidthstring 00.00.0000
10433
10434 \series bold
10435 -
10436 \begin_inset ERT
10437 status collapsed
10438
10439 \begin_layout Standard
10440
10441
10442 \backslash
10443 /
10444 \end_layout
10445
10446 \end_inset
10447
10448 -codeseg
10449 \series default
10450
10451 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10452
10453 \end_inset
10454
10455 \InsetSpace ~
10456 <Name> The name to be used for the code
10457 \begin_inset LatexCommand \index{code}
10458
10459 \end_inset
10460
10461  segment, default CSEG.
10462  This is useful if you need to tell the compiler to put the code in a special
10463  segment so you can later on tell the linker to put this segment in a special
10464  place in memory.
10465  Can be used for instance when using bank switching to put the code in a
10466  bank.
10467 \end_layout
10468
10469 \begin_layout List
10470 \labelwidthstring 00.00.0000
10471
10472 \series bold
10473 -
10474 \begin_inset ERT
10475 status collapsed
10476
10477 \begin_layout Standard
10478
10479
10480 \backslash
10481 /
10482 \end_layout
10483
10484 \end_inset
10485
10486 -constseg
10487 \series default
10488
10489 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10490
10491 \end_inset
10492
10493 \InsetSpace ~
10494 <Name> The name to be used for the const
10495 \begin_inset LatexCommand \index{const}
10496
10497 \end_inset
10498
10499  segment, default CONST.
10500  This is useful if you need to tell the compiler to put the const data in
10501  a special segment so you can later on tell the linker to put this segment
10502  in a special place in memory.
10503  Can be used for instance when using bank switching to put the const data
10504  in a bank.
10505 \end_layout
10506
10507 \begin_layout List
10508 \labelwidthstring 00.00.0000
10509
10510 \series bold
10511 -
10512 \begin_inset ERT
10513 status collapsed
10514
10515 \begin_layout Standard
10516
10517
10518 \backslash
10519 /
10520 \end_layout
10521
10522 \end_inset
10523
10524 -fdollars-in-identifiers
10525 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10526
10527 \end_inset
10528
10529
10530 \series default
10531  Permit '$' as an identifier character.
10532 \end_layout
10533
10534 \begin_layout List
10535 \labelwidthstring 00.00.0000
10536
10537 \series bold
10538 -
10539 \begin_inset ERT
10540 status collapsed
10541
10542 \begin_layout Standard
10543
10544
10545 \backslash
10546 /
10547 \end_layout
10548
10549 \end_inset
10550
10551 -more-pedantic
10552 \series default
10553
10554 \begin_inset LatexCommand \index{-\/-more-pedantic}
10555
10556 \end_inset
10557
10558
10559 \begin_inset LatexCommand \index{pedantic}
10560
10561 \end_inset
10562
10563  Actually this is 
10564 \series bold
10565 \emph on
10566 not
10567 \series default
10568 \emph default
10569  a SDCC compiler option but if you want 
10570 \emph on
10571 more
10572 \emph default
10573  warnings you can use a separate tool dedicated to syntax checking like
10574  splint
10575 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10576
10577 \end_inset
10578
10579
10580 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10581
10582 \end_inset
10583
10584  
10585 \begin_inset LatexCommand \url{http://www.splint.org}
10586
10587 \end_inset
10588
10589 .
10590  To make your source files parseable by splint you will have to include
10591  
10592 \family sans
10593 lint.h
10594 \family default
10595
10596 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10597
10598 \end_inset
10599
10600  in your source file and add brackets around extended keywords (like 
10601 \family sans
10602
10603 \begin_inset Quotes sld
10604 \end_inset
10605
10606 __at\InsetSpace ~
10607
10608 \series bold
10609 (
10610 \series default
10611 0xab
10612 \series bold
10613 )
10614 \series default
10615
10616 \begin_inset Quotes srd
10617 \end_inset
10618
10619
10620 \family default
10621  and 
10622 \family sans
10623
10624 \begin_inset Quotes sld
10625 \end_inset
10626
10627 __interrupt\InsetSpace ~
10628 (2)
10629 \begin_inset Quotes srd
10630 \end_inset
10631
10632
10633 \family default
10634 ).
10635  
10636 \newline
10637 Splint has an excellent on line manual at 
10638 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10639
10640 \end_inset
10641
10642  and it's capabilities go beyond pure syntax checking.
10643  You'll need to tell splint the location of SDCC's include files so a typical
10644  command line could look like this: 
10645 \newline
10646
10647 \family sans
10648 splint\InsetSpace ~
10649 -I\InsetSpace ~
10650 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10651 \InsetSpace ~
10652 myprogram.c
10653 \end_layout
10654
10655 \begin_layout List
10656 \labelwidthstring 00.00.0000
10657
10658 \series bold
10659 -
10660 \begin_inset ERT
10661 status collapsed
10662
10663 \begin_layout Standard
10664
10665
10666 \backslash
10667 /
10668 \end_layout
10669
10670 \end_inset
10671
10672 -short-is-8bits
10673 \series default
10674
10675 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10676
10677 \end_inset
10678
10679
10680 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10681
10682 \end_inset
10683
10684  Treat short as 8-bit (for backward compatibility with older versions of
10685  compiler - see section 
10686 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10687
10688 \end_inset
10689
10690 )
10691 \end_layout
10692
10693 \begin_layout Standard
10694 \begin_inset VSpace bigskip
10695 \end_inset
10696
10697
10698 \end_layout
10699
10700 \begin_layout Subsection
10701 Intermediate Dump Options
10702 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10703
10704 \end_inset
10705
10706
10707 \begin_inset LatexCommand \index{Options intermediate dump}
10708
10709 \end_inset
10710
10711
10712 \begin_inset LatexCommand \index{Intermediate dump options}
10713
10714 \end_inset
10715
10716
10717 \end_layout
10718
10719 \begin_layout Standard
10720 The following options are provided for the purpose of retargetting and debugging
10721  the compiler.
10722  They provide a means to dump the intermediate code (iCode
10723 \begin_inset LatexCommand \index{iCode}
10724
10725 \end_inset
10726
10727 ) generated by the compiler in human readable form at various stages of
10728  the compilation process.
10729  More on iCodes see chapter 
10730 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10731
10732 \end_inset
10733
10734  
10735 \begin_inset Quotes srd
10736 \end_inset
10737
10738 The anatomy of the compiler
10739 \begin_inset Quotes srd
10740 \end_inset
10741
10742 .
10743 \end_layout
10744
10745 \begin_layout List
10746 \labelwidthstring 00.00.0000
10747
10748 \series bold
10749 -
10750 \begin_inset ERT
10751 status collapsed
10752
10753 \begin_layout Standard
10754
10755
10756 \backslash
10757 /
10758 \end_layout
10759
10760 \end_inset
10761
10762 -dumpraw
10763 \begin_inset LatexCommand \index{-\/-dumpraw}
10764
10765 \end_inset
10766
10767
10768 \series default
10769  This option will cause the compiler to dump the intermediate code into
10770  a file of named 
10771 \emph on
10772 <source filename>.dumpraw
10773 \emph default
10774  just after the intermediate code has been generated for a function, i.e.
10775  before any optimizations are done.
10776  The basic blocks
10777 \begin_inset LatexCommand \index{Basic blocks}
10778
10779 \end_inset
10780
10781  at this stage ordered in the depth first number, so they may not be in
10782  sequence of execution.
10783 \end_layout
10784
10785 \begin_layout List
10786 \labelwidthstring 00.00.0000
10787
10788 \series bold
10789 -
10790 \begin_inset ERT
10791 status collapsed
10792
10793 \begin_layout Standard
10794
10795
10796 \backslash
10797 /
10798 \end_layout
10799
10800 \end_inset
10801
10802 -dumpgcse
10803 \begin_inset LatexCommand \index{-\/-dumpgcse}
10804
10805 \end_inset
10806
10807
10808 \series default
10809  Will create a dump of iCodes, after global subexpression elimination
10810 \begin_inset LatexCommand \index{Global subexpression elimination}
10811
10812 \end_inset
10813
10814 , into a file named 
10815 \emph on
10816 <source filename>.dumpgcse.
10817 \end_layout
10818
10819 \begin_layout List
10820 \labelwidthstring 00.00.0000
10821
10822 \series bold
10823 -
10824 \begin_inset ERT
10825 status collapsed
10826
10827 \begin_layout Standard
10828
10829
10830 \backslash
10831 /
10832 \end_layout
10833
10834 \end_inset
10835
10836 -dumpdeadcode
10837 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10838
10839 \end_inset
10840
10841
10842 \series default
10843  Will create a dump of iCodes, after deadcode elimination
10844 \begin_inset LatexCommand \index{Dead-code elimination}
10845
10846 \end_inset
10847
10848 , into a file named 
10849 \emph on
10850 <source filename>.dumpdeadcode.
10851 \end_layout
10852
10853 \begin_layout List
10854 \labelwidthstring 00.00.0000
10855
10856 \series bold
10857 -
10858 \begin_inset ERT
10859 status collapsed
10860
10861 \begin_layout Standard
10862
10863
10864 \backslash
10865 /
10866 \end_layout
10867
10868 \end_inset
10869
10870 -dumploop
10871 \begin_inset LatexCommand \index{-\/-dumploop}
10872
10873 \end_inset
10874
10875
10876 \series default
10877 \size large
10878  
10879 \size default
10880 Will create a dump of iCodes, after loop optimizations
10881 \begin_inset LatexCommand \index{Loop optimization}
10882
10883 \end_inset
10884
10885 , into a file named 
10886 \emph on
10887 <source filename>.dumploop.
10888 \end_layout
10889
10890 \begin_layout List
10891 \labelwidthstring 00.00.0000
10892
10893 \series bold
10894 -
10895 \begin_inset ERT
10896 status collapsed
10897
10898 \begin_layout Standard
10899
10900
10901 \backslash
10902 /
10903 \end_layout
10904
10905 \end_inset
10906
10907 -dumprange
10908 \begin_inset LatexCommand \index{-\/-dumprange}
10909
10910 \end_inset
10911
10912
10913 \series default
10914 \size large
10915  
10916 \size default
10917 Will create a dump of iCodes, after live range analysis
10918 \begin_inset LatexCommand \index{Live range analysis}
10919
10920 \end_inset
10921
10922 , into a file named 
10923 \emph on
10924 <source filename>.dumprange.
10925 \end_layout
10926
10927 \begin_layout List
10928 \labelwidthstring 00.00.0000
10929
10930 \series bold
10931 -
10932 \begin_inset ERT
10933 status collapsed
10934
10935 \begin_layout Standard
10936
10937
10938 \backslash
10939 /
10940 \end_layout
10941
10942 \end_inset
10943
10944 -dumlrange
10945 \begin_inset LatexCommand \index{-\/-dumlrange}
10946
10947 \end_inset
10948
10949
10950 \series default
10951  Will dump the life ranges
10952 \begin_inset LatexCommand \index{Live range analysis}
10953
10954 \end_inset
10955
10956  for all symbols.
10957 \end_layout
10958
10959 \begin_layout List
10960 \labelwidthstring 00.00.0000
10961
10962 \series bold
10963 -
10964 \begin_inset ERT
10965 status collapsed
10966
10967 \begin_layout Standard
10968
10969
10970 \backslash
10971 /
10972 \end_layout
10973
10974 \end_inset
10975
10976 -dumpregassign
10977 \begin_inset LatexCommand \index{-\/-dumpregassign}
10978
10979 \end_inset
10980
10981
10982 \bar under
10983  
10984 \series default
10985 \bar default
10986 Will create a dump of iCodes, after register assignment
10987 \begin_inset LatexCommand \index{Register assignment}
10988
10989 \end_inset
10990
10991 , into a file named 
10992 \emph on
10993 <source filename>.dumprassgn.
10994 \end_layout
10995
10996 \begin_layout List
10997 \labelwidthstring 00.00.0000
10998
10999 \series bold
11000 -
11001 \begin_inset ERT
11002 status collapsed
11003
11004 \begin_layout Standard
11005
11006
11007 \backslash
11008 /
11009 \end_layout
11010
11011 \end_inset
11012
11013 -dumplrange
11014 \begin_inset LatexCommand \index{-\/-dumplrange}
11015
11016 \end_inset
11017
11018
11019 \series default
11020  Will create a dump of the live ranges of iTemp's
11021 \end_layout
11022
11023 \begin_layout List
11024 \labelwidthstring 00.00.0000
11025
11026 \series bold
11027 -
11028 \begin_inset ERT
11029 status collapsed
11030
11031 \begin_layout Standard
11032
11033
11034 \backslash
11035 /
11036 \end_layout
11037
11038 \end_inset
11039
11040 -dumpall
11041 \begin_inset LatexCommand \index{-\/-dumpall}
11042
11043 \end_inset
11044
11045
11046 \size large
11047 \bar under
11048  
11049 \series default
11050 \size default
11051 \bar default
11052 Will cause all the above mentioned dumps to be created.
11053 \end_layout
11054
11055 \begin_layout Standard
11056 \begin_inset VSpace bigskip
11057 \end_inset
11058
11059
11060 \end_layout
11061
11062 \begin_layout Subsection
11063 Redirecting output on Windows Shells
11064 \end_layout
11065
11066 \begin_layout Standard
11067 By default SDCC writes its error messages to 
11068 \begin_inset Quotes sld
11069 \end_inset
11070
11071 standard error
11072 \begin_inset Quotes srd
11073 \end_inset
11074
11075 .
11076  To force all messages to 
11077 \begin_inset Quotes sld
11078 \end_inset
11079
11080 standard output
11081 \begin_inset Quotes srd
11082 \end_inset
11083
11084  use 
11085 \series bold
11086 -
11087 \series default
11088 \emph on
11089
11090 \begin_inset ERT
11091 status collapsed
11092
11093 \begin_layout Standard
11094
11095
11096 \backslash
11097 /
11098 \end_layout
11099
11100 \end_inset
11101
11102
11103 \series bold
11104 \emph default
11105 -
11106 \series default
11107 use-stdout
11108 \begin_inset LatexCommand \index{-\/-use-stdout}
11109
11110 \end_inset
11111
11112 .
11113  Additionally, if you happen to have visual studio installed in your windows
11114  machine, you can use it to compile your sources using a custom build and
11115  the SDCC -
11116 \emph on
11117
11118 \begin_inset ERT
11119 status collapsed
11120
11121 \begin_layout Standard
11122
11123
11124 \backslash
11125 /
11126 \end_layout
11127
11128 \end_inset
11129
11130
11131 \emph default
11132 -vc
11133 \begin_inset LatexCommand \index{-\/-vc}
11134
11135 \end_inset
11136
11137  option.
11138  Something like this should work:
11139 \newline
11140
11141 \newline
11142
11143 \series bold
11144 c:
11145 \backslash
11146 sdcc
11147 \backslash
11148 bin
11149 \backslash
11150 sdcc.exe -
11151 \series default
11152 \emph on
11153
11154 \begin_inset ERT
11155 status collapsed
11156
11157 \begin_layout Standard
11158
11159
11160 \backslash
11161 /
11162 \end_layout
11163
11164 \end_inset
11165
11166
11167 \series bold
11168 \emph default
11169 -vc -
11170 \series default
11171 \emph on
11172
11173 \begin_inset ERT
11174 status collapsed
11175
11176 \begin_layout Standard
11177
11178
11179 \backslash
11180 /
11181 \end_layout
11182
11183 \end_inset
11184
11185
11186 \series bold
11187 \emph default
11188 -model-large -c $(InputPath)
11189 \series default
11190
11191 \begin_inset VSpace bigskip
11192 \end_inset
11193
11194
11195 \end_layout
11196
11197 \begin_layout Section
11198 Environment variables
11199 \begin_inset LatexCommand \index{Environment variables}
11200
11201 \end_inset
11202
11203
11204 \end_layout
11205
11206 \begin_layout Standard
11207 SDCC recognizes the following environment variables:
11208 \end_layout
11209
11210 \begin_layout List
11211 \labelwidthstring 00.00.0000
11212
11213 \series bold
11214 SDCC_LEAVE_SIGNALS
11215 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11216
11217 \end_inset
11218
11219
11220 \series default
11221  SDCC installs a signal handler
11222 \begin_inset LatexCommand \index{signal handler}
11223
11224 \end_inset
11225
11226  to be able to delete temporary files after an user break (^C) or an exception.
11227  If this environment variable is set, SDCC won't install the signal handler
11228  in order to be able to debug SDCC.
11229 \end_layout
11230
11231 \begin_layout List
11232 \labelwidthstring 00.00.0000
11233
11234 \series bold
11235 TMP,\InsetSpace ~
11236 TEMP,\InsetSpace ~
11237 TMPDIR
11238 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11239
11240 \end_inset
11241
11242
11243 \series default
11244  Path, where temporary files will be created.
11245  The order of the variables is the search order.
11246  In a standard *nix environment these variables are not set, and there's
11247  no need to set them.
11248  On Windows it's recommended to set one of them.
11249 \end_layout
11250
11251 \begin_layout List
11252 \labelwidthstring 00.00.0000
11253
11254 \series bold
11255 SDCC_HOME
11256 \begin_inset LatexCommand \index{SDCC\_HOME}
11257
11258 \end_inset
11259
11260
11261 \series default
11262  Path, see section 
11263 \begin_inset LatexCommand \ref{sub:Install-paths}
11264
11265 \end_inset
11266
11267 \InsetSpace ~
11268
11269 \begin_inset Quotes sld
11270 \end_inset
11271
11272  Install Paths
11273 \begin_inset Quotes srd
11274 \end_inset
11275
11276 .
11277 \end_layout
11278
11279 \begin_layout List
11280 \labelwidthstring 00.00.0000
11281
11282 \series bold
11283 SDCC_INCLUDE
11284 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11285
11286 \end_inset
11287
11288
11289 \series default
11290  Path, see section 
11291 \begin_inset LatexCommand \ref{sub:Search-Paths}
11292
11293 \end_inset
11294
11295 \InsetSpace ~
11296
11297 \begin_inset Quotes sld
11298 \end_inset
11299
11300 Search Paths
11301 \begin_inset Quotes srd
11302 \end_inset
11303
11304 .
11305 \end_layout
11306
11307 \begin_layout List
11308 \labelwidthstring 00.00.0000
11309
11310 \series bold
11311 SDCC_LIB
11312 \begin_inset LatexCommand \index{SDCC\_LIB}
11313
11314 \end_inset
11315
11316
11317 \series default
11318  Path, see section 
11319 \begin_inset LatexCommand \ref{sub:Search-Paths}
11320
11321 \end_inset
11322
11323 \InsetSpace ~
11324
11325 \begin_inset Quotes sld
11326 \end_inset
11327
11328 Search Paths
11329 \begin_inset Quotes srd
11330 \end_inset
11331
11332 ..
11333 \end_layout
11334
11335 \begin_layout Standard
11336 There are some more environment variables recognized by SDCC, but these
11337  are solely used for debugging purposes.
11338  They can change or disappear very quickly, and will never be documented.
11339 \begin_inset VSpace bigskip
11340 \end_inset
11341
11342
11343 \end_layout
11344
11345 \begin_layout Section
11346 Storage Class Language Extensions
11347 \end_layout
11348
11349 \begin_layout Subsection
11350 MCS51/DS390 Storage Class
11351 \begin_inset LatexCommand \index{Storage class}
11352
11353 \end_inset
11354
11355  Language Extensions
11356 \end_layout
11357
11358 \begin_layout Standard
11359 In addition to the ANSI storage classes SDCC allows the following MCS51
11360  specific storage classes:
11361 \end_layout
11362
11363 \begin_layout Subsubsection
11364 data
11365 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11366
11367 \end_inset
11368
11369
11370 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11371
11372 \end_inset
11373
11374  / near
11375 \begin_inset LatexCommand \index{near (storage class)}
11376
11377 \end_inset
11378
11379
11380 \begin_inset LatexCommand \index{\_\_near (storage class)}
11381
11382 \end_inset
11383
11384
11385 \end_layout
11386
11387 \begin_layout Standard
11388 This is the 
11389 \series bold
11390 default
11391 \series default
11392  storage class for the Small Memory model (
11393 \emph on
11394 data
11395 \emph default
11396  and 
11397 \emph on
11398 near
11399 \emph default
11400  or the more ANSI-C compliant forms 
11401 \emph on
11402 __data
11403 \emph default
11404  and 
11405 \emph on
11406 __near
11407 \emph default
11408  can be used synonymously).
11409  Variables declared with this storage class will be allocated in the directly
11410  addressable portion of the internal RAM of a 8051, e.g.:
11411 \end_layout
11412
11413 \begin_layout Verse
11414
11415 \family typewriter
11416 __data unsigned char test_data;
11417 \end_layout
11418
11419 \begin_layout Standard
11420 Writing 0x01 to this variable generates the assembly code:
11421 \end_layout
11422
11423 \begin_layout Verse
11424
11425 \family typewriter
11426 75*00 01\InsetSpace ~
11427 \InsetSpace ~
11428 \InsetSpace ~
11429 mov\InsetSpace ~
11430 \InsetSpace ~
11431 _test_data,#0x01
11432 \end_layout
11433
11434 \begin_layout Subsubsection
11435 xdata
11436 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11437
11438 \end_inset
11439
11440
11441 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11442
11443 \end_inset
11444
11445  / far
11446 \begin_inset LatexCommand \index{far (storage class)}
11447
11448 \end_inset
11449
11450
11451 \begin_inset LatexCommand \index{\_\_far (storage class)}
11452
11453 \end_inset
11454
11455
11456 \end_layout
11457
11458 \begin_layout Standard
11459 Variables declared with this storage class will be placed in the external
11460  RAM.
11461  This is the 
11462 \series bold
11463 default
11464 \series default
11465  storage class for the Large Memory model, e.g.:
11466 \end_layout
11467
11468 \begin_layout Verse
11469
11470 \family typewriter
11471 __xdata unsigned char test_xdata;
11472 \end_layout
11473
11474 \begin_layout Standard
11475 Writing 0x01 to this variable generates the assembly code:
11476 \end_layout
11477
11478 \begin_layout Verse
11479
11480 \family typewriter
11481 90s00r00\InsetSpace ~
11482 \InsetSpace ~
11483 \InsetSpace ~
11484 mov\InsetSpace ~
11485 \InsetSpace ~
11486 dptr,#_test_xdata 
11487 \newline
11488 74\InsetSpace ~
11489 01\InsetSpace ~
11490 \InsetSpace ~
11491 \InsetSpace ~
11492 \InsetSpace ~
11493 \InsetSpace ~
11494 \InsetSpace ~
11495 mov\InsetSpace ~
11496 \InsetSpace ~
11497 a,#0x01 
11498 \newline
11499 F0\InsetSpace ~
11500 \InsetSpace ~
11501 \InsetSpace ~
11502 \InsetSpace ~
11503 \InsetSpace ~
11504 \InsetSpace ~
11505 \InsetSpace ~
11506 \InsetSpace ~
11507 \InsetSpace ~
11508 movx\InsetSpace ~
11509 @dptr,a 
11510 \end_layout
11511
11512 \begin_layout Subsubsection
11513 idata
11514 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11515
11516 \end_inset
11517
11518
11519 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11520
11521 \end_inset
11522
11523
11524 \end_layout
11525
11526 \begin_layout Standard
11527 Variables declared with this storage class will be allocated into the indirectly
11528  addressable portion of the internal ram of a 8051, e.g.:
11529 \end_layout
11530
11531 \begin_layout Verse
11532
11533 \family typewriter
11534 __idata unsigned char test_idata;
11535 \end_layout
11536
11537 \begin_layout Standard
11538 Writing 0x01 to this variable generates the assembly code:
11539 \end_layout
11540
11541 \begin_layout Verse
11542
11543 \family typewriter
11544 78r00\InsetSpace ~
11545 \InsetSpace ~
11546 \InsetSpace ~
11547 \InsetSpace ~
11548 \InsetSpace ~
11549 \InsetSpace ~
11550 \InsetSpace ~
11551 mov\InsetSpace ~
11552 \InsetSpace ~
11553 r0,#_test_idata
11554 \newline
11555 76\InsetSpace ~
11556 01\InsetSpace ~
11557 \InsetSpace ~
11558 \InsetSpace ~
11559 \InsetSpace ~
11560 \InsetSpace ~
11561 \InsetSpace ~
11562 \InsetSpace ~
11563 mov\InsetSpace ~
11564 \InsetSpace ~
11565 @r0,#0x01
11566 \end_layout
11567
11568 \begin_layout Standard
11569 Please note, the first 128 byte of idata physically access the same RAM
11570  as the data memory.
11571  The original 8051 had 128 byte idata memory, nowadays most devices have
11572  256 byte idata memory.
11573  The stack
11574 \begin_inset LatexCommand \index{stack}
11575
11576 \end_inset
11577
11578  is located in idata memory.
11579 \end_layout
11580
11581 \begin_layout Subsubsection
11582 pdata
11583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11584
11585 \end_inset
11586
11587
11588 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11589
11590 \end_inset
11591
11592
11593 \end_layout
11594
11595 \begin_layout Standard
11596 Paged xdata access is just as straightforward as using the other addressing
11597  modes of a 8051.
11598  It is typically located at the start of xdata and has a maximum size of
11599  256 bytes.
11600  The following example writes 0x01 to the pdata variable.
11601  Please note, pdata access physically accesses xdata memory.
11602  The high byte of the address is determined by port P2 
11603 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11604
11605 \end_inset
11606
11607 (or in case of some 8051 variants by a separate Special Function Register,
11608  see section 
11609 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11610
11611 \end_inset
11612
11613 ).
11614  This is the 
11615 \series bold
11616 default
11617 \series default
11618  storage class for the Medium Memory model, e.g.:
11619 \end_layout
11620
11621 \begin_layout Verse
11622
11623 \family typewriter
11624 __pdata unsigned char test_pdata;
11625 \end_layout
11626
11627 \begin_layout Standard
11628 Writing 0x01 to this variable generates the assembly code:
11629 \end_layout
11630
11631 \begin_layout Verse
11632
11633 \family typewriter
11634 78r00\InsetSpace ~
11635 \InsetSpace ~
11636 \InsetSpace ~
11637 \InsetSpace ~
11638 \InsetSpace ~
11639 \InsetSpace ~
11640 mov r0,#_test_pdata
11641 \newline
11642 74 01\InsetSpace ~
11643 \InsetSpace ~
11644 \InsetSpace ~
11645 \InsetSpace ~
11646 \InsetSpace ~
11647 \InsetSpace ~
11648 mov a,#0x01 
11649 \newline
11650 F2\InsetSpace ~
11651 \InsetSpace ~
11652 \InsetSpace ~
11653 \InsetSpace ~
11654 \InsetSpace ~
11655 \InsetSpace ~
11656 \InsetSpace ~
11657 \InsetSpace ~
11658 \InsetSpace ~
11659 movx @r0,a
11660 \end_layout
11661
11662 \begin_layout Standard
11663 If the -
11664 \begin_inset ERT
11665 status collapsed
11666
11667 \begin_layout Standard
11668
11669
11670 \backslash
11671 /
11672 \end_layout
11673
11674 \end_inset
11675
11676 -xstack
11677 \begin_inset LatexCommand \index{-\/-xstack}
11678
11679 \end_inset
11680
11681  option is used the pdata memory area is followed by the xstack memory area
11682  and the sum of their sizes is limited to 256 bytes.
11683 \end_layout
11684
11685 \begin_layout Subsubsection
11686 code
11687 \begin_inset LatexCommand \index{code}
11688
11689 \end_inset
11690
11691
11692 \begin_inset LatexCommand \index{\_\_code}
11693
11694 \end_inset
11695
11696
11697 \end_layout
11698
11699 \begin_layout Standard
11700 'Variables' declared with this storage class will be placed in the code
11701  memory:
11702 \end_layout
11703
11704 \begin_layout Verse
11705
11706 \family typewriter
11707 __code unsigned char test_code;
11708 \end_layout
11709
11710 \begin_layout Standard
11711 Read access to this variable generates the assembly code:
11712 \end_layout
11713
11714 \begin_layout Verse
11715
11716 \family typewriter
11717 90s00r6F\InsetSpace ~
11718 \InsetSpace ~
11719 \InsetSpace ~
11720 mov dptr,#_test_code
11721 \newline
11722 E4\InsetSpace ~
11723 \InsetSpace ~
11724 \InsetSpace ~
11725 \InsetSpace ~
11726 \InsetSpace ~
11727 \InsetSpace ~
11728 \InsetSpace ~
11729 \InsetSpace ~
11730 \InsetSpace ~
11731 clr a
11732 \newline
11733 93\InsetSpace ~
11734 \InsetSpace ~
11735 \InsetSpace ~
11736 \InsetSpace ~
11737 \InsetSpace ~
11738 \InsetSpace ~
11739 \InsetSpace ~
11740 \InsetSpace ~
11741 \InsetSpace ~
11742 movc a,@a+dptr 
11743 \end_layout
11744
11745 \begin_layout Standard
11746
11747 \family typewriter
11748 char
11749 \family default
11750  indexed arrays of characters in code memory can be accessed efficiently:
11751 \end_layout
11752
11753 \begin_layout Verse
11754
11755 \family typewriter
11756 __code char test_array[] = {'c','h','e','a','p'}; 
11757 \end_layout
11758
11759 \begin_layout Standard
11760 Read access to this array using an 8-bit unsigned index generates the assembly
11761  code:
11762 \end_layout
11763
11764 \begin_layout Verse
11765
11766 \family typewriter
11767 E5*00\InsetSpace ~
11768 \InsetSpace ~
11769 \InsetSpace ~
11770 \InsetSpace ~
11771 \InsetSpace ~
11772 \InsetSpace ~
11773 mov a,_index 
11774 \end_layout
11775
11776 \begin_layout Verse
11777
11778 \family typewriter
11779 90s00r41\InsetSpace ~
11780 \InsetSpace ~
11781 \InsetSpace ~
11782 mov dptr,#_test_array
11783 \end_layout
11784
11785 \begin_layout Verse
11786
11787 \family typewriter
11788 93\InsetSpace ~
11789 \InsetSpace ~
11790 \InsetSpace ~
11791 \InsetSpace ~
11792 \InsetSpace ~
11793 \InsetSpace ~
11794 \InsetSpace ~
11795 \InsetSpace ~
11796 \InsetSpace ~
11797 movc a,@a+dptr 
11798 \end_layout
11799
11800 \begin_layout Subsubsection
11801 bit
11802 \begin_inset LatexCommand \index{bit}
11803
11804 \end_inset
11805
11806
11807 \begin_inset LatexCommand \index{\_\_bit}
11808
11809 \end_inset
11810
11811
11812 \end_layout
11813
11814 \begin_layout Standard
11815 This is a data-type and a storage class specifier.
11816  When a variable is declared as a bit, it is allocated into the bit addressable
11817  memory of 8051, e.g.:
11818 \end_layout
11819
11820 \begin_layout Verse
11821
11822 \family typewriter
11823 __bit test_bit;
11824 \end_layout
11825
11826 \begin_layout Standard
11827 Writing 1 to this variable generates the assembly code:
11828 \end_layout
11829
11830 \begin_layout Verse
11831
11832 \family typewriter
11833 D2*00\InsetSpace ~
11834 \InsetSpace ~
11835 \InsetSpace ~
11836 \InsetSpace ~
11837 \InsetSpace ~
11838 \InsetSpace ~
11839 \InsetSpace ~
11840 setb\InsetSpace ~
11841 _test_bit
11842 \end_layout
11843
11844 \begin_layout Standard
11845 The bit addressable memory consists of 128 bits which are located from 0x20
11846  to 0x2f in data memory.
11847  
11848 \newline
11849 Apart from this 8051 specific storage class most architectures support
11850  ANSI-C bitfields
11851 \begin_inset LatexCommand \index{bitfields}
11852
11853 \end_inset
11854
11855
11856 \begin_inset Foot
11857 status open
11858
11859 \begin_layout Standard
11860 Not really meant as examples, but nevertheless showing what bitfields are
11861  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11862 \end_layout
11863
11864 \end_inset
11865
11866 .
11867  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11868  signed modifier are implemented as unsigned.
11869 \end_layout
11870
11871 \begin_layout Subsubsection
11872 sfr
11873 \begin_inset LatexCommand \index{sfr}
11874
11875 \end_inset
11876
11877
11878 \begin_inset LatexCommand \index{\_\_sfr}
11879
11880 \end_inset
11881
11882  / sfr16
11883 \begin_inset LatexCommand \index{sfr16}
11884
11885 \end_inset
11886
11887
11888 \begin_inset LatexCommand \index{\_\_sfr16}
11889
11890 \end_inset
11891
11892  / sfr32
11893 \begin_inset LatexCommand \index{sfr32}
11894
11895 \end_inset
11896
11897
11898 \begin_inset LatexCommand \index{\_\_sfr32}
11899
11900 \end_inset
11901
11902  / sbit
11903 \begin_inset LatexCommand \index{\_\_sbit}
11904
11905 \end_inset
11906
11907
11908 \begin_inset LatexCommand \index{sbit}
11909
11910 \end_inset
11911
11912
11913 \end_layout
11914
11915 \begin_layout Standard
11916 Like the bit keyword, 
11917 \emph on
11918 sfr / sfr16 / sfr32 / sbit 
11919 \emph default
11920 signify both a data-type and storage class, they are used to describe the
11921  
11922 \emph on
11923 s
11924 \emph default
11925 pecial 
11926 \emph on
11927 f
11928 \emph default
11929 unction 
11930 \emph on
11931 r
11932 \emph default
11933 egisters and 
11934 \emph on
11935 s
11936 \emph default
11937 pecial 
11938 \emph on
11939 bit
11940 \emph default
11941  variables of a 8051, eg:
11942 \end_layout
11943
11944 \begin_layout Verse
11945
11946 \family typewriter
11947 __sfr __at
11948 \begin_inset LatexCommand \index{at}
11949
11950 \end_inset
11951
11952
11953 \begin_inset LatexCommand \index{\_\_at}
11954
11955 \end_inset
11956
11957  (0x80) P0;\InsetSpace ~
11958  /* special function register P0 at location 0x80 */
11959 \newline
11960
11961 \newline
11962 /* 16 bit
11963  special function register combination for timer 0
11964 \newline
11965 \InsetSpace ~
11966 \InsetSpace ~
11967  with the high byte at
11968  location 0x8C and the low byte at location 0x8A */
11969 \newline
11970 __sfr16 __at (0x8C8A)
11971  TMR0;
11972 \newline
11973
11974 \newline
11975 __sbit __at
11976 \begin_inset LatexCommand \index{at}
11977
11978 \end_inset
11979
11980
11981 \begin_inset LatexCommand \index{\_\_at}
11982
11983 \end_inset
11984
11985  (0xd7) CY;\InsetSpace ~
11986  /* CY (Carry Flag
11987 \begin_inset LatexCommand \index{Flags}
11988
11989 \end_inset
11990
11991
11992 \begin_inset LatexCommand \index{Carry flag}
11993
11994 \end_inset
11995
11996 ) */
11997 \end_layout
11998
11999 \begin_layout Standard
12000 Special function registers which are located on an address dividable by
12001  8 are bit-addressable, an
12002 \emph on
12003  sbit
12004 \emph default
12005  addresses a specific bit within these sfr.
12006 \newline
12007 16 Bit and 32 bit special function
12008  register combinations which require a certain access order are better not
12009  declared using 
12010 \emph on
12011 sfr16
12012 \emph default
12013  or 
12014 \emph on
12015 sfr32.
12016
12017 \emph default
12018  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12019  this is not guaranteed.
12020 \newline
12021
12022 \end_layout
12023
12024 \begin_layout Standard
12025 Please note, if you use a header file which was written for another compiler
12026  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12027  likely be 
12028 \emph on
12029 not 
12030 \emph default
12031 compatible.
12032  Specifically the syntax 
12033 \family typewriter
12034 \InsetSpace ~
12035 sfr P0 = 0x80;\InsetSpace ~
12036
12037 \family default
12038  is compiled 
12039 \emph on
12040 without warning
12041 \emph default
12042  by SDCC to an assignment of 0x80 to a variable called P0 
12043 \family typewriter
12044
12045 \begin_inset Marginal
12046 status collapsed
12047
12048 \begin_layout Standard
12049
12050 \series bold
12051 \InsetSpace ~
12052 !
12053 \end_layout
12054
12055 \end_inset
12056
12057 .
12058  
12059 \family default
12060 Nevertheless it is possible to write header files
12061 \begin_inset LatexCommand \index{Header files}
12062
12063 \end_inset
12064
12065
12066 \begin_inset LatexCommand \index{Include files}
12067
12068 \end_inset
12069
12070  which can be shared among different compilers (see section 
12071 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12072
12073 \end_inset
12074
12075 ).
12076  
12077 \end_layout
12078
12079 \begin_layout Subsubsection
12080 Pointers
12081 \begin_inset LatexCommand \index{Pointer}
12082
12083 \end_inset
12084
12085  to MCS51/DS390 specific memory spaces
12086 \end_layout
12087
12088 \begin_layout Standard
12089 SDCC allows (via language extensions) pointers to explicitly point to any
12090  of the memory spaces
12091 \begin_inset LatexCommand \index{Memory model}
12092
12093 \end_inset
12094
12095  of the 8051.
12096  In addition to the explicit pointers, the compiler uses (by default) generic
12097  pointers which can be used to point to any of the memory spaces.
12098 \newline
12099
12100 \newline
12101 Pointer
12102  declaration examples:
12103 \end_layout
12104
12105 \begin_layout Verse
12106
12107 \family typewriter
12108 /* pointer physically in internal ram pointing to object in external ram
12109  */ 
12110 \newline
12111 __xdata unsigned char * __data p;
12112 \newline
12113
12114 \newline
12115 /* pointer physically in external ram
12116  pointing to object in internal ram */ 
12117 \newline
12118 __data unsigned char * __xdata p;
12119 \newline
12120
12121 \newline
12122 /*
12123  pointer physically in code rom pointing to data in xdata space */ 
12124 \newline
12125 __xdata
12126  unsigned char * __code p;
12127 \newline
12128
12129 \newline
12130 /* pointer physically in code space pointing to
12131  data in code space */ 
12132 \newline
12133 __code unsigned char * __code p;
12134 \newline
12135
12136 \newline
12137 /* generic pointer
12138  physically located in xdata space */
12139 \newline
12140 unsigned char * __xdata p;
12141 \newline
12142
12143 \newline
12144 /* generic
12145  pointer physically located in default memory space */
12146 \newline
12147 unsigned char * p;
12148 \newline
12149
12150 \newline
12151 /*
12152  the following is a function pointer
12153 \begin_inset LatexCommand \index{function pointer}
12154
12155 \end_inset
12156
12157  physically located in data space */
12158 \newline
12159 char (* __data fp)(void);
12160 \end_layout
12161
12162 \begin_layout Standard
12163 Well you get the idea.
12164  
12165 \newline
12166
12167 \newline
12168 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12169 \emph on
12170 generic
12171 \emph default
12172  pointers.
12173  
12174 \size small
12175
12176 \newline
12177
12178 \newline
12179
12180 \size default
12181 The highest order byte of the 
12182 \emph on
12183 generic
12184 \emph default
12185  pointers contains the data space information.
12186  Assembler support routines are called whenever data is stored or retrieved
12187  using 
12188 \emph on
12189 generic
12190 \emph default
12191  pointers.
12192  These are useful for developing reusable library
12193 \begin_inset LatexCommand \index{Libraries}
12194
12195 \end_inset
12196
12197  routines.
12198  Explicitly specifying the pointer
12199 \begin_inset LatexCommand \index{pointer}
12200
12201 \end_inset
12202
12203  type will generate the most efficient code.
12204 \end_layout
12205
12206 \begin_layout Subsubsection
12207 Notes on MCS51 memory
12208 \begin_inset LatexCommand \index{MCS51 memory}
12209
12210 \end_inset
12211
12212  layout
12213 \end_layout
12214
12215 \begin_layout Standard
12216 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12217  RAM memory which is structured as follows:
12218 \newline
12219
12220 \newline
12221 - Bytes 00-1F - 32 bytes to hold
12222  up to 4 banks of the registers R0 to R7, 
12223 \newline
12224 - Bytes 20-2F - 16 bytes to hold
12225  128 bit
12226 \begin_inset LatexCommand \index{bit}
12227
12228 \end_inset
12229
12230  variables and, 
12231 \newline
12232 - Bytes 30-7F - 80 bytes for general purpose use.
12233 \newline
12234
12235 \end_layout
12236
12237 \begin_layout Standard
12238 Additionally some members of the MCS51 family may have up to 128 bytes of
12239  additional, indirectly addressable, internal RAM memory (
12240 \emph on
12241 idata
12242 \emph default
12243
12244 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12245
12246 \end_inset
12247
12248
12249 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12250
12251 \end_inset
12252
12253 ).
12254  Furthermore, some chips may have some built in external memory (
12255 \emph on
12256 xdata
12257 \emph default
12258
12259 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12265
12266 \end_inset
12267
12268 ) which should not be confused with the internal, directly addressable RAM
12269  memory (
12270 \emph on
12271 data
12272 \emph default
12273
12274 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12275
12276 \end_inset
12277
12278
12279 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12280
12281 \end_inset
12282
12283 ).
12284  Sometimes this built in 
12285 \emph on
12286 xdata
12287 \emph default
12288  memory has to be activated before using it (you can probably find this
12289  information on the datasheet of the microcontroller your are using, see
12290  also section 
12291 \begin_inset LatexCommand \ref{sub:Startup-Code}
12292
12293 \end_inset
12294
12295 \InsetSpace ~
12296 Startup-Code).
12297 \end_layout
12298
12299 \begin_layout Standard
12300 Normally SDCC will only use the first bank
12301 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12302
12303 \end_inset
12304
12305  of registers (register bank 0), but it is possible to specify that other
12306  banks of registers (keyword 
12307 \emph on
12308 using
12309 \emph default
12310  
12311 \emph on
12312
12313 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12314
12315 \end_inset
12316
12317
12318 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12319
12320 \end_inset
12321
12322
12323 \emph default
12324 ) should be used for example in interrupt
12325 \begin_inset LatexCommand \index{interrupt}
12326
12327 \end_inset
12328
12329
12330 \begin_inset LatexCommand \index{\_\_interrupt}
12331
12332 \end_inset
12333
12334  routines.
12335  By default, the compiler will place the stack after the last byte of allocated
12336  memory for variables.
12337  For example, if the first 2 banks of registers are used, and only four
12338  bytes are used for 
12339 \emph on
12340 data
12341 \emph default
12342  variables, it will position the base of the internal stack at address 20
12343  (0x14).
12344  This implies that as the stack
12345 \begin_inset LatexCommand \index{stack}
12346
12347 \end_inset
12348
12349  grows, it will use up the remaining register banks, and the 16 bytes used
12350  by the 128 bit variables, and 80 bytes for general purpose use.
12351  If any bit variables are used, the data variables will be placed in unused
12352  register banks and after the byte holding the last bit variable.
12353  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12354  (two bytes used), 
12355 \emph on
12356 data
12357 \emph default
12358  variables will be placed starting from address 0x10 to 0x20 and continue
12359  at address 0x22.
12360  You can also use -
12361 \begin_inset ERT
12362 status collapsed
12363
12364 \begin_layout Standard
12365
12366
12367 \backslash
12368 /
12369 \end_layout
12370
12371 \end_inset
12372
12373 -data-loc
12374 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12375
12376 \end_inset
12377
12378  to specify the start address of the 
12379 \emph on
12380 data
12381 \emph default
12382  and -
12383 \begin_inset ERT
12384 status collapsed
12385
12386 \begin_layout Standard
12387
12388
12389 \backslash
12390 /
12391 \end_layout
12392
12393 \end_inset
12394
12395 -iram-size
12396 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12397
12398 \end_inset
12399
12400  to specify the size of the total internal RAM (
12401 \emph on
12402 data
12403 \emph default
12404 +
12405 \emph on
12406 idata
12407 \emph default
12408 ).
12409  
12410 \newline
12411
12412 \end_layout
12413
12414 \begin_layout Standard
12415 By default the 8051 linker will place the stack after the last byte of (i)data
12416  variables.
12417  Option -
12418 \begin_inset ERT
12419 status collapsed
12420
12421 \begin_layout Standard
12422
12423
12424 \backslash
12425 /
12426 \end_layout
12427
12428 \end_inset
12429
12430 -stack-loc
12431 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12432
12433 \end_inset
12434
12435  allows you to specify the start of the stack, i.e.
12436  you could start it after any data in the general purpose area.
12437  If your microcontroller has additional indirectly addressable internal
12438  RAM (
12439 \emph on
12440 idata
12441 \emph default
12442 ) you can place the stack on it.
12443  You may also need to use -
12444 \begin_inset ERT
12445 status collapsed
12446
12447 \begin_layout Standard
12448
12449
12450 \backslash
12451 /
12452 \end_layout
12453
12454 \end_inset
12455
12456 -xdata-loc
12457 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12458
12459 \end_inset
12460
12461  to set the start address of the external RAM (
12462 \emph on
12463 xdata
12464 \emph default
12465 ) and -
12466 \begin_inset ERT
12467 status collapsed
12468
12469 \begin_layout Standard
12470
12471
12472 \backslash
12473 /
12474 \end_layout
12475
12476 \end_inset
12477
12478 -xram-size
12479 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12480
12481 \end_inset
12482
12483  to specify its size.
12484  Same goes for the code memory, using -
12485 \begin_inset ERT
12486 status collapsed
12487
12488 \begin_layout Standard
12489
12490
12491 \backslash
12492 /
12493 \end_layout
12494
12495 \end_inset
12496
12497 -code-loc
12498 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12499
12500 \end_inset
12501
12502  and -
12503 \begin_inset ERT
12504 status collapsed
12505
12506 \begin_layout Standard
12507
12508
12509 \backslash
12510 /
12511 \end_layout
12512
12513 \end_inset
12514
12515 -code-size
12516 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12517
12518 \end_inset
12519
12520 .
12521  If in doubt, don't specify any options and see if the resulting memory
12522  layout is appropriate, then you can adjust it.
12523 \end_layout
12524
12525 \begin_layout Standard
12526 The linker generates two files with memory allocation information.
12527  The first, with extension .map
12528 \begin_inset LatexCommand \index{<file>.map}
12529
12530 \end_inset
12531
12532  shows all the variables and segments.
12533  The second with extension .mem
12534 \begin_inset LatexCommand \index{<file>.mem}
12535
12536 \end_inset
12537
12538  shows the final memory layout.
12539  The linker will complain either if memory segments overlap, there is not
12540  enough memory, or there is not enough space for stack.
12541  If you get any linking warnings and/or errors related to stack or segments
12542  allocation, take a look at either the .map or .mem files to find out what
12543  the problem is.
12544  The .mem file may even suggest a solution to the problem.
12545 \begin_inset VSpace bigskip
12546 \end_inset
12547
12548
12549 \end_layout
12550
12551 \begin_layout Subsection
12552 Z80/Z180 Storage Class
12553 \begin_inset LatexCommand \index{Z80!Storage class}
12554
12555 \end_inset
12556
12557  Language Extensions
12558 \end_layout
12559
12560 \begin_layout Subsubsection
12561 sfr
12562 \begin_inset LatexCommand \index{sfr}
12563
12564 \end_inset
12565
12566
12567 \begin_inset LatexCommand \index{\_\_sfr}
12568
12569 \end_inset
12570
12571  (in/out to 8-bit addresses)
12572 \end_layout
12573
12574 \begin_layout Standard
12575 The Z80
12576 \begin_inset LatexCommand \index{Z80}
12577
12578 \end_inset
12579
12580  family has separate address spaces for memory and 
12581 \emph on
12582 i
12583 \emph default
12584 nput/
12585 \emph on
12586 o
12587 \emph default
12588 utput memory.
12589  I/O memory
12590 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12591
12592 \end_inset
12593
12594
12595 \begin_inset LatexCommand \index{Z80!I/O memory}
12596
12597 \end_inset
12598
12599
12600 \begin_inset LatexCommand \index{Z180!I/O memory}
12601
12602 \end_inset
12603
12604  is accessed with special instructions, e.g.:
12605 \end_layout
12606
12607 \begin_layout Verse
12608
12609 \family typewriter
12610 sfr at 0x78 IoPort;\InsetSpace ~
12611 \InsetSpace ~
12612 /* define a var in I/O space at 78h called IoPort */
12613  
12614 \end_layout
12615
12616 \begin_layout Standard
12617 Writing 0x01 to this variable generates the assembly code:
12618 \end_layout
12619
12620 \begin_layout Verse
12621
12622 \family typewriter
12623 3E 01\InsetSpace ~
12624 \InsetSpace ~
12625 \InsetSpace ~
12626 \InsetSpace ~
12627 \InsetSpace ~
12628 \InsetSpace ~
12629 ld a,#0x01
12630 \newline
12631 D3 78\InsetSpace ~
12632 \InsetSpace ~
12633 \InsetSpace ~
12634 \InsetSpace ~
12635 \InsetSpace ~
12636 \InsetSpace ~
12637 out (_IoPort),a 
12638 \end_layout
12639
12640 \begin_layout Subsubsection
12641 banked sfr
12642 \begin_inset LatexCommand \index{sfr}
12643
12644 \end_inset
12645
12646
12647 \begin_inset LatexCommand \index{\_\_sfr}
12648
12649 \end_inset
12650
12651  (in/out to 16-bit addresses)
12652 \end_layout
12653
12654 \begin_layout Standard
12655 The keyword 
12656 \emph on
12657 banked
12658 \emph default
12659  is used to support 16 bit addresses in I/O memory e.g.:
12660 \end_layout
12661
12662 \begin_layout Verse
12663
12664 \family typewriter
12665 sfr banked at
12666 \begin_inset LatexCommand \index{at}
12667
12668 \end_inset
12669
12670
12671 \begin_inset LatexCommand \index{\_\_at}
12672
12673 \end_inset
12674
12675  0x123 IoPort; 
12676 \end_layout
12677
12678 \begin_layout Standard
12679 Writing 0x01 to this variable generates the assembly code:
12680 \end_layout
12681
12682 \begin_layout Verse
12683
12684 \family typewriter
12685 01 23 01\InsetSpace ~
12686 \InsetSpace ~
12687 \InsetSpace ~
12688 ld bc,#_IoPort
12689 \newline
12690 3E 01\InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 ld a,#0x01 
12697 \newline
12698 ED 79\InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 out (c),a 
12705 \end_layout
12706
12707 \begin_layout Subsubsection
12708 sfr
12709 \begin_inset LatexCommand \index{sfr}
12710
12711 \end_inset
12712
12713
12714 \begin_inset LatexCommand \index{\_\_sfr}
12715
12716 \end_inset
12717
12718  (in0/out0 to 8 bit addresses on Z180
12719 \begin_inset LatexCommand \index{Z180}
12720
12721 \end_inset
12722
12723 /HD64180
12724 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12725
12726 \end_inset
12727
12728 )
12729 \end_layout
12730
12731 \begin_layout Standard
12732 The compiler option -
12733 \begin_inset ERT
12734 status collapsed
12735
12736 \begin_layout Standard
12737
12738
12739 \backslash
12740 /
12741 \end_layout
12742
12743 \end_inset
12744
12745 -portmode
12746 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12747
12748 \end_inset
12749
12750 =180 (80) and a compiler #pragma\InsetSpace ~
12751 portmode
12752 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12753
12754 \end_inset
12755
12756  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12757 ns 
12758 \family typewriter
12759 in0/out0
12760 \family default
12761  instead of 
12762 \family typewriter
12763 in/out
12764 \family default
12765 .
12766  If you include the file z180.h this will be set automatically.
12767 \begin_inset VSpace bigskip
12768 \end_inset
12769
12770
12771 \end_layout
12772
12773 \begin_layout Subsection
12774 HC08 Storage Class
12775 \begin_inset LatexCommand \index{HC08!Storage class}
12776
12777 \end_inset
12778
12779  Language Extensions
12780 \end_layout
12781
12782 \begin_layout Subsubsection
12783 data
12784 \begin_inset LatexCommand \index{data (hc08 storage class)}
12785
12786 \end_inset
12787
12788
12789 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12790
12791 \end_inset
12792
12793  
12794 \end_layout
12795
12796 \begin_layout Standard
12797 The data storage class declares a variable that resides in the first 256
12798  bytes of memory (the direct page).
12799  The HC08
12800 \begin_inset LatexCommand \index{HC08}
12801
12802 \end_inset
12803
12804  is most efficient at accessing variables (especially pointers) stored here.
12805 \end_layout
12806
12807 \begin_layout Subsubsection
12808 xdata
12809 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12810
12811 \end_inset
12812
12813
12814 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12815
12816 \end_inset
12817
12818  
12819 \end_layout
12820
12821 \begin_layout Standard
12822 The xdata storage class declares a variable that can reside anywhere in
12823  memory.
12824  This is the default if no storage class is specified.
12825  
12826 \begin_inset VSpace bigskip
12827 \end_inset
12828
12829
12830 \end_layout
12831
12832 \begin_layout Section
12833 Absolute Addressing
12834 \begin_inset LatexCommand \index{Absolute addressing}
12835
12836 \end_inset
12837
12838
12839 \end_layout
12840
12841 \begin_layout Standard
12842 Data items can be assigned an absolute address with the 
12843 \emph on
12844 at
12845 \begin_inset LatexCommand \index{at}
12846
12847 \end_inset
12848
12849
12850 \begin_inset LatexCommand \index{\_\_at}
12851
12852 \end_inset
12853
12854  <address>
12855 \emph default
12856  keyword, in addition to a storage class, e.g.:
12857 \end_layout
12858
12859 \begin_layout Verse
12860
12861 \family typewriter
12862 xdata
12863 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12864
12865 \end_inset
12866
12867
12868 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12869
12870 \end_inset
12871
12872  at
12873 \begin_inset LatexCommand \index{at}
12874
12875 \end_inset
12876
12877
12878 \begin_inset LatexCommand \index{\_\_at}
12879
12880 \end_inset
12881
12882  0x7ffe unsigned int chksum;
12883 \end_layout
12884
12885 \begin_layout Standard
12886 or, better conforming to ISO/IEC 9899 C:
12887 \end_layout
12888
12889 \begin_layout Verse
12890
12891 \family typewriter
12892 __xdata __at (0x7ffe) unsigned int chksum;
12893 \end_layout
12894
12895 \begin_layout Standard
12896 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12897  of the external ram.
12898  The compiler does 
12899 \emph on
12900 not
12901 \emph default
12902  reserve any space for variables declared in this way
12903 \begin_inset Marginal
12904 status collapsed
12905
12906 \begin_layout Standard
12907
12908 \series bold
12909 \InsetSpace ~
12910 !
12911 \end_layout
12912
12913 \end_inset
12914
12915  (they are implemented with an equate in the assembler).
12916  Thus it is left to the programmer to make sure there are no overlaps with
12917  other variables that are declared without the absolute address.
12918  The assembler listing file (.lst
12919 \begin_inset LatexCommand \index{<file>.lst}
12920
12921 \end_inset
12922
12923 ) and the linker output files (.rst
12924 \begin_inset LatexCommand \index{<file>.rst}
12925
12926 \end_inset
12927
12928 ) and (.map
12929 \begin_inset LatexCommand \index{<file>.map}
12930
12931 \end_inset
12932
12933 ) are good places to look for such overlaps.
12934 \end_layout
12935
12936 \begin_layout Standard
12937 If however you provide an initializer
12938 \begin_inset LatexCommand \index{Variable initialization}
12939
12940 \end_inset
12941
12942  actual memory allocation will take place and overlaps will be detected
12943  by the linker.
12944  E.g.:
12945 \end_layout
12946
12947 \begin_layout Verse
12948
12949 \family typewriter
12950 __code __at (0x7ff0) char Id[5] = 
12951 \begin_inset Quotes sld
12952 \end_inset
12953
12954 SDCC
12955 \begin_inset Quotes srd
12956 \end_inset
12957
12958 ;
12959 \end_layout
12960
12961 \begin_layout Standard
12962 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
12963  in code memory.
12964 \end_layout
12965
12966 \begin_layout Standard
12967 In case of memory mapped I/O devices the keyword 
12968 \emph on
12969 volatile
12970 \emph default
12971  has to be used to tell the compiler that accesses might not be removed:
12972 \end_layout
12973
12974 \begin_layout Verse
12975
12976 \family typewriter
12977 volatile
12978 \begin_inset LatexCommand \index{volatile}
12979
12980 \end_inset
12981
12982  __xdata
12983 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12984
12985 \end_inset
12986
12987  __at
12988 \begin_inset LatexCommand \index{at}
12989
12990 \end_inset
12991
12992  (0x8000) unsigned char PORTA_8255;
12993 \end_layout
12994
12995 \begin_layout Standard
12996 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12997 r) array
12998 \family typewriter
12999 \size footnotesize
13000
13001 \begin_inset LatexCommand \index{Aligned array}
13002
13003 \end_inset
13004
13005
13006 \family default
13007 \size default
13008  starts at a block (256 byte) boundary
13009 \begin_inset LatexCommand \index{block boundary}
13010
13011 \end_inset
13012
13013  (section 
13014 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13015
13016 \end_inset
13017
13018  has an example).
13019 \newline
13020 Absolute addresses can be specified for variables in all
13021  storage classes, e.g.:
13022 \end_layout
13023
13024 \begin_layout Verse
13025
13026 \family typewriter
13027 __bit
13028 \begin_inset LatexCommand \index{bit}
13029
13030 \end_inset
13031
13032  __at
13033 \begin_inset LatexCommand \index{at}
13034
13035 \end_inset
13036
13037  (0x02) bvar;
13038 \end_layout
13039
13040 \begin_layout Standard
13041 The above example will allocate the variable at offset 0x02 in the bit-addressab
13042 le space.
13043  There is no real advantage to assigning absolute addresses to variables
13044  in this manner, unless you want strict control over all the variables allocated.
13045  One possible use would be to write hardware portable code.
13046  For example, if you have a routine that uses one or more of the microcontroller
13047  I/O pins, and such pins are different for two different hardwares, you
13048  can declare the I/O pins in your routine using:
13049 \end_layout
13050
13051 \begin_layout Verse
13052
13053 \family typewriter
13054 extern volatile
13055 \begin_inset LatexCommand \index{volatile}
13056
13057 \end_inset
13058
13059  __bit MOSI;\InsetSpace ~
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 /* master out, slave in */
13064 \newline
13065 extern volatile __bit MISO;\InsetSpace ~
13066 \InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 /* master
13070  in, slave out */
13071 \newline
13072 extern volatile __bit MCLK;\InsetSpace ~
13073 \InsetSpace ~
13074 \InsetSpace ~
13075 \InsetSpace ~
13076 /* master clock */
13077 \newline
13078
13079 \newline
13080 /* Input and
13081  Output of a byte on a 3-wire serial bus.
13082 \newline
13083 \InsetSpace ~
13084 \InsetSpace ~
13085 \InsetSpace ~
13086 If needed adapt polarity of clock,
13087  polarity of data and bit order
13088 \newline
13089 \InsetSpace ~
13090 */
13091 \newline
13092 unsigned char spi_io(unsigned char out_byte)
13093  
13094 \newline
13095
13096 \newline
13097 \InsetSpace ~
13098 \InsetSpace ~
13099 \InsetSpace ~
13100 \InsetSpace ~
13101 unsigned char i=8;
13102 \newline
13103 \InsetSpace ~
13104 \InsetSpace ~
13105 \InsetSpace ~
13106 \InsetSpace ~
13107 do { 
13108 \newline
13109 \InsetSpace ~
13110 \InsetSpace ~
13111 \InsetSpace ~
13112 \InsetSpace ~
13113 \InsetSpace ~
13114 \InsetSpace ~
13115 \InsetSpace ~
13116 \InsetSpace ~
13117 MOSI = out_byte & 0x80; 
13118 \newline
13119 \InsetSpace ~
13120 \InsetSpace ~
13121 \InsetSpace ~
13122 \InsetSpace ~
13123 \InsetSpace ~
13124 \InsetSpace ~
13125 \InsetSpace ~
13126 \InsetSpace ~
13127 out_byte <<= 1;
13128 \newline
13129 \InsetSpace ~
13130 \InsetSpace ~
13131 \InsetSpace ~
13132 \InsetSpace ~
13133 \InsetSpace ~
13134 \InsetSpace ~
13135 \InsetSpace ~
13136 \InsetSpace ~
13137 MCLK =
13138  1; 
13139 \newline
13140 \InsetSpace ~
13141 \InsetSpace ~
13142 \InsetSpace ~
13143 \InsetSpace ~
13144 \InsetSpace ~
13145 \InsetSpace ~
13146 \InsetSpace ~
13147 \InsetSpace ~
13148 /* _asm nop _endasm; */\InsetSpace ~
13149 \InsetSpace ~
13150 \InsetSpace ~
13151 \InsetSpace ~
13152 \InsetSpace ~
13153 \InsetSpace ~
13154 \InsetSpace ~
13155 \InsetSpace ~
13156 /* for slow peripherals */
13157 \newline
13158 \InsetSpace ~
13159 \InsetSpace ~
13160 \InsetSpace ~
13161 \InsetSpace ~
13162 \InsetSpace ~
13163 \InsetSpace ~
13164 \InsetSpace ~
13165 \InsetSpace ~
13166 if(MISO) 
13167 \newline
13168 \InsetSpace ~
13169 \InsetSpace ~
13170 \InsetSpace ~
13171 \InsetSpace ~
13172 \InsetSpace ~
13173 \InsetSpace ~
13174 \InsetSpace ~
13175 \InsetSpace ~
13176 \InsetSpace ~
13177 \InsetSpace ~
13178 \InsetSpace ~
13179 \InsetSpace ~
13180 out_byte +=
13181  1; 
13182 \newline
13183 \InsetSpace ~
13184 \InsetSpace ~
13185 \InsetSpace ~
13186 \InsetSpace ~
13187 \InsetSpace ~
13188 \InsetSpace ~
13189 \InsetSpace ~
13190 \InsetSpace ~
13191 MCLK = 0; 
13192 \newline
13193 \InsetSpace ~
13194 \InsetSpace ~
13195 \InsetSpace ~
13196 \InsetSpace ~
13197 } while(--i);
13198 \newline
13199 \InsetSpace ~
13200 \InsetSpace ~
13201 \InsetSpace ~
13202 \InsetSpace ~
13203 return out_byte; 
13204 \newline
13205 }
13206 \end_layout
13207
13208 \begin_layout Standard
13209 Then, someplace in the code for the first hardware you would use
13210 \end_layout
13211
13212 \begin_layout Verse
13213
13214 \family typewriter
13215 __bit __at
13216 \begin_inset LatexCommand \index{at}
13217
13218 \end_inset
13219
13220
13221 \begin_inset LatexCommand \index{\_\_at}
13222
13223 \end_inset
13224
13225  (0x80) MOSI;\InsetSpace ~
13226 \InsetSpace ~
13227 \InsetSpace ~
13228 \InsetSpace ~
13229 /* I/O port 0, bit 0 */
13230 \newline
13231 __bit __at (0x81) MISO;\InsetSpace ~
13232 \InsetSpace ~
13233 \InsetSpace ~
13234 \InsetSpace ~
13235 /* I/O port 0,
13236  bit 1 */
13237 \newline
13238 __bit __at (0x82) MCLK;\InsetSpace ~
13239 \InsetSpace ~
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 /* I/O port 0, bit 2 */
13243 \end_layout
13244
13245 \begin_layout Standard
13246 Similarly, for the second hardware you would use
13247 \end_layout
13248
13249 \begin_layout Verse
13250
13251 \family typewriter
13252 __bit __at (0x83) MOSI;\InsetSpace ~
13253 \InsetSpace ~
13254 \InsetSpace ~
13255 \InsetSpace ~
13256 /* I/O port 0, bit 3 */
13257 \newline
13258 __bit __at (0x91) MISO;\InsetSpace ~
13259 \InsetSpace ~
13260 \InsetSpace ~
13261 \InsetSpace ~
13262 /*
13263  I/O port 1, bit 1 */
13264 \newline
13265 __bit
13266 \begin_inset LatexCommand \index{bit}
13267
13268 \end_inset
13269
13270  __at (0x92) MCLK;\InsetSpace ~
13271 \InsetSpace ~
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 /* I/O port 1, bit 2 */
13275 \end_layout
13276
13277 \begin_layout Standard
13278 and you can use the same hardware dependent routine without changes, as
13279  for example in a library.
13280  This is somehow similar to sbit, but only one absolute address has to be
13281  specified in the whole project.
13282 \begin_inset VSpace bigskip
13283 \end_inset
13284
13285
13286 \end_layout
13287
13288 \begin_layout Section
13289 Parameters
13290 \begin_inset LatexCommand \index{Parameters}
13291
13292 \end_inset
13293
13294
13295 \begin_inset LatexCommand \index{function parameter}
13296
13297 \end_inset
13298
13299  & Local Variables
13300 \begin_inset LatexCommand \index{local variables}
13301
13302 \end_inset
13303
13304
13305 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13306
13307 \end_inset
13308
13309
13310 \end_layout
13311
13312 \begin_layout Standard
13313 Automatic (local) variables and parameters to functions can either be placed
13314  on the stack or in data-space.
13315  The default action of the compiler is to place these variables in the internal
13316  RAM (for small model) or external RAM (for medium or large model).
13317  This in fact makes them similar to 
13318 \emph on
13319 static
13320 \begin_inset LatexCommand \index{static}
13321
13322 \end_inset
13323
13324
13325 \emph default
13326  so by default functions are non-reentrant
13327 \begin_inset LatexCommand \index{reentrant}
13328
13329 \end_inset
13330
13331 .
13332  
13333 \newline
13334
13335 \newline
13336 They can be placed on the stack
13337 \begin_inset LatexCommand \index{stack}
13338
13339 \end_inset
13340
13341  by using the
13342 \emph on
13343  -
13344 \begin_inset ERT
13345 status collapsed
13346
13347 \begin_layout Standard
13348
13349
13350 \backslash
13351 /
13352 \end_layout
13353
13354 \end_inset
13355
13356 -stack-auto
13357 \begin_inset LatexCommand \index{-\/-stack-auto}
13358
13359 \end_inset
13360
13361
13362 \emph default
13363  option, by using 
13364 \emph on
13365 #pragma\InsetSpace ~
13366 stackauto
13367 \emph default
13368
13369 \begin_inset LatexCommand \index{\#pragma stackauto}
13370
13371 \end_inset
13372
13373  or by using the 
13374 \emph on
13375 reentrant
13376 \begin_inset LatexCommand \index{reentrant}
13377
13378 \end_inset
13379
13380
13381 \emph default
13382  keyword in the function declaration, e.g.:
13383 \end_layout
13384
13385 \begin_layout Verse
13386
13387 \family typewriter
13388 unsigned char foo(char i) __reentrant 
13389 \newline
13390
13391 \newline
13392 \InsetSpace ~
13393 \InsetSpace ~
13394 \InsetSpace ~
13395 \InsetSpace ~
13396 ...
13397  
13398 \newline
13399 }
13400 \end_layout
13401
13402 \begin_layout Standard
13403 Since stack space on 8051 is limited, the 
13404 \emph on
13405 reentrant 
13406 \emph default
13407 keyword or the
13408 \emph on
13409  -
13410 \begin_inset ERT
13411 status collapsed
13412
13413 \begin_layout Standard
13414
13415
13416 \backslash
13417 /
13418 \end_layout
13419
13420 \end_inset
13421
13422 -stack-auto
13423 \emph default
13424  option should be used sparingly.
13425  Note that the reentrant keyword just means that the parameters & local
13426  variables will be allocated to the stack, it 
13427 \emph on
13428 does not
13429 \emph default
13430  mean that the function is register bank
13431 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13432
13433 \end_inset
13434
13435  independent.
13436 \newline
13437
13438 \newline
13439 Local variables
13440 \begin_inset LatexCommand \index{local variables}
13441
13442 \end_inset
13443
13444  can be assigned storage classes and absolute
13445 \begin_inset LatexCommand \index{Absolute addressing}
13446
13447 \end_inset
13448
13449  addresses, e.g.: 
13450 \end_layout
13451
13452 \begin_layout Verse
13453
13454 \family typewriter
13455 unsigned char foo() 
13456 \newline
13457 {
13458 \newline
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 \InsetSpace ~
13463 __xdata unsigned char i;
13464 \newline
13465 \InsetSpace ~
13466 \InsetSpace ~
13467 \InsetSpace ~
13468 \InsetSpace ~
13469 __bit bvar;
13470 \newline
13471 \InsetSpace ~
13472 \InsetSpace ~
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 __data __at
13476 \begin_inset LatexCommand \index{at}
13477
13478 \end_inset
13479
13480  (0x31) unsigned char j;
13481 \newline
13482 \InsetSpace ~
13483 \InsetSpace ~
13484 \InsetSpace ~
13485 \InsetSpace ~
13486 ...
13487  
13488 \newline
13489 }
13490 \end_layout
13491
13492 \begin_layout Standard
13493 In the above example the variable 
13494 \emph on
13495 i
13496 \emph default
13497  will be allocated in the external ram, 
13498 \emph on
13499 bvar
13500 \emph default
13501  in bit addressable space and
13502 \emph on
13503  j
13504 \emph default
13505  in internal ram.
13506  When compiled with 
13507 \emph on
13508 -
13509 \begin_inset ERT
13510 status collapsed
13511
13512 \begin_layout Standard
13513
13514
13515 \backslash
13516 /
13517 \end_layout
13518
13519 \end_inset
13520
13521 -stack-auto
13522 \emph default
13523  or when a function is declared as 
13524 \emph on
13525 reentrant
13526 \emph default
13527  this should only be done for static variables.
13528 \end_layout
13529
13530 \begin_layout Standard
13531 Parameters
13532 \begin_inset LatexCommand \index{function parameter}
13533
13534 \end_inset
13535
13536  however are not allowed any storage class
13537 \begin_inset LatexCommand \index{Storage class}
13538
13539 \end_inset
13540
13541 , (storage classes for parameters will be ignored), their allocation is
13542  governed by the memory model in use, and the reentrancy options.
13543 \end_layout
13544
13545 \begin_layout Standard
13546 It is however allowed to use bit parameters in reentrant functions and also
13547  non-static local bit variables are supported.
13548  Efficient use is limited to 8 semi-bitregisters in bit space.
13549  They are pushed and popped to stack
13550 \begin_inset LatexCommand \index{stack}
13551
13552 \end_inset
13553
13554  as a single byte just like the normal registers.
13555 \end_layout
13556
13557 \begin_layout Section
13558 Overlaying
13559 \begin_inset LatexCommand \label{sub:Overlaying}
13560
13561 \end_inset
13562
13563
13564 \begin_inset LatexCommand \index{Overlaying}
13565
13566 \end_inset
13567
13568
13569 \end_layout
13570
13571 \begin_layout Standard
13572 For non-reentrant
13573 \begin_inset LatexCommand \index{reentrant}
13574
13575 \end_inset
13576
13577  functions SDCC will try to reduce internal ram space usage by overlaying
13578  parameters and local variables of a function (if possible).
13579  Parameters and local variables
13580 \begin_inset LatexCommand \index{local variables}
13581
13582 \end_inset
13583
13584  of a function will be allocated to an overlayable segment if the function
13585  has 
13586 \emph on
13587 no other function calls and the function is non-reentrant and the memory
13588  model
13589 \begin_inset LatexCommand \index{Memory model}
13590
13591 \end_inset
13592
13593  is small.
13594
13595 \emph default
13596  If an explicit storage class
13597 \begin_inset LatexCommand \index{Storage class}
13598
13599 \end_inset
13600
13601  is specified for a local variable, it will NOT be overlayed.
13602 \end_layout
13603
13604 \begin_layout Standard
13605 Note that the compiler (not the linkage editor) makes the decision for overlayin
13606 g the data items.
13607  Functions that are called from an interrupt service routine
13608 \begin_inset Marginal
13609 status collapsed
13610
13611 \begin_layout Standard
13612
13613 \series bold
13614 !
13615 \end_layout
13616
13617 \end_inset
13618
13619  should be preceded by a #pragma\InsetSpace ~
13620 nooverlay
13621 \begin_inset LatexCommand \index{\#pragma nooverlay}
13622
13623 \end_inset
13624
13625  if they are not reentrant.
13626 \end_layout
13627
13628 \begin_layout Standard
13629 Also note that the compiler does not do any processing of inline assembler
13630  code, so the compiler might incorrectly assign local variables and parameters
13631  of a function into the overlay segment if the inline assembler code calls
13632  other c-functions that might use the overlay.
13633  In that case the #pragma\InsetSpace ~
13634 nooverlay should be used.
13635 \end_layout
13636
13637 \begin_layout Standard
13638 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13639 tion
13640 \begin_inset LatexCommand \index{Multiplication}
13641
13642 \end_inset
13643
13644  or division
13645 \begin_inset LatexCommand \index{Division}
13646
13647 \end_inset
13648
13649  will NOT be overlayed since these are implemented using external functions,
13650  e.g.:
13651 \end_layout
13652
13653 \begin_layout Verse
13654
13655 \family typewriter
13656 #pragma save 
13657 \newline
13658 #pragma nooverlay
13659 \begin_inset LatexCommand \index{\#pragma nooverlay}
13660
13661 \end_inset
13662
13663  
13664 \newline
13665 void set_error(unsigned char errcd) 
13666 \newline
13667 {
13668 \newline
13669 \InsetSpace ~
13670 \InsetSpace ~
13671 \InsetSpace ~
13672 \InsetSpace ~
13673 P3 = errcd;
13674 \newline
13675
13676 \newline
13677 #pragma restore 
13678 \newline
13679
13680 \newline
13681 void
13682  some_isr () __interrupt
13683 \begin_inset LatexCommand \index{interrupt}
13684
13685 \end_inset
13686
13687  (2)
13688 \newline
13689 {
13690 \newline
13691 \InsetSpace ~
13692 \InsetSpace ~
13693 \InsetSpace ~
13694 \InsetSpace ~
13695 ...
13696 \newline
13697 \InsetSpace ~
13698 \InsetSpace ~
13699 \InsetSpace ~
13700 \InsetSpace ~
13701 set_error(10);
13702 \newline
13703 \InsetSpace ~
13704 \InsetSpace ~
13705 \InsetSpace ~
13706 \InsetSpace ~
13707 ...
13708  
13709 \newline
13710 }
13711 \end_layout
13712
13713 \begin_layout Standard
13714 In the above example the parameter 
13715 \emph on
13716 errcd
13717 \emph default
13718  for the function 
13719 \emph on
13720 set_error
13721 \emph default
13722  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13723 nooverlay was
13724  not present, this could cause unpredictable runtime behavior when called
13725  from an interrupt service routine.
13726  The #pragma\InsetSpace ~
13727 nooverlay ensures that the parameters and local variables for
13728  the function are NOT overlayed.
13729 \begin_inset VSpace bigskip
13730 \end_inset
13731
13732
13733 \end_layout
13734
13735 \begin_layout Section
13736 Interrupt Service Routines
13737 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13738
13739 \end_inset
13740
13741
13742 \end_layout
13743
13744 \begin_layout Subsection
13745 General Information
13746 \end_layout
13747
13748 \begin_layout Standard
13749 SDCC allows 
13750 \emph on
13751 i
13752 \emph default
13753 nterrupt 
13754 \emph on
13755 s
13756 \emph default
13757 ervice 
13758 \emph on
13759 r
13760 \emph default
13761 outines to be coded in C, with some extended keywords.
13762 \end_layout
13763
13764 \begin_layout Verse
13765
13766 \family typewriter
13767 void timer_isr (void) __interrupt (1) __using (1) 
13768 \newline
13769
13770 \newline
13771 \InsetSpace ~
13772 \InsetSpace ~
13773 \InsetSpace ~
13774 \InsetSpace ~
13775 ...
13776  
13777 \newline
13778 }
13779 \end_layout
13780
13781 \begin_layout Standard
13782 The optional number following the 
13783 \emph on
13784 interrupt
13785 \begin_inset LatexCommand \index{interrupt}
13786
13787 \end_inset
13788
13789
13790 \begin_inset LatexCommand \index{\_\_interrupt}
13791
13792 \end_inset
13793
13794
13795 \emph default
13796  keyword is the interrupt number this routine will service.
13797  When present, the compiler will insert a call to this routine in the interrupt
13798  vector table
13799 \begin_inset LatexCommand \index{interrupt vector table}
13800
13801 \end_inset
13802
13803  for the interrupt number specified.
13804  If you have multiple source files in your project, interrupt service routines
13805  can be present in any of them, but a prototype of the isr MUST be present
13806  or included in the file that contains the function 
13807 \emph on
13808 main
13809 \emph default
13810 .
13811  The optional (8051 specific) keyword 
13812 \emph on
13813 using
13814 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13815
13816 \end_inset
13817
13818
13819 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13820
13821 \end_inset
13822
13823
13824 \emph default
13825  can be used to tell the compiler to use the specified register bank when
13826  generating code for this function.
13827  
13828 \newline
13829 Interrupt service routines open the door for some very interesting bugs:
13830 \end_layout
13831
13832 \begin_layout Subsubsection
13833 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13834
13835 \end_inset
13836
13837 Common interrupt pitfall: variable not declared 
13838 \emph on
13839 volatile
13840 \end_layout
13841
13842 \begin_layout Standard
13843 If an interrupt service routine changes variables which are accessed by
13844  other functions these variables have to be declared 
13845 \emph on
13846 volatile
13847 \emph default
13848
13849 \begin_inset LatexCommand \index{volatile}
13850
13851 \end_inset
13852
13853 .
13854  See 
13855 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13856
13857 \end_inset
13858
13859  .
13860 \end_layout
13861
13862 \begin_layout Subsubsection
13863 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13864
13865 \end_inset
13866
13867 Common interrupt pitfall: 
13868 \emph on
13869 non-atomic access
13870 \end_layout
13871
13872 \begin_layout Standard
13873 If the access to these variables is not 
13874 \emph on
13875 atomic
13876 \begin_inset LatexCommand \index{atomic}
13877
13878 \end_inset
13879
13880
13881 \emph default
13882  (i.e.
13883  the processor needs more than one instruction for the access and could
13884  be interrupted while accessing the variable) the interrupt must be disabled
13885  during the access to avoid inconsistent data.
13886  
13887 \newline
13888 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13889  and should be protected by disabling interrupts.
13890  You're not automatically on the safe side if you use 8 bit variables though.
13891  We need an example here: f.e.
13892  on the 8051 the harmless looking 
13893 \begin_inset Quotes srd
13894 \end_inset
13895
13896
13897 \family typewriter
13898 flags\InsetSpace ~
13899 |=\InsetSpace ~
13900 0x80;
13901 \family default
13902
13903 \begin_inset Quotes sld
13904 \end_inset
13905
13906  is not atomic if 
13907 \family typewriter
13908 flags
13909 \family default
13910  resides in xdata.
13911  Setting 
13912 \begin_inset Quotes srd
13913 \end_inset
13914
13915
13916 \family typewriter
13917 flags\InsetSpace ~
13918 |=\InsetSpace ~
13919 0x40;
13920 \family default
13921
13922 \begin_inset Quotes sld
13923 \end_inset
13924
13925  from within an interrupt routine might get lost if the interrupt occurs
13926  at the wrong time.
13927  
13928 \begin_inset Quotes sld
13929 \end_inset
13930
13931
13932 \family typewriter
13933 counter\InsetSpace ~
13934 +=\InsetSpace ~
13935 8;
13936 \family default
13937
13938 \begin_inset Quotes srd
13939 \end_inset
13940
13941  is not atomic on the 8051 even if 
13942 \family typewriter
13943 counter
13944 \family default
13945  is located in data memory.
13946 \newline
13947 Bugs like these are hard to reproduce and can
13948  cause a lot of trouble.
13949  
13950 \end_layout
13951
13952 \begin_layout Subsubsection
13953 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13954
13955 \end_inset
13956
13957 Common interrupt pitfall: 
13958 \emph on
13959 stack overflow
13960 \end_layout
13961
13962 \begin_layout Standard
13963 The return address and the registers used in the interrupt service routine
13964  are saved on the stack
13965 \begin_inset LatexCommand \index{stack}
13966
13967 \end_inset
13968
13969  so there must be sufficient stack space.
13970  If there isn't variables or registers (or even the return address itself)
13971  will be corrupted.
13972  This 
13973 \emph on
13974 stack overflow
13975 \emph default
13976
13977 \begin_inset LatexCommand \index{stack overflow}
13978
13979 \end_inset
13980
13981  is most likely to happen if the interrupt occurs during the 
13982 \begin_inset Quotes sld
13983 \end_inset
13984
13985 deepest
13986 \begin_inset Quotes srd
13987 \end_inset
13988
13989  subroutine when the stack is already in use for f.e.
13990  many return addresses.
13991 \end_layout
13992
13993 \begin_layout Subsubsection
13994 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13995
13996 \end_inset
13997
13998 Common interrupt pitfall: 
13999 \emph on
14000 use of non-reentrant functions
14001 \end_layout
14002
14003 \begin_layout Standard
14004 A special note here, int (16 bit) and long (32 bit) integer division
14005 \begin_inset LatexCommand \index{Division}
14006
14007 \end_inset
14008
14009 , multiplication
14010 \begin_inset LatexCommand \index{Multiplication}
14011
14012 \end_inset
14013
14014  & modulus
14015 \begin_inset LatexCommand \index{Modulus}
14016
14017 \end_inset
14018
14019  and floating-point
14020 \begin_inset LatexCommand \index{Floating point support}
14021
14022 \end_inset
14023
14024  operations are implemented using external support routines.
14025  If an interrupt service routine needs to do any of these operations then
14026  the support routines (as mentioned in a following section) will have to
14027  be recompiled using the
14028 \emph on
14029  -
14030 \begin_inset ERT
14031 status collapsed
14032
14033 \begin_layout Standard
14034
14035
14036 \backslash
14037 /
14038 \end_layout
14039
14040 \end_inset
14041
14042 -stack-auto
14043 \begin_inset LatexCommand \index{-\/-stack-auto}
14044
14045 \end_inset
14046
14047
14048 \emph default
14049  option and the source file will need to be compiled using the 
14050 \emph on
14051 -
14052 \begin_inset ERT
14053 status collapsed
14054
14055 \begin_layout Standard
14056
14057
14058 \backslash
14059 /
14060 \end_layout
14061
14062 \end_inset
14063
14064 -int-long-reent
14065 \emph default
14066
14067 \begin_inset LatexCommand \index{-\/-int-long-reent}
14068
14069 \end_inset
14070
14071  compiler option.
14072  
14073 \newline
14074 Note, the type promotion
14075 \begin_inset LatexCommand \index{type promotion}
14076
14077 \end_inset
14078
14079  required by ANSI C can cause 16 bit routines to be used
14080 \begin_inset Marginal
14081 status collapsed
14082
14083 \begin_layout Standard
14084
14085 \series bold
14086 \InsetSpace ~
14087 !
14088 \end_layout
14089
14090 \end_inset
14091
14092  without the programmer being aware of it.
14093  See f.e.
14094  the cast 
14095 \family typewriter
14096 (unsigned char)(tail-1)
14097 \family default
14098  within the if clause in section 
14099 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14100
14101 \end_inset
14102
14103 .
14104 \end_layout
14105
14106 \begin_layout Standard
14107 Calling other functions from an interrupt service routine is not recommended,
14108  avoid it if possible.
14109  Note that when some function is called from an interrupt service routine
14110  it should be preceded by a #pragma\InsetSpace ~
14111 nooverlay
14112 \begin_inset LatexCommand \index{\#pragma nooverlay}
14113
14114 \end_inset
14115
14116  if it is not reentrant.
14117  Furthermore nonreentrant functions should not be called from the main program
14118  while the interrupt service routine might be active.
14119  They also must not be called from low priority interrupt service routines
14120  while a high priority interrupt service routine might be active.
14121  You could use semaphores or make the function
14122 \emph on
14123  critical
14124 \emph default
14125  if all parameters are passed in registers.
14126 \newline
14127  Also see section 
14128 \begin_inset LatexCommand \ref{sub:Overlaying}
14129
14130 \end_inset
14131
14132 \InsetSpace ~
14133 about Overlaying and section 
14134 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14135
14136 \end_inset
14137
14138 \InsetSpace ~
14139 about Functions using private register banks.
14140 \begin_inset VSpace bigskip
14141 \end_inset
14142
14143
14144 \end_layout
14145
14146 \begin_layout Subsection
14147 MCS51/DS390 Interrupt Service Routines
14148 \end_layout
14149
14150 \begin_layout Standard
14151 Interrupt
14152 \begin_inset LatexCommand \index{interrupt}
14153
14154 \end_inset
14155
14156  numbers and the corresponding address & descriptions for the Standard 8051/8052
14157  are listed below.
14158  SDCC will automatically adjust the 
14159 \begin_inset LatexCommand \index{interrupt vector table}
14160
14161 \end_inset
14162
14163  to the maximum interrupt number specified.
14164 \newline
14165
14166 \end_layout
14167
14168 \begin_layout Standard
14169 \align center
14170 \begin_inset Tabular
14171 <lyxtabular version="3" rows="9" columns="3">
14172 <features>
14173 <column alignment="center" valignment="top" leftline="true" width="0in">
14174 <column alignment="left" valignment="top" leftline="true" width="0in">
14175 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14176 <row topline="true" bottomline="true">
14177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14178 \begin_inset Text
14179
14180 \begin_layout Standard
14181 Interrupt #
14182 \end_layout
14183
14184 \end_inset
14185 </cell>
14186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14187 \begin_inset Text
14188
14189 \begin_layout Standard
14190 Description
14191 \end_layout
14192
14193 \end_inset
14194 </cell>
14195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14196 \begin_inset Text
14197
14198 \begin_layout Standard
14199 Vector Address
14200 \end_layout
14201
14202 \end_inset
14203 </cell>
14204 </row>
14205 <row topline="true">
14206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14207 \begin_inset Text
14208
14209 \begin_layout Standard
14210 0
14211 \end_layout
14212
14213 \end_inset
14214 </cell>
14215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14216 \begin_inset Text
14217
14218 \begin_layout Standard
14219 External 0
14220 \end_layout
14221
14222 \end_inset
14223 </cell>
14224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14225 \begin_inset Text
14226
14227 \begin_layout Standard
14228 0x0003
14229 \end_layout
14230
14231 \end_inset
14232 </cell>
14233 </row>
14234 <row topline="true">
14235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14236 \begin_inset Text
14237
14238 \begin_layout Standard
14239 1
14240 \end_layout
14241
14242 \end_inset
14243 </cell>
14244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14245 \begin_inset Text
14246
14247 \begin_layout Standard
14248 Timer 0
14249 \end_layout
14250
14251 \end_inset
14252 </cell>
14253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14254 \begin_inset Text
14255
14256 \begin_layout Standard
14257 0x000b
14258 \end_layout
14259
14260 \end_inset
14261 </cell>
14262 </row>
14263 <row topline="true">
14264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14265 \begin_inset Text
14266
14267 \begin_layout Standard
14268 2
14269 \end_layout
14270
14271 \end_inset
14272 </cell>
14273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14274 \begin_inset Text
14275
14276 \begin_layout Standard
14277 External 1
14278 \end_layout
14279
14280 \end_inset
14281 </cell>
14282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14283 \begin_inset Text
14284
14285 \begin_layout Standard
14286 0x0013
14287 \end_layout
14288
14289 \end_inset
14290 </cell>
14291 </row>
14292 <row topline="true">
14293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14294 \begin_inset Text
14295
14296 \begin_layout Standard
14297 3
14298 \end_layout
14299
14300 \end_inset
14301 </cell>
14302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14303 \begin_inset Text
14304
14305 \begin_layout Standard
14306 Timer 1
14307 \end_layout
14308
14309 \end_inset
14310 </cell>
14311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14312 \begin_inset Text
14313
14314 \begin_layout Standard
14315 0x001b
14316 \end_layout
14317
14318 \end_inset
14319 </cell>
14320 </row>
14321 <row topline="true">
14322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14323 \begin_inset Text
14324
14325 \begin_layout Standard
14326 4
14327 \end_layout
14328
14329 \end_inset
14330 </cell>
14331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14332 \begin_inset Text
14333
14334 \begin_layout Standard
14335 Serial
14336 \end_layout
14337
14338 \end_inset
14339 </cell>
14340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14341 \begin_inset Text
14342
14343 \begin_layout Standard
14344 0x0023
14345 \end_layout
14346
14347 \end_inset
14348 </cell>
14349 </row>
14350 <row topline="true">
14351 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14352 \begin_inset Text
14353
14354 \begin_layout Standard
14355 5
14356 \end_layout
14357
14358 \end_inset
14359 </cell>
14360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14361 \begin_inset Text
14362
14363 \begin_layout Standard
14364 Timer 2 (8052)
14365 \end_layout
14366
14367 \end_inset
14368 </cell>
14369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14370 \begin_inset Text
14371
14372 \begin_layout Standard
14373 0x002b
14374 \end_layout
14375
14376 \end_inset
14377 </cell>
14378 </row>
14379 <row topline="true">
14380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14381 \begin_inset Text
14382
14383 \begin_layout Standard
14384 ...
14385 \end_layout
14386
14387 \end_inset
14388 </cell>
14389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14390 \begin_inset Text
14391
14392 \begin_layout Standard
14393
14394 \end_layout
14395
14396 \end_inset
14397 </cell>
14398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14399 \begin_inset Text
14400
14401 \begin_layout Standard
14402 ...
14403 \end_layout
14404
14405 \end_inset
14406 </cell>
14407 </row>
14408 <row topline="true" bottomline="true">
14409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14410 \begin_inset Text
14411
14412 \begin_layout Standard
14413 n
14414 \end_layout
14415
14416 \end_inset
14417 </cell>
14418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14419 \begin_inset Text
14420
14421 \begin_layout Standard
14422
14423 \end_layout
14424
14425 \end_inset
14426 </cell>
14427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14428 \begin_inset Text
14429
14430 \begin_layout Standard
14431 0x0003 + 8*n
14432 \end_layout
14433
14434 \end_inset
14435 </cell>
14436 </row>
14437 </lyxtabular>
14438
14439 \end_inset
14440
14441
14442 \newline
14443
14444 \end_layout
14445
14446 \begin_layout Standard
14447 If the interrupt service routine is defined without 
14448 \emph on
14449 using
14450 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14451
14452 \end_inset
14453
14454
14455 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14456
14457 \end_inset
14458
14459
14460 \emph default
14461  a register bank or with register bank 0 (
14462 \emph on
14463 using
14464 \emph default
14465  0), the compiler will save the registers used by itself on the stack upon
14466  entry and restore them at exit, however if such an interrupt service routine
14467  calls another function then the entire register bank will be saved on the
14468  stack.
14469  This scheme may be advantageous for small interrupt service routines which
14470  have low register usage.
14471 \end_layout
14472
14473 \begin_layout Standard
14474 If the interrupt service routine is defined to be using a specific register
14475  bank then only 
14476 \emph on
14477 a, b, dptr
14478 \emph default
14479  & psw are saved and restored, if such an interrupt service routine calls
14480  another function (using another register bank) then the entire register
14481  bank of the called function will be saved on the stack
14482 \begin_inset LatexCommand \index{stack}
14483
14484 \end_inset
14485
14486 .
14487  This scheme is recommended for larger interrupt service routines.
14488 \begin_inset VSpace bigskip
14489 \end_inset
14490
14491
14492 \end_layout
14493
14494 \begin_layout Subsection
14495 HC08
14496 \begin_inset LatexCommand \index{HC08}
14497
14498 \end_inset
14499
14500  Interrupt Service Routines
14501 \end_layout
14502
14503 \begin_layout Standard
14504 Since the number of interrupts
14505 \begin_inset LatexCommand \index{HC08!interrupt}
14506
14507 \end_inset
14508
14509  available is chip specific and the interrupt vector table always ends at
14510  the last byte of memory, the interrupt numbers corresponds to the interrupt
14511  vectors in reverse order of address.
14512  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14513  2 will use the interrupt vector at 0xfffa, and so on.
14514  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14515  this way; instead see section 
14516 \begin_inset LatexCommand \ref{sub:Startup-Code}
14517
14518 \end_inset
14519
14520  for details on customizing startup.
14521 \begin_inset VSpace bigskip
14522 \end_inset
14523
14524
14525 \end_layout
14526
14527 \begin_layout Subsection
14528 Z80 Interrupt Service Routines
14529 \end_layout
14530
14531 \begin_layout Standard
14532 The Z80
14533 \begin_inset LatexCommand \index{Z80}
14534
14535 \end_inset
14536
14537  uses several different methods for determining the correct interrupt
14538 \begin_inset LatexCommand \index{Z80!interrupt}
14539
14540 \end_inset
14541
14542  vector depending on the hardware implementation.
14543  Therefore, SDCC ignores the optional interrupt number and does not attempt
14544  to generate an interrupt vector table.
14545 \end_layout
14546
14547 \begin_layout Standard
14548 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14549  instruction to return from the interrupt.
14550  To write an interrupt handler for the non-maskable interrupt, which needs
14551  a RETN instruction instead, add the 
14552 \emph on
14553 critical
14554 \emph default
14555  keyword:
14556 \end_layout
14557
14558 \begin_layout Verse
14559
14560 \family typewriter
14561 void nmi_isr (void) critical interrupt
14562 \newline
14563
14564 \newline
14565 \InsetSpace ~
14566 \InsetSpace ~
14567 \InsetSpace ~
14568 \InsetSpace ~
14569 ...
14570  
14571 \newline
14572 }
14573 \end_layout
14574
14575 \begin_layout Standard
14576 However if you need to create a non-interruptable interrupt service routine
14577  you would also require the 
14578 \emph on
14579 critical
14580 \emph default
14581  keyword.
14582  To distinguish between this and an nmi_isr you must provide an interrupt
14583  number.
14584 \begin_inset VSpace bigskip
14585 \end_inset
14586
14587
14588 \end_layout
14589
14590 \begin_layout Section
14591 Enabling and Disabling Interrupts
14592 \end_layout
14593
14594 \begin_layout Subsection
14595 Critical Functions and Critical Statements
14596 \end_layout
14597
14598 \begin_layout Standard
14599 A special keyword may be associated with a block or a function declaring
14600  it as 
14601 \emph on
14602 critical
14603 \emph default
14604 .
14605  SDCC will generate code to disable all interrupts
14606 \begin_inset LatexCommand \index{interrupt}
14607
14608 \end_inset
14609
14610  upon entry to a critical function and restore the interrupt enable to the
14611  previous state before returning.
14612  Nesting critical functions will need one additional byte on the stack
14613 \begin_inset LatexCommand \index{stack}
14614
14615 \end_inset
14616
14617  for each call.
14618 \end_layout
14619
14620 \begin_layout Verse
14621
14622 \family typewriter
14623 int foo () __critical
14624 \begin_inset LatexCommand \index{critical}
14625
14626 \end_inset
14627
14628
14629 \begin_inset LatexCommand \index{\_\_critical}
14630
14631 \end_inset
14632
14633  
14634 \newline
14635
14636 \newline
14637 \InsetSpace ~
14638 \InsetSpace ~
14639 \InsetSpace ~
14640 \InsetSpace ~
14641 ...
14642  
14643 \newline
14644 \InsetSpace ~
14645 \InsetSpace ~
14646 \InsetSpace ~
14647 \InsetSpace ~
14648 ...
14649  
14650 \newline
14651 }
14652 \end_layout
14653
14654 \begin_layout Standard
14655 The critical attribute maybe used with other attributes like 
14656 \emph on
14657 reentrant.
14658 \emph default
14659
14660 \newline
14661 The keyword 
14662 \emph on
14663 critical
14664 \emph default
14665  may also be used to disable interrupts more locally:
14666 \end_layout
14667
14668 \begin_layout Verse
14669
14670 \family typewriter
14671 __critical{ i++; }
14672 \end_layout
14673
14674 \begin_layout Standard
14675 More than one statement could have been included in the block.
14676 \end_layout
14677
14678 \begin_layout Subsection
14679 Enabling and Disabling Interrupts directly
14680 \end_layout
14681
14682 \begin_layout Standard
14683 Interrupts
14684 \begin_inset LatexCommand \index{interrupt}
14685
14686 \end_inset
14687
14688  can also be disabled and enabled directly (8051):
14689 \end_layout
14690
14691 \begin_layout Verse
14692
14693 \family typewriter
14694 EA = 0;\InsetSpace ~
14695 \InsetSpace ~
14696 \InsetSpace ~
14697 \InsetSpace ~
14698 \InsetSpace ~
14699 \InsetSpace ~
14700 \InsetSpace ~
14701 \InsetSpace ~
14702 \InsetSpace ~
14703 \InsetSpace ~
14704 \InsetSpace ~
14705 \InsetSpace ~
14706 or:\InsetSpace ~
14707 \InsetSpace ~
14708 \InsetSpace ~
14709 \InsetSpace ~
14710 \InsetSpace ~
14711 \InsetSpace ~
14712 \InsetSpace ~
14713 \InsetSpace ~
14714 \InsetSpace ~
14715 \InsetSpace ~
14716 \InsetSpace ~
14717 EA_SAVE = EA;
14718 \end_layout
14719
14720 \begin_layout Verse
14721
14722 \family typewriter
14723 ...\InsetSpace ~
14724 \InsetSpace ~
14725 \InsetSpace ~
14726 \InsetSpace ~
14727 \InsetSpace ~
14728 \InsetSpace ~
14729 \InsetSpace ~
14730 \InsetSpace ~
14731 \InsetSpace ~
14732 \InsetSpace ~
14733 \InsetSpace ~
14734 \InsetSpace ~
14735 \InsetSpace ~
14736 \InsetSpace ~
14737 \InsetSpace ~
14738 \InsetSpace ~
14739 \InsetSpace ~
14740 \InsetSpace ~
14741 \InsetSpace ~
14742 \InsetSpace ~
14743 \InsetSpace ~
14744 \InsetSpace ~
14745 \InsetSpace ~
14746 \InsetSpace ~
14747 \InsetSpace ~
14748 \InsetSpace ~
14749 \InsetSpace ~
14750 \InsetSpace ~
14751 \InsetSpace ~
14752 \InsetSpace ~
14753 EA = 0;
14754 \end_layout
14755
14756 \begin_layout Verse
14757
14758 \family typewriter
14759 EA = 1;\InsetSpace ~
14760 \InsetSpace ~
14761 \InsetSpace ~
14762 \InsetSpace ~
14763 \InsetSpace ~
14764 \InsetSpace ~
14765 \InsetSpace ~
14766 \InsetSpace ~
14767 \InsetSpace ~
14768 \InsetSpace ~
14769 \InsetSpace ~
14770 \InsetSpace ~
14771 \InsetSpace ~
14772 \InsetSpace ~
14773 \InsetSpace ~
14774 \InsetSpace ~
14775 \InsetSpace ~
14776 \InsetSpace ~
14777 \InsetSpace ~
14778 \InsetSpace ~
14779 \InsetSpace ~
14780 \InsetSpace ~
14781 \InsetSpace ~
14782 \InsetSpace ~
14783 \InsetSpace ~
14784 \InsetSpace ~
14785 ...
14786 \end_layout
14787
14788 \begin_layout Verse
14789
14790 \family typewriter
14791 \InsetSpace ~
14792 \InsetSpace ~
14793 \InsetSpace ~
14794 \InsetSpace ~
14795 \InsetSpace ~
14796 \InsetSpace ~
14797 \InsetSpace ~
14798 \InsetSpace ~
14799 \InsetSpace ~
14800 \InsetSpace ~
14801 \InsetSpace ~
14802 \InsetSpace ~
14803 \InsetSpace ~
14804 \InsetSpace ~
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 \InsetSpace ~
14809 \InsetSpace ~
14810 \InsetSpace ~
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 \InsetSpace ~
14822 \InsetSpace ~
14823 \InsetSpace ~
14824 EA = EA_SAVE;
14825 \end_layout
14826
14827 \begin_layout Standard
14828 On other architectures which have seperate opcodes for enabling and disabling
14829  interrupts you might want to make use of defines with inline assembly
14830 \begin_inset LatexCommand \index{Assembler routines}
14831
14832 \end_inset
14833
14834  (HC08
14835 \begin_inset LatexCommand \index{HC08!interrupt}
14836
14837 \end_inset
14838
14839 ):
14840 \end_layout
14841
14842 \begin_layout Verse
14843
14844 \family typewriter
14845 #define CLI _asm
14846 \begin_inset LatexCommand \index{\_asm}
14847
14848 \end_inset
14849
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 cli\InsetSpace ~
14853 \InsetSpace ~
14854 _endasm
14855 \begin_inset LatexCommand \index{\_endasm}
14856
14857 \end_inset
14858
14859
14860 \end_layout
14861
14862 \begin_layout Verse
14863
14864 \family typewriter
14865 #define SEI _asm\InsetSpace ~
14866 \InsetSpace ~
14867 sei\InsetSpace ~
14868 \InsetSpace ~
14869 _endasm; 
14870 \end_layout
14871
14872 \begin_layout Verse
14873
14874 \family typewriter
14875 ...
14876 \end_layout
14877
14878 \begin_layout Standard
14879 Note: it is sometimes sufficient to disable only a specific interrupt source
14880  like f.e.
14881  a timer or serial interrupt by manipulating an 
14882 \emph on
14883 interrupt mask
14884 \begin_inset LatexCommand \index{interrupt mask}
14885
14886 \end_inset
14887
14888
14889 \emph default
14890  register.
14891  
14892 \end_layout
14893
14894 \begin_layout Standard
14895 Usually the time during which interrupts are disabled should be kept as
14896  short as possible.
14897  This minimizes both 
14898 \emph on
14899 interrupt latency
14900 \emph default
14901
14902 \begin_inset LatexCommand \index{interrupt latency}
14903
14904 \end_inset
14905
14906  (the time between the occurrence of the interrupt and the execution of
14907  the first code in the interrupt routine) and 
14908 \emph on
14909 interrupt jitter
14910 \emph default
14911
14912 \begin_inset LatexCommand \index{interrupt jitter}
14913
14914 \end_inset
14915
14916  (the difference between the shortest and the longest interrupt latency).
14917  These really are something different, f.e.
14918  a serial interrupt has to be served before its buffer overruns so it cares
14919  for the maximum interrupt latency, whereas it does not care about jitter.
14920  On a loudspeaker driven via a digital to analog converter which is fed
14921  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14922  a much smaller jitter will be very audible.
14923 \end_layout
14924
14925 \begin_layout Standard
14926 You can reenable interrupts within an interrupt routine and on some architecture
14927 s you can make use of two (or more) levels of 
14928 \emph on
14929 interrupt priorities
14930 \emph default
14931
14932 \begin_inset LatexCommand \index{interrupt priority}
14933
14934 \end_inset
14935
14936 .
14937  On some architectures which don't support interrupt priorities these can
14938  be implemented by manipulating the interrupt mask and reenabling interrupts
14939  within the interrupt routine.
14940  Check there is sufficient space on the stack
14941 \begin_inset LatexCommand \index{stack}
14942
14943 \end_inset
14944
14945  and don't add complexity unless you have to.
14946  
14947 \end_layout
14948
14949 \begin_layout Subsection
14950 Semaphore
14951 \begin_inset LatexCommand \index{semaphore}
14952
14953 \end_inset
14954
14955  locking (mcs51/ds390)
14956 \end_layout
14957
14958 \begin_layout Standard
14959 Some architectures (mcs51/ds390) have an atomic
14960 \begin_inset LatexCommand \index{atomic}
14961
14962 \end_inset
14963
14964  bit test and
14965 \emph on
14966  
14967 \emph default
14968 clear
14969 \emph on
14970  
14971 \emph default
14972 instruction.
14973  These type of instructions are typically used in preemptive multitasking
14974  systems, where a routine f.e.
14975  claims the use of a data structure ('acquires a lock
14976 \begin_inset LatexCommand \index{lock}
14977
14978 \end_inset
14979
14980  on it'), makes some modifications and then releases the lock when the data
14981  structure is consistent again.
14982  The instruction may also be used if interrupt and non-interrupt code have
14983  to compete for a resource.
14984  With the atomic bit test and clear instruction interrupts
14985 \begin_inset LatexCommand \index{interrupt}
14986
14987 \end_inset
14988
14989  don't have to be disabled for the locking operation.
14990  
14991 \end_layout
14992
14993 \begin_layout Standard
14994 SDCC generates this instruction if the source follows this pattern:
14995 \end_layout
14996
14997 \begin_layout Verse
14998
14999 \family typewriter
15000 volatile
15001 \begin_inset LatexCommand \index{volatile}
15002
15003 \end_inset
15004
15005  bit resource_is_free; 
15006 \newline
15007
15008 \newline
15009 if (resource_is_free) 
15010 \newline
15011 \InsetSpace ~
15012 \InsetSpace ~
15013
15014 \newline
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 resource_is_free=0; 
15020 \newline
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 ...
15026  
15027 \newline
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 resource_is_free=1;
15033 \newline
15034 \InsetSpace ~
15035 \InsetSpace ~
15036
15037 \end_layout
15038
15039 \begin_layout Standard
15040 Note, mcs51 and ds390 support only an atomic
15041 \begin_inset LatexCommand \index{atomic}
15042
15043 \end_inset
15044
15045  bit test and 
15046 \emph on
15047 clear
15048 \emph default
15049  instruction (as opposed to atomic bit test and 
15050 \emph on
15051 set).
15052 \end_layout
15053
15054 \begin_layout Section
15055 Functions using private register banks
15056 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15057
15058 \end_inset
15059
15060  (mcs51/ds390)
15061 \end_layout
15062
15063 \begin_layout Standard
15064 Some architectures have support for quickly changing register sets.
15065  SDCC supports this feature with the 
15066 \emph on
15067 using
15068 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15069
15070 \end_inset
15071
15072
15073 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15074
15075 \end_inset
15076
15077
15078 \emph default
15079  attribute (which tells the compiler to use a register bank
15080 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15081
15082 \end_inset
15083
15084  other than the default bank zero).
15085  It should only be applied to 
15086 \emph on
15087 interrupt
15088 \begin_inset LatexCommand \index{interrupt}
15089
15090 \end_inset
15091
15092
15093 \emph default
15094  functions (see footnote below).
15095  This will in most circumstances make the generated ISR code more efficient
15096  since it will not have to save registers on the stack.
15097 \end_layout
15098
15099 \begin_layout Standard
15100 The 
15101 \emph on
15102 using
15103 \emph default
15104  attribute will have no effect on the generated code for a 
15105 \emph on
15106 non-interrupt
15107 \emph default
15108  function (but may occasionally be useful anyway
15109 \begin_inset Foot
15110 status open
15111
15112 \begin_layout Standard
15113 possible exception: if a function is called ONLY from 'interrupt' functions
15114  using a particular bank, it can be declared with the same 'using' attribute
15115  as the calling 'interrupt' functions.
15116  For instance, if you have several ISRs using bank one, and all of them
15117  call memcpy(), it might make sense to create a specialized version of memcpy()
15118  'using 1', since this would prevent the ISR from having to save bank zero
15119  to the stack on entry and switch to bank zero before calling the function
15120 \end_layout
15121
15122 \end_inset
15123
15124 ).
15125 \newline
15126
15127 \emph on
15128 (pending: Note, nowadays the 
15129 \emph default
15130 using
15131 \emph on
15132  attribute has an effect on
15133 \emph default
15134  
15135 \emph on
15136 the generated code for a 
15137 \emph default
15138 non-interrupt
15139 \emph on
15140  function
15141 \emph default
15142 .
15143 \emph on
15144 )
15145 \end_layout
15146
15147 \begin_layout Standard
15148 An 
15149 \emph on
15150 interrupt
15151 \emph default
15152  function using a non-zero bank will assume that it can trash that register
15153  bank, and will not save it.
15154  Since high-priority interrupts
15155 \begin_inset LatexCommand \index{interrupts}
15156
15157 \end_inset
15158
15159
15160 \begin_inset LatexCommand \index{interrupt priority}
15161
15162 \end_inset
15163
15164  can interrupt low-priority ones on the 8051 and friends, this means that
15165  if a high-priority ISR 
15166 \emph on
15167 using
15168 \emph default
15169  a particular bank occurs while processing a low-priority ISR 
15170 \emph on
15171 using
15172 \emph default
15173  the same bank, terrible and bad things can happen.
15174  To prevent this, no single register bank should be 
15175 \emph on
15176 used
15177 \emph default
15178  by both a high priority and a low priority ISR.
15179  This is probably most easily done by having all high priority ISRs use
15180  one bank and all low priority ISRs use another.
15181  If you have an ISR which can change priority at runtime, you're on your
15182  own: I suggest using the default bank zero and taking the small performance
15183  hit.
15184 \end_layout
15185
15186 \begin_layout Standard
15187 It is most efficient if your ISR calls no other functions.
15188  If your ISR must call other functions, it is most efficient if those functions
15189  use the same bank as the ISR (see note 1 below); the next best is if the
15190  called functions use bank zero.
15191  It is very inefficient to call a function using a different, non-zero bank
15192  from an ISR.
15193  
15194 \begin_inset VSpace bigskip
15195 \end_inset
15196
15197
15198 \end_layout
15199
15200 \begin_layout Section
15201 Startup Code
15202 \begin_inset LatexCommand \label{sub:Startup-Code}
15203
15204 \end_inset
15205
15206
15207 \begin_inset LatexCommand \index{Startup code}
15208
15209 \end_inset
15210
15211
15212 \end_layout
15213
15214 \begin_layout Subsection
15215 MCS51/DS390 Startup Code
15216 \end_layout
15217
15218 \begin_layout Standard
15219 The compiler triggers the linker to link certain initialization modules
15220  from the runtime library
15221 \begin_inset LatexCommand \index{Runtime library}
15222
15223 \end_inset
15224
15225  called crt<something>.
15226  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15227  GSINIT5) is not linked unless the -
15228 \series bold
15229
15230 \begin_inset ERT
15231 status open
15232
15233 \begin_layout Standard
15234
15235
15236 \backslash
15237 /
15238 \end_layout
15239
15240 \end_inset
15241
15242
15243 \series default
15244 -xstack option is used.
15245  These modules are highly entangled by the use of special segments/areas,
15246  but a common layout is shown below:
15247 \end_layout
15248
15249 \begin_layout Verse
15250
15251 \family typewriter
15252 \series bold
15253 \size footnotesize
15254 (main.asm)
15255 \end_layout
15256
15257 \begin_layout Verse
15258
15259 \family typewriter
15260 \size footnotesize
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 \InsetSpace ~
15265 \InsetSpace ~
15266 \InsetSpace ~
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 .area HOME (CODE)
15270 \newline
15271 __interrupt_vect:
15272 \newline
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 \InsetSpace ~
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 ljmp __sdcc_gsinit_startup
15282 \end_layout
15283
15284 \begin_layout Verse
15285
15286 \family typewriter
15287 \series bold
15288 \size footnotesize
15289 (crtstart.asm)
15290 \end_layout
15291
15292 \begin_layout Verse
15293
15294 \family typewriter
15295 \size footnotesize
15296 \InsetSpace ~
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 .area GSINIT0 (CODE)
15305 \newline
15306 __sdcc_gsinit_startup::
15307 \newline
15308 \InsetSpace ~
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 mov sp,#__start__stack - 1
15317 \end_layout
15318
15319 \begin_layout Verse
15320
15321 \family typewriter
15322 \series bold
15323 \size footnotesize
15324 (crtxstack.asm)
15325 \end_layout
15326
15327 \begin_layout Verse
15328
15329 \family typewriter
15330 \size footnotesize
15331 \InsetSpace ~
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 .area GSINIT1 (CODE)
15340 \newline
15341 __sdcc_init_xstack::
15342 \newline
15343 ; Need to initialize in GSINIT1 in
15344  case the user's __sdcc_external_startup uses the xstack.
15345 \newline
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 \InsetSpace ~
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 mov __XPAGE,#(__start__x
15355 stack >> 8)
15356 \newline
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 \InsetSpace ~
15364 \InsetSpace ~
15365 mov _spx,#__start__xstack
15366 \end_layout
15367
15368 \begin_layout Verse
15369
15370 \family typewriter
15371 \series bold
15372 \size footnotesize
15373 (crtstart.asm)
15374 \end_layout
15375
15376 \begin_layout Verse
15377
15378 \family typewriter
15379 \size footnotesize
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 \InsetSpace ~
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 .area GSINIT2 (CODE)
15389 \newline
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 lcall __sdcc_external_startup
15399 \newline
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 mov a,dpl
15409 \newline
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 \InsetSpace ~
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 jz __sdcc_init_data
15419 \newline
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 \InsetSpace ~
15426 \InsetSpace ~
15427 \InsetSpace ~
15428 ljmp
15429  __sdcc_program_startup
15430 \newline
15431 __sdcc_init_data:
15432 \end_layout
15433
15434 \begin_layout Verse
15435
15436 \family typewriter
15437 \series bold
15438 \size footnotesize
15439 (crtxinit.asm)
15440 \end_layout
15441
15442 \begin_layout Verse
15443
15444 \family typewriter
15445 \size footnotesize
15446 \InsetSpace ~
15447 \InsetSpace ~
15448 \InsetSpace ~
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 .area GSINIT3 (CODE)
15455 \newline
15456 __mcs51_genXINIT::
15457 \newline
15458 \InsetSpace ~
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 mov r1,#l_XINIT
15467 \newline
15468 \InsetSpace ~
15469 \InsetSpace ~
15470 \InsetSpace ~
15471 \InsetSpace ~
15472 \InsetSpace ~
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 \InsetSpace ~
15476 mov a,r1
15477 \newline
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 \InsetSpace ~
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 orl a,#(l_XINIT
15487  >> 8)
15488 \newline
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 jz 00003$
15498 \newline
15499 \InsetSpace ~
15500 \InsetSpace ~
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 mov r2,#((l_XINIT+255) >> 8)
15508 \newline
15509 \InsetSpace ~
15510 \InsetSpace ~
15511 \InsetSpace ~
15512 \InsetSpace ~
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 mov dptr,#s_XINIT
15518 \newline
15519 \InsetSpace ~
15520 \InsetSpace ~
15521 \InsetSpace ~
15522 \InsetSpace ~
15523 \InsetSpace ~
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 mov r0,#s_XISEG
15528 \newline
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 \InsetSpace ~
15533 \InsetSpace ~
15534 \InsetSpace ~
15535 \InsetSpace ~
15536 \InsetSpace ~
15537 mov
15538  __XPAGE,#(s_XISEG >> 8)
15539 \newline
15540 00001$:\InsetSpace ~
15541 clr a
15542 \newline
15543 \InsetSpace ~
15544 \InsetSpace ~
15545 \InsetSpace ~
15546 \InsetSpace ~
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 movc a,@a+dptr
15552 \newline
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 \InsetSpace ~
15556 \InsetSpace ~
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 movx @r0,a
15562 \newline
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 \InsetSpace ~
15566 \InsetSpace ~
15567 \InsetSpace ~
15568 \InsetSpace ~
15569 \InsetSpace ~
15570 \InsetSpace ~
15571 inc dptr
15572 \newline
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 inc
15582  r0
15583 \newline
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 cjne r0,#0,00002$
15593 \newline
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 inc __XPAGE
15603 \newline
15604 00002$:\InsetSpace ~
15605 djnz r1,00001$
15606 \newline
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 djnz r2,00001$
15616 \newline
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 mov __XPAGE,#0
15626 xFF
15627 \newline
15628 00003$:
15629 \end_layout
15630
15631 \begin_layout Verse
15632
15633 \family typewriter
15634 \series bold
15635 \size footnotesize
15636 (crtclear.asm)
15637 \end_layout
15638
15639 \begin_layout Verse
15640
15641 \family typewriter
15642 \size footnotesize
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 \InsetSpace ~
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 .area GSINIT4 (CODE)
15652 \newline
15653 __mcs51_genRAMCLEAR::
15654 \newline
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 clr a
15664 \newline
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 mov r0,#(l_IRAM-1)
15674 \newline
15675 00004$:\InsetSpace ~
15676 mov
15677  @r0,a
15678 \newline
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 djnz r0,00004$
15688 \newline
15689 ; _mcs51_genRAMCLEAR() end
15690 \end_layout
15691
15692 \begin_layout Verse
15693
15694 \family typewriter
15695 \series bold
15696 \size footnotesize
15697 (crtxclear.asm)
15698 \end_layout
15699
15700 \begin_layout Verse
15701
15702 \family typewriter
15703 \size footnotesize
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 .area GSINIT4 (CODE)
15713 \newline
15714 __mcs51_genXRAMCLEAR::
15715 \newline
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 mov r0,#l_PSEG
15725 \newline
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 mov a,r0
15735 \newline
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 jz 00006$
15745 \newline
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 mov
15755  r1,#s_PSEG
15756 \newline
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 mov __XPAGE,#(s_PSEG >> 8)
15766 \newline
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 \InsetSpace ~
15775 clr a
15776 \newline
15777 00005$:\InsetSpace ~
15778 movx @r1,a
15779 \newline
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 \InsetSpace ~
15785 \InsetSpace ~
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 inc r1
15789 \newline
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 djnz r0,00005$
15799 \newline
15800 0
15801 0006$:
15802 \newline
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 mov r0,#l_XSEG
15812 \newline
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 mov a,r0
15822 \newline
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 \InsetSpace ~
15831 orl a,#(l_XSEG >> 8)
15832 \newline
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 jz 00008$
15842 \newline
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 mov r1,#((l_XSEG
15852  + 255) >> 8)
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 mov dptr,#s_XSEG
15863 \newline
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 clr a
15873 \newline
15874 00007$:\InsetSpace ~
15875 movx @dptr,a
15876 \newline
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 inc dptr
15886 \newline
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 djnz r0,00007$
15896 \newline
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 djnz
15906  r1,00007$
15907 \newline
15908 00008$:
15909 \end_layout
15910
15911 \begin_layout Verse
15912
15913 \family typewriter
15914 \series bold
15915 \size footnotesize
15916 (crtxstack.asm)
15917 \end_layout
15918
15919 \begin_layout Verse
15920
15921 \family typewriter
15922 \size footnotesize
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 .area GSINIT5 (CODE)
15932 \newline
15933 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15934  modifies __XPAGE
15935 \newline
15936 ; and __mcs51_genRAMCLEAR modifies _spx.
15937 \newline
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 mov __XPAGE,#(__start__x
15947 stack >> 8)
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 mov _spx,#__start__xstack
15958 \end_layout
15959
15960 \begin_layout Verse
15961
15962 \family typewriter
15963 \series bold
15964 \size footnotesize
15965 (application modules)
15966 \end_layout
15967
15968 \begin_layout Verse
15969
15970 \family typewriter
15971 \size footnotesize
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 .area GSINIT (CODE)
15981 \end_layout
15982
15983 \begin_layout Verse
15984
15985 \family typewriter
15986 \series bold
15987 \size footnotesize
15988 (main.asm)
15989 \end_layout
15990
15991 \begin_layout Verse
15992
15993 \family typewriter
15994 \size footnotesize
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 .area GSFINAL (CODE)
16004 \newline
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 ljmp __sdcc_program_startup
16014 \newline
16015 ;---------------------------------
16016 -----------------------
16017 \newline
16018 ; Home
16019 \newline
16020 ;--------------------------------------------------
16021 ------
16022 \newline
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 .area HOME (CODE)
16032 \newline
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 .area CSEG (CODE)
16042 \newline
16043 __sdcc_program_startup:
16044 \newline
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 lcall _main
16054 \newline
16055 ;
16056  return from main will lock up
16057 \newline
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 \InsetSpace ~
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 sjmp .
16067 \end_layout
16068
16069 \begin_layout Standard
16070 One of these modules (crtstart.asm) contains a call to the C routine 
16071 \emph on
16072 _sdcc_external_startup()
16073 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16074
16075 \end_inset
16076
16077
16078 \series bold
16079 \emph default
16080  
16081 \series default
16082 at the start of the CODE area.
16083  This routine is also in the runtime library
16084 \begin_inset LatexCommand \index{Runtime library}
16085
16086 \end_inset
16087
16088  and returns 0 by default.
16089  If this routine returns a non-zero value, the static & global variable
16090  initialization will be skipped and the function main will be invoked.
16091  Otherwise static & global variables will be initialized before the function
16092  main is invoked.
16093  You could add an 
16094 \emph on
16095 _sdcc_external_startup()
16096 \emph default
16097  routine to your program to override the default if you need to setup hardware
16098  or perform some other critical operation prior to static & global variable
16099  initialization
16100 \begin_inset LatexCommand \index{Variable initialization}
16101
16102 \end_inset
16103
16104 .
16105  On some mcs51 variants xdata
16106 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16107
16108 \end_inset
16109
16110  memory has to be explicitly enabled before it can be accessed or if the
16111  watchdog
16112 \begin_inset LatexCommand \index{watchdog}
16113
16114 \end_inset
16115
16116  needs to be disabled, this is the place to do it.
16117  The startup code clears all internal data memory, 256 bytes by default,
16118  but from 0 to n-1 if 
16119 \emph on
16120 -
16121 \begin_inset ERT
16122 status collapsed
16123
16124 \begin_layout Standard
16125
16126
16127 \backslash
16128 /
16129 \end_layout
16130
16131 \end_inset
16132
16133 -iram-size
16134 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16135
16136 \end_inset
16137
16138 n
16139 \emph default
16140  is used.
16141  (recommended for Chipcon CC1010).
16142 \end_layout
16143
16144 \begin_layout Standard
16145 See also the compiler options 
16146 \emph on
16147 -
16148 \begin_inset ERT
16149 status collapsed
16150
16151 \begin_layout Standard
16152
16153
16154 \backslash
16155 /
16156 \end_layout
16157
16158 \end_inset
16159
16160 -no-xinit
16161 \emph default
16162 -
16163 \emph on
16164 opt
16165 \emph default
16166
16167 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16168
16169 \end_inset
16170
16171
16172 \emph on
16173 -
16174 \begin_inset ERT
16175 status collapsed
16176
16177 \begin_layout Standard
16178
16179
16180 \backslash
16181 /
16182 \end_layout
16183
16184 \end_inset
16185
16186 -main-return
16187 \emph default
16188
16189 \begin_inset LatexCommand \index{-\/-main-return}
16190
16191 \end_inset
16192
16193  and section 
16194 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16195
16196 \end_inset
16197
16198  about MCS51-variants.
16199 \begin_inset VSpace bigskip
16200 \end_inset
16201
16202
16203 \end_layout
16204
16205 \begin_layout Subsection
16206 HC08 Startup Code
16207 \end_layout
16208
16209 \begin_layout Standard
16210 The HC08
16211 \begin_inset LatexCommand \index{HC08}
16212
16213 \end_inset
16214
16215  startup code follows the same scheme as the MCS51 startup code.
16216 \begin_inset VSpace bigskip
16217 \end_inset
16218
16219
16220 \end_layout
16221
16222 \begin_layout Subsection
16223 Z80 Startup Code
16224 \end_layout
16225
16226 \begin_layout Standard
16227 On the Z80
16228 \begin_inset LatexCommand \index{Z80}
16229
16230 \end_inset
16231
16232  the startup code is inserted by linking with crt0.o which is generated from
16233  sdcc/device/lib/z80/crt0.s.
16234  If you need a different startup code you can use the compiler option 
16235 \emph on
16236 -
16237 \series bold
16238 \emph default
16239
16240 \begin_inset ERT
16241 status collapsed
16242
16243 \begin_layout Standard
16244
16245
16246 \backslash
16247 /
16248 \end_layout
16249
16250 \end_inset
16251
16252
16253 \series default
16254 \emph on
16255 -no-std-crt0
16256 \emph default
16257
16258 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16259
16260 \end_inset
16261
16262  and provide your own crt0.o.
16263  
16264 \begin_inset VSpace bigskip
16265 \end_inset
16266
16267
16268 \end_layout
16269
16270 \begin_layout Section
16271 Inline Assembler Code
16272 \begin_inset LatexCommand \index{Assembler routines}
16273
16274 \end_inset
16275
16276
16277 \end_layout
16278
16279 \begin_layout Subsection
16280 A Step by Step Introduction
16281 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16282
16283 \end_inset
16284
16285
16286 \end_layout
16287
16288 \begin_layout Standard
16289 Starting from a small snippet of c-code this example shows for the MCS51
16290  how to use inline assembly, access variables, a function parameter and
16291  an array in xdata memory.
16292  The example uses an MCS51 here but is easily adapted for other architectures.
16293  This is a buffer routine which should be optimized:
16294 \end_layout
16295
16296 \begin_layout Verse
16297
16298 \family typewriter
16299 \size footnotesize
16300 unsigned char __far
16301 \begin_inset LatexCommand \index{far (storage class)}
16302
16303 \end_inset
16304
16305
16306 \begin_inset LatexCommand \index{\_\_far (storage class)}
16307
16308 \end_inset
16309
16310  __at
16311 \begin_inset LatexCommand \index{at}
16312
16313 \end_inset
16314
16315
16316 \begin_inset LatexCommand \index{\_\_at}
16317
16318 \end_inset
16319
16320 (0x7f00) buf[0x100];
16321 \begin_inset LatexCommand \index{Aligned array}
16322
16323 \end_inset
16324
16325
16326 \newline
16327 unsigned char head, tail;\InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 \InsetSpace ~
16344 /* if interrupts
16345 \begin_inset LatexCommand \index{interrupt}
16346
16347 \end_inset
16348
16349  are involved see
16350 \newline
16351 \InsetSpace ~
16352 \InsetSpace ~
16353 \InsetSpace ~
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 \InsetSpace ~
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 \InsetSpace ~
16377 \InsetSpace ~
16378 \InsetSpace ~
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 \InsetSpace ~
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 section 
16397 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16398
16399 \end_inset
16400
16401  about
16402 \series bold
16403  volatile
16404 \series default
16405  */
16406 \newline
16407
16408 \newline
16409 void to_buffer( unsigned char c ) 
16410 \newline
16411 {
16412 \newline
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 if( head != (unsigned char)(tail-1)
16418  )\InsetSpace ~
16419 /* cast 
16420 \series bold
16421 needed
16422 \series default
16423  to avoid promotion
16424 \begin_inset LatexCommand \index{promotion to signed int}
16425
16426 \end_inset
16427
16428
16429 \begin_inset LatexCommand \index{type promotion}
16430
16431 \end_inset
16432
16433  to integer */
16434 \begin_inset Marginal
16435 status collapsed
16436
16437 \begin_layout Standard
16438
16439 \series bold
16440 \InsetSpace ~
16441 !
16442 \end_layout
16443
16444 \end_inset
16445
16446
16447 \newline
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 buf[ head++ ] = c;\InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 \InsetSpace ~
16463 \InsetSpace ~
16464 \InsetSpace ~
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 /* access to a 256 byte aligned array */
16473 \newline
16474
16475 \end_layout
16476
16477 \begin_layout Standard
16478 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16479  then a corresponding buffer.asm file is generated.
16480  We define a new function 
16481 \family typewriter
16482 to_buffer_asm()
16483 \family default
16484  in file buffer.c in which we cut and paste the generated code, removing
16485  unwanted comments and some ':'.
16486  Then add 
16487 \begin_inset Quotes sld
16488 \end_inset
16489
16490
16491 \series bold
16492 _asm
16493 \series default
16494
16495 \begin_inset Quotes srd
16496 \end_inset
16497
16498  and 
16499 \begin_inset Quotes sld
16500 \end_inset
16501
16502
16503 \series bold
16504 _endasm;
16505 \series default
16506
16507 \begin_inset Quotes srd
16508 \end_inset
16509
16510
16511 \begin_inset Foot
16512 status open
16513
16514 \begin_layout Standard
16515 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16516  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16517  has to be used.
16518  The latter is also used in the library functions.
16519 \end_layout
16520
16521 \end_inset
16522
16523  to the beginning and the end of the function body:
16524 \end_layout
16525
16526 \begin_layout Verse
16527
16528 \family typewriter
16529 \size footnotesize
16530 /* With a cut and paste from the .asm file, we have something to start with.
16531 \newline
16532 \InsetSpace ~
16533 \InsetSpace ~
16534 \InsetSpace ~
16535 The
16536  function is not yet OK! (registers aren't saved) */ 
16537 \newline
16538 void to_buffer_asm(
16539  unsigned char c ) 
16540 \newline
16541
16542 \newline
16543 \InsetSpace ~
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 _asm
16548 \begin_inset LatexCommand \index{\_asm}
16549
16550 \end_inset
16551
16552
16553 \begin_inset LatexCommand \index{\_\_asm}
16554
16555 \end_inset
16556
16557
16558 \newline
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 mov\InsetSpace ~
16564 \InsetSpace ~
16565 r2,dpl 
16566 \newline
16567 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16568 /* cast 
16569 \series bold
16570 needed
16571 \series default
16572  to avoid promotion
16573 \begin_inset LatexCommand \index{promotion to signed int}
16574
16575 \end_inset
16576
16577
16578 \begin_inset LatexCommand \index{type promotion}
16579
16580 \end_inset
16581
16582  to integer */
16583 \newline
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 \InsetSpace ~
16588 mov\InsetSpace ~
16589 \InsetSpace ~
16590 a,_tail 
16591 \newline
16592 \InsetSpace ~
16593 \InsetSpace ~
16594 \InsetSpace ~
16595 \InsetSpace ~
16596 dec\InsetSpace ~
16597 \InsetSpace ~
16598
16599 \newline
16600 \InsetSpace ~
16601 \InsetSpace ~
16602 \InsetSpace ~
16603 \InsetSpace ~
16604 mov\InsetSpace ~
16605 \InsetSpace ~
16606 r3,a 
16607 \newline
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 \InsetSpace ~
16611 \InsetSpace ~
16612 mov\InsetSpace ~
16613 \InsetSpace ~
16614 a,_head 
16615 \newline
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 cjne a,ar3,00106$ 
16621 \newline
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 ret
16627 \newline
16628 00106$:
16629  
16630 \newline
16631 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16632 \begin_inset LatexCommand \index{Aligned array}
16633
16634 \end_inset
16635
16636
16637 \newline
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 mov\InsetSpace ~
16643 \InsetSpace ~
16644 r3,_head 
16645 \newline
16646 \InsetSpace ~
16647 \InsetSpace ~
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 inc\InsetSpace ~
16651 \InsetSpace ~
16652 _head 
16653 \newline
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 \InsetSpace ~
16657 \InsetSpace ~
16658 mov\InsetSpace ~
16659 \InsetSpace ~
16660 dpl,r3 
16661 \newline
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 mov\InsetSpace ~
16667 \InsetSpace ~
16668 dph,#(_buf >> 8) 
16669 \newline
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 mov\InsetSpace ~
16675 \InsetSpace ~
16676 a,r2 
16677 \newline
16678 \InsetSpace ~
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 movx @dptr,a
16683  
16684 \newline
16685 00103$: 
16686 \newline
16687 \InsetSpace ~
16688 \InsetSpace ~
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 ret
16692 \newline
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 _endasm
16698 \begin_inset LatexCommand \index{\_endasm}
16699
16700 \end_inset
16701
16702
16703 \begin_inset LatexCommand \index{\_\_endasm}
16704
16705 \end_inset
16706
16707 ;
16708 \newline
16709
16710 \end_layout
16711
16712 \begin_layout Standard
16713 The new file buffer.c should compile with only one warning about the unreferenced
16714  function argument 'c'.
16715  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16716  (1) and finally have:
16717 \end_layout
16718
16719 \begin_layout Verse
16720
16721 \family typewriter
16722 \size footnotesize
16723 unsigned char __far __at(0x7f00) buf[0x100];
16724 \newline
16725 unsigned char head, tail;
16726 \newline
16727 #define
16728  USE_ASSEMBLY (1)
16729 \newline
16730
16731 \newline
16732 #if !USE_ASSEMBLY
16733 \newline
16734
16735 \newline
16736 void to_buffer( unsigned char c )
16737 \newline
16738 {
16739 \newline
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 if(
16745  head != (unsigned char)(tail-1) )
16746 \newline
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 buf[ head++ ] = c;
16756 \newline
16757 }
16758 \newline
16759
16760 \newline
16761 #else
16762 \newline
16763
16764 \newline
16765 void to_buffer(
16766  unsigned char c )
16767 \newline
16768 {
16769 \newline
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 c; // to avoid warning: unreferenced function argument
16775 \newline
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 _asm
16781 \begin_inset LatexCommand \index{\_asm}
16782
16783 \end_inset
16784
16785
16786 \begin_inset LatexCommand \index{\_\_asm}
16787
16788 \end_inset
16789
16790
16791 \newline
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 ; save used registers here.
16801  
16802 \newline
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 ; If we were still using r2,r3 we would have to push them here.
16812  
16813 \newline
16814 ; if( head != (unsigned char)(tail-1) )
16815 \newline
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 mov\InsetSpace ~
16825  a,_tail
16826 \newline
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 dec\InsetSpace ~
16836  a
16837 \newline
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 xrl\InsetSpace ~
16847  a,_head
16848 \newline
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 ; we
16858  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16859 \newline
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 jz\InsetSpace ~
16869 \InsetSpace ~
16870  t_b_end$
16871 \newline
16872 \InsetSpace ~
16873 \InsetSpace ~
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 ;
16881 \newline
16882 ;
16883  buf[ head++ ] = c;
16884 \newline
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 mov\InsetSpace ~
16894  a,dpl \InsetSpace ~
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 ; dpl holds lower byte of function argument
16902 \newline
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 mov\InsetSpace ~
16912
16913  dpl,_head \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 ; buf is 0x100 byte aligned so head can be used directly
16917 \newline
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 mov\InsetSpace ~
16927  dph,#(_bu
16928 f>>8)
16929 \newline
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 movx @dptr,a
16939 \newline
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 inc \InsetSpace ~
16949 _head
16950 \newline
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 ; we could do an ANL _head,#0x0f here to use a
16960  smaller buffer (see above)
16961 \newline
16962 t_b_end$:
16963 \newline
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 \InsetSpace ~
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 ; restore used registers here 
16973 \newline
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 _endasm
16979 \begin_inset LatexCommand \index{\_endasm}
16980
16981 \end_inset
16982
16983
16984 \begin_inset LatexCommand \index{\_\_endasm}
16985
16986 \end_inset
16987
16988 ;
16989 \newline
16990 }
16991 \newline
16992 #endif
16993 \end_layout
16994
16995 \begin_layout Standard
16996 The inline assembler code can contain any valid code understood by the assembler
16997 , this includes any assembler directives and comment lines.
16998  The assembler does not like some characters like ':' or ''' in comments.
16999  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17000 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17001
17002 \end_inset
17003
17004
17005 \begin_inset LatexCommand \index{Assembler documentation}
17006
17007 \end_inset
17008
17009  or online at 
17010 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17011
17012 \end_inset
17013
17014 \InsetSpace ~
17015 .
17016 \end_layout
17017
17018 \begin_layout Standard
17019 The compiler does not do any validation of the code within the 
17020 \family typewriter
17021 _asm
17022 \begin_inset LatexCommand \index{\_asm}
17023
17024 \end_inset
17025
17026
17027 \begin_inset LatexCommand \index{\_\_asm}
17028
17029 \end_inset
17030
17031  ...
17032  _endasm
17033 \size footnotesize
17034
17035 \begin_inset LatexCommand \index{\_endasm}
17036
17037 \end_inset
17038
17039
17040 \begin_inset LatexCommand \index{\_\_endasm}
17041
17042 \end_inset
17043
17044
17045 \size default
17046 ;
17047 \family default
17048  keyword pair.
17049  Specifically it will not know which registers are used and thus register
17050  pushing/popping
17051 \begin_inset LatexCommand \index{push/pop}
17052
17053 \end_inset
17054
17055  has to be done manually.
17056  
17057 \end_layout
17058
17059 \begin_layout Standard
17060 It is recommended that each assembly instruction (including labels) be placed
17061  in a separate line (as the example shows).
17062  When the -
17063 \begin_inset ERT
17064 status collapsed
17065
17066 \begin_layout Standard
17067
17068
17069 \backslash
17070 /
17071 \end_layout
17072
17073 \end_inset
17074
17075 -
17076 \emph on
17077 peep-asm
17078 \begin_inset LatexCommand \index{-\/-peep-asm}
17079
17080 \end_inset
17081
17082
17083 \emph default
17084  command line option is used, the inline assembler code will be passed through
17085  the peephole optimizer
17086 \begin_inset LatexCommand \index{Peephole optimizer}
17087
17088 \end_inset
17089
17090 .
17091  There are only a few (if any) cases where this option makes sense, it might
17092  cause some unexpected changes in the inline assembler code.
17093  Please go through the peephole optimizer rules defined in file 
17094 \emph on
17095 SDCCpeeph.def
17096 \emph default
17097  before using this option.
17098 \end_layout
17099
17100 \begin_layout Subsection
17101 Naked Functions
17102 \begin_inset LatexCommand \label{sub:Naked-Functions}
17103
17104 \end_inset
17105
17106
17107 \begin_inset LatexCommand \index{Naked functions}
17108
17109 \end_inset
17110
17111
17112 \end_layout
17113
17114 \begin_layout Standard
17115 A special keyword may be associated with a function declaring it as 
17116 \emph on
17117 _naked
17118 \begin_inset LatexCommand \index{\_naked}
17119
17120 \end_inset
17121
17122
17123 \begin_inset LatexCommand \index{\_\_naked}
17124
17125 \end_inset
17126
17127 .
17128  
17129 \emph default
17130 The 
17131 \emph on
17132 _naked
17133 \emph default
17134  function modifier attribute prevents the compiler from generating prologue
17135 \begin_inset LatexCommand \index{function prologue}
17136
17137 \end_inset
17138
17139  and epilogue
17140 \begin_inset LatexCommand \index{function epilogue}
17141
17142 \end_inset
17143
17144  code for that function.
17145  This means that the user is entirely responsible for such things as saving
17146  any registers that may need to be preserved, selecting the proper register
17147  bank, generating the 
17148 \emph on
17149 return
17150 \emph default
17151  instruction at the end, etc.
17152  Practically, this means that the contents of the function must be written
17153  in inline assembler.
17154  This is particularly useful for interrupt functions, which can have a large
17155  (and often unnecessary) prologue/epilogue.
17156  For example, compare the code generated by these two functions:
17157 \end_layout
17158
17159 \begin_layout Verse
17160
17161 \family typewriter
17162 volatile
17163 \begin_inset LatexCommand \index{volatile}
17164
17165 \end_inset
17166
17167  data unsigned char counter;
17168 \newline
17169
17170 \newline
17171 void simpleInterrupt(void) __interrupt
17172 \begin_inset LatexCommand \index{interrupt}
17173
17174 \end_inset
17175
17176
17177 \begin_inset LatexCommand \index{\_\_interrupt}
17178
17179 \end_inset
17180
17181  (1)
17182 \newline
17183 {
17184 \newline
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 counter++;
17190 \newline
17191 }
17192 \newline
17193
17194 \newline
17195 void nakedInterrupt(void) __interrupt (2) __naked
17196 \newline
17197 {
17198 \newline
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 _asm
17204 \begin_inset LatexCommand \index{\_asm}
17205
17206 \end_inset
17207
17208
17209 \begin_inset LatexCommand \index{\_\_asm}
17210
17211 \end_inset
17212
17213
17214 \newline
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 inc\InsetSpace ~
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 _counter ; does not change flags, no need to save psw
17227 \newline
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 reti\InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 ; MUST explicitly
17239  include ret or reti in _naked function.
17240 \newline
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 _endasm
17246 \begin_inset LatexCommand \index{\_endasm}
17247
17248 \end_inset
17249
17250
17251 \begin_inset LatexCommand \index{\_\_endasm}
17252
17253 \end_inset
17254
17255 ;
17256 \newline
17257 }
17258 \end_layout
17259
17260 \begin_layout Standard
17261 For an 8051 target, the generated simpleInterrupt looks like:
17262 \end_layout
17263
17264 \begin_layout Verse
17265
17266 \family typewriter
17267 Note, this is an 
17268 \emph on
17269 outdated
17270 \emph default
17271  example, recent versions of SDCC generate
17272 \newline
17273 the 
17274 \emph on
17275 same
17276 \emph default
17277  code for simpleInterrupt() and nakedInterrupt()!
17278 \newline
17279
17280 \newline
17281 _simpleInterrupt:
17282 \newline
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 push\InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 \InsetSpace ~
17291 acc
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 push\InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 b
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 pu
17308 sh\InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 dpl
17313 \newline
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 push\InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 dph
17323 \newline
17324 \InsetSpace ~
17325 \InsetSpace ~
17326 \InsetSpace ~
17327 \InsetSpace ~
17328 push\InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 psw
17333 \newline
17334 \InsetSpace ~
17335 \InsetSpace ~
17336 \InsetSpace ~
17337 \InsetSpace ~
17338 mov\InsetSpace ~
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 psw,#0x00
17344 \newline
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 \InsetSpace ~
17348 \InsetSpace ~
17349 inc\InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 _counter
17355 \newline
17356 \InsetSpace ~
17357 \InsetSpace ~
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 pop\InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 psw
17366 \newline
17367 \InsetSpace ~
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 pop\InsetSpace ~
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 dph
17377 \newline
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 \InsetSpace ~
17382 pop\InsetSpace ~
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 dpl
17388 \newline
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 pop\InsetSpace ~
17394 \InsetSpace ~
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 b
17399 \newline
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 \InsetSpace ~
17404 pop\InsetSpace ~
17405 \InsetSpace ~
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 acc
17410 \newline
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 \InsetSpace ~
17415 reti
17416 \end_layout
17417
17418 \begin_layout Standard
17419 whereas nakedInterrupt looks like:
17420 \end_layout
17421
17422 \begin_layout Verse
17423
17424 \family typewriter
17425 _nakedInterrupt:
17426 \newline
17427 \InsetSpace ~
17428 \InsetSpace ~
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 inc\InsetSpace ~
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 \InsetSpace ~
17435 _counter ; does not change flags, no need to save psw
17436 \newline
17437 \InsetSpace ~
17438 \InsetSpace ~
17439 \InsetSpace ~
17440 \InsetSpace ~
17441 reti\InsetSpace ~
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 \InsetSpace ~
17445 \InsetSpace ~
17446 \InsetSpace ~
17447 \InsetSpace ~
17448 \InsetSpace ~
17449 \InsetSpace ~
17450 \InsetSpace ~
17451 \InsetSpace ~
17452 \InsetSpace ~
17453 ;
17454  MUST explicitly include ret or reti in _naked function
17455 \end_layout
17456
17457 \begin_layout Standard
17458 The related directive #pragma exclude
17459 \begin_inset LatexCommand \index{\#pragma exclude}
17460
17461 \end_inset
17462
17463  allows a more fine grained control over pushing & popping
17464 \begin_inset LatexCommand \index{push/pop}
17465
17466 \end_inset
17467
17468  the registers.
17469 \end_layout
17470
17471 \begin_layout Standard
17472 While there is nothing preventing you from writing C code inside a 
17473 \family typewriter
17474 _naked
17475 \family default
17476  function, there are many ways to shoot yourself in the foot doing this,
17477  and it is recommended that you stick to inline assembler.
17478 \end_layout
17479
17480 \begin_layout Subsection
17481 Use of Labels within Inline Assembler
17482 \end_layout
17483
17484 \begin_layout Standard
17485 SDCC allows the use of in-line assembler with a few restrictions regarding
17486  labels.
17487  All labels defined within inline assembler code have to be of the form
17488  
17489 \emph on
17490 nnnnn$
17491 \emph default
17492  where nnnnn is a number less than 100 (which implies a limit of utmost
17493  100 inline assembler labels 
17494 \emph on
17495 per function
17496 \emph default
17497 \noun on
17498 )
17499 \noun default
17500 .
17501 \begin_inset Foot
17502 status open
17503
17504 \begin_layout Standard
17505 This is a slightly more stringent rule than absolutely necessary, but stays
17506  always on the safe side.
17507  Labels in the form of nnnnn$ are local labels in the assembler, locality
17508  of which is confined within two labels of the standard form.
17509  The compiler uses the same form for labels within a function (but starting
17510  from nnnnn=00100); and places always a standard label at the beginning
17511  of a function, thus limiting the locality of labels within the scope of
17512  the function.
17513  So, if the inline assembler part would be embedded into C-code, an improperly
17514  placed non-local label in the assembler would break up the reference space
17515  for labels created by the compiler for the C-code, leading to an assembling
17516  error.
17517 \end_layout
17518
17519 \begin_layout Standard
17520 The numeric part of local labels does not need to have 5 digits (although
17521  this is the form of labels output by the compiler), any valid integer will
17522  do.
17523  Please refer to the assemblers documentation for further details.
17524 \end_layout
17525
17526 \end_inset
17527
17528  
17529 \end_layout
17530
17531 \begin_layout Verse
17532
17533 \family typewriter
17534 _asm
17535 \begin_inset LatexCommand \index{\_asm}
17536
17537 \end_inset
17538
17539
17540 \begin_inset LatexCommand \index{\_\_asm}
17541
17542 \end_inset
17543
17544  
17545 \newline
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 mov\InsetSpace ~
17551 \InsetSpace ~
17552 \InsetSpace ~
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 b,#10 
17556 \newline
17557 00001$: 
17558 \newline
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 \InsetSpace ~
17562 \InsetSpace ~
17563 djnz\InsetSpace ~
17564 \InsetSpace ~
17565 \InsetSpace ~
17566 \InsetSpace ~
17567 b,00001$ 
17568 \newline
17569 _endasm
17570 \begin_inset LatexCommand \index{\_endasm}
17571
17572 \end_inset
17573
17574
17575 \begin_inset LatexCommand \index{\_\_endasm}
17576
17577 \end_inset
17578
17579  ;
17580 \end_layout
17581
17582 \begin_layout Standard
17583 Inline assembler code cannot reference any C-labels, however it can reference
17584  labels
17585 \begin_inset LatexCommand \index{Labels}
17586
17587 \end_inset
17588
17589  defined by the inline assembler, e.g.:
17590 \end_layout
17591
17592 \begin_layout Verse
17593
17594 \family typewriter
17595 foo() { 
17596 \newline
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 /* some c code */ 
17602 \newline
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 _asm 
17608 \newline
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 ; some assembler code 
17616 \newline
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 ljmp 0003$ 
17624 \newline
17625 \InsetSpace ~
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 _endasm;
17630  
17631 \newline
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 /* some more c code */ 
17637 \newline
17638 clabel:\InsetSpace ~
17639 \InsetSpace ~
17640 /* inline assembler cannot reference this
17641  label */ 
17642 \begin_inset Foot
17643 status open
17644
17645 \begin_layout Standard
17646 Here, the C-label 
17647 \family typewriter
17648 clabel
17649 \family default
17650  is translated by the compiler into a local label, so the locality of labels
17651  within the function is not broken.
17652 \end_layout
17653
17654 \end_inset
17655
17656
17657 \newline
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 _asm
17663 \newline
17664 \InsetSpace ~
17665 \InsetSpace ~
17666 \InsetSpace ~
17667 \InsetSpace ~
17668 0003$: ;label (can be referenced by inline assembler only) 
17669 \newline
17670 \InsetSpace ~
17671 \InsetSpace ~
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 _endasm
17675 \begin_inset LatexCommand \index{\_endasm}
17676
17677 \end_inset
17678
17679
17680 \begin_inset LatexCommand \index{\_\_endasm}
17681
17682 \end_inset
17683
17684  ; 
17685 \newline
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 /* some more c code */
17691 \newline
17692 }
17693 \end_layout
17694
17695 \begin_layout Standard
17696 In other words inline assembly code can access labels defined in inline
17697  assembly within the scope of the function.
17698  The same goes the other way, i.e.
17699  labels defines in inline assembly can not be accessed by C statements.
17700 \end_layout
17701
17702 \begin_layout Section
17703 Interfacing with Assembler Code
17704 \begin_inset LatexCommand \index{Assembler routines}
17705
17706 \end_inset
17707
17708
17709 \end_layout
17710
17711 \begin_layout Subsection
17712 Global Registers used for Parameter Passing
17713 \begin_inset LatexCommand \index{Parameter passing}
17714
17715 \end_inset
17716
17717
17718 \end_layout
17719
17720 \begin_layout Standard
17721 The compiler always uses the global registers 
17722 \emph on
17723 DPL, DPH
17724 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17725
17726 \end_inset
17727
17728
17729 \begin_inset LatexCommand \index{DPTR}
17730
17731 \end_inset
17732
17733 , B
17734 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17735
17736 \end_inset
17737
17738  
17739 \emph default
17740 and
17741 \emph on
17742  ACC
17743 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17744
17745 \end_inset
17746
17747
17748 \emph default
17749  to pass the first (non-bit) parameter to a function, and also to pass the
17750  return value 
17751 \begin_inset LatexCommand \index{return value}
17752
17753 \end_inset
17754
17755 of function; according to the following scheme: one byte return value in
17756  
17757 \emph on
17758 DPL
17759 \emph default
17760 , two byte value in 
17761 \emph on
17762 DPL
17763 \emph default
17764  (LSB) and 
17765 \emph on
17766 DPH
17767 \emph default
17768  (MSB).
17769  three byte values (generic pointers) in 
17770 \emph on
17771 DPH
17772 \emph default
17773
17774 \emph on
17775 DPL
17776 \emph default
17777  and 
17778 \emph on
17779 B
17780 \emph default
17781 , and four byte values in 
17782 \emph on
17783 DPH
17784 \emph default
17785
17786 \emph on
17787 DPL
17788 \emph default
17789 ,
17790 \emph on
17791  B
17792 \emph default
17793  and 
17794 \emph on
17795 ACC
17796 \emph default
17797 .
17798  Generic pointers
17799 \begin_inset LatexCommand \index{generic pointer}
17800
17801 \end_inset
17802
17803  contain type of accessed memory in 
17804 \emph on
17805 B
17806 \emph default
17807
17808 \series bold
17809 0x00
17810 \series default
17811  -- xdata/far, 
17812 \series bold
17813 0x40
17814 \series default
17815  -- idata/near -- , 
17816 \series bold
17817 0x60
17818 \series default
17819  -- pdata, 
17820 \series bold
17821 0x80
17822 \series default
17823  -- code
17824 \begin_inset Note Note
17825 status collapsed
17826
17827 \begin_layout Standard
17828 This might not be the case of certain memory models (medium???)
17829 \end_layout
17830
17831 \end_inset
17832
17833 .
17834 \end_layout
17835
17836 \begin_layout Standard
17837 The second parameter onwards is either allocated on the stack (for reentrant
17838  routines or if -
17839 \begin_inset ERT
17840 status collapsed
17841
17842 \begin_layout Standard
17843
17844
17845 \backslash
17846 /
17847 \end_layout
17848
17849 \end_inset
17850
17851 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17852 \end_layout
17853
17854 \begin_layout Standard
17855 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
17856  space for reentrant functions or allocated directly in bit memory otherwise.
17857 \end_layout
17858
17859 \begin_layout Standard
17860 Functions (with two or more parameters or bit parameters) that are called
17861  through function pointers
17862 \begin_inset LatexCommand \index{function pointers}
17863
17864 \end_inset
17865
17866  must therefor be reentrant so the compiler knows how to pass the parameters.
17867 \end_layout
17868
17869 \begin_layout Subsection
17870 Registers usage
17871 \end_layout
17872
17873 \begin_layout Standard
17874 Unless the called function is declared as 
17875 \family typewriter
17876 _naked
17877 \family default
17878
17879 \begin_inset LatexCommand \index{naked}
17880
17881 \end_inset
17882
17883 , or the -
17884 \begin_inset ERT
17885 status collapsed
17886
17887 \begin_layout Standard
17888
17889
17890 \backslash
17891 /
17892 \end_layout
17893
17894 \end_inset
17895
17896 -callee-saves
17897 \begin_inset LatexCommand \index{-\/-callee-saves}
17898
17899 \end_inset
17900
17901 /-
17902 \begin_inset ERT
17903 status collapsed
17904
17905 \begin_layout Standard
17906
17907
17908 \backslash
17909 /
17910 \end_layout
17911
17912 \end_inset
17913
17914 -all-callee-saves command line option or the corresponding callee_saves
17915  pragma are used, the caller will save the registers (
17916 \emph on
17917 R0-R7
17918 \emph default
17919 ) around the call, so the called function can destroy they content freely.
17920 \end_layout
17921
17922 \begin_layout Standard
17923 If the called function is not declared as 
17924 \family typewriter
17925 _naked
17926 \family default
17927 , the caller will swap register banks around the call, if caller and callee
17928  use different register banks (having them defined by the 
17929 \family typewriter
17930 _using
17931 \family default
17932  modifier).
17933  
17934 \end_layout
17935
17936 \begin_layout Standard
17937 The called function can also use 
17938 \emph on
17939 DPL
17940 \emph default
17941
17942 \emph on
17943 DPH
17944 \emph default
17945
17946 \emph on
17947 B
17948 \emph default
17949  and 
17950 \emph on
17951 ACC
17952 \emph default
17953  observing that they are used for parameter/return value passing.
17954 \end_layout
17955
17956 \begin_layout Subsection
17957 Assembler Routine (non-reentrant)
17958 \end_layout
17959
17960 \begin_layout Standard
17961 In the following example
17962 \begin_inset LatexCommand \index{reentrant}
17963
17964 \end_inset
17965
17966
17967 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17968
17969 \end_inset
17970
17971  the function c_func calls an assembler routine asm_func, which takes two
17972  parameters
17973 \begin_inset LatexCommand \index{function parameter}
17974
17975 \end_inset
17976
17977 .
17978 \end_layout
17979
17980 \begin_layout Verse
17981
17982 \family typewriter
17983 extern int asm_func(unsigned char, unsigned char);
17984 \newline
17985
17986 \newline
17987 int c_func (unsigned char
17988  i, unsigned char j)
17989 \newline
17990 {
17991 \newline
17992 \InsetSpace ~
17993 \InsetSpace ~
17994 \InsetSpace ~
17995 \InsetSpace ~
17996 return asm_func(i,j);
17997 \newline
17998 }
17999 \newline
18000
18001 \newline
18002 int main()
18003 \newline
18004 {
18005 \newline
18006 \InsetSpace ~
18007 \InsetSpace ~
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 return c_func(10,9);
18011 \newline
18012 }
18013 \end_layout
18014
18015 \begin_layout Standard
18016 The corresponding assembler function is:
18017 \end_layout
18018
18019 \begin_layout Verse
18020
18021 \family typewriter
18022 .globl _asm_func_PARM_2 
18023 \newline
18024 \InsetSpace ~
18025 \InsetSpace ~
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 \InsetSpace ~
18029 \InsetSpace ~
18030 \InsetSpace ~
18031 \InsetSpace ~
18032 .globl _asm_func 
18033 \newline
18034 \InsetSpace ~
18035 \InsetSpace ~
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 \InsetSpace ~
18039 \InsetSpace ~
18040 \InsetSpace ~
18041 \InsetSpace ~
18042 .area OSEG 
18043 \newline
18044 _asm_func_PARM_2:
18045 \newline
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 \InsetSpace ~
18051 \InsetSpace ~
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 .ds   
18055  1 
18056 \newline
18057 \InsetSpace ~
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 \InsetSpace ~
18063 \InsetSpace ~
18064 \InsetSpace ~
18065 .area CSEG 
18066 \newline
18067 _asm_func: 
18068 \newline
18069 \InsetSpace ~
18070 \InsetSpace ~
18071 \InsetSpace ~
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 mov\InsetSpace ~
18078 \InsetSpace ~
18079 \InsetSpace ~
18080 \InsetSpace ~
18081 a,dpl 
18082 \newline
18083 \InsetSpace ~
18084 \InsetSpace ~
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 \InsetSpace ~
18090 \InsetSpace ~
18091 add\InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 a,_asm_func_PARM_2 
18096 \newline
18097 \InsetSpace ~
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 \InsetSpace ~
18102 \InsetSpace ~
18103 \InsetSpace ~
18104 \InsetSpace ~
18105 mov\InsetSpace ~
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 \InsetSpace ~
18109 dpl,a 
18110 \newline
18111 \InsetSpace ~
18112 \InsetSpace ~
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 \InsetSpace ~
18119 mov\InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 dph
18124 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18125
18126 \end_inset
18127
18128 ,#0x00 
18129 \newline
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 \InsetSpace ~
18134 \InsetSpace ~
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 ret
18139 \end_layout
18140
18141 \begin_layout Standard
18142 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18143  the parameter number starting from 1, and counting from the left.
18144  The first parameter is passed in 
18145 \emph on
18146 DPH
18147 \emph default
18148
18149 \emph on
18150 DPL
18151 \emph default
18152
18153 \emph on
18154 B
18155 \emph default
18156  and 
18157 \emph on
18158 ACC
18159 \emph default
18160  according to the description above.
18161  The variable name for the second parameter will be _<function_name>_PARM_2.
18162 \newline
18163
18164 \newline
18165 Assem
18166 ble the assembler routine with the following command:
18167 \newline
18168
18169 \newline
18170
18171 \family sans
18172 \series bold
18173 asx8051 -losg asmfunc.asm
18174 \newline
18175
18176 \newline
18177
18178 \family default
18179 \series default
18180 Then compile and link the assembler routine to the C source file with the
18181  following command:
18182 \newline
18183
18184 \newline
18185
18186 \family sans
18187 \series bold
18188 sdcc cfunc.c asmfunc.rel
18189 \end_layout
18190
18191 \begin_layout Subsection
18192 Assembler Routine (reentrant)
18193 \end_layout
18194
18195 \begin_layout Standard
18196 In this case
18197 \begin_inset LatexCommand \index{reentrant}
18198
18199 \end_inset
18200
18201
18202 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18203
18204 \end_inset
18205
18206  the second parameter
18207 \begin_inset LatexCommand \index{function parameter}
18208
18209 \end_inset
18210
18211  onwards will be passed on the stack, the parameters are pushed from right
18212  to left i.e.
18213  before the call the second leftmost parameter will be on the top of the
18214  stack (the leftmost parameter is passed in registers).
18215  Here is an example:
18216 \end_layout
18217
18218 \begin_layout Verse
18219
18220 \family typewriter
18221 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18222 \newline
18223
18224 \newline
18225 int
18226  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18227 \newline
18228 {
18229  
18230 \newline
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 return asm_func(i,j,k); 
18236 \newline
18237
18238 \newline
18239
18240 \newline
18241 int main() 
18242 \newline
18243
18244 \newline
18245 \InsetSpace ~
18246 \InsetSpace ~
18247 \InsetSpace ~
18248 \InsetSpace ~
18249 return c_func(10,9,8); 
18250 \newline
18251 }
18252 \end_layout
18253
18254 \begin_layout Standard
18255 The corresponding (unoptimized) assembler routine is:
18256 \end_layout
18257
18258 \begin_layout Verse
18259
18260 \family typewriter
18261 .globl _asm_func 
18262 \newline
18263 _asm_func: 
18264 \newline
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 push\InsetSpace ~
18270 _bp 
18271 \newline
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 mov\InsetSpace ~
18277 \InsetSpace ~
18278 _bp,sp\InsetSpace ~
18279 \InsetSpace ~
18280 \InsetSpace ~
18281 \InsetSpace ~
18282 \InsetSpace ~
18283 \InsetSpace ~
18284 ;stack contains: _bp, return
18285  address, second parameter, third parameter
18286 \newline
18287 \InsetSpace ~
18288 \InsetSpace ~
18289 \InsetSpace ~
18290 \InsetSpace ~
18291 mov\InsetSpace ~
18292 \InsetSpace ~
18293 r2,dpl
18294 \newline
18295 \InsetSpace ~
18296 \InsetSpace ~
18297 \InsetSpace ~
18298 \InsetSpace ~
18299 mov\InsetSpace ~
18300 \InsetSpace ~
18301 a,_bp
18302 \newline
18303 \InsetSpace ~
18304 \InsetSpace ~
18305 \InsetSpace ~
18306 \InsetSpace ~
18307 add\InsetSpace ~
18308 \InsetSpace ~
18309 a,#0xfd\InsetSpace ~
18310 \InsetSpace ~
18311 \InsetSpace ~
18312 \InsetSpace ~
18313 \InsetSpace ~
18314 ;calculate
18315  pointer to the second parameter
18316 \newline
18317 \InsetSpace ~
18318 \InsetSpace ~
18319 \InsetSpace ~
18320 \InsetSpace ~
18321 mov\InsetSpace ~
18322 \InsetSpace ~
18323 r0,a 
18324 \newline
18325 \InsetSpace ~
18326 \InsetSpace ~
18327 \InsetSpace ~
18328 \InsetSpace ~
18329 mov\InsetSpace ~
18330 \InsetSpace ~
18331 a,_bp 
18332 \newline
18333 \InsetSpace ~
18334 \InsetSpace ~
18335 \InsetSpace ~
18336 \InsetSpace ~
18337 add\InsetSpace ~
18338 \InsetSpace ~
18339 a,#0xfc\InsetSpace ~
18340 \InsetSpace ~
18341 \InsetSpace ~
18342 \InsetSpace ~
18343 \InsetSpace ~
18344 ;calculate pointer
18345  to the rightmost parameter
18346 \newline
18347 \InsetSpace ~
18348 \InsetSpace ~
18349 \InsetSpace ~
18350 \InsetSpace ~
18351 mov\InsetSpace ~
18352 \InsetSpace ~
18353 r1,a 
18354 \newline
18355 \InsetSpace ~
18356 \InsetSpace ~
18357 \InsetSpace ~
18358 \InsetSpace ~
18359 mov\InsetSpace ~
18360 \InsetSpace ~
18361 a,@r0
18362 \newline
18363 \InsetSpace ~
18364 \InsetSpace ~
18365 \InsetSpace ~
18366 \InsetSpace ~
18367 add\InsetSpace ~
18368 \InsetSpace ~
18369 a,@r1
18370 \newline
18371 \InsetSpace ~
18372 \InsetSpace ~
18373 \InsetSpace ~
18374 \InsetSpace ~
18375 add\InsetSpace ~
18376 \InsetSpace ~
18377 a,r2\InsetSpace ~
18378 \InsetSpace ~
18379 \InsetSpace ~
18380 \InsetSpace ~
18381 \InsetSpace ~
18382 \InsetSpace ~
18383 \InsetSpace ~
18384 \InsetSpace ~
18385 ;calculate the
18386  result (= sum of all three parameters)
18387 \newline
18388 \InsetSpace ~
18389 \InsetSpace ~
18390 \InsetSpace ~
18391 \InsetSpace ~
18392 mov\InsetSpace ~
18393 \InsetSpace ~
18394 dpl,a\InsetSpace ~
18395 \InsetSpace ~
18396 \InsetSpace ~
18397 \InsetSpace ~
18398 \InsetSpace ~
18399 \InsetSpace ~
18400 \InsetSpace ~
18401 ;return value goes into dptr
18402  (cast into int)
18403 \newline
18404 \InsetSpace ~
18405 \InsetSpace ~
18406 \InsetSpace ~
18407 \InsetSpace ~
18408 mov\InsetSpace ~
18409 \InsetSpace ~
18410 dph,#0x00 
18411 \newline
18412 \InsetSpace ~
18413 \InsetSpace ~
18414 \InsetSpace ~
18415 \InsetSpace ~
18416 mov\InsetSpace ~
18417 \InsetSpace ~
18418 sp,_bp 
18419 \newline
18420 \InsetSpace ~
18421 \InsetSpace ~
18422 \InsetSpace ~
18423 \InsetSpace ~
18424 pop\InsetSpace ~
18425 \InsetSpace ~
18426 _bp 
18427 \newline
18428 \InsetSpace ~
18429 \InsetSpace ~
18430 \InsetSpace ~
18431 \InsetSpace ~
18432 ret
18433 \end_layout
18434
18435 \begin_layout Standard
18436 The compiling and linking procedure remains the same, however note the extra
18437  entry & exit linkage required for the assembler code, _bp is the stack
18438  frame pointer and is used to compute the offset into the stack for parameters
18439  and local variables.
18440 \begin_inset VSpace bigskip
18441 \end_inset
18442
18443
18444 \end_layout
18445
18446 \begin_layout Section
18447 int (16 bit)
18448 \begin_inset LatexCommand \index{int (16 bit)}
18449
18450 \end_inset
18451
18452  and long (32 bit)
18453 \begin_inset LatexCommand \index{long (32 bit)}
18454
18455 \end_inset
18456
18457  Support
18458 \end_layout
18459
18460 \begin_layout Standard
18461 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18462  multiplication and modulus operations are implemented by support routines.
18463  These support routines are all developed in ANSI-C to facilitate porting
18464  to other MCUs, although some model specific assembler optimizations are
18465  used.
18466  The following files contain the described routines, all of them can be
18467  found in <installdir>/share/sdcc/lib.
18468 \newline
18469
18470 \end_layout
18471
18472 \begin_layout Standard
18473 \align center
18474 \begin_inset Tabular
18475 <lyxtabular version="3" rows="11" columns="2">
18476 <features>
18477 <column alignment="left" valignment="top" leftline="true" width="0">
18478 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18479 <row topline="true" bottomline="true">
18480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18481 \begin_inset Text
18482
18483 \begin_layout Standard
18484
18485 \series bold
18486 Function
18487 \end_layout
18488
18489 \end_inset
18490 </cell>
18491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18492 \begin_inset Text
18493
18494 \begin_layout Standard
18495
18496 \series bold
18497 Description
18498 \end_layout
18499
18500 \end_inset
18501 </cell>
18502 </row>
18503 <row topline="true">
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18505 \begin_inset Text
18506
18507 \begin_layout Standard
18508 _mulint.c 
18509 \end_layout
18510
18511 \end_inset
18512 </cell>
18513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18514 \begin_inset Text
18515
18516 \begin_layout Standard
18517 16 bit multiplication
18518 \end_layout
18519
18520 \end_inset
18521 </cell>
18522 </row>
18523 <row topline="true">
18524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18525 \begin_inset Text
18526
18527 \begin_layout Standard
18528 _divsint.c 
18529 \end_layout
18530
18531 \end_inset
18532 </cell>
18533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18534 \begin_inset Text
18535
18536 \begin_layout Standard
18537  signed 16 bit division (calls _divuint)
18538 \end_layout
18539
18540 \end_inset
18541 </cell>
18542 </row>
18543 <row topline="true">
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18545 \begin_inset Text
18546
18547 \begin_layout Standard
18548 _divuint.c 
18549 \end_layout
18550
18551 \end_inset
18552 </cell>
18553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18554 \begin_inset Text
18555
18556 \begin_layout Standard
18557  unsigned 16 bit division
18558 \end_layout
18559
18560 \end_inset
18561 </cell>
18562 </row>
18563 <row topline="true">
18564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18565 \begin_inset Text
18566
18567 \begin_layout Standard
18568 _modsint.c
18569 \end_layout
18570
18571 \end_inset
18572 </cell>
18573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18574 \begin_inset Text
18575
18576 \begin_layout Standard
18577 signed 16 bit modulus (calls _moduint)
18578 \end_layout
18579
18580 \end_inset
18581 </cell>
18582 </row>
18583 <row topline="true">
18584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18585 \begin_inset Text
18586
18587 \begin_layout Standard
18588 _moduint.c
18589 \end_layout
18590
18591 \end_inset
18592 </cell>
18593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18594 \begin_inset Text
18595
18596 \begin_layout Standard
18597 unsigned 16 bit modulus
18598 \end_layout
18599
18600 \end_inset
18601 </cell>
18602 </row>
18603 <row topline="true">
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18605 \begin_inset Text
18606
18607 \begin_layout Standard
18608 _mullong.c
18609 \end_layout
18610
18611 \end_inset
18612 </cell>
18613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18614 \begin_inset Text
18615
18616 \begin_layout Standard
18617 32 bit multiplication
18618 \end_layout
18619
18620 \end_inset
18621 </cell>
18622 </row>
18623 <row topline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18625 \begin_inset Text
18626
18627 \begin_layout Standard
18628 _divslong.c 
18629 \end_layout
18630
18631 \end_inset
18632 </cell>
18633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18634 \begin_inset Text
18635
18636 \begin_layout Standard
18637  signed 32 division (calls _divulong)
18638 \end_layout
18639
18640 \end_inset
18641 </cell>
18642 </row>
18643 <row topline="true">
18644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18645 \begin_inset Text
18646
18647 \begin_layout Standard
18648 _divulong.c 
18649 \end_layout
18650
18651 \end_inset
18652 </cell>
18653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18654 \begin_inset Text
18655
18656 \begin_layout Standard
18657 unsigned 32 division
18658 \end_layout
18659
18660 \end_inset
18661 </cell>
18662 </row>
18663 <row topline="true">
18664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18665 \begin_inset Text
18666
18667 \begin_layout Standard
18668 _modslong.c
18669 \end_layout
18670
18671 \end_inset
18672 </cell>
18673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18674 \begin_inset Text
18675
18676 \begin_layout Standard
18677  signed 32 bit modulus (calls _modulong)
18678 \end_layout
18679
18680 \end_inset
18681 </cell>
18682 </row>
18683 <row topline="true" bottomline="true">
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18685 \begin_inset Text
18686
18687 \begin_layout Standard
18688 _modulong.c
18689 \end_layout
18690
18691 \end_inset
18692 </cell>
18693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18694 \begin_inset Text
18695
18696 \begin_layout Standard
18697 unsigned 32 bit modulus
18698 \end_layout
18699
18700 \end_inset
18701 </cell>
18702 </row>
18703 </lyxtabular>
18704
18705 \end_inset
18706
18707
18708 \newline
18709
18710 \end_layout
18711
18712 \begin_layout Standard
18713 Since they are compiled as 
18714 \emph on
18715 non-reentrant
18716 \emph default
18717
18718 \begin_inset LatexCommand \index{reentrant}
18719
18720 \end_inset
18721
18722 , interrupt
18723 \begin_inset LatexCommand \index{interrupt}
18724
18725 \end_inset
18726
18727  service routines should not do any of the above operations.
18728  If this is unavoidable then the above routines will need to be compiled
18729  with the 
18730 \emph on
18731 -
18732 \begin_inset ERT
18733 status collapsed
18734
18735 \begin_layout Standard
18736
18737
18738 \backslash
18739 /
18740 \end_layout
18741
18742 \end_inset
18743
18744 -stack-auto
18745 \begin_inset LatexCommand \index{-\/-stack-auto}
18746
18747 \end_inset
18748
18749
18750 \emph default
18751  option, after which the source program will have to be compiled with 
18752 \emph on
18753 -
18754 \begin_inset ERT
18755 status collapsed
18756
18757 \begin_layout Standard
18758
18759
18760 \backslash
18761 /
18762 \end_layout
18763
18764 \end_inset
18765
18766 -int-long-reent
18767 \begin_inset LatexCommand \index{-\/-int-long-reent}
18768
18769 \end_inset
18770
18771
18772 \emph default
18773  option.
18774  Notice that you don't have to call these routines directly.
18775  The compiler will use them automatically every time an integer operation
18776  is required.
18777 \end_layout
18778
18779 \begin_layout Section
18780 Floating Point Support
18781 \begin_inset LatexCommand \index{Floating point support}
18782
18783 \end_inset
18784
18785
18786 \end_layout
18787
18788 \begin_layout Standard
18789 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18790  The floating point support routines are derived from gcc's floatlib.c and
18791  consist of the following routines:
18792 \newline
18793
18794 \end_layout
18795
18796 \begin_layout Standard
18797 \align center
18798
18799 \size footnotesize
18800 \begin_inset Tabular
18801 <lyxtabular version="3" rows="17" columns="2">
18802 <features>
18803 <column alignment="left" valignment="top" leftline="true" width="0">
18804 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18805 <row topline="true" bottomline="true">
18806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18807 \begin_inset Text
18808
18809 \begin_layout Standard
18810
18811 \family roman
18812 \series medium
18813 \shape up
18814 \size normal
18815 \emph off
18816 \bar no
18817 \noun off
18818 \color none
18819 Function 
18820 \end_layout
18821
18822 \end_inset
18823 </cell>
18824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18825 \begin_inset Text
18826
18827 \begin_layout Standard
18828 Description
18829 \end_layout
18830
18831 \end_inset
18832 </cell>
18833 </row>
18834 <row topline="true">
18835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18836 \begin_inset Text
18837
18838 \begin_layout Standard
18839
18840 \family roman
18841 \series medium
18842 \shape up
18843 \size normal
18844 \emph off
18845 \bar no
18846 \noun off
18847 \color none
18848 _fsadd.c
18849 \end_layout
18850
18851 \end_inset
18852 </cell>
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18854 \begin_inset Text
18855
18856 \begin_layout Standard
18857
18858 \family roman
18859 \series medium
18860 \shape up
18861 \size normal
18862 \emph off
18863 \bar no
18864 \noun off
18865 \color none
18866 add floating point numbers
18867 \end_layout
18868
18869 \end_inset
18870 </cell>
18871 </row>
18872 <row topline="true">
18873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18874 \begin_inset Text
18875
18876 \begin_layout Standard
18877
18878 \family roman
18879 \series medium
18880 \shape up
18881 \size normal
18882 \emph off
18883 \bar no
18884 \noun off
18885 \color none
18886 _fssub.c 
18887 \end_layout
18888
18889 \end_inset
18890 </cell>
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18892 \begin_inset Text
18893
18894 \begin_layout Standard
18895
18896 \family roman
18897 \series medium
18898 \shape up
18899 \size normal
18900 \emph off
18901 \bar no
18902 \noun off
18903 \color none
18904 subtract floating point numbers 
18905 \end_layout
18906
18907 \end_inset
18908 </cell>
18909 </row>
18910 <row topline="true">
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18912 \begin_inset Text
18913
18914 \begin_layout Standard
18915
18916 \family roman
18917 \series medium
18918 \shape up
18919 \size normal
18920 \emph off
18921 \bar no
18922 \noun off
18923 \color none
18924 _fsdiv.c 
18925 \end_layout
18926
18927 \end_inset
18928 </cell>
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18930 \begin_inset Text
18931
18932 \begin_layout Standard
18933
18934 \family roman
18935 \series medium
18936 \shape up
18937 \size normal
18938 \emph off
18939 \bar no
18940 \noun off
18941 \color none
18942 divide floating point numbers 
18943 \end_layout
18944
18945 \end_inset
18946 </cell>
18947 </row>
18948 <row topline="true">
18949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18950 \begin_inset Text
18951
18952 \begin_layout Standard
18953
18954 \family roman
18955 \series medium
18956 \shape up
18957 \size normal
18958 \emph off
18959 \bar no
18960 \noun off
18961 \color none
18962 _fsmul.c 
18963 \end_layout
18964
18965 \end_inset
18966 </cell>
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18968 \begin_inset Text
18969
18970 \begin_layout Standard
18971
18972 \family roman
18973 \series medium
18974 \shape up
18975 \size normal
18976 \emph off
18977 \bar no
18978 \noun off
18979 \color none
18980 multiply floating point numbers 
18981 \end_layout
18982
18983 \end_inset
18984 </cell>
18985 </row>
18986 <row topline="true">
18987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18988 \begin_inset Text
18989
18990 \begin_layout Standard
18991
18992 \family roman
18993 \series medium
18994 \shape up
18995 \size normal
18996 \emph off
18997 \bar no
18998 \noun off
18999 \color none
19000 _fs2uchar.c
19001 \end_layout
19002
19003 \end_inset
19004 </cell>
19005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19006 \begin_inset Text
19007
19008 \begin_layout Standard
19009
19010 \family roman
19011 \series medium
19012 \shape up
19013 \size normal
19014 \emph off
19015 \bar no
19016 \noun off
19017 \color none
19018 convert floating point to unsigned char
19019 \end_layout
19020
19021 \end_inset
19022 </cell>
19023 </row>
19024 <row topline="true">
19025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19026 \begin_inset Text
19027
19028 \begin_layout Standard
19029
19030 \family roman
19031 \series medium
19032 \shape up
19033 \size normal
19034 \emph off
19035 \bar no
19036 \noun off
19037 \color none
19038 _fs2char.c
19039 \end_layout
19040
19041 \end_inset
19042 </cell>
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19044 \begin_inset Text
19045
19046 \begin_layout Standard
19047
19048 \family roman
19049 \series medium
19050 \shape up
19051 \size normal
19052 \emph off
19053 \bar no
19054 \noun off
19055 \color none
19056 convert floating point to signed char
19057 \end_layout
19058
19059 \end_inset
19060 </cell>
19061 </row>
19062 <row topline="true">
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19064 \begin_inset Text
19065
19066 \begin_layout Standard
19067
19068 \family roman
19069 \series medium
19070 \shape up
19071 \size normal
19072 \emph off
19073 \bar no
19074 \noun off
19075 \color none
19076 _fs2uint.c
19077 \end_layout
19078
19079 \end_inset
19080 </cell>
19081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19082 \begin_inset Text
19083
19084 \begin_layout Standard
19085
19086 \family roman
19087 \series medium
19088 \shape up
19089 \size normal
19090 \emph off
19091 \bar no
19092 \noun off
19093 \color none
19094 convert floating point to unsigned int
19095 \end_layout
19096
19097 \end_inset
19098 </cell>
19099 </row>
19100 <row topline="true">
19101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19102 \begin_inset Text
19103
19104 \begin_layout Standard
19105
19106 \family roman
19107 \series medium
19108 \shape up
19109 \size normal
19110 \emph off
19111 \bar no
19112 \noun off
19113 \color none
19114 _fs2int.c
19115 \end_layout
19116
19117 \end_inset
19118 </cell>
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19120 \begin_inset Text
19121
19122 \begin_layout Standard
19123
19124 \family roman
19125 \series medium
19126 \shape up
19127 \size normal
19128 \emph off
19129 \bar no
19130 \noun off
19131 \color none
19132 convert floating point to signed int
19133 \end_layout
19134
19135 \end_inset
19136 </cell>
19137 </row>
19138 <row topline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \begin_layout Standard
19143
19144 \family roman
19145 \series medium
19146 \shape up
19147 \size normal
19148 \emph off
19149 \bar no
19150 \noun off
19151 \color none
19152 _fs2ulong.
19153 \family default
19154 \series default
19155 \shape default
19156 \size default
19157 \emph default
19158 \bar default
19159 \noun default
19160 c
19161 \end_layout
19162
19163 \end_inset
19164 </cell>
19165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19166 \begin_inset Text
19167
19168 \begin_layout Standard
19169
19170 \family roman
19171 \series medium
19172 \shape up
19173 \size normal
19174 \emph off
19175 \bar no
19176 \noun off
19177 \color none
19178 convert floating point to unsigned long
19179 \end_layout
19180
19181 \end_inset
19182 </cell>
19183 </row>
19184 <row topline="true">
19185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19186 \begin_inset Text
19187
19188 \begin_layout Standard
19189
19190 \family roman
19191 \series medium
19192 \shape up
19193 \size normal
19194 \emph off
19195 \bar no
19196 \noun off
19197 \color none
19198 _fs2long.c
19199 \end_layout
19200
19201 \end_inset
19202 </cell>
19203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19204 \begin_inset Text
19205
19206 \begin_layout Standard
19207
19208 \family roman
19209 \series medium
19210 \shape up
19211 \size normal
19212 \emph off
19213 \bar no
19214 \noun off
19215 \color none
19216 convert floating point to signed long
19217 \end_layout
19218
19219 \end_inset
19220 </cell>
19221 </row>
19222 <row topline="true">
19223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19224 \begin_inset Text
19225
19226 \begin_layout Standard
19227
19228 \family roman
19229 \series medium
19230 \shape up
19231 \size normal
19232 \emph off
19233 \bar no
19234 \noun off
19235 \color none
19236 _uchar2fs.c
19237 \end_layout
19238
19239 \end_inset
19240 </cell>
19241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19242 \begin_inset Text
19243
19244 \begin_layout Standard
19245
19246 \family roman
19247 \series medium
19248 \shape up
19249 \size normal
19250 \emph off
19251 \bar no
19252 \noun off
19253 \color none
19254 convert unsigned char to floating point
19255 \end_layout
19256
19257 \end_inset
19258 </cell>
19259 </row>
19260 <row topline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \begin_layout Standard
19265
19266 \family roman
19267 \series medium
19268 \shape up
19269 \size normal
19270 \emph off
19271 \bar no
19272 \noun off
19273 \color none
19274 _char2fs.c
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283
19284 \family roman
19285 \series medium
19286 \shape up
19287 \size normal
19288 \emph off
19289 \bar no
19290 \noun off
19291 \color none
19292 convert char to floating point number
19293 \end_layout
19294
19295 \end_inset
19296 </cell>
19297 </row>
19298 <row topline="true">
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19300 \begin_inset Text
19301
19302 \begin_layout Standard
19303
19304 \family roman
19305 \series medium
19306 \shape up
19307 \size normal
19308 \emph off
19309 \bar no
19310 \noun off
19311 \color none
19312 _uint2fs.c
19313 \end_layout
19314
19315 \end_inset
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \begin_layout Standard
19321
19322 \family roman
19323 \series medium
19324 \shape up
19325 \size normal
19326 \emph off
19327 \bar no
19328 \noun off
19329 \color none
19330 convert unsigned int to floating point
19331 \end_layout
19332
19333 \end_inset
19334 </cell>
19335 </row>
19336 <row topline="true">
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19338 \begin_inset Text
19339
19340 \begin_layout Standard
19341
19342 \family roman
19343 \series medium
19344 \shape up
19345 \size normal
19346 \emph off
19347 \bar no
19348 \noun off
19349 \color none
19350 _int2fs.c
19351 \end_layout
19352
19353 \end_inset
19354 </cell>
19355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19356 \begin_inset Text
19357
19358 \begin_layout Standard
19359
19360 \family roman
19361 \series medium
19362 \shape up
19363 \size normal
19364 \emph off
19365 \bar no
19366 \noun off
19367 \color none
19368 convert int to floating point numbers
19369 \end_layout
19370
19371 \end_inset
19372 </cell>
19373 </row>
19374 <row topline="true">
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19376 \begin_inset Text
19377
19378 \begin_layout Standard
19379
19380 \family roman
19381 \series medium
19382 \shape up
19383 \size normal
19384 \emph off
19385 \bar no
19386 \noun off
19387 \color none
19388 _ulong2fs.c
19389 \end_layout
19390
19391 \end_inset
19392 </cell>
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19394 \begin_inset Text
19395
19396 \begin_layout Standard
19397
19398 \family roman
19399 \series medium
19400 \shape up
19401 \size normal
19402 \emph off
19403 \bar no
19404 \noun off
19405 \color none
19406 convert unsigned long to floating point number
19407 \end_layout
19408
19409 \end_inset
19410 </cell>
19411 </row>
19412 <row topline="true" bottomline="true">
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19414 \begin_inset Text
19415
19416 \begin_layout Standard
19417
19418 \family roman
19419 \series medium
19420 \shape up
19421 \size normal
19422 \emph off
19423 \bar no
19424 \noun off
19425 \color none
19426 _long2fs.c
19427 \end_layout
19428
19429 \end_inset
19430 </cell>
19431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19432 \begin_inset Text
19433
19434 \begin_layout Standard
19435
19436 \family roman
19437 \series medium
19438 \shape up
19439 \size normal
19440 \emph off
19441 \bar no
19442 \noun off
19443 \color none
19444 convert long to floating point number
19445 \end_layout
19446
19447 \end_inset
19448 </cell>
19449 </row>
19450 </lyxtabular>
19451
19452 \end_inset
19453
19454
19455 \newline
19456
19457 \end_layout
19458
19459 \begin_layout Standard
19460 These support routines are developed in ANSI-C so there is room for space
19461  and speed improvement
19462 \begin_inset Foot
19463 status open
19464
19465 \begin_layout Standard
19466 These floating point routines (
19467 \emph on
19468 not
19469 \emph default
19470  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19471  
19472 \end_layout
19473
19474 \end_inset
19475
19476 .
19477  Note if all these routines are used simultaneously the data space might
19478  overflow.
19479  For serious floating point usage the large model might be needed.
19480  Also notice that you don't have to call this routines directly.
19481  The compiler will use them automatically every time a floating point operation
19482  is required.
19483 \begin_inset VSpace bigskip
19484 \end_inset
19485
19486
19487 \end_layout
19488
19489 \begin_layout Section
19490 Library Routines
19491 \begin_inset LatexCommand \index{Libraries}
19492
19493 \end_inset
19494
19495
19496 \end_layout
19497
19498 \begin_layout Standard
19499
19500 \emph on
19501 <pending: this is messy and incomplete - a little more information is in
19502  sdcc/doc/libdoc.txt
19503 \emph default
19504  >
19505 \end_layout
19506
19507 \begin_layout Subsection
19508 Compiler support routines (_gptrget, _mulint etc.)
19509 \end_layout
19510
19511 \begin_layout Subsection
19512 Stdclib functions (puts, printf, strcat etc.)
19513 \end_layout
19514
19515 \begin_layout Subsubsection
19516 <stdio.h>
19517 \end_layout
19518
19519 \begin_layout Paragraph
19520 getchar(), putchar()
19521 \end_layout
19522
19523 \begin_layout Standard
19524 \begin_inset LatexCommand \index{<stdio.h>}
19525
19526 \end_inset
19527
19528 As usual on embedded systems you have to provide your own 
19529 \family typewriter
19530 getchar()
19531 \begin_inset LatexCommand \index{getchar()}
19532
19533 \end_inset
19534
19535  
19536 \family default
19537 and 
19538 \family typewriter
19539 putchar()
19540 \begin_inset LatexCommand \index{putchar()}
19541
19542 \end_inset
19543
19544
19545 \family default
19546  routines.
19547  SDCC does not know whether the system connects to a serial line with or
19548  without handshake, LCD, keyboard or other device.
19549  And whether a 
19550 \family typewriter
19551 lf
19552 \family default
19553  to 
19554 \family typewriter
19555 crlf
19556 \family default
19557  conversion within 
19558 \family typewriter
19559 putchar()
19560 \family default
19561  is intended.
19562  You'll find examples for serial routines f.e.
19563  in sdcc/device/lib.
19564  For the mcs51 this minimalistic polling 
19565 \family typewriter
19566 putchar()
19567 \family default
19568  routine might be a start:
19569 \end_layout
19570
19571 \begin_layout Verse
19572
19573 \family typewriter
19574 void putchar (char c) { 
19575 \newline
19576 \InsetSpace ~
19577 \InsetSpace ~
19578 \InsetSpace ~
19579 \InsetSpace ~
19580 while (!TI)\InsetSpace ~
19581 \InsetSpace ~
19582 \InsetSpace ~
19583  /* assumes UART is initialized */
19584 \newline
19585 \InsetSpace ~
19586 \InsetSpace ~
19587 \InsetSpace ~
19588 \InsetSpace ~
19589 \InsetSpace ~
19590 \InsetSpace ~
19591 \InsetSpace ~
19592 \InsetSpace ~
19593 ;
19594 \newline
19595 \InsetSpace ~
19596 \InsetSpace ~
19597 \InsetSpace ~
19598 \InsetSpace ~
19599 TI
19600  = 0;
19601 \newline
19602 \InsetSpace ~
19603 \InsetSpace ~
19604 \InsetSpace ~
19605 \InsetSpace ~
19606 SBUF = c;
19607 \newline
19608 }
19609 \end_layout
19610
19611 \begin_layout Paragraph
19612 printf()
19613 \end_layout
19614
19615 \begin_layout Standard
19616 The default
19617 \family typewriter
19618  printf()
19619 \begin_inset LatexCommand \index{printf()}
19620
19621 \end_inset
19622
19623
19624 \family default
19625  implementation in
19626 \family typewriter
19627  printf_large.c
19628 \family default
19629  does not support float (except on ds390).
19630  To enable this recompile it with the option 
19631 \emph on
19632 -
19633 \begin_inset ERT
19634 status collapsed
19635
19636 \begin_layout Standard
19637
19638
19639 \backslash
19640 /
19641 \end_layout
19642
19643 \end_inset
19644
19645 DUSE_FLOATS=1
19646 \begin_inset LatexCommand \index{USE\_FLOATS}
19647
19648 \end_inset
19649
19650
19651 \emph default
19652  on the command line.
19653  Use
19654 \emph on
19655  -
19656 \begin_inset ERT
19657 status collapsed
19658
19659 \begin_layout Standard
19660
19661
19662 \backslash
19663 /
19664 \end_layout
19665
19666 \end_inset
19667
19668 -model-large
19669 \begin_inset LatexCommand \index{-\/-model-large}
19670
19671 \end_inset
19672
19673
19674 \emph default
19675  for the mcs51 port, since this uses a lot of memory.
19676 \end_layout
19677
19678 \begin_layout Standard
19679 If you're short on code memory you might want to use 
19680 \family typewriter
19681 printf_small()
19682 \begin_inset LatexCommand \index{printf\_small()}
19683
19684 \end_inset
19685
19686
19687 \family default
19688  
19689 \emph on
19690 instead
19691 \emph default
19692  of
19693 \family typewriter
19694  printf().
19695
19696 \family default
19697  For the mcs51 there additionally are assembly versions 
19698 \family typewriter
19699 printf_tiny()
19700 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19701
19702 \end_inset
19703
19704
19705 \family default
19706  (subset of printf using less than 270 bytes) and 
19707 \family typewriter
19708 printf_fast()
19709 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19710
19711 \end_inset
19712
19713  
19714 \family default
19715 and
19716 \family typewriter
19717  printf_fast_f()
19718 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19719
19720 \end_inset
19721
19722
19723 \family default
19724  (floating-point aware version of printf_fast) which should fit the requirements
19725  of many embedded systems (printf_fast() can be customized by unsetting
19726  #defines to 
19727 \emph on
19728 not
19729 \emph default
19730  support long variables and field widths).
19731  Be sure to use only one of these printf options within a project.
19732 \newline
19733
19734 \end_layout
19735
19736 \begin_layout Standard
19737 Feature matrix of different 
19738 \emph on
19739 printf
19740 \emph default
19741  options on mcs51.
19742 \end_layout
19743
19744 \begin_layout Standard
19745 \begin_inset Tabular
19746 <lyxtabular version="3" rows="14" columns="7">
19747 <features islongtable="true">
19748 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19749 <column alignment="center" valignment="top" leftline="true" width="0">
19750 <column alignment="center" valignment="top" leftline="true" width="12col%">
19751 <column alignment="center" valignment="top" leftline="true" width="10col%">
19752 <column alignment="center" valignment="top" leftline="true" width="0">
19753 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19754 <column alignment="center" valignment="top" rightline="true" width="0">
19755 <row topline="true" bottomline="true" endhead="true">
19756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19757 \begin_inset Text
19758
19759 \begin_layout Standard
19760
19761 \series bold
19762 \size large
19763 mcs51
19764 \end_layout
19765
19766 \end_inset
19767 </cell>
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19769 \begin_inset Text
19770
19771 \begin_layout Standard
19772 printf
19773 \begin_inset LatexCommand \index{printf}
19774
19775 \end_inset
19776
19777
19778 \end_layout
19779
19780 \end_inset
19781 </cell>
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19783 \begin_inset Text
19784
19785 \begin_layout Standard
19786 printf 
19787 \size scriptsize
19788 USE_FLOATS=1
19789 \end_layout
19790
19791 \end_inset
19792 </cell>
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19794 \begin_inset Text
19795
19796 \begin_layout Standard
19797 printf_small
19798 \end_layout
19799
19800 \end_inset
19801 </cell>
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806 printf_fast
19807 \end_layout
19808
19809 \end_inset
19810 </cell>
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19812 \begin_inset Text
19813
19814 \begin_layout Standard
19815 printf_fast_f
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824 printf_tiny
19825 \end_layout
19826
19827 \end_inset
19828 </cell>
19829 </row>
19830 <row topline="true" endhead="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19832 \begin_inset Text
19833
19834 \begin_layout Standard
19835 filename
19836 \end_layout
19837
19838 \end_inset
19839 </cell>
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19841 \begin_inset Text
19842
19843 \begin_layout Standard
19844
19845 \size scriptsize
19846 printf_large.c
19847 \end_layout
19848
19849 \end_inset
19850 </cell>
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_inset Text
19853
19854 \begin_layout Standard
19855
19856 \size scriptsize
19857 printf_large.c
19858 \end_layout
19859
19860 \end_inset
19861 </cell>
19862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19863 \begin_inset Text
19864
19865 \begin_layout Standard
19866
19867 \size scriptsize
19868 printfl.c
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877
19878 \size scriptsize
19879 printf_fast.c
19880 \end_layout
19881
19882 \end_inset
19883 </cell>
19884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19885 \begin_inset Text
19886
19887 \begin_layout Standard
19888
19889 \size scriptsize
19890 printf_fast_f.c
19891 \end_layout
19892
19893 \end_inset
19894 </cell>
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19896 \begin_inset Text
19897
19898 \begin_layout Standard
19899
19900 \size scriptsize
19901 printf_tiny.c
19902 \end_layout
19903
19904 \end_inset
19905 </cell>
19906 </row>
19907 <row topline="true" endhead="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19909 \begin_inset Text
19910
19911 \begin_layout Standard
19912 \begin_inset Quotes sld
19913 \end_inset
19914
19915 Hello World
19916 \begin_inset Quotes srd
19917 \end_inset
19918
19919  size
19920 \end_layout
19921
19922 \begin_layout Standard
19923 small / large
19924 \end_layout
19925
19926 \end_inset
19927 </cell>
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19929 \begin_inset Text
19930
19931 \begin_layout Standard
19932 1.7k / 2.4k
19933 \end_layout
19934
19935 \end_inset
19936 </cell>
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_inset Text
19939
19940 \begin_layout Standard
19941 4.3k / 5.6k
19942 \end_layout
19943
19944 \end_inset
19945 </cell>
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19947 \begin_inset Text
19948
19949 \begin_layout Standard
19950 1.2k / 1.8k
19951 \end_layout
19952
19953 \end_inset
19954 </cell>
19955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19956 \begin_inset Text
19957
19958 \begin_layout Standard
19959 1.3k / 1.3k
19960 \end_layout
19961
19962 \end_inset
19963 </cell>
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19965 \begin_inset Text
19966
19967 \begin_layout Standard
19968 1.9k / 1.9k
19969 \end_layout
19970
19971 \end_inset
19972 </cell>
19973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19974 \begin_inset Text
19975
19976 \begin_layout Standard
19977 0.44k / 0.44k
19978 \end_layout
19979
19980 \end_inset
19981 </cell>
19982 </row>
19983 <row topline="true" endhead="true">
19984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19985 \begin_inset Text
19986
19987 \begin_layout Standard
19988 code size
19989 \end_layout
19990
19991 \begin_layout Standard
19992 small / large
19993 \end_layout
19994
19995 \end_inset
19996 </cell>
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19998 \begin_inset Text
19999
20000 \begin_layout Standard
20001 1.4k / 2.0k
20002 \end_layout
20003
20004 \end_inset
20005 </cell>
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \begin_layout Standard
20010 2.8k / 3.7k
20011 \end_layout
20012
20013 \end_inset
20014 </cell>
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20016 \begin_inset Text
20017
20018 \begin_layout Standard
20019 0.45k / 0.47k (+ _ltoa)
20020 \end_layout
20021
20022 \end_inset
20023 </cell>
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20025 \begin_inset Text
20026
20027 \begin_layout Standard
20028 1.2k / 1.2k
20029 \end_layout
20030
20031 \end_inset
20032 </cell>
20033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20034 \begin_inset Text
20035
20036 \begin_layout Standard
20037 1.6k / 1.6k
20038 \end_layout
20039
20040 \end_inset
20041 </cell>
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_inset Text
20044
20045 \begin_layout Standard
20046 0.26k / 0.26k
20047 \end_layout
20048
20049 \end_inset
20050 </cell>
20051 </row>
20052 <row topline="true">
20053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20054 \begin_inset Text
20055
20056 \begin_layout Standard
20057 formats
20058 \end_layout
20059
20060 \end_inset
20061 </cell>
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20063 \begin_inset Text
20064
20065 \begin_layout Standard
20066 cdi
20067 \emph on
20068 o
20069 \emph default
20070 psux
20071 \end_layout
20072
20073 \end_inset
20074 </cell>
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20076 \begin_inset Text
20077
20078 \begin_layout Standard
20079
20080 \family roman
20081 \series medium
20082 \shape up
20083 \size normal
20084 \emph off
20085 \bar no
20086 \noun off
20087 \color none
20088 cd
20089 \family default
20090 \series default
20091 \shape default
20092 \size default
20093 \emph default
20094 \bar default
20095 \noun default
20096 f
20097 \family roman
20098 \series medium
20099 \shape up
20100 \size normal
20101 \emph off
20102 \bar no
20103 \noun off
20104 i
20105 \family default
20106 \series default
20107 \shape default
20108 \size default
20109 \emph on
20110 \bar default
20111 \noun default
20112 o
20113 \family roman
20114 \series medium
20115 \shape up
20116 \size normal
20117 \emph off
20118 \bar no
20119 \noun off
20120 psux
20121 \end_layout
20122
20123 \end_inset
20124 </cell>
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20126 \begin_inset Text
20127
20128 \begin_layout Standard
20129 c
20130 \family roman
20131 \series medium
20132 \shape up
20133 \size normal
20134 \emph off
20135 \bar no
20136 \noun off
20137 \color none
20138 d
20139 \family default
20140 \series default
20141 \shape default
20142 \size default
20143 \emph on
20144 \bar default
20145 \noun default
20146 o
20147 \family roman
20148 \series medium
20149 \shape up
20150 \size normal
20151 \emph off
20152 \bar no
20153 \noun off
20154 s
20155 \family default
20156 \series default
20157 \shape default
20158 \size default
20159 \emph default
20160 \bar default
20161 \noun default
20162 x
20163 \end_layout
20164
20165 \end_inset
20166 </cell>
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_inset Text
20169
20170 \begin_layout Standard
20171 cdsux
20172 \end_layout
20173
20174 \end_inset
20175 </cell>
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \begin_layout Standard
20180 cdfsux
20181 \end_layout
20182
20183 \end_inset
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \begin_layout Standard
20189 cdsux
20190 \end_layout
20191
20192 \end_inset
20193 </cell>
20194 </row>
20195 <row topline="true">
20196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20197 \begin_inset Text
20198
20199 \begin_layout Standard
20200 long (32 bit) support
20201 \end_layout
20202
20203 \end_inset
20204 </cell>
20205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20206 \begin_inset Text
20207
20208 \begin_layout Standard
20209 x
20210 \end_layout
20211
20212 \end_inset
20213 </cell>
20214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20215 \begin_inset Text
20216
20217 \begin_layout Standard
20218 x
20219 \end_layout
20220
20221 \end_inset
20222 </cell>
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_inset Text
20225
20226 \begin_layout Standard
20227 x
20228 \end_layout
20229
20230 \end_inset
20231 </cell>
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20233 \begin_inset Text
20234
20235 \begin_layout Standard
20236 x
20237 \end_layout
20238
20239 \end_inset
20240 </cell>
20241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20242 \begin_inset Text
20243
20244 \begin_layout Standard
20245
20246 \family roman
20247 \series medium
20248 \shape up
20249 \size normal
20250 \emph off
20251 \bar no
20252 \noun off
20253 \color none
20254 x
20255 \end_layout
20256
20257 \end_inset
20258 </cell>
20259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20260 \begin_inset Text
20261
20262 \begin_layout Standard
20263 -
20264 \end_layout
20265
20266 \end_inset
20267 </cell>
20268 </row>
20269 <row topline="true">
20270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20271 \begin_inset Text
20272
20273 \begin_layout Standard
20274 byte arguments on stack
20275 \end_layout
20276
20277 \end_inset
20278 </cell>
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20280 \begin_inset Text
20281
20282 \begin_layout Standard
20283 b
20284 \end_layout
20285
20286 \end_inset
20287 </cell>
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_inset Text
20290
20291 \begin_layout Standard
20292 b
20293 \end_layout
20294
20295 \end_inset
20296 </cell>
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_inset Text
20299
20300 \begin_layout Standard
20301 -
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310 -
20311 \end_layout
20312
20313 \end_inset
20314 </cell>
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20316 \begin_inset Text
20317
20318 \begin_layout Standard
20319 -
20320 \end_layout
20321
20322 \end_inset
20323 </cell>
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20325 \begin_inset Text
20326
20327 \begin_layout Standard
20328 -
20329 \end_layout
20330
20331 \end_inset
20332 </cell>
20333 </row>
20334 <row topline="true">
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20336 \begin_inset Text
20337
20338 \begin_layout Standard
20339 float format
20340 \begin_inset LatexCommand \index{Floating point support}
20341
20342 \end_inset
20343
20344
20345 \end_layout
20346
20347 \end_inset
20348 </cell>
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \begin_layout Standard
20353 -
20354 \end_layout
20355
20356 \end_inset
20357 </cell>
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_inset Text
20360
20361 \begin_layout Standard
20362 %f
20363 \end_layout
20364
20365 \end_inset
20366 </cell>
20367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20368 \begin_inset Text
20369
20370 \begin_layout Standard
20371 -
20372 \end_layout
20373
20374 \end_inset
20375 </cell>
20376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20377 \begin_inset Text
20378
20379 \begin_layout Standard
20380 -
20381 \end_layout
20382
20383 \end_inset
20384 </cell>
20385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20386 \begin_inset Text
20387
20388 \begin_layout Standard
20389 %f
20390 \begin_inset Foot
20391 status collapsed
20392
20393 \begin_layout Standard
20394 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20395 \end_layout
20396
20397 \end_inset
20398
20399
20400 \end_layout
20401
20402 \end_inset
20403 </cell>
20404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20405 \begin_inset Text
20406
20407 \begin_layout Standard
20408 -
20409 \end_layout
20410
20411 \end_inset
20412 </cell>
20413 </row>
20414 <row topline="true">
20415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20416 \begin_inset Text
20417
20418 \begin_layout Standard
20419 float formats %e %g
20420 \end_layout
20421
20422 \end_inset
20423 </cell>
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20425 \begin_inset Text
20426
20427 \begin_layout Standard
20428 -
20429 \end_layout
20430
20431 \end_inset
20432 </cell>
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20434 \begin_inset Text
20435
20436 \begin_layout Standard
20437 -
20438 \end_layout
20439
20440 \end_inset
20441 </cell>
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20443 \begin_inset Text
20444
20445 \begin_layout Standard
20446 -
20447 \end_layout
20448
20449 \end_inset
20450 </cell>
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20452 \begin_inset Text
20453
20454 \begin_layout Standard
20455 -
20456 \end_layout
20457
20458 \end_inset
20459 </cell>
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20461 \begin_inset Text
20462
20463 \begin_layout Standard
20464 -
20465 \end_layout
20466
20467 \end_inset
20468 </cell>
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20470 \begin_inset Text
20471
20472 \begin_layout Standard
20473 -
20474 \end_layout
20475
20476 \end_inset
20477 </cell>
20478 </row>
20479 <row topline="true" bottomline="true">
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 \begin_inset Text
20482
20483 \begin_layout Standard
20484 field width
20485 \end_layout
20486
20487 \end_inset
20488 </cell>
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 x
20494 \end_layout
20495
20496 \end_inset
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \begin_layout Standard
20502 x
20503 \end_layout
20504
20505 \end_inset
20506 </cell>
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \begin_layout Standard
20511 -
20512 \end_layout
20513
20514 \end_inset
20515 </cell>
20516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20517 \begin_inset Text
20518
20519 \begin_layout Standard
20520 x
20521 \end_layout
20522
20523 \end_inset
20524 </cell>
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20526 \begin_inset Text
20527
20528 \begin_layout Standard
20529 x
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538 -
20539 \end_layout
20540
20541 \end_inset
20542 </cell>
20543 </row>
20544 <row bottomline="true">
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20546 \begin_inset Text
20547
20548 \begin_layout Standard
20549 string speed
20550 \begin_inset Foot
20551 status collapsed
20552
20553 \begin_layout Standard
20554 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20555 \backslash
20556 r', '
20557 \backslash
20558 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20559 \end_layout
20560
20561 \end_inset
20562
20563 ,
20564 \end_layout
20565
20566 \begin_layout Standard
20567 small / large
20568 \end_layout
20569
20570 \end_inset
20571 </cell>
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \begin_layout Standard
20576 1.52 / 2.59 ms
20577 \end_layout
20578
20579 \end_inset
20580 </cell>
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20582 \begin_inset Text
20583
20584 \begin_layout Standard
20585 1.53 / 2.62 ms
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \begin_layout Standard
20594 0.92 / 0.93 ms
20595 \end_layout
20596
20597 \end_inset
20598 </cell>
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20600 \begin_inset Text
20601
20602 \begin_layout Standard
20603 0.45 / 0.45 ms
20604 \end_layout
20605
20606 \end_inset
20607 </cell>
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20609 \begin_inset Text
20610
20611 \begin_layout Standard
20612 0.46 / 0.46 ms
20613 \end_layout
20614
20615 \end_inset
20616 </cell>
20617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20618 \begin_inset Text
20619
20620 \begin_layout Standard
20621 0.45 / 0.45 ms
20622 \end_layout
20623
20624 \end_inset
20625 </cell>
20626 </row>
20627 <row bottomline="true">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20629 \begin_inset Text
20630
20631 \begin_layout Standard
20632 int speed
20633 \begin_inset Foot
20634 status collapsed
20635
20636 \begin_layout Standard
20637 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20638  putchar()
20639 \end_layout
20640
20641 \end_inset
20642
20643 ,
20644 \end_layout
20645
20646 \begin_layout Standard
20647 small / large
20648 \end_layout
20649
20650 \end_inset
20651 </cell>
20652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20653 \begin_inset Text
20654
20655 \begin_layout Standard
20656 3.01 / 3.61 ms
20657 \end_layout
20658
20659 \end_inset
20660 </cell>
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20662 \begin_inset Text
20663
20664 \begin_layout Standard
20665 3.01 / 3.61 ms
20666 \end_layout
20667
20668 \end_inset
20669 </cell>
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_inset Text
20672
20673 \begin_layout Standard
20674 3.51 / 18.13 ms
20675 \end_layout
20676
20677 \end_inset
20678 </cell>
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20680 \begin_inset Text
20681
20682 \begin_layout Standard
20683 0.22 / 0.22 ms
20684 \end_layout
20685
20686 \end_inset
20687 </cell>
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20689 \begin_inset Text
20690
20691 \begin_layout Standard
20692 0.23 / 0.23 ms
20693 \end_layout
20694
20695 \end_inset
20696 </cell>
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \begin_layout Standard
20701 0.25 / 0.25 ms
20702 \begin_inset Foot
20703 status collapsed
20704
20705 \begin_layout Standard
20706 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20707 \end_layout
20708
20709 \end_inset
20710
20711
20712 \end_layout
20713
20714 \end_inset
20715 </cell>
20716 </row>
20717 <row bottomline="true">
20718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20719 \begin_inset Text
20720
20721 \begin_layout Standard
20722 long speed
20723 \begin_inset Foot
20724 status collapsed
20725
20726 \begin_layout Standard
20727 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20728  empty putchar()
20729 \end_layout
20730
20731 \end_inset
20732
20733 ,
20734 \end_layout
20735
20736 \begin_layout Standard
20737 small / large
20738 \end_layout
20739
20740 \end_inset
20741 </cell>
20742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20743 \begin_inset Text
20744
20745 \begin_layout Standard
20746 5.37 / 6.31 ms
20747 \end_layout
20748
20749 \end_inset
20750 </cell>
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20752 \begin_inset Text
20753
20754 \begin_layout Standard
20755 5.37 / 6.31 ms
20756 \end_layout
20757
20758 \end_inset
20759 </cell>
20760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20761 \begin_inset Text
20762
20763 \begin_layout Standard
20764 8.71 / 40.65 ms
20765 \end_layout
20766
20767 \end_inset
20768 </cell>
20769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20770 \begin_inset Text
20771
20772 \begin_layout Standard
20773 0.40 / 0.40 ms
20774 \end_layout
20775
20776 \end_inset
20777 </cell>
20778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20779 \begin_inset Text
20780
20781 \begin_layout Standard
20782 0.40 / 0.40 ms
20783 \end_layout
20784
20785 \end_inset
20786 </cell>
20787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20788 \begin_inset Text
20789
20790 \begin_layout Standard
20791 -
20792 \end_layout
20793
20794 \end_inset
20795 </cell>
20796 </row>
20797 <row bottomline="true">
20798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20799 \begin_inset Text
20800
20801 \begin_layout Standard
20802 float speed
20803 \begin_inset Foot
20804 status collapsed
20805
20806 \begin_layout Standard
20807 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20808  empty putchar()
20809 \end_layout
20810
20811 \end_inset
20812
20813 ,
20814 \end_layout
20815
20816 \begin_layout Standard
20817 small / large
20818 \end_layout
20819
20820 \end_inset
20821 </cell>
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \begin_layout Standard
20826 -
20827 \end_layout
20828
20829 \end_inset
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \begin_layout Standard
20835 7.49 / 22.47 ms
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \begin_layout Standard
20844 -
20845 \end_layout
20846
20847 \end_inset
20848 </cell>
20849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20850 \begin_inset Text
20851
20852 \begin_layout Standard
20853 -
20854 \end_layout
20855
20856 \end_inset
20857 </cell>
20858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20859 \begin_inset Text
20860
20861 \begin_layout Standard
20862 1.04 / 1.04 ms
20863 \end_layout
20864
20865 \end_inset
20866 </cell>
20867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20868 \begin_inset Text
20869
20870 \begin_layout Standard
20871 -
20872 \end_layout
20873
20874 \end_inset
20875 </cell>
20876 </row>
20877 </lyxtabular>
20878
20879 \end_inset
20880
20881
20882 \end_layout
20883
20884 \begin_layout Subsubsection
20885 <malloc.h>
20886 \begin_inset LatexCommand \index{malloc.h}
20887
20888 \end_inset
20889
20890
20891 \end_layout
20892
20893 \begin_layout Standard
20894 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20895  using dynamic memory allocation
20896 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20897
20898 \end_inset
20899
20900  and a default heap
20901 \begin_inset LatexCommand \index{heap (malloc)}
20902
20903 \end_inset
20904
20905  space of 1024 bytes is provided for malloc to allocate memory from.
20906  If you need a different heap size you need to recompile _heap.c with the
20907  required size defined in HEAP_SIZE.
20908  It is recommended to make a copy of this file into your project directory
20909  and compile it there with:
20910 \end_layout
20911
20912 \begin_layout Verse
20913
20914 \family typewriter
20915 sdcc -c _heap.c -D HEAD_SIZE=2048
20916 \end_layout
20917
20918 \begin_layout Standard
20919 And then link it with:
20920 \end_layout
20921
20922 \begin_layout Verse
20923
20924 \family typewriter
20925 sdcc main.rel _heap.rel
20926 \end_layout
20927
20928 \begin_layout Subsection
20929 Math functions (sinf, powf, sqrtf etc.)
20930 \end_layout
20931
20932 \begin_layout Subsubsection
20933 <math.h>
20934 \end_layout
20935
20936 \begin_layout Standard
20937 See definitions in file <math.h>.
20938 \end_layout
20939
20940 \begin_layout Subsection
20941 Other libraries
20942 \end_layout
20943
20944 \begin_layout Standard
20945 Libraries
20946 \begin_inset LatexCommand \index{Libraries}
20947
20948 \end_inset
20949
20950  included in SDCC should have a license at least as liberal as the GNU Lesser
20951  General Public License
20952 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20953
20954 \end_inset
20955
20956  
20957 \emph on
20958 LGPL
20959 \emph default
20960 .
20961 \end_layout
20962
20963 \begin_layout Standard
20964 \begin_inset Note Note
20965 status collapsed
20966
20967 \begin_layout Standard
20968 license statements for the libraries are missing.
20969  sdcc/device/lib/ser_ir.c
20970 \end_layout
20971
20972 \begin_layout Standard
20973 or _decdptr f.e.
20974  come with a GPL (as opposed to LGPL) License - this will not be liberal
20975  enough for many embedded programmers.
20976 \end_layout
20977
20978 \end_inset
20979
20980
20981 \end_layout
20982
20983 \begin_layout Standard
20984 If you have ported some library or want to share experience about some code
20985  which f.e.
20986  falls into any of these categories Busses (I
20987 \begin_inset Formula $^{\textrm{2}}$
20988 \end_inset
20989
20990 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20991  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20992  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20993 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20994
20995 \end_inset
20996
20997 \InsetSpace ~
20998 would certainly like to hear about it.
20999 \end_layout
21000
21001 \begin_layout Standard
21002 Programmers coding for embedded systems are not especially famous for being
21003  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21004 e these references are very valuable.
21005  Let's help to create a climate where information is shared.
21006 \begin_inset VSpace bigskip
21007 \end_inset
21008
21009
21010 \end_layout
21011
21012 \begin_layout Section
21013 Memory Models
21014 \end_layout
21015
21016 \begin_layout Subsection
21017 MCS51 Memory Models
21018 \begin_inset LatexCommand \index{Memory model}
21019
21020 \end_inset
21021
21022
21023 \begin_inset LatexCommand \index{MCS51 memory model}
21024
21025 \end_inset
21026
21027
21028 \end_layout
21029
21030 \begin_layout Subsubsection
21031 Small, Medium and Large
21032 \end_layout
21033
21034 \begin_layout Standard
21035 SDCC allows three memory models for MCS51 code, 
21036 \shape slanted
21037 small, medium
21038 \shape default
21039  and 
21040 \shape slanted
21041 large
21042 \shape default
21043 .
21044  Modules compiled with different memory models should 
21045 \emph on
21046 never
21047 \emph default
21048  be combined together or the results would be unpredictable.
21049  The library routines supplied with the compiler are compiled as small,
21050  medium and large.
21051  The compiled library modules are contained in separate directories as small,
21052  medium and large so that you can link to the appropriate set.
21053 \end_layout
21054
21055 \begin_layout Standard
21056 When the medium or large model is used all variables declared without a
21057  storage class will be allocated into the external ram, this includes all
21058  parameters and local variables (for non-reentrant
21059 \begin_inset LatexCommand \index{reentrant}
21060
21061 \end_inset
21062
21063  functions).
21064  When the small model is used variables without storage class are allocated
21065  in the internal ram.
21066 \end_layout
21067
21068 \begin_layout Standard
21069 Judicious usage of the processor specific storage classes
21070 \begin_inset LatexCommand \index{Storage class}
21071
21072 \end_inset
21073
21074  and the 'reentrant' function type will yield much more efficient code,
21075  than using the large model.
21076  Several optimizations are disabled when the program is compiled using the
21077  large model, it is therefore recommended that the small model be used unless
21078  absolutely required.
21079 \end_layout
21080
21081 \begin_layout Subsubsection
21082 External Stack
21083 \begin_inset LatexCommand \label{sub:External-Stack}
21084
21085 \end_inset
21086
21087
21088 \begin_inset LatexCommand \index{stack}
21089
21090 \end_inset
21091
21092
21093 \begin_inset LatexCommand \index{External stack (mcs51)}
21094
21095 \end_inset
21096
21097
21098 \end_layout
21099
21100 \begin_layout Standard
21101 The external stack (-
21102 \begin_inset ERT
21103 status collapsed
21104
21105 \begin_layout Standard
21106
21107
21108 \backslash
21109 /
21110 \end_layout
21111
21112 \end_inset
21113
21114 -xstack option
21115 \begin_inset LatexCommand \index{-\/-xstack}
21116
21117 \end_inset
21118
21119 ) is located in pdata
21120 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21121
21122 \end_inset
21123
21124  memory (usually at the start of the external ram segment) and uses all
21125  unused space in pdata (max.
21126  256 bytes).
21127  When -
21128 \begin_inset ERT
21129 status collapsed
21130
21131 \begin_layout Standard
21132
21133
21134 \backslash
21135 /
21136 \end_layout
21137
21138 \end_inset
21139
21140 -xstack option is used to compile the program, the parameters and local
21141  variables
21142 \begin_inset LatexCommand \index{local variables}
21143
21144 \end_inset
21145
21146  of all reentrant functions are allocated in this area.
21147  This option is provided for programs with large stack space requirements.
21148  When used with the -
21149 \begin_inset ERT
21150 status collapsed
21151
21152 \begin_layout Standard
21153
21154
21155 \backslash
21156 /
21157 \end_layout
21158
21159 \end_inset
21160
21161 -stack-auto
21162 \begin_inset LatexCommand \index{-\/-stack-auto}
21163
21164 \end_inset
21165
21166  option, all parameters and local variables are allocated on the external
21167  stack (note: support libraries will need to be recompiled with the same
21168  options.
21169  There is a predefined target in the library makefile).
21170 \end_layout
21171
21172 \begin_layout Standard
21173 The compiler outputs the higher order address byte of the external ram segment
21174  into port P2
21175 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21176
21177 \end_inset
21178
21179  (see also section 
21180 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21181
21182 \end_inset
21183
21184 ), therefore when using the External Stack option, this port 
21185 \emph on
21186 may not
21187 \emph default
21188  be used by the application program.
21189 \end_layout
21190
21191 \begin_layout Subsection
21192 DS390 Memory Model
21193 \begin_inset LatexCommand \index{Memory model}
21194
21195 \end_inset
21196
21197
21198 \begin_inset LatexCommand \index{DS390 memory model}
21199
21200 \end_inset
21201
21202
21203 \end_layout
21204
21205 \begin_layout Standard
21206 The only model supported is Flat 24
21207 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21208
21209 \end_inset
21210
21211 .
21212  This generates code for the 24 bit contiguous addressing mode of the Dallas
21213  DS80C390 part.
21214  In this mode, up to four meg of external RAM or code space can be directly
21215  addressed.
21216  See the data sheets at www.dalsemi.com for further information on this part.
21217 \newline
21218
21219 \newline
21220 Note
21221  that the compiler does not generate any code to place the processor into
21222  24 bitmode (although 
21223 \emph on
21224 tinibios
21225 \emph default
21226  in the ds390 libraries will do that for you).
21227  If you don't use 
21228 \emph on
21229 tinibios
21230 \emph default
21231
21232 \begin_inset LatexCommand \index{Tinibios (DS390)}
21233
21234 \end_inset
21235
21236 , the boot loader or similar code must ensure that the processor is in 24
21237  bit contiguous addressing mode before calling the SDCC startup code.
21238 \newline
21239
21240 \newline
21241 Like
21242  the 
21243 \emph on
21244 -
21245 \begin_inset ERT
21246 status collapsed
21247
21248 \begin_layout Standard
21249
21250
21251 \backslash
21252 /
21253 \end_layout
21254
21255 \end_inset
21256
21257 -model-large
21258 \emph default
21259  option, variables will by default be placed into the XDATA segment.
21260  
21261 \newline
21262
21263 \newline
21264 Segments may be placed anywhere in the 4 meg address space using the usual
21265  -
21266 \begin_inset ERT
21267 status collapsed
21268
21269 \begin_layout Standard
21270
21271
21272 \backslash
21273 /
21274 \end_layout
21275
21276 \end_inset
21277
21278 -*-loc options.
21279  Note that if any segments are located above 64K, the -r flag must be passed
21280  to the linker to generate the proper segment relocations, and the Intel
21281  HEX output format must be used.
21282  The -r flag can be passed to the linker by using the option 
21283 \emph on
21284 -Wl-r
21285 \emph default
21286  on the SDCC command line.
21287  However, currently the linker can not handle code segments > 64k.
21288 \end_layout
21289
21290 \begin_layout Section
21291 Pragmas
21292 \begin_inset LatexCommand \label{sec:Pragmas}
21293
21294 \end_inset
21295
21296
21297 \begin_inset LatexCommand \index{Pragmas}
21298
21299 \end_inset
21300
21301
21302 \end_layout
21303
21304 \begin_layout Standard
21305 Pragmas are used to turn on and/or off certain compiler options.
21306  Some of them are closely related to corresponding command-line options
21307  (see section 
21308 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21309
21310 \end_inset
21311
21312 ).
21313 \newline
21314 Pragmas should be placed before and/or after a function, placing pragmas
21315  inside a function body could have unpredictable results.
21316 \newline
21317
21318 \newline
21319 SDCC supports the
21320  following #pragma directives:
21321 \end_layout
21322
21323 \begin_layout Itemize
21324
21325 \series bold
21326 save
21327 \series default
21328
21329 \begin_inset LatexCommand \index{\#pragma save}
21330
21331 \end_inset
21332
21333  - this will save most current options to the save/restore stack.
21334  See #pragma\InsetSpace ~
21335 restore.
21336 \end_layout
21337
21338 \begin_layout Itemize
21339
21340 \series bold
21341 restore
21342 \series default
21343
21344 \begin_inset LatexCommand \index{\#pragma restore}
21345
21346 \end_inset
21347
21348  - will restore saved options from the last save.
21349  saves & restores can be nested.
21350  SDCC uses a save/restore stack: save pushes current options to the stack,
21351  restore pulls current options from the stack.
21352  See #pragma\InsetSpace ~
21353 save.
21354 \newline
21355
21356 \end_layout
21357
21358 \begin_layout Itemize
21359
21360 \series bold
21361 callee_saves
21362 \series default
21363
21364 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21365
21366 \end_inset
21367
21368
21369 \begin_inset LatexCommand \index{function prologue}
21370
21371 \end_inset
21372
21373  function1[,function2[,function3...]] 
21374 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21375
21376 \end_inset
21377
21378 - The compiler by default uses a caller saves convention for register saving
21379  across function calls, however this can cause unnecessary register pushing
21380  and popping
21381 \begin_inset LatexCommand \index{push/pop}
21382
21383 \end_inset
21384
21385  when calling small functions from larger functions.
21386  This option can be used to switch off the register saving convention for
21387  the function names specified.
21388  The compiler will not save registers when calling these functions, extra
21389  code need to be manually inserted at the entry and exit for these functions
21390  to save and restore the registers used by these functions, this can SUBSTANTIAL
21391 LY reduce code and improve run time performance of the generated code.
21392  In the future the compiler (with inter procedural analysis) may be able
21393  to determine the appropriate scheme to use for each function call.
21394  If -
21395 \begin_inset ERT
21396 status collapsed
21397
21398 \begin_layout Standard
21399
21400
21401 \backslash
21402 /
21403 \end_layout
21404
21405 \end_inset
21406
21407 -callee-saves command line option is used (see page 
21408 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21409
21410 \end_inset
21411
21412 ), the function names specified in #pragma\InsetSpace ~
21413 callee_saves
21414 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21415
21416 \end_inset
21417
21418  is appended to the list of functions specified in the command line.
21419 \end_layout
21420
21421 \begin_layout Itemize
21422
21423 \series bold
21424 exclude
21425 \series default
21426
21427 \begin_inset LatexCommand \index{\#pragma exclude}
21428
21429 \end_inset
21430
21431  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21432  of pairs of push/pop
21433 \begin_inset LatexCommand \index{push/pop}
21434
21435 \end_inset
21436
21437  instructions in 
21438 \emph on
21439 I
21440 \emph default
21441 nterrupt
21442 \begin_inset LatexCommand \index{interrupt}
21443
21444 \end_inset
21445
21446  
21447 \emph on
21448 S
21449 \emph default
21450 ervice 
21451 \emph on
21452 R
21453 \emph default
21454 outines.
21455  The directive should be placed immediately before the ISR function definition
21456  and it affects ALL ISR functions following it.
21457  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21458 exclude\InsetSpace ~
21459 none
21460 \begin_inset LatexCommand \index{\#pragma exclude}
21461
21462 \end_inset
21463
21464 .
21465  See also the related keyword _naked
21466 \begin_inset LatexCommand \index{\_naked}
21467
21468 \end_inset
21469
21470
21471 \begin_inset LatexCommand \index{\_\_naked}
21472
21473 \end_inset
21474
21475 .
21476 \end_layout
21477
21478 \begin_layout Itemize
21479
21480 \series bold
21481 less_pedantic
21482 \series default
21483
21484 \begin_inset LatexCommand \index{pedantic}
21485
21486 \end_inset
21487
21488
21489 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21490
21491 \end_inset
21492
21493  
21494 \begin_inset LatexCommand \label{ite:less_pedantic}
21495
21496 \end_inset
21497
21498 - the compiler will not warn you anymore for obvious mistakes, you're on
21499  your own now ;-( .
21500  See also the command line option -
21501 \begin_inset ERT
21502 status collapsed
21503
21504 \begin_layout Standard
21505
21506
21507 \backslash
21508 /
21509 \end_layout
21510
21511 \end_inset
21512
21513 -less-pedantic 
21514 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21515
21516 \end_inset
21517
21518 .
21519  
21520 \newline
21521 More specifically, the following warnings will be disabled: 
21522 \shape italic
21523 comparison is always [true/false] due to limited range of data type
21524 \shape default
21525  (94); 
21526 \shape italic
21527 overflow in implicit constant conversion
21528 \shape default
21529  (158); [the (in)famous] 
21530 \shape italic
21531 conditional flow changed by optimizer: so said EVELYN the modified DOG
21532 \shape default
21533  (110); 
21534 \shape italic
21535 function '[function name]' must return value
21536 \shape default
21537  (59).
21538  
21539 \newline
21540 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21541  level) are disabled, too, namely: 
21542 \shape italic
21543 constant value '[
21544 \begin_inset Note Note
21545 status collapsed
21546
21547 \begin_layout Standard
21548 dunno what comes here - this warning appears to be unused altogether
21549 \end_layout
21550
21551 \end_inset
21552
21553 ]', out of range
21554 \shape default
21555  (81); 
21556 \shape italic
21557 [left/right] shifting more than size of object changed to zero
21558 \shape default
21559  (116); 
21560 \shape italic
21561 unreachable code
21562 \shape default
21563  (126); 
21564 \shape italic
21565 integer overflow in expression
21566 \shape default
21567  (165); 
21568 \shape italic
21569 unmatched #pragma save and #pragma restore
21570 \shape default
21571  (170); 
21572 \shape italic
21573 comparison of 'signed char' with 'unsigned char' requires promotion to int
21574 \shape default
21575  (185); 
21576 \shape italic
21577 ISO C90 does not support flexible array members
21578 \shape default
21579  (187); 
21580 \shape italic
21581 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21582 nam
21583 e]':\InsetSpace ~
21584 [
21585 \begin_inset Note Note
21586 status collapsed
21587
21588 \begin_layout Standard
21589 appears to be always blank - what was supposed to be here?
21590 \end_layout
21591
21592 \end_inset
21593
21594 ]
21595 \shape default
21596  (114); 
21597 \shape italic
21598 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21599  complexity [number]
21600 \shape default
21601  (121).
21602 \end_layout
21603
21604 \begin_layout Itemize
21605
21606 \series bold
21607 disable_warning
21608 \series default
21609  <nnnn>
21610 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21611
21612 \end_inset
21613
21614  - the compiler will not warn you anymore about warning number <nnnn>.
21615 \end_layout
21616
21617 \begin_layout Itemize
21618
21619 \series bold
21620 nogcse
21621 \series default
21622
21623 \begin_inset LatexCommand \index{\#pragma nogcse}
21624
21625 \end_inset
21626
21627  - will stop global common subexpression elimination.
21628 \end_layout
21629
21630 \begin_layout Itemize
21631
21632 \series bold
21633 noinduction
21634 \series default
21635
21636 \begin_inset LatexCommand \index{\#pragma noinduction}
21637
21638 \end_inset
21639
21640  - will stop loop induction optimizations.
21641 \end_layout
21642
21643 \begin_layout Itemize
21644
21645 \series bold
21646 noinvariant
21647 \series default
21648
21649 \begin_inset LatexCommand \index{\#pragma noinvariant}
21650
21651 \end_inset
21652
21653  - will not do loop invariant optimizations.
21654  For more details see Loop Invariants in section
21655 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21656
21657 \end_inset
21658
21659 .
21660 \end_layout
21661
21662 \begin_layout Itemize
21663
21664 \series bold
21665 noiv
21666 \series default
21667
21668 \begin_inset LatexCommand \index{\#pragma noiv}
21669
21670 \end_inset
21671
21672  - Do not generate interrupt
21673 \begin_inset LatexCommand \index{interrupt}
21674
21675 \end_inset
21676
21677  vector table
21678 \begin_inset LatexCommand \index{interrupt vector table}
21679
21680 \end_inset
21681
21682  entries for all ISR functions defined after the pragma.
21683  This is useful in cases where the interrupt vector table must be defined
21684  manually, or when there is a secondary, manually defined interrupt vector
21685  table (e.g.
21686  for the autovector feature of the Cypress EZ-USB FX2).
21687  More elegantly this can be achieved by obmitting the optional interrupt
21688  number after the interrupt keyword, see section 
21689 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21690
21691 \end_inset
21692
21693 \InsetSpace ~
21694 about interrupts.
21695 \end_layout
21696
21697 \begin_layout Itemize
21698
21699 \series bold
21700 nojtbound
21701 \series default
21702
21703 \begin_inset LatexCommand \index{\#pragma nojtbound}
21704
21705 \end_inset
21706
21707  - will not generate code for boundary value checking, when switch statements
21708  are turned into jump-tables (dangerous).
21709  For more details see section 
21710 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21711
21712 \end_inset
21713
21714 .
21715 \end_layout
21716
21717 \begin_layout Itemize
21718
21719 \series bold
21720 noloopreverse
21721 \series default
21722
21723 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21724
21725 \end_inset
21726
21727  - Will not do loop reversal optimization
21728 \end_layout
21729
21730 \begin_layout Itemize
21731
21732 \series bold
21733 nooverlay
21734 \series default
21735
21736 \begin_inset LatexCommand \index{\#pragma nooverlay}
21737
21738 \end_inset
21739
21740  - the compiler will not overlay the parameters and local variables of a
21741  function.
21742 \end_layout
21743
21744 \begin_layout Itemize
21745
21746 \series bold
21747 stackauto
21748 \series default
21749
21750 \begin_inset LatexCommand \index{\#pragma stackauto}
21751
21752 \end_inset
21753
21754 - See option -
21755 \begin_inset ERT
21756 status collapsed
21757
21758 \begin_layout Standard
21759
21760
21761 \backslash
21762 /
21763 \end_layout
21764
21765 \end_inset
21766
21767 -stack-auto
21768 \begin_inset LatexCommand \index{-\/-stack-auto}
21769
21770 \end_inset
21771
21772  and section 
21773 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21774
21775 \end_inset
21776
21777  Parameters and Local Variables.
21778 \end_layout
21779
21780 \begin_layout Itemize
21781
21782 \series bold
21783 opt_code_speed
21784 \series default
21785  
21786 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21787
21788 \end_inset
21789
21790 - The compiler will optimize code generation towards fast code, possibly
21791  at the expense of code size.
21792  Currently this has little effect.
21793 \end_layout
21794
21795 \begin_layout Itemize
21796
21797 \series bold
21798 opt_code_size
21799 \series default
21800  
21801 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21802
21803 \end_inset
21804
21805 - The compiler will optimize code generation towards compact code, possibly
21806  at the expense of code speed.
21807  Currently this has little effect.
21808 \end_layout
21809
21810 \begin_layout Itemize
21811
21812 \series bold
21813 opt_code_balanced
21814 \series default
21815  
21816 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21817
21818 \end_inset
21819
21820 - The compiler will attempt to generate code that is both compact and fast,
21821  as long as meeting one goal is not a detriment to the other (this is the
21822  default).
21823  
21824 \end_layout
21825
21826 \begin_layout Itemize
21827
21828 \series bold
21829 std_sdcc89
21830 \series default
21831  
21832 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21833
21834 \end_inset
21835
21836 - Generally follow the C89 standard, but allow SDCC features that conflict
21837  with the standard (default).
21838 \end_layout
21839
21840 \begin_layout Itemize
21841
21842 \series bold
21843 std_c89
21844 \series default
21845  
21846 \begin_inset LatexCommand \index{\#pragma std\_c89}
21847
21848 \end_inset
21849
21850 - Follow the C89 standard and disable SDCC features that conflict with the
21851  standard.
21852 \end_layout
21853
21854 \begin_layout Itemize
21855
21856 \series bold
21857 std_sdcc99
21858 \series default
21859  
21860 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21861
21862 \end_inset
21863
21864 - Generally follow the C99 standard, but allow SDCC features that conflict
21865  with the standard (incomplete support).
21866 \end_layout
21867
21868 \begin_layout Itemize
21869
21870 \series bold
21871 std_c99
21872 \series default
21873  
21874 \begin_inset LatexCommand \index{\#pragma std\_c99}
21875
21876 \end_inset
21877
21878 - Follow the C99 standard and disable SDCC features that conflict with the
21879  standard (incomplete support).
21880 \end_layout
21881
21882 \begin_layout Itemize
21883
21884 \series bold
21885 codeseg
21886 \series default
21887  <name>
21888 \begin_inset LatexCommand \index{\#pragma codeseg}
21889
21890 \end_inset
21891
21892 - Use this name (max.
21893  8 characters) for the code segment.
21894  See option -
21895 \begin_inset ERT
21896 status collapsed
21897
21898 \begin_layout Standard
21899
21900
21901 \backslash
21902 /
21903 \end_layout
21904
21905 \end_inset
21906
21907 -codeseg.
21908 \end_layout
21909
21910 \begin_layout Itemize
21911
21912 \series bold
21913 constseg
21914 \series default
21915  <name>
21916 \begin_inset LatexCommand \index{\#pragma constseg}
21917
21918 \end_inset
21919
21920 - Use this name (max.
21921  8 characters) for the const segment.
21922  See option -
21923 \begin_inset ERT
21924 status collapsed
21925
21926 \begin_layout Standard
21927
21928
21929 \backslash
21930 /
21931 \end_layout
21932
21933 \end_inset
21934
21935 -constseg.
21936 \end_layout
21937
21938 \begin_layout Standard
21939 The preprocessor SDCPP
21940 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21941
21942 \end_inset
21943
21944  supports the following #pragma directives:
21945 \end_layout
21946
21947 \begin_layout Itemize
21948
21949 \series bold
21950 pedantic_parse_number
21951 \series default
21952
21953 \begin_inset LatexCommand \index{pedantic}
21954
21955 \end_inset
21956
21957
21958 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21959
21960 \end_inset
21961
21962  (+ | -) 
21963 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21964
21965 \end_inset
21966
21967 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21968  properly and the macro LO_B(3) gets expanded.
21969  Default is off.
21970  See also the -
21971 \begin_inset ERT
21972 status collapsed
21973
21974 \begin_layout Standard
21975
21976
21977 \backslash
21978 /
21979 \end_layout
21980
21981 \end_inset
21982
21983 -pedantic-parse-number command line option 
21984 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21985
21986 \end_inset
21987
21988 .
21989  
21990 \newline
21991 Below is an example on how to use this pragma.
21992
21993 \emph on
21994  Note: this functionality is not in conformance with standard!
21995 \end_layout
21996
21997 \begin_layout Verse
21998
21999 \family typewriter
22000 #pragma pedantic_parse_number +
22001 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22002
22003 \end_inset
22004
22005
22006 \newline
22007
22008 \newline
22009 #define LO_B(x) ((x) & 0xff)
22010 \newline
22011
22012 \newline
22013 unsigned char foo(void)
22014 \newline
22015 {
22016 \newline
22017 \InsetSpace ~
22018 \InsetSpace ~
22019 \InsetSpace ~
22020 unsigned char c=0xfe-LO_B(3)
22021 ;
22022 \newline
22023
22024 \newline
22025 \InsetSpace ~
22026 \InsetSpace ~
22027 \InsetSpace ~
22028 return c;
22029 \newline
22030 }
22031 \newline
22032
22033 \end_layout
22034
22035 \begin_layout Itemize
22036
22037 \series bold
22038 preproc_asm
22039 \series default
22040
22041 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22042
22043 \end_inset
22044
22045  (+ | -) - switch _asm _endasm block preprocessing on / off.
22046  Default is on.
22047  You use this prama to define multilines of assembly code.
22048  This will prevent the preprocessor from changing the formating required
22049  by assembly code.
22050  Below is an example on how to use this pragma.
22051 \end_layout
22052
22053 \begin_layout Verse
22054
22055 \family typewriter
22056 #pragma preproc_asm -
22057 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22058
22059 \end_inset
22060
22061
22062 \newline
22063 #define MYDELAY _asm
22064 \newline
22065 \InsetSpace ~
22066 \InsetSpace ~
22067 \InsetSpace ~
22068 nop ;my assembly comment...
22069 \newline
22070 \InsetSpace ~
22071 \InsetSpace ~
22072 \InsetSpace ~
22073 nop
22074 \newline
22075 \InsetSpace ~
22076 \InsetSpace ~
22077 \InsetSpace ~
22078 nop
22079 \newline
22080 _endasm
22081 \newline
22082 #pragma preproc_asm
22083  +
22084 \newline
22085
22086 \newline
22087 void foo (void) 
22088 \newline
22089
22090 \newline
22091 \InsetSpace ~
22092 \InsetSpace ~
22093 \InsetSpace ~
22094  ...
22095  
22096 \newline
22097 \InsetSpace ~
22098 \InsetSpace ~
22099 \InsetSpace ~
22100  MYDELAY;
22101 \newline
22102 \InsetSpace ~
22103 \InsetSpace ~
22104 \InsetSpace ~
22105  ...
22106  
22107 \newline
22108
22109 \newline
22110
22111 \end_layout
22112
22113 \begin_layout Itemize
22114
22115 \series bold
22116 sdcc_hash
22117 \series default
22118
22119 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22120
22121 \end_inset
22122
22123  (+ | -) - Allow "naked" hash in macro definition, for example:
22124 \newline
22125
22126 \family typewriter
22127 #define DIR_LO(x) #(x & 0xff)
22128 \family default
22129
22130 \newline
22131 Default is off.
22132  Below is an example on how to use this pragma.
22133 \end_layout
22134
22135 \begin_layout Verse
22136
22137 \family typewriter
22138 #pragma preproc_asm +
22139 \newline
22140 #pragma sdcc_hash +
22141 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22142
22143 \end_inset
22144
22145
22146 \newline
22147
22148 \newline
22149 #define ROMCALL(x) 
22150 \backslash
22151
22152 \newline
22153 \InsetSpace ~
22154 \InsetSpace ~
22155 \InsetSpace ~
22156 mov R6_B3, #(x & 0xff) 
22157 \backslash
22158
22159 \newline
22160 \InsetSpace ~
22161 \InsetSpace ~
22162 \InsetSpace ~
22163 mov R7_B3, #((x >> 8) & 0xff) 
22164 \backslash
22165
22166 \newline
22167 \InsetSpace ~
22168 \InsetSpace ~
22169 \InsetSpace ~
22170 lcall __romcall
22171 \newline
22172
22173 \newline
22174 ...
22175 \newline
22176 _asm
22177 \newline
22178 ROMCALL(72)
22179 \newline
22180 _endasm;
22181 \newline
22182 ...
22183 \newline
22184
22185 \end_layout
22186
22187 \begin_layout Standard
22188 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22189 ons which might cause the compiler to generate extra stack and/or data space
22190  to store compiler generated temporary variables.
22191  This usually happens in large functions.
22192  Pragma directives should be used as shown in the following example, they
22193  are used to control options and optimizations for a given function.
22194  
22195 \end_layout
22196
22197 \begin_layout Verse
22198
22199 \family typewriter
22200 #pragma save
22201 \begin_inset LatexCommand \index{\#pragma save}
22202
22203 \end_inset
22204
22205  \InsetSpace ~
22206 \InsetSpace ~
22207 \InsetSpace ~
22208 \InsetSpace ~
22209 \InsetSpace ~
22210 \InsetSpace ~
22211 \InsetSpace ~
22212 /* save the current settings */ 
22213 \newline
22214 #pragma nogcse
22215 \begin_inset LatexCommand \index{\#pragma nogcse}
22216
22217 \end_inset
22218
22219  \InsetSpace ~
22220 \InsetSpace ~
22221 \InsetSpace ~
22222 \InsetSpace ~
22223 \InsetSpace ~
22224 /* turnoff global subexpression elimination */ 
22225 \newline
22226 #pragma noinduction
22227 \begin_inset LatexCommand \index{\#pragma noinduction}
22228
22229 \end_inset
22230
22231  /* turn off induction optimizations */ 
22232 \newline
22233 int foo () 
22234 \newline
22235
22236 \newline
22237 \InsetSpace ~
22238  \InsetSpace ~
22239  ...
22240  
22241 \newline
22242 \InsetSpace ~
22243  \InsetSpace ~
22244  /* large code */ 
22245 \newline
22246 \InsetSpace ~
22247  \InsetSpace ~
22248  ...
22249  
22250 \newline
22251
22252 \newline
22253 #pragma restore
22254 \begin_inset LatexCommand \index{\#pragma restore}
22255
22256 \end_inset
22257
22258  /* turn the optimizations back on */
22259 \end_layout
22260
22261 \begin_layout Standard
22262 The compiler will generate a warning message when extra space is allocated.
22263  It is strongly recommended that the save and restore pragmas be used when
22264  changing options for a function.
22265 \newline
22266
22267 \newline
22268
22269 \newline
22270
22271 \end_layout
22272
22273 \begin_layout Section
22274 Defines Created by the Compiler
22275 \end_layout
22276
22277 \begin_layout Standard
22278 The compiler creates the following #defines
22279 \begin_inset LatexCommand \index{\#defines}
22280
22281 \end_inset
22282
22283
22284 \begin_inset LatexCommand \index{Defines created by the compiler}
22285
22286 \end_inset
22287
22288 :
22289 \newline
22290
22291 \end_layout
22292
22293 \begin_layout Standard
22294 \begin_inset Tabular
22295 <lyxtabular version="3" rows="11" columns="2">
22296 <features>
22297 <column alignment="left" valignment="top" leftline="true" width="3in">
22298 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22299 <row topline="true" bottomline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 \begin_inset Text
22302
22303 \begin_layout Standard
22304
22305 \series bold
22306 #define
22307 \end_layout
22308
22309 \end_inset
22310 </cell>
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22312 \begin_inset Text
22313
22314 \begin_layout Standard
22315
22316 \series bold
22317 Description
22318 \end_layout
22319
22320 \end_inset
22321 </cell>
22322 </row>
22323 <row topline="true">
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22325 \begin_inset Text
22326
22327 \begin_layout Standard
22328 SDCC
22329 \begin_inset LatexCommand \index{SDCC}
22330
22331 \end_inset
22332
22333  
22334 \end_layout
22335
22336 \end_inset
22337 </cell>
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22339 \begin_inset Text
22340
22341 \begin_layout Standard
22342 Always defined.
22343  Since version 2.5.6 the version number as an int (ex.
22344  256)
22345 \end_layout
22346
22347 \end_inset
22348 </cell>
22349 </row>
22350 <row topline="true">
22351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22352 \begin_inset Text
22353
22354 \begin_layout Standard
22355 SDCC_mcs51
22356 \begin_inset LatexCommand \index{SDCC\_mcs51}
22357
22358 \end_inset
22359
22360  or SDCC_ds390
22361 \begin_inset LatexCommand \index{SDCC\_ds390}
22362
22363 \end_inset
22364
22365  or SDCC_z80
22366 \begin_inset LatexCommand \index{SDCC\_z80}
22367
22368 \end_inset
22369
22370 , etc.
22371 \end_layout
22372
22373 \end_inset
22374 </cell>
22375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22376 \begin_inset Text
22377
22378 \begin_layout Standard
22379 depending on the model used (e.g.: -mds390)
22380 \end_layout
22381
22382 \end_inset
22383 </cell>
22384 </row>
22385 <row topline="true">
22386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22387 \begin_inset Text
22388
22389 \begin_layout Standard
22390 __mcs51
22391 \begin_inset LatexCommand \index{\_\_mcs51}
22392
22393 \end_inset
22394
22395 , __ds390
22396 \begin_inset LatexCommand \index{\_\_ds390}
22397
22398 \end_inset
22399
22400 , __hc08
22401 \begin_inset LatexCommand \index{\_\_hc08}
22402
22403 \end_inset
22404
22405 , __z80
22406 \begin_inset LatexCommand \index{\_\_z80}
22407
22408 \end_inset
22409
22410 , etc
22411 \end_layout
22412
22413 \end_inset
22414 </cell>
22415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22416 \begin_inset Text
22417
22418 \begin_layout Standard
22419 depending on the model used (e.g.
22420  -mz80)
22421 \end_layout
22422
22423 \end_inset
22424 </cell>
22425 </row>
22426 <row topline="true">
22427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22428 \begin_inset Text
22429
22430 \begin_layout Standard
22431 SDCC_STACK_AUTO
22432 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22433
22434 \end_inset
22435
22436
22437 \end_layout
22438
22439 \end_inset
22440 </cell>
22441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22442 \begin_inset Text
22443
22444 \begin_layout Standard
22445 when 
22446 \emph on
22447 -
22448 \begin_inset ERT
22449 status collapsed
22450
22451 \begin_layout Standard
22452
22453
22454 \backslash
22455 /
22456 \end_layout
22457
22458 \end_inset
22459
22460 -stack-auto
22461 \emph default
22462  option is used
22463 \end_layout
22464
22465 \end_inset
22466 </cell>
22467 </row>
22468 <row topline="true">
22469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22470 \begin_inset Text
22471
22472 \begin_layout Standard
22473 SDCC_MODEL_SMALL
22474 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22475
22476 \end_inset
22477
22478
22479 \end_layout
22480
22481 \end_inset
22482 </cell>
22483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22484 \begin_inset Text
22485
22486 \begin_layout Standard
22487 when 
22488 \emph on
22489 -
22490 \begin_inset ERT
22491 status collapsed
22492
22493 \begin_layout Standard
22494
22495
22496 \backslash
22497 /
22498 \end_layout
22499
22500 \end_inset
22501
22502 -model-small
22503 \emph default
22504  is used
22505 \end_layout
22506
22507 \end_inset
22508 </cell>
22509 </row>
22510 <row topline="true">
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22512 \begin_inset Text
22513
22514 \begin_layout Standard
22515 SDCC_MODEL_MEDIUM
22516 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22517
22518 \end_inset
22519
22520
22521 \end_layout
22522
22523 \end_inset
22524 </cell>
22525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22526 \begin_inset Text
22527
22528 \begin_layout Standard
22529 when 
22530 \emph on
22531 -
22532 \begin_inset ERT
22533 status collapsed
22534
22535 \begin_layout Standard
22536
22537
22538 \backslash
22539 /
22540 \end_layout
22541
22542 \end_inset
22543
22544 -model-medium
22545 \emph default
22546  is used
22547 \end_layout
22548
22549 \end_inset
22550 </cell>
22551 </row>
22552 <row topline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22554 \begin_inset Text
22555
22556 \begin_layout Standard
22557 SDCC_MODEL_LARGE
22558 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22559
22560 \end_inset
22561
22562
22563 \end_layout
22564
22565 \end_inset
22566 </cell>
22567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22568 \begin_inset Text
22569
22570 \begin_layout Standard
22571 when 
22572 \emph on
22573 -
22574 \begin_inset ERT
22575 status collapsed
22576
22577 \begin_layout Standard
22578
22579
22580 \backslash
22581 /
22582 \end_layout
22583
22584 \end_inset
22585
22586 -model-large
22587 \emph default
22588  is used
22589 \end_layout
22590
22591 \end_inset
22592 </cell>
22593 </row>
22594 <row topline="true">
22595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22596 \begin_inset Text
22597
22598 \begin_layout Standard
22599 SDCC_USE_XSTACK
22600 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22601
22602 \end_inset
22603
22604
22605 \end_layout
22606
22607 \end_inset
22608 </cell>
22609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22610 \begin_inset Text
22611
22612 \begin_layout Standard
22613 when 
22614 \emph on
22615 -
22616 \begin_inset ERT
22617 status collapsed
22618
22619 \begin_layout Standard
22620
22621
22622 \backslash
22623 /
22624 \end_layout
22625
22626 \end_inset
22627
22628 -xstack
22629 \emph default
22630  option is used
22631 \end_layout
22632
22633 \end_inset
22634 </cell>
22635 </row>
22636 <row topline="true">
22637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22638 \begin_inset Text
22639
22640 \begin_layout Standard
22641 SDCC_STACK_TENBIT
22642 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22643
22644 \end_inset
22645
22646  
22647 \end_layout
22648
22649 \end_inset
22650 </cell>
22651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22652 \begin_inset Text
22653
22654 \begin_layout Standard
22655 when 
22656 \emph on
22657 -mds390
22658 \emph default
22659  is used
22660 \end_layout
22661
22662 \end_inset
22663 </cell>
22664 </row>
22665 <row topline="true" bottomline="true">
22666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22667 \begin_inset Text
22668
22669 \begin_layout Standard
22670 SDCC_MODEL_FLAT24
22671 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22672
22673 \end_inset
22674
22675
22676 \end_layout
22677
22678 \end_inset
22679 </cell>
22680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22681 \begin_inset Text
22682
22683 \begin_layout Standard
22684 when 
22685 \emph on
22686 -mds390
22687 \emph default
22688  is used
22689 \end_layout
22690
22691 \end_inset
22692 </cell>
22693 </row>
22694 </lyxtabular>
22695
22696 \end_inset
22697
22698
22699 \end_layout
22700
22701 \begin_layout Chapter
22702 Notes on supported Processors
22703 \end_layout
22704
22705 \begin_layout Section
22706 MCS51 variants
22707 \begin_inset LatexCommand \label{sub:MCS51-variants}
22708
22709 \end_inset
22710
22711
22712 \begin_inset LatexCommand \index{MCS51 variants}
22713
22714 \end_inset
22715
22716
22717 \end_layout
22718
22719 \begin_layout Standard
22720 MCS51 processors are available from many vendors and come in many different
22721  flavours.
22722  While they might differ considerably in respect to Special Function Registers
22723  the core MCS51 is usually not modified or is kept compatible.
22724  
22725 \end_layout
22726
22727 \begin_layout Subsection
22728 pdata access by SFR 
22729 \end_layout
22730
22731 \begin_layout Standard
22732 With the upcome of devices with internal xdata and flash memory devices
22733  using port P2
22734 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22735
22736 \end_inset
22737
22738  as dedicated I/O port is becoming more popular.
22739  Switching the high byte for pdata
22740 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22741
22742 \end_inset
22743
22744  access which was formerly done by port P2 is then achieved by a Special
22745  Function Register
22746 \begin_inset LatexCommand \index{sfr}
22747
22748 \end_inset
22749
22750 .
22751  In well-established MCS51 tradition the address of this 
22752 \emph on
22753 sfr
22754 \emph default
22755  is where the chip designers decided to put it.
22756  Needless to say that they didn't agree on a common name either.
22757  So that the startup code can correctly initialize xdata variables, you
22758  should define an sfr with the name _XPAGE
22759 \family typewriter
22760
22761 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22762
22763 \end_inset
22764
22765
22766 \family default
22767  at the appropriate location if the default, port P2, is not used for this.
22768  Some examples are:
22769 \end_layout
22770
22771 \begin_layout Verse
22772
22773 \family typewriter
22774 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22775  MPAGE */
22776 \end_layout
22777
22778 \begin_layout Verse
22779
22780 \family typewriter
22781 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22782  a.k.a.
22783  MPAGE */
22784 \end_layout
22785
22786 \begin_layout Verse
22787
22788 \family typewriter
22789 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22790  XPAGE */
22791 \end_layout
22792
22793 \begin_layout Verse
22794
22795 \family typewriter
22796 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22797  EMI0CN */
22798 \end_layout
22799
22800 \begin_layout Verse
22801
22802 \family typewriter
22803 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22804  EMI0CN */
22805 \end_layout
22806
22807 \begin_layout Standard
22808 For more exotic implementations further customizations may be needed.
22809  See section 
22810 \begin_inset LatexCommand \ref{sub:Startup-Code}
22811
22812 \end_inset
22813
22814  for other possibilities.
22815 \end_layout
22816
22817 \begin_layout Subsection
22818 Other Features available by SFR
22819 \end_layout
22820
22821 \begin_layout Standard
22822 Some MCS51 variants offer features like Double DPTR
22823 \begin_inset LatexCommand \index{DPTR}
22824
22825 \end_inset
22826
22827 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22828  These are currently not used for the MCS51 port.
22829  If you absolutely need them you can fall back to inline assembly or submit
22830  a patch to SDCC.
22831 \begin_inset VSpace bigskip
22832 \end_inset
22833
22834
22835 \end_layout
22836
22837 \begin_layout Section
22838 DS400 port
22839 \end_layout
22840
22841 \begin_layout Standard
22842 The DS80C400
22843 \begin_inset LatexCommand \index{DS80C400}
22844
22845 \end_inset
22846
22847
22848 \begin_inset LatexCommand \index{DS400}
22849
22850 \end_inset
22851
22852  microcontroller has a rich set of peripherals.
22853  In its built-in ROM library it includes functions to access some of the
22854  features, among them is a TCP stack with IP4 and IP6 support.
22855  Library headers (currently in beta status) and other files are provided
22856  at 
22857 \size footnotesize
22858
22859 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22860
22861 \end_inset
22862
22863 .
22864  
22865 \begin_inset VSpace bigskip
22866 \end_inset
22867
22868
22869 \end_layout
22870
22871 \begin_layout Section
22872 The Z80 and gbz80 port
22873 \end_layout
22874
22875 \begin_layout Standard
22876 SDCC can target both the Zilog Z80
22877 \begin_inset LatexCommand \index{Z80}
22878
22879 \end_inset
22880
22881  and the Nintendo Gameboy's Z80-like gbz80
22882 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22883
22884 \end_inset
22885
22886 .
22887  The Z80 port is passed through the same 
22888 \emph on
22889 regressions tests
22890 \begin_inset LatexCommand \index{Regression test}
22891
22892 \end_inset
22893
22894
22895 \emph default
22896  (see section 
22897 \begin_inset LatexCommand \ref{sec:Quality-control}
22898
22899 \end_inset
22900
22901 ) as the MCS51 and DS390 ports, so floating point support, support for long
22902  variables and bitfield support is fine.
22903  See mailing lists and forums about interrupt routines.
22904 \end_layout
22905
22906 \begin_layout Standard
22907 As always, the code is the authoritative reference - see z80/ralloc.c and
22908  z80/gen.c.
22909  The stack
22910 \begin_inset LatexCommand \index{Z80!stack}
22911
22912 \end_inset
22913
22914  frame is similar to that generated by the IAR Z80 compiler.
22915  IX is used as the base pointer, HL and IY are used as a temporary registers,
22916  and BC and DE are available for holding variables.
22917  Return values
22918 \begin_inset LatexCommand \index{Z80!return value}
22919
22920 \end_inset
22921
22922  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22923  bytes).
22924  The gbz80 port use the same set of registers for the return values, but
22925  in a different order of significance: E (one byte), DE (two bytes), or
22926  HLDE (four bytes).
22927 \begin_inset VSpace bigskip
22928 \end_inset
22929
22930
22931 \end_layout
22932
22933 \begin_layout Section
22934 The HC08 port
22935 \end_layout
22936
22937 \begin_layout Standard
22938 The port to the Freescale/Motorola HC08
22939 \begin_inset LatexCommand \index{HC08}
22940
22941 \end_inset
22942
22943  family has been added in October 2003, and is still undergoing some basic
22944  development.
22945  The code generator is complete, but the register allocation is still quite
22946  unoptimized.
22947  Some of the SDCC's standard C library functions have embedded non-HC08
22948  inline assembly and so are not yet usable.
22949 \end_layout
22950
22951 \begin_layout Standard
22952 The HC08 port passes the regression test suite (see section 
22953 \begin_inset LatexCommand \ref{sec:Quality-control}
22954
22955 \end_inset
22956
22957 ).
22958 \begin_inset VSpace bigskip
22959 \end_inset
22960
22961
22962 \newpage
22963
22964 \end_layout
22965
22966 \begin_layout Section
22967 The PIC14
22968 \begin_inset LatexCommand \index{PIC14}
22969
22970 \end_inset
22971
22972  port
22973 \end_layout
22974
22975 \begin_layout Standard
22976 The PIC14 port adds support for Microchip
22977 \begin_inset LatexCommand \index{Microchip}
22978
22979 \end_inset
22980
22981
22982 \begin_inset Formula $^{\text{TM}}$
22983 \end_inset
22984
22985  PIC
22986 \begin_inset LatexCommand \index{PIC14}
22987
22988 \end_inset
22989
22990
22991 \begin_inset Formula $^{\text{TM}}$
22992 \end_inset
22993
22994  MCUs with 14 bit wide instructions.
22995  This port is not yet mature and still lacks many features.
22996  However, it can work for simple code.
22997 \end_layout
22998
22999 \begin_layout Standard
23000 Currently supported devices include:
23001 \end_layout
23002
23003 \begin_layout Standard
23004 12F: 629, 635, 675, 683
23005 \end_layout
23006
23007 \begin_layout Standard
23008 16C: 432, 433
23009 \end_layout
23010
23011 \begin_layout Standard
23012 16C: 554, 557, 558
23013 \end_layout
23014
23015 \begin_layout Standard
23016 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23017 \end_layout
23018
23019 \begin_layout Standard
23020 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23021  781, 782
23022 \end_layout
23023
23024 \begin_layout Standard
23025 16C: 925, 926
23026 \end_layout
23027
23028 \begin_layout Standard
23029 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23030  689, 690
23031 \end_layout
23032
23033 \begin_layout Standard
23034 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23035 \end_layout
23036
23037 \begin_layout Standard
23038 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23039  877, 877a, 88
23040 \end_layout
23041
23042 \begin_layout Standard
23043 16F: 913, 914, 916, 917
23044 \end_layout
23045
23046 \begin_layout Standard
23047 An up-to-date list of currently supported devices can be obtained via 
23048 \family typewriter
23049 sdcc -mpic14 -phelp foo.c
23050 \family default
23051  (foo.c must exist...).
23052 \end_layout
23053
23054 \begin_layout Subsection
23055 PIC Code Pages
23056 \begin_inset LatexCommand \index{code page (pic14)}
23057
23058 \end_inset
23059
23060  and Memory Banks
23061 \begin_inset LatexCommand \index{Memory bank (pic14)}
23062
23063 \end_inset
23064
23065
23066 \end_layout
23067
23068 \begin_layout Standard
23069 The linker organizes allocation for the code page and RAM banks.
23070  It does not have intimate knowledge of the code flow.
23071  It will put all the code section of a single .asm file into a single code
23072  page.
23073  In order to make use of multiple code pages, separate asm files must be
23074  used.
23075  The compiler assigns all 
23076 \emph on
23077 static
23078 \emph default
23079  functions of a single .c file into the same code page.
23080 \newline
23081
23082 \newline
23083 To get the best results,
23084  follow these guidelines:
23085 \end_layout
23086
23087 \begin_layout Enumerate
23088 Make local functions static, as non static functions require code page selection
23089  overhead.
23090 \newline
23091 Due to the way sdcc handles functions, place called functions prior
23092  to calling functions in the file wherever possible: Otherwise sdcc will
23093  insert unneccessary pagesel directives around the call, believing that
23094  the called function is externally defined.
23095 \end_layout
23096
23097 \begin_layout Enumerate
23098 For devices that have multiple code pages it is more efficient to use the
23099  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23100  but only 2 files for the 16F874.
23101  This way the linker can put the code for each file into different code
23102  pages and there will be less page selection overhead.
23103 \end_layout
23104
23105 \begin_layout Enumerate
23106 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23107  instruction set), use `unsigned char' wherever possible instead of `int'.
23108 \end_layout
23109
23110 \begin_layout Subsection
23111 Adding New Devices to the Port 
23112 \end_layout
23113
23114 \begin_layout Standard
23115 Adding support for a new 14
23116 \begin_inset ERT
23117 status open
23118
23119 \begin_layout Standard
23120
23121
23122 \backslash
23123 ,
23124 \end_layout
23125
23126 \end_inset
23127
23128 bit PIC MCU requires the following steps:
23129 \end_layout
23130
23131 \begin_layout Enumerate
23132 Create a new device description.
23133 \newline
23134 Each device is described in two files: pic16f*.h
23135  and pic16f*.c.
23136  These files primarily define SFRs, structs to access their bits, and symbolic
23137  configuration options.
23138  Both files can be generated from gputils' .inc files using the perl script
23139  
23140 \family typewriter
23141 support/scripts/inc2h.pl
23142 \family default
23143 .
23144  This file also contains further instructions on how to proceed.
23145 \end_layout
23146
23147 \begin_layout Enumerate
23148 Copy the .h file into SDCC's include path and either add the .c file to your
23149  project or copy it to 
23150 \family typewriter
23151 device/lib/pic/libdev
23152 \family default
23153 .
23154  Afterwards, rebuild and install the libraries.
23155 \end_layout
23156
23157 \begin_layout Enumerate
23158 Edit pic14devices.txt in SDCC's include path (
23159 \family typewriter
23160 device/include/pic/
23161 \family default
23162  in the source tree or 
23163 \family typewriter
23164 /usr/local/share/sdcc/include/pic
23165 \family default
23166  after installation).
23167 \newline
23168 You need to add a device specification here to make
23169  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23170  the compiler.
23171  Probably you can copy and modify an existing entry.
23172  The file format is documented at the top of the file.
23173 \end_layout
23174
23175 \begin_layout Subsection
23176 Interrupt Code
23177 \end_layout
23178
23179 \begin_layout Standard
23180 For the interrupt function, use the keyword `__interrupt'
23181 \begin_inset LatexCommand \index{PIC14!interrupt}
23182
23183 \end_inset
23184
23185  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23186  there to avoid a syntax error - it ought to be fixed).
23187  E.g.:
23188 \end_layout
23189
23190 \begin_layout Verse
23191
23192 \family typewriter
23193 void Intr(void) __interrupt 0
23194 \newline
23195 {
23196 \newline
23197 \InsetSpace ~
23198 \InsetSpace ~
23199 T0IF = 0; /* Clear timer interrupt */
23200 \newline
23201 }
23202 \end_layout
23203
23204 \begin_layout Subsection
23205 Linking and Assembling
23206 \end_layout
23207
23208 \begin_layout Standard
23209 For assembling you can use either GPUTILS'
23210 \begin_inset LatexCommand \index{gputils (pic tools)}
23211
23212 \end_inset
23213
23214  gpasm.exe or MPLAB's mpasmwin.exe.
23215  GPUTILS are available from 
23216 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23217
23218 \end_inset
23219
23220 .
23221  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23222  If you use MPLAB and an interrupt function then the linker script file
23223  vectors section will need to be enlarged to link with mplink.
23224 \newline
23225
23226 \newline
23227 Here is a 
23228 \family typewriter
23229 Makefile
23230 \family default
23231  using GPUTILS:
23232 \end_layout
23233
23234 \begin_layout Verse
23235
23236 \family typewriter
23237 .c.o:
23238 \newline
23239 \InsetSpace ~
23240 \InsetSpace ~
23241 \InsetSpace ~
23242 \InsetSpace ~
23243 \InsetSpace ~
23244 \InsetSpace ~
23245 \InsetSpace ~
23246 \InsetSpace ~
23247 sdcc -V -mpic14 -p16f877 -c $< 
23248 \newline
23249
23250 \newline
23251 $(PRJ).hex: $(OBJS) 
23252 \newline
23253 \InsetSpace ~
23254 \InsetSpace ~
23255 \InsetSpace ~
23256 \InsetSpace ~
23257 \InsetSpace ~
23258 \InsetSpace ~
23259 \InsetSpace ~
23260 \InsetSpace ~
23261 gplink -m -s $(PRJ).lkr
23262  -o $(PRJ).hex $(OBJS) libsdcc.lib
23263 \end_layout
23264
23265 \begin_layout Standard
23266 Here is a 
23267 \family typewriter
23268 Makefile
23269 \family default
23270  using MPLAB:
23271 \end_layout
23272
23273 \begin_layout Verse
23274
23275 \family typewriter
23276 .c.o: 
23277 \newline
23278 \InsetSpace ~
23279 \InsetSpace ~
23280 \InsetSpace ~
23281 \InsetSpace ~
23282 \InsetSpace ~
23283 \InsetSpace ~
23284 \InsetSpace ~
23285 \InsetSpace ~
23286 sdcc -S -V -mpic14 -p16f877 $< 
23287 \newline
23288 \InsetSpace ~
23289 \InsetSpace ~
23290 \InsetSpace ~
23291 \InsetSpace ~
23292 \InsetSpace ~
23293 \InsetSpace ~
23294 \InsetSpace ~
23295 \InsetSpace ~
23296 mpasmwin /q /o $*.asm
23297 \newline
23298
23299 \newline
23300 $(PRJ).hex: $(OBJS)
23301  
23302 \newline
23303 \InsetSpace ~
23304 \InsetSpace ~
23305 \InsetSpace ~
23306 \InsetSpace ~
23307 \InsetSpace ~
23308 \InsetSpace ~
23309 \InsetSpace ~
23310 \InsetSpace ~
23311 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23312 \end_layout
23313
23314 \begin_layout Standard
23315 Please note that indentations within a
23316 \family typewriter
23317  Makefile
23318 \family default
23319  have to be done with a tabulator character.
23320 \end_layout
23321
23322 \begin_layout Subsection
23323 Command-Line Options
23324 \end_layout
23325
23326 \begin_layout Standard
23327 Besides the switches common to all SDCC backends, the PIC14 port accepts
23328  the following options (for an updated list see sdcc -
23329 \begin_inset ERT
23330 status collapsed
23331
23332 \begin_layout Standard
23333
23334
23335 \backslash
23336 /
23337 \end_layout
23338
23339 \end_inset
23340
23341 -help):
23342 \end_layout
23343
23344 \begin_layout Description
23345 -
23346 \begin_inset ERT
23347 status collapsed
23348
23349 \begin_layout Standard
23350
23351
23352 \backslash
23353 /
23354 \end_layout
23355
23356 \end_inset
23357
23358 -debug-xtra
23359 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23360
23361 \end_inset
23362
23363  emit debug info in assembly output
23364 \end_layout
23365
23366 \begin_layout Description
23367 -
23368 \begin_inset ERT
23369 status collapsed
23370
23371 \begin_layout Standard
23372
23373
23374 \backslash
23375 /
23376 \end_layout
23377
23378 \end_inset
23379
23380 -no-pcode-opt
23381 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23382
23383 \end_inset
23384
23385  disable (slightly faulty) optimization on pCode
23386 \end_layout
23387
23388 \begin_layout Description
23389 -
23390 \begin_inset ERT
23391 status collapsed
23392
23393 \begin_layout Standard
23394
23395
23396 \backslash
23397 /
23398 \end_layout
23399
23400 \end_inset
23401
23402 -stack-loc
23403 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23404
23405 \end_inset
23406
23407  sets the lowest address of the argument passing stack (defaults to a suitably
23408  large shared databank to reduce BANKSEL overhead)
23409 \end_layout
23410
23411 \begin_layout Description
23412 -
23413 \begin_inset ERT
23414 status collapsed
23415
23416 \begin_layout Standard
23417
23418
23419 \backslash
23420 /
23421 \end_layout
23422
23423 \end_inset
23424
23425 -stack-size
23426 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23427
23428 \end_inset
23429
23430  sets the size if the argument passing stack (default: 16, minimum: 4)
23431 \end_layout
23432
23433 \begin_layout Subsection
23434 Environment Variables
23435 \end_layout
23436
23437 \begin_layout Standard
23438 The PIC14 port recognizes the following environment variables:
23439 \end_layout
23440
23441 \begin_layout Description
23442 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23443  register (the ones called r0xNNNN) in a section of its own.
23444  By default (if this variable is unset), sdcc tries to cluster registers
23445  in sections in order to reduce the BANKSEL overhead when accessing them.
23446 \end_layout
23447
23448 \begin_layout Subsection
23449 The Library
23450 \end_layout
23451
23452 \begin_layout Standard
23453 The PIC14 library currently only contains support routines required by the
23454  compiler to implement multiplication, division, and floating point support.
23455  No libc-like replacement is available at the moment, though many of the
23456  common sdcc library sources (in 
23457 \family typewriter
23458 device/lib
23459 \family default
23460 ) should also compile with the PIC14 port.
23461 \end_layout
23462
23463 \begin_layout Subsubsection
23464 error: missing definition for symbol ``__gptrget1''
23465 \end_layout
23466
23467 \begin_layout Standard
23468 The PIC14 port uses library routines to provide more complex operations
23469  like multiplication, division/modulus and (generic) pointer dereferencing.
23470  In order to add these routines to your project, you must link with PIC14's
23471  
23472 \family typewriter
23473 libsdcc.lib
23474 \family default
23475 .
23476  For single source file projects this is done automatically, more complex
23477  projects must add 
23478 \family typewriter
23479 libsdcc.lib
23480 \family default
23481  to the linker's arguments.
23482  Make sure you also add an include path for the library (using the -I switch
23483  to the linker)!
23484 \end_layout
23485
23486 \begin_layout Subsubsection
23487 Processor mismatch in file ``XXX''.
23488 \end_layout
23489
23490 \begin_layout Standard
23491 This warning can usually be ignored due to the very good compatibility amongst
23492  14
23493 \begin_inset ERT
23494 status open
23495
23496 \begin_layout Standard
23497
23498
23499 \backslash
23500 ,
23501 \end_layout
23502
23503 \end_inset
23504
23505 bit PIC
23506 \begin_inset LatexCommand \index{PIC14}
23507
23508 \end_inset
23509
23510  devices.
23511 \end_layout
23512
23513 \begin_layout Standard
23514 You might also consider recompiling the library for your specific device
23515  by changing the ARCH=p16f877 (default target) entry in 
23516 \family typewriter
23517 device/lib/pic/Makefile.in
23518 \family default
23519  and 
23520 \family typewriter
23521 device/lib/pic/Makefile
23522 \family default
23523  to reflect your device.
23524  This might even improve performance for smaller devices as unneccesary
23525  BANKSELs might be removed.
23526 \end_layout
23527
23528 \begin_layout Subsection
23529 Known Bugs
23530 \end_layout
23531
23532 \begin_layout Subsubsection
23533 Function arguments
23534 \end_layout
23535
23536 \begin_layout Standard
23537 Functions with variable argument lists (like printf) are not yet supported.
23538  Similarly, taking the argument of the first argument passed into a function
23539  does not work: It is currently passed in WREG and has no address...
23540 \end_layout
23541
23542 \begin_layout Subsubsection
23543 Regression tests fail
23544 \end_layout
23545
23546 \begin_layout Standard
23547 Though the small subset of regression tests in src/regression passes, SDCC
23548  regression test suite does not, indicating that there are still major bugs
23549  in the port.
23550  However, many smaller projects have successfully used SDCC in the past...
23551 \end_layout
23552
23553 \begin_layout Standard
23554
23555 \size footnotesize
23556
23557 \newpage
23558
23559 \end_layout
23560
23561 \begin_layout Section
23562 The PIC16
23563 \begin_inset LatexCommand \index{PIC16}
23564
23565 \end_inset
23566
23567  port
23568 \end_layout
23569
23570 \begin_layout Standard
23571 The PIC16 port adds support for Microchip
23572 \begin_inset LatexCommand \index{Microchip}
23573
23574 \end_inset
23575
23576
23577 \begin_inset Formula $^{\text{TM}}$
23578 \end_inset
23579
23580  PIC
23581 \begin_inset LatexCommand \index{PIC}
23582
23583 \end_inset
23584
23585
23586 \begin_inset Formula $^{\text{TM}}$
23587 \end_inset
23588
23589  MCUs with 16 bit wide instructions.
23590  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23591 ; devices supported by the port include:
23592 \end_layout
23593
23594 \begin_layout Standard
23595 18F: 242, 248, 252, 258, 442, 448, 452, 458
23596 \end_layout
23597
23598 \begin_layout Standard
23599 18F: 1220, 1320
23600 \end_layout
23601
23602 \begin_layout Standard
23603 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23604  2620
23605 \end_layout
23606
23607 \begin_layout Standard
23608 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23609  45j10, 4620
23610 \end_layout
23611
23612 \begin_layout Standard
23613 18F: 6520, 6620, 6680, 6720
23614 \end_layout
23615
23616 \begin_layout Standard
23617 18F: 8520, 8620, 8680, 8720
23618 \end_layout
23619
23620 \begin_layout Subsection
23621 Global Options
23622 \end_layout
23623
23624 \begin_layout Standard
23625 PIC16 port supports the standard command line arguments as supposed, with
23626  the exception of certain cases that will be mentioned in the following
23627  list:
23628 \end_layout
23629
23630 \begin_layout Description
23631 -
23632 \begin_inset ERT
23633 status collapsed
23634
23635 \begin_layout Standard
23636
23637
23638 \backslash
23639 /
23640 \end_layout
23641
23642 \end_inset
23643
23644 -callee-saves
23645 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23646
23647 \end_inset
23648
23649  See -
23650 \begin_inset ERT
23651 status collapsed
23652
23653 \begin_layout Standard
23654
23655
23656 \backslash
23657 /
23658 \end_layout
23659
23660 \end_inset
23661
23662 -all-callee-saves
23663 \end_layout
23664
23665 \begin_layout Description
23666 -
23667 \begin_inset ERT
23668 status collapsed
23669
23670 \begin_layout Standard
23671
23672
23673 \backslash
23674 /
23675 \end_layout
23676
23677 \end_inset
23678
23679 -fommit-frame-pointer
23680 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23681
23682 \end_inset
23683
23684  Frame pointer will be omitted when the function uses no local variables.
23685 \end_layout
23686
23687 \begin_layout Subsection
23688 Port Specific Options
23689 \begin_inset LatexCommand \index{Options PIC16}
23690
23691 \end_inset
23692
23693
23694 \end_layout
23695
23696 \begin_layout Standard
23697 The port specific options appear after the global options in the sdcc -
23698 \begin_inset ERT
23699 status collapsed
23700
23701 \begin_layout Standard
23702
23703
23704 \backslash
23705 /
23706 \end_layout
23707
23708 \end_inset
23709
23710 -help output.
23711 \end_layout
23712
23713 \begin_layout Subsubsection
23714 Code Generation Options
23715 \end_layout
23716
23717 \begin_layout Standard
23718 These options influence the generated assembler code.
23719 \end_layout
23720
23721 \begin_layout Description
23722 -
23723 \begin_inset ERT
23724 status collapsed
23725
23726 \begin_layout Standard
23727
23728
23729 \backslash
23730 /
23731 \end_layout
23732
23733 \end_inset
23734
23735 -pstack-model=[model] Used in conjuction with the command above.
23736  Defines the stack model to be used, valid stack models are:
23737 \end_layout
23738
23739 \begin_deeper
23740 \begin_layout List
23741 \labelwidthstring 00.00.0000
23742
23743 \emph on
23744 small
23745 \emph default
23746  Selects small stack model.
23747  8 bit stack and frame pointers.
23748  Supports 256 bytes stack size.
23749 \end_layout
23750
23751 \begin_layout List
23752 \labelwidthstring 00.00.0000
23753
23754 \emph on
23755 large
23756 \emph default
23757  Selects large stack model.
23758  16 bit stack and frame pointers.
23759  Supports 65536 bytes stack size.
23760 \end_layout
23761
23762 \end_deeper
23763 \begin_layout Description
23764 -
23765 \begin_inset ERT
23766 status collapsed
23767
23768 \begin_layout Standard
23769
23770
23771 \backslash
23772 /
23773 \end_layout
23774
23775 \end_inset
23776
23777 -pno-banksel Do not generate BANKSEL assembler directives.
23778 \end_layout
23779
23780 \begin_layout Description
23781 -
23782 \begin_inset ERT
23783 status collapsed
23784
23785 \begin_layout Standard
23786
23787
23788 \backslash
23789 /
23790 \end_layout
23791
23792 \end_inset
23793
23794 -extended Enable extended instruction set/literal offset addressing mode.
23795  Use with care!
23796 \end_layout
23797
23798 \begin_layout Subsubsection
23799 Optimization Options
23800 \end_layout
23801
23802 \begin_layout Description
23803 -
23804 \begin_inset ERT
23805 status collapsed
23806
23807 \begin_layout Standard
23808
23809
23810 \backslash
23811 /
23812 \end_layout
23813
23814 \end_inset
23815
23816 -obanksel=n Set optimization level for inserting BANKSELs.
23817 \newline
23818
23819 \end_layout
23820
23821 \begin_deeper
23822 \begin_layout List
23823 \labelwidthstring 00.00.0000
23824 0 no optimization
23825 \end_layout
23826
23827 \begin_layout List
23828 \labelwidthstring 00.00.0000
23829 1 checks previous used register and if it is the same then does not emit
23830  BANKSEL, accounts only for labels.
23831 \end_layout
23832
23833 \begin_layout List
23834 \labelwidthstring 00.00.0000
23835 2 tries to check the location of (even different) symbols and removes BANKSELs
23836  if they are in the same bank.
23837  
23838 \newline
23839
23840 \emph on
23841 Important: There might be problems if the linker script has data sections
23842  across bank borders!
23843 \end_layout
23844
23845 \end_deeper
23846 \begin_layout Description
23847 -
23848 \begin_inset ERT
23849 status collapsed
23850
23851 \begin_layout Standard
23852
23853
23854 \backslash
23855 /
23856 \end_layout
23857
23858 \end_inset
23859
23860 -denable-peeps Force the usage of peepholes.
23861  Use with care.
23862 \end_layout
23863
23864 \begin_layout Description
23865 -
23866 \begin_inset ERT
23867 status collapsed
23868
23869 \begin_layout Standard
23870
23871
23872 \backslash
23873 /
23874 \end_layout
23875
23876 \end_inset
23877
23878 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23879 \end_layout
23880
23881 \begin_layout Description
23882 -
23883 \begin_inset ERT
23884 status collapsed
23885
23886 \begin_layout Standard
23887
23888
23889 \backslash
23890 /
23891 \end_layout
23892
23893 \end_inset
23894
23895 -optimize-cmp Try to optimize some compares.
23896 \end_layout
23897
23898 \begin_layout Description
23899 -
23900 \begin_inset ERT
23901 status collapsed
23902
23903 \begin_layout Standard
23904
23905
23906 \backslash
23907 /
23908 \end_layout
23909
23910 \end_inset
23911
23912 -optimize-df Analyze the dataflow of the generated code and improve it.
23913 \end_layout
23914
23915 \begin_layout Subsubsection
23916 Assembling Options
23917 \end_layout
23918
23919 \begin_layout Description
23920 -
23921 \begin_inset ERT
23922 status collapsed
23923
23924 \begin_layout Standard
23925
23926
23927 \backslash
23928 /
23929 \end_layout
23930
23931 \end_inset
23932
23933 -asm= Sets the full path and name of an external assembler to call.
23934 \end_layout
23935
23936 \begin_layout Description
23937 -
23938 \begin_inset ERT
23939 status collapsed
23940
23941 \begin_layout Standard
23942
23943
23944 \backslash
23945 /
23946 \end_layout
23947
23948 \end_inset
23949
23950 -mplab-comp MPLAB
23951 \begin_inset LatexCommand \index{PIC16!MPLAB}
23952
23953 \end_inset
23954
23955  compatibility option.
23956  Currently only suppresses special gpasm directives.
23957 \end_layout
23958
23959 \begin_layout Subsubsection
23960 Linking Options
23961 \end_layout
23962
23963 \begin_layout Description
23964 -
23965 \begin_inset ERT
23966 status collapsed
23967
23968 \begin_layout Standard
23969
23970
23971 \backslash
23972 /
23973 \end_layout
23974
23975 \end_inset
23976
23977 -link= Sets the full path and name of an external linker to call.
23978 \end_layout
23979
23980 \begin_layout Description
23981 -
23982 \begin_inset ERT
23983 status collapsed
23984
23985 \begin_layout Standard
23986
23987
23988 \backslash
23989 /
23990 \end_layout
23991
23992 \end_inset
23993
23994 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23995  unitialized data variables with [kword].
23996  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23997 \end_layout
23998
23999 \begin_layout Description
24000 -
24001 \begin_inset ERT
24002 status collapsed
24003
24004 \begin_layout Standard
24005
24006
24007 \backslash
24008 /
24009 \end_layout
24010
24011 \end_inset
24012
24013 -ivt-loc=n Place the interrupt vector table at address 
24014 \emph on
24015 n
24016 \emph default
24017 .
24018  Useful for bootloaders.
24019 \end_layout
24020
24021 \begin_layout Description
24022 -
24023 \begin_inset ERT
24024 status collapsed
24025
24026 \begin_layout Standard
24027
24028
24029 \backslash
24030 /
24031 \end_layout
24032
24033 \end_inset
24034
24035 -nodefaultlibs Do not link default libraries when linking.
24036 \end_layout
24037
24038 \begin_layout Description
24039 -
24040 \begin_inset ERT
24041 status collapsed
24042
24043 \begin_layout Standard
24044
24045
24046 \backslash
24047 /
24048 \end_layout
24049
24050 \end_inset
24051
24052 -use-crt= Use a custom run-time module instead of the defaults.
24053 \end_layout
24054
24055 \begin_layout Description
24056 -
24057 \begin_inset ERT
24058 status collapsed
24059
24060 \begin_layout Standard
24061
24062
24063 \backslash
24064 /
24065 \end_layout
24066
24067 \end_inset
24068
24069 -no-crt Don't link the default run-time modules
24070 \end_layout
24071
24072 \begin_layout Subsubsection
24073 Debugging Options
24074 \end_layout
24075
24076 \begin_layout Standard
24077 Debugging options enable extra debugging information in the output files.
24078 \end_layout
24079
24080 \begin_layout Description
24081 -
24082 \begin_inset ERT
24083 status collapsed
24084
24085 \begin_layout Standard
24086
24087
24088 \backslash
24089 /
24090 \end_layout
24091
24092 \end_inset
24093
24094 -debug-xtra Similar to -
24095 \begin_inset ERT
24096 status collapsed
24097
24098 \begin_layout Standard
24099
24100
24101 \backslash
24102 /
24103 \end_layout
24104
24105 \end_inset
24106
24107 -debug
24108 \begin_inset LatexCommand \index{-\/-debug}
24109
24110 \end_inset
24111
24112 , but dumps more information.
24113 \end_layout
24114
24115 \begin_layout Description
24116 -
24117 \begin_inset ERT
24118 status collapsed
24119
24120 \begin_layout Standard
24121
24122
24123 \backslash
24124 /
24125 \end_layout
24126
24127 \end_inset
24128
24129 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24130  information.
24131  <source> is the name of the file being compiled.
24132 \end_layout
24133
24134 \begin_layout Description
24135 -
24136 \begin_inset ERT
24137 status collapsed
24138
24139 \begin_layout Standard
24140
24141
24142 \backslash
24143 /
24144 \end_layout
24145
24146 \end_inset
24147
24148 -pcode-verbose Enable pcode debugging information in translation.
24149 \end_layout
24150
24151 \begin_layout Description
24152 -
24153 \begin_inset ERT
24154 status collapsed
24155
24156 \begin_layout Standard
24157
24158
24159 \backslash
24160 /
24161 \end_layout
24162
24163 \end_inset
24164
24165 -calltree Dump call tree in .calltree file.
24166 \end_layout
24167
24168 \begin_layout Description
24169 -
24170 \begin_inset ERT
24171 status collapsed
24172
24173 \begin_layout Standard
24174
24175
24176 \backslash
24177 /
24178 \end_layout
24179
24180 \end_inset
24181
24182 -gstack Trace push/pops for stack pointer overflow.
24183 \end_layout
24184
24185 \begin_layout Subsection
24186 Enviroment Variables
24187 \end_layout
24188
24189 \begin_layout Standard
24190 There is a number of enviromental variables that can be used when running
24191  SDCC to enable certain optimizations or force a specific program behaviour.
24192  these variables are primarily for debugging purposes so they can be enabled/dis
24193 abled at will.
24194 \end_layout
24195
24196 \begin_layout Standard
24197 Currently there is only two such variables available:
24198 \end_layout
24199
24200 \begin_layout Description
24201 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24202  bitfields is optimized by directly loading FSR0 with the address of the
24203  bitfield structure.
24204  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24205  then load FSR0.
24206  This step saves data ram and code space for functions that make heavy use
24207  of bitfields.
24208  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24209  option).
24210  
24211 \end_layout
24212
24213 \begin_layout Description
24214 NO_REG_OPT Do not perform pCode registers optimization.
24215  This should be used for debugging purposes.
24216  If bugs in the pcode optimizer are found, users can benefit from temporarily
24217  disabling the optimizer until the bug is fixed.
24218 \end_layout
24219
24220 \begin_layout Subsection
24221 Preprocessor Macros
24222 \end_layout
24223
24224 \begin_layout Standard
24225 PIC16
24226 \begin_inset LatexCommand \index{PIC16}
24227
24228 \end_inset
24229
24230  port defines the following preprocessor macros while translating a source.
24231 \end_layout
24232
24233 \begin_layout Standard
24234 \align center
24235 \begin_inset Tabular
24236 <lyxtabular version="3" rows="6" columns="2">
24237 <features>
24238 <column alignment="center" valignment="top" leftline="true" width="0">
24239 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24240 <row topline="true" bottomline="true">
24241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24242 \begin_inset Text
24243
24244 \begin_layout Standard
24245 Macro
24246 \end_layout
24247
24248 \end_inset
24249 </cell>
24250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24251 \begin_inset Text
24252
24253 \begin_layout Standard
24254 Description
24255 \end_layout
24256
24257 \end_inset
24258 </cell>
24259 </row>
24260 <row topline="true">
24261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24262 \begin_inset Text
24263
24264 \begin_layout Standard
24265 SDCC_pic16
24266 \end_layout
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 \begin_layout Standard
24274 Port identification
24275 \end_layout
24276
24277 \end_inset
24278 </cell>
24279 </row>
24280 <row topline="true">
24281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24282 \begin_inset Text
24283
24284 \begin_layout Standard
24285 _
24286 \begin_inset ERT
24287 status collapsed
24288
24289 \begin_layout Standard
24290
24291
24292 \backslash
24293 /
24294 \end_layout
24295
24296 \end_inset
24297
24298 _pic16
24299 \end_layout
24300
24301 \end_inset
24302 </cell>
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24304 \begin_inset Text
24305
24306 \begin_layout Standard
24307 Port identification (same as above)
24308 \end_layout
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 \begin_layout Standard
24318 pic18fxxxx
24319 \end_layout
24320
24321 \end_inset
24322 </cell>
24323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24324 \begin_inset Text
24325
24326 \begin_layout Standard
24327 MCU Identification.
24328  
24329 \emph on
24330 xxxx
24331 \emph default
24332  is the microcontrol identification number, i.e.
24333  452, 6620, etc
24334 \end_layout
24335
24336 \end_inset
24337 </cell>
24338 </row>
24339 <row topline="true">
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24341 \begin_inset Text
24342
24343 \begin_layout Standard
24344 _
24345 \begin_inset ERT
24346 status collapsed
24347
24348 \begin_layout Standard
24349
24350
24351 \backslash
24352 /
24353 \end_layout
24354
24355 \end_inset
24356
24357 _18Fxxxx
24358 \end_layout
24359
24360 \end_inset
24361 </cell>
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24363 \begin_inset Text
24364
24365 \begin_layout Standard
24366 MCU Identification (same as above)
24367 \end_layout
24368
24369 \end_inset
24370 </cell>
24371 </row>
24372 <row topline="true" bottomline="true">
24373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24374 \begin_inset Text
24375
24376 \begin_layout Standard
24377 STACK_MODEL_nnn
24378 \end_layout
24379
24380 \end_inset
24381 </cell>
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24383 \begin_inset Text
24384
24385 \begin_layout Standard
24386 nnn = SMALL or LARGE respectively according to the stack model used
24387 \end_layout
24388
24389 \end_inset
24390 </cell>
24391 </row>
24392 </lyxtabular>
24393
24394 \end_inset
24395
24396
24397 \end_layout
24398
24399 \begin_layout Standard
24400 In addition the following macros are defined when calling assembler:
24401 \end_layout
24402
24403 \begin_layout Standard
24404 \align center
24405 \begin_inset Tabular
24406 <lyxtabular version="3" rows="4" columns="2">
24407 <features>
24408 <column alignment="center" valignment="top" leftline="true" width="0">
24409 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24410 <row topline="true" bottomline="true">
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24412 \begin_inset Text
24413
24414 \begin_layout Standard
24415 Macro
24416 \end_layout
24417
24418 \end_inset
24419 </cell>
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24421 \begin_inset Text
24422
24423 \begin_layout Standard
24424 Description
24425 \end_layout
24426
24427 \end_inset
24428 </cell>
24429 </row>
24430 <row topline="true">
24431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24432 \begin_inset Text
24433
24434 \begin_layout Standard
24435 __18Fxxxx
24436 \end_layout
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 \begin_layout Standard
24444 MCU Identification.
24445  
24446 \emph on
24447 xxxx
24448 \emph default
24449  is the microcontrol identification number, i.e.
24450  452, 6620, etc
24451 \end_layout
24452
24453 \end_inset
24454 </cell>
24455 </row>
24456 <row topline="true">
24457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24458 \begin_inset Text
24459
24460 \begin_layout Standard
24461 SDCC_MODEL_nnn
24462 \end_layout
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 \begin_layout Standard
24470 nnn = SMALL or LARGE respectively according to the memory model used for
24471  SDCC
24472 \end_layout
24473
24474 \end_inset
24475 </cell>
24476 </row>
24477 <row topline="true" bottomline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_inset Text
24480
24481 \begin_layout Standard
24482 STACK_MODEL_nnn
24483 \end_layout
24484
24485 \end_inset
24486 </cell>
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 \begin_inset Text
24489
24490 \begin_layout Standard
24491 nnn = SMALL or LARGE respectively according to the stack model used
24492 \end_layout
24493
24494 \end_inset
24495 </cell>
24496 </row>
24497 </lyxtabular>
24498
24499 \end_inset
24500
24501
24502 \end_layout
24503
24504 \begin_layout Subsection
24505 Directories
24506 \end_layout
24507
24508 \begin_layout Standard
24509 PIC16
24510 \begin_inset LatexCommand \index{PIC16}
24511
24512 \end_inset
24513
24514  port uses the following directories for searching header files and libraries.
24515 \end_layout
24516
24517 \begin_layout Standard
24518 \align center
24519 \begin_inset Tabular
24520 <lyxtabular version="3" rows="3" columns="4">
24521 <features>
24522 <column alignment="center" valignment="top" leftline="true" width="0">
24523 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24524 <column alignment="center" valignment="top" width="0">
24525 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24526 <row topline="true" bottomline="true">
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24528 \begin_inset Text
24529
24530 \begin_layout Standard
24531 Directory
24532 \end_layout
24533
24534 \end_inset
24535 </cell>
24536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24537 \begin_inset Text
24538
24539 \begin_layout Standard
24540 Description
24541 \end_layout
24542
24543 \end_inset
24544 </cell>
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24546 \begin_inset Text
24547
24548 \begin_layout Standard
24549 Target
24550 \end_layout
24551
24552 \end_inset
24553 </cell>
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24555 \begin_inset Text
24556
24557 \begin_layout Standard
24558 Command prefix
24559 \end_layout
24560
24561 \end_inset
24562 </cell>
24563 </row>
24564 <row topline="true">
24565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24566 \begin_inset Text
24567
24568 \begin_layout Standard
24569 PREFIX/sdcc/include/pic16
24570 \end_layout
24571
24572 \end_inset
24573 </cell>
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24575 \begin_inset Text
24576
24577 \begin_layout Standard
24578 PIC16 specific headers
24579 \end_layout
24580
24581 \end_inset
24582 </cell>
24583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24584 \begin_inset Text
24585
24586 \begin_layout Standard
24587 Compiler
24588 \end_layout
24589
24590 \end_inset
24591 </cell>
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24593 \begin_inset Text
24594
24595 \begin_layout Standard
24596 -I
24597 \end_layout
24598
24599 \end_inset
24600 </cell>
24601 </row>
24602 <row topline="true" bottomline="true">
24603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24604 \begin_inset Text
24605
24606 \begin_layout Standard
24607 PREFIX/sdcc/lib/pic16
24608 \end_layout
24609
24610 \end_inset
24611 </cell>
24612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24613 \begin_inset Text
24614
24615 \begin_layout Standard
24616 PIC16 specific libraries
24617 \end_layout
24618
24619 \end_inset
24620 </cell>
24621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24622 \begin_inset Text
24623
24624 \begin_layout Standard
24625 Linker
24626 \end_layout
24627
24628 \end_inset
24629 </cell>
24630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24631 \begin_inset Text
24632
24633 \begin_layout Standard
24634 -L
24635 \end_layout
24636
24637 \end_inset
24638 </cell>
24639 </row>
24640 </lyxtabular>
24641
24642 \end_inset
24643
24644
24645 \end_layout
24646
24647 \begin_layout Subsection
24648 Pragmas
24649 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24650
24651 \end_inset
24652
24653
24654 \end_layout
24655
24656 \begin_layout Standard
24657 The PIC16
24658 \begin_inset LatexCommand \index{PIC16}
24659
24660 \end_inset
24661
24662  port currently supports the following pragmas:
24663 \end_layout
24664
24665 \begin_layout Description
24666 stack
24667 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24668
24669 \end_inset
24670
24671  This forces the code generator to initialize the stack & frame pointers
24672  at a specific address.
24673  This is an ad hoc solution for cases where no STACK directive is available
24674  in the linker script or gplink is not instructed to create a stack section.
24675 \newline
24676 The
24677  stack pragma should be used only once in a project.
24678  Multiple pragmas may result in indeterminate behaviour of the program.
24679 \begin_inset Foot
24680 status open
24681
24682 \begin_layout Standard
24683 The old format (ie.
24684  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24685  cross page boundaries (or even exceed the available data RAM) and crash
24686  the program.
24687  Make sure that stack does not cross page boundaries when using the SMALL
24688  stack model.
24689 \end_layout
24690
24691 \end_inset
24692
24693
24694 \newline
24695 The format is as follows:
24696 \newline
24697
24698 \end_layout
24699
24700 \begin_layout LyX-Code
24701 #pragma stack bottom_address [stack_size]
24702 \newline
24703
24704 \end_layout
24705
24706 \begin_layout Standard
24707
24708 \emph on
24709 bottom_address
24710 \emph default
24711  is the lower bound of the stack section.
24712  The stack pointer initially will point at address (bottom_address+stack_size-1).
24713 \end_layout
24714
24715 \begin_layout LyX-Code
24716 Example:
24717 \end_layout
24718
24719 \begin_layout LyX-Code
24720
24721 \end_layout
24722
24723 \begin_layout LyX-Code
24724 /* initializes stack of 100 bytes at RAM address 0x200 */
24725 \end_layout
24726
24727 \begin_layout LyX-Code
24728 #pragma stack 0x200 100
24729 \end_layout
24730
24731 \begin_layout Standard
24732 If the stack_size field is omitted then a stack is created with the default
24733  size of 64.
24734  This size might be enough for most programs, but its not enough for operations
24735  with deep function nesting or excessive stack usage.
24736 \end_layout
24737
24738 \begin_layout Description
24739 code
24740 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24741
24742 \end_inset
24743
24744  Force a function to a static FLASH address.
24745 \end_layout
24746
24747 \begin_layout LyX-Code
24748 Example:
24749 \end_layout
24750
24751 \begin_layout LyX-Code
24752
24753 \end_layout
24754
24755 \begin_layout LyX-Code
24756 /* place function test_func at 0x4000 */
24757 \end_layout
24758
24759 \begin_layout LyX-Code
24760 #pragma code test_func 0x4000
24761 \end_layout
24762
24763 \begin_layout LyX-Code
24764
24765 \end_layout
24766
24767 \begin_layout Description
24768 library instructs the linker to use a library module.
24769 \newline
24770 Usage:
24771 \end_layout
24772
24773 \begin_layout LyX-Code
24774 #pragma library module_name
24775 \end_layout
24776
24777 \begin_layout Standard
24778
24779 \emph on
24780 module_name
24781 \emph default
24782  can be any library or object file (including its path).
24783  Note that there are four reserved keywords which have special meaning.
24784  These are:
24785 \end_layout
24786
24787 \begin_layout Standard
24788 \align center
24789 \begin_inset Tabular
24790 <lyxtabular version="3" rows="6" columns="3">
24791 <features>
24792 <column alignment="center" valignment="top" leftline="true" width="0">
24793 <column alignment="block" valignment="top" leftline="true" width="20page%">
24794 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24795 <row topline="true" bottomline="true">
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24797 \begin_inset Text
24798
24799 \begin_layout Standard
24800 Keyword
24801 \end_layout
24802
24803 \end_inset
24804 </cell>
24805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24806 \begin_inset Text
24807
24808 \begin_layout Standard
24809 Description
24810 \end_layout
24811
24812 \end_inset
24813 </cell>
24814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24815 \begin_inset Text
24816
24817 \begin_layout Standard
24818 Module to link
24819 \end_layout
24820
24821 \end_inset
24822 </cell>
24823 </row>
24824 <row topline="true">
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24826 \begin_inset Text
24827
24828 \begin_layout Standard
24829
24830 \series bold
24831 ignore
24832 \end_layout
24833
24834 \end_inset
24835 </cell>
24836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24837 \begin_inset Text
24838
24839 \begin_layout Standard
24840 ignore all library pragmas
24841 \end_layout
24842
24843 \end_inset
24844 </cell>
24845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24846 \begin_inset Text
24847
24848 \begin_layout Standard
24849
24850 \emph on
24851 (none)
24852 \end_layout
24853
24854 \end_inset
24855 </cell>
24856 </row>
24857 <row topline="true">
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24859 \begin_inset Text
24860
24861 \begin_layout Standard
24862
24863 \series bold
24864 c
24865 \end_layout
24866
24867 \end_inset
24868 </cell>
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24870 \begin_inset Text
24871
24872 \begin_layout Standard
24873 link the C library
24874 \end_layout
24875
24876 \end_inset
24877 </cell>
24878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24879 \begin_inset Text
24880
24881 \begin_layout Standard
24882
24883 \emph on
24884 libc18f
24885 \emph default
24886 .lib
24887 \end_layout
24888
24889 \end_inset
24890 </cell>
24891 </row>
24892 <row topline="true">
24893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24894 \begin_inset Text
24895
24896 \begin_layout Standard
24897
24898 \series bold
24899 math
24900 \end_layout
24901
24902 \end_inset
24903 </cell>
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24905 \begin_inset Text
24906
24907 \begin_layout Standard
24908 link the Math libarary
24909 \end_layout
24910
24911 \end_inset
24912 </cell>
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24914 \begin_inset Text
24915
24916 \begin_layout Standard
24917
24918 \emph on
24919 libm18f
24920 \emph default
24921 .lib
24922 \end_layout
24923
24924 \end_inset
24925 </cell>
24926 </row>
24927 <row topline="true">
24928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24929 \begin_inset Text
24930
24931 \begin_layout Standard
24932
24933 \series bold
24934 io
24935 \end_layout
24936
24937 \end_inset
24938 </cell>
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24940 \begin_inset Text
24941
24942 \begin_layout Standard
24943 link the I/O library
24944 \end_layout
24945
24946 \end_inset
24947 </cell>
24948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24949 \begin_inset Text
24950
24951 \begin_layout Standard
24952
24953 \emph on
24954 libio18f*
24955 \emph default
24956 .lib
24957 \end_layout
24958
24959 \end_inset
24960 </cell>
24961 </row>
24962 <row topline="true" bottomline="true">
24963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24964 \begin_inset Text
24965
24966 \begin_layout Standard
24967
24968 \series bold
24969 debug
24970 \end_layout
24971
24972 \end_inset
24973 </cell>
24974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24975 \begin_inset Text
24976
24977 \begin_layout Standard
24978 link the debug library
24979 \end_layout
24980
24981 \end_inset
24982 </cell>
24983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24984 \begin_inset Text
24985
24986 \begin_layout Standard
24987
24988 \emph on
24989 libdebug
24990 \emph default
24991 .lib
24992 \end_layout
24993
24994 \end_inset
24995 </cell>
24996 </row>
24997 </lyxtabular>
24998
24999 \end_inset
25000
25001
25002 \newline
25003 * is the device number, i.e.
25004  452 for PIC18F452 MCU.
25005 \end_layout
25006
25007 \begin_layout Standard
25008 This feature allows for linking with specific libraries withoug having to
25009  explicit name them in the command line.
25010  Note that the 
25011 \noun on
25012 ignore
25013 \noun default
25014  keyword will reject all modules specified by the library pragma.
25015 \end_layout
25016
25017 \begin_layout Description
25018 udata The pragma udata instructs the compiler to emit code so that linker
25019  will place a variable at a specific memory bank.
25020 \end_layout
25021
25022 \begin_layout LyX-Code
25023 Example:
25024 \end_layout
25025
25026 \begin_layout LyX-Code
25027
25028 \end_layout
25029
25030 \begin_layout LyX-Code
25031 /* places variable foo at bank2 */
25032 \end_layout
25033
25034 \begin_layout LyX-Code
25035 #pragma udata bank2 foo
25036 \end_layout
25037
25038 \begin_layout LyX-Code
25039 char foo;
25040 \end_layout
25041
25042 \begin_layout Standard
25043 In order for this pragma to work extra SECTION directives should be added
25044  in the .lkr script.
25045  In the following example a sample .lkr file is shown:
25046 \end_layout
25047
25048 \begin_layout LyX-Code
25049
25050 \end_layout
25051
25052 \begin_layout LyX-Code
25053 // Sample linker script for the PIC18F452 processor
25054 \end_layout
25055
25056 \begin_layout LyX-Code
25057 LIBPATH .
25058 \end_layout
25059
25060 \begin_layout LyX-Code
25061 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25062 \end_layout
25063
25064 \begin_layout LyX-Code
25065 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25066 \end_layout
25067
25068 \begin_layout LyX-Code
25069 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25070 \end_layout
25071
25072 \begin_layout LyX-Code
25073 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25074 \end_layout
25075
25076 \begin_layout LyX-Code
25077 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25078 \end_layout
25079
25080 \begin_layout LyX-Code
25081 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25082 \end_layout
25083
25084 \begin_layout LyX-Code
25085 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25086 \end_layout
25087
25088 \begin_layout LyX-Code
25089
25090 \end_layout
25091
25092 \begin_layout LyX-Code
25093 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25094 \end_layout
25095
25096 \begin_layout LyX-Code
25097 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25098 \end_layout
25099
25100 \begin_layout LyX-Code
25101 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25102 \end_layout
25103
25104 \begin_layout LyX-Code
25105 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25106 \end_layout
25107
25108 \begin_layout LyX-Code
25109 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25110 \end_layout
25111
25112 \begin_layout LyX-Code
25113 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25114 \end_layout
25115
25116 \begin_layout LyX-Code
25117 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25118 \end_layout
25119
25120 \begin_layout LyX-Code
25121
25122 \end_layout
25123
25124 \begin_layout LyX-Code
25125 SECTION    NAME=CONFIG     ROM=config
25126 \end_layout
25127
25128 \begin_layout LyX-Code
25129
25130 \end_layout
25131
25132 \begin_layout LyX-Code
25133 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25134 \end_layout
25135
25136 \begin_layout LyX-Code
25137 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25138 \end_layout
25139
25140 \begin_layout LyX-Code
25141 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25142 \end_layout
25143
25144 \begin_layout LyX-Code
25145 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25146 \end_layout
25147
25148 \begin_layout LyX-Code
25149 SECTION    NAME=bank4      RAM=gpr4
25150 \end_layout
25151
25152 \begin_layout LyX-Code
25153 SECTION    NAME=bank5      RAM=gpr5
25154 \end_layout
25155
25156 \begin_layout Standard
25157 The linker will recognise the section name set in the pragma statement and
25158  will position the variable at the memory bank set with the RAM field at
25159  the SECTION line in the linker script file.
25160 \end_layout
25161
25162 \begin_layout Subsection
25163 Header Files
25164 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25165
25166 \end_inset
25167
25168
25169 \end_layout
25170
25171 \begin_layout Standard
25172 There is one main header file
25173 \begin_inset LatexCommand \index{PIC16!Header files}
25174
25175 \end_inset
25176
25177  that can be included to the source files using the pic16
25178 \begin_inset LatexCommand \index{PIC16}
25179
25180 \end_inset
25181
25182  port.
25183  That file is the 
25184 \series bold
25185 pic18fregs.h
25186 \series default
25187 .
25188  This header file contains the definitions for the processor special registers,
25189  so it is necessary if the source accesses them.
25190  It can be included by adding the following line in the beginning of the
25191  file:
25192 \end_layout
25193
25194 \begin_layout LyX-Code
25195 #include <pic18fregs.h>
25196 \end_layout
25197
25198 \begin_layout Standard
25199 The specific microcontroller is selected within the pic18fregs.h automatically,
25200  so the same source can be used with a variety of devices.
25201 \end_layout
25202
25203 \begin_layout Subsection
25204 Libraries
25205 \end_layout
25206
25207 \begin_layout Standard
25208 The libraries
25209 \begin_inset LatexCommand \index{PIC16!Libraries}
25210
25211 \end_inset
25212
25213  that PIC16
25214 \begin_inset LatexCommand \index{PIC16}
25215
25216 \end_inset
25217
25218  port depends on are the microcontroller device libraries which contain
25219  the symbol definitions for the microcontroller special function registers.
25220  These libraries have the format pic18fxxxx.lib, where 
25221 \emph on
25222 xxxx
25223 \emph default
25224  is the microcontroller identification number.
25225  The specific library is selected automatically by the compiler at link
25226  stage according to the selected device.
25227 \end_layout
25228
25229 \begin_layout Standard
25230 Libraries are created with gplib which is part of the gputils package 
25231 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25232
25233 \end_inset
25234
25235 .
25236 \end_layout
25237
25238 \begin_layout Subsubsection*
25239 Building the libraries
25240 \end_layout
25241
25242 \begin_layout Standard
25243 Before using SDCC/pic16 there are some libraries that need to be compiled.
25244  This process is not done automatically by SDCC since not all users use
25245  SDCC for pic16 projects.
25246  So each user should compile the libraries separately.
25247 \end_layout
25248
25249 \begin_layout Standard
25250 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25251 \end_layout
25252
25253 \begin_layout LyX-Code
25254 cd device/lib/pic16
25255 \end_layout
25256
25257 \begin_layout LyX-Code
25258 ./configure
25259 \end_layout
25260
25261 \begin_layout LyX-Code
25262 make
25263 \end_layout
25264
25265 \begin_layout LyX-Code
25266 cd ..
25267 \end_layout
25268
25269 \begin_layout LyX-Code
25270 make model-pic16
25271 \end_layout
25272
25273 \begin_layout LyX-Code
25274 su -c 'make install'     # install the libraries, you need the root password
25275 \end_layout
25276
25277 \begin_layout Standard
25278 If you need to install the headers too, do:
25279 \end_layout
25280
25281 \begin_layout LyX-Code
25282 cd device/include
25283 \end_layout
25284
25285 \begin_layout LyX-Code
25286 su -c 'make install'     # install the headers, you need the root password
25287 \end_layout
25288
25289 \begin_layout Standard
25290 There exist a special target to build the I/O libraries.
25291  This target is not automatically build because it will build the I/O library
25292  for 
25293 \emph on
25294 every
25295 \emph default
25296  supported device.
25297  This way building will take quite a lot of time.
25298  Users are advised to edit the 
25299 \series bold
25300 device/lib/pic16/pics.build
25301 \series default
25302  file and then execute:
25303 \end_layout
25304
25305 \begin_layout LyX-Code
25306 make lib-io
25307 \end_layout
25308
25309 \begin_layout Subsection
25310 Adding New Devices to the Port
25311 \end_layout
25312
25313 \begin_layout Standard
25314 Adding support for a new 16
25315 \begin_inset ERT
25316 status open
25317
25318 \begin_layout Standard
25319
25320
25321 \backslash
25322 ,
25323 \end_layout
25324
25325 \end_inset
25326
25327 bit PIC MCU requires the following steps:
25328 \end_layout
25329
25330 \begin_layout Enumerate
25331 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25332 \newline
25333
25334 \family typewriter
25335 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25336 inc
25337 \end_layout
25338
25339 \begin_layout Enumerate
25340
25341 \family typewriter
25342 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25343 \end_layout
25344
25345 \begin_layout Enumerate
25346
25347 \family typewriter
25348 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25349 \end_layout
25350
25351 \begin_layout Enumerate
25352 Add DEVICE to 
25353 \family typewriter
25354 /path/to/sdcc/device/lib/pics.all
25355 \family default
25356  (and 
25357 \family typewriter
25358 .build
25359 \family default
25360 ).
25361 \newline
25362 Note: No 18f prefix here!
25363 \end_layout
25364
25365 \begin_layout Enumerate
25366 Adjust 
25367 \family typewriter
25368 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25369 \family default
25370
25371 \newline
25372 Add your DEVICE if it does not compile in 
25373 \family typewriter
25374 adc
25375 \family default
25376
25377 \family typewriter
25378 i2c
25379 \family default
25380 , or 
25381 \family typewriter
25382 usart
25383 \family default
25384 .
25385 \end_layout
25386
25387 \begin_layout Enumerate
25388 Edit 
25389 \family typewriter
25390 /path/to/sdcc/device/include/pic16/pic18fregs.h
25391 \family default
25392 .
25393  The file format is self-explanatory, just add
25394 \newline
25395
25396 \family typewriter
25397 #elif defined(picDEVICE)
25398 \newline
25399 # include <picDEVICE.h>
25400 \family default
25401
25402 \newline
25403 at the right place (keep it sorted).
25404 \end_layout
25405
25406 \begin_layout Enumerate
25407 Edit 
25408 \family typewriter
25409 /path/to/sdcc/src/pic16/devices.inc
25410 \family default
25411 .
25412  Copy and modify an existing entry and insert it at the correct place (keep
25413  the file sorted).
25414  The file is hardly documented, look at the entries for the 18f2221...
25415 \end_layout
25416
25417 \begin_layout Enumerate
25418 Recompile SDCC, including the pic16 libraries.
25419 \end_layout
25420
25421 \begin_layout Subsection
25422 Memory Models
25423 \end_layout
25424
25425 \begin_layout Standard
25426 The following memory models are supported by the PIC16 port:
25427 \end_layout
25428
25429 \begin_layout Itemize
25430 small model
25431 \end_layout
25432
25433 \begin_layout Itemize
25434 large model
25435 \end_layout
25436
25437 \begin_layout Standard
25438 Memory model affects the default size of pointers within the source.
25439  The sizes are shown in the next table:
25440 \end_layout
25441
25442 \begin_layout Standard
25443 \align center
25444 \begin_inset Tabular
25445 <lyxtabular version="3" rows="3" columns="3">
25446 <features>
25447 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25448 <column alignment="center" valignment="top" leftline="true" width="0">
25449 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25450 <row topline="true" bottomline="true">
25451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25452 \begin_inset Text
25453
25454 \begin_layout Standard
25455 Pointer sizes according to memory model
25456 \end_layout
25457
25458 \end_inset
25459 </cell>
25460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25461 \begin_inset Text
25462
25463 \begin_layout Standard
25464 small model
25465 \end_layout
25466
25467 \end_inset
25468 </cell>
25469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25470 \begin_inset Text
25471
25472 \begin_layout Standard
25473 large model
25474 \end_layout
25475
25476 \end_inset
25477 </cell>
25478 </row>
25479 <row topline="true" bottomline="true">
25480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25481 \begin_inset Text
25482
25483 \begin_layout Standard
25484 code pointers
25485 \end_layout
25486
25487 \end_inset
25488 </cell>
25489 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25490 \begin_inset Text
25491
25492 \begin_layout Standard
25493 16-bits
25494 \end_layout
25495
25496 \end_inset
25497 </cell>
25498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25499 \begin_inset Text
25500
25501 \begin_layout Standard
25502 24-bits
25503 \end_layout
25504
25505 \end_inset
25506 </cell>
25507 </row>
25508 <row topline="true" bottomline="true">
25509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25510 \begin_inset Text
25511
25512 \begin_layout Standard
25513 data pointers
25514 \end_layout
25515
25516 \end_inset
25517 </cell>
25518 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25519 \begin_inset Text
25520
25521 \begin_layout Standard
25522 16-bits
25523 \end_layout
25524
25525 \end_inset
25526 </cell>
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25528 \begin_inset Text
25529
25530 \begin_layout Standard
25531 16-bits
25532 \end_layout
25533
25534 \end_inset
25535 </cell>
25536 </row>
25537 </lyxtabular>
25538
25539 \end_inset
25540
25541
25542 \end_layout
25543
25544 \begin_layout Standard
25545 It is advisable that all sources within a project are compiled with the
25546  same memory model.
25547  If one wants to override the default memory model, this can be done by
25548  declaring a pointer as 
25549 \series bold
25550 far
25551 \series default
25552  or 
25553 \series bold
25554 near
25555 \series default
25556 .
25557  Far selects large memory model's pointers, while near selects small memory
25558  model's pointers.
25559 \end_layout
25560
25561 \begin_layout Standard
25562 The standard device libraries (see 
25563 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25564
25565 \end_inset
25566
25567 ) contain no reference to pointers, so they can be used with both memory
25568  models.
25569 \end_layout
25570
25571 \begin_layout Subsection
25572 Stack
25573 \end_layout
25574
25575 \begin_layout Standard
25576 The stack
25577 \begin_inset LatexCommand \index{PIC16!stack}
25578
25579 \end_inset
25580
25581  implementation for the PIC16 port uses two indirect registers, FSR1 and
25582  FSR2.
25583 \end_layout
25584
25585 \begin_layout Description
25586 FSR1 is assigned as stack pointer
25587 \end_layout
25588
25589 \begin_layout Description
25590 FSR2 is assigned as frame pointer
25591 \end_layout
25592
25593 \begin_layout Standard
25594 The following stack models are supported by the PIC16 port
25595 \end_layout
25596
25597 \begin_layout Itemize
25598
25599 \noun on
25600 small
25601 \noun default
25602  model
25603 \end_layout
25604
25605 \begin_layout Itemize
25606
25607 \noun on
25608 large
25609 \noun default
25610  model
25611 \end_layout
25612
25613 \begin_layout Standard
25614
25615 \noun on
25616 Small
25617 \noun default
25618  model means that only the FSRxL byte is used to access stack and frame,
25619  while 
25620 \emph on
25621 \noun on
25622 large
25623 \emph default
25624 \noun default
25625  uses both FSRxL and FSRxH registers.
25626  The following table shows the stack/frame pointers sizes according to stack
25627  model and the maximum space they can address:
25628 \end_layout
25629
25630 \begin_layout Standard
25631 \align center
25632 \begin_inset Tabular
25633 <lyxtabular version="3" rows="3" columns="3">
25634 <features>
25635 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25636 <column alignment="center" valignment="top" leftline="true" width="0">
25637 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25638 <row topline="true" bottomline="true">
25639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25640 \begin_inset Text
25641
25642 \begin_layout Standard
25643 Stack & Frame pointer sizes according to stack model
25644 \end_layout
25645
25646 \end_inset
25647 </cell>
25648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25649 \begin_inset Text
25650
25651 \begin_layout Standard
25652 small
25653 \end_layout
25654
25655 \end_inset
25656 </cell>
25657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25658 \begin_inset Text
25659
25660 \begin_layout Standard
25661 large
25662 \end_layout
25663
25664 \end_inset
25665 </cell>
25666 </row>
25667 <row topline="true">
25668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25669 \begin_inset Text
25670
25671 \begin_layout Standard
25672 Stack pointer FSR1
25673 \end_layout
25674
25675 \end_inset
25676 </cell>
25677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25678 \begin_inset Text
25679
25680 \begin_layout Standard
25681 8-bits
25682 \end_layout
25683
25684 \end_inset
25685 </cell>
25686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25687 \begin_inset Text
25688
25689 \begin_layout Standard
25690 16-bits
25691 \end_layout
25692
25693 \end_inset
25694 </cell>
25695 </row>
25696 <row topline="true" bottomline="true">
25697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25698 \begin_inset Text
25699
25700 \begin_layout Standard
25701 Frame pointer FSR2
25702 \end_layout
25703
25704 \end_inset
25705 </cell>
25706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25707 \begin_inset Text
25708
25709 \begin_layout Standard
25710 8-bits
25711 \end_layout
25712
25713 \end_inset
25714 </cell>
25715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25716 \begin_inset Text
25717
25718 \begin_layout Standard
25719 16-bits
25720 \end_layout
25721
25722 \end_inset
25723 </cell>
25724 </row>
25725 </lyxtabular>
25726
25727 \end_inset
25728
25729
25730 \end_layout
25731
25732 \begin_layout Standard
25733
25734 \noun on
25735 Large 
25736 \noun default
25737 stack model is currently not working properly throughout the code generator.
25738  So its use is not advised.
25739  Also there are some other points that need special care:
25740 \newline
25741
25742 \end_layout
25743
25744 \begin_layout Enumerate
25745 Do not create stack sections with size more than one physical bank (that
25746  is 256 bytes)
25747 \end_layout
25748
25749 \begin_layout Enumerate
25750 Stack sections should no cross physical bank limits (i.e.
25751  #pragma stack 0x50 0x100)
25752 \end_layout
25753
25754 \begin_layout Standard
25755 These limitations are caused by the fact that only FSRxL is modified when
25756  using SMALL stack model, so no more than 256 bytes of stack can be used.
25757  This problem will disappear after LARGE model is fully implemented.
25758 \end_layout
25759
25760 \begin_layout Subsection
25761 Functions
25762 \end_layout
25763
25764 \begin_layout Standard
25765 In addition to the standard SDCC function keywords, PIC16
25766 \begin_inset LatexCommand \index{PIC16}
25767
25768 \end_inset
25769
25770  port makes available two more:
25771 \end_layout
25772
25773 \begin_layout Description
25774 wparam
25775 \begin_inset LatexCommand \index{PIC16!wparam}
25776
25777 \end_inset
25778
25779  Use the WREG to pass one byte of the first function argument.
25780  This improves speed but you may not use this for functions with arguments
25781  that are called via function pointers, otherwise the first byte of the
25782  first parameter will get lost.
25783  Usage:
25784 \end_layout
25785
25786 \begin_layout LyX-Code
25787 void func_wparam(int a) wparam
25788 \end_layout
25789
25790 \begin_layout LyX-Code
25791 {
25792 \end_layout
25793
25794 \begin_layout LyX-Code
25795     /* WREG hold the lower part of a */
25796 \end_layout
25797
25798 \begin_layout LyX-Code
25799     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25800  */
25801 \end_layout
25802
25803 \begin_layout LyX-Code
25804 ...
25805 \end_layout
25806
25807 \begin_layout LyX-Code
25808 }
25809 \end_layout
25810
25811 \begin_layout Description
25812 shadowregs
25813 \begin_inset LatexCommand \index{PIC16!shadowregs}
25814
25815 \end_inset
25816
25817  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25818  hardware shadow registers which hold the values of WREG, STATUS and BSR
25819  registers.
25820  This can be done by adding the keyword 
25821 \emph on
25822 shadowregs
25823 \emph default
25824  before the 
25825 \emph on
25826 interrupt
25827 \emph default
25828  keyword in the function's header.
25829 \end_layout
25830
25831 \begin_layout LyX-Code
25832 void isr_shadow(void) shadowregs interrupt 1
25833 \end_layout
25834
25835 \begin_layout LyX-Code
25836 {
25837 \end_layout
25838
25839 \begin_layout LyX-Code
25840 ...
25841 \end_layout
25842
25843 \begin_layout LyX-Code
25844 }
25845 \end_layout
25846
25847 \begin_layout Standard
25848
25849 \emph on
25850 shadowregs
25851 \emph default
25852  instructs the code generator not to store/restore WREG, STATUS, BSR when
25853  entering/exiting the ISR.
25854 \end_layout
25855
25856 \begin_layout Subsection
25857 Function return values
25858 \end_layout
25859
25860 \begin_layout Standard
25861 Return values from functions are placed to the appropriate registers following
25862  a modified Microchip policy optimized for SDCC.
25863  The following table shows these registers:
25864 \end_layout
25865
25866 \begin_layout Standard
25867 \align center
25868 \begin_inset Tabular
25869 <lyxtabular version="3" rows="6" columns="2">
25870 <features>
25871 <column alignment="center" valignment="top" leftline="true" width="0">
25872 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25873 <row topline="true" bottomline="true">
25874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25875 \begin_inset Text
25876
25877 \begin_layout Standard
25878 size
25879 \end_layout
25880
25881 \end_inset
25882 </cell>
25883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25884 \begin_inset Text
25885
25886 \begin_layout Standard
25887 destination register
25888 \end_layout
25889
25890 \end_inset
25891 </cell>
25892 </row>
25893 <row topline="true">
25894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25895 \begin_inset Text
25896
25897 \begin_layout Standard
25898 8 bits
25899 \end_layout
25900
25901 \end_inset
25902 </cell>
25903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25904 \begin_inset Text
25905
25906 \begin_layout Standard
25907 WREG
25908 \end_layout
25909
25910 \end_inset
25911 </cell>
25912 </row>
25913 <row topline="true">
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \begin_layout Standard
25918 16 bits
25919 \end_layout
25920
25921 \end_inset
25922 </cell>
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25924 \begin_inset Text
25925
25926 \begin_layout Standard
25927 PRODL:WREG
25928 \end_layout
25929
25930 \end_inset
25931 </cell>
25932 </row>
25933 <row topline="true">
25934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25935 \begin_inset Text
25936
25937 \begin_layout Standard
25938 24 bits
25939 \end_layout
25940
25941 \end_inset
25942 </cell>
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25944 \begin_inset Text
25945
25946 \begin_layout Standard
25947 PRODH:PRODL:WREG
25948 \end_layout
25949
25950 \end_inset
25951 </cell>
25952 </row>
25953 <row topline="true">
25954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25955 \begin_inset Text
25956
25957 \begin_layout Standard
25958 32 bits
25959 \end_layout
25960
25961 \end_inset
25962 </cell>
25963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25964 \begin_inset Text
25965
25966 \begin_layout Standard
25967 FSR0L:PRODH:PRODL:WREG
25968 \end_layout
25969
25970 \end_inset
25971 </cell>
25972 </row>
25973 <row topline="true" bottomline="true">
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25975 \begin_inset Text
25976
25977 \begin_layout Standard
25978 >32 bits
25979 \end_layout
25980
25981 \end_inset
25982 </cell>
25983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25984 \begin_inset Text
25985
25986 \begin_layout Standard
25987 on stack, FSR0 points to the beginning
25988 \end_layout
25989
25990 \end_inset
25991 </cell>
25992 </row>
25993 </lyxtabular>
25994
25995 \end_inset
25996
25997
25998 \end_layout
25999
26000 \begin_layout Subsection
26001 Interrupts
26002 \end_layout
26003
26004 \begin_layout Standard
26005 An interrupt
26006 \begin_inset LatexCommand \index{PIC16!interrupt}
26007
26008 \end_inset
26009
26010  service routine (ISR) is declared using the 
26011 \emph on
26012 interrupt
26013 \emph default
26014  keyword.
26015 \end_layout
26016
26017 \begin_layout LyX-Code
26018 void isr(void) interrupt 
26019 \emph on
26020 n
26021 \end_layout
26022
26023 \begin_layout LyX-Code
26024 {
26025 \end_layout
26026
26027 \begin_layout LyX-Code
26028 ...
26029 \end_layout
26030
26031 \begin_layout LyX-Code
26032 }
26033 \end_layout
26034
26035 \begin_layout Standard
26036
26037 \emph on
26038 n
26039 \emph default
26040  is the interrupt number, which for PIC18F devices can be:
26041 \end_layout
26042
26043 \begin_layout Standard
26044 \align center
26045 \begin_inset Tabular
26046 <lyxtabular version="3" rows="4" columns="3">
26047 <features>
26048 <column alignment="center" valignment="top" leftline="true" width="0">
26049 <column alignment="center" valignment="top" leftline="true" width="0">
26050 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26051 <row topline="true" bottomline="true">
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26053 \begin_inset Text
26054
26055 \begin_layout Standard
26056
26057 \emph on
26058 n
26059 \end_layout
26060
26061 \end_inset
26062 </cell>
26063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26064 \begin_inset Text
26065
26066 \begin_layout Standard
26067 Interrupt Vector
26068 \end_layout
26069
26070 \end_inset
26071 </cell>
26072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26073 \begin_inset Text
26074
26075 \begin_layout Standard
26076 Interrupt Vector Address
26077 \end_layout
26078
26079 \end_inset
26080 </cell>
26081 </row>
26082 <row topline="true">
26083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26084 \begin_inset Text
26085
26086 \begin_layout Standard
26087 0
26088 \end_layout
26089
26090 \end_inset
26091 </cell>
26092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26093 \begin_inset Text
26094
26095 \begin_layout Standard
26096 RESET vector
26097 \end_layout
26098
26099 \end_inset
26100 </cell>
26101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26102 \begin_inset Text
26103
26104 \begin_layout Standard
26105 0x000000
26106 \end_layout
26107
26108 \end_inset
26109 </cell>
26110 </row>
26111 <row topline="true">
26112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26113 \begin_inset Text
26114
26115 \begin_layout Standard
26116
26117 \family roman
26118 \series medium
26119 \shape up
26120 \size normal
26121 \emph off
26122 \bar no
26123 \noun off
26124 \color none
26125 1
26126 \end_layout
26127
26128 \end_inset
26129 </cell>
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26131 \begin_inset Text
26132
26133 \begin_layout Standard
26134
26135 \family roman
26136 \series medium
26137 \shape up
26138 \size normal
26139 \emph off
26140 \bar no
26141 \noun off
26142 \color none
26143 HIGH priority interrupts
26144 \end_layout
26145
26146 \end_inset
26147 </cell>
26148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26149 \begin_inset Text
26150
26151 \begin_layout Standard
26152 0x000008
26153 \end_layout
26154
26155 \end_inset
26156 </cell>
26157 </row>
26158 <row topline="true" bottomline="true">
26159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26160 \begin_inset Text
26161
26162 \begin_layout Standard
26163 2
26164 \end_layout
26165
26166 \end_inset
26167 </cell>
26168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26169 \begin_inset Text
26170
26171 \begin_layout Standard
26172 LOW priority interrupts
26173 \end_layout
26174
26175 \end_inset
26176 </cell>
26177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26178 \begin_inset Text
26179
26180 \begin_layout Standard
26181 0x000018
26182 \end_layout
26183
26184 \end_inset
26185 </cell>
26186 </row>
26187 </lyxtabular>
26188
26189 \end_inset
26190
26191
26192 \end_layout
26193
26194 \begin_layout Standard
26195 When generating assembly code for ISR the code generator places a 
26196 \noun on
26197 goto 
26198 \noun default
26199 instruction at the 
26200 \emph on
26201 Interrupt Vector Address
26202 \emph default
26203  which points at the genetated ISR.
26204  This single GOTO instruction is part of an automatically generated 
26205 \emph on
26206 interrupt entry point
26207 \emph default
26208  function.
26209  The actuall ISR code is placed as normally would in the code space.
26210  Upon interrupt request, the GOTO instruction is executed which jumps to
26211  the ISR code.
26212  When declaring interrupt functions as _naked this GOTO instruction is 
26213 \series bold
26214 not
26215 \series default
26216  generated.
26217  The whole interrupt functions is therefore placed at the Interrupt Vector
26218  Address of the specific interrupt.
26219  This is not a problem for the LOW priority interrupts, but it is a problem
26220  for the RESET and the HIGH priority interrupts because code may be written
26221  at the next interrupt's vector address and cause undeterminate program
26222  behaviour if that interrupt is raised.
26223 \begin_inset Foot
26224 status open
26225
26226 \begin_layout Standard
26227 This is not a problem when
26228 \end_layout
26229
26230 \begin_layout Enumerate
26231 this is a HIGH interrupt ISR and LOW interrupts are 
26232 \emph on
26233 disabled
26234 \emph default
26235  or not used.
26236 \end_layout
26237
26238 \begin_layout Enumerate
26239 when the ISR is small enough not to reach the next interrupt's vector address.
26240 \end_layout
26241
26242 \end_inset
26243
26244
26245 \end_layout
26246
26247 \begin_layout Standard
26248
26249 \emph on
26250 n
26251 \emph default
26252  may be omitted.
26253  This way a function is generated similar to an ISR, but it is not assigned
26254  to any interrupt.
26255 \end_layout
26256
26257 \begin_layout Standard
26258 When entering an interrupt, currently the PIC16
26259 \begin_inset LatexCommand \index{PIC16}
26260
26261 \end_inset
26262
26263  port automatically saves the following registers:
26264 \end_layout
26265
26266 \begin_layout Itemize
26267 WREG
26268 \end_layout
26269
26270 \begin_layout Itemize
26271 STATUS
26272 \end_layout
26273
26274 \begin_layout Itemize
26275 BSR
26276 \end_layout
26277
26278 \begin_layout Itemize
26279 PROD (PRODL and PRODH)
26280 \end_layout
26281
26282 \begin_layout Itemize
26283 FSR0 (FSR0L and FSR0H)
26284 \end_layout
26285
26286 \begin_layout Standard
26287 These registers are restored upon return from the interrupt routine.
26288 \begin_inset Foot
26289 status open
26290
26291 \begin_layout Standard
26292 NOTE that when the _naked attribute is specified for an interrupt routine,
26293  then NO registers are stored or restored.
26294 \end_layout
26295
26296 \end_inset
26297
26298
26299 \end_layout
26300
26301 \begin_layout Subsection
26302 Generic Pointers
26303 \end_layout
26304
26305 \begin_layout Standard
26306 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26307  There are 3 types of generic pointers currently implemented data, code
26308  and eeprom pointers.
26309  They are differentiated by the value of the 7th and 6th bits of the upper
26310  byte:
26311 \end_layout
26312
26313 \begin_layout Standard
26314 \align center
26315 \begin_inset Tabular
26316 <lyxtabular version="3" rows="5" columns="5">
26317 <features>
26318 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26319 <column alignment="center" valignment="top" width="0">
26320 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26321 <column alignment="center" valignment="top" width="0">
26322 <column alignment="left" valignment="top" rightline="true" width="0">
26323 <row topline="true" bottomline="true">
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26325 \begin_inset Text
26326
26327 \begin_layout Standard
26328 pointer type
26329 \end_layout
26330
26331 \end_inset
26332 </cell>
26333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26334 \begin_inset Text
26335
26336 \begin_layout Standard
26337 7th bit
26338 \end_layout
26339
26340 \end_inset
26341 </cell>
26342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26343 \begin_inset Text
26344
26345 \begin_layout Standard
26346 6th bit
26347 \end_layout
26348
26349 \end_inset
26350 </cell>
26351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26352 \begin_inset Text
26353
26354 \begin_layout Standard
26355 rest of the pointer
26356 \end_layout
26357
26358 \end_inset
26359 </cell>
26360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26361 \begin_inset Text
26362
26363 \begin_layout Standard
26364 description
26365 \end_layout
26366
26367 \end_inset
26368 </cell>
26369 </row>
26370 <row topline="true" bottomline="true">
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26372 \begin_inset Text
26373
26374 \begin_layout Standard
26375 data 
26376 \end_layout
26377
26378 \end_inset
26379 </cell>
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26381 \begin_inset Text
26382
26383 \begin_layout Standard
26384 1
26385 \end_layout
26386
26387 \end_inset
26388 </cell>
26389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26390 \begin_inset Text
26391
26392 \begin_layout Standard
26393 0
26394 \end_layout
26395
26396 \end_inset
26397 </cell>
26398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26399 \begin_inset Text
26400
26401 \begin_layout Standard
26402
26403 \family typewriter
26404 \shape slanted
26405 \emph on
26406 uuuuuu uuuuxxxx xxxxxxxx
26407 \end_layout
26408
26409 \end_inset
26410 </cell>
26411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26412 \begin_inset Text
26413
26414 \begin_layout Standard
26415 a 12-bit data pointer in data RAM memory
26416 \end_layout
26417
26418 \end_inset
26419 </cell>
26420 </row>
26421 <row bottomline="true">
26422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26423 \begin_inset Text
26424
26425 \begin_layout Standard
26426 code
26427 \end_layout
26428
26429 \end_inset
26430 </cell>
26431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26432 \begin_inset Text
26433
26434 \begin_layout Standard
26435 0
26436 \end_layout
26437
26438 \end_inset
26439 </cell>
26440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26441 \begin_inset Text
26442
26443 \begin_layout Standard
26444 0
26445 \end_layout
26446
26447 \end_inset
26448 </cell>
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26450 \begin_inset Text
26451
26452 \begin_layout Standard
26453
26454 \family typewriter
26455 \shape slanted
26456 \emph on
26457 uxxxxx xxxxxxxx xxxxxxxx
26458 \end_layout
26459
26460 \end_inset
26461 </cell>
26462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26463 \begin_inset Text
26464
26465 \begin_layout Standard
26466 a 21-bit code pointer in FLASH memory
26467 \end_layout
26468
26469 \end_inset
26470 </cell>
26471 </row>
26472 <row bottomline="true">
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26474 \begin_inset Text
26475
26476 \begin_layout Standard
26477 eeprom
26478 \end_layout
26479
26480 \end_inset
26481 </cell>
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26483 \begin_inset Text
26484
26485 \begin_layout Standard
26486 0
26487 \end_layout
26488
26489 \end_inset
26490 </cell>
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \begin_layout Standard
26495 1
26496 \end_layout
26497
26498 \end_inset
26499 </cell>
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26501 \begin_inset Text
26502
26503 \begin_layout Standard
26504
26505 \family typewriter
26506 \shape slanted
26507 \emph on
26508 uuuuuu uuuuuuxx xxxxxxxx
26509 \end_layout
26510
26511 \end_inset
26512 </cell>
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26514 \begin_inset Text
26515
26516 \begin_layout Standard
26517 a 10-bit eeprom pointer in EEPROM memory
26518 \end_layout
26519
26520 \end_inset
26521 </cell>
26522 </row>
26523 <row bottomline="true">
26524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26525 \begin_inset Text
26526
26527 \begin_layout Standard
26528 (unimplemented)
26529 \end_layout
26530
26531 \end_inset
26532 </cell>
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26534 \begin_inset Text
26535
26536 \begin_layout Standard
26537 1
26538 \end_layout
26539
26540 \end_inset
26541 </cell>
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26543 \begin_inset Text
26544
26545 \begin_layout Standard
26546 1
26547 \end_layout
26548
26549 \end_inset
26550 </cell>
26551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26552 \begin_inset Text
26553
26554 \begin_layout Standard
26555
26556 \family typewriter
26557 \shape slanted
26558 \emph on
26559 xxxxxx xxxxxxxx xxxxxxxx
26560 \end_layout
26561
26562 \end_inset
26563 </cell>
26564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26565 \begin_inset Text
26566
26567 \begin_layout Standard
26568 unimplemented pointer type
26569 \end_layout
26570
26571 \end_inset
26572 </cell>
26573 </row>
26574 </lyxtabular>
26575
26576 \end_inset
26577
26578
26579 \end_layout
26580
26581 \begin_layout Standard
26582 Generic pointer are read and written with a set of library functions which
26583  read/write 1, 2, 3, 4 bytes.
26584 \end_layout
26585
26586 \begin_layout Subsection
26587 PIC16 C Libraries
26588 \end_layout
26589
26590 \begin_layout Subsubsection
26591 Standard I/O Streams
26592 \end_layout
26593
26594 \begin_layout Standard
26595 In the 
26596 \emph on
26597 stdio.h
26598 \emph default
26599  the type FILE is defined as:
26600 \end_layout
26601
26602 \begin_layout LyX-Code
26603 typedef char * FILE;
26604 \end_layout
26605
26606 \begin_layout Standard
26607 This type is the stream type implemented I/O in the PIC18F devices.
26608  Also the standard input and output streams are declared in stdio.h:
26609 \end_layout
26610
26611 \begin_layout LyX-Code
26612 extern FILE * stdin;
26613 \end_layout
26614
26615 \begin_layout LyX-Code
26616 extern FILE * stdout;
26617 \end_layout
26618
26619 \begin_layout Standard
26620 The FILE type is actually a generic pointer which defines one more type
26621  of generic pointers, the 
26622 \emph on
26623 stream 
26624 \emph default
26625 pointer.
26626  This new type has the format:
26627 \end_layout
26628
26629 \begin_layout Standard
26630 \align center
26631 \begin_inset Tabular
26632 <lyxtabular version="3" rows="2" columns="7">
26633 <features>
26634 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26635 <column alignment="center" valignment="top" width="0">
26636 <column alignment="center" valignment="top" leftline="true" width="0">
26637 <column alignment="center" valignment="top" leftline="true" width="0">
26638 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26639 <column alignment="center" valignment="top" width="0">
26640 <column alignment="left" valignment="top" rightline="true" width="0">
26641 <row topline="true" bottomline="true">
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26643 \begin_inset Text
26644
26645 \begin_layout Standard
26646 pointer type
26647 \end_layout
26648
26649 \end_inset
26650 </cell>
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26652 \begin_inset Text
26653
26654 \begin_layout Standard
26655 <7:6>
26656 \end_layout
26657
26658 \end_inset
26659 </cell>
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26661 \begin_inset Text
26662
26663 \begin_layout Standard
26664 <5>
26665 \end_layout
26666
26667 \end_inset
26668 </cell>
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26670 \begin_inset Text
26671
26672 \begin_layout Standard
26673 <4>
26674 \end_layout
26675
26676 \end_inset
26677 </cell>
26678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_inset Text
26680
26681 \begin_layout Standard
26682 <3:0>
26683 \end_layout
26684
26685 \end_inset
26686 </cell>
26687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26688 \begin_inset Text
26689
26690 \begin_layout Standard
26691 rest of the pointer
26692 \end_layout
26693
26694 \end_inset
26695 </cell>
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26697 \begin_inset Text
26698
26699 \begin_layout Standard
26700 descrption
26701 \end_layout
26702
26703 \end_inset
26704 </cell>
26705 </row>
26706 <row topline="true" bottomline="true">
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26708 \begin_inset Text
26709
26710 \begin_layout Standard
26711 stream
26712 \end_layout
26713
26714 \end_inset
26715 </cell>
26716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26717 \begin_inset Text
26718
26719 \begin_layout Standard
26720 00
26721 \end_layout
26722
26723 \end_inset
26724 </cell>
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_inset Text
26727
26728 \begin_layout Standard
26729 1
26730 \end_layout
26731
26732 \end_inset
26733 </cell>
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26735 \begin_inset Text
26736
26737 \begin_layout Standard
26738 0
26739 \end_layout
26740
26741 \end_inset
26742 </cell>
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26744 \begin_inset Text
26745
26746 \begin_layout Standard
26747 nnnn
26748 \end_layout
26749
26750 \end_inset
26751 </cell>
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26753 \begin_inset Text
26754
26755 \begin_layout Standard
26756
26757 \family typewriter
26758 \shape slanted
26759 \emph on
26760 uuuuuuuu uuuuuuuu
26761 \end_layout
26762
26763 \end_inset
26764 </cell>
26765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26766 \begin_inset Text
26767
26768 \begin_layout Standard
26769 upper byte high nubble is 0x2n, the rest are zeroes
26770 \end_layout
26771
26772 \end_inset
26773 </cell>
26774 </row>
26775 </lyxtabular>
26776
26777 \end_inset
26778
26779
26780 \end_layout
26781
26782 \begin_layout Standard
26783 Currently implemented there are 3 types of streams defined:
26784 \end_layout
26785
26786 \begin_layout Standard
26787 \align center
26788 \begin_inset Tabular
26789 <lyxtabular version="3" rows="4" columns="4">
26790 <features>
26791 <column alignment="center" valignment="top" leftline="true" width="0">
26792 <column alignment="center" valignment="top" leftline="true" width="0">
26793 <column alignment="center" valignment="top" leftline="true" width="0">
26794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26795 <row topline="true" bottomline="true">
26796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26797 \begin_inset Text
26798
26799 \begin_layout Standard
26800 stream type
26801 \end_layout
26802
26803 \end_inset
26804 </cell>
26805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26806 \begin_inset Text
26807
26808 \begin_layout Standard
26809 value
26810 \end_layout
26811
26812 \end_inset
26813 </cell>
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26815 \begin_inset Text
26816
26817 \begin_layout Standard
26818 module
26819 \end_layout
26820
26821 \end_inset
26822 </cell>
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26824 \begin_inset Text
26825
26826 \begin_layout Standard
26827 description
26828 \end_layout
26829
26830 \end_inset
26831 </cell>
26832 </row>
26833 <row topline="true">
26834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26835 \begin_inset Text
26836
26837 \begin_layout Standard
26838 STREAM_USART
26839 \end_layout
26840
26841 \end_inset
26842 </cell>
26843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26844 \begin_inset Text
26845
26846 \begin_layout Standard
26847
26848 \family typewriter
26849 0x200000UL
26850 \end_layout
26851
26852 \end_inset
26853 </cell>
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26855 \begin_inset Text
26856
26857 \begin_layout Standard
26858 USART
26859 \end_layout
26860
26861 \end_inset
26862 </cell>
26863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26864 \begin_inset Text
26865
26866 \begin_layout Standard
26867 Writes/Reads characters via the USART peripheral
26868 \end_layout
26869
26870 \end_inset
26871 </cell>
26872 </row>
26873 <row topline="true">
26874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26875 \begin_inset Text
26876
26877 \begin_layout Standard
26878 STREAM_MSSP
26879 \end_layout
26880
26881 \end_inset
26882 </cell>
26883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26884 \begin_inset Text
26885
26886 \begin_layout Standard
26887
26888 \family typewriter
26889 0x210000UL
26890 \end_layout
26891
26892 \end_inset
26893 </cell>
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26895 \begin_inset Text
26896
26897 \begin_layout Standard
26898 MSSP
26899 \end_layout
26900
26901 \end_inset
26902 </cell>
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26904 \begin_inset Text
26905
26906 \begin_layout Standard
26907 Writes/Reads characters via the MSSP peripheral
26908 \end_layout
26909
26910 \end_inset
26911 </cell>
26912 </row>
26913 <row topline="true" bottomline="true">
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26915 \begin_inset Text
26916
26917 \begin_layout Standard
26918 STREAM_USER
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \begin_layout Standard
26927
26928 \family typewriter
26929 0x2f0000UL
26930 \end_layout
26931
26932 \end_inset
26933 </cell>
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26935 \begin_inset Text
26936
26937 \begin_layout Standard
26938 (none)
26939 \end_layout
26940
26941 \end_inset
26942 </cell>
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26944 \begin_inset Text
26945
26946 \begin_layout Standard
26947 Writes/Reads characters via used defined functions
26948 \end_layout
26949
26950 \end_inset
26951 </cell>
26952 </row>
26953 </lyxtabular>
26954
26955 \end_inset
26956
26957
26958 \end_layout
26959
26960 \begin_layout Standard
26961 The stream identifiers are declared as macros in the stdio.h header.
26962 \end_layout
26963
26964 \begin_layout Standard
26965 In the libc library there exist the functions that are used to write to
26966  each of the above streams.
26967  These are
26968 \end_layout
26969
26970 \begin_layout Description
26971 _
26972 \begin_inset ERT
26973 status collapsed
26974
26975 \begin_layout Standard
26976
26977
26978 \backslash
26979 /
26980 \end_layout
26981
26982 \end_inset
26983
26984 _stream_usart_putchar writes a character at the USART stream
26985 \end_layout
26986
26987 \begin_layout Description
26988 _
26989 \begin_inset ERT
26990 status collapsed
26991
26992 \begin_layout Standard
26993
26994
26995 \backslash
26996 /
26997 \end_layout
26998
26999 \end_inset
27000
27001 _stream_mssp_putchar writes a character at the MSSP stream
27002 \end_layout
27003
27004 \begin_layout Description
27005 putchar dummy function.
27006  This writes a character to a user specified manner.
27007 \end_layout
27008
27009 \begin_layout Standard
27010 In order to increase performance 
27011 \emph on
27012 putchar 
27013 \emph default
27014 is declared in stdio.h as having its parameter in WREG (it has the wparam
27015  keyword).
27016  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27017  in a user-friendly way.
27018  
27019 \emph on
27020 arg
27021 \emph default
27022  is the name of the variable that holds the character to print.
27023  An example follows:
27024 \end_layout
27025
27026 \begin_layout LyX-Code
27027 #include <pic18fregs.h>
27028 \newline
27029 #include <stdio.h>
27030 \newline
27031
27032 \newline
27033 PUTCHAR( c )
27034 \end_layout
27035
27036 \begin_layout LyX-Code
27037 {
27038 \end_layout
27039
27040 \begin_layout LyX-Code
27041     PORTA = c;    /* dump character c to PORTA */
27042 \end_layout
27043
27044 \begin_layout LyX-Code
27045
27046 \newline
27047
27048 \newline
27049 void main(void)
27050 \end_layout
27051
27052 \begin_layout LyX-Code
27053 {
27054 \end_layout
27055
27056 \begin_layout LyX-Code
27057     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27058 \end_layout
27059
27060 \begin_layout LyX-Code
27061                               * by default to STREAM_USER */
27062 \end_layout
27063
27064 \begin_layout LyX-Code
27065     printf (
27066 \begin_inset Quotes sld
27067 \end_inset
27068
27069 This is a printf test
27070 \backslash
27071 n
27072 \begin_inset Quotes srd
27073 \end_inset
27074
27075 );
27076 \end_layout
27077
27078 \begin_layout LyX-Code
27079 }
27080 \end_layout
27081
27082 \begin_layout LyX-Code
27083
27084 \end_layout
27085
27086 \begin_layout Subsubsection
27087 Printing functions
27088 \end_layout
27089
27090 \begin_layout Standard
27091 PIC16 contains an implementation of the printf-family of functions.
27092  There exist the following functions:
27093 \end_layout
27094
27095 \begin_layout LyX-Code
27096 extern unsigned int sprintf(char *buf, char *fmt, ...);
27097 \end_layout
27098
27099 \begin_layout LyX-Code
27100 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27101 \end_layout
27102
27103 \begin_layout LyX-Code
27104
27105 \end_layout
27106
27107 \begin_layout LyX-Code
27108 extern unsigned int printf(char *fmt, ...);
27109 \end_layout
27110
27111 \begin_layout LyX-Code
27112 extern unsigned int vprintf(char *fmt, va_lista ap);
27113 \end_layout
27114
27115 \begin_layout LyX-Code
27116
27117 \end_layout
27118
27119 \begin_layout LyX-Code
27120 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27121 \end_layout
27122
27123 \begin_layout LyX-Code
27124 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27125 \end_layout
27126
27127 \begin_layout Standard
27128 For sprintf and vsprintf 
27129 \emph on
27130 buf 
27131 \emph default
27132 should normally be a data pointer where the resulting string will be placed.
27133  No range checking is done so the user should allocate the necessery buffer.
27134  For fprintf and vfprintf 
27135 \emph on
27136 fp
27137 \emph default
27138  should be a stream pointer (i.e.
27139  stdout, STREAM_MSSP, etc...).
27140 \end_layout
27141
27142 \begin_layout Subsubsection
27143 Signals
27144 \end_layout
27145
27146 \begin_layout Standard
27147 The PIC18F family of microcontrollers supports a number of interrupt sources.
27148  A list of these interrupts is shown in the following table:
27149 \end_layout
27150
27151 \begin_layout Standard
27152 \align center
27153 \begin_inset Tabular
27154 <lyxtabular version="3" rows="11" columns="4">
27155 <features>
27156 <column alignment="left" valignment="top" leftline="true" width="0">
27157 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27158 <column alignment="left" valignment="top" leftline="true" width="0">
27159 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27160 <row topline="true" bottomline="true">
27161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27162 \begin_inset Text
27163
27164 \begin_layout Standard
27165 signal name
27166 \end_layout
27167
27168 \end_inset
27169 </cell>
27170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27171 \begin_inset Text
27172
27173 \begin_layout Standard
27174 description
27175 \end_layout
27176
27177 \end_inset
27178 </cell>
27179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27180 \begin_inset Text
27181
27182 \begin_layout Standard
27183 signal name
27184 \end_layout
27185
27186 \end_inset
27187 </cell>
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27189 \begin_inset Text
27190
27191 \begin_layout Standard
27192 descritpion
27193 \end_layout
27194
27195 \end_inset
27196 </cell>
27197 </row>
27198 <row topline="true">
27199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27200 \begin_inset Text
27201
27202 \begin_layout Standard
27203 SIG_RB
27204 \end_layout
27205
27206 \end_inset
27207 </cell>
27208 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27209 \begin_inset Text
27210
27211 \begin_layout Standard
27212 PORTB change interrupt
27213 \end_layout
27214
27215 \end_inset
27216 </cell>
27217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27218 \begin_inset Text
27219
27220 \begin_layout Standard
27221 SIG_EE
27222 \end_layout
27223
27224 \end_inset
27225 </cell>
27226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27227 \begin_inset Text
27228
27229 \begin_layout Standard
27230 EEPROM/FLASH write complete interrupt
27231 \end_layout
27232
27233 \end_inset
27234 </cell>
27235 </row>
27236 <row topline="true">
27237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27238 \begin_inset Text
27239
27240 \begin_layout Standard
27241 SIG_INT0
27242 \end_layout
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 \begin_layout Standard
27250 INT0 external interrupt
27251 \end_layout
27252
27253 \end_inset
27254 </cell>
27255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27256 \begin_inset Text
27257
27258 \begin_layout Standard
27259 SIG_BCOL
27260 \end_layout
27261
27262 \end_inset
27263 </cell>
27264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27265 \begin_inset Text
27266
27267 \begin_layout Standard
27268 Bus collision interrupt
27269 \end_layout
27270
27271 \end_inset
27272 </cell>
27273 </row>
27274 <row topline="true">
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27276 \begin_inset Text
27277
27278 \begin_layout Standard
27279 SIG_INT1
27280 \end_layout
27281
27282 \end_inset
27283 </cell>
27284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27285 \begin_inset Text
27286
27287 \begin_layout Standard
27288 INT1 external interrupt
27289 \end_layout
27290
27291 \end_inset
27292 </cell>
27293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27294 \begin_inset Text
27295
27296 \begin_layout Standard
27297 SIG_LVD
27298 \end_layout
27299
27300 \end_inset
27301 </cell>
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27303 \begin_inset Text
27304
27305 \begin_layout Standard
27306 Low voltage detect interrupt
27307 \end_layout
27308
27309 \end_inset
27310 </cell>
27311 </row>
27312 <row topline="true">
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27314 \begin_inset Text
27315
27316 \begin_layout Standard
27317 SIG_INT2
27318 \end_layout
27319
27320 \end_inset
27321 </cell>
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27323 \begin_inset Text
27324
27325 \begin_layout Standard
27326 INT2 external interrupt
27327 \end_layout
27328
27329 \end_inset
27330 </cell>
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27332 \begin_inset Text
27333
27334 \begin_layout Standard
27335 SIG_PSP
27336 \end_layout
27337
27338 \end_inset
27339 </cell>
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27341 \begin_inset Text
27342
27343 \begin_layout Standard
27344 Parallel slave port interrupt
27345 \end_layout
27346
27347 \end_inset
27348 </cell>
27349 </row>
27350 <row topline="true">
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27352 \begin_inset Text
27353
27354 \begin_layout Standard
27355 SIG_CCP1
27356 \end_layout
27357
27358 \end_inset
27359 </cell>
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27361 \begin_inset Text
27362
27363 \begin_layout Standard
27364 CCP1 module interrupt
27365 \end_layout
27366
27367 \end_inset
27368 </cell>
27369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27370 \begin_inset Text
27371
27372 \begin_layout Standard
27373 SIG_AD
27374 \end_layout
27375
27376 \end_inset
27377 </cell>
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27379 \begin_inset Text
27380
27381 \begin_layout Standard
27382 AD convertion complete interrupt
27383 \end_layout
27384
27385 \end_inset
27386 </cell>
27387 </row>
27388 <row topline="true">
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27390 \begin_inset Text
27391
27392 \begin_layout Standard
27393 SIG_CCP2
27394 \end_layout
27395
27396 \end_inset
27397 </cell>
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27399 \begin_inset Text
27400
27401 \begin_layout Standard
27402 CCP2 module interrupt
27403 \end_layout
27404
27405 \end_inset
27406 </cell>
27407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27408 \begin_inset Text
27409
27410 \begin_layout Standard
27411 SIG_RC
27412 \end_layout
27413
27414 \end_inset
27415 </cell>
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27417 \begin_inset Text
27418
27419 \begin_layout Standard
27420 USART receive interrupt
27421 \end_layout
27422
27423 \end_inset
27424 </cell>
27425 </row>
27426 <row topline="true">
27427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27428 \begin_inset Text
27429
27430 \begin_layout Standard
27431 SIG_TMR0
27432 \end_layout
27433
27434 \end_inset
27435 </cell>
27436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27437 \begin_inset Text
27438
27439 \begin_layout Standard
27440 TMR0 overflow interrupt
27441 \end_layout
27442
27443 \end_inset
27444 </cell>
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27446 \begin_inset Text
27447
27448 \begin_layout Standard
27449 SIG_TX
27450 \end_layout
27451
27452 \end_inset
27453 </cell>
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27455 \begin_inset Text
27456
27457 \begin_layout Standard
27458 USART transmit interrupt
27459 \end_layout
27460
27461 \end_inset
27462 </cell>
27463 </row>
27464 <row topline="true">
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27466 \begin_inset Text
27467
27468 \begin_layout Standard
27469 SIG_TMR1
27470 \end_layout
27471
27472 \end_inset
27473 </cell>
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27475 \begin_inset Text
27476
27477 \begin_layout Standard
27478 TMR1 overflow interrupt
27479 \end_layout
27480
27481 \end_inset
27482 </cell>
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27484 \begin_inset Text
27485
27486 \begin_layout Standard
27487 SIG_MSSP
27488 \end_layout
27489
27490 \end_inset
27491 </cell>
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27493 \begin_inset Text
27494
27495 \begin_layout Standard
27496 SSP receive/transmit interrupt
27497 \end_layout
27498
27499 \end_inset
27500 </cell>
27501 </row>
27502 <row topline="true">
27503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27504 \begin_inset Text
27505
27506 \begin_layout Standard
27507 SIG_TMR2
27508 \end_layout
27509
27510 \end_inset
27511 </cell>
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27513 \begin_inset Text
27514
27515 \begin_layout Standard
27516 TMR2 matches PR2 interrupt
27517 \end_layout
27518
27519 \end_inset
27520 </cell>
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27522 \begin_inset Text
27523
27524 \begin_layout Standard
27525
27526 \end_layout
27527
27528 \end_inset
27529 </cell>
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27531 \begin_inset Text
27532
27533 \begin_layout Standard
27534
27535 \end_layout
27536
27537 \end_inset
27538 </cell>
27539 </row>
27540 <row topline="true" bottomline="true">
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27542 \begin_inset Text
27543
27544 \begin_layout Standard
27545 SIG_TMR3
27546 \end_layout
27547
27548 \end_inset
27549 </cell>
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27551 \begin_inset Text
27552
27553 \begin_layout Standard
27554 TMR3 overflow interrupt
27555 \end_layout
27556
27557 \end_inset
27558 </cell>
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27560 \begin_inset Text
27561
27562 \begin_layout Standard
27563
27564 \end_layout
27565
27566 \end_inset
27567 </cell>
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27569 \begin_inset Text
27570
27571 \begin_layout Standard
27572
27573 \end_layout
27574
27575 \end_inset
27576 </cell>
27577 </row>
27578 </lyxtabular>
27579
27580 \end_inset
27581
27582
27583 \end_layout
27584
27585 \begin_layout Standard
27586 The prototypes for these names are defined in the header file 
27587 \emph on
27588 signal.h
27589 \emph default
27590  .
27591 \end_layout
27592
27593 \begin_layout Standard
27594 In order to simplify signal handling, a number of macros is provided:
27595 \end_layout
27596
27597 \begin_layout List
27598 \labelwidthstring 00.00.0000
27599 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27600  high priority interrupts.
27601  
27602 \emph on
27603 name
27604 \emph default
27605  is the function name to use.
27606 \end_layout
27607
27608 \begin_layout List
27609 \labelwidthstring 00.00.0000
27610 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27611  low priority interrupt.
27612  
27613 \emph on
27614 name
27615 \emph default
27616  is the function name to use.
27617 \end_layout
27618
27619 \begin_layout List
27620 \labelwidthstring 00.00.0000
27621 DEF_HANDLER(sig,handler) define a handler for signal 
27622 \emph on
27623 sig.
27624 \end_layout
27625
27626 \begin_layout List
27627 \labelwidthstring 00.00.0000
27628 END_DEF end the declaration of the dispatch table.
27629 \end_layout
27630
27631 \begin_layout Standard
27632 Additionally there are two more macros to simplify the declaration of the
27633  signal handler:
27634 \end_layout
27635
27636 \begin_layout List
27637 \labelwidthstring 00.00.0000
27638
27639 \series medium
27640 SIGHANDLER(handler) 
27641 \series default
27642 this declares the function prototype for the 
27643 \emph on
27644 handler
27645 \emph default
27646  function.
27647 \end_layout
27648
27649 \begin_layout List
27650 \labelwidthstring 00.00.0000
27651 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27652 \end_layout
27653
27654 \begin_layout Standard
27655 An example of using the macros above is shown below:
27656 \end_layout
27657
27658 \begin_layout LyX-Code
27659 #include <pic18fregs.h>
27660 \end_layout
27661
27662 \begin_layout LyX-Code
27663 #include <signal.h>
27664 \newline
27665
27666 \newline
27667 DEF_INTHIGH(high_int)
27668 \end_layout
27669
27670 \begin_layout LyX-Code
27671 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27672 \end_layout
27673
27674 \begin_layout LyX-Code
27675 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27676 \end_layout
27677
27678 \begin_layout LyX-Code
27679 END_DEF
27680 \newline
27681
27682 \newline
27683 SIGHANDLER(_tmr0_handler)
27684 \end_layout
27685
27686 \begin_layout LyX-Code
27687 {
27688 \end_layout
27689
27690 \begin_layout LyX-Code
27691   /* action to be taken when timer 0 overflows */
27692 \end_layout
27693
27694 \begin_layout LyX-Code
27695 }
27696 \newline
27697
27698 \newline
27699 SIGHANDLERNAKED(_bcol_handler)
27700 \end_layout
27701
27702 \begin_layout LyX-Code
27703 {
27704 \end_layout
27705
27706 \begin_layout LyX-Code
27707   _asm
27708 \end_layout
27709
27710 \begin_layout LyX-Code
27711     /* action to be taken when bus collision occurs */
27712 \end_layout
27713
27714 \begin_layout LyX-Code
27715     retfie
27716 \end_layout
27717
27718 \begin_layout LyX-Code
27719  _endasm;
27720 \end_layout
27721
27722 \begin_layout LyX-Code
27723 }
27724 \end_layout
27725
27726 \begin_layout Standard
27727
27728 \series bold
27729 NOTES:
27730 \series default
27731  Special care should be taken when using the above scheme:
27732 \end_layout
27733
27734 \begin_layout Itemize
27735 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27736 \end_layout
27737
27738 \begin_layout Itemize
27739 when declaring SIGHANDLERNAKED handler never forget to use 
27740 \emph on
27741 retfie
27742 \emph default
27743  for proper returning.
27744 \end_layout
27745
27746 \begin_layout Subsection
27747 PIC16 Port -- Tips
27748 \end_layout
27749
27750 \begin_layout Standard
27751 Here you can find some general tips for compiling programs with SDCC/pic16.
27752 \end_layout
27753
27754 \begin_layout Subsubsection
27755 Stack size
27756 \end_layout
27757
27758 \begin_layout Standard
27759 The default stack
27760 \begin_inset LatexCommand \index{PIC16!stack}
27761
27762 \end_inset
27763
27764  size (that is 64 bytes) probably is enough for many programs.
27765  One must take care that when there are many levels of function nesting,
27766  or there is excessive usage of stack, its size should be extended.
27767  An example of such a case is the printf/sprintf family of functions.
27768  If you encounter problems like not being able to print integers, then you
27769  need to set the stack size around the maximum (256 for small stack model).
27770  The following diagram shows what happens when calling printf to print an
27771  integer:
27772 \end_layout
27773
27774 \begin_layout LyX-Code
27775 printf () --> ltoa () --> ultoa () --> divschar ()
27776 \end_layout
27777
27778 \begin_layout Standard
27779 It is should be understood that stack is easily consumed when calling complicate
27780 d functions.
27781  Using command line arguments like -
27782 \begin_inset ERT
27783 status collapsed
27784
27785 \begin_layout Standard
27786
27787
27788 \backslash
27789 /
27790 \end_layout
27791
27792 \end_inset
27793
27794 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27795  stack frames.
27796  Other ways to reduce stack usage may exist.
27797 \end_layout
27798
27799 \begin_layout Subsection
27800 Known Bugs
27801 \end_layout
27802
27803 \begin_layout Standard
27804 The PIC16 Port currently does not pass SDCC's regression test
27805 \begin_inset LatexCommand \index{Regression test (PIC16)}
27806
27807 \end_inset
27808
27809  suite (see section 
27810 \begin_inset LatexCommand \ref{sec:Quality-control}
27811
27812 \end_inset
27813
27814 ) and thus the snapshot build regression tests for the PIC16 target are
27815  currently disabled for all hosts
27816 \emph on
27817 .
27818 \end_layout
27819
27820 \begin_layout Chapter
27821 Debugging
27822 \end_layout
27823
27824 \begin_layout Standard
27825 There are several approaches to debugging your code.
27826  This chapter is meant to show your options and to give detail on some of
27827  them:
27828 \newline
27829
27830 \newline
27831 When writing your code:
27832 \end_layout
27833
27834 \begin_layout Itemize
27835 write your code with debugging in mind (avoid duplicating code, put conceptually
27836  similar variables into structs, use structured code, have strategic points
27837  within your code where all variables are consistent, ...)
27838 \end_layout
27839
27840 \begin_layout Itemize
27841 run a syntax-checking tool like splint
27842 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27843
27844 \end_inset
27845
27846
27847 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27848
27849 \end_inset
27850
27851  (see -
27852 \begin_inset ERT
27853 status collapsed
27854
27855 \begin_layout Standard
27856
27857
27858 \backslash
27859 /
27860 \end_layout
27861
27862 \end_inset
27863
27864 -more-pedantic 
27865 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27866
27867 \end_inset
27868
27869 ) over the code.
27870 \end_layout
27871
27872 \begin_layout Itemize
27873 for the high level code use a C-compiler (like f.e.
27874  GCC) to compile run and debug the code on your host.
27875  See (see -
27876 \begin_inset ERT
27877 status collapsed
27878
27879 \begin_layout Standard
27880
27881
27882 \backslash
27883 /
27884 \end_layout
27885
27886 \end_inset
27887
27888 -more-pedantic 
27889 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27890
27891 \end_inset
27892
27893 ) on how to handle syntax extensions like __xdata, __at(), ...
27894  
27895 \end_layout
27896
27897 \begin_layout Itemize
27898 use another C-compiler to compile code for your target.
27899  Always an option but not recommended:) And not very likely to help you.
27900  If you seriously consider walking this path you should at least occasionally
27901  check portability of your code.
27902  Most commercial compiler vendors will offer an evaluation version so you
27903  can test compile your code or snippets of your code.
27904 \end_layout
27905
27906 \begin_layout Standard
27907 Debugging on a simulator:
27908 \end_layout
27909
27910 \begin_layout Itemize
27911 there is a separate section about SDCDB (section 
27912 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27913
27914 \end_inset
27915
27916 ) below.
27917 \end_layout
27918
27919 \begin_layout Itemize
27920 or (8051 specific) use a freeware/commercial simulator which interfaces
27921  to the AOMF
27922 \begin_inset LatexCommand \index{AOMF, AOMF51}
27923
27924 \end_inset
27925
27926  file (see 
27927 \begin_inset LatexCommand \ref{OMF file}
27928
27929 \end_inset
27930
27931 ) optionally generated by SDCC.
27932 \end_layout
27933
27934 \begin_layout Standard
27935 Debugging On-target: 
27936 \end_layout
27937
27938 \begin_layout Itemize
27939 use a MCU port pin to serially output debug data to the RS232 port of your
27940  host.
27941  You'll probably want some level shifting device typically involving a MAX232
27942  or similar IC.
27943  If the hardware serial port of the MCU is not available search for 'Software
27944  UART' in your favourite search machine.
27945 \end_layout
27946
27947 \begin_layout Itemize
27948 use an on-target monitor.
27949  In this context a monitor is a small program which usually accepts commands
27950  via a serial line and allows to set program counter, to single step through
27951  a program and read/write memory locations.
27952  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27953  
27954 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27955
27956 \end_inset
27957
27958 ).
27959 \end_layout
27960
27961 \begin_layout Itemize
27962 toggle MCU port pins at strategic points within your code and use an oscilloscop
27963 e.
27964  A 
27965 \emph on
27966 digital oscilloscope
27967 \emph default
27968
27969 \begin_inset LatexCommand \index{Oscilloscope}
27970
27971 \end_inset
27972
27973  with deep trace memory is really helpful especially if you have to debug
27974  a realtime application.
27975  If you need to monitor more pins than your oscilloscope provides you can
27976  sometimes get away with a small R-2R network.
27977  On a single channel oscilloscope you could f.e.
27978  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27979 k
27980 \begin_inset Formula $\Omega$
27981 \end_inset
27982
27983  resistor and the other one by a 5\InsetSpace ~
27984 k
27985 \begin_inset Formula $\Omega$
27986 \end_inset
27987
27988  resistor to the oscilloscope probe (check output drive capability of the
27989  pins you want to monitor).
27990  If you need to monitor many more pins a 
27991 \emph on
27992 logic analyzer
27993 \emph default
27994  will be handy.
27995 \end_layout
27996
27997 \begin_layout Itemize
27998 use an ICE (
27999 \emph on
28000 i
28001 \emph default
28002
28003 \emph on
28004 c
28005 \emph default
28006 ircuit 
28007 \emph on
28008 e
28009 \emph default
28010 mulator
28011 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28012
28013 \end_inset
28014
28015 ).
28016  Usually very expensive.
28017  And very nice to have too.
28018  And usually locks you (for years...) to the devices the ICE can emulate.
28019  
28020 \end_layout
28021
28022 \begin_layout Itemize
28023 use a remote debugger.
28024  In most 8-bit systems the symbol information is not available on the target,
28025  and a complete debugger is too bulky for the target system.
28026  Therefore usually a debugger on the host system connects to an on-target
28027  debugging stub which accepts only primitive commands.
28028  
28029 \newline
28030 Terms to enter into your favourite search engine could be 'remote debugging',
28031  'gdb stub' or 'inferior debugger'.
28032  (is there one?)
28033 \end_layout
28034
28035 \begin_layout Itemize
28036 use an on target hardware debugger.
28037  Some of the more modern MCUs include hardware support for setting break
28038  points and monitoring/changing variables by using dedicated hardware pins.
28039  This facility doesn't require additional code to run on the target and
28040  
28041 \emph on
28042 usually
28043 \emph default
28044  doesn't affect runtime behaviour until a breakpoint is hit.
28045  For the mcs51 most hardware debuggers use the AOMF
28046 \begin_inset LatexCommand \index{AOMF, AOMF51}
28047
28048 \end_inset
28049
28050  file (see 
28051 \begin_inset LatexCommand \ref{OMF file}
28052
28053 \end_inset
28054
28055 ) as input file.
28056  
28057 \end_layout
28058
28059 \begin_layout Standard
28060 Last not least:
28061 \end_layout
28062
28063 \begin_layout Itemize
28064 if you are not familiar with any of the following terms you're likely to
28065  run into problems rather sooner than later: 
28066 \emph on
28067 volatile
28068 \emph default
28069
28070 \emph on
28071 atomic
28072 \emph default
28073
28074 \emph on
28075 memory map
28076 \emph default
28077
28078 \emph on
28079 overlay
28080 \emph default
28081 .
28082  As an embedded programmer you 
28083 \emph on
28084 have
28085 \emph default
28086  to know them so why not look them up 
28087 \emph on
28088 before
28089 \emph default
28090  you have problems?)
28091 \end_layout
28092
28093 \begin_layout Itemize
28094 tell someone else about your problem (actually this is a surprisingly effective
28095  means to hunt down the bug even if the listener is not familiar with your
28096  environment).
28097  As 'failure to communicate' is probably one of the job-induced deformations
28098  of an embedded programmer this is highly encouraged.
28099 \end_layout
28100
28101 \begin_layout Section
28102 Debugging with SDCDB
28103 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28104
28105 \end_inset
28106
28107
28108 \begin_inset LatexCommand \index{SDCDB (debugger)}
28109
28110 \end_inset
28111
28112  
28113 \end_layout
28114
28115 \begin_layout Standard
28116 SDCC is distributed with a source level debugger
28117 \begin_inset LatexCommand \index{Debugger}
28118
28119 \end_inset
28120
28121 .
28122  The debugger uses a command line interface, the command repertoire of the
28123  debugger has been kept as close to gdb
28124 \begin_inset LatexCommand \index{gdb}
28125
28126 \end_inset
28127
28128  (the GNU debugger) as possible.
28129  The configuration and build process is part of the standard compiler installati
28130 on, which also builds and installs the debugger in the target directory
28131  specified during configuration.
28132  The debugger allows you debug BOTH at the C source and at the ASM source
28133  level.
28134 \end_layout
28135
28136 \begin_layout Subsection
28137 Compiling for Debugging
28138 \end_layout
28139
28140 \begin_layout Standard
28141 The -
28142 \begin_inset ERT
28143 status collapsed
28144
28145 \begin_layout Standard
28146
28147
28148 \backslash
28149 /
28150 \end_layout
28151
28152 \end_inset
28153
28154 -debug
28155 \begin_inset LatexCommand \index{-\/-debug}
28156
28157 \end_inset
28158
28159  option must be specified for all files for which debug information is to
28160  be generated.
28161  The compiler generates a .adb file for each of these files.
28162  The linker creates the .cdb
28163 \begin_inset LatexCommand \index{<file>.cdb}
28164
28165 \end_inset
28166
28167  file from the .adb
28168 \begin_inset LatexCommand \index{<file>.adb}
28169
28170 \end_inset
28171
28172  files and the address information.
28173  This .cdb is used by the debugger.
28174 \end_layout
28175
28176 \begin_layout Subsection
28177 How the Debugger Works
28178 \end_layout
28179
28180 \begin_layout Standard
28181 When the -
28182 \begin_inset ERT
28183 status collapsed
28184
28185 \begin_layout Standard
28186
28187
28188 \backslash
28189 /
28190 \end_layout
28191
28192 \end_inset
28193
28194 -debug option is specified the compiler generates extra symbol information
28195  some of which are put into the assembler source and some are put into the
28196  .adb file.
28197  Then the linker creates the .cdb file from the individual .adb files with
28198  the address information for the symbols.
28199  The debugger reads the symbolic information generated by the compiler &
28200  the address information generated by the linker.
28201  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28202  execution is controlled by the debugger.
28203  When a command is issued for the debugger, it translates it into appropriate
28204  commands for the simulator.
28205  (Currently SDCDM only connects to the simulator but 
28206 \emph on
28207 newcdb
28208 \emph default
28209  at 
28210 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28211
28212 \end_inset
28213
28214  is an effort to connect directly to the hardware.) 
28215 \end_layout
28216
28217 \begin_layout Subsection
28218 Starting the Debugger SDCDB
28219 \end_layout
28220
28221 \begin_layout Standard
28222 The debugger can be started using the following command line.
28223  (Assume the file you are debugging has the file name foo).
28224 \newline
28225
28226 \newline
28227
28228 \family sans
28229 \series bold
28230 sdcdb foo
28231 \newline
28232
28233 \family default
28234 \series default
28235
28236 \newline
28237 The debugger will look for the following files.
28238 \end_layout
28239
28240 \begin_layout Itemize
28241 foo.c - the source file.
28242 \end_layout
28243
28244 \begin_layout Itemize
28245 foo.cdb - the debugger symbol information file.
28246 \end_layout
28247
28248 \begin_layout Itemize
28249 foo.ihx - the Intel hex format
28250 \begin_inset LatexCommand \index{Intel hex format}
28251
28252 \end_inset
28253
28254  object file.
28255 \end_layout
28256
28257 \begin_layout Subsection
28258 SDCDB Command Line Options
28259 \end_layout
28260
28261 \begin_layout Itemize
28262 -
28263 \begin_inset ERT
28264 status collapsed
28265
28266 \begin_layout Standard
28267
28268
28269 \backslash
28270 /
28271 \end_layout
28272
28273 \end_inset
28274
28275 -directory=<source file directory> this option can used to specify the directory
28276  search list.
28277  The debugger will look into the directory list specified for source, cdb
28278  & ihx files.
28279  The items in the directory list must be separated by ':', e.g.
28280  if the source files can be in the directories /home/src1 and /home/src2,
28281  the -
28282 \begin_inset ERT
28283 status collapsed
28284
28285 \begin_layout Standard
28286
28287
28288 \backslash
28289 /
28290 \end_layout
28291
28292 \end_inset
28293
28294 -directory option should be -
28295 \begin_inset ERT
28296 status collapsed
28297
28298 \begin_layout Standard
28299
28300
28301 \backslash
28302 /
28303 \end_layout
28304
28305 \end_inset
28306
28307 -directory=/home/src1:/home/src2.
28308  Note there can be no spaces in the option.
28309  
28310 \end_layout
28311
28312 \begin_layout Itemize
28313 -cd <directory> - change to the <directory>.
28314 \end_layout
28315
28316 \begin_layout Itemize
28317 -fullname - used by GUI front ends.
28318 \end_layout
28319
28320 \begin_layout Itemize
28321 -cpu <cpu-type> - this argument is passed to the simulator please see the
28322  simulator docs for details.
28323 \end_layout
28324
28325 \begin_layout Itemize
28326 -X <Clock frequency > this options is passed to the simulator please see
28327  the simulator docs for details.
28328 \end_layout
28329
28330 \begin_layout Itemize
28331 -s <serial port file> passed to simulator see the simulator docs for details.
28332 \end_layout
28333
28334 \begin_layout Itemize
28335 -S <serial in,out> passed to simulator see the simulator docs for details.
28336 \end_layout
28337
28338 \begin_layout Itemize
28339 -k <port number> passed to simulator see the simulator docs for details.
28340 \end_layout
28341
28342 \begin_layout Subsection
28343 SDCDB Debugger Commands
28344 \end_layout
28345
28346 \begin_layout Standard
28347 As mentioned earlier the command interface for the debugger has been deliberatel
28348 y kept as close the GNU debugger gdb, as possible.
28349  This will help the integration with existing graphical user interfaces
28350  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28351  If you use a graphical user interface for the debugger you can skip this
28352  section.
28353 \end_layout
28354
28355 \begin_layout Subsubsection*
28356 break [line | file:line | function | file:function]
28357 \end_layout
28358
28359 \begin_layout Standard
28360 Set breakpoint at specified line or function:
28361 \newline
28362
28363 \newline
28364
28365 \family sans
28366 \series bold
28367 sdcdb>break 100 
28368 \newline
28369 sdcdb>break foo.c:100
28370 \newline
28371 sdcdb>break funcfoo
28372 \newline
28373 sdcdb>break foo.c:funcfoo
28374 \end_layout
28375
28376 \begin_layout Subsubsection*
28377 clear [line | file:line | function | file:function ]
28378 \end_layout
28379
28380 \begin_layout Standard
28381 Clear breakpoint at specified line or function:
28382 \newline
28383
28384 \newline
28385
28386 \family sans
28387 \series bold
28388 sdcdb>clear 100
28389 \newline
28390 sdcdb>clear foo.c:100
28391 \newline
28392 sdcdb>clear funcfoo
28393 \newline
28394 sdcdb>clear foo.c:funcfoo
28395 \end_layout
28396
28397 \begin_layout Subsubsection*
28398 continue
28399 \end_layout
28400
28401 \begin_layout Standard
28402 Continue program being debugged, after breakpoint.
28403 \end_layout
28404
28405 \begin_layout Subsubsection*
28406 finish
28407 \end_layout
28408
28409 \begin_layout Standard
28410 Execute till the end of the current function.
28411 \end_layout
28412
28413 \begin_layout Subsubsection*
28414 delete [n]
28415 \end_layout
28416
28417 \begin_layout Standard
28418 Delete breakpoint number 'n'.
28419  If used without any option clear ALL user defined break points.
28420 \end_layout
28421
28422 \begin_layout Subsubsection*
28423 info [break | stack | frame | registers ]
28424 \end_layout
28425
28426 \begin_layout Itemize
28427 info break - list all breakpoints
28428 \end_layout
28429
28430 \begin_layout Itemize
28431 info stack - show the function call stack.
28432 \end_layout
28433
28434 \begin_layout Itemize
28435 info frame - show information about the current execution frame.
28436 \end_layout
28437
28438 \begin_layout Itemize
28439 info registers - show content of all registers.
28440 \end_layout
28441
28442 \begin_layout Subsubsection*
28443 step
28444 \end_layout
28445
28446 \begin_layout Standard
28447 Step program until it reaches a different source line.
28448  Note: pressing <return> repeats the last command.
28449 \end_layout
28450
28451 \begin_layout Subsubsection*
28452 next
28453 \end_layout
28454
28455 \begin_layout Standard
28456 Step program, proceeding through subroutine calls.
28457 \end_layout
28458
28459 \begin_layout Subsubsection*
28460 run
28461 \end_layout
28462
28463 \begin_layout Standard
28464 Start debugged program.
28465 \end_layout
28466
28467 \begin_layout Subsubsection*
28468 ptype variable 
28469 \end_layout
28470
28471 \begin_layout Standard
28472 Print type information of the variable.
28473 \end_layout
28474
28475 \begin_layout Subsubsection*
28476 print variable
28477 \end_layout
28478
28479 \begin_layout Standard
28480 print value of variable.
28481 \end_layout
28482
28483 \begin_layout Subsubsection*
28484 file filename
28485 \end_layout
28486
28487 \begin_layout Standard
28488 load the given file name.
28489  Note this is an alternate method of loading file for debugging.
28490 \end_layout
28491
28492 \begin_layout Subsubsection*
28493 frame
28494 \end_layout
28495
28496 \begin_layout Standard
28497 print information about current frame.
28498 \end_layout
28499
28500 \begin_layout Subsubsection*
28501 set srcmode
28502 \end_layout
28503
28504 \begin_layout Standard
28505 Toggle between C source & assembly source.
28506 \end_layout
28507
28508 \begin_layout Subsubsection*
28509 ! simulator command
28510 \end_layout
28511
28512 \begin_layout Standard
28513 Send the string following '!' to the simulator, the simulator response is
28514  displayed.
28515  Note the debugger does not interpret the command being sent to the simulator,
28516  so if a command like 'go' is sent the debugger can loose its execution
28517  context and may display incorrect values.
28518 \end_layout
28519
28520 \begin_layout Subsubsection*
28521 quit
28522 \end_layout
28523
28524 \begin_layout Standard
28525 "Watch me now.
28526  Iam going Down.
28527  My name is Bobby Brown"
28528 \end_layout
28529
28530 \begin_layout Subsection
28531 Interfacing SDCDB with DDD
28532 \end_layout
28533
28534 \begin_layout Standard
28535 \begin_inset Note Note
28536 status collapsed
28537
28538 \begin_layout Standard
28539 The screenshot was converted from png to eps with: 
28540 \begin_inset Quotes sld
28541 \end_inset
28542
28543 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28544 \begin_inset Quotes srd
28545 \end_inset
28546
28547  which produces a pretty compact eps file which is free from compression
28548  artifacts.
28549 \end_layout
28550
28551 \begin_layout Standard
28552 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28553  as this broke the build system on Sourceforge (pdf-file was broken.
28554  pdflatex does not accept eps files).
28555 \end_layout
28556
28557 \end_inset
28558
28559
28560 \end_layout
28561
28562 \begin_layout Standard
28563 The 
28564 \emph on
28565 p
28566 \emph default
28567 ortable 
28568 \emph on
28569 n
28570 \emph default
28571 etwork 
28572 \emph on
28573 g
28574 \emph default
28575 raphics File 
28576 \size footnotesize
28577
28578 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28579
28580 \end_inset
28581
28582
28583 \size default
28584  shows a screenshot of a debugging session with DDD
28585 \begin_inset LatexCommand \index{DDD (debugger)}
28586
28587 \end_inset
28588
28589  (Unix only) on a simulated 8032.
28590  The debugging session might not run as smoothly as the screenshot suggests.
28591  The debugger allows setting of breakpoints, displaying and changing variables,
28592  single stepping through C and assembler code.
28593  
28594 \newline
28595 The source was compiled with 
28596 \family sans
28597 \series bold
28598
28599 \newline
28600
28601 \newline
28602 sdcc -
28603 \family default
28604 \series default
28605
28606 \begin_inset ERT
28607 status collapsed
28608
28609 \begin_layout Standard
28610
28611
28612 \backslash
28613 /
28614 \end_layout
28615
28616 \end_inset
28617
28618
28619 \family sans
28620 \series bold
28621 -debug ddd_example.c
28622 \family default
28623 \series default
28624  
28625 \family sans
28626 \series bold
28627
28628 \newline
28629
28630 \family default
28631 \series default
28632
28633 \newline
28634 and DDD was invoked with 
28635 \family sans
28636 \series bold
28637
28638 \newline
28639
28640 \newline
28641 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28642 \end_layout
28643
28644 \begin_layout Standard
28645 \begin_inset Note Note
28646 status open
28647
28648 \begin_layout Standard
28649 Check that the double quotes or an apostroph within the command line survive
28650  the LyX tool chain.
28651  Previously the apostrophs got slanted in the PDF output so a cut and paste
28652  did not work.
28653 \end_layout
28654
28655 \end_inset
28656
28657
28658 \end_layout
28659
28660 \begin_layout Subsection
28661 Interfacing SDCDB with XEmacs
28662 \begin_inset LatexCommand \index{XEmacs}
28663
28664 \end_inset
28665
28666
28667 \begin_inset LatexCommand \index{Emacs}
28668
28669 \end_inset
28670
28671
28672 \end_layout
28673
28674 \begin_layout Standard
28675 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28676  sdcdb.el and sdcdbsrc.el.
28677  These two files can be found in the $(prefix)/bin directory after the installat
28678 ion is complete.
28679  These files need to be loaded into XEmacs for the interface to work.
28680  This can be done at XEmacs startup time by inserting the following into
28681  your '.xemacs' file (which can be found in your HOME directory): 
28682 \newline
28683
28684 \newline
28685
28686 \family typewriter
28687 (load-file sdcdbsrc.el) 
28688 \family default
28689
28690 \newline
28691
28692 \newline
28693 .xemacs is a lisp file so the () around the command is REQUIRED.
28694  The files can also be loaded dynamically while XEmacs is running, set the
28695  environment variable 'EMACSLOADPATH' to the installation bin directory
28696  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28697  To start the interface enter the following command: 
28698 \newline
28699
28700 \newline
28701
28702 \family sans
28703 \series bold
28704 ESC-x sdcdbsrc
28705 \family default
28706 \series default
28707
28708 \newline
28709
28710 \newline
28711 You will prompted to enter the file name to be debugged.
28712  
28713 \newline
28714
28715 \newline
28716 The command line options that are passed to the simulator directly are
28717  bound to default values in the file sdcdbsrc.el.
28718  The variables are listed below, these values maybe changed as required.
28719 \end_layout
28720
28721 \begin_layout Itemize
28722 sdcdbsrc-cpu-type '51
28723 \end_layout
28724
28725 \begin_layout Itemize
28726 sdcdbsrc-frequency '11059200
28727 \end_layout
28728
28729 \begin_layout Itemize
28730 sdcdbsrc-serial nil
28731 \end_layout
28732
28733 \begin_layout Standard
28734 The following is a list of key mapping for the debugger interface.
28735 \end_layout
28736
28737 \begin_layout Standard
28738 \InsetSpace ~
28739
28740 \family typewriter
28741
28742 \newline
28743 ;;\InsetSpace ~
28744 Current Listing :: 
28745 \newline
28746 ;;key\InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 binding\InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 \InsetSpace ~
28782 Comment 
28783 \newline
28784 ;;---\InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 \InsetSpace ~
28794 \InsetSpace ~
28795 \InsetSpace ~
28796 \InsetSpace ~
28797 \InsetSpace ~
28798 -------\InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 -------
28821 \newline
28822 ;; 
28823 \newline
28824 ;;\InsetSpace ~
28825 n\InsetSpace ~
28826 \InsetSpace ~
28827 \InsetSpace ~
28828 \InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 sdcdb-next-fro
28841 m-src\InsetSpace ~
28842 \InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 SDCDB next command 
28852 \newline
28853 ;;\InsetSpace ~
28854 b\InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 sdcdb-back-from-src\InsetSpace ~
28870 \InsetSpace ~
28871 \InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 \InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 SDCDB back command 
28880 \newline
28881 ;;\InsetSpace ~
28882 c\InsetSpace ~
28883 \InsetSpace ~
28884 \InsetSpace ~
28885 \InsetSpace ~
28886 \InsetSpace ~
28887 \InsetSpace ~
28888 \InsetSpace ~
28889 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 sdcdb-cont-f
28898 rom-src\InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 SDCDB continue command
28909 \newline
28910 ;;\InsetSpace ~
28911 s\InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 sdcdb-step-from-src\InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 SDCDB step command 
28937 \newline
28938 ;;\InsetSpace ~
28939 ?\InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 \InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 sdcdb-w
28955 hatis-c-sexp\InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 \InsetSpace ~
28964 \InsetSpace ~
28965 SDCDB ptypecommand for data at 
28966 \newline
28967 ;;\InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 \InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 \InsetSpace ~
28987 \InsetSpace ~
28988 \InsetSpace ~
28989 \InsetSpace ~
28990 \InsetSpace ~
28991 \InsetSpace ~
28992 \InsetSpace ~
28993 \InsetSpace ~
28994 \InsetSpace ~
28995 \InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
29007 \InsetSpace ~
29008 \InsetSpace ~
29009 \InsetSpace ~
29010 \InsetSpace ~
29011 \InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 buffer point 
29015 \newline
29016 ;;\InsetSpace ~
29017 x\InsetSpace ~
29018 \InsetSpace ~
29019 \InsetSpace ~
29020 \InsetSpace ~
29021 \InsetSpace ~
29022 \InsetSpace ~
29023 \InsetSpace ~
29024 \InsetSpace ~
29025 \InsetSpace ~
29026 \InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 sdcdbsrc-delete\InsetSpace ~
29033 \InsetSpace ~
29034 \InsetSpace ~
29035 \InsetSpace ~
29036 \InsetSpace ~
29037 \InsetSpace ~
29038 \InsetSpace ~
29039 \InsetSpace ~
29040 \InsetSpace ~
29041 \InsetSpace ~
29042 \InsetSpace ~
29043 \InsetSpace ~
29044 \InsetSpace ~
29045 \InsetSpace ~
29046 SDCD
29047 B Delete all breakpoints if no arg 
29048 \newline
29049 ;;\InsetSpace ~
29050 \InsetSpace ~
29051 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 \InsetSpace ~
29055 \InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 \InsetSpace ~
29066 \InsetSpace ~
29067 \InsetSpace ~
29068 \InsetSpace ~
29069 \InsetSpace ~
29070 \InsetSpace ~
29071 \InsetSpace ~
29072 \InsetSpace ~
29073 \InsetSpace ~
29074 \InsetSpace ~
29075 \InsetSpace ~
29076 \InsetSpace ~
29077 \InsetSpace ~
29078 \InsetSpace ~
29079 \InsetSpace ~
29080 \InsetSpace ~
29081 \InsetSpace ~
29082 \InsetSpace ~
29083 \InsetSpace ~
29084 \InsetSpace ~
29085 \InsetSpace ~
29086 \InsetSpace ~
29087 \InsetSpace ~
29088 \InsetSpace ~
29089 \InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 \InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 given or delete arg (C-u arg x) 
29097 \newline
29098 ;;\InsetSpace ~
29099 m\InsetSpace ~
29100 \InsetSpace ~
29101 \InsetSpace ~
29102 \InsetSpace ~
29103 \InsetSpace ~
29104 \InsetSpace ~
29105 \InsetSpace ~
29106 \InsetSpace ~
29107 \InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 \InsetSpace ~
29112 \InsetSpace ~
29113 \InsetSpace ~
29114 sdcdbsrc
29115 -frame\InsetSpace ~
29116 \InsetSpace ~
29117 \InsetSpace ~
29118 \InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 \InsetSpace ~
29122 \InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 SDCDB Display current frame if no arg, 
29131 \newline
29132 ;;\InsetSpace ~
29133 \InsetSpace ~
29134 \InsetSpace ~
29135 \InsetSpace ~
29136 \InsetSpace ~
29137 \InsetSpace ~
29138 \InsetSpace ~
29139 \InsetSpace ~
29140 \InsetSpace ~
29141 \InsetSpace ~
29142 \InsetSpace ~
29143 \InsetSpace ~
29144 \InsetSpace ~
29145 \InsetSpace ~
29146 \InsetSpace ~
29147 \InsetSpace ~
29148 \InsetSpace ~
29149 \InsetSpace ~
29150 \InsetSpace ~
29151 \InsetSpace ~
29152 \InsetSpace ~
29153 \InsetSpace ~
29154 \InsetSpace ~
29155 \InsetSpace ~
29156 \InsetSpace ~
29157 \InsetSpace ~
29158 \InsetSpace ~
29159 \InsetSpace ~
29160 \InsetSpace ~
29161 \InsetSpace ~
29162 \InsetSpace ~
29163 \InsetSpace ~
29164 \InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 \InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 \InsetSpace ~
29173 \InsetSpace ~
29174 \InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 \InsetSpace ~
29178 \InsetSpace ~
29179 given or display frame arg
29180  
29181 \newline
29182 ;;\InsetSpace ~
29183 \InsetSpace ~
29184 \InsetSpace ~
29185 \InsetSpace ~
29186 \InsetSpace ~
29187 \InsetSpace ~
29188 \InsetSpace ~
29189 \InsetSpace ~
29190 \InsetSpace ~
29191 \InsetSpace ~
29192 \InsetSpace ~
29193 \InsetSpace ~
29194 \InsetSpace ~
29195 \InsetSpace ~
29196 \InsetSpace ~
29197 \InsetSpace ~
29198 \InsetSpace ~
29199 \InsetSpace ~
29200 \InsetSpace ~
29201 \InsetSpace ~
29202 \InsetSpace ~
29203 \InsetSpace ~
29204 \InsetSpace ~
29205 \InsetSpace ~
29206 \InsetSpace ~
29207 \InsetSpace ~
29208 \InsetSpace ~
29209 \InsetSpace ~
29210 \InsetSpace ~
29211 \InsetSpace ~
29212 \InsetSpace ~
29213 \InsetSpace ~
29214 \InsetSpace ~
29215 \InsetSpace ~
29216 \InsetSpace ~
29217 \InsetSpace ~
29218 \InsetSpace ~
29219 \InsetSpace ~
29220 \InsetSpace ~
29221 \InsetSpace ~
29222 \InsetSpace ~
29223 \InsetSpace ~
29224 \InsetSpace ~
29225 \InsetSpace ~
29226 \InsetSpace ~
29227 \InsetSpace ~
29228 \InsetSpace ~
29229 buffer point 
29230 \newline
29231 ;;\InsetSpace ~
29232 !\InsetSpace ~
29233 \InsetSpace ~
29234 \InsetSpace ~
29235 \InsetSpace ~
29236 \InsetSpace ~
29237 \InsetSpace ~
29238 \InsetSpace ~
29239 \InsetSpace ~
29240 \InsetSpace ~
29241 \InsetSpace ~
29242 \InsetSpace ~
29243 \InsetSpace ~
29244 \InsetSpace ~
29245 \InsetSpace ~
29246 \InsetSpace ~
29247 sdcdbsrc-goto-sdcdb\InsetSpace ~
29248 \InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 \InsetSpace ~
29252 \InsetSpace ~
29253 \InsetSpace ~
29254 \InsetSpace ~
29255 \InsetSpace ~
29256 \InsetSpace ~
29257 Goto the SDCDB output buffer 
29258 \newline
29259 ;;\InsetSpace ~
29260 p\InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 \InsetSpace ~
29271 \InsetSpace ~
29272 \InsetSpace ~
29273 \InsetSpace ~
29274 \InsetSpace ~
29275 sdcdb-prin
29276 t-c-sexp\InsetSpace ~
29277 \InsetSpace ~
29278 \InsetSpace ~
29279 \InsetSpace ~
29280 \InsetSpace ~
29281 \InsetSpace ~
29282 \InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 SDCDB print command for data at 
29288 \newline
29289 ;;\InsetSpace ~
29290 \InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 \InsetSpace ~
29294 \InsetSpace ~
29295 \InsetSpace ~
29296 \InsetSpace ~
29297 \InsetSpace ~
29298 \InsetSpace ~
29299 \InsetSpace ~
29300 \InsetSpace ~
29301 \InsetSpace ~
29302 \InsetSpace ~
29303 \InsetSpace ~
29304 \InsetSpace ~
29305 \InsetSpace ~
29306 \InsetSpace ~
29307 \InsetSpace ~
29308 \InsetSpace ~
29309 \InsetSpace ~
29310 \InsetSpace ~
29311 \InsetSpace ~
29312 \InsetSpace ~
29313 \InsetSpace ~
29314 \InsetSpace ~
29315 \InsetSpace ~
29316 \InsetSpace ~
29317 \InsetSpace ~
29318 \InsetSpace ~
29319 \InsetSpace ~
29320 \InsetSpace ~
29321 \InsetSpace ~
29322 \InsetSpace ~
29323 \InsetSpace ~
29324 \InsetSpace ~
29325 \InsetSpace ~
29326 \InsetSpace ~
29327 \InsetSpace ~
29328 \InsetSpace ~
29329 \InsetSpace ~
29330 \InsetSpace ~
29331 \InsetSpace ~
29332 \InsetSpace ~
29333 \InsetSpace ~
29334 \InsetSpace ~
29335 \InsetSpace ~
29336 buffer point 
29337 \newline
29338 ;;\InsetSpace ~
29339 g\InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 \InsetSpace ~
29347 \InsetSpace ~
29348 \InsetSpace ~
29349 \InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 sdcdbsrc-goto-sdcdb\InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 \InsetSpace ~
29364 Got
29365 o the SDCDB output buffer 
29366 \newline
29367 ;;\InsetSpace ~
29368 t\InsetSpace ~
29369 \InsetSpace ~
29370 \InsetSpace ~
29371 \InsetSpace ~
29372 \InsetSpace ~
29373 \InsetSpace ~
29374 \InsetSpace ~
29375 \InsetSpace ~
29376 \InsetSpace ~
29377 \InsetSpace ~
29378 \InsetSpace ~
29379 \InsetSpace ~
29380 \InsetSpace ~
29381 \InsetSpace ~
29382 \InsetSpace ~
29383 sdcdbsrc-mode\InsetSpace ~
29384 \InsetSpace ~
29385 \InsetSpace ~
29386 \InsetSpace ~
29387 \InsetSpace ~
29388 \InsetSpace ~
29389 \InsetSpace ~
29390 \InsetSpace ~
29391 \InsetSpace ~
29392 \InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 Toggles Sdcdbsrc mode (turns it
29400  off) 
29401 \newline
29402 ;; 
29403 \newline
29404 ;;\InsetSpace ~
29405 C-c\InsetSpace ~
29406 C-f\InsetSpace ~
29407 \InsetSpace ~
29408 \InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 \InsetSpace ~
29415 sdcdb-finish-from-src\InsetSpace ~
29416 \InsetSpace ~
29417 \InsetSpace ~
29418 \InsetSpace ~
29419 \InsetSpace ~
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 SDCDB finish command 
29424 \newline
29425 ;; 
29426 \newline
29427 ;;\InsetSpace ~
29428 C-x\InsetSpace ~
29429 SPC\InsetSpace ~
29430 \InsetSpace ~
29431 \InsetSpace ~
29432 \InsetSpace ~
29433 \InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 sdcdb-brea
29439 k\InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 \InsetSpace ~
29447 \InsetSpace ~
29448 \InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 Set break for line with point 
29458 \newline
29459 ;;\InsetSpace ~
29460 ESC\InsetSpace ~
29461 t\InsetSpace ~
29462 \InsetSpace ~
29463 \InsetSpace ~
29464 \InsetSpace ~
29465 \InsetSpace ~
29466 \InsetSpace ~
29467 \InsetSpace ~
29468 \InsetSpace ~
29469 \InsetSpace ~
29470 \InsetSpace ~
29471 \InsetSpace ~
29472 sdcdbsrc-mode\InsetSpace ~
29473 \InsetSpace ~
29474 \InsetSpace ~
29475 \InsetSpace ~
29476 \InsetSpace ~
29477 \InsetSpace ~
29478 \InsetSpace ~
29479 \InsetSpace ~
29480 \InsetSpace ~
29481 \InsetSpace ~
29482 \InsetSpace ~
29483 \InsetSpace ~
29484 \InsetSpace ~
29485 \InsetSpace ~
29486 \InsetSpace ~
29487 \InsetSpace ~
29488 Toggle Sdcdbsrc mode 
29489 \newline
29490 ;;\InsetSpace ~
29491 ESC\InsetSpace ~
29492 m\InsetSpace ~
29493 \InsetSpace ~
29494 \InsetSpace ~
29495 \InsetSpace ~
29496 \InsetSpace ~
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500 \InsetSpace ~
29501 \InsetSpace ~
29502 \InsetSpace ~
29503 sdc
29504 dbsrc-srcmode\InsetSpace ~
29505 \InsetSpace ~
29506 \InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 \InsetSpace ~
29516 \InsetSpace ~
29517 Toggle list mode 
29518 \newline
29519 ;; 
29520 \newline
29521
29522 \family default
29523
29524 \newpage
29525
29526 \end_layout
29527
29528 \begin_layout Chapter
29529 TIPS
29530 \end_layout
29531
29532 \begin_layout Standard
29533 Here are a few guidelines that will help the compiler generate more efficient
29534  code, some of the tips are specific to this compiler others are generally
29535  good programming practice.
29536 \end_layout
29537
29538 \begin_layout Itemize
29539 Use the smallest data type to represent your data-value.
29540  If it is known in advance that the value is going to be less than 256 then
29541  use an 'unsigned char' instead of a 'short' or 'int'.
29542  Please note, that ANSI C requires both signed and unsigned chars to be
29543  promoted to 'signed int'
29544 \begin_inset LatexCommand \index{promotion to signed int}
29545
29546 \end_inset
29547
29548
29549 \begin_inset Marginal
29550 status collapsed
29551
29552 \begin_layout Standard
29553
29554 \series bold
29555 \InsetSpace ~
29556 !
29557 \end_layout
29558
29559 \end_inset
29560
29561  before doing any operation.
29562  This promotion
29563 \begin_inset LatexCommand \index{type promotion}
29564
29565 \end_inset
29566
29567
29568 \begin_inset LatexCommand \label{type promotion}
29569
29570 \end_inset
29571
29572  can be omitted, if the result is the same.
29573  The effect of the promotion rules together with the sign-extension is often
29574  surprising:
29575 \end_layout
29576
29577 \begin_deeper
29578 \begin_layout Verse
29579
29580 \family typewriter
29581 unsigned char uc = 0xfe;
29582 \newline
29583 if (uc * uc < 0) /* this is true! */
29584 \newline
29585 {
29586 \newline
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 ....
29592 \newline
29593 }
29594 \end_layout
29595
29596 \begin_layout Standard
29597
29598 \family typewriter
29599 uc * uc
29600 \family default
29601  is evaluated as 
29602 \family typewriter
29603 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29604 \family default
29605 .
29606  
29607 \newline
29608 Another one:
29609 \end_layout
29610
29611 \begin_layout Verse
29612
29613 \family typewriter
29614 (unsigned char) -12 / (signed char) -3 = ...
29615 \end_layout
29616
29617 \begin_layout Standard
29618 No, the result is not 4:
29619 \end_layout
29620
29621 \begin_layout Verse
29622
29623 \family typewriter
29624 (int) (unsigned char) -12 / (int) (signed char) -3 =
29625 \newline
29626 (int) (unsigned char)
29627  0xf4 / (int) (signed char) 0xfd =
29628 \newline
29629 (int) 0x00f4 / (int) 0xfffd =
29630 \newline
29631 (int) 0x00f4
29632  / (int) 0xfffd =
29633 \newline
29634 (int) 244 / (int) -3 =
29635 \newline
29636 (int) -81 = (int) 0xffaf;
29637 \end_layout
29638
29639 \begin_layout Standard
29640 Don't complain, that gcc gives you a different result.
29641  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29642  Therefore the results are different.
29643 \newline
29644 From 
29645 \begin_inset Quotes sld
29646 \end_inset
29647
29648 comp.lang.c FAQ
29649 \begin_inset Quotes srd
29650 \end_inset
29651
29652 :
29653 \end_layout
29654
29655 \begin_layout Quote
29656
29657 \emph on
29658 If well-defined overflow characteristics are important and negative values
29659  are not, or if you want to steer clear of sign-extension problems when
29660  manipulating bits or bytes, use one of the corresponding unsigned types.
29661  (Beware when mixing signed and unsigned values in expressions, though.)
29662 \newline
29663 Although
29664  character types (especially unsigned char) can be used as "tiny" integers,
29665  doing so is sometimes more trouble than it's worth, due to unpredictable
29666  sign extension and increased code size.
29667 \end_layout
29668
29669 \end_deeper
29670 \begin_layout Itemize
29671 Use unsigned when it is known in advance that the value is not going to
29672  be negative.
29673  This helps especially if you are doing division or multiplication, bit-shifting
29674  or are using an array index.
29675 \end_layout
29676
29677 \begin_layout Itemize
29678 NEVER jump into a LOOP.
29679 \end_layout
29680
29681 \begin_layout Itemize
29682 Declare the variables to be local
29683 \begin_inset LatexCommand \index{local variables}
29684
29685 \end_inset
29686
29687  whenever possible, especially loop control variables (induction).
29688 \end_layout
29689
29690 \begin_layout Itemize
29691 Have a look at the assembly listing to get a 
29692 \begin_inset Quotes sld
29693 \end_inset
29694
29695 feeling
29696 \begin_inset Quotes srd
29697 \end_inset
29698
29699  for the code generation.
29700 \end_layout
29701
29702 \begin_layout Section
29703 Porting code from or to other compilers
29704 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29705
29706 \end_inset
29707
29708
29709 \end_layout
29710
29711 \begin_layout Itemize
29712 check whether endianness of the compilers differs and adapt where needed.
29713 \end_layout
29714
29715 \begin_layout Itemize
29716 check the device specific header files
29717 \begin_inset LatexCommand \index{Header files}
29718
29719 \end_inset
29720
29721
29722 \begin_inset LatexCommand \index{Include files}
29723
29724 \end_inset
29725
29726  for compiler specific syntax.
29727  Eventually include the file <compiler.h
29728 \begin_inset LatexCommand \index{compiler.h (include file)}
29729
29730 \end_inset
29731
29732
29733 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29734
29735 \end_inset
29736
29737  to allow using common header files.
29738  (see f.e.
29739  cc2510fx.h 
29740 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29741
29742 \end_inset
29743
29744 ).
29745 \end_layout
29746
29747 \begin_layout Itemize
29748 check whether the startup code contains the correct initialization (watchdog,
29749  peripherals).
29750 \end_layout
29751
29752 \begin_layout Itemize
29753 check whether the sizes of short, int, long match.
29754 \end_layout
29755
29756 \begin_layout Itemize
29757 check if some 16 or 32 bit hardware registers require a specific addressing
29758  order (least significant or most significant byte first) and adapt if needed
29759  (
29760 \emph on
29761 first
29762 \emph default
29763  and 
29764 \emph on
29765 last
29766 \emph default
29767  relate to time and not to lower/upper memory location here, so this is
29768  
29769 \emph on
29770 not
29771 \emph default
29772  the same as endianness).
29773 \end_layout
29774
29775 \begin_layout Itemize
29776 check whether the keyword 
29777 \emph on
29778 volatile
29779 \emph default
29780  is used where needed.
29781  The compilers might differ in their optimization characteristics (as different
29782  versions of the same compiler might also use more clever optimizations
29783  this is good idea anyway).
29784  See section 
29785 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29786
29787 \end_inset
29788
29789 .
29790 \end_layout
29791
29792 \begin_layout Itemize
29793 check that the compilers are not told to supress warnings.
29794 \end_layout
29795
29796 \begin_layout Itemize
29797 check and convert compiler specific extensions (interrupts, memory areas,
29798  pragmas etc.).
29799 \end_layout
29800
29801 \begin_layout Itemize
29802 check for differences in type promotion.
29803  Especially check for math operations on 
29804 \family typewriter
29805 char
29806 \family default
29807  or 
29808 \family typewriter
29809 unsigned char
29810 \family default
29811  variables.
29812  For the sake of C99 compatibility SDCC will probably promote these to 
29813 \family typewriter
29814 int
29815 \family default
29816  more often than other compilers.
29817  Eventually insert explicit casts to 
29818 \family typewriter
29819 (char) 
29820 \family default
29821 or
29822 \family typewriter
29823  (unsigned char)
29824 \family default
29825 .
29826  Also check that the ~\InsetSpace ~
29827 operator
29828 \begin_inset LatexCommand \index{\~\/ Operator}
29829
29830 \end_inset
29831
29832  is not used on 
29833 \family typewriter
29834 bit
29835 \begin_inset LatexCommand \index{bit}
29836
29837 \end_inset
29838
29839
29840 \family default
29841  variables, use the !\InsetSpace ~
29842 operator instead.
29843  See sections 
29844 \begin_inset LatexCommand \ref{type promotion}
29845
29846 \end_inset
29847
29848  and 
29849 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29850
29851 \end_inset
29852
29853 .
29854 \end_layout
29855
29856 \begin_layout Itemize
29857 check the assembly code generated for interrupt routines (f.e.
29858  for calls to possibly non-reentrant library functions).
29859 \end_layout
29860
29861 \begin_layout Itemize
29862 check whether timing loops result in proper timing (or preferably consider
29863  a rewrite of the code with timer based delays instead).
29864 \end_layout
29865
29866 \begin_layout Itemize
29867 check for differences in printf parameters (some compilers push (va_arg
29868 \begin_inset LatexCommand \index{vararg, va\_arg}
29869
29870 \end_inset
29871
29872 ) char variables as 
29873 \family typewriter
29874 int
29875 \family default
29876  others push them as 
29877 \family typewriter
29878 char
29879 \family default
29880 .
29881  See section 
29882 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29883
29884 \end_inset
29885
29886 ).
29887 \end_layout
29888
29889 \begin_layout Itemize
29890 check the resulting memory map
29891 \begin_inset LatexCommand \index{Memory map}
29892
29893 \end_inset
29894
29895 .
29896  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29897 ly idata, pdata, xdata).
29898  Eventually check if unexpected library functions are included.
29899 \end_layout
29900
29901 \begin_layout Section
29902 Tools
29903 \begin_inset LatexCommand \index{Tools}
29904
29905 \end_inset
29906
29907  included in the distribution
29908 \end_layout
29909
29910 \begin_layout Standard
29911 \align left
29912 \begin_inset Tabular
29913 <lyxtabular version="3" rows="12" columns="3">
29914 <features>
29915 <column alignment="left" valignment="top" leftline="true" width="0pt">
29916 <column alignment="left" valignment="top" leftline="true" width="0pt">
29917 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29918 <row topline="true" bottomline="true">
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29920 \begin_inset Text
29921
29922 \begin_layout Standard
29923
29924 \series bold
29925 Name
29926 \end_layout
29927
29928 \end_inset
29929 </cell>
29930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29931 \begin_inset Text
29932
29933 \begin_layout Standard
29934
29935 \series bold
29936 Purpose
29937 \end_layout
29938
29939 \end_inset
29940 </cell>
29941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29942 \begin_inset Text
29943
29944 \begin_layout Standard
29945
29946 \series bold
29947 Directory
29948 \end_layout
29949
29950 \end_inset
29951 </cell>
29952 </row>
29953 <row topline="true">
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29955 \begin_inset Text
29956
29957 \begin_layout Standard
29958 uCsim
29959 \begin_inset LatexCommand \index{uCsim}
29960
29961 \end_inset
29962
29963
29964 \end_layout
29965
29966 \end_inset
29967 </cell>
29968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29969 \begin_inset Text
29970
29971 \begin_layout Standard
29972 Simulator for various architectures
29973 \end_layout
29974
29975 \end_inset
29976 </cell>
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29978 \begin_inset Text
29979
29980 \begin_layout Standard
29981 sdcc/sim/ucsim
29982 \end_layout
29983
29984 \end_inset
29985 </cell>
29986 </row>
29987 <row topline="true">
29988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29989 \begin_inset Text
29990
29991 \begin_layout Standard
29992 keil2sdcc.pl
29993 \end_layout
29994
29995 \end_inset
29996 </cell>
29997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29998 \begin_inset Text
29999
30000 \begin_layout Standard
30001 header file
30002 \begin_inset LatexCommand \index{Header files}
30003
30004 \end_inset
30005
30006
30007 \begin_inset LatexCommand \index{Include files}
30008
30009 \end_inset
30010
30011  conversion
30012 \end_layout
30013
30014 \end_inset
30015 </cell>
30016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30017 \begin_inset Text
30018
30019 \begin_layout Standard
30020 sdcc/support/scripts
30021 \end_layout
30022
30023 \end_inset
30024 </cell>
30025 </row>
30026 <row topline="true">
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30028 \begin_inset Text
30029
30030 \begin_layout Standard
30031 mh2h.c
30032 \end_layout
30033
30034 \end_inset
30035 </cell>
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30037 \begin_inset Text
30038
30039 \begin_layout Standard
30040 header file conversion
30041 \end_layout
30042
30043 \end_inset
30044 </cell>
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30046 \begin_inset Text
30047
30048 \begin_layout Standard
30049 sdcc/support/scripts
30050 \end_layout
30051
30052 \end_inset
30053 </cell>
30054 </row>
30055 <row topline="true">
30056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30057 \begin_inset Text
30058
30059 \begin_layout Standard
30060 as-gbz80
30061 \end_layout
30062
30063 \end_inset
30064 </cell>
30065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30066 \begin_inset Text
30067
30068 \begin_layout Standard
30069 Assembler
30070 \end_layout
30071
30072 \end_inset
30073 </cell>
30074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30075 \begin_inset Text
30076
30077 \begin_layout Standard
30078
30079 \family roman
30080 \series medium
30081 \shape up
30082 \size normal
30083 \emph off
30084 \bar no
30085 \noun off
30086 \color none
30087 sdcc/bin
30088 \end_layout
30089
30090 \end_inset
30091 </cell>
30092 </row>
30093 <row topline="true">
30094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30095 \begin_inset Text
30096
30097 \begin_layout Standard
30098 as-z80
30099 \end_layout
30100
30101 \end_inset
30102 </cell>
30103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30104 \begin_inset Text
30105
30106 \begin_layout Standard
30107 Assembler
30108 \end_layout
30109
30110 \end_inset
30111 </cell>
30112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30113 \begin_inset Text
30114
30115 \begin_layout Standard
30116
30117 \family roman
30118 \series medium
30119 \shape up
30120 \size normal
30121 \emph off
30122 \bar no
30123 \noun off
30124 \color none
30125 sdcc/bin
30126 \end_layout
30127
30128 \end_inset
30129 </cell>
30130 </row>
30131 <row topline="true">
30132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30133 \begin_inset Text
30134
30135 \begin_layout Standard
30136 asx8051
30137 \end_layout
30138
30139 \end_inset
30140 </cell>
30141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30142 \begin_inset Text
30143
30144 \begin_layout Standard
30145 Assembler
30146 \end_layout
30147
30148 \end_inset
30149 </cell>
30150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30151 \begin_inset Text
30152
30153 \begin_layout Standard
30154
30155 \family roman
30156 \series medium
30157 \shape up
30158 \size normal
30159 \emph off
30160 \bar no
30161 \noun off
30162 \color none
30163 sdcc/bin
30164 \end_layout
30165
30166 \end_inset
30167 </cell>
30168 </row>
30169 <row topline="true">
30170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30171 \begin_inset Text
30172
30173 \begin_layout Standard
30174 SDCDB
30175 \end_layout
30176
30177 \end_inset
30178 </cell>
30179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30180 \begin_inset Text
30181
30182 \begin_layout Standard
30183 Simulator
30184 \end_layout
30185
30186 \end_inset
30187 </cell>
30188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30189 \begin_inset Text
30190
30191 \begin_layout Standard
30192
30193 \family roman
30194 \series medium
30195 \shape up
30196 \size normal
30197 \emph off
30198 \bar no
30199 \noun off
30200 \color none
30201 sdcc/bin
30202 \end_layout
30203
30204 \end_inset
30205 </cell>
30206 </row>
30207 <row topline="true">
30208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30209 \begin_inset Text
30210
30211 \begin_layout Standard
30212 aslink
30213 \end_layout
30214
30215 \end_inset
30216 </cell>
30217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30218 \begin_inset Text
30219
30220 \begin_layout Standard
30221 Linker
30222 \end_layout
30223
30224 \end_inset
30225 </cell>
30226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30227 \begin_inset Text
30228
30229 \begin_layout Standard
30230
30231 \family roman
30232 \series medium
30233 \shape up
30234 \size normal
30235 \emph off
30236 \bar no
30237 \noun off
30238 \color none
30239 sdcc/bin
30240 \end_layout
30241
30242 \end_inset
30243 </cell>
30244 </row>
30245 <row topline="true">
30246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30247 \begin_inset Text
30248
30249 \begin_layout Standard
30250 link-z80
30251 \end_layout
30252
30253 \end_inset
30254 </cell>
30255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30256 \begin_inset Text
30257
30258 \begin_layout Standard
30259 Linker
30260 \end_layout
30261
30262 \end_inset
30263 </cell>
30264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30265 \begin_inset Text
30266
30267 \begin_layout Standard
30268
30269 \family roman
30270 \series medium
30271 \shape up
30272 \size normal
30273 \emph off
30274 \bar no
30275 \noun off
30276 \color none
30277 sdcc/bin
30278 \end_layout
30279
30280 \end_inset
30281 </cell>
30282 </row>
30283 <row topline="true">
30284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30285 \begin_inset Text
30286
30287 \begin_layout Standard
30288 link-gbz80
30289 \end_layout
30290
30291 \end_inset
30292 </cell>
30293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30294 \begin_inset Text
30295
30296 \begin_layout Standard
30297 Linker
30298 \end_layout
30299
30300 \end_inset
30301 </cell>
30302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30303 \begin_inset Text
30304
30305 \begin_layout Standard
30306
30307 \family roman
30308 \series medium
30309 \shape up
30310 \size normal
30311 \emph off
30312 \bar no
30313 \noun off
30314 \color none
30315 sdcc/bin
30316 \end_layout
30317
30318 \end_inset
30319 </cell>
30320 </row>
30321 <row topline="true" bottomline="true">
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30323 \begin_inset Text
30324
30325 \begin_layout Standard
30326 packihx
30327 \end_layout
30328
30329 \end_inset
30330 </cell>
30331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30332 \begin_inset Text
30333
30334 \begin_layout Standard
30335 Intel Hex packer 
30336 \begin_inset LatexCommand \index{packihx (tool)}
30337
30338 \end_inset
30339
30340
30341 \end_layout
30342
30343 \end_inset
30344 </cell>
30345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30346 \begin_inset Text
30347
30348 \begin_layout Standard
30349
30350 \family roman
30351 \series medium
30352 \shape up
30353 \size normal
30354 \emph off
30355 \bar no
30356 \noun off
30357 \color none
30358 sdcc/bin
30359 \end_layout
30360
30361 \end_inset
30362 </cell>
30363 </row>
30364 </lyxtabular>
30365
30366 \end_inset
30367
30368
30369 \newline
30370
30371 \end_layout
30372
30373 \begin_layout Section
30374 Documentation
30375 \begin_inset LatexCommand \index{Documentation}
30376
30377 \end_inset
30378
30379  included in the distribution
30380 \end_layout
30381
30382 \begin_layout Standard
30383 \align left
30384 \begin_inset Tabular
30385 <lyxtabular version="3" rows="10" columns="2">
30386 <features>
30387 <column alignment="block" valignment="top" leftline="true" width="40col%">
30388 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30389 <row topline="true" bottomline="true" endhead="true">
30390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30391 \begin_inset Text
30392
30393 \begin_layout Standard
30394
30395 \series bold
30396 Subject / Title
30397 \end_layout
30398
30399 \end_inset
30400 </cell>
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30402 \begin_inset Text
30403
30404 \begin_layout Standard
30405
30406 \series bold
30407 Filename / Where to get
30408 \end_layout
30409
30410 \end_inset
30411 </cell>
30412 </row>
30413 <row topline="true">
30414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30415 \begin_inset Text
30416
30417 \begin_layout Standard
30418 SDCC Compiler User Guide
30419 \end_layout
30420
30421 \end_inset
30422 </cell>
30423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30424 \begin_inset Text
30425
30426 \begin_layout Standard
30427 You're reading it right now
30428 \emph on
30429  \InsetSpace ~
30430 \InsetSpace ~
30431 \InsetSpace ~
30432
30433 \hfill
30434 online at:
30435 \emph default
30436
30437 \newline
30438
30439 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30440
30441 \end_inset
30442
30443
30444 \end_layout
30445
30446 \end_inset
30447 </cell>
30448 </row>
30449 <row topline="true">
30450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30451 \begin_inset Text
30452
30453 \begin_layout Standard
30454 Changelog of SDCC
30455 \end_layout
30456
30457 \end_inset
30458 </cell>
30459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30460 \begin_inset Text
30461
30462 \begin_layout Standard
30463 sdcc/Changelog
30464 \emph on
30465  \InsetSpace ~
30466 \InsetSpace ~
30467 \InsetSpace ~
30468
30469 \hfill
30470 online at:
30471 \emph default
30472
30473 \newline
30474
30475 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30476
30477 \end_inset
30478
30479
30480 \end_layout
30481
30482 \end_inset
30483 </cell>
30484 </row>
30485 <row topline="true">
30486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30487 \begin_inset Text
30488
30489 \begin_layout Standard
30490 ASXXXX
30491 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30492
30493 \end_inset
30494
30495
30496 \begin_inset LatexCommand \index{Assembler documentation}
30497
30498 \end_inset
30499
30500  Assemblers and
30501 \newline
30502 ASLINK
30503 \begin_inset LatexCommand \index{aslink}
30504
30505 \end_inset
30506
30507
30508 \begin_inset LatexCommand \index{Linker documentation}
30509
30510 \end_inset
30511
30512  Relocating Linker
30513 \end_layout
30514
30515 \end_inset
30516 </cell>
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30518 \begin_inset Text
30519
30520 \begin_layout Standard
30521 sdcc/as/doc/asxhtm.html 
30522 \emph on
30523 \InsetSpace ~
30524 \InsetSpace ~
30525 \InsetSpace ~
30526
30527 \hfill
30528 online at:
30529 \emph default
30530
30531 \newline
30532
30533 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30534
30535 \end_inset
30536
30537
30538 \end_layout
30539
30540 \end_inset
30541 </cell>
30542 </row>
30543 <row topline="true">
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30545 \begin_inset Text
30546
30547 \begin_layout Standard
30548 SDCC regression test
30549 \begin_inset LatexCommand \index{Regression test}
30550
30551 \end_inset
30552
30553
30554 \end_layout
30555
30556 \end_inset
30557 </cell>
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30559 \begin_inset Text
30560
30561 \begin_layout Standard
30562 sdcc/doc/test_suite_spec.pdf 
30563 \emph on
30564 \InsetSpace ~
30565 \InsetSpace ~
30566 \InsetSpace ~
30567
30568 \hfill
30569 online at:
30570 \emph default
30571
30572 \newline
30573
30574 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30575
30576 \end_inset
30577
30578
30579 \end_layout
30580
30581 \end_inset
30582 </cell>
30583 </row>
30584 <row topline="true">
30585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30586 \begin_inset Text
30587
30588 \begin_layout Standard
30589 Various notes
30590 \end_layout
30591
30592 \end_inset
30593 </cell>
30594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30595 \begin_inset Text
30596
30597 \begin_layout Standard
30598 sdcc/doc/* 
30599 \emph on
30600 \InsetSpace ~
30601 \InsetSpace ~
30602 \InsetSpace ~
30603
30604 \hfill
30605 online at:
30606 \emph default
30607
30608 \newline
30609
30610 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30611
30612 \end_inset
30613
30614
30615 \end_layout
30616
30617 \end_inset
30618 </cell>
30619 </row>
30620 <row topline="true">
30621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30622 \begin_inset Text
30623
30624 \begin_layout Standard
30625 Notes on debugging with SDCDB
30626 \begin_inset LatexCommand \index{SDCDB (debugger)}
30627
30628 \end_inset
30629
30630
30631 \end_layout
30632
30633 \end_inset
30634 </cell>
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30636 \begin_inset Text
30637
30638 \begin_layout Standard
30639 sdcc/debugger/README 
30640 \emph on
30641 \InsetSpace ~
30642 \InsetSpace ~
30643 \InsetSpace ~
30644
30645 \hfill
30646 online at
30647 \emph default
30648 :
30649 \newline
30650
30651 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30652
30653 \end_inset
30654
30655
30656 \end_layout
30657
30658 \end_inset
30659 </cell>
30660 </row>
30661 <row topline="true">
30662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30663 \begin_inset Text
30664
30665 \begin_layout Standard
30666 uCsim
30667 \begin_inset LatexCommand \index{uCsim}
30668
30669 \end_inset
30670
30671  Software simulator for microcontrollers
30672 \end_layout
30673
30674 \end_inset
30675 </cell>
30676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30677 \begin_inset Text
30678
30679 \begin_layout Standard
30680
30681 \family roman
30682 \series medium
30683 \shape up
30684 \size normal
30685 \emph off
30686 \bar no
30687 \noun off
30688 \color none
30689 sdcc/sim/ucsim/doc
30690 \family default
30691 \series default
30692 \shape default
30693 \size default
30694 \emph default
30695 \bar default
30696 \noun default
30697 /index.html 
30698 \emph on
30699 \InsetSpace ~
30700 \InsetSpace ~
30701 \InsetSpace ~
30702
30703 \hfill
30704 online at:
30705 \emph default
30706
30707 \newline
30708
30709 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30710
30711 \end_inset
30712
30713
30714 \end_layout
30715
30716 \end_inset
30717 </cell>
30718 </row>
30719 <row topline="true">
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30721 \begin_inset Text
30722
30723 \begin_layout Standard
30724 Temporary notes on the pic16
30725 \begin_inset LatexCommand \index{PIC16}
30726
30727 \end_inset
30728
30729  port
30730 \end_layout
30731
30732 \end_inset
30733 </cell>
30734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30735 \begin_inset Text
30736
30737 \begin_layout Standard
30738 sdcc/src/pic16/NOTES 
30739 \emph on
30740 \InsetSpace ~
30741 \InsetSpace ~
30742 \InsetSpace ~
30743
30744 \hfill
30745 online at:
30746 \newline
30747
30748 \emph default
30749
30750 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30751
30752 \end_inset
30753
30754
30755 \end_layout
30756
30757 \end_inset
30758 </cell>
30759 </row>
30760 <row topline="true" bottomline="true">
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30762 \begin_inset Text
30763
30764 \begin_layout Standard
30765 SDCC internal documentation (debugging file format)
30766 \end_layout
30767
30768 \end_inset
30769 </cell>
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30771 \begin_inset Text
30772
30773 \begin_layout Standard
30774 sdcc/doc/
30775 \family roman
30776 \series medium
30777 \shape up
30778 \size normal
30779 \emph off
30780 \bar no
30781 \noun off
30782 \color none
30783 cdbfileformat.pd
30784 \family default
30785 \series default
30786 \shape default
30787 \size default
30788 \emph default
30789 \bar default
30790 \noun default
30791 f
30792 \emph on
30793  \InsetSpace ~
30794 \InsetSpace ~
30795 \InsetSpace ~
30796
30797 \hfill
30798 online at:
30799 \emph default
30800
30801 \newline
30802
30803 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30804
30805 \end_inset
30806
30807
30808 \end_layout
30809
30810 \end_inset
30811 </cell>
30812 </row>
30813 </lyxtabular>
30814
30815 \end_inset
30816
30817
30818 \newline
30819
30820 \end_layout
30821
30822 \begin_layout Section
30823 Related open source tools
30824 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30825
30826 \end_inset
30827
30828
30829 \begin_inset LatexCommand \index{Related tools}
30830
30831 \end_inset
30832
30833
30834 \end_layout
30835
30836 \begin_layout Standard
30837 \align left
30838 \begin_inset Tabular
30839 <lyxtabular version="3" rows="14" columns="3">
30840 <features>
30841 <column alignment="left" valignment="top" leftline="true" width="0pt">
30842 <column alignment="block" valignment="top" leftline="true" width="30line%">
30843 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30844 <row topline="true" bottomline="true">
30845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30846 \begin_inset Text
30847
30848 \begin_layout Standard
30849
30850 \series bold
30851 Name
30852 \end_layout
30853
30854 \end_inset
30855 </cell>
30856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30857 \begin_inset Text
30858
30859 \begin_layout Standard
30860
30861 \series bold
30862 Purpose
30863 \end_layout
30864
30865 \end_inset
30866 </cell>
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30868 \begin_inset Text
30869
30870 \begin_layout Standard
30871
30872 \series bold
30873 Where to get
30874 \end_layout
30875
30876 \end_inset
30877 </cell>
30878 </row>
30879 <row topline="true">
30880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30881 \begin_inset Text
30882
30883 \begin_layout Standard
30884 gpsim
30885 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30886
30887 \end_inset
30888
30889
30890 \end_layout
30891
30892 \end_inset
30893 </cell>
30894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30895 \begin_inset Text
30896
30897 \begin_layout Standard
30898 PIC simulator
30899 \end_layout
30900
30901 \end_inset
30902 </cell>
30903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30904 \begin_inset Text
30905
30906 \begin_layout Standard
30907 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30908
30909 \end_inset
30910
30911
30912 \end_layout
30913
30914 \end_inset
30915 </cell>
30916 </row>
30917 <row topline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30919 \begin_inset Text
30920
30921 \begin_layout Standard
30922 gputils
30923 \begin_inset LatexCommand \index{gputils (pic tools)}
30924
30925 \end_inset
30926
30927
30928 \end_layout
30929
30930 \end_inset
30931 </cell>
30932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30933 \begin_inset Text
30934
30935 \begin_layout Standard
30936 GNU PIC utilities
30937 \end_layout
30938
30939 \end_inset
30940 </cell>
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \begin_layout Standard
30945 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30946
30947 \end_inset
30948
30949
30950 \end_layout
30951
30952 \end_inset
30953 </cell>
30954 </row>
30955 <row topline="true">
30956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30957 \begin_inset Text
30958
30959 \begin_layout Standard
30960 flP5
30961 \end_layout
30962
30963 \end_inset
30964 </cell>
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30966 \begin_inset Text
30967
30968 \begin_layout Standard
30969 PIC programmer
30970 \end_layout
30971
30972 \end_inset
30973 </cell>
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30975 \begin_inset Text
30976
30977 \begin_layout Standard
30978 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30979
30980 \end_inset
30981
30982
30983 \end_layout
30984
30985 \end_inset
30986 </cell>
30987 </row>
30988 <row topline="true">
30989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30990 \begin_inset Text
30991
30992 \begin_layout Standard
30993 ec2drv/newcdb
30994 \end_layout
30995
30996 \end_inset
30997 </cell>
30998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30999 \begin_inset Text
31000
31001 \begin_layout Standard
31002 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31003  (Unix only)
31004 \end_layout
31005
31006 \end_inset
31007 </cell>
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31009 \begin_inset Text
31010
31011 \begin_layout Standard
31012 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31013
31014 \end_inset
31015
31016
31017 \end_layout
31018
31019 \end_inset
31020 </cell>
31021 </row>
31022 <row topline="true">
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027 indent
31028 \begin_inset LatexCommand \index{indent (source formatting tool)}
31029
31030 \end_inset
31031
31032
31033 \end_layout
31034
31035 \end_inset
31036 </cell>
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 \begin_inset Text
31039
31040 \begin_layout Standard
31041 Formats C source - Master of the white spaces
31042 \end_layout
31043
31044 \end_inset
31045 </cell>
31046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31047 \begin_inset Text
31048
31049 \begin_layout Standard
31050 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31051
31052 \end_inset
31053
31054
31055 \end_layout
31056
31057 \end_inset
31058 </cell>
31059 </row>
31060 <row topline="true">
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_inset Text
31063
31064 \begin_layout Standard
31065 srecord
31066 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31067
31068 \end_inset
31069
31070
31071 \end_layout
31072
31073 \end_inset
31074 </cell>
31075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31076 \begin_inset Text
31077
31078 \begin_layout Standard
31079 Object file conversion, checksumming, ...
31080 \end_layout
31081
31082 \end_inset
31083 </cell>
31084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31085 \begin_inset Text
31086
31087 \begin_layout Standard
31088 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31089
31090 \end_inset
31091
31092
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 </row>
31098 <row topline="true">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \begin_layout Standard
31103 objdump
31104 \begin_inset LatexCommand \index{objdump (tool)}
31105
31106 \end_inset
31107
31108
31109 \end_layout
31110
31111 \end_inset
31112 </cell>
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_inset Text
31115
31116 \begin_layout Standard
31117 Object file conversion, ...
31118 \end_layout
31119
31120 \end_inset
31121 </cell>
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31123 \begin_inset Text
31124
31125 \begin_layout Standard
31126 Part of binutils (should be there anyway)
31127 \end_layout
31128
31129 \end_inset
31130 </cell>
31131 </row>
31132 <row topline="true">
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31134 \begin_inset Text
31135
31136 \begin_layout Standard
31137 cmon51
31138 \end_layout
31139
31140 \end_inset
31141 </cell>
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31143 \begin_inset Text
31144
31145 \begin_layout Standard
31146 8051 monitor (hex up-/download, single step, disassemble)
31147 \end_layout
31148
31149 \end_inset
31150 </cell>
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \begin_layout Standard
31155 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31156
31157 \end_inset
31158
31159
31160 \end_layout
31161
31162 \end_inset
31163 </cell>
31164 </row>
31165 <row topline="true">
31166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31167 \begin_inset Text
31168
31169 \begin_layout Standard
31170 doxygen
31171 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31172
31173 \end_inset
31174
31175
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184 Source code documentation system
31185 \end_layout
31186
31187 \end_inset
31188 </cell>
31189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31190 \begin_inset Text
31191
31192 \begin_layout Standard
31193 \begin_inset LatexCommand \url{http://www.doxygen.org}
31194
31195 \end_inset
31196
31197
31198 \end_layout
31199
31200 \end_inset
31201 </cell>
31202 </row>
31203 <row topline="true">
31204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31205 \begin_inset Text
31206
31207 \begin_layout Standard
31208 kdevelop
31209 \end_layout
31210
31211 \end_inset
31212 </cell>
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \begin_layout Standard
31217 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31218 \end_layout
31219
31220 \end_inset
31221 </cell>
31222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31223 \begin_inset Text
31224
31225 \begin_layout Standard
31226 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31227
31228 \end_inset
31229
31230
31231 \end_layout
31232
31233 \end_inset
31234 </cell>
31235 </row>
31236 <row topline="true">
31237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31238 \begin_inset Text
31239
31240 \begin_layout Standard
31241 paulmon
31242 \end_layout
31243
31244 \end_inset
31245 </cell>
31246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31247 \begin_inset Text
31248
31249 \begin_layout Standard
31250 8051 monitor (hex up-/download, single step, disassemble)
31251 \end_layout
31252
31253 \end_inset
31254 </cell>
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31256 \begin_inset Text
31257
31258 \begin_layout Standard
31259 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31260
31261 \end_inset
31262
31263
31264 \end_layout
31265
31266 \end_inset
31267 </cell>
31268 </row>
31269 <row topline="true">
31270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31271 \begin_inset Text
31272
31273 \begin_layout Standard
31274 splint
31275 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31276
31277 \end_inset
31278
31279
31280 \end_layout
31281
31282 \end_inset
31283 </cell>
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31285 \begin_inset Text
31286
31287 \begin_layout Standard
31288 Statically checks c sources (see 
31289 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31290
31291 \end_inset
31292
31293 )
31294 \end_layout
31295
31296 \end_inset
31297 </cell>
31298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31299 \begin_inset Text
31300
31301 \begin_layout Standard
31302 \begin_inset LatexCommand \url{http://www.splint.org}
31303
31304 \end_inset
31305
31306
31307 \end_layout
31308
31309 \end_inset
31310 </cell>
31311 </row>
31312 <row topline="true" bottomline="true">
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31314 \begin_inset Text
31315
31316 \begin_layout Standard
31317 ddd
31318 \begin_inset LatexCommand \index{DDD (debugger)}
31319
31320 \end_inset
31321
31322
31323 \end_layout
31324
31325 \end_inset
31326 </cell>
31327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31328 \begin_inset Text
31329
31330 \begin_layout Standard
31331 Debugger, serves nicely as GUI to SDCDB
31332 \begin_inset LatexCommand \index{SDCDB (debugger)}
31333
31334 \end_inset
31335
31336  (Unix only)
31337 \end_layout
31338
31339 \end_inset
31340 </cell>
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31342 \begin_inset Text
31343
31344 \begin_layout Standard
31345 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31346
31347 \end_inset
31348
31349
31350 \end_layout
31351
31352 \end_inset
31353 </cell>
31354 </row>
31355 </lyxtabular>
31356
31357 \end_inset
31358
31359
31360 \newline
31361
31362 \end_layout
31363
31364 \begin_layout Section
31365 Related documentation / recommended reading
31366 \end_layout
31367
31368 \begin_layout Standard
31369 \align left
31370 \begin_inset Tabular
31371 <lyxtabular version="3" rows="7" columns="3">
31372 <features>
31373 <column alignment="left" valignment="top" leftline="true" width="0pt">
31374 <column alignment="left" valignment="top" leftline="true" width="0">
31375 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31376 <row topline="true" bottomline="true">
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31378 \begin_inset Text
31379
31380 \begin_layout Standard
31381
31382 \series bold
31383 Name
31384 \end_layout
31385
31386 \end_inset
31387 </cell>
31388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31389 \begin_inset Text
31390
31391 \begin_layout Standard
31392
31393 \series bold
31394 Subject / Title
31395 \end_layout
31396
31397 \end_inset
31398 </cell>
31399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31400 \begin_inset Text
31401
31402 \begin_layout Standard
31403
31404 \series bold
31405 Where to get
31406 \end_layout
31407
31408 \end_inset
31409 </cell>
31410 </row>
31411 <row topline="true">
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31413 \begin_inset Text
31414
31415 \begin_layout Standard
31416
31417 \family roman
31418 \series medium
31419 \shape up
31420 \size normal
31421 \emph off
31422 \bar no
31423 \noun off
31424 \color none
31425 c-refcard.pdf
31426 \end_layout
31427
31428 \end_inset
31429 </cell>
31430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31431 \begin_inset Text
31432
31433 \begin_layout Standard
31434 C Reference Card
31435 \begin_inset LatexCommand \index{C Reference card}
31436
31437 \end_inset
31438
31439 , 2 pages
31440 \end_layout
31441
31442 \end_inset
31443 </cell>
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31445 \begin_inset Text
31446
31447 \begin_layout Standard
31448 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31449
31450 \end_inset
31451
31452
31453 \end_layout
31454
31455 \end_inset
31456 </cell>
31457 </row>
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31460 \begin_inset Text
31461
31462 \begin_layout Standard
31463 c-faq
31464 \end_layout
31465
31466 \end_inset
31467 </cell>
31468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31469 \begin_inset Text
31470
31471 \begin_layout Standard
31472 C-FAQ
31473 \begin_inset LatexCommand \index{C FAQ}
31474
31475 \end_inset
31476
31477
31478 \end_layout
31479
31480 \end_inset
31481 </cell>
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31483 \begin_inset Text
31484
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.c-faq.com}
31487
31488 \end_inset
31489
31490
31491 \end_layout
31492
31493 \end_inset
31494 </cell>
31495 </row>
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \begin_layout Standard
31501 ISO/IEC 9899:TC2
31502 \end_layout
31503
31504 \end_inset
31505 </cell>
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31507 \begin_inset Text
31508
31509 \begin_layout Standard
31510 \begin_inset Quotes sld
31511 \end_inset
31512
31513 C-Standard
31514 \begin_inset Quotes srd
31515 \end_inset
31516
31517
31518 \end_layout
31519
31520 \end_inset
31521 </cell>
31522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31523 \begin_inset Text
31524
31525 \begin_layout Standard
31526
31527 \size footnotesize
31528 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31529
31530 \end_inset
31531
31532
31533 \end_layout
31534
31535 \end_inset
31536 </cell>
31537 </row>
31538 <row topline="true">
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31540 \begin_inset Text
31541
31542 \begin_layout Standard
31543 ISO/IEC DTR 18037
31544 \end_layout
31545
31546 \end_inset
31547 </cell>
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31549 \begin_inset Text
31550
31551 \begin_layout Standard
31552 \begin_inset Quotes sld
31553 \end_inset
31554
31555 Extensions for Embedded C
31556 \begin_inset Quotes srd
31557 \end_inset
31558
31559
31560 \end_layout
31561
31562 \end_inset
31563 </cell>
31564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31565 \begin_inset Text
31566
31567 \begin_layout Standard
31568
31569 \size footnotesize
31570 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31571
31572 \end_inset
31573
31574
31575 \end_layout
31576
31577 \end_inset
31578 </cell>
31579 </row>
31580 <row topline="true">
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31582 \begin_inset Text
31583
31584 \begin_layout Standard
31585
31586 \end_layout
31587
31588 \end_inset
31589 </cell>
31590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31591 \begin_inset Text
31592
31593 \begin_layout Standard
31594 Latest datasheet of target CPU
31595 \end_layout
31596
31597 \end_inset
31598 </cell>
31599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31600 \begin_inset Text
31601
31602 \begin_layout Standard
31603 vendor
31604 \end_layout
31605
31606 \end_inset
31607 </cell>
31608 </row>
31609 <row topline="true" bottomline="true">
31610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31611 \begin_inset Text
31612
31613 \begin_layout Standard
31614
31615 \end_layout
31616
31617 \end_inset
31618 </cell>
31619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31620 \begin_inset Text
31621
31622 \begin_layout Standard
31623 Revision history of datasheet
31624 \end_layout
31625
31626 \end_inset
31627 </cell>
31628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31629 \begin_inset Text
31630
31631 \begin_layout Standard
31632 vendor
31633 \end_layout
31634
31635 \end_inset
31636 </cell>
31637 </row>
31638 </lyxtabular>
31639
31640 \end_inset
31641
31642
31643 \newline
31644
31645 \end_layout
31646
31647 \begin_layout Section
31648 Application notes specifically for SDCC
31649 \end_layout
31650
31651 \begin_layout Standard
31652 SDCC makes no claims about the completeness of this list and about up-to-datenes
31653 s or correctness of the application notes
31654 \begin_inset LatexCommand \index{Application notes}
31655
31656 \end_inset
31657
31658 .
31659 \end_layout
31660
31661 \begin_layout Standard
31662 \align left
31663
31664 \size footnotesize
31665 \begin_inset Tabular
31666 <lyxtabular version="3" rows="7" columns="3">
31667 <features>
31668 <column alignment="block" valignment="top" leftline="true" width="17col%">
31669 <column alignment="block" valignment="top" leftline="true" width="27col%">
31670 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31671 <row topline="true" bottomline="true">
31672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31673 \begin_inset Text
31674
31675 \begin_layout Standard
31676
31677 \series bold
31678 \size footnotesize
31679 Vendor
31680 \end_layout
31681
31682 \end_inset
31683 </cell>
31684 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31685 \begin_inset Text
31686
31687 \begin_layout Standard
31688
31689 \series bold
31690 \size footnotesize
31691 Subject / Title
31692 \end_layout
31693
31694 \end_inset
31695 </cell>
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31697 \begin_inset Text
31698
31699 \begin_layout Standard
31700
31701 \series bold
31702 \size footnotesize
31703 Where to get
31704 \end_layout
31705
31706 \end_inset
31707 </cell>
31708 </row>
31709 <row topline="true">
31710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31711 \begin_inset Text
31712
31713 \begin_layout Standard
31714
31715 \size footnotesize
31716 Maxim / Dallas
31717 \end_layout
31718
31719 \end_inset
31720 </cell>
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31722 \begin_inset Text
31723
31724 \begin_layout Standard
31725
31726 \size footnotesize
31727 Using the SDCC Compiler for the DS80C400
31728 \begin_inset LatexCommand \index{DS80C400}
31729
31730 \end_inset
31731
31732
31733 \end_layout
31734
31735 \end_inset
31736 </cell>
31737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31738 \begin_inset Text
31739
31740 \begin_layout Standard
31741
31742 \size footnotesize
31743 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31744
31745 \end_inset
31746
31747
31748 \end_layout
31749
31750 \end_inset
31751 </cell>
31752 </row>
31753 <row topline="true">
31754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31755 \begin_inset Text
31756
31757 \begin_layout Standard
31758
31759 \size footnotesize
31760 Maxim / Dallas
31761 \end_layout
31762
31763 \end_inset
31764 </cell>
31765 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31766 \begin_inset Text
31767
31768 \begin_layout Standard
31769
31770 \size footnotesize
31771 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31772 \begin_inset LatexCommand \index{DS89C4x0}
31773
31774 \end_inset
31775
31776  Family of Microcontrollers
31777 \end_layout
31778
31779 \end_inset
31780 </cell>
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31782 \begin_inset Text
31783
31784 \begin_layout Standard
31785
31786 \size footnotesize
31787 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31788
31789 \end_inset
31790
31791
31792 \end_layout
31793
31794 \end_inset
31795 </cell>
31796 </row>
31797 <row topline="true">
31798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31799 \begin_inset Text
31800
31801 \begin_layout Standard
31802
31803 \size footnotesize
31804 Silicon Laboratories / Cygnal
31805 \end_layout
31806
31807 \end_inset
31808 </cell>
31809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31810 \begin_inset Text
31811
31812 \begin_layout Standard
31813
31814 \size footnotesize
31815 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31816 \begin_inset LatexCommand \index{IDE}
31817
31818 \end_inset
31819
31820
31821 \end_layout
31822
31823 \end_inset
31824 </cell>
31825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31826 \begin_inset Text
31827
31828 \begin_layout Standard
31829
31830 \size footnotesize
31831 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31832
31833 \end_inset
31834
31835
31836 \end_layout
31837
31838 \end_inset
31839 </cell>
31840 </row>
31841 <row topline="true">
31842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31843 \begin_inset Text
31844
31845 \begin_layout Standard
31846
31847 \size footnotesize
31848 Ramtron / Goal Semiconductor
31849 \end_layout
31850
31851 \end_inset
31852 </cell>
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31854 \begin_inset Text
31855
31856 \begin_layout Standard
31857
31858 \size footnotesize
31859 Interfacing SDCC to Syn and Textpad
31860 \end_layout
31861
31862 \end_inset
31863 </cell>
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31865 \begin_inset Text
31866
31867 \begin_layout Standard
31868
31869 \size footnotesize
31870 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31871
31872 \end_inset
31873
31874
31875 \end_layout
31876
31877 \end_inset
31878 </cell>
31879 </row>
31880 <row topline="true">
31881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31882 \begin_inset Text
31883
31884 \begin_layout Standard
31885
31886 \size footnotesize
31887 Ramtron / Goal Semiconductor
31888 \end_layout
31889
31890 \end_inset
31891 </cell>
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31893 \begin_inset Text
31894
31895 \begin_layout Standard
31896
31897 \size footnotesize
31898 Installing and Configuring SDCC and Crimson Editor 
31899 \end_layout
31900
31901 \end_inset
31902 </cell>
31903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31904 \begin_inset Text
31905
31906 \begin_layout Standard
31907
31908 \size footnotesize
31909 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31910
31911 \end_inset
31912
31913
31914 \end_layout
31915
31916 \end_inset
31917 </cell>
31918 </row>
31919 <row topline="true" bottomline="true">
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31921 \begin_inset Text
31922
31923 \begin_layout Standard
31924
31925 \size footnotesize
31926 Texas Instruments
31927 \end_layout
31928
31929 \end_inset
31930 </cell>
31931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31932 \begin_inset Text
31933
31934 \begin_layout Standard
31935
31936 \size footnotesize
31937 MSC12xx Programming with SDCC
31938 \end_layout
31939
31940 \end_inset
31941 </cell>
31942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31943 \begin_inset Text
31944
31945 \begin_layout Standard
31946
31947 \size footnotesize
31948 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31949
31950 \end_inset
31951
31952
31953 \end_layout
31954
31955 \end_inset
31956 </cell>
31957 </row>
31958 </lyxtabular>
31959
31960 \end_inset
31961
31962
31963 \end_layout
31964
31965 \begin_layout Section
31966 Some Questions
31967 \end_layout
31968
31969 \begin_layout Standard
31970 Some questions answered, some pointers given - it might be time to in turn
31971  ask 
31972 \emph on
31973 you
31974 \emph default
31975  some questions: 
31976 \end_layout
31977
31978 \begin_layout Itemize
31979 can you solve your project with the selected microcontroller? Would you
31980  find out early or rather late that your target is too small/slow/whatever?
31981  Can you switch to a slightly better device if it doesn't fit?
31982 \end_layout
31983
31984 \begin_layout Itemize
31985 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31986  and/or another programming language be more adequate? Would an operating
31987  system on the target device help?
31988 \end_layout
31989
31990 \begin_layout Itemize
31991 if you solved the problem, will the marketing department be happy?
31992 \end_layout
31993
31994 \begin_layout Itemize
31995 if the marketing department is happy, will customers be happy?
31996 \end_layout
31997
31998 \begin_layout Itemize
31999 if you're the project manager, marketing department and maybe even the customer
32000  in one person, have you tried to see the project from the outside?
32001 \end_layout
32002
32003 \begin_layout Itemize
32004 is the project done if you think it is done? Or is just that other interface/pro
32005 tocol/feature/configuration/option missing? How about website, manual(s),
32006  internationali(z|s)ation, packaging, labels, 2nd source for components,
32007  electromagnetic compatability/interference, documentation for production,
32008  production test software, update mechanism, patent issues?
32009 \end_layout
32010
32011 \begin_layout Itemize
32012 is your project adequately positioned in that magic triangle: fame, fortune,
32013  fun?
32014 \end_layout
32015
32016 \begin_layout Standard
32017 Maybe not all answers to these questions are known and some answers may
32018  even be 
32019 \emph on
32020 no
32021 \emph default
32022 , nevertheless knowing these questions may help you to avoid burnout
32023 \begin_inset Foot
32024 status open
32025
32026 \begin_layout Standard
32027 burnout is bad for electronic devices, programmers and motorcycle tyres
32028 \end_layout
32029
32030 \end_inset
32031
32032 .
32033  Chances are you didn't want to hear some of them...
32034 \end_layout
32035
32036 \begin_layout Chapter
32037 Support
32038 \begin_inset LatexCommand \index{Support}
32039
32040 \end_inset
32041
32042
32043 \end_layout
32044
32045 \begin_layout Standard
32046 SDCC has grown to be a large project.
32047  The compiler alone (without the preprocessor, assembler and linker) is
32048  well over 150,000 lines of code (blank stripped).
32049  The open source nature of this project is a key to its continued growth
32050  and support.
32051  You gain the benefit and support of many active software developers and
32052  end users.
32053  Is SDCC perfect? No, that's why we need your help.
32054  The developers take pride in fixing reported bugs.
32055  You can help by reporting the bugs and helping other SDCC users.
32056  There are lots of ways to contribute, and we encourage you to take part
32057  in making SDCC a great software package.
32058  
32059 \end_layout
32060
32061 \begin_layout Standard
32062 The SDCC project is hosted on the SDCC sourceforge site at 
32063 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32064
32065 \end_inset
32066
32067 .
32068  You'll find the complete set of mailing lists
32069 \begin_inset LatexCommand \index{Mailing list(s)}
32070
32071 \end_inset
32072
32073 , forums, bug reporting system, patch submission
32074 \begin_inset LatexCommand \index{Patch submission}
32075
32076 \end_inset
32077
32078  system, download
32079 \begin_inset LatexCommand \index{download}
32080
32081 \end_inset
32082
32083  area and Subversion code repository
32084 \begin_inset LatexCommand \index{Subversion code repository}
32085
32086 \end_inset
32087
32088  there.
32089 \end_layout
32090
32091 \begin_layout Section
32092 Reporting Bugs
32093 \begin_inset LatexCommand \index{Bug reporting}
32094
32095 \end_inset
32096
32097
32098 \begin_inset LatexCommand \index{Reporting bugs}
32099
32100 \end_inset
32101
32102
32103 \end_layout
32104
32105 \begin_layout Standard
32106 The recommended way of reporting bugs is using the infrastructure of the
32107  sourceforge site.
32108  You can follow the status of bug reports there and have an overview about
32109  the known bugs.
32110 \end_layout
32111
32112 \begin_layout Standard
32113 Bug reports are automatically forwarded to the developer mailing list and
32114  will be fixed ASAP.
32115  When reporting a bug, it is very useful to include a small test program
32116  (the smaller the better) which reproduces the problem.
32117  If you can isolate the problem by looking at the generated assembly code,
32118  this can be very helpful.
32119  Compiling your program with the -
32120 \begin_inset ERT
32121 status collapsed
32122
32123 \begin_layout Standard
32124
32125
32126 \backslash
32127 /
32128 \end_layout
32129
32130 \end_inset
32131
32132 -dumpall
32133 \begin_inset LatexCommand \index{-\/-dumpall}
32134
32135 \end_inset
32136
32137  option can sometimes be useful in locating optimization problems.
32138  When reporting a bug please make sure you:
32139 \end_layout
32140
32141 \begin_layout Enumerate
32142 Attach the code you are compiling with SDCC.
32143  
32144 \end_layout
32145
32146 \begin_layout Enumerate
32147 Specify the exact command you use to run SDCC, or attach your Makefile.
32148  
32149 \end_layout
32150
32151 \begin_layout Enumerate
32152 Specify the SDCC version (type "
32153 \family sans
32154 \series bold
32155 sdcc -v
32156 \family default
32157 \series default
32158 "), your platform, and operating system.
32159  
32160 \end_layout
32161
32162 \begin_layout Enumerate
32163 Provide an exact copy of any error message or incorrect output.
32164  
32165 \end_layout
32166
32167 \begin_layout Enumerate
32168 Put something meaningful in the subject of your message.
32169 \end_layout
32170
32171 \begin_layout Standard
32172 Please attempt to include these 5 important parts, as applicable, in all
32173  requests for support or when reporting any problems or bugs with SDCC.
32174  Though this will make your message lengthy, it will greatly improve your
32175  chance that SDCC users and developers will be able to help you.
32176  Some SDCC developers are frustrated by bug reports without code provided
32177  that they can use to reproduce and ultimately fix the problem, so please
32178  be sure to provide sample code if you are reporting a bug! 
32179 \end_layout
32180
32181 \begin_layout Standard
32182 Please have a short check that you are using a recent version of SDCC and
32183  the bug is not yet known.
32184  This is the link for reporting bugs: 
32185 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32186
32187 \end_inset
32188
32189 .
32190  With SDCC on average having more than 200 downloads
32191 \begin_inset LatexCommand \index{download}
32192
32193 \end_inset
32194
32195  on sourceforge per day
32196 \begin_inset Foot
32197 status open
32198
32199 \begin_layout Standard
32200 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32201  between 2002 and 2005.
32202  This does not include other methods of distribution.
32203 \end_layout
32204
32205 \end_inset
32206
32207  there must be some users.
32208  So it's not exactly easy to find a new bug.
32209  If you find one we need it: 
32210 \emph on
32211 reporting bugs is good
32212 \emph default
32213 .
32214 \end_layout
32215
32216 \begin_layout Section
32217 Requesting Features
32218 \begin_inset LatexCommand \label{sub:Requesting-Features}
32219
32220 \end_inset
32221
32222
32223 \begin_inset LatexCommand \index{Feature request}
32224
32225 \end_inset
32226
32227
32228 \begin_inset LatexCommand \index{Requesting features}
32229
32230 \end_inset
32231
32232
32233 \end_layout
32234
32235 \begin_layout Standard
32236 Like bug reports feature requests are forwarded to the developer mailing
32237  list.
32238  This is the link for requesting features: 
32239 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32240
32241 \end_inset
32242
32243 .
32244 \end_layout
32245
32246 \begin_layout Section
32247 Submitting patches
32248 \end_layout
32249
32250 \begin_layout Standard
32251 Like bug reports contributed patches are forwarded to the developer mailing
32252  list.
32253  This is the link for submitting patches
32254 \begin_inset LatexCommand \index{Patch submission}
32255
32256 \end_inset
32257
32258
32259 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32260
32261 \end_inset
32262
32263 .
32264 \end_layout
32265
32266 \begin_layout Standard
32267 You need to specify some parameters to the 
32268 \family typewriter
32269 diff
32270 \family default
32271  command for the patches to be useful.
32272  If you modified more than one file a patch created f.e.
32273  with 
32274 \family sans
32275 \series bold
32276
32277 \begin_inset Quotes sld
32278 \end_inset
32279
32280 diff -Naur unmodified_directory modified_directory >my_changes.patch
32281 \begin_inset Quotes srd
32282 \end_inset
32283
32284
32285 \family default
32286 \series default
32287  will be fine, otherwise 
32288 \family sans
32289 \series bold
32290
32291 \begin_inset Quotes sld
32292 \end_inset
32293
32294 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32295 \begin_inset Quotes srd
32296 \end_inset
32297
32298
32299 \series default
32300  
32301 \family default
32302 will do.
32303 \end_layout
32304
32305 \begin_layout Section
32306 Getting Help
32307 \end_layout
32308
32309 \begin_layout Standard
32310 These links should take you directly to the 
32311 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32312
32313 \end_inset
32314
32315
32316 \begin_inset Foot
32317 status open
32318
32319 \begin_layout Standard
32320 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32321  automated messages (mid 2003)
32322 \end_layout
32323
32324 \end_inset
32325
32326  and the 
32327 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32328
32329 \end_inset
32330
32331 , lists
32332 \begin_inset LatexCommand \index{Mailing list(s)}
32333
32334 \end_inset
32335
32336  and forums are archived and searchable so if you are lucky someone already
32337  had a similar problem.
32338  While mails to the lists themselves are delivered promptly their web front
32339  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32340  if you're seriously using SDCC please consider subscribing to the lists.
32341 \end_layout
32342
32343 \begin_layout Section
32344 ChangeLog
32345 \end_layout
32346
32347 \begin_layout Standard
32348 You can follow the status of the Subversion version
32349 \begin_inset LatexCommand \index{version}
32350
32351 \end_inset
32352
32353  of SDCC by watching the Changelog
32354 \begin_inset LatexCommand \index{Changelog}
32355
32356 \end_inset
32357
32358  in the Subversion repository
32359 \size footnotesize
32360  
32361 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32362
32363 \end_inset
32364
32365 .
32366 \end_layout
32367
32368 \begin_layout Section
32369 Subversion Source Code Repository
32370 \end_layout
32371
32372 \begin_layout Standard
32373 The output of 
32374 \family sans
32375 \series bold
32376 sdcc -
32377 \family default
32378
32379 \begin_inset ERT
32380 status open
32381
32382 \begin_layout Standard
32383
32384
32385 \backslash
32386 /
32387 \end_layout
32388
32389 \end_inset
32390
32391
32392 \family sans
32393 -version
32394 \family default
32395 \series default
32396  or the filenames of the snapshot versions of SDCC include date and its
32397  Subversion
32398 \begin_inset LatexCommand \index{Subversion code repository}
32399
32400 \end_inset
32401
32402  number.
32403  Subversion allows to download the source of recent or previous versions
32404  
32405 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32406
32407 \end_inset
32408
32409  (by number or by date).
32410  An on-line source code browser and detailled instructions are also available
32411  there.
32412  SDCC versions starting from 1999 up to now are available (currently the
32413  versions prior to the conversion from cvs
32414 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32415
32416 \end_inset
32417
32418  to Subversion (April 2006) are either by accessible by Subversion or by
32419  cvs).
32420 \end_layout
32421
32422 \begin_layout Section
32423 Release policy
32424 \begin_inset LatexCommand \index{Release policy}
32425
32426 \end_inset
32427
32428
32429 \end_layout
32430
32431 \begin_layout Standard
32432 Historically there often were long delays between official releases and
32433  the sourceforge download area tends to get not updated at all.
32434  Excuses in the past might have referred to problems with live range analysis,
32435  but as this was fixed a while ago, the current problem is that another
32436  excuse has to be found.
32437  Kidding aside, we have to get better there! On the other hand there are
32438  daily snapshots available at 
32439 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32440
32441 \end_inset
32442
32443 , and you can always build the very last version (hopefully with many bugs
32444  fixed, and features added) from the source code available at 
32445 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32446
32447 \end_inset
32448
32449 .
32450  The SDCC Wiki
32451 \begin_inset LatexCommand \index{wiki}
32452
32453 \end_inset
32454
32455
32456 \begin_inset LatexCommand \index{SDCC Wiki}
32457
32458 \end_inset
32459
32460  at 
32461 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32462
32463 \end_inset
32464
32465  also holds some information about past and future releases.
32466 \end_layout
32467
32468 \begin_layout Section
32469 Examples
32470 \begin_inset LatexCommand \index{Examples}
32471
32472 \end_inset
32473
32474
32475 \end_layout
32476
32477 \begin_layout Standard
32478 You'll find some small examples in the directory 
32479 \emph on
32480 sdcc/device/examples/.
32481  
32482 \emph default
32483 More examples and libraries are available at
32484 \emph on
32485  The SDCC Open Knowledge Resource 
32486 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32487
32488 \end_inset
32489
32490  
32491 \emph default
32492 web site or at 
32493 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32494
32495 \end_inset
32496
32497 .
32498 \end_layout
32499
32500 \begin_layout Standard
32501 \begin_inset Note Note
32502 status collapsed
32503
32504 \begin_layout Standard
32505 I did insert a reference to Paul's web site here although it seems rather
32506  dedicated to a specific 8032 board (I think it's okay because it f.e.
32507  shows LCD/Harddisc interface and has a free 8051 monitor.
32508  Independent 8032 board vendors face hard competition of heavily subsidized
32509  development boards anyway).
32510 \end_layout
32511
32512 \begin_layout Standard
32513 Maybe we should include some links to real world applications.
32514  Preferably pointer to pointers (one for each architecture) so this stays
32515  manageable here?
32516 \end_layout
32517
32518 \end_inset
32519
32520
32521 \end_layout
32522
32523 \begin_layout Section
32524 Quality control
32525 \begin_inset LatexCommand \label{sec:Quality-control}
32526
32527 \end_inset
32528
32529
32530 \begin_inset LatexCommand \index{Quality control}
32531
32532 \end_inset
32533
32534
32535 \end_layout
32536
32537 \begin_layout Standard
32538 The compiler is passed through snaphot build compile and build checks.
32539  The so called 
32540 \shape italic
32541 regression tests
32542 \shape default
32543
32544 \begin_inset LatexCommand \index{Regression test}
32545
32546 \end_inset
32547
32548  check that SDCC itself compiles flawlessly on several host platforms (i386,
32549  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32550  the quality of the code generated by SDCC by running the code for several
32551  target platforms through simulators.
32552  The regression test suite comprises more than 100 files which expand to
32553  more than 500 test cases which include more than 4500 tests.
32554  The results of these tests are published daily on SDCC's snapshot page
32555  (click on the red or green symbols on the right side of 
32556 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32557
32558 \end_inset
32559
32560 ).
32561 \end_layout
32562
32563 \begin_layout Standard
32564 There is a separate document 
32565 \shape italic
32566 test_suite.pdf 
32567 \begin_inset LatexCommand \index{Test suite}
32568
32569 \end_inset
32570
32571
32572 \shape default
32573  
32574 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32575
32576 \end_inset
32577
32578  about the regression test suite.
32579 \end_layout
32580
32581 \begin_layout Standard
32582 You'll find the test code in the directory 
32583 \shape italic
32584 sdcc/support/regression
32585 \shape default
32586 .
32587  You can run these tests manually by running 
32588 \family sans
32589 make
32590 \family default
32591  in this directory (or f.e.
32592  
32593 \family sans
32594 \series bold
32595
32596 \begin_inset Quotes sld
32597 \end_inset
32598
32599 make test-mcs51
32600 \begin_inset Quotes srd
32601 \end_inset
32602
32603
32604 \family default
32605 \series default
32606  if you don't want to run the complete tests).
32607  The test code might also be interesting if you want to look for examples
32608 \begin_inset LatexCommand \index{Examples}
32609
32610 \end_inset
32611
32612  checking corner cases of SDCC or if you plan to submit patches
32613 \begin_inset LatexCommand \index{Patch submission}
32614
32615 \end_inset
32616
32617 .
32618 \end_layout
32619
32620 \begin_layout Standard
32621 The PIC14 port uses a different set of regression tests 
32622 \begin_inset LatexCommand \index{Regression test (PIC14)}
32623
32624 \end_inset
32625
32626 , you'll find them in the directory 
32627 \shape italic
32628 sdcc/src/regression
32629 \shape default
32630 .
32631 \end_layout
32632
32633 \begin_layout Section
32634 Use of SDCC in Education
32635 \end_layout
32636
32637 \begin_layout Standard
32638 In short: 
32639 \emph on
32640 highly
32641 \emph default
32642  encouraged
32643 \begin_inset Foot
32644 status open
32645
32646 \begin_layout Standard
32647 the phrase "use in education" might evoke the association "
32648 \emph on
32649 only
32650 \emph default
32651  fit for use in education".
32652  This connotation is not intended but nevertheless risked as the licensing
32653  of SDCC makes it difficult to offer educational discounts
32654 \end_layout
32655
32656 \end_inset
32657
32658 .
32659  If your rationales are to:
32660 \end_layout
32661
32662 \begin_layout Enumerate
32663 give students a chance to understand the 
32664 \emph on
32665 complete
32666 \emph default
32667  steps of code generation
32668 \end_layout
32669
32670 \begin_layout Enumerate
32671 have a curriculum that can be extended for years.
32672  Then you could use an fpga board as target and your curriculum will seamlessly
32673  extend from logic synthesis (
32674 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32675
32676 \end_inset
32677
32678
32679 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32680
32681 \end_inset
32682
32683 ), over assembly programming, to C to FPGA compilers (
32684 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32685
32686 \end_inset
32687
32688 ) and to C.
32689 \end_layout
32690
32691 \begin_layout Enumerate
32692 be able to insert excursions about skills like using a revision control
32693  system, submitting/applying patches, using a type-setting (as opposed to
32694  word-processing) engine LyX/LaTeX, using 
32695 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32696
32697 \end_inset
32698
32699 , following some 
32700 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32701
32702 \end_inset
32703
32704 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32705  Source Software, CPU simulation, compiler regression tests
32706 \begin_inset LatexCommand \index{Regression test}
32707
32708 \end_inset
32709
32710 .
32711  
32712 \newline
32713 And if there should be a shortage of ideas then you can always point students
32714  to the ever-growing feature request list 
32715 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32716
32717 \end_inset
32718
32719 .
32720 \end_layout
32721
32722 \begin_layout Enumerate
32723 not tie students to a specific host platform and instead allow them to use
32724  a host platform of 
32725 \emph on
32726 their
32727 \emph default
32728  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32729  and eventually 
32730 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32731
32732 \end_inset
32733
32734 )
32735 \end_layout
32736
32737 \begin_layout Enumerate
32738 not encourage students to use illegal copies of educational software
32739 \end_layout
32740
32741 \begin_layout Enumerate
32742 be immune to licensing/availability/price changes of the chosen tool chain
32743 \end_layout
32744
32745 \begin_layout Enumerate
32746 be able to change to a new target platform without having to adopt a new
32747  tool chain
32748 \end_layout
32749
32750 \begin_layout Enumerate
32751 have complete control over and insight into the tool chain
32752 \end_layout
32753
32754 \begin_layout Enumerate
32755 make your students aware about the pros and cons of open source software
32756  development
32757 \end_layout
32758
32759 \begin_layout Enumerate
32760 give back to the public as you are probably at least partially publically
32761  funded
32762 \end_layout
32763
32764 \begin_layout Enumerate
32765 give students a chance to publically prove their skills and to possibly
32766  see a world wide impact
32767 \end_layout
32768
32769 \begin_layout Standard
32770 then SDCC is probably among the first choices.
32771  Well, probably SDCC might be the only choice.
32772 \newpage
32773
32774 \end_layout
32775
32776 \begin_layout Chapter
32777 SDCC Technical Data
32778 \end_layout
32779
32780 \begin_layout Section
32781 Optimizations
32782 \begin_inset LatexCommand \index{Optimizations}
32783
32784 \end_inset
32785
32786
32787 \end_layout
32788
32789 \begin_layout Standard
32790 SDCC performs a host of standard optimizations in addition to some MCU specific
32791  optimizations.
32792  
32793 \end_layout
32794
32795 \begin_layout Subsection
32796 Sub-expression Elimination
32797 \begin_inset LatexCommand \index{Subexpression elimination}
32798
32799 \end_inset
32800
32801
32802 \end_layout
32803
32804 \begin_layout Standard
32805 The compiler does local and 
32806 \emph on
32807 g
32808 \emph default
32809 lobal 
32810 \emph on
32811 c
32812 \emph default
32813 ommon 
32814 \emph on
32815 s
32816 \emph default
32817 ubexpression 
32818 \emph on
32819 e
32820 \emph default
32821 limination, e.g.: 
32822 \end_layout
32823
32824 \begin_layout Verse
32825
32826 \family typewriter
32827 i = x + y + 1; 
32828 \newline
32829 j = x + y;
32830 \end_layout
32831
32832 \begin_layout Standard
32833 will be translated to
32834 \end_layout
32835
32836 \begin_layout Verse
32837
32838 \family typewriter
32839 iTemp = x + y; 
32840 \newline
32841 i = iTemp + 1; 
32842 \newline
32843 j = iTemp;
32844 \end_layout
32845
32846 \begin_layout Standard
32847 Some subexpressions are not as obvious as the above example, e.g.:
32848 \end_layout
32849
32850 \begin_layout Verse
32851
32852 \family typewriter
32853 a->b[i].c = 10; 
32854 \newline
32855 a->b[i].d = 11;
32856 \end_layout
32857
32858 \begin_layout Standard
32859 In this case the address arithmetic a->b[i] will be computed only once;
32860  the equivalent code in C would be.
32861 \end_layout
32862
32863 \begin_layout Verse
32864
32865 \family typewriter
32866 iTemp = a->b[i]; 
32867 \newline
32868 iTemp.c = 10; 
32869 \newline
32870 iTemp.d = 11;
32871 \end_layout
32872
32873 \begin_layout Standard
32874 The compiler will try to keep these temporary variables in registers.
32875 \end_layout
32876
32877 \begin_layout Subsection
32878 Dead-Code Elimination
32879 \begin_inset LatexCommand \index{Dead-code elimination}
32880
32881 \end_inset
32882
32883
32884 \end_layout
32885
32886 \begin_layout Verse
32887
32888 \family typewriter
32889 int global;
32890 \newline
32891
32892 \newline
32893 void f () { 
32894 \newline
32895 \InsetSpace ~
32896 \InsetSpace ~
32897 int i; 
32898 \newline
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 i = 1; \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 /* dead store */ 
32907 \newline
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 global = 1;\InsetSpace ~
32911 /* dead
32912  store */ 
32913 \newline
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 global = 2; 
32917 \newline
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 return; 
32921 \newline
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 global = 3;\InsetSpace ~
32925 /* unreachable */ 
32926 \newline
32927 }
32928 \end_layout
32929
32930 \begin_layout Standard
32931 will be changed to
32932 \end_layout
32933
32934 \begin_layout Verse
32935
32936 \family typewriter
32937 int global;
32938 \newline
32939
32940 \newline
32941 void f () {
32942 \newline
32943 \InsetSpace ~
32944 \InsetSpace ~
32945 global = 2; 
32946 \newline
32947 }
32948 \end_layout
32949
32950 \begin_layout Subsection
32951 Copy-Propagation
32952 \begin_inset LatexCommand \index{Copy propagation}
32953
32954 \end_inset
32955
32956
32957 \end_layout
32958
32959 \begin_layout Verse
32960
32961 \family typewriter
32962 int f() { 
32963 \newline
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 int i, j; 
32967 \newline
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 i = 10; 
32971 \newline
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 j = i; 
32975 \newline
32976 \InsetSpace ~
32977 \InsetSpace ~
32978 return j; 
32979 \newline
32980 }
32981 \end_layout
32982
32983 \begin_layout Standard
32984 will be changed to 
32985 \end_layout
32986
32987 \begin_layout Verse
32988
32989 \family typewriter
32990 int f() { 
32991 \newline
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 int i, j; 
32995 \newline
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 i = 10; 
32999 \newline
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 j = 10; 
33003 \newline
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 return 10; 
33007 \newline
33008 }
33009 \end_layout
33010
33011 \begin_layout Standard
33012 Note: the dead stores created by this copy propagation will be eliminated
33013  by dead-code elimination.
33014 \end_layout
33015
33016 \begin_layout Subsection
33017 Loop Optimizations
33018 \begin_inset LatexCommand \index{Loop optimization}
33019
33020 \end_inset
33021
33022
33023 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33024
33025 \end_inset
33026
33027
33028 \end_layout
33029
33030 \begin_layout Standard
33031 Two types of loop optimizations are done by SDCC 
33032 \emph on
33033 loop invariant
33034 \emph default
33035  lifting and
33036 \emph on
33037  strength reduction
33038 \emph default
33039  of loop induction variables.
33040  In addition to the strength reduction the optimizer marks the induction
33041  variables and the register allocator tries to keep the induction variables
33042  in registers for the duration of the loop.
33043  Because of this preference of the register allocator
33044 \begin_inset LatexCommand \index{Register allocation}
33045
33046 \end_inset
33047
33048 , loop induction optimization causes an increase in register pressure, which
33049  may cause unwanted spilling of other temporary variables into the stack
33050 \begin_inset LatexCommand \index{stack}
33051
33052 \end_inset
33053
33054  / data space.
33055  The compiler will generate a warning message when it is forced to allocate
33056  extra space either on the stack or data space.
33057  If this extra space allocation is undesirable then induction optimization
33058  can be eliminated either for the entire source file (with -
33059 \begin_inset ERT
33060 status collapsed
33061
33062 \begin_layout Standard
33063
33064
33065 \backslash
33066 /
33067 \end_layout
33068
33069 \end_inset
33070
33071 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33072 noinduction
33073 \begin_inset LatexCommand \index{\#pragma noinduction}
33074
33075 \end_inset
33076
33077 .
33078 \newline
33079
33080 \newline
33081 Loop Invariant:
33082 \end_layout
33083
33084 \begin_layout Verse
33085
33086 \family typewriter
33087 for (i = 0 ; i < 100 ; i ++) 
33088 \newline
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 f += k + l;
33094 \end_layout
33095
33096 \begin_layout Standard
33097 changed to
33098 \end_layout
33099
33100 \begin_layout Verse
33101
33102 \family typewriter
33103 itemp = k + l; 
33104 \newline
33105 for (i = 0; i < 100; i++) 
33106 \newline
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 f += itemp;
33112 \end_layout
33113
33114 \begin_layout Standard
33115 As mentioned previously some loop invariants are not as apparent, all static
33116  address computations are also moved out of the loop.
33117 \newline
33118
33119 \newline
33120 Strength Reduction
33121 \begin_inset LatexCommand \index{Strength reduction}
33122
33123 \end_inset
33124
33125 , this optimization substitutes an expression by a cheaper expression:
33126 \end_layout
33127
33128 \begin_layout Verse
33129
33130 \family typewriter
33131 for (i=0;i < 100; i++)
33132 \newline
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 ar[i*5] = i*3;
33138 \end_layout
33139
33140 \begin_layout Standard
33141 changed to
33142 \end_layout
33143
33144 \begin_layout Verse
33145
33146 \family typewriter
33147 itemp1 = 0; 
33148 \newline
33149 itemp2 = 0; 
33150 \newline
33151 for (i=0;i< 100;i++) { 
33152 \newline
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 ar[itemp1] = itemp2; 
33158 \newline
33159 \InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 itemp1
33164  += 5; 
33165 \newline
33166 \InsetSpace ~
33167 \InsetSpace ~
33168 \InsetSpace ~
33169 \InsetSpace ~
33170 itemp2 += 3; 
33171 \newline
33172 }
33173 \end_layout
33174
33175 \begin_layout Standard
33176 The more expensive multiplication
33177 \begin_inset LatexCommand \index{Multiplication}
33178
33179 \end_inset
33180
33181  is changed to a less expensive addition.
33182 \end_layout
33183
33184 \begin_layout Subsection
33185 Loop Reversing
33186 \begin_inset LatexCommand \index{Loop reversing}
33187
33188 \end_inset
33189
33190
33191 \end_layout
33192
33193 \begin_layout Standard
33194 This optimization is done to reduce the overhead of checking loop boundaries
33195  for every iteration.
33196  Some simple loops can be reversed and implemented using a 
33197 \begin_inset Quotes eld
33198 \end_inset
33199
33200 decrement and jump if not zero
33201 \begin_inset Quotes erd
33202 \end_inset
33203
33204  instruction.
33205  SDCC checks for the following criterion to determine if a loop is reversible
33206  (note: more sophisticated compilers use data-dependency analysis to make
33207  this determination, SDCC uses a more simple minded analysis).
33208 \end_layout
33209
33210 \begin_layout Itemize
33211 The 'for' loop is of the form 
33212 \newline
33213
33214 \newline
33215
33216 \family typewriter
33217 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33218  += 1])
33219 \newline
33220 \InsetSpace ~
33221 \InsetSpace ~
33222 \InsetSpace ~
33223 \InsetSpace ~
33224 <for body>
33225 \end_layout
33226
33227 \begin_layout Itemize
33228 The <for body> does not contain 
33229 \begin_inset Quotes eld
33230 \end_inset
33231
33232 continue
33233 \begin_inset Quotes erd
33234 \end_inset
33235
33236  or 'break
33237 \begin_inset Quotes erd
33238 \end_inset
33239
33240 .
33241 \end_layout
33242
33243 \begin_layout Itemize
33244 All goto's are contained within the loop.
33245 \end_layout
33246
33247 \begin_layout Itemize
33248 No function calls within the loop.
33249 \end_layout
33250
33251 \begin_layout Itemize
33252 The loop control variable <sym> is not assigned any value within the loop
33253 \end_layout
33254
33255 \begin_layout Itemize
33256 The loop control variable does NOT participate in any arithmetic operation
33257  within the loop.
33258 \end_layout
33259
33260 \begin_layout Itemize
33261 There are NO switch statements in the loop.
33262 \end_layout
33263
33264 \begin_layout Subsection
33265 Algebraic Simplifications
33266 \end_layout
33267
33268 \begin_layout Standard
33269 SDCC does numerous algebraic simplifications, the following is a small sub-set
33270  of these optimizations.
33271 \end_layout
33272
33273 \begin_layout Verse
33274
33275 \family typewriter
33276 i = j + 0;\InsetSpace ~
33277 \InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280  /* changed to: */\InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284  i = j; 
33285 \newline
33286 i /= 2;\InsetSpace ~
33287 \InsetSpace ~
33288 \InsetSpace ~
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293  /* changed to: */\InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297  i >>= 1; 
33298 \newline
33299 i
33300  = j - j;\InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304  /* changed to: */\InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308  i = 0; 
33309 \newline
33310 i = j / 1;\InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314  /* changed to: */\InsetSpace ~
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 \InsetSpace ~
33318  i = j;
33319 \end_layout
33320
33321 \begin_layout Standard
33322 Note the subexpressions
33323 \begin_inset LatexCommand \index{Subexpression}
33324
33325 \end_inset
33326
33327  given above are generally introduced by macro expansions or as a result
33328  of copy/constant propagation.
33329 \end_layout
33330
33331 \begin_layout Subsection
33332 'switch' Statements
33333 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33334
33335 \end_inset
33336
33337
33338 \begin_inset LatexCommand \index{switch statement}
33339
33340 \end_inset
33341
33342
33343 \end_layout
33344
33345 \begin_layout Standard
33346 SDCC can optimize switch statements to jump tables
33347 \begin_inset LatexCommand \index{jump tables}
33348
33349 \end_inset
33350
33351 .
33352  It makes the decision based on an estimate of the generated code size.
33353  SDCC is quite liberal in the requirements for jump table generation: 
33354 \end_layout
33355
33356 \begin_layout Itemize
33357 The labels need not be in order, and the starting number need not be one
33358  or zero, the case labels are in numerical sequence or not too many case
33359  labels are missing.
33360 \end_layout
33361
33362 \begin_deeper
33363 \begin_layout Verse
33364
33365 \family typewriter
33366 switch(i) {\InsetSpace ~
33367 \InsetSpace ~
33368 \InsetSpace ~
33369 \InsetSpace ~
33370 \InsetSpace ~
33371 \InsetSpace ~
33372 \InsetSpace ~
33373 \InsetSpace ~
33374 \InsetSpace ~
33375 \InsetSpace ~
33376 \InsetSpace ~
33377 \InsetSpace ~
33378 \InsetSpace ~
33379 \InsetSpace ~
33380 \InsetSpace ~
33381 \InsetSpace ~
33382 \InsetSpace ~
33383 \InsetSpace ~
33384 \InsetSpace ~
33385 \InsetSpace ~
33386 \InsetSpace ~
33387 \InsetSpace ~
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 \InsetSpace ~
33391 \InsetSpace ~
33392 switch (i) { 
33393 \newline
33394 \InsetSpace ~
33395 \InsetSpace ~
33396 \InsetSpace ~
33397 case 4: ...\InsetSpace ~
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 \InsetSpace ~
33401 \InsetSpace ~
33402 \InsetSpace ~
33403 \InsetSpace ~
33404 \InsetSpace ~
33405 \InsetSpace ~
33406 \InsetSpace ~
33407 \InsetSpace ~
33408 \InsetSpace ~
33409 \InsetSpace ~
33410 \InsetSpace ~
33411 \InsetSpace ~
33412 \InsetSpace ~
33413 \InsetSpace ~
33414 \InsetSpace ~
33415 \InsetSpace ~
33416 \InsetSpace ~
33417 \InsetSpace ~
33418 \InsetSpace ~
33419 \InsetSpace ~
33420 \InsetSpace ~
33421 \InsetSpace ~
33422 \InsetSpace ~
33423 case 0: ...
33424  
33425 \newline
33426 \InsetSpace ~
33427 \InsetSpace ~
33428 \InsetSpace ~
33429 case 5: ...\InsetSpace ~
33430 \InsetSpace ~
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 \InsetSpace ~
33434 \InsetSpace ~
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 \InsetSpace ~
33438 \InsetSpace ~
33439 \InsetSpace ~
33440 \InsetSpace ~
33441 \InsetSpace ~
33442 \InsetSpace ~
33443 \InsetSpace ~
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 \InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450 \InsetSpace ~
33451 \InsetSpace ~
33452 \InsetSpace ~
33453 \InsetSpace ~
33454 \InsetSpace ~
33455 case 1: ...
33456  
33457 \newline
33458 \InsetSpace ~
33459 \InsetSpace ~
33460 \InsetSpace ~
33461 case 3: ...\InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464 \InsetSpace ~
33465 \InsetSpace ~
33466 \InsetSpace ~
33467 \InsetSpace ~
33468 \InsetSpace ~
33469 \InsetSpace ~
33470 \InsetSpace ~
33471 \InsetSpace ~
33472 \InsetSpace ~
33473 \InsetSpace ~
33474 \InsetSpace ~
33475 \InsetSpace ~
33476 \InsetSpace ~
33477 \InsetSpace ~
33478 \InsetSpace ~
33479 \InsetSpace ~
33480 \InsetSpace ~
33481 \InsetSpace ~
33482 \InsetSpace ~
33483 \InsetSpace ~
33484 \InsetSpace ~
33485 \InsetSpace ~
33486 \InsetSpace ~
33487
33488 \newline
33489 \InsetSpace ~
33490 \InsetSpace ~
33491 \InsetSpace ~
33492 case 6: ...\InsetSpace ~
33493 \InsetSpace ~
33494 \InsetSpace ~
33495 \InsetSpace ~
33496 \InsetSpace ~
33497 \InsetSpace ~
33498 \InsetSpace ~
33499 \InsetSpace ~
33500 \InsetSpace ~
33501 \InsetSpace ~
33502 \InsetSpace ~
33503 \InsetSpace ~
33504 \InsetSpace ~
33505 \InsetSpace ~
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 \InsetSpace ~
33510 \InsetSpace ~
33511 \InsetSpace ~
33512 \InsetSpace ~
33513 \InsetSpace ~
33514 \InsetSpace ~
33515 \InsetSpace ~
33516 \InsetSpace ~
33517 \InsetSpace ~
33518 case 3: ...
33519  
33520 \newline
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 case 7: ...\InsetSpace ~
33525 \InsetSpace ~
33526 \InsetSpace ~
33527 \InsetSpace ~
33528 \InsetSpace ~
33529 \InsetSpace ~
33530 \InsetSpace ~
33531 \InsetSpace ~
33532 \InsetSpace ~
33533 \InsetSpace ~
33534 \InsetSpace ~
33535 \InsetSpace ~
33536 \InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 case 4: ...
33551  
33552 \newline
33553 \InsetSpace ~
33554 \InsetSpace ~
33555 \InsetSpace ~
33556 case 8: ...\InsetSpace ~
33557 \InsetSpace ~
33558 \InsetSpace ~
33559 \InsetSpace ~
33560 \InsetSpace ~
33561 \InsetSpace ~
33562 \InsetSpace ~
33563 \InsetSpace ~
33564 \InsetSpace ~
33565 \InsetSpace ~
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 \InsetSpace ~
33569 \InsetSpace ~
33570 \InsetSpace ~
33571 \InsetSpace ~
33572 \InsetSpace ~
33573 \InsetSpace ~
33574 \InsetSpace ~
33575 \InsetSpace ~
33576 \InsetSpace ~
33577 \InsetSpace ~
33578 \InsetSpace ~
33579 \InsetSpace ~
33580 \InsetSpace ~
33581 \InsetSpace ~
33582 case 5: ...
33583  
33584 \newline
33585 \InsetSpace ~
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 case 9: ...\InsetSpace ~
33589 \InsetSpace ~
33590 \InsetSpace ~
33591 \InsetSpace ~
33592 \InsetSpace ~
33593 \InsetSpace ~
33594 \InsetSpace ~
33595 \InsetSpace ~
33596 \InsetSpace ~
33597 \InsetSpace ~
33598 \InsetSpace ~
33599 \InsetSpace ~
33600 \InsetSpace ~
33601 \InsetSpace ~
33602 \InsetSpace ~
33603 \InsetSpace ~
33604 \InsetSpace ~
33605 \InsetSpace ~
33606 \InsetSpace ~
33607 \InsetSpace ~
33608 \InsetSpace ~
33609 \InsetSpace ~
33610 \InsetSpace ~
33611 \InsetSpace ~
33612 \InsetSpace ~
33613 \InsetSpace ~
33614 case 6: ...
33615  
33616 \newline
33617 \InsetSpace ~
33618 \InsetSpace ~
33619 \InsetSpace ~
33620 case 10: ...\InsetSpace ~
33621 \InsetSpace ~
33622 \InsetSpace ~
33623 \InsetSpace ~
33624 \InsetSpace ~
33625 \InsetSpace ~
33626 \InsetSpace ~
33627 \InsetSpace ~
33628 \InsetSpace ~
33629 \InsetSpace ~
33630 \InsetSpace ~
33631 \InsetSpace ~
33632 \InsetSpace ~
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 \InsetSpace ~
33636 \InsetSpace ~
33637 \InsetSpace ~
33638 \InsetSpace ~
33639 \InsetSpace ~
33640 \InsetSpace ~
33641 \InsetSpace ~
33642 \InsetSpace ~
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 case 7: ...
33646  
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 \InsetSpace ~
33651 case 11: ...\InsetSpace ~
33652 \InsetSpace ~
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 \InsetSpace ~
33656 \InsetSpace ~
33657 \InsetSpace ~
33658 \InsetSpace ~
33659 \InsetSpace ~
33660 \InsetSpace ~
33661 \InsetSpace ~
33662 \InsetSpace ~
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 \InsetSpace ~
33666 \InsetSpace ~
33667 \InsetSpace ~
33668 \InsetSpace ~
33669 \InsetSpace ~
33670 \InsetSpace ~
33671 \InsetSpace ~
33672 \InsetSpace ~
33673 \InsetSpace ~
33674 \InsetSpace ~
33675 \InsetSpace ~
33676 case 8: ...
33677  
33678 \newline
33679 }\InsetSpace ~
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 \InsetSpace ~
33683 \InsetSpace ~
33684 \InsetSpace ~
33685 \InsetSpace ~
33686 \InsetSpace ~
33687 \InsetSpace ~
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 \InsetSpace ~
33691 \InsetSpace ~
33692 \InsetSpace ~
33693 \InsetSpace ~
33694 \InsetSpace ~
33695 \InsetSpace ~
33696 \InsetSpace ~
33697 \InsetSpace ~
33698 \InsetSpace ~
33699 \InsetSpace ~
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 \InsetSpace ~
33703 \InsetSpace ~
33704 \InsetSpace ~
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 \InsetSpace ~
33708 \InsetSpace ~
33709 \InsetSpace ~
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 \InsetSpace ~
33713 \InsetSpace ~
33714 \InsetSpace ~
33715 }
33716 \end_layout
33717
33718 \begin_layout Standard
33719 Both the above switch statements will be implemented using a jump-table.
33720  The example to the right side is slightly more efficient as the check for
33721  the lower boundary of the jump-table is not needed.
33722 \end_layout
33723
33724 \end_deeper
33725 \begin_layout Itemize
33726 The number of case labels is not larger than supported by the target architectur
33727 e.
33728 \end_layout
33729
33730 \begin_layout Itemize
33731 If the case labels are not in numerical sequence ('gaps' between cases)
33732  SDCC checks whether a jump table with additionally inserted dummy cases
33733  is still attractive.
33734  
33735 \end_layout
33736
33737 \begin_layout Itemize
33738 If the starting number is not zero and a check for the lower boundary of
33739  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33740  ...
33741  .
33742 \end_layout
33743
33744 \begin_layout Standard
33745 Switch statements which have large gaps in the numeric sequence or those
33746  that have too many case labels can be split into more than one switch statement
33747  for efficient code generation, e.g.:
33748 \end_layout
33749
33750 \begin_layout Verse
33751
33752 \family typewriter
33753 switch (i) { 
33754 \newline
33755 \InsetSpace ~
33756 \InsetSpace ~
33757 case 1: ...
33758  
33759 \newline
33760 \InsetSpace ~
33761 \InsetSpace ~
33762 case 2: ...
33763  
33764 \newline
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 case 3: ...
33768  
33769 \newline
33770 \InsetSpace ~
33771 \InsetSpace ~
33772 case 4: ...
33773  
33774 \newline
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 case 5: ...
33778  
33779 \newline
33780 \InsetSpace ~
33781 \InsetSpace ~
33782 case 6: ...
33783  
33784 \newline
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 case 7: ...
33788  
33789 \newline
33790 \InsetSpace ~
33791 \InsetSpace ~
33792 case 101: ...
33793  
33794 \newline
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 case 102: ...
33798  
33799 \newline
33800 \InsetSpace ~
33801 \InsetSpace ~
33802 case 103: ...
33803  
33804 \newline
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 case 104: ...
33808  
33809 \newline
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 case 105: ...
33813  
33814 \newline
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 case 106: ...
33818  
33819 \newline
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 case 107: ...
33823  
33824 \newline
33825 }
33826 \end_layout
33827
33828 \begin_layout Standard
33829 If the above switch statement is broken down into two switch statements
33830 \end_layout
33831
33832 \begin_layout Verse
33833
33834 \family typewriter
33835 switch (i) { 
33836 \newline
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 case 1: ...
33840  
33841 \newline
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 case 2: ...
33845  
33846 \newline
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 case 3: ...
33850  
33851 \newline
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 case 4: ...
33855  
33856 \newline
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 case 5: ...
33860  
33861 \newline
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 case 6: ...
33865  
33866 \newline
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 case 7: ...
33870  
33871 \newline
33872 }
33873 \end_layout
33874
33875 \begin_layout Standard
33876 and
33877 \end_layout
33878
33879 \begin_layout Verse
33880
33881 \family typewriter
33882 switch (i) { 
33883 \newline
33884 \InsetSpace ~
33885 \InsetSpace ~
33886 case 101: ...
33887  
33888 \newline
33889 \InsetSpace ~
33890 \InsetSpace ~
33891 case 102: ...
33892  
33893 \newline
33894 \InsetSpace ~
33895 \InsetSpace ~
33896 case 103: ...
33897  
33898 \newline
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 case 104: ...
33902  
33903 \newline
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 case 105: ...
33907  
33908 \newline
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 case 106: ...
33912  
33913 \newline
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 case 107: ...
33917  
33918 \newline
33919 }
33920 \end_layout
33921
33922 \begin_layout Standard
33923 then both the switch statements will be implemented using jump-tables whereas
33924  the unmodified switch statement will not be.
33925 \end_layout
33926
33927 \begin_layout Standard
33928 \begin_inset Note Note
33929 status collapsed
33930
33931 \begin_layout Standard
33932 There might be reasons which SDCC cannot know about to either favour or
33933  not favour jump tables.
33934  If the target system has to be as quick for the last switch case as for
33935  the first (pro jump table), or if the switch argument is known to be zero
33936  in the majority of the cases (contra jump table).
33937 \end_layout
33938
33939 \end_inset
33940
33941
33942 \end_layout
33943
33944 \begin_layout Standard
33945 The pragma nojtbound
33946 \begin_inset LatexCommand \index{\#pragma nojtbound}
33947
33948 \end_inset
33949
33950  can be used to turn off checking the 
33951 \emph on
33952 j
33953 \emph default
33954 ump 
33955 \emph on
33956 t
33957 \emph default
33958 able 
33959 \emph on
33960 bound
33961 \emph default
33962 aries.
33963  It has no effect if a default label is supplied.
33964  Use of this pragma is dangerous: if the switch
33965 \begin_inset LatexCommand \index{switch statement}
33966
33967 \end_inset
33968
33969  argument is not matched by a case statement the processor will happily
33970  jump into Nirvana.
33971 \end_layout
33972
33973 \begin_layout Subsection
33974 Bit-shifting Operations
33975 \begin_inset LatexCommand \index{Bit shifting}
33976
33977 \end_inset
33978
33979 .
33980 \end_layout
33981
33982 \begin_layout Standard
33983 Bit shifting is one of the most frequently used operation in embedded programmin
33984 g.
33985  SDCC tries to implement bit-shift operations in the most efficient way
33986  possible, e.g.:
33987 \end_layout
33988
33989 \begin_layout Verse
33990
33991 \family typewriter
33992 unsigned char i;
33993 \newline
33994 ...
33995  
33996 \newline
33997 i >>= 4; 
33998 \newline
33999 ...
34000 \end_layout
34001
34002 \begin_layout Standard
34003 generates the following code:
34004 \end_layout
34005
34006 \begin_layout Verse
34007
34008 \family typewriter
34009 mov\InsetSpace ~
34010  a,_i 
34011 \newline
34012 swap a 
34013 \newline
34014 anl\InsetSpace ~
34015  a,#0x0f 
34016 \newline
34017 mov\InsetSpace ~
34018  _i,a
34019 \end_layout
34020
34021 \begin_layout Standard
34022 In general SDCC will never setup a loop if the shift count is known.
34023  Another example:
34024 \end_layout
34025
34026 \begin_layout Verse
34027
34028 \family typewriter
34029 unsigned int i; 
34030 \newline
34031 ...
34032  
34033 \newline
34034 i >>= 9; 
34035 \newline
34036 ...
34037 \end_layout
34038
34039 \begin_layout Standard
34040 will generate:
34041 \end_layout
34042
34043 \begin_layout Verse
34044
34045 \family typewriter
34046 mov\InsetSpace ~
34047 \InsetSpace ~
34048 a,(_i + 1) 
34049 \newline
34050 mov\InsetSpace ~
34051 \InsetSpace ~
34052 (_i + 1),#0x00 
34053 \newline
34054 clr\InsetSpace ~
34055 \InsetSpace ~
34056
34057 \newline
34058 rrc\InsetSpace ~
34059 \InsetSpace ~
34060
34061 \newline
34062 mov\InsetSpace ~
34063 \InsetSpace ~
34064 _i,a
34065 \end_layout
34066
34067 \begin_layout Subsection
34068 Bit-rotation
34069 \begin_inset LatexCommand \index{Bit rotation}
34070
34071 \end_inset
34072
34073
34074 \end_layout
34075
34076 \begin_layout Standard
34077 A special case of the bit-shift operation is bit rotation
34078 \begin_inset LatexCommand \index{rotating bits}
34079
34080 \end_inset
34081
34082 , SDCC recognizes the following expression to be a left bit-rotation:
34083 \end_layout
34084
34085 \begin_layout Verse
34086
34087 \family typewriter
34088 \series bold
34089 unsigned
34090 \series default
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 char i;\InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104 /* unsigned is needed for rotation */ 
34105 \newline
34106 ...
34107  
34108 \newline
34109 i = ((i << 1) | (i >> 7)); 
34110 \family default
34111
34112 \newline
34113
34114 \family typewriter
34115 ...
34116 \end_layout
34117
34118 \begin_layout Standard
34119 will generate the following code:
34120 \end_layout
34121
34122 \begin_layout Verse
34123
34124 \family typewriter
34125 mov\InsetSpace ~
34126 \InsetSpace ~
34127 a,_i 
34128 \newline
34129 rl\InsetSpace ~
34130 \InsetSpace ~
34131 \InsetSpace ~
34132
34133 \newline
34134 mov\InsetSpace ~
34135 \InsetSpace ~
34136 _i,a
34137 \end_layout
34138
34139 \begin_layout Standard
34140 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34141 ns of this case will also be recognized as bit-rotation, i.e.: 
34142 \end_layout
34143
34144 \begin_layout Verse
34145
34146 \family typewriter
34147 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34148 \end_layout
34149
34150 \begin_layout Subsection
34151 Nibble and Byte Swapping
34152 \end_layout
34153
34154 \begin_layout Standard
34155 Other special cases of the bit-shift operations are nibble or byte swapping
34156 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34157
34158 \end_inset
34159
34160 , SDCC recognizes the following expressions:
34161 \end_layout
34162
34163 \begin_layout Verse
34164
34165 \family typewriter
34166 \series bold
34167 unsigned
34168 \series default
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 char i; 
34172 \newline
34173
34174 \series bold
34175 unsigned
34176 \series default
34177 \InsetSpace ~
34178 \InsetSpace ~
34179 int j; 
34180 \newline
34181 ...
34182  
34183 \newline
34184 i = ((i << 4) | (i >> 4)); 
34185 \family default
34186
34187 \newline
34188
34189 \family typewriter
34190 j = ((j << 8) | (j >> 8)); 
34191 \end_layout
34192
34193 \begin_layout Standard
34194 and generates a swap instruction for the nibble swapping
34195 \begin_inset LatexCommand \index{Nibble swapping}
34196
34197 \end_inset
34198
34199  or move instructions for the byte swapping
34200 \begin_inset LatexCommand \index{Byte swapping}
34201
34202 \end_inset
34203
34204 .
34205  The 
34206 \begin_inset Quotes sld
34207 \end_inset
34208
34209 j
34210 \begin_inset Quotes srd
34211 \end_inset
34212
34213  example can be used to convert from little to big-endian or vice versa.
34214  If you want to change the endianness of a 
34215 \emph on
34216 signed
34217 \emph default
34218  integer you have to cast to 
34219 \family typewriter
34220 (unsigned int)
34221 \family default
34222  first.
34223 \end_layout
34224
34225 \begin_layout Standard
34226 Note that SDCC stores numbers in little-endian
34227 \begin_inset Foot
34228 status open
34229
34230 \begin_layout Standard
34231 Usually 8-bit processors don't care much about endianness.
34232  This is not the case for the standard 8051 which only has an instruction
34233  to increment its 
34234 \emph on
34235 dptr
34236 \emph default
34237
34238 \begin_inset LatexCommand \index{DPTR}
34239
34240 \end_inset
34241
34242 -datapointer
34243 \emph on
34244  
34245 \emph default
34246 so little-endian is the more efficient byte order.
34247 \end_layout
34248
34249 \end_inset
34250
34251
34252 \begin_inset LatexCommand \index{little-endian}
34253
34254 \end_inset
34255
34256
34257 \begin_inset LatexCommand \index{Endianness}
34258
34259 \end_inset
34260
34261  format (i.e.
34262  lowest order first).
34263 \end_layout
34264
34265 \begin_layout Subsection
34266 Highest Order Bit
34267 \begin_inset LatexCommand \index{Highest Order Bit}
34268
34269 \end_inset
34270
34271  / Any Order Bit
34272 \begin_inset LatexCommand \index{Any Order Bit}
34273
34274 \end_inset
34275
34276
34277 \end_layout
34278
34279 \begin_layout Standard
34280 It is frequently required to obtain the highest order bit of an integral
34281  type (long, int, short or char types).
34282  Also obtaining any other order bit is not uncommon.
34283  SDCC recognizes the following expressions to yield the highest order bit
34284  and generates optimized code for it, e.g.:
34285 \end_layout
34286
34287 \begin_layout Verse
34288
34289 \family typewriter
34290 unsigned int gint; 
34291 \newline
34292
34293 \newline
34294 foo () { 
34295 \newline
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 unsigned char hob1, aob1; 
34299 \newline
34300 \InsetSpace ~
34301 \InsetSpace ~
34302 bit hob2, hob3, aob2,
34303  aob3; 
34304 \newline
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 ...
34308  
34309 \newline
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 hob1 = (gint >> 15) & 1; 
34313 \newline
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 hob2 = (gint >> 15) & 1; 
34317 \newline
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 hob3 = gint & 0x8000;
34321  
34322 \newline
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 aob1 = (gint >> 9) & 1; 
34326 \newline
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 aob2 = (gint >> 8) & 1; 
34330 \newline
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 aob3 = gint & 0x0800; 
34334 \newline
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 ..
34338  
34339 \newline
34340 }
34341 \end_layout
34342
34343 \begin_layout Standard
34344 will generate the following code:
34345 \end_layout
34346
34347 \begin_layout Verse
34348
34349 \family typewriter
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375  61 ;\InsetSpace ~
34376  hob.c 7 
34377 \newline
34378 000A E5*01\InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393  62\InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401  mov\InsetSpace ~
34402 \InsetSpace ~
34403  a,(_gint + 1) 
34404 \newline
34405 000C 23\InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423  63\InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431  rl\InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434  a 
34435 \newline
34436 000D 54 01\InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451
34452  64\InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460  anl\InsetSpace ~
34461 \InsetSpace ~
34462  a,#0x01 
34463 \newline
34464 000F F5*02\InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479  65\InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487  mov\InsetSpace ~
34488 \InsetSpace ~
34489  _foo_hob1_1_1,a 
34490 \newline
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516  66 ;\InsetSpace ~
34517  hob.c 8 
34518 \newline
34519 0011 E5*01\InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534
34535  67\InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543  mov\InsetSpace ~
34544 \InsetSpace ~
34545  a,(_gint + 1) 
34546 \newline
34547 0013 33\InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565  68\InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573  rlc\InsetSpace ~
34574 \InsetSpace ~
34575  a 
34576 \newline
34577 0014 92*00\InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 \InsetSpace ~
34592  69\InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600  mov\InsetSpace ~
34601 \InsetSpace ~
34602  _foo_hob2_1_1,c
34603  
34604 \newline
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630  66 ;\InsetSpace ~
34631  hob.c 9 
34632 \newline
34633 0016 E5*01\InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648  67\InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656  mov\InsetSpace ~
34657 \InsetSpace ~
34658  a,(_gint + 1) 
34659 \newline
34660 0018 33\InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678  68\InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686  rlc\InsetSpace ~
34687 \InsetSpace ~
34688  a 
34689 \newline
34690 0019 92*01\InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705
34706  69\InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714  mov\InsetSpace ~
34715 \InsetSpace ~
34716  _foo_hob3_1_1,c 
34717 \newline
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743  70 ;\InsetSpace ~
34744  hob.c 10 
34745 \newline
34746 001B E5*01\InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761  71\InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769  mov\InsetSpace ~
34770 \InsetSpace ~
34771  a,(_gint + 1) 
34772 \newline
34773 001D
34774  03\InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792  72\InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800  rr\InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803  a 
34804 \newline
34805 001E 54 01\InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820  73\InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828  anl\InsetSpace ~
34829 \InsetSpace ~
34830  a,#0x01 
34831 \newline
34832 0020 F5*03\InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847  74\InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855  mov\InsetSpace ~
34856 \InsetSpace ~
34857  _foo_aob1_1_1,a
34858  
34859 \newline
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885  75 ;\InsetSpace ~
34886  hob.c 11 
34887 \newline
34888 0022 E5*01\InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900 \InsetSpace ~
34901 \InsetSpace ~
34902 \InsetSpace ~
34903  76\InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908 \InsetSpace ~
34909 \InsetSpace ~
34910 \InsetSpace ~
34911  mov\InsetSpace ~
34912 \InsetSpace ~
34913  a,(_gint + 1) 
34914 \newline
34915 0024 13\InsetSpace ~
34916 \InsetSpace ~
34917 \InsetSpace ~
34918 \InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925 \InsetSpace ~
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 \InsetSpace ~
34929 \InsetSpace ~
34930 \InsetSpace ~
34931 \InsetSpace ~
34932 \InsetSpace ~
34933  77\InsetSpace ~
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 \InsetSpace ~
34937 \InsetSpace ~
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 \InsetSpace ~
34941  rrc\InsetSpace ~
34942 \InsetSpace ~
34943  a 
34944 \newline
34945 0025 92*02\InsetSpace ~
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 \InsetSpace ~
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 \InsetSpace ~
34955 \InsetSpace ~
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 \InsetSpace ~
34959 \InsetSpace ~
34960
34961  78\InsetSpace ~
34962 \InsetSpace ~
34963 \InsetSpace ~
34964 \InsetSpace ~
34965 \InsetSpace ~
34966 \InsetSpace ~
34967 \InsetSpace ~
34968 \InsetSpace ~
34969  mov\InsetSpace ~
34970 \InsetSpace ~
34971  _foo_aob2_1_1,c 
34972 \newline
34973 \InsetSpace ~
34974 \InsetSpace ~
34975 \InsetSpace ~
34976 \InsetSpace ~
34977 \InsetSpace ~
34978 \InsetSpace ~
34979 \InsetSpace ~
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 \InsetSpace ~
34985 \InsetSpace ~
34986 \InsetSpace ~
34987 \InsetSpace ~
34988 \InsetSpace ~
34989 \InsetSpace ~
34990 \InsetSpace ~
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 \InsetSpace ~
34997 \InsetSpace ~
34998  79 ;\InsetSpace ~
34999  hob.c 12 
35000 \newline
35001 0027 E5*01\InsetSpace ~
35002 \InsetSpace ~
35003 \InsetSpace ~
35004 \InsetSpace ~
35005 \InsetSpace ~
35006 \InsetSpace ~
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 \InsetSpace ~
35014 \InsetSpace ~
35015 \InsetSpace ~
35016  80\InsetSpace ~
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 \InsetSpace ~
35022 \InsetSpace ~
35023 \InsetSpace ~
35024  mov\InsetSpace ~
35025 \InsetSpace ~
35026  a,(_gint + 1) 
35027 \newline
35028 0029
35029  A2 E3\InsetSpace ~
35030 \InsetSpace ~
35031 \InsetSpace ~
35032 \InsetSpace ~
35033 \InsetSpace ~
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 \InsetSpace ~
35044  81\InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052  mov\InsetSpace ~
35053 \InsetSpace ~
35054  c,acc[3] 
35055 \newline
35056 002B 92*03\InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059 \InsetSpace ~
35060 \InsetSpace ~
35061 \InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071  82\InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079  mov\InsetSpace ~
35080 \InsetSpace ~
35081  _foo_aob3_1_1,c 
35082 \end_layout
35083
35084 \begin_layout Standard
35085 Other variations of these cases however will 
35086 \emph on
35087 not
35088 \emph default
35089  be recognized.
35090  They are standard C expressions, so I heartily recommend these be the only
35091  way to get the highest order bit, (it is portable).
35092  Of course it will be recognized even if it is embedded in other expressions,
35093  e.g.:
35094 \end_layout
35095
35096 \begin_layout Verse
35097
35098 \family typewriter
35099 xyz = gint + ((gint >> 15) & 1);
35100 \end_layout
35101
35102 \begin_layout Standard
35103 will still be recognized.
35104 \end_layout
35105
35106 \begin_layout Subsection
35107 Higher Order Byte
35108 \begin_inset LatexCommand \index{Higher Order Byte}
35109
35110 \end_inset
35111
35112  / Higher Order Word
35113 \begin_inset LatexCommand \index{Higher Order Word}
35114
35115 \end_inset
35116
35117
35118 \end_layout
35119
35120 \begin_layout Standard
35121 It is also frequently required to obtain a higher order byte or word of
35122  a larger integral type (long, int or short types).
35123  SDCC recognizes the following expressions to yield the higher order byte
35124  or word and generates optimized code for it, e.g.:
35125 \end_layout
35126
35127 \begin_layout Verse
35128
35129 \family typewriter
35130 unsigned int gint; 
35131 \newline
35132 unsigned long int glong; 
35133 \newline
35134
35135 \newline
35136 foo () { 
35137 \newline
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 unsigned char hob1,
35141  hob2; 
35142 \newline
35143 \InsetSpace ~
35144 \InsetSpace ~
35145 unsigned int how1, how2; 
35146 \newline
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 ...
35150  
35151 \newline
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 hob1 = (gint >> 8) & 0xFF; 
35155 \newline
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 hob2 = glong >> 24; 
35159 \newline
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 how1 = (glong >> 16) & 0xFFFF;
35163  
35164 \newline
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 how2 = glong >> 8; 
35168 \newline
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 ..
35172  
35173 \newline
35174 }
35175 \end_layout
35176
35177 \begin_layout Standard
35178 will generate the following code:
35179 \end_layout
35180
35181 \begin_layout Verse
35182
35183 \family typewriter
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191 \InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199 \InsetSpace ~
35200 \InsetSpace ~
35201 \InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209  91 ;\InsetSpace ~
35210  hob.c 15 
35211 \newline
35212 0037 85*01*06\InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218 \InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224  92\InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228 \InsetSpace ~
35229 \InsetSpace ~
35230 \InsetSpace ~
35231 \InsetSpace ~
35232  mov\InsetSpace ~
35233 \InsetSpace ~
35234  _foo_hob1_1_1,(_gint + 1) 
35235 \newline
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 \InsetSpace ~
35248 \InsetSpace ~
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253 \InsetSpace ~
35254 \InsetSpace ~
35255 \InsetSpace ~
35256 \InsetSpace ~
35257 \InsetSpace ~
35258 \InsetSpace ~
35259 \InsetSpace ~
35260 \InsetSpace ~
35261  93 ;\InsetSpace ~
35262  hob.c
35263  16 
35264 \newline
35265 003A 85*05*07\InsetSpace ~
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 \InsetSpace ~
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 \InsetSpace ~
35273 \InsetSpace ~
35274 \InsetSpace ~
35275 \InsetSpace ~
35276 \InsetSpace ~
35277  94\InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283 \InsetSpace ~
35284 \InsetSpace ~
35285  mov\InsetSpace ~
35286 \InsetSpace ~
35287  _foo_hob2_1_1,(_glong + 3) 
35288 \newline
35289 \InsetSpace ~
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314  95 ;\InsetSpace ~
35315  hob.c 17 
35316 \newline
35317 003D 85*04*08\InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329
35330  96\InsetSpace ~
35331 \InsetSpace ~
35332 \InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338  mov\InsetSpace ~
35339 \InsetSpace ~
35340  _foo_how1_1_1,(_glong + 2) 
35341 \newline
35342 0040 85*05*09\InsetSpace ~
35343 \InsetSpace ~
35344 \InsetSpace ~
35345 \InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354  97\InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362  mov\InsetSpace ~
35363 \InsetSpace ~
35364  (_foo_how1_1_1 +
35365  1),(_glong + 3) 
35366 \newline
35367 0043 85*03*0A\InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379  98\InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387  mov\InsetSpace ~
35388 \InsetSpace ~
35389  _foo_how2_1_1,(_glong + 1) 
35390 \newline
35391 0046 85*04*0B\InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403
35404  99\InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412  mov\InsetSpace ~
35413 \InsetSpace ~
35414  (_foo_how2_1_1 + 1),(_glong + 2) 
35415 \end_layout
35416
35417 \begin_layout Standard
35418 Again, variations of these cases may 
35419 \emph on
35420 not
35421 \emph default
35422  be recognized.
35423  They are standard C expressions, so I heartily recommend these be the only
35424  way to get the higher order byte/word, (it is portable).
35425  Of course it will be recognized even if it is embedded in other expressions,
35426  e.g.:
35427 \end_layout
35428
35429 \begin_layout Verse
35430
35431 \family typewriter
35432 xyz = gint + ((gint >> 8) & 0xFF);
35433 \end_layout
35434
35435 \begin_layout Standard
35436 will still be recognized.
35437 \end_layout
35438
35439 \begin_layout Subsection
35440 Peephole Optimizer
35441 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35442
35443 \end_inset
35444
35445
35446 \begin_inset LatexCommand \index{Peephole optimizer}
35447
35448 \end_inset
35449
35450
35451 \end_layout
35452
35453 \begin_layout Standard
35454 The compiler uses a rule based, pattern matching and re-writing mechanism
35455  for peep-hole optimization.
35456  It is inspired by 
35457 \emph on
35458 copt
35459 \emph default
35460  a peep-hole optimizer by Christopher W.
35461  Fraser (cwfraser\InsetSpace ~
35462 @\InsetSpace ~
35463 microsoft.com).
35464  A default set of rules are compiled into the compiler, additional rules
35465  may be added with the 
35466 \emph on
35467 -
35468 \begin_inset ERT
35469 status collapsed
35470
35471 \begin_layout Standard
35472
35473
35474 \backslash
35475 /
35476 \end_layout
35477
35478 \end_inset
35479
35480 -peep-file
35481 \begin_inset LatexCommand \index{-\/-peep-file}
35482
35483 \end_inset
35484
35485  <filename>
35486 \emph default
35487  option.
35488  The rule language is best illustrated with examples.
35489 \end_layout
35490
35491 \begin_layout Verse
35492
35493 \family typewriter
35494 replace { 
35495 \newline
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 mov %1,a 
35499 \newline
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 mov a,%1
35503 \newline
35504 } by {
35505 \newline
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 mov %1,a
35509 \newline
35510 }
35511 \end_layout
35512
35513 \begin_layout Standard
35514 The above rule will change the following assembly
35515 \begin_inset LatexCommand \index{Assembler routines}
35516
35517 \end_inset
35518
35519  sequence:
35520 \end_layout
35521
35522 \begin_layout Verse
35523
35524 \family typewriter
35525 mov r1,a 
35526 \newline
35527 mov a,r1
35528 \end_layout
35529
35530 \begin_layout Standard
35531 to
35532 \end_layout
35533
35534 \begin_layout Verse
35535
35536 \family typewriter
35537 mov r1,a
35538 \end_layout
35539
35540 \begin_layout Standard
35541 Note: All occurrences of a 
35542 \emph on
35543 %n
35544 \emph default
35545  (pattern variable) must denote the same string.
35546  With the above rule, the assembly sequence:
35547 \end_layout
35548
35549 \begin_layout Verse
35550
35551 \family typewriter
35552 mov r1,a 
35553 \newline
35554 mov a,r2
35555 \end_layout
35556
35557 \begin_layout Standard
35558 will remain unmodified.
35559 \newline
35560
35561 \newline
35562 Other special case optimizations may be added by the
35563  user (via 
35564 \emph on
35565 -
35566 \begin_inset ERT
35567 status collapsed
35568
35569 \begin_layout Standard
35570
35571
35572 \backslash
35573 /
35574 \end_layout
35575
35576 \end_inset
35577
35578 -peep-file option
35579 \emph default
35580 ).
35581  E.g.
35582  some variants of the 8051 MCU
35583 \begin_inset LatexCommand \index{MCS51 variants}
35584
35585 \end_inset
35586
35587  allow only 
35588 \family typewriter
35589 ajmp
35590 \family default
35591  and 
35592 \family typewriter
35593 acall
35594 \family default
35595 .
35596  The following two rules will change all 
35597 \family typewriter
35598 ljmp
35599 \family default
35600  and 
35601 \family typewriter
35602 lcall
35603 \family default
35604  to 
35605 \family typewriter
35606 ajmp
35607 \family default
35608  and 
35609 \family typewriter
35610 acall
35611 \end_layout
35612
35613 \begin_layout Verse
35614
35615 \family typewriter
35616 replace { lcall %1 } by { acall %1 } 
35617 \newline
35618 replace { ljmp %1 } by { ajmp %1 }
35619 \end_layout
35620
35621 \begin_layout Standard
35622 The 
35623 \emph on
35624 inline-assembler code
35625 \emph default
35626  is also passed through the peep hole optimizer, thus the peephole optimizer
35627  can also be used as an assembly level macro expander.
35628  The rules themselves are MCU dependent whereas the rule language infra-structur
35629 e is MCU independent.
35630  Peephole optimization rules for other MCU can be easily programmed using
35631  the rule language.
35632 \newline
35633
35634 \newline
35635 The syntax for a rule is as follows:
35636 \end_layout
35637
35638 \begin_layout Verse
35639
35640 \family typewriter
35641 rule := replace [ restart ] '{' <assembly sequence> '
35642 \backslash
35643 n' 
35644 \newline
35645 \InsetSpace ~
35646  \InsetSpace ~
35647  \InsetSpace ~
35648  \InsetSpace ~
35649  \InsetSpace ~
35650  \InsetSpace ~
35651  \InsetSpace ~
35652  \InsetSpace ~
35653  \InsetSpace ~
35654  \InsetSpace ~
35655  \InsetSpace ~
35656  \InsetSpace ~
35657  \InsetSpace ~
35658  \InsetSpace ~
35659  '}' by '{' '
35660 \backslash
35661 n' 
35662 \newline
35663 \InsetSpace ~
35664  \InsetSpace ~
35665  \InsetSpace ~
35666  \InsetSpace ~
35667  \InsetSpace ~
35668  \InsetSpace ~
35669  \InsetSpace ~
35670  \InsetSpace ~
35671  \InsetSpace ~
35672  \InsetSpace ~
35673  \InsetSpace ~
35674  \InsetSpace ~
35675  \InsetSpace ~
35676  \InsetSpace ~
35677  \InsetSpace ~
35678  \InsetSpace ~
35679  <assembly sequence> '
35680 \backslash
35681 n' 
35682 \newline
35683 \InsetSpace ~
35684  \InsetSpace ~
35685  \InsetSpace ~
35686  \InsetSpace ~
35687  \InsetSpace ~
35688  \InsetSpace ~
35689  \InsetSpace ~
35690  \InsetSpace ~
35691  \InsetSpace ~
35692  \InsetSpace ~
35693  \InsetSpace ~
35694  \InsetSpace ~
35695  \InsetSpace ~
35696  \InsetSpace ~
35697  '}' [if <functionName> ] '
35698 \backslash
35699 n' 
35700 \end_layout
35701
35702 \begin_layout Standard
35703 <assembly sequence> := assembly instruction (each instruction including
35704  labels must be on a separate line).
35705 \newline
35706
35707 \newline
35708 The optimizer will apply to the rules
35709  one by one from the top in the sequence of their appearance, it will terminate
35710  when all rules are exhausted.
35711  If the 'restart' option is specified, then the optimizer will start matching
35712  the rules again from the top, this option for a rule is expensive (performance)
35713 , it is intended to be used in situations where a transformation will trigger
35714  the same rule again.
35715  An example of this (not a good one, it has side effects) is the following
35716  rule:
35717 \end_layout
35718
35719 \begin_layout Verse
35720
35721 \family typewriter
35722 replace restart { 
35723 \newline
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 pop %1 
35727 \newline
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 push %1 } by { 
35731 \newline
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 ; nop 
35735 \newline
35736 }
35737 \end_layout
35738
35739 \begin_layout Standard
35740 Note that the replace pattern cannot be a blank, but can be a comment line.
35741  Without the 'restart' option only the innermost 'pop' 'push' pair would
35742  be eliminated, i.e.:
35743 \end_layout
35744
35745 \begin_layout Verse
35746
35747 \family typewriter
35748 pop ar1 
35749 \newline
35750 pop ar2 
35751 \newline
35752 push ar2 
35753 \newline
35754 push ar1
35755 \end_layout
35756
35757 \begin_layout Standard
35758 would result in:
35759 \end_layout
35760
35761 \begin_layout Verse
35762
35763 \family typewriter
35764 pop ar1 
35765 \newline
35766 ; nop 
35767 \newline
35768 push ar1
35769 \end_layout
35770
35771 \begin_layout Standard
35772
35773 \emph on
35774 with
35775 \emph default
35776  the restart option the rule will be applied again to the resulting code
35777  and then all the pop-push pairs will be eliminated to yield:
35778 \end_layout
35779
35780 \begin_layout Verse
35781
35782 \family typewriter
35783 ; nop 
35784 \newline
35785 ; nop
35786 \end_layout
35787
35788 \begin_layout Standard
35789 A conditional function can be attached to a rule.
35790  Attaching rules are somewhat more involved, let me illustrate this with
35791  an example.
35792 \end_layout
35793
35794 \begin_layout Verse
35795
35796 \family typewriter
35797 replace { 
35798 \newline
35799 \InsetSpace ~
35800  \InsetSpace ~
35801  \InsetSpace ~
35802 ljmp %5 
35803 \newline
35804 %2:
35805 \newline
35806 } by { 
35807 \newline
35808 \InsetSpace ~
35809  \InsetSpace ~
35810  \InsetSpace ~
35811 sjmp %5 
35812 \newline
35813 %2:
35814 \newline
35815 } if labelInRange
35816 \end_layout
35817
35818 \begin_layout Standard
35819 The optimizer does a look-up of a function name table defined in function
35820  
35821 \emph on
35822 callFuncByName
35823 \emph default
35824  in the source file SDCCpeeph.c, with the name 
35825 \emph on
35826 labelInRange
35827 \emph default
35828 .
35829  If it finds a corresponding entry the function is called.
35830  Note there can be no parameters specified for these functions, in this
35831  case the use of 
35832 \emph on
35833 %5
35834 \emph default
35835  is crucial, since the function 
35836 \emph on
35837 labelInRange
35838 \emph default
35839  expects to find the label in that particular variable (the hash table containin
35840 g the variable bindings is passed as a parameter).
35841  If you want to code more such functions, take a close look at the function
35842  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35843  Currently implemented are 
35844 \emph on
35845 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35846  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35847 \emph default
35848 and
35849 \emph on
35850  notVolatile
35851 \emph default
35852 .
35853 \end_layout
35854
35855 \begin_layout Standard
35856 I know this whole thing is a little kludgey, but maybe some day we will
35857  have some better means.
35858  If you are looking at this file, you will see the default rules that are
35859  compiled into the compiler, you can add your own rules in the default set
35860  there if you get tired of specifying the -
35861 \begin_inset ERT
35862 status collapsed
35863
35864 \begin_layout Standard
35865
35866
35867 \backslash
35868 /
35869 \end_layout
35870
35871 \end_inset
35872
35873 -peep-file option.
35874 \end_layout
35875
35876 \begin_layout Section
35877 ANSI-Compliance
35878 \begin_inset LatexCommand \index{ANSI-compliance}
35879
35880 \end_inset
35881
35882
35883 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35884
35885 \end_inset
35886
35887
35888 \end_layout
35889
35890 \begin_layout Standard
35891 The latest publically available version of the standard 
35892 \emph on
35893 ISO/IEC 9899 - Programming languages - C
35894 \emph default
35895  should be available at: 
35896 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35897
35898 \end_inset
35899
35900 .
35901 \newline
35902
35903 \end_layout
35904
35905 \begin_layout Standard
35906 Deviations from the compliance:
35907 \end_layout
35908
35909 \begin_layout Itemize
35910 functions are not reentrant
35911 \begin_inset LatexCommand \index{reentrant}
35912
35913 \end_inset
35914
35915  unless explicitly declared as such or the 
35916 \series bold
35917 -
35918 \begin_inset ERT
35919 status collapsed
35920
35921 \begin_layout Standard
35922
35923
35924 \backslash
35925 /
35926 \end_layout
35927
35928 \end_inset
35929
35930 -stack-auto
35931 \begin_inset LatexCommand \index{-\/-stack-auto}
35932
35933 \end_inset
35934
35935
35936 \series default
35937  command line option is specified.
35938 \end_layout
35939
35940 \begin_layout Itemize
35941 structures
35942 \begin_inset LatexCommand \index{struct}
35943
35944 \end_inset
35945
35946  and unions
35947 \begin_inset LatexCommand \index{union}
35948
35949 \end_inset
35950
35951  cannot be assigned values directly, cannot be passed as function parameters
35952  or assigned to each other and cannot be a return value
35953 \begin_inset LatexCommand \index{return value}
35954
35955 \end_inset
35956
35957  from a function, e.g.:
35958 \end_layout
35959
35960 \begin_deeper
35961 \begin_layout Verse
35962
35963 \family typewriter
35964 struct s { ...
35965  }; 
35966 \newline
35967 struct s s1, s2; 
35968 \newline
35969 foo() 
35970 \newline
35971
35972 \newline
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 ...
35978  
35979 \newline
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35985 \newline
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 ...
35991  
35992 \newline
35993 }
35994 \newline
35995
35996 \series bold
35997 struct
35998 \series default
35999  s foo1 (
36000 \series bold
36001 struct
36002 \series default
36003  s parms) /* invalid in SDCC although allowed in ANSI */
36004 \newline
36005
36006 \newline
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 struct s rets;
36012  
36013 \newline
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 ...
36019  
36020 \newline
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36026 \newline
36027 }
36028 \end_layout
36029
36030 \end_deeper
36031 \begin_layout Itemize
36032 initialization of structure arrays must be fully braced.
36033 \end_layout
36034
36035 \begin_deeper
36036 \begin_layout Verse
36037
36038 \family typewriter
36039 struct s { char x } a[] = {1, 2};\InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 /* invalid in SDCC */
36045 \newline
36046 struct s { char x
36047  } a[] = {{1}, {2}}; /* OK */
36048 \end_layout
36049
36050 \end_deeper
36051 \begin_layout Itemize
36052 'long long
36053 \begin_inset LatexCommand \index{long long (not supported)}
36054
36055 \end_inset
36056
36057 ' (64 bit integers
36058 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36059
36060 \end_inset
36061
36062 ) not supported.
36063 \end_layout
36064
36065 \begin_layout Itemize
36066 'double
36067 \begin_inset LatexCommand \index{double (not supported)}
36068
36069 \end_inset
36070
36071 ' precision floating point 
36072 \begin_inset LatexCommand \index{Floating point support}
36073
36074 \end_inset
36075
36076 not supported.
36077 \end_layout
36078
36079 \begin_layout Itemize
36080 Old K&R style
36081 \begin_inset LatexCommand \index{K\&R style}
36082
36083 \end_inset
36084
36085  function declarations are NOT allowed.
36086 \end_layout
36087
36088 \begin_deeper
36089 \begin_layout Verse
36090
36091 \family typewriter
36092 foo(i,j) /* this old style of function declarations */ 
36093 \newline
36094 int i,j; /* is valid
36095  in ANSI but not valid in SDCC */ 
36096 \newline
36097
36098 \newline
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 ...
36104  
36105 \newline
36106 }
36107 \end_layout
36108
36109 \end_deeper
36110 \begin_layout Itemize
36111 Most enhancements in C99 are not supported, e.g.:
36112 \end_layout
36113
36114 \begin_deeper
36115 \begin_layout Verse
36116
36117 \family typewriter
36118 for (
36119 \series bold
36120 int
36121 \series default
36122  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36123 \end_layout
36124
36125 \end_deeper
36126 \begin_layout Itemize
36127 But some have been added recently in SDCC 2.7.0.
36128  They must be considered alpha quality however.
36129 \end_layout
36130
36131 \begin_deeper
36132 \begin_layout Verse
36133
36134 \family typewriter
36135 \series bold
36136 inline
36137 \begin_inset LatexCommand \index{inline (not supported)}
36138
36139 \end_inset
36140
36141
36142 \series default
36143  int increment (int a) { return a+1; } /* inlines the increment without
36144  function call overhead */
36145 \newline
36146 int * 
36147 \series bold
36148 restrict
36149 \begin_inset LatexCommand \index{inline (not supported)}
36150
36151 \end_inset
36152
36153
36154 \series default
36155  p; /* accepted but ignored */
36156 \end_layout
36157
36158 \end_deeper
36159 \begin_layout Itemize
36160 Certain words that are valid identifiers in the standard may be reserved
36161  words in SDCC unless the 
36162 \series bold
36163 -
36164 \begin_inset ERT
36165 status collapsed
36166
36167 \begin_layout Standard
36168
36169
36170 \backslash
36171 /
36172 \end_layout
36173
36174 \end_inset
36175
36176 -std-c89
36177 \begin_inset LatexCommand \index{-\/-std-c89}
36178
36179 \end_inset
36180
36181  or -
36182 \begin_inset ERT
36183 status collapsed
36184
36185 \begin_layout Standard
36186
36187
36188 \backslash
36189 /
36190 \end_layout
36191
36192 \end_inset
36193
36194 -std-c99
36195 \begin_inset LatexCommand \index{-\/-std-c99}
36196
36197 \end_inset
36198
36199
36200 \series default
36201  command line options are used.
36202  These may include (depending on the selected processor): 'at', 'banked',
36203  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36204 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36205  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36206  '_naked'.
36207  Compliant equivalents of these keywords are always available in a form
36208  that begin with two underscores
36209 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36210
36211 \end_inset
36212
36213 , f.e.
36214  '__data' instead of 'data'.
36215 \end_layout
36216
36217 \begin_layout Section
36218 Cyclomatic Complexity
36219 \begin_inset LatexCommand \index{Cyclomatic complexity}
36220
36221 \end_inset
36222
36223
36224 \end_layout
36225
36226 \begin_layout Standard
36227 Cyclomatic complexity of a function is defined as the number of independent
36228  paths the program can take during execution of the function.
36229  This is an important number since it defines the number test cases you
36230  have to generate to validate the function.
36231  The accepted industry standard for complexity number is 10, if the cyclomatic
36232  complexity reported by SDCC exceeds 10 you should think about simplification
36233  of the function logic.
36234  Note that the complexity level is not related to the number of lines of
36235  code in a function.
36236  Large functions can have low complexity, and small functions can have large
36237  complexity levels.
36238  
36239 \newline
36240
36241 \newline
36242 SDCC uses the following formula to compute the complexity:
36243 \newline
36244
36245 \end_layout
36246
36247 \begin_layout Standard
36248 complexity = (number of edges in control flow graph) - (number of nodes
36249  in control flow graph) + 2;
36250 \newline
36251
36252 \newline
36253 Having said that the industry standard is 10,
36254  you should be aware that in some cases it be may unavoidable to have a
36255  complexity level of less than 10.
36256  For example if you have switch statement with more than 10 case labels,
36257  each case label adds one to the complexity level.
36258  The complexity level is by no means an absolute measure of the algorithmic
36259  complexity of the function, it does however provide a good starting point
36260  for which functions you might look at for further optimization.
36261 \end_layout
36262
36263 \begin_layout Section
36264 Retargetting for other Processors
36265 \end_layout
36266
36267 \begin_layout Standard
36268 The issues for retargetting the compiler are far too numerous to be covered
36269  by this document.
36270  What follows is a brief description of each of the seven phases of the
36271  compiler and its MCU dependency.
36272 \end_layout
36273
36274 \begin_layout Itemize
36275 Parsing the source and building the annotated parse tree.
36276  This phase is largely MCU independent (except for the language extensions).
36277  Syntax & semantic checks are also done in this phase, along with some initial
36278  optimizations like back patching labels and the pattern matching optimizations
36279  like bit-rotation etc.
36280 \end_layout
36281
36282 \begin_layout Itemize
36283 The second phase involves generating an intermediate code which can be easy
36284  manipulated during the later phases.
36285  This phase is entirely MCU independent.
36286  The intermediate code generation assumes the target machine has unlimited
36287  number of registers, and designates them with the name iTemp.
36288  The compiler can be made to dump a human readable form of the code generated
36289  by using the -
36290 \begin_inset ERT
36291 status collapsed
36292
36293 \begin_layout Standard
36294
36295
36296 \backslash
36297 /
36298 \end_layout
36299
36300 \end_inset
36301
36302 -dumpraw option.
36303 \end_layout
36304
36305 \begin_layout Itemize
36306 This phase does the bulk of the standard optimizations and is also MCU independe
36307 nt.
36308  This phase can be broken down into several sub-phases:
36309 \newline
36310
36311 \newline
36312 Break down intermediate
36313  code (iCode) into basic blocks.
36314 \newline
36315 Do control flow & data flow analysis on the
36316  basic blocks.
36317 \newline
36318 Do local common subexpression elimination, then global subexpressio
36319 n elimination
36320 \newline
36321 Dead code elimination
36322 \newline
36323 Loop optimizations
36324 \newline
36325 If loop optimizations
36326  caused any changes then do 'global subexpression elimination' and 'dead
36327  code elimination' again.
36328 \end_layout
36329
36330 \begin_layout Itemize
36331 This phase determines the live-ranges; by live range I mean those iTemp
36332  variables defined by the compiler that still survive after all the optimization
36333 s.
36334  Live range analysis
36335 \begin_inset LatexCommand \index{Live range analysis}
36336
36337 \end_inset
36338
36339  is essential for register allocation, since these computation determines
36340  which of these iTemps will be assigned to registers, and for how long.
36341 \end_layout
36342
36343 \begin_layout Itemize
36344 Phase five is register allocation.
36345  There are two parts to this process.
36346 \newline
36347
36348 \newline
36349 The first part I call 'register packing'
36350  (for lack of a better term).
36351  In this case several MCU specific expression folding is done to reduce
36352  register pressure.
36353 \newline
36354
36355 \newline
36356 The second part is more MCU independent and deals with
36357  allocating registers to the remaining live ranges.
36358  A lot of MCU specific code does creep into this phase because of the limited
36359  number of index registers available in the 8051.
36360 \end_layout
36361
36362 \begin_layout Itemize
36363 The Code generation phase is (unhappily), entirely MCU dependent and very
36364  little (if any at all) of this code can be reused for other MCU.
36365  However the scheme for allocating a homogenized assembler operand for each
36366  iCode operand may be reused.
36367 \end_layout
36368
36369 \begin_layout Itemize
36370 As mentioned in the optimization section the peep-hole optimizer is rule
36371  based system, which can reprogrammed for other MCUs.
36372 \end_layout
36373
36374 \begin_layout Standard
36375 More information is available on SDCC Wiki
36376 \begin_inset LatexCommand \index{wiki}
36377
36378 \end_inset
36379
36380  (preliminary link 
36381 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36382
36383 \end_inset
36384
36385 ) and in the thread 
36386 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36387
36388 \end_inset
36389
36390  .
36391 \end_layout
36392
36393 \begin_layout Chapter
36394 Compiler internals
36395 \begin_inset LatexCommand \index{Compiler internals}
36396
36397 \end_inset
36398
36399
36400 \end_layout
36401
36402 \begin_layout Section
36403 The anatomy of the compiler
36404 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36405
36406 \end_inset
36407
36408
36409 \end_layout
36410
36411 \begin_layout Standard
36412
36413 \shape italic
36414 This is an excerpt from an article published in Circuit Cellar Magazine
36415  in 
36416 \series bold
36417 August 2000
36418 \series default
36419 .
36420  It's a little outdated (the compiler is much more efficient now and user/develo
36421 per friendly), but pretty well exposes the guts of it all.
36422 \shape default
36423
36424 \newline
36425
36426 \newline
36427 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36428  It is fairly easy to retarget for other 8-bit MCU.
36429  Here we take a look at some of the internals of the compiler.
36430  
36431 \end_layout
36432
36433 \begin_layout Paragraph*
36434 Parsing
36435 \begin_inset LatexCommand \index{Parsing}
36436
36437 \end_inset
36438
36439  
36440 \end_layout
36441
36442 \begin_layout Standard
36443 Parsing the input source file and creating an AST (Annotated Syntax Tree
36444 \begin_inset LatexCommand \index{Annotated syntax tree}
36445
36446 \end_inset
36447
36448 ).
36449  This phase also involves propagating types (annotating each node of the
36450  parse tree with type information) and semantic analysis.
36451  There are some MCU specific parsing rules.
36452  For example the storage classes, the extended storage classes are MCU specific
36453  while there may be a xdata storage class for 8051 there is no such storage
36454  class for z80 or Atmel AVR.
36455  SDCC allows MCU specific storage class extensions, i.e.
36456  xdata will be treated as a storage class specifier when parsing 8051 C
36457  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36458  C code.
36459 \end_layout
36460
36461 \begin_layout Paragraph*
36462 Generating iCode
36463 \begin_inset LatexCommand \index{iCode}
36464
36465 \end_inset
36466
36467
36468 \end_layout
36469
36470 \begin_layout Standard
36471 Intermediate code generation.
36472  In this phase the AST is broken down into three-operand form (iCode).
36473  These three operand forms are represented as doubly linked lists.
36474  ICode is the term given to the intermediate form generated by the compiler.
36475  ICode example section shows some examples of iCode generated for some simple
36476  C source functions.
36477 \end_layout
36478
36479 \begin_layout Paragraph*
36480 Optimizations
36481 \begin_inset LatexCommand \index{Optimizations}
36482
36483 \end_inset
36484
36485 .
36486 \end_layout
36487
36488 \begin_layout Standard
36489 Bulk of the target independent optimizations is performed in this phase.
36490  The optimizations include constant propagation, common sub-expression eliminati
36491 on, loop invariant code movement, strength reduction of loop induction variables
36492  and dead-code elimination.
36493 \end_layout
36494
36495 \begin_layout Paragraph*
36496 Live range analysis
36497 \begin_inset LatexCommand \index{Live range analysis}
36498
36499 \end_inset
36500
36501
36502 \end_layout
36503
36504 \begin_layout Standard
36505 During intermediate code generation phase, the compiler assumes the target
36506  machine has infinite number of registers and generates a lot of temporary
36507  variables.
36508  The live range computation determines the lifetime of each of these compiler-ge
36509 nerated temporaries.
36510  A picture speaks a thousand words.
36511  ICode example sections show the live range annotations for each of the
36512  operand.
36513  It is important to note here, each iCode is assigned a number in the order
36514  of its execution in the function.
36515  The live ranges are computed in terms of these numbers.
36516  The from number is the number of the iCode which first defines the operand
36517  and the to number signifies the iCode which uses this operand last.
36518 \end_layout
36519
36520 \begin_layout Paragraph*
36521 Register Allocation
36522 \begin_inset LatexCommand \index{Register allocation}
36523
36524 \end_inset
36525
36526
36527 \end_layout
36528
36529 \begin_layout Standard
36530 The register allocation determines the type and number of registers needed
36531  by each operand.
36532  In most MCUs only a few registers can be used for indirect addressing.
36533  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36534  address the internal ram and DPTR to indirectly address the external ram.
36535  The compiler will try to allocate the appropriate register to pointer variables
36536  if it can.
36537  ICode example section shows the operands annotated with the registers assigned
36538  to them.
36539  The compiler will try to keep operands in registers as much as possible;
36540  there are several schemes the compiler uses to do achieve this.
36541  When the compiler runs out of registers the compiler will check to see
36542  if there are any live operands which is not used or defined in the current
36543  basic block being processed, if there are any found then it will push that
36544  operand and use the registers in this block, the operand will then be popped
36545  at the end of the basic block.
36546  
36547 \end_layout
36548
36549 \begin_layout Standard
36550 There are other MCU specific considerations in this phase.
36551  Some MCUs have an accumulator; very short-lived operands could be assigned
36552  to the accumulator instead of a general-purpose register.
36553 \end_layout
36554
36555 \begin_layout Paragraph*
36556 Code generation
36557 \end_layout
36558
36559 \begin_layout Standard
36560 Figure II gives a table of iCode
36561 \begin_inset LatexCommand \index{iCode}
36562
36563 \end_inset
36564
36565  operations supported by the compiler.
36566  The code generation involves translating these operations into corresponding
36567  assembly code for the processor.
36568  This sounds overly simple but that is the essence of code generation.
36569  Some of the iCode operations are generated on a MCU specific manner for
36570  example, the z80 port does not use registers to pass parameters so the
36571  SEND and RECV iCode operations will not be generated, and it also does
36572  not support JUMPTABLES.
36573  
36574 \newline
36575
36576 \end_layout
36577
36578 \begin_layout Standard
36579
36580 \size footnotesize
36581 Figure II 
36582 \begin_inset Tabular
36583 <lyxtabular version="3" rows="39" columns="4">
36584 <features islongtable="true" headBottomDL="true">
36585 <column alignment="block" valignment="top" leftline="true" width="13col%">
36586 <column alignment="left" valignment="top" leftline="true" width="13col%">
36587 <column alignment="block" valignment="top" leftline="true" width="22col%">
36588 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36589 <row topline="true" bottomline="true" endhead="true">
36590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36591 \begin_inset Text
36592
36593 \begin_layout Standard
36594
36595 \series bold
36596 iCode
36597 \series default
36598
36599 \begin_inset LatexCommand \index{iCode}
36600
36601 \end_inset
36602
36603
36604 \end_layout
36605
36606 \end_inset
36607 </cell>
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36609 \begin_inset Text
36610
36611 \begin_layout Standard
36612
36613 \series bold
36614 Operands
36615 \end_layout
36616
36617 \end_inset
36618 </cell>
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36620 \begin_inset Text
36621
36622 \begin_layout Standard
36623
36624 \series bold
36625 Description
36626 \end_layout
36627
36628 \end_inset
36629 </cell>
36630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36631 \begin_inset Text
36632
36633 \begin_layout Standard
36634
36635 \series bold
36636 C Equivalent
36637 \end_layout
36638
36639 \end_inset
36640 </cell>
36641 </row>
36642 <row topline="true">
36643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36644 \begin_inset Text
36645
36646 \begin_layout Standard
36647
36648 \size footnotesize
36649 '!'
36650 \end_layout
36651
36652 \end_inset
36653 </cell>
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36655 \begin_inset Text
36656
36657 \begin_layout Standard
36658
36659 \size footnotesize
36660 IC_LEFT() IC_RESULT()
36661 \end_layout
36662
36663 \end_inset
36664 </cell>
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36666 \begin_inset Text
36667
36668 \begin_layout Standard
36669
36670 \size footnotesize
36671 NOT operation 
36672 \end_layout
36673
36674 \end_inset
36675 </cell>
36676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36677 \begin_inset Text
36678
36679 \begin_layout Standard
36680
36681 \size footnotesize
36682 IC_RESULT = ! IC_LEFT;
36683 \end_layout
36684
36685 \end_inset
36686 </cell>
36687 </row>
36688 <row topline="true">
36689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36690 \begin_inset Text
36691
36692 \begin_layout Standard
36693
36694 \size footnotesize
36695 '~'
36696 \end_layout
36697
36698 \end_inset
36699 </cell>
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36701 \begin_inset Text
36702
36703 \begin_layout Standard
36704
36705 \size footnotesize
36706 IC_LEFT() IC_RESULT()
36707 \end_layout
36708
36709 \end_inset
36710 </cell>
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36712 \begin_inset Text
36713
36714 \begin_layout Standard
36715
36716 \size footnotesize
36717 Bitwise complement of 
36718 \end_layout
36719
36720 \end_inset
36721 </cell>
36722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36723 \begin_inset Text
36724
36725 \begin_layout Standard
36726
36727 \size footnotesize
36728 IC_RESULT = ~IC_LEFT;
36729 \end_layout
36730
36731 \end_inset
36732 </cell>
36733 </row>
36734 <row topline="true">
36735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36736 \begin_inset Text
36737
36738 \begin_layout Standard
36739
36740 \size footnotesize
36741 RRC
36742 \end_layout
36743
36744 \end_inset
36745 </cell>
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36747 \begin_inset Text
36748
36749 \begin_layout Standard
36750
36751 \size footnotesize
36752 IC_LEFT() IC_RESULT()
36753 \end_layout
36754
36755 \end_inset
36756 </cell>
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36758 \begin_inset Text
36759
36760 \begin_layout Standard
36761
36762 \size footnotesize
36763 Rotate right with carry
36764 \end_layout
36765
36766 \end_inset
36767 </cell>
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36769 \begin_inset Text
36770
36771 \begin_layout Standard
36772
36773 \size footnotesize
36774 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36775 \end_layout
36776
36777 \end_inset
36778 </cell>
36779 </row>
36780 <row topline="true">
36781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36782 \begin_inset Text
36783
36784 \begin_layout Standard
36785
36786 \size footnotesize
36787 RLC
36788 \end_layout
36789
36790 \end_inset
36791 </cell>
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36793 \begin_inset Text
36794
36795 \begin_layout Standard
36796
36797 \size footnotesize
36798 IC_LEFT() IC_RESULT()
36799 \end_layout
36800
36801 \end_inset
36802 </cell>
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36804 \begin_inset Text
36805
36806 \begin_layout Standard
36807
36808 \size footnotesize
36809 Rotate left with carry
36810 \end_layout
36811
36812 \end_inset
36813 </cell>
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36815 \begin_inset Text
36816
36817 \begin_layout Standard
36818
36819 \size footnotesize
36820 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36821 \end_layout
36822
36823 \end_inset
36824 </cell>
36825 </row>
36826 <row topline="true">
36827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36828 \begin_inset Text
36829
36830 \begin_layout Standard
36831
36832 \size footnotesize
36833 GETHBIT
36834 \end_layout
36835
36836 \end_inset
36837 </cell>
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36839 \begin_inset Text
36840
36841 \begin_layout Standard
36842
36843 \size footnotesize
36844 IC_LEFT() IC_RESULT()
36845 \end_layout
36846
36847 \end_inset
36848 </cell>
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36850 \begin_inset Text
36851
36852 \begin_layout Standard
36853
36854 \size footnotesize
36855 Get the highest order bit of IC_LEFT
36856 \end_layout
36857
36858 \end_inset
36859 </cell>
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36861 \begin_inset Text
36862
36863 \begin_layout Standard
36864
36865 \size footnotesize
36866 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36867 \end_layout
36868
36869 \end_inset
36870 </cell>
36871 </row>
36872 <row topline="true">
36873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36874 \begin_inset Text
36875
36876 \begin_layout Standard
36877
36878 \size footnotesize
36879 UNARYMINUS
36880 \end_layout
36881
36882 \end_inset
36883 </cell>
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36885 \begin_inset Text
36886
36887 \begin_layout Standard
36888
36889 \size footnotesize
36890 IC_LEFT() IC_RESULT()
36891 \end_layout
36892
36893 \end_inset
36894 </cell>
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36896 \begin_inset Text
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 Unary minus
36902 \end_layout
36903
36904 \end_inset
36905 </cell>
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36907 \begin_inset Text
36908
36909 \begin_layout Standard
36910
36911 \size footnotesize
36912 IC_RESULT = - IC_LEFT;
36913 \end_layout
36914
36915 \end_inset
36916 </cell>
36917 </row>
36918 <row topline="true">
36919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36920 \begin_inset Text
36921
36922 \begin_layout Standard
36923
36924 \size footnotesize
36925 IPUSH
36926 \end_layout
36927
36928 \end_inset
36929 </cell>
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36931 \begin_inset Text
36932
36933 \begin_layout Standard
36934
36935 \size footnotesize
36936 IC_LEFT()
36937 \end_layout
36938
36939 \end_inset
36940 </cell>
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36942 \begin_inset Text
36943
36944 \begin_layout Standard
36945
36946 \size footnotesize
36947 Push the operand into stack
36948 \end_layout
36949
36950 \end_inset
36951 </cell>
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36953 \begin_inset Text
36954
36955 \begin_layout Standard
36956
36957 \size footnotesize
36958 NONE
36959 \end_layout
36960
36961 \end_inset
36962 </cell>
36963 </row>
36964 <row topline="true">
36965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36966 \begin_inset Text
36967
36968 \begin_layout Standard
36969
36970 \size footnotesize
36971 IPOP
36972 \end_layout
36973
36974 \end_inset
36975 </cell>
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36977 \begin_inset Text
36978
36979 \begin_layout Standard
36980
36981 \size footnotesize
36982 IC_LEFT()
36983 \end_layout
36984
36985 \end_inset
36986 </cell>
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36988 \begin_inset Text
36989
36990 \begin_layout Standard
36991
36992 \size footnotesize
36993 Pop the operand from the stack 
36994 \end_layout
36995
36996 \end_inset
36997 </cell>
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36999 \begin_inset Text
37000
37001 \begin_layout Standard
37002
37003 \size footnotesize
37004 NONE
37005 \end_layout
37006
37007 \end_inset
37008 </cell>
37009 </row>
37010 <row topline="true">
37011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37012 \begin_inset Text
37013
37014 \begin_layout Standard
37015
37016 \size footnotesize
37017 CALL
37018 \end_layout
37019
37020 \end_inset
37021 </cell>
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37023 \begin_inset Text
37024
37025 \begin_layout Standard
37026
37027 \size footnotesize
37028 IC_LEFT() IC_RESULT()
37029 \end_layout
37030
37031 \end_inset
37032 </cell>
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37034 \begin_inset Text
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 Call the function represented by IC_LEFT 
37040 \end_layout
37041
37042 \end_inset
37043 </cell>
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37045 \begin_inset Text
37046
37047 \begin_layout Standard
37048
37049 \size footnotesize
37050 IC_RESULT = IC_LEFT();
37051 \end_layout
37052
37053 \end_inset
37054 </cell>
37055 </row>
37056 <row topline="true">
37057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37058 \begin_inset Text
37059
37060 \begin_layout Standard
37061
37062 \size footnotesize
37063 PCALL
37064 \end_layout
37065
37066 \end_inset
37067 </cell>
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37069 \begin_inset Text
37070
37071 \begin_layout Standard
37072
37073 \size footnotesize
37074 IC_LEFT() IC_RESULT()
37075 \end_layout
37076
37077 \end_inset
37078 </cell>
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37080 \begin_inset Text
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 Call via function pointer
37086 \end_layout
37087
37088 \end_inset
37089 </cell>
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37091 \begin_inset Text
37092
37093 \begin_layout Standard
37094
37095 \size footnotesize
37096 IC_RESULT = (*IC_LEFT)();
37097 \end_layout
37098
37099 \end_inset
37100 </cell>
37101 </row>
37102 <row topline="true">
37103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37104 \begin_inset Text
37105
37106 \begin_layout Standard
37107
37108 \size footnotesize
37109 RETURN
37110 \end_layout
37111
37112 \end_inset
37113 </cell>
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37115 \begin_inset Text
37116
37117 \begin_layout Standard
37118
37119 \size footnotesize
37120 IC_LEFT()
37121 \end_layout
37122
37123 \end_inset
37124 </cell>
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37126 \begin_inset Text
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 Return the value in operand IC_LEFT 
37132 \end_layout
37133
37134 \end_inset
37135 </cell>
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37137 \begin_inset Text
37138
37139 \begin_layout Standard
37140
37141 \size footnotesize
37142 return IC_LEFT;
37143 \end_layout
37144
37145 \end_inset
37146 </cell>
37147 </row>
37148 <row topline="true">
37149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37150 \begin_inset Text
37151
37152 \begin_layout Standard
37153
37154 \size footnotesize
37155 LABEL
37156 \end_layout
37157
37158 \end_inset
37159 </cell>
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_inset Text
37162
37163 \begin_layout Standard
37164
37165 \size footnotesize
37166 IC_LABEL() 
37167 \end_layout
37168
37169 \end_inset
37170 </cell>
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37172 \begin_inset Text
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 Label
37178 \end_layout
37179
37180 \end_inset
37181 </cell>
37182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37183 \begin_inset Text
37184
37185 \begin_layout Standard
37186
37187 \size footnotesize
37188 IC_LABEL:
37189 \end_layout
37190
37191 \end_inset
37192 </cell>
37193 </row>
37194 <row topline="true">
37195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37196 \begin_inset Text
37197
37198 \begin_layout Standard
37199
37200 \size footnotesize
37201 GOTO
37202 \end_layout
37203
37204 \end_inset
37205 </cell>
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_inset Text
37208
37209 \begin_layout Standard
37210
37211 \size footnotesize
37212 IC_LABEL() 
37213 \end_layout
37214
37215 \end_inset
37216 </cell>
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37218 \begin_inset Text
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 Goto label
37224 \end_layout
37225
37226 \end_inset
37227 </cell>
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37229 \begin_inset Text
37230
37231 \begin_layout Standard
37232
37233 \size footnotesize
37234 goto IC_LABEL();
37235 \end_layout
37236
37237 \end_inset
37238 </cell>
37239 </row>
37240 <row topline="true">
37241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37242 \begin_inset Text
37243
37244 \begin_layout Standard
37245
37246 \size footnotesize
37247 '+'
37248 \end_layout
37249
37250 \end_inset
37251 </cell>
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37253 \begin_inset Text
37254
37255 \begin_layout Standard
37256
37257 \size footnotesize
37258 IC_LEFT() IC_RIGHT() IC_RESULT()
37259 \end_layout
37260
37261 \end_inset
37262 </cell>
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37264 \begin_inset Text
37265
37266 \begin_layout Standard
37267
37268 \size footnotesize
37269 Addition
37270 \end_layout
37271
37272 \end_inset
37273 </cell>
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37275 \begin_inset Text
37276
37277 \begin_layout Standard
37278
37279 \size footnotesize
37280 IC_RESULT = IC_LEFT + IC_RIGHT
37281 \end_layout
37282
37283 \end_inset
37284 </cell>
37285 </row>
37286 <row topline="true">
37287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37288 \begin_inset Text
37289
37290 \begin_layout Standard
37291
37292 \size footnotesize
37293 '-'
37294 \end_layout
37295
37296 \end_inset
37297 </cell>
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37299 \begin_inset Text
37300
37301 \begin_layout Standard
37302
37303 \size footnotesize
37304 IC_LEFT() IC_RIGHT() IC_RESULT()
37305 \end_layout
37306
37307 \end_inset
37308 </cell>
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37310 \begin_inset Text
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 Subtraction
37316 \end_layout
37317
37318 \end_inset
37319 </cell>
37320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37321 \begin_inset Text
37322
37323 \begin_layout Standard
37324
37325 \size footnotesize
37326 IC_RESULT = IC_LEFT - IC_RIGHT 
37327 \end_layout
37328
37329 \end_inset
37330 </cell>
37331 </row>
37332 <row topline="true">
37333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37334 \begin_inset Text
37335
37336 \begin_layout Standard
37337
37338 \size footnotesize
37339 '*'
37340 \end_layout
37341
37342 \end_inset
37343 </cell>
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37345 \begin_inset Text
37346
37347 \begin_layout Standard
37348
37349 \size footnotesize
37350 IC_LEFT() IC_RIGHT() IC_RESULT()
37351 \end_layout
37352
37353 \end_inset
37354 </cell>
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37356 \begin_inset Text
37357
37358 \begin_layout Standard
37359
37360 \size footnotesize
37361 Multiplication 
37362 \end_layout
37363
37364 \end_inset
37365 </cell>
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37367 \begin_inset Text
37368
37369 \begin_layout Standard
37370
37371 \size footnotesize
37372 IC_RESULT = IC_LEFT * IC_RIGHT;
37373 \end_layout
37374
37375 \end_inset
37376 </cell>
37377 </row>
37378 <row topline="true">
37379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37380 \begin_inset Text
37381
37382 \begin_layout Standard
37383
37384 \size footnotesize
37385 '/'
37386 \end_layout
37387
37388 \end_inset
37389 </cell>
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37391 \begin_inset Text
37392
37393 \begin_layout Standard
37394
37395 \size footnotesize
37396 IC_LEFT() IC_RIGHT() IC_RESULT()
37397 \end_layout
37398
37399 \end_inset
37400 </cell>
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37402 \begin_inset Text
37403
37404 \begin_layout Standard
37405
37406 \size footnotesize
37407 Division
37408 \end_layout
37409
37410 \end_inset
37411 </cell>
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37413 \begin_inset Text
37414
37415 \begin_layout Standard
37416
37417 \size footnotesize
37418 IC_RESULT = IC_LEFT / IC_RIGHT;
37419 \end_layout
37420
37421 \end_inset
37422 </cell>
37423 </row>
37424 <row topline="true">
37425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37426 \begin_inset Text
37427
37428 \begin_layout Standard
37429
37430 \size footnotesize
37431 '%'
37432 \end_layout
37433
37434 \end_inset
37435 </cell>
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37437 \begin_inset Text
37438
37439 \begin_layout Standard
37440
37441 \size footnotesize
37442 IC_LEFT() IC_RIGHT() IC_RESULT()
37443 \end_layout
37444
37445 \end_inset
37446 </cell>
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37448 \begin_inset Text
37449
37450 \begin_layout Standard
37451
37452 \size footnotesize
37453 Modulus
37454 \end_layout
37455
37456 \end_inset
37457 </cell>
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37459 \begin_inset Text
37460
37461 \begin_layout Standard
37462
37463 \size footnotesize
37464 IC_RESULT = IC_LEFT % IC_RIGHT;
37465 \end_layout
37466
37467 \end_inset
37468 </cell>
37469 </row>
37470 <row topline="true">
37471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37472 \begin_inset Text
37473
37474 \begin_layout Standard
37475
37476 \size footnotesize
37477 '<'
37478 \end_layout
37479
37480 \end_inset
37481 </cell>
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37483 \begin_inset Text
37484
37485 \begin_layout Standard
37486
37487 \size footnotesize
37488 IC_LEFT() IC_RIGHT() IC_RESULT()
37489 \end_layout
37490
37491 \end_inset
37492 </cell>
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37494 \begin_inset Text
37495
37496 \begin_layout Standard
37497
37498 \size footnotesize
37499 Less than
37500 \end_layout
37501
37502 \end_inset
37503 </cell>
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37505 \begin_inset Text
37506
37507 \begin_layout Standard
37508
37509 \size footnotesize
37510 IC_RESULT = IC_LEFT < IC_RIGHT;
37511 \end_layout
37512
37513 \end_inset
37514 </cell>
37515 </row>
37516 <row topline="true">
37517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37518 \begin_inset Text
37519
37520 \begin_layout Standard
37521
37522 \size footnotesize
37523 '>'
37524 \end_layout
37525
37526 \end_inset
37527 </cell>
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37529 \begin_inset Text
37530
37531 \begin_layout Standard
37532
37533 \size footnotesize
37534 IC_LEFT() IC_RIGHT() IC_RESULT()
37535 \end_layout
37536
37537 \end_inset
37538 </cell>
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37540 \begin_inset Text
37541
37542 \begin_layout Standard
37543
37544 \size footnotesize
37545 Greater than 
37546 \end_layout
37547
37548 \end_inset
37549 </cell>
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37551 \begin_inset Text
37552
37553 \begin_layout Standard
37554
37555 \size footnotesize
37556 IC_RESULT = IC_LEFT > IC_RIGHT;
37557 \end_layout
37558
37559 \end_inset
37560 </cell>
37561 </row>
37562 <row topline="true">
37563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37564 \begin_inset Text
37565
37566 \begin_layout Standard
37567
37568 \size footnotesize
37569 EQ_OP
37570 \end_layout
37571
37572 \end_inset
37573 </cell>
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37575 \begin_inset Text
37576
37577 \begin_layout Standard
37578
37579 \size footnotesize
37580 IC_LEFT() IC_RIGHT() IC_RESULT()
37581 \end_layout
37582
37583 \end_inset
37584 </cell>
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37586 \begin_inset Text
37587
37588 \begin_layout Standard
37589
37590 \size footnotesize
37591 Equal to 
37592 \end_layout
37593
37594 \end_inset
37595 </cell>
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37597 \begin_inset Text
37598
37599 \begin_layout Standard
37600
37601 \size footnotesize
37602 IC_RESULT = IC_LEFT == IC_RIGHT;
37603 \end_layout
37604
37605 \end_inset
37606 </cell>
37607 </row>
37608 <row topline="true">
37609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37610 \begin_inset Text
37611
37612 \begin_layout Standard
37613
37614 \size footnotesize
37615 AND_OP
37616 \end_layout
37617
37618 \end_inset
37619 </cell>
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37621 \begin_inset Text
37622
37623 \begin_layout Standard
37624
37625 \size footnotesize
37626 IC_LEFT() IC_RIGHT() IC_RESULT() 
37627 \end_layout
37628
37629 \end_inset
37630 </cell>
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37632 \begin_inset Text
37633
37634 \begin_layout Standard
37635
37636 \size footnotesize
37637 Logical and operation
37638 \end_layout
37639
37640 \end_inset
37641 </cell>
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37643 \begin_inset Text
37644
37645 \begin_layout Standard
37646
37647 \size footnotesize
37648 IC_RESULT = IC_LEFT && IC_RIGHT; 
37649 \end_layout
37650
37651 \end_inset
37652 </cell>
37653 </row>
37654 <row topline="true">
37655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37656 \begin_inset Text
37657
37658 \begin_layout Standard
37659
37660 \size footnotesize
37661 OR_OP
37662 \end_layout
37663
37664 \end_inset
37665 </cell>
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37667 \begin_inset Text
37668
37669 \begin_layout Standard
37670
37671 \size footnotesize
37672 IC_LEFT() IC_RIGHT() IC_RESULT() 
37673 \end_layout
37674
37675 \end_inset
37676 </cell>
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37678 \begin_inset Text
37679
37680 \begin_layout Standard
37681
37682 \size footnotesize
37683 Logical or operation 
37684 \end_layout
37685
37686 \end_inset
37687 </cell>
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37689 \begin_inset Text
37690
37691 \begin_layout Standard
37692
37693 \size footnotesize
37694 IC_RESULT = IC_LEFT || IC_RIGHT; 
37695 \end_layout
37696
37697 \end_inset
37698 </cell>
37699 </row>
37700 <row topline="true">
37701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37702 \begin_inset Text
37703
37704 \begin_layout Standard
37705
37706 \size footnotesize
37707 '^'
37708 \end_layout
37709
37710 \end_inset
37711 </cell>
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37713 \begin_inset Text
37714
37715 \begin_layout Standard
37716
37717 \size footnotesize
37718 IC_LEFT() IC_RIGHT() IC_RESULT() 
37719 \end_layout
37720
37721 \end_inset
37722 </cell>
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37724 \begin_inset Text
37725
37726 \begin_layout Standard
37727
37728 \size footnotesize
37729 Exclusive OR
37730 \end_layout
37731
37732 \end_inset
37733 </cell>
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37735 \begin_inset Text
37736
37737 \begin_layout Standard
37738
37739 \size footnotesize
37740 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37741 \end_layout
37742
37743 \end_inset
37744 </cell>
37745 </row>
37746 <row topline="true">
37747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37748 \begin_inset Text
37749
37750 \begin_layout Standard
37751
37752 \size footnotesize
37753 '|'
37754 \end_layout
37755
37756 \end_inset
37757 </cell>
37758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37759 \begin_inset Text
37760
37761 \begin_layout Standard
37762
37763 \size footnotesize
37764 IC_LEFT() IC_RIGHT() IC_RESULT() 
37765 \end_layout
37766
37767 \end_inset
37768 </cell>
37769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37770 \begin_inset Text
37771
37772 \begin_layout Standard
37773
37774 \size footnotesize
37775 Bitwise OR 
37776 \end_layout
37777
37778 \end_inset
37779 </cell>
37780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37781 \begin_inset Text
37782
37783 \begin_layout Standard
37784
37785 \size footnotesize
37786 IC_RESULT = IC_LEFT | IC_RIGHT;
37787 \end_layout
37788
37789 \end_inset
37790 </cell>
37791 </row>
37792 <row topline="true">
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37794 \begin_inset Text
37795
37796 \begin_layout Standard
37797
37798 \size footnotesize
37799 BITWISEAND
37800 \end_layout
37801
37802 \end_inset
37803 </cell>
37804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37805 \begin_inset Text
37806
37807 \begin_layout Standard
37808
37809 \size footnotesize
37810 IC_LEFT() IC_RIGHT() IC_RESULT()
37811 \end_layout
37812
37813 \end_inset
37814 </cell>
37815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37816 \begin_inset Text
37817
37818 \begin_layout Standard
37819
37820 \size footnotesize
37821 Bitwise AND 
37822 \end_layout
37823
37824 \end_inset
37825 </cell>
37826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37827 \begin_inset Text
37828
37829 \begin_layout Standard
37830
37831 \size footnotesize
37832 IC_RESULT = IC_LEFT & IC_RIGHT;
37833 \end_layout
37834
37835 \end_inset
37836 </cell>
37837 </row>
37838 <row topline="true">
37839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37840 \begin_inset Text
37841
37842 \begin_layout Standard
37843
37844 \size footnotesize
37845 LEFT_OP
37846 \end_layout
37847
37848 \end_inset
37849 </cell>
37850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37851 \begin_inset Text
37852
37853 \begin_layout Standard
37854
37855 \size footnotesize
37856 IC_LEFT() IC_RIGHT() IC_RESULT()
37857 \end_layout
37858
37859 \end_inset
37860 </cell>
37861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37862 \begin_inset Text
37863
37864 \begin_layout Standard
37865
37866 \size footnotesize
37867 Left shift 
37868 \end_layout
37869
37870 \end_inset
37871 </cell>
37872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37873 \begin_inset Text
37874
37875 \begin_layout Standard
37876
37877 \size footnotesize
37878 IC_RESULT = IC_LEFT << IC_RIGHT 
37879 \end_layout
37880
37881 \end_inset
37882 </cell>
37883 </row>
37884 <row topline="true">
37885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37886 \begin_inset Text
37887
37888 \begin_layout Standard
37889
37890 \size footnotesize
37891 RIGHT_OP
37892 \end_layout
37893
37894 \end_inset
37895 </cell>
37896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37897 \begin_inset Text
37898
37899 \begin_layout Standard
37900
37901 \size footnotesize
37902 IC_LEFT() IC_RIGHT() IC_RESULT()
37903 \end_layout
37904
37905 \end_inset
37906 </cell>
37907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37908 \begin_inset Text
37909
37910 \begin_layout Standard
37911
37912 \size footnotesize
37913 Right shift
37914 \end_layout
37915
37916 \end_inset
37917 </cell>
37918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37919 \begin_inset Text
37920
37921 \begin_layout Standard
37922
37923 \size footnotesize
37924 IC_RESULT = IC_LEFT >> IC_RIGHT 
37925 \end_layout
37926
37927 \end_inset
37928 </cell>
37929 </row>
37930 <row topline="true">
37931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37932 \begin_inset Text
37933
37934 \begin_layout Standard
37935
37936 \size footnotesize
37937 GET_VALUE_
37938 \newline
37939 AT_ ADDRESS
37940 \end_layout
37941
37942 \end_inset
37943 </cell>
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37945 \begin_inset Text
37946
37947 \begin_layout Standard
37948
37949 \size footnotesize
37950 IC_LEFT() IC_RESULT()
37951 \end_layout
37952
37953 \end_inset
37954 </cell>
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37956 \begin_inset Text
37957
37958 \begin_layout Standard
37959
37960 \size footnotesize
37961 Indirect fetch 
37962 \end_layout
37963
37964 \end_inset
37965 </cell>
37966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37967 \begin_inset Text
37968
37969 \begin_layout Standard
37970
37971 \size footnotesize
37972 IC_RESULT = (*IC_LEFT);
37973 \end_layout
37974
37975 \end_inset
37976 </cell>
37977 </row>
37978 <row topline="true">
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37980 \begin_inset Text
37981
37982 \begin_layout Standard
37983
37984 \size footnotesize
37985 POINTER_SET
37986 \end_layout
37987
37988 \end_inset
37989 </cell>
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37991 \begin_inset Text
37992
37993 \begin_layout Standard
37994
37995 \size footnotesize
37996 IC_RIGHT() IC_RESULT() 
37997 \end_layout
37998
37999 \end_inset
38000 </cell>
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38002 \begin_inset Text
38003
38004 \begin_layout Standard
38005
38006 \size footnotesize
38007 Indirect set
38008 \end_layout
38009
38010 \end_inset
38011 </cell>
38012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38013 \begin_inset Text
38014
38015 \begin_layout Standard
38016
38017 \size footnotesize
38018 (*IC_RESULT) = IC_RIGHT;
38019 \end_layout
38020
38021 \end_inset
38022 </cell>
38023 </row>
38024 <row topline="true">
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38026 \begin_inset Text
38027
38028 \begin_layout Standard
38029
38030 \size footnotesize
38031 '='
38032 \end_layout
38033
38034 \end_inset
38035 </cell>
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38037 \begin_inset Text
38038
38039 \begin_layout Standard
38040
38041 \size footnotesize
38042 IC_RIGHT() IC_RESULT()
38043 \end_layout
38044
38045 \end_inset
38046 </cell>
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38048 \begin_inset Text
38049
38050 \begin_layout Standard
38051
38052 \size footnotesize
38053 Assignment
38054 \end_layout
38055
38056 \end_inset
38057 </cell>
38058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38059 \begin_inset Text
38060
38061 \begin_layout Standard
38062
38063 \size footnotesize
38064 IC_RESULT = IC_RIGHT;
38065 \end_layout
38066
38067 \end_inset
38068 </cell>
38069 </row>
38070 <row topline="true">
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38072 \begin_inset Text
38073
38074 \begin_layout Standard
38075
38076 \size footnotesize
38077 IFX
38078 \end_layout
38079
38080 \end_inset
38081 </cell>
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38083 \begin_inset Text
38084
38085 \begin_layout Standard
38086
38087 \size footnotesize
38088 IC_COND IC_TRUE IC_LABEL
38089 \end_layout
38090
38091 \end_inset
38092 </cell>
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38094 \begin_inset Text
38095
38096 \begin_layout Standard
38097
38098 \size footnotesize
38099 Conditional jump.
38100  If true label is present then jump to true label if condition is true else
38101  jump to false label if condition is false 
38102 \end_layout
38103
38104 \end_inset
38105 </cell>
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38107 \begin_inset Text
38108
38109 \begin_layout Standard
38110
38111 \size footnotesize
38112 if (IC_COND) goto IC_TRUE; 
38113 \newline
38114 \InsetSpace ~
38115 \InsetSpace ~
38116 Or 
38117 \newline
38118 If (!IC_COND) goto IC_FALSE;
38119 \end_layout
38120
38121 \end_inset
38122 </cell>
38123 </row>
38124 <row topline="true">
38125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38126 \begin_inset Text
38127
38128 \begin_layout Standard
38129
38130 \size footnotesize
38131 ADDRESS_OF
38132 \end_layout
38133
38134 \end_inset
38135 </cell>
38136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38137 \begin_inset Text
38138
38139 \begin_layout Standard
38140
38141 \size footnotesize
38142 IC_LEFT() IC_RESULT()
38143 \end_layout
38144
38145 \end_inset
38146 </cell>
38147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38148 \begin_inset Text
38149
38150 \begin_layout Standard
38151
38152 \size footnotesize
38153 Address of 
38154 \end_layout
38155
38156 \end_inset
38157 </cell>
38158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38159 \begin_inset Text
38160
38161 \begin_layout Standard
38162
38163 \size footnotesize
38164 IC_RESULT = &IC_LEFT();
38165 \end_layout
38166
38167 \end_inset
38168 </cell>
38169 </row>
38170 <row topline="true">
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38172 \begin_inset Text
38173
38174 \begin_layout Standard
38175
38176 \size footnotesize
38177 JUMPTABLE
38178 \end_layout
38179
38180 \end_inset
38181 </cell>
38182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38183 \begin_inset Text
38184
38185 \begin_layout Standard
38186
38187 \size footnotesize
38188 IC_JTCOND IC_JTLABELS
38189 \end_layout
38190
38191 \end_inset
38192 </cell>
38193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38194 \begin_inset Text
38195
38196 \begin_layout Standard
38197
38198 \size footnotesize
38199 Jump to list of labels depending on the value of JTCOND
38200 \end_layout
38201
38202 \end_inset
38203 </cell>
38204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38205 \begin_inset Text
38206
38207 \begin_layout Standard
38208
38209 \size footnotesize
38210 Switch statement
38211 \end_layout
38212
38213 \end_inset
38214 </cell>
38215 </row>
38216 <row topline="true">
38217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38218 \begin_inset Text
38219
38220 \begin_layout Standard
38221
38222 \size footnotesize
38223 CAST
38224 \end_layout
38225
38226 \end_inset
38227 </cell>
38228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38229 \begin_inset Text
38230
38231 \begin_layout Standard
38232
38233 \size footnotesize
38234 IC_RIGHT() IC_LEFT() IC_RESULT()
38235 \end_layout
38236
38237 \end_inset
38238 </cell>
38239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38240 \begin_inset Text
38241
38242 \begin_layout Standard
38243
38244 \size footnotesize
38245 Cast types 
38246 \end_layout
38247
38248 \end_inset
38249 </cell>
38250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38251 \begin_inset Text
38252
38253 \begin_layout Standard
38254
38255 \size footnotesize
38256 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38257 \end_layout
38258
38259 \end_inset
38260 </cell>
38261 </row>
38262 <row topline="true">
38263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38264 \begin_inset Text
38265
38266 \begin_layout Standard
38267
38268 \size footnotesize
38269 SEND
38270 \end_layout
38271
38272 \end_inset
38273 </cell>
38274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38275 \begin_inset Text
38276
38277 \begin_layout Standard
38278
38279 \size footnotesize
38280 IC_LEFT()
38281 \end_layout
38282
38283 \end_inset
38284 </cell>
38285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38286 \begin_inset Text
38287
38288 \begin_layout Standard
38289
38290 \size footnotesize
38291 This is used for passing parameters in registers; 
38292 \newline
38293 move IC_LEFT to the next
38294  available parameter register.
38295 \end_layout
38296
38297 \end_inset
38298 </cell>
38299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38300 \begin_inset Text
38301
38302 \begin_layout Standard
38303
38304 \size footnotesize
38305 None
38306 \end_layout
38307
38308 \end_inset
38309 </cell>
38310 </row>
38311 <row topline="true">
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38313 \begin_inset Text
38314
38315 \begin_layout Standard
38316
38317 \size footnotesize
38318 RECV
38319 \end_layout
38320
38321 \end_inset
38322 </cell>
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38324 \begin_inset Text
38325
38326 \begin_layout Standard
38327
38328 \size footnotesize
38329 IC_RESULT()
38330 \end_layout
38331
38332 \end_inset
38333 </cell>
38334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38335 \begin_inset Text
38336
38337 \begin_layout Standard
38338
38339 \size footnotesize
38340 This is used for receiving parameters passed in registers;
38341 \newline
38342 Move the values
38343  in the next parameter register to IC_RESULT 
38344 \end_layout
38345
38346 \end_inset
38347 </cell>
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38349 \begin_inset Text
38350
38351 \begin_layout Standard
38352
38353 \size footnotesize
38354 None
38355 \end_layout
38356
38357 \end_inset
38358 </cell>
38359 </row>
38360 <row topline="true" bottomline="true">
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38362 \begin_inset Text
38363
38364 \begin_layout Standard
38365
38366 \shape slanted
38367 \size footnotesize
38368 (some more have been added)
38369 \end_layout
38370
38371 \end_inset
38372 </cell>
38373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38374 \begin_inset Text
38375
38376 \begin_layout Standard
38377
38378 \end_layout
38379
38380 \end_inset
38381 </cell>
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38383 \begin_inset Text
38384
38385 \begin_layout Standard
38386
38387 \end_layout
38388
38389 \end_inset
38390 </cell>
38391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38392 \begin_inset Text
38393
38394 \begin_layout Standard
38395
38396 \shape slanted
38397 \size footnotesize
38398 see f.e.
38399  
38400 \family typewriter
38401 gen51Code()
38402 \family default
38403  in 
38404 \family typewriter
38405 src/mcs51/gen.c
38406 \end_layout
38407
38408 \end_inset
38409 </cell>
38410 </row>
38411 </lyxtabular>
38412
38413 \end_inset
38414
38415
38416 \end_layout
38417
38418 \begin_layout Standard
38419 \begin_inset Note Note
38420 status collapsed
38421
38422 \begin_layout Standard
38423 In the original article Figure II was announced to be downloadable on 
38424 \shape italic
38425 Circuit Cellar
38426 \shape default
38427 's web site.
38428  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38429 \end_layout
38430
38431 \end_inset
38432
38433
38434 \end_layout
38435
38436 \begin_layout Paragraph*
38437 ICode Example
38438 \begin_inset LatexCommand \index{iCode}
38439
38440 \end_inset
38441
38442
38443 \end_layout
38444
38445 \begin_layout Standard
38446 This section shows some details of iCode.
38447  The example C code does not do anything useful; it is used as an example
38448  to illustrate the intermediate code generated by the compiler.
38449 \end_layout
38450
38451 \begin_layout Verse
38452
38453 \family typewriter
38454 1.\InsetSpace ~
38455 xdata int * p;
38456 \newline
38457 2.\InsetSpace ~
38458 int gint;
38459 \newline
38460 3.\InsetSpace ~
38461 /* This function does nothing useful.
38462  It is used
38463 \newline
38464 4.\InsetSpace ~
38465 \InsetSpace ~
38466 \InsetSpace ~
38467 \InsetSpace ~
38468 for the purpose of explaining iCode */
38469 \newline
38470 5.\InsetSpace ~
38471 short function (data
38472  int *x)
38473 \newline
38474 6.\InsetSpace ~
38475 {
38476 \newline
38477 7.\InsetSpace ~
38478 \InsetSpace ~
38479 \InsetSpace ~
38480 short i=10; \InsetSpace ~
38481 \InsetSpace ~
38482 /* dead initialization eliminated */
38483 \newline
38484 8.\InsetSpace ~
38485 \InsetSpace ~
38486 \InsetSpace ~
38487 short sum=10;
38488  /* dead initialization eliminated */
38489 \newline
38490 9.\InsetSpace ~
38491 \InsetSpace ~
38492 \InsetSpace ~
38493 short mul;
38494 \newline
38495 10.\InsetSpace ~
38496 \InsetSpace ~
38497 int j ;
38498 \newline
38499 11.\InsetSpace ~
38500 \InsetSpace ~
38501 while (*x) *x++
38502  = *p++; 
38503 \newline
38504 12.\InsetSpace ~
38505 \InsetSpace ~
38506 \InsetSpace ~
38507 \InsetSpace ~
38508 sum = 0 ; 
38509 \newline
38510 13.\InsetSpace ~
38511 \InsetSpace ~
38512 mul = 0;
38513 \newline
38514 14.\InsetSpace ~
38515 \InsetSpace ~
38516 /* compiler detects i,j to be induction
38517  variables */
38518 \newline
38519 15.\InsetSpace ~
38520 \InsetSpace ~
38521 for (i = 0, j = 10 ; i < 10 ; i++, j
38522 \family default
38523 -
38524 \begin_inset ERT
38525 status collapsed
38526
38527 \begin_layout Standard
38528
38529
38530 \backslash
38531 /
38532 \end_layout
38533
38534 \end_inset
38535
38536 -
38537 \family typewriter
38538 ) {
38539 \newline
38540 16.\InsetSpace ~
38541 \InsetSpace ~
38542 \InsetSpace ~
38543 \InsetSpace ~
38544 sum += i;
38545 \newline
38546 17.\InsetSpace ~
38547 \InsetSpace ~
38548 \InsetSpace ~
38549 \InsetSpace ~
38550 mul += i * 3; \InsetSpace ~
38551 \InsetSpace ~
38552 /* this multiplication remains */
38553 \newline
38554 18.\InsetSpace ~
38555 \InsetSpace ~
38556 \InsetSpace ~
38557 \InsetSpace ~
38558 gint +=
38559  j * 3;\InsetSpace ~
38560 \InsetSpace ~
38561 /* this multiplication changed to addition */
38562 \newline
38563 19.\InsetSpace ~
38564 \InsetSpace ~
38565 }
38566 \newline
38567 20.\InsetSpace ~
38568 \InsetSpace ~
38569 return sum+mul;
38570 \newline
38571 21.\InsetSpace ~
38572 }
38573 \end_layout
38574
38575 \begin_layout Standard
38576 In addition to the operands each iCode contains information about the filename
38577  and line it corresponds to in the source file.
38578  The first field in the listing should be interpreted as follows:
38579 \newline
38580
38581 \shape italic
38582 \size footnotesize
38583 Filename(linenumber: iCode Execution sequence number : ICode hash table
38584  key : loop depth of the iCode).
38585 \shape default
38586 \size default
38587
38588 \newline
38589 Then follows the human readable form of the ICode operation.
38590  Each operand of this triplet form can be of three basic types a) compiler
38591  generated temporary b) user defined variable c) a constant value.
38592  Note that local variables and parameters are replaced by compiler generated
38593  temporaries.
38594  Live ranges
38595 \begin_inset LatexCommand \index{Live range analysis}
38596
38597 \end_inset
38598
38599  are computed only for temporaries (i.e.
38600  live ranges are not computed for global variables).
38601  Registers
38602 \begin_inset LatexCommand \index{Register allocation}
38603
38604 \end_inset
38605
38606  are allocated for temporaries only.
38607  Operands are formatted in the following manner:
38608 \newline
38609
38610 \shape italic
38611 \size footnotesize
38612 Operand Name [lr live-from : live-to ] { type information } [ registers
38613  allocated ].
38614 \shape default
38615 \size default
38616
38617 \newline
38618 As mentioned earlier the live ranges are computed in terms of the execution
38619  sequence number of the iCodes, for example 
38620 \newline
38621 the iTemp0 is live from (i.e.
38622  first defined in iCode with execution sequence number 3, and is last used
38623  in the iCode with sequence number 5).
38624  For induction variables such as iTemp21 the live range computation extends
38625  the lifetime from the start to the end of the loop.
38626 \newline
38627 The register allocator
38628  used the live range information to allocate registers, the same registers
38629  may be used for different temporaries if their live ranges do not overlap,
38630  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38631  ranges do not overlap.
38632  In addition the allocator also takes into consideration the type and usage
38633  of a temporary, for example itemp6 is a pointer to near space and is used
38634  as to fetch data from (i.e.
38635  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38636  Some short lived temporaries are allocated to special registers which have
38637  meaning to the code generator e.g.
38638  iTemp13 is allocated to a pseudo register CC which tells the back end that
38639  the temporary is used only for a conditional jump the code generation makes
38640  use of this information to optimize a compare and jump ICode.
38641 \newline
38642 There are several
38643  loop optimizations
38644 \begin_inset LatexCommand \index{Loop optimization}
38645
38646 \end_inset
38647
38648  performed by the compiler.
38649  It can detect induction variables iTemp21(i) and iTemp23(j).
38650  Also note the compiler does selective strength reduction
38651 \begin_inset LatexCommand \index{Strength reduction}
38652
38653 \end_inset
38654
38655 , i.e.
38656  the multiplication of an induction variable in line 18 (gint = j * 3) is
38657  changed to addition, a new temporary iTemp17 is allocated and assigned
38658  a initial value, a constant 3 is then added for each iteration of the loop.
38659  The compiler does not change the multiplication
38660 \begin_inset LatexCommand \index{Multiplication}
38661
38662 \end_inset
38663
38664  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38665 \newline
38666
38667 Note the dead code elimination
38668 \begin_inset LatexCommand \index{Dead-code elimination}
38669
38670 \end_inset
38671
38672  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38673  respectively.
38674 \newline
38675
38676 \end_layout
38677
38678 \begin_layout Standard
38679
38680 \size footnotesize
38681 Sample.c (5:1:0:0) _entry($9) :
38682 \end_layout
38683
38684 \begin_layout Standard
38685
38686 \size footnotesize
38687 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38688 \end_layout
38689
38690 \begin_layout Standard
38691
38692 \size footnotesize
38693 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38694 \end_layout
38695
38696 \begin_layout Standard
38697
38698 \size footnotesize
38699 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38700 \end_layout
38701
38702 \begin_layout Standard
38703
38704 \size footnotesize
38705 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38706  * int}[r2]
38707 \end_layout
38708
38709 \begin_layout Standard
38710
38711 \size footnotesize
38712 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38713 \end_layout
38714
38715 \begin_layout Standard
38716
38717 \size footnotesize
38718 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38719  int}[r0]]
38720 \end_layout
38721
38722 \begin_layout Standard
38723
38724 \size footnotesize
38725 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38726 \end_layout
38727
38728 \begin_layout Standard
38729
38730 \size footnotesize
38731 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38732  * int}
38733 \end_layout
38734
38735 \begin_layout Standard
38736
38737 \size footnotesize
38738 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38739  {short}
38740 \end_layout
38741
38742 \begin_layout Standard
38743
38744 \size footnotesize
38745 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38746  * int}[DPTR]]
38747 \end_layout
38748
38749 \begin_layout Standard
38750
38751 \size footnotesize
38752 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38753 }[r2 r3]
38754 \end_layout
38755
38756 \begin_layout Standard
38757
38758 \size footnotesize
38759 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38760  * int}[r0] + 0x2 {short}
38761 \end_layout
38762
38763 \begin_layout Standard
38764
38765 \size footnotesize
38766 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38767 \end_layout
38768
38769 \begin_layout Standard
38770
38771 \size footnotesize
38772 Sample.c(11:17:21:0)_whilebreak_0($3) :
38773 \end_layout
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38779 \end_layout
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38785 \end_layout
38786
38787 \begin_layout Standard
38788
38789 \size footnotesize
38790 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38791 \end_layout
38792
38793 \begin_layout Standard
38794
38795 \size footnotesize
38796 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38797 \end_layout
38798
38799 \begin_layout Standard
38800
38801 \size footnotesize
38802 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38803 \end_layout
38804
38805 \begin_layout Standard
38806
38807 \size footnotesize
38808 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38809 \end_layout
38810
38811 \begin_layout Standard
38812
38813 \size footnotesize
38814 Sample.c(15:24:26:1)_forcond_0($4) :
38815 \end_layout
38816
38817 \begin_layout Standard
38818
38819 \size footnotesize
38820 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38821  < 0xa {short}
38822 \end_layout
38823
38824 \begin_layout Standard
38825
38826 \size footnotesize
38827 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38828 \end_layout
38829
38830 \begin_layout Standard
38831
38832 \size footnotesize
38833 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38834  + ITemp21 [lr21:38]{short}[r4]
38835 \end_layout
38836
38837 \begin_layout Standard
38838
38839 \size footnotesize
38840 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38841  * 0x3 {short}
38842 \end_layout
38843
38844 \begin_layout Standard
38845
38846 \size footnotesize
38847 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38848  + iTemp15 [lr29:30]{short}[r1]
38849 \end_layout
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38855  r0]- 0x3 {short}
38856 \end_layout
38857
38858 \begin_layout Standard
38859
38860 \size footnotesize
38861 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38862 int}[r7 r0]
38863 \end_layout
38864
38865 \begin_layout Standard
38866
38867 \size footnotesize
38868 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38869  + 0x1 {short}
38870 \end_layout
38871
38872 \begin_layout Standard
38873
38874 \size footnotesize
38875 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38876  r6]- 0x1 {short}
38877 \end_layout
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 Sample.c(19:38:47:1) goto _forcond_0($4)
38883 \end_layout
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 Sample.c(19:39:48:0)_forbreak_0($7) :
38889 \end_layout
38890
38891 \begin_layout Standard
38892
38893 \size footnotesize
38894 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38895  + ITemp11 [lr19:40]{short}[r3]
38896 \end_layout
38897
38898 \begin_layout Standard
38899
38900 \size footnotesize
38901 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38902 \end_layout
38903
38904 \begin_layout Standard
38905
38906 \size footnotesize
38907 Sample.c(20:42:51:0)_return($8) :
38908 \end_layout
38909
38910 \begin_layout Standard
38911
38912 \size footnotesize
38913 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38914 \size default
38915
38916 \newline
38917
38918 \newline
38919 Finally the code generated for this function:
38920 \newline
38921
38922 \end_layout
38923
38924 \begin_layout Standard
38925
38926 \size footnotesize
38927 .area DSEG (DATA)
38928 \end_layout
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 _p::
38934 \end_layout
38935
38936 \begin_layout Standard
38937
38938 \size footnotesize
38939 \InsetSpace ~
38940 \InsetSpace ~
38941 .ds 2
38942 \end_layout
38943
38944 \begin_layout Standard
38945
38946 \size footnotesize
38947 _gint::
38948 \end_layout
38949
38950 \begin_layout Standard
38951
38952 \size footnotesize
38953 \InsetSpace ~
38954 \InsetSpace ~
38955 .ds 2
38956 \end_layout
38957
38958 \begin_layout Standard
38959
38960 \size footnotesize
38961 ; sample.c 5
38962 \end_layout
38963
38964 \begin_layout Standard
38965
38966 \size footnotesize
38967 ; ----------------------------------------------
38968 \end_layout
38969
38970 \begin_layout Standard
38971
38972 \size footnotesize
38973 ; function function
38974 \end_layout
38975
38976 \begin_layout Standard
38977
38978 \size footnotesize
38979 ; ----------------------------------------------
38980 \end_layout
38981
38982 \begin_layout Standard
38983
38984 \size footnotesize
38985 _function:
38986 \end_layout
38987
38988 \begin_layout Standard
38989
38990 \size footnotesize
38991 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38992 \end_layout
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 \InsetSpace ~
38998 \InsetSpace ~
38999 mov r2,dpl
39000 \end_layout
39001
39002 \begin_layout Standard
39003
39004 \size footnotesize
39005 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39006 \end_layout
39007
39008 \begin_layout Standard
39009
39010 \size footnotesize
39011 \InsetSpace ~
39012 \InsetSpace ~
39013 mov ar0,r2
39014 \end_layout
39015
39016 \begin_layout Standard
39017
39018 \size footnotesize
39019 ;_whilecontinue_0($1) :
39020 \end_layout
39021
39022 \begin_layout Standard
39023
39024 \size footnotesize
39025 00101$:
39026 \end_layout
39027
39028 \begin_layout Standard
39029
39030 \size footnotesize
39031 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39032 \end_layout
39033
39034 \begin_layout Standard
39035
39036 \size footnotesize
39037 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39038 \end_layout
39039
39040 \begin_layout Standard
39041
39042 \size footnotesize
39043 \InsetSpace ~
39044 \InsetSpace ~
39045 mov ar2,@r0
39046 \end_layout
39047
39048 \begin_layout Standard
39049
39050 \size footnotesize
39051 \InsetSpace ~
39052 \InsetSpace ~
39053 inc r0
39054 \end_layout
39055
39056 \begin_layout Standard
39057
39058 \size footnotesize
39059 \InsetSpace ~
39060 \InsetSpace ~
39061 mov ar3,@r0
39062 \end_layout
39063
39064 \begin_layout Standard
39065
39066 \size footnotesize
39067 \InsetSpace ~
39068 \InsetSpace ~
39069 dec r0
39070 \end_layout
39071
39072 \begin_layout Standard
39073
39074 \size footnotesize
39075 \InsetSpace ~
39076 \InsetSpace ~
39077 mov a,r2
39078 \end_layout
39079
39080 \begin_layout Standard
39081
39082 \size footnotesize
39083 \InsetSpace ~
39084 \InsetSpace ~
39085 orl a,r3
39086 \end_layout
39087
39088 \begin_layout Standard
39089
39090 \size footnotesize
39091 \InsetSpace ~
39092 \InsetSpace ~
39093 jz 00103$
39094 \end_layout
39095
39096 \begin_layout Standard
39097
39098 \size footnotesize
39099 00114$:
39100 \end_layout
39101
39102 \begin_layout Standard
39103
39104 \size footnotesize
39105 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39106 \end_layout
39107
39108 \begin_layout Standard
39109
39110 \size footnotesize
39111 \InsetSpace ~
39112 \InsetSpace ~
39113 mov dpl,_p
39114 \end_layout
39115
39116 \begin_layout Standard
39117
39118 \size footnotesize
39119 \InsetSpace ~
39120 \InsetSpace ~
39121 mov dph,(_p + 1)
39122 \end_layout
39123
39124 \begin_layout Standard
39125
39126 \size footnotesize
39127 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39128 \end_layout
39129
39130 \begin_layout Standard
39131
39132 \size footnotesize
39133 \InsetSpace ~
39134 \InsetSpace ~
39135 mov a,#0x02
39136 \end_layout
39137
39138 \begin_layout Standard
39139
39140 \size footnotesize
39141 \InsetSpace ~
39142 \InsetSpace ~
39143 add a,_p
39144 \end_layout
39145
39146 \begin_layout Standard
39147
39148 \size footnotesize
39149 \InsetSpace ~
39150 \InsetSpace ~
39151 mov _p,a
39152 \end_layout
39153
39154 \begin_layout Standard
39155
39156 \size footnotesize
39157 \InsetSpace ~
39158 \InsetSpace ~
39159 clr a
39160 \end_layout
39161
39162 \begin_layout Standard
39163
39164 \size footnotesize
39165 \InsetSpace ~
39166 \InsetSpace ~
39167 addc a,(_p + 1)
39168 \end_layout
39169
39170 \begin_layout Standard
39171
39172 \size footnotesize
39173 \InsetSpace ~
39174 \InsetSpace ~
39175 mov (_p + 1),a
39176 \end_layout
39177
39178 \begin_layout Standard
39179
39180 \size footnotesize
39181 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39182 \end_layout
39183
39184 \begin_layout Standard
39185
39186 \size footnotesize
39187 \InsetSpace ~
39188 \InsetSpace ~
39189 movx a,@dptr
39190 \end_layout
39191
39192 \begin_layout Standard
39193
39194 \size footnotesize
39195 \InsetSpace ~
39196 \InsetSpace ~
39197 mov r2,a
39198 \end_layout
39199
39200 \begin_layout Standard
39201
39202 \size footnotesize
39203 \InsetSpace ~
39204 \InsetSpace ~
39205 inc dptr
39206 \end_layout
39207
39208 \begin_layout Standard
39209
39210 \size footnotesize
39211 \InsetSpace ~
39212 \InsetSpace ~
39213 movx a,@dptr
39214 \end_layout
39215
39216 \begin_layout Standard
39217
39218 \size footnotesize
39219 \InsetSpace ~
39220 \InsetSpace ~
39221 mov r3,a
39222 \end_layout
39223
39224 \begin_layout Standard
39225
39226 \size footnotesize
39227 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39228 \end_layout
39229
39230 \begin_layout Standard
39231
39232 \size footnotesize
39233 \InsetSpace ~
39234 \InsetSpace ~
39235 mov @r0,ar2
39236 \end_layout
39237
39238 \begin_layout Standard
39239
39240 \size footnotesize
39241 \InsetSpace ~
39242 \InsetSpace ~
39243 inc r0
39244 \end_layout
39245
39246 \begin_layout Standard
39247
39248 \size footnotesize
39249 \InsetSpace ~
39250 \InsetSpace ~
39251 mov @r0,ar3
39252 \end_layout
39253
39254 \begin_layout Standard
39255
39256 \size footnotesize
39257 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39258 \end_layout
39259
39260 \begin_layout Standard
39261
39262 \size footnotesize
39263 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39264 \end_layout
39265
39266 \begin_layout Standard
39267
39268 \size footnotesize
39269 ; 0x2 {short}
39270 \end_layout
39271
39272 \begin_layout Standard
39273
39274 \size footnotesize
39275 \InsetSpace ~
39276 \InsetSpace ~
39277 inc r0
39278 \end_layout
39279
39280 \begin_layout Standard
39281
39282 \size footnotesize
39283 ; goto _whilecontinue_0($1)
39284 \end_layout
39285
39286 \begin_layout Standard
39287
39288 \size footnotesize
39289 \InsetSpace ~
39290 \InsetSpace ~
39291 sjmp 00101$
39292 \end_layout
39293
39294 \begin_layout Standard
39295
39296 \size footnotesize
39297 ; _whilebreak_0($3) :
39298 \end_layout
39299
39300 \begin_layout Standard
39301
39302 \size footnotesize
39303 00103$:
39304 \end_layout
39305
39306 \begin_layout Standard
39307
39308 \size footnotesize
39309 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39310 \end_layout
39311
39312 \begin_layout Standard
39313
39314 \size footnotesize
39315 \InsetSpace ~
39316 \InsetSpace ~
39317 mov r2,#0x00
39318 \end_layout
39319
39320 \begin_layout Standard
39321
39322 \size footnotesize
39323 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39324 \end_layout
39325
39326 \begin_layout Standard
39327
39328 \size footnotesize
39329 \InsetSpace ~
39330 \InsetSpace ~
39331 mov r3,#0x00
39332 \end_layout
39333
39334 \begin_layout Standard
39335
39336 \size footnotesize
39337 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39338 \end_layout
39339
39340 \begin_layout Standard
39341
39342 \size footnotesize
39343 \InsetSpace ~
39344 \InsetSpace ~
39345 mov r4,#0x00
39346 \end_layout
39347
39348 \begin_layout Standard
39349
39350 \size footnotesize
39351 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39352 \end_layout
39353
39354 \begin_layout Standard
39355
39356 \size footnotesize
39357 \InsetSpace ~
39358 \InsetSpace ~
39359 mov r5,#0x0A
39360 \end_layout
39361
39362 \begin_layout Standard
39363
39364 \size footnotesize
39365 \InsetSpace ~
39366 \InsetSpace ~
39367 mov r6,#0x00
39368 \end_layout
39369
39370 \begin_layout Standard
39371
39372 \size footnotesize
39373 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39374 \end_layout
39375
39376 \begin_layout Standard
39377
39378 \size footnotesize
39379 \InsetSpace ~
39380 \InsetSpace ~
39381 mov r7,#0x1E
39382 \end_layout
39383
39384 \begin_layout Standard
39385
39386 \size footnotesize
39387 \InsetSpace ~
39388 \InsetSpace ~
39389 mov r0,#0x00
39390 \end_layout
39391
39392 \begin_layout Standard
39393
39394 \size footnotesize
39395 ; _forcond_0($4) :
39396 \end_layout
39397
39398 \begin_layout Standard
39399
39400 \size footnotesize
39401 00104$:
39402 \end_layout
39403
39404 \begin_layout Standard
39405
39406 \size footnotesize
39407 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39408 \end_layout
39409
39410 \begin_layout Standard
39411
39412 \size footnotesize
39413 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39414 \end_layout
39415
39416 \begin_layout Standard
39417
39418 \size footnotesize
39419 \InsetSpace ~
39420 \InsetSpace ~
39421 clr c
39422 \end_layout
39423
39424 \begin_layout Standard
39425
39426 \size footnotesize
39427 \InsetSpace ~
39428 \InsetSpace ~
39429 mov a,r4
39430 \end_layout
39431
39432 \begin_layout Standard
39433
39434 \size footnotesize
39435 \InsetSpace ~
39436 \InsetSpace ~
39437 xrl a,#0x80
39438 \end_layout
39439
39440 \begin_layout Standard
39441
39442 \size footnotesize
39443 \InsetSpace ~
39444 \InsetSpace ~
39445 subb a,#0x8a
39446 \end_layout
39447
39448 \begin_layout Standard
39449
39450 \size footnotesize
39451 \InsetSpace ~
39452 \InsetSpace ~
39453 jnc 00107$
39454 \end_layout
39455
39456 \begin_layout Standard
39457
39458 \size footnotesize
39459 00115$:
39460 \end_layout
39461
39462 \begin_layout Standard
39463
39464 \size footnotesize
39465 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39466 \end_layout
39467
39468 \begin_layout Standard
39469
39470 \size footnotesize
39471 ; iTemp21 [lr21:38]{short}[r4]
39472 \end_layout
39473
39474 \begin_layout Standard
39475
39476 \size footnotesize
39477 \InsetSpace ~
39478 \InsetSpace ~
39479 mov a,r4
39480 \end_layout
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 \InsetSpace ~
39486 \InsetSpace ~
39487 add a,r2
39488 \end_layout
39489
39490 \begin_layout Standard
39491
39492 \size footnotesize
39493 \InsetSpace ~
39494 \InsetSpace ~
39495 mov r2,a
39496 \end_layout
39497
39498 \begin_layout Standard
39499
39500 \size footnotesize
39501 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39502 \end_layout
39503
39504 \begin_layout Standard
39505
39506 \size footnotesize
39507 \InsetSpace ~
39508 \InsetSpace ~
39509 mov b,#0x03
39510 \end_layout
39511
39512 \begin_layout Standard
39513
39514 \size footnotesize
39515 \InsetSpace ~
39516 \InsetSpace ~
39517 mov a,r4
39518 \end_layout
39519
39520 \begin_layout Standard
39521
39522 \size footnotesize
39523 \InsetSpace ~
39524 \InsetSpace ~
39525 mul ab
39526 \end_layout
39527
39528 \begin_layout Standard
39529
39530 \size footnotesize
39531 \InsetSpace ~
39532 \InsetSpace ~
39533 mov r1,a
39534 \end_layout
39535
39536 \begin_layout Standard
39537
39538 \size footnotesize
39539 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39540 \end_layout
39541
39542 \begin_layout Standard
39543
39544 \size footnotesize
39545 ; iTemp15 [lr29:30]{short}[r1]
39546 \end_layout
39547
39548 \begin_layout Standard
39549
39550 \size footnotesize
39551 \InsetSpace ~
39552 \InsetSpace ~
39553 add a,r3
39554 \end_layout
39555
39556 \begin_layout Standard
39557
39558 \size footnotesize
39559 \InsetSpace ~
39560 \InsetSpace ~
39561 mov r3,a
39562 \end_layout
39563
39564 \begin_layout Standard
39565
39566 \size footnotesize
39567 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39568 \end_layout
39569
39570 \begin_layout Standard
39571
39572 \size footnotesize
39573 \InsetSpace ~
39574 \InsetSpace ~
39575 mov a,r7
39576 \end_layout
39577
39578 \begin_layout Standard
39579
39580 \size footnotesize
39581 \InsetSpace ~
39582 \InsetSpace ~
39583 add a,#0xfd
39584 \end_layout
39585
39586 \begin_layout Standard
39587
39588 \size footnotesize
39589 \InsetSpace ~
39590 \InsetSpace ~
39591 mov r7,a
39592 \end_layout
39593
39594 \begin_layout Standard
39595
39596 \size footnotesize
39597 \InsetSpace ~
39598 \InsetSpace ~
39599 mov a,r0
39600 \end_layout
39601
39602 \begin_layout Standard
39603
39604 \size footnotesize
39605 \InsetSpace ~
39606 \InsetSpace ~
39607 addc a,#0xff
39608 \end_layout
39609
39610 \begin_layout Standard
39611
39612 \size footnotesize
39613 \InsetSpace ~
39614 \InsetSpace ~
39615 mov r0,a
39616 \end_layout
39617
39618 \begin_layout Standard
39619
39620 \size footnotesize
39621 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39622 \end_layout
39623
39624 \begin_layout Standard
39625
39626 \size footnotesize
39627 \InsetSpace ~
39628 \InsetSpace ~
39629 mov a,r7
39630 \end_layout
39631
39632 \begin_layout Standard
39633
39634 \size footnotesize
39635 \InsetSpace ~
39636 \InsetSpace ~
39637 add a,_gint
39638 \end_layout
39639
39640 \begin_layout Standard
39641
39642 \size footnotesize
39643 \InsetSpace ~
39644 \InsetSpace ~
39645 mov _gint,a
39646 \end_layout
39647
39648 \begin_layout Standard
39649
39650 \size footnotesize
39651 \InsetSpace ~
39652 \InsetSpace ~
39653 mov a,r0
39654 \end_layout
39655
39656 \begin_layout Standard
39657
39658 \size footnotesize
39659 \InsetSpace ~
39660 \InsetSpace ~
39661 addc a,(_gint + 1)
39662 \end_layout
39663
39664 \begin_layout Standard
39665
39666 \size footnotesize
39667 \InsetSpace ~
39668 \InsetSpace ~
39669 mov (_gint + 1),a
39670 \end_layout
39671
39672 \begin_layout Standard
39673
39674 \size footnotesize
39675 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39676 \end_layout
39677
39678 \begin_layout Standard
39679
39680 \size footnotesize
39681 \InsetSpace ~
39682 \InsetSpace ~
39683 inc r4
39684 \end_layout
39685
39686 \begin_layout Standard
39687
39688 \size footnotesize
39689 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39690 \end_layout
39691
39692 \begin_layout Standard
39693
39694 \size footnotesize
39695 \InsetSpace ~
39696 \InsetSpace ~
39697 dec r5
39698 \end_layout
39699
39700 \begin_layout Standard
39701
39702 \size footnotesize
39703 \InsetSpace ~
39704 \InsetSpace ~
39705 cjne r5,#0xff,00104$
39706 \end_layout
39707
39708 \begin_layout Standard
39709
39710 \size footnotesize
39711 \InsetSpace ~
39712 \InsetSpace ~
39713 dec r6
39714 \end_layout
39715
39716 \begin_layout Standard
39717
39718 \size footnotesize
39719 ; goto _forcond_0($4)
39720 \end_layout
39721
39722 \begin_layout Standard
39723
39724 \size footnotesize
39725 \InsetSpace ~
39726 \InsetSpace ~
39727 sjmp 00104$
39728 \end_layout
39729
39730 \begin_layout Standard
39731
39732 \size footnotesize
39733 ; _forbreak_0($7) :
39734 \end_layout
39735
39736 \begin_layout Standard
39737
39738 \size footnotesize
39739 00107$:
39740 \end_layout
39741
39742 \begin_layout Standard
39743
39744 \size footnotesize
39745 ; ret iTemp24 [lr40:41]{short}
39746 \end_layout
39747
39748 \begin_layout Standard
39749
39750 \size footnotesize
39751 \InsetSpace ~
39752 \InsetSpace ~
39753 mov a,r3
39754 \end_layout
39755
39756 \begin_layout Standard
39757
39758 \size footnotesize
39759 \InsetSpace ~
39760 \InsetSpace ~
39761 add a,r2
39762 \end_layout
39763
39764 \begin_layout Standard
39765
39766 \size footnotesize
39767 \InsetSpace ~
39768 \InsetSpace ~
39769 mov dpl,a
39770 \end_layout
39771
39772 \begin_layout Standard
39773
39774 \size footnotesize
39775 ; _return($8) :
39776 \end_layout
39777
39778 \begin_layout Standard
39779
39780 \size footnotesize
39781 00108$:
39782 \end_layout
39783
39784 \begin_layout Standard
39785
39786 \size footnotesize
39787 \InsetSpace ~
39788 \InsetSpace ~
39789 ret
39790 \newline
39791
39792 \end_layout
39793
39794 \begin_layout Section
39795 A few words about basic block successors, predecessors and dominators
39796 \end_layout
39797
39798 \begin_layout Standard
39799 Successors are basic blocks
39800 \begin_inset LatexCommand \index{Basic blocks}
39801
39802 \end_inset
39803
39804  that might execute after this basic block.
39805 \newline
39806 Predecessors are basic blocks
39807  that might execute before reaching this basic block.
39808 \newline
39809 Dominators are basic
39810  blocks that WILL execute before reaching this basic block.
39811 \newline
39812
39813 \end_layout
39814
39815 \begin_layout Standard
39816 [basic block 1]
39817 \end_layout
39818
39819 \begin_layout Standard
39820 if (something)
39821 \end_layout
39822
39823 \begin_layout Standard
39824 \InsetSpace ~
39825 \InsetSpace ~
39826 \InsetSpace ~
39827 \InsetSpace ~
39828 [basic block 2]
39829 \end_layout
39830
39831 \begin_layout Standard
39832 else
39833 \end_layout
39834
39835 \begin_layout Standard
39836 \InsetSpace ~
39837 \InsetSpace ~
39838 \InsetSpace ~
39839 \InsetSpace ~
39840 [basic block 3]
39841 \end_layout
39842
39843 \begin_layout Standard
39844 [basic block 4]
39845 \newline
39846
39847 \end_layout
39848
39849 \begin_layout Standard
39850 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39851 \end_layout
39852
39853 \begin_layout Standard
39854 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39855 \end_layout
39856
39857 \begin_layout Standard
39858 c) domVect of [BB4] = BB1 ...
39859  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39860  was executed.
39861 \end_layout
39862
39863 \begin_layout Chapter
39864 Acknowledgments
39865 \end_layout
39866
39867 \begin_layout Standard
39868 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39869
39870 \end_inset
39871
39872
39873 \newline
39874
39875 \newline
39876
39877 \emph on
39878 Thanks to all the other volunteer developers who have helped with coding,
39879  testing, web-page creation, distribution sets, etc.
39880  You know who you are :-)
39881 \emph default
39882
39883 \newline
39884
39885 \newline
39886
39887 \emph on
39888 Thanks to Sourceforge 
39889 \begin_inset LatexCommand \url{http://www.sf.net}
39890
39891 \end_inset
39892
39893  which has hosted the project since 1999 and donates significant download
39894  bandwidth.
39895 \emph default
39896
39897 \newline
39898
39899 \newline
39900
39901 \emph on
39902 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39903  cycles and bandwidth for snapshot builds.
39904 \newline
39905
39906 \end_layout
39907
39908 \begin_layout Standard
39909 This document was initially written by Sandeep Dutta
39910 \end_layout
39911
39912 \begin_layout Standard
39913 All product names mentioned herein may be trademarks
39914 \begin_inset LatexCommand \index{Trademarks}
39915
39916 \end_inset
39917
39918  of their respective companies.
39919  
39920 \end_layout
39921
39922 \begin_layout Section*
39923 Alphabetical index
39924 \end_layout
39925
39926 \begin_layout Standard
39927 To avoid confusion, the installation and building options for SDCC itself
39928  (chapter 2) are not part of the index.
39929 \end_layout
39930
39931 \begin_layout Standard
39932 \begin_inset LatexCommand \printindex{}
39933
39934 \end_inset
39935
39936
39937 \end_layout
39938
39939 \end_body
39940 \end_document