* doc/sdccman.lyx: removed two index entries which prevented the
[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 \family default
6283 \series default
6284
6285 \newline
6286
6287 \end_layout
6288
6289 \begin_layout Standard
6290 Or, if you preffer:
6291 \family sans
6292 \series bold
6293
6294 \newline
6295
6296 \end_layout
6297
6298 \begin_layout Standard
6299
6300 \family sans
6301 \series bold
6302 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6303 \family default
6304 \series default
6305
6306 \newline
6307
6308 \end_layout
6309
6310 \begin_layout Standard
6311 If the file already exists in the library, it will be replaced.
6312  If a list of .rel files is available, you can tell sdcclib to add those
6313  files to a library.
6314  For example, if the file 'myliblist.txt' contains
6315 \family sans
6316 \series bold
6317
6318 \newline
6319
6320 \end_layout
6321
6322 \begin_layout Standard
6323
6324 \family sans
6325 \series bold
6326 _divsint.rel
6327 \end_layout
6328
6329 \begin_layout Standard
6330
6331 \family sans
6332 \series bold
6333 _divuint.rel
6334 \end_layout
6335
6336 \begin_layout Standard
6337
6338 \family sans
6339 \series bold
6340 _modsint.rel
6341 \end_layout
6342
6343 \begin_layout Standard
6344
6345 \family sans
6346 \series bold
6347 _moduint.rel
6348 \end_layout
6349
6350 \begin_layout Standard
6351
6352 \family sans
6353 \series bold
6354 _mulint.rel
6355 \family default
6356 \series default
6357
6358 \newline
6359
6360 \end_layout
6361
6362 \begin_layout Standard
6363 Use
6364 \family sans
6365 \series bold
6366
6367 \newline
6368
6369 \end_layout
6370
6371 \begin_layout Standard
6372
6373 \family sans
6374 \series bold
6375 sdcclib -l libint.lib myliblist.txt
6376 \family default
6377 \series default
6378
6379 \newline
6380
6381 \end_layout
6382
6383 \begin_layout Standard
6384 Additionally, you can instruct sdcclib to compiles the files before adding
6385  them to the library.
6386  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6387  For example:
6388 \family sans
6389 \series bold
6390
6391 \newline
6392
6393 \end_layout
6394
6395 \begin_layout Standard
6396
6397 \family sans
6398 \series bold
6399 set SDCCLIB_CC=sdcc -c
6400 \end_layout
6401
6402 \begin_layout Standard
6403
6404 \family sans
6405 \series bold
6406 sdcclib -l libint.lib myliblist.txt
6407 \family default
6408 \series default
6409
6410 \newline
6411
6412 \end_layout
6413
6414 \begin_layout Standard
6415 To see what modules and symbols are included in the library, options -s
6416  and -m are available.
6417  For example:
6418 \newline
6419
6420 \newline
6421
6422 \family sans
6423 \series bold
6424 sdcclib -s libint.lib
6425 \family default
6426
6427 \begin_inset LatexCommand \index{sdcclib}
6428
6429 \end_inset
6430
6431
6432 \newline
6433
6434 \family typewriter
6435 \series default
6436 _divsint.rel:
6437 \end_layout
6438
6439 \begin_layout Standard
6440
6441 \family typewriter
6442 __divsint_a_1_1
6443 \end_layout
6444
6445 \begin_layout Standard
6446
6447 \family typewriter
6448 __divsint_PARM_2
6449 \end_layout
6450
6451 \begin_layout Standard
6452
6453 \family typewriter
6454 __divsint
6455 \newline
6456 _divuint.rel:
6457 \end_layout
6458
6459 \begin_layout Standard
6460
6461 \family typewriter
6462 __divuint_a_1_1
6463 \end_layout
6464
6465 \begin_layout Standard
6466
6467 \family typewriter
6468 __divuint_PARM_2
6469 \end_layout
6470
6471 \begin_layout Standard
6472
6473 \family typewriter
6474 __divuint_reste_1_1
6475 \end_layout
6476
6477 \begin_layout Standard
6478
6479 \family typewriter
6480 __divuint_count_1_1
6481 \end_layout
6482
6483 \begin_layout Standard
6484
6485 \family typewriter
6486 __divuint
6487 \newline
6488 _modsint.rel:
6489 \end_layout
6490
6491 \begin_layout Standard
6492
6493 \family typewriter
6494 __modsint_a_1_1
6495 \end_layout
6496
6497 \begin_layout Standard
6498
6499 \family typewriter
6500 __modsint_PARM_2
6501 \end_layout
6502
6503 \begin_layout Standard
6504
6505 \family typewriter
6506 __modsint
6507 \newline
6508 _moduint.rel:
6509 \end_layout
6510
6511 \begin_layout Standard
6512
6513 \family typewriter
6514 __moduint_a_1_1
6515 \end_layout
6516
6517 \begin_layout Standard
6518
6519 \family typewriter
6520 __moduint_PARM_2
6521 \end_layout
6522
6523 \begin_layout Standard
6524
6525 \family typewriter
6526 __moduint_count_1_1
6527 \end_layout
6528
6529 \begin_layout Standard
6530
6531 \family typewriter
6532 __moduint
6533 \newline
6534 _mulint.rel:
6535 \end_layout
6536
6537 \begin_layout Standard
6538
6539 \family typewriter
6540 __mulint_PARM_2
6541 \end_layout
6542
6543 \begin_layout Standard
6544
6545 \family typewriter
6546 __mulint
6547 \family default
6548 \series bold
6549
6550 \newline
6551
6552 \end_layout
6553
6554 \begin_layout Standard
6555 If the source files are compiled using -
6556 \begin_inset ERT
6557 status collapsed
6558
6559 \begin_layout Standard
6560
6561
6562 \backslash
6563 /
6564 \end_layout
6565
6566 \end_inset
6567
6568 -debug
6569 \begin_inset LatexCommand \index{-\/-debug}
6570
6571 \end_inset
6572
6573 , the corresponding debug information file .adb will be include in the library
6574  file as well.
6575  The library files created with sdcclib are plain text files, so they can
6576  be viewed with a text editor.
6577  It is not recomended to modify a library file created with sdcclib using
6578  a text editor, as there are file indexes numbers located accross the file
6579  used by the linker to quickly locate the required module to link.
6580  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6581  it can be safely deleted, since all the information required for linking
6582  is embedded in the library file itself.
6583  Library files created using sdcclib are used as described in the preceding
6584  sections.
6585 \begin_inset VSpace bigskip
6586 \end_inset
6587
6588
6589 \end_layout
6590
6591 \begin_layout Section
6592 Command Line Options
6593 \begin_inset LatexCommand \index{Command Line Options}
6594
6595 \end_inset
6596
6597
6598 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6599
6600 \end_inset
6601
6602
6603 \end_layout
6604
6605 \begin_layout Subsection
6606 Processor Selection Options
6607 \begin_inset LatexCommand \index{Options processor selection}
6608
6609 \end_inset
6610
6611
6612 \begin_inset LatexCommand \index{Processor selection options}
6613
6614 \end_inset
6615
6616
6617 \end_layout
6618
6619 \begin_layout List
6620 \labelwidthstring 00.00.0000
6621
6622 \series bold
6623 -mmcs51
6624 \begin_inset LatexCommand \index{-mmcs51}
6625
6626 \end_inset
6627
6628
6629 \series default
6630  Generate code for the Intel MCS51
6631 \begin_inset LatexCommand \index{MCS51}
6632
6633 \end_inset
6634
6635  family of processors.
6636  This is the default processor target.
6637 \end_layout
6638
6639 \begin_layout List
6640 \labelwidthstring 00.00.0000
6641
6642 \series bold
6643 -mds390
6644 \begin_inset LatexCommand \index{-mds390}
6645
6646 \end_inset
6647
6648
6649 \series default
6650  Generate code for the Dallas DS80C390
6651 \begin_inset LatexCommand \index{DS80C390}
6652
6653 \end_inset
6654
6655  processor.
6656 \end_layout
6657
6658 \begin_layout List
6659 \labelwidthstring 00.00.0000
6660
6661 \series bold
6662 -mds400
6663 \begin_inset LatexCommand \index{-mds400}
6664
6665 \end_inset
6666
6667
6668 \series default
6669  Generate code for the Dallas DS80C400
6670 \begin_inset LatexCommand \index{DS80C400}
6671
6672 \end_inset
6673
6674  processor.
6675 \end_layout
6676
6677 \begin_layout List
6678 \labelwidthstring 00.00.0000
6679
6680 \series bold
6681 -mhc08
6682 \begin_inset LatexCommand \index{-mhc08}
6683
6684 \end_inset
6685
6686
6687 \series default
6688  Generate code for the Freescale/Motorola HC08
6689 \begin_inset LatexCommand \index{HC08}
6690
6691 \end_inset
6692
6693  family of processors.
6694 \end_layout
6695
6696 \begin_layout List
6697 \labelwidthstring 00.00.0000
6698
6699 \series bold
6700 -mz80
6701 \begin_inset LatexCommand \index{-mz80}
6702
6703 \end_inset
6704
6705
6706 \series default
6707  Generate code for the Zilog Z80
6708 \begin_inset LatexCommand \index{Z80}
6709
6710 \end_inset
6711
6712  family of processors.
6713 \end_layout
6714
6715 \begin_layout List
6716 \labelwidthstring 00.00.0000
6717
6718 \series bold
6719 -mgbz80
6720 \begin_inset LatexCommand \index{-mgbz80}
6721
6722 \end_inset
6723
6724
6725 \series default
6726  Generate code for the GameBoy Z80
6727 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6728
6729 \end_inset
6730
6731  processor (Not actively maintained).
6732 \end_layout
6733
6734 \begin_layout List
6735 \labelwidthstring 00.00.0000
6736
6737 \series bold
6738 -mavr
6739 \begin_inset LatexCommand \index{-mavr}
6740
6741 \end_inset
6742
6743
6744 \series default
6745  Generate code for the Atmel AVR
6746 \begin_inset LatexCommand \index{AVR}
6747
6748 \end_inset
6749
6750  processor (Not maintained, not complete).
6751  AVR users should probably have a look at winavr 
6752 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6753
6754 \end_inset
6755
6756  or 
6757 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6758
6759 \end_inset
6760
6761 , which is based on AVR-port of the gcc compiler.
6762 \end_layout
6763
6764 \begin_layout Standard
6765 \begin_inset Note Note
6766 status collapsed
6767
6768 \begin_layout Standard
6769 I think it is fair to direct users there for now.
6770  Open source is also about avoiding unnecessary work .
6771  But I didn't find the 'official' link.
6772 \end_layout
6773
6774 \end_inset
6775
6776
6777 \end_layout
6778
6779 \begin_layout List
6780 \labelwidthstring 00.00.0000
6781
6782 \series bold
6783 -mpic14
6784 \begin_inset LatexCommand \index{-mpic14}
6785
6786 \end_inset
6787
6788
6789 \series default
6790  Generate code for the Microchip PIC 14
6791 \begin_inset LatexCommand \index{PIC14}
6792
6793 \end_inset
6794
6795 -bit processors (p16f84 and variants.
6796  In development, not complete).
6797 \end_layout
6798
6799 \begin_layout Standard
6800 \begin_inset Note Note
6801 status collapsed
6802
6803 \begin_layout Standard
6804 p16f627 p16f628 p16f84 p16f873 p16f877?
6805 \end_layout
6806
6807 \end_inset
6808
6809
6810 \end_layout
6811
6812 \begin_layout List
6813 \labelwidthstring 00.00.0000
6814
6815 \series bold
6816 -mpic16
6817 \begin_inset LatexCommand \index{-mpic16}
6818
6819 \end_inset
6820
6821
6822 \series default
6823  Generate code for the Microchip PIC 16
6824 \begin_inset LatexCommand \index{PIC16}
6825
6826 \end_inset
6827
6828 -bit processors (p18f452 and variants.
6829  In development, not complete).
6830 \end_layout
6831
6832 \begin_layout List
6833 \labelwidthstring 00.00.0000
6834
6835 \series bold
6836 -mtlcs900h
6837 \series default
6838  Generate code for the Toshiba TLCS-900H
6839 \begin_inset LatexCommand \index{TLCS-900H}
6840
6841 \end_inset
6842
6843  processor (Not maintained, not complete).
6844 \end_layout
6845
6846 \begin_layout List
6847 \labelwidthstring 00.00.0000
6848
6849 \series bold
6850 -mxa51
6851 \begin_inset LatexCommand \index{-mxa51}
6852
6853 \end_inset
6854
6855
6856 \series default
6857  Generate code for the Phillips XA51
6858 \begin_inset LatexCommand \index{XA51}
6859
6860 \end_inset
6861
6862  processor (Not maintained, not complete).
6863 \end_layout
6864
6865 \begin_layout Standard
6866 \begin_inset VSpace bigskip
6867 \end_inset
6868
6869
6870 \end_layout
6871
6872 \begin_layout Subsection
6873 Preprocessor Options
6874 \begin_inset LatexCommand \index{Options preprocessor}
6875
6876 \end_inset
6877
6878
6879 \begin_inset LatexCommand \index{Preprocessor options}
6880
6881 \end_inset
6882
6883
6884 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6885
6886 \end_inset
6887
6888
6889 \end_layout
6890
6891 \begin_layout List
6892 \labelwidthstring 00.00.0000
6893
6894 \series bold
6895 -I<path>
6896 \begin_inset LatexCommand \index{-I<path>}
6897
6898 \end_inset
6899
6900
6901 \series default
6902  The additional location where the preprocessor will look for <..h> or 
6903 \begin_inset Quotes eld
6904 \end_inset
6905
6906 ..h
6907 \begin_inset Quotes erd
6908 \end_inset
6909
6910  files.
6911 \end_layout
6912
6913 \begin_layout List
6914 \labelwidthstring 00.00.0000
6915
6916 \series bold
6917 -D<macro[=value]>
6918 \begin_inset LatexCommand \index{-D<macro[=value]>}
6919
6920 \end_inset
6921
6922
6923 \series default
6924  Command line definition of macros.
6925  Passed to the preprocessor.
6926 \end_layout
6927
6928 \begin_layout List
6929 \labelwidthstring 00.00.0000
6930
6931 \series bold
6932 -M
6933 \begin_inset LatexCommand \index{-M}
6934
6935 \end_inset
6936
6937
6938 \series default
6939  Tell the preprocessor to output a rule suitable for make describing the
6940  dependencies of each object file.
6941  For each source file, the preprocessor outputs one make-rule whose target
6942  is the object file name for that source file and whose dependencies are
6943  all the files `#include'd in it.
6944  This rule may be a single line or may be continued with `
6945 \backslash
6946 '-newline if it is long.
6947  The list of rules is printed on standard output instead of the preprocessed
6948  C program.
6949  `-M' implies `-E
6950 \begin_inset LatexCommand \index{-E}
6951
6952 \end_inset
6953
6954 '.
6955 \end_layout
6956
6957 \begin_layout List
6958 \labelwidthstring 00.00.0000
6959
6960 \series bold
6961 -C
6962 \begin_inset LatexCommand \index{-C}
6963
6964 \end_inset
6965
6966
6967 \series default
6968  Tell the preprocessor not to discard comments.
6969  Used with the `-E' option.
6970 \end_layout
6971
6972 \begin_layout List
6973 \labelwidthstring 00.00.0000
6974
6975 \series bold
6976 -MM
6977 \begin_inset LatexCommand \index{-MM}
6978
6979 \end_inset
6980
6981
6982 \size large
6983 \bar under
6984  
6985 \series default
6986 \size default
6987 \bar default
6988 Like `-M' but the output mentions only the user header files included with
6989  `#include 
6990 \begin_inset Quotes eld
6991 \end_inset
6992
6993 file"'.
6994  System header files included with `#include <file>' are omitted.
6995 \end_layout
6996
6997 \begin_layout List
6998 \labelwidthstring 00.00.0000
6999
7000 \series bold
7001 -Aquestion(answer)
7002 \begin_inset LatexCommand \index{-Aquestion(answer)}
7003
7004 \end_inset
7005
7006
7007 \series default
7008  Assert the answer answer for question, in case it is tested with a preprocessor
7009  conditional such as `#if #question(answer)'.
7010  `-A-' disables the standard assertions that normally describe the target
7011  machine.
7012 \end_layout
7013
7014 \begin_layout List
7015 \labelwidthstring 00.00.0000
7016
7017 \series bold
7018 -Umacro
7019 \begin_inset LatexCommand \index{-Umacro}
7020
7021 \end_inset
7022
7023
7024 \series default
7025  Undefine macro macro.
7026  `-U' options are evaluated after all `-D' options, but before any `-include'
7027  and `-imacros' options.
7028 \end_layout
7029
7030 \begin_layout List
7031 \labelwidthstring 00.00.0000
7032
7033 \series bold
7034 -dM
7035 \begin_inset LatexCommand \index{-dM}
7036
7037 \end_inset
7038
7039
7040 \series default
7041  Tell the preprocessor to output only a list of the macro definitions that
7042  are in effect at the end of preprocessing.
7043  Used with the `-E' option.
7044 \end_layout
7045
7046 \begin_layout List
7047 \labelwidthstring 00.00.0000
7048
7049 \series bold
7050 -dD
7051 \begin_inset LatexCommand \index{-dD}
7052
7053 \end_inset
7054
7055
7056 \series default
7057  Tell the preprocessor to pass all macro definitions into the output, in
7058  their proper sequence in the rest of the output.
7059 \end_layout
7060
7061 \begin_layout List
7062 \labelwidthstring 00.00.0000
7063
7064 \series bold
7065 -dN
7066 \begin_inset LatexCommand \index{-dN}
7067
7068 \end_inset
7069
7070
7071 \size large
7072 \bar under
7073  
7074 \series default
7075 \size default
7076 \bar default
7077 Like `-dD' except that the macro arguments and contents are omitted.
7078  Only `#define name' is included in the output.
7079 \end_layout
7080
7081 \begin_layout List
7082 \labelwidthstring 00.00.0000
7083
7084 \series bold
7085 -pedantic-parse-number
7086 \begin_inset LatexCommand \index{pedantic}
7087
7088 \end_inset
7089
7090
7091 \begin_inset LatexCommand \index{-pedantic-parse-number}
7092
7093 \end_inset
7094
7095
7096 \size large
7097 \bar under
7098
7099 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7100
7101 \end_inset
7102
7103  
7104 \series default
7105 \size default
7106 \bar default
7107 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7108  and the macro LO_B(3) gets expanded.
7109  See also #pragma pedantic_parse_number 
7110 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7111
7112 \end_inset
7113
7114  in section
7115 \begin_inset LatexCommand \ref{sec:Pragmas}
7116
7117 \end_inset
7118
7119  
7120 \emph on
7121 Note: this functionality is not in conformance with C99 standard!
7122 \end_layout
7123
7124 \begin_layout List
7125 \labelwidthstring 00.00.0000
7126
7127 \series bold
7128 -Wp\InsetSpace ~
7129 preprocessorOption[,preprocessorOption]
7130 \series default
7131
7132 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7133
7134 \end_inset
7135
7136 ...
7137  Pass the preprocessorOption to the preprocessor 
7138 \family typewriter
7139 sdcpp
7140 \family default
7141
7142 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7143
7144 \end_inset
7145
7146 .
7147  SDCC uses an adapted version of the preprocessor 
7148 \emph on
7149 cpp
7150 \emph default
7151  of the GNU Compiler Collection
7152 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7153
7154 \end_inset
7155
7156  (
7157 \emph on
7158 gcc
7159 \emph default
7160  
7161 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7162
7163 \end_inset
7164
7165 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7166 4.1.1\InsetSpace ~
7167 CPP\InsetSpace ~
7168 Manual
7169  at 
7170 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7171
7172 \end_inset
7173
7174 .
7175 \end_layout
7176
7177 \begin_layout Standard
7178 \begin_inset VSpace bigskip
7179 \end_inset
7180
7181
7182 \end_layout
7183
7184 \begin_layout Subsection
7185 Linker Options
7186 \begin_inset LatexCommand \index{Options linker}
7187
7188 \end_inset
7189
7190
7191 \begin_inset LatexCommand \index{Linker options}
7192
7193 \end_inset
7194
7195
7196 \end_layout
7197
7198 \begin_layout List
7199 \labelwidthstring 00.00.0000
7200
7201 \series bold
7202 -L\InsetSpace ~
7203 -
7204 \series default
7205
7206 \begin_inset ERT
7207 status collapsed
7208
7209 \begin_layout Standard
7210
7211
7212 \backslash
7213 /
7214 \end_layout
7215
7216 \end_inset
7217
7218
7219 \series bold
7220 -lib-path
7221 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7222
7223 \end_inset
7224
7225
7226 \begin_inset LatexCommand \index{-L -\/-lib-path}
7227
7228 \end_inset
7229
7230
7231 \series default
7232 \InsetSpace ~
7233 <absolute path to additional libraries> This option is passed to the linkage
7234  editor's additional libraries
7235 \begin_inset LatexCommand \index{Libraries}
7236
7237 \end_inset
7238
7239  search path.
7240  The path name must be absolute.
7241  Additional library files may be specified in the command line.
7242  See section Compiling programs for more details.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -
7250 \begin_inset ERT
7251 status collapsed
7252
7253 \begin_layout Standard
7254
7255
7256 \backslash
7257 /
7258 \end_layout
7259
7260 \end_inset
7261
7262 -xram-loc
7263 \series default
7264
7265 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7266
7267 \end_inset
7268
7269 \InsetSpace ~
7270 <Value> The start location of the external ram
7271 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7272
7273 \end_inset
7274
7275 , default value is 0.
7276  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7277 \begin_inset ERT
7278 status collapsed
7279
7280 \begin_layout Standard
7281
7282
7283 \backslash
7284 /
7285 \end_layout
7286
7287 \end_inset
7288
7289 -xram-loc 0x8000 or -
7290 \begin_inset ERT
7291 status collapsed
7292
7293 \begin_layout Standard
7294
7295
7296 \backslash
7297 /
7298 \end_layout
7299
7300 \end_inset
7301
7302 -xram-loc 32768.
7303 \end_layout
7304
7305 \begin_layout List
7306 \labelwidthstring 00.00.0000
7307
7308 \series bold
7309 -
7310 \begin_inset ERT
7311 status collapsed
7312
7313 \begin_layout Standard
7314
7315
7316 \backslash
7317 /
7318 \end_layout
7319
7320 \end_inset
7321
7322 -code-loc
7323 \series default
7324
7325 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7326
7327 \end_inset
7328
7329 \InsetSpace ~
7330 <Value> The start location of the code
7331 \begin_inset LatexCommand \index{code}
7332
7333 \end_inset
7334
7335  segment, default value 0.
7336  Note when this option is used the interrupt vector table
7337 \begin_inset LatexCommand \index{interrupt vector table}
7338
7339 \end_inset
7340
7341  is also relocated to the given address.
7342  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7343 \begin_inset ERT
7344 status collapsed
7345
7346 \begin_layout Standard
7347
7348
7349 \backslash
7350 /
7351 \end_layout
7352
7353 \end_inset
7354
7355 -code-loc 0x8000 or -
7356 \begin_inset ERT
7357 status collapsed
7358
7359 \begin_layout Standard
7360
7361
7362 \backslash
7363 /
7364 \end_layout
7365
7366 \end_inset
7367
7368 -code-loc 32768.
7369 \end_layout
7370
7371 \begin_layout List
7372 \labelwidthstring 00.00.0000
7373
7374 \series bold
7375 -
7376 \begin_inset ERT
7377 status collapsed
7378
7379 \begin_layout Standard
7380
7381
7382 \backslash
7383 /
7384 \end_layout
7385
7386 \end_inset
7387
7388 -stack-loc
7389 \series default
7390
7391 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7392
7393 \end_inset
7394
7395 \InsetSpace ~
7396 <Value> By default the stack
7397 \begin_inset LatexCommand \index{stack}
7398
7399 \end_inset
7400
7401  is placed after the data segment.
7402  Using this option the stack can be placed anywhere in the internal memory
7403  space of the 8051.
7404  The value entered can be in Hexadecimal or Decimal format, e.g.
7405  -
7406 \begin_inset ERT
7407 status collapsed
7408
7409 \begin_layout Standard
7410
7411
7412 \backslash
7413 /
7414 \end_layout
7415
7416 \end_inset
7417
7418 -stack-loc 0x20 or -
7419 \begin_inset ERT
7420 status collapsed
7421
7422 \begin_layout Standard
7423
7424
7425 \backslash
7426 /
7427 \end_layout
7428
7429 \end_inset
7430
7431 -stack-loc 32.
7432  Since the sp register is incremented before a push or call, the initial
7433  sp will be set to one byte prior the provided value.
7434  The provided value should not overlap any other memory areas such as used
7435  register banks or the data segment and with enough space for the current
7436  application.
7437  The 
7438 \series bold
7439 -
7440 \begin_inset ERT
7441 status collapsed
7442
7443 \begin_layout Standard
7444
7445
7446 \backslash
7447 /
7448 \end_layout
7449
7450 \end_inset
7451
7452 -pack-iram
7453 \series default
7454 \InsetSpace ~
7455
7456 \begin_inset LatexCommand \index{-\/-pack-iram}
7457
7458 \end_inset
7459
7460  option (which is now a default setting) will override this setting, so
7461  you should also specify the 
7462 \series bold
7463 -
7464 \begin_inset ERT
7465 status collapsed
7466
7467 \begin_layout Standard
7468
7469
7470 \backslash
7471 /
7472 \end_layout
7473
7474 \end_inset
7475
7476 -no-pack-iram
7477 \series default
7478 \InsetSpace ~
7479
7480 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7481
7482 \end_inset
7483
7484  option if you need to manually place the stack.
7485 \end_layout
7486
7487 \begin_layout List
7488 \labelwidthstring 00.00.0000
7489
7490 \series bold
7491 -
7492 \begin_inset ERT
7493 status collapsed
7494
7495 \begin_layout Standard
7496
7497
7498 \backslash
7499 /
7500 \end_layout
7501
7502 \end_inset
7503
7504 -xstack-loc
7505 \series default
7506
7507 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7508
7509 \end_inset
7510
7511 \InsetSpace ~
7512 <Value> By default the external stack
7513 \begin_inset LatexCommand \index{xstack}
7514
7515 \end_inset
7516
7517  is placed after the pdata
7518 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7519
7520 \end_inset
7521
7522  segment.
7523  Using this option the xstack can be placed anywhere in the external memory
7524  space of the 8051.
7525  The value entered can be in Hexadecimal or Decimal format, e.g.
7526  -
7527 \begin_inset ERT
7528 status collapsed
7529
7530 \begin_layout Standard
7531
7532
7533 \backslash
7534 /
7535 \end_layout
7536
7537 \end_inset
7538
7539 -xstack-loc 0x8000 or -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc 32768.
7553  The provided value should not overlap any other memory areas such as the
7554  pdata or xdata segment and with enough space for the current application.
7555 \end_layout
7556
7557 \begin_layout List
7558 \labelwidthstring 00.00.0000
7559
7560 \series bold
7561 -
7562 \begin_inset ERT
7563 status collapsed
7564
7565 \begin_layout Standard
7566
7567
7568 \backslash
7569 /
7570 \end_layout
7571
7572 \end_inset
7573
7574 -data-loc
7575 \series default
7576
7577 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7578
7579 \end_inset
7580
7581 \InsetSpace ~
7582 <Value> The start location of the internal ram data
7583 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7584
7585 \end_inset
7586
7587  segment.
7588  The value entered can be in Hexadecimal or Decimal format, eg.
7589  -
7590 \begin_inset ERT
7591 status collapsed
7592
7593 \begin_layout Standard
7594
7595
7596 \backslash
7597 /
7598 \end_layout
7599
7600 \end_inset
7601
7602 -data-loc 0x20 or -
7603 \begin_inset ERT
7604 status collapsed
7605
7606 \begin_layout Standard
7607
7608
7609 \backslash
7610 /
7611 \end_layout
7612
7613 \end_inset
7614
7615 -data-loc 32.
7616  (By default, the start location of the internal ram data segment  is set
7617  as low as possible in memory, taking into account the used register banks
7618  and the bit segment at address 0x20.
7619  For example if register banks 0 and 1 are used without bit variables, the
7620  data segment will be set, if -
7621 \begin_inset ERT
7622 status collapsed
7623
7624 \begin_layout Standard
7625
7626
7627 \backslash
7628 /
7629 \end_layout
7630
7631 \end_inset
7632
7633 -data-loc is not used, to location 0x10.)
7634 \end_layout
7635
7636 \begin_layout List
7637 \labelwidthstring 00.00.0000
7638
7639 \series bold
7640 -
7641 \begin_inset ERT
7642 status collapsed
7643
7644 \begin_layout Standard
7645
7646
7647 \backslash
7648 /
7649 \end_layout
7650
7651 \end_inset
7652
7653 -idata-loc
7654 \series default
7655
7656 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7657
7658 \end_inset
7659
7660 \InsetSpace ~
7661 <Value> The start location of the indirectly addressable internal ram
7662 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7663
7664 \end_inset
7665
7666  of the 8051, default value is 0x80.
7667  The value entered can be in Hexadecimal or Decimal format, eg.
7668  -
7669 \begin_inset ERT
7670 status collapsed
7671
7672 \begin_layout Standard
7673
7674
7675 \backslash
7676 /
7677 \end_layout
7678
7679 \end_inset
7680
7681 -idata-loc 0x88 or -
7682 \begin_inset ERT
7683 status collapsed
7684
7685 \begin_layout Standard
7686
7687
7688 \backslash
7689 /
7690 \end_layout
7691
7692 \end_inset
7693
7694 -idata-loc 136.
7695 \end_layout
7696
7697 \begin_layout List
7698 \labelwidthstring 00.00.0000
7699
7700 \series bold
7701 -
7702 \begin_inset ERT
7703 status collapsed
7704
7705 \begin_layout Standard
7706
7707
7708 \backslash
7709 /
7710 \end_layout
7711
7712 \end_inset
7713
7714 -bit-loc
7715 \series default
7716 \InsetSpace ~
7717 <Value> The start location of the bit
7718 \begin_inset LatexCommand \index{bit}
7719
7720 \end_inset
7721
7722  addressable internal ram of the 8051.
7723  This is 
7724 \emph on
7725 not
7726 \emph default
7727  implemented yet.
7728  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7729 -bBSEG=<Value>.
7730 \end_layout
7731
7732 \begin_layout List
7733 \labelwidthstring 00.00.0000
7734
7735 \series bold
7736 -
7737 \begin_inset ERT
7738 status collapsed
7739
7740 \begin_layout Standard
7741
7742
7743 \backslash
7744 /
7745 \end_layout
7746
7747 \end_inset
7748
7749 -out-fmt-ihx
7750 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7751
7752 \end_inset
7753
7754
7755 \bar under
7756  
7757 \series default
7758 \bar default
7759 The linker output (final object code) is in Intel Hex format.
7760 \begin_inset LatexCommand \index{Intel hex format}
7761
7762 \end_inset
7763
7764  This is the default option.
7765  The format itself is documented in the documentation of srecord
7766 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7767
7768 \end_inset
7769
7770 .
7771 \end_layout
7772
7773 \begin_layout List
7774 \labelwidthstring 00.00.0000
7775
7776 \series bold
7777 -
7778 \begin_inset ERT
7779 status collapsed
7780
7781 \begin_layout Standard
7782
7783
7784 \backslash
7785 /
7786 \end_layout
7787
7788 \end_inset
7789
7790 -out-fmt-s19
7791 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7792
7793 \end_inset
7794
7795
7796 \bar under
7797  
7798 \series default
7799 \bar default
7800 The linker output (final object code) is in Motorola S19 format
7801 \begin_inset LatexCommand \index{Motorola S19 format}
7802
7803 \end_inset
7804
7805 .
7806  The format itself is documented in the documentation of srecord.
7807 \end_layout
7808
7809 \begin_layout List
7810 \labelwidthstring 00.00.0000
7811
7812 \series bold
7813 -
7814 \begin_inset ERT
7815 status collapsed
7816
7817 \begin_layout Standard
7818
7819
7820 \backslash
7821 /
7822 \end_layout
7823
7824 \end_inset
7825
7826 -out-fmt-elf
7827 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7828
7829 \end_inset
7830
7831
7832 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7833
7834 \end_inset
7835
7836
7837 \bar under
7838  
7839 \series default
7840 \bar default
7841 The linker output (final object code) is in ELF format
7842 \begin_inset LatexCommand \index{ELF format}
7843
7844 \end_inset
7845
7846 .
7847  (Currently only supported for the HC08
7848 \begin_inset LatexCommand \index{HC08}
7849
7850 \end_inset
7851
7852  processors)
7853 \end_layout
7854
7855 \begin_layout List
7856 \labelwidthstring 00.00.0000
7857
7858 \series bold
7859 -Wl\InsetSpace ~
7860 linkOption[,linkOption]
7861 \series default
7862
7863 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7864
7865 \end_inset
7866
7867 ...
7868  Pass the linkOption to the linker.
7869  If a bootloader is used an option like 
7870 \begin_inset Quotes sld
7871 \end_inset
7872
7873 -Wl\InsetSpace ~
7874 -bCSEG=0x1000
7875 \begin_inset Quotes srd
7876 \end_inset
7877
7878  would be typical to set the start of the code segment.
7879  See also #pragma constseg and #pragma codeseg in section 
7880 \begin_inset LatexCommand \ref{sec:Pragmas}
7881
7882 \end_inset
7883
7884  .
7885  File sdcc/as/doc/asxhtm.html has more on linker options.
7886 \end_layout
7887
7888 \begin_layout Standard
7889 \begin_inset VSpace bigskip
7890 \end_inset
7891
7892
7893 \end_layout
7894
7895 \begin_layout Subsection
7896 MCS51 Options
7897 \begin_inset LatexCommand \index{Options MCS51}
7898
7899 \end_inset
7900
7901
7902 \begin_inset LatexCommand \index{MCS51 options}
7903
7904 \end_inset
7905
7906
7907 \end_layout
7908
7909 \begin_layout List
7910 \labelwidthstring 00.00.0000
7911
7912 \series bold
7913 -
7914 \begin_inset ERT
7915 status collapsed
7916
7917 \begin_layout Standard
7918
7919
7920 \backslash
7921 /
7922 \end_layout
7923
7924 \end_inset
7925
7926 -model-small
7927 \begin_inset LatexCommand \index{-\/-model-small}
7928
7929 \end_inset
7930
7931
7932 \series default
7933 \size large
7934 \emph on
7935  
7936 \size default
7937 \emph default
7938 Generate code for Small Model programs, see section Memory Models for more
7939  details.
7940  This is the default model.
7941 \end_layout
7942
7943 \begin_layout List
7944 \labelwidthstring 00.00.0000
7945
7946 \series bold
7947 -
7948 \begin_inset ERT
7949 status collapsed
7950
7951 \begin_layout Standard
7952
7953
7954 \backslash
7955 /
7956 \end_layout
7957
7958 \end_inset
7959
7960 -model-medium
7961 \begin_inset LatexCommand \index{-\/-model-medium}
7962
7963 \end_inset
7964
7965
7966 \series default
7967  Generate code for Medium model programs, see section Memory Models for
7968  more details.
7969  If this option is used all source files in the project have to be compiled
7970  with this option.
7971  It must also be used when invoking the linker.
7972 \end_layout
7973
7974 \begin_layout List
7975 \labelwidthstring 00.00.0000
7976
7977 \series bold
7978 -
7979 \begin_inset ERT
7980 status collapsed
7981
7982 \begin_layout Standard
7983
7984
7985 \backslash
7986 /
7987 \end_layout
7988
7989 \end_inset
7990
7991 -model-large
7992 \begin_inset LatexCommand \index{-\/-model-large}
7993
7994 \end_inset
7995
7996
7997 \series default
7998  Generate code for Large model programs, see section Memory Models for more
7999  details.
8000  If this option is used all source files in the project have to be compiled
8001  with this option.
8002  It must also be used when invoking the linker.
8003 \end_layout
8004
8005 \begin_layout List
8006 \labelwidthstring 00.00.0000
8007
8008 \series bold
8009 -
8010 \begin_inset ERT
8011 status collapsed
8012
8013 \begin_layout Standard
8014
8015
8016 \backslash
8017 /
8018 \end_layout
8019
8020 \end_inset
8021
8022 -xstack
8023 \begin_inset LatexCommand \index{-\/-xstack}
8024
8025 \end_inset
8026
8027
8028 \series default
8029  Uses a pseudo stack in the pdata
8030 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8031
8032 \end_inset
8033
8034  area (usually the first 256 bytes in the external ram) for allocating variables
8035  and passing parameters.
8036  See section 
8037 \begin_inset LatexCommand \ref{sub:External-Stack}
8038
8039 \end_inset
8040
8041 \InsetSpace ~
8042  External Stack for more details.
8043 \end_layout
8044
8045 \begin_layout List
8046 \labelwidthstring 00.00.0000
8047
8048 \series bold
8049 -
8050 \begin_inset ERT
8051 status collapsed
8052
8053 \begin_layout Standard
8054
8055
8056 \backslash
8057 /
8058 \end_layout
8059
8060 \end_inset
8061
8062 -iram-size
8063 \series default
8064 \InsetSpace ~
8065 <Value>
8066 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8067
8068 \end_inset
8069
8070  Causes the linker to check if the internal ram usage is within limits of
8071  the given value.
8072 \end_layout
8073
8074 \begin_layout List
8075 \labelwidthstring 00.00.0000
8076
8077 \series bold
8078 -
8079 \begin_inset ERT
8080 status collapsed
8081
8082 \begin_layout Standard
8083
8084
8085 \backslash
8086 /
8087 \end_layout
8088
8089 \end_inset
8090
8091 -xram-size
8092 \series default
8093 \InsetSpace ~
8094 <Value>
8095 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8096
8097 \end_inset
8098
8099  Causes the linker to check if the external ram usage is within limits of
8100  the given value.
8101 \end_layout
8102
8103 \begin_layout List
8104 \labelwidthstring 00.00.0000
8105
8106 \series bold
8107 -
8108 \begin_inset ERT
8109 status collapsed
8110
8111 \begin_layout Standard
8112
8113
8114 \backslash
8115 /
8116 \end_layout
8117
8118 \end_inset
8119
8120 -code-size
8121 \series default
8122 \InsetSpace ~
8123 <Value>
8124 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8125
8126 \end_inset
8127
8128  Causes the linker to check if the code memory usage is within limits of
8129  the given value.
8130 \end_layout
8131
8132 \begin_layout List
8133 \labelwidthstring 00.00.0000
8134
8135 \series bold
8136 -
8137 \begin_inset ERT
8138 status collapsed
8139
8140 \begin_layout Standard
8141
8142
8143 \backslash
8144 /
8145 \end_layout
8146
8147 \end_inset
8148
8149 -stack-size
8150 \series default
8151 \InsetSpace ~
8152 <Value>
8153 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8154
8155 \end_inset
8156
8157  Causes the linker to check if there is at minimum <Value> bytes for stack.
8158 \end_layout
8159
8160 \begin_layout List
8161 \labelwidthstring 00.00.0000
8162
8163 \series bold
8164 -
8165 \begin_inset ERT
8166 status collapsed
8167
8168 \begin_layout Standard
8169
8170
8171 \backslash
8172 /
8173 \end_layout
8174
8175 \end_inset
8176
8177 -pack-iram
8178 \series default
8179 \InsetSpace ~
8180
8181 \begin_inset LatexCommand \index{-\/-pack-iram}
8182
8183 \end_inset
8184
8185  Causes the linker to use unused register banks for data variables and pack
8186  data, idata and stack together.
8187  This is the default now.
8188 \end_layout
8189
8190 \begin_layout List
8191 \labelwidthstring 00.00.0000
8192
8193 \series bold
8194 -
8195 \begin_inset ERT
8196 status collapsed
8197
8198 \begin_layout Standard
8199
8200
8201 \backslash
8202 /
8203 \end_layout
8204
8205 \end_inset
8206
8207 -no-pack-iram
8208 \series default
8209 \InsetSpace ~
8210
8211 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8212
8213 \end_inset
8214
8215  Causes the linker to use old style for allocating memory areas.
8216 \end_layout
8217
8218 \begin_layout List
8219 \labelwidthstring 00.00.0000
8220
8221 \series bold
8222 -
8223 \begin_inset ERT
8224 status collapsed
8225
8226 \begin_layout Standard
8227
8228
8229 \backslash
8230 /
8231 \end_layout
8232
8233 \end_inset
8234
8235 -acall-ajmp
8236 \series default
8237 \InsetSpace ~
8238
8239 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8240
8241 \end_inset
8242
8243  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8244  acall/ajmp.
8245  Only use this option if your code is in the same 2k block of memory.
8246  You may need to use this option for some 8051 derivatives which lack the
8247  lcall/ljmp instructions..
8248 \end_layout
8249
8250 \begin_layout Standard
8251 \begin_inset VSpace bigskip
8252 \end_inset
8253
8254
8255 \end_layout
8256
8257 \begin_layout Subsection
8258 DS390 / DS400 Options
8259 \begin_inset LatexCommand \index{Options DS390}
8260
8261 \end_inset
8262
8263
8264 \begin_inset LatexCommand \index{DS390}
8265
8266 \end_inset
8267
8268
8269 \end_layout
8270
8271 \begin_layout List
8272 \labelwidthstring 00.00.0000
8273
8274 \series bold
8275 -
8276 \begin_inset ERT
8277 status collapsed
8278
8279 \begin_layout Standard
8280
8281
8282 \backslash
8283 /
8284 \end_layout
8285
8286 \end_inset
8287
8288 -model-flat24
8289 \series default
8290
8291 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8292
8293 \end_inset
8294
8295
8296 \size large
8297 \emph on
8298  
8299 \size default
8300 \emph default
8301 Generate 24-bit flat mode code.
8302  This is the one and only that the ds390 code generator supports right now
8303  and is default when using 
8304 \emph on
8305 -mds390
8306 \emph default
8307 .
8308  See section Memory Models for more details.
8309 \end_layout
8310
8311 \begin_layout List
8312 \labelwidthstring 00.00.0000
8313
8314 \series bold
8315 -
8316 \begin_inset ERT
8317 status collapsed
8318
8319 \begin_layout Standard
8320
8321
8322 \backslash
8323 /
8324 \end_layout
8325
8326 \end_inset
8327
8328 -protect-sp-update
8329 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8330
8331 \end_inset
8332
8333
8334 \series default
8335  disable interrupts during ESP:SP updates.
8336 \end_layout
8337
8338 \begin_layout List
8339 \labelwidthstring 00.00.0000
8340
8341 \series bold
8342 -
8343 \begin_inset ERT
8344 status collapsed
8345
8346 \begin_layout Standard
8347
8348
8349 \backslash
8350 /
8351 \end_layout
8352
8353 \end_inset
8354
8355 -stack-10bit
8356 \series default
8357
8358 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8359
8360 \end_inset
8361
8362  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8363  This is the one and only that the ds390 code generator supports right now
8364  and is default when using 
8365 \emph on
8366 -mds390
8367 \emph default
8368 .
8369  In this mode, the stack is located in the lower 1K of the internal RAM,
8370  which is mapped to 0x400000.
8371  Note that the support is incomplete, since it still uses a single byte
8372  as the stack pointer.
8373  This means that only the lower 256 bytes of the potential 1K stack space
8374  will actually be used.
8375  However, this does allow you to reclaim the precious 256 bytes of low RAM
8376  for use for the DATA and IDATA segments.
8377  The compiler will not generate any code to put the processor into 10 bit
8378  stack mode.
8379  It is important to ensure that the processor is in this mode before calling
8380  any re-entrant functions compiled with this option.
8381  In principle, this should work with the 
8382 \emph on
8383 -
8384 \begin_inset ERT
8385 status collapsed
8386
8387 \begin_layout Standard
8388
8389
8390 \backslash
8391 /
8392 \end_layout
8393
8394 \end_inset
8395
8396 -stack-auto
8397 \begin_inset LatexCommand \index{-\/-stack-auto}
8398
8399 \end_inset
8400
8401
8402 \emph default
8403  option, but that has not been tested.
8404  It is incompatible with the 
8405 \emph on
8406 -
8407 \begin_inset ERT
8408 status collapsed
8409
8410 \begin_layout Standard
8411
8412
8413 \backslash
8414 /
8415 \end_layout
8416
8417 \end_inset
8418
8419 -xstack
8420 \begin_inset LatexCommand \index{-\/-xstack}
8421
8422 \end_inset
8423
8424
8425 \emph default
8426  option.
8427  It also only makes sense if the processor is in 24 bit contiguous addressing
8428  mode (see the 
8429 \emph on
8430 -
8431 \begin_inset ERT
8432 status collapsed
8433
8434 \begin_layout Standard
8435
8436
8437 \backslash
8438 /
8439 \end_layout
8440
8441 \end_inset
8442
8443 -model-flat24 option
8444 \emph default
8445 ).
8446 \series bold
8447
8448 \begin_inset Note Note
8449 status collapsed
8450
8451 \begin_layout List
8452 \labelwidthstring 00.00.0000
8453
8454 \series bold
8455 -
8456 \begin_inset ERT
8457 status open
8458
8459 \begin_layout Standard
8460
8461
8462 \backslash
8463 /
8464 \end_layout
8465
8466 \end_inset
8467
8468 -stack-8-bit - switches off the 10-bit mode
8469 \end_layout
8470
8471 \end_inset
8472
8473
8474 \end_layout
8475
8476 \begin_layout List
8477 \labelwidthstring 00.00.0000
8478
8479 \series bold
8480 -
8481 \begin_inset ERT
8482 status collapsed
8483
8484 \begin_layout Standard
8485
8486
8487 \backslash
8488 /
8489 \end_layout
8490
8491 \end_inset
8492
8493 -stack-probe
8494 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8495
8496 \end_inset
8497
8498
8499 \series default
8500  insert call to function __stack_probe at each function prologue.
8501 \end_layout
8502
8503 \begin_layout List
8504 \labelwidthstring 00.00.0000
8505
8506 \series bold
8507 -
8508 \begin_inset ERT
8509 status open
8510
8511 \begin_layout Standard
8512
8513
8514 \backslash
8515 /
8516 \end_layout
8517
8518 \end_inset
8519
8520 -tini-libid
8521 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8522
8523 \end_inset
8524
8525
8526 \series default
8527  <nnnn> LibraryID used in -mTININative.
8528  
8529 \end_layout
8530
8531 \begin_layout List
8532 \labelwidthstring 00.00.0000
8533
8534 \series bold
8535 -
8536 \begin_inset ERT
8537 status collapsed
8538
8539 \begin_layout Standard
8540
8541
8542 \backslash
8543 /
8544 \end_layout
8545
8546 \end_inset
8547
8548 -use-accelerator
8549 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8550
8551 \end_inset
8552
8553
8554 \series default
8555  generate code for DS390 Arithmetic Accelerator.
8556  
8557 \end_layout
8558
8559 \begin_layout Standard
8560 \begin_inset VSpace bigskip
8561 \end_inset
8562
8563
8564 \end_layout
8565
8566 \begin_layout Subsection
8567 Z80 Options
8568 \begin_inset LatexCommand \index{Options Z80}
8569
8570 \end_inset
8571
8572
8573 \begin_inset LatexCommand \index{Z80}
8574
8575 \end_inset
8576
8577
8578 \end_layout
8579
8580 \begin_layout List
8581 \labelwidthstring 00.00.0000
8582
8583 \series bold
8584 -
8585 \begin_inset ERT
8586 status collapsed
8587
8588 \begin_layout Standard
8589
8590
8591 \backslash
8592 /
8593 \end_layout
8594
8595 \end_inset
8596
8597 -callee-saves-bc
8598 \series default
8599
8600 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8601
8602 \end_inset
8603
8604
8605 \size large
8606 \emph on
8607  
8608 \size default
8609 \emph default
8610 Force a called function to always save BC.
8611 \end_layout
8612
8613 \begin_layout List
8614 \labelwidthstring 00.00.0000
8615
8616 \series bold
8617 -
8618 \begin_inset ERT
8619 status collapsed
8620
8621 \begin_layout Standard
8622
8623
8624 \backslash
8625 /
8626 \end_layout
8627
8628 \end_inset
8629
8630 -no-std-crt0
8631 \series default
8632
8633 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8634
8635 \end_inset
8636
8637  When linking, skip the standard crt0.o object file.
8638  You must provide your own crt0.o for your system when linking.
8639 \end_layout
8640
8641 \begin_layout List
8642 \labelwidthstring 00.00.0000
8643
8644 \series bold
8645 -
8646 \begin_inset ERT
8647 status collapsed
8648
8649 \begin_layout Standard
8650
8651
8652 \backslash
8653 /
8654 \end_layout
8655
8656 \end_inset
8657
8658 -portmode=
8659 \series default
8660 <Value>
8661 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8662
8663 \end_inset
8664
8665  Determinate PORT I/O mode (<Value> is z80 or z180).
8666 \end_layout
8667
8668 \begin_layout List
8669 \labelwidthstring 00.00.0000
8670
8671 \series bold
8672 -
8673 \begin_inset ERT
8674 status collapsed
8675
8676 \begin_layout Standard
8677
8678
8679 \backslash
8680 /
8681 \end_layout
8682
8683 \end_inset
8684
8685 -asm=
8686 \series default
8687 <Value>
8688 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8689
8690 \end_inset
8691
8692  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8693 \end_layout
8694
8695 \begin_layout List
8696 \labelwidthstring 00.00.0000
8697
8698 \series bold
8699 -
8700 \begin_inset ERT
8701 status collapsed
8702
8703 \begin_layout Standard
8704
8705
8706 \backslash
8707 /
8708 \end_layout
8709
8710 \end_inset
8711
8712 -codeseg
8713 \series default
8714 \InsetSpace ~
8715 <Value>
8716 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8717
8718 \end_inset
8719
8720  Use <Value> for the code segment name.
8721 \end_layout
8722
8723 \begin_layout List
8724 \labelwidthstring 00.00.0000
8725
8726 \series bold
8727 -
8728 \begin_inset ERT
8729 status collapsed
8730
8731 \begin_layout Standard
8732
8733
8734 \backslash
8735 /
8736 \end_layout
8737
8738 \end_inset
8739
8740 -constseg
8741 \series default
8742 \InsetSpace ~
8743 <Value>
8744 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8745
8746 \end_inset
8747
8748  Use <Value> for the const segment name.
8749 \end_layout
8750
8751 \begin_layout List
8752 \labelwidthstring 00.00.0000
8753 \begin_inset VSpace bigskip
8754 \end_inset
8755
8756
8757 \end_layout
8758
8759 \begin_layout Subsection
8760 GBZ80 Options
8761 \begin_inset LatexCommand \index{Options GBZ80}
8762
8763 \end_inset
8764
8765
8766 \begin_inset LatexCommand \index{GBZ80}
8767
8768 \end_inset
8769
8770
8771 \end_layout
8772
8773 \begin_layout List
8774 \labelwidthstring 00.00.0000
8775
8776 \series bold
8777 -
8778 \begin_inset ERT
8779 status collapsed
8780
8781 \begin_layout Standard
8782
8783
8784 \backslash
8785 /
8786 \end_layout
8787
8788 \end_inset
8789
8790 -callee-saves-bc
8791 \series default
8792
8793 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8794
8795 \end_inset
8796
8797
8798 \size large
8799 \emph on
8800  
8801 \size default
8802 \emph default
8803 Force a called function to always save BC.
8804 \end_layout
8805
8806 \begin_layout List
8807 \labelwidthstring 00.00.0000
8808
8809 \series bold
8810 -bo
8811 \series default
8812 \InsetSpace ~
8813 <Num>
8814 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8815
8816 \end_inset
8817
8818  Use code bank <Num>.
8819 \end_layout
8820
8821 \begin_layout List
8822 \labelwidthstring 00.00.0000
8823
8824 \series bold
8825 -ba
8826 \series default
8827 \InsetSpace ~
8828 <Num>
8829 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8830
8831 \end_inset
8832
8833  Use data bank <Num>.
8834 \end_layout
8835
8836 \begin_layout List
8837 \labelwidthstring 00.00.0000
8838
8839 \series bold
8840 -
8841 \begin_inset ERT
8842 status collapsed
8843
8844 \begin_layout Standard
8845
8846
8847 \backslash
8848 /
8849 \end_layout
8850
8851 \end_inset
8852
8853 -codeseg
8854 \series default
8855 \InsetSpace ~
8856 <Value>
8857 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8858
8859 \end_inset
8860
8861  Use <Value> for the code segment name.
8862 \end_layout
8863
8864 \begin_layout List
8865 \labelwidthstring 00.00.0000
8866
8867 \series bold
8868 -
8869 \begin_inset ERT
8870 status collapsed
8871
8872 \begin_layout Standard
8873
8874
8875 \backslash
8876 /
8877 \end_layout
8878
8879 \end_inset
8880
8881 -constseg
8882 \series default
8883 \InsetSpace ~
8884 <Value>
8885 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8886
8887 \end_inset
8888
8889  Use <Value> for the const segment name.
8890 \end_layout
8891
8892 \begin_layout Standard
8893 \begin_inset VSpace bigskip
8894 \end_inset
8895
8896
8897 \end_layout
8898
8899 \begin_layout Subsection
8900 Optimization Options
8901 \begin_inset LatexCommand \index{Options optimization}
8902
8903 \end_inset
8904
8905
8906 \begin_inset LatexCommand \index{Optimization options}
8907
8908 \end_inset
8909
8910
8911 \end_layout
8912
8913 \begin_layout List
8914 \labelwidthstring 00.00.0000
8915
8916 \series bold
8917 -
8918 \begin_inset ERT
8919 status collapsed
8920
8921 \begin_layout Standard
8922
8923
8924 \backslash
8925 /
8926 \end_layout
8927
8928 \end_inset
8929
8930 -nogcse
8931 \begin_inset LatexCommand \index{-\/-nogcse}
8932
8933 \end_inset
8934
8935
8936 \series default
8937  Will not do global subexpression elimination, this option may be used when
8938  the compiler creates undesirably large stack/data spaces to store compiler
8939  temporaries (
8940 \emph on
8941 s
8942 \emph default
8943 pill 
8944 \emph on
8945 loc
8946 \emph default
8947 ations, sloc
8948 \begin_inset LatexCommand \index{sloc (spill location)}
8949
8950 \end_inset
8951
8952 ).
8953  A warning message will be generated when this happens and the compiler
8954  will indicate the number of extra bytes it allocated.
8955  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8956 nogcse
8957 \begin_inset LatexCommand \index{\#pragma nogcse}
8958
8959 \end_inset
8960
8961  can be used to turn off global subexpression elimination
8962 \begin_inset LatexCommand \index{Subexpression elimination}
8963
8964 \end_inset
8965
8966  for a given function only.
8967 \end_layout
8968
8969 \begin_layout List
8970 \labelwidthstring 00.00.0000
8971
8972 \series bold
8973 -
8974 \begin_inset ERT
8975 status collapsed
8976
8977 \begin_layout Standard
8978
8979
8980 \backslash
8981 /
8982 \end_layout
8983
8984 \end_inset
8985
8986 -noinvariant
8987 \begin_inset LatexCommand \index{-\/-noinvariant}
8988
8989 \end_inset
8990
8991
8992 \series default
8993  Will not do loop invariant optimizations, this may be turned off for reasons
8994  explained for the previous option.
8995  For more details of loop optimizations performed see Loop Invariants in
8996  section 
8997 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8998
8999 \end_inset
9000
9001 .
9002  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9003 noinvariant
9004 \begin_inset LatexCommand \index{\#pragma noinvariant}
9005
9006 \end_inset
9007
9008  can be used to turn off invariant optimizations for a given function only.
9009 \end_layout
9010
9011 \begin_layout List
9012 \labelwidthstring 00.00.0000
9013
9014 \series bold
9015 -
9016 \begin_inset ERT
9017 status collapsed
9018
9019 \begin_layout Standard
9020
9021
9022 \backslash
9023 /
9024 \end_layout
9025
9026 \end_inset
9027
9028 -noinduction
9029 \begin_inset LatexCommand \index{-\/-noinduction}
9030
9031 \end_inset
9032
9033
9034 \series default
9035  Will not do loop induction optimizations, see section strength reduction
9036  for more details.
9037  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9038 noinduction
9039 \begin_inset LatexCommand \index{\#pragma noinduction}
9040
9041 \end_inset
9042
9043  can be used to turn off induction optimizations for a given function only.
9044 \end_layout
9045
9046 \begin_layout List
9047 \labelwidthstring 00.00.0000
9048
9049 \series bold
9050 -
9051 \begin_inset ERT
9052 status collapsed
9053
9054 \begin_layout Standard
9055
9056
9057 \backslash
9058 /
9059 \end_layout
9060
9061 \end_inset
9062
9063 -nojtbound
9064 \begin_inset LatexCommand \index{-\/-nojtbound}
9065
9066 \end_inset
9067
9068
9069 \size large
9070 \bar under
9071  
9072 \series default
9073 \size default
9074 \bar default
9075  Will not generate boundary condition check when switch statements
9076 \begin_inset LatexCommand \index{switch statement}
9077
9078 \end_inset
9079
9080  are implemented using jump-tables.
9081  See section 
9082 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9083
9084 \end_inset
9085
9086 \InsetSpace ~
9087 Switch Statements for more details.
9088  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9089 nojtbound
9090 \begin_inset LatexCommand \index{\#pragma nojtbound}
9091
9092 \end_inset
9093
9094  can be used to turn off boundary checking for jump tables for a given function
9095  only.
9096 \end_layout
9097
9098 \begin_layout List
9099 \labelwidthstring 00.00.0000
9100
9101 \series bold
9102 -
9103 \begin_inset ERT
9104 status collapsed
9105
9106 \begin_layout Standard
9107
9108
9109 \backslash
9110 /
9111 \end_layout
9112
9113 \end_inset
9114
9115 -noloopreverse
9116 \begin_inset LatexCommand \index{-\/-noloopreverse}
9117
9118 \end_inset
9119
9120
9121 \series default
9122 \size large
9123  
9124 \size default
9125 Will not do loop reversal 
9126 \begin_inset LatexCommand \index{Loop reversing}
9127
9128 \end_inset
9129
9130 optimization.
9131 \end_layout
9132
9133 \begin_layout List
9134 \labelwidthstring 00.00.0000
9135 -
9136 \begin_inset ERT
9137 status collapsed
9138
9139 \begin_layout Standard
9140
9141
9142 \backslash
9143 /
9144 \end_layout
9145
9146 \end_inset
9147
9148 -
9149 \series bold
9150 nolabelopt
9151 \series default
9152  
9153 \begin_inset LatexCommand \index{-\/-nolabelopt }
9154
9155 \end_inset
9156
9157 Will not optimize labels (makes the dumpfiles more readable).
9158 \end_layout
9159
9160 \begin_layout List
9161 \labelwidthstring 00.00.0000
9162
9163 \series bold
9164 -
9165 \begin_inset ERT
9166 status collapsed
9167
9168 \begin_layout Standard
9169
9170
9171 \backslash
9172 /
9173 \end_layout
9174
9175 \end_inset
9176
9177 -no-xinit-opt
9178 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9179
9180 \end_inset
9181
9182
9183 \series default
9184  Will not memcpy initialized data from code space into xdata space.
9185  This saves a few bytes in code space if you don't have initialized data
9186 \begin_inset LatexCommand \index{Variable initialization}
9187
9188 \end_inset
9189
9190 .
9191 \end_layout
9192
9193 \begin_layout List
9194 \labelwidthstring 00.00.0000
9195
9196 \series bold
9197 -
9198 \begin_inset ERT
9199 status collapsed
9200
9201 \begin_layout Standard
9202
9203
9204 \backslash
9205 /
9206 \end_layout
9207
9208 \end_inset
9209
9210 -nooverlay
9211 \begin_inset LatexCommand \index{-\/-nooverlay}
9212
9213 \end_inset
9214
9215
9216 \series default
9217   The compiler will not overlay parameters and local variables of any function,
9218  see section Parameters and local variables for more details.
9219 \end_layout
9220
9221 \begin_layout List
9222 \labelwidthstring 00.00.0000
9223
9224 \series bold
9225 -
9226 \begin_inset ERT
9227 status collapsed
9228
9229 \begin_layout Standard
9230
9231
9232 \backslash
9233 /
9234 \end_layout
9235
9236 \end_inset
9237
9238 -no-peep
9239 \begin_inset LatexCommand \index{-\/-no-peep}
9240
9241 \end_inset
9242
9243
9244 \series default
9245  Disable peep-hole optimization with built-in rules.
9246 \end_layout
9247
9248 \begin_layout List
9249 \labelwidthstring 00.00.0000
9250
9251 \series bold
9252 -
9253 \begin_inset ERT
9254 status collapsed
9255
9256 \begin_layout Standard
9257
9258
9259 \backslash
9260 /
9261 \end_layout
9262
9263 \end_inset
9264
9265 -peep-file
9266 \series default
9267
9268 \begin_inset LatexCommand \index{-\/-peep-file}
9269
9270 \end_inset
9271
9272 \InsetSpace ~
9273 <filename> This option can be used to use additional rules to be used by
9274  the peep hole optimizer.
9275  See section 
9276 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9277
9278 \end_inset
9279
9280 \InsetSpace ~
9281 Peep Hole optimizations for details on how to write these rules.
9282 \end_layout
9283
9284 \begin_layout List
9285 \labelwidthstring 00.00.0000
9286
9287 \series bold
9288 -
9289 \begin_inset ERT
9290 status collapsed
9291
9292 \begin_layout Standard
9293
9294
9295 \backslash
9296 /
9297 \end_layout
9298
9299 \end_inset
9300
9301 -peep-asm
9302 \begin_inset LatexCommand \index{-\/-peep-asm}
9303
9304 \end_inset
9305
9306
9307 \series default
9308  Pass the inline assembler code through the peep hole optimizer.
9309  This can cause unexpected changes to inline assembler code, please go through
9310  the peephole optimizer
9311 \begin_inset LatexCommand \index{Peephole optimizer}
9312
9313 \end_inset
9314
9315  rules defined in the source file tree '<target>/peeph.def' before using
9316  this option.
9317 \end_layout
9318
9319 \begin_layout List
9320 \labelwidthstring 00.00.0000
9321
9322 \series bold
9323 -
9324 \begin_inset ERT
9325 status collapsed
9326
9327 \begin_layout Standard
9328
9329
9330 \backslash
9331 /
9332 \end_layout
9333
9334 \end_inset
9335
9336 -opt-code-speed
9337 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9338
9339 \end_inset
9340
9341
9342 \series default
9343  The compiler will optimize code generation towards fast code, possibly
9344  at the expense of code size.
9345 \end_layout
9346
9347 \begin_layout List
9348 \labelwidthstring 00.00.0000
9349
9350 \series bold
9351 -
9352 \begin_inset ERT
9353 status collapsed
9354
9355 \begin_layout Standard
9356
9357
9358 \backslash
9359 /
9360 \end_layout
9361
9362 \end_inset
9363
9364 -opt-code-size
9365 \begin_inset LatexCommand \index{-\/-opt-code-size}
9366
9367 \end_inset
9368
9369
9370 \series default
9371  The compiler will optimize code generation towards compact code, possibly
9372  at the expense of code speed.
9373 \end_layout
9374
9375 \begin_layout Standard
9376 \begin_inset VSpace bigskip
9377 \end_inset
9378
9379
9380 \end_layout
9381
9382 \begin_layout Subsection
9383 Other Options
9384 \begin_inset LatexCommand \index{Options other}
9385
9386 \end_inset
9387
9388
9389 \end_layout
9390
9391 \begin_layout List
9392 \labelwidthstring 00.00.0000
9393
9394 \series bold
9395 -c\InsetSpace ~
9396 -
9397 \begin_inset ERT
9398 status collapsed
9399
9400 \begin_layout Standard
9401
9402
9403 \backslash
9404 /
9405 \end_layout
9406
9407 \end_inset
9408
9409 -compile-only
9410 \begin_inset LatexCommand \index{-\/-compile-only}
9411
9412 \end_inset
9413
9414
9415 \begin_inset LatexCommand \index{-c -\/-compile-only}
9416
9417 \end_inset
9418
9419
9420 \series default
9421  will compile and assemble the source, but will not call the linkage editor.
9422 \end_layout
9423
9424 \begin_layout List
9425 \labelwidthstring 00.00.0000
9426
9427 \series bold
9428 -
9429 \series default
9430
9431 \begin_inset ERT
9432 status collapsed
9433
9434 \begin_layout Standard
9435
9436
9437 \backslash
9438 /
9439 \end_layout
9440
9441 \end_inset
9442
9443
9444 \series bold
9445 -c1mode
9446 \begin_inset LatexCommand \index{-\/-c1mode}
9447
9448 \end_inset
9449
9450
9451 \series default
9452  reads the preprocessed source from standard input and compiles it.
9453  The file name for the assembler output must be specified using the -o option.
9454 \end_layout
9455
9456 \begin_layout List
9457 \labelwidthstring 00.00.0000
9458
9459 \series bold
9460 -E
9461 \begin_inset LatexCommand \index{-E}
9462
9463 \end_inset
9464
9465
9466 \series default
9467  Run only the C preprocessor.
9468  Preprocess all the C source files specified and output the results to standard
9469  output.
9470 \end_layout
9471
9472 \begin_layout List
9473 \labelwidthstring 00.00.0000
9474
9475 \series bold
9476 -o\InsetSpace ~
9477 <path/file>
9478 \begin_inset LatexCommand \index{-o <path/file>}
9479
9480 \end_inset
9481
9482  
9483 \series default
9484 The output path where everything will be placed or the file name used for
9485  all generated output files.
9486  If the parameter is a path, it must have a trailing slash (or backslash
9487  for the Windows binaries) to be recognized as a path.
9488
9489 \emph on
9490  
9491 \emph default
9492 Note for Windows users: if the path contains spaces, it should be surrounded
9493  by quotes.
9494  The trailing backslash should be doubled in order to prevent escaping the
9495  final quote, for example: 
9496 \emph on
9497 -o 
9498 \begin_inset Quotes sld
9499 \end_inset
9500
9501 F:
9502 \backslash
9503 Projects
9504 \backslash
9505 test3
9506 \backslash
9507 output 1
9508 \backslash
9509
9510 \backslash
9511
9512 \begin_inset Quotes srd
9513 \end_inset
9514
9515
9516 \emph default
9517  or put after the final quote, for example: 
9518 \emph on
9519 -o 
9520 \begin_inset Quotes sld
9521 \end_inset
9522
9523 F:
9524 \backslash
9525 Projects
9526 \backslash
9527 test3
9528 \backslash
9529 output 1
9530 \begin_inset Quotes srd
9531 \end_inset
9532
9533
9534 \backslash
9535
9536 \emph default
9537 .
9538  The path using slashes for directory delimiters can be used too, for example:
9539  
9540 \emph on
9541 -o 
9542 \begin_inset Quotes sld
9543 \end_inset
9544
9545 F:/Projects/test3/output 1/
9546 \begin_inset Quotes srd
9547 \end_inset
9548
9549
9550 \emph default
9551 .
9552 \end_layout
9553
9554 \begin_layout List
9555 \labelwidthstring 00.00.0000
9556
9557 \series bold
9558 -
9559 \begin_inset ERT
9560 status collapsed
9561
9562 \begin_layout Standard
9563
9564
9565 \backslash
9566 /
9567 \end_layout
9568
9569 \end_inset
9570
9571 -stack-auto
9572 \begin_inset LatexCommand \index{-\/-stack-auto}
9573
9574 \end_inset
9575
9576
9577 \series default
9578 \size large
9579 \emph on
9580  
9581 \size default
9582 \emph default
9583 All functions in the source file will be compiled as 
9584 \emph on
9585 reentrant
9586 \emph default
9587
9588 \begin_inset LatexCommand \index{reentrant}
9589
9590 \end_inset
9591
9592 , i.e.
9593  the parameters and local variables will be allocated on the stack
9594 \begin_inset LatexCommand \index{stack}
9595
9596 \end_inset
9597
9598 .
9599  See section 
9600 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9601
9602 \end_inset
9603
9604  Parameters and Local Variables for more details.
9605  If this option is used all source files in the project should be compiled
9606  with this option.
9607  It automatically implies -
9608 \series bold
9609
9610 \begin_inset ERT
9611 status open
9612
9613 \begin_layout Standard
9614
9615
9616 \backslash
9617 /
9618 \end_layout
9619
9620 \end_inset
9621
9622
9623 \series default
9624 -int-long-reent and -
9625 \series bold
9626
9627 \begin_inset ERT
9628 status open
9629
9630 \begin_layout Standard
9631
9632
9633 \backslash
9634 /
9635 \end_layout
9636
9637 \end_inset
9638
9639
9640 \series default
9641 -float-reent.
9642  
9643 \end_layout
9644
9645 \begin_layout List
9646 \labelwidthstring 00.00.0000
9647
9648 \series bold
9649 -
9650 \begin_inset ERT
9651 status collapsed
9652
9653 \begin_layout Standard
9654
9655
9656 \backslash
9657 /
9658 \end_layout
9659
9660 \end_inset
9661
9662 -callee-saves
9663 \begin_inset LatexCommand \index{-\/-callee-saves}
9664
9665 \end_inset
9666
9667  
9668 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9669
9670 \end_inset
9671
9672 function1[,function2][,function3]....
9673
9674 \series default
9675  The compiler by default uses a caller saves convention for register saving
9676  across function calls, however this can cause unnecessary register pushing
9677  and popping when calling small functions from larger functions.
9678  This option can be used to switch the register saving convention for the
9679  function names specified.
9680  The compiler will not save registers when calling these functions, no extra
9681  code will be generated at the entry and exit (function prologue
9682 \series bold
9683
9684 \begin_inset LatexCommand \index{function prologue}
9685
9686 \end_inset
9687
9688
9689 \series default
9690  and epilogue
9691 \series bold
9692
9693 \begin_inset LatexCommand \index{function epilogue}
9694
9695 \end_inset
9696
9697
9698 \series default
9699 ) for these functions to save and restore the registers used by these functions,
9700  this can SUBSTANTIALLY reduce code and improve run time performance of
9701  the generated code.
9702  In the future the compiler (with inter procedural analysis) will be able
9703  to determine the appropriate scheme to use for each function call.
9704  DO NOT use this option for built-in functions such as _mulint..., if this
9705  option is used for a library function the appropriate library function
9706  needs to be recompiled with the same option.
9707  If the project consists of multiple source files then all the source file
9708  should be compiled with the same -
9709 \begin_inset ERT
9710 status collapsed
9711
9712 \begin_layout Standard
9713
9714
9715 \backslash
9716 /
9717 \end_layout
9718
9719 \end_inset
9720
9721 -callee-saves option string.
9722  Also see #pragma\InsetSpace ~
9723 callee_saves 
9724 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9725
9726 \end_inset
9727
9728  
9729 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9730
9731 \end_inset
9732
9733 .
9734 \end_layout
9735
9736 \begin_layout List
9737 \labelwidthstring 00.00.0000
9738
9739 \series bold
9740 -
9741 \begin_inset ERT
9742 status collapsed
9743
9744 \begin_layout Standard
9745
9746
9747 \backslash
9748 /
9749 \end_layout
9750
9751 \end_inset
9752
9753 -all-callee-saves
9754 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9755
9756 \end_inset
9757
9758  
9759 \series default
9760 Function of
9761 \series bold
9762  
9763 \series default
9764 -
9765 \begin_inset ERT
9766 status collapsed
9767
9768 \begin_layout Standard
9769
9770
9771 \backslash
9772 /
9773 \end_layout
9774
9775 \end_inset
9776
9777 -callee-saves will be applied to all functions by default.
9778 \end_layout
9779
9780 \begin_layout List
9781 \labelwidthstring 00.00.0000
9782
9783 \series bold
9784 -
9785 \begin_inset ERT
9786 status collapsed
9787
9788 \begin_layout Standard
9789
9790
9791 \backslash
9792 /
9793 \end_layout
9794
9795 \end_inset
9796
9797 -debug
9798 \begin_inset LatexCommand \index{-\/-debug}
9799
9800 \end_inset
9801
9802
9803 \bar under
9804  
9805 \series default
9806 \bar default
9807 When this option is used the compiler will generate debug information.
9808  The debug information collected in a file with .cdb extension can be used
9809  with the SDCDB.
9810  For more information see documentation for SDCDB.
9811  Another file with no extension contains debug information in AOMF or AOMF51
9812 \begin_inset LatexCommand \index{AOMF, AOMF51}
9813
9814 \end_inset
9815
9816  format which is commonly used by third party tools.
9817 \end_layout
9818
9819 \begin_layout List
9820 \labelwidthstring 00.00.0000
9821
9822 \series bold
9823 -S
9824 \begin_inset LatexCommand \index{-S}
9825
9826 \end_inset
9827
9828
9829 \size large
9830 \bar under
9831  
9832 \series default
9833 \size default
9834 \bar default
9835 Stop after the stage of compilation proper; do not assemble.
9836  The output is an assembler code file for the input file specified.
9837 \end_layout
9838
9839 \begin_layout List
9840 \labelwidthstring 00.00.0000
9841
9842 \series bold
9843 -
9844 \begin_inset ERT
9845 status collapsed
9846
9847 \begin_layout Standard
9848
9849
9850 \backslash
9851 /
9852 \end_layout
9853
9854 \end_inset
9855
9856 -int-long-reent
9857 \begin_inset LatexCommand \index{-\/-int-long-reent}
9858
9859 \end_inset
9860
9861
9862 \series default
9863  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9864  Note by default these libraries are compiled as non-reentrant.
9865  See section Installation for more details.
9866 \end_layout
9867
9868 \begin_layout List
9869 \labelwidthstring 00.00.0000
9870
9871 \series bold
9872 -
9873 \begin_inset ERT
9874 status collapsed
9875
9876 \begin_layout Standard
9877
9878
9879 \backslash
9880 /
9881 \end_layout
9882
9883 \end_inset
9884
9885 -cyclomatic
9886 \begin_inset LatexCommand \index{-\/-cyclomatic}
9887
9888 \end_inset
9889
9890
9891 \bar under
9892  
9893 \series default
9894 \bar default
9895 This option will cause the compiler to generate an information message for
9896  each function in the source file.
9897  The message contains some 
9898 \emph on
9899 important
9900 \emph default
9901  information about the function.
9902  The number of edges and nodes the compiler detected in the control flow
9903  graph of the function, and most importantly the 
9904 \emph on
9905 cyclomatic complexity
9906 \begin_inset LatexCommand \index{Cyclomatic complexity}
9907
9908 \end_inset
9909
9910
9911 \emph default
9912  see section on Cyclomatic Complexity for more details.
9913 \end_layout
9914
9915 \begin_layout List
9916 \labelwidthstring 00.00.0000
9917
9918 \series bold
9919 -
9920 \begin_inset ERT
9921 status collapsed
9922
9923 \begin_layout Standard
9924
9925
9926 \backslash
9927 /
9928 \end_layout
9929
9930 \end_inset
9931
9932 -float-reent
9933 \begin_inset LatexCommand \index{-\/-float-reent}
9934
9935 \end_inset
9936
9937
9938 \series default
9939  Floating point library is compiled as reentrant
9940 \begin_inset LatexCommand \index{reentrant}
9941
9942 \end_inset
9943
9944 .
9945  See section Installation for more details.
9946 \end_layout
9947
9948 \begin_layout List
9949 \labelwidthstring 00.00.0000
9950
9951 \series bold
9952 -
9953 \begin_inset ERT
9954 status collapsed
9955
9956 \begin_layout Standard
9957
9958
9959 \backslash
9960 /
9961 \end_layout
9962
9963 \end_inset
9964
9965 -funsigned-char
9966 \begin_inset LatexCommand \index{-\/-funsigned-char}
9967
9968 \end_inset
9969
9970
9971 \series default
9972  The default signedness for every type is
9973 \family typewriter
9974  signed
9975 \family default
9976 .
9977  In some embedded environments the default signedness of
9978 \family typewriter
9979  char
9980 \family default
9981  is
9982 \family typewriter
9983  unsigned
9984 \family default
9985 .
9986  To set the signess for characters to unsigned, use the option -
9987 \series bold
9988
9989 \begin_inset ERT
9990 status open
9991
9992 \begin_layout Standard
9993
9994
9995 \backslash
9996 /
9997 \end_layout
9998
9999 \end_inset
10000
10001
10002 \series default
10003 -funsigned-char.
10004  If this option is set and no signedness keyword (unsigned/signed) is given,
10005  a char will be signed.
10006  All other types are unaffected.
10007 \end_layout
10008
10009 \begin_layout List
10010 \labelwidthstring 00.00.0000
10011
10012 \series bold
10013 -
10014 \begin_inset ERT
10015 status collapsed
10016
10017 \begin_layout Standard
10018
10019
10020 \backslash
10021 /
10022 \end_layout
10023
10024 \end_inset
10025
10026 -main-return
10027 \begin_inset LatexCommand \index{-\/-main-return}
10028
10029 \end_inset
10030
10031
10032 \series default
10033  This option can be used if the code generated is called by a monitor program
10034  or if the main routine includes an endless loop.
10035  This option results in slightly smaller code and saves two bytes of stack
10036  space.
10037  The return from the 'main'
10038 \begin_inset LatexCommand \index{main return}
10039
10040 \end_inset
10041
10042  function will return to the function calling main.
10043  The default setting is to lock up i.e.
10044  generate a '
10045 \family typewriter
10046 sjmp .
10047 \family default
10048 '.
10049 \end_layout
10050
10051 \begin_layout List
10052 \labelwidthstring 00.00.0000
10053
10054 \series bold
10055 -
10056 \begin_inset ERT
10057 status collapsed
10058
10059 \begin_layout Standard
10060
10061
10062 \backslash
10063 /
10064 \end_layout
10065
10066 \end_inset
10067
10068 -nostdinc
10069 \begin_inset LatexCommand \index{-\/-nostdinc}
10070
10071 \end_inset
10072
10073
10074 \series default
10075  This will prevent the compiler from passing on the default include path
10076  to the preprocessor.
10077 \end_layout
10078
10079 \begin_layout List
10080 \labelwidthstring 00.00.0000
10081
10082 \series bold
10083 -
10084 \begin_inset ERT
10085 status collapsed
10086
10087 \begin_layout Standard
10088
10089
10090 \backslash
10091 /
10092 \end_layout
10093
10094 \end_inset
10095
10096 -nostdlib
10097 \begin_inset LatexCommand \index{-\/-nostdlib}
10098
10099 \end_inset
10100
10101
10102 \series default
10103  This will prevent the compiler from passing on the default library
10104 \begin_inset LatexCommand \index{Libraries}
10105
10106 \end_inset
10107
10108  path to the linker.
10109 \end_layout
10110
10111 \begin_layout List
10112 \labelwidthstring 00.00.0000
10113
10114 \series bold
10115 -
10116 \begin_inset ERT
10117 status collapsed
10118
10119 \begin_layout Standard
10120
10121
10122 \backslash
10123 /
10124 \end_layout
10125
10126 \end_inset
10127
10128 -verbose
10129 \begin_inset LatexCommand \index{-\/-verbose}
10130
10131 \end_inset
10132
10133
10134 \series default
10135  Shows the various actions the compiler is performing.
10136 \end_layout
10137
10138 \begin_layout List
10139 \labelwidthstring 00.00.0000
10140
10141 \series bold
10142 -V
10143 \begin_inset LatexCommand \index{-V}
10144
10145 \end_inset
10146
10147
10148 \series default
10149  Shows the actual commands the compiler is executing.
10150 \end_layout
10151
10152 \begin_layout List
10153 \labelwidthstring 00.00.0000
10154
10155 \series bold
10156 -
10157 \begin_inset ERT
10158 status collapsed
10159
10160 \begin_layout Standard
10161
10162
10163 \backslash
10164 /
10165 \end_layout
10166
10167 \end_inset
10168
10169 -no-c-code-in-asm
10170 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10171
10172 \end_inset
10173
10174
10175 \series default
10176  Hides your ugly and inefficient c-code from the asm file, so you can always
10177  blame the compiler :)
10178 \end_layout
10179
10180 \begin_layout List
10181 \labelwidthstring 00.00.0000
10182
10183 \series bold
10184 -
10185 \begin_inset ERT
10186 status collapsed
10187
10188 \begin_layout Standard
10189
10190
10191 \backslash
10192 /
10193 \end_layout
10194
10195 \end_inset
10196
10197 -fverbose-asm
10198 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10199
10200 \end_inset
10201
10202
10203 \series default
10204  Include code generator and peep-hole comments in the generated asm files.
10205 \end_layout
10206
10207 \begin_layout List
10208 \labelwidthstring 00.00.0000
10209
10210 \series bold
10211 -
10212 \begin_inset ERT
10213 status collapsed
10214
10215 \begin_layout Standard
10216
10217
10218 \backslash
10219 /
10220 \end_layout
10221
10222 \end_inset
10223
10224 -no-peep-comments
10225 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10226
10227 \end_inset
10228
10229
10230 \series default
10231  Don't include peep-hole comments in the generated asm files even if -
10232 \series bold
10233
10234 \begin_inset ERT
10235 status open
10236
10237 \begin_layout Standard
10238
10239
10240 \backslash
10241 /
10242 \end_layout
10243
10244 \end_inset
10245
10246
10247 \series default
10248 -fverbose-asm option is specified.
10249 \end_layout
10250
10251 \begin_layout List
10252 \labelwidthstring 00.00.0000
10253
10254 \series bold
10255 -
10256 \begin_inset ERT
10257 status collapsed
10258
10259 \begin_layout Standard
10260
10261
10262 \backslash
10263 /
10264 \end_layout
10265
10266 \end_inset
10267
10268 -i-code-in-asm
10269 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10270
10271 \end_inset
10272
10273
10274 \series default
10275  Include i-codes in the asm file.
10276  Sounds like noise but is most helpful for debugging the compiler itself.
10277 \end_layout
10278
10279 \begin_layout List
10280 \labelwidthstring 00.00.0000
10281
10282 \series bold
10283 -
10284 \begin_inset ERT
10285 status collapsed
10286
10287 \begin_layout Standard
10288
10289
10290 \backslash
10291 /
10292 \end_layout
10293
10294 \end_inset
10295
10296 -less-pedantic
10297 \begin_inset LatexCommand \index{pedantic}
10298
10299 \end_inset
10300
10301
10302 \begin_inset LatexCommand \index{-\/-less-pedantic}
10303
10304 \end_inset
10305
10306
10307 \series default
10308
10309 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10310
10311 \end_inset
10312
10313  Disable some of the more pedantic warnings
10314 \begin_inset LatexCommand \index{Warnings}
10315
10316 \end_inset
10317
10318 .
10319  For more details, see the less_pedantic pragma 
10320 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10321
10322 \end_inset
10323
10324 .
10325 \end_layout
10326
10327 \begin_layout List
10328 \labelwidthstring 00.00.0000
10329
10330 \series bold
10331 -
10332 \begin_inset ERT
10333 status collapsed
10334
10335 \begin_layout Standard
10336
10337
10338 \backslash
10339 /
10340 \end_layout
10341
10342 \end_inset
10343
10344 -disable-warning\InsetSpace ~
10345 <nnnn>
10346 \begin_inset LatexCommand \index{-\/-disable-warning}
10347
10348 \end_inset
10349
10350
10351 \series default
10352  Disable specific warning with number <nnnn>.
10353 \end_layout
10354
10355 \begin_layout List
10356 \labelwidthstring 00.00.0000
10357
10358 \series bold
10359 -
10360 \begin_inset ERT
10361 status collapsed
10362
10363 \begin_layout Standard
10364
10365
10366 \backslash
10367 /
10368 \end_layout
10369
10370 \end_inset
10371
10372 -print-search-dirs
10373 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10374
10375 \end_inset
10376
10377
10378 \series default
10379  Display the directories in the compiler's search path
10380 \end_layout
10381
10382 \begin_layout List
10383 \labelwidthstring 00.00.0000
10384
10385 \series bold
10386 -
10387 \begin_inset ERT
10388 status collapsed
10389
10390 \begin_layout Standard
10391
10392
10393 \backslash
10394 /
10395 \end_layout
10396
10397 \end_inset
10398
10399 -vc
10400 \begin_inset LatexCommand \index{-\/-vc}
10401
10402 \end_inset
10403
10404
10405 \series default
10406  Display errors and warnings using MSVC style, so you can use SDCC with
10407  the visual studio IDE
10408 \begin_inset LatexCommand \index{IDE}
10409
10410 \end_inset
10411
10412 .
10413  With SDCC both offering a GCC-like (the default) and a MSVC-like
10414 \begin_inset LatexCommand \index{MSVC output style}
10415
10416 \end_inset
10417
10418  output style, integration into most programming editors should be straightforwa
10419 rd.
10420 \end_layout
10421
10422 \begin_layout List
10423 \labelwidthstring 00.00.0000
10424
10425 \series bold
10426 -
10427 \begin_inset ERT
10428 status collapsed
10429
10430 \begin_layout Standard
10431
10432
10433 \backslash
10434 /
10435 \end_layout
10436
10437 \end_inset
10438
10439 -use-stdout
10440 \begin_inset LatexCommand \index{-\/-use-stdout}
10441
10442 \end_inset
10443
10444
10445 \series default
10446  Send errors and warnings to stdout instead of stderr.
10447 \end_layout
10448
10449 \begin_layout List
10450 \labelwidthstring 00.00.0000
10451
10452 \series bold
10453 -Wa\InsetSpace ~
10454 asmOption[,asmOption]
10455 \series default
10456
10457 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10458
10459 \end_inset
10460
10461 ...
10462  Pass the asmOption to the assembler
10463 \begin_inset LatexCommand \index{Options assembler}
10464
10465 \end_inset
10466
10467
10468 \begin_inset LatexCommand \index{Assembler options}
10469
10470 \end_inset
10471
10472 .
10473  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10474 \end_layout
10475
10476 \begin_layout List
10477 \labelwidthstring 00.00.0000
10478
10479 \series bold
10480 -
10481 \begin_inset ERT
10482 status collapsed
10483
10484 \begin_layout Standard
10485
10486
10487 \backslash
10488 /
10489 \end_layout
10490
10491 \end_inset
10492
10493 -std-sdcc89
10494 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10495
10496 \end_inset
10497
10498
10499 \series default
10500  Generally follow the C89 standard, but allow SDCC features that conflict
10501  with the standard (default).
10502 \end_layout
10503
10504 \begin_layout List
10505 \labelwidthstring 00.00.0000
10506
10507 \series bold
10508 -
10509 \begin_inset ERT
10510 status collapsed
10511
10512 \begin_layout Standard
10513
10514
10515 \backslash
10516 /
10517 \end_layout
10518
10519 \end_inset
10520
10521 -std-c89
10522 \begin_inset LatexCommand \index{-\/-std-c89}
10523
10524 \end_inset
10525
10526
10527 \series default
10528  Follow the C89 standard and disable SDCC features that conflict with the
10529  standard.
10530 \end_layout
10531
10532 \begin_layout List
10533 \labelwidthstring 00.00.0000
10534
10535 \series bold
10536 -
10537 \begin_inset ERT
10538 status collapsed
10539
10540 \begin_layout Standard
10541
10542
10543 \backslash
10544 /
10545 \end_layout
10546
10547 \end_inset
10548
10549 -std-sdcc99
10550 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10551
10552 \end_inset
10553
10554
10555 \series default
10556  Generally follow the C99 standard, but allow SDCC features that conflict
10557  with the standard (incomplete support).
10558 \end_layout
10559
10560 \begin_layout List
10561 \labelwidthstring 00.00.0000
10562
10563 \series bold
10564 -
10565 \begin_inset ERT
10566 status collapsed
10567
10568 \begin_layout Standard
10569
10570
10571 \backslash
10572 /
10573 \end_layout
10574
10575 \end_inset
10576
10577 -std-c99
10578 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10579
10580 \end_inset
10581
10582
10583 \series default
10584  Follow the C99 standard and disable SDCC features that conflict with the
10585  standard (incomplete support).
10586 \end_layout
10587
10588 \begin_layout List
10589 \labelwidthstring 00.00.0000
10590
10591 \series bold
10592 -
10593 \begin_inset ERT
10594 status collapsed
10595
10596 \begin_layout Standard
10597
10598
10599 \backslash
10600 /
10601 \end_layout
10602
10603 \end_inset
10604
10605 -codeseg
10606 \series default
10607
10608 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10609
10610 \end_inset
10611
10612 \InsetSpace ~
10613 <Name> The name to be used for the code
10614 \begin_inset LatexCommand \index{code}
10615
10616 \end_inset
10617
10618  segment, default CSEG.
10619  This is useful if you need to tell the compiler to put the code in a special
10620  segment so you can later on tell the linker to put this segment in a special
10621  place in memory.
10622  Can be used for instance when using bank switching to put the code in a
10623  bank.
10624 \end_layout
10625
10626 \begin_layout List
10627 \labelwidthstring 00.00.0000
10628
10629 \series bold
10630 -
10631 \begin_inset ERT
10632 status collapsed
10633
10634 \begin_layout Standard
10635
10636
10637 \backslash
10638 /
10639 \end_layout
10640
10641 \end_inset
10642
10643 -constseg
10644 \series default
10645
10646 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10647
10648 \end_inset
10649
10650 \InsetSpace ~
10651 <Name> The name to be used for the const
10652 \begin_inset LatexCommand \index{const}
10653
10654 \end_inset
10655
10656  segment, default CONST.
10657  This is useful if you need to tell the compiler to put the const data in
10658  a special segment so you can later on tell the linker to put this segment
10659  in a special place in memory.
10660  Can be used for instance when using bank switching to put the const data
10661  in a bank.
10662 \end_layout
10663
10664 \begin_layout List
10665 \labelwidthstring 00.00.0000
10666
10667 \series bold
10668 -
10669 \begin_inset ERT
10670 status collapsed
10671
10672 \begin_layout Standard
10673
10674
10675 \backslash
10676 /
10677 \end_layout
10678
10679 \end_inset
10680
10681 -fdollars-in-identifiers
10682 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10683
10684 \end_inset
10685
10686
10687 \series default
10688  Permit '$' as an identifier character.
10689 \end_layout
10690
10691 \begin_layout List
10692 \labelwidthstring 00.00.0000
10693
10694 \series bold
10695 -
10696 \begin_inset ERT
10697 status collapsed
10698
10699 \begin_layout Standard
10700
10701
10702 \backslash
10703 /
10704 \end_layout
10705
10706 \end_inset
10707
10708 -more-pedantic
10709 \series default
10710
10711 \begin_inset LatexCommand \index{-\/-more-pedantic}
10712
10713 \end_inset
10714
10715
10716 \begin_inset LatexCommand \index{pedantic}
10717
10718 \end_inset
10719
10720  Actually this is 
10721 \series bold
10722 \emph on
10723 not
10724 \series default
10725 \emph default
10726  a SDCC compiler option but if you want 
10727 \emph on
10728 more
10729 \emph default
10730  warnings you can use a separate tool dedicated to syntax checking like
10731  splint
10732 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10733
10734 \end_inset
10735
10736
10737 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10738
10739 \end_inset
10740
10741  
10742 \begin_inset LatexCommand \url{http://www.splint.org}
10743
10744 \end_inset
10745
10746 .
10747  To make your source files parseable by splint you will have to include
10748  
10749 \family sans
10750 lint.h
10751 \family default
10752
10753 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10754
10755 \end_inset
10756
10757  in your source file and add brackets around extended keywords (like 
10758 \family sans
10759
10760 \begin_inset Quotes sld
10761 \end_inset
10762
10763 __at\InsetSpace ~
10764
10765 \series bold
10766 (
10767 \series default
10768 0xab
10769 \series bold
10770 )
10771 \series default
10772
10773 \begin_inset Quotes srd
10774 \end_inset
10775
10776
10777 \family default
10778  and 
10779 \family sans
10780
10781 \begin_inset Quotes sld
10782 \end_inset
10783
10784 __interrupt\InsetSpace ~
10785 (2)
10786 \begin_inset Quotes srd
10787 \end_inset
10788
10789
10790 \family default
10791 ).
10792  
10793 \newline
10794 Splint has an excellent on line manual at 
10795 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10796
10797 \end_inset
10798
10799  and it's capabilities go beyond pure syntax checking.
10800  You'll need to tell splint the location of SDCC's include files so a typical
10801  command line could look like this: 
10802 \newline
10803
10804 \family sans
10805 splint\InsetSpace ~
10806 -I\InsetSpace ~
10807 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10808 \InsetSpace ~
10809 myprogram.c
10810 \end_layout
10811
10812 \begin_layout List
10813 \labelwidthstring 00.00.0000
10814
10815 \series bold
10816 -
10817 \begin_inset ERT
10818 status collapsed
10819
10820 \begin_layout Standard
10821
10822
10823 \backslash
10824 /
10825 \end_layout
10826
10827 \end_inset
10828
10829 -short-is-8bits
10830 \series default
10831
10832 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10833
10834 \end_inset
10835
10836
10837 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10838
10839 \end_inset
10840
10841  Treat short as 8-bit (for backward compatibility with older versions of
10842  compiler - see section 
10843 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10844
10845 \end_inset
10846
10847 )
10848 \end_layout
10849
10850 \begin_layout Standard
10851 \begin_inset VSpace bigskip
10852 \end_inset
10853
10854
10855 \end_layout
10856
10857 \begin_layout Subsection
10858 Intermediate Dump Options
10859 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10860
10861 \end_inset
10862
10863
10864 \begin_inset LatexCommand \index{Options intermediate dump}
10865
10866 \end_inset
10867
10868
10869 \begin_inset LatexCommand \index{Intermediate dump options}
10870
10871 \end_inset
10872
10873
10874 \end_layout
10875
10876 \begin_layout Standard
10877 The following options are provided for the purpose of retargetting and debugging
10878  the compiler.
10879  They provide a means to dump the intermediate code (iCode
10880 \begin_inset LatexCommand \index{iCode}
10881
10882 \end_inset
10883
10884 ) generated by the compiler in human readable form at various stages of
10885  the compilation process.
10886  More on iCodes see chapter 
10887 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10888
10889 \end_inset
10890
10891  
10892 \begin_inset Quotes srd
10893 \end_inset
10894
10895 The anatomy of the compiler
10896 \begin_inset Quotes srd
10897 \end_inset
10898
10899 .
10900 \end_layout
10901
10902 \begin_layout List
10903 \labelwidthstring 00.00.0000
10904
10905 \series bold
10906 -
10907 \begin_inset ERT
10908 status collapsed
10909
10910 \begin_layout Standard
10911
10912
10913 \backslash
10914 /
10915 \end_layout
10916
10917 \end_inset
10918
10919 -dumpraw
10920 \begin_inset LatexCommand \index{-\/-dumpraw}
10921
10922 \end_inset
10923
10924
10925 \series default
10926  This option will cause the compiler to dump the intermediate code into
10927  a file of named 
10928 \emph on
10929 <source filename>.dumpraw
10930 \emph default
10931  just after the intermediate code has been generated for a function, i.e.
10932  before any optimizations are done.
10933  The basic blocks
10934 \begin_inset LatexCommand \index{Basic blocks}
10935
10936 \end_inset
10937
10938  at this stage ordered in the depth first number, so they may not be in
10939  sequence of execution.
10940 \end_layout
10941
10942 \begin_layout List
10943 \labelwidthstring 00.00.0000
10944
10945 \series bold
10946 -
10947 \begin_inset ERT
10948 status collapsed
10949
10950 \begin_layout Standard
10951
10952
10953 \backslash
10954 /
10955 \end_layout
10956
10957 \end_inset
10958
10959 -dumpgcse
10960 \begin_inset LatexCommand \index{-\/-dumpgcse}
10961
10962 \end_inset
10963
10964
10965 \series default
10966  Will create a dump of iCodes, after global subexpression elimination
10967 \begin_inset LatexCommand \index{Global subexpression elimination}
10968
10969 \end_inset
10970
10971 , into a file named 
10972 \emph on
10973 <source filename>.dumpgcse.
10974 \end_layout
10975
10976 \begin_layout List
10977 \labelwidthstring 00.00.0000
10978
10979 \series bold
10980 -
10981 \begin_inset ERT
10982 status collapsed
10983
10984 \begin_layout Standard
10985
10986
10987 \backslash
10988 /
10989 \end_layout
10990
10991 \end_inset
10992
10993 -dumpdeadcode
10994 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10995
10996 \end_inset
10997
10998
10999 \series default
11000  Will create a dump of iCodes, after deadcode elimination
11001 \begin_inset LatexCommand \index{Dead-code elimination}
11002
11003 \end_inset
11004
11005 , into a file named 
11006 \emph on
11007 <source filename>.dumpdeadcode.
11008 \end_layout
11009
11010 \begin_layout List
11011 \labelwidthstring 00.00.0000
11012
11013 \series bold
11014 -
11015 \begin_inset ERT
11016 status collapsed
11017
11018 \begin_layout Standard
11019
11020
11021 \backslash
11022 /
11023 \end_layout
11024
11025 \end_inset
11026
11027 -dumploop
11028 \begin_inset LatexCommand \index{-\/-dumploop}
11029
11030 \end_inset
11031
11032
11033 \series default
11034 \size large
11035  
11036 \size default
11037 Will create a dump of iCodes, after loop optimizations
11038 \begin_inset LatexCommand \index{Loop optimization}
11039
11040 \end_inset
11041
11042 , into a file named 
11043 \emph on
11044 <source filename>.dumploop.
11045 \end_layout
11046
11047 \begin_layout List
11048 \labelwidthstring 00.00.0000
11049
11050 \series bold
11051 -
11052 \begin_inset ERT
11053 status collapsed
11054
11055 \begin_layout Standard
11056
11057
11058 \backslash
11059 /
11060 \end_layout
11061
11062 \end_inset
11063
11064 -dumprange
11065 \begin_inset LatexCommand \index{-\/-dumprange}
11066
11067 \end_inset
11068
11069
11070 \series default
11071 \size large
11072  
11073 \size default
11074 Will create a dump of iCodes, after live range analysis
11075 \begin_inset LatexCommand \index{Live range analysis}
11076
11077 \end_inset
11078
11079 , into a file named 
11080 \emph on
11081 <source filename>.dumprange.
11082 \end_layout
11083
11084 \begin_layout List
11085 \labelwidthstring 00.00.0000
11086
11087 \series bold
11088 -
11089 \begin_inset ERT
11090 status collapsed
11091
11092 \begin_layout Standard
11093
11094
11095 \backslash
11096 /
11097 \end_layout
11098
11099 \end_inset
11100
11101 -dumlrange
11102 \begin_inset LatexCommand \index{-\/-dumlrange}
11103
11104 \end_inset
11105
11106
11107 \series default
11108  Will dump the life ranges
11109 \begin_inset LatexCommand \index{Live range analysis}
11110
11111 \end_inset
11112
11113  for all symbols.
11114 \end_layout
11115
11116 \begin_layout List
11117 \labelwidthstring 00.00.0000
11118
11119 \series bold
11120 -
11121 \begin_inset ERT
11122 status collapsed
11123
11124 \begin_layout Standard
11125
11126
11127 \backslash
11128 /
11129 \end_layout
11130
11131 \end_inset
11132
11133 -dumpregassign
11134 \begin_inset LatexCommand \index{-\/-dumpregassign}
11135
11136 \end_inset
11137
11138
11139 \bar under
11140  
11141 \series default
11142 \bar default
11143 Will create a dump of iCodes, after register assignment
11144 \begin_inset LatexCommand \index{Register assignment}
11145
11146 \end_inset
11147
11148 , into a file named 
11149 \emph on
11150 <source filename>.dumprassgn.
11151 \end_layout
11152
11153 \begin_layout List
11154 \labelwidthstring 00.00.0000
11155
11156 \series bold
11157 -
11158 \begin_inset ERT
11159 status collapsed
11160
11161 \begin_layout Standard
11162
11163
11164 \backslash
11165 /
11166 \end_layout
11167
11168 \end_inset
11169
11170 -dumplrange
11171 \begin_inset LatexCommand \index{-\/-dumplrange}
11172
11173 \end_inset
11174
11175
11176 \series default
11177  Will create a dump of the live ranges of iTemp's
11178 \end_layout
11179
11180 \begin_layout List
11181 \labelwidthstring 00.00.0000
11182
11183 \series bold
11184 -
11185 \begin_inset ERT
11186 status collapsed
11187
11188 \begin_layout Standard
11189
11190
11191 \backslash
11192 /
11193 \end_layout
11194
11195 \end_inset
11196
11197 -dumpall
11198 \begin_inset LatexCommand \index{-\/-dumpall}
11199
11200 \end_inset
11201
11202
11203 \size large
11204 \bar under
11205  
11206 \series default
11207 \size default
11208 \bar default
11209 Will cause all the above mentioned dumps to be created.
11210 \end_layout
11211
11212 \begin_layout Standard
11213 \begin_inset VSpace bigskip
11214 \end_inset
11215
11216
11217 \end_layout
11218
11219 \begin_layout Subsection
11220 Redirecting output on Windows Shells
11221 \end_layout
11222
11223 \begin_layout Standard
11224 By default SDCC writes its error messages to 
11225 \begin_inset Quotes sld
11226 \end_inset
11227
11228 standard error
11229 \begin_inset Quotes srd
11230 \end_inset
11231
11232 .
11233  To force all messages to 
11234 \begin_inset Quotes sld
11235 \end_inset
11236
11237 standard output
11238 \begin_inset Quotes srd
11239 \end_inset
11240
11241  use 
11242 \series bold
11243 -
11244 \series default
11245 \emph on
11246
11247 \begin_inset ERT
11248 status collapsed
11249
11250 \begin_layout Standard
11251
11252
11253 \backslash
11254 /
11255 \end_layout
11256
11257 \end_inset
11258
11259
11260 \series bold
11261 \emph default
11262 -
11263 \series default
11264 use-stdout
11265 \begin_inset LatexCommand \index{-\/-use-stdout}
11266
11267 \end_inset
11268
11269 .
11270  Additionally, if you happen to have visual studio installed in your windows
11271  machine, you can use it to compile your sources using a custom build and
11272  the SDCC -
11273 \emph on
11274
11275 \begin_inset ERT
11276 status collapsed
11277
11278 \begin_layout Standard
11279
11280
11281 \backslash
11282 /
11283 \end_layout
11284
11285 \end_inset
11286
11287
11288 \emph default
11289 -vc
11290 \begin_inset LatexCommand \index{-\/-vc}
11291
11292 \end_inset
11293
11294  option.
11295  Something like this should work:
11296 \newline
11297
11298 \newline
11299
11300 \series bold
11301 c:
11302 \backslash
11303 sdcc
11304 \backslash
11305 bin
11306 \backslash
11307 sdcc.exe -
11308 \series default
11309 \emph on
11310
11311 \begin_inset ERT
11312 status collapsed
11313
11314 \begin_layout Standard
11315
11316
11317 \backslash
11318 /
11319 \end_layout
11320
11321 \end_inset
11322
11323
11324 \series bold
11325 \emph default
11326 -vc -
11327 \series default
11328 \emph on
11329
11330 \begin_inset ERT
11331 status collapsed
11332
11333 \begin_layout Standard
11334
11335
11336 \backslash
11337 /
11338 \end_layout
11339
11340 \end_inset
11341
11342
11343 \series bold
11344 \emph default
11345 -model-large -c $(InputPath)
11346 \series default
11347
11348 \begin_inset VSpace bigskip
11349 \end_inset
11350
11351
11352 \end_layout
11353
11354 \begin_layout Section
11355 Environment variables
11356 \begin_inset LatexCommand \index{Environment variables}
11357
11358 \end_inset
11359
11360
11361 \end_layout
11362
11363 \begin_layout Standard
11364 SDCC recognizes the following environment variables:
11365 \end_layout
11366
11367 \begin_layout List
11368 \labelwidthstring 00.00.0000
11369
11370 \series bold
11371 SDCC_LEAVE_SIGNALS
11372 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11373
11374 \end_inset
11375
11376
11377 \series default
11378  SDCC installs a signal handler
11379 \begin_inset LatexCommand \index{signal handler}
11380
11381 \end_inset
11382
11383  to be able to delete temporary files after an user break (^C) or an exception.
11384  If this environment variable is set, SDCC won't install the signal handler
11385  in order to be able to debug SDCC.
11386 \end_layout
11387
11388 \begin_layout List
11389 \labelwidthstring 00.00.0000
11390
11391 \series bold
11392 TMP,\InsetSpace ~
11393 TEMP,\InsetSpace ~
11394 TMPDIR
11395 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11396
11397 \end_inset
11398
11399
11400 \series default
11401  Path, where temporary files will be created.
11402  The order of the variables is the search order.
11403  In a standard *nix environment these variables are not set, and there's
11404  no need to set them.
11405  On Windows it's recommended to set one of them.
11406 \end_layout
11407
11408 \begin_layout List
11409 \labelwidthstring 00.00.0000
11410
11411 \series bold
11412 SDCC_HOME
11413 \begin_inset LatexCommand \index{SDCC\_HOME}
11414
11415 \end_inset
11416
11417
11418 \series default
11419  Path, see section 
11420 \begin_inset LatexCommand \ref{sub:Install-paths}
11421
11422 \end_inset
11423
11424 \InsetSpace ~
11425
11426 \begin_inset Quotes sld
11427 \end_inset
11428
11429  Install Paths
11430 \begin_inset Quotes srd
11431 \end_inset
11432
11433 .
11434 \end_layout
11435
11436 \begin_layout List
11437 \labelwidthstring 00.00.0000
11438
11439 \series bold
11440 SDCC_INCLUDE
11441 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11442
11443 \end_inset
11444
11445
11446 \series default
11447  Path, see section 
11448 \begin_inset LatexCommand \ref{sub:Search-Paths}
11449
11450 \end_inset
11451
11452 \InsetSpace ~
11453
11454 \begin_inset Quotes sld
11455 \end_inset
11456
11457 Search Paths
11458 \begin_inset Quotes srd
11459 \end_inset
11460
11461 .
11462 \end_layout
11463
11464 \begin_layout List
11465 \labelwidthstring 00.00.0000
11466
11467 \series bold
11468 SDCC_LIB
11469 \begin_inset LatexCommand \index{SDCC\_LIB}
11470
11471 \end_inset
11472
11473
11474 \series default
11475  Path, see section 
11476 \begin_inset LatexCommand \ref{sub:Search-Paths}
11477
11478 \end_inset
11479
11480 \InsetSpace ~
11481
11482 \begin_inset Quotes sld
11483 \end_inset
11484
11485 Search Paths
11486 \begin_inset Quotes srd
11487 \end_inset
11488
11489 ..
11490 \end_layout
11491
11492 \begin_layout Standard
11493 There are some more environment variables recognized by SDCC, but these
11494  are solely used for debugging purposes.
11495  They can change or disappear very quickly, and will never be documented.
11496 \begin_inset VSpace bigskip
11497 \end_inset
11498
11499
11500 \end_layout
11501
11502 \begin_layout Section
11503 Storage Class Language Extensions
11504 \end_layout
11505
11506 \begin_layout Subsection
11507 MCS51/DS390 Storage Class
11508 \begin_inset LatexCommand \index{Storage class}
11509
11510 \end_inset
11511
11512  Language Extensions
11513 \end_layout
11514
11515 \begin_layout Standard
11516 In addition to the ANSI storage classes SDCC allows the following MCS51
11517  specific storage classes:
11518 \end_layout
11519
11520 \begin_layout Subsubsection
11521 data
11522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11523
11524 \end_inset
11525
11526
11527 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11528
11529 \end_inset
11530
11531  / near
11532 \begin_inset LatexCommand \index{near (storage class)}
11533
11534 \end_inset
11535
11536
11537 \begin_inset LatexCommand \index{\_\_near (storage class)}
11538
11539 \end_inset
11540
11541
11542 \end_layout
11543
11544 \begin_layout Standard
11545 This is the 
11546 \series bold
11547 default
11548 \series default
11549  storage class for the Small Memory model (
11550 \emph on
11551 data
11552 \emph default
11553  and 
11554 \emph on
11555 near
11556 \emph default
11557  or the more ANSI-C compliant forms 
11558 \emph on
11559 __data
11560 \emph default
11561  and 
11562 \emph on
11563 __near
11564 \emph default
11565  can be used synonymously).
11566  Variables declared with this storage class will be allocated in the directly
11567  addressable portion of the internal RAM of a 8051, e.g.:
11568 \end_layout
11569
11570 \begin_layout Verse
11571
11572 \family typewriter
11573 __data unsigned char test_data;
11574 \end_layout
11575
11576 \begin_layout Standard
11577 Writing 0x01 to this variable generates the assembly code:
11578 \end_layout
11579
11580 \begin_layout Verse
11581
11582 \family typewriter
11583 75*00 01\InsetSpace ~
11584 \InsetSpace ~
11585 \InsetSpace ~
11586 mov\InsetSpace ~
11587 \InsetSpace ~
11588 _test_data,#0x01
11589 \end_layout
11590
11591 \begin_layout Subsubsection
11592 xdata
11593 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11594
11595 \end_inset
11596
11597
11598 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11599
11600 \end_inset
11601
11602  / far
11603 \begin_inset LatexCommand \index{far (storage class)}
11604
11605 \end_inset
11606
11607
11608 \begin_inset LatexCommand \index{\_\_far (storage class)}
11609
11610 \end_inset
11611
11612
11613 \end_layout
11614
11615 \begin_layout Standard
11616 Variables declared with this storage class will be placed in the external
11617  RAM.
11618  This is the 
11619 \series bold
11620 default
11621 \series default
11622  storage class for the Large Memory model, e.g.:
11623 \end_layout
11624
11625 \begin_layout Verse
11626
11627 \family typewriter
11628 __xdata unsigned char test_xdata;
11629 \end_layout
11630
11631 \begin_layout Standard
11632 Writing 0x01 to this variable generates the assembly code:
11633 \end_layout
11634
11635 \begin_layout Verse
11636
11637 \family typewriter
11638 90s00r00\InsetSpace ~
11639 \InsetSpace ~
11640 \InsetSpace ~
11641 mov\InsetSpace ~
11642 \InsetSpace ~
11643 dptr,#_test_xdata 
11644 \newline
11645 74\InsetSpace ~
11646 01\InsetSpace ~
11647 \InsetSpace ~
11648 \InsetSpace ~
11649 \InsetSpace ~
11650 \InsetSpace ~
11651 \InsetSpace ~
11652 mov\InsetSpace ~
11653 \InsetSpace ~
11654 a,#0x01 
11655 \newline
11656 F0\InsetSpace ~
11657 \InsetSpace ~
11658 \InsetSpace ~
11659 \InsetSpace ~
11660 \InsetSpace ~
11661 \InsetSpace ~
11662 \InsetSpace ~
11663 \InsetSpace ~
11664 \InsetSpace ~
11665 movx\InsetSpace ~
11666 @dptr,a 
11667 \end_layout
11668
11669 \begin_layout Subsubsection
11670 idata
11671 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11672
11673 \end_inset
11674
11675
11676 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11677
11678 \end_inset
11679
11680
11681 \end_layout
11682
11683 \begin_layout Standard
11684 Variables declared with this storage class will be allocated into the indirectly
11685  addressable portion of the internal ram of a 8051, e.g.:
11686 \end_layout
11687
11688 \begin_layout Verse
11689
11690 \family typewriter
11691 __idata unsigned char test_idata;
11692 \end_layout
11693
11694 \begin_layout Standard
11695 Writing 0x01 to this variable generates the assembly code:
11696 \end_layout
11697
11698 \begin_layout Verse
11699
11700 \family typewriter
11701 78r00\InsetSpace ~
11702 \InsetSpace ~
11703 \InsetSpace ~
11704 \InsetSpace ~
11705 \InsetSpace ~
11706 \InsetSpace ~
11707 \InsetSpace ~
11708 mov\InsetSpace ~
11709 \InsetSpace ~
11710 r0,#_test_idata
11711 \newline
11712 76\InsetSpace ~
11713 01\InsetSpace ~
11714 \InsetSpace ~
11715 \InsetSpace ~
11716 \InsetSpace ~
11717 \InsetSpace ~
11718 \InsetSpace ~
11719 \InsetSpace ~
11720 mov\InsetSpace ~
11721 \InsetSpace ~
11722 @r0,#0x01
11723 \end_layout
11724
11725 \begin_layout Standard
11726 Please note, the first 128 byte of idata physically access the same RAM
11727  as the data memory.
11728  The original 8051 had 128 byte idata memory, nowadays most devices have
11729  256 byte idata memory.
11730  The stack
11731 \begin_inset LatexCommand \index{stack}
11732
11733 \end_inset
11734
11735  is located in idata memory.
11736 \end_layout
11737
11738 \begin_layout Subsubsection
11739 pdata
11740 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11741
11742 \end_inset
11743
11744
11745 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11746
11747 \end_inset
11748
11749
11750 \end_layout
11751
11752 \begin_layout Standard
11753 Paged xdata access is just as straightforward as using the other addressing
11754  modes of a 8051.
11755  It is typically located at the start of xdata and has a maximum size of
11756  256 bytes.
11757  The following example writes 0x01 to the pdata variable.
11758  Please note, pdata access physically accesses xdata memory.
11759  The high byte of the address is determined by port P2 
11760 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11761
11762 \end_inset
11763
11764 (or in case of some 8051 variants by a separate Special Function Register,
11765  see section 
11766 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11767
11768 \end_inset
11769
11770 ).
11771  This is the 
11772 \series bold
11773 default
11774 \series default
11775  storage class for the Medium Memory model, e.g.:
11776 \end_layout
11777
11778 \begin_layout Verse
11779
11780 \family typewriter
11781 __pdata unsigned char test_pdata;
11782 \end_layout
11783
11784 \begin_layout Standard
11785 Writing 0x01 to this variable generates the assembly code:
11786 \end_layout
11787
11788 \begin_layout Verse
11789
11790 \family typewriter
11791 78r00\InsetSpace ~
11792 \InsetSpace ~
11793 \InsetSpace ~
11794 \InsetSpace ~
11795 \InsetSpace ~
11796 \InsetSpace ~
11797 mov r0,#_test_pdata
11798 \newline
11799 74 01\InsetSpace ~
11800 \InsetSpace ~
11801 \InsetSpace ~
11802 \InsetSpace ~
11803 \InsetSpace ~
11804 \InsetSpace ~
11805 mov a,#0x01 
11806 \newline
11807 F2\InsetSpace ~
11808 \InsetSpace ~
11809 \InsetSpace ~
11810 \InsetSpace ~
11811 \InsetSpace ~
11812 \InsetSpace ~
11813 \InsetSpace ~
11814 \InsetSpace ~
11815 \InsetSpace ~
11816 movx @r0,a
11817 \end_layout
11818
11819 \begin_layout Standard
11820 If the -
11821 \begin_inset ERT
11822 status collapsed
11823
11824 \begin_layout Standard
11825
11826
11827 \backslash
11828 /
11829 \end_layout
11830
11831 \end_inset
11832
11833 -xstack
11834 \begin_inset LatexCommand \index{-\/-xstack}
11835
11836 \end_inset
11837
11838  option is used the pdata memory area is followed by the xstack memory area
11839  and the sum of their sizes is limited to 256 bytes.
11840 \end_layout
11841
11842 \begin_layout Subsubsection
11843 code
11844 \begin_inset LatexCommand \index{code}
11845
11846 \end_inset
11847
11848
11849 \begin_inset LatexCommand \index{\_\_code}
11850
11851 \end_inset
11852
11853
11854 \end_layout
11855
11856 \begin_layout Standard
11857 'Variables' declared with this storage class will be placed in the code
11858  memory:
11859 \end_layout
11860
11861 \begin_layout Verse
11862
11863 \family typewriter
11864 __code unsigned char test_code;
11865 \end_layout
11866
11867 \begin_layout Standard
11868 Read access to this variable generates the assembly code:
11869 \end_layout
11870
11871 \begin_layout Verse
11872
11873 \family typewriter
11874 90s00r6F\InsetSpace ~
11875 \InsetSpace ~
11876 \InsetSpace ~
11877 mov dptr,#_test_code
11878 \newline
11879 E4\InsetSpace ~
11880 \InsetSpace ~
11881 \InsetSpace ~
11882 \InsetSpace ~
11883 \InsetSpace ~
11884 \InsetSpace ~
11885 \InsetSpace ~
11886 \InsetSpace ~
11887 \InsetSpace ~
11888 clr a
11889 \newline
11890 93\InsetSpace ~
11891 \InsetSpace ~
11892 \InsetSpace ~
11893 \InsetSpace ~
11894 \InsetSpace ~
11895 \InsetSpace ~
11896 \InsetSpace ~
11897 \InsetSpace ~
11898 \InsetSpace ~
11899 movc a,@a+dptr 
11900 \end_layout
11901
11902 \begin_layout Standard
11903
11904 \family typewriter
11905 char
11906 \family default
11907  indexed arrays of characters in code memory can be accessed efficiently:
11908 \end_layout
11909
11910 \begin_layout Verse
11911
11912 \family typewriter
11913 __code char test_array[] = {'c','h','e','a','p'}; 
11914 \end_layout
11915
11916 \begin_layout Standard
11917 Read access to this array using an 8-bit unsigned index generates the assembly
11918  code:
11919 \end_layout
11920
11921 \begin_layout Verse
11922
11923 \family typewriter
11924 E5*00\InsetSpace ~
11925 \InsetSpace ~
11926 \InsetSpace ~
11927 \InsetSpace ~
11928 \InsetSpace ~
11929 \InsetSpace ~
11930 mov a,_index 
11931 \end_layout
11932
11933 \begin_layout Verse
11934
11935 \family typewriter
11936 90s00r41\InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 mov dptr,#_test_array
11940 \end_layout
11941
11942 \begin_layout Verse
11943
11944 \family typewriter
11945 93\InsetSpace ~
11946 \InsetSpace ~
11947 \InsetSpace ~
11948 \InsetSpace ~
11949 \InsetSpace ~
11950 \InsetSpace ~
11951 \InsetSpace ~
11952 \InsetSpace ~
11953 \InsetSpace ~
11954 movc a,@a+dptr 
11955 \end_layout
11956
11957 \begin_layout Subsubsection
11958 bit
11959 \begin_inset LatexCommand \index{bit}
11960
11961 \end_inset
11962
11963
11964 \begin_inset LatexCommand \index{\_\_bit}
11965
11966 \end_inset
11967
11968
11969 \end_layout
11970
11971 \begin_layout Standard
11972 This is a data-type and a storage class specifier.
11973  When a variable is declared as a bit, it is allocated into the bit addressable
11974  memory of 8051, e.g.:
11975 \end_layout
11976
11977 \begin_layout Verse
11978
11979 \family typewriter
11980 __bit test_bit;
11981 \end_layout
11982
11983 \begin_layout Standard
11984 Writing 1 to this variable generates the assembly code:
11985 \end_layout
11986
11987 \begin_layout Verse
11988
11989 \family typewriter
11990 D2*00\InsetSpace ~
11991 \InsetSpace ~
11992 \InsetSpace ~
11993 \InsetSpace ~
11994 \InsetSpace ~
11995 \InsetSpace ~
11996 \InsetSpace ~
11997 setb\InsetSpace ~
11998 _test_bit
11999 \end_layout
12000
12001 \begin_layout Standard
12002 The bit addressable memory consists of 128 bits which are located from 0x20
12003  to 0x2f in data memory.
12004  
12005 \newline
12006 Apart from this 8051 specific storage class most architectures support
12007  ANSI-C bitfields
12008 \begin_inset LatexCommand \index{bitfields}
12009
12010 \end_inset
12011
12012
12013 \begin_inset Foot
12014 status open
12015
12016 \begin_layout Standard
12017 Not really meant as examples, but nevertheless showing what bitfields are
12018  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12019 \end_layout
12020
12021 \end_inset
12022
12023 .
12024  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12025  signed modifier are implemented as unsigned.
12026 \end_layout
12027
12028 \begin_layout Subsubsection
12029 sfr
12030 \begin_inset LatexCommand \index{sfr}
12031
12032 \end_inset
12033
12034
12035 \begin_inset LatexCommand \index{\_\_sfr}
12036
12037 \end_inset
12038
12039  / sfr16
12040 \begin_inset LatexCommand \index{sfr16}
12041
12042 \end_inset
12043
12044
12045 \begin_inset LatexCommand \index{\_\_sfr16}
12046
12047 \end_inset
12048
12049  / sfr32
12050 \begin_inset LatexCommand \index{sfr32}
12051
12052 \end_inset
12053
12054
12055 \begin_inset LatexCommand \index{\_\_sfr32}
12056
12057 \end_inset
12058
12059  / sbit
12060 \begin_inset LatexCommand \index{\_\_sbit}
12061
12062 \end_inset
12063
12064
12065 \begin_inset LatexCommand \index{sbit}
12066
12067 \end_inset
12068
12069
12070 \end_layout
12071
12072 \begin_layout Standard
12073 Like the bit keyword, 
12074 \emph on
12075 sfr / sfr16 / sfr32 / sbit 
12076 \emph default
12077 signify both a data-type and storage class, they are used to describe the
12078  
12079 \emph on
12080 s
12081 \emph default
12082 pecial 
12083 \emph on
12084 f
12085 \emph default
12086 unction 
12087 \emph on
12088 r
12089 \emph default
12090 egisters and 
12091 \emph on
12092 s
12093 \emph default
12094 pecial 
12095 \emph on
12096 bit
12097 \emph default
12098  variables of a 8051, eg:
12099 \end_layout
12100
12101 \begin_layout Verse
12102
12103 \family typewriter
12104 __sfr __at
12105 \begin_inset LatexCommand \index{at}
12106
12107 \end_inset
12108
12109
12110 \begin_inset LatexCommand \index{\_\_at}
12111
12112 \end_inset
12113
12114  (0x80) P0;\InsetSpace ~
12115  /* special function register P0 at location 0x80 */
12116 \newline
12117
12118 \newline
12119 /* 16 bit
12120  special function register combination for timer 0
12121 \newline
12122 \InsetSpace ~
12123 \InsetSpace ~
12124  with the high byte at
12125  location 0x8C and the low byte at location 0x8A */
12126 \newline
12127 __sfr16 __at (0x8C8A)
12128  TMR0;
12129 \newline
12130
12131 \newline
12132 __sbit __at
12133 \begin_inset LatexCommand \index{at}
12134
12135 \end_inset
12136
12137
12138 \begin_inset LatexCommand \index{\_\_at}
12139
12140 \end_inset
12141
12142  (0xd7) CY;\InsetSpace ~
12143  /* CY (Carry Flag
12144 \begin_inset LatexCommand \index{Flags}
12145
12146 \end_inset
12147
12148
12149 \begin_inset LatexCommand \index{Carry flag}
12150
12151 \end_inset
12152
12153 ) */
12154 \end_layout
12155
12156 \begin_layout Standard
12157 Special function registers which are located on an address dividable by
12158  8 are bit-addressable, an
12159 \emph on
12160  sbit
12161 \emph default
12162  addresses a specific bit within these sfr.
12163 \newline
12164 16 Bit and 32 bit special function
12165  register combinations which require a certain access order are better not
12166  declared using 
12167 \emph on
12168 sfr16
12169 \emph default
12170  or 
12171 \emph on
12172 sfr32.
12173
12174 \emph default
12175  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12176  this is not guaranteed.
12177 \newline
12178
12179 \end_layout
12180
12181 \begin_layout Standard
12182 Please note, if you use a header file which was written for another compiler
12183  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12184  likely be 
12185 \emph on
12186 not 
12187 \emph default
12188 compatible.
12189  Specifically the syntax 
12190 \family typewriter
12191 \InsetSpace ~
12192 sfr P0 = 0x80;\InsetSpace ~
12193
12194 \family default
12195  is compiled 
12196 \emph on
12197 without warning
12198 \emph default
12199  by SDCC to an assignment of 0x80 to a variable called P0 
12200 \family typewriter
12201
12202 \begin_inset Marginal
12203 status collapsed
12204
12205 \begin_layout Standard
12206
12207 \series bold
12208 \InsetSpace ~
12209 !
12210 \end_layout
12211
12212 \end_inset
12213
12214 .
12215  
12216 \family default
12217 Nevertheless it is possible to write header files
12218 \begin_inset LatexCommand \index{Header files}
12219
12220 \end_inset
12221
12222
12223 \begin_inset LatexCommand \index{Include files}
12224
12225 \end_inset
12226
12227  which can be shared among different compilers (see section 
12228 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12229
12230 \end_inset
12231
12232 ).
12233  
12234 \end_layout
12235
12236 \begin_layout Subsubsection
12237 Pointers
12238 \begin_inset LatexCommand \index{Pointer}
12239
12240 \end_inset
12241
12242  to MCS51/DS390 specific memory spaces
12243 \end_layout
12244
12245 \begin_layout Standard
12246 SDCC allows (via language extensions) pointers to explicitly point to any
12247  of the memory spaces
12248 \begin_inset LatexCommand \index{Memory model}
12249
12250 \end_inset
12251
12252  of the 8051.
12253  In addition to the explicit pointers, the compiler uses (by default) generic
12254  pointers which can be used to point to any of the memory spaces.
12255 \newline
12256
12257 \newline
12258 Pointer
12259  declaration examples:
12260 \end_layout
12261
12262 \begin_layout Verse
12263
12264 \family typewriter
12265 /* pointer physically in internal ram pointing to object in external ram
12266  */ 
12267 \newline
12268 __xdata unsigned char * __data p;
12269 \newline
12270
12271 \newline
12272 /* pointer physically in external ram
12273  pointing to object in internal ram */ 
12274 \newline
12275 __data unsigned char * __xdata p;
12276 \newline
12277
12278 \newline
12279 /*
12280  pointer physically in code rom pointing to data in xdata space */ 
12281 \newline
12282 __xdata
12283  unsigned char * __code p;
12284 \newline
12285
12286 \newline
12287 /* pointer physically in code space pointing to
12288  data in code space */ 
12289 \newline
12290 __code unsigned char * __code p;
12291 \newline
12292
12293 \newline
12294 /* generic pointer
12295  physically located in xdata space */
12296 \newline
12297 unsigned char * __xdata p;
12298 \newline
12299
12300 \newline
12301 /* generic
12302  pointer physically located in default memory space */
12303 \newline
12304 unsigned char * p;
12305 \newline
12306
12307 \newline
12308 /*
12309  the following is a function pointer
12310 \begin_inset LatexCommand \index{function pointer}
12311
12312 \end_inset
12313
12314  physically located in data space */
12315 \newline
12316 char (* __data fp)(void);
12317 \end_layout
12318
12319 \begin_layout Standard
12320 Well you get the idea.
12321  
12322 \newline
12323
12324 \newline
12325 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12326 \emph on
12327 generic
12328 \emph default
12329  pointers.
12330  
12331 \size small
12332
12333 \newline
12334
12335 \newline
12336
12337 \size default
12338 The highest order byte of the 
12339 \emph on
12340 generic
12341 \emph default
12342  pointers contains the data space information.
12343  Assembler support routines are called whenever data is stored or retrieved
12344  using 
12345 \emph on
12346 generic
12347 \emph default
12348  pointers.
12349  These are useful for developing reusable library
12350 \begin_inset LatexCommand \index{Libraries}
12351
12352 \end_inset
12353
12354  routines.
12355  Explicitly specifying the pointer
12356 \begin_inset LatexCommand \index{pointer}
12357
12358 \end_inset
12359
12360  type will generate the most efficient code.
12361 \end_layout
12362
12363 \begin_layout Subsubsection
12364 Notes on MCS51 memory
12365 \begin_inset LatexCommand \index{MCS51 memory}
12366
12367 \end_inset
12368
12369  layout
12370 \end_layout
12371
12372 \begin_layout Standard
12373 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12374  RAM memory which is structured as follows:
12375 \newline
12376
12377 \newline
12378 - Bytes 00-1F - 32 bytes to hold
12379  up to 4 banks of the registers R0 to R7, 
12380 \newline
12381 - Bytes 20-2F - 16 bytes to hold
12382  128 bit
12383 \begin_inset LatexCommand \index{bit}
12384
12385 \end_inset
12386
12387  variables and, 
12388 \newline
12389 - Bytes 30-7F - 80 bytes for general purpose use.
12390 \newline
12391
12392 \end_layout
12393
12394 \begin_layout Standard
12395 Additionally some members of the MCS51 family may have up to 128 bytes of
12396  additional, indirectly addressable, internal RAM memory (
12397 \emph on
12398 idata
12399 \emph default
12400
12401 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12402
12403 \end_inset
12404
12405
12406 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12407
12408 \end_inset
12409
12410 ).
12411  Furthermore, some chips may have some built in external memory (
12412 \emph on
12413 xdata
12414 \emph default
12415
12416 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12417
12418 \end_inset
12419
12420
12421 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12422
12423 \end_inset
12424
12425 ) which should not be confused with the internal, directly addressable RAM
12426  memory (
12427 \emph on
12428 data
12429 \emph default
12430
12431 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12432
12433 \end_inset
12434
12435
12436 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12437
12438 \end_inset
12439
12440 ).
12441  Sometimes this built in 
12442 \emph on
12443 xdata
12444 \emph default
12445  memory has to be activated before using it (you can probably find this
12446  information on the datasheet of the microcontroller your are using, see
12447  also section 
12448 \begin_inset LatexCommand \ref{sub:Startup-Code}
12449
12450 \end_inset
12451
12452 \InsetSpace ~
12453 Startup-Code).
12454 \end_layout
12455
12456 \begin_layout Standard
12457 Normally SDCC will only use the first bank
12458 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12459
12460 \end_inset
12461
12462  of registers (register bank 0), but it is possible to specify that other
12463  banks of registers (keyword 
12464 \emph on
12465 using
12466 \emph default
12467  
12468 \emph on
12469
12470 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12471
12472 \end_inset
12473
12474
12475 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12476
12477 \end_inset
12478
12479
12480 \emph default
12481 ) should be used for example in interrupt
12482 \begin_inset LatexCommand \index{interrupt}
12483
12484 \end_inset
12485
12486
12487 \begin_inset LatexCommand \index{\_\_interrupt}
12488
12489 \end_inset
12490
12491  routines.
12492  By default, the compiler will place the stack after the last byte of allocated
12493  memory for variables.
12494  For example, if the first 2 banks of registers are used, and only four
12495  bytes are used for 
12496 \emph on
12497 data
12498 \emph default
12499  variables, it will position the base of the internal stack at address 20
12500  (0x14).
12501  This implies that as the stack
12502 \begin_inset LatexCommand \index{stack}
12503
12504 \end_inset
12505
12506  grows, it will use up the remaining register banks, and the 16 bytes used
12507  by the 128 bit variables, and 80 bytes for general purpose use.
12508  If any bit variables are used, the data variables will be placed in unused
12509  register banks and after the byte holding the last bit variable.
12510  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12511  (two bytes used), 
12512 \emph on
12513 data
12514 \emph default
12515  variables will be placed starting from address 0x10 to 0x20 and continue
12516  at address 0x22.
12517  You can also use -
12518 \begin_inset ERT
12519 status collapsed
12520
12521 \begin_layout Standard
12522
12523
12524 \backslash
12525 /
12526 \end_layout
12527
12528 \end_inset
12529
12530 -data-loc
12531 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12532
12533 \end_inset
12534
12535  to specify the start address of the 
12536 \emph on
12537 data
12538 \emph default
12539  and -
12540 \begin_inset ERT
12541 status collapsed
12542
12543 \begin_layout Standard
12544
12545
12546 \backslash
12547 /
12548 \end_layout
12549
12550 \end_inset
12551
12552 -iram-size
12553 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12554
12555 \end_inset
12556
12557  to specify the size of the total internal RAM (
12558 \emph on
12559 data
12560 \emph default
12561 +
12562 \emph on
12563 idata
12564 \emph default
12565 ).
12566  
12567 \newline
12568
12569 \end_layout
12570
12571 \begin_layout Standard
12572 By default the 8051 linker will place the stack after the last byte of (i)data
12573  variables.
12574  Option -
12575 \begin_inset ERT
12576 status collapsed
12577
12578 \begin_layout Standard
12579
12580
12581 \backslash
12582 /
12583 \end_layout
12584
12585 \end_inset
12586
12587 -stack-loc
12588 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12589
12590 \end_inset
12591
12592  allows you to specify the start of the stack, i.e.
12593  you could start it after any data in the general purpose area.
12594  If your microcontroller has additional indirectly addressable internal
12595  RAM (
12596 \emph on
12597 idata
12598 \emph default
12599 ) you can place the stack on it.
12600  You may also need to use -
12601 \begin_inset ERT
12602 status collapsed
12603
12604 \begin_layout Standard
12605
12606
12607 \backslash
12608 /
12609 \end_layout
12610
12611 \end_inset
12612
12613 -xdata-loc
12614 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12615
12616 \end_inset
12617
12618  to set the start address of the external RAM (
12619 \emph on
12620 xdata
12621 \emph default
12622 ) and -
12623 \begin_inset ERT
12624 status collapsed
12625
12626 \begin_layout Standard
12627
12628
12629 \backslash
12630 /
12631 \end_layout
12632
12633 \end_inset
12634
12635 -xram-size
12636 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12637
12638 \end_inset
12639
12640  to specify its size.
12641  Same goes for the code memory, using -
12642 \begin_inset ERT
12643 status collapsed
12644
12645 \begin_layout Standard
12646
12647
12648 \backslash
12649 /
12650 \end_layout
12651
12652 \end_inset
12653
12654 -code-loc
12655 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12656
12657 \end_inset
12658
12659  and -
12660 \begin_inset ERT
12661 status collapsed
12662
12663 \begin_layout Standard
12664
12665
12666 \backslash
12667 /
12668 \end_layout
12669
12670 \end_inset
12671
12672 -code-size
12673 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12674
12675 \end_inset
12676
12677 .
12678  If in doubt, don't specify any options and see if the resulting memory
12679  layout is appropriate, then you can adjust it.
12680 \end_layout
12681
12682 \begin_layout Standard
12683 The linker generates two files with memory allocation information.
12684  The first, with extension .map
12685 \begin_inset LatexCommand \index{<file>.map}
12686
12687 \end_inset
12688
12689  shows all the variables and segments.
12690  The second with extension .mem
12691 \begin_inset LatexCommand \index{<file>.mem}
12692
12693 \end_inset
12694
12695  shows the final memory layout.
12696  The linker will complain either if memory segments overlap, there is not
12697  enough memory, or there is not enough space for stack.
12698  If you get any linking warnings and/or errors related to stack or segments
12699  allocation, take a look at either the .map or .mem files to find out what
12700  the problem is.
12701  The .mem file may even suggest a solution to the problem.
12702 \begin_inset VSpace bigskip
12703 \end_inset
12704
12705
12706 \end_layout
12707
12708 \begin_layout Subsection
12709 Z80/Z180 Storage Class
12710 \begin_inset LatexCommand \index{Z80!Storage class}
12711
12712 \end_inset
12713
12714  Language Extensions
12715 \end_layout
12716
12717 \begin_layout Subsubsection
12718 sfr
12719 \begin_inset LatexCommand \index{sfr}
12720
12721 \end_inset
12722
12723
12724 \begin_inset LatexCommand \index{\_\_sfr}
12725
12726 \end_inset
12727
12728  (in/out to 8-bit addresses)
12729 \end_layout
12730
12731 \begin_layout Standard
12732 The Z80
12733 \begin_inset LatexCommand \index{Z80}
12734
12735 \end_inset
12736
12737  family has separate address spaces for memory and 
12738 \emph on
12739 i
12740 \emph default
12741 nput/
12742 \emph on
12743 o
12744 \emph default
12745 utput memory.
12746  I/O memory
12747 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12748
12749 \end_inset
12750
12751
12752 \begin_inset LatexCommand \index{Z80!I/O memory}
12753
12754 \end_inset
12755
12756
12757 \begin_inset LatexCommand \index{Z180!I/O memory}
12758
12759 \end_inset
12760
12761  is accessed with special instructions, e.g.:
12762 \end_layout
12763
12764 \begin_layout Verse
12765
12766 \family typewriter
12767 sfr at 0x78 IoPort;\InsetSpace ~
12768 \InsetSpace ~
12769 /* define a var in I/O space at 78h called IoPort */
12770  
12771 \end_layout
12772
12773 \begin_layout Standard
12774 Writing 0x01 to this variable generates the assembly code:
12775 \end_layout
12776
12777 \begin_layout Verse
12778
12779 \family typewriter
12780 3E 01\InsetSpace ~
12781 \InsetSpace ~
12782 \InsetSpace ~
12783 \InsetSpace ~
12784 \InsetSpace ~
12785 \InsetSpace ~
12786 ld a,#0x01
12787 \newline
12788 D3 78\InsetSpace ~
12789 \InsetSpace ~
12790 \InsetSpace ~
12791 \InsetSpace ~
12792 \InsetSpace ~
12793 \InsetSpace ~
12794 out (_IoPort),a 
12795 \end_layout
12796
12797 \begin_layout Subsubsection
12798 banked sfr
12799 \begin_inset LatexCommand \index{sfr}
12800
12801 \end_inset
12802
12803
12804 \begin_inset LatexCommand \index{\_\_sfr}
12805
12806 \end_inset
12807
12808  (in/out to 16-bit addresses)
12809 \end_layout
12810
12811 \begin_layout Standard
12812 The keyword 
12813 \emph on
12814 banked
12815 \emph default
12816  is used to support 16 bit addresses in I/O memory e.g.:
12817 \end_layout
12818
12819 \begin_layout Verse
12820
12821 \family typewriter
12822 sfr banked at
12823 \begin_inset LatexCommand \index{at}
12824
12825 \end_inset
12826
12827
12828 \begin_inset LatexCommand \index{\_\_at}
12829
12830 \end_inset
12831
12832  0x123 IoPort; 
12833 \end_layout
12834
12835 \begin_layout Standard
12836 Writing 0x01 to this variable generates the assembly code:
12837 \end_layout
12838
12839 \begin_layout Verse
12840
12841 \family typewriter
12842 01 23 01\InsetSpace ~
12843 \InsetSpace ~
12844 \InsetSpace ~
12845 ld bc,#_IoPort
12846 \newline
12847 3E 01\InsetSpace ~
12848 \InsetSpace ~
12849 \InsetSpace ~
12850 \InsetSpace ~
12851 \InsetSpace ~
12852 \InsetSpace ~
12853 ld a,#0x01 
12854 \newline
12855 ED 79\InsetSpace ~
12856 \InsetSpace ~
12857 \InsetSpace ~
12858 \InsetSpace ~
12859 \InsetSpace ~
12860 \InsetSpace ~
12861 out (c),a 
12862 \end_layout
12863
12864 \begin_layout Subsubsection
12865 sfr
12866 \begin_inset LatexCommand \index{sfr}
12867
12868 \end_inset
12869
12870
12871 \begin_inset LatexCommand \index{\_\_sfr}
12872
12873 \end_inset
12874
12875  (in0/out0 to 8 bit addresses on Z180
12876 \begin_inset LatexCommand \index{Z180}
12877
12878 \end_inset
12879
12880 /HD64180
12881 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12882
12883 \end_inset
12884
12885 )
12886 \end_layout
12887
12888 \begin_layout Standard
12889 The compiler option -
12890 \begin_inset ERT
12891 status collapsed
12892
12893 \begin_layout Standard
12894
12895
12896 \backslash
12897 /
12898 \end_layout
12899
12900 \end_inset
12901
12902 -portmode
12903 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12904
12905 \end_inset
12906
12907 =180 (80) and a compiler #pragma\InsetSpace ~
12908 portmode
12909 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12910
12911 \end_inset
12912
12913  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12914 ns 
12915 \family typewriter
12916 in0/out0
12917 \family default
12918  instead of 
12919 \family typewriter
12920 in/out
12921 \family default
12922 .
12923  If you include the file z180.h this will be set automatically.
12924 \begin_inset VSpace bigskip
12925 \end_inset
12926
12927
12928 \end_layout
12929
12930 \begin_layout Subsection
12931 HC08 Storage Class
12932 \begin_inset LatexCommand \index{HC08!Storage class}
12933
12934 \end_inset
12935
12936  Language Extensions
12937 \end_layout
12938
12939 \begin_layout Subsubsection
12940 data
12941 \begin_inset LatexCommand \index{data (hc08 storage class)}
12942
12943 \end_inset
12944
12945
12946 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12947
12948 \end_inset
12949
12950  
12951 \end_layout
12952
12953 \begin_layout Standard
12954 The data storage class declares a variable that resides in the first 256
12955  bytes of memory (the direct page).
12956  The HC08
12957 \begin_inset LatexCommand \index{HC08}
12958
12959 \end_inset
12960
12961  is most efficient at accessing variables (especially pointers) stored here.
12962 \end_layout
12963
12964 \begin_layout Subsubsection
12965 xdata
12966 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12967
12968 \end_inset
12969
12970
12971 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12972
12973 \end_inset
12974
12975  
12976 \end_layout
12977
12978 \begin_layout Standard
12979 The xdata storage class declares a variable that can reside anywhere in
12980  memory.
12981  This is the default if no storage class is specified.
12982  
12983 \begin_inset VSpace bigskip
12984 \end_inset
12985
12986
12987 \end_layout
12988
12989 \begin_layout Section
12990 Absolute Addressing
12991 \begin_inset LatexCommand \index{Absolute addressing}
12992
12993 \end_inset
12994
12995
12996 \end_layout
12997
12998 \begin_layout Standard
12999 Data items can be assigned an absolute address with the 
13000 \emph on
13001 at
13002 \begin_inset LatexCommand \index{at}
13003
13004 \end_inset
13005
13006
13007 \begin_inset LatexCommand \index{\_\_at}
13008
13009 \end_inset
13010
13011  <address>
13012 \emph default
13013  keyword, in addition to a storage class, e.g.:
13014 \end_layout
13015
13016 \begin_layout Verse
13017
13018 \family typewriter
13019 xdata
13020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13021
13022 \end_inset
13023
13024
13025 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13026
13027 \end_inset
13028
13029  at
13030 \begin_inset LatexCommand \index{at}
13031
13032 \end_inset
13033
13034
13035 \begin_inset LatexCommand \index{\_\_at}
13036
13037 \end_inset
13038
13039  0x7ffe unsigned int chksum;
13040 \end_layout
13041
13042 \begin_layout Standard
13043 or, better conforming to ISO/IEC 9899 C:
13044 \end_layout
13045
13046 \begin_layout Verse
13047
13048 \family typewriter
13049 __xdata __at (0x7ffe) unsigned int chksum;
13050 \end_layout
13051
13052 \begin_layout Standard
13053 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13054  of the external ram.
13055  The compiler does 
13056 \emph on
13057 not
13058 \emph default
13059  reserve any space for variables declared in this way
13060 \begin_inset Marginal
13061 status collapsed
13062
13063 \begin_layout Standard
13064
13065 \series bold
13066 \InsetSpace ~
13067 !
13068 \end_layout
13069
13070 \end_inset
13071
13072  (they are implemented with an equate in the assembler).
13073  Thus it is left to the programmer to make sure there are no overlaps with
13074  other variables that are declared without the absolute address.
13075  The assembler listing file (.lst
13076 \begin_inset LatexCommand \index{<file>.lst}
13077
13078 \end_inset
13079
13080 ) and the linker output files (.rst
13081 \begin_inset LatexCommand \index{<file>.rst}
13082
13083 \end_inset
13084
13085 ) and (.map
13086 \begin_inset LatexCommand \index{<file>.map}
13087
13088 \end_inset
13089
13090 ) are good places to look for such overlaps.
13091 \end_layout
13092
13093 \begin_layout Standard
13094 If however you provide an initializer
13095 \begin_inset LatexCommand \index{Variable initialization}
13096
13097 \end_inset
13098
13099  actual memory allocation will take place and overlaps will be detected
13100  by the linker.
13101  E.g.:
13102 \end_layout
13103
13104 \begin_layout Verse
13105
13106 \family typewriter
13107 __code __at (0x7ff0) char Id[5] = 
13108 \begin_inset Quotes sld
13109 \end_inset
13110
13111 SDCC
13112 \begin_inset Quotes srd
13113 \end_inset
13114
13115 ;
13116 \end_layout
13117
13118 \begin_layout Standard
13119 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13120  in code memory.
13121 \end_layout
13122
13123 \begin_layout Standard
13124 In case of memory mapped I/O devices the keyword 
13125 \emph on
13126 volatile
13127 \emph default
13128  has to be used to tell the compiler that accesses might not be removed:
13129 \end_layout
13130
13131 \begin_layout Verse
13132
13133 \family typewriter
13134 volatile
13135 \begin_inset LatexCommand \index{volatile}
13136
13137 \end_inset
13138
13139  __xdata
13140 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13141
13142 \end_inset
13143
13144  __at
13145 \begin_inset LatexCommand \index{at}
13146
13147 \end_inset
13148
13149  (0x8000) unsigned char PORTA_8255;
13150 \end_layout
13151
13152 \begin_layout Standard
13153 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13154 r) array
13155 \family typewriter
13156 \size footnotesize
13157
13158 \begin_inset LatexCommand \index{Aligned array}
13159
13160 \end_inset
13161
13162
13163 \family default
13164 \size default
13165  starts at a block (256 byte) boundary
13166 \begin_inset LatexCommand \index{block boundary}
13167
13168 \end_inset
13169
13170  (section 
13171 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13172
13173 \end_inset
13174
13175  has an example).
13176 \newline
13177 Absolute addresses can be specified for variables in all
13178  storage classes, e.g.:
13179 \end_layout
13180
13181 \begin_layout Verse
13182
13183 \family typewriter
13184 __bit
13185 \begin_inset LatexCommand \index{bit}
13186
13187 \end_inset
13188
13189  __at
13190 \begin_inset LatexCommand \index{at}
13191
13192 \end_inset
13193
13194  (0x02) bvar;
13195 \end_layout
13196
13197 \begin_layout Standard
13198 The above example will allocate the variable at offset 0x02 in the bit-addressab
13199 le space.
13200  There is no real advantage to assigning absolute addresses to variables
13201  in this manner, unless you want strict control over all the variables allocated.
13202  One possible use would be to write hardware portable code.
13203  For example, if you have a routine that uses one or more of the microcontroller
13204  I/O pins, and such pins are different for two different hardwares, you
13205  can declare the I/O pins in your routine using:
13206 \end_layout
13207
13208 \begin_layout Verse
13209
13210 \family typewriter
13211 extern volatile
13212 \begin_inset LatexCommand \index{volatile}
13213
13214 \end_inset
13215
13216  __bit MOSI;\InsetSpace ~
13217 \InsetSpace ~
13218 \InsetSpace ~
13219 \InsetSpace ~
13220 /* master out, slave in */
13221 \newline
13222 extern volatile __bit MISO;\InsetSpace ~
13223 \InsetSpace ~
13224 \InsetSpace ~
13225 \InsetSpace ~
13226 /* master
13227  in, slave out */
13228 \newline
13229 extern volatile __bit MCLK;\InsetSpace ~
13230 \InsetSpace ~
13231 \InsetSpace ~
13232 \InsetSpace ~
13233 /* master clock */
13234 \newline
13235
13236 \newline
13237 /* Input and
13238  Output of a byte on a 3-wire serial bus.
13239 \newline
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 \InsetSpace ~
13243 If needed adapt polarity of clock,
13244  polarity of data and bit order
13245 \newline
13246 \InsetSpace ~
13247 */
13248 \newline
13249 unsigned char spi_io(unsigned char out_byte)
13250  
13251 \newline
13252
13253 \newline
13254 \InsetSpace ~
13255 \InsetSpace ~
13256 \InsetSpace ~
13257 \InsetSpace ~
13258 unsigned char i=8;
13259 \newline
13260 \InsetSpace ~
13261 \InsetSpace ~
13262 \InsetSpace ~
13263 \InsetSpace ~
13264 do { 
13265 \newline
13266 \InsetSpace ~
13267 \InsetSpace ~
13268 \InsetSpace ~
13269 \InsetSpace ~
13270 \InsetSpace ~
13271 \InsetSpace ~
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 MOSI = out_byte & 0x80; 
13275 \newline
13276 \InsetSpace ~
13277 \InsetSpace ~
13278 \InsetSpace ~
13279 \InsetSpace ~
13280 \InsetSpace ~
13281 \InsetSpace ~
13282 \InsetSpace ~
13283 \InsetSpace ~
13284 out_byte <<= 1;
13285 \newline
13286 \InsetSpace ~
13287 \InsetSpace ~
13288 \InsetSpace ~
13289 \InsetSpace ~
13290 \InsetSpace ~
13291 \InsetSpace ~
13292 \InsetSpace ~
13293 \InsetSpace ~
13294 MCLK =
13295  1; 
13296 \newline
13297 \InsetSpace ~
13298 \InsetSpace ~
13299 \InsetSpace ~
13300 \InsetSpace ~
13301 \InsetSpace ~
13302 \InsetSpace ~
13303 \InsetSpace ~
13304 \InsetSpace ~
13305 /* _asm nop _endasm; */\InsetSpace ~
13306 \InsetSpace ~
13307 \InsetSpace ~
13308 \InsetSpace ~
13309 \InsetSpace ~
13310 \InsetSpace ~
13311 \InsetSpace ~
13312 \InsetSpace ~
13313 /* for slow peripherals */
13314 \newline
13315 \InsetSpace ~
13316 \InsetSpace ~
13317 \InsetSpace ~
13318 \InsetSpace ~
13319 \InsetSpace ~
13320 \InsetSpace ~
13321 \InsetSpace ~
13322 \InsetSpace ~
13323 if(MISO) 
13324 \newline
13325 \InsetSpace ~
13326 \InsetSpace ~
13327 \InsetSpace ~
13328 \InsetSpace ~
13329 \InsetSpace ~
13330 \InsetSpace ~
13331 \InsetSpace ~
13332 \InsetSpace ~
13333 \InsetSpace ~
13334 \InsetSpace ~
13335 \InsetSpace ~
13336 \InsetSpace ~
13337 out_byte +=
13338  1; 
13339 \newline
13340 \InsetSpace ~
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 \InsetSpace ~
13346 \InsetSpace ~
13347 \InsetSpace ~
13348 MCLK = 0; 
13349 \newline
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 \InsetSpace ~
13353 \InsetSpace ~
13354 } while(--i);
13355 \newline
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 \InsetSpace ~
13359 \InsetSpace ~
13360 return out_byte; 
13361 \newline
13362 }
13363 \end_layout
13364
13365 \begin_layout Standard
13366 Then, someplace in the code for the first hardware you would use
13367 \end_layout
13368
13369 \begin_layout Verse
13370
13371 \family typewriter
13372 __bit __at
13373 \begin_inset LatexCommand \index{at}
13374
13375 \end_inset
13376
13377
13378 \begin_inset LatexCommand \index{\_\_at}
13379
13380 \end_inset
13381
13382  (0x80) MOSI;\InsetSpace ~
13383 \InsetSpace ~
13384 \InsetSpace ~
13385 \InsetSpace ~
13386 /* I/O port 0, bit 0 */
13387 \newline
13388 __bit __at (0x81) MISO;\InsetSpace ~
13389 \InsetSpace ~
13390 \InsetSpace ~
13391 \InsetSpace ~
13392 /* I/O port 0,
13393  bit 1 */
13394 \newline
13395 __bit __at (0x82) MCLK;\InsetSpace ~
13396 \InsetSpace ~
13397 \InsetSpace ~
13398 \InsetSpace ~
13399 /* I/O port 0, bit 2 */
13400 \end_layout
13401
13402 \begin_layout Standard
13403 Similarly, for the second hardware you would use
13404 \end_layout
13405
13406 \begin_layout Verse
13407
13408 \family typewriter
13409 __bit __at (0x83) MOSI;\InsetSpace ~
13410 \InsetSpace ~
13411 \InsetSpace ~
13412 \InsetSpace ~
13413 /* I/O port 0, bit 3 */
13414 \newline
13415 __bit __at (0x91) MISO;\InsetSpace ~
13416 \InsetSpace ~
13417 \InsetSpace ~
13418 \InsetSpace ~
13419 /*
13420  I/O port 1, bit 1 */
13421 \newline
13422 __bit
13423 \begin_inset LatexCommand \index{bit}
13424
13425 \end_inset
13426
13427  __at (0x92) MCLK;\InsetSpace ~
13428 \InsetSpace ~
13429 \InsetSpace ~
13430 \InsetSpace ~
13431 /* I/O port 1, bit 2 */
13432 \end_layout
13433
13434 \begin_layout Standard
13435 and you can use the same hardware dependent routine without changes, as
13436  for example in a library.
13437  This is somehow similar to sbit, but only one absolute address has to be
13438  specified in the whole project.
13439 \begin_inset VSpace bigskip
13440 \end_inset
13441
13442
13443 \end_layout
13444
13445 \begin_layout Section
13446 Parameters
13447 \begin_inset LatexCommand \index{Parameters}
13448
13449 \end_inset
13450
13451
13452 \begin_inset LatexCommand \index{function parameter}
13453
13454 \end_inset
13455
13456  & Local Variables
13457 \begin_inset LatexCommand \index{local variables}
13458
13459 \end_inset
13460
13461
13462 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13463
13464 \end_inset
13465
13466
13467 \end_layout
13468
13469 \begin_layout Standard
13470 Automatic (local) variables and parameters to functions can either be placed
13471  on the stack or in data-space.
13472  The default action of the compiler is to place these variables in the internal
13473  RAM (for small model) or external RAM (for medium or large model).
13474  This in fact makes them similar to 
13475 \emph on
13476 static
13477 \begin_inset LatexCommand \index{static}
13478
13479 \end_inset
13480
13481
13482 \emph default
13483  so by default functions are non-reentrant
13484 \begin_inset LatexCommand \index{reentrant}
13485
13486 \end_inset
13487
13488 .
13489  
13490 \newline
13491
13492 \newline
13493 They can be placed on the stack
13494 \begin_inset LatexCommand \index{stack}
13495
13496 \end_inset
13497
13498  by using the
13499 \emph on
13500  -
13501 \begin_inset ERT
13502 status collapsed
13503
13504 \begin_layout Standard
13505
13506
13507 \backslash
13508 /
13509 \end_layout
13510
13511 \end_inset
13512
13513 -stack-auto
13514 \begin_inset LatexCommand \index{-\/-stack-auto}
13515
13516 \end_inset
13517
13518
13519 \emph default
13520  option, by using 
13521 \emph on
13522 #pragma\InsetSpace ~
13523 stackauto
13524 \emph default
13525
13526 \begin_inset LatexCommand \index{\#pragma stackauto}
13527
13528 \end_inset
13529
13530  or by using the 
13531 \emph on
13532 reentrant
13533 \begin_inset LatexCommand \index{reentrant}
13534
13535 \end_inset
13536
13537
13538 \emph default
13539  keyword in the function declaration, e.g.:
13540 \end_layout
13541
13542 \begin_layout Verse
13543
13544 \family typewriter
13545 unsigned char foo(char i) __reentrant 
13546 \newline
13547
13548 \newline
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 \InsetSpace ~
13553 ...
13554  
13555 \newline
13556 }
13557 \end_layout
13558
13559 \begin_layout Standard
13560 Since stack space on 8051 is limited, the 
13561 \emph on
13562 reentrant 
13563 \emph default
13564 keyword or the
13565 \emph on
13566  -
13567 \begin_inset ERT
13568 status collapsed
13569
13570 \begin_layout Standard
13571
13572
13573 \backslash
13574 /
13575 \end_layout
13576
13577 \end_inset
13578
13579 -stack-auto
13580 \emph default
13581  option should be used sparingly.
13582  Note that the reentrant keyword just means that the parameters & local
13583  variables will be allocated to the stack, it 
13584 \emph on
13585 does not
13586 \emph default
13587  mean that the function is register bank
13588 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13589
13590 \end_inset
13591
13592  independent.
13593 \newline
13594
13595 \newline
13596 Local variables
13597 \begin_inset LatexCommand \index{local variables}
13598
13599 \end_inset
13600
13601  can be assigned storage classes and absolute
13602 \begin_inset LatexCommand \index{Absolute addressing}
13603
13604 \end_inset
13605
13606  addresses, e.g.: 
13607 \end_layout
13608
13609 \begin_layout Verse
13610
13611 \family typewriter
13612 unsigned char foo() 
13613 \newline
13614 {
13615 \newline
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 \InsetSpace ~
13619 \InsetSpace ~
13620 __xdata unsigned char i;
13621 \newline
13622 \InsetSpace ~
13623 \InsetSpace ~
13624 \InsetSpace ~
13625 \InsetSpace ~
13626 __bit bvar;
13627 \newline
13628 \InsetSpace ~
13629 \InsetSpace ~
13630 \InsetSpace ~
13631 \InsetSpace ~
13632 __data __at
13633 \begin_inset LatexCommand \index{at}
13634
13635 \end_inset
13636
13637  (0x31) unsigned char j;
13638 \newline
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 \InsetSpace ~
13643 ...
13644  
13645 \newline
13646 }
13647 \end_layout
13648
13649 \begin_layout Standard
13650 In the above example the variable 
13651 \emph on
13652 i
13653 \emph default
13654  will be allocated in the external ram, 
13655 \emph on
13656 bvar
13657 \emph default
13658  in bit addressable space and
13659 \emph on
13660  j
13661 \emph default
13662  in internal ram.
13663  When compiled with 
13664 \emph on
13665 -
13666 \begin_inset ERT
13667 status collapsed
13668
13669 \begin_layout Standard
13670
13671
13672 \backslash
13673 /
13674 \end_layout
13675
13676 \end_inset
13677
13678 -stack-auto
13679 \emph default
13680  or when a function is declared as 
13681 \emph on
13682 reentrant
13683 \emph default
13684  this should only be done for static variables.
13685 \end_layout
13686
13687 \begin_layout Standard
13688 Parameters
13689 \begin_inset LatexCommand \index{function parameter}
13690
13691 \end_inset
13692
13693  however are not allowed any storage class
13694 \begin_inset LatexCommand \index{Storage class}
13695
13696 \end_inset
13697
13698 , (storage classes for parameters will be ignored), their allocation is
13699  governed by the memory model in use, and the reentrancy options.
13700 \end_layout
13701
13702 \begin_layout Standard
13703 It is however allowed to use bit parameters in reentrant functions and also
13704  non-static local bit variables are supported.
13705  Efficient use is limited to 8 semi-bitregisters in bit space.
13706  They are pushed and popped to stack
13707 \begin_inset LatexCommand \index{stack}
13708
13709 \end_inset
13710
13711  as a single byte just like the normal registers.
13712 \end_layout
13713
13714 \begin_layout Section
13715 Overlaying
13716 \begin_inset LatexCommand \label{sub:Overlaying}
13717
13718 \end_inset
13719
13720
13721 \begin_inset LatexCommand \index{Overlaying}
13722
13723 \end_inset
13724
13725
13726 \end_layout
13727
13728 \begin_layout Standard
13729 For non-reentrant
13730 \begin_inset LatexCommand \index{reentrant}
13731
13732 \end_inset
13733
13734  functions SDCC will try to reduce internal ram space usage by overlaying
13735  parameters and local variables of a function (if possible).
13736  Parameters and local variables
13737 \begin_inset LatexCommand \index{local variables}
13738
13739 \end_inset
13740
13741  of a function will be allocated to an overlayable segment if the function
13742  has 
13743 \emph on
13744 no other function calls and the function is non-reentrant and the memory
13745  model
13746 \begin_inset LatexCommand \index{Memory model}
13747
13748 \end_inset
13749
13750  is small.
13751
13752 \emph default
13753  If an explicit storage class
13754 \begin_inset LatexCommand \index{Storage class}
13755
13756 \end_inset
13757
13758  is specified for a local variable, it will NOT be overlayed.
13759 \end_layout
13760
13761 \begin_layout Standard
13762 Note that the compiler (not the linkage editor) makes the decision for overlayin
13763 g the data items.
13764  Functions that are called from an interrupt service routine
13765 \begin_inset Marginal
13766 status collapsed
13767
13768 \begin_layout Standard
13769
13770 \series bold
13771 !
13772 \end_layout
13773
13774 \end_inset
13775
13776  should be preceded by a #pragma\InsetSpace ~
13777 nooverlay
13778 \begin_inset LatexCommand \index{\#pragma nooverlay}
13779
13780 \end_inset
13781
13782  if they are not reentrant.
13783 \end_layout
13784
13785 \begin_layout Standard
13786 Also note that the compiler does not do any processing of inline assembler
13787  code, so the compiler might incorrectly assign local variables and parameters
13788  of a function into the overlay segment if the inline assembler code calls
13789  other c-functions that might use the overlay.
13790  In that case the #pragma\InsetSpace ~
13791 nooverlay should be used.
13792 \end_layout
13793
13794 \begin_layout Standard
13795 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13796 tion
13797 \begin_inset LatexCommand \index{Multiplication}
13798
13799 \end_inset
13800
13801  or division
13802 \begin_inset LatexCommand \index{Division}
13803
13804 \end_inset
13805
13806  will NOT be overlayed since these are implemented using external functions,
13807  e.g.:
13808 \end_layout
13809
13810 \begin_layout Verse
13811
13812 \family typewriter
13813 #pragma save 
13814 \newline
13815 #pragma nooverlay
13816 \begin_inset LatexCommand \index{\#pragma nooverlay}
13817
13818 \end_inset
13819
13820  
13821 \newline
13822 void set_error(unsigned char errcd) 
13823 \newline
13824 {
13825 \newline
13826 \InsetSpace ~
13827 \InsetSpace ~
13828 \InsetSpace ~
13829 \InsetSpace ~
13830 P3 = errcd;
13831 \newline
13832
13833 \newline
13834 #pragma restore 
13835 \newline
13836
13837 \newline
13838 void
13839  some_isr () __interrupt
13840 \begin_inset LatexCommand \index{interrupt}
13841
13842 \end_inset
13843
13844  (2)
13845 \newline
13846 {
13847 \newline
13848 \InsetSpace ~
13849 \InsetSpace ~
13850 \InsetSpace ~
13851 \InsetSpace ~
13852 ...
13853 \newline
13854 \InsetSpace ~
13855 \InsetSpace ~
13856 \InsetSpace ~
13857 \InsetSpace ~
13858 set_error(10);
13859 \newline
13860 \InsetSpace ~
13861 \InsetSpace ~
13862 \InsetSpace ~
13863 \InsetSpace ~
13864 ...
13865  
13866 \newline
13867 }
13868 \end_layout
13869
13870 \begin_layout Standard
13871 In the above example the parameter 
13872 \emph on
13873 errcd
13874 \emph default
13875  for the function 
13876 \emph on
13877 set_error
13878 \emph default
13879  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13880 nooverlay was
13881  not present, this could cause unpredictable runtime behavior when called
13882  from an interrupt service routine.
13883  The #pragma\InsetSpace ~
13884 nooverlay ensures that the parameters and local variables for
13885  the function are NOT overlayed.
13886 \begin_inset VSpace bigskip
13887 \end_inset
13888
13889
13890 \end_layout
13891
13892 \begin_layout Section
13893 Interrupt Service Routines
13894 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13895
13896 \end_inset
13897
13898
13899 \end_layout
13900
13901 \begin_layout Subsection
13902 General Information
13903 \end_layout
13904
13905 \begin_layout Standard
13906 SDCC allows 
13907 \emph on
13908 i
13909 \emph default
13910 nterrupt 
13911 \emph on
13912 s
13913 \emph default
13914 ervice 
13915 \emph on
13916 r
13917 \emph default
13918 outines to be coded in C, with some extended keywords.
13919 \end_layout
13920
13921 \begin_layout Verse
13922
13923 \family typewriter
13924 void timer_isr (void) __interrupt (1) __using (1) 
13925 \newline
13926
13927 \newline
13928 \InsetSpace ~
13929 \InsetSpace ~
13930 \InsetSpace ~
13931 \InsetSpace ~
13932 ...
13933  
13934 \newline
13935 }
13936 \end_layout
13937
13938 \begin_layout Standard
13939 The optional number following the 
13940 \emph on
13941 interrupt
13942 \begin_inset LatexCommand \index{interrupt}
13943
13944 \end_inset
13945
13946
13947 \begin_inset LatexCommand \index{\_\_interrupt}
13948
13949 \end_inset
13950
13951
13952 \emph default
13953  keyword is the interrupt number this routine will service.
13954  When present, the compiler will insert a call to this routine in the interrupt
13955  vector table
13956 \begin_inset LatexCommand \index{interrupt vector table}
13957
13958 \end_inset
13959
13960  for the interrupt number specified.
13961  If you have multiple source files in your project, interrupt service routines
13962  can be present in any of them, but a prototype of the isr MUST be present
13963  or included in the file that contains the function 
13964 \emph on
13965 main
13966 \emph default
13967 .
13968  The optional (8051 specific) keyword 
13969 \emph on
13970 using
13971 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13972
13973 \end_inset
13974
13975
13976 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13977
13978 \end_inset
13979
13980
13981 \emph default
13982  can be used to tell the compiler to use the specified register bank when
13983  generating code for this function.
13984  
13985 \newline
13986 Interrupt service routines open the door for some very interesting bugs:
13987 \end_layout
13988
13989 \begin_layout Subsubsection
13990 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13991
13992 \end_inset
13993
13994 Common interrupt pitfall: variable not declared 
13995 \emph on
13996 volatile
13997 \end_layout
13998
13999 \begin_layout Standard
14000 If an interrupt service routine changes variables which are accessed by
14001  other functions these variables have to be declared 
14002 \emph on
14003 volatile
14004 \emph default
14005
14006 \begin_inset LatexCommand \index{volatile}
14007
14008 \end_inset
14009
14010 .
14011  See 
14012 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14013
14014 \end_inset
14015
14016  .
14017 \end_layout
14018
14019 \begin_layout Subsubsection
14020 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14021
14022 \end_inset
14023
14024 Common interrupt pitfall: 
14025 \emph on
14026 non-atomic access
14027 \end_layout
14028
14029 \begin_layout Standard
14030 If the access to these variables is not 
14031 \emph on
14032 atomic
14033 \begin_inset LatexCommand \index{atomic}
14034
14035 \end_inset
14036
14037
14038 \emph default
14039  (i.e.
14040  the processor needs more than one instruction for the access and could
14041  be interrupted while accessing the variable) the interrupt must be disabled
14042  during the access to avoid inconsistent data.
14043  
14044 \newline
14045 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14046  and should be protected by disabling interrupts.
14047  You're not automatically on the safe side if you use 8 bit variables though.
14048  We need an example here: f.e.
14049  on the 8051 the harmless looking 
14050 \begin_inset Quotes srd
14051 \end_inset
14052
14053
14054 \family typewriter
14055 flags\InsetSpace ~
14056 |=\InsetSpace ~
14057 0x80;
14058 \family default
14059
14060 \begin_inset Quotes sld
14061 \end_inset
14062
14063  is not atomic if 
14064 \family typewriter
14065 flags
14066 \family default
14067  resides in xdata.
14068  Setting 
14069 \begin_inset Quotes srd
14070 \end_inset
14071
14072
14073 \family typewriter
14074 flags\InsetSpace ~
14075 |=\InsetSpace ~
14076 0x40;
14077 \family default
14078
14079 \begin_inset Quotes sld
14080 \end_inset
14081
14082  from within an interrupt routine might get lost if the interrupt occurs
14083  at the wrong time.
14084  
14085 \begin_inset Quotes sld
14086 \end_inset
14087
14088
14089 \family typewriter
14090 counter\InsetSpace ~
14091 +=\InsetSpace ~
14092 8;
14093 \family default
14094
14095 \begin_inset Quotes srd
14096 \end_inset
14097
14098  is not atomic on the 8051 even if 
14099 \family typewriter
14100 counter
14101 \family default
14102  is located in data memory.
14103 \newline
14104 Bugs like these are hard to reproduce and can
14105  cause a lot of trouble.
14106  
14107 \end_layout
14108
14109 \begin_layout Subsubsection
14110 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14111
14112 \end_inset
14113
14114 Common interrupt pitfall: 
14115 \emph on
14116 stack overflow
14117 \end_layout
14118
14119 \begin_layout Standard
14120 The return address and the registers used in the interrupt service routine
14121  are saved on the stack
14122 \begin_inset LatexCommand \index{stack}
14123
14124 \end_inset
14125
14126  so there must be sufficient stack space.
14127  If there isn't variables or registers (or even the return address itself)
14128  will be corrupted.
14129  This 
14130 \emph on
14131 stack overflow
14132 \emph default
14133
14134 \begin_inset LatexCommand \index{stack overflow}
14135
14136 \end_inset
14137
14138  is most likely to happen if the interrupt occurs during the 
14139 \begin_inset Quotes sld
14140 \end_inset
14141
14142 deepest
14143 \begin_inset Quotes srd
14144 \end_inset
14145
14146  subroutine when the stack is already in use for f.e.
14147  many return addresses.
14148 \end_layout
14149
14150 \begin_layout Subsubsection
14151 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14152
14153 \end_inset
14154
14155 Common interrupt pitfall: 
14156 \emph on
14157 use of non-reentrant functions
14158 \end_layout
14159
14160 \begin_layout Standard
14161 A special note here, int (16 bit) and long (32 bit) integer division
14162 \begin_inset LatexCommand \index{Division}
14163
14164 \end_inset
14165
14166 , multiplication
14167 \begin_inset LatexCommand \index{Multiplication}
14168
14169 \end_inset
14170
14171  & modulus
14172 \begin_inset LatexCommand \index{Modulus}
14173
14174 \end_inset
14175
14176  and floating-point
14177 \begin_inset LatexCommand \index{Floating point support}
14178
14179 \end_inset
14180
14181  operations are implemented using external support routines.
14182  If an interrupt service routine needs to do any of these operations then
14183  the support routines (as mentioned in a following section) will have to
14184  be recompiled using the
14185 \emph on
14186  -
14187 \begin_inset ERT
14188 status collapsed
14189
14190 \begin_layout Standard
14191
14192
14193 \backslash
14194 /
14195 \end_layout
14196
14197 \end_inset
14198
14199 -stack-auto
14200 \begin_inset LatexCommand \index{-\/-stack-auto}
14201
14202 \end_inset
14203
14204
14205 \emph default
14206  option and the source file will need to be compiled using the 
14207 \emph on
14208 -
14209 \begin_inset ERT
14210 status collapsed
14211
14212 \begin_layout Standard
14213
14214
14215 \backslash
14216 /
14217 \end_layout
14218
14219 \end_inset
14220
14221 -int-long-reent
14222 \emph default
14223
14224 \begin_inset LatexCommand \index{-\/-int-long-reent}
14225
14226 \end_inset
14227
14228  compiler option.
14229  
14230 \newline
14231 Note, the type promotion
14232 \begin_inset LatexCommand \index{type promotion}
14233
14234 \end_inset
14235
14236  required by ANSI C can cause 16 bit routines to be used
14237 \begin_inset Marginal
14238 status collapsed
14239
14240 \begin_layout Standard
14241
14242 \series bold
14243 \InsetSpace ~
14244 !
14245 \end_layout
14246
14247 \end_inset
14248
14249  without the programmer being aware of it.
14250  See f.e.
14251  the cast 
14252 \family typewriter
14253 (unsigned char)(tail-1)
14254 \family default
14255  within the if clause in section 
14256 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14257
14258 \end_inset
14259
14260 .
14261 \end_layout
14262
14263 \begin_layout Standard
14264 Calling other functions from an interrupt service routine is not recommended,
14265  avoid it if possible.
14266  Note that when some function is called from an interrupt service routine
14267  it should be preceded by a #pragma\InsetSpace ~
14268 nooverlay
14269 \begin_inset LatexCommand \index{\#pragma nooverlay}
14270
14271 \end_inset
14272
14273  if it is not reentrant.
14274  Furthermore nonreentrant functions should not be called from the main program
14275  while the interrupt service routine might be active.
14276  They also must not be called from low priority interrupt service routines
14277  while a high priority interrupt service routine might be active.
14278  You could use semaphores or make the function
14279 \emph on
14280  critical
14281 \emph default
14282  if all parameters are passed in registers.
14283 \newline
14284  Also see section 
14285 \begin_inset LatexCommand \ref{sub:Overlaying}
14286
14287 \end_inset
14288
14289 \InsetSpace ~
14290 about Overlaying and section 
14291 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14292
14293 \end_inset
14294
14295 \InsetSpace ~
14296 about Functions using private register banks.
14297 \begin_inset VSpace bigskip
14298 \end_inset
14299
14300
14301 \end_layout
14302
14303 \begin_layout Subsection
14304 MCS51/DS390 Interrupt Service Routines
14305 \end_layout
14306
14307 \begin_layout Standard
14308 Interrupt
14309 \begin_inset LatexCommand \index{interrupt}
14310
14311 \end_inset
14312
14313  numbers and the corresponding address & descriptions for the Standard 8051/8052
14314  are listed below.
14315  SDCC will automatically adjust the 
14316 \begin_inset LatexCommand \index{interrupt vector table}
14317
14318 \end_inset
14319
14320  to the maximum interrupt number specified.
14321 \newline
14322
14323 \end_layout
14324
14325 \begin_layout Standard
14326 \align center
14327 \begin_inset Tabular
14328 <lyxtabular version="3" rows="9" columns="3">
14329 <features>
14330 <column alignment="center" valignment="top" leftline="true" width="0in">
14331 <column alignment="left" valignment="top" leftline="true" width="0in">
14332 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14333 <row topline="true" bottomline="true">
14334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14335 \begin_inset Text
14336
14337 \begin_layout Standard
14338 Interrupt #
14339 \end_layout
14340
14341 \end_inset
14342 </cell>
14343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14344 \begin_inset Text
14345
14346 \begin_layout Standard
14347 Description
14348 \end_layout
14349
14350 \end_inset
14351 </cell>
14352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14353 \begin_inset Text
14354
14355 \begin_layout Standard
14356 Vector Address
14357 \end_layout
14358
14359 \end_inset
14360 </cell>
14361 </row>
14362 <row topline="true">
14363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14364 \begin_inset Text
14365
14366 \begin_layout Standard
14367 0
14368 \end_layout
14369
14370 \end_inset
14371 </cell>
14372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14373 \begin_inset Text
14374
14375 \begin_layout Standard
14376 External 0
14377 \end_layout
14378
14379 \end_inset
14380 </cell>
14381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14382 \begin_inset Text
14383
14384 \begin_layout Standard
14385 0x0003
14386 \end_layout
14387
14388 \end_inset
14389 </cell>
14390 </row>
14391 <row topline="true">
14392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14393 \begin_inset Text
14394
14395 \begin_layout Standard
14396 1
14397 \end_layout
14398
14399 \end_inset
14400 </cell>
14401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14402 \begin_inset Text
14403
14404 \begin_layout Standard
14405 Timer 0
14406 \end_layout
14407
14408 \end_inset
14409 </cell>
14410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14411 \begin_inset Text
14412
14413 \begin_layout Standard
14414 0x000b
14415 \end_layout
14416
14417 \end_inset
14418 </cell>
14419 </row>
14420 <row topline="true">
14421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14422 \begin_inset Text
14423
14424 \begin_layout Standard
14425 2
14426 \end_layout
14427
14428 \end_inset
14429 </cell>
14430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14431 \begin_inset Text
14432
14433 \begin_layout Standard
14434 External 1
14435 \end_layout
14436
14437 \end_inset
14438 </cell>
14439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14440 \begin_inset Text
14441
14442 \begin_layout Standard
14443 0x0013
14444 \end_layout
14445
14446 \end_inset
14447 </cell>
14448 </row>
14449 <row topline="true">
14450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14451 \begin_inset Text
14452
14453 \begin_layout Standard
14454 3
14455 \end_layout
14456
14457 \end_inset
14458 </cell>
14459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14460 \begin_inset Text
14461
14462 \begin_layout Standard
14463 Timer 1
14464 \end_layout
14465
14466 \end_inset
14467 </cell>
14468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14469 \begin_inset Text
14470
14471 \begin_layout Standard
14472 0x001b
14473 \end_layout
14474
14475 \end_inset
14476 </cell>
14477 </row>
14478 <row topline="true">
14479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14480 \begin_inset Text
14481
14482 \begin_layout Standard
14483 4
14484 \end_layout
14485
14486 \end_inset
14487 </cell>
14488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14489 \begin_inset Text
14490
14491 \begin_layout Standard
14492 Serial
14493 \end_layout
14494
14495 \end_inset
14496 </cell>
14497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14498 \begin_inset Text
14499
14500 \begin_layout Standard
14501 0x0023
14502 \end_layout
14503
14504 \end_inset
14505 </cell>
14506 </row>
14507 <row topline="true">
14508 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14509 \begin_inset Text
14510
14511 \begin_layout Standard
14512 5
14513 \end_layout
14514
14515 \end_inset
14516 </cell>
14517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14518 \begin_inset Text
14519
14520 \begin_layout Standard
14521 Timer 2 (8052)
14522 \end_layout
14523
14524 \end_inset
14525 </cell>
14526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14527 \begin_inset Text
14528
14529 \begin_layout Standard
14530 0x002b
14531 \end_layout
14532
14533 \end_inset
14534 </cell>
14535 </row>
14536 <row topline="true">
14537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14538 \begin_inset Text
14539
14540 \begin_layout Standard
14541 ...
14542 \end_layout
14543
14544 \end_inset
14545 </cell>
14546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14547 \begin_inset Text
14548
14549 \begin_layout Standard
14550
14551 \end_layout
14552
14553 \end_inset
14554 </cell>
14555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14556 \begin_inset Text
14557
14558 \begin_layout Standard
14559 ...
14560 \end_layout
14561
14562 \end_inset
14563 </cell>
14564 </row>
14565 <row topline="true" bottomline="true">
14566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14567 \begin_inset Text
14568
14569 \begin_layout Standard
14570 n
14571 \end_layout
14572
14573 \end_inset
14574 </cell>
14575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14576 \begin_inset Text
14577
14578 \begin_layout Standard
14579
14580 \end_layout
14581
14582 \end_inset
14583 </cell>
14584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14585 \begin_inset Text
14586
14587 \begin_layout Standard
14588 0x0003 + 8*n
14589 \end_layout
14590
14591 \end_inset
14592 </cell>
14593 </row>
14594 </lyxtabular>
14595
14596 \end_inset
14597
14598
14599 \newline
14600
14601 \end_layout
14602
14603 \begin_layout Standard
14604 If the interrupt service routine is defined without 
14605 \emph on
14606 using
14607 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14608
14609 \end_inset
14610
14611
14612 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14613
14614 \end_inset
14615
14616
14617 \emph default
14618  a register bank or with register bank 0 (
14619 \emph on
14620 using
14621 \emph default
14622  0), the compiler will save the registers used by itself on the stack upon
14623  entry and restore them at exit, however if such an interrupt service routine
14624  calls another function then the entire register bank will be saved on the
14625  stack.
14626  This scheme may be advantageous for small interrupt service routines which
14627  have low register usage.
14628 \end_layout
14629
14630 \begin_layout Standard
14631 If the interrupt service routine is defined to be using a specific register
14632  bank then only 
14633 \emph on
14634 a, b, dptr
14635 \emph default
14636  & psw are saved and restored, if such an interrupt service routine calls
14637  another function (using another register bank) then the entire register
14638  bank of the called function will be saved on the stack
14639 \begin_inset LatexCommand \index{stack}
14640
14641 \end_inset
14642
14643 .
14644  This scheme is recommended for larger interrupt service routines.
14645 \begin_inset VSpace bigskip
14646 \end_inset
14647
14648
14649 \end_layout
14650
14651 \begin_layout Subsection
14652 HC08
14653 \begin_inset LatexCommand \index{HC08}
14654
14655 \end_inset
14656
14657  Interrupt Service Routines
14658 \end_layout
14659
14660 \begin_layout Standard
14661 Since the number of interrupts
14662 \begin_inset LatexCommand \index{HC08!interrupt}
14663
14664 \end_inset
14665
14666  available is chip specific and the interrupt vector table always ends at
14667  the last byte of memory, the interrupt numbers corresponds to the interrupt
14668  vectors in reverse order of address.
14669  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14670  2 will use the interrupt vector at 0xfffa, and so on.
14671  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14672  this way; instead see section 
14673 \begin_inset LatexCommand \ref{sub:Startup-Code}
14674
14675 \end_inset
14676
14677  for details on customizing startup.
14678 \begin_inset VSpace bigskip
14679 \end_inset
14680
14681
14682 \end_layout
14683
14684 \begin_layout Subsection
14685 Z80 Interrupt Service Routines
14686 \end_layout
14687
14688 \begin_layout Standard
14689 The Z80
14690 \begin_inset LatexCommand \index{Z80}
14691
14692 \end_inset
14693
14694  uses several different methods for determining the correct interrupt
14695 \begin_inset LatexCommand \index{Z80!interrupt}
14696
14697 \end_inset
14698
14699  vector depending on the hardware implementation.
14700  Therefore, SDCC ignores the optional interrupt number and does not attempt
14701  to generate an interrupt vector table.
14702 \end_layout
14703
14704 \begin_layout Standard
14705 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14706  instruction to return from the interrupt.
14707  To write an interrupt handler for the non-maskable interrupt, which needs
14708  a RETN instruction instead, add the 
14709 \emph on
14710 critical
14711 \emph default
14712  keyword:
14713 \end_layout
14714
14715 \begin_layout Verse
14716
14717 \family typewriter
14718 void nmi_isr (void) critical interrupt
14719 \newline
14720
14721 \newline
14722 \InsetSpace ~
14723 \InsetSpace ~
14724 \InsetSpace ~
14725 \InsetSpace ~
14726 ...
14727  
14728 \newline
14729 }
14730 \end_layout
14731
14732 \begin_layout Standard
14733 However if you need to create a non-interruptable interrupt service routine
14734  you would also require the 
14735 \emph on
14736 critical
14737 \emph default
14738  keyword.
14739  To distinguish between this and an nmi_isr you must provide an interrupt
14740  number.
14741 \begin_inset VSpace bigskip
14742 \end_inset
14743
14744
14745 \end_layout
14746
14747 \begin_layout Section
14748 Enabling and Disabling Interrupts
14749 \end_layout
14750
14751 \begin_layout Subsection
14752 Critical Functions and Critical Statements
14753 \end_layout
14754
14755 \begin_layout Standard
14756 A special keyword may be associated with a block or a function declaring
14757  it as 
14758 \emph on
14759 critical
14760 \emph default
14761 .
14762  SDCC will generate code to disable all interrupts
14763 \begin_inset LatexCommand \index{interrupt}
14764
14765 \end_inset
14766
14767  upon entry to a critical function and restore the interrupt enable to the
14768  previous state before returning.
14769  Nesting critical functions will need one additional byte on the stack
14770 \begin_inset LatexCommand \index{stack}
14771
14772 \end_inset
14773
14774  for each call.
14775 \end_layout
14776
14777 \begin_layout Verse
14778
14779 \family typewriter
14780 int foo () __critical
14781 \begin_inset LatexCommand \index{critical}
14782
14783 \end_inset
14784
14785
14786 \begin_inset LatexCommand \index{\_\_critical}
14787
14788 \end_inset
14789
14790  
14791 \newline
14792
14793 \newline
14794 \InsetSpace ~
14795 \InsetSpace ~
14796 \InsetSpace ~
14797 \InsetSpace ~
14798 ...
14799  
14800 \newline
14801 \InsetSpace ~
14802 \InsetSpace ~
14803 \InsetSpace ~
14804 \InsetSpace ~
14805 ...
14806  
14807 \newline
14808 }
14809 \end_layout
14810
14811 \begin_layout Standard
14812 The critical attribute maybe used with other attributes like 
14813 \emph on
14814 reentrant.
14815 \emph default
14816
14817 \newline
14818 The keyword 
14819 \emph on
14820 critical
14821 \emph default
14822  may also be used to disable interrupts more locally:
14823 \end_layout
14824
14825 \begin_layout Verse
14826
14827 \family typewriter
14828 __critical{ i++; }
14829 \end_layout
14830
14831 \begin_layout Standard
14832 More than one statement could have been included in the block.
14833 \end_layout
14834
14835 \begin_layout Subsection
14836 Enabling and Disabling Interrupts directly
14837 \end_layout
14838
14839 \begin_layout Standard
14840 Interrupts
14841 \begin_inset LatexCommand \index{interrupt}
14842
14843 \end_inset
14844
14845  can also be disabled and enabled directly (8051):
14846 \end_layout
14847
14848 \begin_layout Verse
14849
14850 \family typewriter
14851 EA = 0;\InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 \InsetSpace ~
14857 \InsetSpace ~
14858 \InsetSpace ~
14859 \InsetSpace ~
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 or:\InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 \InsetSpace ~
14869 \InsetSpace ~
14870 \InsetSpace ~
14871 \InsetSpace ~
14872 \InsetSpace ~
14873 \InsetSpace ~
14874 EA_SAVE = EA;
14875 \end_layout
14876
14877 \begin_layout Verse
14878
14879 \family typewriter
14880 ...\InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 \InsetSpace ~
14893 \InsetSpace ~
14894 \InsetSpace ~
14895 \InsetSpace ~
14896 \InsetSpace ~
14897 \InsetSpace ~
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 \InsetSpace ~
14908 \InsetSpace ~
14909 \InsetSpace ~
14910 EA = 0;
14911 \end_layout
14912
14913 \begin_layout Verse
14914
14915 \family typewriter
14916 EA = 1;\InsetSpace ~
14917 \InsetSpace ~
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 \InsetSpace ~
14921 \InsetSpace ~
14922 \InsetSpace ~
14923 \InsetSpace ~
14924 \InsetSpace ~
14925 \InsetSpace ~
14926 \InsetSpace ~
14927 \InsetSpace ~
14928 \InsetSpace ~
14929 \InsetSpace ~
14930 \InsetSpace ~
14931 \InsetSpace ~
14932 \InsetSpace ~
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 \InsetSpace ~
14939 \InsetSpace ~
14940 \InsetSpace ~
14941 \InsetSpace ~
14942 ...
14943 \end_layout
14944
14945 \begin_layout Verse
14946
14947 \family typewriter
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 \InsetSpace ~
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 \InsetSpace ~
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 \InsetSpace ~
14971 \InsetSpace ~
14972 \InsetSpace ~
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 \InsetSpace ~
14981 EA = EA_SAVE;
14982 \end_layout
14983
14984 \begin_layout Standard
14985 On other architectures which have seperate opcodes for enabling and disabling
14986  interrupts you might want to make use of defines with inline assembly
14987 \begin_inset LatexCommand \index{Assembler routines}
14988
14989 \end_inset
14990
14991  (HC08
14992 \begin_inset LatexCommand \index{HC08!interrupt}
14993
14994 \end_inset
14995
14996 ):
14997 \end_layout
14998
14999 \begin_layout Verse
15000
15001 \family typewriter
15002 #define CLI _asm
15003 \begin_inset LatexCommand \index{\_asm}
15004
15005 \end_inset
15006
15007 \InsetSpace ~
15008 \InsetSpace ~
15009 cli\InsetSpace ~
15010 \InsetSpace ~
15011 _endasm
15012 \begin_inset LatexCommand \index{\_endasm}
15013
15014 \end_inset
15015
15016
15017 \end_layout
15018
15019 \begin_layout Verse
15020
15021 \family typewriter
15022 #define SEI _asm\InsetSpace ~
15023 \InsetSpace ~
15024 sei\InsetSpace ~
15025 \InsetSpace ~
15026 _endasm; 
15027 \end_layout
15028
15029 \begin_layout Verse
15030
15031 \family typewriter
15032 ...
15033 \end_layout
15034
15035 \begin_layout Standard
15036 Note: it is sometimes sufficient to disable only a specific interrupt source
15037  like f.e.
15038  a timer or serial interrupt by manipulating an 
15039 \emph on
15040 interrupt mask
15041 \begin_inset LatexCommand \index{interrupt mask}
15042
15043 \end_inset
15044
15045
15046 \emph default
15047  register.
15048  
15049 \end_layout
15050
15051 \begin_layout Standard
15052 Usually the time during which interrupts are disabled should be kept as
15053  short as possible.
15054  This minimizes both 
15055 \emph on
15056 interrupt latency
15057 \emph default
15058
15059 \begin_inset LatexCommand \index{interrupt latency}
15060
15061 \end_inset
15062
15063  (the time between the occurrence of the interrupt and the execution of
15064  the first code in the interrupt routine) and 
15065 \emph on
15066 interrupt jitter
15067 \emph default
15068
15069 \begin_inset LatexCommand \index{interrupt jitter}
15070
15071 \end_inset
15072
15073  (the difference between the shortest and the longest interrupt latency).
15074  These really are something different, f.e.
15075  a serial interrupt has to be served before its buffer overruns so it cares
15076  for the maximum interrupt latency, whereas it does not care about jitter.
15077  On a loudspeaker driven via a digital to analog converter which is fed
15078  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15079  a much smaller jitter will be very audible.
15080 \end_layout
15081
15082 \begin_layout Standard
15083 You can reenable interrupts within an interrupt routine and on some architecture
15084 s you can make use of two (or more) levels of 
15085 \emph on
15086 interrupt priorities
15087 \emph default
15088
15089 \begin_inset LatexCommand \index{interrupt priority}
15090
15091 \end_inset
15092
15093 .
15094  On some architectures which don't support interrupt priorities these can
15095  be implemented by manipulating the interrupt mask and reenabling interrupts
15096  within the interrupt routine.
15097  Check there is sufficient space on the stack
15098 \begin_inset LatexCommand \index{stack}
15099
15100 \end_inset
15101
15102  and don't add complexity unless you have to.
15103  
15104 \end_layout
15105
15106 \begin_layout Subsection
15107 Semaphore
15108 \begin_inset LatexCommand \index{semaphore}
15109
15110 \end_inset
15111
15112  locking (mcs51/ds390)
15113 \end_layout
15114
15115 \begin_layout Standard
15116 Some architectures (mcs51/ds390) have an atomic
15117 \begin_inset LatexCommand \index{atomic}
15118
15119 \end_inset
15120
15121  bit test and
15122 \emph on
15123  
15124 \emph default
15125 clear
15126 \emph on
15127  
15128 \emph default
15129 instruction.
15130  These type of instructions are typically used in preemptive multitasking
15131  systems, where a routine f.e.
15132  claims the use of a data structure ('acquires a lock
15133 \begin_inset LatexCommand \index{lock}
15134
15135 \end_inset
15136
15137  on it'), makes some modifications and then releases the lock when the data
15138  structure is consistent again.
15139  The instruction may also be used if interrupt and non-interrupt code have
15140  to compete for a resource.
15141  With the atomic bit test and clear instruction interrupts
15142 \begin_inset LatexCommand \index{interrupt}
15143
15144 \end_inset
15145
15146  don't have to be disabled for the locking operation.
15147  
15148 \end_layout
15149
15150 \begin_layout Standard
15151 SDCC generates this instruction if the source follows this pattern:
15152 \end_layout
15153
15154 \begin_layout Verse
15155
15156 \family typewriter
15157 volatile
15158 \begin_inset LatexCommand \index{volatile}
15159
15160 \end_inset
15161
15162  bit resource_is_free; 
15163 \newline
15164
15165 \newline
15166 if (resource_is_free) 
15167 \newline
15168 \InsetSpace ~
15169 \InsetSpace ~
15170
15171 \newline
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 resource_is_free=0; 
15177 \newline
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 ...
15183  
15184 \newline
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 resource_is_free=1;
15190 \newline
15191 \InsetSpace ~
15192 \InsetSpace ~
15193
15194 \end_layout
15195
15196 \begin_layout Standard
15197 Note, mcs51 and ds390 support only an atomic
15198 \begin_inset LatexCommand \index{atomic}
15199
15200 \end_inset
15201
15202  bit test and 
15203 \emph on
15204 clear
15205 \emph default
15206  instruction (as opposed to atomic bit test and 
15207 \emph on
15208 set).
15209 \end_layout
15210
15211 \begin_layout Section
15212 Functions using private register banks
15213 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15214
15215 \end_inset
15216
15217  (mcs51/ds390)
15218 \end_layout
15219
15220 \begin_layout Standard
15221 Some architectures have support for quickly changing register sets.
15222  SDCC supports this feature with the 
15223 \emph on
15224 using
15225 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15226
15227 \end_inset
15228
15229
15230 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15231
15232 \end_inset
15233
15234
15235 \emph default
15236  attribute (which tells the compiler to use a register bank
15237 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15238
15239 \end_inset
15240
15241  other than the default bank zero).
15242  It should only be applied to 
15243 \emph on
15244 interrupt
15245 \begin_inset LatexCommand \index{interrupt}
15246
15247 \end_inset
15248
15249
15250 \emph default
15251  functions (see footnote below).
15252  This will in most circumstances make the generated ISR code more efficient
15253  since it will not have to save registers on the stack.
15254 \end_layout
15255
15256 \begin_layout Standard
15257 The 
15258 \emph on
15259 using
15260 \emph default
15261  attribute will have no effect on the generated code for a 
15262 \emph on
15263 non-interrupt
15264 \emph default
15265  function (but may occasionally be useful anyway
15266 \begin_inset Foot
15267 status open
15268
15269 \begin_layout Standard
15270 possible exception: if a function is called ONLY from 'interrupt' functions
15271  using a particular bank, it can be declared with the same 'using' attribute
15272  as the calling 'interrupt' functions.
15273  For instance, if you have several ISRs using bank one, and all of them
15274  call memcpy(), it might make sense to create a specialized version of memcpy()
15275  'using 1', since this would prevent the ISR from having to save bank zero
15276  to the stack on entry and switch to bank zero before calling the function
15277 \end_layout
15278
15279 \end_inset
15280
15281 ).
15282 \newline
15283
15284 \emph on
15285 (pending: Note, nowadays the 
15286 \emph default
15287 using
15288 \emph on
15289  attribute has an effect on
15290 \emph default
15291  
15292 \emph on
15293 the generated code for a 
15294 \emph default
15295 non-interrupt
15296 \emph on
15297  function
15298 \emph default
15299 .
15300 \emph on
15301 )
15302 \end_layout
15303
15304 \begin_layout Standard
15305 An 
15306 \emph on
15307 interrupt
15308 \emph default
15309  function using a non-zero bank will assume that it can trash that register
15310  bank, and will not save it.
15311  Since high-priority interrupts
15312 \begin_inset LatexCommand \index{interrupts}
15313
15314 \end_inset
15315
15316
15317 \begin_inset LatexCommand \index{interrupt priority}
15318
15319 \end_inset
15320
15321  can interrupt low-priority ones on the 8051 and friends, this means that
15322  if a high-priority ISR 
15323 \emph on
15324 using
15325 \emph default
15326  a particular bank occurs while processing a low-priority ISR 
15327 \emph on
15328 using
15329 \emph default
15330  the same bank, terrible and bad things can happen.
15331  To prevent this, no single register bank should be 
15332 \emph on
15333 used
15334 \emph default
15335  by both a high priority and a low priority ISR.
15336  This is probably most easily done by having all high priority ISRs use
15337  one bank and all low priority ISRs use another.
15338  If you have an ISR which can change priority at runtime, you're on your
15339  own: I suggest using the default bank zero and taking the small performance
15340  hit.
15341 \end_layout
15342
15343 \begin_layout Standard
15344 It is most efficient if your ISR calls no other functions.
15345  If your ISR must call other functions, it is most efficient if those functions
15346  use the same bank as the ISR (see note 1 below); the next best is if the
15347  called functions use bank zero.
15348  It is very inefficient to call a function using a different, non-zero bank
15349  from an ISR.
15350  
15351 \begin_inset VSpace bigskip
15352 \end_inset
15353
15354
15355 \end_layout
15356
15357 \begin_layout Section
15358 Startup Code
15359 \begin_inset LatexCommand \label{sub:Startup-Code}
15360
15361 \end_inset
15362
15363
15364 \begin_inset LatexCommand \index{Startup code}
15365
15366 \end_inset
15367
15368
15369 \end_layout
15370
15371 \begin_layout Subsection
15372 MCS51/DS390 Startup Code
15373 \end_layout
15374
15375 \begin_layout Standard
15376 The compiler triggers the linker to link certain initialization modules
15377  from the runtime library
15378 \begin_inset LatexCommand \index{Runtime library}
15379
15380 \end_inset
15381
15382  called crt<something>.
15383  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15384  GSINIT5) is not linked unless the -
15385 \series bold
15386
15387 \begin_inset ERT
15388 status open
15389
15390 \begin_layout Standard
15391
15392
15393 \backslash
15394 /
15395 \end_layout
15396
15397 \end_inset
15398
15399
15400 \series default
15401 -xstack option is used.
15402  These modules are highly entangled by the use of special segments/areas,
15403  but a common layout is shown below:
15404 \end_layout
15405
15406 \begin_layout Verse
15407
15408 \family typewriter
15409 \series bold
15410 \size footnotesize
15411 (main.asm)
15412 \end_layout
15413
15414 \begin_layout Verse
15415
15416 \family typewriter
15417 \size footnotesize
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 \InsetSpace ~
15426 .area HOME (CODE)
15427 \newline
15428 __interrupt_vect:
15429 \newline
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 \InsetSpace ~
15438 ljmp __sdcc_gsinit_startup
15439 \end_layout
15440
15441 \begin_layout Verse
15442
15443 \family typewriter
15444 \series bold
15445 \size footnotesize
15446 (crtstart.asm)
15447 \end_layout
15448
15449 \begin_layout Verse
15450
15451 \family typewriter
15452 \size footnotesize
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 \InsetSpace ~
15458 \InsetSpace ~
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 .area GSINIT0 (CODE)
15462 \newline
15463 __sdcc_gsinit_startup::
15464 \newline
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 \InsetSpace ~
15468 \InsetSpace ~
15469 \InsetSpace ~
15470 \InsetSpace ~
15471 \InsetSpace ~
15472 \InsetSpace ~
15473 mov sp,#__start__stack - 1
15474 \end_layout
15475
15476 \begin_layout Verse
15477
15478 \family typewriter
15479 \series bold
15480 \size footnotesize
15481 (crtxstack.asm)
15482 \end_layout
15483
15484 \begin_layout Verse
15485
15486 \family typewriter
15487 \size footnotesize
15488 \InsetSpace ~
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 .area GSINIT1 (CODE)
15497 \newline
15498 __sdcc_init_xstack::
15499 \newline
15500 ; Need to initialize in GSINIT1 in
15501  case the user's __sdcc_external_startup uses the xstack.
15502 \newline
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 \InsetSpace ~
15509 \InsetSpace ~
15510 \InsetSpace ~
15511 mov __XPAGE,#(__start__x
15512 stack >> 8)
15513 \newline
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 \InsetSpace ~
15519 \InsetSpace ~
15520 \InsetSpace ~
15521 \InsetSpace ~
15522 mov _spx,#__start__xstack
15523 \end_layout
15524
15525 \begin_layout Verse
15526
15527 \family typewriter
15528 \series bold
15529 \size footnotesize
15530 (crtstart.asm)
15531 \end_layout
15532
15533 \begin_layout Verse
15534
15535 \family typewriter
15536 \size footnotesize
15537 \InsetSpace ~
15538 \InsetSpace ~
15539 \InsetSpace ~
15540 \InsetSpace ~
15541 \InsetSpace ~
15542 \InsetSpace ~
15543 \InsetSpace ~
15544 \InsetSpace ~
15545 .area GSINIT2 (CODE)
15546 \newline
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 lcall __sdcc_external_startup
15556 \newline
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 mov a,dpl
15566 \newline
15567 \InsetSpace ~
15568 \InsetSpace ~
15569 \InsetSpace ~
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 jz __sdcc_init_data
15576 \newline
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 ljmp
15586  __sdcc_program_startup
15587 \newline
15588 __sdcc_init_data:
15589 \end_layout
15590
15591 \begin_layout Verse
15592
15593 \family typewriter
15594 \series bold
15595 \size footnotesize
15596 (crtxinit.asm)
15597 \end_layout
15598
15599 \begin_layout Verse
15600
15601 \family typewriter
15602 \size footnotesize
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 .area GSINIT3 (CODE)
15612 \newline
15613 __mcs51_genXINIT::
15614 \newline
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 mov r1,#l_XINIT
15624 \newline
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 \InsetSpace ~
15632 \InsetSpace ~
15633 mov a,r1
15634 \newline
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 orl a,#(l_XINIT
15644  >> 8)
15645 \newline
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 jz 00003$
15655 \newline
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 mov r2,#((l_XINIT+255) >> 8)
15665 \newline
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 mov dptr,#s_XINIT
15675 \newline
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 mov r0,#s_XISEG
15685 \newline
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 mov
15695  __XPAGE,#(s_XISEG >> 8)
15696 \newline
15697 00001$:\InsetSpace ~
15698 clr a
15699 \newline
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 movc a,@a+dptr
15709 \newline
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 movx @r0,a
15719 \newline
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 inc dptr
15729 \newline
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 inc
15739  r0
15740 \newline
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 cjne r0,#0,00002$
15750 \newline
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 inc __XPAGE
15760 \newline
15761 00002$:\InsetSpace ~
15762 djnz r1,00001$
15763 \newline
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 djnz r2,00001$
15773 \newline
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 mov __XPAGE,#0
15783 xFF
15784 \newline
15785 00003$:
15786 \end_layout
15787
15788 \begin_layout Verse
15789
15790 \family typewriter
15791 \series bold
15792 \size footnotesize
15793 (crtclear.asm)
15794 \end_layout
15795
15796 \begin_layout Verse
15797
15798 \family typewriter
15799 \size footnotesize
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 .area GSINIT4 (CODE)
15809 \newline
15810 __mcs51_genRAMCLEAR::
15811 \newline
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 clr a
15821 \newline
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 mov r0,#(l_IRAM-1)
15831 \newline
15832 00004$:\InsetSpace ~
15833 mov
15834  @r0,a
15835 \newline
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 djnz r0,00004$
15845 \newline
15846 ; _mcs51_genRAMCLEAR() end
15847 \end_layout
15848
15849 \begin_layout Verse
15850
15851 \family typewriter
15852 \series bold
15853 \size footnotesize
15854 (crtxclear.asm)
15855 \end_layout
15856
15857 \begin_layout Verse
15858
15859 \family typewriter
15860 \size footnotesize
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 .area GSINIT4 (CODE)
15870 \newline
15871 __mcs51_genXRAMCLEAR::
15872 \newline
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 mov r0,#l_PSEG
15882 \newline
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 mov a,r0
15892 \newline
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 jz 00006$
15902 \newline
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 mov
15912  r1,#s_PSEG
15913 \newline
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 mov __XPAGE,#(s_PSEG >> 8)
15923 \newline
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 clr a
15933 \newline
15934 00005$:\InsetSpace ~
15935 movx @r1,a
15936 \newline
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 inc r1
15946 \newline
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 djnz r0,00005$
15956 \newline
15957 0
15958 0006$:
15959 \newline
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 mov r0,#l_XSEG
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 mov a,r0
15979 \newline
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 orl a,#(l_XSEG >> 8)
15989 \newline
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 jz 00008$
15999 \newline
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 mov r1,#((l_XSEG
16009  + 255) >> 8)
16010 \newline
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 mov dptr,#s_XSEG
16020 \newline
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 clr a
16030 \newline
16031 00007$:\InsetSpace ~
16032 movx @dptr,a
16033 \newline
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 inc dptr
16043 \newline
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 djnz r0,00007$
16053 \newline
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 djnz
16063  r1,00007$
16064 \newline
16065 00008$:
16066 \end_layout
16067
16068 \begin_layout Verse
16069
16070 \family typewriter
16071 \series bold
16072 \size footnotesize
16073 (crtxstack.asm)
16074 \end_layout
16075
16076 \begin_layout Verse
16077
16078 \family typewriter
16079 \size footnotesize
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 .area GSINIT5 (CODE)
16089 \newline
16090 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16091  modifies __XPAGE
16092 \newline
16093 ; and __mcs51_genRAMCLEAR modifies _spx.
16094 \newline
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 \InsetSpace ~
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 mov __XPAGE,#(__start__x
16104 stack >> 8)
16105 \newline
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 \InsetSpace ~
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 mov _spx,#__start__xstack
16115 \end_layout
16116
16117 \begin_layout Verse
16118
16119 \family typewriter
16120 \series bold
16121 \size footnotesize
16122 (application modules)
16123 \end_layout
16124
16125 \begin_layout Verse
16126
16127 \family typewriter
16128 \size footnotesize
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 \InsetSpace ~
16132 \InsetSpace ~
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 .area GSINIT (CODE)
16138 \end_layout
16139
16140 \begin_layout Verse
16141
16142 \family typewriter
16143 \series bold
16144 \size footnotesize
16145 (main.asm)
16146 \end_layout
16147
16148 \begin_layout Verse
16149
16150 \family typewriter
16151 \size footnotesize
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 .area GSFINAL (CODE)
16161 \newline
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 ljmp __sdcc_program_startup
16171 \newline
16172 ;---------------------------------
16173 -----------------------
16174 \newline
16175 ; Home
16176 \newline
16177 ;--------------------------------------------------
16178 ------
16179 \newline
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 .area HOME (CODE)
16189 \newline
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 .area CSEG (CODE)
16199 \newline
16200 __sdcc_program_startup:
16201 \newline
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 lcall _main
16211 \newline
16212 ;
16213  return from main will lock up
16214 \newline
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 sjmp .
16224 \end_layout
16225
16226 \begin_layout Standard
16227 One of these modules (crtstart.asm) contains a call to the C routine 
16228 \emph on
16229 _sdcc_external_startup()
16230 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16231
16232 \end_inset
16233
16234
16235 \series bold
16236 \emph default
16237  
16238 \series default
16239 at the start of the CODE area.
16240  This routine is also in the runtime library
16241 \begin_inset LatexCommand \index{Runtime library}
16242
16243 \end_inset
16244
16245  and returns 0 by default.
16246  If this routine returns a non-zero value, the static & global variable
16247  initialization will be skipped and the function main will be invoked.
16248  Otherwise static & global variables will be initialized before the function
16249  main is invoked.
16250  You could add an 
16251 \emph on
16252 _sdcc_external_startup()
16253 \emph default
16254  routine to your program to override the default if you need to setup hardware
16255  or perform some other critical operation prior to static & global variable
16256  initialization
16257 \begin_inset LatexCommand \index{Variable initialization}
16258
16259 \end_inset
16260
16261 .
16262  On some mcs51 variants xdata
16263 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16264
16265 \end_inset
16266
16267  memory has to be explicitly enabled before it can be accessed or if the
16268  watchdog
16269 \begin_inset LatexCommand \index{watchdog}
16270
16271 \end_inset
16272
16273  needs to be disabled, this is the place to do it.
16274  The startup code clears all internal data memory, 256 bytes by default,
16275  but from 0 to n-1 if 
16276 \emph on
16277 -
16278 \begin_inset ERT
16279 status collapsed
16280
16281 \begin_layout Standard
16282
16283
16284 \backslash
16285 /
16286 \end_layout
16287
16288 \end_inset
16289
16290 -iram-size
16291 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16292
16293 \end_inset
16294
16295 n
16296 \emph default
16297  is used.
16298  (recommended for Chipcon CC1010).
16299 \end_layout
16300
16301 \begin_layout Standard
16302 See also the compiler options 
16303 \emph on
16304 -
16305 \begin_inset ERT
16306 status collapsed
16307
16308 \begin_layout Standard
16309
16310
16311 \backslash
16312 /
16313 \end_layout
16314
16315 \end_inset
16316
16317 -no-xinit
16318 \emph default
16319 -
16320 \emph on
16321 opt
16322 \emph default
16323
16324 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16325
16326 \end_inset
16327
16328
16329 \emph on
16330 -
16331 \begin_inset ERT
16332 status collapsed
16333
16334 \begin_layout Standard
16335
16336
16337 \backslash
16338 /
16339 \end_layout
16340
16341 \end_inset
16342
16343 -main-return
16344 \emph default
16345
16346 \begin_inset LatexCommand \index{-\/-main-return}
16347
16348 \end_inset
16349
16350  and section 
16351 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16352
16353 \end_inset
16354
16355  about MCS51-variants.
16356 \begin_inset VSpace bigskip
16357 \end_inset
16358
16359
16360 \end_layout
16361
16362 \begin_layout Subsection
16363 HC08 Startup Code
16364 \end_layout
16365
16366 \begin_layout Standard
16367 The HC08
16368 \begin_inset LatexCommand \index{HC08}
16369
16370 \end_inset
16371
16372  startup code follows the same scheme as the MCS51 startup code.
16373 \begin_inset VSpace bigskip
16374 \end_inset
16375
16376
16377 \end_layout
16378
16379 \begin_layout Subsection
16380 Z80 Startup Code
16381 \end_layout
16382
16383 \begin_layout Standard
16384 On the Z80
16385 \begin_inset LatexCommand \index{Z80}
16386
16387 \end_inset
16388
16389  the startup code is inserted by linking with crt0.o which is generated from
16390  sdcc/device/lib/z80/crt0.s.
16391  If you need a different startup code you can use the compiler option 
16392 \emph on
16393 -
16394 \series bold
16395 \emph default
16396
16397 \begin_inset ERT
16398 status collapsed
16399
16400 \begin_layout Standard
16401
16402
16403 \backslash
16404 /
16405 \end_layout
16406
16407 \end_inset
16408
16409
16410 \series default
16411 \emph on
16412 -no-std-crt0
16413 \emph default
16414
16415 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16416
16417 \end_inset
16418
16419  and provide your own crt0.o.
16420  
16421 \begin_inset VSpace bigskip
16422 \end_inset
16423
16424
16425 \end_layout
16426
16427 \begin_layout Section
16428 Inline Assembler Code
16429 \begin_inset LatexCommand \index{Assembler routines}
16430
16431 \end_inset
16432
16433
16434 \end_layout
16435
16436 \begin_layout Subsection
16437 A Step by Step Introduction
16438 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16439
16440 \end_inset
16441
16442
16443 \end_layout
16444
16445 \begin_layout Standard
16446 Starting from a small snippet of c-code this example shows for the MCS51
16447  how to use inline assembly, access variables, a function parameter and
16448  an array in xdata memory.
16449  The example uses an MCS51 here but is easily adapted for other architectures.
16450  This is a buffer routine which should be optimized:
16451 \end_layout
16452
16453 \begin_layout Verse
16454
16455 \family typewriter
16456 \size footnotesize
16457 unsigned char __far
16458 \begin_inset LatexCommand \index{far (storage class)}
16459
16460 \end_inset
16461
16462
16463 \begin_inset LatexCommand \index{\_\_far (storage class)}
16464
16465 \end_inset
16466
16467  __at
16468 \begin_inset LatexCommand \index{at}
16469
16470 \end_inset
16471
16472
16473 \begin_inset LatexCommand \index{\_\_at}
16474
16475 \end_inset
16476
16477 (0x7f00) buf[0x100];
16478 \begin_inset LatexCommand \index{Aligned array}
16479
16480 \end_inset
16481
16482
16483 \newline
16484 unsigned char head, tail;\InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 \InsetSpace ~
16501 /* if interrupts
16502 \begin_inset LatexCommand \index{interrupt}
16503
16504 \end_inset
16505
16506  are involved see
16507 \newline
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 \InsetSpace ~
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 \InsetSpace ~
16534 \InsetSpace ~
16535 \InsetSpace ~
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 \InsetSpace ~
16540 \InsetSpace ~
16541 \InsetSpace ~
16542 \InsetSpace ~
16543 \InsetSpace ~
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 \InsetSpace ~
16548 \InsetSpace ~
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 section 
16554 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16555
16556 \end_inset
16557
16558  about
16559 \series bold
16560  volatile
16561 \series default
16562  */
16563 \newline
16564
16565 \newline
16566 void to_buffer( unsigned char c ) 
16567 \newline
16568 {
16569 \newline
16570 \InsetSpace ~
16571 \InsetSpace ~
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 if( head != (unsigned char)(tail-1)
16575  )\InsetSpace ~
16576 /* cast 
16577 \series bold
16578 needed
16579 \series default
16580  to avoid promotion
16581 \begin_inset LatexCommand \index{promotion to signed int}
16582
16583 \end_inset
16584
16585
16586 \begin_inset LatexCommand \index{type promotion}
16587
16588 \end_inset
16589
16590  to integer */
16591 \begin_inset Marginal
16592 status collapsed
16593
16594 \begin_layout Standard
16595
16596 \series bold
16597 \InsetSpace ~
16598 !
16599 \end_layout
16600
16601 \end_inset
16602
16603
16604 \newline
16605 \InsetSpace ~
16606 \InsetSpace ~
16607 \InsetSpace ~
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 \InsetSpace ~
16611 \InsetSpace ~
16612 \InsetSpace ~
16613 buf[ head++ ] = c;\InsetSpace ~
16614 \InsetSpace ~
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 \InsetSpace ~
16627 \InsetSpace ~
16628 \InsetSpace ~
16629 /* access to a 256 byte aligned array */
16630 \newline
16631
16632 \end_layout
16633
16634 \begin_layout Standard
16635 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16636  then a corresponding buffer.asm file is generated.
16637  We define a new function 
16638 \family typewriter
16639 to_buffer_asm()
16640 \family default
16641  in file buffer.c in which we cut and paste the generated code, removing
16642  unwanted comments and some ':'.
16643  Then add 
16644 \begin_inset Quotes sld
16645 \end_inset
16646
16647
16648 \series bold
16649 _asm
16650 \series default
16651
16652 \begin_inset Quotes srd
16653 \end_inset
16654
16655  and 
16656 \begin_inset Quotes sld
16657 \end_inset
16658
16659
16660 \series bold
16661 _endasm;
16662 \series default
16663
16664 \begin_inset Quotes srd
16665 \end_inset
16666
16667
16668 \begin_inset Foot
16669 status open
16670
16671 \begin_layout Standard
16672 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16673  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16674  has to be used.
16675  The latter is also used in the library functions.
16676 \end_layout
16677
16678 \end_inset
16679
16680  to the beginning and the end of the function body:
16681 \end_layout
16682
16683 \begin_layout Verse
16684
16685 \family typewriter
16686 \size footnotesize
16687 /* With a cut and paste from the .asm file, we have something to start with.
16688 \newline
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 \InsetSpace ~
16692 The
16693  function is not yet OK! (registers aren't saved) */ 
16694 \newline
16695 void to_buffer_asm(
16696  unsigned char c ) 
16697 \newline
16698
16699 \newline
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 \InsetSpace ~
16703 \InsetSpace ~
16704 _asm
16705 \begin_inset LatexCommand \index{\_asm}
16706
16707 \end_inset
16708
16709
16710 \begin_inset LatexCommand \index{\_\_asm}
16711
16712 \end_inset
16713
16714
16715 \newline
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 mov\InsetSpace ~
16721 \InsetSpace ~
16722 r2,dpl 
16723 \newline
16724 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16725 /* cast 
16726 \series bold
16727 needed
16728 \series default
16729  to avoid promotion
16730 \begin_inset LatexCommand \index{promotion to signed int}
16731
16732 \end_inset
16733
16734
16735 \begin_inset LatexCommand \index{type promotion}
16736
16737 \end_inset
16738
16739  to integer */
16740 \newline
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 mov\InsetSpace ~
16746 \InsetSpace ~
16747 a,_tail 
16748 \newline
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 dec\InsetSpace ~
16754 \InsetSpace ~
16755
16756 \newline
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 mov\InsetSpace ~
16762 \InsetSpace ~
16763 r3,a 
16764 \newline
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 mov\InsetSpace ~
16770 \InsetSpace ~
16771 a,_head 
16772 \newline
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 cjne a,ar3,00106$ 
16778 \newline
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 ret
16784 \newline
16785 00106$:
16786  
16787 \newline
16788 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16789 \begin_inset LatexCommand \index{Aligned array}
16790
16791 \end_inset
16792
16793
16794 \newline
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 mov\InsetSpace ~
16800 \InsetSpace ~
16801 r3,_head 
16802 \newline
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 inc\InsetSpace ~
16808 \InsetSpace ~
16809 _head 
16810 \newline
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 mov\InsetSpace ~
16816 \InsetSpace ~
16817 dpl,r3 
16818 \newline
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 mov\InsetSpace ~
16824 \InsetSpace ~
16825 dph,#(_buf >> 8) 
16826 \newline
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 mov\InsetSpace ~
16832 \InsetSpace ~
16833 a,r2 
16834 \newline
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 movx @dptr,a
16840  
16841 \newline
16842 00103$: 
16843 \newline
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 ret
16849 \newline
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 _endasm
16855 \begin_inset LatexCommand \index{\_endasm}
16856
16857 \end_inset
16858
16859
16860 \begin_inset LatexCommand \index{\_\_endasm}
16861
16862 \end_inset
16863
16864 ;
16865 \newline
16866
16867 \end_layout
16868
16869 \begin_layout Standard
16870 The new file buffer.c should compile with only one warning about the unreferenced
16871  function argument 'c'.
16872  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16873  (1) and finally have:
16874 \end_layout
16875
16876 \begin_layout Verse
16877
16878 \family typewriter
16879 \size footnotesize
16880 unsigned char __far __at(0x7f00) buf[0x100];
16881 \newline
16882 unsigned char head, tail;
16883 \newline
16884 #define
16885  USE_ASSEMBLY (1)
16886 \newline
16887
16888 \newline
16889 #if !USE_ASSEMBLY
16890 \newline
16891
16892 \newline
16893 void to_buffer( unsigned char c )
16894 \newline
16895 {
16896 \newline
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 if(
16902  head != (unsigned char)(tail-1) )
16903 \newline
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 buf[ head++ ] = c;
16913 \newline
16914 }
16915 \newline
16916
16917 \newline
16918 #else
16919 \newline
16920
16921 \newline
16922 void to_buffer(
16923  unsigned char c )
16924 \newline
16925 {
16926 \newline
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 c; // to avoid warning: unreferenced function argument
16932 \newline
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 _asm
16938 \begin_inset LatexCommand \index{\_asm}
16939
16940 \end_inset
16941
16942
16943 \begin_inset LatexCommand \index{\_\_asm}
16944
16945 \end_inset
16946
16947
16948 \newline
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 ; save used registers here.
16958  
16959 \newline
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 ; If we were still using r2,r3 we would have to push them here.
16969  
16970 \newline
16971 ; if( head != (unsigned char)(tail-1) )
16972 \newline
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 \InsetSpace ~
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 mov\InsetSpace ~
16982  a,_tail
16983 \newline
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 dec\InsetSpace ~
16993  a
16994 \newline
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 xrl\InsetSpace ~
17004  a,_head
17005 \newline
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 \InsetSpace ~
17014 ; we
17015  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17016 \newline
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 \InsetSpace ~
17024 \InsetSpace ~
17025 jz\InsetSpace ~
17026 \InsetSpace ~
17027  t_b_end$
17028 \newline
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 \InsetSpace ~
17032 \InsetSpace ~
17033 \InsetSpace ~
17034 \InsetSpace ~
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 ;
17038 \newline
17039 ;
17040  buf[ head++ ] = c;
17041 \newline
17042 \InsetSpace ~
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 mov\InsetSpace ~
17051  a,dpl \InsetSpace ~
17052 \InsetSpace ~
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 \InsetSpace ~
17058 ; dpl holds lower byte of function argument
17059 \newline
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 mov\InsetSpace ~
17069
17070  dpl,_head \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 ; buf is 0x100 byte aligned so head can be used directly
17074 \newline
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 mov\InsetSpace ~
17084  dph,#(_bu
17085 f>>8)
17086 \newline
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 movx @dptr,a
17096 \newline
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 \InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 inc \InsetSpace ~
17106 _head
17107 \newline
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 ; we could do an ANL _head,#0x0f here to use a
17117  smaller buffer (see above)
17118 \newline
17119 t_b_end$:
17120 \newline
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 ; restore used registers here 
17130 \newline
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 _endasm
17136 \begin_inset LatexCommand \index{\_endasm}
17137
17138 \end_inset
17139
17140
17141 \begin_inset LatexCommand \index{\_\_endasm}
17142
17143 \end_inset
17144
17145 ;
17146 \newline
17147 }
17148 \newline
17149 #endif
17150 \end_layout
17151
17152 \begin_layout Standard
17153 The inline assembler code can contain any valid code understood by the assembler
17154 , this includes any assembler directives and comment lines.
17155  The assembler does not like some characters like ':' or ''' in comments.
17156  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17157 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17158
17159 \end_inset
17160
17161
17162 \begin_inset LatexCommand \index{Assembler documentation}
17163
17164 \end_inset
17165
17166  or online at 
17167 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17168
17169 \end_inset
17170
17171 \InsetSpace ~
17172 .
17173 \end_layout
17174
17175 \begin_layout Standard
17176 The compiler does not do any validation of the code within the 
17177 \family typewriter
17178 _asm
17179 \begin_inset LatexCommand \index{\_asm}
17180
17181 \end_inset
17182
17183
17184 \begin_inset LatexCommand \index{\_\_asm}
17185
17186 \end_inset
17187
17188  ...
17189  _endasm
17190 \size footnotesize
17191
17192 \begin_inset LatexCommand \index{\_endasm}
17193
17194 \end_inset
17195
17196
17197 \begin_inset LatexCommand \index{\_\_endasm}
17198
17199 \end_inset
17200
17201
17202 \size default
17203 ;
17204 \family default
17205  keyword pair.
17206  Specifically it will not know which registers are used and thus register
17207  pushing/popping
17208 \begin_inset LatexCommand \index{push/pop}
17209
17210 \end_inset
17211
17212  has to be done manually.
17213  
17214 \end_layout
17215
17216 \begin_layout Standard
17217 It is recommended that each assembly instruction (including labels) be placed
17218  in a separate line (as the example shows).
17219  When the -
17220 \begin_inset ERT
17221 status collapsed
17222
17223 \begin_layout Standard
17224
17225
17226 \backslash
17227 /
17228 \end_layout
17229
17230 \end_inset
17231
17232 -
17233 \emph on
17234 peep-asm
17235 \begin_inset LatexCommand \index{-\/-peep-asm}
17236
17237 \end_inset
17238
17239
17240 \emph default
17241  command line option is used, the inline assembler code will be passed through
17242  the peephole optimizer
17243 \begin_inset LatexCommand \index{Peephole optimizer}
17244
17245 \end_inset
17246
17247 .
17248  There are only a few (if any) cases where this option makes sense, it might
17249  cause some unexpected changes in the inline assembler code.
17250  Please go through the peephole optimizer rules defined in file 
17251 \emph on
17252 SDCCpeeph.def
17253 \emph default
17254  before using this option.
17255 \end_layout
17256
17257 \begin_layout Subsection
17258 Naked Functions
17259 \begin_inset LatexCommand \label{sub:Naked-Functions}
17260
17261 \end_inset
17262
17263
17264 \begin_inset LatexCommand \index{Naked functions}
17265
17266 \end_inset
17267
17268
17269 \end_layout
17270
17271 \begin_layout Standard
17272 A special keyword may be associated with a function declaring it as 
17273 \emph on
17274 _naked
17275 \begin_inset LatexCommand \index{\_naked}
17276
17277 \end_inset
17278
17279
17280 \begin_inset LatexCommand \index{\_\_naked}
17281
17282 \end_inset
17283
17284 .
17285  
17286 \emph default
17287 The 
17288 \emph on
17289 _naked
17290 \emph default
17291  function modifier attribute prevents the compiler from generating prologue
17292 \begin_inset LatexCommand \index{function prologue}
17293
17294 \end_inset
17295
17296  and epilogue
17297 \begin_inset LatexCommand \index{function epilogue}
17298
17299 \end_inset
17300
17301  code for that function.
17302  This means that the user is entirely responsible for such things as saving
17303  any registers that may need to be preserved, selecting the proper register
17304  bank, generating the 
17305 \emph on
17306 return
17307 \emph default
17308  instruction at the end, etc.
17309  Practically, this means that the contents of the function must be written
17310  in inline assembler.
17311  This is particularly useful for interrupt functions, which can have a large
17312  (and often unnecessary) prologue/epilogue.
17313  For example, compare the code generated by these two functions:
17314 \end_layout
17315
17316 \begin_layout Verse
17317
17318 \family typewriter
17319 volatile
17320 \begin_inset LatexCommand \index{volatile}
17321
17322 \end_inset
17323
17324  data unsigned char counter;
17325 \newline
17326
17327 \newline
17328 void simpleInterrupt(void) __interrupt
17329 \begin_inset LatexCommand \index{interrupt}
17330
17331 \end_inset
17332
17333
17334 \begin_inset LatexCommand \index{\_\_interrupt}
17335
17336 \end_inset
17337
17338  (1)
17339 \newline
17340 {
17341 \newline
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 counter++;
17347 \newline
17348 }
17349 \newline
17350
17351 \newline
17352 void nakedInterrupt(void) __interrupt (2) __naked
17353 \newline
17354 {
17355 \newline
17356 \InsetSpace ~
17357 \InsetSpace ~
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 _asm
17361 \begin_inset LatexCommand \index{\_asm}
17362
17363 \end_inset
17364
17365
17366 \begin_inset LatexCommand \index{\_\_asm}
17367
17368 \end_inset
17369
17370
17371 \newline
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 inc\InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 \InsetSpace ~
17382 \InsetSpace ~
17383 _counter ; does not change flags, no need to save psw
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 reti\InsetSpace ~
17392 \InsetSpace ~
17393 \InsetSpace ~
17394 \InsetSpace ~
17395 ; MUST explicitly
17396  include ret or reti in _naked function.
17397 \newline
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 _endasm
17403 \begin_inset LatexCommand \index{\_endasm}
17404
17405 \end_inset
17406
17407
17408 \begin_inset LatexCommand \index{\_\_endasm}
17409
17410 \end_inset
17411
17412 ;
17413 \newline
17414 }
17415 \end_layout
17416
17417 \begin_layout Standard
17418 For an 8051 target, the generated simpleInterrupt looks like:
17419 \end_layout
17420
17421 \begin_layout Verse
17422
17423 \family typewriter
17424 Note, this is an 
17425 \emph on
17426 outdated
17427 \emph default
17428  example, recent versions of SDCC generate
17429 \newline
17430 the 
17431 \emph on
17432 same
17433 \emph default
17434  code for simpleInterrupt() and nakedInterrupt()!
17435 \newline
17436
17437 \newline
17438 _simpleInterrupt:
17439 \newline
17440 \InsetSpace ~
17441 \InsetSpace ~
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 push\InsetSpace ~
17445 \InsetSpace ~
17446 \InsetSpace ~
17447 \InsetSpace ~
17448 acc
17449 \newline
17450 \InsetSpace ~
17451 \InsetSpace ~
17452 \InsetSpace ~
17453 \InsetSpace ~
17454 push\InsetSpace ~
17455 \InsetSpace ~
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 b
17459 \newline
17460 \InsetSpace ~
17461 \InsetSpace ~
17462 \InsetSpace ~
17463 \InsetSpace ~
17464 pu
17465 sh\InsetSpace ~
17466 \InsetSpace ~
17467 \InsetSpace ~
17468 \InsetSpace ~
17469 dpl
17470 \newline
17471 \InsetSpace ~
17472 \InsetSpace ~
17473 \InsetSpace ~
17474 \InsetSpace ~
17475 push\InsetSpace ~
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 \InsetSpace ~
17479 dph
17480 \newline
17481 \InsetSpace ~
17482 \InsetSpace ~
17483 \InsetSpace ~
17484 \InsetSpace ~
17485 push\InsetSpace ~
17486 \InsetSpace ~
17487 \InsetSpace ~
17488 \InsetSpace ~
17489 psw
17490 \newline
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 \InsetSpace ~
17495 mov\InsetSpace ~
17496 \InsetSpace ~
17497 \InsetSpace ~
17498 \InsetSpace ~
17499 \InsetSpace ~
17500 psw,#0x00
17501 \newline
17502 \InsetSpace ~
17503 \InsetSpace ~
17504 \InsetSpace ~
17505 \InsetSpace ~
17506 inc\InsetSpace ~
17507 \InsetSpace ~
17508 \InsetSpace ~
17509 \InsetSpace ~
17510 \InsetSpace ~
17511 _counter
17512 \newline
17513 \InsetSpace ~
17514 \InsetSpace ~
17515 \InsetSpace ~
17516 \InsetSpace ~
17517 pop\InsetSpace ~
17518 \InsetSpace ~
17519 \InsetSpace ~
17520 \InsetSpace ~
17521 \InsetSpace ~
17522 psw
17523 \newline
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 pop\InsetSpace ~
17529 \InsetSpace ~
17530 \InsetSpace ~
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 dph
17534 \newline
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 pop\InsetSpace ~
17540 \InsetSpace ~
17541 \InsetSpace ~
17542 \InsetSpace ~
17543 \InsetSpace ~
17544 dpl
17545 \newline
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 pop\InsetSpace ~
17551 \InsetSpace ~
17552 \InsetSpace ~
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 b
17556 \newline
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 pop\InsetSpace ~
17562 \InsetSpace ~
17563 \InsetSpace ~
17564 \InsetSpace ~
17565 \InsetSpace ~
17566 acc
17567 \newline
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 \InsetSpace ~
17572 reti
17573 \end_layout
17574
17575 \begin_layout Standard
17576 whereas nakedInterrupt looks like:
17577 \end_layout
17578
17579 \begin_layout Verse
17580
17581 \family typewriter
17582 _nakedInterrupt:
17583 \newline
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 inc\InsetSpace ~
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 _counter ; does not change flags, no need to save psw
17593 \newline
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 reti\InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 ;
17611  MUST explicitly include ret or reti in _naked function
17612 \end_layout
17613
17614 \begin_layout Standard
17615 The related directive #pragma exclude
17616 \begin_inset LatexCommand \index{\#pragma exclude}
17617
17618 \end_inset
17619
17620  allows a more fine grained control over pushing & popping
17621 \begin_inset LatexCommand \index{push/pop}
17622
17623 \end_inset
17624
17625  the registers.
17626 \end_layout
17627
17628 \begin_layout Standard
17629 While there is nothing preventing you from writing C code inside a 
17630 \family typewriter
17631 _naked
17632 \family default
17633  function, there are many ways to shoot yourself in the foot doing this,
17634  and it is recommended that you stick to inline assembler.
17635 \end_layout
17636
17637 \begin_layout Subsection
17638 Use of Labels within Inline Assembler
17639 \end_layout
17640
17641 \begin_layout Standard
17642 SDCC allows the use of in-line assembler with a few restrictions regarding
17643  labels.
17644  All labels defined within inline assembler code have to be of the form
17645  
17646 \emph on
17647 nnnnn$
17648 \emph default
17649  where nnnnn is a number less than 100 (which implies a limit of utmost
17650  100 inline assembler labels 
17651 \emph on
17652 per function
17653 \emph default
17654 \noun on
17655 )
17656 \noun default
17657 .
17658 \begin_inset Foot
17659 status open
17660
17661 \begin_layout Standard
17662 This is a slightly more stringent rule than absolutely necessary, but stays
17663  always on the safe side.
17664  Labels in the form of nnnnn$ are local labels in the assembler, locality
17665  of which is confined within two labels of the standard form.
17666  The compiler uses the same form for labels within a function (but starting
17667  from nnnnn=00100); and places always a standard label at the beginning
17668  of a function, thus limiting the locality of labels within the scope of
17669  the function.
17670  So, if the inline assembler part would be embedded into C-code, an improperly
17671  placed non-local label in the assembler would break up the reference space
17672  for labels created by the compiler for the C-code, leading to an assembling
17673  error.
17674 \end_layout
17675
17676 \begin_layout Standard
17677 The numeric part of local labels does not need to have 5 digits (although
17678  this is the form of labels output by the compiler), any valid integer will
17679  do.
17680  Please refer to the assemblers documentation for further details.
17681 \end_layout
17682
17683 \end_inset
17684
17685  
17686 \end_layout
17687
17688 \begin_layout Verse
17689
17690 \family typewriter
17691 _asm
17692 \begin_inset LatexCommand \index{\_asm}
17693
17694 \end_inset
17695
17696
17697 \begin_inset LatexCommand \index{\_\_asm}
17698
17699 \end_inset
17700
17701  
17702 \newline
17703 \InsetSpace ~
17704 \InsetSpace ~
17705 \InsetSpace ~
17706 \InsetSpace ~
17707 mov\InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 \InsetSpace ~
17711 \InsetSpace ~
17712 b,#10 
17713 \newline
17714 00001$: 
17715 \newline
17716 \InsetSpace ~
17717 \InsetSpace ~
17718 \InsetSpace ~
17719 \InsetSpace ~
17720 djnz\InsetSpace ~
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 b,00001$ 
17725 \newline
17726 _endasm
17727 \begin_inset LatexCommand \index{\_endasm}
17728
17729 \end_inset
17730
17731
17732 \begin_inset LatexCommand \index{\_\_endasm}
17733
17734 \end_inset
17735
17736  ;
17737 \end_layout
17738
17739 \begin_layout Standard
17740 Inline assembler code cannot reference any C-labels, however it can reference
17741  labels
17742 \begin_inset LatexCommand \index{Labels}
17743
17744 \end_inset
17745
17746  defined by the inline assembler, e.g.:
17747 \end_layout
17748
17749 \begin_layout Verse
17750
17751 \family typewriter
17752 foo() { 
17753 \newline
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 \InsetSpace ~
17757 \InsetSpace ~
17758 /* some c code */ 
17759 \newline
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 _asm 
17765 \newline
17766 \InsetSpace ~
17767 \InsetSpace ~
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 ; some assembler code 
17773 \newline
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 ljmp 0003$ 
17781 \newline
17782 \InsetSpace ~
17783 \InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 _endasm;
17787  
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 /* some more c code */ 
17794 \newline
17795 clabel:\InsetSpace ~
17796 \InsetSpace ~
17797 /* inline assembler cannot reference this
17798  label */ 
17799 \begin_inset Foot
17800 status open
17801
17802 \begin_layout Standard
17803 Here, the C-label 
17804 \family typewriter
17805 clabel
17806 \family default
17807  is translated by the compiler into a local label, so the locality of labels
17808  within the function is not broken.
17809 \end_layout
17810
17811 \end_inset
17812
17813
17814 \newline
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 _asm
17820 \newline
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 0003$: ;label (can be referenced by inline assembler only) 
17826 \newline
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 _endasm
17832 \begin_inset LatexCommand \index{\_endasm}
17833
17834 \end_inset
17835
17836
17837 \begin_inset LatexCommand \index{\_\_endasm}
17838
17839 \end_inset
17840
17841  ; 
17842 \newline
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 /* some more c code */
17848 \newline
17849 }
17850 \end_layout
17851
17852 \begin_layout Standard
17853 In other words inline assembly code can access labels defined in inline
17854  assembly within the scope of the function.
17855  The same goes the other way, i.e.
17856  labels defines in inline assembly can not be accessed by C statements.
17857 \end_layout
17858
17859 \begin_layout Section
17860 Interfacing with Assembler Code
17861 \begin_inset LatexCommand \index{Assembler routines}
17862
17863 \end_inset
17864
17865
17866 \end_layout
17867
17868 \begin_layout Subsection
17869 Global Registers used for Parameter Passing
17870 \begin_inset LatexCommand \index{Parameter passing}
17871
17872 \end_inset
17873
17874
17875 \end_layout
17876
17877 \begin_layout Standard
17878 The compiler always uses the global registers 
17879 \emph on
17880 DPL, DPH
17881 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17882
17883 \end_inset
17884
17885
17886 \begin_inset LatexCommand \index{DPTR}
17887
17888 \end_inset
17889
17890 , B
17891 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17892
17893 \end_inset
17894
17895  
17896 \emph default
17897 and
17898 \emph on
17899  ACC
17900 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17901
17902 \end_inset
17903
17904
17905 \emph default
17906  to pass the first (non-bit) parameter to a function, and also to pass the
17907  return value 
17908 \begin_inset LatexCommand \index{return value}
17909
17910 \end_inset
17911
17912 of function; according to the following scheme: one byte return value in
17913  
17914 \emph on
17915 DPL
17916 \emph default
17917 , two byte value in 
17918 \emph on
17919 DPL
17920 \emph default
17921  (LSB) and 
17922 \emph on
17923 DPH
17924 \emph default
17925  (MSB).
17926  three byte values (generic pointers) in 
17927 \emph on
17928 DPH
17929 \emph default
17930
17931 \emph on
17932 DPL
17933 \emph default
17934  and 
17935 \emph on
17936 B
17937 \emph default
17938 , and four byte values in 
17939 \emph on
17940 DPH
17941 \emph default
17942
17943 \emph on
17944 DPL
17945 \emph default
17946 ,
17947 \emph on
17948  B
17949 \emph default
17950  and 
17951 \emph on
17952 ACC
17953 \emph default
17954 .
17955  Generic pointers
17956 \begin_inset LatexCommand \index{generic pointer}
17957
17958 \end_inset
17959
17960  contain type of accessed memory in 
17961 \emph on
17962 B
17963 \emph default
17964
17965 \series bold
17966 0x00
17967 \series default
17968  -- xdata/far, 
17969 \series bold
17970 0x40
17971 \series default
17972  -- idata/near -- , 
17973 \series bold
17974 0x60
17975 \series default
17976  -- pdata, 
17977 \series bold
17978 0x80
17979 \series default
17980  -- code
17981 \begin_inset Note Note
17982 status collapsed
17983
17984 \begin_layout Standard
17985 This might not be the case of certain memory models (medium???)
17986 \end_layout
17987
17988 \end_inset
17989
17990 .
17991 \end_layout
17992
17993 \begin_layout Standard
17994 The second parameter onwards is either allocated on the stack (for reentrant
17995  routines or if -
17996 \begin_inset ERT
17997 status collapsed
17998
17999 \begin_layout Standard
18000
18001
18002 \backslash
18003 /
18004 \end_layout
18005
18006 \end_inset
18007
18008 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18009 \end_layout
18010
18011 \begin_layout Standard
18012 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18013  space for reentrant functions or allocated directly in bit memory otherwise.
18014 \end_layout
18015
18016 \begin_layout Standard
18017 Functions (with two or more parameters or bit parameters) that are called
18018  through function pointers
18019 \begin_inset LatexCommand \index{function pointers}
18020
18021 \end_inset
18022
18023  must therefor be reentrant so the compiler knows how to pass the parameters.
18024 \end_layout
18025
18026 \begin_layout Subsection
18027 Registers usage
18028 \end_layout
18029
18030 \begin_layout Standard
18031 Unless the called function is declared as 
18032 \family typewriter
18033 _naked
18034 \family default
18035
18036 \begin_inset LatexCommand \index{naked}
18037
18038 \end_inset
18039
18040 , or the -
18041 \begin_inset ERT
18042 status collapsed
18043
18044 \begin_layout Standard
18045
18046
18047 \backslash
18048 /
18049 \end_layout
18050
18051 \end_inset
18052
18053 -callee-saves
18054 \begin_inset LatexCommand \index{-\/-callee-saves}
18055
18056 \end_inset
18057
18058 /-
18059 \begin_inset ERT
18060 status collapsed
18061
18062 \begin_layout Standard
18063
18064
18065 \backslash
18066 /
18067 \end_layout
18068
18069 \end_inset
18070
18071 -all-callee-saves command line option or the corresponding callee_saves
18072  pragma are used, the caller will save the registers (
18073 \emph on
18074 R0-R7
18075 \emph default
18076 ) around the call, so the called function can destroy they content freely.
18077 \end_layout
18078
18079 \begin_layout Standard
18080 If the called function is not declared as 
18081 \family typewriter
18082 _naked
18083 \family default
18084 , the caller will swap register banks around the call, if caller and callee
18085  use different register banks (having them defined by the 
18086 \family typewriter
18087 _using
18088 \family default
18089  modifier).
18090  
18091 \end_layout
18092
18093 \begin_layout Standard
18094 The called function can also use 
18095 \emph on
18096 DPL
18097 \emph default
18098
18099 \emph on
18100 DPH
18101 \emph default
18102
18103 \emph on
18104 B
18105 \emph default
18106  and 
18107 \emph on
18108 ACC
18109 \emph default
18110  observing that they are used for parameter/return value passing.
18111 \end_layout
18112
18113 \begin_layout Subsection
18114 Assembler Routine (non-reentrant)
18115 \end_layout
18116
18117 \begin_layout Standard
18118 In the following example
18119 \begin_inset LatexCommand \index{reentrant}
18120
18121 \end_inset
18122
18123
18124 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18125
18126 \end_inset
18127
18128  the function c_func calls an assembler routine asm_func, which takes two
18129  parameters
18130 \begin_inset LatexCommand \index{function parameter}
18131
18132 \end_inset
18133
18134 .
18135 \end_layout
18136
18137 \begin_layout Verse
18138
18139 \family typewriter
18140 extern int asm_func(unsigned char, unsigned char);
18141 \newline
18142
18143 \newline
18144 int c_func (unsigned char
18145  i, unsigned char j)
18146 \newline
18147 {
18148 \newline
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 return asm_func(i,j);
18154 \newline
18155 }
18156 \newline
18157
18158 \newline
18159 int main()
18160 \newline
18161 {
18162 \newline
18163 \InsetSpace ~
18164 \InsetSpace ~
18165 \InsetSpace ~
18166 \InsetSpace ~
18167 return c_func(10,9);
18168 \newline
18169 }
18170 \end_layout
18171
18172 \begin_layout Standard
18173 The corresponding assembler function is:
18174 \end_layout
18175
18176 \begin_layout Verse
18177
18178 \family typewriter
18179 .globl _asm_func_PARM_2 
18180 \newline
18181 \InsetSpace ~
18182 \InsetSpace ~
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 .globl _asm_func 
18190 \newline
18191 \InsetSpace ~
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 \InsetSpace ~
18199 .area OSEG 
18200 \newline
18201 _asm_func_PARM_2:
18202 \newline
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 \InsetSpace ~
18211 .ds   
18212  1 
18213 \newline
18214 \InsetSpace ~
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 .area CSEG 
18223 \newline
18224 _asm_func: 
18225 \newline
18226 \InsetSpace ~
18227 \InsetSpace ~
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 mov\InsetSpace ~
18235 \InsetSpace ~
18236 \InsetSpace ~
18237 \InsetSpace ~
18238 a,dpl 
18239 \newline
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 \InsetSpace ~
18245 \InsetSpace ~
18246 \InsetSpace ~
18247 \InsetSpace ~
18248 add\InsetSpace ~
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 a,_asm_func_PARM_2 
18253 \newline
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 \InsetSpace ~
18257 \InsetSpace ~
18258 \InsetSpace ~
18259 \InsetSpace ~
18260 \InsetSpace ~
18261 \InsetSpace ~
18262 mov\InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 dpl,a 
18267 \newline
18268 \InsetSpace ~
18269 \InsetSpace ~
18270 \InsetSpace ~
18271 \InsetSpace ~
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 mov\InsetSpace ~
18277 \InsetSpace ~
18278 \InsetSpace ~
18279 \InsetSpace ~
18280 dph
18281 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18282
18283 \end_inset
18284
18285 ,#0x00 
18286 \newline
18287 \InsetSpace ~
18288 \InsetSpace ~
18289 \InsetSpace ~
18290 \InsetSpace ~
18291 \InsetSpace ~
18292 \InsetSpace ~
18293 \InsetSpace ~
18294 \InsetSpace ~
18295 ret
18296 \end_layout
18297
18298 \begin_layout Standard
18299 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18300  the parameter number starting from 1, and counting from the left.
18301  The first parameter is passed in 
18302 \emph on
18303 DPH
18304 \emph default
18305
18306 \emph on
18307 DPL
18308 \emph default
18309
18310 \emph on
18311 B
18312 \emph default
18313  and 
18314 \emph on
18315 ACC
18316 \emph default
18317  according to the description above.
18318  The variable name for the second parameter will be _<function_name>_PARM_2.
18319 \newline
18320
18321 \newline
18322 Assem
18323 ble the assembler routine with the following command:
18324 \newline
18325
18326 \newline
18327
18328 \family sans
18329 \series bold
18330 asx8051 -losg asmfunc.asm
18331 \newline
18332
18333 \newline
18334
18335 \family default
18336 \series default
18337 Then compile and link the assembler routine to the C source file with the
18338  following command:
18339 \newline
18340
18341 \newline
18342
18343 \family sans
18344 \series bold
18345 sdcc cfunc.c asmfunc.rel
18346 \end_layout
18347
18348 \begin_layout Subsection
18349 Assembler Routine (reentrant)
18350 \end_layout
18351
18352 \begin_layout Standard
18353 In this case
18354 \begin_inset LatexCommand \index{reentrant}
18355
18356 \end_inset
18357
18358
18359 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18360
18361 \end_inset
18362
18363  the second parameter
18364 \begin_inset LatexCommand \index{function parameter}
18365
18366 \end_inset
18367
18368  onwards will be passed on the stack, the parameters are pushed from right
18369  to left i.e.
18370  before the call the second leftmost parameter will be on the top of the
18371  stack (the leftmost parameter is passed in registers).
18372  Here is an example:
18373 \end_layout
18374
18375 \begin_layout Verse
18376
18377 \family typewriter
18378 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18379 \newline
18380
18381 \newline
18382 int
18383  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18384 \newline
18385 {
18386  
18387 \newline
18388 \InsetSpace ~
18389 \InsetSpace ~
18390 \InsetSpace ~
18391 \InsetSpace ~
18392 return asm_func(i,j,k); 
18393 \newline
18394
18395 \newline
18396
18397 \newline
18398 int main() 
18399 \newline
18400
18401 \newline
18402 \InsetSpace ~
18403 \InsetSpace ~
18404 \InsetSpace ~
18405 \InsetSpace ~
18406 return c_func(10,9,8); 
18407 \newline
18408 }
18409 \end_layout
18410
18411 \begin_layout Standard
18412 The corresponding (unoptimized) assembler routine is:
18413 \end_layout
18414
18415 \begin_layout Verse
18416
18417 \family typewriter
18418 .globl _asm_func 
18419 \newline
18420 _asm_func: 
18421 \newline
18422 \InsetSpace ~
18423 \InsetSpace ~
18424 \InsetSpace ~
18425 \InsetSpace ~
18426 push\InsetSpace ~
18427 _bp 
18428 \newline
18429 \InsetSpace ~
18430 \InsetSpace ~
18431 \InsetSpace ~
18432 \InsetSpace ~
18433 mov\InsetSpace ~
18434 \InsetSpace ~
18435 _bp,sp\InsetSpace ~
18436 \InsetSpace ~
18437 \InsetSpace ~
18438 \InsetSpace ~
18439 \InsetSpace ~
18440 \InsetSpace ~
18441 ;stack contains: _bp, return
18442  address, second parameter, third parameter
18443 \newline
18444 \InsetSpace ~
18445 \InsetSpace ~
18446 \InsetSpace ~
18447 \InsetSpace ~
18448 mov\InsetSpace ~
18449 \InsetSpace ~
18450 r2,dpl
18451 \newline
18452 \InsetSpace ~
18453 \InsetSpace ~
18454 \InsetSpace ~
18455 \InsetSpace ~
18456 mov\InsetSpace ~
18457 \InsetSpace ~
18458 a,_bp
18459 \newline
18460 \InsetSpace ~
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 add\InsetSpace ~
18465 \InsetSpace ~
18466 a,#0xfd\InsetSpace ~
18467 \InsetSpace ~
18468 \InsetSpace ~
18469 \InsetSpace ~
18470 \InsetSpace ~
18471 ;calculate
18472  pointer to the second parameter
18473 \newline
18474 \InsetSpace ~
18475 \InsetSpace ~
18476 \InsetSpace ~
18477 \InsetSpace ~
18478 mov\InsetSpace ~
18479 \InsetSpace ~
18480 r0,a 
18481 \newline
18482 \InsetSpace ~
18483 \InsetSpace ~
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 mov\InsetSpace ~
18487 \InsetSpace ~
18488 a,_bp 
18489 \newline
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 add\InsetSpace ~
18495 \InsetSpace ~
18496 a,#0xfc\InsetSpace ~
18497 \InsetSpace ~
18498 \InsetSpace ~
18499 \InsetSpace ~
18500 \InsetSpace ~
18501 ;calculate pointer
18502  to the rightmost parameter
18503 \newline
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 mov\InsetSpace ~
18509 \InsetSpace ~
18510 r1,a 
18511 \newline
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 mov\InsetSpace ~
18517 \InsetSpace ~
18518 a,@r0
18519 \newline
18520 \InsetSpace ~
18521 \InsetSpace ~
18522 \InsetSpace ~
18523 \InsetSpace ~
18524 add\InsetSpace ~
18525 \InsetSpace ~
18526 a,@r1
18527 \newline
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 add\InsetSpace ~
18533 \InsetSpace ~
18534 a,r2\InsetSpace ~
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 ;calculate the
18543  result (= sum of all three parameters)
18544 \newline
18545 \InsetSpace ~
18546 \InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 mov\InsetSpace ~
18550 \InsetSpace ~
18551 dpl,a\InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 ;return value goes into dptr
18559  (cast into int)
18560 \newline
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 mov\InsetSpace ~
18566 \InsetSpace ~
18567 dph,#0x00 
18568 \newline
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 mov\InsetSpace ~
18574 \InsetSpace ~
18575 sp,_bp 
18576 \newline
18577 \InsetSpace ~
18578 \InsetSpace ~
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 pop\InsetSpace ~
18582 \InsetSpace ~
18583 _bp 
18584 \newline
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 ret
18590 \end_layout
18591
18592 \begin_layout Standard
18593 The compiling and linking procedure remains the same, however note the extra
18594  entry & exit linkage required for the assembler code, _bp is the stack
18595  frame pointer and is used to compute the offset into the stack for parameters
18596  and local variables.
18597 \begin_inset VSpace bigskip
18598 \end_inset
18599
18600
18601 \end_layout
18602
18603 \begin_layout Section
18604 int (16 bit)
18605 \begin_inset LatexCommand \index{int (16 bit)}
18606
18607 \end_inset
18608
18609  and long (32 bit)
18610 \begin_inset LatexCommand \index{long (32 bit)}
18611
18612 \end_inset
18613
18614  Support
18615 \end_layout
18616
18617 \begin_layout Standard
18618 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18619  multiplication and modulus operations are implemented by support routines.
18620  These support routines are all developed in ANSI-C to facilitate porting
18621  to other MCUs, although some model specific assembler optimizations are
18622  used.
18623  The following files contain the described routines, all of them can be
18624  found in <installdir>/share/sdcc/lib.
18625 \newline
18626
18627 \end_layout
18628
18629 \begin_layout Standard
18630 \align center
18631 \begin_inset Tabular
18632 <lyxtabular version="3" rows="11" columns="2">
18633 <features>
18634 <column alignment="left" valignment="top" leftline="true" width="0">
18635 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18636 <row topline="true" bottomline="true">
18637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18638 \begin_inset Text
18639
18640 \begin_layout Standard
18641
18642 \series bold
18643 Function
18644 \end_layout
18645
18646 \end_inset
18647 </cell>
18648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18649 \begin_inset Text
18650
18651 \begin_layout Standard
18652
18653 \series bold
18654 Description
18655 \end_layout
18656
18657 \end_inset
18658 </cell>
18659 </row>
18660 <row topline="true">
18661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18662 \begin_inset Text
18663
18664 \begin_layout Standard
18665 _mulint.c 
18666 \end_layout
18667
18668 \end_inset
18669 </cell>
18670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18671 \begin_inset Text
18672
18673 \begin_layout Standard
18674 16 bit multiplication
18675 \end_layout
18676
18677 \end_inset
18678 </cell>
18679 </row>
18680 <row topline="true">
18681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18682 \begin_inset Text
18683
18684 \begin_layout Standard
18685 _divsint.c 
18686 \end_layout
18687
18688 \end_inset
18689 </cell>
18690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18691 \begin_inset Text
18692
18693 \begin_layout Standard
18694  signed 16 bit division (calls _divuint)
18695 \end_layout
18696
18697 \end_inset
18698 </cell>
18699 </row>
18700 <row topline="true">
18701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18702 \begin_inset Text
18703
18704 \begin_layout Standard
18705 _divuint.c 
18706 \end_layout
18707
18708 \end_inset
18709 </cell>
18710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18711 \begin_inset Text
18712
18713 \begin_layout Standard
18714  unsigned 16 bit division
18715 \end_layout
18716
18717 \end_inset
18718 </cell>
18719 </row>
18720 <row topline="true">
18721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18722 \begin_inset Text
18723
18724 \begin_layout Standard
18725 _modsint.c
18726 \end_layout
18727
18728 \end_inset
18729 </cell>
18730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18731 \begin_inset Text
18732
18733 \begin_layout Standard
18734 signed 16 bit modulus (calls _moduint)
18735 \end_layout
18736
18737 \end_inset
18738 </cell>
18739 </row>
18740 <row topline="true">
18741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18742 \begin_inset Text
18743
18744 \begin_layout Standard
18745 _moduint.c
18746 \end_layout
18747
18748 \end_inset
18749 </cell>
18750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18751 \begin_inset Text
18752
18753 \begin_layout Standard
18754 unsigned 16 bit modulus
18755 \end_layout
18756
18757 \end_inset
18758 </cell>
18759 </row>
18760 <row topline="true">
18761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18762 \begin_inset Text
18763
18764 \begin_layout Standard
18765 _mullong.c
18766 \end_layout
18767
18768 \end_inset
18769 </cell>
18770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18771 \begin_inset Text
18772
18773 \begin_layout Standard
18774 32 bit multiplication
18775 \end_layout
18776
18777 \end_inset
18778 </cell>
18779 </row>
18780 <row topline="true">
18781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18782 \begin_inset Text
18783
18784 \begin_layout Standard
18785 _divslong.c 
18786 \end_layout
18787
18788 \end_inset
18789 </cell>
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18791 \begin_inset Text
18792
18793 \begin_layout Standard
18794  signed 32 division (calls _divulong)
18795 \end_layout
18796
18797 \end_inset
18798 </cell>
18799 </row>
18800 <row topline="true">
18801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18802 \begin_inset Text
18803
18804 \begin_layout Standard
18805 _divulong.c 
18806 \end_layout
18807
18808 \end_inset
18809 </cell>
18810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18811 \begin_inset Text
18812
18813 \begin_layout Standard
18814 unsigned 32 division
18815 \end_layout
18816
18817 \end_inset
18818 </cell>
18819 </row>
18820 <row topline="true">
18821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18822 \begin_inset Text
18823
18824 \begin_layout Standard
18825 _modslong.c
18826 \end_layout
18827
18828 \end_inset
18829 </cell>
18830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18831 \begin_inset Text
18832
18833 \begin_layout Standard
18834  signed 32 bit modulus (calls _modulong)
18835 \end_layout
18836
18837 \end_inset
18838 </cell>
18839 </row>
18840 <row topline="true" bottomline="true">
18841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18842 \begin_inset Text
18843
18844 \begin_layout Standard
18845 _modulong.c
18846 \end_layout
18847
18848 \end_inset
18849 </cell>
18850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18851 \begin_inset Text
18852
18853 \begin_layout Standard
18854 unsigned 32 bit modulus
18855 \end_layout
18856
18857 \end_inset
18858 </cell>
18859 </row>
18860 </lyxtabular>
18861
18862 \end_inset
18863
18864
18865 \newline
18866
18867 \end_layout
18868
18869 \begin_layout Standard
18870 Since they are compiled as 
18871 \emph on
18872 non-reentrant
18873 \emph default
18874
18875 \begin_inset LatexCommand \index{reentrant}
18876
18877 \end_inset
18878
18879 , interrupt
18880 \begin_inset LatexCommand \index{interrupt}
18881
18882 \end_inset
18883
18884  service routines should not do any of the above operations.
18885  If this is unavoidable then the above routines will need to be compiled
18886  with the 
18887 \emph on
18888 -
18889 \begin_inset ERT
18890 status collapsed
18891
18892 \begin_layout Standard
18893
18894
18895 \backslash
18896 /
18897 \end_layout
18898
18899 \end_inset
18900
18901 -stack-auto
18902 \begin_inset LatexCommand \index{-\/-stack-auto}
18903
18904 \end_inset
18905
18906
18907 \emph default
18908  option, after which the source program will have to be compiled with 
18909 \emph on
18910 -
18911 \begin_inset ERT
18912 status collapsed
18913
18914 \begin_layout Standard
18915
18916
18917 \backslash
18918 /
18919 \end_layout
18920
18921 \end_inset
18922
18923 -int-long-reent
18924 \begin_inset LatexCommand \index{-\/-int-long-reent}
18925
18926 \end_inset
18927
18928
18929 \emph default
18930  option.
18931  Notice that you don't have to call these routines directly.
18932  The compiler will use them automatically every time an integer operation
18933  is required.
18934 \end_layout
18935
18936 \begin_layout Section
18937 Floating Point Support
18938 \begin_inset LatexCommand \index{Floating point support}
18939
18940 \end_inset
18941
18942
18943 \end_layout
18944
18945 \begin_layout Standard
18946 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18947  The floating point support routines are derived from gcc's floatlib.c and
18948  consist of the following routines:
18949 \newline
18950
18951 \end_layout
18952
18953 \begin_layout Standard
18954 \align center
18955
18956 \size footnotesize
18957 \begin_inset Tabular
18958 <lyxtabular version="3" rows="17" columns="2">
18959 <features>
18960 <column alignment="left" valignment="top" leftline="true" width="0">
18961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18962 <row topline="true" bottomline="true">
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18964 \begin_inset Text
18965
18966 \begin_layout Standard
18967
18968 \family roman
18969 \series medium
18970 \shape up
18971 \size normal
18972 \emph off
18973 \bar no
18974 \noun off
18975 \color none
18976 Function 
18977 \end_layout
18978
18979 \end_inset
18980 </cell>
18981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18982 \begin_inset Text
18983
18984 \begin_layout Standard
18985 Description
18986 \end_layout
18987
18988 \end_inset
18989 </cell>
18990 </row>
18991 <row topline="true">
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \begin_layout Standard
18996
18997 \family roman
18998 \series medium
18999 \shape up
19000 \size normal
19001 \emph off
19002 \bar no
19003 \noun off
19004 \color none
19005 _fsadd.c
19006 \end_layout
19007
19008 \end_inset
19009 </cell>
19010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19011 \begin_inset Text
19012
19013 \begin_layout Standard
19014
19015 \family roman
19016 \series medium
19017 \shape up
19018 \size normal
19019 \emph off
19020 \bar no
19021 \noun off
19022 \color none
19023 add floating point numbers
19024 \end_layout
19025
19026 \end_inset
19027 </cell>
19028 </row>
19029 <row topline="true">
19030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19031 \begin_inset Text
19032
19033 \begin_layout Standard
19034
19035 \family roman
19036 \series medium
19037 \shape up
19038 \size normal
19039 \emph off
19040 \bar no
19041 \noun off
19042 \color none
19043 _fssub.c 
19044 \end_layout
19045
19046 \end_inset
19047 </cell>
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \begin_layout Standard
19052
19053 \family roman
19054 \series medium
19055 \shape up
19056 \size normal
19057 \emph off
19058 \bar no
19059 \noun off
19060 \color none
19061 subtract floating point numbers 
19062 \end_layout
19063
19064 \end_inset
19065 </cell>
19066 </row>
19067 <row topline="true">
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \begin_layout Standard
19072
19073 \family roman
19074 \series medium
19075 \shape up
19076 \size normal
19077 \emph off
19078 \bar no
19079 \noun off
19080 \color none
19081 _fsdiv.c 
19082 \end_layout
19083
19084 \end_inset
19085 </cell>
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19087 \begin_inset Text
19088
19089 \begin_layout Standard
19090
19091 \family roman
19092 \series medium
19093 \shape up
19094 \size normal
19095 \emph off
19096 \bar no
19097 \noun off
19098 \color none
19099 divide floating point numbers 
19100 \end_layout
19101
19102 \end_inset
19103 </cell>
19104 </row>
19105 <row topline="true">
19106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19107 \begin_inset Text
19108
19109 \begin_layout Standard
19110
19111 \family roman
19112 \series medium
19113 \shape up
19114 \size normal
19115 \emph off
19116 \bar no
19117 \noun off
19118 \color none
19119 _fsmul.c 
19120 \end_layout
19121
19122 \end_inset
19123 </cell>
19124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19125 \begin_inset Text
19126
19127 \begin_layout Standard
19128
19129 \family roman
19130 \series medium
19131 \shape up
19132 \size normal
19133 \emph off
19134 \bar no
19135 \noun off
19136 \color none
19137 multiply floating point numbers 
19138 \end_layout
19139
19140 \end_inset
19141 </cell>
19142 </row>
19143 <row topline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19145 \begin_inset Text
19146
19147 \begin_layout Standard
19148
19149 \family roman
19150 \series medium
19151 \shape up
19152 \size normal
19153 \emph off
19154 \bar no
19155 \noun off
19156 \color none
19157 _fs2uchar.c
19158 \end_layout
19159
19160 \end_inset
19161 </cell>
19162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19163 \begin_inset Text
19164
19165 \begin_layout Standard
19166
19167 \family roman
19168 \series medium
19169 \shape up
19170 \size normal
19171 \emph off
19172 \bar no
19173 \noun off
19174 \color none
19175 convert floating point to unsigned char
19176 \end_layout
19177
19178 \end_inset
19179 </cell>
19180 </row>
19181 <row topline="true">
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19183 \begin_inset Text
19184
19185 \begin_layout Standard
19186
19187 \family roman
19188 \series medium
19189 \shape up
19190 \size normal
19191 \emph off
19192 \bar no
19193 \noun off
19194 \color none
19195 _fs2char.c
19196 \end_layout
19197
19198 \end_inset
19199 </cell>
19200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19201 \begin_inset Text
19202
19203 \begin_layout Standard
19204
19205 \family roman
19206 \series medium
19207 \shape up
19208 \size normal
19209 \emph off
19210 \bar no
19211 \noun off
19212 \color none
19213 convert floating point to signed char
19214 \end_layout
19215
19216 \end_inset
19217 </cell>
19218 </row>
19219 <row topline="true">
19220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19221 \begin_inset Text
19222
19223 \begin_layout Standard
19224
19225 \family roman
19226 \series medium
19227 \shape up
19228 \size normal
19229 \emph off
19230 \bar no
19231 \noun off
19232 \color none
19233 _fs2uint.c
19234 \end_layout
19235
19236 \end_inset
19237 </cell>
19238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19239 \begin_inset Text
19240
19241 \begin_layout Standard
19242
19243 \family roman
19244 \series medium
19245 \shape up
19246 \size normal
19247 \emph off
19248 \bar no
19249 \noun off
19250 \color none
19251 convert floating point to unsigned int
19252 \end_layout
19253
19254 \end_inset
19255 </cell>
19256 </row>
19257 <row topline="true">
19258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19259 \begin_inset Text
19260
19261 \begin_layout Standard
19262
19263 \family roman
19264 \series medium
19265 \shape up
19266 \size normal
19267 \emph off
19268 \bar no
19269 \noun off
19270 \color none
19271 _fs2int.c
19272 \end_layout
19273
19274 \end_inset
19275 </cell>
19276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19277 \begin_inset Text
19278
19279 \begin_layout Standard
19280
19281 \family roman
19282 \series medium
19283 \shape up
19284 \size normal
19285 \emph off
19286 \bar no
19287 \noun off
19288 \color none
19289 convert floating point to signed int
19290 \end_layout
19291
19292 \end_inset
19293 </cell>
19294 </row>
19295 <row topline="true">
19296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19297 \begin_inset Text
19298
19299 \begin_layout Standard
19300
19301 \family roman
19302 \series medium
19303 \shape up
19304 \size normal
19305 \emph off
19306 \bar no
19307 \noun off
19308 \color none
19309 _fs2ulong.
19310 \family default
19311 \series default
19312 \shape default
19313 \size default
19314 \emph default
19315 \bar default
19316 \noun default
19317 c
19318 \end_layout
19319
19320 \end_inset
19321 </cell>
19322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19323 \begin_inset Text
19324
19325 \begin_layout Standard
19326
19327 \family roman
19328 \series medium
19329 \shape up
19330 \size normal
19331 \emph off
19332 \bar no
19333 \noun off
19334 \color none
19335 convert floating point to unsigned long
19336 \end_layout
19337
19338 \end_inset
19339 </cell>
19340 </row>
19341 <row topline="true">
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19343 \begin_inset Text
19344
19345 \begin_layout Standard
19346
19347 \family roman
19348 \series medium
19349 \shape up
19350 \size normal
19351 \emph off
19352 \bar no
19353 \noun off
19354 \color none
19355 _fs2long.c
19356 \end_layout
19357
19358 \end_inset
19359 </cell>
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19361 \begin_inset Text
19362
19363 \begin_layout Standard
19364
19365 \family roman
19366 \series medium
19367 \shape up
19368 \size normal
19369 \emph off
19370 \bar no
19371 \noun off
19372 \color none
19373 convert floating point to signed long
19374 \end_layout
19375
19376 \end_inset
19377 </cell>
19378 </row>
19379 <row topline="true">
19380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19381 \begin_inset Text
19382
19383 \begin_layout Standard
19384
19385 \family roman
19386 \series medium
19387 \shape up
19388 \size normal
19389 \emph off
19390 \bar no
19391 \noun off
19392 \color none
19393 _uchar2fs.c
19394 \end_layout
19395
19396 \end_inset
19397 </cell>
19398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19399 \begin_inset Text
19400
19401 \begin_layout Standard
19402
19403 \family roman
19404 \series medium
19405 \shape up
19406 \size normal
19407 \emph off
19408 \bar no
19409 \noun off
19410 \color none
19411 convert unsigned char to floating point
19412 \end_layout
19413
19414 \end_inset
19415 </cell>
19416 </row>
19417 <row topline="true">
19418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19419 \begin_inset Text
19420
19421 \begin_layout Standard
19422
19423 \family roman
19424 \series medium
19425 \shape up
19426 \size normal
19427 \emph off
19428 \bar no
19429 \noun off
19430 \color none
19431 _char2fs.c
19432 \end_layout
19433
19434 \end_inset
19435 </cell>
19436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19437 \begin_inset Text
19438
19439 \begin_layout Standard
19440
19441 \family roman
19442 \series medium
19443 \shape up
19444 \size normal
19445 \emph off
19446 \bar no
19447 \noun off
19448 \color none
19449 convert char to floating point number
19450 \end_layout
19451
19452 \end_inset
19453 </cell>
19454 </row>
19455 <row topline="true">
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19457 \begin_inset Text
19458
19459 \begin_layout Standard
19460
19461 \family roman
19462 \series medium
19463 \shape up
19464 \size normal
19465 \emph off
19466 \bar no
19467 \noun off
19468 \color none
19469 _uint2fs.c
19470 \end_layout
19471
19472 \end_inset
19473 </cell>
19474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19475 \begin_inset Text
19476
19477 \begin_layout Standard
19478
19479 \family roman
19480 \series medium
19481 \shape up
19482 \size normal
19483 \emph off
19484 \bar no
19485 \noun off
19486 \color none
19487 convert unsigned int to floating point
19488 \end_layout
19489
19490 \end_inset
19491 </cell>
19492 </row>
19493 <row topline="true">
19494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19495 \begin_inset Text
19496
19497 \begin_layout Standard
19498
19499 \family roman
19500 \series medium
19501 \shape up
19502 \size normal
19503 \emph off
19504 \bar no
19505 \noun off
19506 \color none
19507 _int2fs.c
19508 \end_layout
19509
19510 \end_inset
19511 </cell>
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19513 \begin_inset Text
19514
19515 \begin_layout Standard
19516
19517 \family roman
19518 \series medium
19519 \shape up
19520 \size normal
19521 \emph off
19522 \bar no
19523 \noun off
19524 \color none
19525 convert int to floating point numbers
19526 \end_layout
19527
19528 \end_inset
19529 </cell>
19530 </row>
19531 <row topline="true">
19532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19533 \begin_inset Text
19534
19535 \begin_layout Standard
19536
19537 \family roman
19538 \series medium
19539 \shape up
19540 \size normal
19541 \emph off
19542 \bar no
19543 \noun off
19544 \color none
19545 _ulong2fs.c
19546 \end_layout
19547
19548 \end_inset
19549 </cell>
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19551 \begin_inset Text
19552
19553 \begin_layout Standard
19554
19555 \family roman
19556 \series medium
19557 \shape up
19558 \size normal
19559 \emph off
19560 \bar no
19561 \noun off
19562 \color none
19563 convert unsigned long to floating point number
19564 \end_layout
19565
19566 \end_inset
19567 </cell>
19568 </row>
19569 <row topline="true" bottomline="true">
19570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19571 \begin_inset Text
19572
19573 \begin_layout Standard
19574
19575 \family roman
19576 \series medium
19577 \shape up
19578 \size normal
19579 \emph off
19580 \bar no
19581 \noun off
19582 \color none
19583 _long2fs.c
19584 \end_layout
19585
19586 \end_inset
19587 </cell>
19588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19589 \begin_inset Text
19590
19591 \begin_layout Standard
19592
19593 \family roman
19594 \series medium
19595 \shape up
19596 \size normal
19597 \emph off
19598 \bar no
19599 \noun off
19600 \color none
19601 convert long to floating point number
19602 \end_layout
19603
19604 \end_inset
19605 </cell>
19606 </row>
19607 </lyxtabular>
19608
19609 \end_inset
19610
19611
19612 \newline
19613
19614 \end_layout
19615
19616 \begin_layout Standard
19617 These support routines are developed in ANSI-C so there is room for space
19618  and speed improvement
19619 \begin_inset Foot
19620 status open
19621
19622 \begin_layout Standard
19623 These floating point routines (
19624 \emph on
19625 not
19626 \emph default
19627  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19628  
19629 \end_layout
19630
19631 \end_inset
19632
19633 .
19634  Note if all these routines are used simultaneously the data space might
19635  overflow.
19636  For serious floating point usage the large model might be needed.
19637  Also notice that you don't have to call this routines directly.
19638  The compiler will use them automatically every time a floating point operation
19639  is required.
19640 \begin_inset VSpace bigskip
19641 \end_inset
19642
19643
19644 \end_layout
19645
19646 \begin_layout Section
19647 Library Routines
19648 \begin_inset LatexCommand \index{Libraries}
19649
19650 \end_inset
19651
19652
19653 \end_layout
19654
19655 \begin_layout Standard
19656
19657 \emph on
19658 <pending: this is messy and incomplete - a little more information is in
19659  sdcc/doc/libdoc.txt
19660 \emph default
19661  >
19662 \end_layout
19663
19664 \begin_layout Subsection
19665 Compiler support routines (_gptrget, _mulint etc.)
19666 \end_layout
19667
19668 \begin_layout Subsection
19669 Stdclib functions (puts, printf, strcat etc.)
19670 \end_layout
19671
19672 \begin_layout Subsubsection
19673 <stdio.h>
19674 \end_layout
19675
19676 \begin_layout Paragraph
19677 getchar(), putchar()
19678 \end_layout
19679
19680 \begin_layout Standard
19681 \begin_inset LatexCommand \index{<stdio.h>}
19682
19683 \end_inset
19684
19685 As usual on embedded systems you have to provide your own 
19686 \family typewriter
19687 getchar()
19688 \begin_inset LatexCommand \index{getchar()}
19689
19690 \end_inset
19691
19692  
19693 \family default
19694 and 
19695 \family typewriter
19696 putchar()
19697 \begin_inset LatexCommand \index{putchar()}
19698
19699 \end_inset
19700
19701
19702 \family default
19703  routines.
19704  SDCC does not know whether the system connects to a serial line with or
19705  without handshake, LCD, keyboard or other device.
19706  And whether a 
19707 \family typewriter
19708 lf
19709 \family default
19710  to 
19711 \family typewriter
19712 crlf
19713 \family default
19714  conversion within 
19715 \family typewriter
19716 putchar()
19717 \family default
19718  is intended.
19719  You'll find examples for serial routines f.e.
19720  in sdcc/device/lib.
19721  For the mcs51 this minimalistic polling 
19722 \family typewriter
19723 putchar()
19724 \family default
19725  routine might be a start:
19726 \end_layout
19727
19728 \begin_layout Verse
19729
19730 \family typewriter
19731 void putchar (char c) { 
19732 \newline
19733 \InsetSpace ~
19734 \InsetSpace ~
19735 \InsetSpace ~
19736 \InsetSpace ~
19737 while (!TI)\InsetSpace ~
19738 \InsetSpace ~
19739 \InsetSpace ~
19740  /* assumes UART is initialized */
19741 \newline
19742 \InsetSpace ~
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 \InsetSpace ~
19747 \InsetSpace ~
19748 \InsetSpace ~
19749 \InsetSpace ~
19750 ;
19751 \newline
19752 \InsetSpace ~
19753 \InsetSpace ~
19754 \InsetSpace ~
19755 \InsetSpace ~
19756 TI
19757  = 0;
19758 \newline
19759 \InsetSpace ~
19760 \InsetSpace ~
19761 \InsetSpace ~
19762 \InsetSpace ~
19763 SBUF = c;
19764 \newline
19765 }
19766 \end_layout
19767
19768 \begin_layout Paragraph
19769 printf()
19770 \end_layout
19771
19772 \begin_layout Standard
19773 The default
19774 \family typewriter
19775  printf()
19776 \begin_inset LatexCommand \index{printf()}
19777
19778 \end_inset
19779
19780
19781 \family default
19782  implementation in
19783 \family typewriter
19784  printf_large.c
19785 \family default
19786  does not support float (except on ds390).
19787  To enable this recompile it with the option 
19788 \emph on
19789 -
19790 \begin_inset ERT
19791 status collapsed
19792
19793 \begin_layout Standard
19794
19795
19796 \backslash
19797 /
19798 \end_layout
19799
19800 \end_inset
19801
19802 DUSE_FLOATS=1
19803 \begin_inset LatexCommand \index{USE\_FLOATS}
19804
19805 \end_inset
19806
19807
19808 \emph default
19809  on the command line.
19810  Use
19811 \emph on
19812  -
19813 \begin_inset ERT
19814 status collapsed
19815
19816 \begin_layout Standard
19817
19818
19819 \backslash
19820 /
19821 \end_layout
19822
19823 \end_inset
19824
19825 -model-large
19826 \begin_inset LatexCommand \index{-\/-model-large}
19827
19828 \end_inset
19829
19830
19831 \emph default
19832  for the mcs51 port, since this uses a lot of memory.
19833 \end_layout
19834
19835 \begin_layout Standard
19836 If you're short on code memory you might want to use 
19837 \family typewriter
19838 printf_small()
19839 \begin_inset LatexCommand \index{printf\_small()}
19840
19841 \end_inset
19842
19843
19844 \family default
19845  
19846 \emph on
19847 instead
19848 \emph default
19849  of
19850 \family typewriter
19851  printf().
19852
19853 \family default
19854  For the mcs51 there additionally are assembly versions 
19855 \family typewriter
19856 printf_tiny()
19857 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19858
19859 \end_inset
19860
19861
19862 \family default
19863  (subset of printf using less than 270 bytes) and 
19864 \family typewriter
19865 printf_fast()
19866 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19867
19868 \end_inset
19869
19870  
19871 \family default
19872 and
19873 \family typewriter
19874  printf_fast_f()
19875 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19876
19877 \end_inset
19878
19879
19880 \family default
19881  (floating-point aware version of printf_fast) which should fit the requirements
19882  of many embedded systems (printf_fast() can be customized by unsetting
19883  #defines to 
19884 \emph on
19885 not
19886 \emph default
19887  support long variables and field widths).
19888  Be sure to use only one of these printf options within a project.
19889 \newline
19890
19891 \end_layout
19892
19893 \begin_layout Standard
19894 Feature matrix of different 
19895 \emph on
19896 printf
19897 \emph default
19898  options on mcs51.
19899 \end_layout
19900
19901 \begin_layout Standard
19902 \begin_inset Tabular
19903 <lyxtabular version="3" rows="14" columns="7">
19904 <features islongtable="true">
19905 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19906 <column alignment="center" valignment="top" leftline="true" width="0">
19907 <column alignment="center" valignment="top" leftline="true" width="12col%">
19908 <column alignment="center" valignment="top" leftline="true" width="10col%">
19909 <column alignment="center" valignment="top" leftline="true" width="0">
19910 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19911 <column alignment="center" valignment="top" rightline="true" width="0">
19912 <row topline="true" bottomline="true" endhead="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19914 \begin_inset Text
19915
19916 \begin_layout Standard
19917
19918 \series bold
19919 \size large
19920 mcs51
19921 \end_layout
19922
19923 \end_inset
19924 </cell>
19925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19926 \begin_inset Text
19927
19928 \begin_layout Standard
19929 printf
19930 \begin_inset LatexCommand \index{printf}
19931
19932 \end_inset
19933
19934
19935 \end_layout
19936
19937 \end_inset
19938 </cell>
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_inset Text
19941
19942 \begin_layout Standard
19943 printf 
19944 \size scriptsize
19945 USE_FLOATS=1
19946 \end_layout
19947
19948 \end_inset
19949 </cell>
19950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_inset Text
19952
19953 \begin_layout Standard
19954 printf_small
19955 \end_layout
19956
19957 \end_inset
19958 </cell>
19959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19960 \begin_inset Text
19961
19962 \begin_layout Standard
19963 printf_fast
19964 \end_layout
19965
19966 \end_inset
19967 </cell>
19968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19969 \begin_inset Text
19970
19971 \begin_layout Standard
19972 printf_fast_f
19973 \end_layout
19974
19975 \end_inset
19976 </cell>
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_inset Text
19979
19980 \begin_layout Standard
19981 printf_tiny
19982 \end_layout
19983
19984 \end_inset
19985 </cell>
19986 </row>
19987 <row topline="true" endhead="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_inset Text
19990
19991 \begin_layout Standard
19992 filename
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
20002 \size scriptsize
20003 printf_large.c
20004 \end_layout
20005
20006 \end_inset
20007 </cell>
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_inset Text
20010
20011 \begin_layout Standard
20012
20013 \size scriptsize
20014 printf_large.c
20015 \end_layout
20016
20017 \end_inset
20018 </cell>
20019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20020 \begin_inset Text
20021
20022 \begin_layout Standard
20023
20024 \size scriptsize
20025 printfl.c
20026 \end_layout
20027
20028 \end_inset
20029 </cell>
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20031 \begin_inset Text
20032
20033 \begin_layout Standard
20034
20035 \size scriptsize
20036 printf_fast.c
20037 \end_layout
20038
20039 \end_inset
20040 </cell>
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20042 \begin_inset Text
20043
20044 \begin_layout Standard
20045
20046 \size scriptsize
20047 printf_fast_f.c
20048 \end_layout
20049
20050 \end_inset
20051 </cell>
20052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20053 \begin_inset Text
20054
20055 \begin_layout Standard
20056
20057 \size scriptsize
20058 printf_tiny.c
20059 \end_layout
20060
20061 \end_inset
20062 </cell>
20063 </row>
20064 <row topline="true" endhead="true">
20065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20066 \begin_inset Text
20067
20068 \begin_layout Standard
20069 \begin_inset Quotes sld
20070 \end_inset
20071
20072 Hello World
20073 \begin_inset Quotes srd
20074 \end_inset
20075
20076  size
20077 \end_layout
20078
20079 \begin_layout Standard
20080 small / large
20081 \end_layout
20082
20083 \end_inset
20084 </cell>
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20086 \begin_inset Text
20087
20088 \begin_layout Standard
20089 1.7k / 2.4k
20090 \end_layout
20091
20092 \end_inset
20093 </cell>
20094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20095 \begin_inset Text
20096
20097 \begin_layout Standard
20098 4.3k / 5.6k
20099 \end_layout
20100
20101 \end_inset
20102 </cell>
20103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20104 \begin_inset Text
20105
20106 \begin_layout Standard
20107 1.2k / 1.8k
20108 \end_layout
20109
20110 \end_inset
20111 </cell>
20112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20113 \begin_inset Text
20114
20115 \begin_layout Standard
20116 1.3k / 1.3k
20117 \end_layout
20118
20119 \end_inset
20120 </cell>
20121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20122 \begin_inset Text
20123
20124 \begin_layout Standard
20125 1.9k / 1.9k
20126 \end_layout
20127
20128 \end_inset
20129 </cell>
20130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20131 \begin_inset Text
20132
20133 \begin_layout Standard
20134 0.44k / 0.44k
20135 \end_layout
20136
20137 \end_inset
20138 </cell>
20139 </row>
20140 <row topline="true" endhead="true">
20141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20142 \begin_inset Text
20143
20144 \begin_layout Standard
20145 code size
20146 \end_layout
20147
20148 \begin_layout Standard
20149 small / large
20150 \end_layout
20151
20152 \end_inset
20153 </cell>
20154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20155 \begin_inset Text
20156
20157 \begin_layout Standard
20158 1.4k / 2.0k
20159 \end_layout
20160
20161 \end_inset
20162 </cell>
20163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20164 \begin_inset Text
20165
20166 \begin_layout Standard
20167 2.8k / 3.7k
20168 \end_layout
20169
20170 \end_inset
20171 </cell>
20172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20173 \begin_inset Text
20174
20175 \begin_layout Standard
20176 0.45k / 0.47k (+ _ltoa)
20177 \end_layout
20178
20179 \end_inset
20180 </cell>
20181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20182 \begin_inset Text
20183
20184 \begin_layout Standard
20185 1.2k / 1.2k
20186 \end_layout
20187
20188 \end_inset
20189 </cell>
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20191 \begin_inset Text
20192
20193 \begin_layout Standard
20194 1.6k / 1.6k
20195 \end_layout
20196
20197 \end_inset
20198 </cell>
20199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20200 \begin_inset Text
20201
20202 \begin_layout Standard
20203 0.26k / 0.26k
20204 \end_layout
20205
20206 \end_inset
20207 </cell>
20208 </row>
20209 <row topline="true">
20210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20211 \begin_inset Text
20212
20213 \begin_layout Standard
20214 formats
20215 \end_layout
20216
20217 \end_inset
20218 </cell>
20219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20220 \begin_inset Text
20221
20222 \begin_layout Standard
20223 cdi
20224 \emph on
20225 o
20226 \emph default
20227 psux
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
20237 \family roman
20238 \series medium
20239 \shape up
20240 \size normal
20241 \emph off
20242 \bar no
20243 \noun off
20244 \color none
20245 cd
20246 \family default
20247 \series default
20248 \shape default
20249 \size default
20250 \emph default
20251 \bar default
20252 \noun default
20253 f
20254 \family roman
20255 \series medium
20256 \shape up
20257 \size normal
20258 \emph off
20259 \bar no
20260 \noun off
20261 i
20262 \family default
20263 \series default
20264 \shape default
20265 \size default
20266 \emph on
20267 \bar default
20268 \noun default
20269 o
20270 \family roman
20271 \series medium
20272 \shape up
20273 \size normal
20274 \emph off
20275 \bar no
20276 \noun off
20277 psux
20278 \end_layout
20279
20280 \end_inset
20281 </cell>
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_inset Text
20284
20285 \begin_layout Standard
20286 c
20287 \family roman
20288 \series medium
20289 \shape up
20290 \size normal
20291 \emph off
20292 \bar no
20293 \noun off
20294 \color none
20295 d
20296 \family default
20297 \series default
20298 \shape default
20299 \size default
20300 \emph on
20301 \bar default
20302 \noun default
20303 o
20304 \family roman
20305 \series medium
20306 \shape up
20307 \size normal
20308 \emph off
20309 \bar no
20310 \noun off
20311 s
20312 \family default
20313 \series default
20314 \shape default
20315 \size default
20316 \emph default
20317 \bar default
20318 \noun default
20319 x
20320 \end_layout
20321
20322 \end_inset
20323 </cell>
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20325 \begin_inset Text
20326
20327 \begin_layout Standard
20328 cdsux
20329 \end_layout
20330
20331 \end_inset
20332 </cell>
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20334 \begin_inset Text
20335
20336 \begin_layout Standard
20337 cdfsux
20338 \end_layout
20339
20340 \end_inset
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \begin_layout Standard
20346 cdsux
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 </row>
20352 <row topline="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20354 \begin_inset Text
20355
20356 \begin_layout Standard
20357 long (32 bit) support
20358 \end_layout
20359
20360 \end_inset
20361 </cell>
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \begin_layout Standard
20366 x
20367 \end_layout
20368
20369 \end_inset
20370 </cell>
20371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20372 \begin_inset Text
20373
20374 \begin_layout Standard
20375 x
20376 \end_layout
20377
20378 \end_inset
20379 </cell>
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20381 \begin_inset Text
20382
20383 \begin_layout Standard
20384 x
20385 \end_layout
20386
20387 \end_inset
20388 </cell>
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20390 \begin_inset Text
20391
20392 \begin_layout Standard
20393 x
20394 \end_layout
20395
20396 \end_inset
20397 </cell>
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20399 \begin_inset Text
20400
20401 \begin_layout Standard
20402
20403 \family roman
20404 \series medium
20405 \shape up
20406 \size normal
20407 \emph off
20408 \bar no
20409 \noun off
20410 \color none
20411 x
20412 \end_layout
20413
20414 \end_inset
20415 </cell>
20416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20417 \begin_inset Text
20418
20419 \begin_layout Standard
20420 -
20421 \end_layout
20422
20423 \end_inset
20424 </cell>
20425 </row>
20426 <row topline="true">
20427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20428 \begin_inset Text
20429
20430 \begin_layout Standard
20431 byte arguments on stack
20432 \end_layout
20433
20434 \end_inset
20435 </cell>
20436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 \begin_inset Text
20438
20439 \begin_layout Standard
20440 b
20441 \end_layout
20442
20443 \end_inset
20444 </cell>
20445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20446 \begin_inset Text
20447
20448 \begin_layout Standard
20449 b
20450 \end_layout
20451
20452 \end_inset
20453 </cell>
20454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_inset Text
20456
20457 \begin_layout Standard
20458 -
20459 \end_layout
20460
20461 \end_inset
20462 </cell>
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_inset Text
20465
20466 \begin_layout Standard
20467 -
20468 \end_layout
20469
20470 \end_inset
20471 </cell>
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20473 \begin_inset Text
20474
20475 \begin_layout Standard
20476 -
20477 \end_layout
20478
20479 \end_inset
20480 </cell>
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20482 \begin_inset Text
20483
20484 \begin_layout Standard
20485 -
20486 \end_layout
20487
20488 \end_inset
20489 </cell>
20490 </row>
20491 <row topline="true">
20492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20493 \begin_inset Text
20494
20495 \begin_layout Standard
20496 float format
20497 \begin_inset LatexCommand \index{Floating point support}
20498
20499 \end_inset
20500
20501
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20507 \begin_inset Text
20508
20509 \begin_layout Standard
20510 -
20511 \end_layout
20512
20513 \end_inset
20514 </cell>
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20516 \begin_inset Text
20517
20518 \begin_layout Standard
20519 %f
20520 \end_layout
20521
20522 \end_inset
20523 </cell>
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20525 \begin_inset Text
20526
20527 \begin_layout Standard
20528 -
20529 \end_layout
20530
20531 \end_inset
20532 </cell>
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20534 \begin_inset Text
20535
20536 \begin_layout Standard
20537 -
20538 \end_layout
20539
20540 \end_inset
20541 </cell>
20542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20543 \begin_inset Text
20544
20545 \begin_layout Standard
20546 %f
20547 \begin_inset Foot
20548 status collapsed
20549
20550 \begin_layout Standard
20551 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20552 \end_layout
20553
20554 \end_inset
20555
20556
20557 \end_layout
20558
20559 \end_inset
20560 </cell>
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20562 \begin_inset Text
20563
20564 \begin_layout Standard
20565 -
20566 \end_layout
20567
20568 \end_inset
20569 </cell>
20570 </row>
20571 <row topline="true">
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \begin_layout Standard
20576 float formats %e %g
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 -
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 -
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 -
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 -
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 -
20622 \end_layout
20623
20624 \end_inset
20625 </cell>
20626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20627 \begin_inset Text
20628
20629 \begin_layout Standard
20630 -
20631 \end_layout
20632
20633 \end_inset
20634 </cell>
20635 </row>
20636 <row topline="true" bottomline="true">
20637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20638 \begin_inset Text
20639
20640 \begin_layout Standard
20641 field width
20642 \end_layout
20643
20644 \end_inset
20645 </cell>
20646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20647 \begin_inset Text
20648
20649 \begin_layout Standard
20650 x
20651 \end_layout
20652
20653 \end_inset
20654 </cell>
20655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20656 \begin_inset Text
20657
20658 \begin_layout Standard
20659 x
20660 \end_layout
20661
20662 \end_inset
20663 </cell>
20664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20665 \begin_inset Text
20666
20667 \begin_layout Standard
20668 -
20669 \end_layout
20670
20671 \end_inset
20672 </cell>
20673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20674 \begin_inset Text
20675
20676 \begin_layout Standard
20677 x
20678 \end_layout
20679
20680 \end_inset
20681 </cell>
20682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20683 \begin_inset Text
20684
20685 \begin_layout Standard
20686 x
20687 \end_layout
20688
20689 \end_inset
20690 </cell>
20691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20692 \begin_inset Text
20693
20694 \begin_layout Standard
20695 -
20696 \end_layout
20697
20698 \end_inset
20699 </cell>
20700 </row>
20701 <row bottomline="true">
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20703 \begin_inset Text
20704
20705 \begin_layout Standard
20706 string speed
20707 \begin_inset Foot
20708 status collapsed
20709
20710 \begin_layout Standard
20711 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20712 \backslash
20713 r', '
20714 \backslash
20715 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20716 \end_layout
20717
20718 \end_inset
20719
20720 ,
20721 \end_layout
20722
20723 \begin_layout Standard
20724 small / large
20725 \end_layout
20726
20727 \end_inset
20728 </cell>
20729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20730 \begin_inset Text
20731
20732 \begin_layout Standard
20733 1.52 / 2.59 ms
20734 \end_layout
20735
20736 \end_inset
20737 </cell>
20738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20739 \begin_inset Text
20740
20741 \begin_layout Standard
20742 1.53 / 2.62 ms
20743 \end_layout
20744
20745 \end_inset
20746 </cell>
20747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20748 \begin_inset Text
20749
20750 \begin_layout Standard
20751 0.92 / 0.93 ms
20752 \end_layout
20753
20754 \end_inset
20755 </cell>
20756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20757 \begin_inset Text
20758
20759 \begin_layout Standard
20760 0.45 / 0.45 ms
20761 \end_layout
20762
20763 \end_inset
20764 </cell>
20765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20766 \begin_inset Text
20767
20768 \begin_layout Standard
20769 0.46 / 0.46 ms
20770 \end_layout
20771
20772 \end_inset
20773 </cell>
20774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20775 \begin_inset Text
20776
20777 \begin_layout Standard
20778 0.45 / 0.45 ms
20779 \end_layout
20780
20781 \end_inset
20782 </cell>
20783 </row>
20784 <row bottomline="true">
20785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20786 \begin_inset Text
20787
20788 \begin_layout Standard
20789 int speed
20790 \begin_inset Foot
20791 status collapsed
20792
20793 \begin_layout Standard
20794 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20795  putchar()
20796 \end_layout
20797
20798 \end_inset
20799
20800 ,
20801 \end_layout
20802
20803 \begin_layout Standard
20804 small / large
20805 \end_layout
20806
20807 \end_inset
20808 </cell>
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20810 \begin_inset Text
20811
20812 \begin_layout Standard
20813 3.01 / 3.61 ms
20814 \end_layout
20815
20816 \end_inset
20817 </cell>
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20819 \begin_inset Text
20820
20821 \begin_layout Standard
20822 3.01 / 3.61 ms
20823 \end_layout
20824
20825 \end_inset
20826 </cell>
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20828 \begin_inset Text
20829
20830 \begin_layout Standard
20831 3.51 / 18.13 ms
20832 \end_layout
20833
20834 \end_inset
20835 </cell>
20836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20837 \begin_inset Text
20838
20839 \begin_layout Standard
20840 0.22 / 0.22 ms
20841 \end_layout
20842
20843 \end_inset
20844 </cell>
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20846 \begin_inset Text
20847
20848 \begin_layout Standard
20849 0.23 / 0.23 ms
20850 \end_layout
20851
20852 \end_inset
20853 </cell>
20854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20855 \begin_inset Text
20856
20857 \begin_layout Standard
20858 0.25 / 0.25 ms
20859 \begin_inset Foot
20860 status collapsed
20861
20862 \begin_layout Standard
20863 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20864 \end_layout
20865
20866 \end_inset
20867
20868
20869 \end_layout
20870
20871 \end_inset
20872 </cell>
20873 </row>
20874 <row bottomline="true">
20875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20876 \begin_inset Text
20877
20878 \begin_layout Standard
20879 long speed
20880 \begin_inset Foot
20881 status collapsed
20882
20883 \begin_layout Standard
20884 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20885  empty putchar()
20886 \end_layout
20887
20888 \end_inset
20889
20890 ,
20891 \end_layout
20892
20893 \begin_layout Standard
20894 small / large
20895 \end_layout
20896
20897 \end_inset
20898 </cell>
20899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20900 \begin_inset Text
20901
20902 \begin_layout Standard
20903 5.37 / 6.31 ms
20904 \end_layout
20905
20906 \end_inset
20907 </cell>
20908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20909 \begin_inset Text
20910
20911 \begin_layout Standard
20912 5.37 / 6.31 ms
20913 \end_layout
20914
20915 \end_inset
20916 </cell>
20917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20918 \begin_inset Text
20919
20920 \begin_layout Standard
20921 8.71 / 40.65 ms
20922 \end_layout
20923
20924 \end_inset
20925 </cell>
20926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20927 \begin_inset Text
20928
20929 \begin_layout Standard
20930 0.40 / 0.40 ms
20931 \end_layout
20932
20933 \end_inset
20934 </cell>
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \begin_layout Standard
20939 0.40 / 0.40 ms
20940 \end_layout
20941
20942 \end_inset
20943 </cell>
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \begin_layout Standard
20948 -
20949 \end_layout
20950
20951 \end_inset
20952 </cell>
20953 </row>
20954 <row bottomline="true">
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20956 \begin_inset Text
20957
20958 \begin_layout Standard
20959 float speed
20960 \begin_inset Foot
20961 status collapsed
20962
20963 \begin_layout Standard
20964 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20965  empty putchar()
20966 \end_layout
20967
20968 \end_inset
20969
20970 ,
20971 \end_layout
20972
20973 \begin_layout Standard
20974 small / large
20975 \end_layout
20976
20977 \end_inset
20978 </cell>
20979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20980 \begin_inset Text
20981
20982 \begin_layout Standard
20983 -
20984 \end_layout
20985
20986 \end_inset
20987 </cell>
20988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20989 \begin_inset Text
20990
20991 \begin_layout Standard
20992 7.49 / 22.47 ms
20993 \end_layout
20994
20995 \end_inset
20996 </cell>
20997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20998 \begin_inset Text
20999
21000 \begin_layout Standard
21001 -
21002 \end_layout
21003
21004 \end_inset
21005 </cell>
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21007 \begin_inset Text
21008
21009 \begin_layout Standard
21010 -
21011 \end_layout
21012
21013 \end_inset
21014 </cell>
21015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21016 \begin_inset Text
21017
21018 \begin_layout Standard
21019 1.04 / 1.04 ms
21020 \end_layout
21021
21022 \end_inset
21023 </cell>
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21025 \begin_inset Text
21026
21027 \begin_layout Standard
21028 -
21029 \end_layout
21030
21031 \end_inset
21032 </cell>
21033 </row>
21034 </lyxtabular>
21035
21036 \end_inset
21037
21038
21039 \end_layout
21040
21041 \begin_layout Subsubsection
21042 <malloc.h>
21043 \begin_inset LatexCommand \index{malloc.h}
21044
21045 \end_inset
21046
21047
21048 \end_layout
21049
21050 \begin_layout Standard
21051 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21052  using dynamic memory allocation
21053 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21054
21055 \end_inset
21056
21057  and a default heap
21058 \begin_inset LatexCommand \index{heap (malloc)}
21059
21060 \end_inset
21061
21062  space of 1024 bytes is provided for malloc to allocate memory from.
21063  If you need a different heap size you need to recompile _heap.c with the
21064  required size defined in HEAP_SIZE.
21065  It is recommended to make a copy of this file into your project directory
21066  and compile it there with:
21067 \end_layout
21068
21069 \begin_layout Verse
21070
21071 \family typewriter
21072 sdcc -c _heap.c -D HEAD_SIZE=2048
21073 \end_layout
21074
21075 \begin_layout Standard
21076 And then link it with:
21077 \end_layout
21078
21079 \begin_layout Verse
21080
21081 \family typewriter
21082 sdcc main.rel _heap.rel
21083 \end_layout
21084
21085 \begin_layout Subsection
21086 Math functions (sinf, powf, sqrtf etc.)
21087 \end_layout
21088
21089 \begin_layout Subsubsection
21090 <math.h>
21091 \end_layout
21092
21093 \begin_layout Standard
21094 See definitions in file <math.h>.
21095 \end_layout
21096
21097 \begin_layout Subsection
21098 Other libraries
21099 \end_layout
21100
21101 \begin_layout Standard
21102 Libraries
21103 \begin_inset LatexCommand \index{Libraries}
21104
21105 \end_inset
21106
21107  included in SDCC should have a license at least as liberal as the GNU Lesser
21108  General Public License
21109 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21110
21111 \end_inset
21112
21113  
21114 \emph on
21115 LGPL
21116 \emph default
21117 .
21118 \end_layout
21119
21120 \begin_layout Standard
21121 \begin_inset Note Note
21122 status collapsed
21123
21124 \begin_layout Standard
21125 license statements for the libraries are missing.
21126  sdcc/device/lib/ser_ir.c
21127 \end_layout
21128
21129 \begin_layout Standard
21130 or _decdptr f.e.
21131  come with a GPL (as opposed to LGPL) License - this will not be liberal
21132  enough for many embedded programmers.
21133 \end_layout
21134
21135 \end_inset
21136
21137
21138 \end_layout
21139
21140 \begin_layout Standard
21141 If you have ported some library or want to share experience about some code
21142  which f.e.
21143  falls into any of these categories Busses (I
21144 \begin_inset Formula $^{\textrm{2}}$
21145 \end_inset
21146
21147 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21148  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21149  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21150 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21151
21152 \end_inset
21153
21154 \InsetSpace ~
21155 would certainly like to hear about it.
21156 \end_layout
21157
21158 \begin_layout Standard
21159 Programmers coding for embedded systems are not especially famous for being
21160  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21161 e these references are very valuable.
21162  Let's help to create a climate where information is shared.
21163 \begin_inset VSpace bigskip
21164 \end_inset
21165
21166
21167 \end_layout
21168
21169 \begin_layout Section
21170 Memory Models
21171 \end_layout
21172
21173 \begin_layout Subsection
21174 MCS51 Memory Models
21175 \begin_inset LatexCommand \index{Memory model}
21176
21177 \end_inset
21178
21179
21180 \begin_inset LatexCommand \index{MCS51 memory model}
21181
21182 \end_inset
21183
21184
21185 \end_layout
21186
21187 \begin_layout Subsubsection
21188 Small, Medium and Large
21189 \end_layout
21190
21191 \begin_layout Standard
21192 SDCC allows three memory models for MCS51 code, 
21193 \shape slanted
21194 small, medium
21195 \shape default
21196  and 
21197 \shape slanted
21198 large
21199 \shape default
21200 .
21201  Modules compiled with different memory models should 
21202 \emph on
21203 never
21204 \emph default
21205  be combined together or the results would be unpredictable.
21206  The library routines supplied with the compiler are compiled as small,
21207  medium and large.
21208  The compiled library modules are contained in separate directories as small,
21209  medium and large so that you can link to the appropriate set.
21210 \end_layout
21211
21212 \begin_layout Standard
21213 When the medium or large model is used all variables declared without a
21214  storage class will be allocated into the external ram, this includes all
21215  parameters and local variables (for non-reentrant
21216 \begin_inset LatexCommand \index{reentrant}
21217
21218 \end_inset
21219
21220  functions).
21221  When the small model is used variables without storage class are allocated
21222  in the internal ram.
21223 \end_layout
21224
21225 \begin_layout Standard
21226 Judicious usage of the processor specific storage classes
21227 \begin_inset LatexCommand \index{Storage class}
21228
21229 \end_inset
21230
21231  and the 'reentrant' function type will yield much more efficient code,
21232  than using the large model.
21233  Several optimizations are disabled when the program is compiled using the
21234  large model, it is therefore recommended that the small model be used unless
21235  absolutely required.
21236 \end_layout
21237
21238 \begin_layout Subsubsection
21239 External Stack
21240 \begin_inset LatexCommand \label{sub:External-Stack}
21241
21242 \end_inset
21243
21244
21245 \begin_inset LatexCommand \index{stack}
21246
21247 \end_inset
21248
21249
21250 \begin_inset LatexCommand \index{External stack (mcs51)}
21251
21252 \end_inset
21253
21254
21255 \end_layout
21256
21257 \begin_layout Standard
21258 The external stack (-
21259 \begin_inset ERT
21260 status collapsed
21261
21262 \begin_layout Standard
21263
21264
21265 \backslash
21266 /
21267 \end_layout
21268
21269 \end_inset
21270
21271 -xstack option
21272 \begin_inset LatexCommand \index{-\/-xstack}
21273
21274 \end_inset
21275
21276 ) is located in pdata
21277 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21278
21279 \end_inset
21280
21281  memory (usually at the start of the external ram segment) and uses all
21282  unused space in pdata (max.
21283  256 bytes).
21284  When -
21285 \begin_inset ERT
21286 status collapsed
21287
21288 \begin_layout Standard
21289
21290
21291 \backslash
21292 /
21293 \end_layout
21294
21295 \end_inset
21296
21297 -xstack option is used to compile the program, the parameters and local
21298  variables
21299 \begin_inset LatexCommand \index{local variables}
21300
21301 \end_inset
21302
21303  of all reentrant functions are allocated in this area.
21304  This option is provided for programs with large stack space requirements.
21305  When used with the -
21306 \begin_inset ERT
21307 status collapsed
21308
21309 \begin_layout Standard
21310
21311
21312 \backslash
21313 /
21314 \end_layout
21315
21316 \end_inset
21317
21318 -stack-auto
21319 \begin_inset LatexCommand \index{-\/-stack-auto}
21320
21321 \end_inset
21322
21323  option, all parameters and local variables are allocated on the external
21324  stack (note: support libraries will need to be recompiled with the same
21325  options.
21326  There is a predefined target in the library makefile).
21327 \end_layout
21328
21329 \begin_layout Standard
21330 The compiler outputs the higher order address byte of the external ram segment
21331  into port P2
21332 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21333
21334 \end_inset
21335
21336  (see also section 
21337 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21338
21339 \end_inset
21340
21341 ), therefore when using the External Stack option, this port 
21342 \emph on
21343 may not
21344 \emph default
21345  be used by the application program.
21346 \end_layout
21347
21348 \begin_layout Subsection
21349 DS390 Memory Model
21350 \begin_inset LatexCommand \index{Memory model}
21351
21352 \end_inset
21353
21354
21355 \begin_inset LatexCommand \index{DS390 memory model}
21356
21357 \end_inset
21358
21359
21360 \end_layout
21361
21362 \begin_layout Standard
21363 The only model supported is Flat 24
21364 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21365
21366 \end_inset
21367
21368 .
21369  This generates code for the 24 bit contiguous addressing mode of the Dallas
21370  DS80C390 part.
21371  In this mode, up to four meg of external RAM or code space can be directly
21372  addressed.
21373  See the data sheets at www.dalsemi.com for further information on this part.
21374 \newline
21375
21376 \newline
21377 Note
21378  that the compiler does not generate any code to place the processor into
21379  24 bitmode (although 
21380 \emph on
21381 tinibios
21382 \emph default
21383  in the ds390 libraries will do that for you).
21384  If you don't use 
21385 \emph on
21386 tinibios
21387 \emph default
21388
21389 \begin_inset LatexCommand \index{Tinibios (DS390)}
21390
21391 \end_inset
21392
21393 , the boot loader or similar code must ensure that the processor is in 24
21394  bit contiguous addressing mode before calling the SDCC startup code.
21395 \newline
21396
21397 \newline
21398 Like
21399  the 
21400 \emph on
21401 -
21402 \begin_inset ERT
21403 status collapsed
21404
21405 \begin_layout Standard
21406
21407
21408 \backslash
21409 /
21410 \end_layout
21411
21412 \end_inset
21413
21414 -model-large
21415 \emph default
21416  option, variables will by default be placed into the XDATA segment.
21417  
21418 \newline
21419
21420 \newline
21421 Segments may be placed anywhere in the 4 meg address space using the usual
21422  -
21423 \begin_inset ERT
21424 status collapsed
21425
21426 \begin_layout Standard
21427
21428
21429 \backslash
21430 /
21431 \end_layout
21432
21433 \end_inset
21434
21435 -*-loc options.
21436  Note that if any segments are located above 64K, the -r flag must be passed
21437  to the linker to generate the proper segment relocations, and the Intel
21438  HEX output format must be used.
21439  The -r flag can be passed to the linker by using the option 
21440 \emph on
21441 -Wl-r
21442 \emph default
21443  on the SDCC command line.
21444  However, currently the linker can not handle code segments > 64k.
21445 \end_layout
21446
21447 \begin_layout Section
21448 Pragmas
21449 \begin_inset LatexCommand \label{sec:Pragmas}
21450
21451 \end_inset
21452
21453
21454 \begin_inset LatexCommand \index{Pragmas}
21455
21456 \end_inset
21457
21458
21459 \end_layout
21460
21461 \begin_layout Standard
21462 Pragmas are used to turn on and/or off certain compiler options.
21463  Some of them are closely related to corresponding command-line options
21464  (see section 
21465 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21466
21467 \end_inset
21468
21469 ).
21470 \newline
21471 Pragmas should be placed before and/or after a function, placing pragmas
21472  inside a function body could have unpredictable results.
21473 \newline
21474
21475 \newline
21476 SDCC supports the
21477  following #pragma directives:
21478 \end_layout
21479
21480 \begin_layout Itemize
21481
21482 \series bold
21483 save
21484 \series default
21485
21486 \begin_inset LatexCommand \index{\#pragma save}
21487
21488 \end_inset
21489
21490  - this will save most current options to the save/restore stack.
21491  See #pragma\InsetSpace ~
21492 restore.
21493 \end_layout
21494
21495 \begin_layout Itemize
21496
21497 \series bold
21498 restore
21499 \series default
21500
21501 \begin_inset LatexCommand \index{\#pragma restore}
21502
21503 \end_inset
21504
21505  - will restore saved options from the last save.
21506  saves & restores can be nested.
21507  SDCC uses a save/restore stack: save pushes current options to the stack,
21508  restore pulls current options from the stack.
21509  See #pragma\InsetSpace ~
21510 save.
21511 \newline
21512
21513 \end_layout
21514
21515 \begin_layout Itemize
21516
21517 \series bold
21518 callee_saves
21519 \series default
21520
21521 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21522
21523 \end_inset
21524
21525
21526 \begin_inset LatexCommand \index{function prologue}
21527
21528 \end_inset
21529
21530  function1[,function2[,function3...]] 
21531 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21532
21533 \end_inset
21534
21535 - The compiler by default uses a caller saves convention for register saving
21536  across function calls, however this can cause unnecessary register pushing
21537  and popping
21538 \begin_inset LatexCommand \index{push/pop}
21539
21540 \end_inset
21541
21542  when calling small functions from larger functions.
21543  This option can be used to switch off the register saving convention for
21544  the function names specified.
21545  The compiler will not save registers when calling these functions, extra
21546  code need to be manually inserted at the entry and exit for these functions
21547  to save and restore the registers used by these functions, this can SUBSTANTIAL
21548 LY reduce code and improve run time performance of the generated code.
21549  In the future the compiler (with inter procedural analysis) may be able
21550  to determine the appropriate scheme to use for each function call.
21551  If -
21552 \begin_inset ERT
21553 status collapsed
21554
21555 \begin_layout Standard
21556
21557
21558 \backslash
21559 /
21560 \end_layout
21561
21562 \end_inset
21563
21564 -callee-saves command line option is used (see page 
21565 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21566
21567 \end_inset
21568
21569 ), the function names specified in #pragma\InsetSpace ~
21570 callee_saves
21571 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21572
21573 \end_inset
21574
21575  is appended to the list of functions specified in the command line.
21576 \end_layout
21577
21578 \begin_layout Itemize
21579
21580 \series bold
21581 exclude
21582 \series default
21583
21584 \begin_inset LatexCommand \index{\#pragma exclude}
21585
21586 \end_inset
21587
21588  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21589  of pairs of push/pop
21590 \begin_inset LatexCommand \index{push/pop}
21591
21592 \end_inset
21593
21594  instructions in 
21595 \emph on
21596 I
21597 \emph default
21598 nterrupt
21599 \begin_inset LatexCommand \index{interrupt}
21600
21601 \end_inset
21602
21603  
21604 \emph on
21605 S
21606 \emph default
21607 ervice 
21608 \emph on
21609 R
21610 \emph default
21611 outines.
21612  The directive should be placed immediately before the ISR function definition
21613  and it affects ALL ISR functions following it.
21614  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21615 exclude\InsetSpace ~
21616 none
21617 \begin_inset LatexCommand \index{\#pragma exclude}
21618
21619 \end_inset
21620
21621 .
21622  See also the related keyword _naked
21623 \begin_inset LatexCommand \index{\_naked}
21624
21625 \end_inset
21626
21627
21628 \begin_inset LatexCommand \index{\_\_naked}
21629
21630 \end_inset
21631
21632 .
21633 \end_layout
21634
21635 \begin_layout Itemize
21636
21637 \series bold
21638 less_pedantic
21639 \series default
21640
21641 \begin_inset LatexCommand \index{pedantic}
21642
21643 \end_inset
21644
21645
21646 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21647
21648 \end_inset
21649
21650  
21651 \begin_inset LatexCommand \label{ite:less_pedantic}
21652
21653 \end_inset
21654
21655 - the compiler will not warn you anymore for obvious mistakes, you're on
21656  your own now ;-( .
21657  See also the command line option -
21658 \begin_inset ERT
21659 status collapsed
21660
21661 \begin_layout Standard
21662
21663
21664 \backslash
21665 /
21666 \end_layout
21667
21668 \end_inset
21669
21670 -less-pedantic 
21671 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21672
21673 \end_inset
21674
21675 .
21676  
21677 \newline
21678 More specifically, the following warnings will be disabled: 
21679 \shape italic
21680 comparison is always [true/false] due to limited range of data type
21681 \shape default
21682  (94); 
21683 \shape italic
21684 overflow in implicit constant conversion
21685 \shape default
21686  (158); [the (in)famous] 
21687 \shape italic
21688 conditional flow changed by optimizer: so said EVELYN the modified DOG
21689 \shape default
21690  (110); 
21691 \shape italic
21692 function '[function name]' must return value
21693 \shape default
21694  (59).
21695  
21696 \newline
21697 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21698  level) are disabled, too, namely: 
21699 \shape italic
21700 constant value '[
21701 \begin_inset Note Note
21702 status collapsed
21703
21704 \begin_layout Standard
21705 dunno what comes here - this warning appears to be unused altogether
21706 \end_layout
21707
21708 \end_inset
21709
21710 ]', out of range
21711 \shape default
21712  (81); 
21713 \shape italic
21714 [left/right] shifting more than size of object changed to zero
21715 \shape default
21716  (116); 
21717 \shape italic
21718 unreachable code
21719 \shape default
21720  (126); 
21721 \shape italic
21722 integer overflow in expression
21723 \shape default
21724  (165); 
21725 \shape italic
21726 unmatched #pragma save and #pragma restore
21727 \shape default
21728  (170); 
21729 \shape italic
21730 comparison of 'signed char' with 'unsigned char' requires promotion to int
21731 \shape default
21732  (185); 
21733 \shape italic
21734 ISO C90 does not support flexible array members
21735 \shape default
21736  (187); 
21737 \shape italic
21738 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21739 nam
21740 e]':\InsetSpace ~
21741 [
21742 \begin_inset Note Note
21743 status collapsed
21744
21745 \begin_layout Standard
21746 appears to be always blank - what was supposed to be here?
21747 \end_layout
21748
21749 \end_inset
21750
21751 ]
21752 \shape default
21753  (114); 
21754 \shape italic
21755 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21756  complexity [number]
21757 \shape default
21758  (121).
21759 \end_layout
21760
21761 \begin_layout Itemize
21762
21763 \series bold
21764 disable_warning
21765 \series default
21766  <nnnn>
21767 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21768
21769 \end_inset
21770
21771  - the compiler will not warn you anymore about warning number <nnnn>.
21772 \end_layout
21773
21774 \begin_layout Itemize
21775
21776 \series bold
21777 nogcse
21778 \series default
21779
21780 \begin_inset LatexCommand \index{\#pragma nogcse}
21781
21782 \end_inset
21783
21784  - will stop global common subexpression elimination.
21785 \end_layout
21786
21787 \begin_layout Itemize
21788
21789 \series bold
21790 noinduction
21791 \series default
21792
21793 \begin_inset LatexCommand \index{\#pragma noinduction}
21794
21795 \end_inset
21796
21797  - will stop loop induction optimizations.
21798 \end_layout
21799
21800 \begin_layout Itemize
21801
21802 \series bold
21803 noinvariant
21804 \series default
21805
21806 \begin_inset LatexCommand \index{\#pragma noinvariant}
21807
21808 \end_inset
21809
21810  - will not do loop invariant optimizations.
21811  For more details see Loop Invariants in section
21812 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21813
21814 \end_inset
21815
21816 .
21817 \end_layout
21818
21819 \begin_layout Itemize
21820
21821 \series bold
21822 noiv
21823 \series default
21824
21825 \begin_inset LatexCommand \index{\#pragma noiv}
21826
21827 \end_inset
21828
21829  - Do not generate interrupt
21830 \begin_inset LatexCommand \index{interrupt}
21831
21832 \end_inset
21833
21834  vector table
21835 \begin_inset LatexCommand \index{interrupt vector table}
21836
21837 \end_inset
21838
21839  entries for all ISR functions defined after the pragma.
21840  This is useful in cases where the interrupt vector table must be defined
21841  manually, or when there is a secondary, manually defined interrupt vector
21842  table (e.g.
21843  for the autovector feature of the Cypress EZ-USB FX2).
21844  More elegantly this can be achieved by obmitting the optional interrupt
21845  number after the interrupt keyword, see section 
21846 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21847
21848 \end_inset
21849
21850 \InsetSpace ~
21851 about interrupts.
21852 \end_layout
21853
21854 \begin_layout Itemize
21855
21856 \series bold
21857 nojtbound
21858 \series default
21859
21860 \begin_inset LatexCommand \index{\#pragma nojtbound}
21861
21862 \end_inset
21863
21864  - will not generate code for boundary value checking, when switch statements
21865  are turned into jump-tables (dangerous).
21866  For more details see section 
21867 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21868
21869 \end_inset
21870
21871 .
21872 \end_layout
21873
21874 \begin_layout Itemize
21875
21876 \series bold
21877 noloopreverse
21878 \series default
21879
21880 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21881
21882 \end_inset
21883
21884  - Will not do loop reversal optimization
21885 \end_layout
21886
21887 \begin_layout Itemize
21888
21889 \series bold
21890 nooverlay
21891 \series default
21892
21893 \begin_inset LatexCommand \index{\#pragma nooverlay}
21894
21895 \end_inset
21896
21897  - the compiler will not overlay the parameters and local variables of a
21898  function.
21899 \end_layout
21900
21901 \begin_layout Itemize
21902
21903 \series bold
21904 stackauto
21905 \series default
21906
21907 \begin_inset LatexCommand \index{\#pragma stackauto}
21908
21909 \end_inset
21910
21911 - See option -
21912 \begin_inset ERT
21913 status collapsed
21914
21915 \begin_layout Standard
21916
21917
21918 \backslash
21919 /
21920 \end_layout
21921
21922 \end_inset
21923
21924 -stack-auto
21925 \begin_inset LatexCommand \index{-\/-stack-auto}
21926
21927 \end_inset
21928
21929  and section 
21930 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21931
21932 \end_inset
21933
21934  Parameters and Local Variables.
21935 \end_layout
21936
21937 \begin_layout Itemize
21938
21939 \series bold
21940 opt_code_speed
21941 \series default
21942  
21943 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21944
21945 \end_inset
21946
21947 - The compiler will optimize code generation towards fast code, possibly
21948  at the expense of code size.
21949  Currently this has little effect.
21950 \end_layout
21951
21952 \begin_layout Itemize
21953
21954 \series bold
21955 opt_code_size
21956 \series default
21957  
21958 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21959
21960 \end_inset
21961
21962 - The compiler will optimize code generation towards compact code, possibly
21963  at the expense of code speed.
21964  Currently this has little effect.
21965 \end_layout
21966
21967 \begin_layout Itemize
21968
21969 \series bold
21970 opt_code_balanced
21971 \series default
21972  
21973 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21974
21975 \end_inset
21976
21977 - The compiler will attempt to generate code that is both compact and fast,
21978  as long as meeting one goal is not a detriment to the other (this is the
21979  default).
21980  
21981 \end_layout
21982
21983 \begin_layout Itemize
21984
21985 \series bold
21986 std_sdcc89
21987 \series default
21988  
21989 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21990
21991 \end_inset
21992
21993 - Generally follow the C89 standard, but allow SDCC features that conflict
21994  with the standard (default).
21995 \end_layout
21996
21997 \begin_layout Itemize
21998
21999 \series bold
22000 std_c89
22001 \series default
22002  
22003 \begin_inset LatexCommand \index{\#pragma std\_c89}
22004
22005 \end_inset
22006
22007 - Follow the C89 standard and disable SDCC features that conflict with the
22008  standard.
22009 \end_layout
22010
22011 \begin_layout Itemize
22012
22013 \series bold
22014 std_sdcc99
22015 \series default
22016  
22017 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22018
22019 \end_inset
22020
22021 - Generally follow the C99 standard, but allow SDCC features that conflict
22022  with the standard (incomplete support).
22023 \end_layout
22024
22025 \begin_layout Itemize
22026
22027 \series bold
22028 std_c99
22029 \series default
22030  
22031 \begin_inset LatexCommand \index{\#pragma std\_c99}
22032
22033 \end_inset
22034
22035 - Follow the C99 standard and disable SDCC features that conflict with the
22036  standard (incomplete support).
22037 \end_layout
22038
22039 \begin_layout Itemize
22040
22041 \series bold
22042 codeseg
22043 \series default
22044  <name>
22045 \begin_inset LatexCommand \index{\#pragma codeseg}
22046
22047 \end_inset
22048
22049 - Use this name (max.
22050  8 characters) for the code segment.
22051  See option -
22052 \begin_inset ERT
22053 status collapsed
22054
22055 \begin_layout Standard
22056
22057
22058 \backslash
22059 /
22060 \end_layout
22061
22062 \end_inset
22063
22064 -codeseg.
22065 \end_layout
22066
22067 \begin_layout Itemize
22068
22069 \series bold
22070 constseg
22071 \series default
22072  <name>
22073 \begin_inset LatexCommand \index{\#pragma constseg}
22074
22075 \end_inset
22076
22077 - Use this name (max.
22078  8 characters) for the const segment.
22079  See option -
22080 \begin_inset ERT
22081 status collapsed
22082
22083 \begin_layout Standard
22084
22085
22086 \backslash
22087 /
22088 \end_layout
22089
22090 \end_inset
22091
22092 -constseg.
22093 \end_layout
22094
22095 \begin_layout Standard
22096 The preprocessor SDCPP
22097 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22098
22099 \end_inset
22100
22101  supports the following #pragma directives:
22102 \end_layout
22103
22104 \begin_layout Itemize
22105
22106 \series bold
22107 pedantic_parse_number
22108 \series default
22109
22110 \begin_inset LatexCommand \index{pedantic}
22111
22112 \end_inset
22113
22114
22115 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22116
22117 \end_inset
22118
22119  (+ | -) 
22120 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22121
22122 \end_inset
22123
22124 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22125  properly and the macro LO_B(3) gets expanded.
22126  Default is off.
22127  See also the -
22128 \begin_inset ERT
22129 status collapsed
22130
22131 \begin_layout Standard
22132
22133
22134 \backslash
22135 /
22136 \end_layout
22137
22138 \end_inset
22139
22140 -pedantic-parse-number command line option 
22141 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22142
22143 \end_inset
22144
22145 .
22146  
22147 \newline
22148 Below is an example on how to use this pragma.
22149
22150 \emph on
22151  Note: this functionality is not in conformance with standard!
22152 \end_layout
22153
22154 \begin_layout Verse
22155
22156 \family typewriter
22157 #pragma pedantic_parse_number +
22158 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22159
22160 \end_inset
22161
22162
22163 \newline
22164
22165 \newline
22166 #define LO_B(x) ((x) & 0xff)
22167 \newline
22168
22169 \newline
22170 unsigned char foo(void)
22171 \newline
22172 {
22173 \newline
22174 \InsetSpace ~
22175 \InsetSpace ~
22176 \InsetSpace ~
22177 unsigned char c=0xfe-LO_B(3)
22178 ;
22179 \newline
22180
22181 \newline
22182 \InsetSpace ~
22183 \InsetSpace ~
22184 \InsetSpace ~
22185 return c;
22186 \newline
22187 }
22188 \newline
22189
22190 \end_layout
22191
22192 \begin_layout Itemize
22193
22194 \series bold
22195 preproc_asm
22196 \series default
22197
22198 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22199
22200 \end_inset
22201
22202  (+ | -) - switch _asm _endasm block preprocessing on / off.
22203  Default is on.
22204  You use this prama to define multilines of assembly code.
22205  This will prevent the preprocessor from changing the formating required
22206  by assembly code.
22207  Below is an example on how to use this pragma.
22208 \end_layout
22209
22210 \begin_layout Verse
22211
22212 \family typewriter
22213 #pragma preproc_asm -
22214 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22215
22216 \end_inset
22217
22218
22219 \newline
22220 #define MYDELAY _asm
22221 \newline
22222 \InsetSpace ~
22223 \InsetSpace ~
22224 \InsetSpace ~
22225 nop ;my assembly comment...
22226 \newline
22227 \InsetSpace ~
22228 \InsetSpace ~
22229 \InsetSpace ~
22230 nop
22231 \newline
22232 \InsetSpace ~
22233 \InsetSpace ~
22234 \InsetSpace ~
22235 nop
22236 \newline
22237 _endasm
22238 \newline
22239 #pragma preproc_asm
22240  +
22241 \newline
22242
22243 \newline
22244 void foo (void) 
22245 \newline
22246
22247 \newline
22248 \InsetSpace ~
22249 \InsetSpace ~
22250 \InsetSpace ~
22251  ...
22252  
22253 \newline
22254 \InsetSpace ~
22255 \InsetSpace ~
22256 \InsetSpace ~
22257  MYDELAY;
22258 \newline
22259 \InsetSpace ~
22260 \InsetSpace ~
22261 \InsetSpace ~
22262  ...
22263  
22264 \newline
22265
22266 \newline
22267
22268 \end_layout
22269
22270 \begin_layout Itemize
22271
22272 \series bold
22273 sdcc_hash
22274 \series default
22275
22276 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22277
22278 \end_inset
22279
22280  (+ | -) - Allow "naked" hash in macro definition, for example:
22281 \newline
22282
22283 \family typewriter
22284 #define DIR_LO(x) #(x & 0xff)
22285 \family default
22286
22287 \newline
22288 Default is off.
22289  Below is an example on how to use this pragma.
22290 \end_layout
22291
22292 \begin_layout Verse
22293
22294 \family typewriter
22295 #pragma preproc_asm +
22296 \newline
22297 #pragma sdcc_hash +
22298 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22299
22300 \end_inset
22301
22302
22303 \newline
22304
22305 \newline
22306 #define ROMCALL(x) 
22307 \backslash
22308
22309 \newline
22310 \InsetSpace ~
22311 \InsetSpace ~
22312 \InsetSpace ~
22313 mov R6_B3, #(x & 0xff) 
22314 \backslash
22315
22316 \newline
22317 \InsetSpace ~
22318 \InsetSpace ~
22319 \InsetSpace ~
22320 mov R7_B3, #((x >> 8) & 0xff) 
22321 \backslash
22322
22323 \newline
22324 \InsetSpace ~
22325 \InsetSpace ~
22326 \InsetSpace ~
22327 lcall __romcall
22328 \newline
22329
22330 \newline
22331 ...
22332 \newline
22333 _asm
22334 \newline
22335 ROMCALL(72)
22336 \newline
22337 _endasm;
22338 \newline
22339 ...
22340 \newline
22341
22342 \end_layout
22343
22344 \begin_layout Standard
22345 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22346 ons which might cause the compiler to generate extra stack and/or data space
22347  to store compiler generated temporary variables.
22348  This usually happens in large functions.
22349  Pragma directives should be used as shown in the following example, they
22350  are used to control options and optimizations for a given function.
22351  
22352 \end_layout
22353
22354 \begin_layout Verse
22355
22356 \family typewriter
22357 #pragma save
22358 \begin_inset LatexCommand \index{\#pragma save}
22359
22360 \end_inset
22361
22362  \InsetSpace ~
22363 \InsetSpace ~
22364 \InsetSpace ~
22365 \InsetSpace ~
22366 \InsetSpace ~
22367 \InsetSpace ~
22368 \InsetSpace ~
22369 /* save the current settings */ 
22370 \newline
22371 #pragma nogcse
22372 \begin_inset LatexCommand \index{\#pragma nogcse}
22373
22374 \end_inset
22375
22376  \InsetSpace ~
22377 \InsetSpace ~
22378 \InsetSpace ~
22379 \InsetSpace ~
22380 \InsetSpace ~
22381 /* turnoff global subexpression elimination */ 
22382 \newline
22383 #pragma noinduction
22384 \begin_inset LatexCommand \index{\#pragma noinduction}
22385
22386 \end_inset
22387
22388  /* turn off induction optimizations */ 
22389 \newline
22390 int foo () 
22391 \newline
22392
22393 \newline
22394 \InsetSpace ~
22395  \InsetSpace ~
22396  ...
22397  
22398 \newline
22399 \InsetSpace ~
22400  \InsetSpace ~
22401  /* large code */ 
22402 \newline
22403 \InsetSpace ~
22404  \InsetSpace ~
22405  ...
22406  
22407 \newline
22408
22409 \newline
22410 #pragma restore
22411 \begin_inset LatexCommand \index{\#pragma restore}
22412
22413 \end_inset
22414
22415  /* turn the optimizations back on */
22416 \end_layout
22417
22418 \begin_layout Standard
22419 The compiler will generate a warning message when extra space is allocated.
22420  It is strongly recommended that the save and restore pragmas be used when
22421  changing options for a function.
22422 \newline
22423
22424 \newline
22425
22426 \newline
22427
22428 \end_layout
22429
22430 \begin_layout Section
22431 Defines Created by the Compiler
22432 \end_layout
22433
22434 \begin_layout Standard
22435 The compiler creates the following #defines
22436 \begin_inset LatexCommand \index{\#defines}
22437
22438 \end_inset
22439
22440
22441 \begin_inset LatexCommand \index{Defines created by the compiler}
22442
22443 \end_inset
22444
22445 :
22446 \newline
22447
22448 \end_layout
22449
22450 \begin_layout Standard
22451 \begin_inset Tabular
22452 <lyxtabular version="3" rows="11" columns="2">
22453 <features>
22454 <column alignment="left" valignment="top" leftline="true" width="3in">
22455 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22456 <row topline="true" bottomline="true">
22457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22458 \begin_inset Text
22459
22460 \begin_layout Standard
22461
22462 \series bold
22463 #define
22464 \end_layout
22465
22466 \end_inset
22467 </cell>
22468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22469 \begin_inset Text
22470
22471 \begin_layout Standard
22472
22473 \series bold
22474 Description
22475 \end_layout
22476
22477 \end_inset
22478 </cell>
22479 </row>
22480 <row topline="true">
22481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22482 \begin_inset Text
22483
22484 \begin_layout Standard
22485 SDCC
22486 \begin_inset LatexCommand \index{SDCC}
22487
22488 \end_inset
22489
22490  
22491 \end_layout
22492
22493 \end_inset
22494 </cell>
22495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22496 \begin_inset Text
22497
22498 \begin_layout Standard
22499 Always defined.
22500  Since version 2.5.6 the version number as an int (ex.
22501  256)
22502 \end_layout
22503
22504 \end_inset
22505 </cell>
22506 </row>
22507 <row topline="true">
22508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22509 \begin_inset Text
22510
22511 \begin_layout Standard
22512 SDCC_mcs51
22513 \begin_inset LatexCommand \index{SDCC\_mcs51}
22514
22515 \end_inset
22516
22517  or SDCC_ds390
22518 \begin_inset LatexCommand \index{SDCC\_ds390}
22519
22520 \end_inset
22521
22522  or SDCC_z80
22523 \begin_inset LatexCommand \index{SDCC\_z80}
22524
22525 \end_inset
22526
22527 , etc.
22528 \end_layout
22529
22530 \end_inset
22531 </cell>
22532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22533 \begin_inset Text
22534
22535 \begin_layout Standard
22536 depending on the model used (e.g.: -mds390)
22537 \end_layout
22538
22539 \end_inset
22540 </cell>
22541 </row>
22542 <row topline="true">
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22544 \begin_inset Text
22545
22546 \begin_layout Standard
22547 __mcs51
22548 \begin_inset LatexCommand \index{\_\_mcs51}
22549
22550 \end_inset
22551
22552 , __ds390
22553 \begin_inset LatexCommand \index{\_\_ds390}
22554
22555 \end_inset
22556
22557 , __hc08
22558 \begin_inset LatexCommand \index{\_\_hc08}
22559
22560 \end_inset
22561
22562 , __z80
22563 \begin_inset LatexCommand \index{\_\_z80}
22564
22565 \end_inset
22566
22567 , etc
22568 \end_layout
22569
22570 \end_inset
22571 </cell>
22572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22573 \begin_inset Text
22574
22575 \begin_layout Standard
22576 depending on the model used (e.g.
22577  -mz80)
22578 \end_layout
22579
22580 \end_inset
22581 </cell>
22582 </row>
22583 <row topline="true">
22584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22585 \begin_inset Text
22586
22587 \begin_layout Standard
22588 SDCC_STACK_AUTO
22589 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22590
22591 \end_inset
22592
22593
22594 \end_layout
22595
22596 \end_inset
22597 </cell>
22598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22599 \begin_inset Text
22600
22601 \begin_layout Standard
22602 when 
22603 \emph on
22604 -
22605 \begin_inset ERT
22606 status collapsed
22607
22608 \begin_layout Standard
22609
22610
22611 \backslash
22612 /
22613 \end_layout
22614
22615 \end_inset
22616
22617 -stack-auto
22618 \emph default
22619  option is used
22620 \end_layout
22621
22622 \end_inset
22623 </cell>
22624 </row>
22625 <row topline="true">
22626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22627 \begin_inset Text
22628
22629 \begin_layout Standard
22630 SDCC_MODEL_SMALL
22631 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22632
22633 \end_inset
22634
22635
22636 \end_layout
22637
22638 \end_inset
22639 </cell>
22640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22641 \begin_inset Text
22642
22643 \begin_layout Standard
22644 when 
22645 \emph on
22646 -
22647 \begin_inset ERT
22648 status collapsed
22649
22650 \begin_layout Standard
22651
22652
22653 \backslash
22654 /
22655 \end_layout
22656
22657 \end_inset
22658
22659 -model-small
22660 \emph default
22661  is used
22662 \end_layout
22663
22664 \end_inset
22665 </cell>
22666 </row>
22667 <row topline="true">
22668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22669 \begin_inset Text
22670
22671 \begin_layout Standard
22672 SDCC_MODEL_MEDIUM
22673 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22674
22675 \end_inset
22676
22677
22678 \end_layout
22679
22680 \end_inset
22681 </cell>
22682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22683 \begin_inset Text
22684
22685 \begin_layout Standard
22686 when 
22687 \emph on
22688 -
22689 \begin_inset ERT
22690 status collapsed
22691
22692 \begin_layout Standard
22693
22694
22695 \backslash
22696 /
22697 \end_layout
22698
22699 \end_inset
22700
22701 -model-medium
22702 \emph default
22703  is used
22704 \end_layout
22705
22706 \end_inset
22707 </cell>
22708 </row>
22709 <row topline="true">
22710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22711 \begin_inset Text
22712
22713 \begin_layout Standard
22714 SDCC_MODEL_LARGE
22715 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22716
22717 \end_inset
22718
22719
22720 \end_layout
22721
22722 \end_inset
22723 </cell>
22724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22725 \begin_inset Text
22726
22727 \begin_layout Standard
22728 when 
22729 \emph on
22730 -
22731 \begin_inset ERT
22732 status collapsed
22733
22734 \begin_layout Standard
22735
22736
22737 \backslash
22738 /
22739 \end_layout
22740
22741 \end_inset
22742
22743 -model-large
22744 \emph default
22745  is used
22746 \end_layout
22747
22748 \end_inset
22749 </cell>
22750 </row>
22751 <row topline="true">
22752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22753 \begin_inset Text
22754
22755 \begin_layout Standard
22756 SDCC_USE_XSTACK
22757 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22758
22759 \end_inset
22760
22761
22762 \end_layout
22763
22764 \end_inset
22765 </cell>
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22767 \begin_inset Text
22768
22769 \begin_layout Standard
22770 when 
22771 \emph on
22772 -
22773 \begin_inset ERT
22774 status collapsed
22775
22776 \begin_layout Standard
22777
22778
22779 \backslash
22780 /
22781 \end_layout
22782
22783 \end_inset
22784
22785 -xstack
22786 \emph default
22787  option is used
22788 \end_layout
22789
22790 \end_inset
22791 </cell>
22792 </row>
22793 <row topline="true">
22794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22795 \begin_inset Text
22796
22797 \begin_layout Standard
22798 SDCC_STACK_TENBIT
22799 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22800
22801 \end_inset
22802
22803  
22804 \end_layout
22805
22806 \end_inset
22807 </cell>
22808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22809 \begin_inset Text
22810
22811 \begin_layout Standard
22812 when 
22813 \emph on
22814 -mds390
22815 \emph default
22816  is used
22817 \end_layout
22818
22819 \end_inset
22820 </cell>
22821 </row>
22822 <row topline="true" bottomline="true">
22823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22824 \begin_inset Text
22825
22826 \begin_layout Standard
22827 SDCC_MODEL_FLAT24
22828 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22829
22830 \end_inset
22831
22832
22833 \end_layout
22834
22835 \end_inset
22836 </cell>
22837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22838 \begin_inset Text
22839
22840 \begin_layout Standard
22841 when 
22842 \emph on
22843 -mds390
22844 \emph default
22845  is used
22846 \end_layout
22847
22848 \end_inset
22849 </cell>
22850 </row>
22851 </lyxtabular>
22852
22853 \end_inset
22854
22855
22856 \end_layout
22857
22858 \begin_layout Chapter
22859 Notes on supported Processors
22860 \end_layout
22861
22862 \begin_layout Section
22863 MCS51 variants
22864 \begin_inset LatexCommand \label{sub:MCS51-variants}
22865
22866 \end_inset
22867
22868
22869 \begin_inset LatexCommand \index{MCS51 variants}
22870
22871 \end_inset
22872
22873
22874 \end_layout
22875
22876 \begin_layout Standard
22877 MCS51 processors are available from many vendors and come in many different
22878  flavours.
22879  While they might differ considerably in respect to Special Function Registers
22880  the core MCS51 is usually not modified or is kept compatible.
22881  
22882 \end_layout
22883
22884 \begin_layout Subsection
22885 pdata access by SFR 
22886 \end_layout
22887
22888 \begin_layout Standard
22889 With the upcome of devices with internal xdata and flash memory devices
22890  using port P2
22891 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22892
22893 \end_inset
22894
22895  as dedicated I/O port is becoming more popular.
22896  Switching the high byte for pdata
22897 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22898
22899 \end_inset
22900
22901  access which was formerly done by port P2 is then achieved by a Special
22902  Function Register
22903 \begin_inset LatexCommand \index{sfr}
22904
22905 \end_inset
22906
22907 .
22908  In well-established MCS51 tradition the address of this 
22909 \emph on
22910 sfr
22911 \emph default
22912  is where the chip designers decided to put it.
22913  Needless to say that they didn't agree on a common name either.
22914  So that the startup code can correctly initialize xdata variables, you
22915  should define an sfr with the name _XPAGE
22916 \family typewriter
22917
22918 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22919
22920 \end_inset
22921
22922
22923 \family default
22924  at the appropriate location if the default, port P2, is not used for this.
22925  Some examples are:
22926 \end_layout
22927
22928 \begin_layout Verse
22929
22930 \family typewriter
22931 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22932  MPAGE */
22933 \end_layout
22934
22935 \begin_layout Verse
22936
22937 \family typewriter
22938 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22939  a.k.a.
22940  MPAGE */
22941 \end_layout
22942
22943 \begin_layout Verse
22944
22945 \family typewriter
22946 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22947  XPAGE */
22948 \end_layout
22949
22950 \begin_layout Verse
22951
22952 \family typewriter
22953 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22954  EMI0CN */
22955 \end_layout
22956
22957 \begin_layout Verse
22958
22959 \family typewriter
22960 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22961  EMI0CN */
22962 \end_layout
22963
22964 \begin_layout Standard
22965 For more exotic implementations further customizations may be needed.
22966  See section 
22967 \begin_inset LatexCommand \ref{sub:Startup-Code}
22968
22969 \end_inset
22970
22971  for other possibilities.
22972 \end_layout
22973
22974 \begin_layout Subsection
22975 Other Features available by SFR
22976 \end_layout
22977
22978 \begin_layout Standard
22979 Some MCS51 variants offer features like Double DPTR
22980 \begin_inset LatexCommand \index{DPTR}
22981
22982 \end_inset
22983
22984 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22985  These are currently not used for the MCS51 port.
22986  If you absolutely need them you can fall back to inline assembly or submit
22987  a patch to SDCC.
22988 \begin_inset VSpace bigskip
22989 \end_inset
22990
22991
22992 \end_layout
22993
22994 \begin_layout Section
22995 DS400 port
22996 \end_layout
22997
22998 \begin_layout Standard
22999 The DS80C400
23000 \begin_inset LatexCommand \index{DS80C400}
23001
23002 \end_inset
23003
23004
23005 \begin_inset LatexCommand \index{DS400}
23006
23007 \end_inset
23008
23009  microcontroller has a rich set of peripherals.
23010  In its built-in ROM library it includes functions to access some of the
23011  features, among them is a TCP stack with IP4 and IP6 support.
23012  Library headers (currently in beta status) and other files are provided
23013  at 
23014 \size footnotesize
23015
23016 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23017
23018 \end_inset
23019
23020 .
23021  
23022 \begin_inset VSpace bigskip
23023 \end_inset
23024
23025
23026 \end_layout
23027
23028 \begin_layout Section
23029 The Z80 and gbz80 port
23030 \end_layout
23031
23032 \begin_layout Standard
23033 SDCC can target both the Zilog Z80
23034 \begin_inset LatexCommand \index{Z80}
23035
23036 \end_inset
23037
23038  and the Nintendo Gameboy's Z80-like gbz80
23039 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23040
23041 \end_inset
23042
23043 .
23044  The Z80 port is passed through the same 
23045 \emph on
23046 regressions tests
23047 \begin_inset LatexCommand \index{Regression test}
23048
23049 \end_inset
23050
23051
23052 \emph default
23053  (see section 
23054 \begin_inset LatexCommand \ref{sec:Quality-control}
23055
23056 \end_inset
23057
23058 ) as the MCS51 and DS390 ports, so floating point support, support for long
23059  variables and bitfield support is fine.
23060  See mailing lists and forums about interrupt routines.
23061 \end_layout
23062
23063 \begin_layout Standard
23064 As always, the code is the authoritative reference - see z80/ralloc.c and
23065  z80/gen.c.
23066  The stack
23067 \begin_inset LatexCommand \index{Z80!stack}
23068
23069 \end_inset
23070
23071  frame is similar to that generated by the IAR Z80 compiler.
23072  IX is used as the base pointer, HL and IY are used as a temporary registers,
23073  and BC and DE are available for holding variables.
23074  Return values
23075 \begin_inset LatexCommand \index{Z80!return value}
23076
23077 \end_inset
23078
23079  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23080  bytes).
23081  The gbz80 port use the same set of registers for the return values, but
23082  in a different order of significance: E (one byte), DE (two bytes), or
23083  HLDE (four bytes).
23084 \begin_inset VSpace bigskip
23085 \end_inset
23086
23087
23088 \end_layout
23089
23090 \begin_layout Section
23091 The HC08 port
23092 \end_layout
23093
23094 \begin_layout Standard
23095 The port to the Freescale/Motorola HC08
23096 \begin_inset LatexCommand \index{HC08}
23097
23098 \end_inset
23099
23100  family has been added in October 2003, and is still undergoing some basic
23101  development.
23102  The code generator is complete, but the register allocation is still quite
23103  unoptimized.
23104  Some of the SDCC's standard C library functions have embedded non-HC08
23105  inline assembly and so are not yet usable.
23106 \end_layout
23107
23108 \begin_layout Standard
23109 The HC08 port passes the regression test suite (see section 
23110 \begin_inset LatexCommand \ref{sec:Quality-control}
23111
23112 \end_inset
23113
23114 ).
23115 \begin_inset VSpace bigskip
23116 \end_inset
23117
23118
23119 \newpage
23120
23121 \end_layout
23122
23123 \begin_layout Section
23124 The PIC14
23125 \begin_inset LatexCommand \index{PIC14}
23126
23127 \end_inset
23128
23129  port
23130 \end_layout
23131
23132 \begin_layout Standard
23133 The PIC14 port adds support for Microchip
23134 \begin_inset LatexCommand \index{Microchip}
23135
23136 \end_inset
23137
23138
23139 \begin_inset Formula $^{\text{TM}}$
23140 \end_inset
23141
23142  PIC
23143 \begin_inset LatexCommand \index{PIC14}
23144
23145 \end_inset
23146
23147
23148 \begin_inset Formula $^{\text{TM}}$
23149 \end_inset
23150
23151  MCUs with 14 bit wide instructions.
23152  This port is not yet mature and still lacks many features.
23153  However, it can work for simple code.
23154 \end_layout
23155
23156 \begin_layout Standard
23157 Currently supported devices include:
23158 \end_layout
23159
23160 \begin_layout Standard
23161 12F: 629, 635, 675, 683
23162 \end_layout
23163
23164 \begin_layout Standard
23165 16C: 432, 433
23166 \end_layout
23167
23168 \begin_layout Standard
23169 16C: 554, 557, 558
23170 \end_layout
23171
23172 \begin_layout Standard
23173 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23174 \end_layout
23175
23176 \begin_layout Standard
23177 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23178  781, 782
23179 \end_layout
23180
23181 \begin_layout Standard
23182 16C: 925, 926
23183 \end_layout
23184
23185 \begin_layout Standard
23186 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23187  689, 690
23188 \end_layout
23189
23190 \begin_layout Standard
23191 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23192 \end_layout
23193
23194 \begin_layout Standard
23195 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23196  877, 877a, 88
23197 \end_layout
23198
23199 \begin_layout Standard
23200 16F: 913, 914, 916, 917
23201 \end_layout
23202
23203 \begin_layout Standard
23204 An up-to-date list of currently supported devices can be obtained via 
23205 \family typewriter
23206 sdcc -mpic14 -phelp foo.c
23207 \family default
23208  (foo.c must exist...).
23209 \end_layout
23210
23211 \begin_layout Subsection
23212 PIC Code Pages
23213 \begin_inset LatexCommand \index{code page (pic14)}
23214
23215 \end_inset
23216
23217  and Memory Banks
23218 \begin_inset LatexCommand \index{Memory bank (pic14)}
23219
23220 \end_inset
23221
23222
23223 \end_layout
23224
23225 \begin_layout Standard
23226 The linker organizes allocation for the code page and RAM banks.
23227  It does not have intimate knowledge of the code flow.
23228  It will put all the code section of a single .asm file into a single code
23229  page.
23230  In order to make use of multiple code pages, separate asm files must be
23231  used.
23232  The compiler assigns all 
23233 \emph on
23234 static
23235 \emph default
23236  functions of a single .c file into the same code page.
23237 \newline
23238
23239 \newline
23240 To get the best results,
23241  follow these guidelines:
23242 \end_layout
23243
23244 \begin_layout Enumerate
23245 Make local functions static, as non static functions require code page selection
23246  overhead.
23247 \newline
23248 Due to the way sdcc handles functions, place called functions prior
23249  to calling functions in the file wherever possible: Otherwise sdcc will
23250  insert unneccessary pagesel directives around the call, believing that
23251  the called function is externally defined.
23252 \end_layout
23253
23254 \begin_layout Enumerate
23255 For devices that have multiple code pages it is more efficient to use the
23256  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23257  but only 2 files for the 16F874.
23258  This way the linker can put the code for each file into different code
23259  pages and there will be less page selection overhead.
23260 \end_layout
23261
23262 \begin_layout Enumerate
23263 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23264  instruction set), use `unsigned char' wherever possible instead of `int'.
23265 \end_layout
23266
23267 \begin_layout Subsection
23268 Adding New Devices to the Port 
23269 \end_layout
23270
23271 \begin_layout Standard
23272 Adding support for a new 14
23273 \begin_inset ERT
23274 status open
23275
23276 \begin_layout Standard
23277
23278
23279 \backslash
23280 ,
23281 \end_layout
23282
23283 \end_inset
23284
23285 bit PIC MCU requires the following steps:
23286 \end_layout
23287
23288 \begin_layout Enumerate
23289 Create a new device description.
23290 \newline
23291 Each device is described in two files: pic16f*.h
23292  and pic16f*.c.
23293  These files primarily define SFRs, structs to access their bits, and symbolic
23294  configuration options.
23295  Both files can be generated from gputils' .inc files using the perl script
23296  
23297 \family typewriter
23298 support/scripts/inc2h.pl
23299 \family default
23300 .
23301  This file also contains further instructions on how to proceed.
23302 \end_layout
23303
23304 \begin_layout Enumerate
23305 Copy the .h file into SDCC's include path and either add the .c file to your
23306  project or copy it to 
23307 \family typewriter
23308 device/lib/pic/libdev
23309 \family default
23310 .
23311  Afterwards, rebuild and install the libraries.
23312 \end_layout
23313
23314 \begin_layout Enumerate
23315 Edit pic14devices.txt in SDCC's include path (
23316 \family typewriter
23317 device/include/pic/
23318 \family default
23319  in the source tree or 
23320 \family typewriter
23321 /usr/local/share/sdcc/include/pic
23322 \family default
23323  after installation).
23324 \newline
23325 You need to add a device specification here to make
23326  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23327  the compiler.
23328  Probably you can copy and modify an existing entry.
23329  The file format is documented at the top of the file.
23330 \end_layout
23331
23332 \begin_layout Subsection
23333 Interrupt Code
23334 \end_layout
23335
23336 \begin_layout Standard
23337 For the interrupt function, use the keyword `__interrupt'
23338 \begin_inset LatexCommand \index{PIC14!interrupt}
23339
23340 \end_inset
23341
23342  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23343  there to avoid a syntax error - it ought to be fixed).
23344  E.g.:
23345 \end_layout
23346
23347 \begin_layout Verse
23348
23349 \family typewriter
23350 void Intr(void) __interrupt 0
23351 \newline
23352 {
23353 \newline
23354 \InsetSpace ~
23355 \InsetSpace ~
23356 T0IF = 0; /* Clear timer interrupt */
23357 \newline
23358 }
23359 \end_layout
23360
23361 \begin_layout Subsection
23362 Linking and Assembling
23363 \end_layout
23364
23365 \begin_layout Standard
23366 For assembling you can use either GPUTILS'
23367 \begin_inset LatexCommand \index{gputils (pic tools)}
23368
23369 \end_inset
23370
23371  gpasm.exe or MPLAB's mpasmwin.exe.
23372  GPUTILS are available from 
23373 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23374
23375 \end_inset
23376
23377 .
23378  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23379  If you use MPLAB and an interrupt function then the linker script file
23380  vectors section will need to be enlarged to link with mplink.
23381 \newline
23382
23383 \newline
23384 Here is a 
23385 \family typewriter
23386 Makefile
23387 \family default
23388  using GPUTILS:
23389 \end_layout
23390
23391 \begin_layout Verse
23392
23393 \family typewriter
23394 .c.o:
23395 \newline
23396 \InsetSpace ~
23397 \InsetSpace ~
23398 \InsetSpace ~
23399 \InsetSpace ~
23400 \InsetSpace ~
23401 \InsetSpace ~
23402 \InsetSpace ~
23403 \InsetSpace ~
23404 sdcc -V -mpic14 -p16f877 -c $< 
23405 \newline
23406
23407 \newline
23408 $(PRJ).hex: $(OBJS) 
23409 \newline
23410 \InsetSpace ~
23411 \InsetSpace ~
23412 \InsetSpace ~
23413 \InsetSpace ~
23414 \InsetSpace ~
23415 \InsetSpace ~
23416 \InsetSpace ~
23417 \InsetSpace ~
23418 gplink -m -s $(PRJ).lkr
23419  -o $(PRJ).hex $(OBJS) libsdcc.lib
23420 \end_layout
23421
23422 \begin_layout Standard
23423 Here is a 
23424 \family typewriter
23425 Makefile
23426 \family default
23427  using MPLAB:
23428 \end_layout
23429
23430 \begin_layout Verse
23431
23432 \family typewriter
23433 .c.o: 
23434 \newline
23435 \InsetSpace ~
23436 \InsetSpace ~
23437 \InsetSpace ~
23438 \InsetSpace ~
23439 \InsetSpace ~
23440 \InsetSpace ~
23441 \InsetSpace ~
23442 \InsetSpace ~
23443 sdcc -S -V -mpic14 -p16f877 $< 
23444 \newline
23445 \InsetSpace ~
23446 \InsetSpace ~
23447 \InsetSpace ~
23448 \InsetSpace ~
23449 \InsetSpace ~
23450 \InsetSpace ~
23451 \InsetSpace ~
23452 \InsetSpace ~
23453 mpasmwin /q /o $*.asm
23454 \newline
23455
23456 \newline
23457 $(PRJ).hex: $(OBJS)
23458  
23459 \newline
23460 \InsetSpace ~
23461 \InsetSpace ~
23462 \InsetSpace ~
23463 \InsetSpace ~
23464 \InsetSpace ~
23465 \InsetSpace ~
23466 \InsetSpace ~
23467 \InsetSpace ~
23468 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23469 \end_layout
23470
23471 \begin_layout Standard
23472 Please note that indentations within a
23473 \family typewriter
23474  Makefile
23475 \family default
23476  have to be done with a tabulator character.
23477 \end_layout
23478
23479 \begin_layout Subsection
23480 Command-Line Options
23481 \end_layout
23482
23483 \begin_layout Standard
23484 Besides the switches common to all SDCC backends, the PIC14 port accepts
23485  the following options (for an updated list see sdcc -
23486 \begin_inset ERT
23487 status collapsed
23488
23489 \begin_layout Standard
23490
23491
23492 \backslash
23493 /
23494 \end_layout
23495
23496 \end_inset
23497
23498 -help):
23499 \end_layout
23500
23501 \begin_layout Description
23502 -
23503 \begin_inset ERT
23504 status collapsed
23505
23506 \begin_layout Standard
23507
23508
23509 \backslash
23510 /
23511 \end_layout
23512
23513 \end_inset
23514
23515 -debug-xtra
23516 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23517
23518 \end_inset
23519
23520  emit debug info in assembly output
23521 \end_layout
23522
23523 \begin_layout Description
23524 -
23525 \begin_inset ERT
23526 status collapsed
23527
23528 \begin_layout Standard
23529
23530
23531 \backslash
23532 /
23533 \end_layout
23534
23535 \end_inset
23536
23537 -no-pcode-opt
23538 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23539
23540 \end_inset
23541
23542  disable (slightly faulty) optimization on pCode
23543 \end_layout
23544
23545 \begin_layout Description
23546 -
23547 \begin_inset ERT
23548 status collapsed
23549
23550 \begin_layout Standard
23551
23552
23553 \backslash
23554 /
23555 \end_layout
23556
23557 \end_inset
23558
23559 -stack-loc
23560 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23561
23562 \end_inset
23563
23564  sets the lowest address of the argument passing stack (defaults to a suitably
23565  large shared databank to reduce BANKSEL overhead)
23566 \end_layout
23567
23568 \begin_layout Description
23569 -
23570 \begin_inset ERT
23571 status collapsed
23572
23573 \begin_layout Standard
23574
23575
23576 \backslash
23577 /
23578 \end_layout
23579
23580 \end_inset
23581
23582 -stack-size
23583 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23584
23585 \end_inset
23586
23587  sets the size if the argument passing stack (default: 16, minimum: 4)
23588 \end_layout
23589
23590 \begin_layout Subsection
23591 Environment Variables
23592 \end_layout
23593
23594 \begin_layout Standard
23595 The PIC14 port recognizes the following environment variables:
23596 \end_layout
23597
23598 \begin_layout Description
23599 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23600  register (the ones called r0xNNNN) in a section of its own.
23601  By default (if this variable is unset), sdcc tries to cluster registers
23602  in sections in order to reduce the BANKSEL overhead when accessing them.
23603 \end_layout
23604
23605 \begin_layout Subsection
23606 The Library
23607 \end_layout
23608
23609 \begin_layout Standard
23610 The PIC14 library currently only contains support routines required by the
23611  compiler to implement multiplication, division, and floating point support.
23612  No libc-like replacement is available at the moment, though many of the
23613  common sdcc library sources (in 
23614 \family typewriter
23615 device/lib
23616 \family default
23617 ) should also compile with the PIC14 port.
23618 \end_layout
23619
23620 \begin_layout Subsubsection
23621 error: missing definition for symbol ``__gptrget1''
23622 \end_layout
23623
23624 \begin_layout Standard
23625 The PIC14 port uses library routines to provide more complex operations
23626  like multiplication, division/modulus and (generic) pointer dereferencing.
23627  In order to add these routines to your project, you must link with PIC14's
23628  
23629 \family typewriter
23630 libsdcc.lib
23631 \family default
23632 .
23633  For single source file projects this is done automatically, more complex
23634  projects must add 
23635 \family typewriter
23636 libsdcc.lib
23637 \family default
23638  to the linker's arguments.
23639  Make sure you also add an include path for the library (using the -I switch
23640  to the linker)!
23641 \end_layout
23642
23643 \begin_layout Subsubsection
23644 Processor mismatch in file ``XXX''.
23645 \end_layout
23646
23647 \begin_layout Standard
23648 This warning can usually be ignored due to the very good compatibility amongst
23649  14
23650 \begin_inset ERT
23651 status open
23652
23653 \begin_layout Standard
23654
23655
23656 \backslash
23657 ,
23658 \end_layout
23659
23660 \end_inset
23661
23662 bit PIC
23663 \begin_inset LatexCommand \index{PIC14}
23664
23665 \end_inset
23666
23667  devices.
23668 \end_layout
23669
23670 \begin_layout Standard
23671 You might also consider recompiling the library for your specific device
23672  by changing the ARCH=p16f877 (default target) entry in 
23673 \family typewriter
23674 device/lib/pic/Makefile.in
23675 \family default
23676  and 
23677 \family typewriter
23678 device/lib/pic/Makefile
23679 \family default
23680  to reflect your device.
23681  This might even improve performance for smaller devices as unneccesary
23682  BANKSELs might be removed.
23683 \end_layout
23684
23685 \begin_layout Subsection
23686 Known Bugs
23687 \end_layout
23688
23689 \begin_layout Subsubsection
23690 Function arguments
23691 \end_layout
23692
23693 \begin_layout Standard
23694 Functions with variable argument lists (like printf) are not yet supported.
23695  Similarly, taking the argument of the first argument passed into a function
23696  does not work: It is currently passed in WREG and has no address...
23697 \end_layout
23698
23699 \begin_layout Subsubsection
23700 Regression tests fail
23701 \end_layout
23702
23703 \begin_layout Standard
23704 Though the small subset of regression tests in src/regression passes, SDCC
23705  regression test suite does not, indicating that there are still major bugs
23706  in the port.
23707  However, many smaller projects have successfully used SDCC in the past...
23708 \end_layout
23709
23710 \begin_layout Standard
23711
23712 \size footnotesize
23713
23714 \newpage
23715
23716 \end_layout
23717
23718 \begin_layout Section
23719 The PIC16
23720 \begin_inset LatexCommand \index{PIC16}
23721
23722 \end_inset
23723
23724  port
23725 \end_layout
23726
23727 \begin_layout Standard
23728 The PIC16 port adds support for Microchip
23729 \begin_inset LatexCommand \index{Microchip}
23730
23731 \end_inset
23732
23733
23734 \begin_inset Formula $^{\text{TM}}$
23735 \end_inset
23736
23737  PIC
23738 \begin_inset LatexCommand \index{PIC}
23739
23740 \end_inset
23741
23742
23743 \begin_inset Formula $^{\text{TM}}$
23744 \end_inset
23745
23746  MCUs with 16 bit wide instructions.
23747  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23748 ; devices supported by the port include:
23749 \end_layout
23750
23751 \begin_layout Standard
23752 18F: 242, 248, 252, 258, 442, 448, 452, 458
23753 \end_layout
23754
23755 \begin_layout Standard
23756 18F: 1220, 1320
23757 \end_layout
23758
23759 \begin_layout Standard
23760 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23761  2620
23762 \end_layout
23763
23764 \begin_layout Standard
23765 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23766  45j10, 4620
23767 \end_layout
23768
23769 \begin_layout Standard
23770 18F: 6520, 6620, 6680, 6720
23771 \end_layout
23772
23773 \begin_layout Standard
23774 18F: 8520, 8620, 8680, 8720
23775 \end_layout
23776
23777 \begin_layout Subsection
23778 Global Options
23779 \end_layout
23780
23781 \begin_layout Standard
23782 PIC16 port supports the standard command line arguments as supposed, with
23783  the exception of certain cases that will be mentioned in the following
23784  list:
23785 \end_layout
23786
23787 \begin_layout Description
23788 -
23789 \begin_inset ERT
23790 status collapsed
23791
23792 \begin_layout Standard
23793
23794
23795 \backslash
23796 /
23797 \end_layout
23798
23799 \end_inset
23800
23801 -callee-saves
23802 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23803
23804 \end_inset
23805
23806  See -
23807 \begin_inset ERT
23808 status collapsed
23809
23810 \begin_layout Standard
23811
23812
23813 \backslash
23814 /
23815 \end_layout
23816
23817 \end_inset
23818
23819 -all-callee-saves
23820 \end_layout
23821
23822 \begin_layout Description
23823 -
23824 \begin_inset ERT
23825 status collapsed
23826
23827 \begin_layout Standard
23828
23829
23830 \backslash
23831 /
23832 \end_layout
23833
23834 \end_inset
23835
23836 -fommit-frame-pointer
23837 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23838
23839 \end_inset
23840
23841  Frame pointer will be omitted when the function uses no local variables.
23842 \end_layout
23843
23844 \begin_layout Subsection
23845 Port Specific Options
23846 \begin_inset LatexCommand \index{Options PIC16}
23847
23848 \end_inset
23849
23850
23851 \end_layout
23852
23853 \begin_layout Standard
23854 The port specific options appear after the global options in the sdcc -
23855 \begin_inset ERT
23856 status collapsed
23857
23858 \begin_layout Standard
23859
23860
23861 \backslash
23862 /
23863 \end_layout
23864
23865 \end_inset
23866
23867 -help output.
23868 \end_layout
23869
23870 \begin_layout Subsubsection
23871 Code Generation Options
23872 \end_layout
23873
23874 \begin_layout Standard
23875 These options influence the generated assembler code.
23876 \end_layout
23877
23878 \begin_layout Description
23879 -
23880 \begin_inset ERT
23881 status collapsed
23882
23883 \begin_layout Standard
23884
23885
23886 \backslash
23887 /
23888 \end_layout
23889
23890 \end_inset
23891
23892 -pstack-model=[model] Used in conjuction with the command above.
23893  Defines the stack model to be used, valid stack models are:
23894 \end_layout
23895
23896 \begin_deeper
23897 \begin_layout List
23898 \labelwidthstring 00.00.0000
23899
23900 \emph on
23901 small
23902 \emph default
23903  Selects small stack model.
23904  8 bit stack and frame pointers.
23905  Supports 256 bytes stack size.
23906 \end_layout
23907
23908 \begin_layout List
23909 \labelwidthstring 00.00.0000
23910
23911 \emph on
23912 large
23913 \emph default
23914  Selects large stack model.
23915  16 bit stack and frame pointers.
23916  Supports 65536 bytes stack size.
23917 \end_layout
23918
23919 \end_deeper
23920 \begin_layout Description
23921 -
23922 \begin_inset ERT
23923 status collapsed
23924
23925 \begin_layout Standard
23926
23927
23928 \backslash
23929 /
23930 \end_layout
23931
23932 \end_inset
23933
23934 -pno-banksel Do not generate BANKSEL assembler directives.
23935 \end_layout
23936
23937 \begin_layout Description
23938 -
23939 \begin_inset ERT
23940 status collapsed
23941
23942 \begin_layout Standard
23943
23944
23945 \backslash
23946 /
23947 \end_layout
23948
23949 \end_inset
23950
23951 -extended Enable extended instruction set/literal offset addressing mode.
23952  Use with care!
23953 \end_layout
23954
23955 \begin_layout Subsubsection
23956 Optimization Options
23957 \end_layout
23958
23959 \begin_layout Description
23960 -
23961 \begin_inset ERT
23962 status collapsed
23963
23964 \begin_layout Standard
23965
23966
23967 \backslash
23968 /
23969 \end_layout
23970
23971 \end_inset
23972
23973 -obanksel=n Set optimization level for inserting BANKSELs.
23974 \newline
23975
23976 \end_layout
23977
23978 \begin_deeper
23979 \begin_layout List
23980 \labelwidthstring 00.00.0000
23981 0 no optimization
23982 \end_layout
23983
23984 \begin_layout List
23985 \labelwidthstring 00.00.0000
23986 1 checks previous used register and if it is the same then does not emit
23987  BANKSEL, accounts only for labels.
23988 \end_layout
23989
23990 \begin_layout List
23991 \labelwidthstring 00.00.0000
23992 2 tries to check the location of (even different) symbols and removes BANKSELs
23993  if they are in the same bank.
23994  
23995 \newline
23996
23997 \emph on
23998 Important: There might be problems if the linker script has data sections
23999  across bank borders!
24000 \end_layout
24001
24002 \end_deeper
24003 \begin_layout Description
24004 -
24005 \begin_inset ERT
24006 status collapsed
24007
24008 \begin_layout Standard
24009
24010
24011 \backslash
24012 /
24013 \end_layout
24014
24015 \end_inset
24016
24017 -denable-peeps Force the usage of peepholes.
24018  Use with care.
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 -optimize-goto Try to use (conditional) BRA instead of GOTO.
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 -optimize-cmp Try to optimize some compares.
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 -optimize-df Analyze the dataflow of the generated code and improve it.
24070 \end_layout
24071
24072 \begin_layout Subsubsection
24073 Assembling Options
24074 \end_layout
24075
24076 \begin_layout Description
24077 -
24078 \begin_inset ERT
24079 status collapsed
24080
24081 \begin_layout Standard
24082
24083
24084 \backslash
24085 /
24086 \end_layout
24087
24088 \end_inset
24089
24090 -asm= Sets the full path and name of an external assembler to call.
24091 \end_layout
24092
24093 \begin_layout Description
24094 -
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 -mplab-comp MPLAB
24108 \begin_inset LatexCommand \index{PIC16!MPLAB}
24109
24110 \end_inset
24111
24112  compatibility option.
24113  Currently only suppresses special gpasm directives.
24114 \end_layout
24115
24116 \begin_layout Subsubsection
24117 Linking Options
24118 \end_layout
24119
24120 \begin_layout Description
24121 -
24122 \begin_inset ERT
24123 status collapsed
24124
24125 \begin_layout Standard
24126
24127
24128 \backslash
24129 /
24130 \end_layout
24131
24132 \end_inset
24133
24134 -link= Sets the full path and name of an external linker to call.
24135 \end_layout
24136
24137 \begin_layout Description
24138 -
24139 \begin_inset ERT
24140 status collapsed
24141
24142 \begin_layout Standard
24143
24144
24145 \backslash
24146 /
24147 \end_layout
24148
24149 \end_inset
24150
24151 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24152  unitialized data variables with [kword].
24153  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24154 \end_layout
24155
24156 \begin_layout Description
24157 -
24158 \begin_inset ERT
24159 status collapsed
24160
24161 \begin_layout Standard
24162
24163
24164 \backslash
24165 /
24166 \end_layout
24167
24168 \end_inset
24169
24170 -ivt-loc=n Place the interrupt vector table at address 
24171 \emph on
24172 n
24173 \emph default
24174 .
24175  Useful for bootloaders.
24176 \end_layout
24177
24178 \begin_layout Description
24179 -
24180 \begin_inset ERT
24181 status collapsed
24182
24183 \begin_layout Standard
24184
24185
24186 \backslash
24187 /
24188 \end_layout
24189
24190 \end_inset
24191
24192 -nodefaultlibs Do not link default libraries when linking.
24193 \end_layout
24194
24195 \begin_layout Description
24196 -
24197 \begin_inset ERT
24198 status collapsed
24199
24200 \begin_layout Standard
24201
24202
24203 \backslash
24204 /
24205 \end_layout
24206
24207 \end_inset
24208
24209 -use-crt= Use a custom run-time module instead of the defaults.
24210 \end_layout
24211
24212 \begin_layout Description
24213 -
24214 \begin_inset ERT
24215 status collapsed
24216
24217 \begin_layout Standard
24218
24219
24220 \backslash
24221 /
24222 \end_layout
24223
24224 \end_inset
24225
24226 -no-crt Don't link the default run-time modules
24227 \end_layout
24228
24229 \begin_layout Subsubsection
24230 Debugging Options
24231 \end_layout
24232
24233 \begin_layout Standard
24234 Debugging options enable extra debugging information in the output files.
24235 \end_layout
24236
24237 \begin_layout Description
24238 -
24239 \begin_inset ERT
24240 status collapsed
24241
24242 \begin_layout Standard
24243
24244
24245 \backslash
24246 /
24247 \end_layout
24248
24249 \end_inset
24250
24251 -debug-xtra Similar to -
24252 \begin_inset ERT
24253 status collapsed
24254
24255 \begin_layout Standard
24256
24257
24258 \backslash
24259 /
24260 \end_layout
24261
24262 \end_inset
24263
24264 -debug
24265 \begin_inset LatexCommand \index{-\/-debug}
24266
24267 \end_inset
24268
24269 , but dumps more information.
24270 \end_layout
24271
24272 \begin_layout Description
24273 -
24274 \begin_inset ERT
24275 status collapsed
24276
24277 \begin_layout Standard
24278
24279
24280 \backslash
24281 /
24282 \end_layout
24283
24284 \end_inset
24285
24286 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24287  information.
24288  <source> is the name of the file being compiled.
24289 \end_layout
24290
24291 \begin_layout Description
24292 -
24293 \begin_inset ERT
24294 status collapsed
24295
24296 \begin_layout Standard
24297
24298
24299 \backslash
24300 /
24301 \end_layout
24302
24303 \end_inset
24304
24305 -pcode-verbose Enable pcode debugging information in translation.
24306 \end_layout
24307
24308 \begin_layout Description
24309 -
24310 \begin_inset ERT
24311 status collapsed
24312
24313 \begin_layout Standard
24314
24315
24316 \backslash
24317 /
24318 \end_layout
24319
24320 \end_inset
24321
24322 -calltree Dump call tree in .calltree file.
24323 \end_layout
24324
24325 \begin_layout Description
24326 -
24327 \begin_inset ERT
24328 status collapsed
24329
24330 \begin_layout Standard
24331
24332
24333 \backslash
24334 /
24335 \end_layout
24336
24337 \end_inset
24338
24339 -gstack Trace push/pops for stack pointer overflow.
24340 \end_layout
24341
24342 \begin_layout Subsection
24343 Enviroment Variables
24344 \end_layout
24345
24346 \begin_layout Standard
24347 There is a number of enviromental variables that can be used when running
24348  SDCC to enable certain optimizations or force a specific program behaviour.
24349  these variables are primarily for debugging purposes so they can be enabled/dis
24350 abled at will.
24351 \end_layout
24352
24353 \begin_layout Standard
24354 Currently there is only two such variables available:
24355 \end_layout
24356
24357 \begin_layout Description
24358 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24359  bitfields is optimized by directly loading FSR0 with the address of the
24360  bitfield structure.
24361  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24362  then load FSR0.
24363  This step saves data ram and code space for functions that make heavy use
24364  of bitfields.
24365  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24366  option).
24367  
24368 \end_layout
24369
24370 \begin_layout Description
24371 NO_REG_OPT Do not perform pCode registers optimization.
24372  This should be used for debugging purposes.
24373  If bugs in the pcode optimizer are found, users can benefit from temporarily
24374  disabling the optimizer until the bug is fixed.
24375 \end_layout
24376
24377 \begin_layout Subsection
24378 Preprocessor Macros
24379 \end_layout
24380
24381 \begin_layout Standard
24382 PIC16
24383 \begin_inset LatexCommand \index{PIC16}
24384
24385 \end_inset
24386
24387  port defines the following preprocessor macros while translating a source.
24388 \end_layout
24389
24390 \begin_layout Standard
24391 \align center
24392 \begin_inset Tabular
24393 <lyxtabular version="3" rows="6" columns="2">
24394 <features>
24395 <column alignment="center" valignment="top" leftline="true" width="0">
24396 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24397 <row topline="true" bottomline="true">
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24399 \begin_inset Text
24400
24401 \begin_layout Standard
24402 Macro
24403 \end_layout
24404
24405 \end_inset
24406 </cell>
24407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24408 \begin_inset Text
24409
24410 \begin_layout Standard
24411 Description
24412 \end_layout
24413
24414 \end_inset
24415 </cell>
24416 </row>
24417 <row topline="true">
24418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24419 \begin_inset Text
24420
24421 \begin_layout Standard
24422 SDCC_pic16
24423 \end_layout
24424
24425 \end_inset
24426 </cell>
24427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24428 \begin_inset Text
24429
24430 \begin_layout Standard
24431 Port identification
24432 \end_layout
24433
24434 \end_inset
24435 </cell>
24436 </row>
24437 <row topline="true">
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24439 \begin_inset Text
24440
24441 \begin_layout Standard
24442 _
24443 \begin_inset ERT
24444 status collapsed
24445
24446 \begin_layout Standard
24447
24448
24449 \backslash
24450 /
24451 \end_layout
24452
24453 \end_inset
24454
24455 _pic16
24456 \end_layout
24457
24458 \end_inset
24459 </cell>
24460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24461 \begin_inset Text
24462
24463 \begin_layout Standard
24464 Port identification (same as above)
24465 \end_layout
24466
24467 \end_inset
24468 </cell>
24469 </row>
24470 <row topline="true">
24471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24472 \begin_inset Text
24473
24474 \begin_layout Standard
24475 pic18fxxxx
24476 \end_layout
24477
24478 \end_inset
24479 </cell>
24480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24481 \begin_inset Text
24482
24483 \begin_layout Standard
24484 MCU Identification.
24485  
24486 \emph on
24487 xxxx
24488 \emph default
24489  is the microcontrol identification number, i.e.
24490  452, 6620, etc
24491 \end_layout
24492
24493 \end_inset
24494 </cell>
24495 </row>
24496 <row topline="true">
24497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24498 \begin_inset Text
24499
24500 \begin_layout Standard
24501 _
24502 \begin_inset ERT
24503 status collapsed
24504
24505 \begin_layout Standard
24506
24507
24508 \backslash
24509 /
24510 \end_layout
24511
24512 \end_inset
24513
24514 _18Fxxxx
24515 \end_layout
24516
24517 \end_inset
24518 </cell>
24519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24520 \begin_inset Text
24521
24522 \begin_layout Standard
24523 MCU Identification (same as above)
24524 \end_layout
24525
24526 \end_inset
24527 </cell>
24528 </row>
24529 <row topline="true" bottomline="true">
24530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24531 \begin_inset Text
24532
24533 \begin_layout Standard
24534 STACK_MODEL_nnn
24535 \end_layout
24536
24537 \end_inset
24538 </cell>
24539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24540 \begin_inset Text
24541
24542 \begin_layout Standard
24543 nnn = SMALL or LARGE respectively according to the stack model used
24544 \end_layout
24545
24546 \end_inset
24547 </cell>
24548 </row>
24549 </lyxtabular>
24550
24551 \end_inset
24552
24553
24554 \end_layout
24555
24556 \begin_layout Standard
24557 In addition the following macros are defined when calling assembler:
24558 \end_layout
24559
24560 \begin_layout Standard
24561 \align center
24562 \begin_inset Tabular
24563 <lyxtabular version="3" rows="4" columns="2">
24564 <features>
24565 <column alignment="center" valignment="top" leftline="true" width="0">
24566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24567 <row topline="true" bottomline="true">
24568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24569 \begin_inset Text
24570
24571 \begin_layout Standard
24572 Macro
24573 \end_layout
24574
24575 \end_inset
24576 </cell>
24577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24578 \begin_inset Text
24579
24580 \begin_layout Standard
24581 Description
24582 \end_layout
24583
24584 \end_inset
24585 </cell>
24586 </row>
24587 <row topline="true">
24588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24589 \begin_inset Text
24590
24591 \begin_layout Standard
24592 __18Fxxxx
24593 \end_layout
24594
24595 \end_inset
24596 </cell>
24597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24598 \begin_inset Text
24599
24600 \begin_layout Standard
24601 MCU Identification.
24602  
24603 \emph on
24604 xxxx
24605 \emph default
24606  is the microcontrol identification number, i.e.
24607  452, 6620, etc
24608 \end_layout
24609
24610 \end_inset
24611 </cell>
24612 </row>
24613 <row topline="true">
24614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24615 \begin_inset Text
24616
24617 \begin_layout Standard
24618 SDCC_MODEL_nnn
24619 \end_layout
24620
24621 \end_inset
24622 </cell>
24623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24624 \begin_inset Text
24625
24626 \begin_layout Standard
24627 nnn = SMALL or LARGE respectively according to the memory model used for
24628  SDCC
24629 \end_layout
24630
24631 \end_inset
24632 </cell>
24633 </row>
24634 <row topline="true" bottomline="true">
24635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24636 \begin_inset Text
24637
24638 \begin_layout Standard
24639 STACK_MODEL_nnn
24640 \end_layout
24641
24642 \end_inset
24643 </cell>
24644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24645 \begin_inset Text
24646
24647 \begin_layout Standard
24648 nnn = SMALL or LARGE respectively according to the stack model used
24649 \end_layout
24650
24651 \end_inset
24652 </cell>
24653 </row>
24654 </lyxtabular>
24655
24656 \end_inset
24657
24658
24659 \end_layout
24660
24661 \begin_layout Subsection
24662 Directories
24663 \end_layout
24664
24665 \begin_layout Standard
24666 PIC16
24667 \begin_inset LatexCommand \index{PIC16}
24668
24669 \end_inset
24670
24671  port uses the following directories for searching header files and libraries.
24672 \end_layout
24673
24674 \begin_layout Standard
24675 \align center
24676 \begin_inset Tabular
24677 <lyxtabular version="3" rows="3" columns="4">
24678 <features>
24679 <column alignment="center" valignment="top" leftline="true" width="0">
24680 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24681 <column alignment="center" valignment="top" width="0">
24682 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24683 <row topline="true" bottomline="true">
24684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24685 \begin_inset Text
24686
24687 \begin_layout Standard
24688 Directory
24689 \end_layout
24690
24691 \end_inset
24692 </cell>
24693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24694 \begin_inset Text
24695
24696 \begin_layout Standard
24697 Description
24698 \end_layout
24699
24700 \end_inset
24701 </cell>
24702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24703 \begin_inset Text
24704
24705 \begin_layout Standard
24706 Target
24707 \end_layout
24708
24709 \end_inset
24710 </cell>
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \begin_layout Standard
24715 Command prefix
24716 \end_layout
24717
24718 \end_inset
24719 </cell>
24720 </row>
24721 <row topline="true">
24722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24723 \begin_inset Text
24724
24725 \begin_layout Standard
24726 PREFIX/sdcc/include/pic16
24727 \end_layout
24728
24729 \end_inset
24730 </cell>
24731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24732 \begin_inset Text
24733
24734 \begin_layout Standard
24735 PIC16 specific headers
24736 \end_layout
24737
24738 \end_inset
24739 </cell>
24740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24741 \begin_inset Text
24742
24743 \begin_layout Standard
24744 Compiler
24745 \end_layout
24746
24747 \end_inset
24748 </cell>
24749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24750 \begin_inset Text
24751
24752 \begin_layout Standard
24753 -I
24754 \end_layout
24755
24756 \end_inset
24757 </cell>
24758 </row>
24759 <row topline="true" bottomline="true">
24760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24761 \begin_inset Text
24762
24763 \begin_layout Standard
24764 PREFIX/sdcc/lib/pic16
24765 \end_layout
24766
24767 \end_inset
24768 </cell>
24769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24770 \begin_inset Text
24771
24772 \begin_layout Standard
24773 PIC16 specific libraries
24774 \end_layout
24775
24776 \end_inset
24777 </cell>
24778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24779 \begin_inset Text
24780
24781 \begin_layout Standard
24782 Linker
24783 \end_layout
24784
24785 \end_inset
24786 </cell>
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24788 \begin_inset Text
24789
24790 \begin_layout Standard
24791 -L
24792 \end_layout
24793
24794 \end_inset
24795 </cell>
24796 </row>
24797 </lyxtabular>
24798
24799 \end_inset
24800
24801
24802 \end_layout
24803
24804 \begin_layout Subsection
24805 Pragmas
24806 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24807
24808 \end_inset
24809
24810
24811 \end_layout
24812
24813 \begin_layout Standard
24814 The PIC16
24815 \begin_inset LatexCommand \index{PIC16}
24816
24817 \end_inset
24818
24819  port currently supports the following pragmas:
24820 \end_layout
24821
24822 \begin_layout Description
24823 stack
24824 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24825
24826 \end_inset
24827
24828  This forces the code generator to initialize the stack & frame pointers
24829  at a specific address.
24830  This is an ad hoc solution for cases where no STACK directive is available
24831  in the linker script or gplink is not instructed to create a stack section.
24832 \newline
24833 The
24834  stack pragma should be used only once in a project.
24835  Multiple pragmas may result in indeterminate behaviour of the program.
24836 \begin_inset Foot
24837 status open
24838
24839 \begin_layout Standard
24840 The old format (ie.
24841  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24842  cross page boundaries (or even exceed the available data RAM) and crash
24843  the program.
24844  Make sure that stack does not cross page boundaries when using the SMALL
24845  stack model.
24846 \end_layout
24847
24848 \end_inset
24849
24850
24851 \newline
24852 The format is as follows:
24853 \newline
24854
24855 \end_layout
24856
24857 \begin_layout LyX-Code
24858 #pragma stack bottom_address [stack_size]
24859 \newline
24860
24861 \end_layout
24862
24863 \begin_layout Standard
24864
24865 \emph on
24866 bottom_address
24867 \emph default
24868  is the lower bound of the stack section.
24869  The stack pointer initially will point at address (bottom_address+stack_size-1).
24870 \end_layout
24871
24872 \begin_layout LyX-Code
24873 Example:
24874 \end_layout
24875
24876 \begin_layout LyX-Code
24877
24878 \end_layout
24879
24880 \begin_layout LyX-Code
24881 /* initializes stack of 100 bytes at RAM address 0x200 */
24882 \end_layout
24883
24884 \begin_layout LyX-Code
24885 #pragma stack 0x200 100
24886 \end_layout
24887
24888 \begin_layout Standard
24889 If the stack_size field is omitted then a stack is created with the default
24890  size of 64.
24891  This size might be enough for most programs, but its not enough for operations
24892  with deep function nesting or excessive stack usage.
24893 \end_layout
24894
24895 \begin_layout Description
24896 code
24897 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24898
24899 \end_inset
24900
24901  Force a function to a static FLASH address.
24902 \end_layout
24903
24904 \begin_layout LyX-Code
24905 Example:
24906 \end_layout
24907
24908 \begin_layout LyX-Code
24909
24910 \end_layout
24911
24912 \begin_layout LyX-Code
24913 /* place function test_func at 0x4000 */
24914 \end_layout
24915
24916 \begin_layout LyX-Code
24917 #pragma code test_func 0x4000
24918 \end_layout
24919
24920 \begin_layout LyX-Code
24921
24922 \end_layout
24923
24924 \begin_layout Description
24925 library instructs the linker to use a library module.
24926 \newline
24927 Usage:
24928 \end_layout
24929
24930 \begin_layout LyX-Code
24931 #pragma library module_name
24932 \end_layout
24933
24934 \begin_layout Standard
24935
24936 \emph on
24937 module_name
24938 \emph default
24939  can be any library or object file (including its path).
24940  Note that there are four reserved keywords which have special meaning.
24941  These are:
24942 \end_layout
24943
24944 \begin_layout Standard
24945 \align center
24946 \begin_inset Tabular
24947 <lyxtabular version="3" rows="6" columns="3">
24948 <features>
24949 <column alignment="center" valignment="top" leftline="true" width="0">
24950 <column alignment="block" valignment="top" leftline="true" width="20page%">
24951 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24952 <row topline="true" bottomline="true">
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24954 \begin_inset Text
24955
24956 \begin_layout Standard
24957 Keyword
24958 \end_layout
24959
24960 \end_inset
24961 </cell>
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24963 \begin_inset Text
24964
24965 \begin_layout Standard
24966 Description
24967 \end_layout
24968
24969 \end_inset
24970 </cell>
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24972 \begin_inset Text
24973
24974 \begin_layout Standard
24975 Module to link
24976 \end_layout
24977
24978 \end_inset
24979 </cell>
24980 </row>
24981 <row topline="true">
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24983 \begin_inset Text
24984
24985 \begin_layout Standard
24986
24987 \series bold
24988 ignore
24989 \end_layout
24990
24991 \end_inset
24992 </cell>
24993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24994 \begin_inset Text
24995
24996 \begin_layout Standard
24997 ignore all library pragmas
24998 \end_layout
24999
25000 \end_inset
25001 </cell>
25002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25003 \begin_inset Text
25004
25005 \begin_layout Standard
25006
25007 \emph on
25008 (none)
25009 \end_layout
25010
25011 \end_inset
25012 </cell>
25013 </row>
25014 <row topline="true">
25015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25016 \begin_inset Text
25017
25018 \begin_layout Standard
25019
25020 \series bold
25021 c
25022 \end_layout
25023
25024 \end_inset
25025 </cell>
25026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25027 \begin_inset Text
25028
25029 \begin_layout Standard
25030 link the C library
25031 \end_layout
25032
25033 \end_inset
25034 </cell>
25035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25036 \begin_inset Text
25037
25038 \begin_layout Standard
25039
25040 \emph on
25041 libc18f
25042 \emph default
25043 .lib
25044 \end_layout
25045
25046 \end_inset
25047 </cell>
25048 </row>
25049 <row topline="true">
25050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25051 \begin_inset Text
25052
25053 \begin_layout Standard
25054
25055 \series bold
25056 math
25057 \end_layout
25058
25059 \end_inset
25060 </cell>
25061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25062 \begin_inset Text
25063
25064 \begin_layout Standard
25065 link the Math libarary
25066 \end_layout
25067
25068 \end_inset
25069 </cell>
25070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25071 \begin_inset Text
25072
25073 \begin_layout Standard
25074
25075 \emph on
25076 libm18f
25077 \emph default
25078 .lib
25079 \end_layout
25080
25081 \end_inset
25082 </cell>
25083 </row>
25084 <row topline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25086 \begin_inset Text
25087
25088 \begin_layout Standard
25089
25090 \series bold
25091 io
25092 \end_layout
25093
25094 \end_inset
25095 </cell>
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25097 \begin_inset Text
25098
25099 \begin_layout Standard
25100 link the I/O library
25101 \end_layout
25102
25103 \end_inset
25104 </cell>
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25106 \begin_inset Text
25107
25108 \begin_layout Standard
25109
25110 \emph on
25111 libio18f*
25112 \emph default
25113 .lib
25114 \end_layout
25115
25116 \end_inset
25117 </cell>
25118 </row>
25119 <row topline="true" bottomline="true">
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_inset Text
25122
25123 \begin_layout Standard
25124
25125 \series bold
25126 debug
25127 \end_layout
25128
25129 \end_inset
25130 </cell>
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_inset Text
25133
25134 \begin_layout Standard
25135 link the debug library
25136 \end_layout
25137
25138 \end_inset
25139 </cell>
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25141 \begin_inset Text
25142
25143 \begin_layout Standard
25144
25145 \emph on
25146 libdebug
25147 \emph default
25148 .lib
25149 \end_layout
25150
25151 \end_inset
25152 </cell>
25153 </row>
25154 </lyxtabular>
25155
25156 \end_inset
25157
25158
25159 \newline
25160 * is the device number, i.e.
25161  452 for PIC18F452 MCU.
25162 \end_layout
25163
25164 \begin_layout Standard
25165 This feature allows for linking with specific libraries withoug having to
25166  explicit name them in the command line.
25167  Note that the 
25168 \noun on
25169 ignore
25170 \noun default
25171  keyword will reject all modules specified by the library pragma.
25172 \end_layout
25173
25174 \begin_layout Description
25175 udata The pragma udata instructs the compiler to emit code so that linker
25176  will place a variable at a specific memory bank.
25177 \end_layout
25178
25179 \begin_layout LyX-Code
25180 Example:
25181 \end_layout
25182
25183 \begin_layout LyX-Code
25184
25185 \end_layout
25186
25187 \begin_layout LyX-Code
25188 /* places variable foo at bank2 */
25189 \end_layout
25190
25191 \begin_layout LyX-Code
25192 #pragma udata bank2 foo
25193 \end_layout
25194
25195 \begin_layout LyX-Code
25196 char foo;
25197 \end_layout
25198
25199 \begin_layout Standard
25200 In order for this pragma to work extra SECTION directives should be added
25201  in the .lkr script.
25202  In the following example a sample .lkr file is shown:
25203 \end_layout
25204
25205 \begin_layout LyX-Code
25206
25207 \end_layout
25208
25209 \begin_layout LyX-Code
25210 // Sample linker script for the PIC18F452 processor
25211 \end_layout
25212
25213 \begin_layout LyX-Code
25214 LIBPATH .
25215 \end_layout
25216
25217 \begin_layout LyX-Code
25218 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25219 \end_layout
25220
25221 \begin_layout LyX-Code
25222 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25223 \end_layout
25224
25225 \begin_layout LyX-Code
25226 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25227 \end_layout
25228
25229 \begin_layout LyX-Code
25230 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25231 \end_layout
25232
25233 \begin_layout LyX-Code
25234 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25235 \end_layout
25236
25237 \begin_layout LyX-Code
25238 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25239 \end_layout
25240
25241 \begin_layout LyX-Code
25242 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25243 \end_layout
25244
25245 \begin_layout LyX-Code
25246
25247 \end_layout
25248
25249 \begin_layout LyX-Code
25250 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25251 \end_layout
25252
25253 \begin_layout LyX-Code
25254 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25255 \end_layout
25256
25257 \begin_layout LyX-Code
25258 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25259 \end_layout
25260
25261 \begin_layout LyX-Code
25262 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25263 \end_layout
25264
25265 \begin_layout LyX-Code
25266 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25267 \end_layout
25268
25269 \begin_layout LyX-Code
25270 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25271 \end_layout
25272
25273 \begin_layout LyX-Code
25274 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25275 \end_layout
25276
25277 \begin_layout LyX-Code
25278
25279 \end_layout
25280
25281 \begin_layout LyX-Code
25282 SECTION    NAME=CONFIG     ROM=config
25283 \end_layout
25284
25285 \begin_layout LyX-Code
25286
25287 \end_layout
25288
25289 \begin_layout LyX-Code
25290 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25291 \end_layout
25292
25293 \begin_layout LyX-Code
25294 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25295 \end_layout
25296
25297 \begin_layout LyX-Code
25298 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25299 \end_layout
25300
25301 \begin_layout LyX-Code
25302 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25303 \end_layout
25304
25305 \begin_layout LyX-Code
25306 SECTION    NAME=bank4      RAM=gpr4
25307 \end_layout
25308
25309 \begin_layout LyX-Code
25310 SECTION    NAME=bank5      RAM=gpr5
25311 \end_layout
25312
25313 \begin_layout Standard
25314 The linker will recognise the section name set in the pragma statement and
25315  will position the variable at the memory bank set with the RAM field at
25316  the SECTION line in the linker script file.
25317 \end_layout
25318
25319 \begin_layout Subsection
25320 Header Files
25321 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25322
25323 \end_inset
25324
25325
25326 \end_layout
25327
25328 \begin_layout Standard
25329 There is one main header file
25330 \begin_inset LatexCommand \index{PIC16!Header files}
25331
25332 \end_inset
25333
25334  that can be included to the source files using the pic16
25335 \begin_inset LatexCommand \index{PIC16}
25336
25337 \end_inset
25338
25339  port.
25340  That file is the 
25341 \series bold
25342 pic18fregs.h
25343 \series default
25344 .
25345  This header file contains the definitions for the processor special registers,
25346  so it is necessary if the source accesses them.
25347  It can be included by adding the following line in the beginning of the
25348  file:
25349 \end_layout
25350
25351 \begin_layout LyX-Code
25352 #include <pic18fregs.h>
25353 \end_layout
25354
25355 \begin_layout Standard
25356 The specific microcontroller is selected within the pic18fregs.h automatically,
25357  so the same source can be used with a variety of devices.
25358 \end_layout
25359
25360 \begin_layout Subsection
25361 Libraries
25362 \end_layout
25363
25364 \begin_layout Standard
25365 The libraries
25366 \begin_inset LatexCommand \index{PIC16!Libraries}
25367
25368 \end_inset
25369
25370  that PIC16
25371 \begin_inset LatexCommand \index{PIC16}
25372
25373 \end_inset
25374
25375  port depends on are the microcontroller device libraries which contain
25376  the symbol definitions for the microcontroller special function registers.
25377  These libraries have the format pic18fxxxx.lib, where 
25378 \emph on
25379 xxxx
25380 \emph default
25381  is the microcontroller identification number.
25382  The specific library is selected automatically by the compiler at link
25383  stage according to the selected device.
25384 \end_layout
25385
25386 \begin_layout Standard
25387 Libraries are created with gplib which is part of the gputils package 
25388 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25389
25390 \end_inset
25391
25392 .
25393 \end_layout
25394
25395 \begin_layout Subsubsection*
25396 Building the libraries
25397 \end_layout
25398
25399 \begin_layout Standard
25400 Before using SDCC/pic16 there are some libraries that need to be compiled.
25401  This process is not done automatically by SDCC since not all users use
25402  SDCC for pic16 projects.
25403  So each user should compile the libraries separately.
25404 \end_layout
25405
25406 \begin_layout Standard
25407 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25408 \end_layout
25409
25410 \begin_layout LyX-Code
25411 cd device/lib/pic16
25412 \end_layout
25413
25414 \begin_layout LyX-Code
25415 ./configure
25416 \end_layout
25417
25418 \begin_layout LyX-Code
25419 make
25420 \end_layout
25421
25422 \begin_layout LyX-Code
25423 cd ..
25424 \end_layout
25425
25426 \begin_layout LyX-Code
25427 make model-pic16
25428 \end_layout
25429
25430 \begin_layout LyX-Code
25431 su -c 'make install'     # install the libraries, you need the root password
25432 \end_layout
25433
25434 \begin_layout Standard
25435 If you need to install the headers too, do:
25436 \end_layout
25437
25438 \begin_layout LyX-Code
25439 cd device/include
25440 \end_layout
25441
25442 \begin_layout LyX-Code
25443 su -c 'make install'     # install the headers, you need the root password
25444 \end_layout
25445
25446 \begin_layout Standard
25447 There exist a special target to build the I/O libraries.
25448  This target is not automatically build because it will build the I/O library
25449  for 
25450 \emph on
25451 every
25452 \emph default
25453  supported device.
25454  This way building will take quite a lot of time.
25455  Users are advised to edit the 
25456 \series bold
25457 device/lib/pic16/pics.build
25458 \series default
25459  file and then execute:
25460 \end_layout
25461
25462 \begin_layout LyX-Code
25463 make lib-io
25464 \end_layout
25465
25466 \begin_layout Subsection
25467 Adding New Devices to the Port
25468 \end_layout
25469
25470 \begin_layout Standard
25471 Adding support for a new 16
25472 \begin_inset ERT
25473 status open
25474
25475 \begin_layout Standard
25476
25477
25478 \backslash
25479 ,
25480 \end_layout
25481
25482 \end_inset
25483
25484 bit PIC MCU requires the following steps:
25485 \end_layout
25486
25487 \begin_layout Enumerate
25488 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25489 \newline
25490
25491 \family typewriter
25492 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25493 inc
25494 \end_layout
25495
25496 \begin_layout Enumerate
25497
25498 \family typewriter
25499 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25500 \end_layout
25501
25502 \begin_layout Enumerate
25503
25504 \family typewriter
25505 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25506 \end_layout
25507
25508 \begin_layout Enumerate
25509 Add DEVICE to 
25510 \family typewriter
25511 /path/to/sdcc/device/lib/pics.all
25512 \family default
25513  (and 
25514 \family typewriter
25515 .build
25516 \family default
25517 ).
25518 \newline
25519 Note: No 18f prefix here!
25520 \end_layout
25521
25522 \begin_layout Enumerate
25523 Adjust 
25524 \family typewriter
25525 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25526 \family default
25527
25528 \newline
25529 Add your DEVICE if it does not compile in 
25530 \family typewriter
25531 adc
25532 \family default
25533
25534 \family typewriter
25535 i2c
25536 \family default
25537 , or 
25538 \family typewriter
25539 usart
25540 \family default
25541 .
25542 \end_layout
25543
25544 \begin_layout Enumerate
25545 Edit 
25546 \family typewriter
25547 /path/to/sdcc/device/include/pic16/pic18fregs.h
25548 \family default
25549 .
25550  The file format is self-explanatory, just add
25551 \newline
25552
25553 \family typewriter
25554 #elif defined(picDEVICE)
25555 \newline
25556 # include <picDEVICE.h>
25557 \family default
25558
25559 \newline
25560 at the right place (keep it sorted).
25561 \end_layout
25562
25563 \begin_layout Enumerate
25564 Edit 
25565 \family typewriter
25566 /path/to/sdcc/src/pic16/devices.inc
25567 \family default
25568 .
25569  Copy and modify an existing entry and insert it at the correct place (keep
25570  the file sorted).
25571  The file is hardly documented, look at the entries for the 18f2221...
25572 \end_layout
25573
25574 \begin_layout Enumerate
25575 Recompile SDCC, including the pic16 libraries.
25576 \end_layout
25577
25578 \begin_layout Subsection
25579 Memory Models
25580 \end_layout
25581
25582 \begin_layout Standard
25583 The following memory models are supported by the PIC16 port:
25584 \end_layout
25585
25586 \begin_layout Itemize
25587 small model
25588 \end_layout
25589
25590 \begin_layout Itemize
25591 large model
25592 \end_layout
25593
25594 \begin_layout Standard
25595 Memory model affects the default size of pointers within the source.
25596  The sizes are shown in the next table:
25597 \end_layout
25598
25599 \begin_layout Standard
25600 \align center
25601 \begin_inset Tabular
25602 <lyxtabular version="3" rows="3" columns="3">
25603 <features>
25604 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25605 <column alignment="center" valignment="top" leftline="true" width="0">
25606 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25607 <row topline="true" bottomline="true">
25608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25609 \begin_inset Text
25610
25611 \begin_layout Standard
25612 Pointer sizes according to memory model
25613 \end_layout
25614
25615 \end_inset
25616 </cell>
25617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25618 \begin_inset Text
25619
25620 \begin_layout Standard
25621 small model
25622 \end_layout
25623
25624 \end_inset
25625 </cell>
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25627 \begin_inset Text
25628
25629 \begin_layout Standard
25630 large model
25631 \end_layout
25632
25633 \end_inset
25634 </cell>
25635 </row>
25636 <row topline="true" bottomline="true">
25637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25638 \begin_inset Text
25639
25640 \begin_layout Standard
25641 code pointers
25642 \end_layout
25643
25644 \end_inset
25645 </cell>
25646 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25647 \begin_inset Text
25648
25649 \begin_layout Standard
25650 16-bits
25651 \end_layout
25652
25653 \end_inset
25654 </cell>
25655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25656 \begin_inset Text
25657
25658 \begin_layout Standard
25659 24-bits
25660 \end_layout
25661
25662 \end_inset
25663 </cell>
25664 </row>
25665 <row topline="true" bottomline="true">
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25667 \begin_inset Text
25668
25669 \begin_layout Standard
25670 data pointers
25671 \end_layout
25672
25673 \end_inset
25674 </cell>
25675 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25676 \begin_inset Text
25677
25678 \begin_layout Standard
25679 16-bits
25680 \end_layout
25681
25682 \end_inset
25683 </cell>
25684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25685 \begin_inset Text
25686
25687 \begin_layout Standard
25688 16-bits
25689 \end_layout
25690
25691 \end_inset
25692 </cell>
25693 </row>
25694 </lyxtabular>
25695
25696 \end_inset
25697
25698
25699 \end_layout
25700
25701 \begin_layout Standard
25702 It is advisable that all sources within a project are compiled with the
25703  same memory model.
25704  If one wants to override the default memory model, this can be done by
25705  declaring a pointer as 
25706 \series bold
25707 far
25708 \series default
25709  or 
25710 \series bold
25711 near
25712 \series default
25713 .
25714  Far selects large memory model's pointers, while near selects small memory
25715  model's pointers.
25716 \end_layout
25717
25718 \begin_layout Standard
25719 The standard device libraries (see 
25720 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25721
25722 \end_inset
25723
25724 ) contain no reference to pointers, so they can be used with both memory
25725  models.
25726 \end_layout
25727
25728 \begin_layout Subsection
25729 Stack
25730 \end_layout
25731
25732 \begin_layout Standard
25733 The stack
25734 \begin_inset LatexCommand \index{PIC16!stack}
25735
25736 \end_inset
25737
25738  implementation for the PIC16 port uses two indirect registers, FSR1 and
25739  FSR2.
25740 \end_layout
25741
25742 \begin_layout Description
25743 FSR1 is assigned as stack pointer
25744 \end_layout
25745
25746 \begin_layout Description
25747 FSR2 is assigned as frame pointer
25748 \end_layout
25749
25750 \begin_layout Standard
25751 The following stack models are supported by the PIC16 port
25752 \end_layout
25753
25754 \begin_layout Itemize
25755
25756 \noun on
25757 small
25758 \noun default
25759  model
25760 \end_layout
25761
25762 \begin_layout Itemize
25763
25764 \noun on
25765 large
25766 \noun default
25767  model
25768 \end_layout
25769
25770 \begin_layout Standard
25771
25772 \noun on
25773 Small
25774 \noun default
25775  model means that only the FSRxL byte is used to access stack and frame,
25776  while 
25777 \emph on
25778 \noun on
25779 large
25780 \emph default
25781 \noun default
25782  uses both FSRxL and FSRxH registers.
25783  The following table shows the stack/frame pointers sizes according to stack
25784  model and the maximum space they can address:
25785 \end_layout
25786
25787 \begin_layout Standard
25788 \align center
25789 \begin_inset Tabular
25790 <lyxtabular version="3" rows="3" columns="3">
25791 <features>
25792 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25793 <column alignment="center" valignment="top" leftline="true" width="0">
25794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25795 <row topline="true" bottomline="true">
25796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25797 \begin_inset Text
25798
25799 \begin_layout Standard
25800 Stack & Frame pointer sizes according to stack model
25801 \end_layout
25802
25803 \end_inset
25804 </cell>
25805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25806 \begin_inset Text
25807
25808 \begin_layout Standard
25809 small
25810 \end_layout
25811
25812 \end_inset
25813 </cell>
25814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25815 \begin_inset Text
25816
25817 \begin_layout Standard
25818 large
25819 \end_layout
25820
25821 \end_inset
25822 </cell>
25823 </row>
25824 <row topline="true">
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25826 \begin_inset Text
25827
25828 \begin_layout Standard
25829 Stack pointer FSR1
25830 \end_layout
25831
25832 \end_inset
25833 </cell>
25834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25835 \begin_inset Text
25836
25837 \begin_layout Standard
25838 8-bits
25839 \end_layout
25840
25841 \end_inset
25842 </cell>
25843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25844 \begin_inset Text
25845
25846 \begin_layout Standard
25847 16-bits
25848 \end_layout
25849
25850 \end_inset
25851 </cell>
25852 </row>
25853 <row topline="true" bottomline="true">
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25855 \begin_inset Text
25856
25857 \begin_layout Standard
25858 Frame pointer FSR2
25859 \end_layout
25860
25861 \end_inset
25862 </cell>
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25864 \begin_inset Text
25865
25866 \begin_layout Standard
25867 8-bits
25868 \end_layout
25869
25870 \end_inset
25871 </cell>
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25873 \begin_inset Text
25874
25875 \begin_layout Standard
25876 16-bits
25877 \end_layout
25878
25879 \end_inset
25880 </cell>
25881 </row>
25882 </lyxtabular>
25883
25884 \end_inset
25885
25886
25887 \end_layout
25888
25889 \begin_layout Standard
25890
25891 \noun on
25892 Large 
25893 \noun default
25894 stack model is currently not working properly throughout the code generator.
25895  So its use is not advised.
25896  Also there are some other points that need special care:
25897 \newline
25898
25899 \end_layout
25900
25901 \begin_layout Enumerate
25902 Do not create stack sections with size more than one physical bank (that
25903  is 256 bytes)
25904 \end_layout
25905
25906 \begin_layout Enumerate
25907 Stack sections should no cross physical bank limits (i.e.
25908  #pragma stack 0x50 0x100)
25909 \end_layout
25910
25911 \begin_layout Standard
25912 These limitations are caused by the fact that only FSRxL is modified when
25913  using SMALL stack model, so no more than 256 bytes of stack can be used.
25914  This problem will disappear after LARGE model is fully implemented.
25915 \end_layout
25916
25917 \begin_layout Subsection
25918 Functions
25919 \end_layout
25920
25921 \begin_layout Standard
25922 In addition to the standard SDCC function keywords, PIC16
25923 \begin_inset LatexCommand \index{PIC16}
25924
25925 \end_inset
25926
25927  port makes available two more:
25928 \end_layout
25929
25930 \begin_layout Description
25931 wparam
25932 \begin_inset LatexCommand \index{PIC16!wparam}
25933
25934 \end_inset
25935
25936  Use the WREG to pass one byte of the first function argument.
25937  This improves speed but you may not use this for functions with arguments
25938  that are called via function pointers, otherwise the first byte of the
25939  first parameter will get lost.
25940  Usage:
25941 \end_layout
25942
25943 \begin_layout LyX-Code
25944 void func_wparam(int a) wparam
25945 \end_layout
25946
25947 \begin_layout LyX-Code
25948 {
25949 \end_layout
25950
25951 \begin_layout LyX-Code
25952     /* WREG hold the lower part of a */
25953 \end_layout
25954
25955 \begin_layout LyX-Code
25956     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25957  */
25958 \end_layout
25959
25960 \begin_layout LyX-Code
25961 ...
25962 \end_layout
25963
25964 \begin_layout LyX-Code
25965 }
25966 \end_layout
25967
25968 \begin_layout Description
25969 shadowregs
25970 \begin_inset LatexCommand \index{PIC16!shadowregs}
25971
25972 \end_inset
25973
25974  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25975  hardware shadow registers which hold the values of WREG, STATUS and BSR
25976  registers.
25977  This can be done by adding the keyword 
25978 \emph on
25979 shadowregs
25980 \emph default
25981  before the 
25982 \emph on
25983 interrupt
25984 \emph default
25985  keyword in the function's header.
25986 \end_layout
25987
25988 \begin_layout LyX-Code
25989 void isr_shadow(void) shadowregs interrupt 1
25990 \end_layout
25991
25992 \begin_layout LyX-Code
25993 {
25994 \end_layout
25995
25996 \begin_layout LyX-Code
25997 ...
25998 \end_layout
25999
26000 \begin_layout LyX-Code
26001 }
26002 \end_layout
26003
26004 \begin_layout Standard
26005
26006 \emph on
26007 shadowregs
26008 \emph default
26009  instructs the code generator not to store/restore WREG, STATUS, BSR when
26010  entering/exiting the ISR.
26011 \end_layout
26012
26013 \begin_layout Subsection
26014 Function return values
26015 \end_layout
26016
26017 \begin_layout Standard
26018 Return values from functions are placed to the appropriate registers following
26019  a modified Microchip policy optimized for SDCC.
26020  The following table shows these registers:
26021 \end_layout
26022
26023 \begin_layout Standard
26024 \align center
26025 \begin_inset Tabular
26026 <lyxtabular version="3" rows="6" columns="2">
26027 <features>
26028 <column alignment="center" valignment="top" leftline="true" width="0">
26029 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26030 <row topline="true" bottomline="true">
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26032 \begin_inset Text
26033
26034 \begin_layout Standard
26035 size
26036 \end_layout
26037
26038 \end_inset
26039 </cell>
26040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26041 \begin_inset Text
26042
26043 \begin_layout Standard
26044 destination register
26045 \end_layout
26046
26047 \end_inset
26048 </cell>
26049 </row>
26050 <row topline="true">
26051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26052 \begin_inset Text
26053
26054 \begin_layout Standard
26055 8 bits
26056 \end_layout
26057
26058 \end_inset
26059 </cell>
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26061 \begin_inset Text
26062
26063 \begin_layout Standard
26064 WREG
26065 \end_layout
26066
26067 \end_inset
26068 </cell>
26069 </row>
26070 <row topline="true">
26071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26072 \begin_inset Text
26073
26074 \begin_layout Standard
26075 16 bits
26076 \end_layout
26077
26078 \end_inset
26079 </cell>
26080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26081 \begin_inset Text
26082
26083 \begin_layout Standard
26084 PRODL:WREG
26085 \end_layout
26086
26087 \end_inset
26088 </cell>
26089 </row>
26090 <row topline="true">
26091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26092 \begin_inset Text
26093
26094 \begin_layout Standard
26095 24 bits
26096 \end_layout
26097
26098 \end_inset
26099 </cell>
26100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26101 \begin_inset Text
26102
26103 \begin_layout Standard
26104 PRODH:PRODL:WREG
26105 \end_layout
26106
26107 \end_inset
26108 </cell>
26109 </row>
26110 <row topline="true">
26111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26112 \begin_inset Text
26113
26114 \begin_layout Standard
26115 32 bits
26116 \end_layout
26117
26118 \end_inset
26119 </cell>
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26121 \begin_inset Text
26122
26123 \begin_layout Standard
26124 FSR0L:PRODH:PRODL:WREG
26125 \end_layout
26126
26127 \end_inset
26128 </cell>
26129 </row>
26130 <row topline="true" bottomline="true">
26131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26132 \begin_inset Text
26133
26134 \begin_layout Standard
26135 >32 bits
26136 \end_layout
26137
26138 \end_inset
26139 </cell>
26140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26141 \begin_inset Text
26142
26143 \begin_layout Standard
26144 on stack, FSR0 points to the beginning
26145 \end_layout
26146
26147 \end_inset
26148 </cell>
26149 </row>
26150 </lyxtabular>
26151
26152 \end_inset
26153
26154
26155 \end_layout
26156
26157 \begin_layout Subsection
26158 Interrupts
26159 \end_layout
26160
26161 \begin_layout Standard
26162 An interrupt
26163 \begin_inset LatexCommand \index{PIC16!interrupt}
26164
26165 \end_inset
26166
26167  service routine (ISR) is declared using the 
26168 \emph on
26169 interrupt
26170 \emph default
26171  keyword.
26172 \end_layout
26173
26174 \begin_layout LyX-Code
26175 void isr(void) interrupt 
26176 \emph on
26177 n
26178 \end_layout
26179
26180 \begin_layout LyX-Code
26181 {
26182 \end_layout
26183
26184 \begin_layout LyX-Code
26185 ...
26186 \end_layout
26187
26188 \begin_layout LyX-Code
26189 }
26190 \end_layout
26191
26192 \begin_layout Standard
26193
26194 \emph on
26195 n
26196 \emph default
26197  is the interrupt number, which for PIC18F devices can be:
26198 \end_layout
26199
26200 \begin_layout Standard
26201 \align center
26202 \begin_inset Tabular
26203 <lyxtabular version="3" rows="4" columns="3">
26204 <features>
26205 <column alignment="center" valignment="top" leftline="true" width="0">
26206 <column alignment="center" valignment="top" leftline="true" width="0">
26207 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26208 <row topline="true" bottomline="true">
26209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26210 \begin_inset Text
26211
26212 \begin_layout Standard
26213
26214 \emph on
26215 n
26216 \end_layout
26217
26218 \end_inset
26219 </cell>
26220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26221 \begin_inset Text
26222
26223 \begin_layout Standard
26224 Interrupt Vector
26225 \end_layout
26226
26227 \end_inset
26228 </cell>
26229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26230 \begin_inset Text
26231
26232 \begin_layout Standard
26233 Interrupt Vector Address
26234 \end_layout
26235
26236 \end_inset
26237 </cell>
26238 </row>
26239 <row topline="true">
26240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26241 \begin_inset Text
26242
26243 \begin_layout Standard
26244 0
26245 \end_layout
26246
26247 \end_inset
26248 </cell>
26249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26250 \begin_inset Text
26251
26252 \begin_layout Standard
26253 RESET vector
26254 \end_layout
26255
26256 \end_inset
26257 </cell>
26258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26259 \begin_inset Text
26260
26261 \begin_layout Standard
26262 0x000000
26263 \end_layout
26264
26265 \end_inset
26266 </cell>
26267 </row>
26268 <row topline="true">
26269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26270 \begin_inset Text
26271
26272 \begin_layout Standard
26273
26274 \family roman
26275 \series medium
26276 \shape up
26277 \size normal
26278 \emph off
26279 \bar no
26280 \noun off
26281 \color none
26282 1
26283 \end_layout
26284
26285 \end_inset
26286 </cell>
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26288 \begin_inset Text
26289
26290 \begin_layout Standard
26291
26292 \family roman
26293 \series medium
26294 \shape up
26295 \size normal
26296 \emph off
26297 \bar no
26298 \noun off
26299 \color none
26300 HIGH priority interrupts
26301 \end_layout
26302
26303 \end_inset
26304 </cell>
26305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26306 \begin_inset Text
26307
26308 \begin_layout Standard
26309 0x000008
26310 \end_layout
26311
26312 \end_inset
26313 </cell>
26314 </row>
26315 <row topline="true" bottomline="true">
26316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26317 \begin_inset Text
26318
26319 \begin_layout Standard
26320 2
26321 \end_layout
26322
26323 \end_inset
26324 </cell>
26325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26326 \begin_inset Text
26327
26328 \begin_layout Standard
26329 LOW priority interrupts
26330 \end_layout
26331
26332 \end_inset
26333 </cell>
26334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26335 \begin_inset Text
26336
26337 \begin_layout Standard
26338 0x000018
26339 \end_layout
26340
26341 \end_inset
26342 </cell>
26343 </row>
26344 </lyxtabular>
26345
26346 \end_inset
26347
26348
26349 \end_layout
26350
26351 \begin_layout Standard
26352 When generating assembly code for ISR the code generator places a 
26353 \noun on
26354 goto 
26355 \noun default
26356 instruction at the 
26357 \emph on
26358 Interrupt Vector Address
26359 \emph default
26360  which points at the genetated ISR.
26361  This single GOTO instruction is part of an automatically generated 
26362 \emph on
26363 interrupt entry point
26364 \emph default
26365  function.
26366  The actuall ISR code is placed as normally would in the code space.
26367  Upon interrupt request, the GOTO instruction is executed which jumps to
26368  the ISR code.
26369  When declaring interrupt functions as _naked this GOTO instruction is 
26370 \series bold
26371 not
26372 \series default
26373  generated.
26374  The whole interrupt functions is therefore placed at the Interrupt Vector
26375  Address of the specific interrupt.
26376  This is not a problem for the LOW priority interrupts, but it is a problem
26377  for the RESET and the HIGH priority interrupts because code may be written
26378  at the next interrupt's vector address and cause undeterminate program
26379  behaviour if that interrupt is raised.
26380 \begin_inset Foot
26381 status open
26382
26383 \begin_layout Standard
26384 This is not a problem when
26385 \end_layout
26386
26387 \begin_layout Enumerate
26388 this is a HIGH interrupt ISR and LOW interrupts are 
26389 \emph on
26390 disabled
26391 \emph default
26392  or not used.
26393 \end_layout
26394
26395 \begin_layout Enumerate
26396 when the ISR is small enough not to reach the next interrupt's vector address.
26397 \end_layout
26398
26399 \end_inset
26400
26401
26402 \end_layout
26403
26404 \begin_layout Standard
26405
26406 \emph on
26407 n
26408 \emph default
26409  may be omitted.
26410  This way a function is generated similar to an ISR, but it is not assigned
26411  to any interrupt.
26412 \end_layout
26413
26414 \begin_layout Standard
26415 When entering an interrupt, currently the PIC16
26416 \begin_inset LatexCommand \index{PIC16}
26417
26418 \end_inset
26419
26420  port automatically saves the following registers:
26421 \end_layout
26422
26423 \begin_layout Itemize
26424 WREG
26425 \end_layout
26426
26427 \begin_layout Itemize
26428 STATUS
26429 \end_layout
26430
26431 \begin_layout Itemize
26432 BSR
26433 \end_layout
26434
26435 \begin_layout Itemize
26436 PROD (PRODL and PRODH)
26437 \end_layout
26438
26439 \begin_layout Itemize
26440 FSR0 (FSR0L and FSR0H)
26441 \end_layout
26442
26443 \begin_layout Standard
26444 These registers are restored upon return from the interrupt routine.
26445 \begin_inset Foot
26446 status open
26447
26448 \begin_layout Standard
26449 NOTE that when the _naked attribute is specified for an interrupt routine,
26450  then NO registers are stored or restored.
26451 \end_layout
26452
26453 \end_inset
26454
26455
26456 \end_layout
26457
26458 \begin_layout Subsection
26459 Generic Pointers
26460 \end_layout
26461
26462 \begin_layout Standard
26463 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26464  There are 3 types of generic pointers currently implemented data, code
26465  and eeprom pointers.
26466  They are differentiated by the value of the 7th and 6th bits of the upper
26467  byte:
26468 \end_layout
26469
26470 \begin_layout Standard
26471 \align center
26472 \begin_inset Tabular
26473 <lyxtabular version="3" rows="5" columns="5">
26474 <features>
26475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26476 <column alignment="center" valignment="top" width="0">
26477 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26478 <column alignment="center" valignment="top" width="0">
26479 <column alignment="left" valignment="top" rightline="true" width="0">
26480 <row topline="true" bottomline="true">
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26482 \begin_inset Text
26483
26484 \begin_layout Standard
26485 pointer type
26486 \end_layout
26487
26488 \end_inset
26489 </cell>
26490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26491 \begin_inset Text
26492
26493 \begin_layout Standard
26494 7th bit
26495 \end_layout
26496
26497 \end_inset
26498 </cell>
26499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26500 \begin_inset Text
26501
26502 \begin_layout Standard
26503 6th bit
26504 \end_layout
26505
26506 \end_inset
26507 </cell>
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26509 \begin_inset Text
26510
26511 \begin_layout Standard
26512 rest of the pointer
26513 \end_layout
26514
26515 \end_inset
26516 </cell>
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26518 \begin_inset Text
26519
26520 \begin_layout Standard
26521 description
26522 \end_layout
26523
26524 \end_inset
26525 </cell>
26526 </row>
26527 <row topline="true" bottomline="true">
26528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26529 \begin_inset Text
26530
26531 \begin_layout Standard
26532 data 
26533 \end_layout
26534
26535 \end_inset
26536 </cell>
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26538 \begin_inset Text
26539
26540 \begin_layout Standard
26541 1
26542 \end_layout
26543
26544 \end_inset
26545 </cell>
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26547 \begin_inset Text
26548
26549 \begin_layout Standard
26550 0
26551 \end_layout
26552
26553 \end_inset
26554 </cell>
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26556 \begin_inset Text
26557
26558 \begin_layout Standard
26559
26560 \family typewriter
26561 \shape slanted
26562 \emph on
26563 uuuuuu uuuuxxxx xxxxxxxx
26564 \end_layout
26565
26566 \end_inset
26567 </cell>
26568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26569 \begin_inset Text
26570
26571 \begin_layout Standard
26572 a 12-bit data pointer in data RAM memory
26573 \end_layout
26574
26575 \end_inset
26576 </cell>
26577 </row>
26578 <row bottomline="true">
26579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26580 \begin_inset Text
26581
26582 \begin_layout Standard
26583 code
26584 \end_layout
26585
26586 \end_inset
26587 </cell>
26588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26589 \begin_inset Text
26590
26591 \begin_layout Standard
26592 0
26593 \end_layout
26594
26595 \end_inset
26596 </cell>
26597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26598 \begin_inset Text
26599
26600 \begin_layout Standard
26601 0
26602 \end_layout
26603
26604 \end_inset
26605 </cell>
26606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26607 \begin_inset Text
26608
26609 \begin_layout Standard
26610
26611 \family typewriter
26612 \shape slanted
26613 \emph on
26614 uxxxxx xxxxxxxx xxxxxxxx
26615 \end_layout
26616
26617 \end_inset
26618 </cell>
26619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26620 \begin_inset Text
26621
26622 \begin_layout Standard
26623 a 21-bit code pointer in FLASH memory
26624 \end_layout
26625
26626 \end_inset
26627 </cell>
26628 </row>
26629 <row bottomline="true">
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26631 \begin_inset Text
26632
26633 \begin_layout Standard
26634 eeprom
26635 \end_layout
26636
26637 \end_inset
26638 </cell>
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26640 \begin_inset Text
26641
26642 \begin_layout Standard
26643 0
26644 \end_layout
26645
26646 \end_inset
26647 </cell>
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26649 \begin_inset Text
26650
26651 \begin_layout Standard
26652 1
26653 \end_layout
26654
26655 \end_inset
26656 </cell>
26657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26658 \begin_inset Text
26659
26660 \begin_layout Standard
26661
26662 \family typewriter
26663 \shape slanted
26664 \emph on
26665 uuuuuu uuuuuuxx xxxxxxxx
26666 \end_layout
26667
26668 \end_inset
26669 </cell>
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26671 \begin_inset Text
26672
26673 \begin_layout Standard
26674 a 10-bit eeprom pointer in EEPROM memory
26675 \end_layout
26676
26677 \end_inset
26678 </cell>
26679 </row>
26680 <row bottomline="true">
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26682 \begin_inset Text
26683
26684 \begin_layout Standard
26685 (unimplemented)
26686 \end_layout
26687
26688 \end_inset
26689 </cell>
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26691 \begin_inset Text
26692
26693 \begin_layout Standard
26694 1
26695 \end_layout
26696
26697 \end_inset
26698 </cell>
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \begin_layout Standard
26703 1
26704 \end_layout
26705
26706 \end_inset
26707 </cell>
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26709 \begin_inset Text
26710
26711 \begin_layout Standard
26712
26713 \family typewriter
26714 \shape slanted
26715 \emph on
26716 xxxxxx xxxxxxxx xxxxxxxx
26717 \end_layout
26718
26719 \end_inset
26720 </cell>
26721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26722 \begin_inset Text
26723
26724 \begin_layout Standard
26725 unimplemented pointer type
26726 \end_layout
26727
26728 \end_inset
26729 </cell>
26730 </row>
26731 </lyxtabular>
26732
26733 \end_inset
26734
26735
26736 \end_layout
26737
26738 \begin_layout Standard
26739 Generic pointer are read and written with a set of library functions which
26740  read/write 1, 2, 3, 4 bytes.
26741 \end_layout
26742
26743 \begin_layout Subsection
26744 PIC16 C Libraries
26745 \end_layout
26746
26747 \begin_layout Subsubsection
26748 Standard I/O Streams
26749 \end_layout
26750
26751 \begin_layout Standard
26752 In the 
26753 \emph on
26754 stdio.h
26755 \emph default
26756  the type FILE is defined as:
26757 \end_layout
26758
26759 \begin_layout LyX-Code
26760 typedef char * FILE;
26761 \end_layout
26762
26763 \begin_layout Standard
26764 This type is the stream type implemented I/O in the PIC18F devices.
26765  Also the standard input and output streams are declared in stdio.h:
26766 \end_layout
26767
26768 \begin_layout LyX-Code
26769 extern FILE * stdin;
26770 \end_layout
26771
26772 \begin_layout LyX-Code
26773 extern FILE * stdout;
26774 \end_layout
26775
26776 \begin_layout Standard
26777 The FILE type is actually a generic pointer which defines one more type
26778  of generic pointers, the 
26779 \emph on
26780 stream 
26781 \emph default
26782 pointer.
26783  This new type has the format:
26784 \end_layout
26785
26786 \begin_layout Standard
26787 \align center
26788 \begin_inset Tabular
26789 <lyxtabular version="3" rows="2" columns="7">
26790 <features>
26791 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26792 <column alignment="center" valignment="top" width="0">
26793 <column alignment="center" valignment="top" leftline="true" width="0">
26794 <column alignment="center" valignment="top" leftline="true" width="0">
26795 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26796 <column alignment="center" valignment="top" width="0">
26797 <column alignment="left" valignment="top" rightline="true" width="0">
26798 <row topline="true" bottomline="true">
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26800 \begin_inset Text
26801
26802 \begin_layout Standard
26803 pointer type
26804 \end_layout
26805
26806 \end_inset
26807 </cell>
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26809 \begin_inset Text
26810
26811 \begin_layout Standard
26812 <7:6>
26813 \end_layout
26814
26815 \end_inset
26816 </cell>
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26818 \begin_inset Text
26819
26820 \begin_layout Standard
26821 <5>
26822 \end_layout
26823
26824 \end_inset
26825 </cell>
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26827 \begin_inset Text
26828
26829 \begin_layout Standard
26830 <4>
26831 \end_layout
26832
26833 \end_inset
26834 </cell>
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26836 \begin_inset Text
26837
26838 \begin_layout Standard
26839 <3:0>
26840 \end_layout
26841
26842 \end_inset
26843 </cell>
26844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26845 \begin_inset Text
26846
26847 \begin_layout Standard
26848 rest of the pointer
26849 \end_layout
26850
26851 \end_inset
26852 </cell>
26853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26854 \begin_inset Text
26855
26856 \begin_layout Standard
26857 descrption
26858 \end_layout
26859
26860 \end_inset
26861 </cell>
26862 </row>
26863 <row topline="true" bottomline="true">
26864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26865 \begin_inset Text
26866
26867 \begin_layout Standard
26868 stream
26869 \end_layout
26870
26871 \end_inset
26872 </cell>
26873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26874 \begin_inset Text
26875
26876 \begin_layout Standard
26877 00
26878 \end_layout
26879
26880 \end_inset
26881 </cell>
26882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26883 \begin_inset Text
26884
26885 \begin_layout Standard
26886 1
26887 \end_layout
26888
26889 \end_inset
26890 </cell>
26891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26892 \begin_inset Text
26893
26894 \begin_layout Standard
26895 0
26896 \end_layout
26897
26898 \end_inset
26899 </cell>
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26901 \begin_inset Text
26902
26903 \begin_layout Standard
26904 nnnn
26905 \end_layout
26906
26907 \end_inset
26908 </cell>
26909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26910 \begin_inset Text
26911
26912 \begin_layout Standard
26913
26914 \family typewriter
26915 \shape slanted
26916 \emph on
26917 uuuuuuuu uuuuuuuu
26918 \end_layout
26919
26920 \end_inset
26921 </cell>
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26923 \begin_inset Text
26924
26925 \begin_layout Standard
26926 upper byte high nubble is 0x2n, the rest are zeroes
26927 \end_layout
26928
26929 \end_inset
26930 </cell>
26931 </row>
26932 </lyxtabular>
26933
26934 \end_inset
26935
26936
26937 \end_layout
26938
26939 \begin_layout Standard
26940 Currently implemented there are 3 types of streams defined:
26941 \end_layout
26942
26943 \begin_layout Standard
26944 \align center
26945 \begin_inset Tabular
26946 <lyxtabular version="3" rows="4" columns="4">
26947 <features>
26948 <column alignment="center" valignment="top" leftline="true" width="0">
26949 <column alignment="center" valignment="top" leftline="true" width="0">
26950 <column alignment="center" valignment="top" leftline="true" width="0">
26951 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26952 <row topline="true" bottomline="true">
26953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26954 \begin_inset Text
26955
26956 \begin_layout Standard
26957 stream type
26958 \end_layout
26959
26960 \end_inset
26961 </cell>
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26963 \begin_inset Text
26964
26965 \begin_layout Standard
26966 value
26967 \end_layout
26968
26969 \end_inset
26970 </cell>
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 \begin_inset Text
26973
26974 \begin_layout Standard
26975 module
26976 \end_layout
26977
26978 \end_inset
26979 </cell>
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset Text
26982
26983 \begin_layout Standard
26984 description
26985 \end_layout
26986
26987 \end_inset
26988 </cell>
26989 </row>
26990 <row topline="true">
26991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26992 \begin_inset Text
26993
26994 \begin_layout Standard
26995 STREAM_USART
26996 \end_layout
26997
26998 \end_inset
26999 </cell>
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27001 \begin_inset Text
27002
27003 \begin_layout Standard
27004
27005 \family typewriter
27006 0x200000UL
27007 \end_layout
27008
27009 \end_inset
27010 </cell>
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27012 \begin_inset Text
27013
27014 \begin_layout Standard
27015 USART
27016 \end_layout
27017
27018 \end_inset
27019 </cell>
27020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_inset Text
27022
27023 \begin_layout Standard
27024 Writes/Reads characters via the USART peripheral
27025 \end_layout
27026
27027 \end_inset
27028 </cell>
27029 </row>
27030 <row topline="true">
27031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27032 \begin_inset Text
27033
27034 \begin_layout Standard
27035 STREAM_MSSP
27036 \end_layout
27037
27038 \end_inset
27039 </cell>
27040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27041 \begin_inset Text
27042
27043 \begin_layout Standard
27044
27045 \family typewriter
27046 0x210000UL
27047 \end_layout
27048
27049 \end_inset
27050 </cell>
27051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27052 \begin_inset Text
27053
27054 \begin_layout Standard
27055 MSSP
27056 \end_layout
27057
27058 \end_inset
27059 </cell>
27060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27061 \begin_inset Text
27062
27063 \begin_layout Standard
27064 Writes/Reads characters via the MSSP peripheral
27065 \end_layout
27066
27067 \end_inset
27068 </cell>
27069 </row>
27070 <row topline="true" bottomline="true">
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 \begin_inset Text
27073
27074 \begin_layout Standard
27075 STREAM_USER
27076 \end_layout
27077
27078 \end_inset
27079 </cell>
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27081 \begin_inset Text
27082
27083 \begin_layout Standard
27084
27085 \family typewriter
27086 0x2f0000UL
27087 \end_layout
27088
27089 \end_inset
27090 </cell>
27091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27092 \begin_inset Text
27093
27094 \begin_layout Standard
27095 (none)
27096 \end_layout
27097
27098 \end_inset
27099 </cell>
27100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27101 \begin_inset Text
27102
27103 \begin_layout Standard
27104 Writes/Reads characters via used defined functions
27105 \end_layout
27106
27107 \end_inset
27108 </cell>
27109 </row>
27110 </lyxtabular>
27111
27112 \end_inset
27113
27114
27115 \end_layout
27116
27117 \begin_layout Standard
27118 The stream identifiers are declared as macros in the stdio.h header.
27119 \end_layout
27120
27121 \begin_layout Standard
27122 In the libc library there exist the functions that are used to write to
27123  each of the above streams.
27124  These are
27125 \end_layout
27126
27127 \begin_layout Description
27128 _
27129 \begin_inset ERT
27130 status collapsed
27131
27132 \begin_layout Standard
27133
27134
27135 \backslash
27136 /
27137 \end_layout
27138
27139 \end_inset
27140
27141 _stream_usart_putchar writes a character at the USART stream
27142 \end_layout
27143
27144 \begin_layout Description
27145 _
27146 \begin_inset ERT
27147 status collapsed
27148
27149 \begin_layout Standard
27150
27151
27152 \backslash
27153 /
27154 \end_layout
27155
27156 \end_inset
27157
27158 _stream_mssp_putchar writes a character at the MSSP stream
27159 \end_layout
27160
27161 \begin_layout Description
27162 putchar dummy function.
27163  This writes a character to a user specified manner.
27164 \end_layout
27165
27166 \begin_layout Standard
27167 In order to increase performance 
27168 \emph on
27169 putchar 
27170 \emph default
27171 is declared in stdio.h as having its parameter in WREG (it has the wparam
27172  keyword).
27173  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27174  in a user-friendly way.
27175  
27176 \emph on
27177 arg
27178 \emph default
27179  is the name of the variable that holds the character to print.
27180  An example follows:
27181 \end_layout
27182
27183 \begin_layout LyX-Code
27184 #include <pic18fregs.h>
27185 \newline
27186 #include <stdio.h>
27187 \newline
27188
27189 \newline
27190 PUTCHAR( c )
27191 \end_layout
27192
27193 \begin_layout LyX-Code
27194 {
27195 \end_layout
27196
27197 \begin_layout LyX-Code
27198     PORTA = c;    /* dump character c to PORTA */
27199 \end_layout
27200
27201 \begin_layout LyX-Code
27202
27203 \newline
27204
27205 \newline
27206 void main(void)
27207 \end_layout
27208
27209 \begin_layout LyX-Code
27210 {
27211 \end_layout
27212
27213 \begin_layout LyX-Code
27214     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27215 \end_layout
27216
27217 \begin_layout LyX-Code
27218                               * by default to STREAM_USER */
27219 \end_layout
27220
27221 \begin_layout LyX-Code
27222     printf (
27223 \begin_inset Quotes sld
27224 \end_inset
27225
27226 This is a printf test
27227 \backslash
27228 n
27229 \begin_inset Quotes srd
27230 \end_inset
27231
27232 );
27233 \end_layout
27234
27235 \begin_layout LyX-Code
27236 }
27237 \end_layout
27238
27239 \begin_layout LyX-Code
27240
27241 \end_layout
27242
27243 \begin_layout Subsubsection
27244 Printing functions
27245 \end_layout
27246
27247 \begin_layout Standard
27248 PIC16 contains an implementation of the printf-family of functions.
27249  There exist the following functions:
27250 \end_layout
27251
27252 \begin_layout LyX-Code
27253 extern unsigned int sprintf(char *buf, char *fmt, ...);
27254 \end_layout
27255
27256 \begin_layout LyX-Code
27257 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27258 \end_layout
27259
27260 \begin_layout LyX-Code
27261
27262 \end_layout
27263
27264 \begin_layout LyX-Code
27265 extern unsigned int printf(char *fmt, ...);
27266 \end_layout
27267
27268 \begin_layout LyX-Code
27269 extern unsigned int vprintf(char *fmt, va_lista ap);
27270 \end_layout
27271
27272 \begin_layout LyX-Code
27273
27274 \end_layout
27275
27276 \begin_layout LyX-Code
27277 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27278 \end_layout
27279
27280 \begin_layout LyX-Code
27281 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27282 \end_layout
27283
27284 \begin_layout Standard
27285 For sprintf and vsprintf 
27286 \emph on
27287 buf 
27288 \emph default
27289 should normally be a data pointer where the resulting string will be placed.
27290  No range checking is done so the user should allocate the necessery buffer.
27291  For fprintf and vfprintf 
27292 \emph on
27293 fp
27294 \emph default
27295  should be a stream pointer (i.e.
27296  stdout, STREAM_MSSP, etc...).
27297 \end_layout
27298
27299 \begin_layout Subsubsection
27300 Signals
27301 \end_layout
27302
27303 \begin_layout Standard
27304 The PIC18F family of microcontrollers supports a number of interrupt sources.
27305  A list of these interrupts is shown in the following table:
27306 \end_layout
27307
27308 \begin_layout Standard
27309 \align center
27310 \begin_inset Tabular
27311 <lyxtabular version="3" rows="11" columns="4">
27312 <features>
27313 <column alignment="left" valignment="top" leftline="true" width="0">
27314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27315 <column alignment="left" valignment="top" leftline="true" width="0">
27316 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27317 <row topline="true" bottomline="true">
27318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27319 \begin_inset Text
27320
27321 \begin_layout Standard
27322 signal name
27323 \end_layout
27324
27325 \end_inset
27326 </cell>
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27328 \begin_inset Text
27329
27330 \begin_layout Standard
27331 description
27332 \end_layout
27333
27334 \end_inset
27335 </cell>
27336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27337 \begin_inset Text
27338
27339 \begin_layout Standard
27340 signal name
27341 \end_layout
27342
27343 \end_inset
27344 </cell>
27345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27346 \begin_inset Text
27347
27348 \begin_layout Standard
27349 descritpion
27350 \end_layout
27351
27352 \end_inset
27353 </cell>
27354 </row>
27355 <row topline="true">
27356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27357 \begin_inset Text
27358
27359 \begin_layout Standard
27360 SIG_RB
27361 \end_layout
27362
27363 \end_inset
27364 </cell>
27365 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27366 \begin_inset Text
27367
27368 \begin_layout Standard
27369 PORTB change interrupt
27370 \end_layout
27371
27372 \end_inset
27373 </cell>
27374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27375 \begin_inset Text
27376
27377 \begin_layout Standard
27378 SIG_EE
27379 \end_layout
27380
27381 \end_inset
27382 </cell>
27383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27384 \begin_inset Text
27385
27386 \begin_layout Standard
27387 EEPROM/FLASH write complete interrupt
27388 \end_layout
27389
27390 \end_inset
27391 </cell>
27392 </row>
27393 <row topline="true">
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27395 \begin_inset Text
27396
27397 \begin_layout Standard
27398 SIG_INT0
27399 \end_layout
27400
27401 \end_inset
27402 </cell>
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27404 \begin_inset Text
27405
27406 \begin_layout Standard
27407 INT0 external interrupt
27408 \end_layout
27409
27410 \end_inset
27411 </cell>
27412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27413 \begin_inset Text
27414
27415 \begin_layout Standard
27416 SIG_BCOL
27417 \end_layout
27418
27419 \end_inset
27420 </cell>
27421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27422 \begin_inset Text
27423
27424 \begin_layout Standard
27425 Bus collision interrupt
27426 \end_layout
27427
27428 \end_inset
27429 </cell>
27430 </row>
27431 <row topline="true">
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27433 \begin_inset Text
27434
27435 \begin_layout Standard
27436 SIG_INT1
27437 \end_layout
27438
27439 \end_inset
27440 </cell>
27441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27442 \begin_inset Text
27443
27444 \begin_layout Standard
27445 INT1 external interrupt
27446 \end_layout
27447
27448 \end_inset
27449 </cell>
27450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27451 \begin_inset Text
27452
27453 \begin_layout Standard
27454 SIG_LVD
27455 \end_layout
27456
27457 \end_inset
27458 </cell>
27459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27460 \begin_inset Text
27461
27462 \begin_layout Standard
27463 Low voltage detect interrupt
27464 \end_layout
27465
27466 \end_inset
27467 </cell>
27468 </row>
27469 <row topline="true">
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27471 \begin_inset Text
27472
27473 \begin_layout Standard
27474 SIG_INT2
27475 \end_layout
27476
27477 \end_inset
27478 </cell>
27479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27480 \begin_inset Text
27481
27482 \begin_layout Standard
27483 INT2 external interrupt
27484 \end_layout
27485
27486 \end_inset
27487 </cell>
27488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27489 \begin_inset Text
27490
27491 \begin_layout Standard
27492 SIG_PSP
27493 \end_layout
27494
27495 \end_inset
27496 </cell>
27497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27498 \begin_inset Text
27499
27500 \begin_layout Standard
27501 Parallel slave port interrupt
27502 \end_layout
27503
27504 \end_inset
27505 </cell>
27506 </row>
27507 <row topline="true">
27508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27509 \begin_inset Text
27510
27511 \begin_layout Standard
27512 SIG_CCP1
27513 \end_layout
27514
27515 \end_inset
27516 </cell>
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27518 \begin_inset Text
27519
27520 \begin_layout Standard
27521 CCP1 module interrupt
27522 \end_layout
27523
27524 \end_inset
27525 </cell>
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27527 \begin_inset Text
27528
27529 \begin_layout Standard
27530 SIG_AD
27531 \end_layout
27532
27533 \end_inset
27534 </cell>
27535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27536 \begin_inset Text
27537
27538 \begin_layout Standard
27539 AD convertion complete interrupt
27540 \end_layout
27541
27542 \end_inset
27543 </cell>
27544 </row>
27545 <row topline="true">
27546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27547 \begin_inset Text
27548
27549 \begin_layout Standard
27550 SIG_CCP2
27551 \end_layout
27552
27553 \end_inset
27554 </cell>
27555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27556 \begin_inset Text
27557
27558 \begin_layout Standard
27559 CCP2 module interrupt
27560 \end_layout
27561
27562 \end_inset
27563 </cell>
27564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27565 \begin_inset Text
27566
27567 \begin_layout Standard
27568 SIG_RC
27569 \end_layout
27570
27571 \end_inset
27572 </cell>
27573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27574 \begin_inset Text
27575
27576 \begin_layout Standard
27577 USART receive interrupt
27578 \end_layout
27579
27580 \end_inset
27581 </cell>
27582 </row>
27583 <row topline="true">
27584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27585 \begin_inset Text
27586
27587 \begin_layout Standard
27588 SIG_TMR0
27589 \end_layout
27590
27591 \end_inset
27592 </cell>
27593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27594 \begin_inset Text
27595
27596 \begin_layout Standard
27597 TMR0 overflow interrupt
27598 \end_layout
27599
27600 \end_inset
27601 </cell>
27602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27603 \begin_inset Text
27604
27605 \begin_layout Standard
27606 SIG_TX
27607 \end_layout
27608
27609 \end_inset
27610 </cell>
27611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27612 \begin_inset Text
27613
27614 \begin_layout Standard
27615 USART transmit interrupt
27616 \end_layout
27617
27618 \end_inset
27619 </cell>
27620 </row>
27621 <row topline="true">
27622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27623 \begin_inset Text
27624
27625 \begin_layout Standard
27626 SIG_TMR1
27627 \end_layout
27628
27629 \end_inset
27630 </cell>
27631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27632 \begin_inset Text
27633
27634 \begin_layout Standard
27635 TMR1 overflow interrupt
27636 \end_layout
27637
27638 \end_inset
27639 </cell>
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27641 \begin_inset Text
27642
27643 \begin_layout Standard
27644 SIG_MSSP
27645 \end_layout
27646
27647 \end_inset
27648 </cell>
27649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27650 \begin_inset Text
27651
27652 \begin_layout Standard
27653 SSP receive/transmit interrupt
27654 \end_layout
27655
27656 \end_inset
27657 </cell>
27658 </row>
27659 <row topline="true">
27660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27661 \begin_inset Text
27662
27663 \begin_layout Standard
27664 SIG_TMR2
27665 \end_layout
27666
27667 \end_inset
27668 </cell>
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27670 \begin_inset Text
27671
27672 \begin_layout Standard
27673 TMR2 matches PR2 interrupt
27674 \end_layout
27675
27676 \end_inset
27677 </cell>
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27679 \begin_inset Text
27680
27681 \begin_layout Standard
27682
27683 \end_layout
27684
27685 \end_inset
27686 </cell>
27687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27688 \begin_inset Text
27689
27690 \begin_layout Standard
27691
27692 \end_layout
27693
27694 \end_inset
27695 </cell>
27696 </row>
27697 <row topline="true" bottomline="true">
27698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27699 \begin_inset Text
27700
27701 \begin_layout Standard
27702 SIG_TMR3
27703 \end_layout
27704
27705 \end_inset
27706 </cell>
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27708 \begin_inset Text
27709
27710 \begin_layout Standard
27711 TMR3 overflow interrupt
27712 \end_layout
27713
27714 \end_inset
27715 </cell>
27716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27717 \begin_inset Text
27718
27719 \begin_layout Standard
27720
27721 \end_layout
27722
27723 \end_inset
27724 </cell>
27725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27726 \begin_inset Text
27727
27728 \begin_layout Standard
27729
27730 \end_layout
27731
27732 \end_inset
27733 </cell>
27734 </row>
27735 </lyxtabular>
27736
27737 \end_inset
27738
27739
27740 \end_layout
27741
27742 \begin_layout Standard
27743 The prototypes for these names are defined in the header file 
27744 \emph on
27745 signal.h
27746 \emph default
27747  .
27748 \end_layout
27749
27750 \begin_layout Standard
27751 In order to simplify signal handling, a number of macros is provided:
27752 \end_layout
27753
27754 \begin_layout List
27755 \labelwidthstring 00.00.0000
27756 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27757  high priority interrupts.
27758  
27759 \emph on
27760 name
27761 \emph default
27762  is the function name to use.
27763 \end_layout
27764
27765 \begin_layout List
27766 \labelwidthstring 00.00.0000
27767 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27768  low priority interrupt.
27769  
27770 \emph on
27771 name
27772 \emph default
27773  is the function name to use.
27774 \end_layout
27775
27776 \begin_layout List
27777 \labelwidthstring 00.00.0000
27778 DEF_HANDLER(sig,handler) define a handler for signal 
27779 \emph on
27780 sig.
27781 \end_layout
27782
27783 \begin_layout List
27784 \labelwidthstring 00.00.0000
27785 END_DEF end the declaration of the dispatch table.
27786 \end_layout
27787
27788 \begin_layout Standard
27789 Additionally there are two more macros to simplify the declaration of the
27790  signal handler:
27791 \end_layout
27792
27793 \begin_layout List
27794 \labelwidthstring 00.00.0000
27795
27796 \series medium
27797 SIGHANDLER(handler) 
27798 \series default
27799 this declares the function prototype for the 
27800 \emph on
27801 handler
27802 \emph default
27803  function.
27804 \end_layout
27805
27806 \begin_layout List
27807 \labelwidthstring 00.00.0000
27808 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27809 \end_layout
27810
27811 \begin_layout Standard
27812 An example of using the macros above is shown below:
27813 \end_layout
27814
27815 \begin_layout LyX-Code
27816 #include <pic18fregs.h>
27817 \end_layout
27818
27819 \begin_layout LyX-Code
27820 #include <signal.h>
27821 \newline
27822
27823 \newline
27824 DEF_INTHIGH(high_int)
27825 \end_layout
27826
27827 \begin_layout LyX-Code
27828 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27829 \end_layout
27830
27831 \begin_layout LyX-Code
27832 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27833 \end_layout
27834
27835 \begin_layout LyX-Code
27836 END_DEF
27837 \newline
27838
27839 \newline
27840 SIGHANDLER(_tmr0_handler)
27841 \end_layout
27842
27843 \begin_layout LyX-Code
27844 {
27845 \end_layout
27846
27847 \begin_layout LyX-Code
27848   /* action to be taken when timer 0 overflows */
27849 \end_layout
27850
27851 \begin_layout LyX-Code
27852 }
27853 \newline
27854
27855 \newline
27856 SIGHANDLERNAKED(_bcol_handler)
27857 \end_layout
27858
27859 \begin_layout LyX-Code
27860 {
27861 \end_layout
27862
27863 \begin_layout LyX-Code
27864   _asm
27865 \end_layout
27866
27867 \begin_layout LyX-Code
27868     /* action to be taken when bus collision occurs */
27869 \end_layout
27870
27871 \begin_layout LyX-Code
27872     retfie
27873 \end_layout
27874
27875 \begin_layout LyX-Code
27876  _endasm;
27877 \end_layout
27878
27879 \begin_layout LyX-Code
27880 }
27881 \end_layout
27882
27883 \begin_layout Standard
27884
27885 \series bold
27886 NOTES:
27887 \series default
27888  Special care should be taken when using the above scheme:
27889 \end_layout
27890
27891 \begin_layout Itemize
27892 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27893 \end_layout
27894
27895 \begin_layout Itemize
27896 when declaring SIGHANDLERNAKED handler never forget to use 
27897 \emph on
27898 retfie
27899 \emph default
27900  for proper returning.
27901 \end_layout
27902
27903 \begin_layout Subsection
27904 PIC16 Port -- Tips
27905 \end_layout
27906
27907 \begin_layout Standard
27908 Here you can find some general tips for compiling programs with SDCC/pic16.
27909 \end_layout
27910
27911 \begin_layout Subsubsection
27912 Stack size
27913 \end_layout
27914
27915 \begin_layout Standard
27916 The default stack
27917 \begin_inset LatexCommand \index{PIC16!stack}
27918
27919 \end_inset
27920
27921  size (that is 64 bytes) probably is enough for many programs.
27922  One must take care that when there are many levels of function nesting,
27923  or there is excessive usage of stack, its size should be extended.
27924  An example of such a case is the printf/sprintf family of functions.
27925  If you encounter problems like not being able to print integers, then you
27926  need to set the stack size around the maximum (256 for small stack model).
27927  The following diagram shows what happens when calling printf to print an
27928  integer:
27929 \end_layout
27930
27931 \begin_layout LyX-Code
27932 printf () --> ltoa () --> ultoa () --> divschar ()
27933 \end_layout
27934
27935 \begin_layout Standard
27936 It is should be understood that stack is easily consumed when calling complicate
27937 d functions.
27938  Using command line arguments like -
27939 \begin_inset ERT
27940 status collapsed
27941
27942 \begin_layout Standard
27943
27944
27945 \backslash
27946 /
27947 \end_layout
27948
27949 \end_inset
27950
27951 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27952  stack frames.
27953  Other ways to reduce stack usage may exist.
27954 \end_layout
27955
27956 \begin_layout Subsection
27957 Known Bugs
27958 \end_layout
27959
27960 \begin_layout Standard
27961 The PIC16 Port currently does not pass SDCC's regression test
27962 \begin_inset LatexCommand \index{Regression test (PIC16)}
27963
27964 \end_inset
27965
27966  suite (see section 
27967 \begin_inset LatexCommand \ref{sec:Quality-control}
27968
27969 \end_inset
27970
27971 ) and thus the snapshot build regression tests for the PIC16 target are
27972  currently disabled for all hosts
27973 \emph on
27974 .
27975 \end_layout
27976
27977 \begin_layout Chapter
27978 Debugging
27979 \end_layout
27980
27981 \begin_layout Standard
27982 There are several approaches to debugging your code.
27983  This chapter is meant to show your options and to give detail on some of
27984  them:
27985 \newline
27986
27987 \newline
27988 When writing your code:
27989 \end_layout
27990
27991 \begin_layout Itemize
27992 write your code with debugging in mind (avoid duplicating code, put conceptually
27993  similar variables into structs, use structured code, have strategic points
27994  within your code where all variables are consistent, ...)
27995 \end_layout
27996
27997 \begin_layout Itemize
27998 run a syntax-checking tool like splint
27999 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28000
28001 \end_inset
28002
28003
28004 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28005
28006 \end_inset
28007
28008  (see -
28009 \begin_inset ERT
28010 status collapsed
28011
28012 \begin_layout Standard
28013
28014
28015 \backslash
28016 /
28017 \end_layout
28018
28019 \end_inset
28020
28021 -more-pedantic 
28022 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28023
28024 \end_inset
28025
28026 ) over the code.
28027 \end_layout
28028
28029 \begin_layout Itemize
28030 for the high level code use a C-compiler (like f.e.
28031  GCC) to compile run and debug the code on your host.
28032  See (see -
28033 \begin_inset ERT
28034 status collapsed
28035
28036 \begin_layout Standard
28037
28038
28039 \backslash
28040 /
28041 \end_layout
28042
28043 \end_inset
28044
28045 -more-pedantic 
28046 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28047
28048 \end_inset
28049
28050 ) on how to handle syntax extensions like __xdata, __at(), ...
28051  
28052 \end_layout
28053
28054 \begin_layout Itemize
28055 use another C-compiler to compile code for your target.
28056  Always an option but not recommended:) And not very likely to help you.
28057  If you seriously consider walking this path you should at least occasionally
28058  check portability of your code.
28059  Most commercial compiler vendors will offer an evaluation version so you
28060  can test compile your code or snippets of your code.
28061 \end_layout
28062
28063 \begin_layout Standard
28064 Debugging on a simulator:
28065 \end_layout
28066
28067 \begin_layout Itemize
28068 there is a separate section about SDCDB (section 
28069 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28070
28071 \end_inset
28072
28073 ) below.
28074 \end_layout
28075
28076 \begin_layout Itemize
28077 or (8051 specific) use a freeware/commercial simulator which interfaces
28078  to the AOMF
28079 \begin_inset LatexCommand \index{AOMF, AOMF51}
28080
28081 \end_inset
28082
28083  file (see 
28084 \begin_inset LatexCommand \ref{OMF file}
28085
28086 \end_inset
28087
28088 ) optionally generated by SDCC.
28089 \end_layout
28090
28091 \begin_layout Standard
28092 Debugging On-target: 
28093 \end_layout
28094
28095 \begin_layout Itemize
28096 use a MCU port pin to serially output debug data to the RS232 port of your
28097  host.
28098  You'll probably want some level shifting device typically involving a MAX232
28099  or similar IC.
28100  If the hardware serial port of the MCU is not available search for 'Software
28101  UART' in your favourite search machine.
28102 \end_layout
28103
28104 \begin_layout Itemize
28105 use an on-target monitor.
28106  In this context a monitor is a small program which usually accepts commands
28107  via a serial line and allows to set program counter, to single step through
28108  a program and read/write memory locations.
28109  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28110  
28111 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28112
28113 \end_inset
28114
28115 ).
28116 \end_layout
28117
28118 \begin_layout Itemize
28119 toggle MCU port pins at strategic points within your code and use an oscilloscop
28120 e.
28121  A 
28122 \emph on
28123 digital oscilloscope
28124 \emph default
28125
28126 \begin_inset LatexCommand \index{Oscilloscope}
28127
28128 \end_inset
28129
28130  with deep trace memory is really helpful especially if you have to debug
28131  a realtime application.
28132  If you need to monitor more pins than your oscilloscope provides you can
28133  sometimes get away with a small R-2R network.
28134  On a single channel oscilloscope you could f.e.
28135  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28136 k
28137 \begin_inset Formula $\Omega$
28138 \end_inset
28139
28140  resistor and the other one by a 5\InsetSpace ~
28141 k
28142 \begin_inset Formula $\Omega$
28143 \end_inset
28144
28145  resistor to the oscilloscope probe (check output drive capability of the
28146  pins you want to monitor).
28147  If you need to monitor many more pins a 
28148 \emph on
28149 logic analyzer
28150 \emph default
28151  will be handy.
28152 \end_layout
28153
28154 \begin_layout Itemize
28155 use an ICE (
28156 \emph on
28157 i
28158 \emph default
28159
28160 \emph on
28161 c
28162 \emph default
28163 ircuit 
28164 \emph on
28165 e
28166 \emph default
28167 mulator
28168 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28169
28170 \end_inset
28171
28172 ).
28173  Usually very expensive.
28174  And very nice to have too.
28175  And usually locks you (for years...) to the devices the ICE can emulate.
28176  
28177 \end_layout
28178
28179 \begin_layout Itemize
28180 use a remote debugger.
28181  In most 8-bit systems the symbol information is not available on the target,
28182  and a complete debugger is too bulky for the target system.
28183  Therefore usually a debugger on the host system connects to an on-target
28184  debugging stub which accepts only primitive commands.
28185  
28186 \newline
28187 Terms to enter into your favourite search engine could be 'remote debugging',
28188  'gdb stub' or 'inferior debugger'.
28189  (is there one?)
28190 \end_layout
28191
28192 \begin_layout Itemize
28193 use an on target hardware debugger.
28194  Some of the more modern MCUs include hardware support for setting break
28195  points and monitoring/changing variables by using dedicated hardware pins.
28196  This facility doesn't require additional code to run on the target and
28197  
28198 \emph on
28199 usually
28200 \emph default
28201  doesn't affect runtime behaviour until a breakpoint is hit.
28202  For the mcs51 most hardware debuggers use the AOMF
28203 \begin_inset LatexCommand \index{AOMF, AOMF51}
28204
28205 \end_inset
28206
28207  file (see 
28208 \begin_inset LatexCommand \ref{OMF file}
28209
28210 \end_inset
28211
28212 ) as input file.
28213  
28214 \end_layout
28215
28216 \begin_layout Standard
28217 Last not least:
28218 \end_layout
28219
28220 \begin_layout Itemize
28221 if you are not familiar with any of the following terms you're likely to
28222  run into problems rather sooner than later: 
28223 \emph on
28224 volatile
28225 \emph default
28226
28227 \emph on
28228 atomic
28229 \emph default
28230
28231 \emph on
28232 memory map
28233 \emph default
28234
28235 \emph on
28236 overlay
28237 \emph default
28238 .
28239  As an embedded programmer you 
28240 \emph on
28241 have
28242 \emph default
28243  to know them so why not look them up 
28244 \emph on
28245 before
28246 \emph default
28247  you have problems?)
28248 \end_layout
28249
28250 \begin_layout Itemize
28251 tell someone else about your problem (actually this is a surprisingly effective
28252  means to hunt down the bug even if the listener is not familiar with your
28253  environment).
28254  As 'failure to communicate' is probably one of the job-induced deformations
28255  of an embedded programmer this is highly encouraged.
28256 \end_layout
28257
28258 \begin_layout Section
28259 Debugging with SDCDB
28260 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28261
28262 \end_inset
28263
28264
28265 \begin_inset LatexCommand \index{SDCDB (debugger)}
28266
28267 \end_inset
28268
28269  
28270 \end_layout
28271
28272 \begin_layout Standard
28273 SDCC is distributed with a source level debugger
28274 \begin_inset LatexCommand \index{Debugger}
28275
28276 \end_inset
28277
28278 .
28279  The debugger uses a command line interface, the command repertoire of the
28280  debugger has been kept as close to gdb
28281 \begin_inset LatexCommand \index{gdb}
28282
28283 \end_inset
28284
28285  (the GNU debugger) as possible.
28286  The configuration and build process is part of the standard compiler installati
28287 on, which also builds and installs the debugger in the target directory
28288  specified during configuration.
28289  The debugger allows you debug BOTH at the C source and at the ASM source
28290  level.
28291 \end_layout
28292
28293 \begin_layout Subsection
28294 Compiling for Debugging
28295 \end_layout
28296
28297 \begin_layout Standard
28298 The -
28299 \begin_inset ERT
28300 status collapsed
28301
28302 \begin_layout Standard
28303
28304
28305 \backslash
28306 /
28307 \end_layout
28308
28309 \end_inset
28310
28311 -debug
28312 \begin_inset LatexCommand \index{-\/-debug}
28313
28314 \end_inset
28315
28316  option must be specified for all files for which debug information is to
28317  be generated.
28318  The compiler generates a .adb file for each of these files.
28319  The linker creates the .cdb
28320 \begin_inset LatexCommand \index{<file>.cdb}
28321
28322 \end_inset
28323
28324  file from the .adb
28325 \begin_inset LatexCommand \index{<file>.adb}
28326
28327 \end_inset
28328
28329  files and the address information.
28330  This .cdb is used by the debugger.
28331 \end_layout
28332
28333 \begin_layout Subsection
28334 How the Debugger Works
28335 \end_layout
28336
28337 \begin_layout Standard
28338 When the -
28339 \begin_inset ERT
28340 status collapsed
28341
28342 \begin_layout Standard
28343
28344
28345 \backslash
28346 /
28347 \end_layout
28348
28349 \end_inset
28350
28351 -debug option is specified the compiler generates extra symbol information
28352  some of which are put into the assembler source and some are put into the
28353  .adb file.
28354  Then the linker creates the .cdb file from the individual .adb files with
28355  the address information for the symbols.
28356  The debugger reads the symbolic information generated by the compiler &
28357  the address information generated by the linker.
28358  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28359  execution is controlled by the debugger.
28360  When a command is issued for the debugger, it translates it into appropriate
28361  commands for the simulator.
28362  (Currently SDCDM only connects to the simulator but 
28363 \emph on
28364 newcdb
28365 \emph default
28366  at 
28367 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28368
28369 \end_inset
28370
28371  is an effort to connect directly to the hardware.) 
28372 \end_layout
28373
28374 \begin_layout Subsection
28375 Starting the Debugger SDCDB
28376 \end_layout
28377
28378 \begin_layout Standard
28379 The debugger can be started using the following command line.
28380  (Assume the file you are debugging has the file name foo).
28381 \newline
28382
28383 \newline
28384
28385 \family sans
28386 \series bold
28387 sdcdb foo
28388 \newline
28389
28390 \family default
28391 \series default
28392
28393 \newline
28394 The debugger will look for the following files.
28395 \end_layout
28396
28397 \begin_layout Itemize
28398 foo.c - the source file.
28399 \end_layout
28400
28401 \begin_layout Itemize
28402 foo.cdb - the debugger symbol information file.
28403 \end_layout
28404
28405 \begin_layout Itemize
28406 foo.ihx - the Intel hex format
28407 \begin_inset LatexCommand \index{Intel hex format}
28408
28409 \end_inset
28410
28411  object file.
28412 \end_layout
28413
28414 \begin_layout Subsection
28415 SDCDB Command Line Options
28416 \end_layout
28417
28418 \begin_layout Itemize
28419 -
28420 \begin_inset ERT
28421 status collapsed
28422
28423 \begin_layout Standard
28424
28425
28426 \backslash
28427 /
28428 \end_layout
28429
28430 \end_inset
28431
28432 -directory=<source file directory> this option can used to specify the directory
28433  search list.
28434  The debugger will look into the directory list specified for source, cdb
28435  & ihx files.
28436  The items in the directory list must be separated by ':', e.g.
28437  if the source files can be in the directories /home/src1 and /home/src2,
28438  the -
28439 \begin_inset ERT
28440 status collapsed
28441
28442 \begin_layout Standard
28443
28444
28445 \backslash
28446 /
28447 \end_layout
28448
28449 \end_inset
28450
28451 -directory option should be -
28452 \begin_inset ERT
28453 status collapsed
28454
28455 \begin_layout Standard
28456
28457
28458 \backslash
28459 /
28460 \end_layout
28461
28462 \end_inset
28463
28464 -directory=/home/src1:/home/src2.
28465  Note there can be no spaces in the option.
28466  
28467 \end_layout
28468
28469 \begin_layout Itemize
28470 -cd <directory> - change to the <directory>.
28471 \end_layout
28472
28473 \begin_layout Itemize
28474 -fullname - used by GUI front ends.
28475 \end_layout
28476
28477 \begin_layout Itemize
28478 -cpu <cpu-type> - this argument is passed to the simulator please see the
28479  simulator docs for details.
28480 \end_layout
28481
28482 \begin_layout Itemize
28483 -X <Clock frequency > this options is passed to the simulator please see
28484  the simulator docs for details.
28485 \end_layout
28486
28487 \begin_layout Itemize
28488 -s <serial port file> passed to simulator see the simulator docs for details.
28489 \end_layout
28490
28491 \begin_layout Itemize
28492 -S <serial in,out> passed to simulator see the simulator docs for details.
28493 \end_layout
28494
28495 \begin_layout Itemize
28496 -k <port number> passed to simulator see the simulator docs for details.
28497 \end_layout
28498
28499 \begin_layout Subsection
28500 SDCDB Debugger Commands
28501 \end_layout
28502
28503 \begin_layout Standard
28504 As mentioned earlier the command interface for the debugger has been deliberatel
28505 y kept as close the GNU debugger gdb, as possible.
28506  This will help the integration with existing graphical user interfaces
28507  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28508  If you use a graphical user interface for the debugger you can skip this
28509  section.
28510 \end_layout
28511
28512 \begin_layout Subsubsection*
28513 break [line | file:line | function | file:function]
28514 \end_layout
28515
28516 \begin_layout Standard
28517 Set breakpoint at specified line or function:
28518 \newline
28519
28520 \newline
28521
28522 \family sans
28523 \series bold
28524 sdcdb>break 100 
28525 \newline
28526 sdcdb>break foo.c:100
28527 \newline
28528 sdcdb>break funcfoo
28529 \newline
28530 sdcdb>break foo.c:funcfoo
28531 \end_layout
28532
28533 \begin_layout Subsubsection*
28534 clear [line | file:line | function | file:function ]
28535 \end_layout
28536
28537 \begin_layout Standard
28538 Clear breakpoint at specified line or function:
28539 \newline
28540
28541 \newline
28542
28543 \family sans
28544 \series bold
28545 sdcdb>clear 100
28546 \newline
28547 sdcdb>clear foo.c:100
28548 \newline
28549 sdcdb>clear funcfoo
28550 \newline
28551 sdcdb>clear foo.c:funcfoo
28552 \end_layout
28553
28554 \begin_layout Subsubsection*
28555 continue
28556 \end_layout
28557
28558 \begin_layout Standard
28559 Continue program being debugged, after breakpoint.
28560 \end_layout
28561
28562 \begin_layout Subsubsection*
28563 finish
28564 \end_layout
28565
28566 \begin_layout Standard
28567 Execute till the end of the current function.
28568 \end_layout
28569
28570 \begin_layout Subsubsection*
28571 delete [n]
28572 \end_layout
28573
28574 \begin_layout Standard
28575 Delete breakpoint number 'n'.
28576  If used without any option clear ALL user defined break points.
28577 \end_layout
28578
28579 \begin_layout Subsubsection*
28580 info [break | stack | frame | registers ]
28581 \end_layout
28582
28583 \begin_layout Itemize
28584 info break - list all breakpoints
28585 \end_layout
28586
28587 \begin_layout Itemize
28588 info stack - show the function call stack.
28589 \end_layout
28590
28591 \begin_layout Itemize
28592 info frame - show information about the current execution frame.
28593 \end_layout
28594
28595 \begin_layout Itemize
28596 info registers - show content of all registers.
28597 \end_layout
28598
28599 \begin_layout Subsubsection*
28600 step
28601 \end_layout
28602
28603 \begin_layout Standard
28604 Step program until it reaches a different source line.
28605  Note: pressing <return> repeats the last command.
28606 \end_layout
28607
28608 \begin_layout Subsubsection*
28609 next
28610 \end_layout
28611
28612 \begin_layout Standard
28613 Step program, proceeding through subroutine calls.
28614 \end_layout
28615
28616 \begin_layout Subsubsection*
28617 run
28618 \end_layout
28619
28620 \begin_layout Standard
28621 Start debugged program.
28622 \end_layout
28623
28624 \begin_layout Subsubsection*
28625 ptype variable 
28626 \end_layout
28627
28628 \begin_layout Standard
28629 Print type information of the variable.
28630 \end_layout
28631
28632 \begin_layout Subsubsection*
28633 print variable
28634 \end_layout
28635
28636 \begin_layout Standard
28637 print value of variable.
28638 \end_layout
28639
28640 \begin_layout Subsubsection*
28641 file filename
28642 \end_layout
28643
28644 \begin_layout Standard
28645 load the given file name.
28646  Note this is an alternate method of loading file for debugging.
28647 \end_layout
28648
28649 \begin_layout Subsubsection*
28650 frame
28651 \end_layout
28652
28653 \begin_layout Standard
28654 print information about current frame.
28655 \end_layout
28656
28657 \begin_layout Subsubsection*
28658 set srcmode
28659 \end_layout
28660
28661 \begin_layout Standard
28662 Toggle between C source & assembly source.
28663 \end_layout
28664
28665 \begin_layout Subsubsection*
28666 ! simulator command
28667 \end_layout
28668
28669 \begin_layout Standard
28670 Send the string following '!' to the simulator, the simulator response is
28671  displayed.
28672  Note the debugger does not interpret the command being sent to the simulator,
28673  so if a command like 'go' is sent the debugger can loose its execution
28674  context and may display incorrect values.
28675 \end_layout
28676
28677 \begin_layout Subsubsection*
28678 quit
28679 \end_layout
28680
28681 \begin_layout Standard
28682 "Watch me now.
28683  Iam going Down.
28684  My name is Bobby Brown"
28685 \end_layout
28686
28687 \begin_layout Subsection
28688 Interfacing SDCDB with DDD
28689 \end_layout
28690
28691 \begin_layout Standard
28692 \begin_inset Note Note
28693 status collapsed
28694
28695 \begin_layout Standard
28696 The screenshot was converted from png to eps with: 
28697 \begin_inset Quotes sld
28698 \end_inset
28699
28700 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28701 \begin_inset Quotes srd
28702 \end_inset
28703
28704  which produces a pretty compact eps file which is free from compression
28705  artifacts.
28706 \end_layout
28707
28708 \begin_layout Standard
28709 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28710  as this broke the build system on Sourceforge (pdf-file was broken.
28711  pdflatex does not accept eps files).
28712 \end_layout
28713
28714 \end_inset
28715
28716
28717 \end_layout
28718
28719 \begin_layout Standard
28720 The 
28721 \emph on
28722 p
28723 \emph default
28724 ortable 
28725 \emph on
28726 n
28727 \emph default
28728 etwork 
28729 \emph on
28730 g
28731 \emph default
28732 raphics File 
28733 \size footnotesize
28734
28735 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28736
28737 \end_inset
28738
28739
28740 \size default
28741  shows a screenshot of a debugging session with DDD
28742 \begin_inset LatexCommand \index{DDD (debugger)}
28743
28744 \end_inset
28745
28746  (Unix only) on a simulated 8032.
28747  The debugging session might not run as smoothly as the screenshot suggests.
28748  The debugger allows setting of breakpoints, displaying and changing variables,
28749  single stepping through C and assembler code.
28750  
28751 \newline
28752 The source was compiled with 
28753 \family sans
28754 \series bold
28755
28756 \newline
28757
28758 \newline
28759 sdcc -
28760 \family default
28761 \series default
28762
28763 \begin_inset ERT
28764 status collapsed
28765
28766 \begin_layout Standard
28767
28768
28769 \backslash
28770 /
28771 \end_layout
28772
28773 \end_inset
28774
28775
28776 \family sans
28777 \series bold
28778 -debug ddd_example.c
28779 \family default
28780 \series default
28781  
28782 \family sans
28783 \series bold
28784
28785 \newline
28786
28787 \family default
28788 \series default
28789
28790 \newline
28791 and DDD was invoked with 
28792 \family sans
28793 \series bold
28794
28795 \newline
28796
28797 \newline
28798 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28799 \end_layout
28800
28801 \begin_layout Standard
28802 \begin_inset Note Note
28803 status open
28804
28805 \begin_layout Standard
28806 Check that the double quotes or an apostroph within the command line survive
28807  the LyX tool chain.
28808  Previously the apostrophs got slanted in the PDF output so a cut and paste
28809  did not work.
28810 \end_layout
28811
28812 \end_inset
28813
28814
28815 \end_layout
28816
28817 \begin_layout Subsection
28818 Interfacing SDCDB with XEmacs
28819 \begin_inset LatexCommand \index{XEmacs}
28820
28821 \end_inset
28822
28823
28824 \begin_inset LatexCommand \index{Emacs}
28825
28826 \end_inset
28827
28828
28829 \end_layout
28830
28831 \begin_layout Standard
28832 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28833  sdcdb.el and sdcdbsrc.el.
28834  These two files can be found in the $(prefix)/bin directory after the installat
28835 ion is complete.
28836  These files need to be loaded into XEmacs for the interface to work.
28837  This can be done at XEmacs startup time by inserting the following into
28838  your '.xemacs' file (which can be found in your HOME directory): 
28839 \newline
28840
28841 \newline
28842
28843 \family typewriter
28844 (load-file sdcdbsrc.el) 
28845 \family default
28846
28847 \newline
28848
28849 \newline
28850 .xemacs is a lisp file so the () around the command is REQUIRED.
28851  The files can also be loaded dynamically while XEmacs is running, set the
28852  environment variable 'EMACSLOADPATH' to the installation bin directory
28853  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28854  To start the interface enter the following command: 
28855 \newline
28856
28857 \newline
28858
28859 \family sans
28860 \series bold
28861 ESC-x sdcdbsrc
28862 \family default
28863 \series default
28864
28865 \newline
28866
28867 \newline
28868 You will prompted to enter the file name to be debugged.
28869  
28870 \newline
28871
28872 \newline
28873 The command line options that are passed to the simulator directly are
28874  bound to default values in the file sdcdbsrc.el.
28875  The variables are listed below, these values maybe changed as required.
28876 \end_layout
28877
28878 \begin_layout Itemize
28879 sdcdbsrc-cpu-type '51
28880 \end_layout
28881
28882 \begin_layout Itemize
28883 sdcdbsrc-frequency '11059200
28884 \end_layout
28885
28886 \begin_layout Itemize
28887 sdcdbsrc-serial nil
28888 \end_layout
28889
28890 \begin_layout Standard
28891 The following is a list of key mapping for the debugger interface.
28892 \end_layout
28893
28894 \begin_layout Standard
28895 \InsetSpace ~
28896
28897 \family typewriter
28898
28899 \newline
28900 ;;\InsetSpace ~
28901 Current Listing :: 
28902 \newline
28903 ;;key\InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 binding\InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 Comment 
28940 \newline
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 \InsetSpace ~
28955 -------\InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 \InsetSpace ~
28964 \InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 -------
28978 \newline
28979 ;; 
28980 \newline
28981 ;;\InsetSpace ~
28982 n\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 sdcdb-next-fro
28998 m-src\InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
29007 \InsetSpace ~
29008 SDCDB next command 
29009 \newline
29010 ;;\InsetSpace ~
29011 b\InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 \InsetSpace ~
29015 \InsetSpace ~
29016 \InsetSpace ~
29017 \InsetSpace ~
29018 \InsetSpace ~
29019 \InsetSpace ~
29020 \InsetSpace ~
29021 \InsetSpace ~
29022 \InsetSpace ~
29023 \InsetSpace ~
29024 \InsetSpace ~
29025 \InsetSpace ~
29026 sdcdb-back-from-src\InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 \InsetSpace ~
29035 \InsetSpace ~
29036 SDCDB back command 
29037 \newline
29038 ;;\InsetSpace ~
29039 c\InsetSpace ~
29040 \InsetSpace ~
29041 \InsetSpace ~
29042 \InsetSpace ~
29043 \InsetSpace ~
29044 \InsetSpace ~
29045 \InsetSpace ~
29046 \InsetSpace ~
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 \InsetSpace ~
29051 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 sdcdb-cont-f
29055 rom-src\InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 SDCDB continue command
29066 \newline
29067 ;;\InsetSpace ~
29068 s\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 sdcdb-step-from-src\InsetSpace ~
29084 \InsetSpace ~
29085 \InsetSpace ~
29086 \InsetSpace ~
29087 \InsetSpace ~
29088 \InsetSpace ~
29089 \InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 SDCDB step command 
29094 \newline
29095 ;;\InsetSpace ~
29096 ?\InsetSpace ~
29097 \InsetSpace ~
29098 \InsetSpace ~
29099 \InsetSpace ~
29100 \InsetSpace ~
29101 \InsetSpace ~
29102 \InsetSpace ~
29103 \InsetSpace ~
29104 \InsetSpace ~
29105 \InsetSpace ~
29106 \InsetSpace ~
29107 \InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 sdcdb-w
29112 hatis-c-sexp\InsetSpace ~
29113 \InsetSpace ~
29114 \InsetSpace ~
29115 \InsetSpace ~
29116 \InsetSpace ~
29117 \InsetSpace ~
29118 \InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 \InsetSpace ~
29122 SDCDB ptypecommand for data at 
29123 \newline
29124 ;;\InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 \InsetSpace ~
29131 \InsetSpace ~
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 buffer point 
29172 \newline
29173 ;;\InsetSpace ~
29174 x\InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 \InsetSpace ~
29178 \InsetSpace ~
29179 \InsetSpace ~
29180 \InsetSpace ~
29181 \InsetSpace ~
29182 \InsetSpace ~
29183 \InsetSpace ~
29184 \InsetSpace ~
29185 \InsetSpace ~
29186 \InsetSpace ~
29187 \InsetSpace ~
29188 \InsetSpace ~
29189 sdcdbsrc-delete\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 SDCD
29204 B Delete all breakpoints if no arg 
29205 \newline
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 \InsetSpace ~
29230 \InsetSpace ~
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 \InsetSpace ~
29248 \InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 \InsetSpace ~
29252 \InsetSpace ~
29253 given or delete arg (C-u arg x) 
29254 \newline
29255 ;;\InsetSpace ~
29256 m\InsetSpace ~
29257 \InsetSpace ~
29258 \InsetSpace ~
29259 \InsetSpace ~
29260 \InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 \InsetSpace ~
29271 sdcdbsrc
29272 -frame\InsetSpace ~
29273 \InsetSpace ~
29274 \InsetSpace ~
29275 \InsetSpace ~
29276 \InsetSpace ~
29277 \InsetSpace ~
29278 \InsetSpace ~
29279 \InsetSpace ~
29280 \InsetSpace ~
29281 \InsetSpace ~
29282 \InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 SDCDB Display current frame if no arg, 
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 given or display frame arg
29337  
29338 \newline
29339 ;;\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 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 \InsetSpace ~
29364 \InsetSpace ~
29365 \InsetSpace ~
29366 \InsetSpace ~
29367 \InsetSpace ~
29368 \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 \InsetSpace ~
29384 \InsetSpace ~
29385 \InsetSpace ~
29386 buffer point 
29387 \newline
29388 ;;\InsetSpace ~
29389 !\InsetSpace ~
29390 \InsetSpace ~
29391 \InsetSpace ~
29392 \InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 \InsetSpace ~
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 \InsetSpace ~
29403 \InsetSpace ~
29404 sdcdbsrc-goto-sdcdb\InsetSpace ~
29405 \InsetSpace ~
29406 \InsetSpace ~
29407 \InsetSpace ~
29408 \InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 Goto the SDCDB output buffer 
29415 \newline
29416 ;;\InsetSpace ~
29417 p\InsetSpace ~
29418 \InsetSpace ~
29419 \InsetSpace ~
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 \InsetSpace ~
29424 \InsetSpace ~
29425 \InsetSpace ~
29426 \InsetSpace ~
29427 \InsetSpace ~
29428 \InsetSpace ~
29429 \InsetSpace ~
29430 \InsetSpace ~
29431 \InsetSpace ~
29432 sdcdb-prin
29433 t-c-sexp\InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 \InsetSpace ~
29439 \InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 SDCDB print command for data at 
29445 \newline
29446 ;;\InsetSpace ~
29447 \InsetSpace ~
29448 \InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 \InsetSpace ~
29459 \InsetSpace ~
29460 \InsetSpace ~
29461 \InsetSpace ~
29462 \InsetSpace ~
29463 \InsetSpace ~
29464 \InsetSpace ~
29465 \InsetSpace ~
29466 \InsetSpace ~
29467 \InsetSpace ~
29468 \InsetSpace ~
29469 \InsetSpace ~
29470 \InsetSpace ~
29471 \InsetSpace ~
29472 \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 \InsetSpace ~
29489 \InsetSpace ~
29490 \InsetSpace ~
29491 \InsetSpace ~
29492 \InsetSpace ~
29493 buffer point 
29494 \newline
29495 ;;\InsetSpace ~
29496 g\InsetSpace ~
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500 \InsetSpace ~
29501 \InsetSpace ~
29502 \InsetSpace ~
29503 \InsetSpace ~
29504 \InsetSpace ~
29505 \InsetSpace ~
29506 \InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 sdcdbsrc-goto-sdcdb\InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 \InsetSpace ~
29516 \InsetSpace ~
29517 \InsetSpace ~
29518 \InsetSpace ~
29519 \InsetSpace ~
29520 \InsetSpace ~
29521 Got
29522 o the SDCDB output buffer 
29523 \newline
29524 ;;\InsetSpace ~
29525 t\InsetSpace ~
29526 \InsetSpace ~
29527 \InsetSpace ~
29528 \InsetSpace ~
29529 \InsetSpace ~
29530 \InsetSpace ~
29531 \InsetSpace ~
29532 \InsetSpace ~
29533 \InsetSpace ~
29534 \InsetSpace ~
29535 \InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 sdcdbsrc-mode\InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 \InsetSpace ~
29544 \InsetSpace ~
29545 \InsetSpace ~
29546 \InsetSpace ~
29547 \InsetSpace ~
29548 \InsetSpace ~
29549 \InsetSpace ~
29550 \InsetSpace ~
29551 \InsetSpace ~
29552 \InsetSpace ~
29553 \InsetSpace ~
29554 \InsetSpace ~
29555 \InsetSpace ~
29556 Toggles Sdcdbsrc mode (turns it
29557  off) 
29558 \newline
29559 ;; 
29560 \newline
29561 ;;\InsetSpace ~
29562 C-c\InsetSpace ~
29563 C-f\InsetSpace ~
29564 \InsetSpace ~
29565 \InsetSpace ~
29566 \InsetSpace ~
29567 \InsetSpace ~
29568 \InsetSpace ~
29569 \InsetSpace ~
29570 \InsetSpace ~
29571 \InsetSpace ~
29572 sdcdb-finish-from-src\InsetSpace ~
29573 \InsetSpace ~
29574 \InsetSpace ~
29575 \InsetSpace ~
29576 \InsetSpace ~
29577 \InsetSpace ~
29578 \InsetSpace ~
29579 \InsetSpace ~
29580 SDCDB finish command 
29581 \newline
29582 ;; 
29583 \newline
29584 ;;\InsetSpace ~
29585 C-x\InsetSpace ~
29586 SPC\InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 \InsetSpace ~
29592 \InsetSpace ~
29593 \InsetSpace ~
29594 \InsetSpace ~
29595 sdcdb-brea
29596 k\InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 Set break for line with point 
29615 \newline
29616 ;;\InsetSpace ~
29617 ESC\InsetSpace ~
29618 t\InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 sdcdbsrc-mode\InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 Toggle Sdcdbsrc mode 
29646 \newline
29647 ;;\InsetSpace ~
29648 ESC\InsetSpace ~
29649 m\InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 \InsetSpace ~
29658 \InsetSpace ~
29659 \InsetSpace ~
29660 sdc
29661 dbsrc-srcmode\InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 Toggle list mode 
29675 \newline
29676 ;; 
29677 \newline
29678
29679 \family default
29680
29681 \newpage
29682
29683 \end_layout
29684
29685 \begin_layout Chapter
29686 TIPS
29687 \end_layout
29688
29689 \begin_layout Standard
29690 Here are a few guidelines that will help the compiler generate more efficient
29691  code, some of the tips are specific to this compiler others are generally
29692  good programming practice.
29693 \end_layout
29694
29695 \begin_layout Itemize
29696 Use the smallest data type to represent your data-value.
29697  If it is known in advance that the value is going to be less than 256 then
29698  use an 'unsigned char' instead of a 'short' or 'int'.
29699  Please note, that ANSI C requires both signed and unsigned chars to be
29700  promoted to 'signed int'
29701 \begin_inset LatexCommand \index{promotion to signed int}
29702
29703 \end_inset
29704
29705
29706 \begin_inset Marginal
29707 status collapsed
29708
29709 \begin_layout Standard
29710
29711 \series bold
29712 \InsetSpace ~
29713 !
29714 \end_layout
29715
29716 \end_inset
29717
29718  before doing any operation.
29719  This promotion
29720 \begin_inset LatexCommand \index{type promotion}
29721
29722 \end_inset
29723
29724
29725 \begin_inset LatexCommand \label{type promotion}
29726
29727 \end_inset
29728
29729  can be omitted, if the result is the same.
29730  The effect of the promotion rules together with the sign-extension is often
29731  surprising:
29732 \end_layout
29733
29734 \begin_deeper
29735 \begin_layout Verse
29736
29737 \family typewriter
29738 unsigned char uc = 0xfe;
29739 \newline
29740 if (uc * uc < 0) /* this is true! */
29741 \newline
29742 {
29743 \newline
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 ....
29749 \newline
29750 }
29751 \end_layout
29752
29753 \begin_layout Standard
29754
29755 \family typewriter
29756 uc * uc
29757 \family default
29758  is evaluated as 
29759 \family typewriter
29760 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29761 \family default
29762 .
29763  
29764 \newline
29765 Another one:
29766 \end_layout
29767
29768 \begin_layout Verse
29769
29770 \family typewriter
29771 (unsigned char) -12 / (signed char) -3 = ...
29772 \end_layout
29773
29774 \begin_layout Standard
29775 No, the result is not 4:
29776 \end_layout
29777
29778 \begin_layout Verse
29779
29780 \family typewriter
29781 (int) (unsigned char) -12 / (int) (signed char) -3 =
29782 \newline
29783 (int) (unsigned char)
29784  0xf4 / (int) (signed char) 0xfd =
29785 \newline
29786 (int) 0x00f4 / (int) 0xfffd =
29787 \newline
29788 (int) 0x00f4
29789  / (int) 0xfffd =
29790 \newline
29791 (int) 244 / (int) -3 =
29792 \newline
29793 (int) -81 = (int) 0xffaf;
29794 \end_layout
29795
29796 \begin_layout Standard
29797 Don't complain, that gcc gives you a different result.
29798  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29799  Therefore the results are different.
29800 \newline
29801 From 
29802 \begin_inset Quotes sld
29803 \end_inset
29804
29805 comp.lang.c FAQ
29806 \begin_inset Quotes srd
29807 \end_inset
29808
29809 :
29810 \end_layout
29811
29812 \begin_layout Quote
29813
29814 \emph on
29815 If well-defined overflow characteristics are important and negative values
29816  are not, or if you want to steer clear of sign-extension problems when
29817  manipulating bits or bytes, use one of the corresponding unsigned types.
29818  (Beware when mixing signed and unsigned values in expressions, though.)
29819 \newline
29820 Although
29821  character types (especially unsigned char) can be used as "tiny" integers,
29822  doing so is sometimes more trouble than it's worth, due to unpredictable
29823  sign extension and increased code size.
29824 \end_layout
29825
29826 \end_deeper
29827 \begin_layout Itemize
29828 Use unsigned when it is known in advance that the value is not going to
29829  be negative.
29830  This helps especially if you are doing division or multiplication, bit-shifting
29831  or are using an array index.
29832 \end_layout
29833
29834 \begin_layout Itemize
29835 NEVER jump into a LOOP.
29836 \end_layout
29837
29838 \begin_layout Itemize
29839 Declare the variables to be local
29840 \begin_inset LatexCommand \index{local variables}
29841
29842 \end_inset
29843
29844  whenever possible, especially loop control variables (induction).
29845 \end_layout
29846
29847 \begin_layout Itemize
29848 Have a look at the assembly listing to get a 
29849 \begin_inset Quotes sld
29850 \end_inset
29851
29852 feeling
29853 \begin_inset Quotes srd
29854 \end_inset
29855
29856  for the code generation.
29857 \end_layout
29858
29859 \begin_layout Section
29860 Porting code from or to other compilers
29861 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29862
29863 \end_inset
29864
29865
29866 \end_layout
29867
29868 \begin_layout Itemize
29869 check whether endianness of the compilers differs and adapt where needed.
29870 \end_layout
29871
29872 \begin_layout Itemize
29873 check the device specific header files
29874 \begin_inset LatexCommand \index{Header files}
29875
29876 \end_inset
29877
29878
29879 \begin_inset LatexCommand \index{Include files}
29880
29881 \end_inset
29882
29883  for compiler specific syntax.
29884  Eventually include the file <compiler.h
29885 \begin_inset LatexCommand \index{compiler.h (include file)}
29886
29887 \end_inset
29888
29889
29890 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29891
29892 \end_inset
29893
29894  to allow using common header files.
29895  (see f.e.
29896  cc2510fx.h 
29897 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29898
29899 \end_inset
29900
29901 ).
29902 \end_layout
29903
29904 \begin_layout Itemize
29905 check whether the startup code contains the correct initialization (watchdog,
29906  peripherals).
29907 \end_layout
29908
29909 \begin_layout Itemize
29910 check whether the sizes of short, int, long match.
29911 \end_layout
29912
29913 \begin_layout Itemize
29914 check if some 16 or 32 bit hardware registers require a specific addressing
29915  order (least significant or most significant byte first) and adapt if needed
29916  (
29917 \emph on
29918 first
29919 \emph default
29920  and 
29921 \emph on
29922 last
29923 \emph default
29924  relate to time and not to lower/upper memory location here, so this is
29925  
29926 \emph on
29927 not
29928 \emph default
29929  the same as endianness).
29930 \end_layout
29931
29932 \begin_layout Itemize
29933 check whether the keyword 
29934 \emph on
29935 volatile
29936 \emph default
29937  is used where needed.
29938  The compilers might differ in their optimization characteristics (as different
29939  versions of the same compiler might also use more clever optimizations
29940  this is good idea anyway).
29941  See section 
29942 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29943
29944 \end_inset
29945
29946 .
29947 \end_layout
29948
29949 \begin_layout Itemize
29950 check that the compilers are not told to supress warnings.
29951 \end_layout
29952
29953 \begin_layout Itemize
29954 check and convert compiler specific extensions (interrupts, memory areas,
29955  pragmas etc.).
29956 \end_layout
29957
29958 \begin_layout Itemize
29959 check for differences in type promotion.
29960  Especially check for math operations on 
29961 \family typewriter
29962 char
29963 \family default
29964  or 
29965 \family typewriter
29966 unsigned char
29967 \family default
29968  variables.
29969  For the sake of C99 compatibility SDCC will probably promote these to 
29970 \family typewriter
29971 int
29972 \family default
29973  more often than other compilers.
29974  Eventually insert explicit casts to 
29975 \family typewriter
29976 (char) 
29977 \family default
29978 or
29979 \family typewriter
29980  (unsigned char)
29981 \family default
29982 .
29983  Also check that the ~\InsetSpace ~
29984 operator
29985 \begin_inset LatexCommand \index{\~\/ Operator}
29986
29987 \end_inset
29988
29989  is not used on 
29990 \family typewriter
29991 bit
29992 \begin_inset LatexCommand \index{bit}
29993
29994 \end_inset
29995
29996
29997 \family default
29998  variables, use the !\InsetSpace ~
29999 operator instead.
30000  See sections 
30001 \begin_inset LatexCommand \ref{type promotion}
30002
30003 \end_inset
30004
30005  and 
30006 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30007
30008 \end_inset
30009
30010 .
30011 \end_layout
30012
30013 \begin_layout Itemize
30014 check the assembly code generated for interrupt routines (f.e.
30015  for calls to possibly non-reentrant library functions).
30016 \end_layout
30017
30018 \begin_layout Itemize
30019 check whether timing loops result in proper timing (or preferably consider
30020  a rewrite of the code with timer based delays instead).
30021 \end_layout
30022
30023 \begin_layout Itemize
30024 check for differences in printf parameters (some compilers push (va_arg
30025 \begin_inset LatexCommand \index{vararg, va\_arg}
30026
30027 \end_inset
30028
30029 ) char variables as 
30030 \family typewriter
30031 int
30032 \family default
30033  others push them as 
30034 \family typewriter
30035 char
30036 \family default
30037 .
30038  See section 
30039 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30040
30041 \end_inset
30042
30043 ).
30044 \end_layout
30045
30046 \begin_layout Itemize
30047 check the resulting memory map
30048 \begin_inset LatexCommand \index{Memory map}
30049
30050 \end_inset
30051
30052 .
30053  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30054 ly idata, pdata, xdata).
30055  Eventually check if unexpected library functions are included.
30056 \end_layout
30057
30058 \begin_layout Section
30059 Tools
30060 \begin_inset LatexCommand \index{Tools}
30061
30062 \end_inset
30063
30064  included in the distribution
30065 \end_layout
30066
30067 \begin_layout Standard
30068 \align left
30069 \begin_inset Tabular
30070 <lyxtabular version="3" rows="12" columns="3">
30071 <features>
30072 <column alignment="left" valignment="top" leftline="true" width="0pt">
30073 <column alignment="left" valignment="top" leftline="true" width="0pt">
30074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30075 <row topline="true" bottomline="true">
30076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30077 \begin_inset Text
30078
30079 \begin_layout Standard
30080
30081 \series bold
30082 Name
30083 \end_layout
30084
30085 \end_inset
30086 </cell>
30087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30088 \begin_inset Text
30089
30090 \begin_layout Standard
30091
30092 \series bold
30093 Purpose
30094 \end_layout
30095
30096 \end_inset
30097 </cell>
30098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30099 \begin_inset Text
30100
30101 \begin_layout Standard
30102
30103 \series bold
30104 Directory
30105 \end_layout
30106
30107 \end_inset
30108 </cell>
30109 </row>
30110 <row topline="true">
30111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30112 \begin_inset Text
30113
30114 \begin_layout Standard
30115 uCsim
30116 \begin_inset LatexCommand \index{uCsim}
30117
30118 \end_inset
30119
30120
30121 \end_layout
30122
30123 \end_inset
30124 </cell>
30125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30126 \begin_inset Text
30127
30128 \begin_layout Standard
30129 Simulator for various architectures
30130 \end_layout
30131
30132 \end_inset
30133 </cell>
30134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30135 \begin_inset Text
30136
30137 \begin_layout Standard
30138 sdcc/sim/ucsim
30139 \end_layout
30140
30141 \end_inset
30142 </cell>
30143 </row>
30144 <row topline="true">
30145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30146 \begin_inset Text
30147
30148 \begin_layout Standard
30149 keil2sdcc.pl
30150 \end_layout
30151
30152 \end_inset
30153 </cell>
30154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30155 \begin_inset Text
30156
30157 \begin_layout Standard
30158 header file
30159 \begin_inset LatexCommand \index{Header files}
30160
30161 \end_inset
30162
30163
30164 \begin_inset LatexCommand \index{Include files}
30165
30166 \end_inset
30167
30168  conversion
30169 \end_layout
30170
30171 \end_inset
30172 </cell>
30173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30174 \begin_inset Text
30175
30176 \begin_layout Standard
30177 sdcc/support/scripts
30178 \end_layout
30179
30180 \end_inset
30181 </cell>
30182 </row>
30183 <row topline="true">
30184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30185 \begin_inset Text
30186
30187 \begin_layout Standard
30188 mh2h.c
30189 \end_layout
30190
30191 \end_inset
30192 </cell>
30193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30194 \begin_inset Text
30195
30196 \begin_layout Standard
30197 header file conversion
30198 \end_layout
30199
30200 \end_inset
30201 </cell>
30202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30203 \begin_inset Text
30204
30205 \begin_layout Standard
30206 sdcc/support/scripts
30207 \end_layout
30208
30209 \end_inset
30210 </cell>
30211 </row>
30212 <row topline="true">
30213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30214 \begin_inset Text
30215
30216 \begin_layout Standard
30217 as-gbz80
30218 \end_layout
30219
30220 \end_inset
30221 </cell>
30222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30223 \begin_inset Text
30224
30225 \begin_layout Standard
30226 Assembler
30227 \end_layout
30228
30229 \end_inset
30230 </cell>
30231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30232 \begin_inset Text
30233
30234 \begin_layout Standard
30235
30236 \family roman
30237 \series medium
30238 \shape up
30239 \size normal
30240 \emph off
30241 \bar no
30242 \noun off
30243 \color none
30244 sdcc/bin
30245 \end_layout
30246
30247 \end_inset
30248 </cell>
30249 </row>
30250 <row topline="true">
30251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30252 \begin_inset Text
30253
30254 \begin_layout Standard
30255 as-z80
30256 \end_layout
30257
30258 \end_inset
30259 </cell>
30260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30261 \begin_inset Text
30262
30263 \begin_layout Standard
30264 Assembler
30265 \end_layout
30266
30267 \end_inset
30268 </cell>
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30270 \begin_inset Text
30271
30272 \begin_layout Standard
30273
30274 \family roman
30275 \series medium
30276 \shape up
30277 \size normal
30278 \emph off
30279 \bar no
30280 \noun off
30281 \color none
30282 sdcc/bin
30283 \end_layout
30284
30285 \end_inset
30286 </cell>
30287 </row>
30288 <row topline="true">
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30290 \begin_inset Text
30291
30292 \begin_layout Standard
30293 asx8051
30294 \end_layout
30295
30296 \end_inset
30297 </cell>
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30299 \begin_inset Text
30300
30301 \begin_layout Standard
30302 Assembler
30303 \end_layout
30304
30305 \end_inset
30306 </cell>
30307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30308 \begin_inset Text
30309
30310 \begin_layout Standard
30311
30312 \family roman
30313 \series medium
30314 \shape up
30315 \size normal
30316 \emph off
30317 \bar no
30318 \noun off
30319 \color none
30320 sdcc/bin
30321 \end_layout
30322
30323 \end_inset
30324 </cell>
30325 </row>
30326 <row topline="true">
30327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30328 \begin_inset Text
30329
30330 \begin_layout Standard
30331 SDCDB
30332 \end_layout
30333
30334 \end_inset
30335 </cell>
30336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30337 \begin_inset Text
30338
30339 \begin_layout Standard
30340 Simulator
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 <row topline="true">
30365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30366 \begin_inset Text
30367
30368 \begin_layout Standard
30369 aslink
30370 \end_layout
30371
30372 \end_inset
30373 </cell>
30374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30375 \begin_inset Text
30376
30377 \begin_layout Standard
30378 Linker
30379 \end_layout
30380
30381 \end_inset
30382 </cell>
30383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30384 \begin_inset Text
30385
30386 \begin_layout Standard
30387
30388 \family roman
30389 \series medium
30390 \shape up
30391 \size normal
30392 \emph off
30393 \bar no
30394 \noun off
30395 \color none
30396 sdcc/bin
30397 \end_layout
30398
30399 \end_inset
30400 </cell>
30401 </row>
30402 <row topline="true">
30403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30404 \begin_inset Text
30405
30406 \begin_layout Standard
30407 link-z80
30408 \end_layout
30409
30410 \end_inset
30411 </cell>
30412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30413 \begin_inset Text
30414
30415 \begin_layout Standard
30416 Linker
30417 \end_layout
30418
30419 \end_inset
30420 </cell>
30421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30422 \begin_inset Text
30423
30424 \begin_layout Standard
30425
30426 \family roman
30427 \series medium
30428 \shape up
30429 \size normal
30430 \emph off
30431 \bar no
30432 \noun off
30433 \color none
30434 sdcc/bin
30435 \end_layout
30436
30437 \end_inset
30438 </cell>
30439 </row>
30440 <row topline="true">
30441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30442 \begin_inset Text
30443
30444 \begin_layout Standard
30445 link-gbz80
30446 \end_layout
30447
30448 \end_inset
30449 </cell>
30450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30451 \begin_inset Text
30452
30453 \begin_layout Standard
30454 Linker
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
30464 \family roman
30465 \series medium
30466 \shape up
30467 \size normal
30468 \emph off
30469 \bar no
30470 \noun off
30471 \color none
30472 sdcc/bin
30473 \end_layout
30474
30475 \end_inset
30476 </cell>
30477 </row>
30478 <row topline="true" bottomline="true">
30479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30480 \begin_inset Text
30481
30482 \begin_layout Standard
30483 packihx
30484 \end_layout
30485
30486 \end_inset
30487 </cell>
30488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30489 \begin_inset Text
30490
30491 \begin_layout Standard
30492 Intel Hex packer 
30493 \begin_inset LatexCommand \index{packihx (tool)}
30494
30495 \end_inset
30496
30497
30498 \end_layout
30499
30500 \end_inset
30501 </cell>
30502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30503 \begin_inset Text
30504
30505 \begin_layout Standard
30506
30507 \family roman
30508 \series medium
30509 \shape up
30510 \size normal
30511 \emph off
30512 \bar no
30513 \noun off
30514 \color none
30515 sdcc/bin
30516 \end_layout
30517
30518 \end_inset
30519 </cell>
30520 </row>
30521 </lyxtabular>
30522
30523 \end_inset
30524
30525
30526 \newline
30527
30528 \end_layout
30529
30530 \begin_layout Section
30531 Documentation
30532 \begin_inset LatexCommand \index{Documentation}
30533
30534 \end_inset
30535
30536  included in the distribution
30537 \end_layout
30538
30539 \begin_layout Standard
30540 \align left
30541 \begin_inset Tabular
30542 <lyxtabular version="3" rows="10" columns="2">
30543 <features>
30544 <column alignment="block" valignment="top" leftline="true" width="40col%">
30545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30546 <row topline="true" bottomline="true" endhead="true">
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30548 \begin_inset Text
30549
30550 \begin_layout Standard
30551
30552 \series bold
30553 Subject / Title
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
30563 \series bold
30564 Filename / Where to get
30565 \end_layout
30566
30567 \end_inset
30568 </cell>
30569 </row>
30570 <row topline="true">
30571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30572 \begin_inset Text
30573
30574 \begin_layout Standard
30575 SDCC Compiler User Guide
30576 \end_layout
30577
30578 \end_inset
30579 </cell>
30580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30581 \begin_inset Text
30582
30583 \begin_layout Standard
30584 You're reading it right now
30585 \emph on
30586  \InsetSpace ~
30587 \InsetSpace ~
30588 \InsetSpace ~
30589
30590 \hfill
30591 online at:
30592 \emph default
30593
30594 \newline
30595
30596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30597
30598 \end_inset
30599
30600
30601 \end_layout
30602
30603 \end_inset
30604 </cell>
30605 </row>
30606 <row topline="true">
30607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30608 \begin_inset Text
30609
30610 \begin_layout Standard
30611 Changelog of SDCC
30612 \end_layout
30613
30614 \end_inset
30615 </cell>
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30617 \begin_inset Text
30618
30619 \begin_layout Standard
30620 sdcc/Changelog
30621 \emph on
30622  \InsetSpace ~
30623 \InsetSpace ~
30624 \InsetSpace ~
30625
30626 \hfill
30627 online at:
30628 \emph default
30629
30630 \newline
30631
30632 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30633
30634 \end_inset
30635
30636
30637 \end_layout
30638
30639 \end_inset
30640 </cell>
30641 </row>
30642 <row topline="true">
30643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30644 \begin_inset Text
30645
30646 \begin_layout Standard
30647 ASXXXX
30648 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30649
30650 \end_inset
30651
30652
30653 \begin_inset LatexCommand \index{Assembler documentation}
30654
30655 \end_inset
30656
30657  Assemblers and
30658 \newline
30659 ASLINK
30660 \begin_inset LatexCommand \index{aslink}
30661
30662 \end_inset
30663
30664
30665 \begin_inset LatexCommand \index{Linker documentation}
30666
30667 \end_inset
30668
30669  Relocating Linker
30670 \end_layout
30671
30672 \end_inset
30673 </cell>
30674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30675 \begin_inset Text
30676
30677 \begin_layout Standard
30678 sdcc/as/doc/asxhtm.html 
30679 \emph on
30680 \InsetSpace ~
30681 \InsetSpace ~
30682 \InsetSpace ~
30683
30684 \hfill
30685 online at:
30686 \emph default
30687
30688 \newline
30689
30690 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30691
30692 \end_inset
30693
30694
30695 \end_layout
30696
30697 \end_inset
30698 </cell>
30699 </row>
30700 <row topline="true">
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30702 \begin_inset Text
30703
30704 \begin_layout Standard
30705 SDCC regression test
30706 \begin_inset LatexCommand \index{Regression test}
30707
30708 \end_inset
30709
30710
30711 \end_layout
30712
30713 \end_inset
30714 </cell>
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30716 \begin_inset Text
30717
30718 \begin_layout Standard
30719 sdcc/doc/test_suite_spec.pdf 
30720 \emph on
30721 \InsetSpace ~
30722 \InsetSpace ~
30723 \InsetSpace ~
30724
30725 \hfill
30726 online at:
30727 \emph default
30728
30729 \newline
30730
30731 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30732
30733 \end_inset
30734
30735
30736 \end_layout
30737
30738 \end_inset
30739 </cell>
30740 </row>
30741 <row topline="true">
30742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30743 \begin_inset Text
30744
30745 \begin_layout Standard
30746 Various notes
30747 \end_layout
30748
30749 \end_inset
30750 </cell>
30751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30752 \begin_inset Text
30753
30754 \begin_layout Standard
30755 sdcc/doc/* 
30756 \emph on
30757 \InsetSpace ~
30758 \InsetSpace ~
30759 \InsetSpace ~
30760
30761 \hfill
30762 online at:
30763 \emph default
30764
30765 \newline
30766
30767 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30768
30769 \end_inset
30770
30771
30772 \end_layout
30773
30774 \end_inset
30775 </cell>
30776 </row>
30777 <row topline="true">
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 \begin_inset Text
30780
30781 \begin_layout Standard
30782 Notes on debugging with SDCDB
30783 \begin_inset LatexCommand \index{SDCDB (debugger)}
30784
30785 \end_inset
30786
30787
30788 \end_layout
30789
30790 \end_inset
30791 </cell>
30792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30793 \begin_inset Text
30794
30795 \begin_layout Standard
30796 sdcc/debugger/README 
30797 \emph on
30798 \InsetSpace ~
30799 \InsetSpace ~
30800 \InsetSpace ~
30801
30802 \hfill
30803 online at
30804 \emph default
30805 :
30806 \newline
30807
30808 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30809
30810 \end_inset
30811
30812
30813 \end_layout
30814
30815 \end_inset
30816 </cell>
30817 </row>
30818 <row topline="true">
30819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30820 \begin_inset Text
30821
30822 \begin_layout Standard
30823 uCsim
30824 \begin_inset LatexCommand \index{uCsim}
30825
30826 \end_inset
30827
30828  Software simulator for microcontrollers
30829 \end_layout
30830
30831 \end_inset
30832 </cell>
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30834 \begin_inset Text
30835
30836 \begin_layout Standard
30837
30838 \family roman
30839 \series medium
30840 \shape up
30841 \size normal
30842 \emph off
30843 \bar no
30844 \noun off
30845 \color none
30846 sdcc/sim/ucsim/doc
30847 \family default
30848 \series default
30849 \shape default
30850 \size default
30851 \emph default
30852 \bar default
30853 \noun default
30854 /index.html 
30855 \emph on
30856 \InsetSpace ~
30857 \InsetSpace ~
30858 \InsetSpace ~
30859
30860 \hfill
30861 online at:
30862 \emph default
30863
30864 \newline
30865
30866 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30867
30868 \end_inset
30869
30870
30871 \end_layout
30872
30873 \end_inset
30874 </cell>
30875 </row>
30876 <row topline="true">
30877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30878 \begin_inset Text
30879
30880 \begin_layout Standard
30881 Temporary notes on the pic16
30882 \begin_inset LatexCommand \index{PIC16}
30883
30884 \end_inset
30885
30886  port
30887 \end_layout
30888
30889 \end_inset
30890 </cell>
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30892 \begin_inset Text
30893
30894 \begin_layout Standard
30895 sdcc/src/pic16/NOTES 
30896 \emph on
30897 \InsetSpace ~
30898 \InsetSpace ~
30899 \InsetSpace ~
30900
30901 \hfill
30902 online at:
30903 \newline
30904
30905 \emph default
30906
30907 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30908
30909 \end_inset
30910
30911
30912 \end_layout
30913
30914 \end_inset
30915 </cell>
30916 </row>
30917 <row topline="true" bottomline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30919 \begin_inset Text
30920
30921 \begin_layout Standard
30922 SDCC internal documentation (debugging file format)
30923 \end_layout
30924
30925 \end_inset
30926 </cell>
30927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30928 \begin_inset Text
30929
30930 \begin_layout Standard
30931 sdcc/doc/
30932 \family roman
30933 \series medium
30934 \shape up
30935 \size normal
30936 \emph off
30937 \bar no
30938 \noun off
30939 \color none
30940 cdbfileformat.pd
30941 \family default
30942 \series default
30943 \shape default
30944 \size default
30945 \emph default
30946 \bar default
30947 \noun default
30948 f
30949 \emph on
30950  \InsetSpace ~
30951 \InsetSpace ~
30952 \InsetSpace ~
30953
30954 \hfill
30955 online at:
30956 \emph default
30957
30958 \newline
30959
30960 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30961
30962 \end_inset
30963
30964
30965 \end_layout
30966
30967 \end_inset
30968 </cell>
30969 </row>
30970 </lyxtabular>
30971
30972 \end_inset
30973
30974
30975 \newline
30976
30977 \end_layout
30978
30979 \begin_layout Section
30980 Related open source tools
30981 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30982
30983 \end_inset
30984
30985
30986 \begin_inset LatexCommand \index{Related tools}
30987
30988 \end_inset
30989
30990
30991 \end_layout
30992
30993 \begin_layout Standard
30994 \align left
30995 \begin_inset Tabular
30996 <lyxtabular version="3" rows="14" columns="3">
30997 <features>
30998 <column alignment="left" valignment="top" leftline="true" width="0pt">
30999 <column alignment="block" valignment="top" leftline="true" width="30line%">
31000 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31001 <row topline="true" bottomline="true">
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31003 \begin_inset Text
31004
31005 \begin_layout Standard
31006
31007 \series bold
31008 Name
31009 \end_layout
31010
31011 \end_inset
31012 </cell>
31013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31014 \begin_inset Text
31015
31016 \begin_layout Standard
31017
31018 \series bold
31019 Purpose
31020 \end_layout
31021
31022 \end_inset
31023 </cell>
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31025 \begin_inset Text
31026
31027 \begin_layout Standard
31028
31029 \series bold
31030 Where to get
31031 \end_layout
31032
31033 \end_inset
31034 </cell>
31035 </row>
31036 <row topline="true">
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 \begin_inset Text
31039
31040 \begin_layout Standard
31041 gpsim
31042 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31043
31044 \end_inset
31045
31046
31047 \end_layout
31048
31049 \end_inset
31050 </cell>
31051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31052 \begin_inset Text
31053
31054 \begin_layout Standard
31055 PIC simulator
31056 \end_layout
31057
31058 \end_inset
31059 </cell>
31060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31061 \begin_inset Text
31062
31063 \begin_layout Standard
31064 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31065
31066 \end_inset
31067
31068
31069 \end_layout
31070
31071 \end_inset
31072 </cell>
31073 </row>
31074 <row topline="true">
31075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31076 \begin_inset Text
31077
31078 \begin_layout Standard
31079 gputils
31080 \begin_inset LatexCommand \index{gputils (pic tools)}
31081
31082 \end_inset
31083
31084
31085 \end_layout
31086
31087 \end_inset
31088 </cell>
31089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31090 \begin_inset Text
31091
31092 \begin_layout Standard
31093 GNU PIC utilities
31094 \end_layout
31095
31096 \end_inset
31097 </cell>
31098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31099 \begin_inset Text
31100
31101 \begin_layout Standard
31102 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31103
31104 \end_inset
31105
31106
31107 \end_layout
31108
31109 \end_inset
31110 </cell>
31111 </row>
31112 <row topline="true">
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_inset Text
31115
31116 \begin_layout Standard
31117 flP5
31118 \end_layout
31119
31120 \end_inset
31121 </cell>
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31123 \begin_inset Text
31124
31125 \begin_layout Standard
31126 PIC programmer
31127 \end_layout
31128
31129 \end_inset
31130 </cell>
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31132 \begin_inset Text
31133
31134 \begin_layout Standard
31135 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31136
31137 \end_inset
31138
31139
31140 \end_layout
31141
31142 \end_inset
31143 </cell>
31144 </row>
31145 <row topline="true">
31146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31147 \begin_inset Text
31148
31149 \begin_layout Standard
31150 ec2drv/newcdb
31151 \end_layout
31152
31153 \end_inset
31154 </cell>
31155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31156 \begin_inset Text
31157
31158 \begin_layout Standard
31159 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31160  (Unix only)
31161 \end_layout
31162
31163 \end_inset
31164 </cell>
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31166 \begin_inset Text
31167
31168 \begin_layout Standard
31169 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31170
31171 \end_inset
31172
31173
31174 \end_layout
31175
31176 \end_inset
31177 </cell>
31178 </row>
31179 <row topline="true">
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184 indent
31185 \begin_inset LatexCommand \index{indent (source formatting tool)}
31186
31187 \end_inset
31188
31189
31190 \end_layout
31191
31192 \end_inset
31193 </cell>
31194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31195 \begin_inset Text
31196
31197 \begin_layout Standard
31198 Formats C source - Master of the white spaces
31199 \end_layout
31200
31201 \end_inset
31202 </cell>
31203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31204 \begin_inset Text
31205
31206 \begin_layout Standard
31207 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31208
31209 \end_inset
31210
31211
31212 \end_layout
31213
31214 \end_inset
31215 </cell>
31216 </row>
31217 <row topline="true">
31218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31219 \begin_inset Text
31220
31221 \begin_layout Standard
31222 srecord
31223 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31224
31225 \end_inset
31226
31227
31228 \end_layout
31229
31230 \end_inset
31231 </cell>
31232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31233 \begin_inset Text
31234
31235 \begin_layout Standard
31236 Object file conversion, checksumming, ...
31237 \end_layout
31238
31239 \end_inset
31240 </cell>
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31242 \begin_inset Text
31243
31244 \begin_layout Standard
31245 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31246
31247 \end_inset
31248
31249
31250 \end_layout
31251
31252 \end_inset
31253 </cell>
31254 </row>
31255 <row topline="true">
31256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31257 \begin_inset Text
31258
31259 \begin_layout Standard
31260 objdump
31261 \begin_inset LatexCommand \index{objdump (tool)}
31262
31263 \end_inset
31264
31265
31266 \end_layout
31267
31268 \end_inset
31269 </cell>
31270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31271 \begin_inset Text
31272
31273 \begin_layout Standard
31274 Object file conversion, ...
31275 \end_layout
31276
31277 \end_inset
31278 </cell>
31279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31280 \begin_inset Text
31281
31282 \begin_layout Standard
31283 Part of binutils (should be there anyway)
31284 \end_layout
31285
31286 \end_inset
31287 </cell>
31288 </row>
31289 <row topline="true">
31290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31291 \begin_inset Text
31292
31293 \begin_layout Standard
31294 cmon51
31295 \end_layout
31296
31297 \end_inset
31298 </cell>
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \begin_layout Standard
31303 8051 monitor (hex up-/download, single step, disassemble)
31304 \end_layout
31305
31306 \end_inset
31307 </cell>
31308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31309 \begin_inset Text
31310
31311 \begin_layout Standard
31312 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31313
31314 \end_inset
31315
31316
31317 \end_layout
31318
31319 \end_inset
31320 </cell>
31321 </row>
31322 <row topline="true">
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31324 \begin_inset Text
31325
31326 \begin_layout Standard
31327 doxygen
31328 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31329
31330 \end_inset
31331
31332
31333 \end_layout
31334
31335 \end_inset
31336 </cell>
31337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31338 \begin_inset Text
31339
31340 \begin_layout Standard
31341 Source code documentation system
31342 \end_layout
31343
31344 \end_inset
31345 </cell>
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31347 \begin_inset Text
31348
31349 \begin_layout Standard
31350 \begin_inset LatexCommand \url{http://www.doxygen.org}
31351
31352 \end_inset
31353
31354
31355 \end_layout
31356
31357 \end_inset
31358 </cell>
31359 </row>
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365 kdevelop
31366 \end_layout
31367
31368 \end_inset
31369 </cell>
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31371 \begin_inset Text
31372
31373 \begin_layout Standard
31374 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31375 \end_layout
31376
31377 \end_inset
31378 </cell>
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31380 \begin_inset Text
31381
31382 \begin_layout Standard
31383 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31384
31385 \end_inset
31386
31387
31388 \end_layout
31389
31390 \end_inset
31391 </cell>
31392 </row>
31393 <row topline="true">
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_inset Text
31396
31397 \begin_layout Standard
31398 paulmon
31399 \end_layout
31400
31401 \end_inset
31402 </cell>
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_inset Text
31405
31406 \begin_layout Standard
31407 8051 monitor (hex up-/download, single step, disassemble)
31408 \end_layout
31409
31410 \end_inset
31411 </cell>
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31413 \begin_inset Text
31414
31415 \begin_layout Standard
31416 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31417
31418 \end_inset
31419
31420
31421 \end_layout
31422
31423 \end_inset
31424 </cell>
31425 </row>
31426 <row topline="true">
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31428 \begin_inset Text
31429
31430 \begin_layout Standard
31431 splint
31432 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31433
31434 \end_inset
31435
31436
31437 \end_layout
31438
31439 \end_inset
31440 </cell>
31441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31442 \begin_inset Text
31443
31444 \begin_layout Standard
31445 Statically checks c sources (see 
31446 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31447
31448 \end_inset
31449
31450 )
31451 \end_layout
31452
31453 \end_inset
31454 </cell>
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31456 \begin_inset Text
31457
31458 \begin_layout Standard
31459 \begin_inset LatexCommand \url{http://www.splint.org}
31460
31461 \end_inset
31462
31463
31464 \end_layout
31465
31466 \end_inset
31467 </cell>
31468 </row>
31469 <row topline="true" bottomline="true">
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31471 \begin_inset Text
31472
31473 \begin_layout Standard
31474 ddd
31475 \begin_inset LatexCommand \index{DDD (debugger)}
31476
31477 \end_inset
31478
31479
31480 \end_layout
31481
31482 \end_inset
31483 </cell>
31484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31485 \begin_inset Text
31486
31487 \begin_layout Standard
31488 Debugger, serves nicely as GUI to SDCDB
31489 \begin_inset LatexCommand \index{SDCDB (debugger)}
31490
31491 \end_inset
31492
31493  (Unix only)
31494 \end_layout
31495
31496 \end_inset
31497 </cell>
31498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31499 \begin_inset Text
31500
31501 \begin_layout Standard
31502 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31503
31504 \end_inset
31505
31506
31507 \end_layout
31508
31509 \end_inset
31510 </cell>
31511 </row>
31512 </lyxtabular>
31513
31514 \end_inset
31515
31516
31517 \newline
31518
31519 \end_layout
31520
31521 \begin_layout Section
31522 Related documentation / recommended reading
31523 \end_layout
31524
31525 \begin_layout Standard
31526 \align left
31527 \begin_inset Tabular
31528 <lyxtabular version="3" rows="7" columns="3">
31529 <features>
31530 <column alignment="left" valignment="top" leftline="true" width="0pt">
31531 <column alignment="left" valignment="top" leftline="true" width="0">
31532 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31533 <row topline="true" bottomline="true">
31534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31535 \begin_inset Text
31536
31537 \begin_layout Standard
31538
31539 \series bold
31540 Name
31541 \end_layout
31542
31543 \end_inset
31544 </cell>
31545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31546 \begin_inset Text
31547
31548 \begin_layout Standard
31549
31550 \series bold
31551 Subject / Title
31552 \end_layout
31553
31554 \end_inset
31555 </cell>
31556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31557 \begin_inset Text
31558
31559 \begin_layout Standard
31560
31561 \series bold
31562 Where to get
31563 \end_layout
31564
31565 \end_inset
31566 </cell>
31567 </row>
31568 <row topline="true">
31569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31570 \begin_inset Text
31571
31572 \begin_layout Standard
31573
31574 \family roman
31575 \series medium
31576 \shape up
31577 \size normal
31578 \emph off
31579 \bar no
31580 \noun off
31581 \color none
31582 c-refcard.pdf
31583 \end_layout
31584
31585 \end_inset
31586 </cell>
31587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31588 \begin_inset Text
31589
31590 \begin_layout Standard
31591 C Reference Card
31592 \begin_inset LatexCommand \index{C Reference card}
31593
31594 \end_inset
31595
31596 , 2 pages
31597 \end_layout
31598
31599 \end_inset
31600 </cell>
31601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31602 \begin_inset Text
31603
31604 \begin_layout Standard
31605 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31606
31607 \end_inset
31608
31609
31610 \end_layout
31611
31612 \end_inset
31613 </cell>
31614 </row>
31615 <row topline="true">
31616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31617 \begin_inset Text
31618
31619 \begin_layout Standard
31620 c-faq
31621 \end_layout
31622
31623 \end_inset
31624 </cell>
31625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31626 \begin_inset Text
31627
31628 \begin_layout Standard
31629 C-FAQ
31630 \begin_inset LatexCommand \index{C FAQ}
31631
31632 \end_inset
31633
31634
31635 \end_layout
31636
31637 \end_inset
31638 </cell>
31639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31640 \begin_inset Text
31641
31642 \begin_layout Standard
31643 \begin_inset LatexCommand \url{http://www.c-faq.com}
31644
31645 \end_inset
31646
31647
31648 \end_layout
31649
31650 \end_inset
31651 </cell>
31652 </row>
31653 <row topline="true">
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31655 \begin_inset Text
31656
31657 \begin_layout Standard
31658 ISO/IEC 9899:TC2
31659 \end_layout
31660
31661 \end_inset
31662 </cell>
31663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31664 \begin_inset Text
31665
31666 \begin_layout Standard
31667 \begin_inset Quotes sld
31668 \end_inset
31669
31670 C-Standard
31671 \begin_inset Quotes srd
31672 \end_inset
31673
31674
31675 \end_layout
31676
31677 \end_inset
31678 </cell>
31679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31680 \begin_inset Text
31681
31682 \begin_layout Standard
31683
31684 \size footnotesize
31685 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31686
31687 \end_inset
31688
31689
31690 \end_layout
31691
31692 \end_inset
31693 </cell>
31694 </row>
31695 <row topline="true">
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31697 \begin_inset Text
31698
31699 \begin_layout Standard
31700 ISO/IEC DTR 18037
31701 \end_layout
31702
31703 \end_inset
31704 </cell>
31705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31706 \begin_inset Text
31707
31708 \begin_layout Standard
31709 \begin_inset Quotes sld
31710 \end_inset
31711
31712 Extensions for Embedded C
31713 \begin_inset Quotes srd
31714 \end_inset
31715
31716
31717 \end_layout
31718
31719 \end_inset
31720 </cell>
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31722 \begin_inset Text
31723
31724 \begin_layout Standard
31725
31726 \size footnotesize
31727 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31728
31729 \end_inset
31730
31731
31732 \end_layout
31733
31734 \end_inset
31735 </cell>
31736 </row>
31737 <row topline="true">
31738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31739 \begin_inset Text
31740
31741 \begin_layout Standard
31742
31743 \end_layout
31744
31745 \end_inset
31746 </cell>
31747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31748 \begin_inset Text
31749
31750 \begin_layout Standard
31751 Latest datasheet of target CPU
31752 \end_layout
31753
31754 \end_inset
31755 </cell>
31756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31757 \begin_inset Text
31758
31759 \begin_layout Standard
31760 vendor
31761 \end_layout
31762
31763 \end_inset
31764 </cell>
31765 </row>
31766 <row topline="true" bottomline="true">
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31768 \begin_inset Text
31769
31770 \begin_layout Standard
31771
31772 \end_layout
31773
31774 \end_inset
31775 </cell>
31776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31777 \begin_inset Text
31778
31779 \begin_layout Standard
31780 Revision history of datasheet
31781 \end_layout
31782
31783 \end_inset
31784 </cell>
31785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31786 \begin_inset Text
31787
31788 \begin_layout Standard
31789 vendor
31790 \end_layout
31791
31792 \end_inset
31793 </cell>
31794 </row>
31795 </lyxtabular>
31796
31797 \end_inset
31798
31799
31800 \newline
31801
31802 \end_layout
31803
31804 \begin_layout Section
31805 Application notes specifically for SDCC
31806 \end_layout
31807
31808 \begin_layout Standard
31809 SDCC makes no claims about the completeness of this list and about up-to-datenes
31810 s or correctness of the application notes
31811 \begin_inset LatexCommand \index{Application notes}
31812
31813 \end_inset
31814
31815 .
31816 \end_layout
31817
31818 \begin_layout Standard
31819 \align left
31820
31821 \size footnotesize
31822 \begin_inset Tabular
31823 <lyxtabular version="3" rows="7" columns="3">
31824 <features>
31825 <column alignment="block" valignment="top" leftline="true" width="17col%">
31826 <column alignment="block" valignment="top" leftline="true" width="27col%">
31827 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31828 <row topline="true" bottomline="true">
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31830 \begin_inset Text
31831
31832 \begin_layout Standard
31833
31834 \series bold
31835 \size footnotesize
31836 Vendor
31837 \end_layout
31838
31839 \end_inset
31840 </cell>
31841 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31842 \begin_inset Text
31843
31844 \begin_layout Standard
31845
31846 \series bold
31847 \size footnotesize
31848 Subject / Title
31849 \end_layout
31850
31851 \end_inset
31852 </cell>
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31854 \begin_inset Text
31855
31856 \begin_layout Standard
31857
31858 \series bold
31859 \size footnotesize
31860 Where to get
31861 \end_layout
31862
31863 \end_inset
31864 </cell>
31865 </row>
31866 <row topline="true">
31867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31868 \begin_inset Text
31869
31870 \begin_layout Standard
31871
31872 \size footnotesize
31873 Maxim / Dallas
31874 \end_layout
31875
31876 \end_inset
31877 </cell>
31878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31879 \begin_inset Text
31880
31881 \begin_layout Standard
31882
31883 \size footnotesize
31884 Using the SDCC Compiler for the DS80C400
31885 \begin_inset LatexCommand \index{DS80C400}
31886
31887 \end_inset
31888
31889
31890 \end_layout
31891
31892 \end_inset
31893 </cell>
31894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31895 \begin_inset Text
31896
31897 \begin_layout Standard
31898
31899 \size footnotesize
31900 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31901
31902 \end_inset
31903
31904
31905 \end_layout
31906
31907 \end_inset
31908 </cell>
31909 </row>
31910 <row topline="true">
31911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31912 \begin_inset Text
31913
31914 \begin_layout Standard
31915
31916 \size footnotesize
31917 Maxim / Dallas
31918 \end_layout
31919
31920 \end_inset
31921 </cell>
31922 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31923 \begin_inset Text
31924
31925 \begin_layout Standard
31926
31927 \size footnotesize
31928 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31929 \begin_inset LatexCommand \index{DS89C4x0}
31930
31931 \end_inset
31932
31933  Family of Microcontrollers
31934 \end_layout
31935
31936 \end_inset
31937 </cell>
31938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31939 \begin_inset Text
31940
31941 \begin_layout Standard
31942
31943 \size footnotesize
31944 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31945
31946 \end_inset
31947
31948
31949 \end_layout
31950
31951 \end_inset
31952 </cell>
31953 </row>
31954 <row topline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31956 \begin_inset Text
31957
31958 \begin_layout Standard
31959
31960 \size footnotesize
31961 Silicon Laboratories / Cygnal
31962 \end_layout
31963
31964 \end_inset
31965 </cell>
31966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31967 \begin_inset Text
31968
31969 \begin_layout Standard
31970
31971 \size footnotesize
31972 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31973 \begin_inset LatexCommand \index{IDE}
31974
31975 \end_inset
31976
31977
31978 \end_layout
31979
31980 \end_inset
31981 </cell>
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31983 \begin_inset Text
31984
31985 \begin_layout Standard
31986
31987 \size footnotesize
31988 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31989
31990 \end_inset
31991
31992
31993 \end_layout
31994
31995 \end_inset
31996 </cell>
31997 </row>
31998 <row topline="true">
31999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32000 \begin_inset Text
32001
32002 \begin_layout Standard
32003
32004 \size footnotesize
32005 Ramtron / Goal Semiconductor
32006 \end_layout
32007
32008 \end_inset
32009 </cell>
32010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32011 \begin_inset Text
32012
32013 \begin_layout Standard
32014
32015 \size footnotesize
32016 Interfacing SDCC to Syn and Textpad
32017 \end_layout
32018
32019 \end_inset
32020 </cell>
32021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32022 \begin_inset Text
32023
32024 \begin_layout Standard
32025
32026 \size footnotesize
32027 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32028
32029 \end_inset
32030
32031
32032 \end_layout
32033
32034 \end_inset
32035 </cell>
32036 </row>
32037 <row topline="true">
32038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32039 \begin_inset Text
32040
32041 \begin_layout Standard
32042
32043 \size footnotesize
32044 Ramtron / Goal Semiconductor
32045 \end_layout
32046
32047 \end_inset
32048 </cell>
32049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32050 \begin_inset Text
32051
32052 \begin_layout Standard
32053
32054 \size footnotesize
32055 Installing and Configuring SDCC and Crimson Editor 
32056 \end_layout
32057
32058 \end_inset
32059 </cell>
32060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32061 \begin_inset Text
32062
32063 \begin_layout Standard
32064
32065 \size footnotesize
32066 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32067
32068 \end_inset
32069
32070
32071 \end_layout
32072
32073 \end_inset
32074 </cell>
32075 </row>
32076 <row topline="true" bottomline="true">
32077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32078 \begin_inset Text
32079
32080 \begin_layout Standard
32081
32082 \size footnotesize
32083 Texas Instruments
32084 \end_layout
32085
32086 \end_inset
32087 </cell>
32088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32089 \begin_inset Text
32090
32091 \begin_layout Standard
32092
32093 \size footnotesize
32094 MSC12xx Programming with SDCC
32095 \end_layout
32096
32097 \end_inset
32098 </cell>
32099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32100 \begin_inset Text
32101
32102 \begin_layout Standard
32103
32104 \size footnotesize
32105 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32106
32107 \end_inset
32108
32109
32110 \end_layout
32111
32112 \end_inset
32113 </cell>
32114 </row>
32115 </lyxtabular>
32116
32117 \end_inset
32118
32119
32120 \end_layout
32121
32122 \begin_layout Section
32123 Some Questions
32124 \end_layout
32125
32126 \begin_layout Standard
32127 Some questions answered, some pointers given - it might be time to in turn
32128  ask 
32129 \emph on
32130 you
32131 \emph default
32132  some questions: 
32133 \end_layout
32134
32135 \begin_layout Itemize
32136 can you solve your project with the selected microcontroller? Would you
32137  find out early or rather late that your target is too small/slow/whatever?
32138  Can you switch to a slightly better device if it doesn't fit?
32139 \end_layout
32140
32141 \begin_layout Itemize
32142 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32143  and/or another programming language be more adequate? Would an operating
32144  system on the target device help?
32145 \end_layout
32146
32147 \begin_layout Itemize
32148 if you solved the problem, will the marketing department be happy?
32149 \end_layout
32150
32151 \begin_layout Itemize
32152 if the marketing department is happy, will customers be happy?
32153 \end_layout
32154
32155 \begin_layout Itemize
32156 if you're the project manager, marketing department and maybe even the customer
32157  in one person, have you tried to see the project from the outside?
32158 \end_layout
32159
32160 \begin_layout Itemize
32161 is the project done if you think it is done? Or is just that other interface/pro
32162 tocol/feature/configuration/option missing? How about website, manual(s),
32163  internationali(z|s)ation, packaging, labels, 2nd source for components,
32164  electromagnetic compatability/interference, documentation for production,
32165  production test software, update mechanism, patent issues?
32166 \end_layout
32167
32168 \begin_layout Itemize
32169 is your project adequately positioned in that magic triangle: fame, fortune,
32170  fun?
32171 \end_layout
32172
32173 \begin_layout Standard
32174 Maybe not all answers to these questions are known and some answers may
32175  even be 
32176 \emph on
32177 no
32178 \emph default
32179 , nevertheless knowing these questions may help you to avoid burnout
32180 \begin_inset Foot
32181 status open
32182
32183 \begin_layout Standard
32184 burnout is bad for electronic devices, programmers and motorcycle tyres
32185 \end_layout
32186
32187 \end_inset
32188
32189 .
32190  Chances are you didn't want to hear some of them...
32191 \end_layout
32192
32193 \begin_layout Chapter
32194 Support
32195 \begin_inset LatexCommand \index{Support}
32196
32197 \end_inset
32198
32199
32200 \end_layout
32201
32202 \begin_layout Standard
32203 SDCC has grown to be a large project.
32204  The compiler alone (without the preprocessor, assembler and linker) is
32205  well over 150,000 lines of code (blank stripped).
32206  The open source nature of this project is a key to its continued growth
32207  and support.
32208  You gain the benefit and support of many active software developers and
32209  end users.
32210  Is SDCC perfect? No, that's why we need your help.
32211  The developers take pride in fixing reported bugs.
32212  You can help by reporting the bugs and helping other SDCC users.
32213  There are lots of ways to contribute, and we encourage you to take part
32214  in making SDCC a great software package.
32215  
32216 \end_layout
32217
32218 \begin_layout Standard
32219 The SDCC project is hosted on the SDCC sourceforge site at 
32220 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32221
32222 \end_inset
32223
32224 .
32225  You'll find the complete set of mailing lists
32226 \begin_inset LatexCommand \index{Mailing list(s)}
32227
32228 \end_inset
32229
32230 , forums, bug reporting system, patch submission
32231 \begin_inset LatexCommand \index{Patch submission}
32232
32233 \end_inset
32234
32235  system, download
32236 \begin_inset LatexCommand \index{download}
32237
32238 \end_inset
32239
32240  area and Subversion code repository
32241 \begin_inset LatexCommand \index{Subversion code repository}
32242
32243 \end_inset
32244
32245  there.
32246 \end_layout
32247
32248 \begin_layout Section
32249 Reporting Bugs
32250 \begin_inset LatexCommand \index{Bug reporting}
32251
32252 \end_inset
32253
32254
32255 \begin_inset LatexCommand \index{Reporting bugs}
32256
32257 \end_inset
32258
32259
32260 \end_layout
32261
32262 \begin_layout Standard
32263 The recommended way of reporting bugs is using the infrastructure of the
32264  sourceforge site.
32265  You can follow the status of bug reports there and have an overview about
32266  the known bugs.
32267 \end_layout
32268
32269 \begin_layout Standard
32270 Bug reports are automatically forwarded to the developer mailing list and
32271  will be fixed ASAP.
32272  When reporting a bug, it is very useful to include a small test program
32273  (the smaller the better) which reproduces the problem.
32274  If you can isolate the problem by looking at the generated assembly code,
32275  this can be very helpful.
32276  Compiling your program with the -
32277 \begin_inset ERT
32278 status collapsed
32279
32280 \begin_layout Standard
32281
32282
32283 \backslash
32284 /
32285 \end_layout
32286
32287 \end_inset
32288
32289 -dumpall
32290 \begin_inset LatexCommand \index{-\/-dumpall}
32291
32292 \end_inset
32293
32294  option can sometimes be useful in locating optimization problems.
32295  When reporting a bug please make sure you:
32296 \end_layout
32297
32298 \begin_layout Enumerate
32299 Attach the code you are compiling with SDCC.
32300  
32301 \end_layout
32302
32303 \begin_layout Enumerate
32304 Specify the exact command you use to run SDCC, or attach your Makefile.
32305  
32306 \end_layout
32307
32308 \begin_layout Enumerate
32309 Specify the SDCC version (type "
32310 \family sans
32311 \series bold
32312 sdcc -v
32313 \family default
32314 \series default
32315 "), your platform, and operating system.
32316  
32317 \end_layout
32318
32319 \begin_layout Enumerate
32320 Provide an exact copy of any error message or incorrect output.
32321  
32322 \end_layout
32323
32324 \begin_layout Enumerate
32325 Put something meaningful in the subject of your message.
32326 \end_layout
32327
32328 \begin_layout Standard
32329 Please attempt to include these 5 important parts, as applicable, in all
32330  requests for support or when reporting any problems or bugs with SDCC.
32331  Though this will make your message lengthy, it will greatly improve your
32332  chance that SDCC users and developers will be able to help you.
32333  Some SDCC developers are frustrated by bug reports without code provided
32334  that they can use to reproduce and ultimately fix the problem, so please
32335  be sure to provide sample code if you are reporting a bug! 
32336 \end_layout
32337
32338 \begin_layout Standard
32339 Please have a short check that you are using a recent version of SDCC and
32340  the bug is not yet known.
32341  This is the link for reporting bugs: 
32342 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32343
32344 \end_inset
32345
32346 .
32347  With SDCC on average having more than 200 downloads
32348 \begin_inset LatexCommand \index{download}
32349
32350 \end_inset
32351
32352  on sourceforge per day
32353 \begin_inset Foot
32354 status open
32355
32356 \begin_layout Standard
32357 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32358  between 2002 and 2005.
32359  This does not include other methods of distribution.
32360 \end_layout
32361
32362 \end_inset
32363
32364  there must be some users.
32365  So it's not exactly easy to find a new bug.
32366  If you find one we need it: 
32367 \emph on
32368 reporting bugs is good
32369 \emph default
32370 .
32371 \end_layout
32372
32373 \begin_layout Section
32374 Requesting Features
32375 \begin_inset LatexCommand \label{sub:Requesting-Features}
32376
32377 \end_inset
32378
32379
32380 \begin_inset LatexCommand \index{Feature request}
32381
32382 \end_inset
32383
32384
32385 \begin_inset LatexCommand \index{Requesting features}
32386
32387 \end_inset
32388
32389
32390 \end_layout
32391
32392 \begin_layout Standard
32393 Like bug reports feature requests are forwarded to the developer mailing
32394  list.
32395  This is the link for requesting features: 
32396 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32397
32398 \end_inset
32399
32400 .
32401 \end_layout
32402
32403 \begin_layout Section
32404 Submitting patches
32405 \end_layout
32406
32407 \begin_layout Standard
32408 Like bug reports contributed patches are forwarded to the developer mailing
32409  list.
32410  This is the link for submitting patches
32411 \begin_inset LatexCommand \index{Patch submission}
32412
32413 \end_inset
32414
32415
32416 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32417
32418 \end_inset
32419
32420 .
32421 \end_layout
32422
32423 \begin_layout Standard
32424 You need to specify some parameters to the 
32425 \family typewriter
32426 diff
32427 \family default
32428  command for the patches to be useful.
32429  If you modified more than one file a patch created f.e.
32430  with 
32431 \family sans
32432 \series bold
32433
32434 \begin_inset Quotes sld
32435 \end_inset
32436
32437 diff -Naur unmodified_directory modified_directory >my_changes.patch
32438 \begin_inset Quotes srd
32439 \end_inset
32440
32441
32442 \family default
32443 \series default
32444  will be fine, otherwise 
32445 \family sans
32446 \series bold
32447
32448 \begin_inset Quotes sld
32449 \end_inset
32450
32451 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32452 \begin_inset Quotes srd
32453 \end_inset
32454
32455
32456 \series default
32457  
32458 \family default
32459 will do.
32460 \end_layout
32461
32462 \begin_layout Section
32463 Getting Help
32464 \end_layout
32465
32466 \begin_layout Standard
32467 These links should take you directly to the 
32468 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32469
32470 \end_inset
32471
32472
32473 \begin_inset Foot
32474 status open
32475
32476 \begin_layout Standard
32477 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32478  automated messages (mid 2003)
32479 \end_layout
32480
32481 \end_inset
32482
32483  and the 
32484 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32485
32486 \end_inset
32487
32488 , lists
32489 \begin_inset LatexCommand \index{Mailing list(s)}
32490
32491 \end_inset
32492
32493  and forums are archived and searchable so if you are lucky someone already
32494  had a similar problem.
32495  While mails to the lists themselves are delivered promptly their web front
32496  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32497  if you're seriously using SDCC please consider subscribing to the lists.
32498 \end_layout
32499
32500 \begin_layout Section
32501 ChangeLog
32502 \end_layout
32503
32504 \begin_layout Standard
32505 You can follow the status of the Subversion version
32506 \begin_inset LatexCommand \index{version}
32507
32508 \end_inset
32509
32510  of SDCC by watching the Changelog
32511 \begin_inset LatexCommand \index{Changelog}
32512
32513 \end_inset
32514
32515  in the Subversion repository
32516 \size footnotesize
32517  
32518 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32519
32520 \end_inset
32521
32522 .
32523 \end_layout
32524
32525 \begin_layout Section
32526 Subversion Source Code Repository
32527 \end_layout
32528
32529 \begin_layout Standard
32530 The output of 
32531 \family sans
32532 \series bold
32533 sdcc -
32534 \family default
32535
32536 \begin_inset ERT
32537 status open
32538
32539 \begin_layout Standard
32540
32541
32542 \backslash
32543 /
32544 \end_layout
32545
32546 \end_inset
32547
32548
32549 \family sans
32550 -version
32551 \family default
32552 \series default
32553  or the filenames of the snapshot versions of SDCC include date and its
32554  Subversion
32555 \begin_inset LatexCommand \index{Subversion code repository}
32556
32557 \end_inset
32558
32559  number.
32560  Subversion allows to download the source of recent or previous versions
32561  
32562 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32563
32564 \end_inset
32565
32566  (by number or by date).
32567  An on-line source code browser and detailled instructions are also available
32568  there.
32569  SDCC versions starting from 1999 up to now are available (currently the
32570  versions prior to the conversion from cvs
32571 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32572
32573 \end_inset
32574
32575  to Subversion (April 2006) are either by accessible by Subversion or by
32576  cvs).
32577 \end_layout
32578
32579 \begin_layout Section
32580 Release policy
32581 \begin_inset LatexCommand \index{Release policy}
32582
32583 \end_inset
32584
32585
32586 \end_layout
32587
32588 \begin_layout Standard
32589 Historically there often were long delays between official releases and
32590  the sourceforge download area tends to get not updated at all.
32591  Excuses in the past might have referred to problems with live range analysis,
32592  but as this was fixed a while ago, the current problem is that another
32593  excuse has to be found.
32594  Kidding aside, we have to get better there! On the other hand there are
32595  daily snapshots available at 
32596 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32597
32598 \end_inset
32599
32600 , and you can always build the very last version (hopefully with many bugs
32601  fixed, and features added) from the source code available at 
32602 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32603
32604 \end_inset
32605
32606 .
32607  The SDCC Wiki
32608 \begin_inset LatexCommand \index{wiki}
32609
32610 \end_inset
32611
32612
32613 \begin_inset LatexCommand \index{SDCC Wiki}
32614
32615 \end_inset
32616
32617  at 
32618 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32619
32620 \end_inset
32621
32622  also holds some information about past and future releases.
32623 \end_layout
32624
32625 \begin_layout Section
32626 Examples
32627 \begin_inset LatexCommand \index{Examples}
32628
32629 \end_inset
32630
32631
32632 \end_layout
32633
32634 \begin_layout Standard
32635 You'll find some small examples in the directory 
32636 \emph on
32637 sdcc/device/examples/.
32638  
32639 \emph default
32640 More examples and libraries are available at
32641 \emph on
32642  The SDCC Open Knowledge Resource 
32643 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32644
32645 \end_inset
32646
32647  
32648 \emph default
32649 web site or at 
32650 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32651
32652 \end_inset
32653
32654 .
32655 \end_layout
32656
32657 \begin_layout Standard
32658 \begin_inset Note Note
32659 status collapsed
32660
32661 \begin_layout Standard
32662 I did insert a reference to Paul's web site here although it seems rather
32663  dedicated to a specific 8032 board (I think it's okay because it f.e.
32664  shows LCD/Harddisc interface and has a free 8051 monitor.
32665  Independent 8032 board vendors face hard competition of heavily subsidized
32666  development boards anyway).
32667 \end_layout
32668
32669 \begin_layout Standard
32670 Maybe we should include some links to real world applications.
32671  Preferably pointer to pointers (one for each architecture) so this stays
32672  manageable here?
32673 \end_layout
32674
32675 \end_inset
32676
32677
32678 \end_layout
32679
32680 \begin_layout Section
32681 Quality control
32682 \begin_inset LatexCommand \label{sec:Quality-control}
32683
32684 \end_inset
32685
32686
32687 \begin_inset LatexCommand \index{Quality control}
32688
32689 \end_inset
32690
32691
32692 \end_layout
32693
32694 \begin_layout Standard
32695 The compiler is passed through snaphot build compile and build checks.
32696  The so called 
32697 \shape italic
32698 regression tests
32699 \shape default
32700
32701 \begin_inset LatexCommand \index{Regression test}
32702
32703 \end_inset
32704
32705  check that SDCC itself compiles flawlessly on several host platforms (i386,
32706  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32707  the quality of the code generated by SDCC by running the code for several
32708  target platforms through simulators.
32709  The regression test suite comprises more than 100 files which expand to
32710  more than 500 test cases which include more than 4500 tests.
32711  The results of these tests are published daily on SDCC's snapshot page
32712  (click on the red or green symbols on the right side of 
32713 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32714
32715 \end_inset
32716
32717 ).
32718 \end_layout
32719
32720 \begin_layout Standard
32721 There is a separate document 
32722 \shape italic
32723 test_suite.pdf 
32724 \begin_inset LatexCommand \index{Test suite}
32725
32726 \end_inset
32727
32728
32729 \shape default
32730  
32731 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32732
32733 \end_inset
32734
32735  about the regression test suite.
32736 \end_layout
32737
32738 \begin_layout Standard
32739 You'll find the test code in the directory 
32740 \shape italic
32741 sdcc/support/regression
32742 \shape default
32743 .
32744  You can run these tests manually by running 
32745 \family sans
32746 make
32747 \family default
32748  in this directory (or f.e.
32749  
32750 \family sans
32751 \series bold
32752
32753 \begin_inset Quotes sld
32754 \end_inset
32755
32756 make test-mcs51
32757 \begin_inset Quotes srd
32758 \end_inset
32759
32760
32761 \family default
32762 \series default
32763  if you don't want to run the complete tests).
32764  The test code might also be interesting if you want to look for examples
32765 \begin_inset LatexCommand \index{Examples}
32766
32767 \end_inset
32768
32769  checking corner cases of SDCC or if you plan to submit patches
32770 \begin_inset LatexCommand \index{Patch submission}
32771
32772 \end_inset
32773
32774 .
32775 \end_layout
32776
32777 \begin_layout Standard
32778 The PIC14 port uses a different set of regression tests 
32779 \begin_inset LatexCommand \index{Regression test (PIC14)}
32780
32781 \end_inset
32782
32783 , you'll find them in the directory 
32784 \shape italic
32785 sdcc/src/regression
32786 \shape default
32787 .
32788 \end_layout
32789
32790 \begin_layout Section
32791 Use of SDCC in Education
32792 \end_layout
32793
32794 \begin_layout Standard
32795 In short: 
32796 \emph on
32797 highly
32798 \emph default
32799  encouraged
32800 \begin_inset Foot
32801 status open
32802
32803 \begin_layout Standard
32804 the phrase "use in education" might evoke the association "
32805 \emph on
32806 only
32807 \emph default
32808  fit for use in education".
32809  This connotation is not intended but nevertheless risked as the licensing
32810  of SDCC makes it difficult to offer educational discounts
32811 \end_layout
32812
32813 \end_inset
32814
32815 .
32816  If your rationales are to:
32817 \end_layout
32818
32819 \begin_layout Enumerate
32820 give students a chance to understand the 
32821 \emph on
32822 complete
32823 \emph default
32824  steps of code generation
32825 \end_layout
32826
32827 \begin_layout Enumerate
32828 have a curriculum that can be extended for years.
32829  Then you could use an fpga board as target and your curriculum will seamlessly
32830  extend from logic synthesis (
32831 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32832
32833 \end_inset
32834
32835
32836 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32837
32838 \end_inset
32839
32840 ), over assembly programming, to C to FPGA compilers (
32841 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32842
32843 \end_inset
32844
32845 ) and to C.
32846 \end_layout
32847
32848 \begin_layout Enumerate
32849 be able to insert excursions about skills like using a revision control
32850  system, submitting/applying patches, using a type-setting (as opposed to
32851  word-processing) engine LyX/LaTeX, using 
32852 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32853
32854 \end_inset
32855
32856 , following some 
32857 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32858
32859 \end_inset
32860
32861 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32862  Source Software, CPU simulation, compiler regression tests
32863 \begin_inset LatexCommand \index{Regression test}
32864
32865 \end_inset
32866
32867 .
32868  
32869 \newline
32870 And if there should be a shortage of ideas then you can always point students
32871  to the ever-growing feature request list 
32872 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32873
32874 \end_inset
32875
32876 .
32877 \end_layout
32878
32879 \begin_layout Enumerate
32880 not tie students to a specific host platform and instead allow them to use
32881  a host platform of 
32882 \emph on
32883 their
32884 \emph default
32885  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32886  and eventually 
32887 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32888
32889 \end_inset
32890
32891 )
32892 \end_layout
32893
32894 \begin_layout Enumerate
32895 not encourage students to use illegal copies of educational software
32896 \end_layout
32897
32898 \begin_layout Enumerate
32899 be immune to licensing/availability/price changes of the chosen tool chain
32900 \end_layout
32901
32902 \begin_layout Enumerate
32903 be able to change to a new target platform without having to adopt a new
32904  tool chain
32905 \end_layout
32906
32907 \begin_layout Enumerate
32908 have complete control over and insight into the tool chain
32909 \end_layout
32910
32911 \begin_layout Enumerate
32912 make your students aware about the pros and cons of open source software
32913  development
32914 \end_layout
32915
32916 \begin_layout Enumerate
32917 give back to the public as you are probably at least partially publically
32918  funded
32919 \end_layout
32920
32921 \begin_layout Enumerate
32922 give students a chance to publically prove their skills and to possibly
32923  see a world wide impact
32924 \end_layout
32925
32926 \begin_layout Standard
32927 then SDCC is probably among the first choices.
32928  Well, probably SDCC might be the only choice.
32929 \newpage
32930
32931 \end_layout
32932
32933 \begin_layout Chapter
32934 SDCC Technical Data
32935 \end_layout
32936
32937 \begin_layout Section
32938 Optimizations
32939 \begin_inset LatexCommand \index{Optimizations}
32940
32941 \end_inset
32942
32943
32944 \end_layout
32945
32946 \begin_layout Standard
32947 SDCC performs a host of standard optimizations in addition to some MCU specific
32948  optimizations.
32949  
32950 \end_layout
32951
32952 \begin_layout Subsection
32953 Sub-expression Elimination
32954 \begin_inset LatexCommand \index{Subexpression elimination}
32955
32956 \end_inset
32957
32958
32959 \end_layout
32960
32961 \begin_layout Standard
32962 The compiler does local and 
32963 \emph on
32964 g
32965 \emph default
32966 lobal 
32967 \emph on
32968 c
32969 \emph default
32970 ommon 
32971 \emph on
32972 s
32973 \emph default
32974 ubexpression 
32975 \emph on
32976 e
32977 \emph default
32978 limination, e.g.: 
32979 \end_layout
32980
32981 \begin_layout Verse
32982
32983 \family typewriter
32984 i = x + y + 1; 
32985 \newline
32986 j = x + y;
32987 \end_layout
32988
32989 \begin_layout Standard
32990 will be translated to
32991 \end_layout
32992
32993 \begin_layout Verse
32994
32995 \family typewriter
32996 iTemp = x + y; 
32997 \newline
32998 i = iTemp + 1; 
32999 \newline
33000 j = iTemp;
33001 \end_layout
33002
33003 \begin_layout Standard
33004 Some subexpressions are not as obvious as the above example, e.g.:
33005 \end_layout
33006
33007 \begin_layout Verse
33008
33009 \family typewriter
33010 a->b[i].c = 10; 
33011 \newline
33012 a->b[i].d = 11;
33013 \end_layout
33014
33015 \begin_layout Standard
33016 In this case the address arithmetic a->b[i] will be computed only once;
33017  the equivalent code in C would be.
33018 \end_layout
33019
33020 \begin_layout Verse
33021
33022 \family typewriter
33023 iTemp = a->b[i]; 
33024 \newline
33025 iTemp.c = 10; 
33026 \newline
33027 iTemp.d = 11;
33028 \end_layout
33029
33030 \begin_layout Standard
33031 The compiler will try to keep these temporary variables in registers.
33032 \end_layout
33033
33034 \begin_layout Subsection
33035 Dead-Code Elimination
33036 \begin_inset LatexCommand \index{Dead-code elimination}
33037
33038 \end_inset
33039
33040
33041 \end_layout
33042
33043 \begin_layout Verse
33044
33045 \family typewriter
33046 int global;
33047 \newline
33048
33049 \newline
33050 void f () { 
33051 \newline
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 int i; 
33055 \newline
33056 \InsetSpace ~
33057 \InsetSpace ~
33058 i = 1; \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 /* dead store */ 
33064 \newline
33065 \InsetSpace ~
33066 \InsetSpace ~
33067 global = 1;\InsetSpace ~
33068 /* dead
33069  store */ 
33070 \newline
33071 \InsetSpace ~
33072 \InsetSpace ~
33073 global = 2; 
33074 \newline
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 return; 
33078 \newline
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 global = 3;\InsetSpace ~
33082 /* unreachable */ 
33083 \newline
33084 }
33085 \end_layout
33086
33087 \begin_layout Standard
33088 will be changed to
33089 \end_layout
33090
33091 \begin_layout Verse
33092
33093 \family typewriter
33094 int global;
33095 \newline
33096
33097 \newline
33098 void f () {
33099 \newline
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 global = 2; 
33103 \newline
33104 }
33105 \end_layout
33106
33107 \begin_layout Subsection
33108 Copy-Propagation
33109 \begin_inset LatexCommand \index{Copy propagation}
33110
33111 \end_inset
33112
33113
33114 \end_layout
33115
33116 \begin_layout Verse
33117
33118 \family typewriter
33119 int f() { 
33120 \newline
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 int i, j; 
33124 \newline
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 i = 10; 
33128 \newline
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 j = i; 
33132 \newline
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 return j; 
33136 \newline
33137 }
33138 \end_layout
33139
33140 \begin_layout Standard
33141 will be changed to 
33142 \end_layout
33143
33144 \begin_layout Verse
33145
33146 \family typewriter
33147 int f() { 
33148 \newline
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 int i, j; 
33152 \newline
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 i = 10; 
33156 \newline
33157 \InsetSpace ~
33158 \InsetSpace ~
33159 j = 10; 
33160 \newline
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 return 10; 
33164 \newline
33165 }
33166 \end_layout
33167
33168 \begin_layout Standard
33169 Note: the dead stores created by this copy propagation will be eliminated
33170  by dead-code elimination.
33171 \end_layout
33172
33173 \begin_layout Subsection
33174 Loop Optimizations
33175 \begin_inset LatexCommand \index{Loop optimization}
33176
33177 \end_inset
33178
33179
33180 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33181
33182 \end_inset
33183
33184
33185 \end_layout
33186
33187 \begin_layout Standard
33188 Two types of loop optimizations are done by SDCC 
33189 \emph on
33190 loop invariant
33191 \emph default
33192  lifting and
33193 \emph on
33194  strength reduction
33195 \emph default
33196  of loop induction variables.
33197  In addition to the strength reduction the optimizer marks the induction
33198  variables and the register allocator tries to keep the induction variables
33199  in registers for the duration of the loop.
33200  Because of this preference of the register allocator
33201 \begin_inset LatexCommand \index{Register allocation}
33202
33203 \end_inset
33204
33205 , loop induction optimization causes an increase in register pressure, which
33206  may cause unwanted spilling of other temporary variables into the stack
33207 \begin_inset LatexCommand \index{stack}
33208
33209 \end_inset
33210
33211  / data space.
33212  The compiler will generate a warning message when it is forced to allocate
33213  extra space either on the stack or data space.
33214  If this extra space allocation is undesirable then induction optimization
33215  can be eliminated either for the entire source file (with -
33216 \begin_inset ERT
33217 status collapsed
33218
33219 \begin_layout Standard
33220
33221
33222 \backslash
33223 /
33224 \end_layout
33225
33226 \end_inset
33227
33228 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33229 noinduction
33230 \begin_inset LatexCommand \index{\#pragma noinduction}
33231
33232 \end_inset
33233
33234 .
33235 \newline
33236
33237 \newline
33238 Loop Invariant:
33239 \end_layout
33240
33241 \begin_layout Verse
33242
33243 \family typewriter
33244 for (i = 0 ; i < 100 ; i ++) 
33245 \newline
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 f += k + l;
33251 \end_layout
33252
33253 \begin_layout Standard
33254 changed to
33255 \end_layout
33256
33257 \begin_layout Verse
33258
33259 \family typewriter
33260 itemp = k + l; 
33261 \newline
33262 for (i = 0; i < 100; i++) 
33263 \newline
33264 \InsetSpace ~
33265 \InsetSpace ~
33266 \InsetSpace ~
33267 \InsetSpace ~
33268 f += itemp;
33269 \end_layout
33270
33271 \begin_layout Standard
33272 As mentioned previously some loop invariants are not as apparent, all static
33273  address computations are also moved out of the loop.
33274 \newline
33275
33276 \newline
33277 Strength Reduction
33278 \begin_inset LatexCommand \index{Strength reduction}
33279
33280 \end_inset
33281
33282 , this optimization substitutes an expression by a cheaper expression:
33283 \end_layout
33284
33285 \begin_layout Verse
33286
33287 \family typewriter
33288 for (i=0;i < 100; i++)
33289 \newline
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 ar[i*5] = i*3;
33295 \end_layout
33296
33297 \begin_layout Standard
33298 changed to
33299 \end_layout
33300
33301 \begin_layout Verse
33302
33303 \family typewriter
33304 itemp1 = 0; 
33305 \newline
33306 itemp2 = 0; 
33307 \newline
33308 for (i=0;i< 100;i++) { 
33309 \newline
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314 ar[itemp1] = itemp2; 
33315 \newline
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 itemp1
33321  += 5; 
33322 \newline
33323 \InsetSpace ~
33324 \InsetSpace ~
33325 \InsetSpace ~
33326 \InsetSpace ~
33327 itemp2 += 3; 
33328 \newline
33329 }
33330 \end_layout
33331
33332 \begin_layout Standard
33333 The more expensive multiplication
33334 \begin_inset LatexCommand \index{Multiplication}
33335
33336 \end_inset
33337
33338  is changed to a less expensive addition.
33339 \end_layout
33340
33341 \begin_layout Subsection
33342 Loop Reversing
33343 \begin_inset LatexCommand \index{Loop reversing}
33344
33345 \end_inset
33346
33347
33348 \end_layout
33349
33350 \begin_layout Standard
33351 This optimization is done to reduce the overhead of checking loop boundaries
33352  for every iteration.
33353  Some simple loops can be reversed and implemented using a 
33354 \begin_inset Quotes eld
33355 \end_inset
33356
33357 decrement and jump if not zero
33358 \begin_inset Quotes erd
33359 \end_inset
33360
33361  instruction.
33362  SDCC checks for the following criterion to determine if a loop is reversible
33363  (note: more sophisticated compilers use data-dependency analysis to make
33364  this determination, SDCC uses a more simple minded analysis).
33365 \end_layout
33366
33367 \begin_layout Itemize
33368 The 'for' loop is of the form 
33369 \newline
33370
33371 \newline
33372
33373 \family typewriter
33374 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33375  += 1])
33376 \newline
33377 \InsetSpace ~
33378 \InsetSpace ~
33379 \InsetSpace ~
33380 \InsetSpace ~
33381 <for body>
33382 \end_layout
33383
33384 \begin_layout Itemize
33385 The <for body> does not contain 
33386 \begin_inset Quotes eld
33387 \end_inset
33388
33389 continue
33390 \begin_inset Quotes erd
33391 \end_inset
33392
33393  or 'break
33394 \begin_inset Quotes erd
33395 \end_inset
33396
33397 .
33398 \end_layout
33399
33400 \begin_layout Itemize
33401 All goto's are contained within the loop.
33402 \end_layout
33403
33404 \begin_layout Itemize
33405 No function calls within the loop.
33406 \end_layout
33407
33408 \begin_layout Itemize
33409 The loop control variable <sym> is not assigned any value within the loop
33410 \end_layout
33411
33412 \begin_layout Itemize
33413 The loop control variable does NOT participate in any arithmetic operation
33414  within the loop.
33415 \end_layout
33416
33417 \begin_layout Itemize
33418 There are NO switch statements in the loop.
33419 \end_layout
33420
33421 \begin_layout Subsection
33422 Algebraic Simplifications
33423 \end_layout
33424
33425 \begin_layout Standard
33426 SDCC does numerous algebraic simplifications, the following is a small sub-set
33427  of these optimizations.
33428 \end_layout
33429
33430 \begin_layout Verse
33431
33432 \family typewriter
33433 i = j + 0;\InsetSpace ~
33434 \InsetSpace ~
33435 \InsetSpace ~
33436 \InsetSpace ~
33437  /* changed to: */\InsetSpace ~
33438 \InsetSpace ~
33439 \InsetSpace ~
33440 \InsetSpace ~
33441  i = j; 
33442 \newline
33443 i /= 2;\InsetSpace ~
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 \InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450  /* changed to: */\InsetSpace ~
33451 \InsetSpace ~
33452 \InsetSpace ~
33453 \InsetSpace ~
33454  i >>= 1; 
33455 \newline
33456 i
33457  = j - j;\InsetSpace ~
33458 \InsetSpace ~
33459 \InsetSpace ~
33460 \InsetSpace ~
33461  /* changed to: */\InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464 \InsetSpace ~
33465  i = 0; 
33466 \newline
33467 i = j / 1;\InsetSpace ~
33468 \InsetSpace ~
33469 \InsetSpace ~
33470 \InsetSpace ~
33471  /* changed to: */\InsetSpace ~
33472 \InsetSpace ~
33473 \InsetSpace ~
33474 \InsetSpace ~
33475  i = j;
33476 \end_layout
33477
33478 \begin_layout Standard
33479 Note the subexpressions
33480 \begin_inset LatexCommand \index{Subexpression}
33481
33482 \end_inset
33483
33484  given above are generally introduced by macro expansions or as a result
33485  of copy/constant propagation.
33486 \end_layout
33487
33488 \begin_layout Subsection
33489 'switch' Statements
33490 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33491
33492 \end_inset
33493
33494
33495 \begin_inset LatexCommand \index{switch statement}
33496
33497 \end_inset
33498
33499
33500 \end_layout
33501
33502 \begin_layout Standard
33503 SDCC can optimize switch statements to jump tables
33504 \begin_inset LatexCommand \index{jump tables}
33505
33506 \end_inset
33507
33508 .
33509  It makes the decision based on an estimate of the generated code size.
33510  SDCC is quite liberal in the requirements for jump table generation: 
33511 \end_layout
33512
33513 \begin_layout Itemize
33514 The labels need not be in order, and the starting number need not be one
33515  or zero, the case labels are in numerical sequence or not too many case
33516  labels are missing.
33517 \end_layout
33518
33519 \begin_deeper
33520 \begin_layout Verse
33521
33522 \family typewriter
33523 switch(i) {\InsetSpace ~
33524 \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 switch (i) { 
33550 \newline
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 \InsetSpace ~
33554 case 4: ...\InsetSpace ~
33555 \InsetSpace ~
33556 \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 case 0: ...
33581  
33582 \newline
33583 \InsetSpace ~
33584 \InsetSpace ~
33585 \InsetSpace ~
33586 case 5: ...\InsetSpace ~
33587 \InsetSpace ~
33588 \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 case 1: ...
33613  
33614 \newline
33615 \InsetSpace ~
33616 \InsetSpace ~
33617 \InsetSpace ~
33618 case 3: ...\InsetSpace ~
33619 \InsetSpace ~
33620 \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
33645 \newline
33646 \InsetSpace ~
33647 \InsetSpace ~
33648 \InsetSpace ~
33649 case 6: ...\InsetSpace ~
33650 \InsetSpace ~
33651 \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 case 3: ...
33676  
33677 \newline
33678 \InsetSpace ~
33679 \InsetSpace ~
33680 \InsetSpace ~
33681 case 7: ...\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 case 4: ...
33708  
33709 \newline
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 \InsetSpace ~
33713 case 8: ...\InsetSpace ~
33714 \InsetSpace ~
33715 \InsetSpace ~
33716 \InsetSpace ~
33717 \InsetSpace ~
33718 \InsetSpace ~
33719 \InsetSpace ~
33720 \InsetSpace ~
33721 \InsetSpace ~
33722 \InsetSpace ~
33723 \InsetSpace ~
33724 \InsetSpace ~
33725 \InsetSpace ~
33726 \InsetSpace ~
33727 \InsetSpace ~
33728 \InsetSpace ~
33729 \InsetSpace ~
33730 \InsetSpace ~
33731 \InsetSpace ~
33732 \InsetSpace ~
33733 \InsetSpace ~
33734 \InsetSpace ~
33735 \InsetSpace ~
33736 \InsetSpace ~
33737 \InsetSpace ~
33738 \InsetSpace ~
33739 case 5: ...
33740  
33741 \newline
33742 \InsetSpace ~
33743 \InsetSpace ~
33744 \InsetSpace ~
33745 case 9: ...\InsetSpace ~
33746 \InsetSpace ~
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 \InsetSpace ~
33750 \InsetSpace ~
33751 \InsetSpace ~
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 \InsetSpace ~
33755 \InsetSpace ~
33756 \InsetSpace ~
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 \InsetSpace ~
33760 \InsetSpace ~
33761 \InsetSpace ~
33762 \InsetSpace ~
33763 \InsetSpace ~
33764 \InsetSpace ~
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 \InsetSpace ~
33768 \InsetSpace ~
33769 \InsetSpace ~
33770 \InsetSpace ~
33771 case 6: ...
33772  
33773 \newline
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 case 10: ...\InsetSpace ~
33778 \InsetSpace ~
33779 \InsetSpace ~
33780 \InsetSpace ~
33781 \InsetSpace ~
33782 \InsetSpace ~
33783 \InsetSpace ~
33784 \InsetSpace ~
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 \InsetSpace ~
33788 \InsetSpace ~
33789 \InsetSpace ~
33790 \InsetSpace ~
33791 \InsetSpace ~
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 \InsetSpace ~
33801 \InsetSpace ~
33802 case 7: ...
33803  
33804 \newline
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 case 11: ...\InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827 \InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 \InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 case 8: ...
33834  
33835 \newline
33836 }\InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 \InsetSpace ~
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 \InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 }
33873 \end_layout
33874
33875 \begin_layout Standard
33876 Both the above switch statements will be implemented using a jump-table.
33877  The example to the right side is slightly more efficient as the check for
33878  the lower boundary of the jump-table is not needed.
33879 \end_layout
33880
33881 \end_deeper
33882 \begin_layout Itemize
33883 The number of case labels is not larger than supported by the target architectur
33884 e.
33885 \end_layout
33886
33887 \begin_layout Itemize
33888 If the case labels are not in numerical sequence ('gaps' between cases)
33889  SDCC checks whether a jump table with additionally inserted dummy cases
33890  is still attractive.
33891  
33892 \end_layout
33893
33894 \begin_layout Itemize
33895 If the starting number is not zero and a check for the lower boundary of
33896  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33897  ...
33898  .
33899 \end_layout
33900
33901 \begin_layout Standard
33902 Switch statements which have large gaps in the numeric sequence or those
33903  that have too many case labels can be split into more than one switch statement
33904  for efficient code generation, e.g.:
33905 \end_layout
33906
33907 \begin_layout Verse
33908
33909 \family typewriter
33910 switch (i) { 
33911 \newline
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 case 1: ...
33915  
33916 \newline
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 case 2: ...
33920  
33921 \newline
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 case 3: ...
33925  
33926 \newline
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 case 4: ...
33930  
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 case 5: ...
33935  
33936 \newline
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 case 6: ...
33940  
33941 \newline
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 case 7: ...
33945  
33946 \newline
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 case 101: ...
33950  
33951 \newline
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 case 102: ...
33955  
33956 \newline
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 case 103: ...
33960  
33961 \newline
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 case 104: ...
33965  
33966 \newline
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 case 105: ...
33970  
33971 \newline
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 case 106: ...
33975  
33976 \newline
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 case 107: ...
33980  
33981 \newline
33982 }
33983 \end_layout
33984
33985 \begin_layout Standard
33986 If the above switch statement is broken down into two switch statements
33987 \end_layout
33988
33989 \begin_layout Verse
33990
33991 \family typewriter
33992 switch (i) { 
33993 \newline
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 case 1: ...
33997  
33998 \newline
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 case 2: ...
34002  
34003 \newline
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 case 3: ...
34007  
34008 \newline
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 case 4: ...
34012  
34013 \newline
34014 \InsetSpace ~
34015 \InsetSpace ~
34016 case 5: ...
34017  
34018 \newline
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 case 6: ...
34022  
34023 \newline
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 case 7: ...
34027  
34028 \newline
34029 }
34030 \end_layout
34031
34032 \begin_layout Standard
34033 and
34034 \end_layout
34035
34036 \begin_layout Verse
34037
34038 \family typewriter
34039 switch (i) { 
34040 \newline
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 case 101: ...
34044  
34045 \newline
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 case 102: ...
34049  
34050 \newline
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 case 103: ...
34054  
34055 \newline
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 case 104: ...
34059  
34060 \newline
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 case 105: ...
34064  
34065 \newline
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 case 106: ...
34069  
34070 \newline
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 case 107: ...
34074  
34075 \newline
34076 }
34077 \end_layout
34078
34079 \begin_layout Standard
34080 then both the switch statements will be implemented using jump-tables whereas
34081  the unmodified switch statement will not be.
34082 \end_layout
34083
34084 \begin_layout Standard
34085 \begin_inset Note Note
34086 status collapsed
34087
34088 \begin_layout Standard
34089 There might be reasons which SDCC cannot know about to either favour or
34090  not favour jump tables.
34091  If the target system has to be as quick for the last switch case as for
34092  the first (pro jump table), or if the switch argument is known to be zero
34093  in the majority of the cases (contra jump table).
34094 \end_layout
34095
34096 \end_inset
34097
34098
34099 \end_layout
34100
34101 \begin_layout Standard
34102 The pragma nojtbound
34103 \begin_inset LatexCommand \index{\#pragma nojtbound}
34104
34105 \end_inset
34106
34107  can be used to turn off checking the 
34108 \emph on
34109 j
34110 \emph default
34111 ump 
34112 \emph on
34113 t
34114 \emph default
34115 able 
34116 \emph on
34117 bound
34118 \emph default
34119 aries.
34120  It has no effect if a default label is supplied.
34121  Use of this pragma is dangerous: if the switch
34122 \begin_inset LatexCommand \index{switch statement}
34123
34124 \end_inset
34125
34126  argument is not matched by a case statement the processor will happily
34127  jump into Nirvana.
34128 \end_layout
34129
34130 \begin_layout Subsection
34131 Bit-shifting Operations
34132 \begin_inset LatexCommand \index{Bit shifting}
34133
34134 \end_inset
34135
34136 .
34137 \end_layout
34138
34139 \begin_layout Standard
34140 Bit shifting is one of the most frequently used operation in embedded programmin
34141 g.
34142  SDCC tries to implement bit-shift operations in the most efficient way
34143  possible, e.g.:
34144 \end_layout
34145
34146 \begin_layout Verse
34147
34148 \family typewriter
34149 unsigned char i;
34150 \newline
34151 ...
34152  
34153 \newline
34154 i >>= 4; 
34155 \newline
34156 ...
34157 \end_layout
34158
34159 \begin_layout Standard
34160 generates the following code:
34161 \end_layout
34162
34163 \begin_layout Verse
34164
34165 \family typewriter
34166 mov\InsetSpace ~
34167  a,_i 
34168 \newline
34169 swap a 
34170 \newline
34171 anl\InsetSpace ~
34172  a,#0x0f 
34173 \newline
34174 mov\InsetSpace ~
34175  _i,a
34176 \end_layout
34177
34178 \begin_layout Standard
34179 In general SDCC will never setup a loop if the shift count is known.
34180  Another example:
34181 \end_layout
34182
34183 \begin_layout Verse
34184
34185 \family typewriter
34186 unsigned int i; 
34187 \newline
34188 ...
34189  
34190 \newline
34191 i >>= 9; 
34192 \newline
34193 ...
34194 \end_layout
34195
34196 \begin_layout Standard
34197 will generate:
34198 \end_layout
34199
34200 \begin_layout Verse
34201
34202 \family typewriter
34203 mov\InsetSpace ~
34204 \InsetSpace ~
34205 a,(_i + 1) 
34206 \newline
34207 mov\InsetSpace ~
34208 \InsetSpace ~
34209 (_i + 1),#0x00 
34210 \newline
34211 clr\InsetSpace ~
34212 \InsetSpace ~
34213
34214 \newline
34215 rrc\InsetSpace ~
34216 \InsetSpace ~
34217
34218 \newline
34219 mov\InsetSpace ~
34220 \InsetSpace ~
34221 _i,a
34222 \end_layout
34223
34224 \begin_layout Subsection
34225 Bit-rotation
34226 \begin_inset LatexCommand \index{Bit rotation}
34227
34228 \end_inset
34229
34230
34231 \end_layout
34232
34233 \begin_layout Standard
34234 A special case of the bit-shift operation is bit rotation
34235 \begin_inset LatexCommand \index{rotating bits}
34236
34237 \end_inset
34238
34239 , SDCC recognizes the following expression to be a left bit-rotation:
34240 \end_layout
34241
34242 \begin_layout Verse
34243
34244 \family typewriter
34245 \series bold
34246 unsigned
34247 \series default
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 char i;\InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 /* unsigned is needed for rotation */ 
34262 \newline
34263 ...
34264  
34265 \newline
34266 i = ((i << 1) | (i >> 7)); 
34267 \family default
34268
34269 \newline
34270
34271 \family typewriter
34272 ...
34273 \end_layout
34274
34275 \begin_layout Standard
34276 will generate the following code:
34277 \end_layout
34278
34279 \begin_layout Verse
34280
34281 \family typewriter
34282 mov\InsetSpace ~
34283 \InsetSpace ~
34284 a,_i 
34285 \newline
34286 rl\InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289
34290 \newline
34291 mov\InsetSpace ~
34292 \InsetSpace ~
34293 _i,a
34294 \end_layout
34295
34296 \begin_layout Standard
34297 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34298 ns of this case will also be recognized as bit-rotation, i.e.: 
34299 \end_layout
34300
34301 \begin_layout Verse
34302
34303 \family typewriter
34304 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34305 \end_layout
34306
34307 \begin_layout Subsection
34308 Nibble and Byte Swapping
34309 \end_layout
34310
34311 \begin_layout Standard
34312 Other special cases of the bit-shift operations are nibble or byte swapping
34313 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34314
34315 \end_inset
34316
34317 , SDCC recognizes the following expressions:
34318 \end_layout
34319
34320 \begin_layout Verse
34321
34322 \family typewriter
34323 \series bold
34324 unsigned
34325 \series default
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 char i; 
34329 \newline
34330
34331 \series bold
34332 unsigned
34333 \series default
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 int j; 
34337 \newline
34338 ...
34339  
34340 \newline
34341 i = ((i << 4) | (i >> 4)); 
34342 \family default
34343
34344 \newline
34345
34346 \family typewriter
34347 j = ((j << 8) | (j >> 8)); 
34348 \end_layout
34349
34350 \begin_layout Standard
34351 and generates a swap instruction for the nibble swapping
34352 \begin_inset LatexCommand \index{Nibble swapping}
34353
34354 \end_inset
34355
34356  or move instructions for the byte swapping
34357 \begin_inset LatexCommand \index{Byte swapping}
34358
34359 \end_inset
34360
34361 .
34362  The 
34363 \begin_inset Quotes sld
34364 \end_inset
34365
34366 j
34367 \begin_inset Quotes srd
34368 \end_inset
34369
34370  example can be used to convert from little to big-endian or vice versa.
34371  If you want to change the endianness of a 
34372 \emph on
34373 signed
34374 \emph default
34375  integer you have to cast to 
34376 \family typewriter
34377 (unsigned int)
34378 \family default
34379  first.
34380 \end_layout
34381
34382 \begin_layout Standard
34383 Note that SDCC stores numbers in little-endian
34384 \begin_inset Foot
34385 status open
34386
34387 \begin_layout Standard
34388 Usually 8-bit processors don't care much about endianness.
34389  This is not the case for the standard 8051 which only has an instruction
34390  to increment its 
34391 \emph on
34392 dptr
34393 \emph default
34394
34395 \begin_inset LatexCommand \index{DPTR}
34396
34397 \end_inset
34398
34399 -datapointer
34400 \emph on
34401  
34402 \emph default
34403 so little-endian is the more efficient byte order.
34404 \end_layout
34405
34406 \end_inset
34407
34408
34409 \begin_inset LatexCommand \index{little-endian}
34410
34411 \end_inset
34412
34413
34414 \begin_inset LatexCommand \index{Endianness}
34415
34416 \end_inset
34417
34418  format (i.e.
34419  lowest order first).
34420 \end_layout
34421
34422 \begin_layout Subsection
34423 Highest Order Bit
34424 \begin_inset LatexCommand \index{Highest Order Bit}
34425
34426 \end_inset
34427
34428  / Any Order Bit
34429 \begin_inset LatexCommand \index{Any Order Bit}
34430
34431 \end_inset
34432
34433
34434 \end_layout
34435
34436 \begin_layout Standard
34437 It is frequently required to obtain the highest order bit of an integral
34438  type (long, int, short or char types).
34439  Also obtaining any other order bit is not uncommon.
34440  SDCC recognizes the following expressions to yield the highest order bit
34441  and generates optimized code for it, e.g.:
34442 \end_layout
34443
34444 \begin_layout Verse
34445
34446 \family typewriter
34447 unsigned int gint; 
34448 \newline
34449
34450 \newline
34451 foo () { 
34452 \newline
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 unsigned char hob1, aob1; 
34456 \newline
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 bit hob2, hob3, aob2,
34460  aob3; 
34461 \newline
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 ...
34465  
34466 \newline
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 hob1 = (gint >> 15) & 1; 
34470 \newline
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 hob2 = (gint >> 15) & 1; 
34474 \newline
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 hob3 = gint & 0x8000;
34478  
34479 \newline
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 aob1 = (gint >> 9) & 1; 
34483 \newline
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 aob2 = (gint >> 8) & 1; 
34487 \newline
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 aob3 = gint & 0x0800; 
34491 \newline
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 ..
34495  
34496 \newline
34497 }
34498 \end_layout
34499
34500 \begin_layout Standard
34501 will generate the following code:
34502 \end_layout
34503
34504 \begin_layout Verse
34505
34506 \family typewriter
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \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  61 ;\InsetSpace ~
34533  hob.c 7 
34534 \newline
34535 000A E5*01\InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550  62\InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558  mov\InsetSpace ~
34559 \InsetSpace ~
34560  a,(_gint + 1) 
34561 \newline
34562 000C 23\InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580  63\InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588  rl\InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591  a 
34592 \newline
34593 000D 54 01\InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608
34609  64\InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617  anl\InsetSpace ~
34618 \InsetSpace ~
34619  a,#0x01 
34620 \newline
34621 000F F5*02\InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636  65\InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644  mov\InsetSpace ~
34645 \InsetSpace ~
34646  _foo_hob1_1_1,a 
34647 \newline
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \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  66 ;\InsetSpace ~
34674  hob.c 8 
34675 \newline
34676 0011 E5*01\InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691
34692  67\InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700  mov\InsetSpace ~
34701 \InsetSpace ~
34702  a,(_gint + 1) 
34703 \newline
34704 0013 33\InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722  68\InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730  rlc\InsetSpace ~
34731 \InsetSpace ~
34732  a 
34733 \newline
34734 0014 92*00\InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749  69\InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757  mov\InsetSpace ~
34758 \InsetSpace ~
34759  _foo_hob2_1_1,c
34760  
34761 \newline
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \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  66 ;\InsetSpace ~
34788  hob.c 9 
34789 \newline
34790 0016 E5*01\InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805  67\InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813  mov\InsetSpace ~
34814 \InsetSpace ~
34815  a,(_gint + 1) 
34816 \newline
34817 0018 33\InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835  68\InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843  rlc\InsetSpace ~
34844 \InsetSpace ~
34845  a 
34846 \newline
34847 0019 92*01\InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862
34863  69\InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871  mov\InsetSpace ~
34872 \InsetSpace ~
34873  _foo_hob3_1_1,c 
34874 \newline
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885 \InsetSpace ~
34886 \InsetSpace ~
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900  70 ;\InsetSpace ~
34901  hob.c 10 
34902 \newline
34903 001B E5*01\InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908 \InsetSpace ~
34909 \InsetSpace ~
34910 \InsetSpace ~
34911 \InsetSpace ~
34912 \InsetSpace ~
34913 \InsetSpace ~
34914 \InsetSpace ~
34915 \InsetSpace ~
34916 \InsetSpace ~
34917 \InsetSpace ~
34918  71\InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925 \InsetSpace ~
34926  mov\InsetSpace ~
34927 \InsetSpace ~
34928  a,(_gint + 1) 
34929 \newline
34930 001D
34931  03\InsetSpace ~
34932 \InsetSpace ~
34933 \InsetSpace ~
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 \InsetSpace ~
34937 \InsetSpace ~
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 \InsetSpace ~
34942 \InsetSpace ~
34943 \InsetSpace ~
34944 \InsetSpace ~
34945 \InsetSpace ~
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 \InsetSpace ~
34949  72\InsetSpace ~
34950 \InsetSpace ~
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 \InsetSpace ~
34955 \InsetSpace ~
34956 \InsetSpace ~
34957  rr\InsetSpace ~
34958 \InsetSpace ~
34959 \InsetSpace ~
34960  a 
34961 \newline
34962 001E 54 01\InsetSpace ~
34963 \InsetSpace ~
34964 \InsetSpace ~
34965 \InsetSpace ~
34966 \InsetSpace ~
34967 \InsetSpace ~
34968 \InsetSpace ~
34969 \InsetSpace ~
34970 \InsetSpace ~
34971 \InsetSpace ~
34972 \InsetSpace ~
34973 \InsetSpace ~
34974 \InsetSpace ~
34975 \InsetSpace ~
34976 \InsetSpace ~
34977  73\InsetSpace ~
34978 \InsetSpace ~
34979 \InsetSpace ~
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 \InsetSpace ~
34985  anl\InsetSpace ~
34986 \InsetSpace ~
34987  a,#0x01 
34988 \newline
34989 0020 F5*03\InsetSpace ~
34990 \InsetSpace ~
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 \InsetSpace ~
34997 \InsetSpace ~
34998 \InsetSpace ~
34999 \InsetSpace ~
35000 \InsetSpace ~
35001 \InsetSpace ~
35002 \InsetSpace ~
35003 \InsetSpace ~
35004  74\InsetSpace ~
35005 \InsetSpace ~
35006 \InsetSpace ~
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012  mov\InsetSpace ~
35013 \InsetSpace ~
35014  _foo_aob1_1_1,a
35015  
35016 \newline
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 \InsetSpace ~
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 \InsetSpace ~
35027 \InsetSpace ~
35028 \InsetSpace ~
35029 \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  75 ;\InsetSpace ~
35043  hob.c 11 
35044 \newline
35045 0022 E5*01\InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 \InsetSpace ~
35055 \InsetSpace ~
35056 \InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059 \InsetSpace ~
35060  76\InsetSpace ~
35061 \InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068  mov\InsetSpace ~
35069 \InsetSpace ~
35070  a,(_gint + 1) 
35071 \newline
35072 0024 13\InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090  77\InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098  rrc\InsetSpace ~
35099 \InsetSpace ~
35100  a 
35101 \newline
35102 0025 92*02\InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115 \InsetSpace ~
35116 \InsetSpace ~
35117
35118  78\InsetSpace ~
35119 \InsetSpace ~
35120 \InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126  mov\InsetSpace ~
35127 \InsetSpace ~
35128  _foo_aob2_1_1,c 
35129 \newline
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135 \InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143 \InsetSpace ~
35144 \InsetSpace ~
35145 \InsetSpace ~
35146 \InsetSpace ~
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 \InsetSpace ~
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 \InsetSpace ~
35155  79 ;\InsetSpace ~
35156  hob.c 12 
35157 \newline
35158 0027 E5*01\InsetSpace ~
35159 \InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163 \InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 \InsetSpace ~
35173  80\InsetSpace ~
35174 \InsetSpace ~
35175 \InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181  mov\InsetSpace ~
35182 \InsetSpace ~
35183  a,(_gint + 1) 
35184 \newline
35185 0029
35186  A2 E3\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  81\InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209  mov\InsetSpace ~
35210 \InsetSpace ~
35211  c,acc[3] 
35212 \newline
35213 002B 92*03\InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218 \InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228  82\InsetSpace ~
35229 \InsetSpace ~
35230 \InsetSpace ~
35231 \InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236  mov\InsetSpace ~
35237 \InsetSpace ~
35238  _foo_aob3_1_1,c 
35239 \end_layout
35240
35241 \begin_layout Standard
35242 Other variations of these cases however will 
35243 \emph on
35244 not
35245 \emph default
35246  be recognized.
35247  They are standard C expressions, so I heartily recommend these be the only
35248  way to get the highest order bit, (it is portable).
35249  Of course it will be recognized even if it is embedded in other expressions,
35250  e.g.:
35251 \end_layout
35252
35253 \begin_layout Verse
35254
35255 \family typewriter
35256 xyz = gint + ((gint >> 15) & 1);
35257 \end_layout
35258
35259 \begin_layout Standard
35260 will still be recognized.
35261 \end_layout
35262
35263 \begin_layout Subsection
35264 Higher Order Byte
35265 \begin_inset LatexCommand \index{Higher Order Byte}
35266
35267 \end_inset
35268
35269  / Higher Order Word
35270 \begin_inset LatexCommand \index{Higher Order Word}
35271
35272 \end_inset
35273
35274
35275 \end_layout
35276
35277 \begin_layout Standard
35278 It is also frequently required to obtain a higher order byte or word of
35279  a larger integral type (long, int or short types).
35280  SDCC recognizes the following expressions to yield the higher order byte
35281  or word and generates optimized code for it, e.g.:
35282 \end_layout
35283
35284 \begin_layout Verse
35285
35286 \family typewriter
35287 unsigned int gint; 
35288 \newline
35289 unsigned long int glong; 
35290 \newline
35291
35292 \newline
35293 foo () { 
35294 \newline
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 unsigned char hob1,
35298  hob2; 
35299 \newline
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 unsigned int how1, how2; 
35303 \newline
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 ...
35307  
35308 \newline
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 hob1 = (gint >> 8) & 0xFF; 
35312 \newline
35313 \InsetSpace ~
35314 \InsetSpace ~
35315 hob2 = glong >> 24; 
35316 \newline
35317 \InsetSpace ~
35318 \InsetSpace ~
35319 how1 = (glong >> 16) & 0xFFFF;
35320  
35321 \newline
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 how2 = glong >> 8; 
35325 \newline
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 ..
35329  
35330 \newline
35331 }
35332 \end_layout
35333
35334 \begin_layout Standard
35335 will generate the following code:
35336 \end_layout
35337
35338 \begin_layout Verse
35339
35340 \family typewriter
35341 \InsetSpace ~
35342 \InsetSpace ~
35343 \InsetSpace ~
35344 \InsetSpace ~
35345 \InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366  91 ;\InsetSpace ~
35367  hob.c 15 
35368 \newline
35369 0037 85*01*06\InsetSpace ~
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381  92\InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389  mov\InsetSpace ~
35390 \InsetSpace ~
35391  _foo_hob1_1_1,(_gint + 1) 
35392 \newline
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418  93 ;\InsetSpace ~
35419  hob.c
35420  16 
35421 \newline
35422 003A 85*05*07\InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434  94\InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442  mov\InsetSpace ~
35443 \InsetSpace ~
35444  _foo_hob2_1_1,(_glong + 3) 
35445 \newline
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471  95 ;\InsetSpace ~
35472  hob.c 17 
35473 \newline
35474 003D 85*04*08\InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486
35487  96\InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495  mov\InsetSpace ~
35496 \InsetSpace ~
35497  _foo_how1_1_1,(_glong + 2) 
35498 \newline
35499 0040 85*05*09\InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511  97\InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 \InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519  mov\InsetSpace ~
35520 \InsetSpace ~
35521  (_foo_how1_1_1 +
35522  1),(_glong + 3) 
35523 \newline
35524 0043 85*03*0A\InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536  98\InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544  mov\InsetSpace ~
35545 \InsetSpace ~
35546  _foo_how2_1_1,(_glong + 1) 
35547 \newline
35548 0046 85*04*0B\InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560
35561  99\InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569  mov\InsetSpace ~
35570 \InsetSpace ~
35571  (_foo_how2_1_1 + 1),(_glong + 2) 
35572 \end_layout
35573
35574 \begin_layout Standard
35575 Again, variations of these cases may 
35576 \emph on
35577 not
35578 \emph default
35579  be recognized.
35580  They are standard C expressions, so I heartily recommend these be the only
35581  way to get the higher order byte/word, (it is portable).
35582  Of course it will be recognized even if it is embedded in other expressions,
35583  e.g.:
35584 \end_layout
35585
35586 \begin_layout Verse
35587
35588 \family typewriter
35589 xyz = gint + ((gint >> 8) & 0xFF);
35590 \end_layout
35591
35592 \begin_layout Standard
35593 will still be recognized.
35594 \end_layout
35595
35596 \begin_layout Subsection
35597 Peephole Optimizer
35598 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35599
35600 \end_inset
35601
35602
35603 \begin_inset LatexCommand \index{Peephole optimizer}
35604
35605 \end_inset
35606
35607
35608 \end_layout
35609
35610 \begin_layout Standard
35611 The compiler uses a rule based, pattern matching and re-writing mechanism
35612  for peep-hole optimization.
35613  It is inspired by 
35614 \emph on
35615 copt
35616 \emph default
35617  a peep-hole optimizer by Christopher W.
35618  Fraser (cwfraser\InsetSpace ~
35619 @\InsetSpace ~
35620 microsoft.com).
35621  A default set of rules are compiled into the compiler, additional rules
35622  may be added with the 
35623 \emph on
35624 -
35625 \begin_inset ERT
35626 status collapsed
35627
35628 \begin_layout Standard
35629
35630
35631 \backslash
35632 /
35633 \end_layout
35634
35635 \end_inset
35636
35637 -peep-file
35638 \begin_inset LatexCommand \index{-\/-peep-file}
35639
35640 \end_inset
35641
35642  <filename>
35643 \emph default
35644  option.
35645  The rule language is best illustrated with examples.
35646 \end_layout
35647
35648 \begin_layout Verse
35649
35650 \family typewriter
35651 replace { 
35652 \newline
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 mov %1,a 
35656 \newline
35657 \InsetSpace ~
35658 \InsetSpace ~
35659 mov a,%1
35660 \newline
35661 } by {
35662 \newline
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 mov %1,a
35666 \newline
35667 }
35668 \end_layout
35669
35670 \begin_layout Standard
35671 The above rule will change the following assembly
35672 \begin_inset LatexCommand \index{Assembler routines}
35673
35674 \end_inset
35675
35676  sequence:
35677 \end_layout
35678
35679 \begin_layout Verse
35680
35681 \family typewriter
35682 mov r1,a 
35683 \newline
35684 mov a,r1
35685 \end_layout
35686
35687 \begin_layout Standard
35688 to
35689 \end_layout
35690
35691 \begin_layout Verse
35692
35693 \family typewriter
35694 mov r1,a
35695 \end_layout
35696
35697 \begin_layout Standard
35698 Note: All occurrences of a 
35699 \emph on
35700 %n
35701 \emph default
35702  (pattern variable) must denote the same string.
35703  With the above rule, the assembly sequence:
35704 \end_layout
35705
35706 \begin_layout Verse
35707
35708 \family typewriter
35709 mov r1,a 
35710 \newline
35711 mov a,r2
35712 \end_layout
35713
35714 \begin_layout Standard
35715 will remain unmodified.
35716 \newline
35717
35718 \newline
35719 Other special case optimizations may be added by the
35720  user (via 
35721 \emph on
35722 -
35723 \begin_inset ERT
35724 status collapsed
35725
35726 \begin_layout Standard
35727
35728
35729 \backslash
35730 /
35731 \end_layout
35732
35733 \end_inset
35734
35735 -peep-file option
35736 \emph default
35737 ).
35738  E.g.
35739  some variants of the 8051 MCU
35740 \begin_inset LatexCommand \index{MCS51 variants}
35741
35742 \end_inset
35743
35744  allow only 
35745 \family typewriter
35746 ajmp
35747 \family default
35748  and 
35749 \family typewriter
35750 acall
35751 \family default
35752 .
35753  The following two rules will change all 
35754 \family typewriter
35755 ljmp
35756 \family default
35757  and 
35758 \family typewriter
35759 lcall
35760 \family default
35761  to 
35762 \family typewriter
35763 ajmp
35764 \family default
35765  and 
35766 \family typewriter
35767 acall
35768 \end_layout
35769
35770 \begin_layout Verse
35771
35772 \family typewriter
35773 replace { lcall %1 } by { acall %1 } 
35774 \newline
35775 replace { ljmp %1 } by { ajmp %1 }
35776 \end_layout
35777
35778 \begin_layout Standard
35779 (NOTE: from version 2.7.3 on, you can use option -
35780 \emph on
35781
35782 \begin_inset ERT
35783 status collapsed
35784
35785 \begin_layout Standard
35786
35787
35788 \backslash
35789 /
35790 \end_layout
35791
35792 \end_inset
35793
35794
35795 \emph default
35796 -acall-ajmp
35797 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35798
35799 \end_inset
35800
35801 , which also takes care of aligning the interrupt vectors properly.)
35802 \newline
35803
35804 \end_layout
35805
35806 \begin_layout Standard
35807 The 
35808 \emph on
35809 inline-assembler code
35810 \emph default
35811  is also passed through the peep hole optimizer, thus the peephole optimizer
35812  can also be used as an assembly level macro expander.
35813  The rules themselves are MCU dependent whereas the rule language infra-structur
35814 e is MCU independent.
35815  Peephole optimization rules for other MCU can be easily programmed using
35816  the rule language.
35817 \newline
35818
35819 \newline
35820 The syntax for a rule is as follows:
35821 \end_layout
35822
35823 \begin_layout Verse
35824
35825 \family typewriter
35826 rule := replace [ restart ] '{' <assembly sequence> '
35827 \backslash
35828 n' 
35829 \newline
35830 \InsetSpace ~
35831  \InsetSpace ~
35832  \InsetSpace ~
35833  \InsetSpace ~
35834  \InsetSpace ~
35835  \InsetSpace ~
35836  \InsetSpace ~
35837  \InsetSpace ~
35838  \InsetSpace ~
35839  \InsetSpace ~
35840  \InsetSpace ~
35841  \InsetSpace ~
35842  \InsetSpace ~
35843  \InsetSpace ~
35844  '}' by '{' '
35845 \backslash
35846 n' 
35847 \newline
35848 \InsetSpace ~
35849  \InsetSpace ~
35850  \InsetSpace ~
35851  \InsetSpace ~
35852  \InsetSpace ~
35853  \InsetSpace ~
35854  \InsetSpace ~
35855  \InsetSpace ~
35856  \InsetSpace ~
35857  \InsetSpace ~
35858  \InsetSpace ~
35859  \InsetSpace ~
35860  \InsetSpace ~
35861  \InsetSpace ~
35862  \InsetSpace ~
35863  \InsetSpace ~
35864  <assembly sequence> '
35865 \backslash
35866 n' 
35867 \newline
35868 \InsetSpace ~
35869  \InsetSpace ~
35870  \InsetSpace ~
35871  \InsetSpace ~
35872  \InsetSpace ~
35873  \InsetSpace ~
35874  \InsetSpace ~
35875  \InsetSpace ~
35876  \InsetSpace ~
35877  \InsetSpace ~
35878  \InsetSpace ~
35879  \InsetSpace ~
35880  \InsetSpace ~
35881  \InsetSpace ~
35882  '}' [if <functionName> ] '
35883 \backslash
35884 n' 
35885 \end_layout
35886
35887 \begin_layout Standard
35888 <assembly sequence> := assembly instruction (each instruction including
35889  labels must be on a separate line).
35890 \newline
35891
35892 \newline
35893 The optimizer will apply to the rules
35894  one by one from the top in the sequence of their appearance, it will terminate
35895  when all rules are exhausted.
35896  If the 'restart' option is specified, then the optimizer will start matching
35897  the rules again from the top, this option for a rule is expensive (performance)
35898 , it is intended to be used in situations where a transformation will trigger
35899  the same rule again.
35900  An example of this (not a good one, it has side effects) is the following
35901  rule:
35902 \end_layout
35903
35904 \begin_layout Verse
35905
35906 \family typewriter
35907 replace restart { 
35908 \newline
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 pop %1 
35912 \newline
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 push %1 } by { 
35916 \newline
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 ; nop 
35920 \newline
35921 }
35922 \end_layout
35923
35924 \begin_layout Standard
35925 Note that the replace pattern cannot be a blank, but can be a comment line.
35926  Without the 'restart' option only the innermost 'pop' 'push' pair would
35927  be eliminated, i.e.:
35928 \end_layout
35929
35930 \begin_layout Verse
35931
35932 \family typewriter
35933 pop ar1 
35934 \newline
35935 pop ar2 
35936 \newline
35937 push ar2 
35938 \newline
35939 push ar1
35940 \end_layout
35941
35942 \begin_layout Standard
35943 would result in:
35944 \end_layout
35945
35946 \begin_layout Verse
35947
35948 \family typewriter
35949 pop ar1 
35950 \newline
35951 ; nop 
35952 \newline
35953 push ar1
35954 \end_layout
35955
35956 \begin_layout Standard
35957
35958 \emph on
35959 with
35960 \emph default
35961  the restart option the rule will be applied again to the resulting code
35962  and then all the pop-push pairs will be eliminated to yield:
35963 \end_layout
35964
35965 \begin_layout Verse
35966
35967 \family typewriter
35968 ; nop 
35969 \newline
35970 ; nop
35971 \end_layout
35972
35973 \begin_layout Standard
35974 A conditional function can be attached to a rule.
35975  Attaching rules are somewhat more involved, let me illustrate this with
35976  an example.
35977 \end_layout
35978
35979 \begin_layout Verse
35980
35981 \family typewriter
35982 replace { 
35983 \newline
35984 \InsetSpace ~
35985  \InsetSpace ~
35986  \InsetSpace ~
35987 ljmp %5 
35988 \newline
35989 %2:
35990 \newline
35991 } by { 
35992 \newline
35993 \InsetSpace ~
35994  \InsetSpace ~
35995  \InsetSpace ~
35996 sjmp %5 
35997 \newline
35998 %2:
35999 \newline
36000 } if labelInRange
36001 \end_layout
36002
36003 \begin_layout Standard
36004 The optimizer does a look-up of a function name table defined in function
36005  
36006 \emph on
36007 callFuncByName
36008 \emph default
36009  in the source file SDCCpeeph.c, with the name 
36010 \emph on
36011 labelInRange
36012 \emph default
36013 .
36014  If it finds a corresponding entry the function is called.
36015  Note there can be no parameters specified for these functions, in this
36016  case the use of 
36017 \emph on
36018 %5
36019 \emph default
36020  is crucial, since the function 
36021 \emph on
36022 labelInRange
36023 \emph default
36024  expects to find the label in that particular variable (the hash table containin
36025 g the variable bindings is passed as a parameter).
36026  If you want to code more such functions, take a close look at the function
36027  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36028  Currently implemented are 
36029 \emph on
36030 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36031  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36032 \emph default
36033 and
36034 \emph on
36035  notVolatile
36036 \emph default
36037 .
36038 \end_layout
36039
36040 \begin_layout Standard
36041 I know this whole thing is a little kludgey, but maybe some day we will
36042  have some better means.
36043  If you are looking at this file, you will see the default rules that are
36044  compiled into the compiler, you can add your own rules in the default set
36045  there if you get tired of specifying the -
36046 \begin_inset ERT
36047 status collapsed
36048
36049 \begin_layout Standard
36050
36051
36052 \backslash
36053 /
36054 \end_layout
36055
36056 \end_inset
36057
36058 -peep-file option.
36059 \end_layout
36060
36061 \begin_layout Section
36062 ANSI-Compliance
36063 \begin_inset LatexCommand \index{ANSI-compliance}
36064
36065 \end_inset
36066
36067
36068 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36069
36070 \end_inset
36071
36072
36073 \end_layout
36074
36075 \begin_layout Standard
36076 The latest publically available version of the standard 
36077 \emph on
36078 ISO/IEC 9899 - Programming languages - C
36079 \emph default
36080  should be available at: 
36081 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36082
36083 \end_inset
36084
36085 .
36086 \newline
36087
36088 \end_layout
36089
36090 \begin_layout Standard
36091 Deviations from the compliance:
36092 \end_layout
36093
36094 \begin_layout Itemize
36095 functions are not reentrant
36096 \begin_inset LatexCommand \index{reentrant}
36097
36098 \end_inset
36099
36100  unless explicitly declared as such or the 
36101 \series bold
36102 -
36103 \begin_inset ERT
36104 status collapsed
36105
36106 \begin_layout Standard
36107
36108
36109 \backslash
36110 /
36111 \end_layout
36112
36113 \end_inset
36114
36115 -stack-auto
36116 \begin_inset LatexCommand \index{-\/-stack-auto}
36117
36118 \end_inset
36119
36120
36121 \series default
36122  command line option is specified.
36123 \end_layout
36124
36125 \begin_layout Itemize
36126 structures
36127 \begin_inset LatexCommand \index{struct}
36128
36129 \end_inset
36130
36131  and unions
36132 \begin_inset LatexCommand \index{union}
36133
36134 \end_inset
36135
36136  cannot be assigned values directly, cannot be passed as function parameters
36137  or assigned to each other and cannot be a return value
36138 \begin_inset LatexCommand \index{return value}
36139
36140 \end_inset
36141
36142  from a function, e.g.:
36143 \end_layout
36144
36145 \begin_deeper
36146 \begin_layout Verse
36147
36148 \family typewriter
36149 struct s { ...
36150  }; 
36151 \newline
36152 struct s s1, s2; 
36153 \newline
36154 foo() 
36155 \newline
36156
36157 \newline
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 ...
36163  
36164 \newline
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36170 \newline
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 \InsetSpace ~
36175 ...
36176  
36177 \newline
36178 }
36179 \newline
36180
36181 \series bold
36182 struct
36183 \series default
36184  s foo1 (
36185 \series bold
36186 struct
36187 \series default
36188  s parms) /* invalid in SDCC although allowed in ANSI */
36189 \newline
36190
36191 \newline
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 \InsetSpace ~
36195 \InsetSpace ~
36196 struct s rets;
36197  
36198 \newline
36199 \InsetSpace ~
36200 \InsetSpace ~
36201 \InsetSpace ~
36202 \InsetSpace ~
36203 ...
36204  
36205 \newline
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36211 \newline
36212 }
36213 \end_layout
36214
36215 \end_deeper
36216 \begin_layout Itemize
36217 initialization of structure arrays must be fully braced.
36218 \end_layout
36219
36220 \begin_deeper
36221 \begin_layout Verse
36222
36223 \family typewriter
36224 struct s { char x } a[] = {1, 2};\InsetSpace ~
36225 \InsetSpace ~
36226 \InsetSpace ~
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 /* invalid in SDCC */
36230 \newline
36231 struct s { char x
36232  } a[] = {{1}, {2}}; /* OK */
36233 \end_layout
36234
36235 \end_deeper
36236 \begin_layout Itemize
36237 'long long
36238 \begin_inset LatexCommand \index{long long (not supported)}
36239
36240 \end_inset
36241
36242 ' (64 bit integers
36243 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36244
36245 \end_inset
36246
36247 ) not supported.
36248 \end_layout
36249
36250 \begin_layout Itemize
36251 'double
36252 \begin_inset LatexCommand \index{double (not supported)}
36253
36254 \end_inset
36255
36256 ' precision floating point 
36257 \begin_inset LatexCommand \index{Floating point support}
36258
36259 \end_inset
36260
36261 not supported.
36262 \end_layout
36263
36264 \begin_layout Itemize
36265 Old K&R style
36266 \begin_inset LatexCommand \index{K\&R style}
36267
36268 \end_inset
36269
36270  function declarations are NOT allowed.
36271 \end_layout
36272
36273 \begin_deeper
36274 \begin_layout Verse
36275
36276 \family typewriter
36277 foo(i,j) /* this old style of function declarations */ 
36278 \newline
36279 int i,j; /* is valid
36280  in ANSI but not valid in SDCC */ 
36281 \newline
36282
36283 \newline
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 ...
36289  
36290 \newline
36291 }
36292 \end_layout
36293
36294 \end_deeper
36295 \begin_layout Itemize
36296 Most enhancements in C99 are not supported, e.g.:
36297 \end_layout
36298
36299 \begin_deeper
36300 \begin_layout Verse
36301
36302 \family typewriter
36303 for (
36304 \series bold
36305 int
36306 \series default
36307  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36308 \end_layout
36309
36310 \end_deeper
36311 \begin_layout Itemize
36312 But some have been added recently in SDCC 2.7.0.
36313  They must be considered alpha quality however.
36314 \end_layout
36315
36316 \begin_deeper
36317 \begin_layout Verse
36318
36319 \family typewriter
36320 \series bold
36321 inline
36322 \begin_inset LatexCommand \index{inline (not supported)}
36323
36324 \end_inset
36325
36326
36327 \series default
36328  int increment (int a) { return a+1; } /* inlines the increment without
36329  function call overhead */
36330 \newline
36331 int * 
36332 \series bold
36333 restrict
36334 \begin_inset LatexCommand \index{inline (not supported)}
36335
36336 \end_inset
36337
36338
36339 \series default
36340  p; /* accepted but ignored */
36341 \end_layout
36342
36343 \end_deeper
36344 \begin_layout Itemize
36345 Certain words that are valid identifiers in the standard may be reserved
36346  words in SDCC unless the 
36347 \series bold
36348 -
36349 \begin_inset ERT
36350 status collapsed
36351
36352 \begin_layout Standard
36353
36354
36355 \backslash
36356 /
36357 \end_layout
36358
36359 \end_inset
36360
36361 -std-c89
36362 \begin_inset LatexCommand \index{-\/-std-c89}
36363
36364 \end_inset
36365
36366  or -
36367 \begin_inset ERT
36368 status collapsed
36369
36370 \begin_layout Standard
36371
36372
36373 \backslash
36374 /
36375 \end_layout
36376
36377 \end_inset
36378
36379 -std-c99
36380 \begin_inset LatexCommand \index{-\/-std-c99}
36381
36382 \end_inset
36383
36384
36385 \series default
36386  command line options are used.
36387  These may include (depending on the selected processor): 'at', 'banked',
36388  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36389 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36390  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36391  '_naked'.
36392  Compliant equivalents of these keywords are always available in a form
36393  that begin with two underscores
36394 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36395
36396 \end_inset
36397
36398 , f.e.
36399  '__data' instead of 'data'.
36400 \end_layout
36401
36402 \begin_layout Section
36403 Cyclomatic Complexity
36404 \begin_inset LatexCommand \index{Cyclomatic complexity}
36405
36406 \end_inset
36407
36408
36409 \end_layout
36410
36411 \begin_layout Standard
36412 Cyclomatic complexity of a function is defined as the number of independent
36413  paths the program can take during execution of the function.
36414  This is an important number since it defines the number test cases you
36415  have to generate to validate the function.
36416  The accepted industry standard for complexity number is 10, if the cyclomatic
36417  complexity reported by SDCC exceeds 10 you should think about simplification
36418  of the function logic.
36419  Note that the complexity level is not related to the number of lines of
36420  code in a function.
36421  Large functions can have low complexity, and small functions can have large
36422  complexity levels.
36423  
36424 \newline
36425
36426 \newline
36427 SDCC uses the following formula to compute the complexity:
36428 \newline
36429
36430 \end_layout
36431
36432 \begin_layout Standard
36433 complexity = (number of edges in control flow graph) - (number of nodes
36434  in control flow graph) + 2;
36435 \newline
36436
36437 \newline
36438 Having said that the industry standard is 10,
36439  you should be aware that in some cases it be may unavoidable to have a
36440  complexity level of less than 10.
36441  For example if you have switch statement with more than 10 case labels,
36442  each case label adds one to the complexity level.
36443  The complexity level is by no means an absolute measure of the algorithmic
36444  complexity of the function, it does however provide a good starting point
36445  for which functions you might look at for further optimization.
36446 \end_layout
36447
36448 \begin_layout Section
36449 Retargetting for other Processors
36450 \end_layout
36451
36452 \begin_layout Standard
36453 The issues for retargetting the compiler are far too numerous to be covered
36454  by this document.
36455  What follows is a brief description of each of the seven phases of the
36456  compiler and its MCU dependency.
36457 \end_layout
36458
36459 \begin_layout Itemize
36460 Parsing the source and building the annotated parse tree.
36461  This phase is largely MCU independent (except for the language extensions).
36462  Syntax & semantic checks are also done in this phase, along with some initial
36463  optimizations like back patching labels and the pattern matching optimizations
36464  like bit-rotation etc.
36465 \end_layout
36466
36467 \begin_layout Itemize
36468 The second phase involves generating an intermediate code which can be easy
36469  manipulated during the later phases.
36470  This phase is entirely MCU independent.
36471  The intermediate code generation assumes the target machine has unlimited
36472  number of registers, and designates them with the name iTemp.
36473  The compiler can be made to dump a human readable form of the code generated
36474  by using the -
36475 \begin_inset ERT
36476 status collapsed
36477
36478 \begin_layout Standard
36479
36480
36481 \backslash
36482 /
36483 \end_layout
36484
36485 \end_inset
36486
36487 -dumpraw option.
36488 \end_layout
36489
36490 \begin_layout Itemize
36491 This phase does the bulk of the standard optimizations and is also MCU independe
36492 nt.
36493  This phase can be broken down into several sub-phases:
36494 \newline
36495
36496 \newline
36497 Break down intermediate
36498  code (iCode) into basic blocks.
36499 \newline
36500 Do control flow & data flow analysis on the
36501  basic blocks.
36502 \newline
36503 Do local common subexpression elimination, then global subexpressio
36504 n elimination
36505 \newline
36506 Dead code elimination
36507 \newline
36508 Loop optimizations
36509 \newline
36510 If loop optimizations
36511  caused any changes then do 'global subexpression elimination' and 'dead
36512  code elimination' again.
36513 \end_layout
36514
36515 \begin_layout Itemize
36516 This phase determines the live-ranges; by live range I mean those iTemp
36517  variables defined by the compiler that still survive after all the optimization
36518 s.
36519  Live range analysis
36520 \begin_inset LatexCommand \index{Live range analysis}
36521
36522 \end_inset
36523
36524  is essential for register allocation, since these computation determines
36525  which of these iTemps will be assigned to registers, and for how long.
36526 \end_layout
36527
36528 \begin_layout Itemize
36529 Phase five is register allocation.
36530  There are two parts to this process.
36531 \newline
36532
36533 \newline
36534 The first part I call 'register packing'
36535  (for lack of a better term).
36536  In this case several MCU specific expression folding is done to reduce
36537  register pressure.
36538 \newline
36539
36540 \newline
36541 The second part is more MCU independent and deals with
36542  allocating registers to the remaining live ranges.
36543  A lot of MCU specific code does creep into this phase because of the limited
36544  number of index registers available in the 8051.
36545 \end_layout
36546
36547 \begin_layout Itemize
36548 The Code generation phase is (unhappily), entirely MCU dependent and very
36549  little (if any at all) of this code can be reused for other MCU.
36550  However the scheme for allocating a homogenized assembler operand for each
36551  iCode operand may be reused.
36552 \end_layout
36553
36554 \begin_layout Itemize
36555 As mentioned in the optimization section the peep-hole optimizer is rule
36556  based system, which can reprogrammed for other MCUs.
36557 \end_layout
36558
36559 \begin_layout Standard
36560 More information is available on SDCC Wiki
36561 \begin_inset LatexCommand \index{wiki}
36562
36563 \end_inset
36564
36565  (preliminary link 
36566 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36567
36568 \end_inset
36569
36570 ) and in the thread 
36571 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36572
36573 \end_inset
36574
36575  .
36576 \end_layout
36577
36578 \begin_layout Chapter
36579 Compiler internals
36580 \begin_inset LatexCommand \index{Compiler internals}
36581
36582 \end_inset
36583
36584
36585 \end_layout
36586
36587 \begin_layout Section
36588 The anatomy of the compiler
36589 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36590
36591 \end_inset
36592
36593
36594 \end_layout
36595
36596 \begin_layout Standard
36597
36598 \shape italic
36599 This is an excerpt from an article published in Circuit Cellar Magazine
36600  in 
36601 \series bold
36602 August 2000
36603 \series default
36604 .
36605  It's a little outdated (the compiler is much more efficient now and user/develo
36606 per friendly), but pretty well exposes the guts of it all.
36607 \shape default
36608
36609 \newline
36610
36611 \newline
36612 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36613  It is fairly easy to retarget for other 8-bit MCU.
36614  Here we take a look at some of the internals of the compiler.
36615  
36616 \end_layout
36617
36618 \begin_layout Paragraph*
36619 Parsing
36620 \begin_inset LatexCommand \index{Parsing}
36621
36622 \end_inset
36623
36624  
36625 \end_layout
36626
36627 \begin_layout Standard
36628 Parsing the input source file and creating an AST (Annotated Syntax Tree
36629 \begin_inset LatexCommand \index{Annotated syntax tree}
36630
36631 \end_inset
36632
36633 ).
36634  This phase also involves propagating types (annotating each node of the
36635  parse tree with type information) and semantic analysis.
36636  There are some MCU specific parsing rules.
36637  For example the storage classes, the extended storage classes are MCU specific
36638  while there may be a xdata storage class for 8051 there is no such storage
36639  class for z80 or Atmel AVR.
36640  SDCC allows MCU specific storage class extensions, i.e.
36641  xdata will be treated as a storage class specifier when parsing 8051 C
36642  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36643  C code.
36644 \end_layout
36645
36646 \begin_layout Paragraph*
36647 Generating iCode
36648 \begin_inset LatexCommand \index{iCode}
36649
36650 \end_inset
36651
36652
36653 \end_layout
36654
36655 \begin_layout Standard
36656 Intermediate code generation.
36657  In this phase the AST is broken down into three-operand form (iCode).
36658  These three operand forms are represented as doubly linked lists.
36659  ICode is the term given to the intermediate form generated by the compiler.
36660  ICode example section shows some examples of iCode generated for some simple
36661  C source functions.
36662 \end_layout
36663
36664 \begin_layout Paragraph*
36665 Optimizations
36666 \begin_inset LatexCommand \index{Optimizations}
36667
36668 \end_inset
36669
36670 .
36671 \end_layout
36672
36673 \begin_layout Standard
36674 Bulk of the target independent optimizations is performed in this phase.
36675  The optimizations include constant propagation, common sub-expression eliminati
36676 on, loop invariant code movement, strength reduction of loop induction variables
36677  and dead-code elimination.
36678 \end_layout
36679
36680 \begin_layout Paragraph*
36681 Live range analysis
36682 \begin_inset LatexCommand \index{Live range analysis}
36683
36684 \end_inset
36685
36686
36687 \end_layout
36688
36689 \begin_layout Standard
36690 During intermediate code generation phase, the compiler assumes the target
36691  machine has infinite number of registers and generates a lot of temporary
36692  variables.
36693  The live range computation determines the lifetime of each of these compiler-ge
36694 nerated temporaries.
36695  A picture speaks a thousand words.
36696  ICode example sections show the live range annotations for each of the
36697  operand.
36698  It is important to note here, each iCode is assigned a number in the order
36699  of its execution in the function.
36700  The live ranges are computed in terms of these numbers.
36701  The from number is the number of the iCode which first defines the operand
36702  and the to number signifies the iCode which uses this operand last.
36703 \end_layout
36704
36705 \begin_layout Paragraph*
36706 Register Allocation
36707 \begin_inset LatexCommand \index{Register allocation}
36708
36709 \end_inset
36710
36711
36712 \end_layout
36713
36714 \begin_layout Standard
36715 The register allocation determines the type and number of registers needed
36716  by each operand.
36717  In most MCUs only a few registers can be used for indirect addressing.
36718  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36719  address the internal ram and DPTR to indirectly address the external ram.
36720  The compiler will try to allocate the appropriate register to pointer variables
36721  if it can.
36722  ICode example section shows the operands annotated with the registers assigned
36723  to them.
36724  The compiler will try to keep operands in registers as much as possible;
36725  there are several schemes the compiler uses to do achieve this.
36726  When the compiler runs out of registers the compiler will check to see
36727  if there are any live operands which is not used or defined in the current
36728  basic block being processed, if there are any found then it will push that
36729  operand and use the registers in this block, the operand will then be popped
36730  at the end of the basic block.
36731  
36732 \end_layout
36733
36734 \begin_layout Standard
36735 There are other MCU specific considerations in this phase.
36736  Some MCUs have an accumulator; very short-lived operands could be assigned
36737  to the accumulator instead of a general-purpose register.
36738 \end_layout
36739
36740 \begin_layout Paragraph*
36741 Code generation
36742 \end_layout
36743
36744 \begin_layout Standard
36745 Figure II gives a table of iCode
36746 \begin_inset LatexCommand \index{iCode}
36747
36748 \end_inset
36749
36750  operations supported by the compiler.
36751  The code generation involves translating these operations into corresponding
36752  assembly code for the processor.
36753  This sounds overly simple but that is the essence of code generation.
36754  Some of the iCode operations are generated on a MCU specific manner for
36755  example, the z80 port does not use registers to pass parameters so the
36756  SEND and RECV iCode operations will not be generated, and it also does
36757  not support JUMPTABLES.
36758  
36759 \newline
36760
36761 \end_layout
36762
36763 \begin_layout Standard
36764
36765 \size footnotesize
36766 Figure II 
36767 \begin_inset Tabular
36768 <lyxtabular version="3" rows="39" columns="4">
36769 <features islongtable="true" headBottomDL="true">
36770 <column alignment="block" valignment="top" leftline="true" width="13col%">
36771 <column alignment="left" valignment="top" leftline="true" width="13col%">
36772 <column alignment="block" valignment="top" leftline="true" width="22col%">
36773 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36774 <row topline="true" bottomline="true" endhead="true">
36775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36776 \begin_inset Text
36777
36778 \begin_layout Standard
36779
36780 \series bold
36781 iCode
36782 \series default
36783
36784 \begin_inset LatexCommand \index{iCode}
36785
36786 \end_inset
36787
36788
36789 \end_layout
36790
36791 \end_inset
36792 </cell>
36793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36794 \begin_inset Text
36795
36796 \begin_layout Standard
36797
36798 \series bold
36799 Operands
36800 \end_layout
36801
36802 \end_inset
36803 </cell>
36804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36805 \begin_inset Text
36806
36807 \begin_layout Standard
36808
36809 \series bold
36810 Description
36811 \end_layout
36812
36813 \end_inset
36814 </cell>
36815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36816 \begin_inset Text
36817
36818 \begin_layout Standard
36819
36820 \series bold
36821 C Equivalent
36822 \end_layout
36823
36824 \end_inset
36825 </cell>
36826 </row>
36827 <row topline="true">
36828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36829 \begin_inset Text
36830
36831 \begin_layout Standard
36832
36833 \size footnotesize
36834 '!'
36835 \end_layout
36836
36837 \end_inset
36838 </cell>
36839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36840 \begin_inset Text
36841
36842 \begin_layout Standard
36843
36844 \size footnotesize
36845 IC_LEFT() IC_RESULT()
36846 \end_layout
36847
36848 \end_inset
36849 </cell>
36850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36851 \begin_inset Text
36852
36853 \begin_layout Standard
36854
36855 \size footnotesize
36856 NOT operation 
36857 \end_layout
36858
36859 \end_inset
36860 </cell>
36861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36862 \begin_inset Text
36863
36864 \begin_layout Standard
36865
36866 \size footnotesize
36867 IC_RESULT = ! IC_LEFT;
36868 \end_layout
36869
36870 \end_inset
36871 </cell>
36872 </row>
36873 <row topline="true">
36874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36875 \begin_inset Text
36876
36877 \begin_layout Standard
36878
36879 \size footnotesize
36880 '~'
36881 \end_layout
36882
36883 \end_inset
36884 </cell>
36885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36886 \begin_inset Text
36887
36888 \begin_layout Standard
36889
36890 \size footnotesize
36891 IC_LEFT() IC_RESULT()
36892 \end_layout
36893
36894 \end_inset
36895 </cell>
36896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36897 \begin_inset Text
36898
36899 \begin_layout Standard
36900
36901 \size footnotesize
36902 Bitwise complement of 
36903 \end_layout
36904
36905 \end_inset
36906 </cell>
36907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36908 \begin_inset Text
36909
36910 \begin_layout Standard
36911
36912 \size footnotesize
36913 IC_RESULT = ~IC_LEFT;
36914 \end_layout
36915
36916 \end_inset
36917 </cell>
36918 </row>
36919 <row topline="true">
36920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36921 \begin_inset Text
36922
36923 \begin_layout Standard
36924
36925 \size footnotesize
36926 RRC
36927 \end_layout
36928
36929 \end_inset
36930 </cell>
36931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36932 \begin_inset Text
36933
36934 \begin_layout Standard
36935
36936 \size footnotesize
36937 IC_LEFT() IC_RESULT()
36938 \end_layout
36939
36940 \end_inset
36941 </cell>
36942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36943 \begin_inset Text
36944
36945 \begin_layout Standard
36946
36947 \size footnotesize
36948 Rotate right with carry
36949 \end_layout
36950
36951 \end_inset
36952 </cell>
36953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36954 \begin_inset Text
36955
36956 \begin_layout Standard
36957
36958 \size footnotesize
36959 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36960 \end_layout
36961
36962 \end_inset
36963 </cell>
36964 </row>
36965 <row topline="true">
36966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36967 \begin_inset Text
36968
36969 \begin_layout Standard
36970
36971 \size footnotesize
36972 RLC
36973 \end_layout
36974
36975 \end_inset
36976 </cell>
36977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36978 \begin_inset Text
36979
36980 \begin_layout Standard
36981
36982 \size footnotesize
36983 IC_LEFT() IC_RESULT()
36984 \end_layout
36985
36986 \end_inset
36987 </cell>
36988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36989 \begin_inset Text
36990
36991 \begin_layout Standard
36992
36993 \size footnotesize
36994 Rotate left with carry
36995 \end_layout
36996
36997 \end_inset
36998 </cell>
36999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37000 \begin_inset Text
37001
37002 \begin_layout Standard
37003
37004 \size footnotesize
37005 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37006 \end_layout
37007
37008 \end_inset
37009 </cell>
37010 </row>
37011 <row topline="true">
37012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37013 \begin_inset Text
37014
37015 \begin_layout Standard
37016
37017 \size footnotesize
37018 GETHBIT
37019 \end_layout
37020
37021 \end_inset
37022 </cell>
37023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37024 \begin_inset Text
37025
37026 \begin_layout Standard
37027
37028 \size footnotesize
37029 IC_LEFT() IC_RESULT()
37030 \end_layout
37031
37032 \end_inset
37033 </cell>
37034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37035 \begin_inset Text
37036
37037 \begin_layout Standard
37038
37039 \size footnotesize
37040 Get the highest order bit of IC_LEFT
37041 \end_layout
37042
37043 \end_inset
37044 </cell>
37045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37046 \begin_inset Text
37047
37048 \begin_layout Standard
37049
37050 \size footnotesize
37051 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37052 \end_layout
37053
37054 \end_inset
37055 </cell>
37056 </row>
37057 <row topline="true">
37058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37059 \begin_inset Text
37060
37061 \begin_layout Standard
37062
37063 \size footnotesize
37064 UNARYMINUS
37065 \end_layout
37066
37067 \end_inset
37068 </cell>
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37070 \begin_inset Text
37071
37072 \begin_layout Standard
37073
37074 \size footnotesize
37075 IC_LEFT() IC_RESULT()
37076 \end_layout
37077
37078 \end_inset
37079 </cell>
37080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37081 \begin_inset Text
37082
37083 \begin_layout Standard
37084
37085 \size footnotesize
37086 Unary minus
37087 \end_layout
37088
37089 \end_inset
37090 </cell>
37091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37092 \begin_inset Text
37093
37094 \begin_layout Standard
37095
37096 \size footnotesize
37097 IC_RESULT = - IC_LEFT;
37098 \end_layout
37099
37100 \end_inset
37101 </cell>
37102 </row>
37103 <row topline="true">
37104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37105 \begin_inset Text
37106
37107 \begin_layout Standard
37108
37109 \size footnotesize
37110 IPUSH
37111 \end_layout
37112
37113 \end_inset
37114 </cell>
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37116 \begin_inset Text
37117
37118 \begin_layout Standard
37119
37120 \size footnotesize
37121 IC_LEFT()
37122 \end_layout
37123
37124 \end_inset
37125 </cell>
37126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37127 \begin_inset Text
37128
37129 \begin_layout Standard
37130
37131 \size footnotesize
37132 Push the operand into stack
37133 \end_layout
37134
37135 \end_inset
37136 </cell>
37137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37138 \begin_inset Text
37139
37140 \begin_layout Standard
37141
37142 \size footnotesize
37143 NONE
37144 \end_layout
37145
37146 \end_inset
37147 </cell>
37148 </row>
37149 <row topline="true">
37150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37151 \begin_inset Text
37152
37153 \begin_layout Standard
37154
37155 \size footnotesize
37156 IPOP
37157 \end_layout
37158
37159 \end_inset
37160 </cell>
37161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37162 \begin_inset Text
37163
37164 \begin_layout Standard
37165
37166 \size footnotesize
37167 IC_LEFT()
37168 \end_layout
37169
37170 \end_inset
37171 </cell>
37172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37173 \begin_inset Text
37174
37175 \begin_layout Standard
37176
37177 \size footnotesize
37178 Pop the operand from the stack 
37179 \end_layout
37180
37181 \end_inset
37182 </cell>
37183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37184 \begin_inset Text
37185
37186 \begin_layout Standard
37187
37188 \size footnotesize
37189 NONE
37190 \end_layout
37191
37192 \end_inset
37193 </cell>
37194 </row>
37195 <row topline="true">
37196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37197 \begin_inset Text
37198
37199 \begin_layout Standard
37200
37201 \size footnotesize
37202 CALL
37203 \end_layout
37204
37205 \end_inset
37206 </cell>
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37208 \begin_inset Text
37209
37210 \begin_layout Standard
37211
37212 \size footnotesize
37213 IC_LEFT() IC_RESULT()
37214 \end_layout
37215
37216 \end_inset
37217 </cell>
37218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37219 \begin_inset Text
37220
37221 \begin_layout Standard
37222
37223 \size footnotesize
37224 Call the function represented by IC_LEFT 
37225 \end_layout
37226
37227 \end_inset
37228 </cell>
37229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37230 \begin_inset Text
37231
37232 \begin_layout Standard
37233
37234 \size footnotesize
37235 IC_RESULT = IC_LEFT();
37236 \end_layout
37237
37238 \end_inset
37239 </cell>
37240 </row>
37241 <row topline="true">
37242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37243 \begin_inset Text
37244
37245 \begin_layout Standard
37246
37247 \size footnotesize
37248 PCALL
37249 \end_layout
37250
37251 \end_inset
37252 </cell>
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37254 \begin_inset Text
37255
37256 \begin_layout Standard
37257
37258 \size footnotesize
37259 IC_LEFT() IC_RESULT()
37260 \end_layout
37261
37262 \end_inset
37263 </cell>
37264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37265 \begin_inset Text
37266
37267 \begin_layout Standard
37268
37269 \size footnotesize
37270 Call via function pointer
37271 \end_layout
37272
37273 \end_inset
37274 </cell>
37275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37276 \begin_inset Text
37277
37278 \begin_layout Standard
37279
37280 \size footnotesize
37281 IC_RESULT = (*IC_LEFT)();
37282 \end_layout
37283
37284 \end_inset
37285 </cell>
37286 </row>
37287 <row topline="true">
37288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37289 \begin_inset Text
37290
37291 \begin_layout Standard
37292
37293 \size footnotesize
37294 RETURN
37295 \end_layout
37296
37297 \end_inset
37298 </cell>
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37300 \begin_inset Text
37301
37302 \begin_layout Standard
37303
37304 \size footnotesize
37305 IC_LEFT()
37306 \end_layout
37307
37308 \end_inset
37309 </cell>
37310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37311 \begin_inset Text
37312
37313 \begin_layout Standard
37314
37315 \size footnotesize
37316 Return the value in operand IC_LEFT 
37317 \end_layout
37318
37319 \end_inset
37320 </cell>
37321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37322 \begin_inset Text
37323
37324 \begin_layout Standard
37325
37326 \size footnotesize
37327 return IC_LEFT;
37328 \end_layout
37329
37330 \end_inset
37331 </cell>
37332 </row>
37333 <row topline="true">
37334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37335 \begin_inset Text
37336
37337 \begin_layout Standard
37338
37339 \size footnotesize
37340 LABEL
37341 \end_layout
37342
37343 \end_inset
37344 </cell>
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37346 \begin_inset Text
37347
37348 \begin_layout Standard
37349
37350 \size footnotesize
37351 IC_LABEL() 
37352 \end_layout
37353
37354 \end_inset
37355 </cell>
37356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37357 \begin_inset Text
37358
37359 \begin_layout Standard
37360
37361 \size footnotesize
37362 Label
37363 \end_layout
37364
37365 \end_inset
37366 </cell>
37367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37368 \begin_inset Text
37369
37370 \begin_layout Standard
37371
37372 \size footnotesize
37373 IC_LABEL:
37374 \end_layout
37375
37376 \end_inset
37377 </cell>
37378 </row>
37379 <row topline="true">
37380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37381 \begin_inset Text
37382
37383 \begin_layout Standard
37384
37385 \size footnotesize
37386 GOTO
37387 \end_layout
37388
37389 \end_inset
37390 </cell>
37391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37392 \begin_inset Text
37393
37394 \begin_layout Standard
37395
37396 \size footnotesize
37397 IC_LABEL() 
37398 \end_layout
37399
37400 \end_inset
37401 </cell>
37402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37403 \begin_inset Text
37404
37405 \begin_layout Standard
37406
37407 \size footnotesize
37408 Goto label
37409 \end_layout
37410
37411 \end_inset
37412 </cell>
37413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37414 \begin_inset Text
37415
37416 \begin_layout Standard
37417
37418 \size footnotesize
37419 goto IC_LABEL();
37420 \end_layout
37421
37422 \end_inset
37423 </cell>
37424 </row>
37425 <row topline="true">
37426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37427 \begin_inset Text
37428
37429 \begin_layout Standard
37430
37431 \size footnotesize
37432 '+'
37433 \end_layout
37434
37435 \end_inset
37436 </cell>
37437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37438 \begin_inset Text
37439
37440 \begin_layout Standard
37441
37442 \size footnotesize
37443 IC_LEFT() IC_RIGHT() IC_RESULT()
37444 \end_layout
37445
37446 \end_inset
37447 </cell>
37448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37449 \begin_inset Text
37450
37451 \begin_layout Standard
37452
37453 \size footnotesize
37454 Addition
37455 \end_layout
37456
37457 \end_inset
37458 </cell>
37459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37460 \begin_inset Text
37461
37462 \begin_layout Standard
37463
37464 \size footnotesize
37465 IC_RESULT = IC_LEFT + IC_RIGHT
37466 \end_layout
37467
37468 \end_inset
37469 </cell>
37470 </row>
37471 <row topline="true">
37472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37473 \begin_inset Text
37474
37475 \begin_layout Standard
37476
37477 \size footnotesize
37478 '-'
37479 \end_layout
37480
37481 \end_inset
37482 </cell>
37483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37484 \begin_inset Text
37485
37486 \begin_layout Standard
37487
37488 \size footnotesize
37489 IC_LEFT() IC_RIGHT() IC_RESULT()
37490 \end_layout
37491
37492 \end_inset
37493 </cell>
37494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37495 \begin_inset Text
37496
37497 \begin_layout Standard
37498
37499 \size footnotesize
37500 Subtraction
37501 \end_layout
37502
37503 \end_inset
37504 </cell>
37505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37506 \begin_inset Text
37507
37508 \begin_layout Standard
37509
37510 \size footnotesize
37511 IC_RESULT = IC_LEFT - IC_RIGHT 
37512 \end_layout
37513
37514 \end_inset
37515 </cell>
37516 </row>
37517 <row topline="true">
37518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37519 \begin_inset Text
37520
37521 \begin_layout Standard
37522
37523 \size footnotesize
37524 '*'
37525 \end_layout
37526
37527 \end_inset
37528 </cell>
37529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37530 \begin_inset Text
37531
37532 \begin_layout Standard
37533
37534 \size footnotesize
37535 IC_LEFT() IC_RIGHT() IC_RESULT()
37536 \end_layout
37537
37538 \end_inset
37539 </cell>
37540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37541 \begin_inset Text
37542
37543 \begin_layout Standard
37544
37545 \size footnotesize
37546 Multiplication 
37547 \end_layout
37548
37549 \end_inset
37550 </cell>
37551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37552 \begin_inset Text
37553
37554 \begin_layout Standard
37555
37556 \size footnotesize
37557 IC_RESULT = IC_LEFT * IC_RIGHT;
37558 \end_layout
37559
37560 \end_inset
37561 </cell>
37562 </row>
37563 <row topline="true">
37564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37565 \begin_inset Text
37566
37567 \begin_layout Standard
37568
37569 \size footnotesize
37570 '/'
37571 \end_layout
37572
37573 \end_inset
37574 </cell>
37575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37576 \begin_inset Text
37577
37578 \begin_layout Standard
37579
37580 \size footnotesize
37581 IC_LEFT() IC_RIGHT() IC_RESULT()
37582 \end_layout
37583
37584 \end_inset
37585 </cell>
37586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37587 \begin_inset Text
37588
37589 \begin_layout Standard
37590
37591 \size footnotesize
37592 Division
37593 \end_layout
37594
37595 \end_inset
37596 </cell>
37597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37598 \begin_inset Text
37599
37600 \begin_layout Standard
37601
37602 \size footnotesize
37603 IC_RESULT = IC_LEFT / IC_RIGHT;
37604 \end_layout
37605
37606 \end_inset
37607 </cell>
37608 </row>
37609 <row topline="true">
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37611 \begin_inset Text
37612
37613 \begin_layout Standard
37614
37615 \size footnotesize
37616 '%'
37617 \end_layout
37618
37619 \end_inset
37620 </cell>
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37622 \begin_inset Text
37623
37624 \begin_layout Standard
37625
37626 \size footnotesize
37627 IC_LEFT() IC_RIGHT() IC_RESULT()
37628 \end_layout
37629
37630 \end_inset
37631 </cell>
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37633 \begin_inset Text
37634
37635 \begin_layout Standard
37636
37637 \size footnotesize
37638 Modulus
37639 \end_layout
37640
37641 \end_inset
37642 </cell>
37643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37644 \begin_inset Text
37645
37646 \begin_layout Standard
37647
37648 \size footnotesize
37649 IC_RESULT = IC_LEFT % IC_RIGHT;
37650 \end_layout
37651
37652 \end_inset
37653 </cell>
37654 </row>
37655 <row topline="true">
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37657 \begin_inset Text
37658
37659 \begin_layout Standard
37660
37661 \size footnotesize
37662 '<'
37663 \end_layout
37664
37665 \end_inset
37666 </cell>
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37668 \begin_inset Text
37669
37670 \begin_layout Standard
37671
37672 \size footnotesize
37673 IC_LEFT() IC_RIGHT() IC_RESULT()
37674 \end_layout
37675
37676 \end_inset
37677 </cell>
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37679 \begin_inset Text
37680
37681 \begin_layout Standard
37682
37683 \size footnotesize
37684 Less than
37685 \end_layout
37686
37687 \end_inset
37688 </cell>
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37690 \begin_inset Text
37691
37692 \begin_layout Standard
37693
37694 \size footnotesize
37695 IC_RESULT = IC_LEFT < IC_RIGHT;
37696 \end_layout
37697
37698 \end_inset
37699 </cell>
37700 </row>
37701 <row topline="true">
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37703 \begin_inset Text
37704
37705 \begin_layout Standard
37706
37707 \size footnotesize
37708 '>'
37709 \end_layout
37710
37711 \end_inset
37712 </cell>
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37714 \begin_inset Text
37715
37716 \begin_layout Standard
37717
37718 \size footnotesize
37719 IC_LEFT() IC_RIGHT() IC_RESULT()
37720 \end_layout
37721
37722 \end_inset
37723 </cell>
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37725 \begin_inset Text
37726
37727 \begin_layout Standard
37728
37729 \size footnotesize
37730 Greater than 
37731 \end_layout
37732
37733 \end_inset
37734 </cell>
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37736 \begin_inset Text
37737
37738 \begin_layout Standard
37739
37740 \size footnotesize
37741 IC_RESULT = IC_LEFT > IC_RIGHT;
37742 \end_layout
37743
37744 \end_inset
37745 </cell>
37746 </row>
37747 <row topline="true">
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37749 \begin_inset Text
37750
37751 \begin_layout Standard
37752
37753 \size footnotesize
37754 EQ_OP
37755 \end_layout
37756
37757 \end_inset
37758 </cell>
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37760 \begin_inset Text
37761
37762 \begin_layout Standard
37763
37764 \size footnotesize
37765 IC_LEFT() IC_RIGHT() IC_RESULT()
37766 \end_layout
37767
37768 \end_inset
37769 </cell>
37770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37771 \begin_inset Text
37772
37773 \begin_layout Standard
37774
37775 \size footnotesize
37776 Equal to 
37777 \end_layout
37778
37779 \end_inset
37780 </cell>
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37782 \begin_inset Text
37783
37784 \begin_layout Standard
37785
37786 \size footnotesize
37787 IC_RESULT = IC_LEFT == IC_RIGHT;
37788 \end_layout
37789
37790 \end_inset
37791 </cell>
37792 </row>
37793 <row topline="true">
37794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37795 \begin_inset Text
37796
37797 \begin_layout Standard
37798
37799 \size footnotesize
37800 AND_OP
37801 \end_layout
37802
37803 \end_inset
37804 </cell>
37805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37806 \begin_inset Text
37807
37808 \begin_layout Standard
37809
37810 \size footnotesize
37811 IC_LEFT() IC_RIGHT() IC_RESULT() 
37812 \end_layout
37813
37814 \end_inset
37815 </cell>
37816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37817 \begin_inset Text
37818
37819 \begin_layout Standard
37820
37821 \size footnotesize
37822 Logical and operation
37823 \end_layout
37824
37825 \end_inset
37826 </cell>
37827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37828 \begin_inset Text
37829
37830 \begin_layout Standard
37831
37832 \size footnotesize
37833 IC_RESULT = IC_LEFT && IC_RIGHT; 
37834 \end_layout
37835
37836 \end_inset
37837 </cell>
37838 </row>
37839 <row topline="true">
37840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37841 \begin_inset Text
37842
37843 \begin_layout Standard
37844
37845 \size footnotesize
37846 OR_OP
37847 \end_layout
37848
37849 \end_inset
37850 </cell>
37851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37852 \begin_inset Text
37853
37854 \begin_layout Standard
37855
37856 \size footnotesize
37857 IC_LEFT() IC_RIGHT() IC_RESULT() 
37858 \end_layout
37859
37860 \end_inset
37861 </cell>
37862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37863 \begin_inset Text
37864
37865 \begin_layout Standard
37866
37867 \size footnotesize
37868 Logical or operation 
37869 \end_layout
37870
37871 \end_inset
37872 </cell>
37873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37874 \begin_inset Text
37875
37876 \begin_layout Standard
37877
37878 \size footnotesize
37879 IC_RESULT = IC_LEFT || IC_RIGHT; 
37880 \end_layout
37881
37882 \end_inset
37883 </cell>
37884 </row>
37885 <row topline="true">
37886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37887 \begin_inset Text
37888
37889 \begin_layout Standard
37890
37891 \size footnotesize
37892 '^'
37893 \end_layout
37894
37895 \end_inset
37896 </cell>
37897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37898 \begin_inset Text
37899
37900 \begin_layout Standard
37901
37902 \size footnotesize
37903 IC_LEFT() IC_RIGHT() IC_RESULT() 
37904 \end_layout
37905
37906 \end_inset
37907 </cell>
37908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37909 \begin_inset Text
37910
37911 \begin_layout Standard
37912
37913 \size footnotesize
37914 Exclusive OR
37915 \end_layout
37916
37917 \end_inset
37918 </cell>
37919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37920 \begin_inset Text
37921
37922 \begin_layout Standard
37923
37924 \size footnotesize
37925 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37926 \end_layout
37927
37928 \end_inset
37929 </cell>
37930 </row>
37931 <row topline="true">
37932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37933 \begin_inset Text
37934
37935 \begin_layout Standard
37936
37937 \size footnotesize
37938 '|'
37939 \end_layout
37940
37941 \end_inset
37942 </cell>
37943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37944 \begin_inset Text
37945
37946 \begin_layout Standard
37947
37948 \size footnotesize
37949 IC_LEFT() IC_RIGHT() IC_RESULT() 
37950 \end_layout
37951
37952 \end_inset
37953 </cell>
37954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37955 \begin_inset Text
37956
37957 \begin_layout Standard
37958
37959 \size footnotesize
37960 Bitwise OR 
37961 \end_layout
37962
37963 \end_inset
37964 </cell>
37965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37966 \begin_inset Text
37967
37968 \begin_layout Standard
37969
37970 \size footnotesize
37971 IC_RESULT = IC_LEFT | IC_RIGHT;
37972 \end_layout
37973
37974 \end_inset
37975 </cell>
37976 </row>
37977 <row topline="true">
37978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37979 \begin_inset Text
37980
37981 \begin_layout Standard
37982
37983 \size footnotesize
37984 BITWISEAND
37985 \end_layout
37986
37987 \end_inset
37988 </cell>
37989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37990 \begin_inset Text
37991
37992 \begin_layout Standard
37993
37994 \size footnotesize
37995 IC_LEFT() IC_RIGHT() IC_RESULT()
37996 \end_layout
37997
37998 \end_inset
37999 </cell>
38000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38001 \begin_inset Text
38002
38003 \begin_layout Standard
38004
38005 \size footnotesize
38006 Bitwise AND 
38007 \end_layout
38008
38009 \end_inset
38010 </cell>
38011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38012 \begin_inset Text
38013
38014 \begin_layout Standard
38015
38016 \size footnotesize
38017 IC_RESULT = IC_LEFT & IC_RIGHT;
38018 \end_layout
38019
38020 \end_inset
38021 </cell>
38022 </row>
38023 <row topline="true">
38024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38025 \begin_inset Text
38026
38027 \begin_layout Standard
38028
38029 \size footnotesize
38030 LEFT_OP
38031 \end_layout
38032
38033 \end_inset
38034 </cell>
38035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38036 \begin_inset Text
38037
38038 \begin_layout Standard
38039
38040 \size footnotesize
38041 IC_LEFT() IC_RIGHT() IC_RESULT()
38042 \end_layout
38043
38044 \end_inset
38045 </cell>
38046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38047 \begin_inset Text
38048
38049 \begin_layout Standard
38050
38051 \size footnotesize
38052 Left shift 
38053 \end_layout
38054
38055 \end_inset
38056 </cell>
38057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38058 \begin_inset Text
38059
38060 \begin_layout Standard
38061
38062 \size footnotesize
38063 IC_RESULT = IC_LEFT << IC_RIGHT 
38064 \end_layout
38065
38066 \end_inset
38067 </cell>
38068 </row>
38069 <row topline="true">
38070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38071 \begin_inset Text
38072
38073 \begin_layout Standard
38074
38075 \size footnotesize
38076 RIGHT_OP
38077 \end_layout
38078
38079 \end_inset
38080 </cell>
38081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38082 \begin_inset Text
38083
38084 \begin_layout Standard
38085
38086 \size footnotesize
38087 IC_LEFT() IC_RIGHT() IC_RESULT()
38088 \end_layout
38089
38090 \end_inset
38091 </cell>
38092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38093 \begin_inset Text
38094
38095 \begin_layout Standard
38096
38097 \size footnotesize
38098 Right shift
38099 \end_layout
38100
38101 \end_inset
38102 </cell>
38103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38104 \begin_inset Text
38105
38106 \begin_layout Standard
38107
38108 \size footnotesize
38109 IC_RESULT = IC_LEFT >> IC_RIGHT 
38110 \end_layout
38111
38112 \end_inset
38113 </cell>
38114 </row>
38115 <row topline="true">
38116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38117 \begin_inset Text
38118
38119 \begin_layout Standard
38120
38121 \size footnotesize
38122 GET_VALUE_
38123 \newline
38124 AT_ ADDRESS
38125 \end_layout
38126
38127 \end_inset
38128 </cell>
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38130 \begin_inset Text
38131
38132 \begin_layout Standard
38133
38134 \size footnotesize
38135 IC_LEFT() IC_RESULT()
38136 \end_layout
38137
38138 \end_inset
38139 </cell>
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38141 \begin_inset Text
38142
38143 \begin_layout Standard
38144
38145 \size footnotesize
38146 Indirect fetch 
38147 \end_layout
38148
38149 \end_inset
38150 </cell>
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38152 \begin_inset Text
38153
38154 \begin_layout Standard
38155
38156 \size footnotesize
38157 IC_RESULT = (*IC_LEFT);
38158 \end_layout
38159
38160 \end_inset
38161 </cell>
38162 </row>
38163 <row topline="true">
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38165 \begin_inset Text
38166
38167 \begin_layout Standard
38168
38169 \size footnotesize
38170 POINTER_SET
38171 \end_layout
38172
38173 \end_inset
38174 </cell>
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38176 \begin_inset Text
38177
38178 \begin_layout Standard
38179
38180 \size footnotesize
38181 IC_RIGHT() IC_RESULT() 
38182 \end_layout
38183
38184 \end_inset
38185 </cell>
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38187 \begin_inset Text
38188
38189 \begin_layout Standard
38190
38191 \size footnotesize
38192 Indirect set
38193 \end_layout
38194
38195 \end_inset
38196 </cell>
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38198 \begin_inset Text
38199
38200 \begin_layout Standard
38201
38202 \size footnotesize
38203 (*IC_RESULT) = IC_RIGHT;
38204 \end_layout
38205
38206 \end_inset
38207 </cell>
38208 </row>
38209 <row topline="true">
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38211 \begin_inset Text
38212
38213 \begin_layout Standard
38214
38215 \size footnotesize
38216 '='
38217 \end_layout
38218
38219 \end_inset
38220 </cell>
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38222 \begin_inset Text
38223
38224 \begin_layout Standard
38225
38226 \size footnotesize
38227 IC_RIGHT() IC_RESULT()
38228 \end_layout
38229
38230 \end_inset
38231 </cell>
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38233 \begin_inset Text
38234
38235 \begin_layout Standard
38236
38237 \size footnotesize
38238 Assignment
38239 \end_layout
38240
38241 \end_inset
38242 </cell>
38243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38244 \begin_inset Text
38245
38246 \begin_layout Standard
38247
38248 \size footnotesize
38249 IC_RESULT = IC_RIGHT;
38250 \end_layout
38251
38252 \end_inset
38253 </cell>
38254 </row>
38255 <row topline="true">
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38257 \begin_inset Text
38258
38259 \begin_layout Standard
38260
38261 \size footnotesize
38262 IFX
38263 \end_layout
38264
38265 \end_inset
38266 </cell>
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38268 \begin_inset Text
38269
38270 \begin_layout Standard
38271
38272 \size footnotesize
38273 IC_COND IC_TRUE IC_LABEL
38274 \end_layout
38275
38276 \end_inset
38277 </cell>
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38279 \begin_inset Text
38280
38281 \begin_layout Standard
38282
38283 \size footnotesize
38284 Conditional jump.
38285  If true label is present then jump to true label if condition is true else
38286  jump to false label if condition is false 
38287 \end_layout
38288
38289 \end_inset
38290 </cell>
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38292 \begin_inset Text
38293
38294 \begin_layout Standard
38295
38296 \size footnotesize
38297 if (IC_COND) goto IC_TRUE; 
38298 \newline
38299 \InsetSpace ~
38300 \InsetSpace ~
38301 Or 
38302 \newline
38303 If (!IC_COND) goto IC_FALSE;
38304 \end_layout
38305
38306 \end_inset
38307 </cell>
38308 </row>
38309 <row topline="true">
38310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38311 \begin_inset Text
38312
38313 \begin_layout Standard
38314
38315 \size footnotesize
38316 ADDRESS_OF
38317 \end_layout
38318
38319 \end_inset
38320 </cell>
38321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38322 \begin_inset Text
38323
38324 \begin_layout Standard
38325
38326 \size footnotesize
38327 IC_LEFT() IC_RESULT()
38328 \end_layout
38329
38330 \end_inset
38331 </cell>
38332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38333 \begin_inset Text
38334
38335 \begin_layout Standard
38336
38337 \size footnotesize
38338 Address of 
38339 \end_layout
38340
38341 \end_inset
38342 </cell>
38343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38344 \begin_inset Text
38345
38346 \begin_layout Standard
38347
38348 \size footnotesize
38349 IC_RESULT = &IC_LEFT();
38350 \end_layout
38351
38352 \end_inset
38353 </cell>
38354 </row>
38355 <row topline="true">
38356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38357 \begin_inset Text
38358
38359 \begin_layout Standard
38360
38361 \size footnotesize
38362 JUMPTABLE
38363 \end_layout
38364
38365 \end_inset
38366 </cell>
38367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38368 \begin_inset Text
38369
38370 \begin_layout Standard
38371
38372 \size footnotesize
38373 IC_JTCOND IC_JTLABELS
38374 \end_layout
38375
38376 \end_inset
38377 </cell>
38378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38379 \begin_inset Text
38380
38381 \begin_layout Standard
38382
38383 \size footnotesize
38384 Jump to list of labels depending on the value of JTCOND
38385 \end_layout
38386
38387 \end_inset
38388 </cell>
38389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38390 \begin_inset Text
38391
38392 \begin_layout Standard
38393
38394 \size footnotesize
38395 Switch statement
38396 \end_layout
38397
38398 \end_inset
38399 </cell>
38400 </row>
38401 <row topline="true">
38402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38403 \begin_inset Text
38404
38405 \begin_layout Standard
38406
38407 \size footnotesize
38408 CAST
38409 \end_layout
38410
38411 \end_inset
38412 </cell>
38413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38414 \begin_inset Text
38415
38416 \begin_layout Standard
38417
38418 \size footnotesize
38419 IC_RIGHT() IC_LEFT() IC_RESULT()
38420 \end_layout
38421
38422 \end_inset
38423 </cell>
38424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38425 \begin_inset Text
38426
38427 \begin_layout Standard
38428
38429 \size footnotesize
38430 Cast types 
38431 \end_layout
38432
38433 \end_inset
38434 </cell>
38435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38436 \begin_inset Text
38437
38438 \begin_layout Standard
38439
38440 \size footnotesize
38441 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38442 \end_layout
38443
38444 \end_inset
38445 </cell>
38446 </row>
38447 <row topline="true">
38448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38449 \begin_inset Text
38450
38451 \begin_layout Standard
38452
38453 \size footnotesize
38454 SEND
38455 \end_layout
38456
38457 \end_inset
38458 </cell>
38459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38460 \begin_inset Text
38461
38462 \begin_layout Standard
38463
38464 \size footnotesize
38465 IC_LEFT()
38466 \end_layout
38467
38468 \end_inset
38469 </cell>
38470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38471 \begin_inset Text
38472
38473 \begin_layout Standard
38474
38475 \size footnotesize
38476 This is used for passing parameters in registers; 
38477 \newline
38478 move IC_LEFT to the next
38479  available parameter register.
38480 \end_layout
38481
38482 \end_inset
38483 </cell>
38484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38485 \begin_inset Text
38486
38487 \begin_layout Standard
38488
38489 \size footnotesize
38490 None
38491 \end_layout
38492
38493 \end_inset
38494 </cell>
38495 </row>
38496 <row topline="true">
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38498 \begin_inset Text
38499
38500 \begin_layout Standard
38501
38502 \size footnotesize
38503 RECV
38504 \end_layout
38505
38506 \end_inset
38507 </cell>
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38509 \begin_inset Text
38510
38511 \begin_layout Standard
38512
38513 \size footnotesize
38514 IC_RESULT()
38515 \end_layout
38516
38517 \end_inset
38518 </cell>
38519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38520 \begin_inset Text
38521
38522 \begin_layout Standard
38523
38524 \size footnotesize
38525 This is used for receiving parameters passed in registers;
38526 \newline
38527 Move the values
38528  in the next parameter register to IC_RESULT 
38529 \end_layout
38530
38531 \end_inset
38532 </cell>
38533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38534 \begin_inset Text
38535
38536 \begin_layout Standard
38537
38538 \size footnotesize
38539 None
38540 \end_layout
38541
38542 \end_inset
38543 </cell>
38544 </row>
38545 <row topline="true" bottomline="true">
38546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38547 \begin_inset Text
38548
38549 \begin_layout Standard
38550
38551 \shape slanted
38552 \size footnotesize
38553 (some more have been added)
38554 \end_layout
38555
38556 \end_inset
38557 </cell>
38558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38559 \begin_inset Text
38560
38561 \begin_layout Standard
38562
38563 \end_layout
38564
38565 \end_inset
38566 </cell>
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38568 \begin_inset Text
38569
38570 \begin_layout Standard
38571
38572 \end_layout
38573
38574 \end_inset
38575 </cell>
38576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38577 \begin_inset Text
38578
38579 \begin_layout Standard
38580
38581 \shape slanted
38582 \size footnotesize
38583 see f.e.
38584  
38585 \family typewriter
38586 gen51Code()
38587 \family default
38588  in 
38589 \family typewriter
38590 src/mcs51/gen.c
38591 \end_layout
38592
38593 \end_inset
38594 </cell>
38595 </row>
38596 </lyxtabular>
38597
38598 \end_inset
38599
38600
38601 \end_layout
38602
38603 \begin_layout Standard
38604 \begin_inset Note Note
38605 status collapsed
38606
38607 \begin_layout Standard
38608 In the original article Figure II was announced to be downloadable on 
38609 \shape italic
38610 Circuit Cellar
38611 \shape default
38612 's web site.
38613  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38614 \end_layout
38615
38616 \end_inset
38617
38618
38619 \end_layout
38620
38621 \begin_layout Paragraph*
38622 ICode Example
38623 \begin_inset LatexCommand \index{iCode}
38624
38625 \end_inset
38626
38627
38628 \end_layout
38629
38630 \begin_layout Standard
38631 This section shows some details of iCode.
38632  The example C code does not do anything useful; it is used as an example
38633  to illustrate the intermediate code generated by the compiler.
38634 \end_layout
38635
38636 \begin_layout Verse
38637
38638 \family typewriter
38639 1.\InsetSpace ~
38640 xdata int * p;
38641 \newline
38642 2.\InsetSpace ~
38643 int gint;
38644 \newline
38645 3.\InsetSpace ~
38646 /* This function does nothing useful.
38647  It is used
38648 \newline
38649 4.\InsetSpace ~
38650 \InsetSpace ~
38651 \InsetSpace ~
38652 \InsetSpace ~
38653 for the purpose of explaining iCode */
38654 \newline
38655 5.\InsetSpace ~
38656 short function (data
38657  int *x)
38658 \newline
38659 6.\InsetSpace ~
38660 {
38661 \newline
38662 7.\InsetSpace ~
38663 \InsetSpace ~
38664 \InsetSpace ~
38665 short i=10; \InsetSpace ~
38666 \InsetSpace ~
38667 /* dead initialization eliminated */
38668 \newline
38669 8.\InsetSpace ~
38670 \InsetSpace ~
38671 \InsetSpace ~
38672 short sum=10;
38673  /* dead initialization eliminated */
38674 \newline
38675 9.\InsetSpace ~
38676 \InsetSpace ~
38677 \InsetSpace ~
38678 short mul;
38679 \newline
38680 10.\InsetSpace ~
38681 \InsetSpace ~
38682 int j ;
38683 \newline
38684 11.\InsetSpace ~
38685 \InsetSpace ~
38686 while (*x) *x++
38687  = *p++; 
38688 \newline
38689 12.\InsetSpace ~
38690 \InsetSpace ~
38691 \InsetSpace ~
38692 \InsetSpace ~
38693 sum = 0 ; 
38694 \newline
38695 13.\InsetSpace ~
38696 \InsetSpace ~
38697 mul = 0;
38698 \newline
38699 14.\InsetSpace ~
38700 \InsetSpace ~
38701 /* compiler detects i,j to be induction
38702  variables */
38703 \newline
38704 15.\InsetSpace ~
38705 \InsetSpace ~
38706 for (i = 0, j = 10 ; i < 10 ; i++, j
38707 \family default
38708 -
38709 \begin_inset ERT
38710 status collapsed
38711
38712 \begin_layout Standard
38713
38714
38715 \backslash
38716 /
38717 \end_layout
38718
38719 \end_inset
38720
38721 -
38722 \family typewriter
38723 ) {
38724 \newline
38725 16.\InsetSpace ~
38726 \InsetSpace ~
38727 \InsetSpace ~
38728 \InsetSpace ~
38729 sum += i;
38730 \newline
38731 17.\InsetSpace ~
38732 \InsetSpace ~
38733 \InsetSpace ~
38734 \InsetSpace ~
38735 mul += i * 3; \InsetSpace ~
38736 \InsetSpace ~
38737 /* this multiplication remains */
38738 \newline
38739 18.\InsetSpace ~
38740 \InsetSpace ~
38741 \InsetSpace ~
38742 \InsetSpace ~
38743 gint +=
38744  j * 3;\InsetSpace ~
38745 \InsetSpace ~
38746 /* this multiplication changed to addition */
38747 \newline
38748 19.\InsetSpace ~
38749 \InsetSpace ~
38750 }
38751 \newline
38752 20.\InsetSpace ~
38753 \InsetSpace ~
38754 return sum+mul;
38755 \newline
38756 21.\InsetSpace ~
38757 }
38758 \end_layout
38759
38760 \begin_layout Standard
38761 In addition to the operands each iCode contains information about the filename
38762  and line it corresponds to in the source file.
38763  The first field in the listing should be interpreted as follows:
38764 \newline
38765
38766 \shape italic
38767 \size footnotesize
38768 Filename(linenumber: iCode Execution sequence number : ICode hash table
38769  key : loop depth of the iCode).
38770 \shape default
38771 \size default
38772
38773 \newline
38774 Then follows the human readable form of the ICode operation.
38775  Each operand of this triplet form can be of three basic types a) compiler
38776  generated temporary b) user defined variable c) a constant value.
38777  Note that local variables and parameters are replaced by compiler generated
38778  temporaries.
38779  Live ranges
38780 \begin_inset LatexCommand \index{Live range analysis}
38781
38782 \end_inset
38783
38784  are computed only for temporaries (i.e.
38785  live ranges are not computed for global variables).
38786  Registers
38787 \begin_inset LatexCommand \index{Register allocation}
38788
38789 \end_inset
38790
38791  are allocated for temporaries only.
38792  Operands are formatted in the following manner:
38793 \newline
38794
38795 \shape italic
38796 \size footnotesize
38797 Operand Name [lr live-from : live-to ] { type information } [ registers
38798  allocated ].
38799 \shape default
38800 \size default
38801
38802 \newline
38803 As mentioned earlier the live ranges are computed in terms of the execution
38804  sequence number of the iCodes, for example 
38805 \newline
38806 the iTemp0 is live from (i.e.
38807  first defined in iCode with execution sequence number 3, and is last used
38808  in the iCode with sequence number 5).
38809  For induction variables such as iTemp21 the live range computation extends
38810  the lifetime from the start to the end of the loop.
38811 \newline
38812 The register allocator
38813  used the live range information to allocate registers, the same registers
38814  may be used for different temporaries if their live ranges do not overlap,
38815  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38816  ranges do not overlap.
38817  In addition the allocator also takes into consideration the type and usage
38818  of a temporary, for example itemp6 is a pointer to near space and is used
38819  as to fetch data from (i.e.
38820  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38821  Some short lived temporaries are allocated to special registers which have
38822  meaning to the code generator e.g.
38823  iTemp13 is allocated to a pseudo register CC which tells the back end that
38824  the temporary is used only for a conditional jump the code generation makes
38825  use of this information to optimize a compare and jump ICode.
38826 \newline
38827 There are several
38828  loop optimizations
38829 \begin_inset LatexCommand \index{Loop optimization}
38830
38831 \end_inset
38832
38833  performed by the compiler.
38834  It can detect induction variables iTemp21(i) and iTemp23(j).
38835  Also note the compiler does selective strength reduction
38836 \begin_inset LatexCommand \index{Strength reduction}
38837
38838 \end_inset
38839
38840 , i.e.
38841  the multiplication of an induction variable in line 18 (gint = j * 3) is
38842  changed to addition, a new temporary iTemp17 is allocated and assigned
38843  a initial value, a constant 3 is then added for each iteration of the loop.
38844  The compiler does not change the multiplication
38845 \begin_inset LatexCommand \index{Multiplication}
38846
38847 \end_inset
38848
38849  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38850 \newline
38851
38852 Note the dead code elimination
38853 \begin_inset LatexCommand \index{Dead-code elimination}
38854
38855 \end_inset
38856
38857  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38858  respectively.
38859 \newline
38860
38861 \end_layout
38862
38863 \begin_layout Standard
38864
38865 \size footnotesize
38866 Sample.c (5:1:0:0) _entry($9) :
38867 \end_layout
38868
38869 \begin_layout Standard
38870
38871 \size footnotesize
38872 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38873 \end_layout
38874
38875 \begin_layout Standard
38876
38877 \size footnotesize
38878 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38879 \end_layout
38880
38881 \begin_layout Standard
38882
38883 \size footnotesize
38884 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38885 \end_layout
38886
38887 \begin_layout Standard
38888
38889 \size footnotesize
38890 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38891  * int}[r2]
38892 \end_layout
38893
38894 \begin_layout Standard
38895
38896 \size footnotesize
38897 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38898 \end_layout
38899
38900 \begin_layout Standard
38901
38902 \size footnotesize
38903 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38904  int}[r0]]
38905 \end_layout
38906
38907 \begin_layout Standard
38908
38909 \size footnotesize
38910 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38911 \end_layout
38912
38913 \begin_layout Standard
38914
38915 \size footnotesize
38916 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38917  * int}
38918 \end_layout
38919
38920 \begin_layout Standard
38921
38922 \size footnotesize
38923 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38924  {short}
38925 \end_layout
38926
38927 \begin_layout Standard
38928
38929 \size footnotesize
38930 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38931  * int}[DPTR]]
38932 \end_layout
38933
38934 \begin_layout Standard
38935
38936 \size footnotesize
38937 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38938 }[r2 r3]
38939 \end_layout
38940
38941 \begin_layout Standard
38942
38943 \size footnotesize
38944 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38945  * int}[r0] + 0x2 {short}
38946 \end_layout
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38952 \end_layout
38953
38954 \begin_layout Standard
38955
38956 \size footnotesize
38957 Sample.c(11:17:21:0)_whilebreak_0($3) :
38958 \end_layout
38959
38960 \begin_layout Standard
38961
38962 \size footnotesize
38963 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38964 \end_layout
38965
38966 \begin_layout Standard
38967
38968 \size footnotesize
38969 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38970 \end_layout
38971
38972 \begin_layout Standard
38973
38974 \size footnotesize
38975 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38976 \end_layout
38977
38978 \begin_layout Standard
38979
38980 \size footnotesize
38981 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38982 \end_layout
38983
38984 \begin_layout Standard
38985
38986 \size footnotesize
38987 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38988 \end_layout
38989
38990 \begin_layout Standard
38991
38992 \size footnotesize
38993 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38994 \end_layout
38995
38996 \begin_layout Standard
38997
38998 \size footnotesize
38999 Sample.c(15:24:26:1)_forcond_0($4) :
39000 \end_layout
39001
39002 \begin_layout Standard
39003
39004 \size footnotesize
39005 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39006  < 0xa {short}
39007 \end_layout
39008
39009 \begin_layout Standard
39010
39011 \size footnotesize
39012 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39013 \end_layout
39014
39015 \begin_layout Standard
39016
39017 \size footnotesize
39018 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39019  + ITemp21 [lr21:38]{short}[r4]
39020 \end_layout
39021
39022 \begin_layout Standard
39023
39024 \size footnotesize
39025 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39026  * 0x3 {short}
39027 \end_layout
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39033  + iTemp15 [lr29:30]{short}[r1]
39034 \end_layout
39035
39036 \begin_layout Standard
39037
39038 \size footnotesize
39039 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39040  r0]- 0x3 {short}
39041 \end_layout
39042
39043 \begin_layout Standard
39044
39045 \size footnotesize
39046 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39047 int}[r7 r0]
39048 \end_layout
39049
39050 \begin_layout Standard
39051
39052 \size footnotesize
39053 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39054  + 0x1 {short}
39055 \end_layout
39056
39057 \begin_layout Standard
39058
39059 \size footnotesize
39060 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39061  r6]- 0x1 {short}
39062 \end_layout
39063
39064 \begin_layout Standard
39065
39066 \size footnotesize
39067 Sample.c(19:38:47:1) goto _forcond_0($4)
39068 \end_layout
39069
39070 \begin_layout Standard
39071
39072 \size footnotesize
39073 Sample.c(19:39:48:0)_forbreak_0($7) :
39074 \end_layout
39075
39076 \begin_layout Standard
39077
39078 \size footnotesize
39079 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39080  + ITemp11 [lr19:40]{short}[r3]
39081 \end_layout
39082
39083 \begin_layout Standard
39084
39085 \size footnotesize
39086 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39087 \end_layout
39088
39089 \begin_layout Standard
39090
39091 \size footnotesize
39092 Sample.c(20:42:51:0)_return($8) :
39093 \end_layout
39094
39095 \begin_layout Standard
39096
39097 \size footnotesize
39098 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39099 \size default
39100
39101 \newline
39102
39103 \newline
39104 Finally the code generated for this function:
39105 \newline
39106
39107 \end_layout
39108
39109 \begin_layout Standard
39110
39111 \size footnotesize
39112 .area DSEG (DATA)
39113 \end_layout
39114
39115 \begin_layout Standard
39116
39117 \size footnotesize
39118 _p::
39119 \end_layout
39120
39121 \begin_layout Standard
39122
39123 \size footnotesize
39124 \InsetSpace ~
39125 \InsetSpace ~
39126 .ds 2
39127 \end_layout
39128
39129 \begin_layout Standard
39130
39131 \size footnotesize
39132 _gint::
39133 \end_layout
39134
39135 \begin_layout Standard
39136
39137 \size footnotesize
39138 \InsetSpace ~
39139 \InsetSpace ~
39140 .ds 2
39141 \end_layout
39142
39143 \begin_layout Standard
39144
39145 \size footnotesize
39146 ; sample.c 5
39147 \end_layout
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 ; ----------------------------------------------
39153 \end_layout
39154
39155 \begin_layout Standard
39156
39157 \size footnotesize
39158 ; function function
39159 \end_layout
39160
39161 \begin_layout Standard
39162
39163 \size footnotesize
39164 ; ----------------------------------------------
39165 \end_layout
39166
39167 \begin_layout Standard
39168
39169 \size footnotesize
39170 _function:
39171 \end_layout
39172
39173 \begin_layout Standard
39174
39175 \size footnotesize
39176 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39177 \end_layout
39178
39179 \begin_layout Standard
39180
39181 \size footnotesize
39182 \InsetSpace ~
39183 \InsetSpace ~
39184 mov r2,dpl
39185 \end_layout
39186
39187 \begin_layout Standard
39188
39189 \size footnotesize
39190 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39191 \end_layout
39192
39193 \begin_layout Standard
39194
39195 \size footnotesize
39196 \InsetSpace ~
39197 \InsetSpace ~
39198 mov ar0,r2
39199 \end_layout
39200
39201 \begin_layout Standard
39202
39203 \size footnotesize
39204 ;_whilecontinue_0($1) :
39205 \end_layout
39206
39207 \begin_layout Standard
39208
39209 \size footnotesize
39210 00101$:
39211 \end_layout
39212
39213 \begin_layout Standard
39214
39215 \size footnotesize
39216 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39217 \end_layout
39218
39219 \begin_layout Standard
39220
39221 \size footnotesize
39222 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39223 \end_layout
39224
39225 \begin_layout Standard
39226
39227 \size footnotesize
39228 \InsetSpace ~
39229 \InsetSpace ~
39230 mov ar2,@r0
39231 \end_layout
39232
39233 \begin_layout Standard
39234
39235 \size footnotesize
39236 \InsetSpace ~
39237 \InsetSpace ~
39238 inc r0
39239 \end_layout
39240
39241 \begin_layout Standard
39242
39243 \size footnotesize
39244 \InsetSpace ~
39245 \InsetSpace ~
39246 mov ar3,@r0
39247 \end_layout
39248
39249 \begin_layout Standard
39250
39251 \size footnotesize
39252 \InsetSpace ~
39253 \InsetSpace ~
39254 dec r0
39255 \end_layout
39256
39257 \begin_layout Standard
39258
39259 \size footnotesize
39260 \InsetSpace ~
39261 \InsetSpace ~
39262 mov a,r2
39263 \end_layout
39264
39265 \begin_layout Standard
39266
39267 \size footnotesize
39268 \InsetSpace ~
39269 \InsetSpace ~
39270 orl a,r3
39271 \end_layout
39272
39273 \begin_layout Standard
39274
39275 \size footnotesize
39276 \InsetSpace ~
39277 \InsetSpace ~
39278 jz 00103$
39279 \end_layout
39280
39281 \begin_layout Standard
39282
39283 \size footnotesize
39284 00114$:
39285 \end_layout
39286
39287 \begin_layout Standard
39288
39289 \size footnotesize
39290 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39291 \end_layout
39292
39293 \begin_layout Standard
39294
39295 \size footnotesize
39296 \InsetSpace ~
39297 \InsetSpace ~
39298 mov dpl,_p
39299 \end_layout
39300
39301 \begin_layout Standard
39302
39303 \size footnotesize
39304 \InsetSpace ~
39305 \InsetSpace ~
39306 mov dph,(_p + 1)
39307 \end_layout
39308
39309 \begin_layout Standard
39310
39311 \size footnotesize
39312 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39313 \end_layout
39314
39315 \begin_layout Standard
39316
39317 \size footnotesize
39318 \InsetSpace ~
39319 \InsetSpace ~
39320 mov a,#0x02
39321 \end_layout
39322
39323 \begin_layout Standard
39324
39325 \size footnotesize
39326 \InsetSpace ~
39327 \InsetSpace ~
39328 add a,_p
39329 \end_layout
39330
39331 \begin_layout Standard
39332
39333 \size footnotesize
39334 \InsetSpace ~
39335 \InsetSpace ~
39336 mov _p,a
39337 \end_layout
39338
39339 \begin_layout Standard
39340
39341 \size footnotesize
39342 \InsetSpace ~
39343 \InsetSpace ~
39344 clr a
39345 \end_layout
39346
39347 \begin_layout Standard
39348
39349 \size footnotesize
39350 \InsetSpace ~
39351 \InsetSpace ~
39352 addc a,(_p + 1)
39353 \end_layout
39354
39355 \begin_layout Standard
39356
39357 \size footnotesize
39358 \InsetSpace ~
39359 \InsetSpace ~
39360 mov (_p + 1),a
39361 \end_layout
39362
39363 \begin_layout Standard
39364
39365 \size footnotesize
39366 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39367 \end_layout
39368
39369 \begin_layout Standard
39370
39371 \size footnotesize
39372 \InsetSpace ~
39373 \InsetSpace ~
39374 movx a,@dptr
39375 \end_layout
39376
39377 \begin_layout Standard
39378
39379 \size footnotesize
39380 \InsetSpace ~
39381 \InsetSpace ~
39382 mov r2,a
39383 \end_layout
39384
39385 \begin_layout Standard
39386
39387 \size footnotesize
39388 \InsetSpace ~
39389 \InsetSpace ~
39390 inc dptr
39391 \end_layout
39392
39393 \begin_layout Standard
39394
39395 \size footnotesize
39396 \InsetSpace ~
39397 \InsetSpace ~
39398 movx a,@dptr
39399 \end_layout
39400
39401 \begin_layout Standard
39402
39403 \size footnotesize
39404 \InsetSpace ~
39405 \InsetSpace ~
39406 mov r3,a
39407 \end_layout
39408
39409 \begin_layout Standard
39410
39411 \size footnotesize
39412 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39413 \end_layout
39414
39415 \begin_layout Standard
39416
39417 \size footnotesize
39418 \InsetSpace ~
39419 \InsetSpace ~
39420 mov @r0,ar2
39421 \end_layout
39422
39423 \begin_layout Standard
39424
39425 \size footnotesize
39426 \InsetSpace ~
39427 \InsetSpace ~
39428 inc r0
39429 \end_layout
39430
39431 \begin_layout Standard
39432
39433 \size footnotesize
39434 \InsetSpace ~
39435 \InsetSpace ~
39436 mov @r0,ar3
39437 \end_layout
39438
39439 \begin_layout Standard
39440
39441 \size footnotesize
39442 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39443 \end_layout
39444
39445 \begin_layout Standard
39446
39447 \size footnotesize
39448 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39449 \end_layout
39450
39451 \begin_layout Standard
39452
39453 \size footnotesize
39454 ; 0x2 {short}
39455 \end_layout
39456
39457 \begin_layout Standard
39458
39459 \size footnotesize
39460 \InsetSpace ~
39461 \InsetSpace ~
39462 inc r0
39463 \end_layout
39464
39465 \begin_layout Standard
39466
39467 \size footnotesize
39468 ; goto _whilecontinue_0($1)
39469 \end_layout
39470
39471 \begin_layout Standard
39472
39473 \size footnotesize
39474 \InsetSpace ~
39475 \InsetSpace ~
39476 sjmp 00101$
39477 \end_layout
39478
39479 \begin_layout Standard
39480
39481 \size footnotesize
39482 ; _whilebreak_0($3) :
39483 \end_layout
39484
39485 \begin_layout Standard
39486
39487 \size footnotesize
39488 00103$:
39489 \end_layout
39490
39491 \begin_layout Standard
39492
39493 \size footnotesize
39494 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39495 \end_layout
39496
39497 \begin_layout Standard
39498
39499 \size footnotesize
39500 \InsetSpace ~
39501 \InsetSpace ~
39502 mov r2,#0x00
39503 \end_layout
39504
39505 \begin_layout Standard
39506
39507 \size footnotesize
39508 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39509 \end_layout
39510
39511 \begin_layout Standard
39512
39513 \size footnotesize
39514 \InsetSpace ~
39515 \InsetSpace ~
39516 mov r3,#0x00
39517 \end_layout
39518
39519 \begin_layout Standard
39520
39521 \size footnotesize
39522 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39523 \end_layout
39524
39525 \begin_layout Standard
39526
39527 \size footnotesize
39528 \InsetSpace ~
39529 \InsetSpace ~
39530 mov r4,#0x00
39531 \end_layout
39532
39533 \begin_layout Standard
39534
39535 \size footnotesize
39536 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39537 \end_layout
39538
39539 \begin_layout Standard
39540
39541 \size footnotesize
39542 \InsetSpace ~
39543 \InsetSpace ~
39544 mov r5,#0x0A
39545 \end_layout
39546
39547 \begin_layout Standard
39548
39549 \size footnotesize
39550 \InsetSpace ~
39551 \InsetSpace ~
39552 mov r6,#0x00
39553 \end_layout
39554
39555 \begin_layout Standard
39556
39557 \size footnotesize
39558 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39559 \end_layout
39560
39561 \begin_layout Standard
39562
39563 \size footnotesize
39564 \InsetSpace ~
39565 \InsetSpace ~
39566 mov r7,#0x1E
39567 \end_layout
39568
39569 \begin_layout Standard
39570
39571 \size footnotesize
39572 \InsetSpace ~
39573 \InsetSpace ~
39574 mov r0,#0x00
39575 \end_layout
39576
39577 \begin_layout Standard
39578
39579 \size footnotesize
39580 ; _forcond_0($4) :
39581 \end_layout
39582
39583 \begin_layout Standard
39584
39585 \size footnotesize
39586 00104$:
39587 \end_layout
39588
39589 \begin_layout Standard
39590
39591 \size footnotesize
39592 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39593 \end_layout
39594
39595 \begin_layout Standard
39596
39597 \size footnotesize
39598 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39599 \end_layout
39600
39601 \begin_layout Standard
39602
39603 \size footnotesize
39604 \InsetSpace ~
39605 \InsetSpace ~
39606 clr c
39607 \end_layout
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 \InsetSpace ~
39613 \InsetSpace ~
39614 mov a,r4
39615 \end_layout
39616
39617 \begin_layout Standard
39618
39619 \size footnotesize
39620 \InsetSpace ~
39621 \InsetSpace ~
39622 xrl a,#0x80
39623 \end_layout
39624
39625 \begin_layout Standard
39626
39627 \size footnotesize
39628 \InsetSpace ~
39629 \InsetSpace ~
39630 subb a,#0x8a
39631 \end_layout
39632
39633 \begin_layout Standard
39634
39635 \size footnotesize
39636 \InsetSpace ~
39637 \InsetSpace ~
39638 jnc 00107$
39639 \end_layout
39640
39641 \begin_layout Standard
39642
39643 \size footnotesize
39644 00115$:
39645 \end_layout
39646
39647 \begin_layout Standard
39648
39649 \size footnotesize
39650 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39651 \end_layout
39652
39653 \begin_layout Standard
39654
39655 \size footnotesize
39656 ; iTemp21 [lr21:38]{short}[r4]
39657 \end_layout
39658
39659 \begin_layout Standard
39660
39661 \size footnotesize
39662 \InsetSpace ~
39663 \InsetSpace ~
39664 mov a,r4
39665 \end_layout
39666
39667 \begin_layout Standard
39668
39669 \size footnotesize
39670 \InsetSpace ~
39671 \InsetSpace ~
39672 add a,r2
39673 \end_layout
39674
39675 \begin_layout Standard
39676
39677 \size footnotesize
39678 \InsetSpace ~
39679 \InsetSpace ~
39680 mov r2,a
39681 \end_layout
39682
39683 \begin_layout Standard
39684
39685 \size footnotesize
39686 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39687 \end_layout
39688
39689 \begin_layout Standard
39690
39691 \size footnotesize
39692 \InsetSpace ~
39693 \InsetSpace ~
39694 mov b,#0x03
39695 \end_layout
39696
39697 \begin_layout Standard
39698
39699 \size footnotesize
39700 \InsetSpace ~
39701 \InsetSpace ~
39702 mov a,r4
39703 \end_layout
39704
39705 \begin_layout Standard
39706
39707 \size footnotesize
39708 \InsetSpace ~
39709 \InsetSpace ~
39710 mul ab
39711 \end_layout
39712
39713 \begin_layout Standard
39714
39715 \size footnotesize
39716 \InsetSpace ~
39717 \InsetSpace ~
39718 mov r1,a
39719 \end_layout
39720
39721 \begin_layout Standard
39722
39723 \size footnotesize
39724 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39725 \end_layout
39726
39727 \begin_layout Standard
39728
39729 \size footnotesize
39730 ; iTemp15 [lr29:30]{short}[r1]
39731 \end_layout
39732
39733 \begin_layout Standard
39734
39735 \size footnotesize
39736 \InsetSpace ~
39737 \InsetSpace ~
39738 add a,r3
39739 \end_layout
39740
39741 \begin_layout Standard
39742
39743 \size footnotesize
39744 \InsetSpace ~
39745 \InsetSpace ~
39746 mov r3,a
39747 \end_layout
39748
39749 \begin_layout Standard
39750
39751 \size footnotesize
39752 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39753 \end_layout
39754
39755 \begin_layout Standard
39756
39757 \size footnotesize
39758 \InsetSpace ~
39759 \InsetSpace ~
39760 mov a,r7
39761 \end_layout
39762
39763 \begin_layout Standard
39764
39765 \size footnotesize
39766 \InsetSpace ~
39767 \InsetSpace ~
39768 add a,#0xfd
39769 \end_layout
39770
39771 \begin_layout Standard
39772
39773 \size footnotesize
39774 \InsetSpace ~
39775 \InsetSpace ~
39776 mov r7,a
39777 \end_layout
39778
39779 \begin_layout Standard
39780
39781 \size footnotesize
39782 \InsetSpace ~
39783 \InsetSpace ~
39784 mov a,r0
39785 \end_layout
39786
39787 \begin_layout Standard
39788
39789 \size footnotesize
39790 \InsetSpace ~
39791 \InsetSpace ~
39792 addc a,#0xff
39793 \end_layout
39794
39795 \begin_layout Standard
39796
39797 \size footnotesize
39798 \InsetSpace ~
39799 \InsetSpace ~
39800 mov r0,a
39801 \end_layout
39802
39803 \begin_layout Standard
39804
39805 \size footnotesize
39806 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39807 \end_layout
39808
39809 \begin_layout Standard
39810
39811 \size footnotesize
39812 \InsetSpace ~
39813 \InsetSpace ~
39814 mov a,r7
39815 \end_layout
39816
39817 \begin_layout Standard
39818
39819 \size footnotesize
39820 \InsetSpace ~
39821 \InsetSpace ~
39822 add a,_gint
39823 \end_layout
39824
39825 \begin_layout Standard
39826
39827 \size footnotesize
39828 \InsetSpace ~
39829 \InsetSpace ~
39830 mov _gint,a
39831 \end_layout
39832
39833 \begin_layout Standard
39834
39835 \size footnotesize
39836 \InsetSpace ~
39837 \InsetSpace ~
39838 mov a,r0
39839 \end_layout
39840
39841 \begin_layout Standard
39842
39843 \size footnotesize
39844 \InsetSpace ~
39845 \InsetSpace ~
39846 addc a,(_gint + 1)
39847 \end_layout
39848
39849 \begin_layout Standard
39850
39851 \size footnotesize
39852 \InsetSpace ~
39853 \InsetSpace ~
39854 mov (_gint + 1),a
39855 \end_layout
39856
39857 \begin_layout Standard
39858
39859 \size footnotesize
39860 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39861 \end_layout
39862
39863 \begin_layout Standard
39864
39865 \size footnotesize
39866 \InsetSpace ~
39867 \InsetSpace ~
39868 inc r4
39869 \end_layout
39870
39871 \begin_layout Standard
39872
39873 \size footnotesize
39874 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39875 \end_layout
39876
39877 \begin_layout Standard
39878
39879 \size footnotesize
39880 \InsetSpace ~
39881 \InsetSpace ~
39882 dec r5
39883 \end_layout
39884
39885 \begin_layout Standard
39886
39887 \size footnotesize
39888 \InsetSpace ~
39889 \InsetSpace ~
39890 cjne r5,#0xff,00104$
39891 \end_layout
39892
39893 \begin_layout Standard
39894
39895 \size footnotesize
39896 \InsetSpace ~
39897 \InsetSpace ~
39898 dec r6
39899 \end_layout
39900
39901 \begin_layout Standard
39902
39903 \size footnotesize
39904 ; goto _forcond_0($4)
39905 \end_layout
39906
39907 \begin_layout Standard
39908
39909 \size footnotesize
39910 \InsetSpace ~
39911 \InsetSpace ~
39912 sjmp 00104$
39913 \end_layout
39914
39915 \begin_layout Standard
39916
39917 \size footnotesize
39918 ; _forbreak_0($7) :
39919 \end_layout
39920
39921 \begin_layout Standard
39922
39923 \size footnotesize
39924 00107$:
39925 \end_layout
39926
39927 \begin_layout Standard
39928
39929 \size footnotesize
39930 ; ret iTemp24 [lr40:41]{short}
39931 \end_layout
39932
39933 \begin_layout Standard
39934
39935 \size footnotesize
39936 \InsetSpace ~
39937 \InsetSpace ~
39938 mov a,r3
39939 \end_layout
39940
39941 \begin_layout Standard
39942
39943 \size footnotesize
39944 \InsetSpace ~
39945 \InsetSpace ~
39946 add a,r2
39947 \end_layout
39948
39949 \begin_layout Standard
39950
39951 \size footnotesize
39952 \InsetSpace ~
39953 \InsetSpace ~
39954 mov dpl,a
39955 \end_layout
39956
39957 \begin_layout Standard
39958
39959 \size footnotesize
39960 ; _return($8) :
39961 \end_layout
39962
39963 \begin_layout Standard
39964
39965 \size footnotesize
39966 00108$:
39967 \end_layout
39968
39969 \begin_layout Standard
39970
39971 \size footnotesize
39972 \InsetSpace ~
39973 \InsetSpace ~
39974 ret
39975 \newline
39976
39977 \end_layout
39978
39979 \begin_layout Section
39980 A few words about basic block successors, predecessors and dominators
39981 \end_layout
39982
39983 \begin_layout Standard
39984 Successors are basic blocks
39985 \begin_inset LatexCommand \index{Basic blocks}
39986
39987 \end_inset
39988
39989  that might execute after this basic block.
39990 \newline
39991 Predecessors are basic blocks
39992  that might execute before reaching this basic block.
39993 \newline
39994 Dominators are basic
39995  blocks that WILL execute before reaching this basic block.
39996 \newline
39997
39998 \end_layout
39999
40000 \begin_layout Standard
40001 [basic block 1]
40002 \end_layout
40003
40004 \begin_layout Standard
40005 if (something)
40006 \end_layout
40007
40008 \begin_layout Standard
40009 \InsetSpace ~
40010 \InsetSpace ~
40011 \InsetSpace ~
40012 \InsetSpace ~
40013 [basic block 2]
40014 \end_layout
40015
40016 \begin_layout Standard
40017 else
40018 \end_layout
40019
40020 \begin_layout Standard
40021 \InsetSpace ~
40022 \InsetSpace ~
40023 \InsetSpace ~
40024 \InsetSpace ~
40025 [basic block 3]
40026 \end_layout
40027
40028 \begin_layout Standard
40029 [basic block 4]
40030 \newline
40031
40032 \end_layout
40033
40034 \begin_layout Standard
40035 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40036 \end_layout
40037
40038 \begin_layout Standard
40039 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40040 \end_layout
40041
40042 \begin_layout Standard
40043 c) domVect of [BB4] = BB1 ...
40044  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40045  was executed.
40046 \end_layout
40047
40048 \begin_layout Chapter
40049 Acknowledgments
40050 \end_layout
40051
40052 \begin_layout Standard
40053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40054
40055 \end_inset
40056
40057
40058 \newline
40059
40060 \newline
40061
40062 \emph on
40063 Thanks to all the other volunteer developers who have helped with coding,
40064  testing, web-page creation, distribution sets, etc.
40065  You know who you are :-)
40066 \emph default
40067
40068 \newline
40069
40070 \newline
40071
40072 \emph on
40073 Thanks to Sourceforge 
40074 \begin_inset LatexCommand \url{http://www.sf.net}
40075
40076 \end_inset
40077
40078  which has hosted the project since 1999 and donates significant download
40079  bandwidth.
40080 \emph default
40081
40082 \newline
40083
40084 \newline
40085
40086 \emph on
40087 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40088  cycles and bandwidth for snapshot builds.
40089 \newline
40090
40091 \end_layout
40092
40093 \begin_layout Standard
40094 This document was initially written by Sandeep Dutta
40095 \end_layout
40096
40097 \begin_layout Standard
40098 All product names mentioned herein may be trademarks
40099 \begin_inset LatexCommand \index{Trademarks}
40100
40101 \end_inset
40102
40103  of their respective companies.
40104  
40105 \end_layout
40106
40107 \begin_layout Section*
40108 Alphabetical index
40109 \end_layout
40110
40111 \begin_layout Standard
40112 To avoid confusion, the installation and building options for SDCC itself
40113  (chapter 2) are not part of the index.
40114 \end_layout
40115
40116 \begin_layout Standard
40117 \begin_inset LatexCommand \printindex{}
40118
40119 \end_inset
40120
40121
40122 \end_layout
40123
40124 \end_body
40125 \end_document