doc/sdccman.lyx: Same changes made 2007-07-28 but using lyx 1.4.4 instead of lyx...
[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
6387 \begin_inset LatexCommand \index{SDCCLIB_CC}
6388
6389 \end_inset
6390
6391  and/or SDCCLIB_AS
6392 \begin_inset LatexCommand \index{SDCCLIB_AS}
6393
6394 \end_inset
6395
6396 .
6397  For example:
6398 \family sans
6399 \series bold
6400
6401 \newline
6402
6403 \end_layout
6404
6405 \begin_layout Standard
6406
6407 \family sans
6408 \series bold
6409 set SDCCLIB_CC=sdcc -c
6410 \end_layout
6411
6412 \begin_layout Standard
6413
6414 \family sans
6415 \series bold
6416 sdcclib -l libint.lib myliblist.txt
6417 \family default
6418 \series default
6419
6420 \newline
6421
6422 \end_layout
6423
6424 \begin_layout Standard
6425 To see what modules and symbols are included in the library, options -s
6426  and -m are available.
6427  For example:
6428 \newline
6429
6430 \newline
6431
6432 \family sans
6433 \series bold
6434 sdcclib -s libint.lib
6435 \family default
6436
6437 \begin_inset LatexCommand \index{sdcclib}
6438
6439 \end_inset
6440
6441
6442 \newline
6443
6444 \family typewriter
6445 \series default
6446 _divsint.rel:
6447 \end_layout
6448
6449 \begin_layout Standard
6450
6451 \family typewriter
6452 __divsint_a_1_1
6453 \end_layout
6454
6455 \begin_layout Standard
6456
6457 \family typewriter
6458 __divsint_PARM_2
6459 \end_layout
6460
6461 \begin_layout Standard
6462
6463 \family typewriter
6464 __divsint
6465 \newline
6466 _divuint.rel:
6467 \end_layout
6468
6469 \begin_layout Standard
6470
6471 \family typewriter
6472 __divuint_a_1_1
6473 \end_layout
6474
6475 \begin_layout Standard
6476
6477 \family typewriter
6478 __divuint_PARM_2
6479 \end_layout
6480
6481 \begin_layout Standard
6482
6483 \family typewriter
6484 __divuint_reste_1_1
6485 \end_layout
6486
6487 \begin_layout Standard
6488
6489 \family typewriter
6490 __divuint_count_1_1
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family typewriter
6496 __divuint
6497 \newline
6498 _modsint.rel:
6499 \end_layout
6500
6501 \begin_layout Standard
6502
6503 \family typewriter
6504 __modsint_a_1_1
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family typewriter
6510 __modsint_PARM_2
6511 \end_layout
6512
6513 \begin_layout Standard
6514
6515 \family typewriter
6516 __modsint
6517 \newline
6518 _moduint.rel:
6519 \end_layout
6520
6521 \begin_layout Standard
6522
6523 \family typewriter
6524 __moduint_a_1_1
6525 \end_layout
6526
6527 \begin_layout Standard
6528
6529 \family typewriter
6530 __moduint_PARM_2
6531 \end_layout
6532
6533 \begin_layout Standard
6534
6535 \family typewriter
6536 __moduint_count_1_1
6537 \end_layout
6538
6539 \begin_layout Standard
6540
6541 \family typewriter
6542 __moduint
6543 \newline
6544 _mulint.rel:
6545 \end_layout
6546
6547 \begin_layout Standard
6548
6549 \family typewriter
6550 __mulint_PARM_2
6551 \end_layout
6552
6553 \begin_layout Standard
6554
6555 \family typewriter
6556 __mulint
6557 \family default
6558 \series bold
6559
6560 \newline
6561
6562 \end_layout
6563
6564 \begin_layout Standard
6565 If the source files are compiled using -
6566 \begin_inset ERT
6567 status collapsed
6568
6569 \begin_layout Standard
6570
6571
6572 \backslash
6573 /
6574 \end_layout
6575
6576 \end_inset
6577
6578 -debug
6579 \begin_inset LatexCommand \index{-\/-debug}
6580
6581 \end_inset
6582
6583 , the corresponding debug information file .adb will be include in the library
6584  file as well.
6585  The library files created with sdcclib are plain text files, so they can
6586  be viewed with a text editor.
6587  It is not recomended to modify a library file created with sdcclib using
6588  a text editor, as there are file indexes numbers located accross the file
6589  used by the linker to quickly locate the required module to link.
6590  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6591  it can be safely deleted, since all the information required for linking
6592  is embedded in the library file itself.
6593  Library files created using sdcclib are used as described in the preceding
6594  sections.
6595 \begin_inset VSpace bigskip
6596 \end_inset
6597
6598
6599 \end_layout
6600
6601 \begin_layout Section
6602 Command Line Options
6603 \begin_inset LatexCommand \index{Command Line Options}
6604
6605 \end_inset
6606
6607
6608 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6609
6610 \end_inset
6611
6612
6613 \end_layout
6614
6615 \begin_layout Subsection
6616 Processor Selection Options
6617 \begin_inset LatexCommand \index{Options processor selection}
6618
6619 \end_inset
6620
6621
6622 \begin_inset LatexCommand \index{Processor selection options}
6623
6624 \end_inset
6625
6626
6627 \end_layout
6628
6629 \begin_layout List
6630 \labelwidthstring 00.00.0000
6631
6632 \series bold
6633 -mmcs51
6634 \begin_inset LatexCommand \index{-mmcs51}
6635
6636 \end_inset
6637
6638
6639 \series default
6640  Generate code for the Intel MCS51
6641 \begin_inset LatexCommand \index{MCS51}
6642
6643 \end_inset
6644
6645  family of processors.
6646  This is the default processor target.
6647 \end_layout
6648
6649 \begin_layout List
6650 \labelwidthstring 00.00.0000
6651
6652 \series bold
6653 -mds390
6654 \begin_inset LatexCommand \index{-mds390}
6655
6656 \end_inset
6657
6658
6659 \series default
6660  Generate code for the Dallas DS80C390
6661 \begin_inset LatexCommand \index{DS80C390}
6662
6663 \end_inset
6664
6665  processor.
6666 \end_layout
6667
6668 \begin_layout List
6669 \labelwidthstring 00.00.0000
6670
6671 \series bold
6672 -mds400
6673 \begin_inset LatexCommand \index{-mds400}
6674
6675 \end_inset
6676
6677
6678 \series default
6679  Generate code for the Dallas DS80C400
6680 \begin_inset LatexCommand \index{DS80C400}
6681
6682 \end_inset
6683
6684  processor.
6685 \end_layout
6686
6687 \begin_layout List
6688 \labelwidthstring 00.00.0000
6689
6690 \series bold
6691 -mhc08
6692 \begin_inset LatexCommand \index{-mhc08}
6693
6694 \end_inset
6695
6696
6697 \series default
6698  Generate code for the Freescale/Motorola HC08
6699 \begin_inset LatexCommand \index{HC08}
6700
6701 \end_inset
6702
6703  family of processors.
6704 \end_layout
6705
6706 \begin_layout List
6707 \labelwidthstring 00.00.0000
6708
6709 \series bold
6710 -mz80
6711 \begin_inset LatexCommand \index{-mz80}
6712
6713 \end_inset
6714
6715
6716 \series default
6717  Generate code for the Zilog Z80
6718 \begin_inset LatexCommand \index{Z80}
6719
6720 \end_inset
6721
6722  family of processors.
6723 \end_layout
6724
6725 \begin_layout List
6726 \labelwidthstring 00.00.0000
6727
6728 \series bold
6729 -mgbz80
6730 \begin_inset LatexCommand \index{-mgbz80}
6731
6732 \end_inset
6733
6734
6735 \series default
6736  Generate code for the GameBoy Z80
6737 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6738
6739 \end_inset
6740
6741  processor (Not actively maintained).
6742 \end_layout
6743
6744 \begin_layout List
6745 \labelwidthstring 00.00.0000
6746
6747 \series bold
6748 -mavr
6749 \begin_inset LatexCommand \index{-mavr}
6750
6751 \end_inset
6752
6753
6754 \series default
6755  Generate code for the Atmel AVR
6756 \begin_inset LatexCommand \index{AVR}
6757
6758 \end_inset
6759
6760  processor (Not maintained, not complete).
6761  AVR users should probably have a look at winavr 
6762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6763
6764 \end_inset
6765
6766  or 
6767 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6768
6769 \end_inset
6770
6771 , which is based on AVR-port of the gcc compiler.
6772 \end_layout
6773
6774 \begin_layout Standard
6775 \begin_inset Note Note
6776 status collapsed
6777
6778 \begin_layout Standard
6779 I think it is fair to direct users there for now.
6780  Open source is also about avoiding unnecessary work .
6781  But I didn't find the 'official' link.
6782 \end_layout
6783
6784 \end_inset
6785
6786
6787 \end_layout
6788
6789 \begin_layout List
6790 \labelwidthstring 00.00.0000
6791
6792 \series bold
6793 -mpic14
6794 \begin_inset LatexCommand \index{-mpic14}
6795
6796 \end_inset
6797
6798
6799 \series default
6800  Generate code for the Microchip PIC 14
6801 \begin_inset LatexCommand \index{PIC14}
6802
6803 \end_inset
6804
6805 -bit processors (p16f84 and variants.
6806  In development, not complete).
6807 \end_layout
6808
6809 \begin_layout Standard
6810 \begin_inset Note Note
6811 status collapsed
6812
6813 \begin_layout Standard
6814 p16f627 p16f628 p16f84 p16f873 p16f877?
6815 \end_layout
6816
6817 \end_inset
6818
6819
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mpic16
6827 \begin_inset LatexCommand \index{-mpic16}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Microchip PIC 16
6834 \begin_inset LatexCommand \index{PIC16}
6835
6836 \end_inset
6837
6838 -bit processors (p18f452 and variants.
6839  In development, not complete).
6840 \end_layout
6841
6842 \begin_layout List
6843 \labelwidthstring 00.00.0000
6844
6845 \series bold
6846 -mtlcs900h
6847 \series default
6848  Generate code for the Toshiba TLCS-900H
6849 \begin_inset LatexCommand \index{TLCS-900H}
6850
6851 \end_inset
6852
6853  processor (Not maintained, not complete).
6854 \end_layout
6855
6856 \begin_layout List
6857 \labelwidthstring 00.00.0000
6858
6859 \series bold
6860 -mxa51
6861 \begin_inset LatexCommand \index{-mxa51}
6862
6863 \end_inset
6864
6865
6866 \series default
6867  Generate code for the Phillips XA51
6868 \begin_inset LatexCommand \index{XA51}
6869
6870 \end_inset
6871
6872  processor (Not maintained, not complete).
6873 \end_layout
6874
6875 \begin_layout Standard
6876 \begin_inset VSpace bigskip
6877 \end_inset
6878
6879
6880 \end_layout
6881
6882 \begin_layout Subsection
6883 Preprocessor Options
6884 \begin_inset LatexCommand \index{Options preprocessor}
6885
6886 \end_inset
6887
6888
6889 \begin_inset LatexCommand \index{Preprocessor options}
6890
6891 \end_inset
6892
6893
6894 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6895
6896 \end_inset
6897
6898
6899 \end_layout
6900
6901 \begin_layout List
6902 \labelwidthstring 00.00.0000
6903
6904 \series bold
6905 -I<path>
6906 \begin_inset LatexCommand \index{-I<path>}
6907
6908 \end_inset
6909
6910
6911 \series default
6912  The additional location where the preprocessor will look for <..h> or 
6913 \begin_inset Quotes eld
6914 \end_inset
6915
6916 ..h
6917 \begin_inset Quotes erd
6918 \end_inset
6919
6920  files.
6921 \end_layout
6922
6923 \begin_layout List
6924 \labelwidthstring 00.00.0000
6925
6926 \series bold
6927 -D<macro[=value]>
6928 \begin_inset LatexCommand \index{-D<macro[=value]>}
6929
6930 \end_inset
6931
6932
6933 \series default
6934  Command line definition of macros.
6935  Passed to the preprocessor.
6936 \end_layout
6937
6938 \begin_layout List
6939 \labelwidthstring 00.00.0000
6940
6941 \series bold
6942 -M
6943 \begin_inset LatexCommand \index{-M}
6944
6945 \end_inset
6946
6947
6948 \series default
6949  Tell the preprocessor to output a rule suitable for make describing the
6950  dependencies of each object file.
6951  For each source file, the preprocessor outputs one make-rule whose target
6952  is the object file name for that source file and whose dependencies are
6953  all the files `#include'd in it.
6954  This rule may be a single line or may be continued with `
6955 \backslash
6956 '-newline if it is long.
6957  The list of rules is printed on standard output instead of the preprocessed
6958  C program.
6959  `-M' implies `-E
6960 \begin_inset LatexCommand \index{-E}
6961
6962 \end_inset
6963
6964 '.
6965 \end_layout
6966
6967 \begin_layout List
6968 \labelwidthstring 00.00.0000
6969
6970 \series bold
6971 -C
6972 \begin_inset LatexCommand \index{-C}
6973
6974 \end_inset
6975
6976
6977 \series default
6978  Tell the preprocessor not to discard comments.
6979  Used with the `-E' option.
6980 \end_layout
6981
6982 \begin_layout List
6983 \labelwidthstring 00.00.0000
6984
6985 \series bold
6986 -MM
6987 \begin_inset LatexCommand \index{-MM}
6988
6989 \end_inset
6990
6991
6992 \size large
6993 \bar under
6994  
6995 \series default
6996 \size default
6997 \bar default
6998 Like `-M' but the output mentions only the user header files included with
6999  `#include 
7000 \begin_inset Quotes eld
7001 \end_inset
7002
7003 file"'.
7004  System header files included with `#include <file>' are omitted.
7005 \end_layout
7006
7007 \begin_layout List
7008 \labelwidthstring 00.00.0000
7009
7010 \series bold
7011 -Aquestion(answer)
7012 \begin_inset LatexCommand \index{-Aquestion(answer)}
7013
7014 \end_inset
7015
7016
7017 \series default
7018  Assert the answer answer for question, in case it is tested with a preprocessor
7019  conditional such as `#if #question(answer)'.
7020  `-A-' disables the standard assertions that normally describe the target
7021  machine.
7022 \end_layout
7023
7024 \begin_layout List
7025 \labelwidthstring 00.00.0000
7026
7027 \series bold
7028 -Umacro
7029 \begin_inset LatexCommand \index{-Umacro}
7030
7031 \end_inset
7032
7033
7034 \series default
7035  Undefine macro macro.
7036  `-U' options are evaluated after all `-D' options, but before any `-include'
7037  and `-imacros' options.
7038 \end_layout
7039
7040 \begin_layout List
7041 \labelwidthstring 00.00.0000
7042
7043 \series bold
7044 -dM
7045 \begin_inset LatexCommand \index{-dM}
7046
7047 \end_inset
7048
7049
7050 \series default
7051  Tell the preprocessor to output only a list of the macro definitions that
7052  are in effect at the end of preprocessing.
7053  Used with the `-E' option.
7054 \end_layout
7055
7056 \begin_layout List
7057 \labelwidthstring 00.00.0000
7058
7059 \series bold
7060 -dD
7061 \begin_inset LatexCommand \index{-dD}
7062
7063 \end_inset
7064
7065
7066 \series default
7067  Tell the preprocessor to pass all macro definitions into the output, in
7068  their proper sequence in the rest of the output.
7069 \end_layout
7070
7071 \begin_layout List
7072 \labelwidthstring 00.00.0000
7073
7074 \series bold
7075 -dN
7076 \begin_inset LatexCommand \index{-dN}
7077
7078 \end_inset
7079
7080
7081 \size large
7082 \bar under
7083  
7084 \series default
7085 \size default
7086 \bar default
7087 Like `-dD' except that the macro arguments and contents are omitted.
7088  Only `#define name' is included in the output.
7089 \end_layout
7090
7091 \begin_layout List
7092 \labelwidthstring 00.00.0000
7093
7094 \series bold
7095 -pedantic-parse-number
7096 \begin_inset LatexCommand \index{pedantic}
7097
7098 \end_inset
7099
7100
7101 \begin_inset LatexCommand \index{-pedantic-parse-number}
7102
7103 \end_inset
7104
7105
7106 \size large
7107 \bar under
7108
7109 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7110
7111 \end_inset
7112
7113  
7114 \series default
7115 \size default
7116 \bar default
7117 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7118  and the macro LO_B(3) gets expanded.
7119  See also #pragma pedantic_parse_number 
7120 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7121
7122 \end_inset
7123
7124  in section
7125 \begin_inset LatexCommand \ref{sec:Pragmas}
7126
7127 \end_inset
7128
7129  
7130 \emph on
7131 Note: this functionality is not in conformance with C99 standard!
7132 \end_layout
7133
7134 \begin_layout List
7135 \labelwidthstring 00.00.0000
7136
7137 \series bold
7138 -Wp\InsetSpace ~
7139 preprocessorOption[,preprocessorOption]
7140 \series default
7141
7142 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7143
7144 \end_inset
7145
7146 ...
7147  Pass the preprocessorOption to the preprocessor 
7148 \family typewriter
7149 sdcpp
7150 \family default
7151
7152 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7153
7154 \end_inset
7155
7156 .
7157  SDCC uses an adapted version of the preprocessor 
7158 \emph on
7159 cpp
7160 \emph default
7161  of the GNU Compiler Collection
7162 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7163
7164 \end_inset
7165
7166  (
7167 \emph on
7168 gcc
7169 \emph default
7170  
7171 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7172
7173 \end_inset
7174
7175 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7176 4.1.1\InsetSpace ~
7177 CPP\InsetSpace ~
7178 Manual
7179  at 
7180 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7181
7182 \end_inset
7183
7184 .
7185 \end_layout
7186
7187 \begin_layout Standard
7188 \begin_inset VSpace bigskip
7189 \end_inset
7190
7191
7192 \end_layout
7193
7194 \begin_layout Subsection
7195 Linker Options
7196 \begin_inset LatexCommand \index{Options linker}
7197
7198 \end_inset
7199
7200
7201 \begin_inset LatexCommand \index{Linker options}
7202
7203 \end_inset
7204
7205
7206 \end_layout
7207
7208 \begin_layout List
7209 \labelwidthstring 00.00.0000
7210
7211 \series bold
7212 -L\InsetSpace ~
7213 -
7214 \series default
7215
7216 \begin_inset ERT
7217 status collapsed
7218
7219 \begin_layout Standard
7220
7221
7222 \backslash
7223 /
7224 \end_layout
7225
7226 \end_inset
7227
7228
7229 \series bold
7230 -lib-path
7231 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7232
7233 \end_inset
7234
7235
7236 \begin_inset LatexCommand \index{-L -\/-lib-path}
7237
7238 \end_inset
7239
7240
7241 \series default
7242 \InsetSpace ~
7243 <absolute path to additional libraries> This option is passed to the linkage
7244  editor's additional libraries
7245 \begin_inset LatexCommand \index{Libraries}
7246
7247 \end_inset
7248
7249  search path.
7250  The path name must be absolute.
7251  Additional library files may be specified in the command line.
7252  See section Compiling programs for more details.
7253 \end_layout
7254
7255 \begin_layout List
7256 \labelwidthstring 00.00.0000
7257
7258 \series bold
7259 -
7260 \begin_inset ERT
7261 status collapsed
7262
7263 \begin_layout Standard
7264
7265
7266 \backslash
7267 /
7268 \end_layout
7269
7270 \end_inset
7271
7272 -xram-loc
7273 \series default
7274
7275 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7276
7277 \end_inset
7278
7279 \InsetSpace ~
7280 <Value> The start location of the external ram
7281 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7282
7283 \end_inset
7284
7285 , default value is 0.
7286  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7287 \begin_inset ERT
7288 status collapsed
7289
7290 \begin_layout Standard
7291
7292
7293 \backslash
7294 /
7295 \end_layout
7296
7297 \end_inset
7298
7299 -xram-loc 0x8000 or -
7300 \begin_inset ERT
7301 status collapsed
7302
7303 \begin_layout Standard
7304
7305
7306 \backslash
7307 /
7308 \end_layout
7309
7310 \end_inset
7311
7312 -xram-loc 32768.
7313 \end_layout
7314
7315 \begin_layout List
7316 \labelwidthstring 00.00.0000
7317
7318 \series bold
7319 -
7320 \begin_inset ERT
7321 status collapsed
7322
7323 \begin_layout Standard
7324
7325
7326 \backslash
7327 /
7328 \end_layout
7329
7330 \end_inset
7331
7332 -code-loc
7333 \series default
7334
7335 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7336
7337 \end_inset
7338
7339 \InsetSpace ~
7340 <Value> The start location of the code
7341 \begin_inset LatexCommand \index{code}
7342
7343 \end_inset
7344
7345  segment, default value 0.
7346  Note when this option is used the interrupt vector table
7347 \begin_inset LatexCommand \index{interrupt vector table}
7348
7349 \end_inset
7350
7351  is also relocated to the given address.
7352  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7353 \begin_inset ERT
7354 status collapsed
7355
7356 \begin_layout Standard
7357
7358
7359 \backslash
7360 /
7361 \end_layout
7362
7363 \end_inset
7364
7365 -code-loc 0x8000 or -
7366 \begin_inset ERT
7367 status collapsed
7368
7369 \begin_layout Standard
7370
7371
7372 \backslash
7373 /
7374 \end_layout
7375
7376 \end_inset
7377
7378 -code-loc 32768.
7379 \end_layout
7380
7381 \begin_layout List
7382 \labelwidthstring 00.00.0000
7383
7384 \series bold
7385 -
7386 \begin_inset ERT
7387 status collapsed
7388
7389 \begin_layout Standard
7390
7391
7392 \backslash
7393 /
7394 \end_layout
7395
7396 \end_inset
7397
7398 -stack-loc
7399 \series default
7400
7401 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7402
7403 \end_inset
7404
7405 \InsetSpace ~
7406 <Value> By default the stack
7407 \begin_inset LatexCommand \index{stack}
7408
7409 \end_inset
7410
7411  is placed after the data segment.
7412  Using this option the stack can be placed anywhere in the internal memory
7413  space of the 8051.
7414  The value entered can be in Hexadecimal or Decimal format, e.g.
7415  -
7416 \begin_inset ERT
7417 status collapsed
7418
7419 \begin_layout Standard
7420
7421
7422 \backslash
7423 /
7424 \end_layout
7425
7426 \end_inset
7427
7428 -stack-loc 0x20 or -
7429 \begin_inset ERT
7430 status collapsed
7431
7432 \begin_layout Standard
7433
7434
7435 \backslash
7436 /
7437 \end_layout
7438
7439 \end_inset
7440
7441 -stack-loc 32.
7442  Since the sp register is incremented before a push or call, the initial
7443  sp will be set to one byte prior the provided value.
7444  The provided value should not overlap any other memory areas such as used
7445  register banks or the data segment and with enough space for the current
7446  application.
7447  The 
7448 \series bold
7449 -
7450 \begin_inset ERT
7451 status collapsed
7452
7453 \begin_layout Standard
7454
7455
7456 \backslash
7457 /
7458 \end_layout
7459
7460 \end_inset
7461
7462 -pack-iram
7463 \series default
7464 \InsetSpace ~
7465
7466 \begin_inset LatexCommand \index{-\/-pack-iram}
7467
7468 \end_inset
7469
7470  option (which is now a default setting) will override this setting, so
7471  you should also specify the 
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -no-pack-iram
7487 \series default
7488 \InsetSpace ~
7489
7490 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7491
7492 \end_inset
7493
7494  option if you need to manually place the stack.
7495 \end_layout
7496
7497 \begin_layout List
7498 \labelwidthstring 00.00.0000
7499
7500 \series bold
7501 -
7502 \begin_inset ERT
7503 status collapsed
7504
7505 \begin_layout Standard
7506
7507
7508 \backslash
7509 /
7510 \end_layout
7511
7512 \end_inset
7513
7514 -xstack-loc
7515 \series default
7516
7517 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7518
7519 \end_inset
7520
7521 \InsetSpace ~
7522 <Value> By default the external stack
7523 \begin_inset LatexCommand \index{xstack}
7524
7525 \end_inset
7526
7527  is placed after the pdata
7528 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7529
7530 \end_inset
7531
7532  segment.
7533  Using this option the xstack can be placed anywhere in the external memory
7534  space of the 8051.
7535  The value entered can be in Hexadecimal or Decimal format, e.g.
7536  -
7537 \begin_inset ERT
7538 status collapsed
7539
7540 \begin_layout Standard
7541
7542
7543 \backslash
7544 /
7545 \end_layout
7546
7547 \end_inset
7548
7549 -xstack-loc 0x8000 or -
7550 \begin_inset ERT
7551 status collapsed
7552
7553 \begin_layout Standard
7554
7555
7556 \backslash
7557 /
7558 \end_layout
7559
7560 \end_inset
7561
7562 -stack-loc 32768.
7563  The provided value should not overlap any other memory areas such as the
7564  pdata or xdata segment and with enough space for the current application.
7565 \end_layout
7566
7567 \begin_layout List
7568 \labelwidthstring 00.00.0000
7569
7570 \series bold
7571 -
7572 \begin_inset ERT
7573 status collapsed
7574
7575 \begin_layout Standard
7576
7577
7578 \backslash
7579 /
7580 \end_layout
7581
7582 \end_inset
7583
7584 -data-loc
7585 \series default
7586
7587 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7588
7589 \end_inset
7590
7591 \InsetSpace ~
7592 <Value> The start location of the internal ram data
7593 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7594
7595 \end_inset
7596
7597  segment.
7598  The value entered can be in Hexadecimal or Decimal format, eg.
7599  -
7600 \begin_inset ERT
7601 status collapsed
7602
7603 \begin_layout Standard
7604
7605
7606 \backslash
7607 /
7608 \end_layout
7609
7610 \end_inset
7611
7612 -data-loc 0x20 or -
7613 \begin_inset ERT
7614 status collapsed
7615
7616 \begin_layout Standard
7617
7618
7619 \backslash
7620 /
7621 \end_layout
7622
7623 \end_inset
7624
7625 -data-loc 32.
7626  (By default, the start location of the internal ram data segment  is set
7627  as low as possible in memory, taking into account the used register banks
7628  and the bit segment at address 0x20.
7629  For example if register banks 0 and 1 are used without bit variables, the
7630  data segment will be set, if -
7631 \begin_inset ERT
7632 status collapsed
7633
7634 \begin_layout Standard
7635
7636
7637 \backslash
7638 /
7639 \end_layout
7640
7641 \end_inset
7642
7643 -data-loc is not used, to location 0x10.)
7644 \end_layout
7645
7646 \begin_layout List
7647 \labelwidthstring 00.00.0000
7648
7649 \series bold
7650 -
7651 \begin_inset ERT
7652 status collapsed
7653
7654 \begin_layout Standard
7655
7656
7657 \backslash
7658 /
7659 \end_layout
7660
7661 \end_inset
7662
7663 -idata-loc
7664 \series default
7665
7666 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7667
7668 \end_inset
7669
7670 \InsetSpace ~
7671 <Value> The start location of the indirectly addressable internal ram
7672 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7673
7674 \end_inset
7675
7676  of the 8051, default value is 0x80.
7677  The value entered can be in Hexadecimal or Decimal format, eg.
7678  -
7679 \begin_inset ERT
7680 status collapsed
7681
7682 \begin_layout Standard
7683
7684
7685 \backslash
7686 /
7687 \end_layout
7688
7689 \end_inset
7690
7691 -idata-loc 0x88 or -
7692 \begin_inset ERT
7693 status collapsed
7694
7695 \begin_layout Standard
7696
7697
7698 \backslash
7699 /
7700 \end_layout
7701
7702 \end_inset
7703
7704 -idata-loc 136.
7705 \end_layout
7706
7707 \begin_layout List
7708 \labelwidthstring 00.00.0000
7709
7710 \series bold
7711 -
7712 \begin_inset ERT
7713 status collapsed
7714
7715 \begin_layout Standard
7716
7717
7718 \backslash
7719 /
7720 \end_layout
7721
7722 \end_inset
7723
7724 -bit-loc
7725 \series default
7726 \InsetSpace ~
7727 <Value> The start location of the bit
7728 \begin_inset LatexCommand \index{bit}
7729
7730 \end_inset
7731
7732  addressable internal ram of the 8051.
7733  This is 
7734 \emph on
7735 not
7736 \emph default
7737  implemented yet.
7738  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7739 -bBSEG=<Value>.
7740 \end_layout
7741
7742 \begin_layout List
7743 \labelwidthstring 00.00.0000
7744
7745 \series bold
7746 -
7747 \begin_inset ERT
7748 status collapsed
7749
7750 \begin_layout Standard
7751
7752
7753 \backslash
7754 /
7755 \end_layout
7756
7757 \end_inset
7758
7759 -out-fmt-ihx
7760 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7761
7762 \end_inset
7763
7764
7765 \bar under
7766  
7767 \series default
7768 \bar default
7769 The linker output (final object code) is in Intel Hex format.
7770 \begin_inset LatexCommand \index{Intel hex format}
7771
7772 \end_inset
7773
7774  This is the default option.
7775  The format itself is documented in the documentation of srecord
7776 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7777
7778 \end_inset
7779
7780 .
7781 \end_layout
7782
7783 \begin_layout List
7784 \labelwidthstring 00.00.0000
7785
7786 \series bold
7787 -
7788 \begin_inset ERT
7789 status collapsed
7790
7791 \begin_layout Standard
7792
7793
7794 \backslash
7795 /
7796 \end_layout
7797
7798 \end_inset
7799
7800 -out-fmt-s19
7801 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7802
7803 \end_inset
7804
7805
7806 \bar under
7807  
7808 \series default
7809 \bar default
7810 The linker output (final object code) is in Motorola S19 format
7811 \begin_inset LatexCommand \index{Motorola S19 format}
7812
7813 \end_inset
7814
7815 .
7816  The format itself is documented in the documentation of srecord.
7817 \end_layout
7818
7819 \begin_layout List
7820 \labelwidthstring 00.00.0000
7821
7822 \series bold
7823 -
7824 \begin_inset ERT
7825 status collapsed
7826
7827 \begin_layout Standard
7828
7829
7830 \backslash
7831 /
7832 \end_layout
7833
7834 \end_inset
7835
7836 -out-fmt-elf
7837 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7838
7839 \end_inset
7840
7841
7842 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7843
7844 \end_inset
7845
7846
7847 \bar under
7848  
7849 \series default
7850 \bar default
7851 The linker output (final object code) is in ELF format
7852 \begin_inset LatexCommand \index{ELF format}
7853
7854 \end_inset
7855
7856 .
7857  (Currently only supported for the HC08
7858 \begin_inset LatexCommand \index{HC08}
7859
7860 \end_inset
7861
7862  processors)
7863 \end_layout
7864
7865 \begin_layout List
7866 \labelwidthstring 00.00.0000
7867
7868 \series bold
7869 -Wl\InsetSpace ~
7870 linkOption[,linkOption]
7871 \series default
7872
7873 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7874
7875 \end_inset
7876
7877 ...
7878  Pass the linkOption to the linker.
7879  If a bootloader is used an option like 
7880 \begin_inset Quotes sld
7881 \end_inset
7882
7883 -Wl\InsetSpace ~
7884 -bCSEG=0x1000
7885 \begin_inset Quotes srd
7886 \end_inset
7887
7888  would be typical to set the start of the code segment.
7889  See also #pragma constseg and #pragma codeseg in section 
7890 \begin_inset LatexCommand \ref{sec:Pragmas}
7891
7892 \end_inset
7893
7894  .
7895  File sdcc/as/doc/asxhtm.html has more on linker options.
7896 \end_layout
7897
7898 \begin_layout Standard
7899 \begin_inset VSpace bigskip
7900 \end_inset
7901
7902
7903 \end_layout
7904
7905 \begin_layout Subsection
7906 MCS51 Options
7907 \begin_inset LatexCommand \index{Options MCS51}
7908
7909 \end_inset
7910
7911
7912 \begin_inset LatexCommand \index{MCS51 options}
7913
7914 \end_inset
7915
7916
7917 \end_layout
7918
7919 \begin_layout List
7920 \labelwidthstring 00.00.0000
7921
7922 \series bold
7923 -
7924 \begin_inset ERT
7925 status collapsed
7926
7927 \begin_layout Standard
7928
7929
7930 \backslash
7931 /
7932 \end_layout
7933
7934 \end_inset
7935
7936 -model-small
7937 \begin_inset LatexCommand \index{-\/-model-small}
7938
7939 \end_inset
7940
7941
7942 \series default
7943 \size large
7944 \emph on
7945  
7946 \size default
7947 \emph default
7948 Generate code for Small Model programs, see section Memory Models for more
7949  details.
7950  This is the default model.
7951 \end_layout
7952
7953 \begin_layout List
7954 \labelwidthstring 00.00.0000
7955
7956 \series bold
7957 -
7958 \begin_inset ERT
7959 status collapsed
7960
7961 \begin_layout Standard
7962
7963
7964 \backslash
7965 /
7966 \end_layout
7967
7968 \end_inset
7969
7970 -model-medium
7971 \begin_inset LatexCommand \index{-\/-model-medium}
7972
7973 \end_inset
7974
7975
7976 \series default
7977  Generate code for Medium model programs, see section Memory Models for
7978  more details.
7979  If this option is used all source files in the project have to be compiled
7980  with this option.
7981  It must also be used when invoking the linker.
7982 \end_layout
7983
7984 \begin_layout List
7985 \labelwidthstring 00.00.0000
7986
7987 \series bold
7988 -
7989 \begin_inset ERT
7990 status collapsed
7991
7992 \begin_layout Standard
7993
7994
7995 \backslash
7996 /
7997 \end_layout
7998
7999 \end_inset
8000
8001 -model-large
8002 \begin_inset LatexCommand \index{-\/-model-large}
8003
8004 \end_inset
8005
8006
8007 \series default
8008  Generate code for Large model programs, see section Memory Models for more
8009  details.
8010  If this option is used all source files in the project have to be compiled
8011  with this option.
8012  It must also be used when invoking the linker.
8013 \end_layout
8014
8015 \begin_layout List
8016 \labelwidthstring 00.00.0000
8017
8018 \series bold
8019 -
8020 \begin_inset ERT
8021 status collapsed
8022
8023 \begin_layout Standard
8024
8025
8026 \backslash
8027 /
8028 \end_layout
8029
8030 \end_inset
8031
8032 -xstack
8033 \begin_inset LatexCommand \index{-\/-xstack}
8034
8035 \end_inset
8036
8037
8038 \series default
8039  Uses a pseudo stack in the pdata
8040 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8041
8042 \end_inset
8043
8044  area (usually the first 256 bytes in the external ram) for allocating variables
8045  and passing parameters.
8046  See section 
8047 \begin_inset LatexCommand \ref{sub:External-Stack}
8048
8049 \end_inset
8050
8051 \InsetSpace ~
8052  External Stack for more details.
8053 \end_layout
8054
8055 \begin_layout List
8056 \labelwidthstring 00.00.0000
8057
8058 \series bold
8059 -
8060 \begin_inset ERT
8061 status collapsed
8062
8063 \begin_layout Standard
8064
8065
8066 \backslash
8067 /
8068 \end_layout
8069
8070 \end_inset
8071
8072 -iram-size
8073 \series default
8074 \InsetSpace ~
8075 <Value>
8076 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8077
8078 \end_inset
8079
8080  Causes the linker to check if the internal ram usage is within limits of
8081  the given value.
8082 \end_layout
8083
8084 \begin_layout List
8085 \labelwidthstring 00.00.0000
8086
8087 \series bold
8088 -
8089 \begin_inset ERT
8090 status collapsed
8091
8092 \begin_layout Standard
8093
8094
8095 \backslash
8096 /
8097 \end_layout
8098
8099 \end_inset
8100
8101 -xram-size
8102 \series default
8103 \InsetSpace ~
8104 <Value>
8105 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8106
8107 \end_inset
8108
8109  Causes the linker to check if the external ram usage is within limits of
8110  the given value.
8111 \end_layout
8112
8113 \begin_layout List
8114 \labelwidthstring 00.00.0000
8115
8116 \series bold
8117 -
8118 \begin_inset ERT
8119 status collapsed
8120
8121 \begin_layout Standard
8122
8123
8124 \backslash
8125 /
8126 \end_layout
8127
8128 \end_inset
8129
8130 -code-size
8131 \series default
8132 \InsetSpace ~
8133 <Value>
8134 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8135
8136 \end_inset
8137
8138  Causes the linker to check if the code memory usage is within limits of
8139  the given value.
8140 \end_layout
8141
8142 \begin_layout List
8143 \labelwidthstring 00.00.0000
8144
8145 \series bold
8146 -
8147 \begin_inset ERT
8148 status collapsed
8149
8150 \begin_layout Standard
8151
8152
8153 \backslash
8154 /
8155 \end_layout
8156
8157 \end_inset
8158
8159 -stack-size
8160 \series default
8161 \InsetSpace ~
8162 <Value>
8163 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8164
8165 \end_inset
8166
8167  Causes the linker to check if there is at minimum <Value> bytes for stack.
8168 \end_layout
8169
8170 \begin_layout List
8171 \labelwidthstring 00.00.0000
8172
8173 \series bold
8174 -
8175 \begin_inset ERT
8176 status collapsed
8177
8178 \begin_layout Standard
8179
8180
8181 \backslash
8182 /
8183 \end_layout
8184
8185 \end_inset
8186
8187 -pack-iram
8188 \series default
8189 \InsetSpace ~
8190
8191 \begin_inset LatexCommand \index{-\/-pack-iram}
8192
8193 \end_inset
8194
8195  Causes the linker to use unused register banks for data variables and pack
8196  data, idata and stack together.
8197  This is the default now.
8198 \end_layout
8199
8200 \begin_layout List
8201 \labelwidthstring 00.00.0000
8202
8203 \series bold
8204 -
8205 \begin_inset ERT
8206 status collapsed
8207
8208 \begin_layout Standard
8209
8210
8211 \backslash
8212 /
8213 \end_layout
8214
8215 \end_inset
8216
8217 -no-pack-iram
8218 \series default
8219 \InsetSpace ~
8220
8221 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8222
8223 \end_inset
8224
8225  Causes the linker to use old style for allocating memory areas.
8226 \end_layout
8227
8228 \begin_layout List
8229 \labelwidthstring 00.00.0000
8230
8231 \series bold
8232 -
8233 \begin_inset ERT
8234 status collapsed
8235
8236 \begin_layout Standard
8237
8238
8239 \backslash
8240 /
8241 \end_layout
8242
8243 \end_inset
8244
8245 -acall-ajmp
8246 \series default
8247 \InsetSpace ~
8248
8249 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8250
8251 \end_inset
8252
8253  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8254  acall/ajmp.
8255  Only use this option if your code is in the same 2k block of memory.
8256  You may need to use this option for some 8051 derivatives which lack the
8257  lcall/ljmp instructions..
8258 \end_layout
8259
8260 \begin_layout Standard
8261 \begin_inset VSpace bigskip
8262 \end_inset
8263
8264
8265 \end_layout
8266
8267 \begin_layout Subsection
8268 DS390 / DS400 Options
8269 \begin_inset LatexCommand \index{Options DS390}
8270
8271 \end_inset
8272
8273
8274 \begin_inset LatexCommand \index{DS390}
8275
8276 \end_inset
8277
8278
8279 \end_layout
8280
8281 \begin_layout List
8282 \labelwidthstring 00.00.0000
8283
8284 \series bold
8285 -
8286 \begin_inset ERT
8287 status collapsed
8288
8289 \begin_layout Standard
8290
8291
8292 \backslash
8293 /
8294 \end_layout
8295
8296 \end_inset
8297
8298 -model-flat24
8299 \series default
8300
8301 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8302
8303 \end_inset
8304
8305
8306 \size large
8307 \emph on
8308  
8309 \size default
8310 \emph default
8311 Generate 24-bit flat mode code.
8312  This is the one and only that the ds390 code generator supports right now
8313  and is default when using 
8314 \emph on
8315 -mds390
8316 \emph default
8317 .
8318  See section Memory Models for more details.
8319 \end_layout
8320
8321 \begin_layout List
8322 \labelwidthstring 00.00.0000
8323
8324 \series bold
8325 -
8326 \begin_inset ERT
8327 status collapsed
8328
8329 \begin_layout Standard
8330
8331
8332 \backslash
8333 /
8334 \end_layout
8335
8336 \end_inset
8337
8338 -protect-sp-update
8339 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8340
8341 \end_inset
8342
8343
8344 \series default
8345  disable interrupts during ESP:SP updates.
8346 \end_layout
8347
8348 \begin_layout List
8349 \labelwidthstring 00.00.0000
8350
8351 \series bold
8352 -
8353 \begin_inset ERT
8354 status collapsed
8355
8356 \begin_layout Standard
8357
8358
8359 \backslash
8360 /
8361 \end_layout
8362
8363 \end_inset
8364
8365 -stack-10bit
8366 \series default
8367
8368 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8369
8370 \end_inset
8371
8372  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8373  This is the one and only that the ds390 code generator supports right now
8374  and is default when using 
8375 \emph on
8376 -mds390
8377 \emph default
8378 .
8379  In this mode, the stack is located in the lower 1K of the internal RAM,
8380  which is mapped to 0x400000.
8381  Note that the support is incomplete, since it still uses a single byte
8382  as the stack pointer.
8383  This means that only the lower 256 bytes of the potential 1K stack space
8384  will actually be used.
8385  However, this does allow you to reclaim the precious 256 bytes of low RAM
8386  for use for the DATA and IDATA segments.
8387  The compiler will not generate any code to put the processor into 10 bit
8388  stack mode.
8389  It is important to ensure that the processor is in this mode before calling
8390  any re-entrant functions compiled with this option.
8391  In principle, this should work with the 
8392 \emph on
8393 -
8394 \begin_inset ERT
8395 status collapsed
8396
8397 \begin_layout Standard
8398
8399
8400 \backslash
8401 /
8402 \end_layout
8403
8404 \end_inset
8405
8406 -stack-auto
8407 \begin_inset LatexCommand \index{-\/-stack-auto}
8408
8409 \end_inset
8410
8411
8412 \emph default
8413  option, but that has not been tested.
8414  It is incompatible with the 
8415 \emph on
8416 -
8417 \begin_inset ERT
8418 status collapsed
8419
8420 \begin_layout Standard
8421
8422
8423 \backslash
8424 /
8425 \end_layout
8426
8427 \end_inset
8428
8429 -xstack
8430 \begin_inset LatexCommand \index{-\/-xstack}
8431
8432 \end_inset
8433
8434
8435 \emph default
8436  option.
8437  It also only makes sense if the processor is in 24 bit contiguous addressing
8438  mode (see the 
8439 \emph on
8440 -
8441 \begin_inset ERT
8442 status collapsed
8443
8444 \begin_layout Standard
8445
8446
8447 \backslash
8448 /
8449 \end_layout
8450
8451 \end_inset
8452
8453 -model-flat24 option
8454 \emph default
8455 ).
8456 \series bold
8457
8458 \begin_inset Note Note
8459 status collapsed
8460
8461 \begin_layout List
8462 \labelwidthstring 00.00.0000
8463
8464 \series bold
8465 -
8466 \begin_inset ERT
8467 status open
8468
8469 \begin_layout Standard
8470
8471
8472 \backslash
8473 /
8474 \end_layout
8475
8476 \end_inset
8477
8478 -stack-8-bit - switches off the 10-bit mode
8479 \end_layout
8480
8481 \end_inset
8482
8483
8484 \end_layout
8485
8486 \begin_layout List
8487 \labelwidthstring 00.00.0000
8488
8489 \series bold
8490 -
8491 \begin_inset ERT
8492 status collapsed
8493
8494 \begin_layout Standard
8495
8496
8497 \backslash
8498 /
8499 \end_layout
8500
8501 \end_inset
8502
8503 -stack-probe
8504 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8505
8506 \end_inset
8507
8508
8509 \series default
8510  insert call to function __stack_probe at each function prologue.
8511 \end_layout
8512
8513 \begin_layout List
8514 \labelwidthstring 00.00.0000
8515
8516 \series bold
8517 -
8518 \begin_inset ERT
8519 status open
8520
8521 \begin_layout Standard
8522
8523
8524 \backslash
8525 /
8526 \end_layout
8527
8528 \end_inset
8529
8530 -tini-libid
8531 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8532
8533 \end_inset
8534
8535
8536 \series default
8537  <nnnn> LibraryID used in -mTININative.
8538  
8539 \end_layout
8540
8541 \begin_layout List
8542 \labelwidthstring 00.00.0000
8543
8544 \series bold
8545 -
8546 \begin_inset ERT
8547 status collapsed
8548
8549 \begin_layout Standard
8550
8551
8552 \backslash
8553 /
8554 \end_layout
8555
8556 \end_inset
8557
8558 -use-accelerator
8559 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8560
8561 \end_inset
8562
8563
8564 \series default
8565  generate code for DS390 Arithmetic Accelerator.
8566  
8567 \end_layout
8568
8569 \begin_layout Standard
8570 \begin_inset VSpace bigskip
8571 \end_inset
8572
8573
8574 \end_layout
8575
8576 \begin_layout Subsection
8577 Z80 Options
8578 \begin_inset LatexCommand \index{Options Z80}
8579
8580 \end_inset
8581
8582
8583 \begin_inset LatexCommand \index{Z80}
8584
8585 \end_inset
8586
8587
8588 \end_layout
8589
8590 \begin_layout List
8591 \labelwidthstring 00.00.0000
8592
8593 \series bold
8594 -
8595 \begin_inset ERT
8596 status collapsed
8597
8598 \begin_layout Standard
8599
8600
8601 \backslash
8602 /
8603 \end_layout
8604
8605 \end_inset
8606
8607 -callee-saves-bc
8608 \series default
8609
8610 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8611
8612 \end_inset
8613
8614
8615 \size large
8616 \emph on
8617  
8618 \size default
8619 \emph default
8620 Force a called function to always save BC.
8621 \end_layout
8622
8623 \begin_layout List
8624 \labelwidthstring 00.00.0000
8625
8626 \series bold
8627 -
8628 \begin_inset ERT
8629 status collapsed
8630
8631 \begin_layout Standard
8632
8633
8634 \backslash
8635 /
8636 \end_layout
8637
8638 \end_inset
8639
8640 -no-std-crt0
8641 \series default
8642
8643 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8644
8645 \end_inset
8646
8647  When linking, skip the standard crt0.o object file.
8648  You must provide your own crt0.o for your system when linking.
8649 \end_layout
8650
8651 \begin_layout List
8652 \labelwidthstring 00.00.0000
8653
8654 \series bold
8655 -
8656 \begin_inset ERT
8657 status collapsed
8658
8659 \begin_layout Standard
8660
8661
8662 \backslash
8663 /
8664 \end_layout
8665
8666 \end_inset
8667
8668 -portmode=
8669 \series default
8670 <Value>
8671 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8672
8673 \end_inset
8674
8675  Determinate PORT I/O mode (<Value> is z80 or z180).
8676 \end_layout
8677
8678 \begin_layout List
8679 \labelwidthstring 00.00.0000
8680
8681 \series bold
8682 -
8683 \begin_inset ERT
8684 status collapsed
8685
8686 \begin_layout Standard
8687
8688
8689 \backslash
8690 /
8691 \end_layout
8692
8693 \end_inset
8694
8695 -asm=
8696 \series default
8697 <Value>
8698 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8699
8700 \end_inset
8701
8702  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8703 \end_layout
8704
8705 \begin_layout List
8706 \labelwidthstring 00.00.0000
8707
8708 \series bold
8709 -
8710 \begin_inset ERT
8711 status collapsed
8712
8713 \begin_layout Standard
8714
8715
8716 \backslash
8717 /
8718 \end_layout
8719
8720 \end_inset
8721
8722 -codeseg
8723 \series default
8724 \InsetSpace ~
8725 <Value>
8726 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8727
8728 \end_inset
8729
8730  Use <Value> for the code segment name.
8731 \end_layout
8732
8733 \begin_layout List
8734 \labelwidthstring 00.00.0000
8735
8736 \series bold
8737 -
8738 \begin_inset ERT
8739 status collapsed
8740
8741 \begin_layout Standard
8742
8743
8744 \backslash
8745 /
8746 \end_layout
8747
8748 \end_inset
8749
8750 -constseg
8751 \series default
8752 \InsetSpace ~
8753 <Value>
8754 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8755
8756 \end_inset
8757
8758  Use <Value> for the const segment name.
8759 \end_layout
8760
8761 \begin_layout List
8762 \labelwidthstring 00.00.0000
8763 \begin_inset VSpace bigskip
8764 \end_inset
8765
8766
8767 \end_layout
8768
8769 \begin_layout Subsection
8770 GBZ80 Options
8771 \begin_inset LatexCommand \index{Options GBZ80}
8772
8773 \end_inset
8774
8775
8776 \begin_inset LatexCommand \index{GBZ80}
8777
8778 \end_inset
8779
8780
8781 \end_layout
8782
8783 \begin_layout List
8784 \labelwidthstring 00.00.0000
8785
8786 \series bold
8787 -
8788 \begin_inset ERT
8789 status collapsed
8790
8791 \begin_layout Standard
8792
8793
8794 \backslash
8795 /
8796 \end_layout
8797
8798 \end_inset
8799
8800 -callee-saves-bc
8801 \series default
8802
8803 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8804
8805 \end_inset
8806
8807
8808 \size large
8809 \emph on
8810  
8811 \size default
8812 \emph default
8813 Force a called function to always save BC.
8814 \end_layout
8815
8816 \begin_layout List
8817 \labelwidthstring 00.00.0000
8818
8819 \series bold
8820 -bo
8821 \series default
8822 \InsetSpace ~
8823 <Num>
8824 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8825
8826 \end_inset
8827
8828  Use code bank <Num>.
8829 \end_layout
8830
8831 \begin_layout List
8832 \labelwidthstring 00.00.0000
8833
8834 \series bold
8835 -ba
8836 \series default
8837 \InsetSpace ~
8838 <Num>
8839 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8840
8841 \end_inset
8842
8843  Use data bank <Num>.
8844 \end_layout
8845
8846 \begin_layout List
8847 \labelwidthstring 00.00.0000
8848
8849 \series bold
8850 -
8851 \begin_inset ERT
8852 status collapsed
8853
8854 \begin_layout Standard
8855
8856
8857 \backslash
8858 /
8859 \end_layout
8860
8861 \end_inset
8862
8863 -codeseg
8864 \series default
8865 \InsetSpace ~
8866 <Value>
8867 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8868
8869 \end_inset
8870
8871  Use <Value> for the code segment name.
8872 \end_layout
8873
8874 \begin_layout List
8875 \labelwidthstring 00.00.0000
8876
8877 \series bold
8878 -
8879 \begin_inset ERT
8880 status collapsed
8881
8882 \begin_layout Standard
8883
8884
8885 \backslash
8886 /
8887 \end_layout
8888
8889 \end_inset
8890
8891 -constseg
8892 \series default
8893 \InsetSpace ~
8894 <Value>
8895 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8896
8897 \end_inset
8898
8899  Use <Value> for the const segment name.
8900 \end_layout
8901
8902 \begin_layout Standard
8903 \begin_inset VSpace bigskip
8904 \end_inset
8905
8906
8907 \end_layout
8908
8909 \begin_layout Subsection
8910 Optimization Options
8911 \begin_inset LatexCommand \index{Options optimization}
8912
8913 \end_inset
8914
8915
8916 \begin_inset LatexCommand \index{Optimization options}
8917
8918 \end_inset
8919
8920
8921 \end_layout
8922
8923 \begin_layout List
8924 \labelwidthstring 00.00.0000
8925
8926 \series bold
8927 -
8928 \begin_inset ERT
8929 status collapsed
8930
8931 \begin_layout Standard
8932
8933
8934 \backslash
8935 /
8936 \end_layout
8937
8938 \end_inset
8939
8940 -nogcse
8941 \begin_inset LatexCommand \index{-\/-nogcse}
8942
8943 \end_inset
8944
8945
8946 \series default
8947  Will not do global subexpression elimination, this option may be used when
8948  the compiler creates undesirably large stack/data spaces to store compiler
8949  temporaries (
8950 \emph on
8951 s
8952 \emph default
8953 pill 
8954 \emph on
8955 loc
8956 \emph default
8957 ations, sloc
8958 \begin_inset LatexCommand \index{sloc (spill location)}
8959
8960 \end_inset
8961
8962 ).
8963  A warning message will be generated when this happens and the compiler
8964  will indicate the number of extra bytes it allocated.
8965  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8966 nogcse
8967 \begin_inset LatexCommand \index{\#pragma nogcse}
8968
8969 \end_inset
8970
8971  can be used to turn off global subexpression elimination
8972 \begin_inset LatexCommand \index{Subexpression elimination}
8973
8974 \end_inset
8975
8976  for a given function only.
8977 \end_layout
8978
8979 \begin_layout List
8980 \labelwidthstring 00.00.0000
8981
8982 \series bold
8983 -
8984 \begin_inset ERT
8985 status collapsed
8986
8987 \begin_layout Standard
8988
8989
8990 \backslash
8991 /
8992 \end_layout
8993
8994 \end_inset
8995
8996 -noinvariant
8997 \begin_inset LatexCommand \index{-\/-noinvariant}
8998
8999 \end_inset
9000
9001
9002 \series default
9003  Will not do loop invariant optimizations, this may be turned off for reasons
9004  explained for the previous option.
9005  For more details of loop optimizations performed see Loop Invariants in
9006  section 
9007 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9008
9009 \end_inset
9010
9011 .
9012  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9013 noinvariant
9014 \begin_inset LatexCommand \index{\#pragma noinvariant}
9015
9016 \end_inset
9017
9018  can be used to turn off invariant optimizations for a given function only.
9019 \end_layout
9020
9021 \begin_layout List
9022 \labelwidthstring 00.00.0000
9023
9024 \series bold
9025 -
9026 \begin_inset ERT
9027 status collapsed
9028
9029 \begin_layout Standard
9030
9031
9032 \backslash
9033 /
9034 \end_layout
9035
9036 \end_inset
9037
9038 -noinduction
9039 \begin_inset LatexCommand \index{-\/-noinduction}
9040
9041 \end_inset
9042
9043
9044 \series default
9045  Will not do loop induction optimizations, see section strength reduction
9046  for more details.
9047  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9048 noinduction
9049 \begin_inset LatexCommand \index{\#pragma noinduction}
9050
9051 \end_inset
9052
9053  can be used to turn off induction optimizations for a given function only.
9054 \end_layout
9055
9056 \begin_layout List
9057 \labelwidthstring 00.00.0000
9058
9059 \series bold
9060 -
9061 \begin_inset ERT
9062 status collapsed
9063
9064 \begin_layout Standard
9065
9066
9067 \backslash
9068 /
9069 \end_layout
9070
9071 \end_inset
9072
9073 -nojtbound
9074 \begin_inset LatexCommand \index{-\/-nojtbound}
9075
9076 \end_inset
9077
9078
9079 \size large
9080 \bar under
9081  
9082 \series default
9083 \size default
9084 \bar default
9085  Will not generate boundary condition check when switch statements
9086 \begin_inset LatexCommand \index{switch statement}
9087
9088 \end_inset
9089
9090  are implemented using jump-tables.
9091  See section 
9092 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9093
9094 \end_inset
9095
9096 \InsetSpace ~
9097 Switch Statements for more details.
9098  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9099 nojtbound
9100 \begin_inset LatexCommand \index{\#pragma nojtbound}
9101
9102 \end_inset
9103
9104  can be used to turn off boundary checking for jump tables for a given function
9105  only.
9106 \end_layout
9107
9108 \begin_layout List
9109 \labelwidthstring 00.00.0000
9110
9111 \series bold
9112 -
9113 \begin_inset ERT
9114 status collapsed
9115
9116 \begin_layout Standard
9117
9118
9119 \backslash
9120 /
9121 \end_layout
9122
9123 \end_inset
9124
9125 -noloopreverse
9126 \begin_inset LatexCommand \index{-\/-noloopreverse}
9127
9128 \end_inset
9129
9130
9131 \series default
9132 \size large
9133  
9134 \size default
9135 Will not do loop reversal 
9136 \begin_inset LatexCommand \index{Loop reversing}
9137
9138 \end_inset
9139
9140 optimization.
9141 \end_layout
9142
9143 \begin_layout List
9144 \labelwidthstring 00.00.0000
9145 -
9146 \begin_inset ERT
9147 status collapsed
9148
9149 \begin_layout Standard
9150
9151
9152 \backslash
9153 /
9154 \end_layout
9155
9156 \end_inset
9157
9158 -
9159 \series bold
9160 nolabelopt
9161 \series default
9162  
9163 \begin_inset LatexCommand \index{-\/-nolabelopt }
9164
9165 \end_inset
9166
9167 Will not optimize labels (makes the dumpfiles more readable).
9168 \end_layout
9169
9170 \begin_layout List
9171 \labelwidthstring 00.00.0000
9172
9173 \series bold
9174 -
9175 \begin_inset ERT
9176 status collapsed
9177
9178 \begin_layout Standard
9179
9180
9181 \backslash
9182 /
9183 \end_layout
9184
9185 \end_inset
9186
9187 -no-xinit-opt
9188 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9189
9190 \end_inset
9191
9192
9193 \series default
9194  Will not memcpy initialized data from code space into xdata space.
9195  This saves a few bytes in code space if you don't have initialized data
9196 \begin_inset LatexCommand \index{Variable initialization}
9197
9198 \end_inset
9199
9200 .
9201 \end_layout
9202
9203 \begin_layout List
9204 \labelwidthstring 00.00.0000
9205
9206 \series bold
9207 -
9208 \begin_inset ERT
9209 status collapsed
9210
9211 \begin_layout Standard
9212
9213
9214 \backslash
9215 /
9216 \end_layout
9217
9218 \end_inset
9219
9220 -nooverlay
9221 \begin_inset LatexCommand \index{-\/-nooverlay}
9222
9223 \end_inset
9224
9225
9226 \series default
9227   The compiler will not overlay parameters and local variables of any function,
9228  see section Parameters and local variables for more details.
9229 \end_layout
9230
9231 \begin_layout List
9232 \labelwidthstring 00.00.0000
9233
9234 \series bold
9235 -
9236 \begin_inset ERT
9237 status collapsed
9238
9239 \begin_layout Standard
9240
9241
9242 \backslash
9243 /
9244 \end_layout
9245
9246 \end_inset
9247
9248 -no-peep
9249 \begin_inset LatexCommand \index{-\/-no-peep}
9250
9251 \end_inset
9252
9253
9254 \series default
9255  Disable peep-hole optimization with built-in rules.
9256 \end_layout
9257
9258 \begin_layout List
9259 \labelwidthstring 00.00.0000
9260
9261 \series bold
9262 -
9263 \begin_inset ERT
9264 status collapsed
9265
9266 \begin_layout Standard
9267
9268
9269 \backslash
9270 /
9271 \end_layout
9272
9273 \end_inset
9274
9275 -peep-file
9276 \series default
9277
9278 \begin_inset LatexCommand \index{-\/-peep-file}
9279
9280 \end_inset
9281
9282 \InsetSpace ~
9283 <filename> This option can be used to use additional rules to be used by
9284  the peep hole optimizer.
9285  See section 
9286 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9287
9288 \end_inset
9289
9290 \InsetSpace ~
9291 Peep Hole optimizations for details on how to write these rules.
9292 \end_layout
9293
9294 \begin_layout List
9295 \labelwidthstring 00.00.0000
9296
9297 \series bold
9298 -
9299 \begin_inset ERT
9300 status collapsed
9301
9302 \begin_layout Standard
9303
9304
9305 \backslash
9306 /
9307 \end_layout
9308
9309 \end_inset
9310
9311 -peep-asm
9312 \begin_inset LatexCommand \index{-\/-peep-asm}
9313
9314 \end_inset
9315
9316
9317 \series default
9318  Pass the inline assembler code through the peep hole optimizer.
9319  This can cause unexpected changes to inline assembler code, please go through
9320  the peephole optimizer
9321 \begin_inset LatexCommand \index{Peephole optimizer}
9322
9323 \end_inset
9324
9325  rules defined in the source file tree '<target>/peeph.def' before using
9326  this option.
9327 \end_layout
9328
9329 \begin_layout List
9330 \labelwidthstring 00.00.0000
9331
9332 \series bold
9333 -
9334 \begin_inset ERT
9335 status collapsed
9336
9337 \begin_layout Standard
9338
9339
9340 \backslash
9341 /
9342 \end_layout
9343
9344 \end_inset
9345
9346 -opt-code-speed
9347 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9348
9349 \end_inset
9350
9351
9352 \series default
9353  The compiler will optimize code generation towards fast code, possibly
9354  at the expense of code size.
9355 \end_layout
9356
9357 \begin_layout List
9358 \labelwidthstring 00.00.0000
9359
9360 \series bold
9361 -
9362 \begin_inset ERT
9363 status collapsed
9364
9365 \begin_layout Standard
9366
9367
9368 \backslash
9369 /
9370 \end_layout
9371
9372 \end_inset
9373
9374 -opt-code-size
9375 \begin_inset LatexCommand \index{-\/-opt-code-size}
9376
9377 \end_inset
9378
9379
9380 \series default
9381  The compiler will optimize code generation towards compact code, possibly
9382  at the expense of code speed.
9383 \end_layout
9384
9385 \begin_layout Standard
9386 \begin_inset VSpace bigskip
9387 \end_inset
9388
9389
9390 \end_layout
9391
9392 \begin_layout Subsection
9393 Other Options
9394 \begin_inset LatexCommand \index{Options other}
9395
9396 \end_inset
9397
9398
9399 \end_layout
9400
9401 \begin_layout List
9402 \labelwidthstring 00.00.0000
9403
9404 \series bold
9405 -c\InsetSpace ~
9406 -
9407 \begin_inset ERT
9408 status collapsed
9409
9410 \begin_layout Standard
9411
9412
9413 \backslash
9414 /
9415 \end_layout
9416
9417 \end_inset
9418
9419 -compile-only
9420 \begin_inset LatexCommand \index{-\/-compile-only}
9421
9422 \end_inset
9423
9424
9425 \begin_inset LatexCommand \index{-c -\/-compile-only}
9426
9427 \end_inset
9428
9429
9430 \series default
9431  will compile and assemble the source, but will not call the linkage editor.
9432 \end_layout
9433
9434 \begin_layout List
9435 \labelwidthstring 00.00.0000
9436
9437 \series bold
9438 -
9439 \series default
9440
9441 \begin_inset ERT
9442 status collapsed
9443
9444 \begin_layout Standard
9445
9446
9447 \backslash
9448 /
9449 \end_layout
9450
9451 \end_inset
9452
9453
9454 \series bold
9455 -c1mode
9456 \begin_inset LatexCommand \index{-\/-c1mode}
9457
9458 \end_inset
9459
9460
9461 \series default
9462  reads the preprocessed source from standard input and compiles it.
9463  The file name for the assembler output must be specified using the -o option.
9464 \end_layout
9465
9466 \begin_layout List
9467 \labelwidthstring 00.00.0000
9468
9469 \series bold
9470 -E
9471 \begin_inset LatexCommand \index{-E}
9472
9473 \end_inset
9474
9475
9476 \series default
9477  Run only the C preprocessor.
9478  Preprocess all the C source files specified and output the results to standard
9479  output.
9480 \end_layout
9481
9482 \begin_layout List
9483 \labelwidthstring 00.00.0000
9484
9485 \series bold
9486 -o\InsetSpace ~
9487 <path/file>
9488 \begin_inset LatexCommand \index{-o <path/file>}
9489
9490 \end_inset
9491
9492  
9493 \series default
9494 The output path where everything will be placed or the file name used for
9495  all generated output files.
9496  If the parameter is a path, it must have a trailing slash (or backslash
9497  for the Windows binaries) to be recognized as a path.
9498
9499 \emph on
9500  
9501 \emph default
9502 Note for Windows users: if the path contains spaces, it should be surrounded
9503  by quotes.
9504  The trailing backslash should be doubled in order to prevent escaping the
9505  final quote, for example: 
9506 \emph on
9507 -o 
9508 \begin_inset Quotes sld
9509 \end_inset
9510
9511 F:
9512 \backslash
9513 Projects
9514 \backslash
9515 test3
9516 \backslash
9517 output 1
9518 \backslash
9519
9520 \backslash
9521
9522 \begin_inset Quotes srd
9523 \end_inset
9524
9525
9526 \emph default
9527  or put after the final quote, for example: 
9528 \emph on
9529 -o 
9530 \begin_inset Quotes sld
9531 \end_inset
9532
9533 F:
9534 \backslash
9535 Projects
9536 \backslash
9537 test3
9538 \backslash
9539 output 1
9540 \begin_inset Quotes srd
9541 \end_inset
9542
9543
9544 \backslash
9545
9546 \emph default
9547 .
9548  The path using slashes for directory delimiters can be used too, for example:
9549  
9550 \emph on
9551 -o 
9552 \begin_inset Quotes sld
9553 \end_inset
9554
9555 F:/Projects/test3/output 1/
9556 \begin_inset Quotes srd
9557 \end_inset
9558
9559
9560 \emph default
9561 .
9562 \end_layout
9563
9564 \begin_layout List
9565 \labelwidthstring 00.00.0000
9566
9567 \series bold
9568 -
9569 \begin_inset ERT
9570 status collapsed
9571
9572 \begin_layout Standard
9573
9574
9575 \backslash
9576 /
9577 \end_layout
9578
9579 \end_inset
9580
9581 -stack-auto
9582 \begin_inset LatexCommand \index{-\/-stack-auto}
9583
9584 \end_inset
9585
9586
9587 \series default
9588 \size large
9589 \emph on
9590  
9591 \size default
9592 \emph default
9593 All functions in the source file will be compiled as 
9594 \emph on
9595 reentrant
9596 \emph default
9597
9598 \begin_inset LatexCommand \index{reentrant}
9599
9600 \end_inset
9601
9602 , i.e.
9603  the parameters and local variables will be allocated on the stack
9604 \begin_inset LatexCommand \index{stack}
9605
9606 \end_inset
9607
9608 .
9609  See section 
9610 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9611
9612 \end_inset
9613
9614  Parameters and Local Variables for more details.
9615  If this option is used all source files in the project should be compiled
9616  with this option.
9617  It automatically implies -
9618 \series bold
9619
9620 \begin_inset ERT
9621 status open
9622
9623 \begin_layout Standard
9624
9625
9626 \backslash
9627 /
9628 \end_layout
9629
9630 \end_inset
9631
9632
9633 \series default
9634 -int-long-reent and -
9635 \series bold
9636
9637 \begin_inset ERT
9638 status open
9639
9640 \begin_layout Standard
9641
9642
9643 \backslash
9644 /
9645 \end_layout
9646
9647 \end_inset
9648
9649
9650 \series default
9651 -float-reent.
9652  
9653 \end_layout
9654
9655 \begin_layout List
9656 \labelwidthstring 00.00.0000
9657
9658 \series bold
9659 -
9660 \begin_inset ERT
9661 status collapsed
9662
9663 \begin_layout Standard
9664
9665
9666 \backslash
9667 /
9668 \end_layout
9669
9670 \end_inset
9671
9672 -callee-saves
9673 \begin_inset LatexCommand \index{-\/-callee-saves}
9674
9675 \end_inset
9676
9677  
9678 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9679
9680 \end_inset
9681
9682 function1[,function2][,function3]....
9683
9684 \series default
9685  The compiler by default uses a caller saves convention for register saving
9686  across function calls, however this can cause unnecessary register pushing
9687  and popping when calling small functions from larger functions.
9688  This option can be used to switch the register saving convention for the
9689  function names specified.
9690  The compiler will not save registers when calling these functions, no extra
9691  code will be generated at the entry and exit (function prologue
9692 \series bold
9693
9694 \begin_inset LatexCommand \index{function prologue}
9695
9696 \end_inset
9697
9698
9699 \series default
9700  and epilogue
9701 \series bold
9702
9703 \begin_inset LatexCommand \index{function epilogue}
9704
9705 \end_inset
9706
9707
9708 \series default
9709 ) for these functions to save and restore the registers used by these functions,
9710  this can SUBSTANTIALLY reduce code and improve run time performance of
9711  the generated code.
9712  In the future the compiler (with inter procedural analysis) will be able
9713  to determine the appropriate scheme to use for each function call.
9714  DO NOT use this option for built-in functions such as _mulint..., if this
9715  option is used for a library function the appropriate library function
9716  needs to be recompiled with the same option.
9717  If the project consists of multiple source files then all the source file
9718  should be compiled with the same -
9719 \begin_inset ERT
9720 status collapsed
9721
9722 \begin_layout Standard
9723
9724
9725 \backslash
9726 /
9727 \end_layout
9728
9729 \end_inset
9730
9731 -callee-saves option string.
9732  Also see #pragma\InsetSpace ~
9733 callee_saves 
9734 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9735
9736 \end_inset
9737
9738  
9739 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9740
9741 \end_inset
9742
9743 .
9744 \end_layout
9745
9746 \begin_layout List
9747 \labelwidthstring 00.00.0000
9748
9749 \series bold
9750 -
9751 \begin_inset ERT
9752 status collapsed
9753
9754 \begin_layout Standard
9755
9756
9757 \backslash
9758 /
9759 \end_layout
9760
9761 \end_inset
9762
9763 -all-callee-saves
9764 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9765
9766 \end_inset
9767
9768  
9769 \series default
9770 Function of
9771 \series bold
9772  
9773 \series default
9774 -
9775 \begin_inset ERT
9776 status collapsed
9777
9778 \begin_layout Standard
9779
9780
9781 \backslash
9782 /
9783 \end_layout
9784
9785 \end_inset
9786
9787 -callee-saves will be applied to all functions by default.
9788 \end_layout
9789
9790 \begin_layout List
9791 \labelwidthstring 00.00.0000
9792
9793 \series bold
9794 -
9795 \begin_inset ERT
9796 status collapsed
9797
9798 \begin_layout Standard
9799
9800
9801 \backslash
9802 /
9803 \end_layout
9804
9805 \end_inset
9806
9807 -debug
9808 \begin_inset LatexCommand \index{-\/-debug}
9809
9810 \end_inset
9811
9812
9813 \bar under
9814  
9815 \series default
9816 \bar default
9817 When this option is used the compiler will generate debug information.
9818  The debug information collected in a file with .cdb extension can be used
9819  with the SDCDB.
9820  For more information see documentation for SDCDB.
9821  Another file with no extension contains debug information in AOMF or AOMF51
9822 \begin_inset LatexCommand \index{AOMF, AOMF51}
9823
9824 \end_inset
9825
9826  format which is commonly used by third party tools.
9827 \end_layout
9828
9829 \begin_layout List
9830 \labelwidthstring 00.00.0000
9831
9832 \series bold
9833 -S
9834 \begin_inset LatexCommand \index{-S}
9835
9836 \end_inset
9837
9838
9839 \size large
9840 \bar under
9841  
9842 \series default
9843 \size default
9844 \bar default
9845 Stop after the stage of compilation proper; do not assemble.
9846  The output is an assembler code file for the input file specified.
9847 \end_layout
9848
9849 \begin_layout List
9850 \labelwidthstring 00.00.0000
9851
9852 \series bold
9853 -
9854 \begin_inset ERT
9855 status collapsed
9856
9857 \begin_layout Standard
9858
9859
9860 \backslash
9861 /
9862 \end_layout
9863
9864 \end_inset
9865
9866 -int-long-reent
9867 \begin_inset LatexCommand \index{-\/-int-long-reent}
9868
9869 \end_inset
9870
9871
9872 \series default
9873  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9874  Note by default these libraries are compiled as non-reentrant.
9875  See section Installation for more details.
9876 \end_layout
9877
9878 \begin_layout List
9879 \labelwidthstring 00.00.0000
9880
9881 \series bold
9882 -
9883 \begin_inset ERT
9884 status collapsed
9885
9886 \begin_layout Standard
9887
9888
9889 \backslash
9890 /
9891 \end_layout
9892
9893 \end_inset
9894
9895 -cyclomatic
9896 \begin_inset LatexCommand \index{-\/-cyclomatic}
9897
9898 \end_inset
9899
9900
9901 \bar under
9902  
9903 \series default
9904 \bar default
9905 This option will cause the compiler to generate an information message for
9906  each function in the source file.
9907  The message contains some 
9908 \emph on
9909 important
9910 \emph default
9911  information about the function.
9912  The number of edges and nodes the compiler detected in the control flow
9913  graph of the function, and most importantly the 
9914 \emph on
9915 cyclomatic complexity
9916 \begin_inset LatexCommand \index{Cyclomatic complexity}
9917
9918 \end_inset
9919
9920
9921 \emph default
9922  see section on Cyclomatic Complexity for more details.
9923 \end_layout
9924
9925 \begin_layout List
9926 \labelwidthstring 00.00.0000
9927
9928 \series bold
9929 -
9930 \begin_inset ERT
9931 status collapsed
9932
9933 \begin_layout Standard
9934
9935
9936 \backslash
9937 /
9938 \end_layout
9939
9940 \end_inset
9941
9942 -float-reent
9943 \begin_inset LatexCommand \index{-\/-float-reent}
9944
9945 \end_inset
9946
9947
9948 \series default
9949  Floating point library is compiled as reentrant
9950 \begin_inset LatexCommand \index{reentrant}
9951
9952 \end_inset
9953
9954 .
9955  See section Installation for more details.
9956 \end_layout
9957
9958 \begin_layout List
9959 \labelwidthstring 00.00.0000
9960
9961 \series bold
9962 -
9963 \begin_inset ERT
9964 status collapsed
9965
9966 \begin_layout Standard
9967
9968
9969 \backslash
9970 /
9971 \end_layout
9972
9973 \end_inset
9974
9975 -funsigned-char
9976 \begin_inset LatexCommand \index{-\/-funsigned-char}
9977
9978 \end_inset
9979
9980
9981 \series default
9982  The default signedness for every type is
9983 \family typewriter
9984  signed
9985 \family default
9986 .
9987  In some embedded environments the default signedness of
9988 \family typewriter
9989  char
9990 \family default
9991  is
9992 \family typewriter
9993  unsigned
9994 \family default
9995 .
9996  To set the signess for characters to unsigned, use the option -
9997 \series bold
9998
9999 \begin_inset ERT
10000 status open
10001
10002 \begin_layout Standard
10003
10004
10005 \backslash
10006 /
10007 \end_layout
10008
10009 \end_inset
10010
10011
10012 \series default
10013 -funsigned-char.
10014  If this option is set and no signedness keyword (unsigned/signed) is given,
10015  a char will be signed.
10016  All other types are unaffected.
10017 \end_layout
10018
10019 \begin_layout List
10020 \labelwidthstring 00.00.0000
10021
10022 \series bold
10023 -
10024 \begin_inset ERT
10025 status collapsed
10026
10027 \begin_layout Standard
10028
10029
10030 \backslash
10031 /
10032 \end_layout
10033
10034 \end_inset
10035
10036 -main-return
10037 \begin_inset LatexCommand \index{-\/-main-return}
10038
10039 \end_inset
10040
10041
10042 \series default
10043  This option can be used if the code generated is called by a monitor program
10044  or if the main routine includes an endless loop.
10045  This option results in slightly smaller code and saves two bytes of stack
10046  space.
10047  The return from the 'main'
10048 \begin_inset LatexCommand \index{main return}
10049
10050 \end_inset
10051
10052  function will return to the function calling main.
10053  The default setting is to lock up i.e.
10054  generate a '
10055 \family typewriter
10056 sjmp .
10057 \family default
10058 '.
10059 \end_layout
10060
10061 \begin_layout List
10062 \labelwidthstring 00.00.0000
10063
10064 \series bold
10065 -
10066 \begin_inset ERT
10067 status collapsed
10068
10069 \begin_layout Standard
10070
10071
10072 \backslash
10073 /
10074 \end_layout
10075
10076 \end_inset
10077
10078 -nostdinc
10079 \begin_inset LatexCommand \index{-\/-nostdinc}
10080
10081 \end_inset
10082
10083
10084 \series default
10085  This will prevent the compiler from passing on the default include path
10086  to the preprocessor.
10087 \end_layout
10088
10089 \begin_layout List
10090 \labelwidthstring 00.00.0000
10091
10092 \series bold
10093 -
10094 \begin_inset ERT
10095 status collapsed
10096
10097 \begin_layout Standard
10098
10099
10100 \backslash
10101 /
10102 \end_layout
10103
10104 \end_inset
10105
10106 -nostdlib
10107 \begin_inset LatexCommand \index{-\/-nostdlib}
10108
10109 \end_inset
10110
10111
10112 \series default
10113  This will prevent the compiler from passing on the default library
10114 \begin_inset LatexCommand \index{Libraries}
10115
10116 \end_inset
10117
10118  path to the linker.
10119 \end_layout
10120
10121 \begin_layout List
10122 \labelwidthstring 00.00.0000
10123
10124 \series bold
10125 -
10126 \begin_inset ERT
10127 status collapsed
10128
10129 \begin_layout Standard
10130
10131
10132 \backslash
10133 /
10134 \end_layout
10135
10136 \end_inset
10137
10138 -verbose
10139 \begin_inset LatexCommand \index{-\/-verbose}
10140
10141 \end_inset
10142
10143
10144 \series default
10145  Shows the various actions the compiler is performing.
10146 \end_layout
10147
10148 \begin_layout List
10149 \labelwidthstring 00.00.0000
10150
10151 \series bold
10152 -V
10153 \begin_inset LatexCommand \index{-V}
10154
10155 \end_inset
10156
10157
10158 \series default
10159  Shows the actual commands the compiler is executing.
10160 \end_layout
10161
10162 \begin_layout List
10163 \labelwidthstring 00.00.0000
10164
10165 \series bold
10166 -
10167 \begin_inset ERT
10168 status collapsed
10169
10170 \begin_layout Standard
10171
10172
10173 \backslash
10174 /
10175 \end_layout
10176
10177 \end_inset
10178
10179 -no-c-code-in-asm
10180 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10181
10182 \end_inset
10183
10184
10185 \series default
10186  Hides your ugly and inefficient c-code from the asm file, so you can always
10187  blame the compiler :)
10188 \end_layout
10189
10190 \begin_layout List
10191 \labelwidthstring 00.00.0000
10192
10193 \series bold
10194 -
10195 \begin_inset ERT
10196 status collapsed
10197
10198 \begin_layout Standard
10199
10200
10201 \backslash
10202 /
10203 \end_layout
10204
10205 \end_inset
10206
10207 -fverbose-asm
10208 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10209
10210 \end_inset
10211
10212
10213 \series default
10214  Include code generator and peep-hole comments in the generated asm files.
10215 \end_layout
10216
10217 \begin_layout List
10218 \labelwidthstring 00.00.0000
10219
10220 \series bold
10221 -
10222 \begin_inset ERT
10223 status collapsed
10224
10225 \begin_layout Standard
10226
10227
10228 \backslash
10229 /
10230 \end_layout
10231
10232 \end_inset
10233
10234 -no-peep-comments
10235 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10236
10237 \end_inset
10238
10239
10240 \series default
10241  Don't include peep-hole comments in the generated asm files even if -
10242 \series bold
10243
10244 \begin_inset ERT
10245 status open
10246
10247 \begin_layout Standard
10248
10249
10250 \backslash
10251 /
10252 \end_layout
10253
10254 \end_inset
10255
10256
10257 \series default
10258 -fverbose-asm option is specified.
10259 \end_layout
10260
10261 \begin_layout List
10262 \labelwidthstring 00.00.0000
10263
10264 \series bold
10265 -
10266 \begin_inset ERT
10267 status collapsed
10268
10269 \begin_layout Standard
10270
10271
10272 \backslash
10273 /
10274 \end_layout
10275
10276 \end_inset
10277
10278 -i-code-in-asm
10279 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10280
10281 \end_inset
10282
10283
10284 \series default
10285  Include i-codes in the asm file.
10286  Sounds like noise but is most helpful for debugging the compiler itself.
10287 \end_layout
10288
10289 \begin_layout List
10290 \labelwidthstring 00.00.0000
10291
10292 \series bold
10293 -
10294 \begin_inset ERT
10295 status collapsed
10296
10297 \begin_layout Standard
10298
10299
10300 \backslash
10301 /
10302 \end_layout
10303
10304 \end_inset
10305
10306 -less-pedantic
10307 \begin_inset LatexCommand \index{pedantic}
10308
10309 \end_inset
10310
10311
10312 \begin_inset LatexCommand \index{-\/-less-pedantic}
10313
10314 \end_inset
10315
10316
10317 \series default
10318
10319 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10320
10321 \end_inset
10322
10323  Disable some of the more pedantic warnings
10324 \begin_inset LatexCommand \index{Warnings}
10325
10326 \end_inset
10327
10328 .
10329  For more details, see the less_pedantic pragma 
10330 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10331
10332 \end_inset
10333
10334 .
10335 \end_layout
10336
10337 \begin_layout List
10338 \labelwidthstring 00.00.0000
10339
10340 \series bold
10341 -
10342 \begin_inset ERT
10343 status collapsed
10344
10345 \begin_layout Standard
10346
10347
10348 \backslash
10349 /
10350 \end_layout
10351
10352 \end_inset
10353
10354 -disable-warning\InsetSpace ~
10355 <nnnn>
10356 \begin_inset LatexCommand \index{-\/-disable-warning}
10357
10358 \end_inset
10359
10360
10361 \series default
10362  Disable specific warning with number <nnnn>.
10363 \end_layout
10364
10365 \begin_layout List
10366 \labelwidthstring 00.00.0000
10367
10368 \series bold
10369 -
10370 \begin_inset ERT
10371 status collapsed
10372
10373 \begin_layout Standard
10374
10375
10376 \backslash
10377 /
10378 \end_layout
10379
10380 \end_inset
10381
10382 -print-search-dirs
10383 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10384
10385 \end_inset
10386
10387
10388 \series default
10389  Display the directories in the compiler's search path
10390 \end_layout
10391
10392 \begin_layout List
10393 \labelwidthstring 00.00.0000
10394
10395 \series bold
10396 -
10397 \begin_inset ERT
10398 status collapsed
10399
10400 \begin_layout Standard
10401
10402
10403 \backslash
10404 /
10405 \end_layout
10406
10407 \end_inset
10408
10409 -vc
10410 \begin_inset LatexCommand \index{-\/-vc}
10411
10412 \end_inset
10413
10414
10415 \series default
10416  Display errors and warnings using MSVC style, so you can use SDCC with
10417  the visual studio IDE
10418 \begin_inset LatexCommand \index{IDE}
10419
10420 \end_inset
10421
10422 .
10423  With SDCC both offering a GCC-like (the default) and a MSVC-like
10424 \begin_inset LatexCommand \index{MSVC output style}
10425
10426 \end_inset
10427
10428  output style, integration into most programming editors should be straightforwa
10429 rd.
10430 \end_layout
10431
10432 \begin_layout List
10433 \labelwidthstring 00.00.0000
10434
10435 \series bold
10436 -
10437 \begin_inset ERT
10438 status collapsed
10439
10440 \begin_layout Standard
10441
10442
10443 \backslash
10444 /
10445 \end_layout
10446
10447 \end_inset
10448
10449 -use-stdout
10450 \begin_inset LatexCommand \index{-\/-use-stdout}
10451
10452 \end_inset
10453
10454
10455 \series default
10456  Send errors and warnings to stdout instead of stderr.
10457 \end_layout
10458
10459 \begin_layout List
10460 \labelwidthstring 00.00.0000
10461
10462 \series bold
10463 -Wa\InsetSpace ~
10464 asmOption[,asmOption]
10465 \series default
10466
10467 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10468
10469 \end_inset
10470
10471 ...
10472  Pass the asmOption to the assembler
10473 \begin_inset LatexCommand \index{Options assembler}
10474
10475 \end_inset
10476
10477
10478 \begin_inset LatexCommand \index{Assembler options}
10479
10480 \end_inset
10481
10482 .
10483  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10484 \end_layout
10485
10486 \begin_layout List
10487 \labelwidthstring 00.00.0000
10488
10489 \series bold
10490 -
10491 \begin_inset ERT
10492 status collapsed
10493
10494 \begin_layout Standard
10495
10496
10497 \backslash
10498 /
10499 \end_layout
10500
10501 \end_inset
10502
10503 -std-sdcc89
10504 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10505
10506 \end_inset
10507
10508
10509 \series default
10510  Generally follow the C89 standard, but allow SDCC features that conflict
10511  with the standard (default).
10512 \end_layout
10513
10514 \begin_layout List
10515 \labelwidthstring 00.00.0000
10516
10517 \series bold
10518 -
10519 \begin_inset ERT
10520 status collapsed
10521
10522 \begin_layout Standard
10523
10524
10525 \backslash
10526 /
10527 \end_layout
10528
10529 \end_inset
10530
10531 -std-c89
10532 \begin_inset LatexCommand \index{-\/-std-c89}
10533
10534 \end_inset
10535
10536
10537 \series default
10538  Follow the C89 standard and disable SDCC features that conflict with the
10539  standard.
10540 \end_layout
10541
10542 \begin_layout List
10543 \labelwidthstring 00.00.0000
10544
10545 \series bold
10546 -
10547 \begin_inset ERT
10548 status collapsed
10549
10550 \begin_layout Standard
10551
10552
10553 \backslash
10554 /
10555 \end_layout
10556
10557 \end_inset
10558
10559 -std-sdcc99
10560 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10561
10562 \end_inset
10563
10564
10565 \series default
10566  Generally follow the C99 standard, but allow SDCC features that conflict
10567  with the standard (incomplete support).
10568 \end_layout
10569
10570 \begin_layout List
10571 \labelwidthstring 00.00.0000
10572
10573 \series bold
10574 -
10575 \begin_inset ERT
10576 status collapsed
10577
10578 \begin_layout Standard
10579
10580
10581 \backslash
10582 /
10583 \end_layout
10584
10585 \end_inset
10586
10587 -std-c99
10588 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10589
10590 \end_inset
10591
10592
10593 \series default
10594  Follow the C99 standard and disable SDCC features that conflict with the
10595  standard (incomplete support).
10596 \end_layout
10597
10598 \begin_layout List
10599 \labelwidthstring 00.00.0000
10600
10601 \series bold
10602 -
10603 \begin_inset ERT
10604 status collapsed
10605
10606 \begin_layout Standard
10607
10608
10609 \backslash
10610 /
10611 \end_layout
10612
10613 \end_inset
10614
10615 -codeseg
10616 \series default
10617
10618 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10619
10620 \end_inset
10621
10622 \InsetSpace ~
10623 <Name> The name to be used for the code
10624 \begin_inset LatexCommand \index{code}
10625
10626 \end_inset
10627
10628  segment, default CSEG.
10629  This is useful if you need to tell the compiler to put the code in a special
10630  segment so you can later on tell the linker to put this segment in a special
10631  place in memory.
10632  Can be used for instance when using bank switching to put the code in a
10633  bank.
10634 \end_layout
10635
10636 \begin_layout List
10637 \labelwidthstring 00.00.0000
10638
10639 \series bold
10640 -
10641 \begin_inset ERT
10642 status collapsed
10643
10644 \begin_layout Standard
10645
10646
10647 \backslash
10648 /
10649 \end_layout
10650
10651 \end_inset
10652
10653 -constseg
10654 \series default
10655
10656 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10657
10658 \end_inset
10659
10660 \InsetSpace ~
10661 <Name> The name to be used for the const
10662 \begin_inset LatexCommand \index{const}
10663
10664 \end_inset
10665
10666  segment, default CONST.
10667  This is useful if you need to tell the compiler to put the const data in
10668  a special segment so you can later on tell the linker to put this segment
10669  in a special place in memory.
10670  Can be used for instance when using bank switching to put the const data
10671  in a bank.
10672 \end_layout
10673
10674 \begin_layout List
10675 \labelwidthstring 00.00.0000
10676
10677 \series bold
10678 -
10679 \begin_inset ERT
10680 status collapsed
10681
10682 \begin_layout Standard
10683
10684
10685 \backslash
10686 /
10687 \end_layout
10688
10689 \end_inset
10690
10691 -fdollars-in-identifiers
10692 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10693
10694 \end_inset
10695
10696
10697 \series default
10698  Permit '$' as an identifier character.
10699 \end_layout
10700
10701 \begin_layout List
10702 \labelwidthstring 00.00.0000
10703
10704 \series bold
10705 -
10706 \begin_inset ERT
10707 status collapsed
10708
10709 \begin_layout Standard
10710
10711
10712 \backslash
10713 /
10714 \end_layout
10715
10716 \end_inset
10717
10718 -more-pedantic
10719 \series default
10720
10721 \begin_inset LatexCommand \index{-\/-more-pedantic}
10722
10723 \end_inset
10724
10725
10726 \begin_inset LatexCommand \index{pedantic}
10727
10728 \end_inset
10729
10730  Actually this is 
10731 \series bold
10732 \emph on
10733 not
10734 \series default
10735 \emph default
10736  a SDCC compiler option but if you want 
10737 \emph on
10738 more
10739 \emph default
10740  warnings you can use a separate tool dedicated to syntax checking like
10741  splint
10742 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10743
10744 \end_inset
10745
10746
10747 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10748
10749 \end_inset
10750
10751  
10752 \begin_inset LatexCommand \url{http://www.splint.org}
10753
10754 \end_inset
10755
10756 .
10757  To make your source files parseable by splint you will have to include
10758  
10759 \family sans
10760 lint.h
10761 \family default
10762
10763 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10764
10765 \end_inset
10766
10767  in your source file and add brackets around extended keywords (like 
10768 \family sans
10769
10770 \begin_inset Quotes sld
10771 \end_inset
10772
10773 __at\InsetSpace ~
10774
10775 \series bold
10776 (
10777 \series default
10778 0xab
10779 \series bold
10780 )
10781 \series default
10782
10783 \begin_inset Quotes srd
10784 \end_inset
10785
10786
10787 \family default
10788  and 
10789 \family sans
10790
10791 \begin_inset Quotes sld
10792 \end_inset
10793
10794 __interrupt\InsetSpace ~
10795 (2)
10796 \begin_inset Quotes srd
10797 \end_inset
10798
10799
10800 \family default
10801 ).
10802  
10803 \newline
10804 Splint has an excellent on line manual at 
10805 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10806
10807 \end_inset
10808
10809  and it's capabilities go beyond pure syntax checking.
10810  You'll need to tell splint the location of SDCC's include files so a typical
10811  command line could look like this: 
10812 \newline
10813
10814 \family sans
10815 splint\InsetSpace ~
10816 -I\InsetSpace ~
10817 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10818 \InsetSpace ~
10819 myprogram.c
10820 \end_layout
10821
10822 \begin_layout List
10823 \labelwidthstring 00.00.0000
10824
10825 \series bold
10826 -
10827 \begin_inset ERT
10828 status collapsed
10829
10830 \begin_layout Standard
10831
10832
10833 \backslash
10834 /
10835 \end_layout
10836
10837 \end_inset
10838
10839 -short-is-8bits
10840 \series default
10841
10842 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10843
10844 \end_inset
10845
10846
10847 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10848
10849 \end_inset
10850
10851  Treat short as 8-bit (for backward compatibility with older versions of
10852  compiler - see section 
10853 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10854
10855 \end_inset
10856
10857 )
10858 \end_layout
10859
10860 \begin_layout Standard
10861 \begin_inset VSpace bigskip
10862 \end_inset
10863
10864
10865 \end_layout
10866
10867 \begin_layout Subsection
10868 Intermediate Dump Options
10869 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10870
10871 \end_inset
10872
10873
10874 \begin_inset LatexCommand \index{Options intermediate dump}
10875
10876 \end_inset
10877
10878
10879 \begin_inset LatexCommand \index{Intermediate dump options}
10880
10881 \end_inset
10882
10883
10884 \end_layout
10885
10886 \begin_layout Standard
10887 The following options are provided for the purpose of retargetting and debugging
10888  the compiler.
10889  They provide a means to dump the intermediate code (iCode
10890 \begin_inset LatexCommand \index{iCode}
10891
10892 \end_inset
10893
10894 ) generated by the compiler in human readable form at various stages of
10895  the compilation process.
10896  More on iCodes see chapter 
10897 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10898
10899 \end_inset
10900
10901  
10902 \begin_inset Quotes srd
10903 \end_inset
10904
10905 The anatomy of the compiler
10906 \begin_inset Quotes srd
10907 \end_inset
10908
10909 .
10910 \end_layout
10911
10912 \begin_layout List
10913 \labelwidthstring 00.00.0000
10914
10915 \series bold
10916 -
10917 \begin_inset ERT
10918 status collapsed
10919
10920 \begin_layout Standard
10921
10922
10923 \backslash
10924 /
10925 \end_layout
10926
10927 \end_inset
10928
10929 -dumpraw
10930 \begin_inset LatexCommand \index{-\/-dumpraw}
10931
10932 \end_inset
10933
10934
10935 \series default
10936  This option will cause the compiler to dump the intermediate code into
10937  a file of named 
10938 \emph on
10939 <source filename>.dumpraw
10940 \emph default
10941  just after the intermediate code has been generated for a function, i.e.
10942  before any optimizations are done.
10943  The basic blocks
10944 \begin_inset LatexCommand \index{Basic blocks}
10945
10946 \end_inset
10947
10948  at this stage ordered in the depth first number, so they may not be in
10949  sequence of execution.
10950 \end_layout
10951
10952 \begin_layout List
10953 \labelwidthstring 00.00.0000
10954
10955 \series bold
10956 -
10957 \begin_inset ERT
10958 status collapsed
10959
10960 \begin_layout Standard
10961
10962
10963 \backslash
10964 /
10965 \end_layout
10966
10967 \end_inset
10968
10969 -dumpgcse
10970 \begin_inset LatexCommand \index{-\/-dumpgcse}
10971
10972 \end_inset
10973
10974
10975 \series default
10976  Will create a dump of iCodes, after global subexpression elimination
10977 \begin_inset LatexCommand \index{Global subexpression elimination}
10978
10979 \end_inset
10980
10981 , into a file named 
10982 \emph on
10983 <source filename>.dumpgcse.
10984 \end_layout
10985
10986 \begin_layout List
10987 \labelwidthstring 00.00.0000
10988
10989 \series bold
10990 -
10991 \begin_inset ERT
10992 status collapsed
10993
10994 \begin_layout Standard
10995
10996
10997 \backslash
10998 /
10999 \end_layout
11000
11001 \end_inset
11002
11003 -dumpdeadcode
11004 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11005
11006 \end_inset
11007
11008
11009 \series default
11010  Will create a dump of iCodes, after deadcode elimination
11011 \begin_inset LatexCommand \index{Dead-code elimination}
11012
11013 \end_inset
11014
11015 , into a file named 
11016 \emph on
11017 <source filename>.dumpdeadcode.
11018 \end_layout
11019
11020 \begin_layout List
11021 \labelwidthstring 00.00.0000
11022
11023 \series bold
11024 -
11025 \begin_inset ERT
11026 status collapsed
11027
11028 \begin_layout Standard
11029
11030
11031 \backslash
11032 /
11033 \end_layout
11034
11035 \end_inset
11036
11037 -dumploop
11038 \begin_inset LatexCommand \index{-\/-dumploop}
11039
11040 \end_inset
11041
11042
11043 \series default
11044 \size large
11045  
11046 \size default
11047 Will create a dump of iCodes, after loop optimizations
11048 \begin_inset LatexCommand \index{Loop optimization}
11049
11050 \end_inset
11051
11052 , into a file named 
11053 \emph on
11054 <source filename>.dumploop.
11055 \end_layout
11056
11057 \begin_layout List
11058 \labelwidthstring 00.00.0000
11059
11060 \series bold
11061 -
11062 \begin_inset ERT
11063 status collapsed
11064
11065 \begin_layout Standard
11066
11067
11068 \backslash
11069 /
11070 \end_layout
11071
11072 \end_inset
11073
11074 -dumprange
11075 \begin_inset LatexCommand \index{-\/-dumprange}
11076
11077 \end_inset
11078
11079
11080 \series default
11081 \size large
11082  
11083 \size default
11084 Will create a dump of iCodes, after live range analysis
11085 \begin_inset LatexCommand \index{Live range analysis}
11086
11087 \end_inset
11088
11089 , into a file named 
11090 \emph on
11091 <source filename>.dumprange.
11092 \end_layout
11093
11094 \begin_layout List
11095 \labelwidthstring 00.00.0000
11096
11097 \series bold
11098 -
11099 \begin_inset ERT
11100 status collapsed
11101
11102 \begin_layout Standard
11103
11104
11105 \backslash
11106 /
11107 \end_layout
11108
11109 \end_inset
11110
11111 -dumlrange
11112 \begin_inset LatexCommand \index{-\/-dumlrange}
11113
11114 \end_inset
11115
11116
11117 \series default
11118  Will dump the life ranges
11119 \begin_inset LatexCommand \index{Live range analysis}
11120
11121 \end_inset
11122
11123  for all symbols.
11124 \end_layout
11125
11126 \begin_layout List
11127 \labelwidthstring 00.00.0000
11128
11129 \series bold
11130 -
11131 \begin_inset ERT
11132 status collapsed
11133
11134 \begin_layout Standard
11135
11136
11137 \backslash
11138 /
11139 \end_layout
11140
11141 \end_inset
11142
11143 -dumpregassign
11144 \begin_inset LatexCommand \index{-\/-dumpregassign}
11145
11146 \end_inset
11147
11148
11149 \bar under
11150  
11151 \series default
11152 \bar default
11153 Will create a dump of iCodes, after register assignment
11154 \begin_inset LatexCommand \index{Register assignment}
11155
11156 \end_inset
11157
11158 , into a file named 
11159 \emph on
11160 <source filename>.dumprassgn.
11161 \end_layout
11162
11163 \begin_layout List
11164 \labelwidthstring 00.00.0000
11165
11166 \series bold
11167 -
11168 \begin_inset ERT
11169 status collapsed
11170
11171 \begin_layout Standard
11172
11173
11174 \backslash
11175 /
11176 \end_layout
11177
11178 \end_inset
11179
11180 -dumplrange
11181 \begin_inset LatexCommand \index{-\/-dumplrange}
11182
11183 \end_inset
11184
11185
11186 \series default
11187  Will create a dump of the live ranges of iTemp's
11188 \end_layout
11189
11190 \begin_layout List
11191 \labelwidthstring 00.00.0000
11192
11193 \series bold
11194 -
11195 \begin_inset ERT
11196 status collapsed
11197
11198 \begin_layout Standard
11199
11200
11201 \backslash
11202 /
11203 \end_layout
11204
11205 \end_inset
11206
11207 -dumpall
11208 \begin_inset LatexCommand \index{-\/-dumpall}
11209
11210 \end_inset
11211
11212
11213 \size large
11214 \bar under
11215  
11216 \series default
11217 \size default
11218 \bar default
11219 Will cause all the above mentioned dumps to be created.
11220 \end_layout
11221
11222 \begin_layout Standard
11223 \begin_inset VSpace bigskip
11224 \end_inset
11225
11226
11227 \end_layout
11228
11229 \begin_layout Subsection
11230 Redirecting output on Windows Shells
11231 \end_layout
11232
11233 \begin_layout Standard
11234 By default SDCC writes its error messages to 
11235 \begin_inset Quotes sld
11236 \end_inset
11237
11238 standard error
11239 \begin_inset Quotes srd
11240 \end_inset
11241
11242 .
11243  To force all messages to 
11244 \begin_inset Quotes sld
11245 \end_inset
11246
11247 standard output
11248 \begin_inset Quotes srd
11249 \end_inset
11250
11251  use 
11252 \series bold
11253 -
11254 \series default
11255 \emph on
11256
11257 \begin_inset ERT
11258 status collapsed
11259
11260 \begin_layout Standard
11261
11262
11263 \backslash
11264 /
11265 \end_layout
11266
11267 \end_inset
11268
11269
11270 \series bold
11271 \emph default
11272 -
11273 \series default
11274 use-stdout
11275 \begin_inset LatexCommand \index{-\/-use-stdout}
11276
11277 \end_inset
11278
11279 .
11280  Additionally, if you happen to have visual studio installed in your windows
11281  machine, you can use it to compile your sources using a custom build and
11282  the SDCC -
11283 \emph on
11284
11285 \begin_inset ERT
11286 status collapsed
11287
11288 \begin_layout Standard
11289
11290
11291 \backslash
11292 /
11293 \end_layout
11294
11295 \end_inset
11296
11297
11298 \emph default
11299 -vc
11300 \begin_inset LatexCommand \index{-\/-vc}
11301
11302 \end_inset
11303
11304  option.
11305  Something like this should work:
11306 \newline
11307
11308 \newline
11309
11310 \series bold
11311 c:
11312 \backslash
11313 sdcc
11314 \backslash
11315 bin
11316 \backslash
11317 sdcc.exe -
11318 \series default
11319 \emph on
11320
11321 \begin_inset ERT
11322 status collapsed
11323
11324 \begin_layout Standard
11325
11326
11327 \backslash
11328 /
11329 \end_layout
11330
11331 \end_inset
11332
11333
11334 \series bold
11335 \emph default
11336 -vc -
11337 \series default
11338 \emph on
11339
11340 \begin_inset ERT
11341 status collapsed
11342
11343 \begin_layout Standard
11344
11345
11346 \backslash
11347 /
11348 \end_layout
11349
11350 \end_inset
11351
11352
11353 \series bold
11354 \emph default
11355 -model-large -c $(InputPath)
11356 \series default
11357
11358 \begin_inset VSpace bigskip
11359 \end_inset
11360
11361
11362 \end_layout
11363
11364 \begin_layout Section
11365 Environment variables
11366 \begin_inset LatexCommand \index{Environment variables}
11367
11368 \end_inset
11369
11370
11371 \end_layout
11372
11373 \begin_layout Standard
11374 SDCC recognizes the following environment variables:
11375 \end_layout
11376
11377 \begin_layout List
11378 \labelwidthstring 00.00.0000
11379
11380 \series bold
11381 SDCC_LEAVE_SIGNALS
11382 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11383
11384 \end_inset
11385
11386
11387 \series default
11388  SDCC installs a signal handler
11389 \begin_inset LatexCommand \index{signal handler}
11390
11391 \end_inset
11392
11393  to be able to delete temporary files after an user break (^C) or an exception.
11394  If this environment variable is set, SDCC won't install the signal handler
11395  in order to be able to debug SDCC.
11396 \end_layout
11397
11398 \begin_layout List
11399 \labelwidthstring 00.00.0000
11400
11401 \series bold
11402 TMP,\InsetSpace ~
11403 TEMP,\InsetSpace ~
11404 TMPDIR
11405 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11406
11407 \end_inset
11408
11409
11410 \series default
11411  Path, where temporary files will be created.
11412  The order of the variables is the search order.
11413  In a standard *nix environment these variables are not set, and there's
11414  no need to set them.
11415  On Windows it's recommended to set one of them.
11416 \end_layout
11417
11418 \begin_layout List
11419 \labelwidthstring 00.00.0000
11420
11421 \series bold
11422 SDCC_HOME
11423 \begin_inset LatexCommand \index{SDCC\_HOME}
11424
11425 \end_inset
11426
11427
11428 \series default
11429  Path, see section 
11430 \begin_inset LatexCommand \ref{sub:Install-paths}
11431
11432 \end_inset
11433
11434 \InsetSpace ~
11435
11436 \begin_inset Quotes sld
11437 \end_inset
11438
11439  Install Paths
11440 \begin_inset Quotes srd
11441 \end_inset
11442
11443 .
11444 \end_layout
11445
11446 \begin_layout List
11447 \labelwidthstring 00.00.0000
11448
11449 \series bold
11450 SDCC_INCLUDE
11451 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11452
11453 \end_inset
11454
11455
11456 \series default
11457  Path, see section 
11458 \begin_inset LatexCommand \ref{sub:Search-Paths}
11459
11460 \end_inset
11461
11462 \InsetSpace ~
11463
11464 \begin_inset Quotes sld
11465 \end_inset
11466
11467 Search Paths
11468 \begin_inset Quotes srd
11469 \end_inset
11470
11471 .
11472 \end_layout
11473
11474 \begin_layout List
11475 \labelwidthstring 00.00.0000
11476
11477 \series bold
11478 SDCC_LIB
11479 \begin_inset LatexCommand \index{SDCC\_LIB}
11480
11481 \end_inset
11482
11483
11484 \series default
11485  Path, see section 
11486 \begin_inset LatexCommand \ref{sub:Search-Paths}
11487
11488 \end_inset
11489
11490 \InsetSpace ~
11491
11492 \begin_inset Quotes sld
11493 \end_inset
11494
11495 Search Paths
11496 \begin_inset Quotes srd
11497 \end_inset
11498
11499 ..
11500 \end_layout
11501
11502 \begin_layout Standard
11503 There are some more environment variables recognized by SDCC, but these
11504  are solely used for debugging purposes.
11505  They can change or disappear very quickly, and will never be documented.
11506 \begin_inset VSpace bigskip
11507 \end_inset
11508
11509
11510 \end_layout
11511
11512 \begin_layout Section
11513 Storage Class Language Extensions
11514 \end_layout
11515
11516 \begin_layout Subsection
11517 MCS51/DS390 Storage Class
11518 \begin_inset LatexCommand \index{Storage class}
11519
11520 \end_inset
11521
11522  Language Extensions
11523 \end_layout
11524
11525 \begin_layout Standard
11526 In addition to the ANSI storage classes SDCC allows the following MCS51
11527  specific storage classes:
11528 \end_layout
11529
11530 \begin_layout Subsubsection
11531 data
11532 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11533
11534 \end_inset
11535
11536
11537 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11538
11539 \end_inset
11540
11541  / near
11542 \begin_inset LatexCommand \index{near (storage class)}
11543
11544 \end_inset
11545
11546
11547 \begin_inset LatexCommand \index{\_\_near (storage class)}
11548
11549 \end_inset
11550
11551
11552 \end_layout
11553
11554 \begin_layout Standard
11555 This is the 
11556 \series bold
11557 default
11558 \series default
11559  storage class for the Small Memory model (
11560 \emph on
11561 data
11562 \emph default
11563  and 
11564 \emph on
11565 near
11566 \emph default
11567  or the more ANSI-C compliant forms 
11568 \emph on
11569 __data
11570 \emph default
11571  and 
11572 \emph on
11573 __near
11574 \emph default
11575  can be used synonymously).
11576  Variables declared with this storage class will be allocated in the directly
11577  addressable portion of the internal RAM of a 8051, e.g.:
11578 \end_layout
11579
11580 \begin_layout Verse
11581
11582 \family typewriter
11583 __data unsigned char test_data;
11584 \end_layout
11585
11586 \begin_layout Standard
11587 Writing 0x01 to this variable generates the assembly code:
11588 \end_layout
11589
11590 \begin_layout Verse
11591
11592 \family typewriter
11593 75*00 01\InsetSpace ~
11594 \InsetSpace ~
11595 \InsetSpace ~
11596 mov\InsetSpace ~
11597 \InsetSpace ~
11598 _test_data,#0x01
11599 \end_layout
11600
11601 \begin_layout Subsubsection
11602 xdata
11603 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11604
11605 \end_inset
11606
11607
11608 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11609
11610 \end_inset
11611
11612  / far
11613 \begin_inset LatexCommand \index{far (storage class)}
11614
11615 \end_inset
11616
11617
11618 \begin_inset LatexCommand \index{\_\_far (storage class)}
11619
11620 \end_inset
11621
11622
11623 \end_layout
11624
11625 \begin_layout Standard
11626 Variables declared with this storage class will be placed in the external
11627  RAM.
11628  This is the 
11629 \series bold
11630 default
11631 \series default
11632  storage class for the Large Memory model, e.g.:
11633 \end_layout
11634
11635 \begin_layout Verse
11636
11637 \family typewriter
11638 __xdata unsigned char test_xdata;
11639 \end_layout
11640
11641 \begin_layout Standard
11642 Writing 0x01 to this variable generates the assembly code:
11643 \end_layout
11644
11645 \begin_layout Verse
11646
11647 \family typewriter
11648 90s00r00\InsetSpace ~
11649 \InsetSpace ~
11650 \InsetSpace ~
11651 mov\InsetSpace ~
11652 \InsetSpace ~
11653 dptr,#_test_xdata 
11654 \newline
11655 74\InsetSpace ~
11656 01\InsetSpace ~
11657 \InsetSpace ~
11658 \InsetSpace ~
11659 \InsetSpace ~
11660 \InsetSpace ~
11661 \InsetSpace ~
11662 mov\InsetSpace ~
11663 \InsetSpace ~
11664 a,#0x01 
11665 \newline
11666 F0\InsetSpace ~
11667 \InsetSpace ~
11668 \InsetSpace ~
11669 \InsetSpace ~
11670 \InsetSpace ~
11671 \InsetSpace ~
11672 \InsetSpace ~
11673 \InsetSpace ~
11674 \InsetSpace ~
11675 movx\InsetSpace ~
11676 @dptr,a 
11677 \end_layout
11678
11679 \begin_layout Subsubsection
11680 idata
11681 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11682
11683 \end_inset
11684
11685
11686 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11687
11688 \end_inset
11689
11690
11691 \end_layout
11692
11693 \begin_layout Standard
11694 Variables declared with this storage class will be allocated into the indirectly
11695  addressable portion of the internal ram of a 8051, e.g.:
11696 \end_layout
11697
11698 \begin_layout Verse
11699
11700 \family typewriter
11701 __idata unsigned char test_idata;
11702 \end_layout
11703
11704 \begin_layout Standard
11705 Writing 0x01 to this variable generates the assembly code:
11706 \end_layout
11707
11708 \begin_layout Verse
11709
11710 \family typewriter
11711 78r00\InsetSpace ~
11712 \InsetSpace ~
11713 \InsetSpace ~
11714 \InsetSpace ~
11715 \InsetSpace ~
11716 \InsetSpace ~
11717 \InsetSpace ~
11718 mov\InsetSpace ~
11719 \InsetSpace ~
11720 r0,#_test_idata
11721 \newline
11722 76\InsetSpace ~
11723 01\InsetSpace ~
11724 \InsetSpace ~
11725 \InsetSpace ~
11726 \InsetSpace ~
11727 \InsetSpace ~
11728 \InsetSpace ~
11729 \InsetSpace ~
11730 mov\InsetSpace ~
11731 \InsetSpace ~
11732 @r0,#0x01
11733 \end_layout
11734
11735 \begin_layout Standard
11736 Please note, the first 128 byte of idata physically access the same RAM
11737  as the data memory.
11738  The original 8051 had 128 byte idata memory, nowadays most devices have
11739  256 byte idata memory.
11740  The stack
11741 \begin_inset LatexCommand \index{stack}
11742
11743 \end_inset
11744
11745  is located in idata memory.
11746 \end_layout
11747
11748 \begin_layout Subsubsection
11749 pdata
11750 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11751
11752 \end_inset
11753
11754
11755 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11756
11757 \end_inset
11758
11759
11760 \end_layout
11761
11762 \begin_layout Standard
11763 Paged xdata access is just as straightforward as using the other addressing
11764  modes of a 8051.
11765  It is typically located at the start of xdata and has a maximum size of
11766  256 bytes.
11767  The following example writes 0x01 to the pdata variable.
11768  Please note, pdata access physically accesses xdata memory.
11769  The high byte of the address is determined by port P2 
11770 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11771
11772 \end_inset
11773
11774 (or in case of some 8051 variants by a separate Special Function Register,
11775  see section 
11776 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11777
11778 \end_inset
11779
11780 ).
11781  This is the 
11782 \series bold
11783 default
11784 \series default
11785  storage class for the Medium Memory model, e.g.:
11786 \end_layout
11787
11788 \begin_layout Verse
11789
11790 \family typewriter
11791 __pdata unsigned char test_pdata;
11792 \end_layout
11793
11794 \begin_layout Standard
11795 Writing 0x01 to this variable generates the assembly code:
11796 \end_layout
11797
11798 \begin_layout Verse
11799
11800 \family typewriter
11801 78r00\InsetSpace ~
11802 \InsetSpace ~
11803 \InsetSpace ~
11804 \InsetSpace ~
11805 \InsetSpace ~
11806 \InsetSpace ~
11807 mov r0,#_test_pdata
11808 \newline
11809 74 01\InsetSpace ~
11810 \InsetSpace ~
11811 \InsetSpace ~
11812 \InsetSpace ~
11813 \InsetSpace ~
11814 \InsetSpace ~
11815 mov a,#0x01 
11816 \newline
11817 F2\InsetSpace ~
11818 \InsetSpace ~
11819 \InsetSpace ~
11820 \InsetSpace ~
11821 \InsetSpace ~
11822 \InsetSpace ~
11823 \InsetSpace ~
11824 \InsetSpace ~
11825 \InsetSpace ~
11826 movx @r0,a
11827 \end_layout
11828
11829 \begin_layout Standard
11830 If the -
11831 \begin_inset ERT
11832 status collapsed
11833
11834 \begin_layout Standard
11835
11836
11837 \backslash
11838 /
11839 \end_layout
11840
11841 \end_inset
11842
11843 -xstack
11844 \begin_inset LatexCommand \index{-\/-xstack}
11845
11846 \end_inset
11847
11848  option is used the pdata memory area is followed by the xstack memory area
11849  and the sum of their sizes is limited to 256 bytes.
11850 \end_layout
11851
11852 \begin_layout Subsubsection
11853 code
11854 \begin_inset LatexCommand \index{code}
11855
11856 \end_inset
11857
11858
11859 \begin_inset LatexCommand \index{\_\_code}
11860
11861 \end_inset
11862
11863
11864 \end_layout
11865
11866 \begin_layout Standard
11867 'Variables' declared with this storage class will be placed in the code
11868  memory:
11869 \end_layout
11870
11871 \begin_layout Verse
11872
11873 \family typewriter
11874 __code unsigned char test_code;
11875 \end_layout
11876
11877 \begin_layout Standard
11878 Read access to this variable generates the assembly code:
11879 \end_layout
11880
11881 \begin_layout Verse
11882
11883 \family typewriter
11884 90s00r6F\InsetSpace ~
11885 \InsetSpace ~
11886 \InsetSpace ~
11887 mov dptr,#_test_code
11888 \newline
11889 E4\InsetSpace ~
11890 \InsetSpace ~
11891 \InsetSpace ~
11892 \InsetSpace ~
11893 \InsetSpace ~
11894 \InsetSpace ~
11895 \InsetSpace ~
11896 \InsetSpace ~
11897 \InsetSpace ~
11898 clr a
11899 \newline
11900 93\InsetSpace ~
11901 \InsetSpace ~
11902 \InsetSpace ~
11903 \InsetSpace ~
11904 \InsetSpace ~
11905 \InsetSpace ~
11906 \InsetSpace ~
11907 \InsetSpace ~
11908 \InsetSpace ~
11909 movc a,@a+dptr 
11910 \end_layout
11911
11912 \begin_layout Standard
11913
11914 \family typewriter
11915 char
11916 \family default
11917  indexed arrays of characters in code memory can be accessed efficiently:
11918 \end_layout
11919
11920 \begin_layout Verse
11921
11922 \family typewriter
11923 __code char test_array[] = {'c','h','e','a','p'}; 
11924 \end_layout
11925
11926 \begin_layout Standard
11927 Read access to this array using an 8-bit unsigned index generates the assembly
11928  code:
11929 \end_layout
11930
11931 \begin_layout Verse
11932
11933 \family typewriter
11934 E5*00\InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 \InsetSpace ~
11940 mov a,_index 
11941 \end_layout
11942
11943 \begin_layout Verse
11944
11945 \family typewriter
11946 90s00r41\InsetSpace ~
11947 \InsetSpace ~
11948 \InsetSpace ~
11949 mov dptr,#_test_array
11950 \end_layout
11951
11952 \begin_layout Verse
11953
11954 \family typewriter
11955 93\InsetSpace ~
11956 \InsetSpace ~
11957 \InsetSpace ~
11958 \InsetSpace ~
11959 \InsetSpace ~
11960 \InsetSpace ~
11961 \InsetSpace ~
11962 \InsetSpace ~
11963 \InsetSpace ~
11964 movc a,@a+dptr 
11965 \end_layout
11966
11967 \begin_layout Subsubsection
11968 bit
11969 \begin_inset LatexCommand \index{bit}
11970
11971 \end_inset
11972
11973
11974 \begin_inset LatexCommand \index{\_\_bit}
11975
11976 \end_inset
11977
11978
11979 \end_layout
11980
11981 \begin_layout Standard
11982 This is a data-type and a storage class specifier.
11983  When a variable is declared as a bit, it is allocated into the bit addressable
11984  memory of 8051, e.g.:
11985 \end_layout
11986
11987 \begin_layout Verse
11988
11989 \family typewriter
11990 __bit test_bit;
11991 \end_layout
11992
11993 \begin_layout Standard
11994 Writing 1 to this variable generates the assembly code:
11995 \end_layout
11996
11997 \begin_layout Verse
11998
11999 \family typewriter
12000 D2*00\InsetSpace ~
12001 \InsetSpace ~
12002 \InsetSpace ~
12003 \InsetSpace ~
12004 \InsetSpace ~
12005 \InsetSpace ~
12006 \InsetSpace ~
12007 setb\InsetSpace ~
12008 _test_bit
12009 \end_layout
12010
12011 \begin_layout Standard
12012 The bit addressable memory consists of 128 bits which are located from 0x20
12013  to 0x2f in data memory.
12014  
12015 \newline
12016 Apart from this 8051 specific storage class most architectures support
12017  ANSI-C bitfields
12018 \begin_inset LatexCommand \index{bitfields}
12019
12020 \end_inset
12021
12022
12023 \begin_inset Foot
12024 status open
12025
12026 \begin_layout Standard
12027 Not really meant as examples, but nevertheless showing what bitfields are
12028  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12029 \end_layout
12030
12031 \end_inset
12032
12033 .
12034  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12035  signed modifier are implemented as unsigned.
12036 \end_layout
12037
12038 \begin_layout Subsubsection
12039 sfr
12040 \begin_inset LatexCommand \index{sfr}
12041
12042 \end_inset
12043
12044
12045 \begin_inset LatexCommand \index{\_\_sfr}
12046
12047 \end_inset
12048
12049  / sfr16
12050 \begin_inset LatexCommand \index{sfr16}
12051
12052 \end_inset
12053
12054
12055 \begin_inset LatexCommand \index{\_\_sfr16}
12056
12057 \end_inset
12058
12059  / sfr32
12060 \begin_inset LatexCommand \index{sfr32}
12061
12062 \end_inset
12063
12064
12065 \begin_inset LatexCommand \index{\_\_sfr32}
12066
12067 \end_inset
12068
12069  / sbit
12070 \begin_inset LatexCommand \index{\_\_sbit}
12071
12072 \end_inset
12073
12074
12075 \begin_inset LatexCommand \index{sbit}
12076
12077 \end_inset
12078
12079
12080 \end_layout
12081
12082 \begin_layout Standard
12083 Like the bit keyword, 
12084 \emph on
12085 sfr / sfr16 / sfr32 / sbit 
12086 \emph default
12087 signify both a data-type and storage class, they are used to describe the
12088  
12089 \emph on
12090 s
12091 \emph default
12092 pecial 
12093 \emph on
12094 f
12095 \emph default
12096 unction 
12097 \emph on
12098 r
12099 \emph default
12100 egisters and 
12101 \emph on
12102 s
12103 \emph default
12104 pecial 
12105 \emph on
12106 bit
12107 \emph default
12108  variables of a 8051, eg:
12109 \end_layout
12110
12111 \begin_layout Verse
12112
12113 \family typewriter
12114 __sfr __at
12115 \begin_inset LatexCommand \index{at}
12116
12117 \end_inset
12118
12119
12120 \begin_inset LatexCommand \index{\_\_at}
12121
12122 \end_inset
12123
12124  (0x80) P0;\InsetSpace ~
12125  /* special function register P0 at location 0x80 */
12126 \newline
12127
12128 \newline
12129 /* 16 bit
12130  special function register combination for timer 0
12131 \newline
12132 \InsetSpace ~
12133 \InsetSpace ~
12134  with the high byte at
12135  location 0x8C and the low byte at location 0x8A */
12136 \newline
12137 __sfr16 __at (0x8C8A)
12138  TMR0;
12139 \newline
12140
12141 \newline
12142 __sbit __at
12143 \begin_inset LatexCommand \index{at}
12144
12145 \end_inset
12146
12147
12148 \begin_inset LatexCommand \index{\_\_at}
12149
12150 \end_inset
12151
12152  (0xd7) CY;\InsetSpace ~
12153  /* CY (Carry Flag
12154 \begin_inset LatexCommand \index{Flags}
12155
12156 \end_inset
12157
12158
12159 \begin_inset LatexCommand \index{Carry flag}
12160
12161 \end_inset
12162
12163 ) */
12164 \end_layout
12165
12166 \begin_layout Standard
12167 Special function registers which are located on an address dividable by
12168  8 are bit-addressable, an
12169 \emph on
12170  sbit
12171 \emph default
12172  addresses a specific bit within these sfr.
12173 \newline
12174 16 Bit and 32 bit special function
12175  register combinations which require a certain access order are better not
12176  declared using 
12177 \emph on
12178 sfr16
12179 \emph default
12180  or 
12181 \emph on
12182 sfr32.
12183
12184 \emph default
12185  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12186  this is not guaranteed.
12187 \newline
12188
12189 \end_layout
12190
12191 \begin_layout Standard
12192 Please note, if you use a header file which was written for another compiler
12193  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12194  likely be 
12195 \emph on
12196 not 
12197 \emph default
12198 compatible.
12199  Specifically the syntax 
12200 \family typewriter
12201 \InsetSpace ~
12202 sfr P0 = 0x80;\InsetSpace ~
12203
12204 \family default
12205  is compiled 
12206 \emph on
12207 without warning
12208 \emph default
12209  by SDCC to an assignment of 0x80 to a variable called P0 
12210 \family typewriter
12211
12212 \begin_inset Marginal
12213 status collapsed
12214
12215 \begin_layout Standard
12216
12217 \series bold
12218 \InsetSpace ~
12219 !
12220 \end_layout
12221
12222 \end_inset
12223
12224 .
12225  
12226 \family default
12227 Nevertheless it is possible to write header files
12228 \begin_inset LatexCommand \index{Header files}
12229
12230 \end_inset
12231
12232
12233 \begin_inset LatexCommand \index{Include files}
12234
12235 \end_inset
12236
12237  which can be shared among different compilers (see section 
12238 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12239
12240 \end_inset
12241
12242 ).
12243  
12244 \end_layout
12245
12246 \begin_layout Subsubsection
12247 Pointers
12248 \begin_inset LatexCommand \index{Pointer}
12249
12250 \end_inset
12251
12252  to MCS51/DS390 specific memory spaces
12253 \end_layout
12254
12255 \begin_layout Standard
12256 SDCC allows (via language extensions) pointers to explicitly point to any
12257  of the memory spaces
12258 \begin_inset LatexCommand \index{Memory model}
12259
12260 \end_inset
12261
12262  of the 8051.
12263  In addition to the explicit pointers, the compiler uses (by default) generic
12264  pointers which can be used to point to any of the memory spaces.
12265 \newline
12266
12267 \newline
12268 Pointer
12269  declaration examples:
12270 \end_layout
12271
12272 \begin_layout Verse
12273
12274 \family typewriter
12275 /* pointer physically in internal ram pointing to object in external ram
12276  */ 
12277 \newline
12278 __xdata unsigned char * __data p;
12279 \newline
12280
12281 \newline
12282 /* pointer physically in external ram
12283  pointing to object in internal ram */ 
12284 \newline
12285 __data unsigned char * __xdata p;
12286 \newline
12287
12288 \newline
12289 /*
12290  pointer physically in code rom pointing to data in xdata space */ 
12291 \newline
12292 __xdata
12293  unsigned char * __code p;
12294 \newline
12295
12296 \newline
12297 /* pointer physically in code space pointing to
12298  data in code space */ 
12299 \newline
12300 __code unsigned char * __code p;
12301 \newline
12302
12303 \newline
12304 /* generic pointer
12305  physically located in xdata space */
12306 \newline
12307 unsigned char * __xdata p;
12308 \newline
12309
12310 \newline
12311 /* generic
12312  pointer physically located in default memory space */
12313 \newline
12314 unsigned char * p;
12315 \newline
12316
12317 \newline
12318 /*
12319  the following is a function pointer
12320 \begin_inset LatexCommand \index{function pointer}
12321
12322 \end_inset
12323
12324  physically located in data space */
12325 \newline
12326 char (* __data fp)(void);
12327 \end_layout
12328
12329 \begin_layout Standard
12330 Well you get the idea.
12331  
12332 \newline
12333
12334 \newline
12335 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12336 \emph on
12337 generic
12338 \emph default
12339  pointers.
12340  
12341 \size small
12342
12343 \newline
12344
12345 \newline
12346
12347 \size default
12348 The highest order byte of the 
12349 \emph on
12350 generic
12351 \emph default
12352  pointers contains the data space information.
12353  Assembler support routines are called whenever data is stored or retrieved
12354  using 
12355 \emph on
12356 generic
12357 \emph default
12358  pointers.
12359  These are useful for developing reusable library
12360 \begin_inset LatexCommand \index{Libraries}
12361
12362 \end_inset
12363
12364  routines.
12365  Explicitly specifying the pointer
12366 \begin_inset LatexCommand \index{pointer}
12367
12368 \end_inset
12369
12370  type will generate the most efficient code.
12371 \end_layout
12372
12373 \begin_layout Subsubsection
12374 Notes on MCS51 memory
12375 \begin_inset LatexCommand \index{MCS51 memory}
12376
12377 \end_inset
12378
12379  layout
12380 \end_layout
12381
12382 \begin_layout Standard
12383 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12384  RAM memory which is structured as follows:
12385 \newline
12386
12387 \newline
12388 - Bytes 00-1F - 32 bytes to hold
12389  up to 4 banks of the registers R0 to R7, 
12390 \newline
12391 - Bytes 20-2F - 16 bytes to hold
12392  128 bit
12393 \begin_inset LatexCommand \index{bit}
12394
12395 \end_inset
12396
12397  variables and, 
12398 \newline
12399 - Bytes 30-7F - 80 bytes for general purpose use.
12400 \newline
12401
12402 \end_layout
12403
12404 \begin_layout Standard
12405 Additionally some members of the MCS51 family may have up to 128 bytes of
12406  additional, indirectly addressable, internal RAM memory (
12407 \emph on
12408 idata
12409 \emph default
12410
12411 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12412
12413 \end_inset
12414
12415
12416 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12417
12418 \end_inset
12419
12420 ).
12421  Furthermore, some chips may have some built in external memory (
12422 \emph on
12423 xdata
12424 \emph default
12425
12426 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12427
12428 \end_inset
12429
12430
12431 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12432
12433 \end_inset
12434
12435 ) which should not be confused with the internal, directly addressable RAM
12436  memory (
12437 \emph on
12438 data
12439 \emph default
12440
12441 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12442
12443 \end_inset
12444
12445
12446 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12447
12448 \end_inset
12449
12450 ).
12451  Sometimes this built in 
12452 \emph on
12453 xdata
12454 \emph default
12455  memory has to be activated before using it (you can probably find this
12456  information on the datasheet of the microcontroller your are using, see
12457  also section 
12458 \begin_inset LatexCommand \ref{sub:Startup-Code}
12459
12460 \end_inset
12461
12462 \InsetSpace ~
12463 Startup-Code).
12464 \end_layout
12465
12466 \begin_layout Standard
12467 Normally SDCC will only use the first bank
12468 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12469
12470 \end_inset
12471
12472  of registers (register bank 0), but it is possible to specify that other
12473  banks of registers (keyword 
12474 \emph on
12475 using
12476 \emph default
12477  
12478 \emph on
12479
12480 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12481
12482 \end_inset
12483
12484
12485 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12486
12487 \end_inset
12488
12489
12490 \emph default
12491 ) should be used for example in interrupt
12492 \begin_inset LatexCommand \index{interrupt}
12493
12494 \end_inset
12495
12496
12497 \begin_inset LatexCommand \index{\_\_interrupt}
12498
12499 \end_inset
12500
12501  routines.
12502  By default, the compiler will place the stack after the last byte of allocated
12503  memory for variables.
12504  For example, if the first 2 banks of registers are used, and only four
12505  bytes are used for 
12506 \emph on
12507 data
12508 \emph default
12509  variables, it will position the base of the internal stack at address 20
12510  (0x14).
12511  This implies that as the stack
12512 \begin_inset LatexCommand \index{stack}
12513
12514 \end_inset
12515
12516  grows, it will use up the remaining register banks, and the 16 bytes used
12517  by the 128 bit variables, and 80 bytes for general purpose use.
12518  If any bit variables are used, the data variables will be placed in unused
12519  register banks and after the byte holding the last bit variable.
12520  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12521  (two bytes used), 
12522 \emph on
12523 data
12524 \emph default
12525  variables will be placed starting from address 0x10 to 0x20 and continue
12526  at address 0x22.
12527  You can also use -
12528 \begin_inset ERT
12529 status collapsed
12530
12531 \begin_layout Standard
12532
12533
12534 \backslash
12535 /
12536 \end_layout
12537
12538 \end_inset
12539
12540 -data-loc
12541 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12542
12543 \end_inset
12544
12545  to specify the start address of the 
12546 \emph on
12547 data
12548 \emph default
12549  and -
12550 \begin_inset ERT
12551 status collapsed
12552
12553 \begin_layout Standard
12554
12555
12556 \backslash
12557 /
12558 \end_layout
12559
12560 \end_inset
12561
12562 -iram-size
12563 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12564
12565 \end_inset
12566
12567  to specify the size of the total internal RAM (
12568 \emph on
12569 data
12570 \emph default
12571 +
12572 \emph on
12573 idata
12574 \emph default
12575 ).
12576  
12577 \newline
12578
12579 \end_layout
12580
12581 \begin_layout Standard
12582 By default the 8051 linker will place the stack after the last byte of (i)data
12583  variables.
12584  Option -
12585 \begin_inset ERT
12586 status collapsed
12587
12588 \begin_layout Standard
12589
12590
12591 \backslash
12592 /
12593 \end_layout
12594
12595 \end_inset
12596
12597 -stack-loc
12598 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12599
12600 \end_inset
12601
12602  allows you to specify the start of the stack, i.e.
12603  you could start it after any data in the general purpose area.
12604  If your microcontroller has additional indirectly addressable internal
12605  RAM (
12606 \emph on
12607 idata
12608 \emph default
12609 ) you can place the stack on it.
12610  You may also need to use -
12611 \begin_inset ERT
12612 status collapsed
12613
12614 \begin_layout Standard
12615
12616
12617 \backslash
12618 /
12619 \end_layout
12620
12621 \end_inset
12622
12623 -xdata-loc
12624 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12625
12626 \end_inset
12627
12628  to set the start address of the external RAM (
12629 \emph on
12630 xdata
12631 \emph default
12632 ) and -
12633 \begin_inset ERT
12634 status collapsed
12635
12636 \begin_layout Standard
12637
12638
12639 \backslash
12640 /
12641 \end_layout
12642
12643 \end_inset
12644
12645 -xram-size
12646 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12647
12648 \end_inset
12649
12650  to specify its size.
12651  Same goes for the code memory, using -
12652 \begin_inset ERT
12653 status collapsed
12654
12655 \begin_layout Standard
12656
12657
12658 \backslash
12659 /
12660 \end_layout
12661
12662 \end_inset
12663
12664 -code-loc
12665 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12666
12667 \end_inset
12668
12669  and -
12670 \begin_inset ERT
12671 status collapsed
12672
12673 \begin_layout Standard
12674
12675
12676 \backslash
12677 /
12678 \end_layout
12679
12680 \end_inset
12681
12682 -code-size
12683 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12684
12685 \end_inset
12686
12687 .
12688  If in doubt, don't specify any options and see if the resulting memory
12689  layout is appropriate, then you can adjust it.
12690 \end_layout
12691
12692 \begin_layout Standard
12693 The linker generates two files with memory allocation information.
12694  The first, with extension .map
12695 \begin_inset LatexCommand \index{<file>.map}
12696
12697 \end_inset
12698
12699  shows all the variables and segments.
12700  The second with extension .mem
12701 \begin_inset LatexCommand \index{<file>.mem}
12702
12703 \end_inset
12704
12705  shows the final memory layout.
12706  The linker will complain either if memory segments overlap, there is not
12707  enough memory, or there is not enough space for stack.
12708  If you get any linking warnings and/or errors related to stack or segments
12709  allocation, take a look at either the .map or .mem files to find out what
12710  the problem is.
12711  The .mem file may even suggest a solution to the problem.
12712 \begin_inset VSpace bigskip
12713 \end_inset
12714
12715
12716 \end_layout
12717
12718 \begin_layout Subsection
12719 Z80/Z180 Storage Class
12720 \begin_inset LatexCommand \index{Z80!Storage class}
12721
12722 \end_inset
12723
12724  Language Extensions
12725 \end_layout
12726
12727 \begin_layout Subsubsection
12728 sfr
12729 \begin_inset LatexCommand \index{sfr}
12730
12731 \end_inset
12732
12733
12734 \begin_inset LatexCommand \index{\_\_sfr}
12735
12736 \end_inset
12737
12738  (in/out to 8-bit addresses)
12739 \end_layout
12740
12741 \begin_layout Standard
12742 The Z80
12743 \begin_inset LatexCommand \index{Z80}
12744
12745 \end_inset
12746
12747  family has separate address spaces for memory and 
12748 \emph on
12749 i
12750 \emph default
12751 nput/
12752 \emph on
12753 o
12754 \emph default
12755 utput memory.
12756  I/O memory
12757 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12758
12759 \end_inset
12760
12761
12762 \begin_inset LatexCommand \index{Z80!I/O memory}
12763
12764 \end_inset
12765
12766
12767 \begin_inset LatexCommand \index{Z180!I/O memory}
12768
12769 \end_inset
12770
12771  is accessed with special instructions, e.g.:
12772 \end_layout
12773
12774 \begin_layout Verse
12775
12776 \family typewriter
12777 sfr at 0x78 IoPort;\InsetSpace ~
12778 \InsetSpace ~
12779 /* define a var in I/O space at 78h called IoPort */
12780  
12781 \end_layout
12782
12783 \begin_layout Standard
12784 Writing 0x01 to this variable generates the assembly code:
12785 \end_layout
12786
12787 \begin_layout Verse
12788
12789 \family typewriter
12790 3E 01\InsetSpace ~
12791 \InsetSpace ~
12792 \InsetSpace ~
12793 \InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 ld a,#0x01
12797 \newline
12798 D3 78\InsetSpace ~
12799 \InsetSpace ~
12800 \InsetSpace ~
12801 \InsetSpace ~
12802 \InsetSpace ~
12803 \InsetSpace ~
12804 out (_IoPort),a 
12805 \end_layout
12806
12807 \begin_layout Subsubsection
12808 banked sfr
12809 \begin_inset LatexCommand \index{sfr}
12810
12811 \end_inset
12812
12813
12814 \begin_inset LatexCommand \index{\_\_sfr}
12815
12816 \end_inset
12817
12818  (in/out to 16-bit addresses)
12819 \end_layout
12820
12821 \begin_layout Standard
12822 The keyword 
12823 \emph on
12824 banked
12825 \emph default
12826  is used to support 16 bit addresses in I/O memory e.g.:
12827 \end_layout
12828
12829 \begin_layout Verse
12830
12831 \family typewriter
12832 sfr banked at
12833 \begin_inset LatexCommand \index{at}
12834
12835 \end_inset
12836
12837
12838 \begin_inset LatexCommand \index{\_\_at}
12839
12840 \end_inset
12841
12842  0x123 IoPort; 
12843 \end_layout
12844
12845 \begin_layout Standard
12846 Writing 0x01 to this variable generates the assembly code:
12847 \end_layout
12848
12849 \begin_layout Verse
12850
12851 \family typewriter
12852 01 23 01\InsetSpace ~
12853 \InsetSpace ~
12854 \InsetSpace ~
12855 ld bc,#_IoPort
12856 \newline
12857 3E 01\InsetSpace ~
12858 \InsetSpace ~
12859 \InsetSpace ~
12860 \InsetSpace ~
12861 \InsetSpace ~
12862 \InsetSpace ~
12863 ld a,#0x01 
12864 \newline
12865 ED 79\InsetSpace ~
12866 \InsetSpace ~
12867 \InsetSpace ~
12868 \InsetSpace ~
12869 \InsetSpace ~
12870 \InsetSpace ~
12871 out (c),a 
12872 \end_layout
12873
12874 \begin_layout Subsubsection
12875 sfr
12876 \begin_inset LatexCommand \index{sfr}
12877
12878 \end_inset
12879
12880
12881 \begin_inset LatexCommand \index{\_\_sfr}
12882
12883 \end_inset
12884
12885  (in0/out0 to 8 bit addresses on Z180
12886 \begin_inset LatexCommand \index{Z180}
12887
12888 \end_inset
12889
12890 /HD64180
12891 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12892
12893 \end_inset
12894
12895 )
12896 \end_layout
12897
12898 \begin_layout Standard
12899 The compiler option -
12900 \begin_inset ERT
12901 status collapsed
12902
12903 \begin_layout Standard
12904
12905
12906 \backslash
12907 /
12908 \end_layout
12909
12910 \end_inset
12911
12912 -portmode
12913 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12914
12915 \end_inset
12916
12917 =180 (80) and a compiler #pragma\InsetSpace ~
12918 portmode
12919 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12920
12921 \end_inset
12922
12923  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12924 ns 
12925 \family typewriter
12926 in0/out0
12927 \family default
12928  instead of 
12929 \family typewriter
12930 in/out
12931 \family default
12932 .
12933  If you include the file z180.h this will be set automatically.
12934 \begin_inset VSpace bigskip
12935 \end_inset
12936
12937
12938 \end_layout
12939
12940 \begin_layout Subsection
12941 HC08 Storage Class
12942 \begin_inset LatexCommand \index{HC08!Storage class}
12943
12944 \end_inset
12945
12946  Language Extensions
12947 \end_layout
12948
12949 \begin_layout Subsubsection
12950 data
12951 \begin_inset LatexCommand \index{data (hc08 storage class)}
12952
12953 \end_inset
12954
12955
12956 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12957
12958 \end_inset
12959
12960  
12961 \end_layout
12962
12963 \begin_layout Standard
12964 The data storage class declares a variable that resides in the first 256
12965  bytes of memory (the direct page).
12966  The HC08
12967 \begin_inset LatexCommand \index{HC08}
12968
12969 \end_inset
12970
12971  is most efficient at accessing variables (especially pointers) stored here.
12972 \end_layout
12973
12974 \begin_layout Subsubsection
12975 xdata
12976 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12977
12978 \end_inset
12979
12980
12981 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12982
12983 \end_inset
12984
12985  
12986 \end_layout
12987
12988 \begin_layout Standard
12989 The xdata storage class declares a variable that can reside anywhere in
12990  memory.
12991  This is the default if no storage class is specified.
12992  
12993 \begin_inset VSpace bigskip
12994 \end_inset
12995
12996
12997 \end_layout
12998
12999 \begin_layout Section
13000 Absolute Addressing
13001 \begin_inset LatexCommand \index{Absolute addressing}
13002
13003 \end_inset
13004
13005
13006 \end_layout
13007
13008 \begin_layout Standard
13009 Data items can be assigned an absolute address with the 
13010 \emph on
13011 at
13012 \begin_inset LatexCommand \index{at}
13013
13014 \end_inset
13015
13016
13017 \begin_inset LatexCommand \index{\_\_at}
13018
13019 \end_inset
13020
13021  <address>
13022 \emph default
13023  keyword, in addition to a storage class, e.g.:
13024 \end_layout
13025
13026 \begin_layout Verse
13027
13028 \family typewriter
13029 xdata
13030 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13031
13032 \end_inset
13033
13034
13035 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13036
13037 \end_inset
13038
13039  at
13040 \begin_inset LatexCommand \index{at}
13041
13042 \end_inset
13043
13044
13045 \begin_inset LatexCommand \index{\_\_at}
13046
13047 \end_inset
13048
13049  0x7ffe unsigned int chksum;
13050 \end_layout
13051
13052 \begin_layout Standard
13053 or, better conforming to ISO/IEC 9899 C:
13054 \end_layout
13055
13056 \begin_layout Verse
13057
13058 \family typewriter
13059 __xdata __at (0x7ffe) unsigned int chksum;
13060 \end_layout
13061
13062 \begin_layout Standard
13063 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13064  of the external ram.
13065  The compiler does 
13066 \emph on
13067 not
13068 \emph default
13069  reserve any space for variables declared in this way
13070 \begin_inset Marginal
13071 status collapsed
13072
13073 \begin_layout Standard
13074
13075 \series bold
13076 \InsetSpace ~
13077 !
13078 \end_layout
13079
13080 \end_inset
13081
13082  (they are implemented with an equate in the assembler).
13083  Thus it is left to the programmer to make sure there are no overlaps with
13084  other variables that are declared without the absolute address.
13085  The assembler listing file (.lst
13086 \begin_inset LatexCommand \index{<file>.lst}
13087
13088 \end_inset
13089
13090 ) and the linker output files (.rst
13091 \begin_inset LatexCommand \index{<file>.rst}
13092
13093 \end_inset
13094
13095 ) and (.map
13096 \begin_inset LatexCommand \index{<file>.map}
13097
13098 \end_inset
13099
13100 ) are good places to look for such overlaps.
13101 \end_layout
13102
13103 \begin_layout Standard
13104 If however you provide an initializer
13105 \begin_inset LatexCommand \index{Variable initialization}
13106
13107 \end_inset
13108
13109  actual memory allocation will take place and overlaps will be detected
13110  by the linker.
13111  E.g.:
13112 \end_layout
13113
13114 \begin_layout Verse
13115
13116 \family typewriter
13117 __code __at (0x7ff0) char Id[5] = 
13118 \begin_inset Quotes sld
13119 \end_inset
13120
13121 SDCC
13122 \begin_inset Quotes srd
13123 \end_inset
13124
13125 ;
13126 \end_layout
13127
13128 \begin_layout Standard
13129 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13130  in code memory.
13131 \end_layout
13132
13133 \begin_layout Standard
13134 In case of memory mapped I/O devices the keyword 
13135 \emph on
13136 volatile
13137 \emph default
13138  has to be used to tell the compiler that accesses might not be removed:
13139 \end_layout
13140
13141 \begin_layout Verse
13142
13143 \family typewriter
13144 volatile
13145 \begin_inset LatexCommand \index{volatile}
13146
13147 \end_inset
13148
13149  __xdata
13150 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13151
13152 \end_inset
13153
13154  __at
13155 \begin_inset LatexCommand \index{at}
13156
13157 \end_inset
13158
13159  (0x8000) unsigned char PORTA_8255;
13160 \end_layout
13161
13162 \begin_layout Standard
13163 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13164 r) array
13165 \family typewriter
13166 \size footnotesize
13167
13168 \begin_inset LatexCommand \index{Aligned array}
13169
13170 \end_inset
13171
13172
13173 \family default
13174 \size default
13175  starts at a block (256 byte) boundary
13176 \begin_inset LatexCommand \index{block boundary}
13177
13178 \end_inset
13179
13180  (section 
13181 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13182
13183 \end_inset
13184
13185  has an example).
13186 \newline
13187 Absolute addresses can be specified for variables in all
13188  storage classes, e.g.:
13189 \end_layout
13190
13191 \begin_layout Verse
13192
13193 \family typewriter
13194 __bit
13195 \begin_inset LatexCommand \index{bit}
13196
13197 \end_inset
13198
13199  __at
13200 \begin_inset LatexCommand \index{at}
13201
13202 \end_inset
13203
13204  (0x02) bvar;
13205 \end_layout
13206
13207 \begin_layout Standard
13208 The above example will allocate the variable at offset 0x02 in the bit-addressab
13209 le space.
13210  There is no real advantage to assigning absolute addresses to variables
13211  in this manner, unless you want strict control over all the variables allocated.
13212  One possible use would be to write hardware portable code.
13213  For example, if you have a routine that uses one or more of the microcontroller
13214  I/O pins, and such pins are different for two different hardwares, you
13215  can declare the I/O pins in your routine using:
13216 \end_layout
13217
13218 \begin_layout Verse
13219
13220 \family typewriter
13221 extern volatile
13222 \begin_inset LatexCommand \index{volatile}
13223
13224 \end_inset
13225
13226  __bit MOSI;\InsetSpace ~
13227 \InsetSpace ~
13228 \InsetSpace ~
13229 \InsetSpace ~
13230 /* master out, slave in */
13231 \newline
13232 extern volatile __bit MISO;\InsetSpace ~
13233 \InsetSpace ~
13234 \InsetSpace ~
13235 \InsetSpace ~
13236 /* master
13237  in, slave out */
13238 \newline
13239 extern volatile __bit MCLK;\InsetSpace ~
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 \InsetSpace ~
13243 /* master clock */
13244 \newline
13245
13246 \newline
13247 /* Input and
13248  Output of a byte on a 3-wire serial bus.
13249 \newline
13250 \InsetSpace ~
13251 \InsetSpace ~
13252 \InsetSpace ~
13253 If needed adapt polarity of clock,
13254  polarity of data and bit order
13255 \newline
13256 \InsetSpace ~
13257 */
13258 \newline
13259 unsigned char spi_io(unsigned char out_byte)
13260  
13261 \newline
13262
13263 \newline
13264 \InsetSpace ~
13265 \InsetSpace ~
13266 \InsetSpace ~
13267 \InsetSpace ~
13268 unsigned char i=8;
13269 \newline
13270 \InsetSpace ~
13271 \InsetSpace ~
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 do { 
13275 \newline
13276 \InsetSpace ~
13277 \InsetSpace ~
13278 \InsetSpace ~
13279 \InsetSpace ~
13280 \InsetSpace ~
13281 \InsetSpace ~
13282 \InsetSpace ~
13283 \InsetSpace ~
13284 MOSI = out_byte & 0x80; 
13285 \newline
13286 \InsetSpace ~
13287 \InsetSpace ~
13288 \InsetSpace ~
13289 \InsetSpace ~
13290 \InsetSpace ~
13291 \InsetSpace ~
13292 \InsetSpace ~
13293 \InsetSpace ~
13294 out_byte <<= 1;
13295 \newline
13296 \InsetSpace ~
13297 \InsetSpace ~
13298 \InsetSpace ~
13299 \InsetSpace ~
13300 \InsetSpace ~
13301 \InsetSpace ~
13302 \InsetSpace ~
13303 \InsetSpace ~
13304 MCLK =
13305  1; 
13306 \newline
13307 \InsetSpace ~
13308 \InsetSpace ~
13309 \InsetSpace ~
13310 \InsetSpace ~
13311 \InsetSpace ~
13312 \InsetSpace ~
13313 \InsetSpace ~
13314 \InsetSpace ~
13315 /* _asm nop _endasm; */\InsetSpace ~
13316 \InsetSpace ~
13317 \InsetSpace ~
13318 \InsetSpace ~
13319 \InsetSpace ~
13320 \InsetSpace ~
13321 \InsetSpace ~
13322 \InsetSpace ~
13323 /* for slow peripherals */
13324 \newline
13325 \InsetSpace ~
13326 \InsetSpace ~
13327 \InsetSpace ~
13328 \InsetSpace ~
13329 \InsetSpace ~
13330 \InsetSpace ~
13331 \InsetSpace ~
13332 \InsetSpace ~
13333 if(MISO) 
13334 \newline
13335 \InsetSpace ~
13336 \InsetSpace ~
13337 \InsetSpace ~
13338 \InsetSpace ~
13339 \InsetSpace ~
13340 \InsetSpace ~
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 \InsetSpace ~
13346 \InsetSpace ~
13347 out_byte +=
13348  1; 
13349 \newline
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 \InsetSpace ~
13353 \InsetSpace ~
13354 \InsetSpace ~
13355 \InsetSpace ~
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 MCLK = 0; 
13359 \newline
13360 \InsetSpace ~
13361 \InsetSpace ~
13362 \InsetSpace ~
13363 \InsetSpace ~
13364 } while(--i);
13365 \newline
13366 \InsetSpace ~
13367 \InsetSpace ~
13368 \InsetSpace ~
13369 \InsetSpace ~
13370 return out_byte; 
13371 \newline
13372 }
13373 \end_layout
13374
13375 \begin_layout Standard
13376 Then, someplace in the code for the first hardware you would use
13377 \end_layout
13378
13379 \begin_layout Verse
13380
13381 \family typewriter
13382 __bit __at
13383 \begin_inset LatexCommand \index{at}
13384
13385 \end_inset
13386
13387
13388 \begin_inset LatexCommand \index{\_\_at}
13389
13390 \end_inset
13391
13392  (0x80) MOSI;\InsetSpace ~
13393 \InsetSpace ~
13394 \InsetSpace ~
13395 \InsetSpace ~
13396 /* I/O port 0, bit 0 */
13397 \newline
13398 __bit __at (0x81) MISO;\InsetSpace ~
13399 \InsetSpace ~
13400 \InsetSpace ~
13401 \InsetSpace ~
13402 /* I/O port 0,
13403  bit 1 */
13404 \newline
13405 __bit __at (0x82) MCLK;\InsetSpace ~
13406 \InsetSpace ~
13407 \InsetSpace ~
13408 \InsetSpace ~
13409 /* I/O port 0, bit 2 */
13410 \end_layout
13411
13412 \begin_layout Standard
13413 Similarly, for the second hardware you would use
13414 \end_layout
13415
13416 \begin_layout Verse
13417
13418 \family typewriter
13419 __bit __at (0x83) MOSI;\InsetSpace ~
13420 \InsetSpace ~
13421 \InsetSpace ~
13422 \InsetSpace ~
13423 /* I/O port 0, bit 3 */
13424 \newline
13425 __bit __at (0x91) MISO;\InsetSpace ~
13426 \InsetSpace ~
13427 \InsetSpace ~
13428 \InsetSpace ~
13429 /*
13430  I/O port 1, bit 1 */
13431 \newline
13432 __bit
13433 \begin_inset LatexCommand \index{bit}
13434
13435 \end_inset
13436
13437  __at (0x92) MCLK;\InsetSpace ~
13438 \InsetSpace ~
13439 \InsetSpace ~
13440 \InsetSpace ~
13441 /* I/O port 1, bit 2 */
13442 \end_layout
13443
13444 \begin_layout Standard
13445 and you can use the same hardware dependent routine without changes, as
13446  for example in a library.
13447  This is somehow similar to sbit, but only one absolute address has to be
13448  specified in the whole project.
13449 \begin_inset VSpace bigskip
13450 \end_inset
13451
13452
13453 \end_layout
13454
13455 \begin_layout Section
13456 Parameters
13457 \begin_inset LatexCommand \index{Parameters}
13458
13459 \end_inset
13460
13461
13462 \begin_inset LatexCommand \index{function parameter}
13463
13464 \end_inset
13465
13466  & Local Variables
13467 \begin_inset LatexCommand \index{local variables}
13468
13469 \end_inset
13470
13471
13472 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13473
13474 \end_inset
13475
13476
13477 \end_layout
13478
13479 \begin_layout Standard
13480 Automatic (local) variables and parameters to functions can either be placed
13481  on the stack or in data-space.
13482  The default action of the compiler is to place these variables in the internal
13483  RAM (for small model) or external RAM (for medium or large model).
13484  This in fact makes them similar to 
13485 \emph on
13486 static
13487 \begin_inset LatexCommand \index{static}
13488
13489 \end_inset
13490
13491
13492 \emph default
13493  so by default functions are non-reentrant
13494 \begin_inset LatexCommand \index{reentrant}
13495
13496 \end_inset
13497
13498 .
13499  
13500 \newline
13501
13502 \newline
13503 They can be placed on the stack
13504 \begin_inset LatexCommand \index{stack}
13505
13506 \end_inset
13507
13508  by using the
13509 \emph on
13510  -
13511 \begin_inset ERT
13512 status collapsed
13513
13514 \begin_layout Standard
13515
13516
13517 \backslash
13518 /
13519 \end_layout
13520
13521 \end_inset
13522
13523 -stack-auto
13524 \begin_inset LatexCommand \index{-\/-stack-auto}
13525
13526 \end_inset
13527
13528
13529 \emph default
13530  option, by using 
13531 \emph on
13532 #pragma\InsetSpace ~
13533 stackauto
13534 \emph default
13535
13536 \begin_inset LatexCommand \index{\#pragma stackauto}
13537
13538 \end_inset
13539
13540  or by using the 
13541 \emph on
13542 reentrant
13543 \begin_inset LatexCommand \index{reentrant}
13544
13545 \end_inset
13546
13547
13548 \emph default
13549  keyword in the function declaration, e.g.:
13550 \end_layout
13551
13552 \begin_layout Verse
13553
13554 \family typewriter
13555 unsigned char foo(char i) __reentrant 
13556 \newline
13557
13558 \newline
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 ...
13564  
13565 \newline
13566 }
13567 \end_layout
13568
13569 \begin_layout Standard
13570 Since stack space on 8051 is limited, the 
13571 \emph on
13572 reentrant 
13573 \emph default
13574 keyword or the
13575 \emph on
13576  -
13577 \begin_inset ERT
13578 status collapsed
13579
13580 \begin_layout Standard
13581
13582
13583 \backslash
13584 /
13585 \end_layout
13586
13587 \end_inset
13588
13589 -stack-auto
13590 \emph default
13591  option should be used sparingly.
13592  Note that the reentrant keyword just means that the parameters & local
13593  variables will be allocated to the stack, it 
13594 \emph on
13595 does not
13596 \emph default
13597  mean that the function is register bank
13598 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13599
13600 \end_inset
13601
13602  independent.
13603 \newline
13604
13605 \newline
13606 Local variables
13607 \begin_inset LatexCommand \index{local variables}
13608
13609 \end_inset
13610
13611  can be assigned storage classes and absolute
13612 \begin_inset LatexCommand \index{Absolute addressing}
13613
13614 \end_inset
13615
13616  addresses, e.g.: 
13617 \end_layout
13618
13619 \begin_layout Verse
13620
13621 \family typewriter
13622 unsigned char foo() 
13623 \newline
13624 {
13625 \newline
13626 \InsetSpace ~
13627 \InsetSpace ~
13628 \InsetSpace ~
13629 \InsetSpace ~
13630 __xdata unsigned char i;
13631 \newline
13632 \InsetSpace ~
13633 \InsetSpace ~
13634 \InsetSpace ~
13635 \InsetSpace ~
13636 __bit bvar;
13637 \newline
13638 \InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 __data __at
13643 \begin_inset LatexCommand \index{at}
13644
13645 \end_inset
13646
13647  (0x31) unsigned char j;
13648 \newline
13649 \InsetSpace ~
13650 \InsetSpace ~
13651 \InsetSpace ~
13652 \InsetSpace ~
13653 ...
13654  
13655 \newline
13656 }
13657 \end_layout
13658
13659 \begin_layout Standard
13660 In the above example the variable 
13661 \emph on
13662 i
13663 \emph default
13664  will be allocated in the external ram, 
13665 \emph on
13666 bvar
13667 \emph default
13668  in bit addressable space and
13669 \emph on
13670  j
13671 \emph default
13672  in internal ram.
13673  When compiled with 
13674 \emph on
13675 -
13676 \begin_inset ERT
13677 status collapsed
13678
13679 \begin_layout Standard
13680
13681
13682 \backslash
13683 /
13684 \end_layout
13685
13686 \end_inset
13687
13688 -stack-auto
13689 \emph default
13690  or when a function is declared as 
13691 \emph on
13692 reentrant
13693 \emph default
13694  this should only be done for static variables.
13695 \end_layout
13696
13697 \begin_layout Standard
13698 Parameters
13699 \begin_inset LatexCommand \index{function parameter}
13700
13701 \end_inset
13702
13703  however are not allowed any storage class
13704 \begin_inset LatexCommand \index{Storage class}
13705
13706 \end_inset
13707
13708 , (storage classes for parameters will be ignored), their allocation is
13709  governed by the memory model in use, and the reentrancy options.
13710 \end_layout
13711
13712 \begin_layout Standard
13713 It is however allowed to use bit parameters in reentrant functions and also
13714  non-static local bit variables are supported.
13715  Efficient use is limited to 8 semi-bitregisters in bit space.
13716  They are pushed and popped to stack
13717 \begin_inset LatexCommand \index{stack}
13718
13719 \end_inset
13720
13721  as a single byte just like the normal registers.
13722 \end_layout
13723
13724 \begin_layout Section
13725 Overlaying
13726 \begin_inset LatexCommand \label{sub:Overlaying}
13727
13728 \end_inset
13729
13730
13731 \begin_inset LatexCommand \index{Overlaying}
13732
13733 \end_inset
13734
13735
13736 \end_layout
13737
13738 \begin_layout Standard
13739 For non-reentrant
13740 \begin_inset LatexCommand \index{reentrant}
13741
13742 \end_inset
13743
13744  functions SDCC will try to reduce internal ram space usage by overlaying
13745  parameters and local variables of a function (if possible).
13746  Parameters and local variables
13747 \begin_inset LatexCommand \index{local variables}
13748
13749 \end_inset
13750
13751  of a function will be allocated to an overlayable segment if the function
13752  has 
13753 \emph on
13754 no other function calls and the function is non-reentrant and the memory
13755  model
13756 \begin_inset LatexCommand \index{Memory model}
13757
13758 \end_inset
13759
13760  is small.
13761
13762 \emph default
13763  If an explicit storage class
13764 \begin_inset LatexCommand \index{Storage class}
13765
13766 \end_inset
13767
13768  is specified for a local variable, it will NOT be overlayed.
13769 \end_layout
13770
13771 \begin_layout Standard
13772 Note that the compiler (not the linkage editor) makes the decision for overlayin
13773 g the data items.
13774  Functions that are called from an interrupt service routine
13775 \begin_inset Marginal
13776 status collapsed
13777
13778 \begin_layout Standard
13779
13780 \series bold
13781 !
13782 \end_layout
13783
13784 \end_inset
13785
13786  should be preceded by a #pragma\InsetSpace ~
13787 nooverlay
13788 \begin_inset LatexCommand \index{\#pragma nooverlay}
13789
13790 \end_inset
13791
13792  if they are not reentrant.
13793 \end_layout
13794
13795 \begin_layout Standard
13796 Also note that the compiler does not do any processing of inline assembler
13797  code, so the compiler might incorrectly assign local variables and parameters
13798  of a function into the overlay segment if the inline assembler code calls
13799  other c-functions that might use the overlay.
13800  In that case the #pragma\InsetSpace ~
13801 nooverlay should be used.
13802 \end_layout
13803
13804 \begin_layout Standard
13805 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13806 tion
13807 \begin_inset LatexCommand \index{Multiplication}
13808
13809 \end_inset
13810
13811  or division
13812 \begin_inset LatexCommand \index{Division}
13813
13814 \end_inset
13815
13816  will NOT be overlayed since these are implemented using external functions,
13817  e.g.:
13818 \end_layout
13819
13820 \begin_layout Verse
13821
13822 \family typewriter
13823 #pragma save 
13824 \newline
13825 #pragma nooverlay
13826 \begin_inset LatexCommand \index{\#pragma nooverlay}
13827
13828 \end_inset
13829
13830  
13831 \newline
13832 void set_error(unsigned char errcd) 
13833 \newline
13834 {
13835 \newline
13836 \InsetSpace ~
13837 \InsetSpace ~
13838 \InsetSpace ~
13839 \InsetSpace ~
13840 P3 = errcd;
13841 \newline
13842
13843 \newline
13844 #pragma restore 
13845 \newline
13846
13847 \newline
13848 void
13849  some_isr () __interrupt
13850 \begin_inset LatexCommand \index{interrupt}
13851
13852 \end_inset
13853
13854  (2)
13855 \newline
13856 {
13857 \newline
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 \InsetSpace ~
13862 ...
13863 \newline
13864 \InsetSpace ~
13865 \InsetSpace ~
13866 \InsetSpace ~
13867 \InsetSpace ~
13868 set_error(10);
13869 \newline
13870 \InsetSpace ~
13871 \InsetSpace ~
13872 \InsetSpace ~
13873 \InsetSpace ~
13874 ...
13875  
13876 \newline
13877 }
13878 \end_layout
13879
13880 \begin_layout Standard
13881 In the above example the parameter 
13882 \emph on
13883 errcd
13884 \emph default
13885  for the function 
13886 \emph on
13887 set_error
13888 \emph default
13889  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13890 nooverlay was
13891  not present, this could cause unpredictable runtime behavior when called
13892  from an interrupt service routine.
13893  The #pragma\InsetSpace ~
13894 nooverlay ensures that the parameters and local variables for
13895  the function are NOT overlayed.
13896 \begin_inset VSpace bigskip
13897 \end_inset
13898
13899
13900 \end_layout
13901
13902 \begin_layout Section
13903 Interrupt Service Routines
13904 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13905
13906 \end_inset
13907
13908
13909 \end_layout
13910
13911 \begin_layout Subsection
13912 General Information
13913 \end_layout
13914
13915 \begin_layout Standard
13916 SDCC allows 
13917 \emph on
13918 i
13919 \emph default
13920 nterrupt 
13921 \emph on
13922 s
13923 \emph default
13924 ervice 
13925 \emph on
13926 r
13927 \emph default
13928 outines to be coded in C, with some extended keywords.
13929 \end_layout
13930
13931 \begin_layout Verse
13932
13933 \family typewriter
13934 void timer_isr (void) __interrupt (1) __using (1) 
13935 \newline
13936
13937 \newline
13938 \InsetSpace ~
13939 \InsetSpace ~
13940 \InsetSpace ~
13941 \InsetSpace ~
13942 ...
13943  
13944 \newline
13945 }
13946 \end_layout
13947
13948 \begin_layout Standard
13949 The optional number following the 
13950 \emph on
13951 interrupt
13952 \begin_inset LatexCommand \index{interrupt}
13953
13954 \end_inset
13955
13956
13957 \begin_inset LatexCommand \index{\_\_interrupt}
13958
13959 \end_inset
13960
13961
13962 \emph default
13963  keyword is the interrupt number this routine will service.
13964  When present, the compiler will insert a call to this routine in the interrupt
13965  vector table
13966 \begin_inset LatexCommand \index{interrupt vector table}
13967
13968 \end_inset
13969
13970  for the interrupt number specified.
13971  If you have multiple source files in your project, interrupt service routines
13972  can be present in any of them, but a prototype of the isr MUST be present
13973  or included in the file that contains the function 
13974 \emph on
13975 main
13976 \emph default
13977 .
13978  The optional (8051 specific) keyword 
13979 \emph on
13980 using
13981 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13982
13983 \end_inset
13984
13985
13986 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13987
13988 \end_inset
13989
13990
13991 \emph default
13992  can be used to tell the compiler to use the specified register bank when
13993  generating code for this function.
13994  
13995 \newline
13996 Interrupt service routines open the door for some very interesting bugs:
13997 \end_layout
13998
13999 \begin_layout Subsubsection
14000 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14001
14002 \end_inset
14003
14004 Common interrupt pitfall: variable not declared 
14005 \emph on
14006 volatile
14007 \end_layout
14008
14009 \begin_layout Standard
14010 If an interrupt service routine changes variables which are accessed by
14011  other functions these variables have to be declared 
14012 \emph on
14013 volatile
14014 \emph default
14015
14016 \begin_inset LatexCommand \index{volatile}
14017
14018 \end_inset
14019
14020 .
14021  See 
14022 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14023
14024 \end_inset
14025
14026  .
14027 \end_layout
14028
14029 \begin_layout Subsubsection
14030 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14031
14032 \end_inset
14033
14034 Common interrupt pitfall: 
14035 \emph on
14036 non-atomic access
14037 \end_layout
14038
14039 \begin_layout Standard
14040 If the access to these variables is not 
14041 \emph on
14042 atomic
14043 \begin_inset LatexCommand \index{atomic}
14044
14045 \end_inset
14046
14047
14048 \emph default
14049  (i.e.
14050  the processor needs more than one instruction for the access and could
14051  be interrupted while accessing the variable) the interrupt must be disabled
14052  during the access to avoid inconsistent data.
14053  
14054 \newline
14055 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14056  and should be protected by disabling interrupts.
14057  You're not automatically on the safe side if you use 8 bit variables though.
14058  We need an example here: f.e.
14059  on the 8051 the harmless looking 
14060 \begin_inset Quotes srd
14061 \end_inset
14062
14063
14064 \family typewriter
14065 flags\InsetSpace ~
14066 |=\InsetSpace ~
14067 0x80;
14068 \family default
14069
14070 \begin_inset Quotes sld
14071 \end_inset
14072
14073  is not atomic if 
14074 \family typewriter
14075 flags
14076 \family default
14077  resides in xdata.
14078  Setting 
14079 \begin_inset Quotes srd
14080 \end_inset
14081
14082
14083 \family typewriter
14084 flags\InsetSpace ~
14085 |=\InsetSpace ~
14086 0x40;
14087 \family default
14088
14089 \begin_inset Quotes sld
14090 \end_inset
14091
14092  from within an interrupt routine might get lost if the interrupt occurs
14093  at the wrong time.
14094  
14095 \begin_inset Quotes sld
14096 \end_inset
14097
14098
14099 \family typewriter
14100 counter\InsetSpace ~
14101 +=\InsetSpace ~
14102 8;
14103 \family default
14104
14105 \begin_inset Quotes srd
14106 \end_inset
14107
14108  is not atomic on the 8051 even if 
14109 \family typewriter
14110 counter
14111 \family default
14112  is located in data memory.
14113 \newline
14114 Bugs like these are hard to reproduce and can
14115  cause a lot of trouble.
14116  
14117 \end_layout
14118
14119 \begin_layout Subsubsection
14120 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14121
14122 \end_inset
14123
14124 Common interrupt pitfall: 
14125 \emph on
14126 stack overflow
14127 \end_layout
14128
14129 \begin_layout Standard
14130 The return address and the registers used in the interrupt service routine
14131  are saved on the stack
14132 \begin_inset LatexCommand \index{stack}
14133
14134 \end_inset
14135
14136  so there must be sufficient stack space.
14137  If there isn't variables or registers (or even the return address itself)
14138  will be corrupted.
14139  This 
14140 \emph on
14141 stack overflow
14142 \emph default
14143
14144 \begin_inset LatexCommand \index{stack overflow}
14145
14146 \end_inset
14147
14148  is most likely to happen if the interrupt occurs during the 
14149 \begin_inset Quotes sld
14150 \end_inset
14151
14152 deepest
14153 \begin_inset Quotes srd
14154 \end_inset
14155
14156  subroutine when the stack is already in use for f.e.
14157  many return addresses.
14158 \end_layout
14159
14160 \begin_layout Subsubsection
14161 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14162
14163 \end_inset
14164
14165 Common interrupt pitfall: 
14166 \emph on
14167 use of non-reentrant functions
14168 \end_layout
14169
14170 \begin_layout Standard
14171 A special note here, int (16 bit) and long (32 bit) integer division
14172 \begin_inset LatexCommand \index{Division}
14173
14174 \end_inset
14175
14176 , multiplication
14177 \begin_inset LatexCommand \index{Multiplication}
14178
14179 \end_inset
14180
14181  & modulus
14182 \begin_inset LatexCommand \index{Modulus}
14183
14184 \end_inset
14185
14186  and floating-point
14187 \begin_inset LatexCommand \index{Floating point support}
14188
14189 \end_inset
14190
14191  operations are implemented using external support routines.
14192  If an interrupt service routine needs to do any of these operations then
14193  the support routines (as mentioned in a following section) will have to
14194  be recompiled using the
14195 \emph on
14196  -
14197 \begin_inset ERT
14198 status collapsed
14199
14200 \begin_layout Standard
14201
14202
14203 \backslash
14204 /
14205 \end_layout
14206
14207 \end_inset
14208
14209 -stack-auto
14210 \begin_inset LatexCommand \index{-\/-stack-auto}
14211
14212 \end_inset
14213
14214
14215 \emph default
14216  option and the source file will need to be compiled using the 
14217 \emph on
14218 -
14219 \begin_inset ERT
14220 status collapsed
14221
14222 \begin_layout Standard
14223
14224
14225 \backslash
14226 /
14227 \end_layout
14228
14229 \end_inset
14230
14231 -int-long-reent
14232 \emph default
14233
14234 \begin_inset LatexCommand \index{-\/-int-long-reent}
14235
14236 \end_inset
14237
14238  compiler option.
14239  
14240 \newline
14241 Note, the type promotion
14242 \begin_inset LatexCommand \index{type promotion}
14243
14244 \end_inset
14245
14246  required by ANSI C can cause 16 bit routines to be used
14247 \begin_inset Marginal
14248 status collapsed
14249
14250 \begin_layout Standard
14251
14252 \series bold
14253 \InsetSpace ~
14254 !
14255 \end_layout
14256
14257 \end_inset
14258
14259  without the programmer being aware of it.
14260  See f.e.
14261  the cast 
14262 \family typewriter
14263 (unsigned char)(tail-1)
14264 \family default
14265  within the if clause in section 
14266 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14267
14268 \end_inset
14269
14270 .
14271 \end_layout
14272
14273 \begin_layout Standard
14274 Calling other functions from an interrupt service routine is not recommended,
14275  avoid it if possible.
14276  Note that when some function is called from an interrupt service routine
14277  it should be preceded by a #pragma\InsetSpace ~
14278 nooverlay
14279 \begin_inset LatexCommand \index{\#pragma nooverlay}
14280
14281 \end_inset
14282
14283  if it is not reentrant.
14284  Furthermore nonreentrant functions should not be called from the main program
14285  while the interrupt service routine might be active.
14286  They also must not be called from low priority interrupt service routines
14287  while a high priority interrupt service routine might be active.
14288  You could use semaphores or make the function
14289 \emph on
14290  critical
14291 \emph default
14292  if all parameters are passed in registers.
14293 \newline
14294  Also see section 
14295 \begin_inset LatexCommand \ref{sub:Overlaying}
14296
14297 \end_inset
14298
14299 \InsetSpace ~
14300 about Overlaying and section 
14301 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14302
14303 \end_inset
14304
14305 \InsetSpace ~
14306 about Functions using private register banks.
14307 \begin_inset VSpace bigskip
14308 \end_inset
14309
14310
14311 \end_layout
14312
14313 \begin_layout Subsection
14314 MCS51/DS390 Interrupt Service Routines
14315 \end_layout
14316
14317 \begin_layout Standard
14318 Interrupt
14319 \begin_inset LatexCommand \index{interrupt}
14320
14321 \end_inset
14322
14323  numbers and the corresponding address & descriptions for the Standard 8051/8052
14324  are listed below.
14325  SDCC will automatically adjust the 
14326 \begin_inset LatexCommand \index{interrupt vector table}
14327
14328 \end_inset
14329
14330  to the maximum interrupt number specified.
14331 \newline
14332
14333 \end_layout
14334
14335 \begin_layout Standard
14336 \align center
14337 \begin_inset Tabular
14338 <lyxtabular version="3" rows="9" columns="3">
14339 <features>
14340 <column alignment="center" valignment="top" leftline="true" width="0in">
14341 <column alignment="left" valignment="top" leftline="true" width="0in">
14342 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14343 <row topline="true" bottomline="true">
14344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14345 \begin_inset Text
14346
14347 \begin_layout Standard
14348 Interrupt #
14349 \end_layout
14350
14351 \end_inset
14352 </cell>
14353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14354 \begin_inset Text
14355
14356 \begin_layout Standard
14357 Description
14358 \end_layout
14359
14360 \end_inset
14361 </cell>
14362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14363 \begin_inset Text
14364
14365 \begin_layout Standard
14366 Vector Address
14367 \end_layout
14368
14369 \end_inset
14370 </cell>
14371 </row>
14372 <row topline="true">
14373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14374 \begin_inset Text
14375
14376 \begin_layout Standard
14377 0
14378 \end_layout
14379
14380 \end_inset
14381 </cell>
14382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14383 \begin_inset Text
14384
14385 \begin_layout Standard
14386 External 0
14387 \end_layout
14388
14389 \end_inset
14390 </cell>
14391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14392 \begin_inset Text
14393
14394 \begin_layout Standard
14395 0x0003
14396 \end_layout
14397
14398 \end_inset
14399 </cell>
14400 </row>
14401 <row topline="true">
14402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14403 \begin_inset Text
14404
14405 \begin_layout Standard
14406 1
14407 \end_layout
14408
14409 \end_inset
14410 </cell>
14411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14412 \begin_inset Text
14413
14414 \begin_layout Standard
14415 Timer 0
14416 \end_layout
14417
14418 \end_inset
14419 </cell>
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14421 \begin_inset Text
14422
14423 \begin_layout Standard
14424 0x000b
14425 \end_layout
14426
14427 \end_inset
14428 </cell>
14429 </row>
14430 <row topline="true">
14431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14432 \begin_inset Text
14433
14434 \begin_layout Standard
14435 2
14436 \end_layout
14437
14438 \end_inset
14439 </cell>
14440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14441 \begin_inset Text
14442
14443 \begin_layout Standard
14444 External 1
14445 \end_layout
14446
14447 \end_inset
14448 </cell>
14449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14450 \begin_inset Text
14451
14452 \begin_layout Standard
14453 0x0013
14454 \end_layout
14455
14456 \end_inset
14457 </cell>
14458 </row>
14459 <row topline="true">
14460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14461 \begin_inset Text
14462
14463 \begin_layout Standard
14464 3
14465 \end_layout
14466
14467 \end_inset
14468 </cell>
14469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14470 \begin_inset Text
14471
14472 \begin_layout Standard
14473 Timer 1
14474 \end_layout
14475
14476 \end_inset
14477 </cell>
14478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14479 \begin_inset Text
14480
14481 \begin_layout Standard
14482 0x001b
14483 \end_layout
14484
14485 \end_inset
14486 </cell>
14487 </row>
14488 <row topline="true">
14489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14490 \begin_inset Text
14491
14492 \begin_layout Standard
14493 4
14494 \end_layout
14495
14496 \end_inset
14497 </cell>
14498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14499 \begin_inset Text
14500
14501 \begin_layout Standard
14502 Serial
14503 \end_layout
14504
14505 \end_inset
14506 </cell>
14507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14508 \begin_inset Text
14509
14510 \begin_layout Standard
14511 0x0023
14512 \end_layout
14513
14514 \end_inset
14515 </cell>
14516 </row>
14517 <row topline="true">
14518 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14519 \begin_inset Text
14520
14521 \begin_layout Standard
14522 5
14523 \end_layout
14524
14525 \end_inset
14526 </cell>
14527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14528 \begin_inset Text
14529
14530 \begin_layout Standard
14531 Timer 2 (8052)
14532 \end_layout
14533
14534 \end_inset
14535 </cell>
14536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14537 \begin_inset Text
14538
14539 \begin_layout Standard
14540 0x002b
14541 \end_layout
14542
14543 \end_inset
14544 </cell>
14545 </row>
14546 <row topline="true">
14547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14548 \begin_inset Text
14549
14550 \begin_layout Standard
14551 ...
14552 \end_layout
14553
14554 \end_inset
14555 </cell>
14556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14557 \begin_inset Text
14558
14559 \begin_layout Standard
14560
14561 \end_layout
14562
14563 \end_inset
14564 </cell>
14565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14566 \begin_inset Text
14567
14568 \begin_layout Standard
14569 ...
14570 \end_layout
14571
14572 \end_inset
14573 </cell>
14574 </row>
14575 <row topline="true" bottomline="true">
14576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14577 \begin_inset Text
14578
14579 \begin_layout Standard
14580 n
14581 \end_layout
14582
14583 \end_inset
14584 </cell>
14585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14586 \begin_inset Text
14587
14588 \begin_layout Standard
14589
14590 \end_layout
14591
14592 \end_inset
14593 </cell>
14594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14595 \begin_inset Text
14596
14597 \begin_layout Standard
14598 0x0003 + 8*n
14599 \end_layout
14600
14601 \end_inset
14602 </cell>
14603 </row>
14604 </lyxtabular>
14605
14606 \end_inset
14607
14608
14609 \newline
14610
14611 \end_layout
14612
14613 \begin_layout Standard
14614 If the interrupt service routine is defined without 
14615 \emph on
14616 using
14617 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14618
14619 \end_inset
14620
14621
14622 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14623
14624 \end_inset
14625
14626
14627 \emph default
14628  a register bank or with register bank 0 (
14629 \emph on
14630 using
14631 \emph default
14632  0), the compiler will save the registers used by itself on the stack upon
14633  entry and restore them at exit, however if such an interrupt service routine
14634  calls another function then the entire register bank will be saved on the
14635  stack.
14636  This scheme may be advantageous for small interrupt service routines which
14637  have low register usage.
14638 \end_layout
14639
14640 \begin_layout Standard
14641 If the interrupt service routine is defined to be using a specific register
14642  bank then only 
14643 \emph on
14644 a, b, dptr
14645 \emph default
14646  & psw are saved and restored, if such an interrupt service routine calls
14647  another function (using another register bank) then the entire register
14648  bank of the called function will be saved on the stack
14649 \begin_inset LatexCommand \index{stack}
14650
14651 \end_inset
14652
14653 .
14654  This scheme is recommended for larger interrupt service routines.
14655 \begin_inset VSpace bigskip
14656 \end_inset
14657
14658
14659 \end_layout
14660
14661 \begin_layout Subsection
14662 HC08
14663 \begin_inset LatexCommand \index{HC08}
14664
14665 \end_inset
14666
14667  Interrupt Service Routines
14668 \end_layout
14669
14670 \begin_layout Standard
14671 Since the number of interrupts
14672 \begin_inset LatexCommand \index{HC08!interrupt}
14673
14674 \end_inset
14675
14676  available is chip specific and the interrupt vector table always ends at
14677  the last byte of memory, the interrupt numbers corresponds to the interrupt
14678  vectors in reverse order of address.
14679  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14680  2 will use the interrupt vector at 0xfffa, and so on.
14681  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14682  this way; instead see section 
14683 \begin_inset LatexCommand \ref{sub:Startup-Code}
14684
14685 \end_inset
14686
14687  for details on customizing startup.
14688 \begin_inset VSpace bigskip
14689 \end_inset
14690
14691
14692 \end_layout
14693
14694 \begin_layout Subsection
14695 Z80 Interrupt Service Routines
14696 \end_layout
14697
14698 \begin_layout Standard
14699 The Z80
14700 \begin_inset LatexCommand \index{Z80}
14701
14702 \end_inset
14703
14704  uses several different methods for determining the correct interrupt
14705 \begin_inset LatexCommand \index{Z80!interrupt}
14706
14707 \end_inset
14708
14709  vector depending on the hardware implementation.
14710  Therefore, SDCC ignores the optional interrupt number and does not attempt
14711  to generate an interrupt vector table.
14712 \end_layout
14713
14714 \begin_layout Standard
14715 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14716  instruction to return from the interrupt.
14717  To write an interrupt handler for the non-maskable interrupt, which needs
14718  a RETN instruction instead, add the 
14719 \emph on
14720 critical
14721 \emph default
14722  keyword:
14723 \end_layout
14724
14725 \begin_layout Verse
14726
14727 \family typewriter
14728 void nmi_isr (void) critical interrupt
14729 \newline
14730
14731 \newline
14732 \InsetSpace ~
14733 \InsetSpace ~
14734 \InsetSpace ~
14735 \InsetSpace ~
14736 ...
14737  
14738 \newline
14739 }
14740 \end_layout
14741
14742 \begin_layout Standard
14743 However if you need to create a non-interruptable interrupt service routine
14744  you would also require the 
14745 \emph on
14746 critical
14747 \emph default
14748  keyword.
14749  To distinguish between this and an nmi_isr you must provide an interrupt
14750  number.
14751 \begin_inset VSpace bigskip
14752 \end_inset
14753
14754
14755 \end_layout
14756
14757 \begin_layout Section
14758 Enabling and Disabling Interrupts
14759 \end_layout
14760
14761 \begin_layout Subsection
14762 Critical Functions and Critical Statements
14763 \end_layout
14764
14765 \begin_layout Standard
14766 A special keyword may be associated with a block or a function declaring
14767  it as 
14768 \emph on
14769 critical
14770 \emph default
14771 .
14772  SDCC will generate code to disable all interrupts
14773 \begin_inset LatexCommand \index{interrupt}
14774
14775 \end_inset
14776
14777  upon entry to a critical function and restore the interrupt enable to the
14778  previous state before returning.
14779  Nesting critical functions will need one additional byte on the stack
14780 \begin_inset LatexCommand \index{stack}
14781
14782 \end_inset
14783
14784  for each call.
14785 \end_layout
14786
14787 \begin_layout Verse
14788
14789 \family typewriter
14790 int foo () __critical
14791 \begin_inset LatexCommand \index{critical}
14792
14793 \end_inset
14794
14795
14796 \begin_inset LatexCommand \index{\_\_critical}
14797
14798 \end_inset
14799
14800  
14801 \newline
14802
14803 \newline
14804 \InsetSpace ~
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 ...
14809  
14810 \newline
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 ...
14816  
14817 \newline
14818 }
14819 \end_layout
14820
14821 \begin_layout Standard
14822 The critical attribute maybe used with other attributes like 
14823 \emph on
14824 reentrant.
14825 \emph default
14826
14827 \newline
14828 The keyword 
14829 \emph on
14830 critical
14831 \emph default
14832  may also be used to disable interrupts more locally:
14833 \end_layout
14834
14835 \begin_layout Verse
14836
14837 \family typewriter
14838 __critical{ i++; }
14839 \end_layout
14840
14841 \begin_layout Standard
14842 More than one statement could have been included in the block.
14843 \end_layout
14844
14845 \begin_layout Subsection
14846 Enabling and Disabling Interrupts directly
14847 \end_layout
14848
14849 \begin_layout Standard
14850 Interrupts
14851 \begin_inset LatexCommand \index{interrupt}
14852
14853 \end_inset
14854
14855  can also be disabled and enabled directly (8051):
14856 \end_layout
14857
14858 \begin_layout Verse
14859
14860 \family typewriter
14861 EA = 0;\InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 \InsetSpace ~
14869 \InsetSpace ~
14870 \InsetSpace ~
14871 \InsetSpace ~
14872 \InsetSpace ~
14873 or:\InsetSpace ~
14874 \InsetSpace ~
14875 \InsetSpace ~
14876 \InsetSpace ~
14877 \InsetSpace ~
14878 \InsetSpace ~
14879 \InsetSpace ~
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 EA_SAVE = EA;
14885 \end_layout
14886
14887 \begin_layout Verse
14888
14889 \family typewriter
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 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 \InsetSpace ~
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 EA = 0;
14921 \end_layout
14922
14923 \begin_layout Verse
14924
14925 \family typewriter
14926 EA = 1;\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 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 \InsetSpace ~
14951 \InsetSpace ~
14952 ...
14953 \end_layout
14954
14955 \begin_layout Verse
14956
14957 \family typewriter
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 \InsetSpace ~
14982 \InsetSpace ~
14983 \InsetSpace ~
14984 \InsetSpace ~
14985 \InsetSpace ~
14986 \InsetSpace ~
14987 \InsetSpace ~
14988 \InsetSpace ~
14989 \InsetSpace ~
14990 \InsetSpace ~
14991 EA = EA_SAVE;
14992 \end_layout
14993
14994 \begin_layout Standard
14995 On other architectures which have seperate opcodes for enabling and disabling
14996  interrupts you might want to make use of defines with inline assembly
14997 \begin_inset LatexCommand \index{Assembler routines}
14998
14999 \end_inset
15000
15001  (HC08
15002 \begin_inset LatexCommand \index{HC08!interrupt}
15003
15004 \end_inset
15005
15006 ):
15007 \end_layout
15008
15009 \begin_layout Verse
15010
15011 \family typewriter
15012 #define CLI _asm
15013 \begin_inset LatexCommand \index{\_asm}
15014
15015 \end_inset
15016
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 cli\InsetSpace ~
15020 \InsetSpace ~
15021 _endasm
15022 \begin_inset LatexCommand \index{\_endasm}
15023
15024 \end_inset
15025
15026
15027 \end_layout
15028
15029 \begin_layout Verse
15030
15031 \family typewriter
15032 #define SEI _asm\InsetSpace ~
15033 \InsetSpace ~
15034 sei\InsetSpace ~
15035 \InsetSpace ~
15036 _endasm; 
15037 \end_layout
15038
15039 \begin_layout Verse
15040
15041 \family typewriter
15042 ...
15043 \end_layout
15044
15045 \begin_layout Standard
15046 Note: it is sometimes sufficient to disable only a specific interrupt source
15047  like f.e.
15048  a timer or serial interrupt by manipulating an 
15049 \emph on
15050 interrupt mask
15051 \begin_inset LatexCommand \index{interrupt mask}
15052
15053 \end_inset
15054
15055
15056 \emph default
15057  register.
15058  
15059 \end_layout
15060
15061 \begin_layout Standard
15062 Usually the time during which interrupts are disabled should be kept as
15063  short as possible.
15064  This minimizes both 
15065 \emph on
15066 interrupt latency
15067 \emph default
15068
15069 \begin_inset LatexCommand \index{interrupt latency}
15070
15071 \end_inset
15072
15073  (the time between the occurrence of the interrupt and the execution of
15074  the first code in the interrupt routine) and 
15075 \emph on
15076 interrupt jitter
15077 \emph default
15078
15079 \begin_inset LatexCommand \index{interrupt jitter}
15080
15081 \end_inset
15082
15083  (the difference between the shortest and the longest interrupt latency).
15084  These really are something different, f.e.
15085  a serial interrupt has to be served before its buffer overruns so it cares
15086  for the maximum interrupt latency, whereas it does not care about jitter.
15087  On a loudspeaker driven via a digital to analog converter which is fed
15088  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15089  a much smaller jitter will be very audible.
15090 \end_layout
15091
15092 \begin_layout Standard
15093 You can reenable interrupts within an interrupt routine and on some architecture
15094 s you can make use of two (or more) levels of 
15095 \emph on
15096 interrupt priorities
15097 \emph default
15098
15099 \begin_inset LatexCommand \index{interrupt priority}
15100
15101 \end_inset
15102
15103 .
15104  On some architectures which don't support interrupt priorities these can
15105  be implemented by manipulating the interrupt mask and reenabling interrupts
15106  within the interrupt routine.
15107  Check there is sufficient space on the stack
15108 \begin_inset LatexCommand \index{stack}
15109
15110 \end_inset
15111
15112  and don't add complexity unless you have to.
15113  
15114 \end_layout
15115
15116 \begin_layout Subsection
15117 Semaphore
15118 \begin_inset LatexCommand \index{semaphore}
15119
15120 \end_inset
15121
15122  locking (mcs51/ds390)
15123 \end_layout
15124
15125 \begin_layout Standard
15126 Some architectures (mcs51/ds390) have an atomic
15127 \begin_inset LatexCommand \index{atomic}
15128
15129 \end_inset
15130
15131  bit test and
15132 \emph on
15133  
15134 \emph default
15135 clear
15136 \emph on
15137  
15138 \emph default
15139 instruction.
15140  These type of instructions are typically used in preemptive multitasking
15141  systems, where a routine f.e.
15142  claims the use of a data structure ('acquires a lock
15143 \begin_inset LatexCommand \index{lock}
15144
15145 \end_inset
15146
15147  on it'), makes some modifications and then releases the lock when the data
15148  structure is consistent again.
15149  The instruction may also be used if interrupt and non-interrupt code have
15150  to compete for a resource.
15151  With the atomic bit test and clear instruction interrupts
15152 \begin_inset LatexCommand \index{interrupt}
15153
15154 \end_inset
15155
15156  don't have to be disabled for the locking operation.
15157  
15158 \end_layout
15159
15160 \begin_layout Standard
15161 SDCC generates this instruction if the source follows this pattern:
15162 \end_layout
15163
15164 \begin_layout Verse
15165
15166 \family typewriter
15167 volatile
15168 \begin_inset LatexCommand \index{volatile}
15169
15170 \end_inset
15171
15172  bit resource_is_free; 
15173 \newline
15174
15175 \newline
15176 if (resource_is_free) 
15177 \newline
15178 \InsetSpace ~
15179 \InsetSpace ~
15180
15181 \newline
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 resource_is_free=0; 
15187 \newline
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 ...
15193  
15194 \newline
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 resource_is_free=1;
15200 \newline
15201 \InsetSpace ~
15202 \InsetSpace ~
15203
15204 \end_layout
15205
15206 \begin_layout Standard
15207 Note, mcs51 and ds390 support only an atomic
15208 \begin_inset LatexCommand \index{atomic}
15209
15210 \end_inset
15211
15212  bit test and 
15213 \emph on
15214 clear
15215 \emph default
15216  instruction (as opposed to atomic bit test and 
15217 \emph on
15218 set).
15219 \end_layout
15220
15221 \begin_layout Section
15222 Functions using private register banks
15223 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15224
15225 \end_inset
15226
15227  (mcs51/ds390)
15228 \end_layout
15229
15230 \begin_layout Standard
15231 Some architectures have support for quickly changing register sets.
15232  SDCC supports this feature with the 
15233 \emph on
15234 using
15235 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15236
15237 \end_inset
15238
15239
15240 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15241
15242 \end_inset
15243
15244
15245 \emph default
15246  attribute (which tells the compiler to use a register bank
15247 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15248
15249 \end_inset
15250
15251  other than the default bank zero).
15252  It should only be applied to 
15253 \emph on
15254 interrupt
15255 \begin_inset LatexCommand \index{interrupt}
15256
15257 \end_inset
15258
15259
15260 \emph default
15261  functions (see footnote below).
15262  This will in most circumstances make the generated ISR code more efficient
15263  since it will not have to save registers on the stack.
15264 \end_layout
15265
15266 \begin_layout Standard
15267 The 
15268 \emph on
15269 using
15270 \emph default
15271  attribute will have no effect on the generated code for a 
15272 \emph on
15273 non-interrupt
15274 \emph default
15275  function (but may occasionally be useful anyway
15276 \begin_inset Foot
15277 status open
15278
15279 \begin_layout Standard
15280 possible exception: if a function is called ONLY from 'interrupt' functions
15281  using a particular bank, it can be declared with the same 'using' attribute
15282  as the calling 'interrupt' functions.
15283  For instance, if you have several ISRs using bank one, and all of them
15284  call memcpy(), it might make sense to create a specialized version of memcpy()
15285  'using 1', since this would prevent the ISR from having to save bank zero
15286  to the stack on entry and switch to bank zero before calling the function
15287 \end_layout
15288
15289 \end_inset
15290
15291 ).
15292 \newline
15293
15294 \emph on
15295 (pending: Note, nowadays the 
15296 \emph default
15297 using
15298 \emph on
15299  attribute has an effect on
15300 \emph default
15301  
15302 \emph on
15303 the generated code for a 
15304 \emph default
15305 non-interrupt
15306 \emph on
15307  function
15308 \emph default
15309 .
15310 \emph on
15311 )
15312 \end_layout
15313
15314 \begin_layout Standard
15315 An 
15316 \emph on
15317 interrupt
15318 \emph default
15319  function using a non-zero bank will assume that it can trash that register
15320  bank, and will not save it.
15321  Since high-priority interrupts
15322 \begin_inset LatexCommand \index{interrupts}
15323
15324 \end_inset
15325
15326
15327 \begin_inset LatexCommand \index{interrupt priority}
15328
15329 \end_inset
15330
15331  can interrupt low-priority ones on the 8051 and friends, this means that
15332  if a high-priority ISR 
15333 \emph on
15334 using
15335 \emph default
15336  a particular bank occurs while processing a low-priority ISR 
15337 \emph on
15338 using
15339 \emph default
15340  the same bank, terrible and bad things can happen.
15341  To prevent this, no single register bank should be 
15342 \emph on
15343 used
15344 \emph default
15345  by both a high priority and a low priority ISR.
15346  This is probably most easily done by having all high priority ISRs use
15347  one bank and all low priority ISRs use another.
15348  If you have an ISR which can change priority at runtime, you're on your
15349  own: I suggest using the default bank zero and taking the small performance
15350  hit.
15351 \end_layout
15352
15353 \begin_layout Standard
15354 It is most efficient if your ISR calls no other functions.
15355  If your ISR must call other functions, it is most efficient if those functions
15356  use the same bank as the ISR (see note 1 below); the next best is if the
15357  called functions use bank zero.
15358  It is very inefficient to call a function using a different, non-zero bank
15359  from an ISR.
15360  
15361 \begin_inset VSpace bigskip
15362 \end_inset
15363
15364
15365 \end_layout
15366
15367 \begin_layout Section
15368 Startup Code
15369 \begin_inset LatexCommand \label{sub:Startup-Code}
15370
15371 \end_inset
15372
15373
15374 \begin_inset LatexCommand \index{Startup code}
15375
15376 \end_inset
15377
15378
15379 \end_layout
15380
15381 \begin_layout Subsection
15382 MCS51/DS390 Startup Code
15383 \end_layout
15384
15385 \begin_layout Standard
15386 The compiler triggers the linker to link certain initialization modules
15387  from the runtime library
15388 \begin_inset LatexCommand \index{Runtime library}
15389
15390 \end_inset
15391
15392  called crt<something>.
15393  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15394  GSINIT5) is not linked unless the -
15395 \series bold
15396
15397 \begin_inset ERT
15398 status open
15399
15400 \begin_layout Standard
15401
15402
15403 \backslash
15404 /
15405 \end_layout
15406
15407 \end_inset
15408
15409
15410 \series default
15411 -xstack option is used.
15412  These modules are highly entangled by the use of special segments/areas,
15413  but a common layout is shown below:
15414 \end_layout
15415
15416 \begin_layout Verse
15417
15418 \family typewriter
15419 \series bold
15420 \size footnotesize
15421 (main.asm)
15422 \end_layout
15423
15424 \begin_layout Verse
15425
15426 \family typewriter
15427 \size footnotesize
15428 \InsetSpace ~
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 .area HOME (CODE)
15437 \newline
15438 __interrupt_vect:
15439 \newline
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 \InsetSpace ~
15448 ljmp __sdcc_gsinit_startup
15449 \end_layout
15450
15451 \begin_layout Verse
15452
15453 \family typewriter
15454 \series bold
15455 \size footnotesize
15456 (crtstart.asm)
15457 \end_layout
15458
15459 \begin_layout Verse
15460
15461 \family typewriter
15462 \size footnotesize
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 \InsetSpace ~
15468 \InsetSpace ~
15469 \InsetSpace ~
15470 \InsetSpace ~
15471 .area GSINIT0 (CODE)
15472 \newline
15473 __sdcc_gsinit_startup::
15474 \newline
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 mov sp,#__start__stack - 1
15484 \end_layout
15485
15486 \begin_layout Verse
15487
15488 \family typewriter
15489 \series bold
15490 \size footnotesize
15491 (crtxstack.asm)
15492 \end_layout
15493
15494 \begin_layout Verse
15495
15496 \family typewriter
15497 \size footnotesize
15498 \InsetSpace ~
15499 \InsetSpace ~
15500 \InsetSpace ~
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 .area GSINIT1 (CODE)
15507 \newline
15508 __sdcc_init_xstack::
15509 \newline
15510 ; Need to initialize in GSINIT1 in
15511  case the user's __sdcc_external_startup uses the xstack.
15512 \newline
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 \InsetSpace ~
15519 \InsetSpace ~
15520 \InsetSpace ~
15521 mov __XPAGE,#(__start__x
15522 stack >> 8)
15523 \newline
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 mov _spx,#__start__xstack
15533 \end_layout
15534
15535 \begin_layout Verse
15536
15537 \family typewriter
15538 \series bold
15539 \size footnotesize
15540 (crtstart.asm)
15541 \end_layout
15542
15543 \begin_layout Verse
15544
15545 \family typewriter
15546 \size footnotesize
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 .area GSINIT2 (CODE)
15556 \newline
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 lcall __sdcc_external_startup
15566 \newline
15567 \InsetSpace ~
15568 \InsetSpace ~
15569 \InsetSpace ~
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 mov a,dpl
15576 \newline
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 jz __sdcc_init_data
15586 \newline
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 ljmp
15596  __sdcc_program_startup
15597 \newline
15598 __sdcc_init_data:
15599 \end_layout
15600
15601 \begin_layout Verse
15602
15603 \family typewriter
15604 \series bold
15605 \size footnotesize
15606 (crtxinit.asm)
15607 \end_layout
15608
15609 \begin_layout Verse
15610
15611 \family typewriter
15612 \size footnotesize
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 .area GSINIT3 (CODE)
15622 \newline
15623 __mcs51_genXINIT::
15624 \newline
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 \InsetSpace ~
15632 \InsetSpace ~
15633 mov r1,#l_XINIT
15634 \newline
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 mov a,r1
15644 \newline
15645 \InsetSpace ~
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 orl a,#(l_XINIT
15654  >> 8)
15655 \newline
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 jz 00003$
15665 \newline
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 mov r2,#((l_XINIT+255) >> 8)
15675 \newline
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 mov dptr,#s_XINIT
15685 \newline
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 mov r0,#s_XISEG
15695 \newline
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 mov
15705  __XPAGE,#(s_XISEG >> 8)
15706 \newline
15707 00001$:\InsetSpace ~
15708 clr a
15709 \newline
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 movc a,@a+dptr
15719 \newline
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 movx @r0,a
15729 \newline
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 inc dptr
15739 \newline
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 inc
15749  r0
15750 \newline
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 cjne r0,#0,00002$
15760 \newline
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 inc __XPAGE
15770 \newline
15771 00002$:\InsetSpace ~
15772 djnz r1,00001$
15773 \newline
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 djnz r2,00001$
15783 \newline
15784 \InsetSpace ~
15785 \InsetSpace ~
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 mov __XPAGE,#0
15793 xFF
15794 \newline
15795 00003$:
15796 \end_layout
15797
15798 \begin_layout Verse
15799
15800 \family typewriter
15801 \series bold
15802 \size footnotesize
15803 (crtclear.asm)
15804 \end_layout
15805
15806 \begin_layout Verse
15807
15808 \family typewriter
15809 \size footnotesize
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 .area GSINIT4 (CODE)
15819 \newline
15820 __mcs51_genRAMCLEAR::
15821 \newline
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 clr a
15831 \newline
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 mov r0,#(l_IRAM-1)
15841 \newline
15842 00004$:\InsetSpace ~
15843 mov
15844  @r0,a
15845 \newline
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 djnz r0,00004$
15855 \newline
15856 ; _mcs51_genRAMCLEAR() end
15857 \end_layout
15858
15859 \begin_layout Verse
15860
15861 \family typewriter
15862 \series bold
15863 \size footnotesize
15864 (crtxclear.asm)
15865 \end_layout
15866
15867 \begin_layout Verse
15868
15869 \family typewriter
15870 \size footnotesize
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 .area GSINIT4 (CODE)
15880 \newline
15881 __mcs51_genXRAMCLEAR::
15882 \newline
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 mov r0,#l_PSEG
15892 \newline
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 mov a,r0
15902 \newline
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 jz 00006$
15912 \newline
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 mov
15922  r1,#s_PSEG
15923 \newline
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 mov __XPAGE,#(s_PSEG >> 8)
15933 \newline
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 clr a
15943 \newline
15944 00005$:\InsetSpace ~
15945 movx @r1,a
15946 \newline
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 inc r1
15956 \newline
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 djnz r0,00005$
15966 \newline
15967 0
15968 0006$:
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 mov r0,#l_XSEG
15979 \newline
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 mov a,r0
15989 \newline
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 orl a,#(l_XSEG >> 8)
15999 \newline
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 jz 00008$
16009 \newline
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 mov r1,#((l_XSEG
16019  + 255) >> 8)
16020 \newline
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 mov dptr,#s_XSEG
16030 \newline
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 clr a
16040 \newline
16041 00007$:\InsetSpace ~
16042 movx @dptr,a
16043 \newline
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 inc dptr
16053 \newline
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 djnz r0,00007$
16063 \newline
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 djnz
16073  r1,00007$
16074 \newline
16075 00008$:
16076 \end_layout
16077
16078 \begin_layout Verse
16079
16080 \family typewriter
16081 \series bold
16082 \size footnotesize
16083 (crtxstack.asm)
16084 \end_layout
16085
16086 \begin_layout Verse
16087
16088 \family typewriter
16089 \size footnotesize
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 .area GSINIT5 (CODE)
16099 \newline
16100 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16101  modifies __XPAGE
16102 \newline
16103 ; and __mcs51_genRAMCLEAR modifies _spx.
16104 \newline
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 \InsetSpace ~
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 mov __XPAGE,#(__start__x
16114 stack >> 8)
16115 \newline
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 \InsetSpace ~
16121 \InsetSpace ~
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 mov _spx,#__start__xstack
16125 \end_layout
16126
16127 \begin_layout Verse
16128
16129 \family typewriter
16130 \series bold
16131 \size footnotesize
16132 (application modules)
16133 \end_layout
16134
16135 \begin_layout Verse
16136
16137 \family typewriter
16138 \size footnotesize
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 \InsetSpace ~
16142 \InsetSpace ~
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 .area GSINIT (CODE)
16148 \end_layout
16149
16150 \begin_layout Verse
16151
16152 \family typewriter
16153 \series bold
16154 \size footnotesize
16155 (main.asm)
16156 \end_layout
16157
16158 \begin_layout Verse
16159
16160 \family typewriter
16161 \size footnotesize
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 .area GSFINAL (CODE)
16171 \newline
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 ljmp __sdcc_program_startup
16181 \newline
16182 ;---------------------------------
16183 -----------------------
16184 \newline
16185 ; Home
16186 \newline
16187 ;--------------------------------------------------
16188 ------
16189 \newline
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 .area HOME (CODE)
16199 \newline
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 .area CSEG (CODE)
16209 \newline
16210 __sdcc_program_startup:
16211 \newline
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 lcall _main
16221 \newline
16222 ;
16223  return from main will lock up
16224 \newline
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 sjmp .
16234 \end_layout
16235
16236 \begin_layout Standard
16237 One of these modules (crtstart.asm) contains a call to the C routine 
16238 \emph on
16239 _sdcc_external_startup()
16240 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16241
16242 \end_inset
16243
16244
16245 \series bold
16246 \emph default
16247  
16248 \series default
16249 at the start of the CODE area.
16250  This routine is also in the runtime library
16251 \begin_inset LatexCommand \index{Runtime library}
16252
16253 \end_inset
16254
16255  and returns 0 by default.
16256  If this routine returns a non-zero value, the static & global variable
16257  initialization will be skipped and the function main will be invoked.
16258  Otherwise static & global variables will be initialized before the function
16259  main is invoked.
16260  You could add an 
16261 \emph on
16262 _sdcc_external_startup()
16263 \emph default
16264  routine to your program to override the default if you need to setup hardware
16265  or perform some other critical operation prior to static & global variable
16266  initialization
16267 \begin_inset LatexCommand \index{Variable initialization}
16268
16269 \end_inset
16270
16271 .
16272  On some mcs51 variants xdata
16273 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16274
16275 \end_inset
16276
16277  memory has to be explicitly enabled before it can be accessed or if the
16278  watchdog
16279 \begin_inset LatexCommand \index{watchdog}
16280
16281 \end_inset
16282
16283  needs to be disabled, this is the place to do it.
16284  The startup code clears all internal data memory, 256 bytes by default,
16285  but from 0 to n-1 if 
16286 \emph on
16287 -
16288 \begin_inset ERT
16289 status collapsed
16290
16291 \begin_layout Standard
16292
16293
16294 \backslash
16295 /
16296 \end_layout
16297
16298 \end_inset
16299
16300 -iram-size
16301 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16302
16303 \end_inset
16304
16305 n
16306 \emph default
16307  is used.
16308  (recommended for Chipcon CC1010).
16309 \end_layout
16310
16311 \begin_layout Standard
16312 See also the compiler options 
16313 \emph on
16314 -
16315 \begin_inset ERT
16316 status collapsed
16317
16318 \begin_layout Standard
16319
16320
16321 \backslash
16322 /
16323 \end_layout
16324
16325 \end_inset
16326
16327 -no-xinit
16328 \emph default
16329 -
16330 \emph on
16331 opt
16332 \emph default
16333
16334 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16335
16336 \end_inset
16337
16338
16339 \emph on
16340 -
16341 \begin_inset ERT
16342 status collapsed
16343
16344 \begin_layout Standard
16345
16346
16347 \backslash
16348 /
16349 \end_layout
16350
16351 \end_inset
16352
16353 -main-return
16354 \emph default
16355
16356 \begin_inset LatexCommand \index{-\/-main-return}
16357
16358 \end_inset
16359
16360  and section 
16361 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16362
16363 \end_inset
16364
16365  about MCS51-variants.
16366 \begin_inset VSpace bigskip
16367 \end_inset
16368
16369
16370 \end_layout
16371
16372 \begin_layout Subsection
16373 HC08 Startup Code
16374 \end_layout
16375
16376 \begin_layout Standard
16377 The HC08
16378 \begin_inset LatexCommand \index{HC08}
16379
16380 \end_inset
16381
16382  startup code follows the same scheme as the MCS51 startup code.
16383 \begin_inset VSpace bigskip
16384 \end_inset
16385
16386
16387 \end_layout
16388
16389 \begin_layout Subsection
16390 Z80 Startup Code
16391 \end_layout
16392
16393 \begin_layout Standard
16394 On the Z80
16395 \begin_inset LatexCommand \index{Z80}
16396
16397 \end_inset
16398
16399  the startup code is inserted by linking with crt0.o which is generated from
16400  sdcc/device/lib/z80/crt0.s.
16401  If you need a different startup code you can use the compiler option 
16402 \emph on
16403 -
16404 \series bold
16405 \emph default
16406
16407 \begin_inset ERT
16408 status collapsed
16409
16410 \begin_layout Standard
16411
16412
16413 \backslash
16414 /
16415 \end_layout
16416
16417 \end_inset
16418
16419
16420 \series default
16421 \emph on
16422 -no-std-crt0
16423 \emph default
16424
16425 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16426
16427 \end_inset
16428
16429  and provide your own crt0.o.
16430  
16431 \begin_inset VSpace bigskip
16432 \end_inset
16433
16434
16435 \end_layout
16436
16437 \begin_layout Section
16438 Inline Assembler Code
16439 \begin_inset LatexCommand \index{Assembler routines}
16440
16441 \end_inset
16442
16443
16444 \end_layout
16445
16446 \begin_layout Subsection
16447 A Step by Step Introduction
16448 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16449
16450 \end_inset
16451
16452
16453 \end_layout
16454
16455 \begin_layout Standard
16456 Starting from a small snippet of c-code this example shows for the MCS51
16457  how to use inline assembly, access variables, a function parameter and
16458  an array in xdata memory.
16459  The example uses an MCS51 here but is easily adapted for other architectures.
16460  This is a buffer routine which should be optimized:
16461 \end_layout
16462
16463 \begin_layout Verse
16464
16465 \family typewriter
16466 \size footnotesize
16467 unsigned char __far
16468 \begin_inset LatexCommand \index{far (storage class)}
16469
16470 \end_inset
16471
16472
16473 \begin_inset LatexCommand \index{\_\_far (storage class)}
16474
16475 \end_inset
16476
16477  __at
16478 \begin_inset LatexCommand \index{at}
16479
16480 \end_inset
16481
16482
16483 \begin_inset LatexCommand \index{\_\_at}
16484
16485 \end_inset
16486
16487 (0x7f00) buf[0x100];
16488 \begin_inset LatexCommand \index{Aligned array}
16489
16490 \end_inset
16491
16492
16493 \newline
16494 unsigned char head, tail;\InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 \InsetSpace ~
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 /* if interrupts
16512 \begin_inset LatexCommand \index{interrupt}
16513
16514 \end_inset
16515
16516  are involved see
16517 \newline
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 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 \InsetSpace ~
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 section 
16564 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16565
16566 \end_inset
16567
16568  about
16569 \series bold
16570  volatile
16571 \series default
16572  */
16573 \newline
16574
16575 \newline
16576 void to_buffer( unsigned char c ) 
16577 \newline
16578 {
16579 \newline
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 if( head != (unsigned char)(tail-1)
16585  )\InsetSpace ~
16586 /* cast 
16587 \series bold
16588 needed
16589 \series default
16590  to avoid promotion
16591 \begin_inset LatexCommand \index{promotion to signed int}
16592
16593 \end_inset
16594
16595
16596 \begin_inset LatexCommand \index{type promotion}
16597
16598 \end_inset
16599
16600  to integer */
16601 \begin_inset Marginal
16602 status collapsed
16603
16604 \begin_layout Standard
16605
16606 \series bold
16607 \InsetSpace ~
16608 !
16609 \end_layout
16610
16611 \end_inset
16612
16613
16614 \newline
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 buf[ head++ ] = c;\InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 \InsetSpace ~
16627 \InsetSpace ~
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 \InsetSpace ~
16637 \InsetSpace ~
16638 \InsetSpace ~
16639 /* access to a 256 byte aligned array */
16640 \newline
16641
16642 \end_layout
16643
16644 \begin_layout Standard
16645 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16646  then a corresponding buffer.asm file is generated.
16647  We define a new function 
16648 \family typewriter
16649 to_buffer_asm()
16650 \family default
16651  in file buffer.c in which we cut and paste the generated code, removing
16652  unwanted comments and some ':'.
16653  Then add 
16654 \begin_inset Quotes sld
16655 \end_inset
16656
16657
16658 \series bold
16659 _asm
16660 \series default
16661
16662 \begin_inset Quotes srd
16663 \end_inset
16664
16665  and 
16666 \begin_inset Quotes sld
16667 \end_inset
16668
16669
16670 \series bold
16671 _endasm;
16672 \series default
16673
16674 \begin_inset Quotes srd
16675 \end_inset
16676
16677
16678 \begin_inset Foot
16679 status open
16680
16681 \begin_layout Standard
16682 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16683  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16684  has to be used.
16685  The latter is also used in the library functions.
16686 \end_layout
16687
16688 \end_inset
16689
16690  to the beginning and the end of the function body:
16691 \end_layout
16692
16693 \begin_layout Verse
16694
16695 \family typewriter
16696 \size footnotesize
16697 /* With a cut and paste from the .asm file, we have something to start with.
16698 \newline
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 The
16703  function is not yet OK! (registers aren't saved) */ 
16704 \newline
16705 void to_buffer_asm(
16706  unsigned char c ) 
16707 \newline
16708
16709 \newline
16710 \InsetSpace ~
16711 \InsetSpace ~
16712 \InsetSpace ~
16713 \InsetSpace ~
16714 _asm
16715 \begin_inset LatexCommand \index{\_asm}
16716
16717 \end_inset
16718
16719
16720 \begin_inset LatexCommand \index{\_\_asm}
16721
16722 \end_inset
16723
16724
16725 \newline
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 mov\InsetSpace ~
16731 \InsetSpace ~
16732 r2,dpl 
16733 \newline
16734 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16735 /* cast 
16736 \series bold
16737 needed
16738 \series default
16739  to avoid promotion
16740 \begin_inset LatexCommand \index{promotion to signed int}
16741
16742 \end_inset
16743
16744
16745 \begin_inset LatexCommand \index{type promotion}
16746
16747 \end_inset
16748
16749  to integer */
16750 \newline
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 mov\InsetSpace ~
16756 \InsetSpace ~
16757 a,_tail 
16758 \newline
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 dec\InsetSpace ~
16764 \InsetSpace ~
16765
16766 \newline
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 mov\InsetSpace ~
16772 \InsetSpace ~
16773 r3,a 
16774 \newline
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 mov\InsetSpace ~
16780 \InsetSpace ~
16781 a,_head 
16782 \newline
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 cjne a,ar3,00106$ 
16788 \newline
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 ret
16794 \newline
16795 00106$:
16796  
16797 \newline
16798 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16799 \begin_inset LatexCommand \index{Aligned array}
16800
16801 \end_inset
16802
16803
16804 \newline
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 mov\InsetSpace ~
16810 \InsetSpace ~
16811 r3,_head 
16812 \newline
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 inc\InsetSpace ~
16818 \InsetSpace ~
16819 _head 
16820 \newline
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 mov\InsetSpace ~
16826 \InsetSpace ~
16827 dpl,r3 
16828 \newline
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 mov\InsetSpace ~
16834 \InsetSpace ~
16835 dph,#(_buf >> 8) 
16836 \newline
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 mov\InsetSpace ~
16842 \InsetSpace ~
16843 a,r2 
16844 \newline
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 movx @dptr,a
16850  
16851 \newline
16852 00103$: 
16853 \newline
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 ret
16859 \newline
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 _endasm
16865 \begin_inset LatexCommand \index{\_endasm}
16866
16867 \end_inset
16868
16869
16870 \begin_inset LatexCommand \index{\_\_endasm}
16871
16872 \end_inset
16873
16874 ;
16875 \newline
16876
16877 \end_layout
16878
16879 \begin_layout Standard
16880 The new file buffer.c should compile with only one warning about the unreferenced
16881  function argument 'c'.
16882  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16883  (1) and finally have:
16884 \end_layout
16885
16886 \begin_layout Verse
16887
16888 \family typewriter
16889 \size footnotesize
16890 unsigned char __far __at(0x7f00) buf[0x100];
16891 \newline
16892 unsigned char head, tail;
16893 \newline
16894 #define
16895  USE_ASSEMBLY (1)
16896 \newline
16897
16898 \newline
16899 #if !USE_ASSEMBLY
16900 \newline
16901
16902 \newline
16903 void to_buffer( unsigned char c )
16904 \newline
16905 {
16906 \newline
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 if(
16912  head != (unsigned char)(tail-1) )
16913 \newline
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 buf[ head++ ] = c;
16923 \newline
16924 }
16925 \newline
16926
16927 \newline
16928 #else
16929 \newline
16930
16931 \newline
16932 void to_buffer(
16933  unsigned char c )
16934 \newline
16935 {
16936 \newline
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 c; // to avoid warning: unreferenced function argument
16942 \newline
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 _asm
16948 \begin_inset LatexCommand \index{\_asm}
16949
16950 \end_inset
16951
16952
16953 \begin_inset LatexCommand \index{\_\_asm}
16954
16955 \end_inset
16956
16957
16958 \newline
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 ; save used registers here.
16968  
16969 \newline
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 ; If we were still using r2,r3 we would have to push them here.
16979  
16980 \newline
16981 ; if( head != (unsigned char)(tail-1) )
16982 \newline
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 mov\InsetSpace ~
16992  a,_tail
16993 \newline
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 dec\InsetSpace ~
17003  a
17004 \newline
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 xrl\InsetSpace ~
17014  a,_head
17015 \newline
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 \InsetSpace ~
17024 ; we
17025  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17026 \newline
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 \InsetSpace ~
17032 \InsetSpace ~
17033 \InsetSpace ~
17034 \InsetSpace ~
17035 jz\InsetSpace ~
17036 \InsetSpace ~
17037  t_b_end$
17038 \newline
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 ;
17048 \newline
17049 ;
17050  buf[ head++ ] = c;
17051 \newline
17052 \InsetSpace ~
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 mov\InsetSpace ~
17061  a,dpl \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 ; dpl holds lower byte of function argument
17069 \newline
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 mov\InsetSpace ~
17079
17080  dpl,_head \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 ; buf is 0x100 byte aligned so head can be used directly
17084 \newline
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 mov\InsetSpace ~
17094  dph,#(_bu
17095 f>>8)
17096 \newline
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 \InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 movx @dptr,a
17106 \newline
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 inc \InsetSpace ~
17116 _head
17117 \newline
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 ; we could do an ANL _head,#0x0f here to use a
17127  smaller buffer (see above)
17128 \newline
17129 t_b_end$:
17130 \newline
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 ; restore used registers here 
17140 \newline
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 _endasm
17146 \begin_inset LatexCommand \index{\_endasm}
17147
17148 \end_inset
17149
17150
17151 \begin_inset LatexCommand \index{\_\_endasm}
17152
17153 \end_inset
17154
17155 ;
17156 \newline
17157 }
17158 \newline
17159 #endif
17160 \end_layout
17161
17162 \begin_layout Standard
17163 The inline assembler code can contain any valid code understood by the assembler
17164 , this includes any assembler directives and comment lines.
17165  The assembler does not like some characters like ':' or ''' in comments.
17166  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17167 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17168
17169 \end_inset
17170
17171
17172 \begin_inset LatexCommand \index{Assembler documentation}
17173
17174 \end_inset
17175
17176  or online at 
17177 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17178
17179 \end_inset
17180
17181 \InsetSpace ~
17182 .
17183 \end_layout
17184
17185 \begin_layout Standard
17186 The compiler does not do any validation of the code within the 
17187 \family typewriter
17188 _asm
17189 \begin_inset LatexCommand \index{\_asm}
17190
17191 \end_inset
17192
17193
17194 \begin_inset LatexCommand \index{\_\_asm}
17195
17196 \end_inset
17197
17198  ...
17199  _endasm
17200 \size footnotesize
17201
17202 \begin_inset LatexCommand \index{\_endasm}
17203
17204 \end_inset
17205
17206
17207 \begin_inset LatexCommand \index{\_\_endasm}
17208
17209 \end_inset
17210
17211
17212 \size default
17213 ;
17214 \family default
17215  keyword pair.
17216  Specifically it will not know which registers are used and thus register
17217  pushing/popping
17218 \begin_inset LatexCommand \index{push/pop}
17219
17220 \end_inset
17221
17222  has to be done manually.
17223  
17224 \end_layout
17225
17226 \begin_layout Standard
17227 It is recommended that each assembly instruction (including labels) be placed
17228  in a separate line (as the example shows).
17229  When the -
17230 \begin_inset ERT
17231 status collapsed
17232
17233 \begin_layout Standard
17234
17235
17236 \backslash
17237 /
17238 \end_layout
17239
17240 \end_inset
17241
17242 -
17243 \emph on
17244 peep-asm
17245 \begin_inset LatexCommand \index{-\/-peep-asm}
17246
17247 \end_inset
17248
17249
17250 \emph default
17251  command line option is used, the inline assembler code will be passed through
17252  the peephole optimizer
17253 \begin_inset LatexCommand \index{Peephole optimizer}
17254
17255 \end_inset
17256
17257 .
17258  There are only a few (if any) cases where this option makes sense, it might
17259  cause some unexpected changes in the inline assembler code.
17260  Please go through the peephole optimizer rules defined in file 
17261 \emph on
17262 SDCCpeeph.def
17263 \emph default
17264  before using this option.
17265 \end_layout
17266
17267 \begin_layout Subsection
17268 Naked Functions
17269 \begin_inset LatexCommand \label{sub:Naked-Functions}
17270
17271 \end_inset
17272
17273
17274 \begin_inset LatexCommand \index{Naked functions}
17275
17276 \end_inset
17277
17278
17279 \end_layout
17280
17281 \begin_layout Standard
17282 A special keyword may be associated with a function declaring it as 
17283 \emph on
17284 _naked
17285 \begin_inset LatexCommand \index{\_naked}
17286
17287 \end_inset
17288
17289
17290 \begin_inset LatexCommand \index{\_\_naked}
17291
17292 \end_inset
17293
17294 .
17295  
17296 \emph default
17297 The 
17298 \emph on
17299 _naked
17300 \emph default
17301  function modifier attribute prevents the compiler from generating prologue
17302 \begin_inset LatexCommand \index{function prologue}
17303
17304 \end_inset
17305
17306  and epilogue
17307 \begin_inset LatexCommand \index{function epilogue}
17308
17309 \end_inset
17310
17311  code for that function.
17312  This means that the user is entirely responsible for such things as saving
17313  any registers that may need to be preserved, selecting the proper register
17314  bank, generating the 
17315 \emph on
17316 return
17317 \emph default
17318  instruction at the end, etc.
17319  Practically, this means that the contents of the function must be written
17320  in inline assembler.
17321  This is particularly useful for interrupt functions, which can have a large
17322  (and often unnecessary) prologue/epilogue.
17323  For example, compare the code generated by these two functions:
17324 \end_layout
17325
17326 \begin_layout Verse
17327
17328 \family typewriter
17329 volatile
17330 \begin_inset LatexCommand \index{volatile}
17331
17332 \end_inset
17333
17334  data unsigned char counter;
17335 \newline
17336
17337 \newline
17338 void simpleInterrupt(void) __interrupt
17339 \begin_inset LatexCommand \index{interrupt}
17340
17341 \end_inset
17342
17343
17344 \begin_inset LatexCommand \index{\_\_interrupt}
17345
17346 \end_inset
17347
17348  (1)
17349 \newline
17350 {
17351 \newline
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 counter++;
17357 \newline
17358 }
17359 \newline
17360
17361 \newline
17362 void nakedInterrupt(void) __interrupt (2) __naked
17363 \newline
17364 {
17365 \newline
17366 \InsetSpace ~
17367 \InsetSpace ~
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 _asm
17371 \begin_inset LatexCommand \index{\_asm}
17372
17373 \end_inset
17374
17375
17376 \begin_inset LatexCommand \index{\_\_asm}
17377
17378 \end_inset
17379
17380
17381 \newline
17382 \InsetSpace ~
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 inc\InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 _counter ; does not change flags, no need to save psw
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 reti\InsetSpace ~
17402 \InsetSpace ~
17403 \InsetSpace ~
17404 \InsetSpace ~
17405 ; MUST explicitly
17406  include ret or reti in _naked function.
17407 \newline
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 _endasm
17413 \begin_inset LatexCommand \index{\_endasm}
17414
17415 \end_inset
17416
17417
17418 \begin_inset LatexCommand \index{\_\_endasm}
17419
17420 \end_inset
17421
17422 ;
17423 \newline
17424 }
17425 \end_layout
17426
17427 \begin_layout Standard
17428 For an 8051 target, the generated simpleInterrupt looks like:
17429 \end_layout
17430
17431 \begin_layout Verse
17432
17433 \family typewriter
17434 Note, this is an 
17435 \emph on
17436 outdated
17437 \emph default
17438  example, recent versions of SDCC generate
17439 \newline
17440 the 
17441 \emph on
17442 same
17443 \emph default
17444  code for simpleInterrupt() and nakedInterrupt()!
17445 \newline
17446
17447 \newline
17448 _simpleInterrupt:
17449 \newline
17450 \InsetSpace ~
17451 \InsetSpace ~
17452 \InsetSpace ~
17453 \InsetSpace ~
17454 push\InsetSpace ~
17455 \InsetSpace ~
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 acc
17459 \newline
17460 \InsetSpace ~
17461 \InsetSpace ~
17462 \InsetSpace ~
17463 \InsetSpace ~
17464 push\InsetSpace ~
17465 \InsetSpace ~
17466 \InsetSpace ~
17467 \InsetSpace ~
17468 b
17469 \newline
17470 \InsetSpace ~
17471 \InsetSpace ~
17472 \InsetSpace ~
17473 \InsetSpace ~
17474 pu
17475 sh\InsetSpace ~
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 \InsetSpace ~
17479 dpl
17480 \newline
17481 \InsetSpace ~
17482 \InsetSpace ~
17483 \InsetSpace ~
17484 \InsetSpace ~
17485 push\InsetSpace ~
17486 \InsetSpace ~
17487 \InsetSpace ~
17488 \InsetSpace ~
17489 dph
17490 \newline
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 \InsetSpace ~
17495 push\InsetSpace ~
17496 \InsetSpace ~
17497 \InsetSpace ~
17498 \InsetSpace ~
17499 psw
17500 \newline
17501 \InsetSpace ~
17502 \InsetSpace ~
17503 \InsetSpace ~
17504 \InsetSpace ~
17505 mov\InsetSpace ~
17506 \InsetSpace ~
17507 \InsetSpace ~
17508 \InsetSpace ~
17509 \InsetSpace ~
17510 psw,#0x00
17511 \newline
17512 \InsetSpace ~
17513 \InsetSpace ~
17514 \InsetSpace ~
17515 \InsetSpace ~
17516 inc\InsetSpace ~
17517 \InsetSpace ~
17518 \InsetSpace ~
17519 \InsetSpace ~
17520 \InsetSpace ~
17521 _counter
17522 \newline
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 pop\InsetSpace ~
17528 \InsetSpace ~
17529 \InsetSpace ~
17530 \InsetSpace ~
17531 \InsetSpace ~
17532 psw
17533 \newline
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 pop\InsetSpace ~
17539 \InsetSpace ~
17540 \InsetSpace ~
17541 \InsetSpace ~
17542 \InsetSpace ~
17543 dph
17544 \newline
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 pop\InsetSpace ~
17550 \InsetSpace ~
17551 \InsetSpace ~
17552 \InsetSpace ~
17553 \InsetSpace ~
17554 dpl
17555 \newline
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 pop\InsetSpace ~
17561 \InsetSpace ~
17562 \InsetSpace ~
17563 \InsetSpace ~
17564 \InsetSpace ~
17565 b
17566 \newline
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 pop\InsetSpace ~
17572 \InsetSpace ~
17573 \InsetSpace ~
17574 \InsetSpace ~
17575 \InsetSpace ~
17576 acc
17577 \newline
17578 \InsetSpace ~
17579 \InsetSpace ~
17580 \InsetSpace ~
17581 \InsetSpace ~
17582 reti
17583 \end_layout
17584
17585 \begin_layout Standard
17586 whereas nakedInterrupt looks like:
17587 \end_layout
17588
17589 \begin_layout Verse
17590
17591 \family typewriter
17592 _nakedInterrupt:
17593 \newline
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 inc\InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 _counter ; does not change flags, no need to save psw
17603 \newline
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 reti\InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 \InsetSpace ~
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 ;
17621  MUST explicitly include ret or reti in _naked function
17622 \end_layout
17623
17624 \begin_layout Standard
17625 The related directive #pragma exclude
17626 \begin_inset LatexCommand \index{\#pragma exclude}
17627
17628 \end_inset
17629
17630  allows a more fine grained control over pushing & popping
17631 \begin_inset LatexCommand \index{push/pop}
17632
17633 \end_inset
17634
17635  the registers.
17636 \end_layout
17637
17638 \begin_layout Standard
17639 While there is nothing preventing you from writing C code inside a 
17640 \family typewriter
17641 _naked
17642 \family default
17643  function, there are many ways to shoot yourself in the foot doing this,
17644  and it is recommended that you stick to inline assembler.
17645 \end_layout
17646
17647 \begin_layout Subsection
17648 Use of Labels within Inline Assembler
17649 \end_layout
17650
17651 \begin_layout Standard
17652 SDCC allows the use of in-line assembler with a few restrictions regarding
17653  labels.
17654  All labels defined within inline assembler code have to be of the form
17655  
17656 \emph on
17657 nnnnn$
17658 \emph default
17659  where nnnnn is a number less than 100 (which implies a limit of utmost
17660  100 inline assembler labels 
17661 \emph on
17662 per function
17663 \emph default
17664 \noun on
17665 )
17666 \noun default
17667 .
17668 \begin_inset Foot
17669 status open
17670
17671 \begin_layout Standard
17672 This is a slightly more stringent rule than absolutely necessary, but stays
17673  always on the safe side.
17674  Labels in the form of nnnnn$ are local labels in the assembler, locality
17675  of which is confined within two labels of the standard form.
17676  The compiler uses the same form for labels within a function (but starting
17677  from nnnnn=00100); and places always a standard label at the beginning
17678  of a function, thus limiting the locality of labels within the scope of
17679  the function.
17680  So, if the inline assembler part would be embedded into C-code, an improperly
17681  placed non-local label in the assembler would break up the reference space
17682  for labels created by the compiler for the C-code, leading to an assembling
17683  error.
17684 \end_layout
17685
17686 \begin_layout Standard
17687 The numeric part of local labels does not need to have 5 digits (although
17688  this is the form of labels output by the compiler), any valid integer will
17689  do.
17690  Please refer to the assemblers documentation for further details.
17691 \end_layout
17692
17693 \end_inset
17694
17695  
17696 \end_layout
17697
17698 \begin_layout Verse
17699
17700 \family typewriter
17701 _asm
17702 \begin_inset LatexCommand \index{\_asm}
17703
17704 \end_inset
17705
17706
17707 \begin_inset LatexCommand \index{\_\_asm}
17708
17709 \end_inset
17710
17711  
17712 \newline
17713 \InsetSpace ~
17714 \InsetSpace ~
17715 \InsetSpace ~
17716 \InsetSpace ~
17717 mov\InsetSpace ~
17718 \InsetSpace ~
17719 \InsetSpace ~
17720 \InsetSpace ~
17721 \InsetSpace ~
17722 b,#10 
17723 \newline
17724 00001$: 
17725 \newline
17726 \InsetSpace ~
17727 \InsetSpace ~
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 djnz\InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 b,00001$ 
17735 \newline
17736 _endasm
17737 \begin_inset LatexCommand \index{\_endasm}
17738
17739 \end_inset
17740
17741
17742 \begin_inset LatexCommand \index{\_\_endasm}
17743
17744 \end_inset
17745
17746  ;
17747 \end_layout
17748
17749 \begin_layout Standard
17750 Inline assembler code cannot reference any C-labels, however it can reference
17751  labels
17752 \begin_inset LatexCommand \index{Labels}
17753
17754 \end_inset
17755
17756  defined by the inline assembler, e.g.:
17757 \end_layout
17758
17759 \begin_layout Verse
17760
17761 \family typewriter
17762 foo() { 
17763 \newline
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 \InsetSpace ~
17768 /* some c code */ 
17769 \newline
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 \InsetSpace ~
17774 _asm 
17775 \newline
17776 \InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 ; some assembler code 
17783 \newline
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 \InsetSpace ~
17788 \InsetSpace ~
17789 \InsetSpace ~
17790 ljmp 0003$ 
17791 \newline
17792 \InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 _endasm;
17797  
17798 \newline
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 /* some more c code */ 
17804 \newline
17805 clabel:\InsetSpace ~
17806 \InsetSpace ~
17807 /* inline assembler cannot reference this
17808  label */ 
17809 \begin_inset Foot
17810 status open
17811
17812 \begin_layout Standard
17813 Here, the C-label 
17814 \family typewriter
17815 clabel
17816 \family default
17817  is translated by the compiler into a local label, so the locality of labels
17818  within the function is not broken.
17819 \end_layout
17820
17821 \end_inset
17822
17823
17824 \newline
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 _asm
17830 \newline
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 0003$: ;label (can be referenced by inline assembler only) 
17836 \newline
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 _endasm
17842 \begin_inset LatexCommand \index{\_endasm}
17843
17844 \end_inset
17845
17846
17847 \begin_inset LatexCommand \index{\_\_endasm}
17848
17849 \end_inset
17850
17851  ; 
17852 \newline
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 /* some more c code */
17858 \newline
17859 }
17860 \end_layout
17861
17862 \begin_layout Standard
17863 In other words inline assembly code can access labels defined in inline
17864  assembly within the scope of the function.
17865  The same goes the other way, i.e.
17866  labels defines in inline assembly can not be accessed by C statements.
17867 \end_layout
17868
17869 \begin_layout Section
17870 Interfacing with Assembler Code
17871 \begin_inset LatexCommand \index{Assembler routines}
17872
17873 \end_inset
17874
17875
17876 \end_layout
17877
17878 \begin_layout Subsection
17879 Global Registers used for Parameter Passing
17880 \begin_inset LatexCommand \index{Parameter passing}
17881
17882 \end_inset
17883
17884
17885 \end_layout
17886
17887 \begin_layout Standard
17888 The compiler always uses the global registers 
17889 \emph on
17890 DPL, DPH
17891 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17892
17893 \end_inset
17894
17895
17896 \begin_inset LatexCommand \index{DPTR}
17897
17898 \end_inset
17899
17900 , B
17901 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17902
17903 \end_inset
17904
17905  
17906 \emph default
17907 and
17908 \emph on
17909  ACC
17910 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17911
17912 \end_inset
17913
17914
17915 \emph default
17916  to pass the first (non-bit) parameter to a function, and also to pass the
17917  return value 
17918 \begin_inset LatexCommand \index{return value}
17919
17920 \end_inset
17921
17922 of function; according to the following scheme: one byte return value in
17923  
17924 \emph on
17925 DPL
17926 \emph default
17927 , two byte value in 
17928 \emph on
17929 DPL
17930 \emph default
17931  (LSB) and 
17932 \emph on
17933 DPH
17934 \emph default
17935  (MSB).
17936  three byte values (generic pointers) in 
17937 \emph on
17938 DPH
17939 \emph default
17940
17941 \emph on
17942 DPL
17943 \emph default
17944  and 
17945 \emph on
17946 B
17947 \emph default
17948 , and four byte values in 
17949 \emph on
17950 DPH
17951 \emph default
17952
17953 \emph on
17954 DPL
17955 \emph default
17956 ,
17957 \emph on
17958  B
17959 \emph default
17960  and 
17961 \emph on
17962 ACC
17963 \emph default
17964 .
17965  Generic pointers
17966 \begin_inset LatexCommand \index{generic pointer}
17967
17968 \end_inset
17969
17970  contain type of accessed memory in 
17971 \emph on
17972 B
17973 \emph default
17974
17975 \series bold
17976 0x00
17977 \series default
17978  -- xdata/far, 
17979 \series bold
17980 0x40
17981 \series default
17982  -- idata/near -- , 
17983 \series bold
17984 0x60
17985 \series default
17986  -- pdata, 
17987 \series bold
17988 0x80
17989 \series default
17990  -- code
17991 \begin_inset Note Note
17992 status collapsed
17993
17994 \begin_layout Standard
17995 This might not be the case of certain memory models (medium???)
17996 \end_layout
17997
17998 \end_inset
17999
18000 .
18001 \end_layout
18002
18003 \begin_layout Standard
18004 The second parameter onwards is either allocated on the stack (for reentrant
18005  routines or if -
18006 \begin_inset ERT
18007 status collapsed
18008
18009 \begin_layout Standard
18010
18011
18012 \backslash
18013 /
18014 \end_layout
18015
18016 \end_inset
18017
18018 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18019 \end_layout
18020
18021 \begin_layout Standard
18022 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18023  space for reentrant functions or allocated directly in bit memory otherwise.
18024 \end_layout
18025
18026 \begin_layout Standard
18027 Functions (with two or more parameters or bit parameters) that are called
18028  through function pointers
18029 \begin_inset LatexCommand \index{function pointers}
18030
18031 \end_inset
18032
18033  must therefor be reentrant so the compiler knows how to pass the parameters.
18034 \end_layout
18035
18036 \begin_layout Subsection
18037 Registers usage
18038 \end_layout
18039
18040 \begin_layout Standard
18041 Unless the called function is declared as 
18042 \family typewriter
18043 _naked
18044 \family default
18045
18046 \begin_inset LatexCommand \index{naked}
18047
18048 \end_inset
18049
18050 , or the -
18051 \begin_inset ERT
18052 status collapsed
18053
18054 \begin_layout Standard
18055
18056
18057 \backslash
18058 /
18059 \end_layout
18060
18061 \end_inset
18062
18063 -callee-saves
18064 \begin_inset LatexCommand \index{-\/-callee-saves}
18065
18066 \end_inset
18067
18068 /-
18069 \begin_inset ERT
18070 status collapsed
18071
18072 \begin_layout Standard
18073
18074
18075 \backslash
18076 /
18077 \end_layout
18078
18079 \end_inset
18080
18081 -all-callee-saves command line option or the corresponding callee_saves
18082  pragma are used, the caller will save the registers (
18083 \emph on
18084 R0-R7
18085 \emph default
18086 ) around the call, so the called function can destroy they content freely.
18087 \end_layout
18088
18089 \begin_layout Standard
18090 If the called function is not declared as 
18091 \family typewriter
18092 _naked
18093 \family default
18094 , the caller will swap register banks around the call, if caller and callee
18095  use different register banks (having them defined by the 
18096 \family typewriter
18097 _using
18098 \family default
18099  modifier).
18100  
18101 \end_layout
18102
18103 \begin_layout Standard
18104 The called function can also use 
18105 \emph on
18106 DPL
18107 \emph default
18108
18109 \emph on
18110 DPH
18111 \emph default
18112
18113 \emph on
18114 B
18115 \emph default
18116  and 
18117 \emph on
18118 ACC
18119 \emph default
18120  observing that they are used for parameter/return value passing.
18121 \end_layout
18122
18123 \begin_layout Subsection
18124 Assembler Routine (non-reentrant)
18125 \end_layout
18126
18127 \begin_layout Standard
18128 In the following example
18129 \begin_inset LatexCommand \index{reentrant}
18130
18131 \end_inset
18132
18133
18134 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18135
18136 \end_inset
18137
18138  the function c_func calls an assembler routine asm_func, which takes two
18139  parameters
18140 \begin_inset LatexCommand \index{function parameter}
18141
18142 \end_inset
18143
18144 .
18145 \end_layout
18146
18147 \begin_layout Verse
18148
18149 \family typewriter
18150 extern int asm_func(unsigned char, unsigned char);
18151 \newline
18152
18153 \newline
18154 int c_func (unsigned char
18155  i, unsigned char j)
18156 \newline
18157 {
18158 \newline
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 \InsetSpace ~
18163 return asm_func(i,j);
18164 \newline
18165 }
18166 \newline
18167
18168 \newline
18169 int main()
18170 \newline
18171 {
18172 \newline
18173 \InsetSpace ~
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 \InsetSpace ~
18177 return c_func(10,9);
18178 \newline
18179 }
18180 \end_layout
18181
18182 \begin_layout Standard
18183 The corresponding assembler function is:
18184 \end_layout
18185
18186 \begin_layout Verse
18187
18188 \family typewriter
18189 .globl _asm_func_PARM_2 
18190 \newline
18191 \InsetSpace ~
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 \InsetSpace ~
18199 .globl _asm_func 
18200 \newline
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 .area OSEG 
18210 \newline
18211 _asm_func_PARM_2:
18212 \newline
18213 \InsetSpace ~
18214 \InsetSpace ~
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 .ds   
18222  1 
18223 \newline
18224 \InsetSpace ~
18225 \InsetSpace ~
18226 \InsetSpace ~
18227 \InsetSpace ~
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 .area CSEG 
18233 \newline
18234 _asm_func: 
18235 \newline
18236 \InsetSpace ~
18237 \InsetSpace ~
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 mov\InsetSpace ~
18245 \InsetSpace ~
18246 \InsetSpace ~
18247 \InsetSpace ~
18248 a,dpl 
18249 \newline
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 \InsetSpace ~
18257 \InsetSpace ~
18258 add\InsetSpace ~
18259 \InsetSpace ~
18260 \InsetSpace ~
18261 \InsetSpace ~
18262 a,_asm_func_PARM_2 
18263 \newline
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 \InsetSpace ~
18270 \InsetSpace ~
18271 \InsetSpace ~
18272 mov\InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 dpl,a 
18277 \newline
18278 \InsetSpace ~
18279 \InsetSpace ~
18280 \InsetSpace ~
18281 \InsetSpace ~
18282 \InsetSpace ~
18283 \InsetSpace ~
18284 \InsetSpace ~
18285 \InsetSpace ~
18286 mov\InsetSpace ~
18287 \InsetSpace ~
18288 \InsetSpace ~
18289 \InsetSpace ~
18290 dph
18291 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18292
18293 \end_inset
18294
18295 ,#0x00 
18296 \newline
18297 \InsetSpace ~
18298 \InsetSpace ~
18299 \InsetSpace ~
18300 \InsetSpace ~
18301 \InsetSpace ~
18302 \InsetSpace ~
18303 \InsetSpace ~
18304 \InsetSpace ~
18305 ret
18306 \end_layout
18307
18308 \begin_layout Standard
18309 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18310  the parameter number starting from 1, and counting from the left.
18311  The first parameter is passed in 
18312 \emph on
18313 DPH
18314 \emph default
18315
18316 \emph on
18317 DPL
18318 \emph default
18319
18320 \emph on
18321 B
18322 \emph default
18323  and 
18324 \emph on
18325 ACC
18326 \emph default
18327  according to the description above.
18328  The variable name for the second parameter will be _<function_name>_PARM_2.
18329 \newline
18330
18331 \newline
18332 Assem
18333 ble the assembler routine with the following command:
18334 \newline
18335
18336 \newline
18337
18338 \family sans
18339 \series bold
18340 asx8051 -losg asmfunc.asm
18341 \newline
18342
18343 \newline
18344
18345 \family default
18346 \series default
18347 Then compile and link the assembler routine to the C source file with the
18348  following command:
18349 \newline
18350
18351 \newline
18352
18353 \family sans
18354 \series bold
18355 sdcc cfunc.c asmfunc.rel
18356 \end_layout
18357
18358 \begin_layout Subsection
18359 Assembler Routine (reentrant)
18360 \end_layout
18361
18362 \begin_layout Standard
18363 In this case
18364 \begin_inset LatexCommand \index{reentrant}
18365
18366 \end_inset
18367
18368
18369 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18370
18371 \end_inset
18372
18373  the second parameter
18374 \begin_inset LatexCommand \index{function parameter}
18375
18376 \end_inset
18377
18378  onwards will be passed on the stack, the parameters are pushed from right
18379  to left i.e.
18380  before the call the second leftmost parameter will be on the top of the
18381  stack (the leftmost parameter is passed in registers).
18382  Here is an example:
18383 \end_layout
18384
18385 \begin_layout Verse
18386
18387 \family typewriter
18388 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18389 \newline
18390
18391 \newline
18392 int
18393  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18394 \newline
18395 {
18396  
18397 \newline
18398 \InsetSpace ~
18399 \InsetSpace ~
18400 \InsetSpace ~
18401 \InsetSpace ~
18402 return asm_func(i,j,k); 
18403 \newline
18404
18405 \newline
18406
18407 \newline
18408 int main() 
18409 \newline
18410
18411 \newline
18412 \InsetSpace ~
18413 \InsetSpace ~
18414 \InsetSpace ~
18415 \InsetSpace ~
18416 return c_func(10,9,8); 
18417 \newline
18418 }
18419 \end_layout
18420
18421 \begin_layout Standard
18422 The corresponding (unoptimized) assembler routine is:
18423 \end_layout
18424
18425 \begin_layout Verse
18426
18427 \family typewriter
18428 .globl _asm_func 
18429 \newline
18430 _asm_func: 
18431 \newline
18432 \InsetSpace ~
18433 \InsetSpace ~
18434 \InsetSpace ~
18435 \InsetSpace ~
18436 push\InsetSpace ~
18437 _bp 
18438 \newline
18439 \InsetSpace ~
18440 \InsetSpace ~
18441 \InsetSpace ~
18442 \InsetSpace ~
18443 mov\InsetSpace ~
18444 \InsetSpace ~
18445 _bp,sp\InsetSpace ~
18446 \InsetSpace ~
18447 \InsetSpace ~
18448 \InsetSpace ~
18449 \InsetSpace ~
18450 \InsetSpace ~
18451 ;stack contains: _bp, return
18452  address, second parameter, third parameter
18453 \newline
18454 \InsetSpace ~
18455 \InsetSpace ~
18456 \InsetSpace ~
18457 \InsetSpace ~
18458 mov\InsetSpace ~
18459 \InsetSpace ~
18460 r2,dpl
18461 \newline
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 \InsetSpace ~
18465 \InsetSpace ~
18466 mov\InsetSpace ~
18467 \InsetSpace ~
18468 a,_bp
18469 \newline
18470 \InsetSpace ~
18471 \InsetSpace ~
18472 \InsetSpace ~
18473 \InsetSpace ~
18474 add\InsetSpace ~
18475 \InsetSpace ~
18476 a,#0xfd\InsetSpace ~
18477 \InsetSpace ~
18478 \InsetSpace ~
18479 \InsetSpace ~
18480 \InsetSpace ~
18481 ;calculate
18482  pointer to the second parameter
18483 \newline
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 \InsetSpace ~
18488 mov\InsetSpace ~
18489 \InsetSpace ~
18490 r0,a 
18491 \newline
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 mov\InsetSpace ~
18497 \InsetSpace ~
18498 a,_bp 
18499 \newline
18500 \InsetSpace ~
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 add\InsetSpace ~
18505 \InsetSpace ~
18506 a,#0xfc\InsetSpace ~
18507 \InsetSpace ~
18508 \InsetSpace ~
18509 \InsetSpace ~
18510 \InsetSpace ~
18511 ;calculate pointer
18512  to the rightmost parameter
18513 \newline
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 mov\InsetSpace ~
18519 \InsetSpace ~
18520 r1,a 
18521 \newline
18522 \InsetSpace ~
18523 \InsetSpace ~
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 mov\InsetSpace ~
18527 \InsetSpace ~
18528 a,@r0
18529 \newline
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 \InsetSpace ~
18533 \InsetSpace ~
18534 add\InsetSpace ~
18535 \InsetSpace ~
18536 a,@r1
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 add\InsetSpace ~
18543 \InsetSpace ~
18544 a,r2\InsetSpace ~
18545 \InsetSpace ~
18546 \InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 ;calculate the
18553  result (= sum of all three parameters)
18554 \newline
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 mov\InsetSpace ~
18560 \InsetSpace ~
18561 dpl,a\InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 \InsetSpace ~
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 ;return value goes into dptr
18569  (cast into int)
18570 \newline
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 \InsetSpace ~
18575 mov\InsetSpace ~
18576 \InsetSpace ~
18577 dph,#0x00 
18578 \newline
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 \InsetSpace ~
18582 \InsetSpace ~
18583 mov\InsetSpace ~
18584 \InsetSpace ~
18585 sp,_bp 
18586 \newline
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 pop\InsetSpace ~
18592 \InsetSpace ~
18593 _bp 
18594 \newline
18595 \InsetSpace ~
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 ret
18600 \end_layout
18601
18602 \begin_layout Standard
18603 The compiling and linking procedure remains the same, however note the extra
18604  entry & exit linkage required for the assembler code, _bp is the stack
18605  frame pointer and is used to compute the offset into the stack for parameters
18606  and local variables.
18607 \begin_inset VSpace bigskip
18608 \end_inset
18609
18610
18611 \end_layout
18612
18613 \begin_layout Section
18614 int (16 bit)
18615 \begin_inset LatexCommand \index{int (16 bit)}
18616
18617 \end_inset
18618
18619  and long (32 bit)
18620 \begin_inset LatexCommand \index{long (32 bit)}
18621
18622 \end_inset
18623
18624  Support
18625 \end_layout
18626
18627 \begin_layout Standard
18628 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18629  multiplication and modulus operations are implemented by support routines.
18630  These support routines are all developed in ANSI-C to facilitate porting
18631  to other MCUs, although some model specific assembler optimizations are
18632  used.
18633  The following files contain the described routines, all of them can be
18634  found in <installdir>/share/sdcc/lib.
18635 \newline
18636
18637 \end_layout
18638
18639 \begin_layout Standard
18640 \align center
18641 \begin_inset Tabular
18642 <lyxtabular version="3" rows="11" columns="2">
18643 <features>
18644 <column alignment="left" valignment="top" leftline="true" width="0">
18645 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18646 <row topline="true" bottomline="true">
18647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18648 \begin_inset Text
18649
18650 \begin_layout Standard
18651
18652 \series bold
18653 Function
18654 \end_layout
18655
18656 \end_inset
18657 </cell>
18658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18659 \begin_inset Text
18660
18661 \begin_layout Standard
18662
18663 \series bold
18664 Description
18665 \end_layout
18666
18667 \end_inset
18668 </cell>
18669 </row>
18670 <row topline="true">
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18672 \begin_inset Text
18673
18674 \begin_layout Standard
18675 _mulint.c 
18676 \end_layout
18677
18678 \end_inset
18679 </cell>
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18681 \begin_inset Text
18682
18683 \begin_layout Standard
18684 16 bit multiplication
18685 \end_layout
18686
18687 \end_inset
18688 </cell>
18689 </row>
18690 <row topline="true">
18691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18692 \begin_inset Text
18693
18694 \begin_layout Standard
18695 _divsint.c 
18696 \end_layout
18697
18698 \end_inset
18699 </cell>
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18701 \begin_inset Text
18702
18703 \begin_layout Standard
18704  signed 16 bit division (calls _divuint)
18705 \end_layout
18706
18707 \end_inset
18708 </cell>
18709 </row>
18710 <row topline="true">
18711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18712 \begin_inset Text
18713
18714 \begin_layout Standard
18715 _divuint.c 
18716 \end_layout
18717
18718 \end_inset
18719 </cell>
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18721 \begin_inset Text
18722
18723 \begin_layout Standard
18724  unsigned 16 bit division
18725 \end_layout
18726
18727 \end_inset
18728 </cell>
18729 </row>
18730 <row topline="true">
18731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18732 \begin_inset Text
18733
18734 \begin_layout Standard
18735 _modsint.c
18736 \end_layout
18737
18738 \end_inset
18739 </cell>
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18741 \begin_inset Text
18742
18743 \begin_layout Standard
18744 signed 16 bit modulus (calls _moduint)
18745 \end_layout
18746
18747 \end_inset
18748 </cell>
18749 </row>
18750 <row topline="true">
18751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18752 \begin_inset Text
18753
18754 \begin_layout Standard
18755 _moduint.c
18756 \end_layout
18757
18758 \end_inset
18759 </cell>
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18761 \begin_inset Text
18762
18763 \begin_layout Standard
18764 unsigned 16 bit modulus
18765 \end_layout
18766
18767 \end_inset
18768 </cell>
18769 </row>
18770 <row topline="true">
18771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18772 \begin_inset Text
18773
18774 \begin_layout Standard
18775 _mullong.c
18776 \end_layout
18777
18778 \end_inset
18779 </cell>
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18781 \begin_inset Text
18782
18783 \begin_layout Standard
18784 32 bit multiplication
18785 \end_layout
18786
18787 \end_inset
18788 </cell>
18789 </row>
18790 <row topline="true">
18791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18792 \begin_inset Text
18793
18794 \begin_layout Standard
18795 _divslong.c 
18796 \end_layout
18797
18798 \end_inset
18799 </cell>
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18801 \begin_inset Text
18802
18803 \begin_layout Standard
18804  signed 32 division (calls _divulong)
18805 \end_layout
18806
18807 \end_inset
18808 </cell>
18809 </row>
18810 <row topline="true">
18811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18812 \begin_inset Text
18813
18814 \begin_layout Standard
18815 _divulong.c 
18816 \end_layout
18817
18818 \end_inset
18819 </cell>
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18821 \begin_inset Text
18822
18823 \begin_layout Standard
18824 unsigned 32 division
18825 \end_layout
18826
18827 \end_inset
18828 </cell>
18829 </row>
18830 <row topline="true">
18831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18832 \begin_inset Text
18833
18834 \begin_layout Standard
18835 _modslong.c
18836 \end_layout
18837
18838 \end_inset
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \begin_layout Standard
18844  signed 32 bit modulus (calls _modulong)
18845 \end_layout
18846
18847 \end_inset
18848 </cell>
18849 </row>
18850 <row topline="true" bottomline="true">
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18852 \begin_inset Text
18853
18854 \begin_layout Standard
18855 _modulong.c
18856 \end_layout
18857
18858 \end_inset
18859 </cell>
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18861 \begin_inset Text
18862
18863 \begin_layout Standard
18864 unsigned 32 bit modulus
18865 \end_layout
18866
18867 \end_inset
18868 </cell>
18869 </row>
18870 </lyxtabular>
18871
18872 \end_inset
18873
18874
18875 \newline
18876
18877 \end_layout
18878
18879 \begin_layout Standard
18880 Since they are compiled as 
18881 \emph on
18882 non-reentrant
18883 \emph default
18884
18885 \begin_inset LatexCommand \index{reentrant}
18886
18887 \end_inset
18888
18889 , interrupt
18890 \begin_inset LatexCommand \index{interrupt}
18891
18892 \end_inset
18893
18894  service routines should not do any of the above operations.
18895  If this is unavoidable then the above routines will need to be compiled
18896  with the 
18897 \emph on
18898 -
18899 \begin_inset ERT
18900 status collapsed
18901
18902 \begin_layout Standard
18903
18904
18905 \backslash
18906 /
18907 \end_layout
18908
18909 \end_inset
18910
18911 -stack-auto
18912 \begin_inset LatexCommand \index{-\/-stack-auto}
18913
18914 \end_inset
18915
18916
18917 \emph default
18918  option, after which the source program will have to be compiled with 
18919 \emph on
18920 -
18921 \begin_inset ERT
18922 status collapsed
18923
18924 \begin_layout Standard
18925
18926
18927 \backslash
18928 /
18929 \end_layout
18930
18931 \end_inset
18932
18933 -int-long-reent
18934 \begin_inset LatexCommand \index{-\/-int-long-reent}
18935
18936 \end_inset
18937
18938
18939 \emph default
18940  option.
18941  Notice that you don't have to call these routines directly.
18942  The compiler will use them automatically every time an integer operation
18943  is required.
18944 \end_layout
18945
18946 \begin_layout Section
18947 Floating Point Support
18948 \begin_inset LatexCommand \index{Floating point support}
18949
18950 \end_inset
18951
18952
18953 \end_layout
18954
18955 \begin_layout Standard
18956 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18957  The floating point support routines are derived from gcc's floatlib.c and
18958  consist of the following routines:
18959 \newline
18960
18961 \end_layout
18962
18963 \begin_layout Standard
18964 \align center
18965
18966 \size footnotesize
18967 \begin_inset Tabular
18968 <lyxtabular version="3" rows="17" columns="2">
18969 <features>
18970 <column alignment="left" valignment="top" leftline="true" width="0">
18971 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18972 <row topline="true" bottomline="true">
18973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18974 \begin_inset Text
18975
18976 \begin_layout Standard
18977
18978 \family roman
18979 \series medium
18980 \shape up
18981 \size normal
18982 \emph off
18983 \bar no
18984 \noun off
18985 \color none
18986 Function 
18987 \end_layout
18988
18989 \end_inset
18990 </cell>
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \begin_layout Standard
18995 Description
18996 \end_layout
18997
18998 \end_inset
18999 </cell>
19000 </row>
19001 <row topline="true">
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19003 \begin_inset Text
19004
19005 \begin_layout Standard
19006
19007 \family roman
19008 \series medium
19009 \shape up
19010 \size normal
19011 \emph off
19012 \bar no
19013 \noun off
19014 \color none
19015 _fsadd.c
19016 \end_layout
19017
19018 \end_inset
19019 </cell>
19020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19021 \begin_inset Text
19022
19023 \begin_layout Standard
19024
19025 \family roman
19026 \series medium
19027 \shape up
19028 \size normal
19029 \emph off
19030 \bar no
19031 \noun off
19032 \color none
19033 add floating point numbers
19034 \end_layout
19035
19036 \end_inset
19037 </cell>
19038 </row>
19039 <row topline="true">
19040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19041 \begin_inset Text
19042
19043 \begin_layout Standard
19044
19045 \family roman
19046 \series medium
19047 \shape up
19048 \size normal
19049 \emph off
19050 \bar no
19051 \noun off
19052 \color none
19053 _fssub.c 
19054 \end_layout
19055
19056 \end_inset
19057 </cell>
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19059 \begin_inset Text
19060
19061 \begin_layout Standard
19062
19063 \family roman
19064 \series medium
19065 \shape up
19066 \size normal
19067 \emph off
19068 \bar no
19069 \noun off
19070 \color none
19071 subtract floating point numbers 
19072 \end_layout
19073
19074 \end_inset
19075 </cell>
19076 </row>
19077 <row topline="true">
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19079 \begin_inset Text
19080
19081 \begin_layout Standard
19082
19083 \family roman
19084 \series medium
19085 \shape up
19086 \size normal
19087 \emph off
19088 \bar no
19089 \noun off
19090 \color none
19091 _fsdiv.c 
19092 \end_layout
19093
19094 \end_inset
19095 </cell>
19096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19097 \begin_inset Text
19098
19099 \begin_layout Standard
19100
19101 \family roman
19102 \series medium
19103 \shape up
19104 \size normal
19105 \emph off
19106 \bar no
19107 \noun off
19108 \color none
19109 divide floating point numbers 
19110 \end_layout
19111
19112 \end_inset
19113 </cell>
19114 </row>
19115 <row topline="true">
19116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19117 \begin_inset Text
19118
19119 \begin_layout Standard
19120
19121 \family roman
19122 \series medium
19123 \shape up
19124 \size normal
19125 \emph off
19126 \bar no
19127 \noun off
19128 \color none
19129 _fsmul.c 
19130 \end_layout
19131
19132 \end_inset
19133 </cell>
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19135 \begin_inset Text
19136
19137 \begin_layout Standard
19138
19139 \family roman
19140 \series medium
19141 \shape up
19142 \size normal
19143 \emph off
19144 \bar no
19145 \noun off
19146 \color none
19147 multiply floating point numbers 
19148 \end_layout
19149
19150 \end_inset
19151 </cell>
19152 </row>
19153 <row topline="true">
19154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19155 \begin_inset Text
19156
19157 \begin_layout Standard
19158
19159 \family roman
19160 \series medium
19161 \shape up
19162 \size normal
19163 \emph off
19164 \bar no
19165 \noun off
19166 \color none
19167 _fs2uchar.c
19168 \end_layout
19169
19170 \end_inset
19171 </cell>
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19173 \begin_inset Text
19174
19175 \begin_layout Standard
19176
19177 \family roman
19178 \series medium
19179 \shape up
19180 \size normal
19181 \emph off
19182 \bar no
19183 \noun off
19184 \color none
19185 convert floating point to unsigned char
19186 \end_layout
19187
19188 \end_inset
19189 </cell>
19190 </row>
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19193 \begin_inset Text
19194
19195 \begin_layout Standard
19196
19197 \family roman
19198 \series medium
19199 \shape up
19200 \size normal
19201 \emph off
19202 \bar no
19203 \noun off
19204 \color none
19205 _fs2char.c
19206 \end_layout
19207
19208 \end_inset
19209 </cell>
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19211 \begin_inset Text
19212
19213 \begin_layout Standard
19214
19215 \family roman
19216 \series medium
19217 \shape up
19218 \size normal
19219 \emph off
19220 \bar no
19221 \noun off
19222 \color none
19223 convert floating point to signed char
19224 \end_layout
19225
19226 \end_inset
19227 </cell>
19228 </row>
19229 <row topline="true">
19230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19231 \begin_inset Text
19232
19233 \begin_layout Standard
19234
19235 \family roman
19236 \series medium
19237 \shape up
19238 \size normal
19239 \emph off
19240 \bar no
19241 \noun off
19242 \color none
19243 _fs2uint.c
19244 \end_layout
19245
19246 \end_inset
19247 </cell>
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19249 \begin_inset Text
19250
19251 \begin_layout Standard
19252
19253 \family roman
19254 \series medium
19255 \shape up
19256 \size normal
19257 \emph off
19258 \bar no
19259 \noun off
19260 \color none
19261 convert floating point to unsigned int
19262 \end_layout
19263
19264 \end_inset
19265 </cell>
19266 </row>
19267 <row topline="true">
19268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19269 \begin_inset Text
19270
19271 \begin_layout Standard
19272
19273 \family roman
19274 \series medium
19275 \shape up
19276 \size normal
19277 \emph off
19278 \bar no
19279 \noun off
19280 \color none
19281 _fs2int.c
19282 \end_layout
19283
19284 \end_inset
19285 </cell>
19286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19287 \begin_inset Text
19288
19289 \begin_layout Standard
19290
19291 \family roman
19292 \series medium
19293 \shape up
19294 \size normal
19295 \emph off
19296 \bar no
19297 \noun off
19298 \color none
19299 convert floating point to signed int
19300 \end_layout
19301
19302 \end_inset
19303 </cell>
19304 </row>
19305 <row topline="true">
19306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19307 \begin_inset Text
19308
19309 \begin_layout Standard
19310
19311 \family roman
19312 \series medium
19313 \shape up
19314 \size normal
19315 \emph off
19316 \bar no
19317 \noun off
19318 \color none
19319 _fs2ulong.
19320 \family default
19321 \series default
19322 \shape default
19323 \size default
19324 \emph default
19325 \bar default
19326 \noun default
19327 c
19328 \end_layout
19329
19330 \end_inset
19331 </cell>
19332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19333 \begin_inset Text
19334
19335 \begin_layout Standard
19336
19337 \family roman
19338 \series medium
19339 \shape up
19340 \size normal
19341 \emph off
19342 \bar no
19343 \noun off
19344 \color none
19345 convert floating point to unsigned long
19346 \end_layout
19347
19348 \end_inset
19349 </cell>
19350 </row>
19351 <row topline="true">
19352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19353 \begin_inset Text
19354
19355 \begin_layout Standard
19356
19357 \family roman
19358 \series medium
19359 \shape up
19360 \size normal
19361 \emph off
19362 \bar no
19363 \noun off
19364 \color none
19365 _fs2long.c
19366 \end_layout
19367
19368 \end_inset
19369 </cell>
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19371 \begin_inset Text
19372
19373 \begin_layout Standard
19374
19375 \family roman
19376 \series medium
19377 \shape up
19378 \size normal
19379 \emph off
19380 \bar no
19381 \noun off
19382 \color none
19383 convert floating point to signed long
19384 \end_layout
19385
19386 \end_inset
19387 </cell>
19388 </row>
19389 <row topline="true">
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19391 \begin_inset Text
19392
19393 \begin_layout Standard
19394
19395 \family roman
19396 \series medium
19397 \shape up
19398 \size normal
19399 \emph off
19400 \bar no
19401 \noun off
19402 \color none
19403 _uchar2fs.c
19404 \end_layout
19405
19406 \end_inset
19407 </cell>
19408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19409 \begin_inset Text
19410
19411 \begin_layout Standard
19412
19413 \family roman
19414 \series medium
19415 \shape up
19416 \size normal
19417 \emph off
19418 \bar no
19419 \noun off
19420 \color none
19421 convert unsigned char to floating point
19422 \end_layout
19423
19424 \end_inset
19425 </cell>
19426 </row>
19427 <row topline="true">
19428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19429 \begin_inset Text
19430
19431 \begin_layout Standard
19432
19433 \family roman
19434 \series medium
19435 \shape up
19436 \size normal
19437 \emph off
19438 \bar no
19439 \noun off
19440 \color none
19441 _char2fs.c
19442 \end_layout
19443
19444 \end_inset
19445 </cell>
19446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19447 \begin_inset Text
19448
19449 \begin_layout Standard
19450
19451 \family roman
19452 \series medium
19453 \shape up
19454 \size normal
19455 \emph off
19456 \bar no
19457 \noun off
19458 \color none
19459 convert char to floating point number
19460 \end_layout
19461
19462 \end_inset
19463 </cell>
19464 </row>
19465 <row topline="true">
19466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19467 \begin_inset Text
19468
19469 \begin_layout Standard
19470
19471 \family roman
19472 \series medium
19473 \shape up
19474 \size normal
19475 \emph off
19476 \bar no
19477 \noun off
19478 \color none
19479 _uint2fs.c
19480 \end_layout
19481
19482 \end_inset
19483 </cell>
19484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19485 \begin_inset Text
19486
19487 \begin_layout Standard
19488
19489 \family roman
19490 \series medium
19491 \shape up
19492 \size normal
19493 \emph off
19494 \bar no
19495 \noun off
19496 \color none
19497 convert unsigned int to floating point
19498 \end_layout
19499
19500 \end_inset
19501 </cell>
19502 </row>
19503 <row topline="true">
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19505 \begin_inset Text
19506
19507 \begin_layout Standard
19508
19509 \family roman
19510 \series medium
19511 \shape up
19512 \size normal
19513 \emph off
19514 \bar no
19515 \noun off
19516 \color none
19517 _int2fs.c
19518 \end_layout
19519
19520 \end_inset
19521 </cell>
19522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19523 \begin_inset Text
19524
19525 \begin_layout Standard
19526
19527 \family roman
19528 \series medium
19529 \shape up
19530 \size normal
19531 \emph off
19532 \bar no
19533 \noun off
19534 \color none
19535 convert int to floating point numbers
19536 \end_layout
19537
19538 \end_inset
19539 </cell>
19540 </row>
19541 <row topline="true">
19542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19543 \begin_inset Text
19544
19545 \begin_layout Standard
19546
19547 \family roman
19548 \series medium
19549 \shape up
19550 \size normal
19551 \emph off
19552 \bar no
19553 \noun off
19554 \color none
19555 _ulong2fs.c
19556 \end_layout
19557
19558 \end_inset
19559 </cell>
19560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19561 \begin_inset Text
19562
19563 \begin_layout Standard
19564
19565 \family roman
19566 \series medium
19567 \shape up
19568 \size normal
19569 \emph off
19570 \bar no
19571 \noun off
19572 \color none
19573 convert unsigned long to floating point number
19574 \end_layout
19575
19576 \end_inset
19577 </cell>
19578 </row>
19579 <row topline="true" bottomline="true">
19580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19581 \begin_inset Text
19582
19583 \begin_layout Standard
19584
19585 \family roman
19586 \series medium
19587 \shape up
19588 \size normal
19589 \emph off
19590 \bar no
19591 \noun off
19592 \color none
19593 _long2fs.c
19594 \end_layout
19595
19596 \end_inset
19597 </cell>
19598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19599 \begin_inset Text
19600
19601 \begin_layout Standard
19602
19603 \family roman
19604 \series medium
19605 \shape up
19606 \size normal
19607 \emph off
19608 \bar no
19609 \noun off
19610 \color none
19611 convert long to floating point number
19612 \end_layout
19613
19614 \end_inset
19615 </cell>
19616 </row>
19617 </lyxtabular>
19618
19619 \end_inset
19620
19621
19622 \newline
19623
19624 \end_layout
19625
19626 \begin_layout Standard
19627 These support routines are developed in ANSI-C so there is room for space
19628  and speed improvement
19629 \begin_inset Foot
19630 status open
19631
19632 \begin_layout Standard
19633 These floating point routines (
19634 \emph on
19635 not
19636 \emph default
19637  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19638  
19639 \end_layout
19640
19641 \end_inset
19642
19643 .
19644  Note if all these routines are used simultaneously the data space might
19645  overflow.
19646  For serious floating point usage the large model might be needed.
19647  Also notice that you don't have to call this routines directly.
19648  The compiler will use them automatically every time a floating point operation
19649  is required.
19650 \begin_inset VSpace bigskip
19651 \end_inset
19652
19653
19654 \end_layout
19655
19656 \begin_layout Section
19657 Library Routines
19658 \begin_inset LatexCommand \index{Libraries}
19659
19660 \end_inset
19661
19662
19663 \end_layout
19664
19665 \begin_layout Standard
19666
19667 \emph on
19668 <pending: this is messy and incomplete - a little more information is in
19669  sdcc/doc/libdoc.txt
19670 \emph default
19671  >
19672 \end_layout
19673
19674 \begin_layout Subsection
19675 Compiler support routines (_gptrget, _mulint etc.)
19676 \end_layout
19677
19678 \begin_layout Subsection
19679 Stdclib functions (puts, printf, strcat etc.)
19680 \end_layout
19681
19682 \begin_layout Subsubsection
19683 <stdio.h>
19684 \end_layout
19685
19686 \begin_layout Paragraph
19687 getchar(), putchar()
19688 \end_layout
19689
19690 \begin_layout Standard
19691 \begin_inset LatexCommand \index{<stdio.h>}
19692
19693 \end_inset
19694
19695 As usual on embedded systems you have to provide your own 
19696 \family typewriter
19697 getchar()
19698 \begin_inset LatexCommand \index{getchar()}
19699
19700 \end_inset
19701
19702  
19703 \family default
19704 and 
19705 \family typewriter
19706 putchar()
19707 \begin_inset LatexCommand \index{putchar()}
19708
19709 \end_inset
19710
19711
19712 \family default
19713  routines.
19714  SDCC does not know whether the system connects to a serial line with or
19715  without handshake, LCD, keyboard or other device.
19716  And whether a 
19717 \family typewriter
19718 lf
19719 \family default
19720  to 
19721 \family typewriter
19722 crlf
19723 \family default
19724  conversion within 
19725 \family typewriter
19726 putchar()
19727 \family default
19728  is intended.
19729  You'll find examples for serial routines f.e.
19730  in sdcc/device/lib.
19731  For the mcs51 this minimalistic polling 
19732 \family typewriter
19733 putchar()
19734 \family default
19735  routine might be a start:
19736 \end_layout
19737
19738 \begin_layout Verse
19739
19740 \family typewriter
19741 void putchar (char c) { 
19742 \newline
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 \InsetSpace ~
19747 while (!TI)\InsetSpace ~
19748 \InsetSpace ~
19749 \InsetSpace ~
19750  /* assumes UART is initialized */
19751 \newline
19752 \InsetSpace ~
19753 \InsetSpace ~
19754 \InsetSpace ~
19755 \InsetSpace ~
19756 \InsetSpace ~
19757 \InsetSpace ~
19758 \InsetSpace ~
19759 \InsetSpace ~
19760 ;
19761 \newline
19762 \InsetSpace ~
19763 \InsetSpace ~
19764 \InsetSpace ~
19765 \InsetSpace ~
19766 TI
19767  = 0;
19768 \newline
19769 \InsetSpace ~
19770 \InsetSpace ~
19771 \InsetSpace ~
19772 \InsetSpace ~
19773 SBUF = c;
19774 \newline
19775 }
19776 \end_layout
19777
19778 \begin_layout Paragraph
19779 printf()
19780 \end_layout
19781
19782 \begin_layout Standard
19783 The default
19784 \family typewriter
19785  printf()
19786 \begin_inset LatexCommand \index{printf()}
19787
19788 \end_inset
19789
19790
19791 \family default
19792  implementation in
19793 \family typewriter
19794  printf_large.c
19795 \family default
19796  does not support float (except on ds390).
19797  To enable this recompile it with the option 
19798 \emph on
19799 -
19800 \begin_inset ERT
19801 status collapsed
19802
19803 \begin_layout Standard
19804
19805
19806 \backslash
19807 /
19808 \end_layout
19809
19810 \end_inset
19811
19812 DUSE_FLOATS=1
19813 \begin_inset LatexCommand \index{USE\_FLOATS}
19814
19815 \end_inset
19816
19817
19818 \emph default
19819  on the command line.
19820  Use
19821 \emph on
19822  -
19823 \begin_inset ERT
19824 status collapsed
19825
19826 \begin_layout Standard
19827
19828
19829 \backslash
19830 /
19831 \end_layout
19832
19833 \end_inset
19834
19835 -model-large
19836 \begin_inset LatexCommand \index{-\/-model-large}
19837
19838 \end_inset
19839
19840
19841 \emph default
19842  for the mcs51 port, since this uses a lot of memory.
19843 \end_layout
19844
19845 \begin_layout Standard
19846 If you're short on code memory you might want to use 
19847 \family typewriter
19848 printf_small()
19849 \begin_inset LatexCommand \index{printf\_small()}
19850
19851 \end_inset
19852
19853
19854 \family default
19855  
19856 \emph on
19857 instead
19858 \emph default
19859  of
19860 \family typewriter
19861  printf().
19862
19863 \family default
19864  For the mcs51 there additionally are assembly versions 
19865 \family typewriter
19866 printf_tiny()
19867 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19868
19869 \end_inset
19870
19871
19872 \family default
19873  (subset of printf using less than 270 bytes) and 
19874 \family typewriter
19875 printf_fast()
19876 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19877
19878 \end_inset
19879
19880  
19881 \family default
19882 and
19883 \family typewriter
19884  printf_fast_f()
19885 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19886
19887 \end_inset
19888
19889
19890 \family default
19891  (floating-point aware version of printf_fast) which should fit the requirements
19892  of many embedded systems (printf_fast() can be customized by unsetting
19893  #defines to 
19894 \emph on
19895 not
19896 \emph default
19897  support long variables and field widths).
19898  Be sure to use only one of these printf options within a project.
19899 \newline
19900
19901 \end_layout
19902
19903 \begin_layout Standard
19904 Feature matrix of different 
19905 \emph on
19906 printf
19907 \emph default
19908  options on mcs51.
19909 \end_layout
19910
19911 \begin_layout Standard
19912 \begin_inset Tabular
19913 <lyxtabular version="3" rows="14" columns="7">
19914 <features islongtable="true">
19915 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19916 <column alignment="center" valignment="top" leftline="true" width="0">
19917 <column alignment="center" valignment="top" leftline="true" width="12col%">
19918 <column alignment="center" valignment="top" leftline="true" width="10col%">
19919 <column alignment="center" valignment="top" leftline="true" width="0">
19920 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19921 <column alignment="center" valignment="top" rightline="true" width="0">
19922 <row topline="true" bottomline="true" endhead="true">
19923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19924 \begin_inset Text
19925
19926 \begin_layout Standard
19927
19928 \series bold
19929 \size large
19930 mcs51
19931 \end_layout
19932
19933 \end_inset
19934 </cell>
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19936 \begin_inset Text
19937
19938 \begin_layout Standard
19939 printf
19940 \begin_inset LatexCommand \index{printf}
19941
19942 \end_inset
19943
19944
19945 \end_layout
19946
19947 \end_inset
19948 </cell>
19949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19950 \begin_inset Text
19951
19952 \begin_layout Standard
19953 printf 
19954 \size scriptsize
19955 USE_FLOATS=1
19956 \end_layout
19957
19958 \end_inset
19959 </cell>
19960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19961 \begin_inset Text
19962
19963 \begin_layout Standard
19964 printf_small
19965 \end_layout
19966
19967 \end_inset
19968 </cell>
19969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19970 \begin_inset Text
19971
19972 \begin_layout Standard
19973 printf_fast
19974 \end_layout
19975
19976 \end_inset
19977 </cell>
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19979 \begin_inset Text
19980
19981 \begin_layout Standard
19982 printf_fast_f
19983 \end_layout
19984
19985 \end_inset
19986 </cell>
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19988 \begin_inset Text
19989
19990 \begin_layout Standard
19991 printf_tiny
19992 \end_layout
19993
19994 \end_inset
19995 </cell>
19996 </row>
19997 <row topline="true" endhead="true">
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19999 \begin_inset Text
20000
20001 \begin_layout Standard
20002 filename
20003 \end_layout
20004
20005 \end_inset
20006 </cell>
20007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_inset Text
20009
20010 \begin_layout Standard
20011
20012 \size scriptsize
20013 printf_large.c
20014 \end_layout
20015
20016 \end_inset
20017 </cell>
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20019 \begin_inset Text
20020
20021 \begin_layout Standard
20022
20023 \size scriptsize
20024 printf_large.c
20025 \end_layout
20026
20027 \end_inset
20028 </cell>
20029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20030 \begin_inset Text
20031
20032 \begin_layout Standard
20033
20034 \size scriptsize
20035 printfl.c
20036 \end_layout
20037
20038 \end_inset
20039 </cell>
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20041 \begin_inset Text
20042
20043 \begin_layout Standard
20044
20045 \size scriptsize
20046 printf_fast.c
20047 \end_layout
20048
20049 \end_inset
20050 </cell>
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20052 \begin_inset Text
20053
20054 \begin_layout Standard
20055
20056 \size scriptsize
20057 printf_fast_f.c
20058 \end_layout
20059
20060 \end_inset
20061 </cell>
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20063 \begin_inset Text
20064
20065 \begin_layout Standard
20066
20067 \size scriptsize
20068 printf_tiny.c
20069 \end_layout
20070
20071 \end_inset
20072 </cell>
20073 </row>
20074 <row topline="true" endhead="true">
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20076 \begin_inset Text
20077
20078 \begin_layout Standard
20079 \begin_inset Quotes sld
20080 \end_inset
20081
20082 Hello World
20083 \begin_inset Quotes srd
20084 \end_inset
20085
20086  size
20087 \end_layout
20088
20089 \begin_layout Standard
20090 small / large
20091 \end_layout
20092
20093 \end_inset
20094 </cell>
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20096 \begin_inset Text
20097
20098 \begin_layout Standard
20099 1.7k / 2.4k
20100 \end_layout
20101
20102 \end_inset
20103 </cell>
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20105 \begin_inset Text
20106
20107 \begin_layout Standard
20108 4.3k / 5.6k
20109 \end_layout
20110
20111 \end_inset
20112 </cell>
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20114 \begin_inset Text
20115
20116 \begin_layout Standard
20117 1.2k / 1.8k
20118 \end_layout
20119
20120 \end_inset
20121 </cell>
20122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20123 \begin_inset Text
20124
20125 \begin_layout Standard
20126 1.3k / 1.3k
20127 \end_layout
20128
20129 \end_inset
20130 </cell>
20131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20132 \begin_inset Text
20133
20134 \begin_layout Standard
20135 1.9k / 1.9k
20136 \end_layout
20137
20138 \end_inset
20139 </cell>
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20141 \begin_inset Text
20142
20143 \begin_layout Standard
20144 0.44k / 0.44k
20145 \end_layout
20146
20147 \end_inset
20148 </cell>
20149 </row>
20150 <row topline="true" endhead="true">
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20152 \begin_inset Text
20153
20154 \begin_layout Standard
20155 code size
20156 \end_layout
20157
20158 \begin_layout Standard
20159 small / large
20160 \end_layout
20161
20162 \end_inset
20163 </cell>
20164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20165 \begin_inset Text
20166
20167 \begin_layout Standard
20168 1.4k / 2.0k
20169 \end_layout
20170
20171 \end_inset
20172 </cell>
20173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20174 \begin_inset Text
20175
20176 \begin_layout Standard
20177 2.8k / 3.7k
20178 \end_layout
20179
20180 \end_inset
20181 </cell>
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20183 \begin_inset Text
20184
20185 \begin_layout Standard
20186 0.45k / 0.47k (+ _ltoa)
20187 \end_layout
20188
20189 \end_inset
20190 </cell>
20191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20192 \begin_inset Text
20193
20194 \begin_layout Standard
20195 1.2k / 1.2k
20196 \end_layout
20197
20198 \end_inset
20199 </cell>
20200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20201 \begin_inset Text
20202
20203 \begin_layout Standard
20204 1.6k / 1.6k
20205 \end_layout
20206
20207 \end_inset
20208 </cell>
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20210 \begin_inset Text
20211
20212 \begin_layout Standard
20213 0.26k / 0.26k
20214 \end_layout
20215
20216 \end_inset
20217 </cell>
20218 </row>
20219 <row topline="true">
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20221 \begin_inset Text
20222
20223 \begin_layout Standard
20224 formats
20225 \end_layout
20226
20227 \end_inset
20228 </cell>
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20230 \begin_inset Text
20231
20232 \begin_layout Standard
20233 cdi
20234 \emph on
20235 o
20236 \emph default
20237 psux
20238 \end_layout
20239
20240 \end_inset
20241 </cell>
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_inset Text
20244
20245 \begin_layout Standard
20246
20247 \family roman
20248 \series medium
20249 \shape up
20250 \size normal
20251 \emph off
20252 \bar no
20253 \noun off
20254 \color none
20255 cd
20256 \family default
20257 \series default
20258 \shape default
20259 \size default
20260 \emph default
20261 \bar default
20262 \noun default
20263 f
20264 \family roman
20265 \series medium
20266 \shape up
20267 \size normal
20268 \emph off
20269 \bar no
20270 \noun off
20271 i
20272 \family default
20273 \series default
20274 \shape default
20275 \size default
20276 \emph on
20277 \bar default
20278 \noun default
20279 o
20280 \family roman
20281 \series medium
20282 \shape up
20283 \size normal
20284 \emph off
20285 \bar no
20286 \noun off
20287 psux
20288 \end_layout
20289
20290 \end_inset
20291 </cell>
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_inset Text
20294
20295 \begin_layout Standard
20296 c
20297 \family roman
20298 \series medium
20299 \shape up
20300 \size normal
20301 \emph off
20302 \bar no
20303 \noun off
20304 \color none
20305 d
20306 \family default
20307 \series default
20308 \shape default
20309 \size default
20310 \emph on
20311 \bar default
20312 \noun default
20313 o
20314 \family roman
20315 \series medium
20316 \shape up
20317 \size normal
20318 \emph off
20319 \bar no
20320 \noun off
20321 s
20322 \family default
20323 \series default
20324 \shape default
20325 \size default
20326 \emph default
20327 \bar default
20328 \noun default
20329 x
20330 \end_layout
20331
20332 \end_inset
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \begin_layout Standard
20338 cdsux
20339 \end_layout
20340
20341 \end_inset
20342 </cell>
20343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20344 \begin_inset Text
20345
20346 \begin_layout Standard
20347 cdfsux
20348 \end_layout
20349
20350 \end_inset
20351 </cell>
20352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20353 \begin_inset Text
20354
20355 \begin_layout Standard
20356 cdsux
20357 \end_layout
20358
20359 \end_inset
20360 </cell>
20361 </row>
20362 <row topline="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 long (32 bit) support
20368 \end_layout
20369
20370 \end_inset
20371 </cell>
20372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20373 \begin_inset Text
20374
20375 \begin_layout Standard
20376 x
20377 \end_layout
20378
20379 \end_inset
20380 </cell>
20381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20382 \begin_inset Text
20383
20384 \begin_layout Standard
20385 x
20386 \end_layout
20387
20388 \end_inset
20389 </cell>
20390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20391 \begin_inset Text
20392
20393 \begin_layout Standard
20394 x
20395 \end_layout
20396
20397 \end_inset
20398 </cell>
20399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20400 \begin_inset Text
20401
20402 \begin_layout Standard
20403 x
20404 \end_layout
20405
20406 \end_inset
20407 </cell>
20408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20409 \begin_inset Text
20410
20411 \begin_layout Standard
20412
20413 \family roman
20414 \series medium
20415 \shape up
20416 \size normal
20417 \emph off
20418 \bar no
20419 \noun off
20420 \color none
20421 x
20422 \end_layout
20423
20424 \end_inset
20425 </cell>
20426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20427 \begin_inset Text
20428
20429 \begin_layout Standard
20430 -
20431 \end_layout
20432
20433 \end_inset
20434 </cell>
20435 </row>
20436 <row topline="true">
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20438 \begin_inset Text
20439
20440 \begin_layout Standard
20441 byte arguments on stack
20442 \end_layout
20443
20444 \end_inset
20445 </cell>
20446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20447 \begin_inset Text
20448
20449 \begin_layout Standard
20450 b
20451 \end_layout
20452
20453 \end_inset
20454 </cell>
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20456 \begin_inset Text
20457
20458 \begin_layout Standard
20459 b
20460 \end_layout
20461
20462 \end_inset
20463 </cell>
20464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20465 \begin_inset Text
20466
20467 \begin_layout Standard
20468 -
20469 \end_layout
20470
20471 \end_inset
20472 </cell>
20473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20474 \begin_inset Text
20475
20476 \begin_layout Standard
20477 -
20478 \end_layout
20479
20480 \end_inset
20481 </cell>
20482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20483 \begin_inset Text
20484
20485 \begin_layout Standard
20486 -
20487 \end_layout
20488
20489 \end_inset
20490 </cell>
20491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20492 \begin_inset Text
20493
20494 \begin_layout Standard
20495 -
20496 \end_layout
20497
20498 \end_inset
20499 </cell>
20500 </row>
20501 <row topline="true">
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20503 \begin_inset Text
20504
20505 \begin_layout Standard
20506 float format
20507 \begin_inset LatexCommand \index{Floating point support}
20508
20509 \end_inset
20510
20511
20512 \end_layout
20513
20514 \end_inset
20515 </cell>
20516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20517 \begin_inset Text
20518
20519 \begin_layout Standard
20520 -
20521 \end_layout
20522
20523 \end_inset
20524 </cell>
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20526 \begin_inset Text
20527
20528 \begin_layout Standard
20529 %f
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538 -
20539 \end_layout
20540
20541 \end_inset
20542 </cell>
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20544 \begin_inset Text
20545
20546 \begin_layout Standard
20547 -
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20553 \begin_inset Text
20554
20555 \begin_layout Standard
20556 %f
20557 \begin_inset Foot
20558 status collapsed
20559
20560 \begin_layout Standard
20561 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20562 \end_layout
20563
20564 \end_inset
20565
20566
20567 \end_layout
20568
20569 \end_inset
20570 </cell>
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \begin_layout Standard
20575 -
20576 \end_layout
20577
20578 \end_inset
20579 </cell>
20580 </row>
20581 <row topline="true">
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_inset Text
20584
20585 \begin_layout Standard
20586 float formats %e %g
20587 \end_layout
20588
20589 \end_inset
20590 </cell>
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20592 \begin_inset Text
20593
20594 \begin_layout Standard
20595 -
20596 \end_layout
20597
20598 \end_inset
20599 </cell>
20600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20601 \begin_inset Text
20602
20603 \begin_layout Standard
20604 -
20605 \end_layout
20606
20607 \end_inset
20608 </cell>
20609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20610 \begin_inset Text
20611
20612 \begin_layout Standard
20613 -
20614 \end_layout
20615
20616 \end_inset
20617 </cell>
20618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20619 \begin_inset Text
20620
20621 \begin_layout Standard
20622 -
20623 \end_layout
20624
20625 \end_inset
20626 </cell>
20627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20628 \begin_inset Text
20629
20630 \begin_layout Standard
20631 -
20632 \end_layout
20633
20634 \end_inset
20635 </cell>
20636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20637 \begin_inset Text
20638
20639 \begin_layout Standard
20640 -
20641 \end_layout
20642
20643 \end_inset
20644 </cell>
20645 </row>
20646 <row topline="true" bottomline="true">
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20648 \begin_inset Text
20649
20650 \begin_layout Standard
20651 field width
20652 \end_layout
20653
20654 \end_inset
20655 </cell>
20656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20657 \begin_inset Text
20658
20659 \begin_layout Standard
20660 x
20661 \end_layout
20662
20663 \end_inset
20664 </cell>
20665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20666 \begin_inset Text
20667
20668 \begin_layout Standard
20669 x
20670 \end_layout
20671
20672 \end_inset
20673 </cell>
20674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20675 \begin_inset Text
20676
20677 \begin_layout Standard
20678 -
20679 \end_layout
20680
20681 \end_inset
20682 </cell>
20683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20684 \begin_inset Text
20685
20686 \begin_layout Standard
20687 x
20688 \end_layout
20689
20690 \end_inset
20691 </cell>
20692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20693 \begin_inset Text
20694
20695 \begin_layout Standard
20696 x
20697 \end_layout
20698
20699 \end_inset
20700 </cell>
20701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20702 \begin_inset Text
20703
20704 \begin_layout Standard
20705 -
20706 \end_layout
20707
20708 \end_inset
20709 </cell>
20710 </row>
20711 <row bottomline="true">
20712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20713 \begin_inset Text
20714
20715 \begin_layout Standard
20716 string speed
20717 \begin_inset Foot
20718 status collapsed
20719
20720 \begin_layout Standard
20721 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20722 \backslash
20723 r', '
20724 \backslash
20725 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20726 \end_layout
20727
20728 \end_inset
20729
20730 ,
20731 \end_layout
20732
20733 \begin_layout Standard
20734 small / large
20735 \end_layout
20736
20737 \end_inset
20738 </cell>
20739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20740 \begin_inset Text
20741
20742 \begin_layout Standard
20743 1.52 / 2.59 ms
20744 \end_layout
20745
20746 \end_inset
20747 </cell>
20748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20749 \begin_inset Text
20750
20751 \begin_layout Standard
20752 1.53 / 2.62 ms
20753 \end_layout
20754
20755 \end_inset
20756 </cell>
20757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20758 \begin_inset Text
20759
20760 \begin_layout Standard
20761 0.92 / 0.93 ms
20762 \end_layout
20763
20764 \end_inset
20765 </cell>
20766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20767 \begin_inset Text
20768
20769 \begin_layout Standard
20770 0.45 / 0.45 ms
20771 \end_layout
20772
20773 \end_inset
20774 </cell>
20775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20776 \begin_inset Text
20777
20778 \begin_layout Standard
20779 0.46 / 0.46 ms
20780 \end_layout
20781
20782 \end_inset
20783 </cell>
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20785 \begin_inset Text
20786
20787 \begin_layout Standard
20788 0.45 / 0.45 ms
20789 \end_layout
20790
20791 \end_inset
20792 </cell>
20793 </row>
20794 <row bottomline="true">
20795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20796 \begin_inset Text
20797
20798 \begin_layout Standard
20799 int speed
20800 \begin_inset Foot
20801 status collapsed
20802
20803 \begin_layout Standard
20804 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20805  putchar()
20806 \end_layout
20807
20808 \end_inset
20809
20810 ,
20811 \end_layout
20812
20813 \begin_layout Standard
20814 small / large
20815 \end_layout
20816
20817 \end_inset
20818 </cell>
20819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20820 \begin_inset Text
20821
20822 \begin_layout Standard
20823 3.01 / 3.61 ms
20824 \end_layout
20825
20826 \end_inset
20827 </cell>
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_inset Text
20830
20831 \begin_layout Standard
20832 3.01 / 3.61 ms
20833 \end_layout
20834
20835 \end_inset
20836 </cell>
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20838 \begin_inset Text
20839
20840 \begin_layout Standard
20841 3.51 / 18.13 ms
20842 \end_layout
20843
20844 \end_inset
20845 </cell>
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20847 \begin_inset Text
20848
20849 \begin_layout Standard
20850 0.22 / 0.22 ms
20851 \end_layout
20852
20853 \end_inset
20854 </cell>
20855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20856 \begin_inset Text
20857
20858 \begin_layout Standard
20859 0.23 / 0.23 ms
20860 \end_layout
20861
20862 \end_inset
20863 </cell>
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20865 \begin_inset Text
20866
20867 \begin_layout Standard
20868 0.25 / 0.25 ms
20869 \begin_inset Foot
20870 status collapsed
20871
20872 \begin_layout Standard
20873 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20874 \end_layout
20875
20876 \end_inset
20877
20878
20879 \end_layout
20880
20881 \end_inset
20882 </cell>
20883 </row>
20884 <row bottomline="true">
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20886 \begin_inset Text
20887
20888 \begin_layout Standard
20889 long speed
20890 \begin_inset Foot
20891 status collapsed
20892
20893 \begin_layout Standard
20894 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20895  empty putchar()
20896 \end_layout
20897
20898 \end_inset
20899
20900 ,
20901 \end_layout
20902
20903 \begin_layout Standard
20904 small / large
20905 \end_layout
20906
20907 \end_inset
20908 </cell>
20909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20910 \begin_inset Text
20911
20912 \begin_layout Standard
20913 5.37 / 6.31 ms
20914 \end_layout
20915
20916 \end_inset
20917 </cell>
20918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20919 \begin_inset Text
20920
20921 \begin_layout Standard
20922 5.37 / 6.31 ms
20923 \end_layout
20924
20925 \end_inset
20926 </cell>
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20928 \begin_inset Text
20929
20930 \begin_layout Standard
20931 8.71 / 40.65 ms
20932 \end_layout
20933
20934 \end_inset
20935 </cell>
20936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20937 \begin_inset Text
20938
20939 \begin_layout Standard
20940 0.40 / 0.40 ms
20941 \end_layout
20942
20943 \end_inset
20944 </cell>
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_inset Text
20947
20948 \begin_layout Standard
20949 0.40 / 0.40 ms
20950 \end_layout
20951
20952 \end_inset
20953 </cell>
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20955 \begin_inset Text
20956
20957 \begin_layout Standard
20958 -
20959 \end_layout
20960
20961 \end_inset
20962 </cell>
20963 </row>
20964 <row bottomline="true">
20965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20966 \begin_inset Text
20967
20968 \begin_layout Standard
20969 float speed
20970 \begin_inset Foot
20971 status collapsed
20972
20973 \begin_layout Standard
20974 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20975  empty putchar()
20976 \end_layout
20977
20978 \end_inset
20979
20980 ,
20981 \end_layout
20982
20983 \begin_layout Standard
20984 small / large
20985 \end_layout
20986
20987 \end_inset
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \begin_layout Standard
20993 -
20994 \end_layout
20995
20996 \end_inset
20997 </cell>
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20999 \begin_inset Text
21000
21001 \begin_layout Standard
21002 7.49 / 22.47 ms
21003 \end_layout
21004
21005 \end_inset
21006 </cell>
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21008 \begin_inset Text
21009
21010 \begin_layout Standard
21011 -
21012 \end_layout
21013
21014 \end_inset
21015 </cell>
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \begin_layout Standard
21020 -
21021 \end_layout
21022
21023 \end_inset
21024 </cell>
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21026 \begin_inset Text
21027
21028 \begin_layout Standard
21029 1.04 / 1.04 ms
21030 \end_layout
21031
21032 \end_inset
21033 </cell>
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21035 \begin_inset Text
21036
21037 \begin_layout Standard
21038 -
21039 \end_layout
21040
21041 \end_inset
21042 </cell>
21043 </row>
21044 </lyxtabular>
21045
21046 \end_inset
21047
21048
21049 \end_layout
21050
21051 \begin_layout Subsubsection
21052 <malloc.h>
21053 \begin_inset LatexCommand \index{malloc.h}
21054
21055 \end_inset
21056
21057
21058 \end_layout
21059
21060 \begin_layout Standard
21061 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21062  using dynamic memory allocation
21063 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21064
21065 \end_inset
21066
21067  and a default heap
21068 \begin_inset LatexCommand \index{heap (malloc)}
21069
21070 \end_inset
21071
21072  space of 1024 bytes is provided for malloc to allocate memory from.
21073  If you need a different heap size you need to recompile _heap.c with the
21074  required size defined in HEAP_SIZE.
21075  It is recommended to make a copy of this file into your project directory
21076  and compile it there with:
21077 \end_layout
21078
21079 \begin_layout Verse
21080
21081 \family typewriter
21082 sdcc -c _heap.c -D HEAD_SIZE=2048
21083 \end_layout
21084
21085 \begin_layout Standard
21086 And then link it with:
21087 \end_layout
21088
21089 \begin_layout Verse
21090
21091 \family typewriter
21092 sdcc main.rel _heap.rel
21093 \end_layout
21094
21095 \begin_layout Subsection
21096 Math functions (sinf, powf, sqrtf etc.)
21097 \end_layout
21098
21099 \begin_layout Subsubsection
21100 <math.h>
21101 \end_layout
21102
21103 \begin_layout Standard
21104 See definitions in file <math.h>.
21105 \end_layout
21106
21107 \begin_layout Subsection
21108 Other libraries
21109 \end_layout
21110
21111 \begin_layout Standard
21112 Libraries
21113 \begin_inset LatexCommand \index{Libraries}
21114
21115 \end_inset
21116
21117  included in SDCC should have a license at least as liberal as the GNU Lesser
21118  General Public License
21119 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21120
21121 \end_inset
21122
21123  
21124 \emph on
21125 LGPL
21126 \emph default
21127 .
21128 \end_layout
21129
21130 \begin_layout Standard
21131 \begin_inset Note Note
21132 status collapsed
21133
21134 \begin_layout Standard
21135 license statements for the libraries are missing.
21136  sdcc/device/lib/ser_ir.c
21137 \end_layout
21138
21139 \begin_layout Standard
21140 or _decdptr f.e.
21141  come with a GPL (as opposed to LGPL) License - this will not be liberal
21142  enough for many embedded programmers.
21143 \end_layout
21144
21145 \end_inset
21146
21147
21148 \end_layout
21149
21150 \begin_layout Standard
21151 If you have ported some library or want to share experience about some code
21152  which f.e.
21153  falls into any of these categories Busses (I
21154 \begin_inset Formula $^{\textrm{2}}$
21155 \end_inset
21156
21157 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21158  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21159  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21160 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21161
21162 \end_inset
21163
21164 \InsetSpace ~
21165 would certainly like to hear about it.
21166 \end_layout
21167
21168 \begin_layout Standard
21169 Programmers coding for embedded systems are not especially famous for being
21170  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21171 e these references are very valuable.
21172  Let's help to create a climate where information is shared.
21173 \begin_inset VSpace bigskip
21174 \end_inset
21175
21176
21177 \end_layout
21178
21179 \begin_layout Section
21180 Memory Models
21181 \end_layout
21182
21183 \begin_layout Subsection
21184 MCS51 Memory Models
21185 \begin_inset LatexCommand \index{Memory model}
21186
21187 \end_inset
21188
21189
21190 \begin_inset LatexCommand \index{MCS51 memory model}
21191
21192 \end_inset
21193
21194
21195 \end_layout
21196
21197 \begin_layout Subsubsection
21198 Small, Medium and Large
21199 \end_layout
21200
21201 \begin_layout Standard
21202 SDCC allows three memory models for MCS51 code, 
21203 \shape slanted
21204 small, medium
21205 \shape default
21206  and 
21207 \shape slanted
21208 large
21209 \shape default
21210 .
21211  Modules compiled with different memory models should 
21212 \emph on
21213 never
21214 \emph default
21215  be combined together or the results would be unpredictable.
21216  The library routines supplied with the compiler are compiled as small,
21217  medium and large.
21218  The compiled library modules are contained in separate directories as small,
21219  medium and large so that you can link to the appropriate set.
21220 \end_layout
21221
21222 \begin_layout Standard
21223 When the medium or large model is used all variables declared without a
21224  storage class will be allocated into the external ram, this includes all
21225  parameters and local variables (for non-reentrant
21226 \begin_inset LatexCommand \index{reentrant}
21227
21228 \end_inset
21229
21230  functions).
21231  When the small model is used variables without storage class are allocated
21232  in the internal ram.
21233 \end_layout
21234
21235 \begin_layout Standard
21236 Judicious usage of the processor specific storage classes
21237 \begin_inset LatexCommand \index{Storage class}
21238
21239 \end_inset
21240
21241  and the 'reentrant' function type will yield much more efficient code,
21242  than using the large model.
21243  Several optimizations are disabled when the program is compiled using the
21244  large model, it is therefore recommended that the small model be used unless
21245  absolutely required.
21246 \end_layout
21247
21248 \begin_layout Subsubsection
21249 External Stack
21250 \begin_inset LatexCommand \label{sub:External-Stack}
21251
21252 \end_inset
21253
21254
21255 \begin_inset LatexCommand \index{stack}
21256
21257 \end_inset
21258
21259
21260 \begin_inset LatexCommand \index{External stack (mcs51)}
21261
21262 \end_inset
21263
21264
21265 \end_layout
21266
21267 \begin_layout Standard
21268 The external stack (-
21269 \begin_inset ERT
21270 status collapsed
21271
21272 \begin_layout Standard
21273
21274
21275 \backslash
21276 /
21277 \end_layout
21278
21279 \end_inset
21280
21281 -xstack option
21282 \begin_inset LatexCommand \index{-\/-xstack}
21283
21284 \end_inset
21285
21286 ) is located in pdata
21287 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21288
21289 \end_inset
21290
21291  memory (usually at the start of the external ram segment) and uses all
21292  unused space in pdata (max.
21293  256 bytes).
21294  When -
21295 \begin_inset ERT
21296 status collapsed
21297
21298 \begin_layout Standard
21299
21300
21301 \backslash
21302 /
21303 \end_layout
21304
21305 \end_inset
21306
21307 -xstack option is used to compile the program, the parameters and local
21308  variables
21309 \begin_inset LatexCommand \index{local variables}
21310
21311 \end_inset
21312
21313  of all reentrant functions are allocated in this area.
21314  This option is provided for programs with large stack space requirements.
21315  When used with the -
21316 \begin_inset ERT
21317 status collapsed
21318
21319 \begin_layout Standard
21320
21321
21322 \backslash
21323 /
21324 \end_layout
21325
21326 \end_inset
21327
21328 -stack-auto
21329 \begin_inset LatexCommand \index{-\/-stack-auto}
21330
21331 \end_inset
21332
21333  option, all parameters and local variables are allocated on the external
21334  stack (note: support libraries will need to be recompiled with the same
21335  options.
21336  There is a predefined target in the library makefile).
21337 \end_layout
21338
21339 \begin_layout Standard
21340 The compiler outputs the higher order address byte of the external ram segment
21341  into port P2
21342 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21343
21344 \end_inset
21345
21346  (see also section 
21347 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21348
21349 \end_inset
21350
21351 ), therefore when using the External Stack option, this port 
21352 \emph on
21353 may not
21354 \emph default
21355  be used by the application program.
21356 \end_layout
21357
21358 \begin_layout Subsection
21359 DS390 Memory Model
21360 \begin_inset LatexCommand \index{Memory model}
21361
21362 \end_inset
21363
21364
21365 \begin_inset LatexCommand \index{DS390 memory model}
21366
21367 \end_inset
21368
21369
21370 \end_layout
21371
21372 \begin_layout Standard
21373 The only model supported is Flat 24
21374 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21375
21376 \end_inset
21377
21378 .
21379  This generates code for the 24 bit contiguous addressing mode of the Dallas
21380  DS80C390 part.
21381  In this mode, up to four meg of external RAM or code space can be directly
21382  addressed.
21383  See the data sheets at www.dalsemi.com for further information on this part.
21384 \newline
21385
21386 \newline
21387 Note
21388  that the compiler does not generate any code to place the processor into
21389  24 bitmode (although 
21390 \emph on
21391 tinibios
21392 \emph default
21393  in the ds390 libraries will do that for you).
21394  If you don't use 
21395 \emph on
21396 tinibios
21397 \emph default
21398
21399 \begin_inset LatexCommand \index{Tinibios (DS390)}
21400
21401 \end_inset
21402
21403 , the boot loader or similar code must ensure that the processor is in 24
21404  bit contiguous addressing mode before calling the SDCC startup code.
21405 \newline
21406
21407 \newline
21408 Like
21409  the 
21410 \emph on
21411 -
21412 \begin_inset ERT
21413 status collapsed
21414
21415 \begin_layout Standard
21416
21417
21418 \backslash
21419 /
21420 \end_layout
21421
21422 \end_inset
21423
21424 -model-large
21425 \emph default
21426  option, variables will by default be placed into the XDATA segment.
21427  
21428 \newline
21429
21430 \newline
21431 Segments may be placed anywhere in the 4 meg address space using the usual
21432  -
21433 \begin_inset ERT
21434 status collapsed
21435
21436 \begin_layout Standard
21437
21438
21439 \backslash
21440 /
21441 \end_layout
21442
21443 \end_inset
21444
21445 -*-loc options.
21446  Note that if any segments are located above 64K, the -r flag must be passed
21447  to the linker to generate the proper segment relocations, and the Intel
21448  HEX output format must be used.
21449  The -r flag can be passed to the linker by using the option 
21450 \emph on
21451 -Wl-r
21452 \emph default
21453  on the SDCC command line.
21454  However, currently the linker can not handle code segments > 64k.
21455 \end_layout
21456
21457 \begin_layout Section
21458 Pragmas
21459 \begin_inset LatexCommand \label{sec:Pragmas}
21460
21461 \end_inset
21462
21463
21464 \begin_inset LatexCommand \index{Pragmas}
21465
21466 \end_inset
21467
21468
21469 \end_layout
21470
21471 \begin_layout Standard
21472 Pragmas are used to turn on and/or off certain compiler options.
21473  Some of them are closely related to corresponding command-line options
21474  (see section 
21475 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21476
21477 \end_inset
21478
21479 ).
21480 \newline
21481 Pragmas should be placed before and/or after a function, placing pragmas
21482  inside a function body could have unpredictable results.
21483 \newline
21484
21485 \newline
21486 SDCC supports the
21487  following #pragma directives:
21488 \end_layout
21489
21490 \begin_layout Itemize
21491
21492 \series bold
21493 save
21494 \series default
21495
21496 \begin_inset LatexCommand \index{\#pragma save}
21497
21498 \end_inset
21499
21500  - this will save most current options to the save/restore stack.
21501  See #pragma\InsetSpace ~
21502 restore.
21503 \end_layout
21504
21505 \begin_layout Itemize
21506
21507 \series bold
21508 restore
21509 \series default
21510
21511 \begin_inset LatexCommand \index{\#pragma restore}
21512
21513 \end_inset
21514
21515  - will restore saved options from the last save.
21516  saves & restores can be nested.
21517  SDCC uses a save/restore stack: save pushes current options to the stack,
21518  restore pulls current options from the stack.
21519  See #pragma\InsetSpace ~
21520 save.
21521 \newline
21522
21523 \end_layout
21524
21525 \begin_layout Itemize
21526
21527 \series bold
21528 callee_saves
21529 \series default
21530
21531 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21532
21533 \end_inset
21534
21535
21536 \begin_inset LatexCommand \index{function prologue}
21537
21538 \end_inset
21539
21540  function1[,function2[,function3...]] 
21541 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21542
21543 \end_inset
21544
21545 - The compiler by default uses a caller saves convention for register saving
21546  across function calls, however this can cause unnecessary register pushing
21547  and popping
21548 \begin_inset LatexCommand \index{push/pop}
21549
21550 \end_inset
21551
21552  when calling small functions from larger functions.
21553  This option can be used to switch off the register saving convention for
21554  the function names specified.
21555  The compiler will not save registers when calling these functions, extra
21556  code need to be manually inserted at the entry and exit for these functions
21557  to save and restore the registers used by these functions, this can SUBSTANTIAL
21558 LY reduce code and improve run time performance of the generated code.
21559  In the future the compiler (with inter procedural analysis) may be able
21560  to determine the appropriate scheme to use for each function call.
21561  If -
21562 \begin_inset ERT
21563 status collapsed
21564
21565 \begin_layout Standard
21566
21567
21568 \backslash
21569 /
21570 \end_layout
21571
21572 \end_inset
21573
21574 -callee-saves command line option is used (see page 
21575 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21576
21577 \end_inset
21578
21579 ), the function names specified in #pragma\InsetSpace ~
21580 callee_saves
21581 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21582
21583 \end_inset
21584
21585  is appended to the list of functions specified in the command line.
21586 \end_layout
21587
21588 \begin_layout Itemize
21589
21590 \series bold
21591 exclude
21592 \series default
21593
21594 \begin_inset LatexCommand \index{\#pragma exclude}
21595
21596 \end_inset
21597
21598  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21599  of pairs of push/pop
21600 \begin_inset LatexCommand \index{push/pop}
21601
21602 \end_inset
21603
21604  instructions in 
21605 \emph on
21606 I
21607 \emph default
21608 nterrupt
21609 \begin_inset LatexCommand \index{interrupt}
21610
21611 \end_inset
21612
21613  
21614 \emph on
21615 S
21616 \emph default
21617 ervice 
21618 \emph on
21619 R
21620 \emph default
21621 outines.
21622  The directive should be placed immediately before the ISR function definition
21623  and it affects ALL ISR functions following it.
21624  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21625 exclude\InsetSpace ~
21626 none
21627 \begin_inset LatexCommand \index{\#pragma exclude}
21628
21629 \end_inset
21630
21631 .
21632  See also the related keyword _naked
21633 \begin_inset LatexCommand \index{\_naked}
21634
21635 \end_inset
21636
21637
21638 \begin_inset LatexCommand \index{\_\_naked}
21639
21640 \end_inset
21641
21642 .
21643 \end_layout
21644
21645 \begin_layout Itemize
21646
21647 \series bold
21648 less_pedantic
21649 \series default
21650
21651 \begin_inset LatexCommand \index{pedantic}
21652
21653 \end_inset
21654
21655
21656 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21657
21658 \end_inset
21659
21660  
21661 \begin_inset LatexCommand \label{ite:less_pedantic}
21662
21663 \end_inset
21664
21665 - the compiler will not warn you anymore for obvious mistakes, you're on
21666  your own now ;-( .
21667  See also the command line option -
21668 \begin_inset ERT
21669 status collapsed
21670
21671 \begin_layout Standard
21672
21673
21674 \backslash
21675 /
21676 \end_layout
21677
21678 \end_inset
21679
21680 -less-pedantic 
21681 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21682
21683 \end_inset
21684
21685 .
21686  
21687 \newline
21688 More specifically, the following warnings will be disabled: 
21689 \shape italic
21690 comparison is always [true/false] due to limited range of data type
21691 \shape default
21692  (94); 
21693 \shape italic
21694 overflow in implicit constant conversion
21695 \shape default
21696  (158); [the (in)famous] 
21697 \shape italic
21698 conditional flow changed by optimizer: so said EVELYN the modified DOG
21699 \shape default
21700  (110); 
21701 \shape italic
21702 function '[function name]' must return value
21703 \shape default
21704  (59).
21705  
21706 \newline
21707 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21708  level) are disabled, too, namely: 
21709 \shape italic
21710 constant value '[
21711 \begin_inset Note Note
21712 status collapsed
21713
21714 \begin_layout Standard
21715 dunno what comes here - this warning appears to be unused altogether
21716 \end_layout
21717
21718 \end_inset
21719
21720 ]', out of range
21721 \shape default
21722  (81); 
21723 \shape italic
21724 [left/right] shifting more than size of object changed to zero
21725 \shape default
21726  (116); 
21727 \shape italic
21728 unreachable code
21729 \shape default
21730  (126); 
21731 \shape italic
21732 integer overflow in expression
21733 \shape default
21734  (165); 
21735 \shape italic
21736 unmatched #pragma save and #pragma restore
21737 \shape default
21738  (170); 
21739 \shape italic
21740 comparison of 'signed char' with 'unsigned char' requires promotion to int
21741 \shape default
21742  (185); 
21743 \shape italic
21744 ISO C90 does not support flexible array members
21745 \shape default
21746  (187); 
21747 \shape italic
21748 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21749 nam
21750 e]':\InsetSpace ~
21751 [
21752 \begin_inset Note Note
21753 status collapsed
21754
21755 \begin_layout Standard
21756 appears to be always blank - what was supposed to be here?
21757 \end_layout
21758
21759 \end_inset
21760
21761 ]
21762 \shape default
21763  (114); 
21764 \shape italic
21765 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21766  complexity [number]
21767 \shape default
21768  (121).
21769 \end_layout
21770
21771 \begin_layout Itemize
21772
21773 \series bold
21774 disable_warning
21775 \series default
21776  <nnnn>
21777 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21778
21779 \end_inset
21780
21781  - the compiler will not warn you anymore about warning number <nnnn>.
21782 \end_layout
21783
21784 \begin_layout Itemize
21785
21786 \series bold
21787 nogcse
21788 \series default
21789
21790 \begin_inset LatexCommand \index{\#pragma nogcse}
21791
21792 \end_inset
21793
21794  - will stop global common subexpression elimination.
21795 \end_layout
21796
21797 \begin_layout Itemize
21798
21799 \series bold
21800 noinduction
21801 \series default
21802
21803 \begin_inset LatexCommand \index{\#pragma noinduction}
21804
21805 \end_inset
21806
21807  - will stop loop induction optimizations.
21808 \end_layout
21809
21810 \begin_layout Itemize
21811
21812 \series bold
21813 noinvariant
21814 \series default
21815
21816 \begin_inset LatexCommand \index{\#pragma noinvariant}
21817
21818 \end_inset
21819
21820  - will not do loop invariant optimizations.
21821  For more details see Loop Invariants in section
21822 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21823
21824 \end_inset
21825
21826 .
21827 \end_layout
21828
21829 \begin_layout Itemize
21830
21831 \series bold
21832 noiv
21833 \series default
21834
21835 \begin_inset LatexCommand \index{\#pragma noiv}
21836
21837 \end_inset
21838
21839  - Do not generate interrupt
21840 \begin_inset LatexCommand \index{interrupt}
21841
21842 \end_inset
21843
21844  vector table
21845 \begin_inset LatexCommand \index{interrupt vector table}
21846
21847 \end_inset
21848
21849  entries for all ISR functions defined after the pragma.
21850  This is useful in cases where the interrupt vector table must be defined
21851  manually, or when there is a secondary, manually defined interrupt vector
21852  table (e.g.
21853  for the autovector feature of the Cypress EZ-USB FX2).
21854  More elegantly this can be achieved by obmitting the optional interrupt
21855  number after the interrupt keyword, see section 
21856 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21857
21858 \end_inset
21859
21860 \InsetSpace ~
21861 about interrupts.
21862 \end_layout
21863
21864 \begin_layout Itemize
21865
21866 \series bold
21867 nojtbound
21868 \series default
21869
21870 \begin_inset LatexCommand \index{\#pragma nojtbound}
21871
21872 \end_inset
21873
21874  - will not generate code for boundary value checking, when switch statements
21875  are turned into jump-tables (dangerous).
21876  For more details see section 
21877 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21878
21879 \end_inset
21880
21881 .
21882 \end_layout
21883
21884 \begin_layout Itemize
21885
21886 \series bold
21887 noloopreverse
21888 \series default
21889
21890 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21891
21892 \end_inset
21893
21894  - Will not do loop reversal optimization
21895 \end_layout
21896
21897 \begin_layout Itemize
21898
21899 \series bold
21900 nooverlay
21901 \series default
21902
21903 \begin_inset LatexCommand \index{\#pragma nooverlay}
21904
21905 \end_inset
21906
21907  - the compiler will not overlay the parameters and local variables of a
21908  function.
21909 \end_layout
21910
21911 \begin_layout Itemize
21912
21913 \series bold
21914 stackauto
21915 \series default
21916
21917 \begin_inset LatexCommand \index{\#pragma stackauto}
21918
21919 \end_inset
21920
21921 - See option -
21922 \begin_inset ERT
21923 status collapsed
21924
21925 \begin_layout Standard
21926
21927
21928 \backslash
21929 /
21930 \end_layout
21931
21932 \end_inset
21933
21934 -stack-auto
21935 \begin_inset LatexCommand \index{-\/-stack-auto}
21936
21937 \end_inset
21938
21939  and section 
21940 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21941
21942 \end_inset
21943
21944  Parameters and Local Variables.
21945 \end_layout
21946
21947 \begin_layout Itemize
21948
21949 \series bold
21950 opt_code_speed
21951 \series default
21952  
21953 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21954
21955 \end_inset
21956
21957 - The compiler will optimize code generation towards fast code, possibly
21958  at the expense of code size.
21959  Currently this has little effect.
21960 \end_layout
21961
21962 \begin_layout Itemize
21963
21964 \series bold
21965 opt_code_size
21966 \series default
21967  
21968 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21969
21970 \end_inset
21971
21972 - The compiler will optimize code generation towards compact code, possibly
21973  at the expense of code speed.
21974  Currently this has little effect.
21975 \end_layout
21976
21977 \begin_layout Itemize
21978
21979 \series bold
21980 opt_code_balanced
21981 \series default
21982  
21983 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21984
21985 \end_inset
21986
21987 - The compiler will attempt to generate code that is both compact and fast,
21988  as long as meeting one goal is not a detriment to the other (this is the
21989  default).
21990  
21991 \end_layout
21992
21993 \begin_layout Itemize
21994
21995 \series bold
21996 std_sdcc89
21997 \series default
21998  
21999 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22000
22001 \end_inset
22002
22003 - Generally follow the C89 standard, but allow SDCC features that conflict
22004  with the standard (default).
22005 \end_layout
22006
22007 \begin_layout Itemize
22008
22009 \series bold
22010 std_c89
22011 \series default
22012  
22013 \begin_inset LatexCommand \index{\#pragma std\_c89}
22014
22015 \end_inset
22016
22017 - Follow the C89 standard and disable SDCC features that conflict with the
22018  standard.
22019 \end_layout
22020
22021 \begin_layout Itemize
22022
22023 \series bold
22024 std_sdcc99
22025 \series default
22026  
22027 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22028
22029 \end_inset
22030
22031 - Generally follow the C99 standard, but allow SDCC features that conflict
22032  with the standard (incomplete support).
22033 \end_layout
22034
22035 \begin_layout Itemize
22036
22037 \series bold
22038 std_c99
22039 \series default
22040  
22041 \begin_inset LatexCommand \index{\#pragma std\_c99}
22042
22043 \end_inset
22044
22045 - Follow the C99 standard and disable SDCC features that conflict with the
22046  standard (incomplete support).
22047 \end_layout
22048
22049 \begin_layout Itemize
22050
22051 \series bold
22052 codeseg
22053 \series default
22054  <name>
22055 \begin_inset LatexCommand \index{\#pragma codeseg}
22056
22057 \end_inset
22058
22059 - Use this name (max.
22060  8 characters) for the code segment.
22061  See option -
22062 \begin_inset ERT
22063 status collapsed
22064
22065 \begin_layout Standard
22066
22067
22068 \backslash
22069 /
22070 \end_layout
22071
22072 \end_inset
22073
22074 -codeseg.
22075 \end_layout
22076
22077 \begin_layout Itemize
22078
22079 \series bold
22080 constseg
22081 \series default
22082  <name>
22083 \begin_inset LatexCommand \index{\#pragma constseg}
22084
22085 \end_inset
22086
22087 - Use this name (max.
22088  8 characters) for the const segment.
22089  See option -
22090 \begin_inset ERT
22091 status collapsed
22092
22093 \begin_layout Standard
22094
22095
22096 \backslash
22097 /
22098 \end_layout
22099
22100 \end_inset
22101
22102 -constseg.
22103 \end_layout
22104
22105 \begin_layout Standard
22106 The preprocessor SDCPP
22107 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22108
22109 \end_inset
22110
22111  supports the following #pragma directives:
22112 \end_layout
22113
22114 \begin_layout Itemize
22115
22116 \series bold
22117 pedantic_parse_number
22118 \series default
22119
22120 \begin_inset LatexCommand \index{pedantic}
22121
22122 \end_inset
22123
22124
22125 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22126
22127 \end_inset
22128
22129  (+ | -) 
22130 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22131
22132 \end_inset
22133
22134 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22135  properly and the macro LO_B(3) gets expanded.
22136  Default is off.
22137  See also the -
22138 \begin_inset ERT
22139 status collapsed
22140
22141 \begin_layout Standard
22142
22143
22144 \backslash
22145 /
22146 \end_layout
22147
22148 \end_inset
22149
22150 -pedantic-parse-number command line option 
22151 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22152
22153 \end_inset
22154
22155 .
22156  
22157 \newline
22158 Below is an example on how to use this pragma.
22159
22160 \emph on
22161  Note: this functionality is not in conformance with standard!
22162 \end_layout
22163
22164 \begin_layout Verse
22165
22166 \family typewriter
22167 #pragma pedantic_parse_number +
22168 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22169
22170 \end_inset
22171
22172
22173 \newline
22174
22175 \newline
22176 #define LO_B(x) ((x) & 0xff)
22177 \newline
22178
22179 \newline
22180 unsigned char foo(void)
22181 \newline
22182 {
22183 \newline
22184 \InsetSpace ~
22185 \InsetSpace ~
22186 \InsetSpace ~
22187 unsigned char c=0xfe-LO_B(3)
22188 ;
22189 \newline
22190
22191 \newline
22192 \InsetSpace ~
22193 \InsetSpace ~
22194 \InsetSpace ~
22195 return c;
22196 \newline
22197 }
22198 \newline
22199
22200 \end_layout
22201
22202 \begin_layout Itemize
22203
22204 \series bold
22205 preproc_asm
22206 \series default
22207
22208 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22209
22210 \end_inset
22211
22212  (+ | -) - switch _asm _endasm block preprocessing on / off.
22213  Default is on.
22214  You use this prama to define multilines of assembly code.
22215  This will prevent the preprocessor from changing the formating required
22216  by assembly code.
22217  Below is an example on how to use this pragma.
22218 \end_layout
22219
22220 \begin_layout Verse
22221
22222 \family typewriter
22223 #pragma preproc_asm -
22224 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22225
22226 \end_inset
22227
22228
22229 \newline
22230 #define MYDELAY _asm
22231 \newline
22232 \InsetSpace ~
22233 \InsetSpace ~
22234 \InsetSpace ~
22235 nop ;my assembly comment...
22236 \newline
22237 \InsetSpace ~
22238 \InsetSpace ~
22239 \InsetSpace ~
22240 nop
22241 \newline
22242 \InsetSpace ~
22243 \InsetSpace ~
22244 \InsetSpace ~
22245 nop
22246 \newline
22247 _endasm
22248 \newline
22249 #pragma preproc_asm
22250  +
22251 \newline
22252
22253 \newline
22254 void foo (void) 
22255 \newline
22256
22257 \newline
22258 \InsetSpace ~
22259 \InsetSpace ~
22260 \InsetSpace ~
22261  ...
22262  
22263 \newline
22264 \InsetSpace ~
22265 \InsetSpace ~
22266 \InsetSpace ~
22267  MYDELAY;
22268 \newline
22269 \InsetSpace ~
22270 \InsetSpace ~
22271 \InsetSpace ~
22272  ...
22273  
22274 \newline
22275
22276 \newline
22277
22278 \end_layout
22279
22280 \begin_layout Itemize
22281
22282 \series bold
22283 sdcc_hash
22284 \series default
22285
22286 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22287
22288 \end_inset
22289
22290  (+ | -) - Allow "naked" hash in macro definition, for example:
22291 \newline
22292
22293 \family typewriter
22294 #define DIR_LO(x) #(x & 0xff)
22295 \family default
22296
22297 \newline
22298 Default is off.
22299  Below is an example on how to use this pragma.
22300 \end_layout
22301
22302 \begin_layout Verse
22303
22304 \family typewriter
22305 #pragma preproc_asm +
22306 \newline
22307 #pragma sdcc_hash +
22308 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22309
22310 \end_inset
22311
22312
22313 \newline
22314
22315 \newline
22316 #define ROMCALL(x) 
22317 \backslash
22318
22319 \newline
22320 \InsetSpace ~
22321 \InsetSpace ~
22322 \InsetSpace ~
22323 mov R6_B3, #(x & 0xff) 
22324 \backslash
22325
22326 \newline
22327 \InsetSpace ~
22328 \InsetSpace ~
22329 \InsetSpace ~
22330 mov R7_B3, #((x >> 8) & 0xff) 
22331 \backslash
22332
22333 \newline
22334 \InsetSpace ~
22335 \InsetSpace ~
22336 \InsetSpace ~
22337 lcall __romcall
22338 \newline
22339
22340 \newline
22341 ...
22342 \newline
22343 _asm
22344 \newline
22345 ROMCALL(72)
22346 \newline
22347 _endasm;
22348 \newline
22349 ...
22350 \newline
22351
22352 \end_layout
22353
22354 \begin_layout Standard
22355 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22356 ons which might cause the compiler to generate extra stack and/or data space
22357  to store compiler generated temporary variables.
22358  This usually happens in large functions.
22359  Pragma directives should be used as shown in the following example, they
22360  are used to control options and optimizations for a given function.
22361  
22362 \end_layout
22363
22364 \begin_layout Verse
22365
22366 \family typewriter
22367 #pragma save
22368 \begin_inset LatexCommand \index{\#pragma save}
22369
22370 \end_inset
22371
22372  \InsetSpace ~
22373 \InsetSpace ~
22374 \InsetSpace ~
22375 \InsetSpace ~
22376 \InsetSpace ~
22377 \InsetSpace ~
22378 \InsetSpace ~
22379 /* save the current settings */ 
22380 \newline
22381 #pragma nogcse
22382 \begin_inset LatexCommand \index{\#pragma nogcse}
22383
22384 \end_inset
22385
22386  \InsetSpace ~
22387 \InsetSpace ~
22388 \InsetSpace ~
22389 \InsetSpace ~
22390 \InsetSpace ~
22391 /* turnoff global subexpression elimination */ 
22392 \newline
22393 #pragma noinduction
22394 \begin_inset LatexCommand \index{\#pragma noinduction}
22395
22396 \end_inset
22397
22398  /* turn off induction optimizations */ 
22399 \newline
22400 int foo () 
22401 \newline
22402
22403 \newline
22404 \InsetSpace ~
22405  \InsetSpace ~
22406  ...
22407  
22408 \newline
22409 \InsetSpace ~
22410  \InsetSpace ~
22411  /* large code */ 
22412 \newline
22413 \InsetSpace ~
22414  \InsetSpace ~
22415  ...
22416  
22417 \newline
22418
22419 \newline
22420 #pragma restore
22421 \begin_inset LatexCommand \index{\#pragma restore}
22422
22423 \end_inset
22424
22425  /* turn the optimizations back on */
22426 \end_layout
22427
22428 \begin_layout Standard
22429 The compiler will generate a warning message when extra space is allocated.
22430  It is strongly recommended that the save and restore pragmas be used when
22431  changing options for a function.
22432 \newline
22433
22434 \newline
22435
22436 \newline
22437
22438 \end_layout
22439
22440 \begin_layout Section
22441 Defines Created by the Compiler
22442 \end_layout
22443
22444 \begin_layout Standard
22445 The compiler creates the following #defines
22446 \begin_inset LatexCommand \index{\#defines}
22447
22448 \end_inset
22449
22450
22451 \begin_inset LatexCommand \index{Defines created by the compiler}
22452
22453 \end_inset
22454
22455 :
22456 \newline
22457
22458 \end_layout
22459
22460 \begin_layout Standard
22461 \begin_inset Tabular
22462 <lyxtabular version="3" rows="11" columns="2">
22463 <features>
22464 <column alignment="left" valignment="top" leftline="true" width="3in">
22465 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22466 <row topline="true" bottomline="true">
22467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22468 \begin_inset Text
22469
22470 \begin_layout Standard
22471
22472 \series bold
22473 #define
22474 \end_layout
22475
22476 \end_inset
22477 </cell>
22478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22479 \begin_inset Text
22480
22481 \begin_layout Standard
22482
22483 \series bold
22484 Description
22485 \end_layout
22486
22487 \end_inset
22488 </cell>
22489 </row>
22490 <row topline="true">
22491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22492 \begin_inset Text
22493
22494 \begin_layout Standard
22495 SDCC
22496 \begin_inset LatexCommand \index{SDCC}
22497
22498 \end_inset
22499
22500  
22501 \end_layout
22502
22503 \end_inset
22504 </cell>
22505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22506 \begin_inset Text
22507
22508 \begin_layout Standard
22509 Always defined.
22510  Since version 2.5.6 the version number as an int (ex.
22511  256)
22512 \end_layout
22513
22514 \end_inset
22515 </cell>
22516 </row>
22517 <row topline="true">
22518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22519 \begin_inset Text
22520
22521 \begin_layout Standard
22522 SDCC_mcs51
22523 \begin_inset LatexCommand \index{SDCC\_mcs51}
22524
22525 \end_inset
22526
22527  or SDCC_ds390
22528 \begin_inset LatexCommand \index{SDCC\_ds390}
22529
22530 \end_inset
22531
22532  or SDCC_z80
22533 \begin_inset LatexCommand \index{SDCC\_z80}
22534
22535 \end_inset
22536
22537 , etc.
22538 \end_layout
22539
22540 \end_inset
22541 </cell>
22542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22543 \begin_inset Text
22544
22545 \begin_layout Standard
22546 depending on the model used (e.g.: -mds390)
22547 \end_layout
22548
22549 \end_inset
22550 </cell>
22551 </row>
22552 <row topline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22554 \begin_inset Text
22555
22556 \begin_layout Standard
22557 __mcs51
22558 \begin_inset LatexCommand \index{\_\_mcs51}
22559
22560 \end_inset
22561
22562 , __ds390
22563 \begin_inset LatexCommand \index{\_\_ds390}
22564
22565 \end_inset
22566
22567 , __hc08
22568 \begin_inset LatexCommand \index{\_\_hc08}
22569
22570 \end_inset
22571
22572 , __z80
22573 \begin_inset LatexCommand \index{\_\_z80}
22574
22575 \end_inset
22576
22577 , etc
22578 \end_layout
22579
22580 \end_inset
22581 </cell>
22582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22583 \begin_inset Text
22584
22585 \begin_layout Standard
22586 depending on the model used (e.g.
22587  -mz80)
22588 \end_layout
22589
22590 \end_inset
22591 </cell>
22592 </row>
22593 <row topline="true">
22594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22595 \begin_inset Text
22596
22597 \begin_layout Standard
22598 SDCC_STACK_AUTO
22599 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22600
22601 \end_inset
22602
22603
22604 \end_layout
22605
22606 \end_inset
22607 </cell>
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22609 \begin_inset Text
22610
22611 \begin_layout Standard
22612 when 
22613 \emph on
22614 -
22615 \begin_inset ERT
22616 status collapsed
22617
22618 \begin_layout Standard
22619
22620
22621 \backslash
22622 /
22623 \end_layout
22624
22625 \end_inset
22626
22627 -stack-auto
22628 \emph default
22629  option is used
22630 \end_layout
22631
22632 \end_inset
22633 </cell>
22634 </row>
22635 <row topline="true">
22636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22637 \begin_inset Text
22638
22639 \begin_layout Standard
22640 SDCC_MODEL_SMALL
22641 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22642
22643 \end_inset
22644
22645
22646 \end_layout
22647
22648 \end_inset
22649 </cell>
22650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22651 \begin_inset Text
22652
22653 \begin_layout Standard
22654 when 
22655 \emph on
22656 -
22657 \begin_inset ERT
22658 status collapsed
22659
22660 \begin_layout Standard
22661
22662
22663 \backslash
22664 /
22665 \end_layout
22666
22667 \end_inset
22668
22669 -model-small
22670 \emph default
22671  is used
22672 \end_layout
22673
22674 \end_inset
22675 </cell>
22676 </row>
22677 <row topline="true">
22678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22679 \begin_inset Text
22680
22681 \begin_layout Standard
22682 SDCC_MODEL_MEDIUM
22683 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22684
22685 \end_inset
22686
22687
22688 \end_layout
22689
22690 \end_inset
22691 </cell>
22692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22693 \begin_inset Text
22694
22695 \begin_layout Standard
22696 when 
22697 \emph on
22698 -
22699 \begin_inset ERT
22700 status collapsed
22701
22702 \begin_layout Standard
22703
22704
22705 \backslash
22706 /
22707 \end_layout
22708
22709 \end_inset
22710
22711 -model-medium
22712 \emph default
22713  is used
22714 \end_layout
22715
22716 \end_inset
22717 </cell>
22718 </row>
22719 <row topline="true">
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22721 \begin_inset Text
22722
22723 \begin_layout Standard
22724 SDCC_MODEL_LARGE
22725 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22726
22727 \end_inset
22728
22729
22730 \end_layout
22731
22732 \end_inset
22733 </cell>
22734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22735 \begin_inset Text
22736
22737 \begin_layout Standard
22738 when 
22739 \emph on
22740 -
22741 \begin_inset ERT
22742 status collapsed
22743
22744 \begin_layout Standard
22745
22746
22747 \backslash
22748 /
22749 \end_layout
22750
22751 \end_inset
22752
22753 -model-large
22754 \emph default
22755  is used
22756 \end_layout
22757
22758 \end_inset
22759 </cell>
22760 </row>
22761 <row topline="true">
22762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22763 \begin_inset Text
22764
22765 \begin_layout Standard
22766 SDCC_USE_XSTACK
22767 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22768
22769 \end_inset
22770
22771
22772 \end_layout
22773
22774 \end_inset
22775 </cell>
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_inset Text
22778
22779 \begin_layout Standard
22780 when 
22781 \emph on
22782 -
22783 \begin_inset ERT
22784 status collapsed
22785
22786 \begin_layout Standard
22787
22788
22789 \backslash
22790 /
22791 \end_layout
22792
22793 \end_inset
22794
22795 -xstack
22796 \emph default
22797  option is used
22798 \end_layout
22799
22800 \end_inset
22801 </cell>
22802 </row>
22803 <row topline="true">
22804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22805 \begin_inset Text
22806
22807 \begin_layout Standard
22808 SDCC_STACK_TENBIT
22809 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22810
22811 \end_inset
22812
22813  
22814 \end_layout
22815
22816 \end_inset
22817 </cell>
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22819 \begin_inset Text
22820
22821 \begin_layout Standard
22822 when 
22823 \emph on
22824 -mds390
22825 \emph default
22826  is used
22827 \end_layout
22828
22829 \end_inset
22830 </cell>
22831 </row>
22832 <row topline="true" bottomline="true">
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22834 \begin_inset Text
22835
22836 \begin_layout Standard
22837 SDCC_MODEL_FLAT24
22838 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22839
22840 \end_inset
22841
22842
22843 \end_layout
22844
22845 \end_inset
22846 </cell>
22847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22848 \begin_inset Text
22849
22850 \begin_layout Standard
22851 when 
22852 \emph on
22853 -mds390
22854 \emph default
22855  is used
22856 \end_layout
22857
22858 \end_inset
22859 </cell>
22860 </row>
22861 </lyxtabular>
22862
22863 \end_inset
22864
22865
22866 \end_layout
22867
22868 \begin_layout Chapter
22869 Notes on supported Processors
22870 \end_layout
22871
22872 \begin_layout Section
22873 MCS51 variants
22874 \begin_inset LatexCommand \label{sub:MCS51-variants}
22875
22876 \end_inset
22877
22878
22879 \begin_inset LatexCommand \index{MCS51 variants}
22880
22881 \end_inset
22882
22883
22884 \end_layout
22885
22886 \begin_layout Standard
22887 MCS51 processors are available from many vendors and come in many different
22888  flavours.
22889  While they might differ considerably in respect to Special Function Registers
22890  the core MCS51 is usually not modified or is kept compatible.
22891  
22892 \end_layout
22893
22894 \begin_layout Subsection
22895 pdata access by SFR 
22896 \end_layout
22897
22898 \begin_layout Standard
22899 With the upcome of devices with internal xdata and flash memory devices
22900  using port P2
22901 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22902
22903 \end_inset
22904
22905  as dedicated I/O port is becoming more popular.
22906  Switching the high byte for pdata
22907 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22908
22909 \end_inset
22910
22911  access which was formerly done by port P2 is then achieved by a Special
22912  Function Register
22913 \begin_inset LatexCommand \index{sfr}
22914
22915 \end_inset
22916
22917 .
22918  In well-established MCS51 tradition the address of this 
22919 \emph on
22920 sfr
22921 \emph default
22922  is where the chip designers decided to put it.
22923  Needless to say that they didn't agree on a common name either.
22924  So that the startup code can correctly initialize xdata variables, you
22925  should define an sfr with the name _XPAGE
22926 \family typewriter
22927
22928 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22929
22930 \end_inset
22931
22932
22933 \family default
22934  at the appropriate location if the default, port P2, is not used for this.
22935  Some examples are:
22936 \end_layout
22937
22938 \begin_layout Verse
22939
22940 \family typewriter
22941 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22942  MPAGE */
22943 \end_layout
22944
22945 \begin_layout Verse
22946
22947 \family typewriter
22948 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22949  a.k.a.
22950  MPAGE */
22951 \end_layout
22952
22953 \begin_layout Verse
22954
22955 \family typewriter
22956 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22957  XPAGE */
22958 \end_layout
22959
22960 \begin_layout Verse
22961
22962 \family typewriter
22963 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22964  EMI0CN */
22965 \end_layout
22966
22967 \begin_layout Verse
22968
22969 \family typewriter
22970 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22971  EMI0CN */
22972 \end_layout
22973
22974 \begin_layout Standard
22975 For more exotic implementations further customizations may be needed.
22976  See section 
22977 \begin_inset LatexCommand \ref{sub:Startup-Code}
22978
22979 \end_inset
22980
22981  for other possibilities.
22982 \end_layout
22983
22984 \begin_layout Subsection
22985 Other Features available by SFR
22986 \end_layout
22987
22988 \begin_layout Standard
22989 Some MCS51 variants offer features like Double DPTR
22990 \begin_inset LatexCommand \index{DPTR}
22991
22992 \end_inset
22993
22994 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22995  These are currently not used for the MCS51 port.
22996  If you absolutely need them you can fall back to inline assembly or submit
22997  a patch to SDCC.
22998 \begin_inset VSpace bigskip
22999 \end_inset
23000
23001
23002 \end_layout
23003
23004 \begin_layout Section
23005 DS400 port
23006 \end_layout
23007
23008 \begin_layout Standard
23009 The DS80C400
23010 \begin_inset LatexCommand \index{DS80C400}
23011
23012 \end_inset
23013
23014
23015 \begin_inset LatexCommand \index{DS400}
23016
23017 \end_inset
23018
23019  microcontroller has a rich set of peripherals.
23020  In its built-in ROM library it includes functions to access some of the
23021  features, among them is a TCP stack with IP4 and IP6 support.
23022  Library headers (currently in beta status) and other files are provided
23023  at 
23024 \size footnotesize
23025
23026 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23027
23028 \end_inset
23029
23030 .
23031  
23032 \begin_inset VSpace bigskip
23033 \end_inset
23034
23035
23036 \end_layout
23037
23038 \begin_layout Section
23039 The Z80 and gbz80 port
23040 \end_layout
23041
23042 \begin_layout Standard
23043 SDCC can target both the Zilog Z80
23044 \begin_inset LatexCommand \index{Z80}
23045
23046 \end_inset
23047
23048  and the Nintendo Gameboy's Z80-like gbz80
23049 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23050
23051 \end_inset
23052
23053 .
23054  The Z80 port is passed through the same 
23055 \emph on
23056 regressions tests
23057 \begin_inset LatexCommand \index{Regression test}
23058
23059 \end_inset
23060
23061
23062 \emph default
23063  (see section 
23064 \begin_inset LatexCommand \ref{sec:Quality-control}
23065
23066 \end_inset
23067
23068 ) as the MCS51 and DS390 ports, so floating point support, support for long
23069  variables and bitfield support is fine.
23070  See mailing lists and forums about interrupt routines.
23071 \end_layout
23072
23073 \begin_layout Standard
23074 As always, the code is the authoritative reference - see z80/ralloc.c and
23075  z80/gen.c.
23076  The stack
23077 \begin_inset LatexCommand \index{Z80!stack}
23078
23079 \end_inset
23080
23081  frame is similar to that generated by the IAR Z80 compiler.
23082  IX is used as the base pointer, HL and IY are used as a temporary registers,
23083  and BC and DE are available for holding variables.
23084  Return values
23085 \begin_inset LatexCommand \index{Z80!return value}
23086
23087 \end_inset
23088
23089  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23090  bytes).
23091  The gbz80 port use the same set of registers for the return values, but
23092  in a different order of significance: E (one byte), DE (two bytes), or
23093  HLDE (four bytes).
23094 \begin_inset VSpace bigskip
23095 \end_inset
23096
23097
23098 \end_layout
23099
23100 \begin_layout Section
23101 The HC08 port
23102 \end_layout
23103
23104 \begin_layout Standard
23105 The port to the Freescale/Motorola HC08
23106 \begin_inset LatexCommand \index{HC08}
23107
23108 \end_inset
23109
23110  family has been added in October 2003, and is still undergoing some basic
23111  development.
23112  The code generator is complete, but the register allocation is still quite
23113  unoptimized.
23114  Some of the SDCC's standard C library functions have embedded non-HC08
23115  inline assembly and so are not yet usable.
23116 \end_layout
23117
23118 \begin_layout Standard
23119 The HC08 port passes the regression test suite (see section 
23120 \begin_inset LatexCommand \ref{sec:Quality-control}
23121
23122 \end_inset
23123
23124 ).
23125 \begin_inset VSpace bigskip
23126 \end_inset
23127
23128
23129 \newpage
23130
23131 \end_layout
23132
23133 \begin_layout Section
23134 The PIC14
23135 \begin_inset LatexCommand \index{PIC14}
23136
23137 \end_inset
23138
23139  port
23140 \end_layout
23141
23142 \begin_layout Standard
23143 The PIC14 port adds support for Microchip
23144 \begin_inset LatexCommand \index{Microchip}
23145
23146 \end_inset
23147
23148
23149 \begin_inset Formula $^{\text{TM}}$
23150 \end_inset
23151
23152  PIC
23153 \begin_inset LatexCommand \index{PIC14}
23154
23155 \end_inset
23156
23157
23158 \begin_inset Formula $^{\text{TM}}$
23159 \end_inset
23160
23161  MCUs with 14 bit wide instructions.
23162  This port is not yet mature and still lacks many features.
23163  However, it can work for simple code.
23164 \end_layout
23165
23166 \begin_layout Standard
23167 Currently supported devices include:
23168 \end_layout
23169
23170 \begin_layout Standard
23171 12F: 629, 635, 675, 683
23172 \end_layout
23173
23174 \begin_layout Standard
23175 16C: 432, 433
23176 \end_layout
23177
23178 \begin_layout Standard
23179 16C: 554, 557, 558
23180 \end_layout
23181
23182 \begin_layout Standard
23183 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23184 \end_layout
23185
23186 \begin_layout Standard
23187 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23188  781, 782
23189 \end_layout
23190
23191 \begin_layout Standard
23192 16C: 925, 926
23193 \end_layout
23194
23195 \begin_layout Standard
23196 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23197  689, 690
23198 \end_layout
23199
23200 \begin_layout Standard
23201 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23202 \end_layout
23203
23204 \begin_layout Standard
23205 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23206  877, 877a, 88
23207 \end_layout
23208
23209 \begin_layout Standard
23210 16F: 913, 914, 916, 917
23211 \end_layout
23212
23213 \begin_layout Standard
23214 An up-to-date list of currently supported devices can be obtained via 
23215 \family typewriter
23216 sdcc -mpic14 -phelp foo.c
23217 \family default
23218  (foo.c must exist...).
23219 \end_layout
23220
23221 \begin_layout Subsection
23222 PIC Code Pages
23223 \begin_inset LatexCommand \index{code page (pic14)}
23224
23225 \end_inset
23226
23227  and Memory Banks
23228 \begin_inset LatexCommand \index{Memory bank (pic14)}
23229
23230 \end_inset
23231
23232
23233 \end_layout
23234
23235 \begin_layout Standard
23236 The linker organizes allocation for the code page and RAM banks.
23237  It does not have intimate knowledge of the code flow.
23238  It will put all the code section of a single .asm file into a single code
23239  page.
23240  In order to make use of multiple code pages, separate asm files must be
23241  used.
23242  The compiler assigns all 
23243 \emph on
23244 static
23245 \emph default
23246  functions of a single .c file into the same code page.
23247 \newline
23248
23249 \newline
23250 To get the best results,
23251  follow these guidelines:
23252 \end_layout
23253
23254 \begin_layout Enumerate
23255 Make local functions static, as non static functions require code page selection
23256  overhead.
23257 \newline
23258 Due to the way sdcc handles functions, place called functions prior
23259  to calling functions in the file wherever possible: Otherwise sdcc will
23260  insert unneccessary pagesel directives around the call, believing that
23261  the called function is externally defined.
23262 \end_layout
23263
23264 \begin_layout Enumerate
23265 For devices that have multiple code pages it is more efficient to use the
23266  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23267  but only 2 files for the 16F874.
23268  This way the linker can put the code for each file into different code
23269  pages and there will be less page selection overhead.
23270 \end_layout
23271
23272 \begin_layout Enumerate
23273 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23274  instruction set), use `unsigned char' wherever possible instead of `int'.
23275 \end_layout
23276
23277 \begin_layout Subsection
23278 Adding New Devices to the Port 
23279 \end_layout
23280
23281 \begin_layout Standard
23282 Adding support for a new 14
23283 \begin_inset ERT
23284 status open
23285
23286 \begin_layout Standard
23287
23288
23289 \backslash
23290 ,
23291 \end_layout
23292
23293 \end_inset
23294
23295 bit PIC MCU requires the following steps:
23296 \end_layout
23297
23298 \begin_layout Enumerate
23299 Create a new device description.
23300 \newline
23301 Each device is described in two files: pic16f*.h
23302  and pic16f*.c.
23303  These files primarily define SFRs, structs to access their bits, and symbolic
23304  configuration options.
23305  Both files can be generated from gputils' .inc files using the perl script
23306  
23307 \family typewriter
23308 support/scripts/inc2h.pl
23309 \family default
23310 .
23311  This file also contains further instructions on how to proceed.
23312 \end_layout
23313
23314 \begin_layout Enumerate
23315 Copy the .h file into SDCC's include path and either add the .c file to your
23316  project or copy it to 
23317 \family typewriter
23318 device/lib/pic/libdev
23319 \family default
23320 .
23321  Afterwards, rebuild and install the libraries.
23322 \end_layout
23323
23324 \begin_layout Enumerate
23325 Edit pic14devices.txt in SDCC's include path (
23326 \family typewriter
23327 device/include/pic/
23328 \family default
23329  in the source tree or 
23330 \family typewriter
23331 /usr/local/share/sdcc/include/pic
23332 \family default
23333  after installation).
23334 \newline
23335 You need to add a device specification here to make
23336  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23337  the compiler.
23338  Probably you can copy and modify an existing entry.
23339  The file format is documented at the top of the file.
23340 \end_layout
23341
23342 \begin_layout Subsection
23343 Interrupt Code
23344 \end_layout
23345
23346 \begin_layout Standard
23347 For the interrupt function, use the keyword `__interrupt'
23348 \begin_inset LatexCommand \index{PIC14!interrupt}
23349
23350 \end_inset
23351
23352  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23353  there to avoid a syntax error - it ought to be fixed).
23354  E.g.:
23355 \end_layout
23356
23357 \begin_layout Verse
23358
23359 \family typewriter
23360 void Intr(void) __interrupt 0
23361 \newline
23362 {
23363 \newline
23364 \InsetSpace ~
23365 \InsetSpace ~
23366 T0IF = 0; /* Clear timer interrupt */
23367 \newline
23368 }
23369 \end_layout
23370
23371 \begin_layout Subsection
23372 Linking and Assembling
23373 \end_layout
23374
23375 \begin_layout Standard
23376 For assembling you can use either GPUTILS'
23377 \begin_inset LatexCommand \index{gputils (pic tools)}
23378
23379 \end_inset
23380
23381  gpasm.exe or MPLAB's mpasmwin.exe.
23382  GPUTILS are available from 
23383 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23384
23385 \end_inset
23386
23387 .
23388  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23389  If you use MPLAB and an interrupt function then the linker script file
23390  vectors section will need to be enlarged to link with mplink.
23391 \newline
23392
23393 \newline
23394 Here is a 
23395 \family typewriter
23396 Makefile
23397 \family default
23398  using GPUTILS:
23399 \end_layout
23400
23401 \begin_layout Verse
23402
23403 \family typewriter
23404 .c.o:
23405 \newline
23406 \InsetSpace ~
23407 \InsetSpace ~
23408 \InsetSpace ~
23409 \InsetSpace ~
23410 \InsetSpace ~
23411 \InsetSpace ~
23412 \InsetSpace ~
23413 \InsetSpace ~
23414 sdcc -V -mpic14 -p16f877 -c $< 
23415 \newline
23416
23417 \newline
23418 $(PRJ).hex: $(OBJS) 
23419 \newline
23420 \InsetSpace ~
23421 \InsetSpace ~
23422 \InsetSpace ~
23423 \InsetSpace ~
23424 \InsetSpace ~
23425 \InsetSpace ~
23426 \InsetSpace ~
23427 \InsetSpace ~
23428 gplink -m -s $(PRJ).lkr
23429  -o $(PRJ).hex $(OBJS) libsdcc.lib
23430 \end_layout
23431
23432 \begin_layout Standard
23433 Here is a 
23434 \family typewriter
23435 Makefile
23436 \family default
23437  using MPLAB:
23438 \end_layout
23439
23440 \begin_layout Verse
23441
23442 \family typewriter
23443 .c.o: 
23444 \newline
23445 \InsetSpace ~
23446 \InsetSpace ~
23447 \InsetSpace ~
23448 \InsetSpace ~
23449 \InsetSpace ~
23450 \InsetSpace ~
23451 \InsetSpace ~
23452 \InsetSpace ~
23453 sdcc -S -V -mpic14 -p16f877 $< 
23454 \newline
23455 \InsetSpace ~
23456 \InsetSpace ~
23457 \InsetSpace ~
23458 \InsetSpace ~
23459 \InsetSpace ~
23460 \InsetSpace ~
23461 \InsetSpace ~
23462 \InsetSpace ~
23463 mpasmwin /q /o $*.asm
23464 \newline
23465
23466 \newline
23467 $(PRJ).hex: $(OBJS)
23468  
23469 \newline
23470 \InsetSpace ~
23471 \InsetSpace ~
23472 \InsetSpace ~
23473 \InsetSpace ~
23474 \InsetSpace ~
23475 \InsetSpace ~
23476 \InsetSpace ~
23477 \InsetSpace ~
23478 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23479 \end_layout
23480
23481 \begin_layout Standard
23482 Please note that indentations within a
23483 \family typewriter
23484  Makefile
23485 \family default
23486  have to be done with a tabulator character.
23487 \end_layout
23488
23489 \begin_layout Subsection
23490 Command-Line Options
23491 \end_layout
23492
23493 \begin_layout Standard
23494 Besides the switches common to all SDCC backends, the PIC14 port accepts
23495  the following options (for an updated list see sdcc -
23496 \begin_inset ERT
23497 status collapsed
23498
23499 \begin_layout Standard
23500
23501
23502 \backslash
23503 /
23504 \end_layout
23505
23506 \end_inset
23507
23508 -help):
23509 \end_layout
23510
23511 \begin_layout Description
23512 -
23513 \begin_inset ERT
23514 status collapsed
23515
23516 \begin_layout Standard
23517
23518
23519 \backslash
23520 /
23521 \end_layout
23522
23523 \end_inset
23524
23525 -debug-xtra
23526 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23527
23528 \end_inset
23529
23530  emit debug info in assembly output
23531 \end_layout
23532
23533 \begin_layout Description
23534 -
23535 \begin_inset ERT
23536 status collapsed
23537
23538 \begin_layout Standard
23539
23540
23541 \backslash
23542 /
23543 \end_layout
23544
23545 \end_inset
23546
23547 -no-pcode-opt
23548 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23549
23550 \end_inset
23551
23552  disable (slightly faulty) optimization on pCode
23553 \end_layout
23554
23555 \begin_layout Description
23556 -
23557 \begin_inset ERT
23558 status collapsed
23559
23560 \begin_layout Standard
23561
23562
23563 \backslash
23564 /
23565 \end_layout
23566
23567 \end_inset
23568
23569 -stack-loc
23570 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23571
23572 \end_inset
23573
23574  sets the lowest address of the argument passing stack (defaults to a suitably
23575  large shared databank to reduce BANKSEL overhead)
23576 \end_layout
23577
23578 \begin_layout Description
23579 -
23580 \begin_inset ERT
23581 status collapsed
23582
23583 \begin_layout Standard
23584
23585
23586 \backslash
23587 /
23588 \end_layout
23589
23590 \end_inset
23591
23592 -stack-size
23593 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23594
23595 \end_inset
23596
23597  sets the size if the argument passing stack (default: 16, minimum: 4)
23598 \end_layout
23599
23600 \begin_layout Subsection
23601 Environment Variables
23602 \end_layout
23603
23604 \begin_layout Standard
23605 The PIC14 port recognizes the following environment variables:
23606 \end_layout
23607
23608 \begin_layout Description
23609 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23610  register (the ones called r0xNNNN) in a section of its own.
23611  By default (if this variable is unset), sdcc tries to cluster registers
23612  in sections in order to reduce the BANKSEL overhead when accessing them.
23613 \end_layout
23614
23615 \begin_layout Subsection
23616 The Library
23617 \end_layout
23618
23619 \begin_layout Standard
23620 The PIC14 library currently only contains support routines required by the
23621  compiler to implement multiplication, division, and floating point support.
23622  No libc-like replacement is available at the moment, though many of the
23623  common sdcc library sources (in 
23624 \family typewriter
23625 device/lib
23626 \family default
23627 ) should also compile with the PIC14 port.
23628 \end_layout
23629
23630 \begin_layout Subsubsection
23631 error: missing definition for symbol ``__gptrget1''
23632 \end_layout
23633
23634 \begin_layout Standard
23635 The PIC14 port uses library routines to provide more complex operations
23636  like multiplication, division/modulus and (generic) pointer dereferencing.
23637  In order to add these routines to your project, you must link with PIC14's
23638  
23639 \family typewriter
23640 libsdcc.lib
23641 \family default
23642 .
23643  For single source file projects this is done automatically, more complex
23644  projects must add 
23645 \family typewriter
23646 libsdcc.lib
23647 \family default
23648  to the linker's arguments.
23649  Make sure you also add an include path for the library (using the -I switch
23650  to the linker)!
23651 \end_layout
23652
23653 \begin_layout Subsubsection
23654 Processor mismatch in file ``XXX''.
23655 \end_layout
23656
23657 \begin_layout Standard
23658 This warning can usually be ignored due to the very good compatibility amongst
23659  14
23660 \begin_inset ERT
23661 status open
23662
23663 \begin_layout Standard
23664
23665
23666 \backslash
23667 ,
23668 \end_layout
23669
23670 \end_inset
23671
23672 bit PIC
23673 \begin_inset LatexCommand \index{PIC14}
23674
23675 \end_inset
23676
23677  devices.
23678 \end_layout
23679
23680 \begin_layout Standard
23681 You might also consider recompiling the library for your specific device
23682  by changing the ARCH=p16f877 (default target) entry in 
23683 \family typewriter
23684 device/lib/pic/Makefile.in
23685 \family default
23686  and 
23687 \family typewriter
23688 device/lib/pic/Makefile
23689 \family default
23690  to reflect your device.
23691  This might even improve performance for smaller devices as unneccesary
23692  BANKSELs might be removed.
23693 \end_layout
23694
23695 \begin_layout Subsection
23696 Known Bugs
23697 \end_layout
23698
23699 \begin_layout Subsubsection
23700 Function arguments
23701 \end_layout
23702
23703 \begin_layout Standard
23704 Functions with variable argument lists (like printf) are not yet supported.
23705  Similarly, taking the argument of the first argument passed into a function
23706  does not work: It is currently passed in WREG and has no address...
23707 \end_layout
23708
23709 \begin_layout Subsubsection
23710 Regression tests fail
23711 \end_layout
23712
23713 \begin_layout Standard
23714 Though the small subset of regression tests in src/regression passes, SDCC
23715  regression test suite does not, indicating that there are still major bugs
23716  in the port.
23717  However, many smaller projects have successfully used SDCC in the past...
23718 \end_layout
23719
23720 \begin_layout Standard
23721
23722 \size footnotesize
23723
23724 \newpage
23725
23726 \end_layout
23727
23728 \begin_layout Section
23729 The PIC16
23730 \begin_inset LatexCommand \index{PIC16}
23731
23732 \end_inset
23733
23734  port
23735 \end_layout
23736
23737 \begin_layout Standard
23738 The PIC16 port adds support for Microchip
23739 \begin_inset LatexCommand \index{Microchip}
23740
23741 \end_inset
23742
23743
23744 \begin_inset Formula $^{\text{TM}}$
23745 \end_inset
23746
23747  PIC
23748 \begin_inset LatexCommand \index{PIC}
23749
23750 \end_inset
23751
23752
23753 \begin_inset Formula $^{\text{TM}}$
23754 \end_inset
23755
23756  MCUs with 16 bit wide instructions.
23757  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23758 ; devices supported by the port include:
23759 \end_layout
23760
23761 \begin_layout Standard
23762 18F: 242, 248, 252, 258, 442, 448, 452, 458
23763 \end_layout
23764
23765 \begin_layout Standard
23766 18F: 1220, 1320
23767 \end_layout
23768
23769 \begin_layout Standard
23770 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23771  2620
23772 \end_layout
23773
23774 \begin_layout Standard
23775 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23776  45j10, 4620
23777 \end_layout
23778
23779 \begin_layout Standard
23780 18F: 6520, 6620, 6680, 6720
23781 \end_layout
23782
23783 \begin_layout Standard
23784 18F: 8520, 8620, 8680, 8720
23785 \end_layout
23786
23787 \begin_layout Subsection
23788 Global Options
23789 \end_layout
23790
23791 \begin_layout Standard
23792 PIC16 port supports the standard command line arguments as supposed, with
23793  the exception of certain cases that will be mentioned in the following
23794  list:
23795 \end_layout
23796
23797 \begin_layout Description
23798 -
23799 \begin_inset ERT
23800 status collapsed
23801
23802 \begin_layout Standard
23803
23804
23805 \backslash
23806 /
23807 \end_layout
23808
23809 \end_inset
23810
23811 -callee-saves
23812 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23813
23814 \end_inset
23815
23816  See -
23817 \begin_inset ERT
23818 status collapsed
23819
23820 \begin_layout Standard
23821
23822
23823 \backslash
23824 /
23825 \end_layout
23826
23827 \end_inset
23828
23829 -all-callee-saves
23830 \end_layout
23831
23832 \begin_layout Description
23833 -
23834 \begin_inset ERT
23835 status collapsed
23836
23837 \begin_layout Standard
23838
23839
23840 \backslash
23841 /
23842 \end_layout
23843
23844 \end_inset
23845
23846 -fommit-frame-pointer
23847 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23848
23849 \end_inset
23850
23851  Frame pointer will be omitted when the function uses no local variables.
23852 \end_layout
23853
23854 \begin_layout Subsection
23855 Port Specific Options
23856 \begin_inset LatexCommand \index{Options PIC16}
23857
23858 \end_inset
23859
23860
23861 \end_layout
23862
23863 \begin_layout Standard
23864 The port specific options appear after the global options in the sdcc -
23865 \begin_inset ERT
23866 status collapsed
23867
23868 \begin_layout Standard
23869
23870
23871 \backslash
23872 /
23873 \end_layout
23874
23875 \end_inset
23876
23877 -help output.
23878 \end_layout
23879
23880 \begin_layout Subsubsection
23881 Code Generation Options
23882 \end_layout
23883
23884 \begin_layout Standard
23885 These options influence the generated assembler code.
23886 \end_layout
23887
23888 \begin_layout Description
23889 -
23890 \begin_inset ERT
23891 status collapsed
23892
23893 \begin_layout Standard
23894
23895
23896 \backslash
23897 /
23898 \end_layout
23899
23900 \end_inset
23901
23902 -pstack-model=[model] Used in conjuction with the command above.
23903  Defines the stack model to be used, valid stack models are:
23904 \end_layout
23905
23906 \begin_deeper
23907 \begin_layout List
23908 \labelwidthstring 00.00.0000
23909
23910 \emph on
23911 small
23912 \emph default
23913  Selects small stack model.
23914  8 bit stack and frame pointers.
23915  Supports 256 bytes stack size.
23916 \end_layout
23917
23918 \begin_layout List
23919 \labelwidthstring 00.00.0000
23920
23921 \emph on
23922 large
23923 \emph default
23924  Selects large stack model.
23925  16 bit stack and frame pointers.
23926  Supports 65536 bytes stack size.
23927 \end_layout
23928
23929 \end_deeper
23930 \begin_layout Description
23931 -
23932 \begin_inset ERT
23933 status collapsed
23934
23935 \begin_layout Standard
23936
23937
23938 \backslash
23939 /
23940 \end_layout
23941
23942 \end_inset
23943
23944 -pno-banksel Do not generate BANKSEL assembler directives.
23945 \end_layout
23946
23947 \begin_layout Description
23948 -
23949 \begin_inset ERT
23950 status collapsed
23951
23952 \begin_layout Standard
23953
23954
23955 \backslash
23956 /
23957 \end_layout
23958
23959 \end_inset
23960
23961 -extended Enable extended instruction set/literal offset addressing mode.
23962  Use with care!
23963 \end_layout
23964
23965 \begin_layout Subsubsection
23966 Optimization Options
23967 \end_layout
23968
23969 \begin_layout Description
23970 -
23971 \begin_inset ERT
23972 status collapsed
23973
23974 \begin_layout Standard
23975
23976
23977 \backslash
23978 /
23979 \end_layout
23980
23981 \end_inset
23982
23983 -obanksel=n Set optimization level for inserting BANKSELs.
23984 \newline
23985
23986 \end_layout
23987
23988 \begin_deeper
23989 \begin_layout List
23990 \labelwidthstring 00.00.0000
23991 0 no optimization
23992 \end_layout
23993
23994 \begin_layout List
23995 \labelwidthstring 00.00.0000
23996 1 checks previous used register and if it is the same then does not emit
23997  BANKSEL, accounts only for labels.
23998 \end_layout
23999
24000 \begin_layout List
24001 \labelwidthstring 00.00.0000
24002 2 tries to check the location of (even different) symbols and removes BANKSELs
24003  if they are in the same bank.
24004  
24005 \newline
24006
24007 \emph on
24008 Important: There might be problems if the linker script has data sections
24009  across bank borders!
24010 \end_layout
24011
24012 \end_deeper
24013 \begin_layout Description
24014 -
24015 \begin_inset ERT
24016 status collapsed
24017
24018 \begin_layout Standard
24019
24020
24021 \backslash
24022 /
24023 \end_layout
24024
24025 \end_inset
24026
24027 -denable-peeps Force the usage of peepholes.
24028  Use with care.
24029 \end_layout
24030
24031 \begin_layout Description
24032 -
24033 \begin_inset ERT
24034 status collapsed
24035
24036 \begin_layout Standard
24037
24038
24039 \backslash
24040 /
24041 \end_layout
24042
24043 \end_inset
24044
24045 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24046 \end_layout
24047
24048 \begin_layout Description
24049 -
24050 \begin_inset ERT
24051 status collapsed
24052
24053 \begin_layout Standard
24054
24055
24056 \backslash
24057 /
24058 \end_layout
24059
24060 \end_inset
24061
24062 -optimize-cmp Try to optimize some compares.
24063 \end_layout
24064
24065 \begin_layout Description
24066 -
24067 \begin_inset ERT
24068 status collapsed
24069
24070 \begin_layout Standard
24071
24072
24073 \backslash
24074 /
24075 \end_layout
24076
24077 \end_inset
24078
24079 -optimize-df Analyze the dataflow of the generated code and improve it.
24080 \end_layout
24081
24082 \begin_layout Subsubsection
24083 Assembling Options
24084 \end_layout
24085
24086 \begin_layout Description
24087 -
24088 \begin_inset ERT
24089 status collapsed
24090
24091 \begin_layout Standard
24092
24093
24094 \backslash
24095 /
24096 \end_layout
24097
24098 \end_inset
24099
24100 -asm= Sets the full path and name of an external assembler to call.
24101 \end_layout
24102
24103 \begin_layout Description
24104 -
24105 \begin_inset ERT
24106 status collapsed
24107
24108 \begin_layout Standard
24109
24110
24111 \backslash
24112 /
24113 \end_layout
24114
24115 \end_inset
24116
24117 -mplab-comp MPLAB
24118 \begin_inset LatexCommand \index{PIC16!MPLAB}
24119
24120 \end_inset
24121
24122  compatibility option.
24123  Currently only suppresses special gpasm directives.
24124 \end_layout
24125
24126 \begin_layout Subsubsection
24127 Linking Options
24128 \end_layout
24129
24130 \begin_layout Description
24131 -
24132 \begin_inset ERT
24133 status collapsed
24134
24135 \begin_layout Standard
24136
24137
24138 \backslash
24139 /
24140 \end_layout
24141
24142 \end_inset
24143
24144 -link= Sets the full path and name of an external linker to call.
24145 \end_layout
24146
24147 \begin_layout Description
24148 -
24149 \begin_inset ERT
24150 status collapsed
24151
24152 \begin_layout Standard
24153
24154
24155 \backslash
24156 /
24157 \end_layout
24158
24159 \end_inset
24160
24161 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24162  unitialized data variables with [kword].
24163  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24164 \end_layout
24165
24166 \begin_layout Description
24167 -
24168 \begin_inset ERT
24169 status collapsed
24170
24171 \begin_layout Standard
24172
24173
24174 \backslash
24175 /
24176 \end_layout
24177
24178 \end_inset
24179
24180 -ivt-loc=n Place the interrupt vector table at address 
24181 \emph on
24182 n
24183 \emph default
24184 .
24185  Useful for bootloaders.
24186 \end_layout
24187
24188 \begin_layout Description
24189 -
24190 \begin_inset ERT
24191 status collapsed
24192
24193 \begin_layout Standard
24194
24195
24196 \backslash
24197 /
24198 \end_layout
24199
24200 \end_inset
24201
24202 -nodefaultlibs Do not link default libraries when linking.
24203 \end_layout
24204
24205 \begin_layout Description
24206 -
24207 \begin_inset ERT
24208 status collapsed
24209
24210 \begin_layout Standard
24211
24212
24213 \backslash
24214 /
24215 \end_layout
24216
24217 \end_inset
24218
24219 -use-crt= Use a custom run-time module instead of the defaults.
24220 \end_layout
24221
24222 \begin_layout Description
24223 -
24224 \begin_inset ERT
24225 status collapsed
24226
24227 \begin_layout Standard
24228
24229
24230 \backslash
24231 /
24232 \end_layout
24233
24234 \end_inset
24235
24236 -no-crt Don't link the default run-time modules
24237 \end_layout
24238
24239 \begin_layout Subsubsection
24240 Debugging Options
24241 \end_layout
24242
24243 \begin_layout Standard
24244 Debugging options enable extra debugging information in the output files.
24245 \end_layout
24246
24247 \begin_layout Description
24248 -
24249 \begin_inset ERT
24250 status collapsed
24251
24252 \begin_layout Standard
24253
24254
24255 \backslash
24256 /
24257 \end_layout
24258
24259 \end_inset
24260
24261 -debug-xtra Similar to -
24262 \begin_inset ERT
24263 status collapsed
24264
24265 \begin_layout Standard
24266
24267
24268 \backslash
24269 /
24270 \end_layout
24271
24272 \end_inset
24273
24274 -debug
24275 \begin_inset LatexCommand \index{-\/-debug}
24276
24277 \end_inset
24278
24279 , but dumps more information.
24280 \end_layout
24281
24282 \begin_layout Description
24283 -
24284 \begin_inset ERT
24285 status collapsed
24286
24287 \begin_layout Standard
24288
24289
24290 \backslash
24291 /
24292 \end_layout
24293
24294 \end_inset
24295
24296 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24297  information.
24298  <source> is the name of the file being compiled.
24299 \end_layout
24300
24301 \begin_layout Description
24302 -
24303 \begin_inset ERT
24304 status collapsed
24305
24306 \begin_layout Standard
24307
24308
24309 \backslash
24310 /
24311 \end_layout
24312
24313 \end_inset
24314
24315 -pcode-verbose Enable pcode debugging information in translation.
24316 \end_layout
24317
24318 \begin_layout Description
24319 -
24320 \begin_inset ERT
24321 status collapsed
24322
24323 \begin_layout Standard
24324
24325
24326 \backslash
24327 /
24328 \end_layout
24329
24330 \end_inset
24331
24332 -calltree Dump call tree in .calltree file.
24333 \end_layout
24334
24335 \begin_layout Description
24336 -
24337 \begin_inset ERT
24338 status collapsed
24339
24340 \begin_layout Standard
24341
24342
24343 \backslash
24344 /
24345 \end_layout
24346
24347 \end_inset
24348
24349 -gstack Trace push/pops for stack pointer overflow.
24350 \end_layout
24351
24352 \begin_layout Subsection
24353 Enviroment Variables
24354 \end_layout
24355
24356 \begin_layout Standard
24357 There is a number of enviromental variables that can be used when running
24358  SDCC to enable certain optimizations or force a specific program behaviour.
24359  these variables are primarily for debugging purposes so they can be enabled/dis
24360 abled at will.
24361 \end_layout
24362
24363 \begin_layout Standard
24364 Currently there is only two such variables available:
24365 \end_layout
24366
24367 \begin_layout Description
24368 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24369  bitfields is optimized by directly loading FSR0 with the address of the
24370  bitfield structure.
24371  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24372  then load FSR0.
24373  This step saves data ram and code space for functions that make heavy use
24374  of bitfields.
24375  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24376  option).
24377  
24378 \end_layout
24379
24380 \begin_layout Description
24381 NO_REG_OPT Do not perform pCode registers optimization.
24382  This should be used for debugging purposes.
24383  If bugs in the pcode optimizer are found, users can benefit from temporarily
24384  disabling the optimizer until the bug is fixed.
24385 \end_layout
24386
24387 \begin_layout Subsection
24388 Preprocessor Macros
24389 \end_layout
24390
24391 \begin_layout Standard
24392 PIC16
24393 \begin_inset LatexCommand \index{PIC16}
24394
24395 \end_inset
24396
24397  port defines the following preprocessor macros while translating a source.
24398 \end_layout
24399
24400 \begin_layout Standard
24401 \align center
24402 \begin_inset Tabular
24403 <lyxtabular version="3" rows="6" columns="2">
24404 <features>
24405 <column alignment="center" valignment="top" leftline="true" width="0">
24406 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24407 <row topline="true" bottomline="true">
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24409 \begin_inset Text
24410
24411 \begin_layout Standard
24412 Macro
24413 \end_layout
24414
24415 \end_inset
24416 </cell>
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24418 \begin_inset Text
24419
24420 \begin_layout Standard
24421 Description
24422 \end_layout
24423
24424 \end_inset
24425 </cell>
24426 </row>
24427 <row topline="true">
24428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24429 \begin_inset Text
24430
24431 \begin_layout Standard
24432 SDCC_pic16
24433 \end_layout
24434
24435 \end_inset
24436 </cell>
24437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24438 \begin_inset Text
24439
24440 \begin_layout Standard
24441 Port identification
24442 \end_layout
24443
24444 \end_inset
24445 </cell>
24446 </row>
24447 <row topline="true">
24448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24449 \begin_inset Text
24450
24451 \begin_layout Standard
24452 _
24453 \begin_inset ERT
24454 status collapsed
24455
24456 \begin_layout Standard
24457
24458
24459 \backslash
24460 /
24461 \end_layout
24462
24463 \end_inset
24464
24465 _pic16
24466 \end_layout
24467
24468 \end_inset
24469 </cell>
24470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24471 \begin_inset Text
24472
24473 \begin_layout Standard
24474 Port identification (same as above)
24475 \end_layout
24476
24477 \end_inset
24478 </cell>
24479 </row>
24480 <row topline="true">
24481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24482 \begin_inset Text
24483
24484 \begin_layout Standard
24485 pic18fxxxx
24486 \end_layout
24487
24488 \end_inset
24489 </cell>
24490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24491 \begin_inset Text
24492
24493 \begin_layout Standard
24494 MCU Identification.
24495  
24496 \emph on
24497 xxxx
24498 \emph default
24499  is the microcontrol identification number, i.e.
24500  452, 6620, etc
24501 \end_layout
24502
24503 \end_inset
24504 </cell>
24505 </row>
24506 <row topline="true">
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24508 \begin_inset Text
24509
24510 \begin_layout Standard
24511 _
24512 \begin_inset ERT
24513 status collapsed
24514
24515 \begin_layout Standard
24516
24517
24518 \backslash
24519 /
24520 \end_layout
24521
24522 \end_inset
24523
24524 _18Fxxxx
24525 \end_layout
24526
24527 \end_inset
24528 </cell>
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24530 \begin_inset Text
24531
24532 \begin_layout Standard
24533 MCU Identification (same as above)
24534 \end_layout
24535
24536 \end_inset
24537 </cell>
24538 </row>
24539 <row topline="true" bottomline="true">
24540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24541 \begin_inset Text
24542
24543 \begin_layout Standard
24544 STACK_MODEL_nnn
24545 \end_layout
24546
24547 \end_inset
24548 </cell>
24549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24550 \begin_inset Text
24551
24552 \begin_layout Standard
24553 nnn = SMALL or LARGE respectively according to the stack model used
24554 \end_layout
24555
24556 \end_inset
24557 </cell>
24558 </row>
24559 </lyxtabular>
24560
24561 \end_inset
24562
24563
24564 \end_layout
24565
24566 \begin_layout Standard
24567 In addition the following macros are defined when calling assembler:
24568 \end_layout
24569
24570 \begin_layout Standard
24571 \align center
24572 \begin_inset Tabular
24573 <lyxtabular version="3" rows="4" columns="2">
24574 <features>
24575 <column alignment="center" valignment="top" leftline="true" width="0">
24576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24577 <row topline="true" bottomline="true">
24578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24579 \begin_inset Text
24580
24581 \begin_layout Standard
24582 Macro
24583 \end_layout
24584
24585 \end_inset
24586 </cell>
24587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24588 \begin_inset Text
24589
24590 \begin_layout Standard
24591 Description
24592 \end_layout
24593
24594 \end_inset
24595 </cell>
24596 </row>
24597 <row topline="true">
24598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24599 \begin_inset Text
24600
24601 \begin_layout Standard
24602 __18Fxxxx
24603 \end_layout
24604
24605 \end_inset
24606 </cell>
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \begin_layout Standard
24611 MCU Identification.
24612  
24613 \emph on
24614 xxxx
24615 \emph default
24616  is the microcontrol identification number, i.e.
24617  452, 6620, etc
24618 \end_layout
24619
24620 \end_inset
24621 </cell>
24622 </row>
24623 <row topline="true">
24624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24625 \begin_inset Text
24626
24627 \begin_layout Standard
24628 SDCC_MODEL_nnn
24629 \end_layout
24630
24631 \end_inset
24632 </cell>
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24634 \begin_inset Text
24635
24636 \begin_layout Standard
24637 nnn = SMALL or LARGE respectively according to the memory model used for
24638  SDCC
24639 \end_layout
24640
24641 \end_inset
24642 </cell>
24643 </row>
24644 <row topline="true" bottomline="true">
24645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24646 \begin_inset Text
24647
24648 \begin_layout Standard
24649 STACK_MODEL_nnn
24650 \end_layout
24651
24652 \end_inset
24653 </cell>
24654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24655 \begin_inset Text
24656
24657 \begin_layout Standard
24658 nnn = SMALL or LARGE respectively according to the stack model used
24659 \end_layout
24660
24661 \end_inset
24662 </cell>
24663 </row>
24664 </lyxtabular>
24665
24666 \end_inset
24667
24668
24669 \end_layout
24670
24671 \begin_layout Subsection
24672 Directories
24673 \end_layout
24674
24675 \begin_layout Standard
24676 PIC16
24677 \begin_inset LatexCommand \index{PIC16}
24678
24679 \end_inset
24680
24681  port uses the following directories for searching header files and libraries.
24682 \end_layout
24683
24684 \begin_layout Standard
24685 \align center
24686 \begin_inset Tabular
24687 <lyxtabular version="3" rows="3" columns="4">
24688 <features>
24689 <column alignment="center" valignment="top" leftline="true" width="0">
24690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24691 <column alignment="center" valignment="top" width="0">
24692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24693 <row topline="true" bottomline="true">
24694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24695 \begin_inset Text
24696
24697 \begin_layout Standard
24698 Directory
24699 \end_layout
24700
24701 \end_inset
24702 </cell>
24703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24704 \begin_inset Text
24705
24706 \begin_layout Standard
24707 Description
24708 \end_layout
24709
24710 \end_inset
24711 </cell>
24712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24713 \begin_inset Text
24714
24715 \begin_layout Standard
24716 Target
24717 \end_layout
24718
24719 \end_inset
24720 </cell>
24721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24722 \begin_inset Text
24723
24724 \begin_layout Standard
24725 Command prefix
24726 \end_layout
24727
24728 \end_inset
24729 </cell>
24730 </row>
24731 <row topline="true">
24732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24733 \begin_inset Text
24734
24735 \begin_layout Standard
24736 PREFIX/sdcc/include/pic16
24737 \end_layout
24738
24739 \end_inset
24740 </cell>
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24742 \begin_inset Text
24743
24744 \begin_layout Standard
24745 PIC16 specific headers
24746 \end_layout
24747
24748 \end_inset
24749 </cell>
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24751 \begin_inset Text
24752
24753 \begin_layout Standard
24754 Compiler
24755 \end_layout
24756
24757 \end_inset
24758 </cell>
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24760 \begin_inset Text
24761
24762 \begin_layout Standard
24763 -I
24764 \end_layout
24765
24766 \end_inset
24767 </cell>
24768 </row>
24769 <row topline="true" bottomline="true">
24770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24771 \begin_inset Text
24772
24773 \begin_layout Standard
24774 PREFIX/sdcc/lib/pic16
24775 \end_layout
24776
24777 \end_inset
24778 </cell>
24779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24780 \begin_inset Text
24781
24782 \begin_layout Standard
24783 PIC16 specific libraries
24784 \end_layout
24785
24786 \end_inset
24787 </cell>
24788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24789 \begin_inset Text
24790
24791 \begin_layout Standard
24792 Linker
24793 \end_layout
24794
24795 \end_inset
24796 </cell>
24797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24798 \begin_inset Text
24799
24800 \begin_layout Standard
24801 -L
24802 \end_layout
24803
24804 \end_inset
24805 </cell>
24806 </row>
24807 </lyxtabular>
24808
24809 \end_inset
24810
24811
24812 \end_layout
24813
24814 \begin_layout Subsection
24815 Pragmas
24816 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24817
24818 \end_inset
24819
24820
24821 \end_layout
24822
24823 \begin_layout Standard
24824 The PIC16
24825 \begin_inset LatexCommand \index{PIC16}
24826
24827 \end_inset
24828
24829  port currently supports the following pragmas:
24830 \end_layout
24831
24832 \begin_layout Description
24833 stack
24834 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24835
24836 \end_inset
24837
24838  This forces the code generator to initialize the stack & frame pointers
24839  at a specific address.
24840  This is an ad hoc solution for cases where no STACK directive is available
24841  in the linker script or gplink is not instructed to create a stack section.
24842 \newline
24843 The
24844  stack pragma should be used only once in a project.
24845  Multiple pragmas may result in indeterminate behaviour of the program.
24846 \begin_inset Foot
24847 status open
24848
24849 \begin_layout Standard
24850 The old format (ie.
24851  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24852  cross page boundaries (or even exceed the available data RAM) and crash
24853  the program.
24854  Make sure that stack does not cross page boundaries when using the SMALL
24855  stack model.
24856 \end_layout
24857
24858 \end_inset
24859
24860
24861 \newline
24862 The format is as follows:
24863 \newline
24864
24865 \end_layout
24866
24867 \begin_layout LyX-Code
24868 #pragma stack bottom_address [stack_size]
24869 \newline
24870
24871 \end_layout
24872
24873 \begin_layout Standard
24874
24875 \emph on
24876 bottom_address
24877 \emph default
24878  is the lower bound of the stack section.
24879  The stack pointer initially will point at address (bottom_address+stack_size-1).
24880 \end_layout
24881
24882 \begin_layout LyX-Code
24883 Example:
24884 \end_layout
24885
24886 \begin_layout LyX-Code
24887
24888 \end_layout
24889
24890 \begin_layout LyX-Code
24891 /* initializes stack of 100 bytes at RAM address 0x200 */
24892 \end_layout
24893
24894 \begin_layout LyX-Code
24895 #pragma stack 0x200 100
24896 \end_layout
24897
24898 \begin_layout Standard
24899 If the stack_size field is omitted then a stack is created with the default
24900  size of 64.
24901  This size might be enough for most programs, but its not enough for operations
24902  with deep function nesting or excessive stack usage.
24903 \end_layout
24904
24905 \begin_layout Description
24906 code
24907 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24908
24909 \end_inset
24910
24911  Force a function to a static FLASH address.
24912 \end_layout
24913
24914 \begin_layout LyX-Code
24915 Example:
24916 \end_layout
24917
24918 \begin_layout LyX-Code
24919
24920 \end_layout
24921
24922 \begin_layout LyX-Code
24923 /* place function test_func at 0x4000 */
24924 \end_layout
24925
24926 \begin_layout LyX-Code
24927 #pragma code test_func 0x4000
24928 \end_layout
24929
24930 \begin_layout LyX-Code
24931
24932 \end_layout
24933
24934 \begin_layout Description
24935 library instructs the linker to use a library module.
24936 \newline
24937 Usage:
24938 \end_layout
24939
24940 \begin_layout LyX-Code
24941 #pragma library module_name
24942 \end_layout
24943
24944 \begin_layout Standard
24945
24946 \emph on
24947 module_name
24948 \emph default
24949  can be any library or object file (including its path).
24950  Note that there are four reserved keywords which have special meaning.
24951  These are:
24952 \end_layout
24953
24954 \begin_layout Standard
24955 \align center
24956 \begin_inset Tabular
24957 <lyxtabular version="3" rows="6" columns="3">
24958 <features>
24959 <column alignment="center" valignment="top" leftline="true" width="0">
24960 <column alignment="block" valignment="top" leftline="true" width="20page%">
24961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24962 <row topline="true" bottomline="true">
24963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24964 \begin_inset Text
24965
24966 \begin_layout Standard
24967 Keyword
24968 \end_layout
24969
24970 \end_inset
24971 </cell>
24972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24973 \begin_inset Text
24974
24975 \begin_layout Standard
24976 Description
24977 \end_layout
24978
24979 \end_inset
24980 </cell>
24981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24982 \begin_inset Text
24983
24984 \begin_layout Standard
24985 Module to link
24986 \end_layout
24987
24988 \end_inset
24989 </cell>
24990 </row>
24991 <row topline="true">
24992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24993 \begin_inset Text
24994
24995 \begin_layout Standard
24996
24997 \series bold
24998 ignore
24999 \end_layout
25000
25001 \end_inset
25002 </cell>
25003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25004 \begin_inset Text
25005
25006 \begin_layout Standard
25007 ignore all library pragmas
25008 \end_layout
25009
25010 \end_inset
25011 </cell>
25012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25013 \begin_inset Text
25014
25015 \begin_layout Standard
25016
25017 \emph on
25018 (none)
25019 \end_layout
25020
25021 \end_inset
25022 </cell>
25023 </row>
25024 <row topline="true">
25025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25026 \begin_inset Text
25027
25028 \begin_layout Standard
25029
25030 \series bold
25031 c
25032 \end_layout
25033
25034 \end_inset
25035 </cell>
25036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25037 \begin_inset Text
25038
25039 \begin_layout Standard
25040 link the C library
25041 \end_layout
25042
25043 \end_inset
25044 </cell>
25045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25046 \begin_inset Text
25047
25048 \begin_layout Standard
25049
25050 \emph on
25051 libc18f
25052 \emph default
25053 .lib
25054 \end_layout
25055
25056 \end_inset
25057 </cell>
25058 </row>
25059 <row topline="true">
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25061 \begin_inset Text
25062
25063 \begin_layout Standard
25064
25065 \series bold
25066 math
25067 \end_layout
25068
25069 \end_inset
25070 </cell>
25071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25072 \begin_inset Text
25073
25074 \begin_layout Standard
25075 link the Math libarary
25076 \end_layout
25077
25078 \end_inset
25079 </cell>
25080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25081 \begin_inset Text
25082
25083 \begin_layout Standard
25084
25085 \emph on
25086 libm18f
25087 \emph default
25088 .lib
25089 \end_layout
25090
25091 \end_inset
25092 </cell>
25093 </row>
25094 <row topline="true">
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25096 \begin_inset Text
25097
25098 \begin_layout Standard
25099
25100 \series bold
25101 io
25102 \end_layout
25103
25104 \end_inset
25105 </cell>
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25107 \begin_inset Text
25108
25109 \begin_layout Standard
25110 link the I/O library
25111 \end_layout
25112
25113 \end_inset
25114 </cell>
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25116 \begin_inset Text
25117
25118 \begin_layout Standard
25119
25120 \emph on
25121 libio18f*
25122 \emph default
25123 .lib
25124 \end_layout
25125
25126 \end_inset
25127 </cell>
25128 </row>
25129 <row topline="true" bottomline="true">
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25131 \begin_inset Text
25132
25133 \begin_layout Standard
25134
25135 \series bold
25136 debug
25137 \end_layout
25138
25139 \end_inset
25140 </cell>
25141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25142 \begin_inset Text
25143
25144 \begin_layout Standard
25145 link the debug library
25146 \end_layout
25147
25148 \end_inset
25149 </cell>
25150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25151 \begin_inset Text
25152
25153 \begin_layout Standard
25154
25155 \emph on
25156 libdebug
25157 \emph default
25158 .lib
25159 \end_layout
25160
25161 \end_inset
25162 </cell>
25163 </row>
25164 </lyxtabular>
25165
25166 \end_inset
25167
25168
25169 \newline
25170 * is the device number, i.e.
25171  452 for PIC18F452 MCU.
25172 \end_layout
25173
25174 \begin_layout Standard
25175 This feature allows for linking with specific libraries withoug having to
25176  explicit name them in the command line.
25177  Note that the 
25178 \noun on
25179 ignore
25180 \noun default
25181  keyword will reject all modules specified by the library pragma.
25182 \end_layout
25183
25184 \begin_layout Description
25185 udata The pragma udata instructs the compiler to emit code so that linker
25186  will place a variable at a specific memory bank.
25187 \end_layout
25188
25189 \begin_layout LyX-Code
25190 Example:
25191 \end_layout
25192
25193 \begin_layout LyX-Code
25194
25195 \end_layout
25196
25197 \begin_layout LyX-Code
25198 /* places variable foo at bank2 */
25199 \end_layout
25200
25201 \begin_layout LyX-Code
25202 #pragma udata bank2 foo
25203 \end_layout
25204
25205 \begin_layout LyX-Code
25206 char foo;
25207 \end_layout
25208
25209 \begin_layout Standard
25210 In order for this pragma to work extra SECTION directives should be added
25211  in the .lkr script.
25212  In the following example a sample .lkr file is shown:
25213 \end_layout
25214
25215 \begin_layout LyX-Code
25216
25217 \end_layout
25218
25219 \begin_layout LyX-Code
25220 // Sample linker script for the PIC18F452 processor
25221 \end_layout
25222
25223 \begin_layout LyX-Code
25224 LIBPATH .
25225 \end_layout
25226
25227 \begin_layout LyX-Code
25228 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25229 \end_layout
25230
25231 \begin_layout LyX-Code
25232 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25233 \end_layout
25234
25235 \begin_layout LyX-Code
25236 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25237 \end_layout
25238
25239 \begin_layout LyX-Code
25240 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25241 \end_layout
25242
25243 \begin_layout LyX-Code
25244 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25245 \end_layout
25246
25247 \begin_layout LyX-Code
25248 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25249 \end_layout
25250
25251 \begin_layout LyX-Code
25252 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25253 \end_layout
25254
25255 \begin_layout LyX-Code
25256
25257 \end_layout
25258
25259 \begin_layout LyX-Code
25260 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25261 \end_layout
25262
25263 \begin_layout LyX-Code
25264 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25265 \end_layout
25266
25267 \begin_layout LyX-Code
25268 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25269 \end_layout
25270
25271 \begin_layout LyX-Code
25272 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25273 \end_layout
25274
25275 \begin_layout LyX-Code
25276 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25277 \end_layout
25278
25279 \begin_layout LyX-Code
25280 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25281 \end_layout
25282
25283 \begin_layout LyX-Code
25284 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25285 \end_layout
25286
25287 \begin_layout LyX-Code
25288
25289 \end_layout
25290
25291 \begin_layout LyX-Code
25292 SECTION    NAME=CONFIG     ROM=config
25293 \end_layout
25294
25295 \begin_layout LyX-Code
25296
25297 \end_layout
25298
25299 \begin_layout LyX-Code
25300 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25301 \end_layout
25302
25303 \begin_layout LyX-Code
25304 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25305 \end_layout
25306
25307 \begin_layout LyX-Code
25308 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25309 \end_layout
25310
25311 \begin_layout LyX-Code
25312 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25313 \end_layout
25314
25315 \begin_layout LyX-Code
25316 SECTION    NAME=bank4      RAM=gpr4
25317 \end_layout
25318
25319 \begin_layout LyX-Code
25320 SECTION    NAME=bank5      RAM=gpr5
25321 \end_layout
25322
25323 \begin_layout Standard
25324 The linker will recognise the section name set in the pragma statement and
25325  will position the variable at the memory bank set with the RAM field at
25326  the SECTION line in the linker script file.
25327 \end_layout
25328
25329 \begin_layout Subsection
25330 Header Files
25331 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25332
25333 \end_inset
25334
25335
25336 \end_layout
25337
25338 \begin_layout Standard
25339 There is one main header file
25340 \begin_inset LatexCommand \index{PIC16!Header files}
25341
25342 \end_inset
25343
25344  that can be included to the source files using the pic16
25345 \begin_inset LatexCommand \index{PIC16}
25346
25347 \end_inset
25348
25349  port.
25350  That file is the 
25351 \series bold
25352 pic18fregs.h
25353 \series default
25354 .
25355  This header file contains the definitions for the processor special registers,
25356  so it is necessary if the source accesses them.
25357  It can be included by adding the following line in the beginning of the
25358  file:
25359 \end_layout
25360
25361 \begin_layout LyX-Code
25362 #include <pic18fregs.h>
25363 \end_layout
25364
25365 \begin_layout Standard
25366 The specific microcontroller is selected within the pic18fregs.h automatically,
25367  so the same source can be used with a variety of devices.
25368 \end_layout
25369
25370 \begin_layout Subsection
25371 Libraries
25372 \end_layout
25373
25374 \begin_layout Standard
25375 The libraries
25376 \begin_inset LatexCommand \index{PIC16!Libraries}
25377
25378 \end_inset
25379
25380  that PIC16
25381 \begin_inset LatexCommand \index{PIC16}
25382
25383 \end_inset
25384
25385  port depends on are the microcontroller device libraries which contain
25386  the symbol definitions for the microcontroller special function registers.
25387  These libraries have the format pic18fxxxx.lib, where 
25388 \emph on
25389 xxxx
25390 \emph default
25391  is the microcontroller identification number.
25392  The specific library is selected automatically by the compiler at link
25393  stage according to the selected device.
25394 \end_layout
25395
25396 \begin_layout Standard
25397 Libraries are created with gplib which is part of the gputils package 
25398 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25399
25400 \end_inset
25401
25402 .
25403 \end_layout
25404
25405 \begin_layout Subsubsection*
25406 Building the libraries
25407 \end_layout
25408
25409 \begin_layout Standard
25410 Before using SDCC/pic16 there are some libraries that need to be compiled.
25411  This process is not done automatically by SDCC since not all users use
25412  SDCC for pic16 projects.
25413  So each user should compile the libraries separately.
25414 \end_layout
25415
25416 \begin_layout Standard
25417 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25418 \end_layout
25419
25420 \begin_layout LyX-Code
25421 cd device/lib/pic16
25422 \end_layout
25423
25424 \begin_layout LyX-Code
25425 ./configure
25426 \end_layout
25427
25428 \begin_layout LyX-Code
25429 make
25430 \end_layout
25431
25432 \begin_layout LyX-Code
25433 cd ..
25434 \end_layout
25435
25436 \begin_layout LyX-Code
25437 make model-pic16
25438 \end_layout
25439
25440 \begin_layout LyX-Code
25441 su -c 'make install'     # install the libraries, you need the root password
25442 \end_layout
25443
25444 \begin_layout Standard
25445 If you need to install the headers too, do:
25446 \end_layout
25447
25448 \begin_layout LyX-Code
25449 cd device/include
25450 \end_layout
25451
25452 \begin_layout LyX-Code
25453 su -c 'make install'     # install the headers, you need the root password
25454 \end_layout
25455
25456 \begin_layout Standard
25457 There exist a special target to build the I/O libraries.
25458  This target is not automatically build because it will build the I/O library
25459  for 
25460 \emph on
25461 every
25462 \emph default
25463  supported device.
25464  This way building will take quite a lot of time.
25465  Users are advised to edit the 
25466 \series bold
25467 device/lib/pic16/pics.build
25468 \series default
25469  file and then execute:
25470 \end_layout
25471
25472 \begin_layout LyX-Code
25473 make lib-io
25474 \end_layout
25475
25476 \begin_layout Subsection
25477 Adding New Devices to the Port
25478 \end_layout
25479
25480 \begin_layout Standard
25481 Adding support for a new 16
25482 \begin_inset ERT
25483 status open
25484
25485 \begin_layout Standard
25486
25487
25488 \backslash
25489 ,
25490 \end_layout
25491
25492 \end_inset
25493
25494 bit PIC MCU requires the following steps:
25495 \end_layout
25496
25497 \begin_layout Enumerate
25498 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25499 \newline
25500
25501 \family typewriter
25502 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25503 inc
25504 \end_layout
25505
25506 \begin_layout Enumerate
25507
25508 \family typewriter
25509 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25510 \end_layout
25511
25512 \begin_layout Enumerate
25513
25514 \family typewriter
25515 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25516 \end_layout
25517
25518 \begin_layout Enumerate
25519 Add DEVICE to 
25520 \family typewriter
25521 /path/to/sdcc/device/lib/pics.all
25522 \family default
25523  (and 
25524 \family typewriter
25525 .build
25526 \family default
25527 ).
25528 \newline
25529 Note: No 18f prefix here!
25530 \end_layout
25531
25532 \begin_layout Enumerate
25533 Adjust 
25534 \family typewriter
25535 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25536 \family default
25537
25538 \newline
25539 Add your DEVICE if it does not compile in 
25540 \family typewriter
25541 adc
25542 \family default
25543
25544 \family typewriter
25545 i2c
25546 \family default
25547 , or 
25548 \family typewriter
25549 usart
25550 \family default
25551 .
25552 \end_layout
25553
25554 \begin_layout Enumerate
25555 Edit 
25556 \family typewriter
25557 /path/to/sdcc/device/include/pic16/pic18fregs.h
25558 \family default
25559 .
25560  The file format is self-explanatory, just add
25561 \newline
25562
25563 \family typewriter
25564 #elif defined(picDEVICE)
25565 \newline
25566 # include <picDEVICE.h>
25567 \family default
25568
25569 \newline
25570 at the right place (keep it sorted).
25571 \end_layout
25572
25573 \begin_layout Enumerate
25574 Edit 
25575 \family typewriter
25576 /path/to/sdcc/src/pic16/devices.inc
25577 \family default
25578 .
25579  Copy and modify an existing entry and insert it at the correct place (keep
25580  the file sorted).
25581  The file is hardly documented, look at the entries for the 18f2221...
25582 \end_layout
25583
25584 \begin_layout Enumerate
25585 Recompile SDCC, including the pic16 libraries.
25586 \end_layout
25587
25588 \begin_layout Subsection
25589 Memory Models
25590 \end_layout
25591
25592 \begin_layout Standard
25593 The following memory models are supported by the PIC16 port:
25594 \end_layout
25595
25596 \begin_layout Itemize
25597 small model
25598 \end_layout
25599
25600 \begin_layout Itemize
25601 large model
25602 \end_layout
25603
25604 \begin_layout Standard
25605 Memory model affects the default size of pointers within the source.
25606  The sizes are shown in the next table:
25607 \end_layout
25608
25609 \begin_layout Standard
25610 \align center
25611 \begin_inset Tabular
25612 <lyxtabular version="3" rows="3" columns="3">
25613 <features>
25614 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25615 <column alignment="center" valignment="top" leftline="true" width="0">
25616 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25617 <row topline="true" bottomline="true">
25618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25619 \begin_inset Text
25620
25621 \begin_layout Standard
25622 Pointer sizes according to memory model
25623 \end_layout
25624
25625 \end_inset
25626 </cell>
25627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25628 \begin_inset Text
25629
25630 \begin_layout Standard
25631 small model
25632 \end_layout
25633
25634 \end_inset
25635 </cell>
25636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25637 \begin_inset Text
25638
25639 \begin_layout Standard
25640 large model
25641 \end_layout
25642
25643 \end_inset
25644 </cell>
25645 </row>
25646 <row topline="true" bottomline="true">
25647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25648 \begin_inset Text
25649
25650 \begin_layout Standard
25651 code pointers
25652 \end_layout
25653
25654 \end_inset
25655 </cell>
25656 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25657 \begin_inset Text
25658
25659 \begin_layout Standard
25660 16-bits
25661 \end_layout
25662
25663 \end_inset
25664 </cell>
25665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25666 \begin_inset Text
25667
25668 \begin_layout Standard
25669 24-bits
25670 \end_layout
25671
25672 \end_inset
25673 </cell>
25674 </row>
25675 <row topline="true" bottomline="true">
25676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25677 \begin_inset Text
25678
25679 \begin_layout Standard
25680 data pointers
25681 \end_layout
25682
25683 \end_inset
25684 </cell>
25685 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25686 \begin_inset Text
25687
25688 \begin_layout Standard
25689 16-bits
25690 \end_layout
25691
25692 \end_inset
25693 </cell>
25694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25695 \begin_inset Text
25696
25697 \begin_layout Standard
25698 16-bits
25699 \end_layout
25700
25701 \end_inset
25702 </cell>
25703 </row>
25704 </lyxtabular>
25705
25706 \end_inset
25707
25708
25709 \end_layout
25710
25711 \begin_layout Standard
25712 It is advisable that all sources within a project are compiled with the
25713  same memory model.
25714  If one wants to override the default memory model, this can be done by
25715  declaring a pointer as 
25716 \series bold
25717 far
25718 \series default
25719  or 
25720 \series bold
25721 near
25722 \series default
25723 .
25724  Far selects large memory model's pointers, while near selects small memory
25725  model's pointers.
25726 \end_layout
25727
25728 \begin_layout Standard
25729 The standard device libraries (see 
25730 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25731
25732 \end_inset
25733
25734 ) contain no reference to pointers, so they can be used with both memory
25735  models.
25736 \end_layout
25737
25738 \begin_layout Subsection
25739 Stack
25740 \end_layout
25741
25742 \begin_layout Standard
25743 The stack
25744 \begin_inset LatexCommand \index{PIC16!stack}
25745
25746 \end_inset
25747
25748  implementation for the PIC16 port uses two indirect registers, FSR1 and
25749  FSR2.
25750 \end_layout
25751
25752 \begin_layout Description
25753 FSR1 is assigned as stack pointer
25754 \end_layout
25755
25756 \begin_layout Description
25757 FSR2 is assigned as frame pointer
25758 \end_layout
25759
25760 \begin_layout Standard
25761 The following stack models are supported by the PIC16 port
25762 \end_layout
25763
25764 \begin_layout Itemize
25765
25766 \noun on
25767 small
25768 \noun default
25769  model
25770 \end_layout
25771
25772 \begin_layout Itemize
25773
25774 \noun on
25775 large
25776 \noun default
25777  model
25778 \end_layout
25779
25780 \begin_layout Standard
25781
25782 \noun on
25783 Small
25784 \noun default
25785  model means that only the FSRxL byte is used to access stack and frame,
25786  while 
25787 \emph on
25788 \noun on
25789 large
25790 \emph default
25791 \noun default
25792  uses both FSRxL and FSRxH registers.
25793  The following table shows the stack/frame pointers sizes according to stack
25794  model and the maximum space they can address:
25795 \end_layout
25796
25797 \begin_layout Standard
25798 \align center
25799 \begin_inset Tabular
25800 <lyxtabular version="3" rows="3" columns="3">
25801 <features>
25802 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25803 <column alignment="center" valignment="top" leftline="true" width="0">
25804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25805 <row topline="true" bottomline="true">
25806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25807 \begin_inset Text
25808
25809 \begin_layout Standard
25810 Stack & Frame pointer sizes according to stack model
25811 \end_layout
25812
25813 \end_inset
25814 </cell>
25815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25816 \begin_inset Text
25817
25818 \begin_layout Standard
25819 small
25820 \end_layout
25821
25822 \end_inset
25823 </cell>
25824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25825 \begin_inset Text
25826
25827 \begin_layout Standard
25828 large
25829 \end_layout
25830
25831 \end_inset
25832 </cell>
25833 </row>
25834 <row topline="true">
25835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25836 \begin_inset Text
25837
25838 \begin_layout Standard
25839 Stack pointer FSR1
25840 \end_layout
25841
25842 \end_inset
25843 </cell>
25844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25845 \begin_inset Text
25846
25847 \begin_layout Standard
25848 8-bits
25849 \end_layout
25850
25851 \end_inset
25852 </cell>
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25854 \begin_inset Text
25855
25856 \begin_layout Standard
25857 16-bits
25858 \end_layout
25859
25860 \end_inset
25861 </cell>
25862 </row>
25863 <row topline="true" bottomline="true">
25864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25865 \begin_inset Text
25866
25867 \begin_layout Standard
25868 Frame pointer FSR2
25869 \end_layout
25870
25871 \end_inset
25872 </cell>
25873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25874 \begin_inset Text
25875
25876 \begin_layout Standard
25877 8-bits
25878 \end_layout
25879
25880 \end_inset
25881 </cell>
25882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25883 \begin_inset Text
25884
25885 \begin_layout Standard
25886 16-bits
25887 \end_layout
25888
25889 \end_inset
25890 </cell>
25891 </row>
25892 </lyxtabular>
25893
25894 \end_inset
25895
25896
25897 \end_layout
25898
25899 \begin_layout Standard
25900
25901 \noun on
25902 Large 
25903 \noun default
25904 stack model is currently not working properly throughout the code generator.
25905  So its use is not advised.
25906  Also there are some other points that need special care:
25907 \newline
25908
25909 \end_layout
25910
25911 \begin_layout Enumerate
25912 Do not create stack sections with size more than one physical bank (that
25913  is 256 bytes)
25914 \end_layout
25915
25916 \begin_layout Enumerate
25917 Stack sections should no cross physical bank limits (i.e.
25918  #pragma stack 0x50 0x100)
25919 \end_layout
25920
25921 \begin_layout Standard
25922 These limitations are caused by the fact that only FSRxL is modified when
25923  using SMALL stack model, so no more than 256 bytes of stack can be used.
25924  This problem will disappear after LARGE model is fully implemented.
25925 \end_layout
25926
25927 \begin_layout Subsection
25928 Functions
25929 \end_layout
25930
25931 \begin_layout Standard
25932 In addition to the standard SDCC function keywords, PIC16
25933 \begin_inset LatexCommand \index{PIC16}
25934
25935 \end_inset
25936
25937  port makes available two more:
25938 \end_layout
25939
25940 \begin_layout Description
25941 wparam
25942 \begin_inset LatexCommand \index{PIC16!wparam}
25943
25944 \end_inset
25945
25946  Use the WREG to pass one byte of the first function argument.
25947  This improves speed but you may not use this for functions with arguments
25948  that are called via function pointers, otherwise the first byte of the
25949  first parameter will get lost.
25950  Usage:
25951 \end_layout
25952
25953 \begin_layout LyX-Code
25954 void func_wparam(int a) wparam
25955 \end_layout
25956
25957 \begin_layout LyX-Code
25958 {
25959 \end_layout
25960
25961 \begin_layout LyX-Code
25962     /* WREG hold the lower part of a */
25963 \end_layout
25964
25965 \begin_layout LyX-Code
25966     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25967  */
25968 \end_layout
25969
25970 \begin_layout LyX-Code
25971 ...
25972 \end_layout
25973
25974 \begin_layout LyX-Code
25975 }
25976 \end_layout
25977
25978 \begin_layout Description
25979 shadowregs
25980 \begin_inset LatexCommand \index{PIC16!shadowregs}
25981
25982 \end_inset
25983
25984  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25985  hardware shadow registers which hold the values of WREG, STATUS and BSR
25986  registers.
25987  This can be done by adding the keyword 
25988 \emph on
25989 shadowregs
25990 \emph default
25991  before the 
25992 \emph on
25993 interrupt
25994 \emph default
25995  keyword in the function's header.
25996 \end_layout
25997
25998 \begin_layout LyX-Code
25999 void isr_shadow(void) shadowregs interrupt 1
26000 \end_layout
26001
26002 \begin_layout LyX-Code
26003 {
26004 \end_layout
26005
26006 \begin_layout LyX-Code
26007 ...
26008 \end_layout
26009
26010 \begin_layout LyX-Code
26011 }
26012 \end_layout
26013
26014 \begin_layout Standard
26015
26016 \emph on
26017 shadowregs
26018 \emph default
26019  instructs the code generator not to store/restore WREG, STATUS, BSR when
26020  entering/exiting the ISR.
26021 \end_layout
26022
26023 \begin_layout Subsection
26024 Function return values
26025 \end_layout
26026
26027 \begin_layout Standard
26028 Return values from functions are placed to the appropriate registers following
26029  a modified Microchip policy optimized for SDCC.
26030  The following table shows these registers:
26031 \end_layout
26032
26033 \begin_layout Standard
26034 \align center
26035 \begin_inset Tabular
26036 <lyxtabular version="3" rows="6" columns="2">
26037 <features>
26038 <column alignment="center" valignment="top" leftline="true" width="0">
26039 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26040 <row topline="true" bottomline="true">
26041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26042 \begin_inset Text
26043
26044 \begin_layout Standard
26045 size
26046 \end_layout
26047
26048 \end_inset
26049 </cell>
26050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26051 \begin_inset Text
26052
26053 \begin_layout Standard
26054 destination register
26055 \end_layout
26056
26057 \end_inset
26058 </cell>
26059 </row>
26060 <row topline="true">
26061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26062 \begin_inset Text
26063
26064 \begin_layout Standard
26065 8 bits
26066 \end_layout
26067
26068 \end_inset
26069 </cell>
26070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26071 \begin_inset Text
26072
26073 \begin_layout Standard
26074 WREG
26075 \end_layout
26076
26077 \end_inset
26078 </cell>
26079 </row>
26080 <row topline="true">
26081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26082 \begin_inset Text
26083
26084 \begin_layout Standard
26085 16 bits
26086 \end_layout
26087
26088 \end_inset
26089 </cell>
26090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26091 \begin_inset Text
26092
26093 \begin_layout Standard
26094 PRODL:WREG
26095 \end_layout
26096
26097 \end_inset
26098 </cell>
26099 </row>
26100 <row topline="true">
26101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26102 \begin_inset Text
26103
26104 \begin_layout Standard
26105 24 bits
26106 \end_layout
26107
26108 \end_inset
26109 </cell>
26110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26111 \begin_inset Text
26112
26113 \begin_layout Standard
26114 PRODH:PRODL:WREG
26115 \end_layout
26116
26117 \end_inset
26118 </cell>
26119 </row>
26120 <row topline="true">
26121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26122 \begin_inset Text
26123
26124 \begin_layout Standard
26125 32 bits
26126 \end_layout
26127
26128 \end_inset
26129 </cell>
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26131 \begin_inset Text
26132
26133 \begin_layout Standard
26134 FSR0L:PRODH:PRODL:WREG
26135 \end_layout
26136
26137 \end_inset
26138 </cell>
26139 </row>
26140 <row topline="true" bottomline="true">
26141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26142 \begin_inset Text
26143
26144 \begin_layout Standard
26145 >32 bits
26146 \end_layout
26147
26148 \end_inset
26149 </cell>
26150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26151 \begin_inset Text
26152
26153 \begin_layout Standard
26154 on stack, FSR0 points to the beginning
26155 \end_layout
26156
26157 \end_inset
26158 </cell>
26159 </row>
26160 </lyxtabular>
26161
26162 \end_inset
26163
26164
26165 \end_layout
26166
26167 \begin_layout Subsection
26168 Interrupts
26169 \end_layout
26170
26171 \begin_layout Standard
26172 An interrupt
26173 \begin_inset LatexCommand \index{PIC16!interrupt}
26174
26175 \end_inset
26176
26177  service routine (ISR) is declared using the 
26178 \emph on
26179 interrupt
26180 \emph default
26181  keyword.
26182 \end_layout
26183
26184 \begin_layout LyX-Code
26185 void isr(void) interrupt 
26186 \emph on
26187 n
26188 \end_layout
26189
26190 \begin_layout LyX-Code
26191 {
26192 \end_layout
26193
26194 \begin_layout LyX-Code
26195 ...
26196 \end_layout
26197
26198 \begin_layout LyX-Code
26199 }
26200 \end_layout
26201
26202 \begin_layout Standard
26203
26204 \emph on
26205 n
26206 \emph default
26207  is the interrupt number, which for PIC18F devices can be:
26208 \end_layout
26209
26210 \begin_layout Standard
26211 \align center
26212 \begin_inset Tabular
26213 <lyxtabular version="3" rows="4" columns="3">
26214 <features>
26215 <column alignment="center" valignment="top" leftline="true" width="0">
26216 <column alignment="center" valignment="top" leftline="true" width="0">
26217 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26218 <row topline="true" bottomline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26220 \begin_inset Text
26221
26222 \begin_layout Standard
26223
26224 \emph on
26225 n
26226 \end_layout
26227
26228 \end_inset
26229 </cell>
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26231 \begin_inset Text
26232
26233 \begin_layout Standard
26234 Interrupt Vector
26235 \end_layout
26236
26237 \end_inset
26238 </cell>
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26240 \begin_inset Text
26241
26242 \begin_layout Standard
26243 Interrupt Vector Address
26244 \end_layout
26245
26246 \end_inset
26247 </cell>
26248 </row>
26249 <row topline="true">
26250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26251 \begin_inset Text
26252
26253 \begin_layout Standard
26254 0
26255 \end_layout
26256
26257 \end_inset
26258 </cell>
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26260 \begin_inset Text
26261
26262 \begin_layout Standard
26263 RESET vector
26264 \end_layout
26265
26266 \end_inset
26267 </cell>
26268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26269 \begin_inset Text
26270
26271 \begin_layout Standard
26272 0x000000
26273 \end_layout
26274
26275 \end_inset
26276 </cell>
26277 </row>
26278 <row topline="true">
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \begin_layout Standard
26283
26284 \family roman
26285 \series medium
26286 \shape up
26287 \size normal
26288 \emph off
26289 \bar no
26290 \noun off
26291 \color none
26292 1
26293 \end_layout
26294
26295 \end_inset
26296 </cell>
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \begin_layout Standard
26301
26302 \family roman
26303 \series medium
26304 \shape up
26305 \size normal
26306 \emph off
26307 \bar no
26308 \noun off
26309 \color none
26310 HIGH priority interrupts
26311 \end_layout
26312
26313 \end_inset
26314 </cell>
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26316 \begin_inset Text
26317
26318 \begin_layout Standard
26319 0x000008
26320 \end_layout
26321
26322 \end_inset
26323 </cell>
26324 </row>
26325 <row topline="true" bottomline="true">
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26327 \begin_inset Text
26328
26329 \begin_layout Standard
26330 2
26331 \end_layout
26332
26333 \end_inset
26334 </cell>
26335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26336 \begin_inset Text
26337
26338 \begin_layout Standard
26339 LOW priority interrupts
26340 \end_layout
26341
26342 \end_inset
26343 </cell>
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26345 \begin_inset Text
26346
26347 \begin_layout Standard
26348 0x000018
26349 \end_layout
26350
26351 \end_inset
26352 </cell>
26353 </row>
26354 </lyxtabular>
26355
26356 \end_inset
26357
26358
26359 \end_layout
26360
26361 \begin_layout Standard
26362 When generating assembly code for ISR the code generator places a 
26363 \noun on
26364 goto 
26365 \noun default
26366 instruction at the 
26367 \emph on
26368 Interrupt Vector Address
26369 \emph default
26370  which points at the genetated ISR.
26371  This single GOTO instruction is part of an automatically generated 
26372 \emph on
26373 interrupt entry point
26374 \emph default
26375  function.
26376  The actuall ISR code is placed as normally would in the code space.
26377  Upon interrupt request, the GOTO instruction is executed which jumps to
26378  the ISR code.
26379  When declaring interrupt functions as _naked this GOTO instruction is 
26380 \series bold
26381 not
26382 \series default
26383  generated.
26384  The whole interrupt functions is therefore placed at the Interrupt Vector
26385  Address of the specific interrupt.
26386  This is not a problem for the LOW priority interrupts, but it is a problem
26387  for the RESET and the HIGH priority interrupts because code may be written
26388  at the next interrupt's vector address and cause undeterminate program
26389  behaviour if that interrupt is raised.
26390 \begin_inset Foot
26391 status open
26392
26393 \begin_layout Standard
26394 This is not a problem when
26395 \end_layout
26396
26397 \begin_layout Enumerate
26398 this is a HIGH interrupt ISR and LOW interrupts are 
26399 \emph on
26400 disabled
26401 \emph default
26402  or not used.
26403 \end_layout
26404
26405 \begin_layout Enumerate
26406 when the ISR is small enough not to reach the next interrupt's vector address.
26407 \end_layout
26408
26409 \end_inset
26410
26411
26412 \end_layout
26413
26414 \begin_layout Standard
26415
26416 \emph on
26417 n
26418 \emph default
26419  may be omitted.
26420  This way a function is generated similar to an ISR, but it is not assigned
26421  to any interrupt.
26422 \end_layout
26423
26424 \begin_layout Standard
26425 When entering an interrupt, currently the PIC16
26426 \begin_inset LatexCommand \index{PIC16}
26427
26428 \end_inset
26429
26430  port automatically saves the following registers:
26431 \end_layout
26432
26433 \begin_layout Itemize
26434 WREG
26435 \end_layout
26436
26437 \begin_layout Itemize
26438 STATUS
26439 \end_layout
26440
26441 \begin_layout Itemize
26442 BSR
26443 \end_layout
26444
26445 \begin_layout Itemize
26446 PROD (PRODL and PRODH)
26447 \end_layout
26448
26449 \begin_layout Itemize
26450 FSR0 (FSR0L and FSR0H)
26451 \end_layout
26452
26453 \begin_layout Standard
26454 These registers are restored upon return from the interrupt routine.
26455 \begin_inset Foot
26456 status open
26457
26458 \begin_layout Standard
26459 NOTE that when the _naked attribute is specified for an interrupt routine,
26460  then NO registers are stored or restored.
26461 \end_layout
26462
26463 \end_inset
26464
26465
26466 \end_layout
26467
26468 \begin_layout Subsection
26469 Generic Pointers
26470 \end_layout
26471
26472 \begin_layout Standard
26473 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26474  There are 3 types of generic pointers currently implemented data, code
26475  and eeprom pointers.
26476  They are differentiated by the value of the 7th and 6th bits of the upper
26477  byte:
26478 \end_layout
26479
26480 \begin_layout Standard
26481 \align center
26482 \begin_inset Tabular
26483 <lyxtabular version="3" rows="5" columns="5">
26484 <features>
26485 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26486 <column alignment="center" valignment="top" width="0">
26487 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26488 <column alignment="center" valignment="top" width="0">
26489 <column alignment="left" valignment="top" rightline="true" width="0">
26490 <row topline="true" bottomline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \begin_layout Standard
26495 pointer type
26496 \end_layout
26497
26498 \end_inset
26499 </cell>
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26501 \begin_inset Text
26502
26503 \begin_layout Standard
26504 7th bit
26505 \end_layout
26506
26507 \end_inset
26508 </cell>
26509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26510 \begin_inset Text
26511
26512 \begin_layout Standard
26513 6th bit
26514 \end_layout
26515
26516 \end_inset
26517 </cell>
26518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26519 \begin_inset Text
26520
26521 \begin_layout Standard
26522 rest of the pointer
26523 \end_layout
26524
26525 \end_inset
26526 </cell>
26527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26528 \begin_inset Text
26529
26530 \begin_layout Standard
26531 description
26532 \end_layout
26533
26534 \end_inset
26535 </cell>
26536 </row>
26537 <row topline="true" bottomline="true">
26538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26539 \begin_inset Text
26540
26541 \begin_layout Standard
26542 data 
26543 \end_layout
26544
26545 \end_inset
26546 </cell>
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26548 \begin_inset Text
26549
26550 \begin_layout Standard
26551 1
26552 \end_layout
26553
26554 \end_inset
26555 </cell>
26556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26557 \begin_inset Text
26558
26559 \begin_layout Standard
26560 0
26561 \end_layout
26562
26563 \end_inset
26564 </cell>
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26566 \begin_inset Text
26567
26568 \begin_layout Standard
26569
26570 \family typewriter
26571 \shape slanted
26572 \emph on
26573 uuuuuu uuuuxxxx xxxxxxxx
26574 \end_layout
26575
26576 \end_inset
26577 </cell>
26578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26579 \begin_inset Text
26580
26581 \begin_layout Standard
26582 a 12-bit data pointer in data RAM memory
26583 \end_layout
26584
26585 \end_inset
26586 </cell>
26587 </row>
26588 <row bottomline="true">
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26590 \begin_inset Text
26591
26592 \begin_layout Standard
26593 code
26594 \end_layout
26595
26596 \end_inset
26597 </cell>
26598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26599 \begin_inset Text
26600
26601 \begin_layout Standard
26602 0
26603 \end_layout
26604
26605 \end_inset
26606 </cell>
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26608 \begin_inset Text
26609
26610 \begin_layout Standard
26611 0
26612 \end_layout
26613
26614 \end_inset
26615 </cell>
26616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26617 \begin_inset Text
26618
26619 \begin_layout Standard
26620
26621 \family typewriter
26622 \shape slanted
26623 \emph on
26624 uxxxxx xxxxxxxx xxxxxxxx
26625 \end_layout
26626
26627 \end_inset
26628 </cell>
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26630 \begin_inset Text
26631
26632 \begin_layout Standard
26633 a 21-bit code pointer in FLASH memory
26634 \end_layout
26635
26636 \end_inset
26637 </cell>
26638 </row>
26639 <row bottomline="true">
26640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26641 \begin_inset Text
26642
26643 \begin_layout Standard
26644 eeprom
26645 \end_layout
26646
26647 \end_inset
26648 </cell>
26649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26650 \begin_inset Text
26651
26652 \begin_layout Standard
26653 0
26654 \end_layout
26655
26656 \end_inset
26657 </cell>
26658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26659 \begin_inset Text
26660
26661 \begin_layout Standard
26662 1
26663 \end_layout
26664
26665 \end_inset
26666 </cell>
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26668 \begin_inset Text
26669
26670 \begin_layout Standard
26671
26672 \family typewriter
26673 \shape slanted
26674 \emph on
26675 uuuuuu uuuuuuxx xxxxxxxx
26676 \end_layout
26677
26678 \end_inset
26679 </cell>
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26681 \begin_inset Text
26682
26683 \begin_layout Standard
26684 a 10-bit eeprom pointer in EEPROM memory
26685 \end_layout
26686
26687 \end_inset
26688 </cell>
26689 </row>
26690 <row bottomline="true">
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26692 \begin_inset Text
26693
26694 \begin_layout Standard
26695 (unimplemented)
26696 \end_layout
26697
26698 \end_inset
26699 </cell>
26700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26701 \begin_inset Text
26702
26703 \begin_layout Standard
26704 1
26705 \end_layout
26706
26707 \end_inset
26708 </cell>
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \begin_layout Standard
26713 1
26714 \end_layout
26715
26716 \end_inset
26717 </cell>
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26719 \begin_inset Text
26720
26721 \begin_layout Standard
26722
26723 \family typewriter
26724 \shape slanted
26725 \emph on
26726 xxxxxx xxxxxxxx xxxxxxxx
26727 \end_layout
26728
26729 \end_inset
26730 </cell>
26731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26732 \begin_inset Text
26733
26734 \begin_layout Standard
26735 unimplemented pointer type
26736 \end_layout
26737
26738 \end_inset
26739 </cell>
26740 </row>
26741 </lyxtabular>
26742
26743 \end_inset
26744
26745
26746 \end_layout
26747
26748 \begin_layout Standard
26749 Generic pointer are read and written with a set of library functions which
26750  read/write 1, 2, 3, 4 bytes.
26751 \end_layout
26752
26753 \begin_layout Subsection
26754 PIC16 C Libraries
26755 \end_layout
26756
26757 \begin_layout Subsubsection
26758 Standard I/O Streams
26759 \end_layout
26760
26761 \begin_layout Standard
26762 In the 
26763 \emph on
26764 stdio.h
26765 \emph default
26766  the type FILE is defined as:
26767 \end_layout
26768
26769 \begin_layout LyX-Code
26770 typedef char * FILE;
26771 \end_layout
26772
26773 \begin_layout Standard
26774 This type is the stream type implemented I/O in the PIC18F devices.
26775  Also the standard input and output streams are declared in stdio.h:
26776 \end_layout
26777
26778 \begin_layout LyX-Code
26779 extern FILE * stdin;
26780 \end_layout
26781
26782 \begin_layout LyX-Code
26783 extern FILE * stdout;
26784 \end_layout
26785
26786 \begin_layout Standard
26787 The FILE type is actually a generic pointer which defines one more type
26788  of generic pointers, the 
26789 \emph on
26790 stream 
26791 \emph default
26792 pointer.
26793  This new type has the format:
26794 \end_layout
26795
26796 \begin_layout Standard
26797 \align center
26798 \begin_inset Tabular
26799 <lyxtabular version="3" rows="2" columns="7">
26800 <features>
26801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26802 <column alignment="center" valignment="top" width="0">
26803 <column alignment="center" valignment="top" leftline="true" width="0">
26804 <column alignment="center" valignment="top" leftline="true" width="0">
26805 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26806 <column alignment="center" valignment="top" width="0">
26807 <column alignment="left" valignment="top" rightline="true" width="0">
26808 <row topline="true" bottomline="true">
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 pointer type
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \begin_layout Standard
26822 <7:6>
26823 \end_layout
26824
26825 \end_inset
26826 </cell>
26827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26828 \begin_inset Text
26829
26830 \begin_layout Standard
26831 <5>
26832 \end_layout
26833
26834 \end_inset
26835 </cell>
26836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26837 \begin_inset Text
26838
26839 \begin_layout Standard
26840 <4>
26841 \end_layout
26842
26843 \end_inset
26844 </cell>
26845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26846 \begin_inset Text
26847
26848 \begin_layout Standard
26849 <3:0>
26850 \end_layout
26851
26852 \end_inset
26853 </cell>
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26855 \begin_inset Text
26856
26857 \begin_layout Standard
26858 rest of the pointer
26859 \end_layout
26860
26861 \end_inset
26862 </cell>
26863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26864 \begin_inset Text
26865
26866 \begin_layout Standard
26867 descrption
26868 \end_layout
26869
26870 \end_inset
26871 </cell>
26872 </row>
26873 <row topline="true" bottomline="true">
26874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26875 \begin_inset Text
26876
26877 \begin_layout Standard
26878 stream
26879 \end_layout
26880
26881 \end_inset
26882 </cell>
26883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26884 \begin_inset Text
26885
26886 \begin_layout Standard
26887 00
26888 \end_layout
26889
26890 \end_inset
26891 </cell>
26892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26893 \begin_inset Text
26894
26895 \begin_layout Standard
26896 1
26897 \end_layout
26898
26899 \end_inset
26900 </cell>
26901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26902 \begin_inset Text
26903
26904 \begin_layout Standard
26905 0
26906 \end_layout
26907
26908 \end_inset
26909 </cell>
26910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26911 \begin_inset Text
26912
26913 \begin_layout Standard
26914 nnnn
26915 \end_layout
26916
26917 \end_inset
26918 </cell>
26919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26920 \begin_inset Text
26921
26922 \begin_layout Standard
26923
26924 \family typewriter
26925 \shape slanted
26926 \emph on
26927 uuuuuuuu uuuuuuuu
26928 \end_layout
26929
26930 \end_inset
26931 </cell>
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26933 \begin_inset Text
26934
26935 \begin_layout Standard
26936 upper byte high nubble is 0x2n, the rest are zeroes
26937 \end_layout
26938
26939 \end_inset
26940 </cell>
26941 </row>
26942 </lyxtabular>
26943
26944 \end_inset
26945
26946
26947 \end_layout
26948
26949 \begin_layout Standard
26950 Currently implemented there are 3 types of streams defined:
26951 \end_layout
26952
26953 \begin_layout Standard
26954 \align center
26955 \begin_inset Tabular
26956 <lyxtabular version="3" rows="4" columns="4">
26957 <features>
26958 <column alignment="center" valignment="top" leftline="true" width="0">
26959 <column alignment="center" valignment="top" leftline="true" width="0">
26960 <column alignment="center" valignment="top" leftline="true" width="0">
26961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26962 <row topline="true" bottomline="true">
26963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26964 \begin_inset Text
26965
26966 \begin_layout Standard
26967 stream type
26968 \end_layout
26969
26970 \end_inset
26971 </cell>
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26973 \begin_inset Text
26974
26975 \begin_layout Standard
26976 value
26977 \end_layout
26978
26979 \end_inset
26980 </cell>
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26982 \begin_inset Text
26983
26984 \begin_layout Standard
26985 module
26986 \end_layout
26987
26988 \end_inset
26989 </cell>
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994 description
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 </row>
27000 <row topline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \begin_layout Standard
27005 STREAM_USART
27006 \end_layout
27007
27008 \end_inset
27009 </cell>
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014
27015 \family typewriter
27016 0x200000UL
27017 \end_layout
27018
27019 \end_inset
27020 </cell>
27021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27022 \begin_inset Text
27023
27024 \begin_layout Standard
27025 USART
27026 \end_layout
27027
27028 \end_inset
27029 </cell>
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_inset Text
27032
27033 \begin_layout Standard
27034 Writes/Reads characters via the USART peripheral
27035 \end_layout
27036
27037 \end_inset
27038 </cell>
27039 </row>
27040 <row topline="true">
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27042 \begin_inset Text
27043
27044 \begin_layout Standard
27045 STREAM_MSSP
27046 \end_layout
27047
27048 \end_inset
27049 </cell>
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27051 \begin_inset Text
27052
27053 \begin_layout Standard
27054
27055 \family typewriter
27056 0x210000UL
27057 \end_layout
27058
27059 \end_inset
27060 </cell>
27061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27062 \begin_inset Text
27063
27064 \begin_layout Standard
27065 MSSP
27066 \end_layout
27067
27068 \end_inset
27069 </cell>
27070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27071 \begin_inset Text
27072
27073 \begin_layout Standard
27074 Writes/Reads characters via the MSSP peripheral
27075 \end_layout
27076
27077 \end_inset
27078 </cell>
27079 </row>
27080 <row topline="true" bottomline="true">
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27082 \begin_inset Text
27083
27084 \begin_layout Standard
27085 STREAM_USER
27086 \end_layout
27087
27088 \end_inset
27089 </cell>
27090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27091 \begin_inset Text
27092
27093 \begin_layout Standard
27094
27095 \family typewriter
27096 0x2f0000UL
27097 \end_layout
27098
27099 \end_inset
27100 </cell>
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27102 \begin_inset Text
27103
27104 \begin_layout Standard
27105 (none)
27106 \end_layout
27107
27108 \end_inset
27109 </cell>
27110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27111 \begin_inset Text
27112
27113 \begin_layout Standard
27114 Writes/Reads characters via used defined functions
27115 \end_layout
27116
27117 \end_inset
27118 </cell>
27119 </row>
27120 </lyxtabular>
27121
27122 \end_inset
27123
27124
27125 \end_layout
27126
27127 \begin_layout Standard
27128 The stream identifiers are declared as macros in the stdio.h header.
27129 \end_layout
27130
27131 \begin_layout Standard
27132 In the libc library there exist the functions that are used to write to
27133  each of the above streams.
27134  These are
27135 \end_layout
27136
27137 \begin_layout Description
27138 _
27139 \begin_inset ERT
27140 status collapsed
27141
27142 \begin_layout Standard
27143
27144
27145 \backslash
27146 /
27147 \end_layout
27148
27149 \end_inset
27150
27151 _stream_usart_putchar writes a character at the USART stream
27152 \end_layout
27153
27154 \begin_layout Description
27155 _
27156 \begin_inset ERT
27157 status collapsed
27158
27159 \begin_layout Standard
27160
27161
27162 \backslash
27163 /
27164 \end_layout
27165
27166 \end_inset
27167
27168 _stream_mssp_putchar writes a character at the MSSP stream
27169 \end_layout
27170
27171 \begin_layout Description
27172 putchar dummy function.
27173  This writes a character to a user specified manner.
27174 \end_layout
27175
27176 \begin_layout Standard
27177 In order to increase performance 
27178 \emph on
27179 putchar 
27180 \emph default
27181 is declared in stdio.h as having its parameter in WREG (it has the wparam
27182  keyword).
27183  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27184  in a user-friendly way.
27185  
27186 \emph on
27187 arg
27188 \emph default
27189  is the name of the variable that holds the character to print.
27190  An example follows:
27191 \end_layout
27192
27193 \begin_layout LyX-Code
27194 #include <pic18fregs.h>
27195 \newline
27196 #include <stdio.h>
27197 \newline
27198
27199 \newline
27200 PUTCHAR( c )
27201 \end_layout
27202
27203 \begin_layout LyX-Code
27204 {
27205 \end_layout
27206
27207 \begin_layout LyX-Code
27208     PORTA = c;    /* dump character c to PORTA */
27209 \end_layout
27210
27211 \begin_layout LyX-Code
27212
27213 \newline
27214
27215 \newline
27216 void main(void)
27217 \end_layout
27218
27219 \begin_layout LyX-Code
27220 {
27221 \end_layout
27222
27223 \begin_layout LyX-Code
27224     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27225 \end_layout
27226
27227 \begin_layout LyX-Code
27228                               * by default to STREAM_USER */
27229 \end_layout
27230
27231 \begin_layout LyX-Code
27232     printf (
27233 \begin_inset Quotes sld
27234 \end_inset
27235
27236 This is a printf test
27237 \backslash
27238 n
27239 \begin_inset Quotes srd
27240 \end_inset
27241
27242 );
27243 \end_layout
27244
27245 \begin_layout LyX-Code
27246 }
27247 \end_layout
27248
27249 \begin_layout LyX-Code
27250
27251 \end_layout
27252
27253 \begin_layout Subsubsection
27254 Printing functions
27255 \end_layout
27256
27257 \begin_layout Standard
27258 PIC16 contains an implementation of the printf-family of functions.
27259  There exist the following functions:
27260 \end_layout
27261
27262 \begin_layout LyX-Code
27263 extern unsigned int sprintf(char *buf, char *fmt, ...);
27264 \end_layout
27265
27266 \begin_layout LyX-Code
27267 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27268 \end_layout
27269
27270 \begin_layout LyX-Code
27271
27272 \end_layout
27273
27274 \begin_layout LyX-Code
27275 extern unsigned int printf(char *fmt, ...);
27276 \end_layout
27277
27278 \begin_layout LyX-Code
27279 extern unsigned int vprintf(char *fmt, va_lista ap);
27280 \end_layout
27281
27282 \begin_layout LyX-Code
27283
27284 \end_layout
27285
27286 \begin_layout LyX-Code
27287 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27288 \end_layout
27289
27290 \begin_layout LyX-Code
27291 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27292 \end_layout
27293
27294 \begin_layout Standard
27295 For sprintf and vsprintf 
27296 \emph on
27297 buf 
27298 \emph default
27299 should normally be a data pointer where the resulting string will be placed.
27300  No range checking is done so the user should allocate the necessery buffer.
27301  For fprintf and vfprintf 
27302 \emph on
27303 fp
27304 \emph default
27305  should be a stream pointer (i.e.
27306  stdout, STREAM_MSSP, etc...).
27307 \end_layout
27308
27309 \begin_layout Subsubsection
27310 Signals
27311 \end_layout
27312
27313 \begin_layout Standard
27314 The PIC18F family of microcontrollers supports a number of interrupt sources.
27315  A list of these interrupts is shown in the following table:
27316 \end_layout
27317
27318 \begin_layout Standard
27319 \align center
27320 \begin_inset Tabular
27321 <lyxtabular version="3" rows="11" columns="4">
27322 <features>
27323 <column alignment="left" valignment="top" leftline="true" width="0">
27324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27325 <column alignment="left" valignment="top" leftline="true" width="0">
27326 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27327 <row topline="true" bottomline="true">
27328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27329 \begin_inset Text
27330
27331 \begin_layout Standard
27332 signal name
27333 \end_layout
27334
27335 \end_inset
27336 </cell>
27337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27338 \begin_inset Text
27339
27340 \begin_layout Standard
27341 description
27342 \end_layout
27343
27344 \end_inset
27345 </cell>
27346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27347 \begin_inset Text
27348
27349 \begin_layout Standard
27350 signal name
27351 \end_layout
27352
27353 \end_inset
27354 </cell>
27355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27356 \begin_inset Text
27357
27358 \begin_layout Standard
27359 descritpion
27360 \end_layout
27361
27362 \end_inset
27363 </cell>
27364 </row>
27365 <row topline="true">
27366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27367 \begin_inset Text
27368
27369 \begin_layout Standard
27370 SIG_RB
27371 \end_layout
27372
27373 \end_inset
27374 </cell>
27375 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27376 \begin_inset Text
27377
27378 \begin_layout Standard
27379 PORTB change interrupt
27380 \end_layout
27381
27382 \end_inset
27383 </cell>
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27385 \begin_inset Text
27386
27387 \begin_layout Standard
27388 SIG_EE
27389 \end_layout
27390
27391 \end_inset
27392 </cell>
27393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27394 \begin_inset Text
27395
27396 \begin_layout Standard
27397 EEPROM/FLASH write complete interrupt
27398 \end_layout
27399
27400 \end_inset
27401 </cell>
27402 </row>
27403 <row topline="true">
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27405 \begin_inset Text
27406
27407 \begin_layout Standard
27408 SIG_INT0
27409 \end_layout
27410
27411 \end_inset
27412 </cell>
27413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27414 \begin_inset Text
27415
27416 \begin_layout Standard
27417 INT0 external interrupt
27418 \end_layout
27419
27420 \end_inset
27421 </cell>
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27423 \begin_inset Text
27424
27425 \begin_layout Standard
27426 SIG_BCOL
27427 \end_layout
27428
27429 \end_inset
27430 </cell>
27431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27432 \begin_inset Text
27433
27434 \begin_layout Standard
27435 Bus collision interrupt
27436 \end_layout
27437
27438 \end_inset
27439 </cell>
27440 </row>
27441 <row topline="true">
27442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27443 \begin_inset Text
27444
27445 \begin_layout Standard
27446 SIG_INT1
27447 \end_layout
27448
27449 \end_inset
27450 </cell>
27451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27452 \begin_inset Text
27453
27454 \begin_layout Standard
27455 INT1 external interrupt
27456 \end_layout
27457
27458 \end_inset
27459 </cell>
27460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27461 \begin_inset Text
27462
27463 \begin_layout Standard
27464 SIG_LVD
27465 \end_layout
27466
27467 \end_inset
27468 </cell>
27469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27470 \begin_inset Text
27471
27472 \begin_layout Standard
27473 Low voltage detect interrupt
27474 \end_layout
27475
27476 \end_inset
27477 </cell>
27478 </row>
27479 <row topline="true">
27480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27481 \begin_inset Text
27482
27483 \begin_layout Standard
27484 SIG_INT2
27485 \end_layout
27486
27487 \end_inset
27488 </cell>
27489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27490 \begin_inset Text
27491
27492 \begin_layout Standard
27493 INT2 external interrupt
27494 \end_layout
27495
27496 \end_inset
27497 </cell>
27498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27499 \begin_inset Text
27500
27501 \begin_layout Standard
27502 SIG_PSP
27503 \end_layout
27504
27505 \end_inset
27506 </cell>
27507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27508 \begin_inset Text
27509
27510 \begin_layout Standard
27511 Parallel slave port interrupt
27512 \end_layout
27513
27514 \end_inset
27515 </cell>
27516 </row>
27517 <row topline="true">
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27519 \begin_inset Text
27520
27521 \begin_layout Standard
27522 SIG_CCP1
27523 \end_layout
27524
27525 \end_inset
27526 </cell>
27527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27528 \begin_inset Text
27529
27530 \begin_layout Standard
27531 CCP1 module interrupt
27532 \end_layout
27533
27534 \end_inset
27535 </cell>
27536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27537 \begin_inset Text
27538
27539 \begin_layout Standard
27540 SIG_AD
27541 \end_layout
27542
27543 \end_inset
27544 </cell>
27545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27546 \begin_inset Text
27547
27548 \begin_layout Standard
27549 AD convertion complete interrupt
27550 \end_layout
27551
27552 \end_inset
27553 </cell>
27554 </row>
27555 <row topline="true">
27556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27557 \begin_inset Text
27558
27559 \begin_layout Standard
27560 SIG_CCP2
27561 \end_layout
27562
27563 \end_inset
27564 </cell>
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27566 \begin_inset Text
27567
27568 \begin_layout Standard
27569 CCP2 module interrupt
27570 \end_layout
27571
27572 \end_inset
27573 </cell>
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27575 \begin_inset Text
27576
27577 \begin_layout Standard
27578 SIG_RC
27579 \end_layout
27580
27581 \end_inset
27582 </cell>
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27584 \begin_inset Text
27585
27586 \begin_layout Standard
27587 USART receive interrupt
27588 \end_layout
27589
27590 \end_inset
27591 </cell>
27592 </row>
27593 <row topline="true">
27594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27595 \begin_inset Text
27596
27597 \begin_layout Standard
27598 SIG_TMR0
27599 \end_layout
27600
27601 \end_inset
27602 </cell>
27603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27604 \begin_inset Text
27605
27606 \begin_layout Standard
27607 TMR0 overflow interrupt
27608 \end_layout
27609
27610 \end_inset
27611 </cell>
27612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27613 \begin_inset Text
27614
27615 \begin_layout Standard
27616 SIG_TX
27617 \end_layout
27618
27619 \end_inset
27620 </cell>
27621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27622 \begin_inset Text
27623
27624 \begin_layout Standard
27625 USART transmit interrupt
27626 \end_layout
27627
27628 \end_inset
27629 </cell>
27630 </row>
27631 <row topline="true">
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27633 \begin_inset Text
27634
27635 \begin_layout Standard
27636 SIG_TMR1
27637 \end_layout
27638
27639 \end_inset
27640 </cell>
27641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27642 \begin_inset Text
27643
27644 \begin_layout Standard
27645 TMR1 overflow interrupt
27646 \end_layout
27647
27648 \end_inset
27649 </cell>
27650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27651 \begin_inset Text
27652
27653 \begin_layout Standard
27654 SIG_MSSP
27655 \end_layout
27656
27657 \end_inset
27658 </cell>
27659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27660 \begin_inset Text
27661
27662 \begin_layout Standard
27663 SSP receive/transmit interrupt
27664 \end_layout
27665
27666 \end_inset
27667 </cell>
27668 </row>
27669 <row topline="true">
27670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27671 \begin_inset Text
27672
27673 \begin_layout Standard
27674 SIG_TMR2
27675 \end_layout
27676
27677 \end_inset
27678 </cell>
27679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27680 \begin_inset Text
27681
27682 \begin_layout Standard
27683 TMR2 matches PR2 interrupt
27684 \end_layout
27685
27686 \end_inset
27687 </cell>
27688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27689 \begin_inset Text
27690
27691 \begin_layout Standard
27692
27693 \end_layout
27694
27695 \end_inset
27696 </cell>
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27698 \begin_inset Text
27699
27700 \begin_layout Standard
27701
27702 \end_layout
27703
27704 \end_inset
27705 </cell>
27706 </row>
27707 <row topline="true" bottomline="true">
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27709 \begin_inset Text
27710
27711 \begin_layout Standard
27712 SIG_TMR3
27713 \end_layout
27714
27715 \end_inset
27716 </cell>
27717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27718 \begin_inset Text
27719
27720 \begin_layout Standard
27721 TMR3 overflow interrupt
27722 \end_layout
27723
27724 \end_inset
27725 </cell>
27726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27727 \begin_inset Text
27728
27729 \begin_layout Standard
27730
27731 \end_layout
27732
27733 \end_inset
27734 </cell>
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27736 \begin_inset Text
27737
27738 \begin_layout Standard
27739
27740 \end_layout
27741
27742 \end_inset
27743 </cell>
27744 </row>
27745 </lyxtabular>
27746
27747 \end_inset
27748
27749
27750 \end_layout
27751
27752 \begin_layout Standard
27753 The prototypes for these names are defined in the header file 
27754 \emph on
27755 signal.h
27756 \emph default
27757  .
27758 \end_layout
27759
27760 \begin_layout Standard
27761 In order to simplify signal handling, a number of macros is provided:
27762 \end_layout
27763
27764 \begin_layout List
27765 \labelwidthstring 00.00.0000
27766 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27767  high priority interrupts.
27768  
27769 \emph on
27770 name
27771 \emph default
27772  is the function name to use.
27773 \end_layout
27774
27775 \begin_layout List
27776 \labelwidthstring 00.00.0000
27777 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27778  low priority interrupt.
27779  
27780 \emph on
27781 name
27782 \emph default
27783  is the function name to use.
27784 \end_layout
27785
27786 \begin_layout List
27787 \labelwidthstring 00.00.0000
27788 DEF_HANDLER(sig,handler) define a handler for signal 
27789 \emph on
27790 sig.
27791 \end_layout
27792
27793 \begin_layout List
27794 \labelwidthstring 00.00.0000
27795 END_DEF end the declaration of the dispatch table.
27796 \end_layout
27797
27798 \begin_layout Standard
27799 Additionally there are two more macros to simplify the declaration of the
27800  signal handler:
27801 \end_layout
27802
27803 \begin_layout List
27804 \labelwidthstring 00.00.0000
27805
27806 \series medium
27807 SIGHANDLER(handler) 
27808 \series default
27809 this declares the function prototype for the 
27810 \emph on
27811 handler
27812 \emph default
27813  function.
27814 \end_layout
27815
27816 \begin_layout List
27817 \labelwidthstring 00.00.0000
27818 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27819 \end_layout
27820
27821 \begin_layout Standard
27822 An example of using the macros above is shown below:
27823 \end_layout
27824
27825 \begin_layout LyX-Code
27826 #include <pic18fregs.h>
27827 \end_layout
27828
27829 \begin_layout LyX-Code
27830 #include <signal.h>
27831 \newline
27832
27833 \newline
27834 DEF_INTHIGH(high_int)
27835 \end_layout
27836
27837 \begin_layout LyX-Code
27838 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27839 \end_layout
27840
27841 \begin_layout LyX-Code
27842 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27843 \end_layout
27844
27845 \begin_layout LyX-Code
27846 END_DEF
27847 \newline
27848
27849 \newline
27850 SIGHANDLER(_tmr0_handler)
27851 \end_layout
27852
27853 \begin_layout LyX-Code
27854 {
27855 \end_layout
27856
27857 \begin_layout LyX-Code
27858   /* action to be taken when timer 0 overflows */
27859 \end_layout
27860
27861 \begin_layout LyX-Code
27862 }
27863 \newline
27864
27865 \newline
27866 SIGHANDLERNAKED(_bcol_handler)
27867 \end_layout
27868
27869 \begin_layout LyX-Code
27870 {
27871 \end_layout
27872
27873 \begin_layout LyX-Code
27874   _asm
27875 \end_layout
27876
27877 \begin_layout LyX-Code
27878     /* action to be taken when bus collision occurs */
27879 \end_layout
27880
27881 \begin_layout LyX-Code
27882     retfie
27883 \end_layout
27884
27885 \begin_layout LyX-Code
27886  _endasm;
27887 \end_layout
27888
27889 \begin_layout LyX-Code
27890 }
27891 \end_layout
27892
27893 \begin_layout Standard
27894
27895 \series bold
27896 NOTES:
27897 \series default
27898  Special care should be taken when using the above scheme:
27899 \end_layout
27900
27901 \begin_layout Itemize
27902 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27903 \end_layout
27904
27905 \begin_layout Itemize
27906 when declaring SIGHANDLERNAKED handler never forget to use 
27907 \emph on
27908 retfie
27909 \emph default
27910  for proper returning.
27911 \end_layout
27912
27913 \begin_layout Subsection
27914 PIC16 Port -- Tips
27915 \end_layout
27916
27917 \begin_layout Standard
27918 Here you can find some general tips for compiling programs with SDCC/pic16.
27919 \end_layout
27920
27921 \begin_layout Subsubsection
27922 Stack size
27923 \end_layout
27924
27925 \begin_layout Standard
27926 The default stack
27927 \begin_inset LatexCommand \index{PIC16!stack}
27928
27929 \end_inset
27930
27931  size (that is 64 bytes) probably is enough for many programs.
27932  One must take care that when there are many levels of function nesting,
27933  or there is excessive usage of stack, its size should be extended.
27934  An example of such a case is the printf/sprintf family of functions.
27935  If you encounter problems like not being able to print integers, then you
27936  need to set the stack size around the maximum (256 for small stack model).
27937  The following diagram shows what happens when calling printf to print an
27938  integer:
27939 \end_layout
27940
27941 \begin_layout LyX-Code
27942 printf () --> ltoa () --> ultoa () --> divschar ()
27943 \end_layout
27944
27945 \begin_layout Standard
27946 It is should be understood that stack is easily consumed when calling complicate
27947 d functions.
27948  Using command line arguments like -
27949 \begin_inset ERT
27950 status collapsed
27951
27952 \begin_layout Standard
27953
27954
27955 \backslash
27956 /
27957 \end_layout
27958
27959 \end_inset
27960
27961 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27962  stack frames.
27963  Other ways to reduce stack usage may exist.
27964 \end_layout
27965
27966 \begin_layout Subsection
27967 Known Bugs
27968 \end_layout
27969
27970 \begin_layout Standard
27971 The PIC16 Port currently does not pass SDCC's regression test
27972 \begin_inset LatexCommand \index{Regression test (PIC16)}
27973
27974 \end_inset
27975
27976  suite (see section 
27977 \begin_inset LatexCommand \ref{sec:Quality-control}
27978
27979 \end_inset
27980
27981 ) and thus the snapshot build regression tests for the PIC16 target are
27982  currently disabled for all hosts
27983 \emph on
27984 .
27985 \end_layout
27986
27987 \begin_layout Chapter
27988 Debugging
27989 \end_layout
27990
27991 \begin_layout Standard
27992 There are several approaches to debugging your code.
27993  This chapter is meant to show your options and to give detail on some of
27994  them:
27995 \newline
27996
27997 \newline
27998 When writing your code:
27999 \end_layout
28000
28001 \begin_layout Itemize
28002 write your code with debugging in mind (avoid duplicating code, put conceptually
28003  similar variables into structs, use structured code, have strategic points
28004  within your code where all variables are consistent, ...)
28005 \end_layout
28006
28007 \begin_layout Itemize
28008 run a syntax-checking tool like splint
28009 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28010
28011 \end_inset
28012
28013
28014 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28015
28016 \end_inset
28017
28018  (see -
28019 \begin_inset ERT
28020 status collapsed
28021
28022 \begin_layout Standard
28023
28024
28025 \backslash
28026 /
28027 \end_layout
28028
28029 \end_inset
28030
28031 -more-pedantic 
28032 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28033
28034 \end_inset
28035
28036 ) over the code.
28037 \end_layout
28038
28039 \begin_layout Itemize
28040 for the high level code use a C-compiler (like f.e.
28041  GCC) to compile run and debug the code on your host.
28042  See (see -
28043 \begin_inset ERT
28044 status collapsed
28045
28046 \begin_layout Standard
28047
28048
28049 \backslash
28050 /
28051 \end_layout
28052
28053 \end_inset
28054
28055 -more-pedantic 
28056 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28057
28058 \end_inset
28059
28060 ) on how to handle syntax extensions like __xdata, __at(), ...
28061  
28062 \end_layout
28063
28064 \begin_layout Itemize
28065 use another C-compiler to compile code for your target.
28066  Always an option but not recommended:) And not very likely to help you.
28067  If you seriously consider walking this path you should at least occasionally
28068  check portability of your code.
28069  Most commercial compiler vendors will offer an evaluation version so you
28070  can test compile your code or snippets of your code.
28071 \end_layout
28072
28073 \begin_layout Standard
28074 Debugging on a simulator:
28075 \end_layout
28076
28077 \begin_layout Itemize
28078 there is a separate section about SDCDB (section 
28079 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28080
28081 \end_inset
28082
28083 ) below.
28084 \end_layout
28085
28086 \begin_layout Itemize
28087 or (8051 specific) use a freeware/commercial simulator which interfaces
28088  to the AOMF
28089 \begin_inset LatexCommand \index{AOMF, AOMF51}
28090
28091 \end_inset
28092
28093  file (see 
28094 \begin_inset LatexCommand \ref{OMF file}
28095
28096 \end_inset
28097
28098 ) optionally generated by SDCC.
28099 \end_layout
28100
28101 \begin_layout Standard
28102 Debugging On-target: 
28103 \end_layout
28104
28105 \begin_layout Itemize
28106 use a MCU port pin to serially output debug data to the RS232 port of your
28107  host.
28108  You'll probably want some level shifting device typically involving a MAX232
28109  or similar IC.
28110  If the hardware serial port of the MCU is not available search for 'Software
28111  UART' in your favourite search machine.
28112 \end_layout
28113
28114 \begin_layout Itemize
28115 use an on-target monitor.
28116  In this context a monitor is a small program which usually accepts commands
28117  via a serial line and allows to set program counter, to single step through
28118  a program and read/write memory locations.
28119  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28120  
28121 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28122
28123 \end_inset
28124
28125 ).
28126 \end_layout
28127
28128 \begin_layout Itemize
28129 toggle MCU port pins at strategic points within your code and use an oscilloscop
28130 e.
28131  A 
28132 \emph on
28133 digital oscilloscope
28134 \emph default
28135
28136 \begin_inset LatexCommand \index{Oscilloscope}
28137
28138 \end_inset
28139
28140  with deep trace memory is really helpful especially if you have to debug
28141  a realtime application.
28142  If you need to monitor more pins than your oscilloscope provides you can
28143  sometimes get away with a small R-2R network.
28144  On a single channel oscilloscope you could f.e.
28145  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28146 k
28147 \begin_inset Formula $\Omega$
28148 \end_inset
28149
28150  resistor and the other one by a 5\InsetSpace ~
28151 k
28152 \begin_inset Formula $\Omega$
28153 \end_inset
28154
28155  resistor to the oscilloscope probe (check output drive capability of the
28156  pins you want to monitor).
28157  If you need to monitor many more pins a 
28158 \emph on
28159 logic analyzer
28160 \emph default
28161  will be handy.
28162 \end_layout
28163
28164 \begin_layout Itemize
28165 use an ICE (
28166 \emph on
28167 i
28168 \emph default
28169
28170 \emph on
28171 c
28172 \emph default
28173 ircuit 
28174 \emph on
28175 e
28176 \emph default
28177 mulator
28178 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28179
28180 \end_inset
28181
28182 ).
28183  Usually very expensive.
28184  And very nice to have too.
28185  And usually locks you (for years...) to the devices the ICE can emulate.
28186  
28187 \end_layout
28188
28189 \begin_layout Itemize
28190 use a remote debugger.
28191  In most 8-bit systems the symbol information is not available on the target,
28192  and a complete debugger is too bulky for the target system.
28193  Therefore usually a debugger on the host system connects to an on-target
28194  debugging stub which accepts only primitive commands.
28195  
28196 \newline
28197 Terms to enter into your favourite search engine could be 'remote debugging',
28198  'gdb stub' or 'inferior debugger'.
28199  (is there one?)
28200 \end_layout
28201
28202 \begin_layout Itemize
28203 use an on target hardware debugger.
28204  Some of the more modern MCUs include hardware support for setting break
28205  points and monitoring/changing variables by using dedicated hardware pins.
28206  This facility doesn't require additional code to run on the target and
28207  
28208 \emph on
28209 usually
28210 \emph default
28211  doesn't affect runtime behaviour until a breakpoint is hit.
28212  For the mcs51 most hardware debuggers use the AOMF
28213 \begin_inset LatexCommand \index{AOMF, AOMF51}
28214
28215 \end_inset
28216
28217  file (see 
28218 \begin_inset LatexCommand \ref{OMF file}
28219
28220 \end_inset
28221
28222 ) as input file.
28223  
28224 \end_layout
28225
28226 \begin_layout Standard
28227 Last not least:
28228 \end_layout
28229
28230 \begin_layout Itemize
28231 if you are not familiar with any of the following terms you're likely to
28232  run into problems rather sooner than later: 
28233 \emph on
28234 volatile
28235 \emph default
28236
28237 \emph on
28238 atomic
28239 \emph default
28240
28241 \emph on
28242 memory map
28243 \emph default
28244
28245 \emph on
28246 overlay
28247 \emph default
28248 .
28249  As an embedded programmer you 
28250 \emph on
28251 have
28252 \emph default
28253  to know them so why not look them up 
28254 \emph on
28255 before
28256 \emph default
28257  you have problems?)
28258 \end_layout
28259
28260 \begin_layout Itemize
28261 tell someone else about your problem (actually this is a surprisingly effective
28262  means to hunt down the bug even if the listener is not familiar with your
28263  environment).
28264  As 'failure to communicate' is probably one of the job-induced deformations
28265  of an embedded programmer this is highly encouraged.
28266 \end_layout
28267
28268 \begin_layout Section
28269 Debugging with SDCDB
28270 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28271
28272 \end_inset
28273
28274
28275 \begin_inset LatexCommand \index{SDCDB (debugger)}
28276
28277 \end_inset
28278
28279  
28280 \end_layout
28281
28282 \begin_layout Standard
28283 SDCC is distributed with a source level debugger
28284 \begin_inset LatexCommand \index{Debugger}
28285
28286 \end_inset
28287
28288 .
28289  The debugger uses a command line interface, the command repertoire of the
28290  debugger has been kept as close to gdb
28291 \begin_inset LatexCommand \index{gdb}
28292
28293 \end_inset
28294
28295  (the GNU debugger) as possible.
28296  The configuration and build process is part of the standard compiler installati
28297 on, which also builds and installs the debugger in the target directory
28298  specified during configuration.
28299  The debugger allows you debug BOTH at the C source and at the ASM source
28300  level.
28301 \end_layout
28302
28303 \begin_layout Subsection
28304 Compiling for Debugging
28305 \end_layout
28306
28307 \begin_layout Standard
28308 The -
28309 \begin_inset ERT
28310 status collapsed
28311
28312 \begin_layout Standard
28313
28314
28315 \backslash
28316 /
28317 \end_layout
28318
28319 \end_inset
28320
28321 -debug
28322 \begin_inset LatexCommand \index{-\/-debug}
28323
28324 \end_inset
28325
28326  option must be specified for all files for which debug information is to
28327  be generated.
28328  The compiler generates a .adb file for each of these files.
28329  The linker creates the .cdb
28330 \begin_inset LatexCommand \index{<file>.cdb}
28331
28332 \end_inset
28333
28334  file from the .adb
28335 \begin_inset LatexCommand \index{<file>.adb}
28336
28337 \end_inset
28338
28339  files and the address information.
28340  This .cdb is used by the debugger.
28341 \end_layout
28342
28343 \begin_layout Subsection
28344 How the Debugger Works
28345 \end_layout
28346
28347 \begin_layout Standard
28348 When the -
28349 \begin_inset ERT
28350 status collapsed
28351
28352 \begin_layout Standard
28353
28354
28355 \backslash
28356 /
28357 \end_layout
28358
28359 \end_inset
28360
28361 -debug option is specified the compiler generates extra symbol information
28362  some of which are put into the assembler source and some are put into the
28363  .adb file.
28364  Then the linker creates the .cdb file from the individual .adb files with
28365  the address information for the symbols.
28366  The debugger reads the symbolic information generated by the compiler &
28367  the address information generated by the linker.
28368  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28369  execution is controlled by the debugger.
28370  When a command is issued for the debugger, it translates it into appropriate
28371  commands for the simulator.
28372  (Currently SDCDM only connects to the simulator but 
28373 \emph on
28374 newcdb
28375 \emph default
28376  at 
28377 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28378
28379 \end_inset
28380
28381  is an effort to connect directly to the hardware.) 
28382 \end_layout
28383
28384 \begin_layout Subsection
28385 Starting the Debugger SDCDB
28386 \end_layout
28387
28388 \begin_layout Standard
28389 The debugger can be started using the following command line.
28390  (Assume the file you are debugging has the file name foo).
28391 \newline
28392
28393 \newline
28394
28395 \family sans
28396 \series bold
28397 sdcdb foo
28398 \newline
28399
28400 \family default
28401 \series default
28402
28403 \newline
28404 The debugger will look for the following files.
28405 \end_layout
28406
28407 \begin_layout Itemize
28408 foo.c - the source file.
28409 \end_layout
28410
28411 \begin_layout Itemize
28412 foo.cdb - the debugger symbol information file.
28413 \end_layout
28414
28415 \begin_layout Itemize
28416 foo.ihx - the Intel hex format
28417 \begin_inset LatexCommand \index{Intel hex format}
28418
28419 \end_inset
28420
28421  object file.
28422 \end_layout
28423
28424 \begin_layout Subsection
28425 SDCDB Command Line Options
28426 \end_layout
28427
28428 \begin_layout Itemize
28429 -
28430 \begin_inset ERT
28431 status collapsed
28432
28433 \begin_layout Standard
28434
28435
28436 \backslash
28437 /
28438 \end_layout
28439
28440 \end_inset
28441
28442 -directory=<source file directory> this option can used to specify the directory
28443  search list.
28444  The debugger will look into the directory list specified for source, cdb
28445  & ihx files.
28446  The items in the directory list must be separated by ':', e.g.
28447  if the source files can be in the directories /home/src1 and /home/src2,
28448  the -
28449 \begin_inset ERT
28450 status collapsed
28451
28452 \begin_layout Standard
28453
28454
28455 \backslash
28456 /
28457 \end_layout
28458
28459 \end_inset
28460
28461 -directory option should be -
28462 \begin_inset ERT
28463 status collapsed
28464
28465 \begin_layout Standard
28466
28467
28468 \backslash
28469 /
28470 \end_layout
28471
28472 \end_inset
28473
28474 -directory=/home/src1:/home/src2.
28475  Note there can be no spaces in the option.
28476  
28477 \end_layout
28478
28479 \begin_layout Itemize
28480 -cd <directory> - change to the <directory>.
28481 \end_layout
28482
28483 \begin_layout Itemize
28484 -fullname - used by GUI front ends.
28485 \end_layout
28486
28487 \begin_layout Itemize
28488 -cpu <cpu-type> - this argument is passed to the simulator please see the
28489  simulator docs for details.
28490 \end_layout
28491
28492 \begin_layout Itemize
28493 -X <Clock frequency > this options is passed to the simulator please see
28494  the simulator docs for details.
28495 \end_layout
28496
28497 \begin_layout Itemize
28498 -s <serial port file> passed to simulator see the simulator docs for details.
28499 \end_layout
28500
28501 \begin_layout Itemize
28502 -S <serial in,out> passed to simulator see the simulator docs for details.
28503 \end_layout
28504
28505 \begin_layout Itemize
28506 -k <port number> passed to simulator see the simulator docs for details.
28507 \end_layout
28508
28509 \begin_layout Subsection
28510 SDCDB Debugger Commands
28511 \end_layout
28512
28513 \begin_layout Standard
28514 As mentioned earlier the command interface for the debugger has been deliberatel
28515 y kept as close the GNU debugger gdb, as possible.
28516  This will help the integration with existing graphical user interfaces
28517  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28518  If you use a graphical user interface for the debugger you can skip this
28519  section.
28520 \end_layout
28521
28522 \begin_layout Subsubsection*
28523 break [line | file:line | function | file:function]
28524 \end_layout
28525
28526 \begin_layout Standard
28527 Set breakpoint at specified line or function:
28528 \newline
28529
28530 \newline
28531
28532 \family sans
28533 \series bold
28534 sdcdb>break 100 
28535 \newline
28536 sdcdb>break foo.c:100
28537 \newline
28538 sdcdb>break funcfoo
28539 \newline
28540 sdcdb>break foo.c:funcfoo
28541 \end_layout
28542
28543 \begin_layout Subsubsection*
28544 clear [line | file:line | function | file:function ]
28545 \end_layout
28546
28547 \begin_layout Standard
28548 Clear breakpoint at specified line or function:
28549 \newline
28550
28551 \newline
28552
28553 \family sans
28554 \series bold
28555 sdcdb>clear 100
28556 \newline
28557 sdcdb>clear foo.c:100
28558 \newline
28559 sdcdb>clear funcfoo
28560 \newline
28561 sdcdb>clear foo.c:funcfoo
28562 \end_layout
28563
28564 \begin_layout Subsubsection*
28565 continue
28566 \end_layout
28567
28568 \begin_layout Standard
28569 Continue program being debugged, after breakpoint.
28570 \end_layout
28571
28572 \begin_layout Subsubsection*
28573 finish
28574 \end_layout
28575
28576 \begin_layout Standard
28577 Execute till the end of the current function.
28578 \end_layout
28579
28580 \begin_layout Subsubsection*
28581 delete [n]
28582 \end_layout
28583
28584 \begin_layout Standard
28585 Delete breakpoint number 'n'.
28586  If used without any option clear ALL user defined break points.
28587 \end_layout
28588
28589 \begin_layout Subsubsection*
28590 info [break | stack | frame | registers ]
28591 \end_layout
28592
28593 \begin_layout Itemize
28594 info break - list all breakpoints
28595 \end_layout
28596
28597 \begin_layout Itemize
28598 info stack - show the function call stack.
28599 \end_layout
28600
28601 \begin_layout Itemize
28602 info frame - show information about the current execution frame.
28603 \end_layout
28604
28605 \begin_layout Itemize
28606 info registers - show content of all registers.
28607 \end_layout
28608
28609 \begin_layout Subsubsection*
28610 step
28611 \end_layout
28612
28613 \begin_layout Standard
28614 Step program until it reaches a different source line.
28615  Note: pressing <return> repeats the last command.
28616 \end_layout
28617
28618 \begin_layout Subsubsection*
28619 next
28620 \end_layout
28621
28622 \begin_layout Standard
28623 Step program, proceeding through subroutine calls.
28624 \end_layout
28625
28626 \begin_layout Subsubsection*
28627 run
28628 \end_layout
28629
28630 \begin_layout Standard
28631 Start debugged program.
28632 \end_layout
28633
28634 \begin_layout Subsubsection*
28635 ptype variable 
28636 \end_layout
28637
28638 \begin_layout Standard
28639 Print type information of the variable.
28640 \end_layout
28641
28642 \begin_layout Subsubsection*
28643 print variable
28644 \end_layout
28645
28646 \begin_layout Standard
28647 print value of variable.
28648 \end_layout
28649
28650 \begin_layout Subsubsection*
28651 file filename
28652 \end_layout
28653
28654 \begin_layout Standard
28655 load the given file name.
28656  Note this is an alternate method of loading file for debugging.
28657 \end_layout
28658
28659 \begin_layout Subsubsection*
28660 frame
28661 \end_layout
28662
28663 \begin_layout Standard
28664 print information about current frame.
28665 \end_layout
28666
28667 \begin_layout Subsubsection*
28668 set srcmode
28669 \end_layout
28670
28671 \begin_layout Standard
28672 Toggle between C source & assembly source.
28673 \end_layout
28674
28675 \begin_layout Subsubsection*
28676 ! simulator command
28677 \end_layout
28678
28679 \begin_layout Standard
28680 Send the string following '!' to the simulator, the simulator response is
28681  displayed.
28682  Note the debugger does not interpret the command being sent to the simulator,
28683  so if a command like 'go' is sent the debugger can loose its execution
28684  context and may display incorrect values.
28685 \end_layout
28686
28687 \begin_layout Subsubsection*
28688 quit
28689 \end_layout
28690
28691 \begin_layout Standard
28692 "Watch me now.
28693  Iam going Down.
28694  My name is Bobby Brown"
28695 \end_layout
28696
28697 \begin_layout Subsection
28698 Interfacing SDCDB with DDD
28699 \end_layout
28700
28701 \begin_layout Standard
28702 \begin_inset Note Note
28703 status collapsed
28704
28705 \begin_layout Standard
28706 The screenshot was converted from png to eps with: 
28707 \begin_inset Quotes sld
28708 \end_inset
28709
28710 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28711 \begin_inset Quotes srd
28712 \end_inset
28713
28714  which produces a pretty compact eps file which is free from compression
28715  artifacts.
28716 \end_layout
28717
28718 \begin_layout Standard
28719 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28720  as this broke the build system on Sourceforge (pdf-file was broken.
28721  pdflatex does not accept eps files).
28722 \end_layout
28723
28724 \end_inset
28725
28726
28727 \end_layout
28728
28729 \begin_layout Standard
28730 The 
28731 \emph on
28732 p
28733 \emph default
28734 ortable 
28735 \emph on
28736 n
28737 \emph default
28738 etwork 
28739 \emph on
28740 g
28741 \emph default
28742 raphics File 
28743 \size footnotesize
28744
28745 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28746
28747 \end_inset
28748
28749
28750 \size default
28751  shows a screenshot of a debugging session with DDD
28752 \begin_inset LatexCommand \index{DDD (debugger)}
28753
28754 \end_inset
28755
28756  (Unix only) on a simulated 8032.
28757  The debugging session might not run as smoothly as the screenshot suggests.
28758  The debugger allows setting of breakpoints, displaying and changing variables,
28759  single stepping through C and assembler code.
28760  
28761 \newline
28762 The source was compiled with 
28763 \family sans
28764 \series bold
28765
28766 \newline
28767
28768 \newline
28769 sdcc -
28770 \family default
28771 \series default
28772
28773 \begin_inset ERT
28774 status collapsed
28775
28776 \begin_layout Standard
28777
28778
28779 \backslash
28780 /
28781 \end_layout
28782
28783 \end_inset
28784
28785
28786 \family sans
28787 \series bold
28788 -debug ddd_example.c
28789 \family default
28790 \series default
28791  
28792 \family sans
28793 \series bold
28794
28795 \newline
28796
28797 \family default
28798 \series default
28799
28800 \newline
28801 and DDD was invoked with 
28802 \family sans
28803 \series bold
28804
28805 \newline
28806
28807 \newline
28808 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28809 \end_layout
28810
28811 \begin_layout Standard
28812 \begin_inset Note Note
28813 status open
28814
28815 \begin_layout Standard
28816 Check that the double quotes or an apostroph within the command line survive
28817  the LyX tool chain.
28818  Previously the apostrophs got slanted in the PDF output so a cut and paste
28819  did not work.
28820 \end_layout
28821
28822 \end_inset
28823
28824
28825 \end_layout
28826
28827 \begin_layout Subsection
28828 Interfacing SDCDB with XEmacs
28829 \begin_inset LatexCommand \index{XEmacs}
28830
28831 \end_inset
28832
28833
28834 \begin_inset LatexCommand \index{Emacs}
28835
28836 \end_inset
28837
28838
28839 \end_layout
28840
28841 \begin_layout Standard
28842 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28843  sdcdb.el and sdcdbsrc.el.
28844  These two files can be found in the $(prefix)/bin directory after the installat
28845 ion is complete.
28846  These files need to be loaded into XEmacs for the interface to work.
28847  This can be done at XEmacs startup time by inserting the following into
28848  your '.xemacs' file (which can be found in your HOME directory): 
28849 \newline
28850
28851 \newline
28852
28853 \family typewriter
28854 (load-file sdcdbsrc.el) 
28855 \family default
28856
28857 \newline
28858
28859 \newline
28860 .xemacs is a lisp file so the () around the command is REQUIRED.
28861  The files can also be loaded dynamically while XEmacs is running, set the
28862  environment variable 'EMACSLOADPATH' to the installation bin directory
28863  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28864  To start the interface enter the following command: 
28865 \newline
28866
28867 \newline
28868
28869 \family sans
28870 \series bold
28871 ESC-x sdcdbsrc
28872 \family default
28873 \series default
28874
28875 \newline
28876
28877 \newline
28878 You will prompted to enter the file name to be debugged.
28879  
28880 \newline
28881
28882 \newline
28883 The command line options that are passed to the simulator directly are
28884  bound to default values in the file sdcdbsrc.el.
28885  The variables are listed below, these values maybe changed as required.
28886 \end_layout
28887
28888 \begin_layout Itemize
28889 sdcdbsrc-cpu-type '51
28890 \end_layout
28891
28892 \begin_layout Itemize
28893 sdcdbsrc-frequency '11059200
28894 \end_layout
28895
28896 \begin_layout Itemize
28897 sdcdbsrc-serial nil
28898 \end_layout
28899
28900 \begin_layout Standard
28901 The following is a list of key mapping for the debugger interface.
28902 \end_layout
28903
28904 \begin_layout Standard
28905 \InsetSpace ~
28906
28907 \family typewriter
28908
28909 \newline
28910 ;;\InsetSpace ~
28911 Current Listing :: 
28912 \newline
28913 ;;key\InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 binding\InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 Comment 
28950 \newline
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 \InsetSpace ~
28978 \InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 \InsetSpace ~
28987 -------
28988 \newline
28989 ;; 
28990 \newline
28991 ;;\InsetSpace ~
28992 n\InsetSpace ~
28993 \InsetSpace ~
28994 \InsetSpace ~
28995 \InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
29007 sdcdb-next-fro
29008 m-src\InsetSpace ~
29009 \InsetSpace ~
29010 \InsetSpace ~
29011 \InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 \InsetSpace ~
29015 \InsetSpace ~
29016 \InsetSpace ~
29017 \InsetSpace ~
29018 SDCDB next command 
29019 \newline
29020 ;;\InsetSpace ~
29021 b\InsetSpace ~
29022 \InsetSpace ~
29023 \InsetSpace ~
29024 \InsetSpace ~
29025 \InsetSpace ~
29026 \InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 \InsetSpace ~
29035 \InsetSpace ~
29036 sdcdb-back-from-src\InsetSpace ~
29037 \InsetSpace ~
29038 \InsetSpace ~
29039 \InsetSpace ~
29040 \InsetSpace ~
29041 \InsetSpace ~
29042 \InsetSpace ~
29043 \InsetSpace ~
29044 \InsetSpace ~
29045 \InsetSpace ~
29046 SDCDB back command 
29047 \newline
29048 ;;\InsetSpace ~
29049 c\InsetSpace ~
29050 \InsetSpace ~
29051 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 \InsetSpace ~
29055 \InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 sdcdb-cont-f
29065 rom-src\InsetSpace ~
29066 \InsetSpace ~
29067 \InsetSpace ~
29068 \InsetSpace ~
29069 \InsetSpace ~
29070 \InsetSpace ~
29071 \InsetSpace ~
29072 \InsetSpace ~
29073 \InsetSpace ~
29074 \InsetSpace ~
29075 SDCDB continue command
29076 \newline
29077 ;;\InsetSpace ~
29078 s\InsetSpace ~
29079 \InsetSpace ~
29080 \InsetSpace ~
29081 \InsetSpace ~
29082 \InsetSpace ~
29083 \InsetSpace ~
29084 \InsetSpace ~
29085 \InsetSpace ~
29086 \InsetSpace ~
29087 \InsetSpace ~
29088 \InsetSpace ~
29089 \InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 sdcdb-step-from-src\InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 \InsetSpace ~
29097 \InsetSpace ~
29098 \InsetSpace ~
29099 \InsetSpace ~
29100 \InsetSpace ~
29101 \InsetSpace ~
29102 \InsetSpace ~
29103 SDCDB step command 
29104 \newline
29105 ;;\InsetSpace ~
29106 ?\InsetSpace ~
29107 \InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 \InsetSpace ~
29112 \InsetSpace ~
29113 \InsetSpace ~
29114 \InsetSpace ~
29115 \InsetSpace ~
29116 \InsetSpace ~
29117 \InsetSpace ~
29118 \InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 sdcdb-w
29122 hatis-c-sexp\InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 \InsetSpace ~
29131 \InsetSpace ~
29132 SDCDB ptypecommand for data at 
29133 \newline
29134 ;;\InsetSpace ~
29135 \InsetSpace ~
29136 \InsetSpace ~
29137 \InsetSpace ~
29138 \InsetSpace ~
29139 \InsetSpace ~
29140 \InsetSpace ~
29141 \InsetSpace ~
29142 \InsetSpace ~
29143 \InsetSpace ~
29144 \InsetSpace ~
29145 \InsetSpace ~
29146 \InsetSpace ~
29147 \InsetSpace ~
29148 \InsetSpace ~
29149 \InsetSpace ~
29150 \InsetSpace ~
29151 \InsetSpace ~
29152 \InsetSpace ~
29153 \InsetSpace ~
29154 \InsetSpace ~
29155 \InsetSpace ~
29156 \InsetSpace ~
29157 \InsetSpace ~
29158 \InsetSpace ~
29159 \InsetSpace ~
29160 \InsetSpace ~
29161 \InsetSpace ~
29162 \InsetSpace ~
29163 \InsetSpace ~
29164 \InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 \InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 \InsetSpace ~
29173 \InsetSpace ~
29174 \InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 \InsetSpace ~
29178 \InsetSpace ~
29179 \InsetSpace ~
29180 \InsetSpace ~
29181 buffer point 
29182 \newline
29183 ;;\InsetSpace ~
29184 x\InsetSpace ~
29185 \InsetSpace ~
29186 \InsetSpace ~
29187 \InsetSpace ~
29188 \InsetSpace ~
29189 \InsetSpace ~
29190 \InsetSpace ~
29191 \InsetSpace ~
29192 \InsetSpace ~
29193 \InsetSpace ~
29194 \InsetSpace ~
29195 \InsetSpace ~
29196 \InsetSpace ~
29197 \InsetSpace ~
29198 \InsetSpace ~
29199 sdcdbsrc-delete\InsetSpace ~
29200 \InsetSpace ~
29201 \InsetSpace ~
29202 \InsetSpace ~
29203 \InsetSpace ~
29204 \InsetSpace ~
29205 \InsetSpace ~
29206 \InsetSpace ~
29207 \InsetSpace ~
29208 \InsetSpace ~
29209 \InsetSpace ~
29210 \InsetSpace ~
29211 \InsetSpace ~
29212 \InsetSpace ~
29213 SDCD
29214 B Delete all breakpoints if no arg 
29215 \newline
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 \InsetSpace ~
29254 \InsetSpace ~
29255 \InsetSpace ~
29256 \InsetSpace ~
29257 \InsetSpace ~
29258 \InsetSpace ~
29259 \InsetSpace ~
29260 \InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 given or delete arg (C-u arg x) 
29264 \newline
29265 ;;\InsetSpace ~
29266 m\InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 \InsetSpace ~
29271 \InsetSpace ~
29272 \InsetSpace ~
29273 \InsetSpace ~
29274 \InsetSpace ~
29275 \InsetSpace ~
29276 \InsetSpace ~
29277 \InsetSpace ~
29278 \InsetSpace ~
29279 \InsetSpace ~
29280 \InsetSpace ~
29281 sdcdbsrc
29282 -frame\InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288 \InsetSpace ~
29289 \InsetSpace ~
29290 \InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 \InsetSpace ~
29294 \InsetSpace ~
29295 \InsetSpace ~
29296 \InsetSpace ~
29297 SDCDB Display current frame if no arg, 
29298 \newline
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 \InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 \InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 given or display frame arg
29347  
29348 \newline
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 \InsetSpace ~
29387 \InsetSpace ~
29388 \InsetSpace ~
29389 \InsetSpace ~
29390 \InsetSpace ~
29391 \InsetSpace ~
29392 \InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 buffer point 
29397 \newline
29398 ;;\InsetSpace ~
29399 !\InsetSpace ~
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 \InsetSpace ~
29403 \InsetSpace ~
29404 \InsetSpace ~
29405 \InsetSpace ~
29406 \InsetSpace ~
29407 \InsetSpace ~
29408 \InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 sdcdbsrc-goto-sdcdb\InsetSpace ~
29415 \InsetSpace ~
29416 \InsetSpace ~
29417 \InsetSpace ~
29418 \InsetSpace ~
29419 \InsetSpace ~
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 \InsetSpace ~
29424 Goto the SDCDB output buffer 
29425 \newline
29426 ;;\InsetSpace ~
29427 p\InsetSpace ~
29428 \InsetSpace ~
29429 \InsetSpace ~
29430 \InsetSpace ~
29431 \InsetSpace ~
29432 \InsetSpace ~
29433 \InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 \InsetSpace ~
29439 \InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 sdcdb-prin
29443 t-c-sexp\InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 \InsetSpace ~
29447 \InsetSpace ~
29448 \InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 SDCDB print command for data at 
29455 \newline
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 \InsetSpace ~
29494 \InsetSpace ~
29495 \InsetSpace ~
29496 \InsetSpace ~
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500 \InsetSpace ~
29501 \InsetSpace ~
29502 \InsetSpace ~
29503 buffer point 
29504 \newline
29505 ;;\InsetSpace ~
29506 g\InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 \InsetSpace ~
29516 \InsetSpace ~
29517 \InsetSpace ~
29518 \InsetSpace ~
29519 \InsetSpace ~
29520 \InsetSpace ~
29521 sdcdbsrc-goto-sdcdb\InsetSpace ~
29522 \InsetSpace ~
29523 \InsetSpace ~
29524 \InsetSpace ~
29525 \InsetSpace ~
29526 \InsetSpace ~
29527 \InsetSpace ~
29528 \InsetSpace ~
29529 \InsetSpace ~
29530 \InsetSpace ~
29531 Got
29532 o the SDCDB output buffer 
29533 \newline
29534 ;;\InsetSpace ~
29535 t\InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 \InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 \InsetSpace ~
29544 \InsetSpace ~
29545 \InsetSpace ~
29546 \InsetSpace ~
29547 \InsetSpace ~
29548 \InsetSpace ~
29549 \InsetSpace ~
29550 sdcdbsrc-mode\InsetSpace ~
29551 \InsetSpace ~
29552 \InsetSpace ~
29553 \InsetSpace ~
29554 \InsetSpace ~
29555 \InsetSpace ~
29556 \InsetSpace ~
29557 \InsetSpace ~
29558 \InsetSpace ~
29559 \InsetSpace ~
29560 \InsetSpace ~
29561 \InsetSpace ~
29562 \InsetSpace ~
29563 \InsetSpace ~
29564 \InsetSpace ~
29565 \InsetSpace ~
29566 Toggles Sdcdbsrc mode (turns it
29567  off) 
29568 \newline
29569 ;; 
29570 \newline
29571 ;;\InsetSpace ~
29572 C-c\InsetSpace ~
29573 C-f\InsetSpace ~
29574 \InsetSpace ~
29575 \InsetSpace ~
29576 \InsetSpace ~
29577 \InsetSpace ~
29578 \InsetSpace ~
29579 \InsetSpace ~
29580 \InsetSpace ~
29581 \InsetSpace ~
29582 sdcdb-finish-from-src\InsetSpace ~
29583 \InsetSpace ~
29584 \InsetSpace ~
29585 \InsetSpace ~
29586 \InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 SDCDB finish command 
29591 \newline
29592 ;; 
29593 \newline
29594 ;;\InsetSpace ~
29595 C-x\InsetSpace ~
29596 SPC\InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 sdcdb-brea
29606 k\InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 \InsetSpace ~
29618 \InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 Set break for line with point 
29625 \newline
29626 ;;\InsetSpace ~
29627 ESC\InsetSpace ~
29628 t\InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 sdcdbsrc-mode\InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 Toggle Sdcdbsrc mode 
29656 \newline
29657 ;;\InsetSpace ~
29658 ESC\InsetSpace ~
29659 m\InsetSpace ~
29660 \InsetSpace ~
29661 \InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 sdc
29671 dbsrc-srcmode\InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 \InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 Toggle list mode 
29685 \newline
29686 ;; 
29687 \newline
29688
29689 \family default
29690
29691 \newpage
29692
29693 \end_layout
29694
29695 \begin_layout Chapter
29696 TIPS
29697 \end_layout
29698
29699 \begin_layout Standard
29700 Here are a few guidelines that will help the compiler generate more efficient
29701  code, some of the tips are specific to this compiler others are generally
29702  good programming practice.
29703 \end_layout
29704
29705 \begin_layout Itemize
29706 Use the smallest data type to represent your data-value.
29707  If it is known in advance that the value is going to be less than 256 then
29708  use an 'unsigned char' instead of a 'short' or 'int'.
29709  Please note, that ANSI C requires both signed and unsigned chars to be
29710  promoted to 'signed int'
29711 \begin_inset LatexCommand \index{promotion to signed int}
29712
29713 \end_inset
29714
29715
29716 \begin_inset Marginal
29717 status collapsed
29718
29719 \begin_layout Standard
29720
29721 \series bold
29722 \InsetSpace ~
29723 !
29724 \end_layout
29725
29726 \end_inset
29727
29728  before doing any operation.
29729  This promotion
29730 \begin_inset LatexCommand \index{type promotion}
29731
29732 \end_inset
29733
29734
29735 \begin_inset LatexCommand \label{type promotion}
29736
29737 \end_inset
29738
29739  can be omitted, if the result is the same.
29740  The effect of the promotion rules together with the sign-extension is often
29741  surprising:
29742 \end_layout
29743
29744 \begin_deeper
29745 \begin_layout Verse
29746
29747 \family typewriter
29748 unsigned char uc = 0xfe;
29749 \newline
29750 if (uc * uc < 0) /* this is true! */
29751 \newline
29752 {
29753 \newline
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 ....
29759 \newline
29760 }
29761 \end_layout
29762
29763 \begin_layout Standard
29764
29765 \family typewriter
29766 uc * uc
29767 \family default
29768  is evaluated as 
29769 \family typewriter
29770 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29771 \family default
29772 .
29773  
29774 \newline
29775 Another one:
29776 \end_layout
29777
29778 \begin_layout Verse
29779
29780 \family typewriter
29781 (unsigned char) -12 / (signed char) -3 = ...
29782 \end_layout
29783
29784 \begin_layout Standard
29785 No, the result is not 4:
29786 \end_layout
29787
29788 \begin_layout Verse
29789
29790 \family typewriter
29791 (int) (unsigned char) -12 / (int) (signed char) -3 =
29792 \newline
29793 (int) (unsigned char)
29794  0xf4 / (int) (signed char) 0xfd =
29795 \newline
29796 (int) 0x00f4 / (int) 0xfffd =
29797 \newline
29798 (int) 0x00f4
29799  / (int) 0xfffd =
29800 \newline
29801 (int) 244 / (int) -3 =
29802 \newline
29803 (int) -81 = (int) 0xffaf;
29804 \end_layout
29805
29806 \begin_layout Standard
29807 Don't complain, that gcc gives you a different result.
29808  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29809  Therefore the results are different.
29810 \newline
29811 From 
29812 \begin_inset Quotes sld
29813 \end_inset
29814
29815 comp.lang.c FAQ
29816 \begin_inset Quotes srd
29817 \end_inset
29818
29819 :
29820 \end_layout
29821
29822 \begin_layout Quote
29823
29824 \emph on
29825 If well-defined overflow characteristics are important and negative values
29826  are not, or if you want to steer clear of sign-extension problems when
29827  manipulating bits or bytes, use one of the corresponding unsigned types.
29828  (Beware when mixing signed and unsigned values in expressions, though.)
29829 \newline
29830 Although
29831  character types (especially unsigned char) can be used as "tiny" integers,
29832  doing so is sometimes more trouble than it's worth, due to unpredictable
29833  sign extension and increased code size.
29834 \end_layout
29835
29836 \end_deeper
29837 \begin_layout Itemize
29838 Use unsigned when it is known in advance that the value is not going to
29839  be negative.
29840  This helps especially if you are doing division or multiplication, bit-shifting
29841  or are using an array index.
29842 \end_layout
29843
29844 \begin_layout Itemize
29845 NEVER jump into a LOOP.
29846 \end_layout
29847
29848 \begin_layout Itemize
29849 Declare the variables to be local
29850 \begin_inset LatexCommand \index{local variables}
29851
29852 \end_inset
29853
29854  whenever possible, especially loop control variables (induction).
29855 \end_layout
29856
29857 \begin_layout Itemize
29858 Have a look at the assembly listing to get a 
29859 \begin_inset Quotes sld
29860 \end_inset
29861
29862 feeling
29863 \begin_inset Quotes srd
29864 \end_inset
29865
29866  for the code generation.
29867 \end_layout
29868
29869 \begin_layout Section
29870 Porting code from or to other compilers
29871 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29872
29873 \end_inset
29874
29875
29876 \end_layout
29877
29878 \begin_layout Itemize
29879 check whether endianness of the compilers differs and adapt where needed.
29880 \end_layout
29881
29882 \begin_layout Itemize
29883 check the device specific header files
29884 \begin_inset LatexCommand \index{Header files}
29885
29886 \end_inset
29887
29888
29889 \begin_inset LatexCommand \index{Include files}
29890
29891 \end_inset
29892
29893  for compiler specific syntax.
29894  Eventually include the file <compiler.h
29895 \begin_inset LatexCommand \index{compiler.h (include file)}
29896
29897 \end_inset
29898
29899
29900 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29901
29902 \end_inset
29903
29904  to allow using common header files.
29905  (see f.e.
29906  cc2510fx.h 
29907 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29908
29909 \end_inset
29910
29911 ).
29912 \end_layout
29913
29914 \begin_layout Itemize
29915 check whether the startup code contains the correct initialization (watchdog,
29916  peripherals).
29917 \end_layout
29918
29919 \begin_layout Itemize
29920 check whether the sizes of short, int, long match.
29921 \end_layout
29922
29923 \begin_layout Itemize
29924 check if some 16 or 32 bit hardware registers require a specific addressing
29925  order (least significant or most significant byte first) and adapt if needed
29926  (
29927 \emph on
29928 first
29929 \emph default
29930  and 
29931 \emph on
29932 last
29933 \emph default
29934  relate to time and not to lower/upper memory location here, so this is
29935  
29936 \emph on
29937 not
29938 \emph default
29939  the same as endianness).
29940 \end_layout
29941
29942 \begin_layout Itemize
29943 check whether the keyword 
29944 \emph on
29945 volatile
29946 \emph default
29947  is used where needed.
29948  The compilers might differ in their optimization characteristics (as different
29949  versions of the same compiler might also use more clever optimizations
29950  this is good idea anyway).
29951  See section 
29952 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29953
29954 \end_inset
29955
29956 .
29957 \end_layout
29958
29959 \begin_layout Itemize
29960 check that the compilers are not told to supress warnings.
29961 \end_layout
29962
29963 \begin_layout Itemize
29964 check and convert compiler specific extensions (interrupts, memory areas,
29965  pragmas etc.).
29966 \end_layout
29967
29968 \begin_layout Itemize
29969 check for differences in type promotion.
29970  Especially check for math operations on 
29971 \family typewriter
29972 char
29973 \family default
29974  or 
29975 \family typewriter
29976 unsigned char
29977 \family default
29978  variables.
29979  For the sake of C99 compatibility SDCC will probably promote these to 
29980 \family typewriter
29981 int
29982 \family default
29983  more often than other compilers.
29984  Eventually insert explicit casts to 
29985 \family typewriter
29986 (char) 
29987 \family default
29988 or
29989 \family typewriter
29990  (unsigned char)
29991 \family default
29992 .
29993  Also check that the ~\InsetSpace ~
29994 operator
29995 \begin_inset LatexCommand \index{\~\/ Operator}
29996
29997 \end_inset
29998
29999  is not used on 
30000 \family typewriter
30001 bit
30002 \begin_inset LatexCommand \index{bit}
30003
30004 \end_inset
30005
30006
30007 \family default
30008  variables, use the !\InsetSpace ~
30009 operator instead.
30010  See sections 
30011 \begin_inset LatexCommand \ref{type promotion}
30012
30013 \end_inset
30014
30015  and 
30016 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30017
30018 \end_inset
30019
30020 .
30021 \end_layout
30022
30023 \begin_layout Itemize
30024 check the assembly code generated for interrupt routines (f.e.
30025  for calls to possibly non-reentrant library functions).
30026 \end_layout
30027
30028 \begin_layout Itemize
30029 check whether timing loops result in proper timing (or preferably consider
30030  a rewrite of the code with timer based delays instead).
30031 \end_layout
30032
30033 \begin_layout Itemize
30034 check for differences in printf parameters (some compilers push (va_arg
30035 \begin_inset LatexCommand \index{vararg, va\_arg}
30036
30037 \end_inset
30038
30039 ) char variables as 
30040 \family typewriter
30041 int
30042 \family default
30043  others push them as 
30044 \family typewriter
30045 char
30046 \family default
30047 .
30048  See section 
30049 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30050
30051 \end_inset
30052
30053 ).
30054 \end_layout
30055
30056 \begin_layout Itemize
30057 check the resulting memory map
30058 \begin_inset LatexCommand \index{Memory map}
30059
30060 \end_inset
30061
30062 .
30063  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30064 ly idata, pdata, xdata).
30065  Eventually check if unexpected library functions are included.
30066 \end_layout
30067
30068 \begin_layout Section
30069 Tools
30070 \begin_inset LatexCommand \index{Tools}
30071
30072 \end_inset
30073
30074  included in the distribution
30075 \end_layout
30076
30077 \begin_layout Standard
30078 \align left
30079 \begin_inset Tabular
30080 <lyxtabular version="3" rows="12" columns="3">
30081 <features>
30082 <column alignment="left" valignment="top" leftline="true" width="0pt">
30083 <column alignment="left" valignment="top" leftline="true" width="0pt">
30084 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30085 <row topline="true" bottomline="true">
30086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30087 \begin_inset Text
30088
30089 \begin_layout Standard
30090
30091 \series bold
30092 Name
30093 \end_layout
30094
30095 \end_inset
30096 </cell>
30097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30098 \begin_inset Text
30099
30100 \begin_layout Standard
30101
30102 \series bold
30103 Purpose
30104 \end_layout
30105
30106 \end_inset
30107 </cell>
30108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30109 \begin_inset Text
30110
30111 \begin_layout Standard
30112
30113 \series bold
30114 Directory
30115 \end_layout
30116
30117 \end_inset
30118 </cell>
30119 </row>
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30122 \begin_inset Text
30123
30124 \begin_layout Standard
30125 uCsim
30126 \begin_inset LatexCommand \index{uCsim}
30127
30128 \end_inset
30129
30130
30131 \end_layout
30132
30133 \end_inset
30134 </cell>
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30136 \begin_inset Text
30137
30138 \begin_layout Standard
30139 Simulator for various architectures
30140 \end_layout
30141
30142 \end_inset
30143 </cell>
30144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30145 \begin_inset Text
30146
30147 \begin_layout Standard
30148 sdcc/sim/ucsim
30149 \end_layout
30150
30151 \end_inset
30152 </cell>
30153 </row>
30154 <row topline="true">
30155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30156 \begin_inset Text
30157
30158 \begin_layout Standard
30159 keil2sdcc.pl
30160 \end_layout
30161
30162 \end_inset
30163 </cell>
30164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30165 \begin_inset Text
30166
30167 \begin_layout Standard
30168 header file
30169 \begin_inset LatexCommand \index{Header files}
30170
30171 \end_inset
30172
30173
30174 \begin_inset LatexCommand \index{Include files}
30175
30176 \end_inset
30177
30178  conversion
30179 \end_layout
30180
30181 \end_inset
30182 </cell>
30183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30184 \begin_inset Text
30185
30186 \begin_layout Standard
30187 sdcc/support/scripts
30188 \end_layout
30189
30190 \end_inset
30191 </cell>
30192 </row>
30193 <row topline="true">
30194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30195 \begin_inset Text
30196
30197 \begin_layout Standard
30198 mh2h.c
30199 \end_layout
30200
30201 \end_inset
30202 </cell>
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30204 \begin_inset Text
30205
30206 \begin_layout Standard
30207 header file conversion
30208 \end_layout
30209
30210 \end_inset
30211 </cell>
30212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30213 \begin_inset Text
30214
30215 \begin_layout Standard
30216 sdcc/support/scripts
30217 \end_layout
30218
30219 \end_inset
30220 </cell>
30221 </row>
30222 <row topline="true">
30223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30224 \begin_inset Text
30225
30226 \begin_layout Standard
30227 as-gbz80
30228 \end_layout
30229
30230 \end_inset
30231 </cell>
30232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30233 \begin_inset Text
30234
30235 \begin_layout Standard
30236 Assembler
30237 \end_layout
30238
30239 \end_inset
30240 </cell>
30241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30242 \begin_inset Text
30243
30244 \begin_layout Standard
30245
30246 \family roman
30247 \series medium
30248 \shape up
30249 \size normal
30250 \emph off
30251 \bar no
30252 \noun off
30253 \color none
30254 sdcc/bin
30255 \end_layout
30256
30257 \end_inset
30258 </cell>
30259 </row>
30260 <row topline="true">
30261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30262 \begin_inset Text
30263
30264 \begin_layout Standard
30265 as-z80
30266 \end_layout
30267
30268 \end_inset
30269 </cell>
30270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30271 \begin_inset Text
30272
30273 \begin_layout Standard
30274 Assembler
30275 \end_layout
30276
30277 \end_inset
30278 </cell>
30279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30280 \begin_inset Text
30281
30282 \begin_layout Standard
30283
30284 \family roman
30285 \series medium
30286 \shape up
30287 \size normal
30288 \emph off
30289 \bar no
30290 \noun off
30291 \color none
30292 sdcc/bin
30293 \end_layout
30294
30295 \end_inset
30296 </cell>
30297 </row>
30298 <row topline="true">
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30300 \begin_inset Text
30301
30302 \begin_layout Standard
30303 asx8051
30304 \end_layout
30305
30306 \end_inset
30307 </cell>
30308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30309 \begin_inset Text
30310
30311 \begin_layout Standard
30312 Assembler
30313 \end_layout
30314
30315 \end_inset
30316 </cell>
30317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30318 \begin_inset Text
30319
30320 \begin_layout Standard
30321
30322 \family roman
30323 \series medium
30324 \shape up
30325 \size normal
30326 \emph off
30327 \bar no
30328 \noun off
30329 \color none
30330 sdcc/bin
30331 \end_layout
30332
30333 \end_inset
30334 </cell>
30335 </row>
30336 <row topline="true">
30337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30338 \begin_inset Text
30339
30340 \begin_layout Standard
30341 SDCDB
30342 \end_layout
30343
30344 \end_inset
30345 </cell>
30346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30347 \begin_inset Text
30348
30349 \begin_layout Standard
30350 Simulator
30351 \end_layout
30352
30353 \end_inset
30354 </cell>
30355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30356 \begin_inset Text
30357
30358 \begin_layout Standard
30359
30360 \family roman
30361 \series medium
30362 \shape up
30363 \size normal
30364 \emph off
30365 \bar no
30366 \noun off
30367 \color none
30368 sdcc/bin
30369 \end_layout
30370
30371 \end_inset
30372 </cell>
30373 </row>
30374 <row topline="true">
30375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30376 \begin_inset Text
30377
30378 \begin_layout Standard
30379 aslink
30380 \end_layout
30381
30382 \end_inset
30383 </cell>
30384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30385 \begin_inset Text
30386
30387 \begin_layout Standard
30388 Linker
30389 \end_layout
30390
30391 \end_inset
30392 </cell>
30393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30394 \begin_inset Text
30395
30396 \begin_layout Standard
30397
30398 \family roman
30399 \series medium
30400 \shape up
30401 \size normal
30402 \emph off
30403 \bar no
30404 \noun off
30405 \color none
30406 sdcc/bin
30407 \end_layout
30408
30409 \end_inset
30410 </cell>
30411 </row>
30412 <row topline="true">
30413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30414 \begin_inset Text
30415
30416 \begin_layout Standard
30417 link-z80
30418 \end_layout
30419
30420 \end_inset
30421 </cell>
30422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30423 \begin_inset Text
30424
30425 \begin_layout Standard
30426 Linker
30427 \end_layout
30428
30429 \end_inset
30430 </cell>
30431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30432 \begin_inset Text
30433
30434 \begin_layout Standard
30435
30436 \family roman
30437 \series medium
30438 \shape up
30439 \size normal
30440 \emph off
30441 \bar no
30442 \noun off
30443 \color none
30444 sdcc/bin
30445 \end_layout
30446
30447 \end_inset
30448 </cell>
30449 </row>
30450 <row topline="true">
30451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30452 \begin_inset Text
30453
30454 \begin_layout Standard
30455 link-gbz80
30456 \end_layout
30457
30458 \end_inset
30459 </cell>
30460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30461 \begin_inset Text
30462
30463 \begin_layout Standard
30464 Linker
30465 \end_layout
30466
30467 \end_inset
30468 </cell>
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30470 \begin_inset Text
30471
30472 \begin_layout Standard
30473
30474 \family roman
30475 \series medium
30476 \shape up
30477 \size normal
30478 \emph off
30479 \bar no
30480 \noun off
30481 \color none
30482 sdcc/bin
30483 \end_layout
30484
30485 \end_inset
30486 </cell>
30487 </row>
30488 <row topline="true" bottomline="true">
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30490 \begin_inset Text
30491
30492 \begin_layout Standard
30493 packihx
30494 \end_layout
30495
30496 \end_inset
30497 </cell>
30498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30499 \begin_inset Text
30500
30501 \begin_layout Standard
30502 Intel Hex packer 
30503 \begin_inset LatexCommand \index{packihx (tool)}
30504
30505 \end_inset
30506
30507
30508 \end_layout
30509
30510 \end_inset
30511 </cell>
30512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30513 \begin_inset Text
30514
30515 \begin_layout Standard
30516
30517 \family roman
30518 \series medium
30519 \shape up
30520 \size normal
30521 \emph off
30522 \bar no
30523 \noun off
30524 \color none
30525 sdcc/bin
30526 \end_layout
30527
30528 \end_inset
30529 </cell>
30530 </row>
30531 </lyxtabular>
30532
30533 \end_inset
30534
30535
30536 \newline
30537
30538 \end_layout
30539
30540 \begin_layout Section
30541 Documentation
30542 \begin_inset LatexCommand \index{Documentation}
30543
30544 \end_inset
30545
30546  included in the distribution
30547 \end_layout
30548
30549 \begin_layout Standard
30550 \align left
30551 \begin_inset Tabular
30552 <lyxtabular version="3" rows="10" columns="2">
30553 <features>
30554 <column alignment="block" valignment="top" leftline="true" width="40col%">
30555 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30556 <row topline="true" bottomline="true" endhead="true">
30557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30558 \begin_inset Text
30559
30560 \begin_layout Standard
30561
30562 \series bold
30563 Subject / Title
30564 \end_layout
30565
30566 \end_inset
30567 </cell>
30568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30569 \begin_inset Text
30570
30571 \begin_layout Standard
30572
30573 \series bold
30574 Filename / Where to get
30575 \end_layout
30576
30577 \end_inset
30578 </cell>
30579 </row>
30580 <row topline="true">
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30582 \begin_inset Text
30583
30584 \begin_layout Standard
30585 SDCC Compiler User Guide
30586 \end_layout
30587
30588 \end_inset
30589 </cell>
30590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30591 \begin_inset Text
30592
30593 \begin_layout Standard
30594 You're reading it right now
30595 \emph on
30596  \InsetSpace ~
30597 \InsetSpace ~
30598 \InsetSpace ~
30599
30600 \hfill
30601 online at:
30602 \emph default
30603
30604 \newline
30605
30606 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30607
30608 \end_inset
30609
30610
30611 \end_layout
30612
30613 \end_inset
30614 </cell>
30615 </row>
30616 <row topline="true">
30617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30618 \begin_inset Text
30619
30620 \begin_layout Standard
30621 Changelog of SDCC
30622 \end_layout
30623
30624 \end_inset
30625 </cell>
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30627 \begin_inset Text
30628
30629 \begin_layout Standard
30630 sdcc/Changelog
30631 \emph on
30632  \InsetSpace ~
30633 \InsetSpace ~
30634 \InsetSpace ~
30635
30636 \hfill
30637 online at:
30638 \emph default
30639
30640 \newline
30641
30642 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30643
30644 \end_inset
30645
30646
30647 \end_layout
30648
30649 \end_inset
30650 </cell>
30651 </row>
30652 <row topline="true">
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30654 \begin_inset Text
30655
30656 \begin_layout Standard
30657 ASXXXX
30658 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30659
30660 \end_inset
30661
30662
30663 \begin_inset LatexCommand \index{Assembler documentation}
30664
30665 \end_inset
30666
30667  Assemblers and
30668 \newline
30669 ASLINK
30670 \begin_inset LatexCommand \index{aslink}
30671
30672 \end_inset
30673
30674
30675 \begin_inset LatexCommand \index{Linker documentation}
30676
30677 \end_inset
30678
30679  Relocating Linker
30680 \end_layout
30681
30682 \end_inset
30683 </cell>
30684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30685 \begin_inset Text
30686
30687 \begin_layout Standard
30688 sdcc/as/doc/asxhtm.html 
30689 \emph on
30690 \InsetSpace ~
30691 \InsetSpace ~
30692 \InsetSpace ~
30693
30694 \hfill
30695 online at:
30696 \emph default
30697
30698 \newline
30699
30700 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30701
30702 \end_inset
30703
30704
30705 \end_layout
30706
30707 \end_inset
30708 </cell>
30709 </row>
30710 <row topline="true">
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30712 \begin_inset Text
30713
30714 \begin_layout Standard
30715 SDCC regression test
30716 \begin_inset LatexCommand \index{Regression test}
30717
30718 \end_inset
30719
30720
30721 \end_layout
30722
30723 \end_inset
30724 </cell>
30725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30726 \begin_inset Text
30727
30728 \begin_layout Standard
30729 sdcc/doc/test_suite_spec.pdf 
30730 \emph on
30731 \InsetSpace ~
30732 \InsetSpace ~
30733 \InsetSpace ~
30734
30735 \hfill
30736 online at:
30737 \emph default
30738
30739 \newline
30740
30741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30742
30743 \end_inset
30744
30745
30746 \end_layout
30747
30748 \end_inset
30749 </cell>
30750 </row>
30751 <row topline="true">
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30753 \begin_inset Text
30754
30755 \begin_layout Standard
30756 Various notes
30757 \end_layout
30758
30759 \end_inset
30760 </cell>
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30762 \begin_inset Text
30763
30764 \begin_layout Standard
30765 sdcc/doc/* 
30766 \emph on
30767 \InsetSpace ~
30768 \InsetSpace ~
30769 \InsetSpace ~
30770
30771 \hfill
30772 online at:
30773 \emph default
30774
30775 \newline
30776
30777 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30778
30779 \end_inset
30780
30781
30782 \end_layout
30783
30784 \end_inset
30785 </cell>
30786 </row>
30787 <row topline="true">
30788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30789 \begin_inset Text
30790
30791 \begin_layout Standard
30792 Notes on debugging with SDCDB
30793 \begin_inset LatexCommand \index{SDCDB (debugger)}
30794
30795 \end_inset
30796
30797
30798 \end_layout
30799
30800 \end_inset
30801 </cell>
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30803 \begin_inset Text
30804
30805 \begin_layout Standard
30806 sdcc/debugger/README 
30807 \emph on
30808 \InsetSpace ~
30809 \InsetSpace ~
30810 \InsetSpace ~
30811
30812 \hfill
30813 online at
30814 \emph default
30815 :
30816 \newline
30817
30818 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30819
30820 \end_inset
30821
30822
30823 \end_layout
30824
30825 \end_inset
30826 </cell>
30827 </row>
30828 <row topline="true">
30829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30830 \begin_inset Text
30831
30832 \begin_layout Standard
30833 uCsim
30834 \begin_inset LatexCommand \index{uCsim}
30835
30836 \end_inset
30837
30838  Software simulator for microcontrollers
30839 \end_layout
30840
30841 \end_inset
30842 </cell>
30843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30844 \begin_inset Text
30845
30846 \begin_layout Standard
30847
30848 \family roman
30849 \series medium
30850 \shape up
30851 \size normal
30852 \emph off
30853 \bar no
30854 \noun off
30855 \color none
30856 sdcc/sim/ucsim/doc
30857 \family default
30858 \series default
30859 \shape default
30860 \size default
30861 \emph default
30862 \bar default
30863 \noun default
30864 /index.html 
30865 \emph on
30866 \InsetSpace ~
30867 \InsetSpace ~
30868 \InsetSpace ~
30869
30870 \hfill
30871 online at:
30872 \emph default
30873
30874 \newline
30875
30876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30877
30878 \end_inset
30879
30880
30881 \end_layout
30882
30883 \end_inset
30884 </cell>
30885 </row>
30886 <row topline="true">
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30888 \begin_inset Text
30889
30890 \begin_layout Standard
30891 Temporary notes on the pic16
30892 \begin_inset LatexCommand \index{PIC16}
30893
30894 \end_inset
30895
30896  port
30897 \end_layout
30898
30899 \end_inset
30900 </cell>
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30902 \begin_inset Text
30903
30904 \begin_layout Standard
30905 sdcc/src/pic16/NOTES 
30906 \emph on
30907 \InsetSpace ~
30908 \InsetSpace ~
30909 \InsetSpace ~
30910
30911 \hfill
30912 online at:
30913 \newline
30914
30915 \emph default
30916
30917 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30918
30919 \end_inset
30920
30921
30922 \end_layout
30923
30924 \end_inset
30925 </cell>
30926 </row>
30927 <row topline="true" bottomline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \begin_layout Standard
30932 SDCC internal documentation (debugging file format)
30933 \end_layout
30934
30935 \end_inset
30936 </cell>
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30938 \begin_inset Text
30939
30940 \begin_layout Standard
30941 sdcc/doc/
30942 \family roman
30943 \series medium
30944 \shape up
30945 \size normal
30946 \emph off
30947 \bar no
30948 \noun off
30949 \color none
30950 cdbfileformat.pd
30951 \family default
30952 \series default
30953 \shape default
30954 \size default
30955 \emph default
30956 \bar default
30957 \noun default
30958 f
30959 \emph on
30960  \InsetSpace ~
30961 \InsetSpace ~
30962 \InsetSpace ~
30963
30964 \hfill
30965 online at:
30966 \emph default
30967
30968 \newline
30969
30970 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30971
30972 \end_inset
30973
30974
30975 \end_layout
30976
30977 \end_inset
30978 </cell>
30979 </row>
30980 </lyxtabular>
30981
30982 \end_inset
30983
30984
30985 \newline
30986
30987 \end_layout
30988
30989 \begin_layout Section
30990 Related open source tools
30991 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30992
30993 \end_inset
30994
30995
30996 \begin_inset LatexCommand \index{Related tools}
30997
30998 \end_inset
30999
31000
31001 \end_layout
31002
31003 \begin_layout Standard
31004 \align left
31005 \begin_inset Tabular
31006 <lyxtabular version="3" rows="14" columns="3">
31007 <features>
31008 <column alignment="left" valignment="top" leftline="true" width="0pt">
31009 <column alignment="block" valignment="top" leftline="true" width="30line%">
31010 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31011 <row topline="true" bottomline="true">
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31013 \begin_inset Text
31014
31015 \begin_layout Standard
31016
31017 \series bold
31018 Name
31019 \end_layout
31020
31021 \end_inset
31022 </cell>
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027
31028 \series bold
31029 Purpose
31030 \end_layout
31031
31032 \end_inset
31033 </cell>
31034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31035 \begin_inset Text
31036
31037 \begin_layout Standard
31038
31039 \series bold
31040 Where to get
31041 \end_layout
31042
31043 \end_inset
31044 </cell>
31045 </row>
31046 <row topline="true">
31047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31048 \begin_inset Text
31049
31050 \begin_layout Standard
31051 gpsim
31052 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31053
31054 \end_inset
31055
31056
31057 \end_layout
31058
31059 \end_inset
31060 </cell>
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_inset Text
31063
31064 \begin_layout Standard
31065 PIC simulator
31066 \end_layout
31067
31068 \end_inset
31069 </cell>
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \begin_layout Standard
31074 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31075
31076 \end_inset
31077
31078
31079 \end_layout
31080
31081 \end_inset
31082 </cell>
31083 </row>
31084 <row topline="true">
31085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31086 \begin_inset Text
31087
31088 \begin_layout Standard
31089 gputils
31090 \begin_inset LatexCommand \index{gputils (pic tools)}
31091
31092 \end_inset
31093
31094
31095 \end_layout
31096
31097 \end_inset
31098 </cell>
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \begin_layout Standard
31103 GNU PIC utilities
31104 \end_layout
31105
31106 \end_inset
31107 </cell>
31108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31109 \begin_inset Text
31110
31111 \begin_layout Standard
31112 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31113
31114 \end_inset
31115
31116
31117 \end_layout
31118
31119 \end_inset
31120 </cell>
31121 </row>
31122 <row topline="true">
31123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31124 \begin_inset Text
31125
31126 \begin_layout Standard
31127 flP5
31128 \end_layout
31129
31130 \end_inset
31131 </cell>
31132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31133 \begin_inset Text
31134
31135 \begin_layout Standard
31136 PIC programmer
31137 \end_layout
31138
31139 \end_inset
31140 </cell>
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31142 \begin_inset Text
31143
31144 \begin_layout Standard
31145 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31146
31147 \end_inset
31148
31149
31150 \end_layout
31151
31152 \end_inset
31153 </cell>
31154 </row>
31155 <row topline="true">
31156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31157 \begin_inset Text
31158
31159 \begin_layout Standard
31160 ec2drv/newcdb
31161 \end_layout
31162
31163 \end_inset
31164 </cell>
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31166 \begin_inset Text
31167
31168 \begin_layout Standard
31169 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31170  (Unix only)
31171 \end_layout
31172
31173 \end_inset
31174 </cell>
31175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31176 \begin_inset Text
31177
31178 \begin_layout Standard
31179 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31180
31181 \end_inset
31182
31183
31184 \end_layout
31185
31186 \end_inset
31187 </cell>
31188 </row>
31189 <row topline="true">
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31191 \begin_inset Text
31192
31193 \begin_layout Standard
31194 indent
31195 \begin_inset LatexCommand \index{indent (source formatting tool)}
31196
31197 \end_inset
31198
31199
31200 \end_layout
31201
31202 \end_inset
31203 </cell>
31204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31205 \begin_inset Text
31206
31207 \begin_layout Standard
31208 Formats C source - Master of the white spaces
31209 \end_layout
31210
31211 \end_inset
31212 </cell>
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \begin_layout Standard
31217 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31218
31219 \end_inset
31220
31221
31222 \end_layout
31223
31224 \end_inset
31225 </cell>
31226 </row>
31227 <row topline="true">
31228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31229 \begin_inset Text
31230
31231 \begin_layout Standard
31232 srecord
31233 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31234
31235 \end_inset
31236
31237
31238 \end_layout
31239
31240 \end_inset
31241 </cell>
31242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31243 \begin_inset Text
31244
31245 \begin_layout Standard
31246 Object file conversion, checksumming, ...
31247 \end_layout
31248
31249 \end_inset
31250 </cell>
31251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31252 \begin_inset Text
31253
31254 \begin_layout Standard
31255 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31256
31257 \end_inset
31258
31259
31260 \end_layout
31261
31262 \end_inset
31263 </cell>
31264 </row>
31265 <row topline="true">
31266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31267 \begin_inset Text
31268
31269 \begin_layout Standard
31270 objdump
31271 \begin_inset LatexCommand \index{objdump (tool)}
31272
31273 \end_inset
31274
31275
31276 \end_layout
31277
31278 \end_inset
31279 </cell>
31280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31281 \begin_inset Text
31282
31283 \begin_layout Standard
31284 Object file conversion, ...
31285 \end_layout
31286
31287 \end_inset
31288 </cell>
31289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31290 \begin_inset Text
31291
31292 \begin_layout Standard
31293 Part of binutils (should be there anyway)
31294 \end_layout
31295
31296 \end_inset
31297 </cell>
31298 </row>
31299 <row topline="true">
31300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31301 \begin_inset Text
31302
31303 \begin_layout Standard
31304 cmon51
31305 \end_layout
31306
31307 \end_inset
31308 </cell>
31309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31310 \begin_inset Text
31311
31312 \begin_layout Standard
31313 8051 monitor (hex up-/download, single step, disassemble)
31314 \end_layout
31315
31316 \end_inset
31317 </cell>
31318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31319 \begin_inset Text
31320
31321 \begin_layout Standard
31322 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31323
31324 \end_inset
31325
31326
31327 \end_layout
31328
31329 \end_inset
31330 </cell>
31331 </row>
31332 <row topline="true">
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31334 \begin_inset Text
31335
31336 \begin_layout Standard
31337 doxygen
31338 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31339
31340 \end_inset
31341
31342
31343 \end_layout
31344
31345 \end_inset
31346 </cell>
31347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31348 \begin_inset Text
31349
31350 \begin_layout Standard
31351 Source code documentation system
31352 \end_layout
31353
31354 \end_inset
31355 </cell>
31356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31357 \begin_inset Text
31358
31359 \begin_layout Standard
31360 \begin_inset LatexCommand \url{http://www.doxygen.org}
31361
31362 \end_inset
31363
31364
31365 \end_layout
31366
31367 \end_inset
31368 </cell>
31369 </row>
31370 <row topline="true">
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31372 \begin_inset Text
31373
31374 \begin_layout Standard
31375 kdevelop
31376 \end_layout
31377
31378 \end_inset
31379 </cell>
31380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31381 \begin_inset Text
31382
31383 \begin_layout Standard
31384 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31385 \end_layout
31386
31387 \end_inset
31388 </cell>
31389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31390 \begin_inset Text
31391
31392 \begin_layout Standard
31393 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31394
31395 \end_inset
31396
31397
31398 \end_layout
31399
31400 \end_inset
31401 </cell>
31402 </row>
31403 <row topline="true">
31404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31405 \begin_inset Text
31406
31407 \begin_layout Standard
31408 paulmon
31409 \end_layout
31410
31411 \end_inset
31412 </cell>
31413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31414 \begin_inset Text
31415
31416 \begin_layout Standard
31417 8051 monitor (hex up-/download, single step, disassemble)
31418 \end_layout
31419
31420 \end_inset
31421 </cell>
31422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31423 \begin_inset Text
31424
31425 \begin_layout Standard
31426 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31427
31428 \end_inset
31429
31430
31431 \end_layout
31432
31433 \end_inset
31434 </cell>
31435 </row>
31436 <row topline="true">
31437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31438 \begin_inset Text
31439
31440 \begin_layout Standard
31441 splint
31442 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31443
31444 \end_inset
31445
31446
31447 \end_layout
31448
31449 \end_inset
31450 </cell>
31451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31452 \begin_inset Text
31453
31454 \begin_layout Standard
31455 Statically checks c sources (see 
31456 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31457
31458 \end_inset
31459
31460 )
31461 \end_layout
31462
31463 \end_inset
31464 </cell>
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31466 \begin_inset Text
31467
31468 \begin_layout Standard
31469 \begin_inset LatexCommand \url{http://www.splint.org}
31470
31471 \end_inset
31472
31473
31474 \end_layout
31475
31476 \end_inset
31477 </cell>
31478 </row>
31479 <row topline="true" bottomline="true">
31480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31481 \begin_inset Text
31482
31483 \begin_layout Standard
31484 ddd
31485 \begin_inset LatexCommand \index{DDD (debugger)}
31486
31487 \end_inset
31488
31489
31490 \end_layout
31491
31492 \end_inset
31493 </cell>
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31495 \begin_inset Text
31496
31497 \begin_layout Standard
31498 Debugger, serves nicely as GUI to SDCDB
31499 \begin_inset LatexCommand \index{SDCDB (debugger)}
31500
31501 \end_inset
31502
31503  (Unix only)
31504 \end_layout
31505
31506 \end_inset
31507 </cell>
31508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31509 \begin_inset Text
31510
31511 \begin_layout Standard
31512 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31513
31514 \end_inset
31515
31516
31517 \end_layout
31518
31519 \end_inset
31520 </cell>
31521 </row>
31522 </lyxtabular>
31523
31524 \end_inset
31525
31526
31527 \newline
31528
31529 \end_layout
31530
31531 \begin_layout Section
31532 Related documentation / recommended reading
31533 \end_layout
31534
31535 \begin_layout Standard
31536 \align left
31537 \begin_inset Tabular
31538 <lyxtabular version="3" rows="7" columns="3">
31539 <features>
31540 <column alignment="left" valignment="top" leftline="true" width="0pt">
31541 <column alignment="left" valignment="top" leftline="true" width="0">
31542 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31543 <row topline="true" bottomline="true">
31544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31545 \begin_inset Text
31546
31547 \begin_layout Standard
31548
31549 \series bold
31550 Name
31551 \end_layout
31552
31553 \end_inset
31554 </cell>
31555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31556 \begin_inset Text
31557
31558 \begin_layout Standard
31559
31560 \series bold
31561 Subject / Title
31562 \end_layout
31563
31564 \end_inset
31565 </cell>
31566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31567 \begin_inset Text
31568
31569 \begin_layout Standard
31570
31571 \series bold
31572 Where to get
31573 \end_layout
31574
31575 \end_inset
31576 </cell>
31577 </row>
31578 <row topline="true">
31579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31580 \begin_inset Text
31581
31582 \begin_layout Standard
31583
31584 \family roman
31585 \series medium
31586 \shape up
31587 \size normal
31588 \emph off
31589 \bar no
31590 \noun off
31591 \color none
31592 c-refcard.pdf
31593 \end_layout
31594
31595 \end_inset
31596 </cell>
31597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31598 \begin_inset Text
31599
31600 \begin_layout Standard
31601 C Reference Card
31602 \begin_inset LatexCommand \index{C Reference card}
31603
31604 \end_inset
31605
31606 , 2 pages
31607 \end_layout
31608
31609 \end_inset
31610 </cell>
31611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31612 \begin_inset Text
31613
31614 \begin_layout Standard
31615 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31616
31617 \end_inset
31618
31619
31620 \end_layout
31621
31622 \end_inset
31623 </cell>
31624 </row>
31625 <row topline="true">
31626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31627 \begin_inset Text
31628
31629 \begin_layout Standard
31630 c-faq
31631 \end_layout
31632
31633 \end_inset
31634 </cell>
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31636 \begin_inset Text
31637
31638 \begin_layout Standard
31639 C-FAQ
31640 \begin_inset LatexCommand \index{C FAQ}
31641
31642 \end_inset
31643
31644
31645 \end_layout
31646
31647 \end_inset
31648 </cell>
31649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31650 \begin_inset Text
31651
31652 \begin_layout Standard
31653 \begin_inset LatexCommand \url{http://www.c-faq.com}
31654
31655 \end_inset
31656
31657
31658 \end_layout
31659
31660 \end_inset
31661 </cell>
31662 </row>
31663 <row topline="true">
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31665 \begin_inset Text
31666
31667 \begin_layout Standard
31668 ISO/IEC 9899:TC2
31669 \end_layout
31670
31671 \end_inset
31672 </cell>
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31674 \begin_inset Text
31675
31676 \begin_layout Standard
31677 \begin_inset Quotes sld
31678 \end_inset
31679
31680 C-Standard
31681 \begin_inset Quotes srd
31682 \end_inset
31683
31684
31685 \end_layout
31686
31687 \end_inset
31688 </cell>
31689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31690 \begin_inset Text
31691
31692 \begin_layout Standard
31693
31694 \size footnotesize
31695 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31696
31697 \end_inset
31698
31699
31700 \end_layout
31701
31702 \end_inset
31703 </cell>
31704 </row>
31705 <row topline="true">
31706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31707 \begin_inset Text
31708
31709 \begin_layout Standard
31710 ISO/IEC DTR 18037
31711 \end_layout
31712
31713 \end_inset
31714 </cell>
31715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31716 \begin_inset Text
31717
31718 \begin_layout Standard
31719 \begin_inset Quotes sld
31720 \end_inset
31721
31722 Extensions for Embedded C
31723 \begin_inset Quotes srd
31724 \end_inset
31725
31726
31727 \end_layout
31728
31729 \end_inset
31730 </cell>
31731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31732 \begin_inset Text
31733
31734 \begin_layout Standard
31735
31736 \size footnotesize
31737 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31738
31739 \end_inset
31740
31741
31742 \end_layout
31743
31744 \end_inset
31745 </cell>
31746 </row>
31747 <row topline="true">
31748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31749 \begin_inset Text
31750
31751 \begin_layout Standard
31752
31753 \end_layout
31754
31755 \end_inset
31756 </cell>
31757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31758 \begin_inset Text
31759
31760 \begin_layout Standard
31761 Latest datasheet of target CPU
31762 \end_layout
31763
31764 \end_inset
31765 </cell>
31766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31767 \begin_inset Text
31768
31769 \begin_layout Standard
31770 vendor
31771 \end_layout
31772
31773 \end_inset
31774 </cell>
31775 </row>
31776 <row topline="true" bottomline="true">
31777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31778 \begin_inset Text
31779
31780 \begin_layout Standard
31781
31782 \end_layout
31783
31784 \end_inset
31785 </cell>
31786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31787 \begin_inset Text
31788
31789 \begin_layout Standard
31790 Revision history of datasheet
31791 \end_layout
31792
31793 \end_inset
31794 </cell>
31795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31796 \begin_inset Text
31797
31798 \begin_layout Standard
31799 vendor
31800 \end_layout
31801
31802 \end_inset
31803 </cell>
31804 </row>
31805 </lyxtabular>
31806
31807 \end_inset
31808
31809
31810 \newline
31811
31812 \end_layout
31813
31814 \begin_layout Section
31815 Application notes specifically for SDCC
31816 \end_layout
31817
31818 \begin_layout Standard
31819 SDCC makes no claims about the completeness of this list and about up-to-datenes
31820 s or correctness of the application notes
31821 \begin_inset LatexCommand \index{Application notes}
31822
31823 \end_inset
31824
31825 .
31826 \end_layout
31827
31828 \begin_layout Standard
31829 \align left
31830
31831 \size footnotesize
31832 \begin_inset Tabular
31833 <lyxtabular version="3" rows="7" columns="3">
31834 <features>
31835 <column alignment="block" valignment="top" leftline="true" width="17col%">
31836 <column alignment="block" valignment="top" leftline="true" width="27col%">
31837 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31838 <row topline="true" bottomline="true">
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31840 \begin_inset Text
31841
31842 \begin_layout Standard
31843
31844 \series bold
31845 \size footnotesize
31846 Vendor
31847 \end_layout
31848
31849 \end_inset
31850 </cell>
31851 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31852 \begin_inset Text
31853
31854 \begin_layout Standard
31855
31856 \series bold
31857 \size footnotesize
31858 Subject / Title
31859 \end_layout
31860
31861 \end_inset
31862 </cell>
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31864 \begin_inset Text
31865
31866 \begin_layout Standard
31867
31868 \series bold
31869 \size footnotesize
31870 Where to get
31871 \end_layout
31872
31873 \end_inset
31874 </cell>
31875 </row>
31876 <row topline="true">
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31878 \begin_inset Text
31879
31880 \begin_layout Standard
31881
31882 \size footnotesize
31883 Maxim / Dallas
31884 \end_layout
31885
31886 \end_inset
31887 </cell>
31888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31889 \begin_inset Text
31890
31891 \begin_layout Standard
31892
31893 \size footnotesize
31894 Using the SDCC Compiler for the DS80C400
31895 \begin_inset LatexCommand \index{DS80C400}
31896
31897 \end_inset
31898
31899
31900 \end_layout
31901
31902 \end_inset
31903 </cell>
31904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31905 \begin_inset Text
31906
31907 \begin_layout Standard
31908
31909 \size footnotesize
31910 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31911
31912 \end_inset
31913
31914
31915 \end_layout
31916
31917 \end_inset
31918 </cell>
31919 </row>
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31922 \begin_inset Text
31923
31924 \begin_layout Standard
31925
31926 \size footnotesize
31927 Maxim / Dallas
31928 \end_layout
31929
31930 \end_inset
31931 </cell>
31932 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31933 \begin_inset Text
31934
31935 \begin_layout Standard
31936
31937 \size footnotesize
31938 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31939 \begin_inset LatexCommand \index{DS89C4x0}
31940
31941 \end_inset
31942
31943  Family of Microcontrollers
31944 \end_layout
31945
31946 \end_inset
31947 </cell>
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31949 \begin_inset Text
31950
31951 \begin_layout Standard
31952
31953 \size footnotesize
31954 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31955
31956 \end_inset
31957
31958
31959 \end_layout
31960
31961 \end_inset
31962 </cell>
31963 </row>
31964 <row topline="true">
31965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31966 \begin_inset Text
31967
31968 \begin_layout Standard
31969
31970 \size footnotesize
31971 Silicon Laboratories / Cygnal
31972 \end_layout
31973
31974 \end_inset
31975 </cell>
31976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31977 \begin_inset Text
31978
31979 \begin_layout Standard
31980
31981 \size footnotesize
31982 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31983 \begin_inset LatexCommand \index{IDE}
31984
31985 \end_inset
31986
31987
31988 \end_layout
31989
31990 \end_inset
31991 </cell>
31992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31993 \begin_inset Text
31994
31995 \begin_layout Standard
31996
31997 \size footnotesize
31998 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31999
32000 \end_inset
32001
32002
32003 \end_layout
32004
32005 \end_inset
32006 </cell>
32007 </row>
32008 <row topline="true">
32009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32010 \begin_inset Text
32011
32012 \begin_layout Standard
32013
32014 \size footnotesize
32015 Ramtron / Goal Semiconductor
32016 \end_layout
32017
32018 \end_inset
32019 </cell>
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32021 \begin_inset Text
32022
32023 \begin_layout Standard
32024
32025 \size footnotesize
32026 Interfacing SDCC to Syn and Textpad
32027 \end_layout
32028
32029 \end_inset
32030 </cell>
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32032 \begin_inset Text
32033
32034 \begin_layout Standard
32035
32036 \size footnotesize
32037 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32038
32039 \end_inset
32040
32041
32042 \end_layout
32043
32044 \end_inset
32045 </cell>
32046 </row>
32047 <row topline="true">
32048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32049 \begin_inset Text
32050
32051 \begin_layout Standard
32052
32053 \size footnotesize
32054 Ramtron / Goal Semiconductor
32055 \end_layout
32056
32057 \end_inset
32058 </cell>
32059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32060 \begin_inset Text
32061
32062 \begin_layout Standard
32063
32064 \size footnotesize
32065 Installing and Configuring SDCC and Crimson Editor 
32066 \end_layout
32067
32068 \end_inset
32069 </cell>
32070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32071 \begin_inset Text
32072
32073 \begin_layout Standard
32074
32075 \size footnotesize
32076 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32077
32078 \end_inset
32079
32080
32081 \end_layout
32082
32083 \end_inset
32084 </cell>
32085 </row>
32086 <row topline="true" bottomline="true">
32087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32088 \begin_inset Text
32089
32090 \begin_layout Standard
32091
32092 \size footnotesize
32093 Texas Instruments
32094 \end_layout
32095
32096 \end_inset
32097 </cell>
32098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32099 \begin_inset Text
32100
32101 \begin_layout Standard
32102
32103 \size footnotesize
32104 MSC12xx Programming with SDCC
32105 \end_layout
32106
32107 \end_inset
32108 </cell>
32109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32110 \begin_inset Text
32111
32112 \begin_layout Standard
32113
32114 \size footnotesize
32115 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32116
32117 \end_inset
32118
32119
32120 \end_layout
32121
32122 \end_inset
32123 </cell>
32124 </row>
32125 </lyxtabular>
32126
32127 \end_inset
32128
32129
32130 \end_layout
32131
32132 \begin_layout Section
32133 Some Questions
32134 \end_layout
32135
32136 \begin_layout Standard
32137 Some questions answered, some pointers given - it might be time to in turn
32138  ask 
32139 \emph on
32140 you
32141 \emph default
32142  some questions: 
32143 \end_layout
32144
32145 \begin_layout Itemize
32146 can you solve your project with the selected microcontroller? Would you
32147  find out early or rather late that your target is too small/slow/whatever?
32148  Can you switch to a slightly better device if it doesn't fit?
32149 \end_layout
32150
32151 \begin_layout Itemize
32152 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32153  and/or another programming language be more adequate? Would an operating
32154  system on the target device help?
32155 \end_layout
32156
32157 \begin_layout Itemize
32158 if you solved the problem, will the marketing department be happy?
32159 \end_layout
32160
32161 \begin_layout Itemize
32162 if the marketing department is happy, will customers be happy?
32163 \end_layout
32164
32165 \begin_layout Itemize
32166 if you're the project manager, marketing department and maybe even the customer
32167  in one person, have you tried to see the project from the outside?
32168 \end_layout
32169
32170 \begin_layout Itemize
32171 is the project done if you think it is done? Or is just that other interface/pro
32172 tocol/feature/configuration/option missing? How about website, manual(s),
32173  internationali(z|s)ation, packaging, labels, 2nd source for components,
32174  electromagnetic compatability/interference, documentation for production,
32175  production test software, update mechanism, patent issues?
32176 \end_layout
32177
32178 \begin_layout Itemize
32179 is your project adequately positioned in that magic triangle: fame, fortune,
32180  fun?
32181 \end_layout
32182
32183 \begin_layout Standard
32184 Maybe not all answers to these questions are known and some answers may
32185  even be 
32186 \emph on
32187 no
32188 \emph default
32189 , nevertheless knowing these questions may help you to avoid burnout
32190 \begin_inset Foot
32191 status open
32192
32193 \begin_layout Standard
32194 burnout is bad for electronic devices, programmers and motorcycle tyres
32195 \end_layout
32196
32197 \end_inset
32198
32199 .
32200  Chances are you didn't want to hear some of them...
32201 \end_layout
32202
32203 \begin_layout Chapter
32204 Support
32205 \begin_inset LatexCommand \index{Support}
32206
32207 \end_inset
32208
32209
32210 \end_layout
32211
32212 \begin_layout Standard
32213 SDCC has grown to be a large project.
32214  The compiler alone (without the preprocessor, assembler and linker) is
32215  well over 150,000 lines of code (blank stripped).
32216  The open source nature of this project is a key to its continued growth
32217  and support.
32218  You gain the benefit and support of many active software developers and
32219  end users.
32220  Is SDCC perfect? No, that's why we need your help.
32221  The developers take pride in fixing reported bugs.
32222  You can help by reporting the bugs and helping other SDCC users.
32223  There are lots of ways to contribute, and we encourage you to take part
32224  in making SDCC a great software package.
32225  
32226 \end_layout
32227
32228 \begin_layout Standard
32229 The SDCC project is hosted on the SDCC sourceforge site at 
32230 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32231
32232 \end_inset
32233
32234 .
32235  You'll find the complete set of mailing lists
32236 \begin_inset LatexCommand \index{Mailing list(s)}
32237
32238 \end_inset
32239
32240 , forums, bug reporting system, patch submission
32241 \begin_inset LatexCommand \index{Patch submission}
32242
32243 \end_inset
32244
32245  system, download
32246 \begin_inset LatexCommand \index{download}
32247
32248 \end_inset
32249
32250  area and Subversion code repository
32251 \begin_inset LatexCommand \index{Subversion code repository}
32252
32253 \end_inset
32254
32255  there.
32256 \end_layout
32257
32258 \begin_layout Section
32259 Reporting Bugs
32260 \begin_inset LatexCommand \index{Bug reporting}
32261
32262 \end_inset
32263
32264
32265 \begin_inset LatexCommand \index{Reporting bugs}
32266
32267 \end_inset
32268
32269
32270 \end_layout
32271
32272 \begin_layout Standard
32273 The recommended way of reporting bugs is using the infrastructure of the
32274  sourceforge site.
32275  You can follow the status of bug reports there and have an overview about
32276  the known bugs.
32277 \end_layout
32278
32279 \begin_layout Standard
32280 Bug reports are automatically forwarded to the developer mailing list and
32281  will be fixed ASAP.
32282  When reporting a bug, it is very useful to include a small test program
32283  (the smaller the better) which reproduces the problem.
32284  If you can isolate the problem by looking at the generated assembly code,
32285  this can be very helpful.
32286  Compiling your program with the -
32287 \begin_inset ERT
32288 status collapsed
32289
32290 \begin_layout Standard
32291
32292
32293 \backslash
32294 /
32295 \end_layout
32296
32297 \end_inset
32298
32299 -dumpall
32300 \begin_inset LatexCommand \index{-\/-dumpall}
32301
32302 \end_inset
32303
32304  option can sometimes be useful in locating optimization problems.
32305  When reporting a bug please make sure you:
32306 \end_layout
32307
32308 \begin_layout Enumerate
32309 Attach the code you are compiling with SDCC.
32310  
32311 \end_layout
32312
32313 \begin_layout Enumerate
32314 Specify the exact command you use to run SDCC, or attach your Makefile.
32315  
32316 \end_layout
32317
32318 \begin_layout Enumerate
32319 Specify the SDCC version (type "
32320 \family sans
32321 \series bold
32322 sdcc -v
32323 \family default
32324 \series default
32325 "), your platform, and operating system.
32326  
32327 \end_layout
32328
32329 \begin_layout Enumerate
32330 Provide an exact copy of any error message or incorrect output.
32331  
32332 \end_layout
32333
32334 \begin_layout Enumerate
32335 Put something meaningful in the subject of your message.
32336 \end_layout
32337
32338 \begin_layout Standard
32339 Please attempt to include these 5 important parts, as applicable, in all
32340  requests for support or when reporting any problems or bugs with SDCC.
32341  Though this will make your message lengthy, it will greatly improve your
32342  chance that SDCC users and developers will be able to help you.
32343  Some SDCC developers are frustrated by bug reports without code provided
32344  that they can use to reproduce and ultimately fix the problem, so please
32345  be sure to provide sample code if you are reporting a bug! 
32346 \end_layout
32347
32348 \begin_layout Standard
32349 Please have a short check that you are using a recent version of SDCC and
32350  the bug is not yet known.
32351  This is the link for reporting bugs: 
32352 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32353
32354 \end_inset
32355
32356 .
32357  With SDCC on average having more than 200 downloads
32358 \begin_inset LatexCommand \index{download}
32359
32360 \end_inset
32361
32362  on sourceforge per day
32363 \begin_inset Foot
32364 status open
32365
32366 \begin_layout Standard
32367 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32368  between 2002 and 2005.
32369  This does not include other methods of distribution.
32370 \end_layout
32371
32372 \end_inset
32373
32374  there must be some users.
32375  So it's not exactly easy to find a new bug.
32376  If you find one we need it: 
32377 \emph on
32378 reporting bugs is good
32379 \emph default
32380 .
32381 \end_layout
32382
32383 \begin_layout Section
32384 Requesting Features
32385 \begin_inset LatexCommand \label{sub:Requesting-Features}
32386
32387 \end_inset
32388
32389
32390 \begin_inset LatexCommand \index{Feature request}
32391
32392 \end_inset
32393
32394
32395 \begin_inset LatexCommand \index{Requesting features}
32396
32397 \end_inset
32398
32399
32400 \end_layout
32401
32402 \begin_layout Standard
32403 Like bug reports feature requests are forwarded to the developer mailing
32404  list.
32405  This is the link for requesting features: 
32406 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32407
32408 \end_inset
32409
32410 .
32411 \end_layout
32412
32413 \begin_layout Section
32414 Submitting patches
32415 \end_layout
32416
32417 \begin_layout Standard
32418 Like bug reports contributed patches are forwarded to the developer mailing
32419  list.
32420  This is the link for submitting patches
32421 \begin_inset LatexCommand \index{Patch submission}
32422
32423 \end_inset
32424
32425
32426 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32427
32428 \end_inset
32429
32430 .
32431 \end_layout
32432
32433 \begin_layout Standard
32434 You need to specify some parameters to the 
32435 \family typewriter
32436 diff
32437 \family default
32438  command for the patches to be useful.
32439  If you modified more than one file a patch created f.e.
32440  with 
32441 \family sans
32442 \series bold
32443
32444 \begin_inset Quotes sld
32445 \end_inset
32446
32447 diff -Naur unmodified_directory modified_directory >my_changes.patch
32448 \begin_inset Quotes srd
32449 \end_inset
32450
32451
32452 \family default
32453 \series default
32454  will be fine, otherwise 
32455 \family sans
32456 \series bold
32457
32458 \begin_inset Quotes sld
32459 \end_inset
32460
32461 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32462 \begin_inset Quotes srd
32463 \end_inset
32464
32465
32466 \series default
32467  
32468 \family default
32469 will do.
32470 \end_layout
32471
32472 \begin_layout Section
32473 Getting Help
32474 \end_layout
32475
32476 \begin_layout Standard
32477 These links should take you directly to the 
32478 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32479
32480 \end_inset
32481
32482
32483 \begin_inset Foot
32484 status open
32485
32486 \begin_layout Standard
32487 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32488  automated messages (mid 2003)
32489 \end_layout
32490
32491 \end_inset
32492
32493  and the 
32494 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32495
32496 \end_inset
32497
32498 , lists
32499 \begin_inset LatexCommand \index{Mailing list(s)}
32500
32501 \end_inset
32502
32503  and forums are archived and searchable so if you are lucky someone already
32504  had a similar problem.
32505  While mails to the lists themselves are delivered promptly their web front
32506  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32507  if you're seriously using SDCC please consider subscribing to the lists.
32508 \end_layout
32509
32510 \begin_layout Section
32511 ChangeLog
32512 \end_layout
32513
32514 \begin_layout Standard
32515 You can follow the status of the Subversion version
32516 \begin_inset LatexCommand \index{version}
32517
32518 \end_inset
32519
32520  of SDCC by watching the Changelog
32521 \begin_inset LatexCommand \index{Changelog}
32522
32523 \end_inset
32524
32525  in the Subversion repository
32526 \size footnotesize
32527  
32528 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32529
32530 \end_inset
32531
32532 .
32533 \end_layout
32534
32535 \begin_layout Section
32536 Subversion Source Code Repository
32537 \end_layout
32538
32539 \begin_layout Standard
32540 The output of 
32541 \family sans
32542 \series bold
32543 sdcc -
32544 \family default
32545
32546 \begin_inset ERT
32547 status open
32548
32549 \begin_layout Standard
32550
32551
32552 \backslash
32553 /
32554 \end_layout
32555
32556 \end_inset
32557
32558
32559 \family sans
32560 -version
32561 \family default
32562 \series default
32563  or the filenames of the snapshot versions of SDCC include date and its
32564  Subversion
32565 \begin_inset LatexCommand \index{Subversion code repository}
32566
32567 \end_inset
32568
32569  number.
32570  Subversion allows to download the source of recent or previous versions
32571  
32572 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32573
32574 \end_inset
32575
32576  (by number or by date).
32577  An on-line source code browser and detailled instructions are also available
32578  there.
32579  SDCC versions starting from 1999 up to now are available (currently the
32580  versions prior to the conversion from cvs
32581 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32582
32583 \end_inset
32584
32585  to Subversion (April 2006) are either by accessible by Subversion or by
32586  cvs).
32587 \end_layout
32588
32589 \begin_layout Section
32590 Release policy
32591 \begin_inset LatexCommand \index{Release policy}
32592
32593 \end_inset
32594
32595
32596 \end_layout
32597
32598 \begin_layout Standard
32599 Historically there often were long delays between official releases and
32600  the sourceforge download area tends to get not updated at all.
32601  Excuses in the past might have referred to problems with live range analysis,
32602  but as this was fixed a while ago, the current problem is that another
32603  excuse has to be found.
32604  Kidding aside, we have to get better there! On the other hand there are
32605  daily snapshots available at 
32606 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32607
32608 \end_inset
32609
32610 , and you can always build the very last version (hopefully with many bugs
32611  fixed, and features added) from the source code available at 
32612 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32613
32614 \end_inset
32615
32616 .
32617  The SDCC Wiki
32618 \begin_inset LatexCommand \index{wiki}
32619
32620 \end_inset
32621
32622
32623 \begin_inset LatexCommand \index{SDCC Wiki}
32624
32625 \end_inset
32626
32627  at 
32628 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32629
32630 \end_inset
32631
32632  also holds some information about past and future releases.
32633 \end_layout
32634
32635 \begin_layout Section
32636 Examples
32637 \begin_inset LatexCommand \index{Examples}
32638
32639 \end_inset
32640
32641
32642 \end_layout
32643
32644 \begin_layout Standard
32645 You'll find some small examples in the directory 
32646 \emph on
32647 sdcc/device/examples/.
32648  
32649 \emph default
32650 More examples and libraries are available at
32651 \emph on
32652  The SDCC Open Knowledge Resource 
32653 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32654
32655 \end_inset
32656
32657  
32658 \emph default
32659 web site or at 
32660 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32661
32662 \end_inset
32663
32664 .
32665 \end_layout
32666
32667 \begin_layout Standard
32668 \begin_inset Note Note
32669 status collapsed
32670
32671 \begin_layout Standard
32672 I did insert a reference to Paul's web site here although it seems rather
32673  dedicated to a specific 8032 board (I think it's okay because it f.e.
32674  shows LCD/Harddisc interface and has a free 8051 monitor.
32675  Independent 8032 board vendors face hard competition of heavily subsidized
32676  development boards anyway).
32677 \end_layout
32678
32679 \begin_layout Standard
32680 Maybe we should include some links to real world applications.
32681  Preferably pointer to pointers (one for each architecture) so this stays
32682  manageable here?
32683 \end_layout
32684
32685 \end_inset
32686
32687
32688 \end_layout
32689
32690 \begin_layout Section
32691 Quality control
32692 \begin_inset LatexCommand \label{sec:Quality-control}
32693
32694 \end_inset
32695
32696
32697 \begin_inset LatexCommand \index{Quality control}
32698
32699 \end_inset
32700
32701
32702 \end_layout
32703
32704 \begin_layout Standard
32705 The compiler is passed through snaphot build compile and build checks.
32706  The so called 
32707 \shape italic
32708 regression tests
32709 \shape default
32710
32711 \begin_inset LatexCommand \index{Regression test}
32712
32713 \end_inset
32714
32715  check that SDCC itself compiles flawlessly on several host platforms (i386,
32716  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32717  the quality of the code generated by SDCC by running the code for several
32718  target platforms through simulators.
32719  The regression test suite comprises more than 100 files which expand to
32720  more than 500 test cases which include more than 4500 tests.
32721  The results of these tests are published daily on SDCC's snapshot page
32722  (click on the red or green symbols on the right side of 
32723 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32724
32725 \end_inset
32726
32727 ).
32728 \end_layout
32729
32730 \begin_layout Standard
32731 There is a separate document 
32732 \shape italic
32733 test_suite.pdf 
32734 \begin_inset LatexCommand \index{Test suite}
32735
32736 \end_inset
32737
32738
32739 \shape default
32740  
32741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32742
32743 \end_inset
32744
32745  about the regression test suite.
32746 \end_layout
32747
32748 \begin_layout Standard
32749 You'll find the test code in the directory 
32750 \shape italic
32751 sdcc/support/regression
32752 \shape default
32753 .
32754  You can run these tests manually by running 
32755 \family sans
32756 make
32757 \family default
32758  in this directory (or f.e.
32759  
32760 \family sans
32761 \series bold
32762
32763 \begin_inset Quotes sld
32764 \end_inset
32765
32766 make test-mcs51
32767 \begin_inset Quotes srd
32768 \end_inset
32769
32770
32771 \family default
32772 \series default
32773  if you don't want to run the complete tests).
32774  The test code might also be interesting if you want to look for examples
32775 \begin_inset LatexCommand \index{Examples}
32776
32777 \end_inset
32778
32779  checking corner cases of SDCC or if you plan to submit patches
32780 \begin_inset LatexCommand \index{Patch submission}
32781
32782 \end_inset
32783
32784 .
32785 \end_layout
32786
32787 \begin_layout Standard
32788 The PIC14 port uses a different set of regression tests 
32789 \begin_inset LatexCommand \index{Regression test (PIC14)}
32790
32791 \end_inset
32792
32793 , you'll find them in the directory 
32794 \shape italic
32795 sdcc/src/regression
32796 \shape default
32797 .
32798 \end_layout
32799
32800 \begin_layout Section
32801 Use of SDCC in Education
32802 \end_layout
32803
32804 \begin_layout Standard
32805 In short: 
32806 \emph on
32807 highly
32808 \emph default
32809  encouraged
32810 \begin_inset Foot
32811 status open
32812
32813 \begin_layout Standard
32814 the phrase "use in education" might evoke the association "
32815 \emph on
32816 only
32817 \emph default
32818  fit for use in education".
32819  This connotation is not intended but nevertheless risked as the licensing
32820  of SDCC makes it difficult to offer educational discounts
32821 \end_layout
32822
32823 \end_inset
32824
32825 .
32826  If your rationales are to:
32827 \end_layout
32828
32829 \begin_layout Enumerate
32830 give students a chance to understand the 
32831 \emph on
32832 complete
32833 \emph default
32834  steps of code generation
32835 \end_layout
32836
32837 \begin_layout Enumerate
32838 have a curriculum that can be extended for years.
32839  Then you could use an fpga board as target and your curriculum will seamlessly
32840  extend from logic synthesis (
32841 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32842
32843 \end_inset
32844
32845
32846 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32847
32848 \end_inset
32849
32850 ), over assembly programming, to C to FPGA compilers (
32851 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32852
32853 \end_inset
32854
32855 ) and to C.
32856 \end_layout
32857
32858 \begin_layout Enumerate
32859 be able to insert excursions about skills like using a revision control
32860  system, submitting/applying patches, using a type-setting (as opposed to
32861  word-processing) engine LyX/LaTeX, using 
32862 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32863
32864 \end_inset
32865
32866 , following some 
32867 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32868
32869 \end_inset
32870
32871 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32872  Source Software, CPU simulation, compiler regression tests
32873 \begin_inset LatexCommand \index{Regression test}
32874
32875 \end_inset
32876
32877 .
32878  
32879 \newline
32880 And if there should be a shortage of ideas then you can always point students
32881  to the ever-growing feature request list 
32882 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32883
32884 \end_inset
32885
32886 .
32887 \end_layout
32888
32889 \begin_layout Enumerate
32890 not tie students to a specific host platform and instead allow them to use
32891  a host platform of 
32892 \emph on
32893 their
32894 \emph default
32895  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32896  and eventually 
32897 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32898
32899 \end_inset
32900
32901 )
32902 \end_layout
32903
32904 \begin_layout Enumerate
32905 not encourage students to use illegal copies of educational software
32906 \end_layout
32907
32908 \begin_layout Enumerate
32909 be immune to licensing/availability/price changes of the chosen tool chain
32910 \end_layout
32911
32912 \begin_layout Enumerate
32913 be able to change to a new target platform without having to adopt a new
32914  tool chain
32915 \end_layout
32916
32917 \begin_layout Enumerate
32918 have complete control over and insight into the tool chain
32919 \end_layout
32920
32921 \begin_layout Enumerate
32922 make your students aware about the pros and cons of open source software
32923  development
32924 \end_layout
32925
32926 \begin_layout Enumerate
32927 give back to the public as you are probably at least partially publically
32928  funded
32929 \end_layout
32930
32931 \begin_layout Enumerate
32932 give students a chance to publically prove their skills and to possibly
32933  see a world wide impact
32934 \end_layout
32935
32936 \begin_layout Standard
32937 then SDCC is probably among the first choices.
32938  Well, probably SDCC might be the only choice.
32939 \newpage
32940
32941 \end_layout
32942
32943 \begin_layout Chapter
32944 SDCC Technical Data
32945 \end_layout
32946
32947 \begin_layout Section
32948 Optimizations
32949 \begin_inset LatexCommand \index{Optimizations}
32950
32951 \end_inset
32952
32953
32954 \end_layout
32955
32956 \begin_layout Standard
32957 SDCC performs a host of standard optimizations in addition to some MCU specific
32958  optimizations.
32959  
32960 \end_layout
32961
32962 \begin_layout Subsection
32963 Sub-expression Elimination
32964 \begin_inset LatexCommand \index{Subexpression elimination}
32965
32966 \end_inset
32967
32968
32969 \end_layout
32970
32971 \begin_layout Standard
32972 The compiler does local and 
32973 \emph on
32974 g
32975 \emph default
32976 lobal 
32977 \emph on
32978 c
32979 \emph default
32980 ommon 
32981 \emph on
32982 s
32983 \emph default
32984 ubexpression 
32985 \emph on
32986 e
32987 \emph default
32988 limination, e.g.: 
32989 \end_layout
32990
32991 \begin_layout Verse
32992
32993 \family typewriter
32994 i = x + y + 1; 
32995 \newline
32996 j = x + y;
32997 \end_layout
32998
32999 \begin_layout Standard
33000 will be translated to
33001 \end_layout
33002
33003 \begin_layout Verse
33004
33005 \family typewriter
33006 iTemp = x + y; 
33007 \newline
33008 i = iTemp + 1; 
33009 \newline
33010 j = iTemp;
33011 \end_layout
33012
33013 \begin_layout Standard
33014 Some subexpressions are not as obvious as the above example, e.g.:
33015 \end_layout
33016
33017 \begin_layout Verse
33018
33019 \family typewriter
33020 a->b[i].c = 10; 
33021 \newline
33022 a->b[i].d = 11;
33023 \end_layout
33024
33025 \begin_layout Standard
33026 In this case the address arithmetic a->b[i] will be computed only once;
33027  the equivalent code in C would be.
33028 \end_layout
33029
33030 \begin_layout Verse
33031
33032 \family typewriter
33033 iTemp = a->b[i]; 
33034 \newline
33035 iTemp.c = 10; 
33036 \newline
33037 iTemp.d = 11;
33038 \end_layout
33039
33040 \begin_layout Standard
33041 The compiler will try to keep these temporary variables in registers.
33042 \end_layout
33043
33044 \begin_layout Subsection
33045 Dead-Code Elimination
33046 \begin_inset LatexCommand \index{Dead-code elimination}
33047
33048 \end_inset
33049
33050
33051 \end_layout
33052
33053 \begin_layout Verse
33054
33055 \family typewriter
33056 int global;
33057 \newline
33058
33059 \newline
33060 void f () { 
33061 \newline
33062 \InsetSpace ~
33063 \InsetSpace ~
33064 int i; 
33065 \newline
33066 \InsetSpace ~
33067 \InsetSpace ~
33068 i = 1; \InsetSpace ~
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 \InsetSpace ~
33072 \InsetSpace ~
33073 /* dead store */ 
33074 \newline
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 global = 1;\InsetSpace ~
33078 /* dead
33079  store */ 
33080 \newline
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 global = 2; 
33084 \newline
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 return; 
33088 \newline
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 global = 3;\InsetSpace ~
33092 /* unreachable */ 
33093 \newline
33094 }
33095 \end_layout
33096
33097 \begin_layout Standard
33098 will be changed to
33099 \end_layout
33100
33101 \begin_layout Verse
33102
33103 \family typewriter
33104 int global;
33105 \newline
33106
33107 \newline
33108 void f () {
33109 \newline
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 global = 2; 
33113 \newline
33114 }
33115 \end_layout
33116
33117 \begin_layout Subsection
33118 Copy-Propagation
33119 \begin_inset LatexCommand \index{Copy propagation}
33120
33121 \end_inset
33122
33123
33124 \end_layout
33125
33126 \begin_layout Verse
33127
33128 \family typewriter
33129 int f() { 
33130 \newline
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 int i, j; 
33134 \newline
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 i = 10; 
33138 \newline
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 j = i; 
33142 \newline
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 return j; 
33146 \newline
33147 }
33148 \end_layout
33149
33150 \begin_layout Standard
33151 will be changed to 
33152 \end_layout
33153
33154 \begin_layout Verse
33155
33156 \family typewriter
33157 int f() { 
33158 \newline
33159 \InsetSpace ~
33160 \InsetSpace ~
33161 int i, j; 
33162 \newline
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 i = 10; 
33166 \newline
33167 \InsetSpace ~
33168 \InsetSpace ~
33169 j = 10; 
33170 \newline
33171 \InsetSpace ~
33172 \InsetSpace ~
33173 return 10; 
33174 \newline
33175 }
33176 \end_layout
33177
33178 \begin_layout Standard
33179 Note: the dead stores created by this copy propagation will be eliminated
33180  by dead-code elimination.
33181 \end_layout
33182
33183 \begin_layout Subsection
33184 Loop Optimizations
33185 \begin_inset LatexCommand \index{Loop optimization}
33186
33187 \end_inset
33188
33189
33190 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33191
33192 \end_inset
33193
33194
33195 \end_layout
33196
33197 \begin_layout Standard
33198 Two types of loop optimizations are done by SDCC 
33199 \emph on
33200 loop invariant
33201 \emph default
33202  lifting and
33203 \emph on
33204  strength reduction
33205 \emph default
33206  of loop induction variables.
33207  In addition to the strength reduction the optimizer marks the induction
33208  variables and the register allocator tries to keep the induction variables
33209  in registers for the duration of the loop.
33210  Because of this preference of the register allocator
33211 \begin_inset LatexCommand \index{Register allocation}
33212
33213 \end_inset
33214
33215 , loop induction optimization causes an increase in register pressure, which
33216  may cause unwanted spilling of other temporary variables into the stack
33217 \begin_inset LatexCommand \index{stack}
33218
33219 \end_inset
33220
33221  / data space.
33222  The compiler will generate a warning message when it is forced to allocate
33223  extra space either on the stack or data space.
33224  If this extra space allocation is undesirable then induction optimization
33225  can be eliminated either for the entire source file (with -
33226 \begin_inset ERT
33227 status collapsed
33228
33229 \begin_layout Standard
33230
33231
33232 \backslash
33233 /
33234 \end_layout
33235
33236 \end_inset
33237
33238 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33239 noinduction
33240 \begin_inset LatexCommand \index{\#pragma noinduction}
33241
33242 \end_inset
33243
33244 .
33245 \newline
33246
33247 \newline
33248 Loop Invariant:
33249 \end_layout
33250
33251 \begin_layout Verse
33252
33253 \family typewriter
33254 for (i = 0 ; i < 100 ; i ++) 
33255 \newline
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 f += k + l;
33261 \end_layout
33262
33263 \begin_layout Standard
33264 changed to
33265 \end_layout
33266
33267 \begin_layout Verse
33268
33269 \family typewriter
33270 itemp = k + l; 
33271 \newline
33272 for (i = 0; i < 100; i++) 
33273 \newline
33274 \InsetSpace ~
33275 \InsetSpace ~
33276 \InsetSpace ~
33277 \InsetSpace ~
33278 f += itemp;
33279 \end_layout
33280
33281 \begin_layout Standard
33282 As mentioned previously some loop invariants are not as apparent, all static
33283  address computations are also moved out of the loop.
33284 \newline
33285
33286 \newline
33287 Strength Reduction
33288 \begin_inset LatexCommand \index{Strength reduction}
33289
33290 \end_inset
33291
33292 , this optimization substitutes an expression by a cheaper expression:
33293 \end_layout
33294
33295 \begin_layout Verse
33296
33297 \family typewriter
33298 for (i=0;i < 100; i++)
33299 \newline
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304 ar[i*5] = i*3;
33305 \end_layout
33306
33307 \begin_layout Standard
33308 changed to
33309 \end_layout
33310
33311 \begin_layout Verse
33312
33313 \family typewriter
33314 itemp1 = 0; 
33315 \newline
33316 itemp2 = 0; 
33317 \newline
33318 for (i=0;i< 100;i++) { 
33319 \newline
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 \InsetSpace ~
33324 ar[itemp1] = itemp2; 
33325 \newline
33326 \InsetSpace ~
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 \InsetSpace ~
33330 itemp1
33331  += 5; 
33332 \newline
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 itemp2 += 3; 
33338 \newline
33339 }
33340 \end_layout
33341
33342 \begin_layout Standard
33343 The more expensive multiplication
33344 \begin_inset LatexCommand \index{Multiplication}
33345
33346 \end_inset
33347
33348  is changed to a less expensive addition.
33349 \end_layout
33350
33351 \begin_layout Subsection
33352 Loop Reversing
33353 \begin_inset LatexCommand \index{Loop reversing}
33354
33355 \end_inset
33356
33357
33358 \end_layout
33359
33360 \begin_layout Standard
33361 This optimization is done to reduce the overhead of checking loop boundaries
33362  for every iteration.
33363  Some simple loops can be reversed and implemented using a 
33364 \begin_inset Quotes eld
33365 \end_inset
33366
33367 decrement and jump if not zero
33368 \begin_inset Quotes erd
33369 \end_inset
33370
33371  instruction.
33372  SDCC checks for the following criterion to determine if a loop is reversible
33373  (note: more sophisticated compilers use data-dependency analysis to make
33374  this determination, SDCC uses a more simple minded analysis).
33375 \end_layout
33376
33377 \begin_layout Itemize
33378 The 'for' loop is of the form 
33379 \newline
33380
33381 \newline
33382
33383 \family typewriter
33384 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33385  += 1])
33386 \newline
33387 \InsetSpace ~
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 \InsetSpace ~
33391 <for body>
33392 \end_layout
33393
33394 \begin_layout Itemize
33395 The <for body> does not contain 
33396 \begin_inset Quotes eld
33397 \end_inset
33398
33399 continue
33400 \begin_inset Quotes erd
33401 \end_inset
33402
33403  or 'break
33404 \begin_inset Quotes erd
33405 \end_inset
33406
33407 .
33408 \end_layout
33409
33410 \begin_layout Itemize
33411 All goto's are contained within the loop.
33412 \end_layout
33413
33414 \begin_layout Itemize
33415 No function calls within the loop.
33416 \end_layout
33417
33418 \begin_layout Itemize
33419 The loop control variable <sym> is not assigned any value within the loop
33420 \end_layout
33421
33422 \begin_layout Itemize
33423 The loop control variable does NOT participate in any arithmetic operation
33424  within the loop.
33425 \end_layout
33426
33427 \begin_layout Itemize
33428 There are NO switch statements in the loop.
33429 \end_layout
33430
33431 \begin_layout Subsection
33432 Algebraic Simplifications
33433 \end_layout
33434
33435 \begin_layout Standard
33436 SDCC does numerous algebraic simplifications, the following is a small sub-set
33437  of these optimizations.
33438 \end_layout
33439
33440 \begin_layout Verse
33441
33442 \family typewriter
33443 i = j + 0;\InsetSpace ~
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447  /* changed to: */\InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450 \InsetSpace ~
33451  i = j; 
33452 \newline
33453 i /= 2;\InsetSpace ~
33454 \InsetSpace ~
33455 \InsetSpace ~
33456 \InsetSpace ~
33457 \InsetSpace ~
33458 \InsetSpace ~
33459 \InsetSpace ~
33460  /* changed to: */\InsetSpace ~
33461 \InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464  i >>= 1; 
33465 \newline
33466 i
33467  = j - j;\InsetSpace ~
33468 \InsetSpace ~
33469 \InsetSpace ~
33470 \InsetSpace ~
33471  /* changed to: */\InsetSpace ~
33472 \InsetSpace ~
33473 \InsetSpace ~
33474 \InsetSpace ~
33475  i = 0; 
33476 \newline
33477 i = j / 1;\InsetSpace ~
33478 \InsetSpace ~
33479 \InsetSpace ~
33480 \InsetSpace ~
33481  /* changed to: */\InsetSpace ~
33482 \InsetSpace ~
33483 \InsetSpace ~
33484 \InsetSpace ~
33485  i = j;
33486 \end_layout
33487
33488 \begin_layout Standard
33489 Note the subexpressions
33490 \begin_inset LatexCommand \index{Subexpression}
33491
33492 \end_inset
33493
33494  given above are generally introduced by macro expansions or as a result
33495  of copy/constant propagation.
33496 \end_layout
33497
33498 \begin_layout Subsection
33499 'switch' Statements
33500 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33501
33502 \end_inset
33503
33504
33505 \begin_inset LatexCommand \index{switch statement}
33506
33507 \end_inset
33508
33509
33510 \end_layout
33511
33512 \begin_layout Standard
33513 SDCC can optimize switch statements to jump tables
33514 \begin_inset LatexCommand \index{jump tables}
33515
33516 \end_inset
33517
33518 .
33519  It makes the decision based on an estimate of the generated code size.
33520  SDCC is quite liberal in the requirements for jump table generation: 
33521 \end_layout
33522
33523 \begin_layout Itemize
33524 The labels need not be in order, and the starting number need not be one
33525  or zero, the case labels are in numerical sequence or not too many case
33526  labels are missing.
33527 \end_layout
33528
33529 \begin_deeper
33530 \begin_layout Verse
33531
33532 \family typewriter
33533 switch(i) {\InsetSpace ~
33534 \InsetSpace ~
33535 \InsetSpace ~
33536 \InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 \InsetSpace ~
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 \InsetSpace ~
33554 \InsetSpace ~
33555 \InsetSpace ~
33556 \InsetSpace ~
33557 \InsetSpace ~
33558 \InsetSpace ~
33559 switch (i) { 
33560 \newline
33561 \InsetSpace ~
33562 \InsetSpace ~
33563 \InsetSpace ~
33564 case 4: ...\InsetSpace ~
33565 \InsetSpace ~
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 \InsetSpace ~
33569 \InsetSpace ~
33570 \InsetSpace ~
33571 \InsetSpace ~
33572 \InsetSpace ~
33573 \InsetSpace ~
33574 \InsetSpace ~
33575 \InsetSpace ~
33576 \InsetSpace ~
33577 \InsetSpace ~
33578 \InsetSpace ~
33579 \InsetSpace ~
33580 \InsetSpace ~
33581 \InsetSpace ~
33582 \InsetSpace ~
33583 \InsetSpace ~
33584 \InsetSpace ~
33585 \InsetSpace ~
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 \InsetSpace ~
33589 \InsetSpace ~
33590 case 0: ...
33591  
33592 \newline
33593 \InsetSpace ~
33594 \InsetSpace ~
33595 \InsetSpace ~
33596 case 5: ...\InsetSpace ~
33597 \InsetSpace ~
33598 \InsetSpace ~
33599 \InsetSpace ~
33600 \InsetSpace ~
33601 \InsetSpace ~
33602 \InsetSpace ~
33603 \InsetSpace ~
33604 \InsetSpace ~
33605 \InsetSpace ~
33606 \InsetSpace ~
33607 \InsetSpace ~
33608 \InsetSpace ~
33609 \InsetSpace ~
33610 \InsetSpace ~
33611 \InsetSpace ~
33612 \InsetSpace ~
33613 \InsetSpace ~
33614 \InsetSpace ~
33615 \InsetSpace ~
33616 \InsetSpace ~
33617 \InsetSpace ~
33618 \InsetSpace ~
33619 \InsetSpace ~
33620 \InsetSpace ~
33621 \InsetSpace ~
33622 case 1: ...
33623  
33624 \newline
33625 \InsetSpace ~
33626 \InsetSpace ~
33627 \InsetSpace ~
33628 case 3: ...\InsetSpace ~
33629 \InsetSpace ~
33630 \InsetSpace ~
33631 \InsetSpace ~
33632 \InsetSpace ~
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 \InsetSpace ~
33636 \InsetSpace ~
33637 \InsetSpace ~
33638 \InsetSpace ~
33639 \InsetSpace ~
33640 \InsetSpace ~
33641 \InsetSpace ~
33642 \InsetSpace ~
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 \InsetSpace ~
33646 \InsetSpace ~
33647 \InsetSpace ~
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 \InsetSpace ~
33651 \InsetSpace ~
33652 \InsetSpace ~
33653 \InsetSpace ~
33654
33655 \newline
33656 \InsetSpace ~
33657 \InsetSpace ~
33658 \InsetSpace ~
33659 case 6: ...\InsetSpace ~
33660 \InsetSpace ~
33661 \InsetSpace ~
33662 \InsetSpace ~
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 \InsetSpace ~
33666 \InsetSpace ~
33667 \InsetSpace ~
33668 \InsetSpace ~
33669 \InsetSpace ~
33670 \InsetSpace ~
33671 \InsetSpace ~
33672 \InsetSpace ~
33673 \InsetSpace ~
33674 \InsetSpace ~
33675 \InsetSpace ~
33676 \InsetSpace ~
33677 \InsetSpace ~
33678 \InsetSpace ~
33679 \InsetSpace ~
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 \InsetSpace ~
33683 \InsetSpace ~
33684 \InsetSpace ~
33685 case 3: ...
33686  
33687 \newline
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 \InsetSpace ~
33691 case 7: ...\InsetSpace ~
33692 \InsetSpace ~
33693 \InsetSpace ~
33694 \InsetSpace ~
33695 \InsetSpace ~
33696 \InsetSpace ~
33697 \InsetSpace ~
33698 \InsetSpace ~
33699 \InsetSpace ~
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 \InsetSpace ~
33703 \InsetSpace ~
33704 \InsetSpace ~
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 \InsetSpace ~
33708 \InsetSpace ~
33709 \InsetSpace ~
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 \InsetSpace ~
33713 \InsetSpace ~
33714 \InsetSpace ~
33715 \InsetSpace ~
33716 \InsetSpace ~
33717 case 4: ...
33718  
33719 \newline
33720 \InsetSpace ~
33721 \InsetSpace ~
33722 \InsetSpace ~
33723 case 8: ...\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 \InsetSpace ~
33740 \InsetSpace ~
33741 \InsetSpace ~
33742 \InsetSpace ~
33743 \InsetSpace ~
33744 \InsetSpace ~
33745 \InsetSpace ~
33746 \InsetSpace ~
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 case 5: ...
33750  
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 \InsetSpace ~
33755 case 9: ...\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 \InsetSpace ~
33772 \InsetSpace ~
33773 \InsetSpace ~
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 \InsetSpace ~
33778 \InsetSpace ~
33779 \InsetSpace ~
33780 \InsetSpace ~
33781 case 6: ...
33782  
33783 \newline
33784 \InsetSpace ~
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 case 10: ...\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 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 case 7: ...
33813  
33814 \newline
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 case 11: ...\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 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 \InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 case 8: ...
33844  
33845 \newline
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 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 }
33883 \end_layout
33884
33885 \begin_layout Standard
33886 Both the above switch statements will be implemented using a jump-table.
33887  The example to the right side is slightly more efficient as the check for
33888  the lower boundary of the jump-table is not needed.
33889 \end_layout
33890
33891 \end_deeper
33892 \begin_layout Itemize
33893 The number of case labels is not larger than supported by the target architectur
33894 e.
33895 \end_layout
33896
33897 \begin_layout Itemize
33898 If the case labels are not in numerical sequence ('gaps' between cases)
33899  SDCC checks whether a jump table with additionally inserted dummy cases
33900  is still attractive.
33901  
33902 \end_layout
33903
33904 \begin_layout Itemize
33905 If the starting number is not zero and a check for the lower boundary of
33906  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33907  ...
33908  .
33909 \end_layout
33910
33911 \begin_layout Standard
33912 Switch statements which have large gaps in the numeric sequence or those
33913  that have too many case labels can be split into more than one switch statement
33914  for efficient code generation, e.g.:
33915 \end_layout
33916
33917 \begin_layout Verse
33918
33919 \family typewriter
33920 switch (i) { 
33921 \newline
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 case 1: ...
33925  
33926 \newline
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 case 2: ...
33930  
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 case 3: ...
33935  
33936 \newline
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 case 4: ...
33940  
33941 \newline
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 case 5: ...
33945  
33946 \newline
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 case 6: ...
33950  
33951 \newline
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 case 7: ...
33955  
33956 \newline
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 case 101: ...
33960  
33961 \newline
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 case 102: ...
33965  
33966 \newline
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 case 103: ...
33970  
33971 \newline
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 case 104: ...
33975  
33976 \newline
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 case 105: ...
33980  
33981 \newline
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 case 106: ...
33985  
33986 \newline
33987 \InsetSpace ~
33988 \InsetSpace ~
33989 case 107: ...
33990  
33991 \newline
33992 }
33993 \end_layout
33994
33995 \begin_layout Standard
33996 If the above switch statement is broken down into two switch statements
33997 \end_layout
33998
33999 \begin_layout Verse
34000
34001 \family typewriter
34002 switch (i) { 
34003 \newline
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 case 1: ...
34007  
34008 \newline
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 case 2: ...
34012  
34013 \newline
34014 \InsetSpace ~
34015 \InsetSpace ~
34016 case 3: ...
34017  
34018 \newline
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 case 4: ...
34022  
34023 \newline
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 case 5: ...
34027  
34028 \newline
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 case 6: ...
34032  
34033 \newline
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 case 7: ...
34037  
34038 \newline
34039 }
34040 \end_layout
34041
34042 \begin_layout Standard
34043 and
34044 \end_layout
34045
34046 \begin_layout Verse
34047
34048 \family typewriter
34049 switch (i) { 
34050 \newline
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 case 101: ...
34054  
34055 \newline
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 case 102: ...
34059  
34060 \newline
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 case 103: ...
34064  
34065 \newline
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 case 104: ...
34069  
34070 \newline
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 case 105: ...
34074  
34075 \newline
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 case 106: ...
34079  
34080 \newline
34081 \InsetSpace ~
34082 \InsetSpace ~
34083 case 107: ...
34084  
34085 \newline
34086 }
34087 \end_layout
34088
34089 \begin_layout Standard
34090 then both the switch statements will be implemented using jump-tables whereas
34091  the unmodified switch statement will not be.
34092 \end_layout
34093
34094 \begin_layout Standard
34095 \begin_inset Note Note
34096 status collapsed
34097
34098 \begin_layout Standard
34099 There might be reasons which SDCC cannot know about to either favour or
34100  not favour jump tables.
34101  If the target system has to be as quick for the last switch case as for
34102  the first (pro jump table), or if the switch argument is known to be zero
34103  in the majority of the cases (contra jump table).
34104 \end_layout
34105
34106 \end_inset
34107
34108
34109 \end_layout
34110
34111 \begin_layout Standard
34112 The pragma nojtbound
34113 \begin_inset LatexCommand \index{\#pragma nojtbound}
34114
34115 \end_inset
34116
34117  can be used to turn off checking the 
34118 \emph on
34119 j
34120 \emph default
34121 ump 
34122 \emph on
34123 t
34124 \emph default
34125 able 
34126 \emph on
34127 bound
34128 \emph default
34129 aries.
34130  It has no effect if a default label is supplied.
34131  Use of this pragma is dangerous: if the switch
34132 \begin_inset LatexCommand \index{switch statement}
34133
34134 \end_inset
34135
34136  argument is not matched by a case statement the processor will happily
34137  jump into Nirvana.
34138 \end_layout
34139
34140 \begin_layout Subsection
34141 Bit-shifting Operations
34142 \begin_inset LatexCommand \index{Bit shifting}
34143
34144 \end_inset
34145
34146 .
34147 \end_layout
34148
34149 \begin_layout Standard
34150 Bit shifting is one of the most frequently used operation in embedded programmin
34151 g.
34152  SDCC tries to implement bit-shift operations in the most efficient way
34153  possible, e.g.:
34154 \end_layout
34155
34156 \begin_layout Verse
34157
34158 \family typewriter
34159 unsigned char i;
34160 \newline
34161 ...
34162  
34163 \newline
34164 i >>= 4; 
34165 \newline
34166 ...
34167 \end_layout
34168
34169 \begin_layout Standard
34170 generates the following code:
34171 \end_layout
34172
34173 \begin_layout Verse
34174
34175 \family typewriter
34176 mov\InsetSpace ~
34177  a,_i 
34178 \newline
34179 swap a 
34180 \newline
34181 anl\InsetSpace ~
34182  a,#0x0f 
34183 \newline
34184 mov\InsetSpace ~
34185  _i,a
34186 \end_layout
34187
34188 \begin_layout Standard
34189 In general SDCC will never setup a loop if the shift count is known.
34190  Another example:
34191 \end_layout
34192
34193 \begin_layout Verse
34194
34195 \family typewriter
34196 unsigned int i; 
34197 \newline
34198 ...
34199  
34200 \newline
34201 i >>= 9; 
34202 \newline
34203 ...
34204 \end_layout
34205
34206 \begin_layout Standard
34207 will generate:
34208 \end_layout
34209
34210 \begin_layout Verse
34211
34212 \family typewriter
34213 mov\InsetSpace ~
34214 \InsetSpace ~
34215 a,(_i + 1) 
34216 \newline
34217 mov\InsetSpace ~
34218 \InsetSpace ~
34219 (_i + 1),#0x00 
34220 \newline
34221 clr\InsetSpace ~
34222 \InsetSpace ~
34223
34224 \newline
34225 rrc\InsetSpace ~
34226 \InsetSpace ~
34227
34228 \newline
34229 mov\InsetSpace ~
34230 \InsetSpace ~
34231 _i,a
34232 \end_layout
34233
34234 \begin_layout Subsection
34235 Bit-rotation
34236 \begin_inset LatexCommand \index{Bit rotation}
34237
34238 \end_inset
34239
34240
34241 \end_layout
34242
34243 \begin_layout Standard
34244 A special case of the bit-shift operation is bit rotation
34245 \begin_inset LatexCommand \index{rotating bits}
34246
34247 \end_inset
34248
34249 , SDCC recognizes the following expression to be a left bit-rotation:
34250 \end_layout
34251
34252 \begin_layout Verse
34253
34254 \family typewriter
34255 \series bold
34256 unsigned
34257 \series default
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 char i;\InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 /* unsigned is needed for rotation */ 
34272 \newline
34273 ...
34274  
34275 \newline
34276 i = ((i << 1) | (i >> 7)); 
34277 \family default
34278
34279 \newline
34280
34281 \family typewriter
34282 ...
34283 \end_layout
34284
34285 \begin_layout Standard
34286 will generate the following code:
34287 \end_layout
34288
34289 \begin_layout Verse
34290
34291 \family typewriter
34292 mov\InsetSpace ~
34293 \InsetSpace ~
34294 a,_i 
34295 \newline
34296 rl\InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299
34300 \newline
34301 mov\InsetSpace ~
34302 \InsetSpace ~
34303 _i,a
34304 \end_layout
34305
34306 \begin_layout Standard
34307 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34308 ns of this case will also be recognized as bit-rotation, i.e.: 
34309 \end_layout
34310
34311 \begin_layout Verse
34312
34313 \family typewriter
34314 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34315 \end_layout
34316
34317 \begin_layout Subsection
34318 Nibble and Byte Swapping
34319 \end_layout
34320
34321 \begin_layout Standard
34322 Other special cases of the bit-shift operations are nibble or byte swapping
34323 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34324
34325 \end_inset
34326
34327 , SDCC recognizes the following expressions:
34328 \end_layout
34329
34330 \begin_layout Verse
34331
34332 \family typewriter
34333 \series bold
34334 unsigned
34335 \series default
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 char i; 
34339 \newline
34340
34341 \series bold
34342 unsigned
34343 \series default
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 int j; 
34347 \newline
34348 ...
34349  
34350 \newline
34351 i = ((i << 4) | (i >> 4)); 
34352 \family default
34353
34354 \newline
34355
34356 \family typewriter
34357 j = ((j << 8) | (j >> 8)); 
34358 \end_layout
34359
34360 \begin_layout Standard
34361 and generates a swap instruction for the nibble swapping
34362 \begin_inset LatexCommand \index{Nibble swapping}
34363
34364 \end_inset
34365
34366  or move instructions for the byte swapping
34367 \begin_inset LatexCommand \index{Byte swapping}
34368
34369 \end_inset
34370
34371 .
34372  The 
34373 \begin_inset Quotes sld
34374 \end_inset
34375
34376 j
34377 \begin_inset Quotes srd
34378 \end_inset
34379
34380  example can be used to convert from little to big-endian or vice versa.
34381  If you want to change the endianness of a 
34382 \emph on
34383 signed
34384 \emph default
34385  integer you have to cast to 
34386 \family typewriter
34387 (unsigned int)
34388 \family default
34389  first.
34390 \end_layout
34391
34392 \begin_layout Standard
34393 Note that SDCC stores numbers in little-endian
34394 \begin_inset Foot
34395 status open
34396
34397 \begin_layout Standard
34398 Usually 8-bit processors don't care much about endianness.
34399  This is not the case for the standard 8051 which only has an instruction
34400  to increment its 
34401 \emph on
34402 dptr
34403 \emph default
34404
34405 \begin_inset LatexCommand \index{DPTR}
34406
34407 \end_inset
34408
34409 -datapointer
34410 \emph on
34411  
34412 \emph default
34413 so little-endian is the more efficient byte order.
34414 \end_layout
34415
34416 \end_inset
34417
34418
34419 \begin_inset LatexCommand \index{little-endian}
34420
34421 \end_inset
34422
34423
34424 \begin_inset LatexCommand \index{Endianness}
34425
34426 \end_inset
34427
34428  format (i.e.
34429  lowest order first).
34430 \end_layout
34431
34432 \begin_layout Subsection
34433 Highest Order Bit
34434 \begin_inset LatexCommand \index{Highest Order Bit}
34435
34436 \end_inset
34437
34438  / Any Order Bit
34439 \begin_inset LatexCommand \index{Any Order Bit}
34440
34441 \end_inset
34442
34443
34444 \end_layout
34445
34446 \begin_layout Standard
34447 It is frequently required to obtain the highest order bit of an integral
34448  type (long, int, short or char types).
34449  Also obtaining any other order bit is not uncommon.
34450  SDCC recognizes the following expressions to yield the highest order bit
34451  and generates optimized code for it, e.g.:
34452 \end_layout
34453
34454 \begin_layout Verse
34455
34456 \family typewriter
34457 unsigned int gint; 
34458 \newline
34459
34460 \newline
34461 foo () { 
34462 \newline
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 unsigned char hob1, aob1; 
34466 \newline
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 bit hob2, hob3, aob2,
34470  aob3; 
34471 \newline
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 ...
34475  
34476 \newline
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 hob1 = (gint >> 15) & 1; 
34480 \newline
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 hob2 = (gint >> 15) & 1; 
34484 \newline
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 hob3 = gint & 0x8000;
34488  
34489 \newline
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 aob1 = (gint >> 9) & 1; 
34493 \newline
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 aob2 = (gint >> 8) & 1; 
34497 \newline
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 aob3 = gint & 0x0800; 
34501 \newline
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 ..
34505  
34506 \newline
34507 }
34508 \end_layout
34509
34510 \begin_layout Standard
34511 will generate the following code:
34512 \end_layout
34513
34514 \begin_layout Verse
34515
34516 \family typewriter
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 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542  61 ;\InsetSpace ~
34543  hob.c 7 
34544 \newline
34545 000A E5*01\InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560  62\InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568  mov\InsetSpace ~
34569 \InsetSpace ~
34570  a,(_gint + 1) 
34571 \newline
34572 000C 23\InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590  63\InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598  rl\InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601  a 
34602 \newline
34603 000D 54 01\InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618
34619  64\InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627  anl\InsetSpace ~
34628 \InsetSpace ~
34629  a,#0x01 
34630 \newline
34631 000F F5*02\InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646  65\InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654  mov\InsetSpace ~
34655 \InsetSpace ~
34656  _foo_hob1_1_1,a 
34657 \newline
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 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683  66 ;\InsetSpace ~
34684  hob.c 8 
34685 \newline
34686 0011 E5*01\InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701
34702  67\InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710  mov\InsetSpace ~
34711 \InsetSpace ~
34712  a,(_gint + 1) 
34713 \newline
34714 0013 33\InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732  68\InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740  rlc\InsetSpace ~
34741 \InsetSpace ~
34742  a 
34743 \newline
34744 0014 92*00\InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759  69\InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767  mov\InsetSpace ~
34768 \InsetSpace ~
34769  _foo_hob2_1_1,c
34770  
34771 \newline
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 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797  66 ;\InsetSpace ~
34798  hob.c 9 
34799 \newline
34800 0016 E5*01\InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815  67\InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823  mov\InsetSpace ~
34824 \InsetSpace ~
34825  a,(_gint + 1) 
34826 \newline
34827 0018 33\InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845  68\InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853  rlc\InsetSpace ~
34854 \InsetSpace ~
34855  a 
34856 \newline
34857 0019 92*01\InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872
34873  69\InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881  mov\InsetSpace ~
34882 \InsetSpace ~
34883  _foo_hob3_1_1,c 
34884 \newline
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 \InsetSpace ~
34901 \InsetSpace ~
34902 \InsetSpace ~
34903 \InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908 \InsetSpace ~
34909 \InsetSpace ~
34910  70 ;\InsetSpace ~
34911  hob.c 10 
34912 \newline
34913 001B E5*01\InsetSpace ~
34914 \InsetSpace ~
34915 \InsetSpace ~
34916 \InsetSpace ~
34917 \InsetSpace ~
34918 \InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925 \InsetSpace ~
34926 \InsetSpace ~
34927 \InsetSpace ~
34928  71\InsetSpace ~
34929 \InsetSpace ~
34930 \InsetSpace ~
34931 \InsetSpace ~
34932 \InsetSpace ~
34933 \InsetSpace ~
34934 \InsetSpace ~
34935 \InsetSpace ~
34936  mov\InsetSpace ~
34937 \InsetSpace ~
34938  a,(_gint + 1) 
34939 \newline
34940 001D
34941  03\InsetSpace ~
34942 \InsetSpace ~
34943 \InsetSpace ~
34944 \InsetSpace ~
34945 \InsetSpace ~
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 \InsetSpace ~
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 \InsetSpace ~
34955 \InsetSpace ~
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 \InsetSpace ~
34959  72\InsetSpace ~
34960 \InsetSpace ~
34961 \InsetSpace ~
34962 \InsetSpace ~
34963 \InsetSpace ~
34964 \InsetSpace ~
34965 \InsetSpace ~
34966 \InsetSpace ~
34967  rr\InsetSpace ~
34968 \InsetSpace ~
34969 \InsetSpace ~
34970  a 
34971 \newline
34972 001E 54 01\InsetSpace ~
34973 \InsetSpace ~
34974 \InsetSpace ~
34975 \InsetSpace ~
34976 \InsetSpace ~
34977 \InsetSpace ~
34978 \InsetSpace ~
34979 \InsetSpace ~
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 \InsetSpace ~
34985 \InsetSpace ~
34986 \InsetSpace ~
34987  73\InsetSpace ~
34988 \InsetSpace ~
34989 \InsetSpace ~
34990 \InsetSpace ~
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 \InsetSpace ~
34995  anl\InsetSpace ~
34996 \InsetSpace ~
34997  a,#0x01 
34998 \newline
34999 0020 F5*03\InsetSpace ~
35000 \InsetSpace ~
35001 \InsetSpace ~
35002 \InsetSpace ~
35003 \InsetSpace ~
35004 \InsetSpace ~
35005 \InsetSpace ~
35006 \InsetSpace ~
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 \InsetSpace ~
35014  74\InsetSpace ~
35015 \InsetSpace ~
35016 \InsetSpace ~
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 \InsetSpace ~
35022  mov\InsetSpace ~
35023 \InsetSpace ~
35024  _foo_aob1_1_1,a
35025  
35026 \newline
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 \InsetSpace ~
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052  75 ;\InsetSpace ~
35053  hob.c 11 
35054 \newline
35055 0022 E5*01\InsetSpace ~
35056 \InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059 \InsetSpace ~
35060 \InsetSpace ~
35061 \InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070  76\InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078  mov\InsetSpace ~
35079 \InsetSpace ~
35080  a,(_gint + 1) 
35081 \newline
35082 0024 13\InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090 \InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100  77\InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108  rrc\InsetSpace ~
35109 \InsetSpace ~
35110  a 
35111 \newline
35112 0025 92*02\InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115 \InsetSpace ~
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 \InsetSpace ~
35119 \InsetSpace ~
35120 \InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126 \InsetSpace ~
35127
35128  78\InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135 \InsetSpace ~
35136  mov\InsetSpace ~
35137 \InsetSpace ~
35138  _foo_aob2_1_1,c 
35139 \newline
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 \InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 \InsetSpace ~
35159 \InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163 \InsetSpace ~
35164 \InsetSpace ~
35165  79 ;\InsetSpace ~
35166  hob.c 12 
35167 \newline
35168 0027 E5*01\InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 \InsetSpace ~
35173 \InsetSpace ~
35174 \InsetSpace ~
35175 \InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183  80\InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191  mov\InsetSpace ~
35192 \InsetSpace ~
35193  a,(_gint + 1) 
35194 \newline
35195 0029
35196  A2 E3\InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199 \InsetSpace ~
35200 \InsetSpace ~
35201 \InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211  81\InsetSpace ~
35212 \InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218 \InsetSpace ~
35219  mov\InsetSpace ~
35220 \InsetSpace ~
35221  c,acc[3] 
35222 \newline
35223 002B 92*03\InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228 \InsetSpace ~
35229 \InsetSpace ~
35230 \InsetSpace ~
35231 \InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 \InsetSpace ~
35238  82\InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245 \InsetSpace ~
35246  mov\InsetSpace ~
35247 \InsetSpace ~
35248  _foo_aob3_1_1,c 
35249 \end_layout
35250
35251 \begin_layout Standard
35252 Other variations of these cases however will 
35253 \emph on
35254 not
35255 \emph default
35256  be recognized.
35257  They are standard C expressions, so I heartily recommend these be the only
35258  way to get the highest order bit, (it is portable).
35259  Of course it will be recognized even if it is embedded in other expressions,
35260  e.g.:
35261 \end_layout
35262
35263 \begin_layout Verse
35264
35265 \family typewriter
35266 xyz = gint + ((gint >> 15) & 1);
35267 \end_layout
35268
35269 \begin_layout Standard
35270 will still be recognized.
35271 \end_layout
35272
35273 \begin_layout Subsection
35274 Higher Order Byte
35275 \begin_inset LatexCommand \index{Higher Order Byte}
35276
35277 \end_inset
35278
35279  / Higher Order Word
35280 \begin_inset LatexCommand \index{Higher Order Word}
35281
35282 \end_inset
35283
35284
35285 \end_layout
35286
35287 \begin_layout Standard
35288 It is also frequently required to obtain a higher order byte or word of
35289  a larger integral type (long, int or short types).
35290  SDCC recognizes the following expressions to yield the higher order byte
35291  or word and generates optimized code for it, e.g.:
35292 \end_layout
35293
35294 \begin_layout Verse
35295
35296 \family typewriter
35297 unsigned int gint; 
35298 \newline
35299 unsigned long int glong; 
35300 \newline
35301
35302 \newline
35303 foo () { 
35304 \newline
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 unsigned char hob1,
35308  hob2; 
35309 \newline
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 unsigned int how1, how2; 
35313 \newline
35314 \InsetSpace ~
35315 \InsetSpace ~
35316 ...
35317  
35318 \newline
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 hob1 = (gint >> 8) & 0xFF; 
35322 \newline
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 hob2 = glong >> 24; 
35326 \newline
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 how1 = (glong >> 16) & 0xFFFF;
35330  
35331 \newline
35332 \InsetSpace ~
35333 \InsetSpace ~
35334 how2 = glong >> 8; 
35335 \newline
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 ..
35339  
35340 \newline
35341 }
35342 \end_layout
35343
35344 \begin_layout Standard
35345 will generate the following code:
35346 \end_layout
35347
35348 \begin_layout Verse
35349
35350 \family typewriter
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 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376  91 ;\InsetSpace ~
35377  hob.c 15 
35378 \newline
35379 0037 85*01*06\InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390 \InsetSpace ~
35391  92\InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399  mov\InsetSpace ~
35400 \InsetSpace ~
35401  _foo_hob1_1_1,(_gint + 1) 
35402 \newline
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 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428  93 ;\InsetSpace ~
35429  hob.c
35430  16 
35431 \newline
35432 003A 85*05*07\InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444  94\InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452  mov\InsetSpace ~
35453 \InsetSpace ~
35454  _foo_hob2_1_1,(_glong + 3) 
35455 \newline
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 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481  95 ;\InsetSpace ~
35482  hob.c 17 
35483 \newline
35484 003D 85*04*08\InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 \InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496
35497  96\InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505  mov\InsetSpace ~
35506 \InsetSpace ~
35507  _foo_how1_1_1,(_glong + 2) 
35508 \newline
35509 0040 85*05*09\InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 \InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521  97\InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529  mov\InsetSpace ~
35530 \InsetSpace ~
35531  (_foo_how1_1_1 +
35532  1),(_glong + 3) 
35533 \newline
35534 0043 85*03*0A\InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545 \InsetSpace ~
35546  98\InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554  mov\InsetSpace ~
35555 \InsetSpace ~
35556  _foo_how2_1_1,(_glong + 1) 
35557 \newline
35558 0046 85*04*0B\InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570
35571  99\InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579  mov\InsetSpace ~
35580 \InsetSpace ~
35581  (_foo_how2_1_1 + 1),(_glong + 2) 
35582 \end_layout
35583
35584 \begin_layout Standard
35585 Again, variations of these cases may 
35586 \emph on
35587 not
35588 \emph default
35589  be recognized.
35590  They are standard C expressions, so I heartily recommend these be the only
35591  way to get the higher order byte/word, (it is portable).
35592  Of course it will be recognized even if it is embedded in other expressions,
35593  e.g.:
35594 \end_layout
35595
35596 \begin_layout Verse
35597
35598 \family typewriter
35599 xyz = gint + ((gint >> 8) & 0xFF);
35600 \end_layout
35601
35602 \begin_layout Standard
35603 will still be recognized.
35604 \end_layout
35605
35606 \begin_layout Subsection
35607 Peephole Optimizer
35608 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35609
35610 \end_inset
35611
35612
35613 \begin_inset LatexCommand \index{Peephole optimizer}
35614
35615 \end_inset
35616
35617
35618 \end_layout
35619
35620 \begin_layout Standard
35621 The compiler uses a rule based, pattern matching and re-writing mechanism
35622  for peep-hole optimization.
35623  It is inspired by 
35624 \emph on
35625 copt
35626 \emph default
35627  a peep-hole optimizer by Christopher W.
35628  Fraser (cwfraser\InsetSpace ~
35629 @\InsetSpace ~
35630 microsoft.com).
35631  A default set of rules are compiled into the compiler, additional rules
35632  may be added with the 
35633 \emph on
35634 -
35635 \begin_inset ERT
35636 status collapsed
35637
35638 \begin_layout Standard
35639
35640
35641 \backslash
35642 /
35643 \end_layout
35644
35645 \end_inset
35646
35647 -peep-file
35648 \begin_inset LatexCommand \index{-\/-peep-file}
35649
35650 \end_inset
35651
35652  <filename>
35653 \emph default
35654  option.
35655  The rule language is best illustrated with examples.
35656 \end_layout
35657
35658 \begin_layout Verse
35659
35660 \family typewriter
35661 replace { 
35662 \newline
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 mov %1,a 
35666 \newline
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 mov a,%1
35670 \newline
35671 } by {
35672 \newline
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 mov %1,a
35676 \newline
35677 }
35678 \end_layout
35679
35680 \begin_layout Standard
35681 The above rule will change the following assembly
35682 \begin_inset LatexCommand \index{Assembler routines}
35683
35684 \end_inset
35685
35686  sequence:
35687 \end_layout
35688
35689 \begin_layout Verse
35690
35691 \family typewriter
35692 mov r1,a 
35693 \newline
35694 mov a,r1
35695 \end_layout
35696
35697 \begin_layout Standard
35698 to
35699 \end_layout
35700
35701 \begin_layout Verse
35702
35703 \family typewriter
35704 mov r1,a
35705 \end_layout
35706
35707 \begin_layout Standard
35708 Note: All occurrences of a 
35709 \emph on
35710 %n
35711 \emph default
35712  (pattern variable) must denote the same string.
35713  With the above rule, the assembly sequence:
35714 \end_layout
35715
35716 \begin_layout Verse
35717
35718 \family typewriter
35719 mov r1,a 
35720 \newline
35721 mov a,r2
35722 \end_layout
35723
35724 \begin_layout Standard
35725 will remain unmodified.
35726 \newline
35727
35728 \newline
35729 Other special case optimizations may be added by the
35730  user (via 
35731 \emph on
35732 -
35733 \begin_inset ERT
35734 status collapsed
35735
35736 \begin_layout Standard
35737
35738
35739 \backslash
35740 /
35741 \end_layout
35742
35743 \end_inset
35744
35745 -peep-file option
35746 \emph default
35747 ).
35748  E.g.
35749  some variants of the 8051 MCU
35750 \begin_inset LatexCommand \index{MCS51 variants}
35751
35752 \end_inset
35753
35754  allow only 
35755 \family typewriter
35756 ajmp
35757 \family default
35758  and 
35759 \family typewriter
35760 acall
35761 \family default
35762 .
35763  The following two rules will change all 
35764 \family typewriter
35765 ljmp
35766 \family default
35767  and 
35768 \family typewriter
35769 lcall
35770 \family default
35771  to 
35772 \family typewriter
35773 ajmp
35774 \family default
35775  and 
35776 \family typewriter
35777 acall
35778 \end_layout
35779
35780 \begin_layout Verse
35781
35782 \family typewriter
35783 replace { lcall %1 } by { acall %1 } 
35784 \newline
35785 replace { ljmp %1 } by { ajmp %1 }
35786 \end_layout
35787
35788 \begin_layout Standard
35789 (NOTE: from version 2.7.3 on, you can use option -
35790 \emph on
35791
35792 \begin_inset ERT
35793 status collapsed
35794
35795 \begin_layout Standard
35796
35797
35798 \backslash
35799 /
35800 \end_layout
35801
35802 \end_inset
35803
35804
35805 \emph default
35806 -acall-ajmp
35807 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35808
35809 \end_inset
35810
35811 , which also takes care of aligning the interrupt vectors properly.)
35812 \newline
35813
35814 \end_layout
35815
35816 \begin_layout Standard
35817 The 
35818 \emph on
35819 inline-assembler code
35820 \emph default
35821  is also passed through the peep hole optimizer, thus the peephole optimizer
35822  can also be used as an assembly level macro expander.
35823  The rules themselves are MCU dependent whereas the rule language infra-structur
35824 e is MCU independent.
35825  Peephole optimization rules for other MCU can be easily programmed using
35826  the rule language.
35827 \newline
35828
35829 \newline
35830 The syntax for a rule is as follows:
35831 \end_layout
35832
35833 \begin_layout Verse
35834
35835 \family typewriter
35836 rule := replace [ restart ] '{' <assembly sequence> '
35837 \backslash
35838 n' 
35839 \newline
35840 \InsetSpace ~
35841  \InsetSpace ~
35842  \InsetSpace ~
35843  \InsetSpace ~
35844  \InsetSpace ~
35845  \InsetSpace ~
35846  \InsetSpace ~
35847  \InsetSpace ~
35848  \InsetSpace ~
35849  \InsetSpace ~
35850  \InsetSpace ~
35851  \InsetSpace ~
35852  \InsetSpace ~
35853  \InsetSpace ~
35854  '}' by '{' '
35855 \backslash
35856 n' 
35857 \newline
35858 \InsetSpace ~
35859  \InsetSpace ~
35860  \InsetSpace ~
35861  \InsetSpace ~
35862  \InsetSpace ~
35863  \InsetSpace ~
35864  \InsetSpace ~
35865  \InsetSpace ~
35866  \InsetSpace ~
35867  \InsetSpace ~
35868  \InsetSpace ~
35869  \InsetSpace ~
35870  \InsetSpace ~
35871  \InsetSpace ~
35872  \InsetSpace ~
35873  \InsetSpace ~
35874  <assembly sequence> '
35875 \backslash
35876 n' 
35877 \newline
35878 \InsetSpace ~
35879  \InsetSpace ~
35880  \InsetSpace ~
35881  \InsetSpace ~
35882  \InsetSpace ~
35883  \InsetSpace ~
35884  \InsetSpace ~
35885  \InsetSpace ~
35886  \InsetSpace ~
35887  \InsetSpace ~
35888  \InsetSpace ~
35889  \InsetSpace ~
35890  \InsetSpace ~
35891  \InsetSpace ~
35892  '}' [if <functionName> ] '
35893 \backslash
35894 n' 
35895 \end_layout
35896
35897 \begin_layout Standard
35898 <assembly sequence> := assembly instruction (each instruction including
35899  labels must be on a separate line).
35900 \newline
35901
35902 \newline
35903 The optimizer will apply to the rules
35904  one by one from the top in the sequence of their appearance, it will terminate
35905  when all rules are exhausted.
35906  If the 'restart' option is specified, then the optimizer will start matching
35907  the rules again from the top, this option for a rule is expensive (performance)
35908 , it is intended to be used in situations where a transformation will trigger
35909  the same rule again.
35910  An example of this (not a good one, it has side effects) is the following
35911  rule:
35912 \end_layout
35913
35914 \begin_layout Verse
35915
35916 \family typewriter
35917 replace restart { 
35918 \newline
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 pop %1 
35922 \newline
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 push %1 } by { 
35926 \newline
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 ; nop 
35930 \newline
35931 }
35932 \end_layout
35933
35934 \begin_layout Standard
35935 Note that the replace pattern cannot be a blank, but can be a comment line.
35936  Without the 'restart' option only the innermost 'pop' 'push' pair would
35937  be eliminated, i.e.:
35938 \end_layout
35939
35940 \begin_layout Verse
35941
35942 \family typewriter
35943 pop ar1 
35944 \newline
35945 pop ar2 
35946 \newline
35947 push ar2 
35948 \newline
35949 push ar1
35950 \end_layout
35951
35952 \begin_layout Standard
35953 would result in:
35954 \end_layout
35955
35956 \begin_layout Verse
35957
35958 \family typewriter
35959 pop ar1 
35960 \newline
35961 ; nop 
35962 \newline
35963 push ar1
35964 \end_layout
35965
35966 \begin_layout Standard
35967
35968 \emph on
35969 with
35970 \emph default
35971  the restart option the rule will be applied again to the resulting code
35972  and then all the pop-push pairs will be eliminated to yield:
35973 \end_layout
35974
35975 \begin_layout Verse
35976
35977 \family typewriter
35978 ; nop 
35979 \newline
35980 ; nop
35981 \end_layout
35982
35983 \begin_layout Standard
35984 A conditional function can be attached to a rule.
35985  Attaching rules are somewhat more involved, let me illustrate this with
35986  an example.
35987 \end_layout
35988
35989 \begin_layout Verse
35990
35991 \family typewriter
35992 replace { 
35993 \newline
35994 \InsetSpace ~
35995  \InsetSpace ~
35996  \InsetSpace ~
35997 ljmp %5 
35998 \newline
35999 %2:
36000 \newline
36001 } by { 
36002 \newline
36003 \InsetSpace ~
36004  \InsetSpace ~
36005  \InsetSpace ~
36006 sjmp %5 
36007 \newline
36008 %2:
36009 \newline
36010 } if labelInRange
36011 \end_layout
36012
36013 \begin_layout Standard
36014 The optimizer does a look-up of a function name table defined in function
36015  
36016 \emph on
36017 callFuncByName
36018 \emph default
36019  in the source file SDCCpeeph.c, with the name 
36020 \emph on
36021 labelInRange
36022 \emph default
36023 .
36024  If it finds a corresponding entry the function is called.
36025  Note there can be no parameters specified for these functions, in this
36026  case the use of 
36027 \emph on
36028 %5
36029 \emph default
36030  is crucial, since the function 
36031 \emph on
36032 labelInRange
36033 \emph default
36034  expects to find the label in that particular variable (the hash table containin
36035 g the variable bindings is passed as a parameter).
36036  If you want to code more such functions, take a close look at the function
36037  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36038  Currently implemented are 
36039 \emph on
36040 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36041  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36042 \emph default
36043 and
36044 \emph on
36045  notVolatile
36046 \emph default
36047 .
36048 \end_layout
36049
36050 \begin_layout Standard
36051 I know this whole thing is a little kludgey, but maybe some day we will
36052  have some better means.
36053  If you are looking at this file, you will see the default rules that are
36054  compiled into the compiler, you can add your own rules in the default set
36055  there if you get tired of specifying the -
36056 \begin_inset ERT
36057 status collapsed
36058
36059 \begin_layout Standard
36060
36061
36062 \backslash
36063 /
36064 \end_layout
36065
36066 \end_inset
36067
36068 -peep-file option.
36069 \end_layout
36070
36071 \begin_layout Section
36072 ANSI-Compliance
36073 \begin_inset LatexCommand \index{ANSI-compliance}
36074
36075 \end_inset
36076
36077
36078 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36079
36080 \end_inset
36081
36082
36083 \end_layout
36084
36085 \begin_layout Standard
36086 The latest publically available version of the standard 
36087 \emph on
36088 ISO/IEC 9899 - Programming languages - C
36089 \emph default
36090  should be available at: 
36091 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36092
36093 \end_inset
36094
36095 .
36096 \newline
36097
36098 \end_layout
36099
36100 \begin_layout Standard
36101 Deviations from the compliance:
36102 \end_layout
36103
36104 \begin_layout Itemize
36105 functions are not reentrant
36106 \begin_inset LatexCommand \index{reentrant}
36107
36108 \end_inset
36109
36110  unless explicitly declared as such or the 
36111 \series bold
36112 -
36113 \begin_inset ERT
36114 status collapsed
36115
36116 \begin_layout Standard
36117
36118
36119 \backslash
36120 /
36121 \end_layout
36122
36123 \end_inset
36124
36125 -stack-auto
36126 \begin_inset LatexCommand \index{-\/-stack-auto}
36127
36128 \end_inset
36129
36130
36131 \series default
36132  command line option is specified.
36133 \end_layout
36134
36135 \begin_layout Itemize
36136 structures
36137 \begin_inset LatexCommand \index{struct}
36138
36139 \end_inset
36140
36141  and unions
36142 \begin_inset LatexCommand \index{union}
36143
36144 \end_inset
36145
36146  cannot be assigned values directly, cannot be passed as function parameters
36147  or assigned to each other and cannot be a return value
36148 \begin_inset LatexCommand \index{return value}
36149
36150 \end_inset
36151
36152  from a function, e.g.:
36153 \end_layout
36154
36155 \begin_deeper
36156 \begin_layout Verse
36157
36158 \family typewriter
36159 struct s { ...
36160  }; 
36161 \newline
36162 struct s s1, s2; 
36163 \newline
36164 foo() 
36165 \newline
36166
36167 \newline
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172 ...
36173  
36174 \newline
36175 \InsetSpace ~
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36180 \newline
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 \InsetSpace ~
36185 ...
36186  
36187 \newline
36188 }
36189 \newline
36190
36191 \series bold
36192 struct
36193 \series default
36194  s foo1 (
36195 \series bold
36196 struct
36197 \series default
36198  s parms) /* invalid in SDCC although allowed in ANSI */
36199 \newline
36200
36201 \newline
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 \InsetSpace ~
36205 \InsetSpace ~
36206 struct s rets;
36207  
36208 \newline
36209 \InsetSpace ~
36210 \InsetSpace ~
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 ...
36214  
36215 \newline
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36221 \newline
36222 }
36223 \end_layout
36224
36225 \end_deeper
36226 \begin_layout Itemize
36227 initialization of structure arrays must be fully braced.
36228 \end_layout
36229
36230 \begin_deeper
36231 \begin_layout Verse
36232
36233 \family typewriter
36234 struct s { char x } a[] = {1, 2};\InsetSpace ~
36235 \InsetSpace ~
36236 \InsetSpace ~
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 /* invalid in SDCC */
36240 \newline
36241 struct s { char x
36242  } a[] = {{1}, {2}}; /* OK */
36243 \end_layout
36244
36245 \end_deeper
36246 \begin_layout Itemize
36247 'long long
36248 \begin_inset LatexCommand \index{long long (not supported)}
36249
36250 \end_inset
36251
36252 ' (64 bit integers
36253 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36254
36255 \end_inset
36256
36257 ) not supported.
36258 \end_layout
36259
36260 \begin_layout Itemize
36261 'double
36262 \begin_inset LatexCommand \index{double (not supported)}
36263
36264 \end_inset
36265
36266 ' precision floating point 
36267 \begin_inset LatexCommand \index{Floating point support}
36268
36269 \end_inset
36270
36271 not supported.
36272 \end_layout
36273
36274 \begin_layout Itemize
36275 Old K&R style
36276 \begin_inset LatexCommand \index{K\&R style}
36277
36278 \end_inset
36279
36280  function declarations are NOT allowed.
36281 \end_layout
36282
36283 \begin_deeper
36284 \begin_layout Verse
36285
36286 \family typewriter
36287 foo(i,j) /* this old style of function declarations */ 
36288 \newline
36289 int i,j; /* is valid
36290  in ANSI but not valid in SDCC */ 
36291 \newline
36292
36293 \newline
36294 \InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 ...
36299  
36300 \newline
36301 }
36302 \end_layout
36303
36304 \end_deeper
36305 \begin_layout Itemize
36306 Most enhancements in C99 are not supported, e.g.:
36307 \end_layout
36308
36309 \begin_deeper
36310 \begin_layout Verse
36311
36312 \family typewriter
36313 for (
36314 \series bold
36315 int
36316 \series default
36317  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36318 \end_layout
36319
36320 \end_deeper
36321 \begin_layout Itemize
36322 But some have been added recently in SDCC 2.7.0.
36323  They must be considered alpha quality however.
36324 \end_layout
36325
36326 \begin_deeper
36327 \begin_layout Verse
36328
36329 \family typewriter
36330 \series bold
36331 inline
36332 \begin_inset LatexCommand \index{inline (not supported)}
36333
36334 \end_inset
36335
36336
36337 \series default
36338  int increment (int a) { return a+1; } /* inlines the increment without
36339  function call overhead */
36340 \newline
36341 int * 
36342 \series bold
36343 restrict
36344 \begin_inset LatexCommand \index{inline (not supported)}
36345
36346 \end_inset
36347
36348
36349 \series default
36350  p; /* accepted but ignored */
36351 \end_layout
36352
36353 \end_deeper
36354 \begin_layout Itemize
36355 Certain words that are valid identifiers in the standard may be reserved
36356  words in SDCC unless the 
36357 \series bold
36358 -
36359 \begin_inset ERT
36360 status collapsed
36361
36362 \begin_layout Standard
36363
36364
36365 \backslash
36366 /
36367 \end_layout
36368
36369 \end_inset
36370
36371 -std-c89
36372 \begin_inset LatexCommand \index{-\/-std-c89}
36373
36374 \end_inset
36375
36376  or -
36377 \begin_inset ERT
36378 status collapsed
36379
36380 \begin_layout Standard
36381
36382
36383 \backslash
36384 /
36385 \end_layout
36386
36387 \end_inset
36388
36389 -std-c99
36390 \begin_inset LatexCommand \index{-\/-std-c99}
36391
36392 \end_inset
36393
36394
36395 \series default
36396  command line options are used.
36397  These may include (depending on the selected processor): 'at', 'banked',
36398  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36399 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36400  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36401  '_naked'.
36402  Compliant equivalents of these keywords are always available in a form
36403  that begin with two underscores
36404 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36405
36406 \end_inset
36407
36408 , f.e.
36409  '__data' instead of 'data'.
36410 \end_layout
36411
36412 \begin_layout Section
36413 Cyclomatic Complexity
36414 \begin_inset LatexCommand \index{Cyclomatic complexity}
36415
36416 \end_inset
36417
36418
36419 \end_layout
36420
36421 \begin_layout Standard
36422 Cyclomatic complexity of a function is defined as the number of independent
36423  paths the program can take during execution of the function.
36424  This is an important number since it defines the number test cases you
36425  have to generate to validate the function.
36426  The accepted industry standard for complexity number is 10, if the cyclomatic
36427  complexity reported by SDCC exceeds 10 you should think about simplification
36428  of the function logic.
36429  Note that the complexity level is not related to the number of lines of
36430  code in a function.
36431  Large functions can have low complexity, and small functions can have large
36432  complexity levels.
36433  
36434 \newline
36435
36436 \newline
36437 SDCC uses the following formula to compute the complexity:
36438 \newline
36439
36440 \end_layout
36441
36442 \begin_layout Standard
36443 complexity = (number of edges in control flow graph) - (number of nodes
36444  in control flow graph) + 2;
36445 \newline
36446
36447 \newline
36448 Having said that the industry standard is 10,
36449  you should be aware that in some cases it be may unavoidable to have a
36450  complexity level of less than 10.
36451  For example if you have switch statement with more than 10 case labels,
36452  each case label adds one to the complexity level.
36453  The complexity level is by no means an absolute measure of the algorithmic
36454  complexity of the function, it does however provide a good starting point
36455  for which functions you might look at for further optimization.
36456 \end_layout
36457
36458 \begin_layout Section
36459 Retargetting for other Processors
36460 \end_layout
36461
36462 \begin_layout Standard
36463 The issues for retargetting the compiler are far too numerous to be covered
36464  by this document.
36465  What follows is a brief description of each of the seven phases of the
36466  compiler and its MCU dependency.
36467 \end_layout
36468
36469 \begin_layout Itemize
36470 Parsing the source and building the annotated parse tree.
36471  This phase is largely MCU independent (except for the language extensions).
36472  Syntax & semantic checks are also done in this phase, along with some initial
36473  optimizations like back patching labels and the pattern matching optimizations
36474  like bit-rotation etc.
36475 \end_layout
36476
36477 \begin_layout Itemize
36478 The second phase involves generating an intermediate code which can be easy
36479  manipulated during the later phases.
36480  This phase is entirely MCU independent.
36481  The intermediate code generation assumes the target machine has unlimited
36482  number of registers, and designates them with the name iTemp.
36483  The compiler can be made to dump a human readable form of the code generated
36484  by using the -
36485 \begin_inset ERT
36486 status collapsed
36487
36488 \begin_layout Standard
36489
36490
36491 \backslash
36492 /
36493 \end_layout
36494
36495 \end_inset
36496
36497 -dumpraw option.
36498 \end_layout
36499
36500 \begin_layout Itemize
36501 This phase does the bulk of the standard optimizations and is also MCU independe
36502 nt.
36503  This phase can be broken down into several sub-phases:
36504 \newline
36505
36506 \newline
36507 Break down intermediate
36508  code (iCode) into basic blocks.
36509 \newline
36510 Do control flow & data flow analysis on the
36511  basic blocks.
36512 \newline
36513 Do local common subexpression elimination, then global subexpressio
36514 n elimination
36515 \newline
36516 Dead code elimination
36517 \newline
36518 Loop optimizations
36519 \newline
36520 If loop optimizations
36521  caused any changes then do 'global subexpression elimination' and 'dead
36522  code elimination' again.
36523 \end_layout
36524
36525 \begin_layout Itemize
36526 This phase determines the live-ranges; by live range I mean those iTemp
36527  variables defined by the compiler that still survive after all the optimization
36528 s.
36529  Live range analysis
36530 \begin_inset LatexCommand \index{Live range analysis}
36531
36532 \end_inset
36533
36534  is essential for register allocation, since these computation determines
36535  which of these iTemps will be assigned to registers, and for how long.
36536 \end_layout
36537
36538 \begin_layout Itemize
36539 Phase five is register allocation.
36540  There are two parts to this process.
36541 \newline
36542
36543 \newline
36544 The first part I call 'register packing'
36545  (for lack of a better term).
36546  In this case several MCU specific expression folding is done to reduce
36547  register pressure.
36548 \newline
36549
36550 \newline
36551 The second part is more MCU independent and deals with
36552  allocating registers to the remaining live ranges.
36553  A lot of MCU specific code does creep into this phase because of the limited
36554  number of index registers available in the 8051.
36555 \end_layout
36556
36557 \begin_layout Itemize
36558 The Code generation phase is (unhappily), entirely MCU dependent and very
36559  little (if any at all) of this code can be reused for other MCU.
36560  However the scheme for allocating a homogenized assembler operand for each
36561  iCode operand may be reused.
36562 \end_layout
36563
36564 \begin_layout Itemize
36565 As mentioned in the optimization section the peep-hole optimizer is rule
36566  based system, which can reprogrammed for other MCUs.
36567 \end_layout
36568
36569 \begin_layout Standard
36570 More information is available on SDCC Wiki
36571 \begin_inset LatexCommand \index{wiki}
36572
36573 \end_inset
36574
36575  (preliminary link 
36576 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36577
36578 \end_inset
36579
36580 ) and in the thread 
36581 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36582
36583 \end_inset
36584
36585  .
36586 \end_layout
36587
36588 \begin_layout Chapter
36589 Compiler internals
36590 \begin_inset LatexCommand \index{Compiler internals}
36591
36592 \end_inset
36593
36594
36595 \end_layout
36596
36597 \begin_layout Section
36598 The anatomy of the compiler
36599 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36600
36601 \end_inset
36602
36603
36604 \end_layout
36605
36606 \begin_layout Standard
36607
36608 \shape italic
36609 This is an excerpt from an article published in Circuit Cellar Magazine
36610  in 
36611 \series bold
36612 August 2000
36613 \series default
36614 .
36615  It's a little outdated (the compiler is much more efficient now and user/develo
36616 per friendly), but pretty well exposes the guts of it all.
36617 \shape default
36618
36619 \newline
36620
36621 \newline
36622 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36623  It is fairly easy to retarget for other 8-bit MCU.
36624  Here we take a look at some of the internals of the compiler.
36625  
36626 \end_layout
36627
36628 \begin_layout Paragraph*
36629 Parsing
36630 \begin_inset LatexCommand \index{Parsing}
36631
36632 \end_inset
36633
36634  
36635 \end_layout
36636
36637 \begin_layout Standard
36638 Parsing the input source file and creating an AST (Annotated Syntax Tree
36639 \begin_inset LatexCommand \index{Annotated syntax tree}
36640
36641 \end_inset
36642
36643 ).
36644  This phase also involves propagating types (annotating each node of the
36645  parse tree with type information) and semantic analysis.
36646  There are some MCU specific parsing rules.
36647  For example the storage classes, the extended storage classes are MCU specific
36648  while there may be a xdata storage class for 8051 there is no such storage
36649  class for z80 or Atmel AVR.
36650  SDCC allows MCU specific storage class extensions, i.e.
36651  xdata will be treated as a storage class specifier when parsing 8051 C
36652  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36653  C code.
36654 \end_layout
36655
36656 \begin_layout Paragraph*
36657 Generating iCode
36658 \begin_inset LatexCommand \index{iCode}
36659
36660 \end_inset
36661
36662
36663 \end_layout
36664
36665 \begin_layout Standard
36666 Intermediate code generation.
36667  In this phase the AST is broken down into three-operand form (iCode).
36668  These three operand forms are represented as doubly linked lists.
36669  ICode is the term given to the intermediate form generated by the compiler.
36670  ICode example section shows some examples of iCode generated for some simple
36671  C source functions.
36672 \end_layout
36673
36674 \begin_layout Paragraph*
36675 Optimizations
36676 \begin_inset LatexCommand \index{Optimizations}
36677
36678 \end_inset
36679
36680 .
36681 \end_layout
36682
36683 \begin_layout Standard
36684 Bulk of the target independent optimizations is performed in this phase.
36685  The optimizations include constant propagation, common sub-expression eliminati
36686 on, loop invariant code movement, strength reduction of loop induction variables
36687  and dead-code elimination.
36688 \end_layout
36689
36690 \begin_layout Paragraph*
36691 Live range analysis
36692 \begin_inset LatexCommand \index{Live range analysis}
36693
36694 \end_inset
36695
36696
36697 \end_layout
36698
36699 \begin_layout Standard
36700 During intermediate code generation phase, the compiler assumes the target
36701  machine has infinite number of registers and generates a lot of temporary
36702  variables.
36703  The live range computation determines the lifetime of each of these compiler-ge
36704 nerated temporaries.
36705  A picture speaks a thousand words.
36706  ICode example sections show the live range annotations for each of the
36707  operand.
36708  It is important to note here, each iCode is assigned a number in the order
36709  of its execution in the function.
36710  The live ranges are computed in terms of these numbers.
36711  The from number is the number of the iCode which first defines the operand
36712  and the to number signifies the iCode which uses this operand last.
36713 \end_layout
36714
36715 \begin_layout Paragraph*
36716 Register Allocation
36717 \begin_inset LatexCommand \index{Register allocation}
36718
36719 \end_inset
36720
36721
36722 \end_layout
36723
36724 \begin_layout Standard
36725 The register allocation determines the type and number of registers needed
36726  by each operand.
36727  In most MCUs only a few registers can be used for indirect addressing.
36728  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36729  address the internal ram and DPTR to indirectly address the external ram.
36730  The compiler will try to allocate the appropriate register to pointer variables
36731  if it can.
36732  ICode example section shows the operands annotated with the registers assigned
36733  to them.
36734  The compiler will try to keep operands in registers as much as possible;
36735  there are several schemes the compiler uses to do achieve this.
36736  When the compiler runs out of registers the compiler will check to see
36737  if there are any live operands which is not used or defined in the current
36738  basic block being processed, if there are any found then it will push that
36739  operand and use the registers in this block, the operand will then be popped
36740  at the end of the basic block.
36741  
36742 \end_layout
36743
36744 \begin_layout Standard
36745 There are other MCU specific considerations in this phase.
36746  Some MCUs have an accumulator; very short-lived operands could be assigned
36747  to the accumulator instead of a general-purpose register.
36748 \end_layout
36749
36750 \begin_layout Paragraph*
36751 Code generation
36752 \end_layout
36753
36754 \begin_layout Standard
36755 Figure II gives a table of iCode
36756 \begin_inset LatexCommand \index{iCode}
36757
36758 \end_inset
36759
36760  operations supported by the compiler.
36761  The code generation involves translating these operations into corresponding
36762  assembly code for the processor.
36763  This sounds overly simple but that is the essence of code generation.
36764  Some of the iCode operations are generated on a MCU specific manner for
36765  example, the z80 port does not use registers to pass parameters so the
36766  SEND and RECV iCode operations will not be generated, and it also does
36767  not support JUMPTABLES.
36768  
36769 \newline
36770
36771 \end_layout
36772
36773 \begin_layout Standard
36774
36775 \size footnotesize
36776 Figure II 
36777 \begin_inset Tabular
36778 <lyxtabular version="3" rows="39" columns="4">
36779 <features islongtable="true" headBottomDL="true">
36780 <column alignment="block" valignment="top" leftline="true" width="13col%">
36781 <column alignment="left" valignment="top" leftline="true" width="13col%">
36782 <column alignment="block" valignment="top" leftline="true" width="22col%">
36783 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36784 <row topline="true" bottomline="true" endhead="true">
36785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36786 \begin_inset Text
36787
36788 \begin_layout Standard
36789
36790 \series bold
36791 iCode
36792 \series default
36793
36794 \begin_inset LatexCommand \index{iCode}
36795
36796 \end_inset
36797
36798
36799 \end_layout
36800
36801 \end_inset
36802 </cell>
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36804 \begin_inset Text
36805
36806 \begin_layout Standard
36807
36808 \series bold
36809 Operands
36810 \end_layout
36811
36812 \end_inset
36813 </cell>
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36815 \begin_inset Text
36816
36817 \begin_layout Standard
36818
36819 \series bold
36820 Description
36821 \end_layout
36822
36823 \end_inset
36824 </cell>
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36826 \begin_inset Text
36827
36828 \begin_layout Standard
36829
36830 \series bold
36831 C Equivalent
36832 \end_layout
36833
36834 \end_inset
36835 </cell>
36836 </row>
36837 <row topline="true">
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36839 \begin_inset Text
36840
36841 \begin_layout Standard
36842
36843 \size footnotesize
36844 '!'
36845 \end_layout
36846
36847 \end_inset
36848 </cell>
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36850 \begin_inset Text
36851
36852 \begin_layout Standard
36853
36854 \size footnotesize
36855 IC_LEFT() IC_RESULT()
36856 \end_layout
36857
36858 \end_inset
36859 </cell>
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36861 \begin_inset Text
36862
36863 \begin_layout Standard
36864
36865 \size footnotesize
36866 NOT operation 
36867 \end_layout
36868
36869 \end_inset
36870 </cell>
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36872 \begin_inset Text
36873
36874 \begin_layout Standard
36875
36876 \size footnotesize
36877 IC_RESULT = ! IC_LEFT;
36878 \end_layout
36879
36880 \end_inset
36881 </cell>
36882 </row>
36883 <row topline="true">
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36885 \begin_inset Text
36886
36887 \begin_layout Standard
36888
36889 \size footnotesize
36890 '~'
36891 \end_layout
36892
36893 \end_inset
36894 </cell>
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36896 \begin_inset Text
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 IC_LEFT() IC_RESULT()
36902 \end_layout
36903
36904 \end_inset
36905 </cell>
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36907 \begin_inset Text
36908
36909 \begin_layout Standard
36910
36911 \size footnotesize
36912 Bitwise complement of 
36913 \end_layout
36914
36915 \end_inset
36916 </cell>
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36918 \begin_inset Text
36919
36920 \begin_layout Standard
36921
36922 \size footnotesize
36923 IC_RESULT = ~IC_LEFT;
36924 \end_layout
36925
36926 \end_inset
36927 </cell>
36928 </row>
36929 <row topline="true">
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36931 \begin_inset Text
36932
36933 \begin_layout Standard
36934
36935 \size footnotesize
36936 RRC
36937 \end_layout
36938
36939 \end_inset
36940 </cell>
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36942 \begin_inset Text
36943
36944 \begin_layout Standard
36945
36946 \size footnotesize
36947 IC_LEFT() IC_RESULT()
36948 \end_layout
36949
36950 \end_inset
36951 </cell>
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36953 \begin_inset Text
36954
36955 \begin_layout Standard
36956
36957 \size footnotesize
36958 Rotate right with carry
36959 \end_layout
36960
36961 \end_inset
36962 </cell>
36963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36964 \begin_inset Text
36965
36966 \begin_layout Standard
36967
36968 \size footnotesize
36969 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36970 \end_layout
36971
36972 \end_inset
36973 </cell>
36974 </row>
36975 <row topline="true">
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36977 \begin_inset Text
36978
36979 \begin_layout Standard
36980
36981 \size footnotesize
36982 RLC
36983 \end_layout
36984
36985 \end_inset
36986 </cell>
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36988 \begin_inset Text
36989
36990 \begin_layout Standard
36991
36992 \size footnotesize
36993 IC_LEFT() IC_RESULT()
36994 \end_layout
36995
36996 \end_inset
36997 </cell>
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36999 \begin_inset Text
37000
37001 \begin_layout Standard
37002
37003 \size footnotesize
37004 Rotate left with carry
37005 \end_layout
37006
37007 \end_inset
37008 </cell>
37009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37010 \begin_inset Text
37011
37012 \begin_layout Standard
37013
37014 \size footnotesize
37015 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37016 \end_layout
37017
37018 \end_inset
37019 </cell>
37020 </row>
37021 <row topline="true">
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37023 \begin_inset Text
37024
37025 \begin_layout Standard
37026
37027 \size footnotesize
37028 GETHBIT
37029 \end_layout
37030
37031 \end_inset
37032 </cell>
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37034 \begin_inset Text
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 IC_LEFT() IC_RESULT()
37040 \end_layout
37041
37042 \end_inset
37043 </cell>
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37045 \begin_inset Text
37046
37047 \begin_layout Standard
37048
37049 \size footnotesize
37050 Get the highest order bit of IC_LEFT
37051 \end_layout
37052
37053 \end_inset
37054 </cell>
37055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37056 \begin_inset Text
37057
37058 \begin_layout Standard
37059
37060 \size footnotesize
37061 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37062 \end_layout
37063
37064 \end_inset
37065 </cell>
37066 </row>
37067 <row topline="true">
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37069 \begin_inset Text
37070
37071 \begin_layout Standard
37072
37073 \size footnotesize
37074 UNARYMINUS
37075 \end_layout
37076
37077 \end_inset
37078 </cell>
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37080 \begin_inset Text
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 IC_LEFT() IC_RESULT()
37086 \end_layout
37087
37088 \end_inset
37089 </cell>
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37091 \begin_inset Text
37092
37093 \begin_layout Standard
37094
37095 \size footnotesize
37096 Unary minus
37097 \end_layout
37098
37099 \end_inset
37100 </cell>
37101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37102 \begin_inset Text
37103
37104 \begin_layout Standard
37105
37106 \size footnotesize
37107 IC_RESULT = - IC_LEFT;
37108 \end_layout
37109
37110 \end_inset
37111 </cell>
37112 </row>
37113 <row topline="true">
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37115 \begin_inset Text
37116
37117 \begin_layout Standard
37118
37119 \size footnotesize
37120 IPUSH
37121 \end_layout
37122
37123 \end_inset
37124 </cell>
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37126 \begin_inset Text
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 IC_LEFT()
37132 \end_layout
37133
37134 \end_inset
37135 </cell>
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37137 \begin_inset Text
37138
37139 \begin_layout Standard
37140
37141 \size footnotesize
37142 Push the operand into stack
37143 \end_layout
37144
37145 \end_inset
37146 </cell>
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37148 \begin_inset Text
37149
37150 \begin_layout Standard
37151
37152 \size footnotesize
37153 NONE
37154 \end_layout
37155
37156 \end_inset
37157 </cell>
37158 </row>
37159 <row topline="true">
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_inset Text
37162
37163 \begin_layout Standard
37164
37165 \size footnotesize
37166 IPOP
37167 \end_layout
37168
37169 \end_inset
37170 </cell>
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37172 \begin_inset Text
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 IC_LEFT()
37178 \end_layout
37179
37180 \end_inset
37181 </cell>
37182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37183 \begin_inset Text
37184
37185 \begin_layout Standard
37186
37187 \size footnotesize
37188 Pop the operand from the stack 
37189 \end_layout
37190
37191 \end_inset
37192 </cell>
37193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37194 \begin_inset Text
37195
37196 \begin_layout Standard
37197
37198 \size footnotesize
37199 NONE
37200 \end_layout
37201
37202 \end_inset
37203 </cell>
37204 </row>
37205 <row topline="true">
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_inset Text
37208
37209 \begin_layout Standard
37210
37211 \size footnotesize
37212 CALL
37213 \end_layout
37214
37215 \end_inset
37216 </cell>
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37218 \begin_inset Text
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 IC_LEFT() IC_RESULT()
37224 \end_layout
37225
37226 \end_inset
37227 </cell>
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37229 \begin_inset Text
37230
37231 \begin_layout Standard
37232
37233 \size footnotesize
37234 Call the function represented by IC_LEFT 
37235 \end_layout
37236
37237 \end_inset
37238 </cell>
37239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37240 \begin_inset Text
37241
37242 \begin_layout Standard
37243
37244 \size footnotesize
37245 IC_RESULT = IC_LEFT();
37246 \end_layout
37247
37248 \end_inset
37249 </cell>
37250 </row>
37251 <row topline="true">
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37253 \begin_inset Text
37254
37255 \begin_layout Standard
37256
37257 \size footnotesize
37258 PCALL
37259 \end_layout
37260
37261 \end_inset
37262 </cell>
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37264 \begin_inset Text
37265
37266 \begin_layout Standard
37267
37268 \size footnotesize
37269 IC_LEFT() IC_RESULT()
37270 \end_layout
37271
37272 \end_inset
37273 </cell>
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37275 \begin_inset Text
37276
37277 \begin_layout Standard
37278
37279 \size footnotesize
37280 Call via function pointer
37281 \end_layout
37282
37283 \end_inset
37284 </cell>
37285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37286 \begin_inset Text
37287
37288 \begin_layout Standard
37289
37290 \size footnotesize
37291 IC_RESULT = (*IC_LEFT)();
37292 \end_layout
37293
37294 \end_inset
37295 </cell>
37296 </row>
37297 <row topline="true">
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37299 \begin_inset Text
37300
37301 \begin_layout Standard
37302
37303 \size footnotesize
37304 RETURN
37305 \end_layout
37306
37307 \end_inset
37308 </cell>
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37310 \begin_inset Text
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 IC_LEFT()
37316 \end_layout
37317
37318 \end_inset
37319 </cell>
37320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37321 \begin_inset Text
37322
37323 \begin_layout Standard
37324
37325 \size footnotesize
37326 Return the value in operand IC_LEFT 
37327 \end_layout
37328
37329 \end_inset
37330 </cell>
37331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37332 \begin_inset Text
37333
37334 \begin_layout Standard
37335
37336 \size footnotesize
37337 return IC_LEFT;
37338 \end_layout
37339
37340 \end_inset
37341 </cell>
37342 </row>
37343 <row topline="true">
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37345 \begin_inset Text
37346
37347 \begin_layout Standard
37348
37349 \size footnotesize
37350 LABEL
37351 \end_layout
37352
37353 \end_inset
37354 </cell>
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37356 \begin_inset Text
37357
37358 \begin_layout Standard
37359
37360 \size footnotesize
37361 IC_LABEL() 
37362 \end_layout
37363
37364 \end_inset
37365 </cell>
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37367 \begin_inset Text
37368
37369 \begin_layout Standard
37370
37371 \size footnotesize
37372 Label
37373 \end_layout
37374
37375 \end_inset
37376 </cell>
37377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37378 \begin_inset Text
37379
37380 \begin_layout Standard
37381
37382 \size footnotesize
37383 IC_LABEL:
37384 \end_layout
37385
37386 \end_inset
37387 </cell>
37388 </row>
37389 <row topline="true">
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37391 \begin_inset Text
37392
37393 \begin_layout Standard
37394
37395 \size footnotesize
37396 GOTO
37397 \end_layout
37398
37399 \end_inset
37400 </cell>
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37402 \begin_inset Text
37403
37404 \begin_layout Standard
37405
37406 \size footnotesize
37407 IC_LABEL() 
37408 \end_layout
37409
37410 \end_inset
37411 </cell>
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37413 \begin_inset Text
37414
37415 \begin_layout Standard
37416
37417 \size footnotesize
37418 Goto label
37419 \end_layout
37420
37421 \end_inset
37422 </cell>
37423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37424 \begin_inset Text
37425
37426 \begin_layout Standard
37427
37428 \size footnotesize
37429 goto IC_LABEL();
37430 \end_layout
37431
37432 \end_inset
37433 </cell>
37434 </row>
37435 <row topline="true">
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37437 \begin_inset Text
37438
37439 \begin_layout Standard
37440
37441 \size footnotesize
37442 '+'
37443 \end_layout
37444
37445 \end_inset
37446 </cell>
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37448 \begin_inset Text
37449
37450 \begin_layout Standard
37451
37452 \size footnotesize
37453 IC_LEFT() IC_RIGHT() IC_RESULT()
37454 \end_layout
37455
37456 \end_inset
37457 </cell>
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37459 \begin_inset Text
37460
37461 \begin_layout Standard
37462
37463 \size footnotesize
37464 Addition
37465 \end_layout
37466
37467 \end_inset
37468 </cell>
37469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37470 \begin_inset Text
37471
37472 \begin_layout Standard
37473
37474 \size footnotesize
37475 IC_RESULT = IC_LEFT + IC_RIGHT
37476 \end_layout
37477
37478 \end_inset
37479 </cell>
37480 </row>
37481 <row topline="true">
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37483 \begin_inset Text
37484
37485 \begin_layout Standard
37486
37487 \size footnotesize
37488 '-'
37489 \end_layout
37490
37491 \end_inset
37492 </cell>
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37494 \begin_inset Text
37495
37496 \begin_layout Standard
37497
37498 \size footnotesize
37499 IC_LEFT() IC_RIGHT() IC_RESULT()
37500 \end_layout
37501
37502 \end_inset
37503 </cell>
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37505 \begin_inset Text
37506
37507 \begin_layout Standard
37508
37509 \size footnotesize
37510 Subtraction
37511 \end_layout
37512
37513 \end_inset
37514 </cell>
37515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37516 \begin_inset Text
37517
37518 \begin_layout Standard
37519
37520 \size footnotesize
37521 IC_RESULT = IC_LEFT - IC_RIGHT 
37522 \end_layout
37523
37524 \end_inset
37525 </cell>
37526 </row>
37527 <row topline="true">
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37529 \begin_inset Text
37530
37531 \begin_layout Standard
37532
37533 \size footnotesize
37534 '*'
37535 \end_layout
37536
37537 \end_inset
37538 </cell>
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37540 \begin_inset Text
37541
37542 \begin_layout Standard
37543
37544 \size footnotesize
37545 IC_LEFT() IC_RIGHT() IC_RESULT()
37546 \end_layout
37547
37548 \end_inset
37549 </cell>
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37551 \begin_inset Text
37552
37553 \begin_layout Standard
37554
37555 \size footnotesize
37556 Multiplication 
37557 \end_layout
37558
37559 \end_inset
37560 </cell>
37561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37562 \begin_inset Text
37563
37564 \begin_layout Standard
37565
37566 \size footnotesize
37567 IC_RESULT = IC_LEFT * IC_RIGHT;
37568 \end_layout
37569
37570 \end_inset
37571 </cell>
37572 </row>
37573 <row topline="true">
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37575 \begin_inset Text
37576
37577 \begin_layout Standard
37578
37579 \size footnotesize
37580 '/'
37581 \end_layout
37582
37583 \end_inset
37584 </cell>
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37586 \begin_inset Text
37587
37588 \begin_layout Standard
37589
37590 \size footnotesize
37591 IC_LEFT() IC_RIGHT() IC_RESULT()
37592 \end_layout
37593
37594 \end_inset
37595 </cell>
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37597 \begin_inset Text
37598
37599 \begin_layout Standard
37600
37601 \size footnotesize
37602 Division
37603 \end_layout
37604
37605 \end_inset
37606 </cell>
37607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37608 \begin_inset Text
37609
37610 \begin_layout Standard
37611
37612 \size footnotesize
37613 IC_RESULT = IC_LEFT / IC_RIGHT;
37614 \end_layout
37615
37616 \end_inset
37617 </cell>
37618 </row>
37619 <row topline="true">
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37621 \begin_inset Text
37622
37623 \begin_layout Standard
37624
37625 \size footnotesize
37626 '%'
37627 \end_layout
37628
37629 \end_inset
37630 </cell>
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37632 \begin_inset Text
37633
37634 \begin_layout Standard
37635
37636 \size footnotesize
37637 IC_LEFT() IC_RIGHT() IC_RESULT()
37638 \end_layout
37639
37640 \end_inset
37641 </cell>
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37643 \begin_inset Text
37644
37645 \begin_layout Standard
37646
37647 \size footnotesize
37648 Modulus
37649 \end_layout
37650
37651 \end_inset
37652 </cell>
37653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37654 \begin_inset Text
37655
37656 \begin_layout Standard
37657
37658 \size footnotesize
37659 IC_RESULT = IC_LEFT % IC_RIGHT;
37660 \end_layout
37661
37662 \end_inset
37663 </cell>
37664 </row>
37665 <row topline="true">
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37667 \begin_inset Text
37668
37669 \begin_layout Standard
37670
37671 \size footnotesize
37672 '<'
37673 \end_layout
37674
37675 \end_inset
37676 </cell>
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37678 \begin_inset Text
37679
37680 \begin_layout Standard
37681
37682 \size footnotesize
37683 IC_LEFT() IC_RIGHT() IC_RESULT()
37684 \end_layout
37685
37686 \end_inset
37687 </cell>
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37689 \begin_inset Text
37690
37691 \begin_layout Standard
37692
37693 \size footnotesize
37694 Less than
37695 \end_layout
37696
37697 \end_inset
37698 </cell>
37699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37700 \begin_inset Text
37701
37702 \begin_layout Standard
37703
37704 \size footnotesize
37705 IC_RESULT = IC_LEFT < IC_RIGHT;
37706 \end_layout
37707
37708 \end_inset
37709 </cell>
37710 </row>
37711 <row topline="true">
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37713 \begin_inset Text
37714
37715 \begin_layout Standard
37716
37717 \size footnotesize
37718 '>'
37719 \end_layout
37720
37721 \end_inset
37722 </cell>
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37724 \begin_inset Text
37725
37726 \begin_layout Standard
37727
37728 \size footnotesize
37729 IC_LEFT() IC_RIGHT() IC_RESULT()
37730 \end_layout
37731
37732 \end_inset
37733 </cell>
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37735 \begin_inset Text
37736
37737 \begin_layout Standard
37738
37739 \size footnotesize
37740 Greater than 
37741 \end_layout
37742
37743 \end_inset
37744 </cell>
37745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37746 \begin_inset Text
37747
37748 \begin_layout Standard
37749
37750 \size footnotesize
37751 IC_RESULT = IC_LEFT > IC_RIGHT;
37752 \end_layout
37753
37754 \end_inset
37755 </cell>
37756 </row>
37757 <row topline="true">
37758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37759 \begin_inset Text
37760
37761 \begin_layout Standard
37762
37763 \size footnotesize
37764 EQ_OP
37765 \end_layout
37766
37767 \end_inset
37768 </cell>
37769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37770 \begin_inset Text
37771
37772 \begin_layout Standard
37773
37774 \size footnotesize
37775 IC_LEFT() IC_RIGHT() IC_RESULT()
37776 \end_layout
37777
37778 \end_inset
37779 </cell>
37780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37781 \begin_inset Text
37782
37783 \begin_layout Standard
37784
37785 \size footnotesize
37786 Equal to 
37787 \end_layout
37788
37789 \end_inset
37790 </cell>
37791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37792 \begin_inset Text
37793
37794 \begin_layout Standard
37795
37796 \size footnotesize
37797 IC_RESULT = IC_LEFT == IC_RIGHT;
37798 \end_layout
37799
37800 \end_inset
37801 </cell>
37802 </row>
37803 <row topline="true">
37804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37805 \begin_inset Text
37806
37807 \begin_layout Standard
37808
37809 \size footnotesize
37810 AND_OP
37811 \end_layout
37812
37813 \end_inset
37814 </cell>
37815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37816 \begin_inset Text
37817
37818 \begin_layout Standard
37819
37820 \size footnotesize
37821 IC_LEFT() IC_RIGHT() IC_RESULT() 
37822 \end_layout
37823
37824 \end_inset
37825 </cell>
37826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37827 \begin_inset Text
37828
37829 \begin_layout Standard
37830
37831 \size footnotesize
37832 Logical and operation
37833 \end_layout
37834
37835 \end_inset
37836 </cell>
37837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37838 \begin_inset Text
37839
37840 \begin_layout Standard
37841
37842 \size footnotesize
37843 IC_RESULT = IC_LEFT && IC_RIGHT; 
37844 \end_layout
37845
37846 \end_inset
37847 </cell>
37848 </row>
37849 <row topline="true">
37850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37851 \begin_inset Text
37852
37853 \begin_layout Standard
37854
37855 \size footnotesize
37856 OR_OP
37857 \end_layout
37858
37859 \end_inset
37860 </cell>
37861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37862 \begin_inset Text
37863
37864 \begin_layout Standard
37865
37866 \size footnotesize
37867 IC_LEFT() IC_RIGHT() IC_RESULT() 
37868 \end_layout
37869
37870 \end_inset
37871 </cell>
37872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37873 \begin_inset Text
37874
37875 \begin_layout Standard
37876
37877 \size footnotesize
37878 Logical or operation 
37879 \end_layout
37880
37881 \end_inset
37882 </cell>
37883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37884 \begin_inset Text
37885
37886 \begin_layout Standard
37887
37888 \size footnotesize
37889 IC_RESULT = IC_LEFT || IC_RIGHT; 
37890 \end_layout
37891
37892 \end_inset
37893 </cell>
37894 </row>
37895 <row topline="true">
37896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37897 \begin_inset Text
37898
37899 \begin_layout Standard
37900
37901 \size footnotesize
37902 '^'
37903 \end_layout
37904
37905 \end_inset
37906 </cell>
37907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37908 \begin_inset Text
37909
37910 \begin_layout Standard
37911
37912 \size footnotesize
37913 IC_LEFT() IC_RIGHT() IC_RESULT() 
37914 \end_layout
37915
37916 \end_inset
37917 </cell>
37918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37919 \begin_inset Text
37920
37921 \begin_layout Standard
37922
37923 \size footnotesize
37924 Exclusive OR
37925 \end_layout
37926
37927 \end_inset
37928 </cell>
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37930 \begin_inset Text
37931
37932 \begin_layout Standard
37933
37934 \size footnotesize
37935 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37936 \end_layout
37937
37938 \end_inset
37939 </cell>
37940 </row>
37941 <row topline="true">
37942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37943 \begin_inset Text
37944
37945 \begin_layout Standard
37946
37947 \size footnotesize
37948 '|'
37949 \end_layout
37950
37951 \end_inset
37952 </cell>
37953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37954 \begin_inset Text
37955
37956 \begin_layout Standard
37957
37958 \size footnotesize
37959 IC_LEFT() IC_RIGHT() IC_RESULT() 
37960 \end_layout
37961
37962 \end_inset
37963 </cell>
37964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37965 \begin_inset Text
37966
37967 \begin_layout Standard
37968
37969 \size footnotesize
37970 Bitwise OR 
37971 \end_layout
37972
37973 \end_inset
37974 </cell>
37975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37976 \begin_inset Text
37977
37978 \begin_layout Standard
37979
37980 \size footnotesize
37981 IC_RESULT = IC_LEFT | IC_RIGHT;
37982 \end_layout
37983
37984 \end_inset
37985 </cell>
37986 </row>
37987 <row topline="true">
37988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37989 \begin_inset Text
37990
37991 \begin_layout Standard
37992
37993 \size footnotesize
37994 BITWISEAND
37995 \end_layout
37996
37997 \end_inset
37998 </cell>
37999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38000 \begin_inset Text
38001
38002 \begin_layout Standard
38003
38004 \size footnotesize
38005 IC_LEFT() IC_RIGHT() IC_RESULT()
38006 \end_layout
38007
38008 \end_inset
38009 </cell>
38010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38011 \begin_inset Text
38012
38013 \begin_layout Standard
38014
38015 \size footnotesize
38016 Bitwise AND 
38017 \end_layout
38018
38019 \end_inset
38020 </cell>
38021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38022 \begin_inset Text
38023
38024 \begin_layout Standard
38025
38026 \size footnotesize
38027 IC_RESULT = IC_LEFT & IC_RIGHT;
38028 \end_layout
38029
38030 \end_inset
38031 </cell>
38032 </row>
38033 <row topline="true">
38034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38035 \begin_inset Text
38036
38037 \begin_layout Standard
38038
38039 \size footnotesize
38040 LEFT_OP
38041 \end_layout
38042
38043 \end_inset
38044 </cell>
38045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38046 \begin_inset Text
38047
38048 \begin_layout Standard
38049
38050 \size footnotesize
38051 IC_LEFT() IC_RIGHT() IC_RESULT()
38052 \end_layout
38053
38054 \end_inset
38055 </cell>
38056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38057 \begin_inset Text
38058
38059 \begin_layout Standard
38060
38061 \size footnotesize
38062 Left shift 
38063 \end_layout
38064
38065 \end_inset
38066 </cell>
38067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38068 \begin_inset Text
38069
38070 \begin_layout Standard
38071
38072 \size footnotesize
38073 IC_RESULT = IC_LEFT << IC_RIGHT 
38074 \end_layout
38075
38076 \end_inset
38077 </cell>
38078 </row>
38079 <row topline="true">
38080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38081 \begin_inset Text
38082
38083 \begin_layout Standard
38084
38085 \size footnotesize
38086 RIGHT_OP
38087 \end_layout
38088
38089 \end_inset
38090 </cell>
38091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38092 \begin_inset Text
38093
38094 \begin_layout Standard
38095
38096 \size footnotesize
38097 IC_LEFT() IC_RIGHT() IC_RESULT()
38098 \end_layout
38099
38100 \end_inset
38101 </cell>
38102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38103 \begin_inset Text
38104
38105 \begin_layout Standard
38106
38107 \size footnotesize
38108 Right shift
38109 \end_layout
38110
38111 \end_inset
38112 </cell>
38113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38114 \begin_inset Text
38115
38116 \begin_layout Standard
38117
38118 \size footnotesize
38119 IC_RESULT = IC_LEFT >> IC_RIGHT 
38120 \end_layout
38121
38122 \end_inset
38123 </cell>
38124 </row>
38125 <row topline="true">
38126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38127 \begin_inset Text
38128
38129 \begin_layout Standard
38130
38131 \size footnotesize
38132 GET_VALUE_
38133 \newline
38134 AT_ ADDRESS
38135 \end_layout
38136
38137 \end_inset
38138 </cell>
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38140 \begin_inset Text
38141
38142 \begin_layout Standard
38143
38144 \size footnotesize
38145 IC_LEFT() IC_RESULT()
38146 \end_layout
38147
38148 \end_inset
38149 </cell>
38150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38151 \begin_inset Text
38152
38153 \begin_layout Standard
38154
38155 \size footnotesize
38156 Indirect fetch 
38157 \end_layout
38158
38159 \end_inset
38160 </cell>
38161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38162 \begin_inset Text
38163
38164 \begin_layout Standard
38165
38166 \size footnotesize
38167 IC_RESULT = (*IC_LEFT);
38168 \end_layout
38169
38170 \end_inset
38171 </cell>
38172 </row>
38173 <row topline="true">
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38175 \begin_inset Text
38176
38177 \begin_layout Standard
38178
38179 \size footnotesize
38180 POINTER_SET
38181 \end_layout
38182
38183 \end_inset
38184 </cell>
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38186 \begin_inset Text
38187
38188 \begin_layout Standard
38189
38190 \size footnotesize
38191 IC_RIGHT() IC_RESULT() 
38192 \end_layout
38193
38194 \end_inset
38195 </cell>
38196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38197 \begin_inset Text
38198
38199 \begin_layout Standard
38200
38201 \size footnotesize
38202 Indirect set
38203 \end_layout
38204
38205 \end_inset
38206 </cell>
38207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38208 \begin_inset Text
38209
38210 \begin_layout Standard
38211
38212 \size footnotesize
38213 (*IC_RESULT) = IC_RIGHT;
38214 \end_layout
38215
38216 \end_inset
38217 </cell>
38218 </row>
38219 <row topline="true">
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38221 \begin_inset Text
38222
38223 \begin_layout Standard
38224
38225 \size footnotesize
38226 '='
38227 \end_layout
38228
38229 \end_inset
38230 </cell>
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38232 \begin_inset Text
38233
38234 \begin_layout Standard
38235
38236 \size footnotesize
38237 IC_RIGHT() IC_RESULT()
38238 \end_layout
38239
38240 \end_inset
38241 </cell>
38242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38243 \begin_inset Text
38244
38245 \begin_layout Standard
38246
38247 \size footnotesize
38248 Assignment
38249 \end_layout
38250
38251 \end_inset
38252 </cell>
38253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38254 \begin_inset Text
38255
38256 \begin_layout Standard
38257
38258 \size footnotesize
38259 IC_RESULT = IC_RIGHT;
38260 \end_layout
38261
38262 \end_inset
38263 </cell>
38264 </row>
38265 <row topline="true">
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38267 \begin_inset Text
38268
38269 \begin_layout Standard
38270
38271 \size footnotesize
38272 IFX
38273 \end_layout
38274
38275 \end_inset
38276 </cell>
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38278 \begin_inset Text
38279
38280 \begin_layout Standard
38281
38282 \size footnotesize
38283 IC_COND IC_TRUE IC_LABEL
38284 \end_layout
38285
38286 \end_inset
38287 </cell>
38288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38289 \begin_inset Text
38290
38291 \begin_layout Standard
38292
38293 \size footnotesize
38294 Conditional jump.
38295  If true label is present then jump to true label if condition is true else
38296  jump to false label if condition is false 
38297 \end_layout
38298
38299 \end_inset
38300 </cell>
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38302 \begin_inset Text
38303
38304 \begin_layout Standard
38305
38306 \size footnotesize
38307 if (IC_COND) goto IC_TRUE; 
38308 \newline
38309 \InsetSpace ~
38310 \InsetSpace ~
38311 Or 
38312 \newline
38313 If (!IC_COND) goto IC_FALSE;
38314 \end_layout
38315
38316 \end_inset
38317 </cell>
38318 </row>
38319 <row topline="true">
38320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38321 \begin_inset Text
38322
38323 \begin_layout Standard
38324
38325 \size footnotesize
38326 ADDRESS_OF
38327 \end_layout
38328
38329 \end_inset
38330 </cell>
38331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38332 \begin_inset Text
38333
38334 \begin_layout Standard
38335
38336 \size footnotesize
38337 IC_LEFT() IC_RESULT()
38338 \end_layout
38339
38340 \end_inset
38341 </cell>
38342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38343 \begin_inset Text
38344
38345 \begin_layout Standard
38346
38347 \size footnotesize
38348 Address of 
38349 \end_layout
38350
38351 \end_inset
38352 </cell>
38353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38354 \begin_inset Text
38355
38356 \begin_layout Standard
38357
38358 \size footnotesize
38359 IC_RESULT = &IC_LEFT();
38360 \end_layout
38361
38362 \end_inset
38363 </cell>
38364 </row>
38365 <row topline="true">
38366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38367 \begin_inset Text
38368
38369 \begin_layout Standard
38370
38371 \size footnotesize
38372 JUMPTABLE
38373 \end_layout
38374
38375 \end_inset
38376 </cell>
38377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38378 \begin_inset Text
38379
38380 \begin_layout Standard
38381
38382 \size footnotesize
38383 IC_JTCOND IC_JTLABELS
38384 \end_layout
38385
38386 \end_inset
38387 </cell>
38388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38389 \begin_inset Text
38390
38391 \begin_layout Standard
38392
38393 \size footnotesize
38394 Jump to list of labels depending on the value of JTCOND
38395 \end_layout
38396
38397 \end_inset
38398 </cell>
38399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38400 \begin_inset Text
38401
38402 \begin_layout Standard
38403
38404 \size footnotesize
38405 Switch statement
38406 \end_layout
38407
38408 \end_inset
38409 </cell>
38410 </row>
38411 <row topline="true">
38412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38413 \begin_inset Text
38414
38415 \begin_layout Standard
38416
38417 \size footnotesize
38418 CAST
38419 \end_layout
38420
38421 \end_inset
38422 </cell>
38423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38424 \begin_inset Text
38425
38426 \begin_layout Standard
38427
38428 \size footnotesize
38429 IC_RIGHT() IC_LEFT() IC_RESULT()
38430 \end_layout
38431
38432 \end_inset
38433 </cell>
38434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38435 \begin_inset Text
38436
38437 \begin_layout Standard
38438
38439 \size footnotesize
38440 Cast types 
38441 \end_layout
38442
38443 \end_inset
38444 </cell>
38445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38446 \begin_inset Text
38447
38448 \begin_layout Standard
38449
38450 \size footnotesize
38451 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38452 \end_layout
38453
38454 \end_inset
38455 </cell>
38456 </row>
38457 <row topline="true">
38458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38459 \begin_inset Text
38460
38461 \begin_layout Standard
38462
38463 \size footnotesize
38464 SEND
38465 \end_layout
38466
38467 \end_inset
38468 </cell>
38469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38470 \begin_inset Text
38471
38472 \begin_layout Standard
38473
38474 \size footnotesize
38475 IC_LEFT()
38476 \end_layout
38477
38478 \end_inset
38479 </cell>
38480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38481 \begin_inset Text
38482
38483 \begin_layout Standard
38484
38485 \size footnotesize
38486 This is used for passing parameters in registers; 
38487 \newline
38488 move IC_LEFT to the next
38489  available parameter register.
38490 \end_layout
38491
38492 \end_inset
38493 </cell>
38494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38495 \begin_inset Text
38496
38497 \begin_layout Standard
38498
38499 \size footnotesize
38500 None
38501 \end_layout
38502
38503 \end_inset
38504 </cell>
38505 </row>
38506 <row topline="true">
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38508 \begin_inset Text
38509
38510 \begin_layout Standard
38511
38512 \size footnotesize
38513 RECV
38514 \end_layout
38515
38516 \end_inset
38517 </cell>
38518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38519 \begin_inset Text
38520
38521 \begin_layout Standard
38522
38523 \size footnotesize
38524 IC_RESULT()
38525 \end_layout
38526
38527 \end_inset
38528 </cell>
38529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38530 \begin_inset Text
38531
38532 \begin_layout Standard
38533
38534 \size footnotesize
38535 This is used for receiving parameters passed in registers;
38536 \newline
38537 Move the values
38538  in the next parameter register to IC_RESULT 
38539 \end_layout
38540
38541 \end_inset
38542 </cell>
38543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38544 \begin_inset Text
38545
38546 \begin_layout Standard
38547
38548 \size footnotesize
38549 None
38550 \end_layout
38551
38552 \end_inset
38553 </cell>
38554 </row>
38555 <row topline="true" bottomline="true">
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38557 \begin_inset Text
38558
38559 \begin_layout Standard
38560
38561 \shape slanted
38562 \size footnotesize
38563 (some more have been added)
38564 \end_layout
38565
38566 \end_inset
38567 </cell>
38568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38569 \begin_inset Text
38570
38571 \begin_layout Standard
38572
38573 \end_layout
38574
38575 \end_inset
38576 </cell>
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38578 \begin_inset Text
38579
38580 \begin_layout Standard
38581
38582 \end_layout
38583
38584 \end_inset
38585 </cell>
38586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38587 \begin_inset Text
38588
38589 \begin_layout Standard
38590
38591 \shape slanted
38592 \size footnotesize
38593 see f.e.
38594  
38595 \family typewriter
38596 gen51Code()
38597 \family default
38598  in 
38599 \family typewriter
38600 src/mcs51/gen.c
38601 \end_layout
38602
38603 \end_inset
38604 </cell>
38605 </row>
38606 </lyxtabular>
38607
38608 \end_inset
38609
38610
38611 \end_layout
38612
38613 \begin_layout Standard
38614 \begin_inset Note Note
38615 status collapsed
38616
38617 \begin_layout Standard
38618 In the original article Figure II was announced to be downloadable on 
38619 \shape italic
38620 Circuit Cellar
38621 \shape default
38622 's web site.
38623  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38624 \end_layout
38625
38626 \end_inset
38627
38628
38629 \end_layout
38630
38631 \begin_layout Paragraph*
38632 ICode Example
38633 \begin_inset LatexCommand \index{iCode}
38634
38635 \end_inset
38636
38637
38638 \end_layout
38639
38640 \begin_layout Standard
38641 This section shows some details of iCode.
38642  The example C code does not do anything useful; it is used as an example
38643  to illustrate the intermediate code generated by the compiler.
38644 \end_layout
38645
38646 \begin_layout Verse
38647
38648 \family typewriter
38649 1.\InsetSpace ~
38650 xdata int * p;
38651 \newline
38652 2.\InsetSpace ~
38653 int gint;
38654 \newline
38655 3.\InsetSpace ~
38656 /* This function does nothing useful.
38657  It is used
38658 \newline
38659 4.\InsetSpace ~
38660 \InsetSpace ~
38661 \InsetSpace ~
38662 \InsetSpace ~
38663 for the purpose of explaining iCode */
38664 \newline
38665 5.\InsetSpace ~
38666 short function (data
38667  int *x)
38668 \newline
38669 6.\InsetSpace ~
38670 {
38671 \newline
38672 7.\InsetSpace ~
38673 \InsetSpace ~
38674 \InsetSpace ~
38675 short i=10; \InsetSpace ~
38676 \InsetSpace ~
38677 /* dead initialization eliminated */
38678 \newline
38679 8.\InsetSpace ~
38680 \InsetSpace ~
38681 \InsetSpace ~
38682 short sum=10;
38683  /* dead initialization eliminated */
38684 \newline
38685 9.\InsetSpace ~
38686 \InsetSpace ~
38687 \InsetSpace ~
38688 short mul;
38689 \newline
38690 10.\InsetSpace ~
38691 \InsetSpace ~
38692 int j ;
38693 \newline
38694 11.\InsetSpace ~
38695 \InsetSpace ~
38696 while (*x) *x++
38697  = *p++; 
38698 \newline
38699 12.\InsetSpace ~
38700 \InsetSpace ~
38701 \InsetSpace ~
38702 \InsetSpace ~
38703 sum = 0 ; 
38704 \newline
38705 13.\InsetSpace ~
38706 \InsetSpace ~
38707 mul = 0;
38708 \newline
38709 14.\InsetSpace ~
38710 \InsetSpace ~
38711 /* compiler detects i,j to be induction
38712  variables */
38713 \newline
38714 15.\InsetSpace ~
38715 \InsetSpace ~
38716 for (i = 0, j = 10 ; i < 10 ; i++, j
38717 \family default
38718 -
38719 \begin_inset ERT
38720 status collapsed
38721
38722 \begin_layout Standard
38723
38724
38725 \backslash
38726 /
38727 \end_layout
38728
38729 \end_inset
38730
38731 -
38732 \family typewriter
38733 ) {
38734 \newline
38735 16.\InsetSpace ~
38736 \InsetSpace ~
38737 \InsetSpace ~
38738 \InsetSpace ~
38739 sum += i;
38740 \newline
38741 17.\InsetSpace ~
38742 \InsetSpace ~
38743 \InsetSpace ~
38744 \InsetSpace ~
38745 mul += i * 3; \InsetSpace ~
38746 \InsetSpace ~
38747 /* this multiplication remains */
38748 \newline
38749 18.\InsetSpace ~
38750 \InsetSpace ~
38751 \InsetSpace ~
38752 \InsetSpace ~
38753 gint +=
38754  j * 3;\InsetSpace ~
38755 \InsetSpace ~
38756 /* this multiplication changed to addition */
38757 \newline
38758 19.\InsetSpace ~
38759 \InsetSpace ~
38760 }
38761 \newline
38762 20.\InsetSpace ~
38763 \InsetSpace ~
38764 return sum+mul;
38765 \newline
38766 21.\InsetSpace ~
38767 }
38768 \end_layout
38769
38770 \begin_layout Standard
38771 In addition to the operands each iCode contains information about the filename
38772  and line it corresponds to in the source file.
38773  The first field in the listing should be interpreted as follows:
38774 \newline
38775
38776 \shape italic
38777 \size footnotesize
38778 Filename(linenumber: iCode Execution sequence number : ICode hash table
38779  key : loop depth of the iCode).
38780 \shape default
38781 \size default
38782
38783 \newline
38784 Then follows the human readable form of the ICode operation.
38785  Each operand of this triplet form can be of three basic types a) compiler
38786  generated temporary b) user defined variable c) a constant value.
38787  Note that local variables and parameters are replaced by compiler generated
38788  temporaries.
38789  Live ranges
38790 \begin_inset LatexCommand \index{Live range analysis}
38791
38792 \end_inset
38793
38794  are computed only for temporaries (i.e.
38795  live ranges are not computed for global variables).
38796  Registers
38797 \begin_inset LatexCommand \index{Register allocation}
38798
38799 \end_inset
38800
38801  are allocated for temporaries only.
38802  Operands are formatted in the following manner:
38803 \newline
38804
38805 \shape italic
38806 \size footnotesize
38807 Operand Name [lr live-from : live-to ] { type information } [ registers
38808  allocated ].
38809 \shape default
38810 \size default
38811
38812 \newline
38813 As mentioned earlier the live ranges are computed in terms of the execution
38814  sequence number of the iCodes, for example 
38815 \newline
38816 the iTemp0 is live from (i.e.
38817  first defined in iCode with execution sequence number 3, and is last used
38818  in the iCode with sequence number 5).
38819  For induction variables such as iTemp21 the live range computation extends
38820  the lifetime from the start to the end of the loop.
38821 \newline
38822 The register allocator
38823  used the live range information to allocate registers, the same registers
38824  may be used for different temporaries if their live ranges do not overlap,
38825  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38826  ranges do not overlap.
38827  In addition the allocator also takes into consideration the type and usage
38828  of a temporary, for example itemp6 is a pointer to near space and is used
38829  as to fetch data from (i.e.
38830  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38831  Some short lived temporaries are allocated to special registers which have
38832  meaning to the code generator e.g.
38833  iTemp13 is allocated to a pseudo register CC which tells the back end that
38834  the temporary is used only for a conditional jump the code generation makes
38835  use of this information to optimize a compare and jump ICode.
38836 \newline
38837 There are several
38838  loop optimizations
38839 \begin_inset LatexCommand \index{Loop optimization}
38840
38841 \end_inset
38842
38843  performed by the compiler.
38844  It can detect induction variables iTemp21(i) and iTemp23(j).
38845  Also note the compiler does selective strength reduction
38846 \begin_inset LatexCommand \index{Strength reduction}
38847
38848 \end_inset
38849
38850 , i.e.
38851  the multiplication of an induction variable in line 18 (gint = j * 3) is
38852  changed to addition, a new temporary iTemp17 is allocated and assigned
38853  a initial value, a constant 3 is then added for each iteration of the loop.
38854  The compiler does not change the multiplication
38855 \begin_inset LatexCommand \index{Multiplication}
38856
38857 \end_inset
38858
38859  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38860 \newline
38861
38862 Note the dead code elimination
38863 \begin_inset LatexCommand \index{Dead-code elimination}
38864
38865 \end_inset
38866
38867  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38868  respectively.
38869 \newline
38870
38871 \end_layout
38872
38873 \begin_layout Standard
38874
38875 \size footnotesize
38876 Sample.c (5:1:0:0) _entry($9) :
38877 \end_layout
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38883 \end_layout
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38889 \end_layout
38890
38891 \begin_layout Standard
38892
38893 \size footnotesize
38894 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38895 \end_layout
38896
38897 \begin_layout Standard
38898
38899 \size footnotesize
38900 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38901  * int}[r2]
38902 \end_layout
38903
38904 \begin_layout Standard
38905
38906 \size footnotesize
38907 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38908 \end_layout
38909
38910 \begin_layout Standard
38911
38912 \size footnotesize
38913 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38914  int}[r0]]
38915 \end_layout
38916
38917 \begin_layout Standard
38918
38919 \size footnotesize
38920 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38921 \end_layout
38922
38923 \begin_layout Standard
38924
38925 \size footnotesize
38926 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38927  * int}
38928 \end_layout
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38934  {short}
38935 \end_layout
38936
38937 \begin_layout Standard
38938
38939 \size footnotesize
38940 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38941  * int}[DPTR]]
38942 \end_layout
38943
38944 \begin_layout Standard
38945
38946 \size footnotesize
38947 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38948 }[r2 r3]
38949 \end_layout
38950
38951 \begin_layout Standard
38952
38953 \size footnotesize
38954 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38955  * int}[r0] + 0x2 {short}
38956 \end_layout
38957
38958 \begin_layout Standard
38959
38960 \size footnotesize
38961 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38962 \end_layout
38963
38964 \begin_layout Standard
38965
38966 \size footnotesize
38967 Sample.c(11:17:21:0)_whilebreak_0($3) :
38968 \end_layout
38969
38970 \begin_layout Standard
38971
38972 \size footnotesize
38973 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38974 \end_layout
38975
38976 \begin_layout Standard
38977
38978 \size footnotesize
38979 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38980 \end_layout
38981
38982 \begin_layout Standard
38983
38984 \size footnotesize
38985 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38986 \end_layout
38987
38988 \begin_layout Standard
38989
38990 \size footnotesize
38991 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38992 \end_layout
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38998 \end_layout
38999
39000 \begin_layout Standard
39001
39002 \size footnotesize
39003 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39004 \end_layout
39005
39006 \begin_layout Standard
39007
39008 \size footnotesize
39009 Sample.c(15:24:26:1)_forcond_0($4) :
39010 \end_layout
39011
39012 \begin_layout Standard
39013
39014 \size footnotesize
39015 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39016  < 0xa {short}
39017 \end_layout
39018
39019 \begin_layout Standard
39020
39021 \size footnotesize
39022 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39023 \end_layout
39024
39025 \begin_layout Standard
39026
39027 \size footnotesize
39028 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39029  + ITemp21 [lr21:38]{short}[r4]
39030 \end_layout
39031
39032 \begin_layout Standard
39033
39034 \size footnotesize
39035 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39036  * 0x3 {short}
39037 \end_layout
39038
39039 \begin_layout Standard
39040
39041 \size footnotesize
39042 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39043  + iTemp15 [lr29:30]{short}[r1]
39044 \end_layout
39045
39046 \begin_layout Standard
39047
39048 \size footnotesize
39049 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39050  r0]- 0x3 {short}
39051 \end_layout
39052
39053 \begin_layout Standard
39054
39055 \size footnotesize
39056 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39057 int}[r7 r0]
39058 \end_layout
39059
39060 \begin_layout Standard
39061
39062 \size footnotesize
39063 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39064  + 0x1 {short}
39065 \end_layout
39066
39067 \begin_layout Standard
39068
39069 \size footnotesize
39070 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39071  r6]- 0x1 {short}
39072 \end_layout
39073
39074 \begin_layout Standard
39075
39076 \size footnotesize
39077 Sample.c(19:38:47:1) goto _forcond_0($4)
39078 \end_layout
39079
39080 \begin_layout Standard
39081
39082 \size footnotesize
39083 Sample.c(19:39:48:0)_forbreak_0($7) :
39084 \end_layout
39085
39086 \begin_layout Standard
39087
39088 \size footnotesize
39089 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39090  + ITemp11 [lr19:40]{short}[r3]
39091 \end_layout
39092
39093 \begin_layout Standard
39094
39095 \size footnotesize
39096 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39097 \end_layout
39098
39099 \begin_layout Standard
39100
39101 \size footnotesize
39102 Sample.c(20:42:51:0)_return($8) :
39103 \end_layout
39104
39105 \begin_layout Standard
39106
39107 \size footnotesize
39108 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39109 \size default
39110
39111 \newline
39112
39113 \newline
39114 Finally the code generated for this function:
39115 \newline
39116
39117 \end_layout
39118
39119 \begin_layout Standard
39120
39121 \size footnotesize
39122 .area DSEG (DATA)
39123 \end_layout
39124
39125 \begin_layout Standard
39126
39127 \size footnotesize
39128 _p::
39129 \end_layout
39130
39131 \begin_layout Standard
39132
39133 \size footnotesize
39134 \InsetSpace ~
39135 \InsetSpace ~
39136 .ds 2
39137 \end_layout
39138
39139 \begin_layout Standard
39140
39141 \size footnotesize
39142 _gint::
39143 \end_layout
39144
39145 \begin_layout Standard
39146
39147 \size footnotesize
39148 \InsetSpace ~
39149 \InsetSpace ~
39150 .ds 2
39151 \end_layout
39152
39153 \begin_layout Standard
39154
39155 \size footnotesize
39156 ; sample.c 5
39157 \end_layout
39158
39159 \begin_layout Standard
39160
39161 \size footnotesize
39162 ; ----------------------------------------------
39163 \end_layout
39164
39165 \begin_layout Standard
39166
39167 \size footnotesize
39168 ; function function
39169 \end_layout
39170
39171 \begin_layout Standard
39172
39173 \size footnotesize
39174 ; ----------------------------------------------
39175 \end_layout
39176
39177 \begin_layout Standard
39178
39179 \size footnotesize
39180 _function:
39181 \end_layout
39182
39183 \begin_layout Standard
39184
39185 \size footnotesize
39186 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39187 \end_layout
39188
39189 \begin_layout Standard
39190
39191 \size footnotesize
39192 \InsetSpace ~
39193 \InsetSpace ~
39194 mov r2,dpl
39195 \end_layout
39196
39197 \begin_layout Standard
39198
39199 \size footnotesize
39200 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39201 \end_layout
39202
39203 \begin_layout Standard
39204
39205 \size footnotesize
39206 \InsetSpace ~
39207 \InsetSpace ~
39208 mov ar0,r2
39209 \end_layout
39210
39211 \begin_layout Standard
39212
39213 \size footnotesize
39214 ;_whilecontinue_0($1) :
39215 \end_layout
39216
39217 \begin_layout Standard
39218
39219 \size footnotesize
39220 00101$:
39221 \end_layout
39222
39223 \begin_layout Standard
39224
39225 \size footnotesize
39226 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39227 \end_layout
39228
39229 \begin_layout Standard
39230
39231 \size footnotesize
39232 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39233 \end_layout
39234
39235 \begin_layout Standard
39236
39237 \size footnotesize
39238 \InsetSpace ~
39239 \InsetSpace ~
39240 mov ar2,@r0
39241 \end_layout
39242
39243 \begin_layout Standard
39244
39245 \size footnotesize
39246 \InsetSpace ~
39247 \InsetSpace ~
39248 inc r0
39249 \end_layout
39250
39251 \begin_layout Standard
39252
39253 \size footnotesize
39254 \InsetSpace ~
39255 \InsetSpace ~
39256 mov ar3,@r0
39257 \end_layout
39258
39259 \begin_layout Standard
39260
39261 \size footnotesize
39262 \InsetSpace ~
39263 \InsetSpace ~
39264 dec r0
39265 \end_layout
39266
39267 \begin_layout Standard
39268
39269 \size footnotesize
39270 \InsetSpace ~
39271 \InsetSpace ~
39272 mov a,r2
39273 \end_layout
39274
39275 \begin_layout Standard
39276
39277 \size footnotesize
39278 \InsetSpace ~
39279 \InsetSpace ~
39280 orl a,r3
39281 \end_layout
39282
39283 \begin_layout Standard
39284
39285 \size footnotesize
39286 \InsetSpace ~
39287 \InsetSpace ~
39288 jz 00103$
39289 \end_layout
39290
39291 \begin_layout Standard
39292
39293 \size footnotesize
39294 00114$:
39295 \end_layout
39296
39297 \begin_layout Standard
39298
39299 \size footnotesize
39300 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39301 \end_layout
39302
39303 \begin_layout Standard
39304
39305 \size footnotesize
39306 \InsetSpace ~
39307 \InsetSpace ~
39308 mov dpl,_p
39309 \end_layout
39310
39311 \begin_layout Standard
39312
39313 \size footnotesize
39314 \InsetSpace ~
39315 \InsetSpace ~
39316 mov dph,(_p + 1)
39317 \end_layout
39318
39319 \begin_layout Standard
39320
39321 \size footnotesize
39322 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39323 \end_layout
39324
39325 \begin_layout Standard
39326
39327 \size footnotesize
39328 \InsetSpace ~
39329 \InsetSpace ~
39330 mov a,#0x02
39331 \end_layout
39332
39333 \begin_layout Standard
39334
39335 \size footnotesize
39336 \InsetSpace ~
39337 \InsetSpace ~
39338 add a,_p
39339 \end_layout
39340
39341 \begin_layout Standard
39342
39343 \size footnotesize
39344 \InsetSpace ~
39345 \InsetSpace ~
39346 mov _p,a
39347 \end_layout
39348
39349 \begin_layout Standard
39350
39351 \size footnotesize
39352 \InsetSpace ~
39353 \InsetSpace ~
39354 clr a
39355 \end_layout
39356
39357 \begin_layout Standard
39358
39359 \size footnotesize
39360 \InsetSpace ~
39361 \InsetSpace ~
39362 addc a,(_p + 1)
39363 \end_layout
39364
39365 \begin_layout Standard
39366
39367 \size footnotesize
39368 \InsetSpace ~
39369 \InsetSpace ~
39370 mov (_p + 1),a
39371 \end_layout
39372
39373 \begin_layout Standard
39374
39375 \size footnotesize
39376 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39377 \end_layout
39378
39379 \begin_layout Standard
39380
39381 \size footnotesize
39382 \InsetSpace ~
39383 \InsetSpace ~
39384 movx a,@dptr
39385 \end_layout
39386
39387 \begin_layout Standard
39388
39389 \size footnotesize
39390 \InsetSpace ~
39391 \InsetSpace ~
39392 mov r2,a
39393 \end_layout
39394
39395 \begin_layout Standard
39396
39397 \size footnotesize
39398 \InsetSpace ~
39399 \InsetSpace ~
39400 inc dptr
39401 \end_layout
39402
39403 \begin_layout Standard
39404
39405 \size footnotesize
39406 \InsetSpace ~
39407 \InsetSpace ~
39408 movx a,@dptr
39409 \end_layout
39410
39411 \begin_layout Standard
39412
39413 \size footnotesize
39414 \InsetSpace ~
39415 \InsetSpace ~
39416 mov r3,a
39417 \end_layout
39418
39419 \begin_layout Standard
39420
39421 \size footnotesize
39422 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39423 \end_layout
39424
39425 \begin_layout Standard
39426
39427 \size footnotesize
39428 \InsetSpace ~
39429 \InsetSpace ~
39430 mov @r0,ar2
39431 \end_layout
39432
39433 \begin_layout Standard
39434
39435 \size footnotesize
39436 \InsetSpace ~
39437 \InsetSpace ~
39438 inc r0
39439 \end_layout
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 \InsetSpace ~
39445 \InsetSpace ~
39446 mov @r0,ar3
39447 \end_layout
39448
39449 \begin_layout Standard
39450
39451 \size footnotesize
39452 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39453 \end_layout
39454
39455 \begin_layout Standard
39456
39457 \size footnotesize
39458 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39459 \end_layout
39460
39461 \begin_layout Standard
39462
39463 \size footnotesize
39464 ; 0x2 {short}
39465 \end_layout
39466
39467 \begin_layout Standard
39468
39469 \size footnotesize
39470 \InsetSpace ~
39471 \InsetSpace ~
39472 inc r0
39473 \end_layout
39474
39475 \begin_layout Standard
39476
39477 \size footnotesize
39478 ; goto _whilecontinue_0($1)
39479 \end_layout
39480
39481 \begin_layout Standard
39482
39483 \size footnotesize
39484 \InsetSpace ~
39485 \InsetSpace ~
39486 sjmp 00101$
39487 \end_layout
39488
39489 \begin_layout Standard
39490
39491 \size footnotesize
39492 ; _whilebreak_0($3) :
39493 \end_layout
39494
39495 \begin_layout Standard
39496
39497 \size footnotesize
39498 00103$:
39499 \end_layout
39500
39501 \begin_layout Standard
39502
39503 \size footnotesize
39504 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39505 \end_layout
39506
39507 \begin_layout Standard
39508
39509 \size footnotesize
39510 \InsetSpace ~
39511 \InsetSpace ~
39512 mov r2,#0x00
39513 \end_layout
39514
39515 \begin_layout Standard
39516
39517 \size footnotesize
39518 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39519 \end_layout
39520
39521 \begin_layout Standard
39522
39523 \size footnotesize
39524 \InsetSpace ~
39525 \InsetSpace ~
39526 mov r3,#0x00
39527 \end_layout
39528
39529 \begin_layout Standard
39530
39531 \size footnotesize
39532 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39533 \end_layout
39534
39535 \begin_layout Standard
39536
39537 \size footnotesize
39538 \InsetSpace ~
39539 \InsetSpace ~
39540 mov r4,#0x00
39541 \end_layout
39542
39543 \begin_layout Standard
39544
39545 \size footnotesize
39546 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39547 \end_layout
39548
39549 \begin_layout Standard
39550
39551 \size footnotesize
39552 \InsetSpace ~
39553 \InsetSpace ~
39554 mov r5,#0x0A
39555 \end_layout
39556
39557 \begin_layout Standard
39558
39559 \size footnotesize
39560 \InsetSpace ~
39561 \InsetSpace ~
39562 mov r6,#0x00
39563 \end_layout
39564
39565 \begin_layout Standard
39566
39567 \size footnotesize
39568 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39569 \end_layout
39570
39571 \begin_layout Standard
39572
39573 \size footnotesize
39574 \InsetSpace ~
39575 \InsetSpace ~
39576 mov r7,#0x1E
39577 \end_layout
39578
39579 \begin_layout Standard
39580
39581 \size footnotesize
39582 \InsetSpace ~
39583 \InsetSpace ~
39584 mov r0,#0x00
39585 \end_layout
39586
39587 \begin_layout Standard
39588
39589 \size footnotesize
39590 ; _forcond_0($4) :
39591 \end_layout
39592
39593 \begin_layout Standard
39594
39595 \size footnotesize
39596 00104$:
39597 \end_layout
39598
39599 \begin_layout Standard
39600
39601 \size footnotesize
39602 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39603 \end_layout
39604
39605 \begin_layout Standard
39606
39607 \size footnotesize
39608 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39609 \end_layout
39610
39611 \begin_layout Standard
39612
39613 \size footnotesize
39614 \InsetSpace ~
39615 \InsetSpace ~
39616 clr c
39617 \end_layout
39618
39619 \begin_layout Standard
39620
39621 \size footnotesize
39622 \InsetSpace ~
39623 \InsetSpace ~
39624 mov a,r4
39625 \end_layout
39626
39627 \begin_layout Standard
39628
39629 \size footnotesize
39630 \InsetSpace ~
39631 \InsetSpace ~
39632 xrl a,#0x80
39633 \end_layout
39634
39635 \begin_layout Standard
39636
39637 \size footnotesize
39638 \InsetSpace ~
39639 \InsetSpace ~
39640 subb a,#0x8a
39641 \end_layout
39642
39643 \begin_layout Standard
39644
39645 \size footnotesize
39646 \InsetSpace ~
39647 \InsetSpace ~
39648 jnc 00107$
39649 \end_layout
39650
39651 \begin_layout Standard
39652
39653 \size footnotesize
39654 00115$:
39655 \end_layout
39656
39657 \begin_layout Standard
39658
39659 \size footnotesize
39660 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39661 \end_layout
39662
39663 \begin_layout Standard
39664
39665 \size footnotesize
39666 ; iTemp21 [lr21:38]{short}[r4]
39667 \end_layout
39668
39669 \begin_layout Standard
39670
39671 \size footnotesize
39672 \InsetSpace ~
39673 \InsetSpace ~
39674 mov a,r4
39675 \end_layout
39676
39677 \begin_layout Standard
39678
39679 \size footnotesize
39680 \InsetSpace ~
39681 \InsetSpace ~
39682 add a,r2
39683 \end_layout
39684
39685 \begin_layout Standard
39686
39687 \size footnotesize
39688 \InsetSpace ~
39689 \InsetSpace ~
39690 mov r2,a
39691 \end_layout
39692
39693 \begin_layout Standard
39694
39695 \size footnotesize
39696 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39697 \end_layout
39698
39699 \begin_layout Standard
39700
39701 \size footnotesize
39702 \InsetSpace ~
39703 \InsetSpace ~
39704 mov b,#0x03
39705 \end_layout
39706
39707 \begin_layout Standard
39708
39709 \size footnotesize
39710 \InsetSpace ~
39711 \InsetSpace ~
39712 mov a,r4
39713 \end_layout
39714
39715 \begin_layout Standard
39716
39717 \size footnotesize
39718 \InsetSpace ~
39719 \InsetSpace ~
39720 mul ab
39721 \end_layout
39722
39723 \begin_layout Standard
39724
39725 \size footnotesize
39726 \InsetSpace ~
39727 \InsetSpace ~
39728 mov r1,a
39729 \end_layout
39730
39731 \begin_layout Standard
39732
39733 \size footnotesize
39734 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39735 \end_layout
39736
39737 \begin_layout Standard
39738
39739 \size footnotesize
39740 ; iTemp15 [lr29:30]{short}[r1]
39741 \end_layout
39742
39743 \begin_layout Standard
39744
39745 \size footnotesize
39746 \InsetSpace ~
39747 \InsetSpace ~
39748 add a,r3
39749 \end_layout
39750
39751 \begin_layout Standard
39752
39753 \size footnotesize
39754 \InsetSpace ~
39755 \InsetSpace ~
39756 mov r3,a
39757 \end_layout
39758
39759 \begin_layout Standard
39760
39761 \size footnotesize
39762 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39763 \end_layout
39764
39765 \begin_layout Standard
39766
39767 \size footnotesize
39768 \InsetSpace ~
39769 \InsetSpace ~
39770 mov a,r7
39771 \end_layout
39772
39773 \begin_layout Standard
39774
39775 \size footnotesize
39776 \InsetSpace ~
39777 \InsetSpace ~
39778 add a,#0xfd
39779 \end_layout
39780
39781 \begin_layout Standard
39782
39783 \size footnotesize
39784 \InsetSpace ~
39785 \InsetSpace ~
39786 mov r7,a
39787 \end_layout
39788
39789 \begin_layout Standard
39790
39791 \size footnotesize
39792 \InsetSpace ~
39793 \InsetSpace ~
39794 mov a,r0
39795 \end_layout
39796
39797 \begin_layout Standard
39798
39799 \size footnotesize
39800 \InsetSpace ~
39801 \InsetSpace ~
39802 addc a,#0xff
39803 \end_layout
39804
39805 \begin_layout Standard
39806
39807 \size footnotesize
39808 \InsetSpace ~
39809 \InsetSpace ~
39810 mov r0,a
39811 \end_layout
39812
39813 \begin_layout Standard
39814
39815 \size footnotesize
39816 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39817 \end_layout
39818
39819 \begin_layout Standard
39820
39821 \size footnotesize
39822 \InsetSpace ~
39823 \InsetSpace ~
39824 mov a,r7
39825 \end_layout
39826
39827 \begin_layout Standard
39828
39829 \size footnotesize
39830 \InsetSpace ~
39831 \InsetSpace ~
39832 add a,_gint
39833 \end_layout
39834
39835 \begin_layout Standard
39836
39837 \size footnotesize
39838 \InsetSpace ~
39839 \InsetSpace ~
39840 mov _gint,a
39841 \end_layout
39842
39843 \begin_layout Standard
39844
39845 \size footnotesize
39846 \InsetSpace ~
39847 \InsetSpace ~
39848 mov a,r0
39849 \end_layout
39850
39851 \begin_layout Standard
39852
39853 \size footnotesize
39854 \InsetSpace ~
39855 \InsetSpace ~
39856 addc a,(_gint + 1)
39857 \end_layout
39858
39859 \begin_layout Standard
39860
39861 \size footnotesize
39862 \InsetSpace ~
39863 \InsetSpace ~
39864 mov (_gint + 1),a
39865 \end_layout
39866
39867 \begin_layout Standard
39868
39869 \size footnotesize
39870 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39871 \end_layout
39872
39873 \begin_layout Standard
39874
39875 \size footnotesize
39876 \InsetSpace ~
39877 \InsetSpace ~
39878 inc r4
39879 \end_layout
39880
39881 \begin_layout Standard
39882
39883 \size footnotesize
39884 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39885 \end_layout
39886
39887 \begin_layout Standard
39888
39889 \size footnotesize
39890 \InsetSpace ~
39891 \InsetSpace ~
39892 dec r5
39893 \end_layout
39894
39895 \begin_layout Standard
39896
39897 \size footnotesize
39898 \InsetSpace ~
39899 \InsetSpace ~
39900 cjne r5,#0xff,00104$
39901 \end_layout
39902
39903 \begin_layout Standard
39904
39905 \size footnotesize
39906 \InsetSpace ~
39907 \InsetSpace ~
39908 dec r6
39909 \end_layout
39910
39911 \begin_layout Standard
39912
39913 \size footnotesize
39914 ; goto _forcond_0($4)
39915 \end_layout
39916
39917 \begin_layout Standard
39918
39919 \size footnotesize
39920 \InsetSpace ~
39921 \InsetSpace ~
39922 sjmp 00104$
39923 \end_layout
39924
39925 \begin_layout Standard
39926
39927 \size footnotesize
39928 ; _forbreak_0($7) :
39929 \end_layout
39930
39931 \begin_layout Standard
39932
39933 \size footnotesize
39934 00107$:
39935 \end_layout
39936
39937 \begin_layout Standard
39938
39939 \size footnotesize
39940 ; ret iTemp24 [lr40:41]{short}
39941 \end_layout
39942
39943 \begin_layout Standard
39944
39945 \size footnotesize
39946 \InsetSpace ~
39947 \InsetSpace ~
39948 mov a,r3
39949 \end_layout
39950
39951 \begin_layout Standard
39952
39953 \size footnotesize
39954 \InsetSpace ~
39955 \InsetSpace ~
39956 add a,r2
39957 \end_layout
39958
39959 \begin_layout Standard
39960
39961 \size footnotesize
39962 \InsetSpace ~
39963 \InsetSpace ~
39964 mov dpl,a
39965 \end_layout
39966
39967 \begin_layout Standard
39968
39969 \size footnotesize
39970 ; _return($8) :
39971 \end_layout
39972
39973 \begin_layout Standard
39974
39975 \size footnotesize
39976 00108$:
39977 \end_layout
39978
39979 \begin_layout Standard
39980
39981 \size footnotesize
39982 \InsetSpace ~
39983 \InsetSpace ~
39984 ret
39985 \newline
39986
39987 \end_layout
39988
39989 \begin_layout Section
39990 A few words about basic block successors, predecessors and dominators
39991 \end_layout
39992
39993 \begin_layout Standard
39994 Successors are basic blocks
39995 \begin_inset LatexCommand \index{Basic blocks}
39996
39997 \end_inset
39998
39999  that might execute after this basic block.
40000 \newline
40001 Predecessors are basic blocks
40002  that might execute before reaching this basic block.
40003 \newline
40004 Dominators are basic
40005  blocks that WILL execute before reaching this basic block.
40006 \newline
40007
40008 \end_layout
40009
40010 \begin_layout Standard
40011 [basic block 1]
40012 \end_layout
40013
40014 \begin_layout Standard
40015 if (something)
40016 \end_layout
40017
40018 \begin_layout Standard
40019 \InsetSpace ~
40020 \InsetSpace ~
40021 \InsetSpace ~
40022 \InsetSpace ~
40023 [basic block 2]
40024 \end_layout
40025
40026 \begin_layout Standard
40027 else
40028 \end_layout
40029
40030 \begin_layout Standard
40031 \InsetSpace ~
40032 \InsetSpace ~
40033 \InsetSpace ~
40034 \InsetSpace ~
40035 [basic block 3]
40036 \end_layout
40037
40038 \begin_layout Standard
40039 [basic block 4]
40040 \newline
40041
40042 \end_layout
40043
40044 \begin_layout Standard
40045 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40046 \end_layout
40047
40048 \begin_layout Standard
40049 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40050 \end_layout
40051
40052 \begin_layout Standard
40053 c) domVect of [BB4] = BB1 ...
40054  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40055  was executed.
40056 \end_layout
40057
40058 \begin_layout Chapter
40059 Acknowledgments
40060 \end_layout
40061
40062 \begin_layout Standard
40063 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40064
40065 \end_inset
40066
40067
40068 \newline
40069
40070 \newline
40071
40072 \emph on
40073 Thanks to all the other volunteer developers who have helped with coding,
40074  testing, web-page creation, distribution sets, etc.
40075  You know who you are :-)
40076 \emph default
40077
40078 \newline
40079
40080 \newline
40081
40082 \emph on
40083 Thanks to Sourceforge 
40084 \begin_inset LatexCommand \url{http://www.sf.net}
40085
40086 \end_inset
40087
40088  which has hosted the project since 1999 and donates significant download
40089  bandwidth.
40090 \emph default
40091
40092 \newline
40093
40094 \newline
40095
40096 \emph on
40097 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40098  cycles and bandwidth for snapshot builds.
40099 \newline
40100
40101 \end_layout
40102
40103 \begin_layout Standard
40104 This document was initially written by Sandeep Dutta
40105 \end_layout
40106
40107 \begin_layout Standard
40108 All product names mentioned herein may be trademarks
40109 \begin_inset LatexCommand \index{Trademarks}
40110
40111 \end_inset
40112
40113  of their respective companies.
40114  
40115 \end_layout
40116
40117 \begin_layout Section*
40118 Alphabetical index
40119 \end_layout
40120
40121 \begin_layout Standard
40122 To avoid confusion, the installation and building options for SDCC itself
40123  (chapter 2) are not part of the index.
40124 \end_layout
40125
40126 \begin_layout Standard
40127 \begin_inset LatexCommand \printindex{}
40128
40129 \end_inset
40130
40131
40132 \end_layout
40133
40134 \end_body
40135 \end_document