* dos/sdccman.lyx: docummented predefined macros SDCC_REVISION,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.5 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.5
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 and 
872 \series bold
873 -
874 \begin_inset ERT
875 status collapsed
876
877 \begin_layout Standard
878
879
880 \backslash
881 /
882 \end_layout
883
884 \end_inset
885
886 -std-c89
887 \begin_inset LatexCommand \index{-\/-std-c89}
888
889 \end_inset
890
891  
892 \series default
893 and
894 \series bold
895  -
896 \begin_inset ERT
897 status collapsed
898
899 \begin_layout Standard
900
901
902 \backslash
903 /
904 \end_layout
905
906 \end_inset
907
908 -std-c99
909 \begin_inset LatexCommand \index{-\/-std-c99}
910
911 \end_inset
912
913
914 \series default
915  command line option are not defined 
916 \begin_inset Marginal
917 status collapsed
918
919 \begin_layout Standard
920
921 \series bold
922 \InsetSpace ~
923 !
924 \end_layout
925
926 \end_inset
927
928 , e.g.: 
929 \newline
930
931 \family typewriter
932 \InsetSpace ~
933 \InsetSpace ~
934 char a=3;
935 \newline
936 \InsetSpace ~
937 \InsetSpace ~
938 printf ("%d %c
939 \backslash
940 n", a, (char)a);
941 \family default
942
943 \newline
944  will push a as an int and as a char resp.
945 \newline
946
947 \newline
948
949 \family typewriter
950 \InsetSpace ~
951 \InsetSpace ~
952 char a=3;
953 \newline
954 \InsetSpace ~
955 \InsetSpace ~
956 printf ("%d %c
957 \backslash
958 n", a, (char)a);
959 \family default
960
961 \newline
962  will push a as two ints if
963 \series bold
964  -
965 \begin_inset ERT
966 status collapsed
967
968 \begin_layout Standard
969
970
971 \backslash
972 /
973 \end_layout
974
975 \end_inset
976
977 -std-c89
978 \begin_inset LatexCommand \index{-\/-std-c89}
979
980 \end_inset
981
982  
983 \series default
984 or
985 \series bold
986  -
987 \begin_inset ERT
988 status collapsed
989
990 \begin_layout Standard
991
992
993 \backslash
994 /
995 \end_layout
996
997 \end_inset
998
999 -std-c99
1000 \begin_inset LatexCommand \index{-\/-std-c99}
1001
1002 \end_inset
1003
1004
1005 \series default
1006  command line option is defined.
1007 \end_layout
1008
1009 \begin_layout Itemize
1010 option -
1011 \begin_inset ERT
1012 status collapsed
1013
1014 \begin_layout Standard
1015
1016
1017 \backslash
1018 /
1019 \end_layout
1020
1021 \end_inset
1022
1023 -regextend has been removed.
1024 \end_layout
1025
1026 \begin_layout Itemize
1027 option -
1028 \begin_inset ERT
1029 status collapsed
1030
1031 \begin_layout Standard
1032
1033
1034 \backslash
1035 /
1036 \end_layout
1037
1038 \end_inset
1039
1040 -noregparms has been removed.
1041 \end_layout
1042
1043 \begin_layout Itemize
1044 option -
1045 \begin_inset ERT
1046 status collapsed
1047
1048 \begin_layout Standard
1049
1050
1051 \backslash
1052 /
1053 \end_layout
1054
1055 \end_inset
1056
1057 -stack-after-data has been removed.
1058 \end_layout
1059
1060 \begin_layout Itemize
1061 bit
1062 \begin_inset LatexCommand \index{bit}
1063
1064 \end_inset
1065
1066  and sbit
1067 \begin_inset LatexCommand \index{sbit}
1068
1069 \end_inset
1070
1071
1072 \begin_inset LatexCommand \index{\_\_sbit}
1073
1074 \end_inset
1075
1076  types now consistently behave like the C99 _Bool type with respect to type
1077  conversion
1078 \begin_inset LatexCommand \index{type conversion}
1079
1080 \end_inset
1081
1082
1083 \begin_inset LatexCommand \index{type promotion}
1084
1085 \end_inset
1086
1087 .
1088  The most common incompatibility resulting from this change is related to
1089  bit toggling
1090 \begin_inset LatexCommand \index{Bit toggling}
1091
1092 \end_inset
1093
1094  idioms, e.g.:
1095 \newline
1096
1097 \family typewriter
1098 \InsetSpace ~
1099 \InsetSpace ~
1100 bit b;
1101 \newline
1102 \InsetSpace ~
1103 \InsetSpace ~
1104 b = ~
1105 \begin_inset LatexCommand \index{\~\/ Operator}
1106
1107 \end_inset
1108
1109 b; /* equivalent to b=1 instead of toggling b */
1110 \begin_inset Marginal
1111 status collapsed
1112
1113 \begin_layout Standard
1114
1115 \series bold
1116 \InsetSpace ~
1117 !
1118 \end_layout
1119
1120 \end_inset
1121
1122
1123 \newline
1124 \InsetSpace ~
1125 \InsetSpace ~
1126 b = !b; /* toggles b */
1127 \newline
1128
1129 \family default
1130 In previous versions, both forms would have toggled the bit.
1131 \end_layout
1132
1133 \begin_layout Standard
1134
1135 \emph on
1136 <pending: more incompatibilities?>
1137 \end_layout
1138
1139 \begin_layout Section
1140 System Requirements
1141 \end_layout
1142
1143 \begin_layout Standard
1144 What do you need before you start installation of SDCC? A computer, and
1145  a desire to compute.
1146  The preferred method of installation is to compile SDCC from source using
1147  GNU gcc and make.
1148  For Windows some pre-compiled binary distributions are available for your
1149  convenience.
1150  You should have some experience with command line tools and compiler use.
1151 \end_layout
1152
1153 \begin_layout Section
1154 Other Resources
1155 \end_layout
1156
1157 \begin_layout Standard
1158 The SDCC home page at 
1159 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1160
1161 \end_inset
1162
1163  is a great place to find distribution sets.
1164  You can also find links to the user mailing lists that offer help or discuss
1165  SDCC with other SDCC users.
1166  Web links to other SDCC related sites can also be found here.
1167  This document can be found in the DOC directory of the source package as
1168  a text or HTML file.
1169  A pdf version of this document is available at 
1170 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1171
1172 \end_inset
1173
1174 .
1175  Some of the other tools (simulator and assembler) included with SDCC contain
1176  their own documentation and can be found in the source distribution.
1177  If you want the latest unreleased software, the complete source package
1178  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1179 sdcc/trunk/sdcc.
1180 \end_layout
1181
1182 \begin_layout Section
1183 Wishes for the future
1184 \end_layout
1185
1186 \begin_layout Standard
1187 There are (and always will be) some things that could be done.
1188  Here are some I can think of:
1189 \newline
1190
1191 \end_layout
1192
1193 \begin_layout Standard
1194
1195 \family typewriter
1196 char KernelFunction3(char p) at 0x340;
1197 \newline
1198
1199 \end_layout
1200
1201 \begin_layout Standard
1202
1203 \family typewriter
1204 better code banking
1205 \begin_inset LatexCommand \index{code banking (limited support)}
1206
1207 \end_inset
1208
1209  support for mcs51
1210 \newline
1211
1212 \newline
1213
1214 \family default
1215 If you can think of some more, please see the section 
1216 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1217
1218 \end_inset
1219
1220  about filing feature requests
1221 \begin_inset LatexCommand \index{Requesting features}
1222
1223 \end_inset
1224
1225
1226 \begin_inset LatexCommand \index{Feature request}
1227
1228 \end_inset
1229
1230 .
1231 \newline
1232
1233 \end_layout
1234
1235 \begin_layout Chapter
1236 Installing SDCC
1237 \begin_inset LatexCommand \index{Installation}
1238
1239 \end_inset
1240
1241
1242 \end_layout
1243
1244 \begin_layout Standard
1245 For most users it is sufficient to skip to either section 
1246 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1247
1248 \end_inset
1249
1250  (Unix) or section 
1251 \begin_inset LatexCommand \ref{sub:Windows-Install}
1252
1253 \end_inset
1254
1255  (Windows).
1256  More detailed instructions follow below.
1257 \end_layout
1258
1259 \begin_layout Section
1260 Configure Options
1261 \begin_inset LatexCommand \index{Options SDCC configuration}
1262
1263 \end_inset
1264
1265
1266 \end_layout
1267
1268 \begin_layout Standard
1269 The install paths, search paths and other options are defined when running
1270  'configure'.
1271  The defaults can be overridden by:
1272 \end_layout
1273
1274 \begin_layout List
1275 \labelwidthstring 00.00.0000
1276 -
1277 \begin_inset ERT
1278 status collapsed
1279
1280 \begin_layout Standard
1281
1282
1283 \backslash
1284 /
1285 \end_layout
1286
1287 \end_inset
1288
1289 -prefix see table below
1290 \end_layout
1291
1292 \begin_layout List
1293 \labelwidthstring 00.00.0000
1294 -
1295 \begin_inset ERT
1296 status collapsed
1297
1298 \begin_layout Standard
1299
1300
1301 \backslash
1302 /
1303 \end_layout
1304
1305 \end_inset
1306
1307 -exec_prefix see table below
1308 \end_layout
1309
1310 \begin_layout List
1311 \labelwidthstring 00.00.0000
1312 -
1313 \begin_inset ERT
1314 status collapsed
1315
1316 \begin_layout Standard
1317
1318
1319 \backslash
1320 /
1321 \end_layout
1322
1323 \end_inset
1324
1325 -bindir see table below
1326 \end_layout
1327
1328 \begin_layout List
1329 \labelwidthstring 00.00.0000
1330 -
1331 \begin_inset ERT
1332 status collapsed
1333
1334 \begin_layout Standard
1335
1336
1337 \backslash
1338 /
1339 \end_layout
1340
1341 \end_inset
1342
1343 -datadir see table below
1344 \end_layout
1345
1346 \begin_layout List
1347 \labelwidthstring 00.00.0000
1348 -
1349 \begin_inset ERT
1350 status collapsed
1351
1352 \begin_layout Standard
1353
1354
1355 \backslash
1356 /
1357 \end_layout
1358
1359 \end_inset
1360
1361 -datarootdir see table below
1362 \newline
1363
1364 \end_layout
1365
1366 \begin_layout List
1367 \labelwidthstring 00.00.0000
1368 \InsetSpace ~
1369 \InsetSpace ~
1370 docdir environment variable, see table below
1371 \end_layout
1372
1373 \begin_layout List
1374 \labelwidthstring 00.00.0000
1375 \InsetSpace ~
1376 \InsetSpace ~
1377 include_dir_suffix environment variable, see table below
1378 \end_layout
1379
1380 \begin_layout List
1381 \labelwidthstring 00.00.0000
1382 \InsetSpace ~
1383 \InsetSpace ~
1384 lib_dir_suffix environment variable, see table below
1385 \end_layout
1386
1387 \begin_layout List
1388 \labelwidthstring 00.00.0000
1389 \InsetSpace ~
1390 \InsetSpace ~
1391 sdccconf_h_dir_separator environment variable, either / or 
1392 \backslash
1393
1394 \backslash
1395  makes sense here.
1396  This character will only be used in sdccconf.h; don't forget it's a C-header,
1397  therefore a double-backslash is needed there.
1398 \newline
1399
1400 \end_layout
1401
1402 \begin_layout List
1403 \labelwidthstring 00.00.0000
1404 -
1405 \begin_inset ERT
1406 status collapsed
1407
1408 \begin_layout Standard
1409
1410
1411 \backslash
1412 /
1413 \end_layout
1414
1415 \end_inset
1416
1417 -disable-mcs51-port Excludes the Intel mcs51 port
1418 \end_layout
1419
1420 \begin_layout List
1421 \labelwidthstring 00.00.0000
1422 -
1423 \begin_inset ERT
1424 status collapsed
1425
1426 \begin_layout Standard
1427
1428
1429 \backslash
1430 /
1431 \end_layout
1432
1433 \end_inset
1434
1435 -disable-gbz80-port Excludes the Gameboy gbz80 port
1436 \end_layout
1437
1438 \begin_layout List
1439 \labelwidthstring 00.00.0000
1440 -
1441 \begin_inset ERT
1442 status collapsed
1443
1444 \begin_layout Standard
1445
1446
1447 \backslash
1448 /
1449 \end_layout
1450
1451 \end_inset
1452
1453 -disable-z80-port Excludes the z80 port
1454 \end_layout
1455
1456 \begin_layout List
1457 \labelwidthstring 00.00.0000
1458 -
1459 \begin_inset ERT
1460 status collapsed
1461
1462 \begin_layout Standard
1463
1464
1465 \backslash
1466 /
1467 \end_layout
1468
1469 \end_inset
1470
1471 -disable-avr-port Excludes the AVR port
1472 \end_layout
1473
1474 \begin_layout List
1475 \labelwidthstring 00.00.0000
1476 -
1477 \begin_inset ERT
1478 status collapsed
1479
1480 \begin_layout Standard
1481
1482
1483 \backslash
1484 /
1485 \end_layout
1486
1487 \end_inset
1488
1489 -disable-ds390-port Excludes the DS390 port
1490 \end_layout
1491
1492 \begin_layout List
1493 \labelwidthstring 00.00.0000
1494 -
1495 \begin_inset ERT
1496 status collapsed
1497
1498 \begin_layout Standard
1499
1500
1501 \backslash
1502 /
1503 \end_layout
1504
1505 \end_inset
1506
1507 -disable-hc08-port Excludes the HC08 port
1508 \end_layout
1509
1510 \begin_layout List
1511 \labelwidthstring 00.00.0000
1512 -
1513 \begin_inset ERT
1514 status collapsed
1515
1516 \begin_layout Standard
1517
1518
1519 \backslash
1520 /
1521 \end_layout
1522
1523 \end_inset
1524
1525 -disable-pic-port Excludes the PIC14 port
1526 \end_layout
1527
1528 \begin_layout List
1529 \labelwidthstring 00.00.0000
1530 -
1531 \begin_inset ERT
1532 status collapsed
1533
1534 \begin_layout Standard
1535
1536
1537 \backslash
1538 /
1539 \end_layout
1540
1541 \end_inset
1542
1543 -disable-pic16-port Excludes the PIC16 port
1544 \end_layout
1545
1546 \begin_layout List
1547 \labelwidthstring 00.00.0000
1548 -
1549 \begin_inset ERT
1550 status collapsed
1551
1552 \begin_layout Standard
1553
1554
1555 \backslash
1556 /
1557 \end_layout
1558
1559 \end_inset
1560
1561 -disable-xa51-port Excludes the XA51 port
1562 \end_layout
1563
1564 \begin_layout List
1565 \labelwidthstring 00.00.0000
1566 -
1567 \begin_inset ERT
1568 status collapsed
1569
1570 \begin_layout Standard
1571
1572
1573 \backslash
1574 /
1575 \end_layout
1576
1577 \end_inset
1578
1579 -disable-ucsim Disables configuring and building of ucsim
1580 \end_layout
1581
1582 \begin_layout List
1583 \labelwidthstring 00.00.0000
1584 -
1585 \begin_inset ERT
1586 status collapsed
1587
1588 \begin_layout Standard
1589
1590
1591 \backslash
1592 /
1593 \end_layout
1594
1595 \end_inset
1596
1597 -disable-device-lib Disables automatically building device libraries
1598 \end_layout
1599
1600 \begin_layout List
1601 \labelwidthstring 00.00.0000
1602 -
1603 \begin_inset ERT
1604 status collapsed
1605
1606 \begin_layout Standard
1607
1608
1609 \backslash
1610 /
1611 \end_layout
1612
1613 \end_inset
1614
1615 -disable-packihx Disables building packihx
1616 \newline
1617
1618 \end_layout
1619
1620 \begin_layout List
1621 \labelwidthstring 00.00.0000
1622 -
1623 \begin_inset ERT
1624 status collapsed
1625
1626 \begin_layout Standard
1627
1628
1629 \backslash
1630 /
1631 \end_layout
1632
1633 \end_inset
1634
1635 -enable-doc Build pdf, html and txt files from the lyx sources
1636 \end_layout
1637
1638 \begin_layout List
1639 \labelwidthstring 00.00.0000
1640 -
1641 \begin_inset ERT
1642 status collapsed
1643
1644 \begin_layout Standard
1645
1646
1647 \backslash
1648 /
1649 \end_layout
1650
1651 \end_inset
1652
1653 -enable-libgc Use the Bohem memory allocator.
1654  Lower runtime footprint.
1655 \end_layout
1656
1657 \begin_layout Standard
1658 Furthermore the environment variables CC, CFLAGS, ...
1659  the tools and their arguments can be influenced.
1660  Please see `configure -
1661 \begin_inset ERT
1662 status collapsed
1663
1664 \begin_layout Standard
1665
1666
1667 \backslash
1668 /
1669 \end_layout
1670
1671 \end_inset
1672
1673 -help' and the man/info pages of `configure' for details.
1674 \newline
1675
1676 \newline
1677 The names of the
1678  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1679 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1680  SDCC_LIB_NAME are defined by `configure' too.
1681  At the moment it's not possible to change the default settings (it was
1682  simply never required).
1683 \newline
1684
1685 \newline
1686 These configure options are compiled into the binaries,
1687  and can only be changed by rerunning 'configure' and recompiling SDCC.
1688  The configure options are written in 
1689 \emph on
1690 italics
1691 \emph default
1692  to distinguish them from run time environment variables (see section search
1693  paths).
1694 \newline
1695
1696 \newline
1697 The settings for 
1698 \begin_inset Quotes sld
1699 \end_inset
1700
1701 Win32 builds
1702 \begin_inset Quotes srd
1703 \end_inset
1704
1705  are used by the SDCC team to build the official Win32 binaries.
1706  The SDCC team uses Mingw32 to build the official Windows binaries, because
1707  it's
1708 \end_layout
1709
1710 \begin_layout Enumerate
1711 open source, 
1712 \end_layout
1713
1714 \begin_layout Enumerate
1715 a gcc compiler and last but not least
1716 \end_layout
1717
1718 \begin_layout Enumerate
1719 the binaries can be built by cross compiling on SDCC Distributed Compile
1720  Farm.
1721 \end_layout
1722
1723 \begin_layout Standard
1724 See the examples, how to pass the Win32 settings to 'configure'.
1725  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1726  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1727  for Win32.
1728 \newline
1729
1730 \newline
1731 These defaults are:
1732 \newline
1733
1734 \end_layout
1735
1736 \begin_layout Standard
1737 \align center
1738 \begin_inset Tabular
1739 <lyxtabular version="3" rows="9" columns="3">
1740 <features>
1741 <column alignment="block" valignment="top" leftline="true" width="0in">
1742 <column alignment="block" valignment="top" leftline="true" width="0in">
1743 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1744 <row topline="true" bottomline="true">
1745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1746 \begin_inset Text
1747
1748 \begin_layout Standard
1749 Variable
1750 \end_layout
1751
1752 \end_inset
1753 </cell>
1754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1755 \begin_inset Text
1756
1757 \begin_layout Standard
1758 default
1759 \end_layout
1760
1761 \end_inset
1762 </cell>
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1764 \begin_inset Text
1765
1766 \begin_layout Standard
1767 Win32 builds
1768 \end_layout
1769
1770 \end_inset
1771 </cell>
1772 </row>
1773 <row topline="true">
1774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1775 \begin_inset Text
1776
1777 \begin_layout Standard
1778
1779 \emph on
1780 PREFIX
1781 \end_layout
1782
1783 \end_inset
1784 </cell>
1785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1786 \begin_inset Text
1787
1788 \begin_layout Standard
1789 /usr/local
1790 \end_layout
1791
1792 \end_inset
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \begin_layout Standard
1798
1799 \backslash
1800 sdcc
1801 \end_layout
1802
1803 \end_inset
1804 </cell>
1805 </row>
1806 <row topline="true">
1807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1808 \begin_inset Text
1809
1810 \begin_layout Standard
1811
1812 \emph on
1813 EXEC_PREFIX
1814 \end_layout
1815
1816 \end_inset
1817 </cell>
1818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1819 \begin_inset Text
1820
1821 \begin_layout Standard
1822
1823 \emph on
1824 $PREFIX
1825 \end_layout
1826
1827 \end_inset
1828 </cell>
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1830 \begin_inset Text
1831
1832 \begin_layout Standard
1833
1834 \emph on
1835 $PREFIX
1836 \end_layout
1837
1838 \end_inset
1839 </cell>
1840 </row>
1841 <row topline="true">
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 \begin_inset Text
1844
1845 \begin_layout Standard
1846
1847 \emph on
1848 BINDIR
1849 \end_layout
1850
1851 \end_inset
1852 </cell>
1853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1854 \begin_inset Text
1855
1856 \begin_layout Standard
1857
1858 \emph on
1859 $EXEC_PREFIX
1860 \emph default
1861 /bin
1862 \end_layout
1863
1864 \end_inset
1865 </cell>
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1867 \begin_inset Text
1868
1869 \begin_layout Standard
1870
1871 \emph on
1872 $EXEC_PREFIX
1873 \emph default
1874
1875 \backslash
1876 bin
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 </row>
1882 <row topline="true">
1883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1884 \begin_inset Text
1885
1886 \begin_layout Standard
1887
1888 \emph on
1889 DATADIR
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $DATAROOTDIR
1901 \end_layout
1902
1903 \end_inset
1904 </cell>
1905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1906 \begin_inset Text
1907
1908 \begin_layout Standard
1909
1910 \emph on
1911 $DATAROOTDIR
1912 \end_layout
1913
1914 \end_inset
1915 </cell>
1916 </row>
1917 <row topline="true">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1919 \begin_inset Text
1920
1921 \begin_layout Standard
1922
1923 \emph on
1924 DATAROOTDIR
1925 \end_layout
1926
1927 \end_inset
1928 </cell>
1929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1930 \begin_inset Text
1931
1932 \begin_layout Standard
1933
1934 \emph on
1935 $PREFIX
1936 \emph default
1937 /share
1938 \end_layout
1939
1940 \end_inset
1941 </cell>
1942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1943 \begin_inset Text
1944
1945 \begin_layout Standard
1946
1947 \emph on
1948 $PREFIX
1949 \end_layout
1950
1951 \end_inset
1952 </cell>
1953 </row>
1954 <row topline="true">
1955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1956 \begin_inset Text
1957
1958 \begin_layout Standard
1959
1960 \emph on
1961 DOCDIR
1962 \end_layout
1963
1964 \end_inset
1965 </cell>
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \begin_layout Standard
1970
1971 \emph on
1972 $DATAROOTDIR
1973 \emph default
1974 /sdcc/doc
1975 \end_layout
1976
1977 \end_inset
1978 </cell>
1979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1980 \begin_inset Text
1981
1982 \begin_layout Standard
1983
1984 \emph on
1985 $DATAROOTDIR
1986 \emph default
1987
1988 \backslash
1989 doc
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 </row>
1995 <row topline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \begin_layout Standard
2000
2001 \emph on
2002 INCLUDE_DIR_SUFFIX
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011 sdcc/include
2012 \end_layout
2013
2014 \end_inset
2015 </cell>
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2017 \begin_inset Text
2018
2019 \begin_layout Standard
2020 include
2021 \end_layout
2022
2023 \end_inset
2024 </cell>
2025 </row>
2026 <row topline="true" bottomline="true">
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2028 \begin_inset Text
2029
2030 \begin_layout Standard
2031
2032 \emph on
2033 LIB_DIR_SUFFIX
2034 \end_layout
2035
2036 \end_inset
2037 </cell>
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_inset Text
2040
2041 \begin_layout Standard
2042 sdcc/lib
2043 \end_layout
2044
2045 \end_inset
2046 </cell>
2047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2048 \begin_inset Text
2049
2050 \begin_layout Standard
2051 lib
2052 \end_layout
2053
2054 \end_inset
2055 </cell>
2056 </row>
2057 </lyxtabular>
2058
2059 \end_inset
2060
2061
2062 \newline
2063
2064 \end_layout
2065
2066 \begin_layout Standard
2067 \noindent
2068 'configure' also computes relative paths.
2069  This is needed for full relocatability of a binary package and to complete
2070  search paths (see section search paths below):
2071 \newline
2072  
2073 \end_layout
2074
2075 \begin_layout Standard
2076 \align center
2077 \begin_inset Tabular
2078 <lyxtabular version="3" rows="4" columns="3">
2079 <features>
2080 <column alignment="block" valignment="top" leftline="true" width="0in">
2081 <column alignment="block" valignment="top" leftline="true" width="0in">
2082 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2083 <row topline="true" bottomline="true">
2084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2085 \begin_inset Text
2086
2087 \begin_layout Standard
2088 Variable (computed)
2089 \end_layout
2090
2091 \end_inset
2092 </cell>
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2094 \begin_inset Text
2095
2096 \begin_layout Standard
2097 default
2098 \end_layout
2099
2100 \end_inset
2101 </cell>
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2103 \begin_inset Text
2104
2105 \begin_layout Standard
2106 Win32 builds
2107 \end_layout
2108
2109 \end_inset
2110 </cell>
2111 </row>
2112 <row topline="true" bottomline="true">
2113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2114 \begin_inset Text
2115
2116 \begin_layout Standard
2117
2118 \emph on
2119 BIN2DATA_DIR
2120 \end_layout
2121
2122 \end_inset
2123 </cell>
2124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2125 \begin_inset Text
2126
2127 \begin_layout Standard
2128 ../share
2129 \end_layout
2130
2131 \end_inset
2132 </cell>
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \begin_layout Standard
2137 ..
2138 \end_layout
2139
2140 \end_inset
2141 </cell>
2142 </row>
2143 <row bottomline="true">
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_inset Text
2146
2147 \begin_layout Standard
2148
2149 \emph on
2150 PREFIX2BIN_DIR
2151 \end_layout
2152
2153 \end_inset
2154 </cell>
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2156 \begin_inset Text
2157
2158 \begin_layout Standard
2159 bin
2160 \end_layout
2161
2162 \end_inset
2163 </cell>
2164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2165 \begin_inset Text
2166
2167 \begin_layout Standard
2168 bin
2169 \end_layout
2170
2171 \end_inset
2172 </cell>
2173 </row>
2174 <row bottomline="true">
2175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2176 \begin_inset Text
2177
2178 \begin_layout Standard
2179
2180 \emph on
2181 PREFIX2DATA_DIR
2182 \end_layout
2183
2184 \end_inset
2185 </cell>
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \begin_layout Standard
2190 share/sdcc
2191 \end_layout
2192
2193 \end_inset
2194 </cell>
2195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2196 \begin_inset Text
2197
2198 \begin_layout Standard
2199
2200 \end_layout
2201
2202 \end_inset
2203 </cell>
2204 </row>
2205 </lyxtabular>
2206
2207 \end_inset
2208
2209
2210 \newline
2211
2212 \end_layout
2213
2214 \begin_layout Standard
2215 \noindent
2216 Examples:
2217 \end_layout
2218
2219 \begin_layout LyX-Code
2220 ./configure
2221 \newline
2222 ./configure -
2223 \begin_inset ERT
2224 status collapsed
2225
2226 \begin_layout Standard
2227
2228
2229 \backslash
2230 /
2231 \end_layout
2232
2233 \end_inset
2234
2235 -prefix=
2236 \begin_inset Quotes srd
2237 \end_inset
2238
2239 /usr/bin
2240 \begin_inset Quotes srd
2241 \end_inset
2242
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 -datarootdir=
2257 \begin_inset Quotes srd
2258 \end_inset
2259
2260 /usr/share
2261 \begin_inset Quotes srd
2262 \end_inset
2263
2264
2265 \newline
2266 ./configure -
2267 \begin_inset ERT
2268 status collapsed
2269
2270 \begin_layout Standard
2271
2272
2273 \backslash
2274 /
2275 \end_layout
2276
2277 \end_inset
2278
2279 -disable-avr-port -
2280 \begin_inset ERT
2281 status collapsed
2282
2283 \begin_layout Standard
2284
2285
2286 \backslash
2287 /
2288 \end_layout
2289
2290 \end_inset
2291
2292 -disable-xa51-port
2293 \end_layout
2294
2295 \begin_layout Standard
2296 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2297 32'):
2298 \end_layout
2299
2300 \begin_layout LyX-Code
2301 ./configure 
2302 \backslash
2303
2304 \newline
2305 CC=
2306 \begin_inset Quotes srd
2307 \end_inset
2308
2309 i586-mingw32msvc-gcc
2310 \begin_inset Quotes srd
2311 \end_inset
2312
2313  CXX=
2314 \begin_inset Quotes srd
2315 \end_inset
2316
2317 i586-mingw32msvc-g++
2318 \begin_inset Quotes srd
2319 \end_inset
2320
2321  
2322 \backslash
2323  
2324 \newline
2325 RANLIB=
2326 \begin_inset Quotes srd
2327 \end_inset
2328
2329 i586-mingw32msvc-ranlib
2330 \begin_inset Quotes srd
2331 \end_inset
2332
2333  
2334 \backslash
2335
2336 \newline
2337 STRIP=
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341 i586-mingw32msvc-strip
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345  
2346 \backslash
2347
2348 \newline
2349 -
2350 \begin_inset ERT
2351 status collapsed
2352
2353 \begin_layout Standard
2354
2355
2356 \backslash
2357 /
2358 \end_layout
2359
2360 \end_inset
2361
2362 -prefix=
2363 \begin_inset Quotes srd
2364 \end_inset
2365
2366 /sdcc
2367 \begin_inset Quotes srd
2368 \end_inset
2369
2370  
2371 \backslash
2372
2373 \newline
2374 -
2375 \begin_inset ERT
2376 status collapsed
2377
2378 \begin_layout Standard
2379
2380
2381 \backslash
2382 /
2383 \end_layout
2384
2385 \end_inset
2386
2387 -datarootdir=
2388 \begin_inset Quotes srd
2389 \end_inset
2390
2391 /sdcc
2392 \begin_inset Quotes srd
2393 \end_inset
2394
2395  
2396 \backslash
2397
2398 \newline
2399 docdir=
2400 \begin_inset Quotes srd
2401 \end_inset
2402
2403
2404 \backslash
2405 ${datarootdir}/doc
2406 \begin_inset Quotes srd
2407 \end_inset
2408
2409  
2410 \backslash
2411
2412 \newline
2413 include_dir_suffix=
2414 \begin_inset Quotes srd
2415 \end_inset
2416
2417 include
2418 \begin_inset Quotes srd
2419 \end_inset
2420
2421  
2422 \backslash
2423
2424 \newline
2425 lib_dir_suffix=
2426 \begin_inset Quotes srd
2427 \end_inset
2428
2429 lib
2430 \begin_inset Quotes srd
2431 \end_inset
2432
2433  
2434 \backslash
2435
2436 \newline
2437 sdccconf_h_dir_separator=
2438 \begin_inset Quotes srd
2439 \end_inset
2440
2441
2442 \backslash
2443
2444 \backslash
2445
2446 \backslash
2447
2448 \backslash
2449
2450 \begin_inset Quotes srd
2451 \end_inset
2452
2453  
2454 \backslash
2455
2456 \newline
2457 -
2458 \begin_inset ERT
2459 status collapsed
2460
2461 \begin_layout Standard
2462
2463
2464 \backslash
2465 /
2466 \end_layout
2467
2468 \end_inset
2469
2470 -disable-device-lib
2471 \backslash
2472
2473 \newline
2474 -
2475 \begin_inset ERT
2476 status collapsed
2477
2478 \begin_layout Standard
2479
2480
2481 \backslash
2482 /
2483 \end_layout
2484
2485 \end_inset
2486
2487 -host=i586-mingw32msvc
2488 \backslash
2489
2490 \newline
2491 -
2492 \begin_inset ERT
2493 status collapsed
2494
2495 \begin_layout Standard
2496
2497
2498 \backslash
2499 /
2500 \end_layout
2501
2502 \end_inset
2503
2504 -build=unknown-unknown-linux-gnu
2505 \end_layout
2506
2507 \begin_layout Standard
2508 To 
2509 \begin_inset Quotes sld
2510 \end_inset
2511
2512 cross
2513 \begin_inset Quotes srd
2514 \end_inset
2515
2516 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2517 ):
2518 \end_layout
2519
2520 \begin_layout LyX-Code
2521 ./configure -C 
2522 \backslash
2523
2524 \newline
2525 -
2526 \begin_inset ERT
2527 status collapsed
2528
2529 \begin_layout Standard
2530
2531
2532 \backslash
2533 /
2534 \end_layout
2535
2536 \end_inset
2537
2538 -prefix=
2539 \begin_inset Quotes srd
2540 \end_inset
2541
2542 /sdcc
2543 \begin_inset Quotes srd
2544 \end_inset
2545
2546  
2547 \backslash
2548
2549 \newline
2550 -
2551 \begin_inset ERT
2552 status collapsed
2553
2554 \begin_layout Standard
2555
2556
2557 \backslash
2558 /
2559 \end_layout
2560
2561 \end_inset
2562
2563 -datarootdir=
2564 \begin_inset Quotes srd
2565 \end_inset
2566
2567 /sdcc
2568 \begin_inset Quotes srd
2569 \end_inset
2570
2571  
2572 \backslash
2573
2574 \newline
2575 docdir=
2576 \begin_inset Quotes srd
2577 \end_inset
2578
2579
2580 \backslash
2581 ${datarootdir}/doc
2582 \begin_inset Quotes srd
2583 \end_inset
2584
2585  
2586 \backslash
2587  
2588 \newline
2589 include_dir_suffix=
2590 \begin_inset Quotes srd
2591 \end_inset
2592
2593 include
2594 \begin_inset Quotes srd
2595 \end_inset
2596
2597  
2598 \backslash
2599
2600 \newline
2601 lib_dir_suffix=
2602 \begin_inset Quotes srd
2603 \end_inset
2604
2605 lib
2606 \begin_inset Quotes srd
2607 \end_inset
2608
2609  
2610 \backslash
2611
2612 \newline
2613 sdccconf_h_dir_separator=
2614 \begin_inset Quotes srd
2615 \end_inset
2616
2617
2618 \backslash
2619
2620 \backslash
2621
2622 \backslash
2623
2624 \backslash
2625
2626 \begin_inset Quotes srd
2627 \end_inset
2628
2629  
2630 \backslash
2631
2632 \newline
2633 CC=
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637 gcc -mno-cygwin
2638 \begin_inset Quotes srd
2639 \end_inset
2640
2641  
2642 \backslash
2643
2644 \newline
2645 CXX=
2646 \begin_inset Quotes srd
2647 \end_inset
2648
2649 g++ -mno-cygwin
2650 \begin_inset Quotes srd
2651 \end_inset
2652
2653  
2654 \end_layout
2655
2656 \begin_layout Standard
2657 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2658  The option '-
2659 \begin_inset ERT
2660 status collapsed
2661
2662 \begin_layout Standard
2663
2664
2665 \backslash
2666 /
2667 \end_layout
2668
2669 \end_inset
2670
2671 -C' turns on caching, which gives a little bit extra speed.
2672  However if options are changed, it can be necessary to delete the config.cache
2673  file.
2674 \end_layout
2675
2676 \begin_layout Section
2677 Install paths
2678 \begin_inset LatexCommand \label{sub:Install-paths}
2679
2680 \end_inset
2681
2682
2683 \begin_inset LatexCommand \index{Install paths}
2684
2685 \end_inset
2686
2687
2688 \end_layout
2689
2690 \begin_layout Standard
2691 \begin_inset VSpace medskip
2692 \end_inset
2693
2694
2695 \end_layout
2696
2697 \begin_layout Standard
2698 \align center
2699 \begin_inset Tabular
2700 <lyxtabular version="3" rows="5" columns="4">
2701 <features>
2702 <column alignment="left" valignment="top" leftline="true" width="0">
2703 <column alignment="left" valignment="top" leftline="true" width="0">
2704 <column alignment="left" valignment="top" leftline="true" width="0">
2705 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2706 <row topline="true" bottomline="true">
2707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2708 \begin_inset Text
2709
2710 \begin_layout Standard
2711
2712 \series bold
2713 Description
2714 \end_layout
2715
2716 \end_inset
2717 </cell>
2718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2719 \begin_inset Text
2720
2721 \begin_layout Standard
2722
2723 \series bold
2724 Path
2725 \end_layout
2726
2727 \end_inset
2728 </cell>
2729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2730 \begin_inset Text
2731
2732 \begin_layout Standard
2733
2734 \series bold
2735 Default
2736 \end_layout
2737
2738 \end_inset
2739 </cell>
2740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2741 \begin_inset Text
2742
2743 \begin_layout Standard
2744
2745 \series bold
2746 Win32 builds
2747 \end_layout
2748
2749 \end_inset
2750 </cell>
2751 </row>
2752 <row topline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \begin_layout Standard
2757 Binary files*
2758 \end_layout
2759
2760 \end_inset
2761 </cell>
2762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2763 \begin_inset Text
2764
2765 \begin_layout Standard
2766
2767 \emph on
2768 $EXEC_PREFIX
2769 \end_layout
2770
2771 \end_inset
2772 </cell>
2773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2774 \begin_inset Text
2775
2776 \begin_layout Standard
2777 /usr/local/bin
2778 \end_layout
2779
2780 \end_inset
2781 </cell>
2782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2783 \begin_inset Text
2784
2785 \begin_layout Standard
2786
2787 \backslash
2788 sdcc
2789 \backslash
2790 bin
2791 \end_layout
2792
2793 \end_inset
2794 </cell>
2795 </row>
2796 <row topline="true">
2797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2798 \begin_inset Text
2799
2800 \begin_layout Standard
2801 Include files
2802 \end_layout
2803
2804 \end_inset
2805 </cell>
2806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2807 \begin_inset Text
2808
2809 \begin_layout Standard
2810
2811 \emph on
2812 $DATADIR/ $INCLUDE_DIR_SUFFIX
2813 \end_layout
2814
2815 \end_inset
2816 </cell>
2817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2818 \begin_inset Text
2819
2820 \begin_layout Standard
2821 /usr/local/share/sdcc/include
2822 \end_layout
2823
2824 \end_inset
2825 </cell>
2826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2827 \begin_inset Text
2828
2829 \begin_layout Standard
2830
2831 \backslash
2832 sdcc
2833 \backslash
2834 include
2835 \end_layout
2836
2837 \end_inset
2838 </cell>
2839 </row>
2840 <row topline="true">
2841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2842 \begin_inset Text
2843
2844 \begin_layout Standard
2845 Library file**
2846 \end_layout
2847
2848 \end_inset
2849 </cell>
2850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2851 \begin_inset Text
2852
2853 \begin_layout Standard
2854
2855 \emph on
2856 $DATADIR/$LIB_DIR_SUFFIX
2857 \end_layout
2858
2859 \end_inset
2860 </cell>
2861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2862 \begin_inset Text
2863
2864 \begin_layout Standard
2865 /usr/local/share/sdcc/lib
2866 \end_layout
2867
2868 \end_inset
2869 </cell>
2870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2871 \begin_inset Text
2872
2873 \begin_layout Standard
2874
2875 \backslash
2876 sdcc
2877 \backslash
2878 lib
2879 \end_layout
2880
2881 \end_inset
2882 </cell>
2883 </row>
2884 <row topline="true" bottomline="true">
2885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2886 \begin_inset Text
2887
2888 \begin_layout Standard
2889 Documentation
2890 \end_layout
2891
2892 \end_inset
2893 </cell>
2894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2895 \begin_inset Text
2896
2897 \begin_layout Standard
2898
2899 \emph on
2900 $DOCDIR
2901 \end_layout
2902
2903 \end_inset
2904 </cell>
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \begin_layout Standard
2909 /usr/local/share/sdcc/doc
2910 \end_layout
2911
2912 \end_inset
2913 </cell>
2914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2915 \begin_inset Text
2916
2917 \begin_layout Standard
2918
2919 \backslash
2920 sdcc
2921 \backslash
2922 doc
2923 \end_layout
2924
2925 \end_inset
2926 </cell>
2927 </row>
2928 </lyxtabular>
2929
2930 \end_inset
2931
2932
2933 \end_layout
2934
2935 \begin_layout Verse
2936
2937 \size footnotesize
2938 *compiler, preprocessor, assembler, and linker
2939 \newline
2940 **the 
2941 \shape italic
2942 model
2943 \shape default
2944  is auto-appended by the compiler, e.g.
2945  small, large, z80, ds390 etc
2946 \end_layout
2947
2948 \begin_layout Standard
2949 \noindent
2950 The install paths can still be changed during `make install' with e.g.:
2951 \end_layout
2952
2953 \begin_layout LyX-Code
2954 make install prefix=$(HOME)/local/sdcc
2955 \end_layout
2956
2957 \begin_layout Standard
2958 Of course this doesn't change the search paths compiled into the binaries.
2959 \newline
2960
2961 \newline
2962 Moreove
2963 r the install path can be changed by defining DESTDIR
2964 \begin_inset LatexCommand \index{DESTDIR}
2965
2966 \end_inset
2967
2968 :
2969 \end_layout
2970
2971 \begin_layout LyX-Code
2972 make install DESTDIR=$(HOME)/sdcc.rpm/
2973 \end_layout
2974
2975 \begin_layout Standard
2976 Please note that DESTDIR must have a trailing slash!
2977 \end_layout
2978
2979 \begin_layout Section
2980 Search Paths
2981 \begin_inset LatexCommand \label{sub:Search-Paths}
2982
2983 \end_inset
2984
2985
2986 \begin_inset LatexCommand \index{Search path}
2987
2988 \end_inset
2989
2990
2991 \end_layout
2992
2993 \begin_layout Standard
2994 Some search paths or parts of them are determined by configure variables
2995  (in 
2996 \emph on
2997 italics
2998 \emph default
2999 , see section above).
3000  Further search paths are determined by environment variables during runtime.
3001  
3002 \newline
3003 The paths searched when running the compiler are as follows (the first
3004  catch wins):
3005 \newline
3006
3007 \newline
3008 1.
3009  Binary files (preprocessor, assembler and linker)
3010 \newline
3011
3012 \end_layout
3013
3014 \begin_layout Standard
3015 \align center
3016 \begin_inset Tabular
3017 <lyxtabular version="3" rows="4" columns="3">
3018 <features>
3019 <column alignment="block" valignment="top" leftline="true" width="0in">
3020 <column alignment="block" valignment="top" leftline="true" width="0in">
3021 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3022 <row topline="true" bottomline="true">
3023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3024 \begin_inset Text
3025
3026 \begin_layout Standard
3027 Search path
3028 \end_layout
3029
3030 \end_inset
3031 </cell>
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_inset Text
3034
3035 \begin_layout Standard
3036 default
3037 \end_layout
3038
3039 \end_inset
3040 </cell>
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3042 \begin_inset Text
3043
3044 \begin_layout Standard
3045 Win32 builds
3046 \end_layout
3047
3048 \end_inset
3049 </cell>
3050 </row>
3051 <row topline="true">
3052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3053 \begin_inset Text
3054
3055 \begin_layout Standard
3056 $SDCC_HOME/
3057 \emph on
3058 $PPREFIX2BIN_DIR
3059 \end_layout
3060
3061 \end_inset
3062 </cell>
3063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 \begin_inset Text
3065
3066 \begin_layout Standard
3067 $SDCC_HOME/bin
3068 \end_layout
3069
3070 \end_inset
3071 </cell>
3072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3073 \begin_inset Text
3074
3075 \begin_layout Standard
3076 $SDCC_HOME
3077 \backslash
3078 bin
3079 \end_layout
3080
3081 \end_inset
3082 </cell>
3083 </row>
3084 <row topline="true">
3085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3086 \begin_inset Text
3087
3088 \begin_layout Standard
3089 Path of argv[0] (if available)
3090 \end_layout
3091
3092 \end_inset
3093 </cell>
3094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3095 \begin_inset Text
3096
3097 \begin_layout Standard
3098 Path of argv[0]
3099 \end_layout
3100
3101 \end_inset
3102 </cell>
3103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3104 \begin_inset Text
3105
3106 \begin_layout Standard
3107 Path of argv[0]
3108 \end_layout
3109
3110 \end_inset
3111 </cell>
3112 </row>
3113 <row topline="true" bottomline="true">
3114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3115 \begin_inset Text
3116
3117 \begin_layout Standard
3118 $PATH
3119 \end_layout
3120
3121 \end_inset
3122 </cell>
3123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3124 \begin_inset Text
3125
3126 \begin_layout Standard
3127 $PATH
3128 \end_layout
3129
3130 \end_inset
3131 </cell>
3132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3133 \begin_inset Text
3134
3135 \begin_layout Standard
3136 $PATH
3137 \end_layout
3138
3139 \end_inset
3140 </cell>
3141 </row>
3142 </lyxtabular>
3143
3144 \end_inset
3145
3146  
3147 \newline
3148
3149 \end_layout
3150
3151 \begin_layout Standard
3152 \noindent
3153 2.
3154  Include files
3155 \newline
3156
3157 \end_layout
3158
3159 \begin_layout Standard
3160 \align center
3161 \begin_inset Tabular
3162 <lyxtabular version="3" rows="6" columns="3">
3163 <features>
3164 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3165 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3166 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3167 <row topline="true" bottomline="true">
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3169 \begin_inset Text
3170
3171 \begin_layout Standard
3172 Search path
3173 \end_layout
3174
3175 \end_inset
3176 </cell>
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3178 \begin_inset Text
3179
3180 \begin_layout Standard
3181 default
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3187 \begin_inset Text
3188
3189 \begin_layout Standard
3190 Win32 builds
3191 \end_layout
3192
3193 \end_inset
3194 </cell>
3195 </row>
3196 <row topline="true">
3197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3198 \begin_inset Text
3199
3200 \begin_layout Standard
3201 -
3202 \begin_inset ERT
3203 status collapsed
3204
3205 \begin_layout Standard
3206
3207
3208 \backslash
3209 /
3210 \end_layout
3211
3212 \end_inset
3213
3214 -I dir
3215 \end_layout
3216
3217 \end_inset
3218 </cell>
3219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3220 \begin_inset Text
3221
3222 \begin_layout Standard
3223 -
3224 \begin_inset ERT
3225 status collapsed
3226
3227 \begin_layout Standard
3228
3229
3230 \backslash
3231 /
3232 \end_layout
3233
3234 \end_inset
3235
3236 -I dir
3237 \end_layout
3238
3239 \end_inset
3240 </cell>
3241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3242 \begin_inset Text
3243
3244 \begin_layout Standard
3245 -
3246 \begin_inset ERT
3247 status collapsed
3248
3249 \begin_layout Standard
3250
3251
3252 \backslash
3253 /
3254 \end_layout
3255
3256 \end_inset
3257
3258 -I dir
3259 \end_layout
3260
3261 \end_inset
3262 </cell>
3263 </row>
3264 <row topline="true">
3265 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3266 \begin_inset Text
3267
3268 \begin_layout Standard
3269 $SDCC_INCLUDE
3270 \end_layout
3271
3272 \end_inset
3273 </cell>
3274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3275 \begin_inset Text
3276
3277 \begin_layout Standard
3278 $SDCC_INCLUDE
3279 \end_layout
3280
3281 \end_inset
3282 </cell>
3283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3284 \begin_inset Text
3285
3286 \begin_layout Standard
3287 $SDCC_INCLUDE
3288 \end_layout
3289
3290 \end_inset
3291 </cell>
3292 </row>
3293 <row topline="true">
3294 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3295 \begin_inset Text
3296
3297 \begin_layout Standard
3298 $SDCC_HOME/
3299 \newline
3300
3301 \emph on
3302 $PREFIX2DATA_DIR/
3303 \newline
3304 $INCLUDE_DIR_SUFFIX
3305 \end_layout
3306
3307 \end_inset
3308 </cell>
3309 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_inset Text
3311
3312 \begin_layout Standard
3313 $SDCC_ HOME/
3314 \newline
3315 share/sdcc/
3316 \newline
3317 include
3318 \end_layout
3319
3320 \end_inset
3321 </cell>
3322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME
3327 \backslash
3328 include
3329 \end_layout
3330
3331 \end_inset
3332 </cell>
3333 </row>
3334 <row topline="true">
3335 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3336 \begin_inset Text
3337
3338 \begin_layout Standard
3339 path(argv[0])/
3340 \newline
3341
3342 \emph on
3343 $BIN2DATADIR/
3344 \emph default
3345
3346 \newline
3347
3348 \emph on
3349 $INCLUDE_DIR_SUFFIX
3350 \end_layout
3351
3352 \end_inset
3353 </cell>
3354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3355 \begin_inset Text
3356
3357 \begin_layout Standard
3358 path(argv[0])/
3359 \newline
3360 ../sdcc/include
3361 \newline
3362 \InsetSpace ~
3363 \InsetSpace ~
3364 \InsetSpace ~
3365 \InsetSpace ~
3366 \InsetSpace ~
3367 \InsetSpace ~
3368 \InsetSpace ~
3369 \InsetSpace ~
3370 \InsetSpace ~
3371 \InsetSpace ~
3372 \InsetSpace ~
3373 \InsetSpace ~
3374 \InsetSpace ~
3375 \InsetSpace ~
3376 \InsetSpace ~
3377 \InsetSpace ~
3378 \InsetSpace ~
3379 \InsetSpace ~
3380 \InsetSpace ~
3381 \InsetSpace ~
3382 \InsetSpace ~
3383 \InsetSpace ~
3384 \InsetSpace ~
3385 \InsetSpace ~
3386 \InsetSpace ~
3387 \InsetSpace ~
3388 \InsetSpace ~
3389 \InsetSpace ~
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400
3401 \end_layout
3402
3403 \end_inset
3404 </cell>
3405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3406 \begin_inset Text
3407
3408 \begin_layout Standard
3409 path(argv[0])
3410 \backslash
3411 ..
3412 \backslash
3413 include
3414 \end_layout
3415
3416 \end_inset
3417 </cell>
3418 </row>
3419 <row topline="true" bottomline="true">
3420 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3421 \begin_inset Text
3422
3423 \begin_layout Standard
3424
3425 \emph on
3426 $DATADIR/
3427 \emph default
3428
3429 \newline
3430
3431 \emph on
3432 $INCLUDE_DIR_SUFFIX
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 /usr/local/share/sdcc/
3442 \newline
3443 include
3444 \end_layout
3445
3446 \end_inset
3447 </cell>
3448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452 (not on Win32)
3453 \end_layout
3454
3455 \end_inset
3456 </cell>
3457 </row>
3458 </lyxtabular>
3459
3460 \end_inset
3461
3462  
3463 \newline
3464
3465 \end_layout
3466
3467 \begin_layout Standard
3468 \noindent
3469 The option -
3470 \begin_inset ERT
3471 status collapsed
3472
3473 \begin_layout Standard
3474
3475
3476 \backslash
3477 /
3478 \end_layout
3479
3480 \end_inset
3481
3482 -nostdinc disables the last two search paths.
3483 \newline
3484
3485 \newline
3486 3.
3487  Library files 
3488 \newline
3489
3490 \end_layout
3491
3492 \begin_layout Standard
3493 With the exception of 
3494 \begin_inset Quotes sld
3495 \end_inset
3496
3497 -
3498 \begin_inset ERT
3499 status collapsed
3500
3501 \begin_layout Standard
3502
3503
3504 \backslash
3505 /
3506 \end_layout
3507
3508 \end_inset
3509
3510 -L dir
3511 \begin_inset Quotes srd
3512 \end_inset
3513
3514  the 
3515 \shape italic
3516 model
3517 \shape default
3518  is auto-appended by the compiler (e.g.
3519  small, large, z80, ds390 etc.).
3520  
3521 \newline
3522
3523 \end_layout
3524
3525 \begin_layout Standard
3526 \align center
3527 \begin_inset Tabular
3528 <lyxtabular version="3" rows="6" columns="3">
3529 <features>
3530 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3531 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3532 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3533 <row topline="true" bottomline="true">
3534 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3535 \begin_inset Text
3536
3537 \begin_layout Standard
3538 Search path
3539 \end_layout
3540
3541 \end_inset
3542 </cell>
3543 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3544 \begin_inset Text
3545
3546 \begin_layout Standard
3547 default
3548 \end_layout
3549
3550 \end_inset
3551 </cell>
3552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3553 \begin_inset Text
3554
3555 \begin_layout Standard
3556 Win32 builds
3557 \end_layout
3558
3559 \end_inset
3560 </cell>
3561 </row>
3562 <row topline="true">
3563 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3564 \begin_inset Text
3565
3566 \begin_layout Standard
3567 -
3568 \begin_inset ERT
3569 status collapsed
3570
3571 \begin_layout Standard
3572
3573
3574 \backslash
3575 /
3576 \end_layout
3577
3578 \end_inset
3579
3580 -L dir
3581 \end_layout
3582
3583 \end_inset
3584 </cell>
3585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_inset Text
3587
3588 \begin_layout Standard
3589 -
3590 \begin_inset ERT
3591 status collapsed
3592
3593 \begin_layout Standard
3594
3595
3596 \backslash
3597 /
3598 \end_layout
3599
3600 \end_inset
3601
3602 -L dir
3603 \end_layout
3604
3605 \end_inset
3606 </cell>
3607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3608 \begin_inset Text
3609
3610 \begin_layout Standard
3611 -
3612 \begin_inset ERT
3613 status collapsed
3614
3615 \begin_layout Standard
3616
3617
3618 \backslash
3619 /
3620 \end_layout
3621
3622 \end_inset
3623
3624 -L dir
3625 \end_layout
3626
3627 \end_inset
3628 </cell>
3629 </row>
3630 <row topline="true">
3631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3632 \begin_inset Text
3633
3634 \begin_layout Standard
3635 $SDCC_LIB/
3636 \newline
3637
3638 \emph on
3639 <model>
3640 \end_layout
3641
3642 \end_inset
3643 </cell>
3644 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3645 \begin_inset Text
3646
3647 \begin_layout Standard
3648 $SDCC_LIB/
3649 \newline
3650
3651 \emph on
3652 <model>
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3658 \begin_inset Text
3659
3660 \begin_layout Standard
3661 $SDCC_LIB
3662 \backslash
3663
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 </row>
3673 <row topline="true">
3674 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3675 \begin_inset Text
3676
3677 \begin_layout Standard
3678 $SDCC_HOME/
3679 \newline
3680
3681 \emph on
3682 $PREFIX2DATA_DIR/
3683 \newline
3684 $LIB_DIR_SUFFIX/<model>
3685 \end_layout
3686
3687 \end_inset
3688 </cell>
3689 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3690 \begin_inset Text
3691
3692 \begin_layout Standard
3693 $SDCC_HOME/
3694 \newline
3695 share/sdcc/
3696 \newline
3697 lib/
3698 \emph on
3699 <model>
3700 \end_layout
3701
3702 \end_inset
3703 </cell>
3704 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3705 \begin_inset Text
3706
3707 \begin_layout Standard
3708 $SDCC_HOME
3709 \backslash
3710 lib
3711 \backslash
3712
3713 \emph on
3714
3715 \newline
3716 <model>
3717 \end_layout
3718
3719 \end_inset
3720 </cell>
3721 </row>
3722 <row topline="true">
3723 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3724 \begin_inset Text
3725
3726 \begin_layout Standard
3727 path(argv[0])/
3728 \newline
3729
3730 \emph on
3731 $BIN2DATADIR/
3732 \emph default
3733
3734 \newline
3735
3736 \emph on
3737 $LIB_DIR_SUFFIX/<model>
3738 \end_layout
3739
3740 \end_inset
3741 </cell>
3742 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3743 \begin_inset Text
3744
3745 \begin_layout Standard
3746 path(argv[0])/
3747 \newline
3748 ../sdcc/lib/
3749 \emph on
3750 <model>
3751 \newline
3752 \InsetSpace ~
3753 \InsetSpace ~
3754 \InsetSpace ~
3755 \InsetSpace ~
3756 \InsetSpace ~
3757 \InsetSpace ~
3758 \InsetSpace ~
3759 \InsetSpace ~
3760 \InsetSpace ~
3761 \InsetSpace ~
3762 \InsetSpace ~
3763 \InsetSpace ~
3764 \InsetSpace ~
3765 \InsetSpace ~
3766 \InsetSpace ~
3767 \InsetSpace ~
3768 \InsetSpace ~
3769 \InsetSpace ~
3770 \InsetSpace ~
3771 \InsetSpace ~
3772 \InsetSpace ~
3773 \InsetSpace ~
3774 \InsetSpace ~
3775 \InsetSpace ~
3776 \InsetSpace ~
3777 \InsetSpace ~
3778 \InsetSpace ~
3779 \InsetSpace ~
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791
3792 \end_layout
3793
3794 \end_inset
3795 </cell>
3796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3797 \begin_inset Text
3798
3799 \begin_layout Standard
3800 path(argv[0])
3801 \backslash
3802
3803 \newline
3804 ..
3805 \backslash
3806 lib
3807 \backslash
3808
3809 \emph on
3810 <model>
3811 \newline
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819 \InsetSpace ~
3820 \InsetSpace ~
3821 \InsetSpace ~
3822 \InsetSpace ~
3823 \InsetSpace ~
3824 \InsetSpace ~
3825 \InsetSpace ~
3826 \InsetSpace ~
3827 \InsetSpace ~
3828 \InsetSpace ~
3829 \InsetSpace ~
3830 \InsetSpace ~
3831 \InsetSpace ~
3832 \InsetSpace ~
3833 \InsetSpace ~
3834 \InsetSpace ~
3835 \InsetSpace ~
3836 \InsetSpace ~
3837 \InsetSpace ~
3838 \InsetSpace ~
3839 \InsetSpace ~
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847
3848 \end_layout
3849
3850 \end_inset
3851 </cell>
3852 </row>
3853 <row topline="true" bottomline="true">
3854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3855 \begin_inset Text
3856
3857 \begin_layout Standard
3858
3859 \emph on
3860 $DATADIR/
3861 \newline
3862 $LIB_DIR_SUFFIX/<model>
3863 \end_layout
3864
3865 \end_inset
3866 </cell>
3867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3868 \begin_inset Text
3869
3870 \begin_layout Standard
3871 /usr/local/share/sdcc/
3872 \newline
3873 lib/
3874 \emph on
3875 <model>
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3881 \begin_inset Text
3882
3883 \begin_layout Standard
3884 (not on Win32)
3885 \end_layout
3886
3887 \end_inset
3888 </cell>
3889 </row>
3890 </lyxtabular>
3891
3892 \end_inset
3893
3894
3895 \newline
3896
3897 \end_layout
3898
3899 \begin_layout Standard
3900 \begin_inset Note Note
3901 status collapsed
3902
3903 \begin_layout Standard
3904 Don't delete any of the stray spaces in the table above without checking
3905  the HTML output (last line)!
3906 \end_layout
3907
3908 \end_inset
3909
3910
3911 \end_layout
3912
3913 \begin_layout Standard
3914 \InsetSpace ~
3915
3916 \newline
3917 The option -
3918 \begin_inset ERT
3919 status collapsed
3920
3921 \begin_layout Standard
3922
3923
3924 \backslash
3925 /
3926 \end_layout
3927
3928 \end_inset
3929
3930 -nostdlib disables the last two search paths.
3931 \end_layout
3932
3933 \begin_layout Section
3934 Building SDCC
3935 \begin_inset LatexCommand \index{Building SDCC}
3936
3937 \end_inset
3938
3939
3940 \end_layout
3941
3942 \begin_layout Subsection
3943 Building SDCC on Linux
3944 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3945
3946 \end_inset
3947
3948
3949 \end_layout
3950
3951 \begin_layout Enumerate
3952
3953 \series medium
3954 Download the source package
3955 \series default
3956  either from the SDCC Subversion repository or from snapshot builds
3957 \series medium
3958 , it will be named something like sdcc
3959 \series default
3960 -src
3961 \series medium
3962 -yyyymmdd-rrrr.t
3963 \series default
3964 ar.
3965 \series medium
3966 bz2
3967 \series default
3968  
3969 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3970
3971 \end_inset
3972
3973 .
3974 \end_layout
3975
3976 \begin_layout Enumerate
3977
3978 \series medium
3979 Bring up a command line terminal, such as xterm.
3980 \end_layout
3981
3982 \begin_layout Enumerate
3983
3984 \series medium
3985 Unpack the file using a command like: 
3986 \family sans
3987 \series bold
3988 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3989 \begin_inset Quotes srd
3990 \end_inset
3991
3992
3993 \family default
3994 \series medium
3995 , this will create a sub-directory called sdcc with all of the sources.
3996 \end_layout
3997
3998 \begin_layout Enumerate
3999 Change directory into the main SDCC directory, for example type: 
4000 \family sans
4001 \series bold
4002 "cd sdcc
4003 \series default
4004 ".
4005 \end_layout
4006
4007 \begin_layout Enumerate
4008
4009 \series medium
4010 Type 
4011 \family sans
4012 \series bold
4013 "./configure
4014 \family default
4015 \series default
4016 ".
4017  This configures the package for compilation on your system.
4018 \end_layout
4019
4020 \begin_layout Enumerate
4021
4022 \series medium
4023 Type 
4024 \family sans
4025 \series bold
4026 "make
4027 \family default
4028 \series default
4029 "
4030 \series medium
4031 .
4032
4033 \series default
4034  All of the source packages will compile, this can take a while.
4035 \end_layout
4036
4037 \begin_layout Enumerate
4038
4039 \series medium
4040 Type 
4041 \family sans
4042 \series bold
4043 "make install"
4044 \family default
4045 \series default
4046  as root
4047 \series medium
4048 .
4049
4050 \series default
4051  This copies the binary executables, the include files, the libraries and
4052  the documentation to the install directories.
4053  Proceed with section 
4054 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4055
4056 \end_inset
4057
4058 .
4059 \end_layout
4060
4061 \begin_layout Subsection
4062 Building SDCC on Mac OS X
4063 \end_layout
4064
4065 \begin_layout Standard
4066 Follow the instruction for Linux.
4067 \newline
4068
4069 \newline
4070 On Mac OS X 10.2.x it was reported, that the
4071  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4072  Fortunately there's also gcc 2.9.x installed, which works fine.
4073  This compiler can be selected by running 'configure' with:
4074 \end_layout
4075
4076 \begin_layout LyX-Code
4077 ./configure CC=gcc2 CXX=g++2
4078 \end_layout
4079
4080 \begin_layout Standard
4081 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4082  Xcode.
4083  Run 'configure' with:
4084 \end_layout
4085
4086 \begin_layout LyX-Code
4087 ./configure 
4088 \backslash
4089
4090 \end_layout
4091
4092 \begin_layout LyX-Code
4093 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4094  ppc" 
4095 \backslash
4096
4097 \end_layout
4098
4099 \begin_layout LyX-Code
4100 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4101  ppc" 
4102 \backslash
4103
4104 \end_layout
4105
4106 \begin_layout LyX-Code
4107 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4108 \end_layout
4109
4110 \begin_layout Subsection
4111 Cross compiling SDCC on Linux for Windows
4112 \end_layout
4113
4114 \begin_layout Standard
4115 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4116  See section 'Configure Options'.
4117 \end_layout
4118
4119 \begin_layout Subsection
4120 Building SDCC using Cygwin and Mingw32
4121 \end_layout
4122
4123 \begin_layout Standard
4124 For building and installing a Cygwin executable follow the instructions
4125  for Linux.
4126 \newline
4127
4128 \newline
4129 On Cygwin a 
4130 \begin_inset Quotes sld
4131 \end_inset
4132
4133 native
4134 \begin_inset Quotes srd
4135 \end_inset
4136
4137  Win32-binary can be built, which will not need the Cygwin-DLL.
4138  For the necessary 'configure' options see section 'configure options' or
4139  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4140 \newline
4141
4142 \newline
4143 In order to install
4144  Cygwin on Windows download setup.exe from 
4145 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4146
4147 \end_inset
4148
4149 .
4150  Run it, set the 
4151 \begin_inset Quotes sld
4152 \end_inset
4153
4154 default text file type
4155 \begin_inset Quotes srd
4156 \end_inset
4157
4158  to 
4159 \begin_inset Quotes sld
4160 \end_inset
4161
4162 unix
4163 \begin_inset Quotes srd
4164 \end_inset
4165
4166  and download/install at least the following packages.
4167  Some packages are selected by default, others will be automatically selected
4168  because of dependencies with the manually selected packages.
4169  Never deselect these packages!
4170 \end_layout
4171
4172 \begin_layout Itemize
4173 flex
4174 \end_layout
4175
4176 \begin_layout Itemize
4177 bison
4178 \end_layout
4179
4180 \begin_layout Itemize
4181 gcc ; version 3.x is fine, no need to use the old 2.9x
4182 \end_layout
4183
4184 \begin_layout Itemize
4185 binutils ; selected with gcc
4186 \end_layout
4187
4188 \begin_layout Itemize
4189 make
4190 \end_layout
4191
4192 \begin_layout Itemize
4193 rxvt ; a nice console, which makes life much easier under windoze (see below)
4194 \end_layout
4195
4196 \begin_layout Itemize
4197 man ; not really needed for building SDCC, but you'll miss it sooner or
4198  later
4199 \end_layout
4200
4201 \begin_layout Itemize
4202 less ; not really needed for building SDCC, but you'll miss it sooner or
4203  later
4204 \end_layout
4205
4206 \begin_layout Itemize
4207 svn ; only if you use Subversion access
4208 \end_layout
4209
4210 \begin_layout Standard
4211 If you want to develop something you'll need:
4212 \end_layout
4213
4214 \begin_layout Itemize
4215 python ; for the regression tests
4216 \end_layout
4217
4218 \begin_layout Itemize
4219 gdb ; the gnu debugger, together with the nice GUI 
4220 \begin_inset Quotes sld
4221 \end_inset
4222
4223 insight
4224 \begin_inset Quotes srd
4225 \end_inset
4226
4227
4228 \end_layout
4229
4230 \begin_layout Itemize
4231 openssh ; to access the CF or commit changes
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4236  use autoconf-stable!
4237 \end_layout
4238
4239 \begin_layout Standard
4240 rxvt is a nice console with history.
4241  Replace in your cygwin.bat the line
4242 \end_layout
4243
4244 \begin_layout LyX-Code
4245 bash -
4246 \begin_inset ERT
4247 status collapsed
4248
4249 \begin_layout Standard
4250
4251
4252 \backslash
4253 /
4254 \end_layout
4255
4256 \end_inset
4257
4258 -login -i 
4259 \end_layout
4260
4261 \begin_layout Standard
4262 with (one line):
4263 \end_layout
4264
4265 \begin_layout LyX-Code
4266 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4267 \end_layout
4268
4269 \begin_layout LyX-Code
4270      -bg black -fg white -geometry 100x65 -e bash -
4271 \begin_inset ERT
4272 status collapsed
4273
4274 \begin_layout Standard
4275
4276
4277 \backslash
4278 /
4279 \end_layout
4280
4281 \end_inset
4282
4283 -login
4284 \end_layout
4285
4286 \begin_layout Standard
4287 Text selected with the mouse is automatically copied to the clipboard, pasting
4288  works with shift-insert.
4289 \newline
4290
4291 \newline
4292 The other good tip is to make sure you have no //c/-styl
4293 e paths anywhere, use /cygdrive/c/ instead.
4294  Using // invokes a network lookup which is very slow.
4295  If you think 
4296 \begin_inset Quotes sld
4297 \end_inset
4298
4299 cygdrive
4300 \begin_inset Quotes srd
4301 \end_inset
4302
4303  is too long, you can change it with e.g.
4304 \end_layout
4305
4306 \begin_layout LyX-Code
4307 mount -s -u -c /mnt
4308 \end_layout
4309
4310 \begin_layout Standard
4311 SDCC sources use the unix line ending LF.
4312  Life is much easier, if you store the source tree on a drive which is mounted
4313  in binary mode.
4314  And use an editor which can handle LF-only line endings.
4315  Make sure not to commit files with windows line endings.
4316  The tabulator spacing
4317 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4318
4319 \end_inset
4320
4321  used in the project is 8.
4322  Although a tabulator spacing of 8 is a sensible choice for programmers
4323  (it's a power of 2 and allows to display 8/16 bit signed variables without
4324  loosing columns) the plan is to move towards using only spaces in the source.
4325 \end_layout
4326
4327 \begin_layout Subsection
4328 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4329 \end_layout
4330
4331 \begin_layout Standard
4332
4333 \series medium
4334 Download the source package
4335 \series default
4336  either from the SDCC Subversion repository or from the 
4337 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4338
4339 \end_inset
4340
4341
4342 \series medium
4343 , it will be named something like sdcc
4344 \series default
4345 -src
4346 \series medium
4347 -yyyymmdd-rrrr.tar.bz2.
4348
4349 \series default
4350  SDCC is distributed with all the projects, workspaces, and files you need
4351  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4352  The workspace name is 'sdcc.dsw'.
4353  Please note that as it is now, all the executables are created in a folder
4354  called sdcc
4355 \backslash
4356 bin_vc.
4357  Once built you need to copy the executables from sdcc
4358 \backslash
4359 bin_vc to sdcc
4360 \backslash
4361 bin before running SDCC.
4362  
4363 \newline
4364
4365 \newline
4366 WARNING: Visual studio is very picky with line terminations; it expects
4367  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4368  When using the Subversion repository it's easiest to configure the svn
4369  client to convert automatically for you.
4370  If however you are getting a message such as "This makefile was not generated
4371  by Developer Studio etc.
4372  etc.
4373 \begin_inset Quotes srd
4374 \end_inset
4375
4376  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4377  need to convert the Unix style line endings to DOS style line endings.
4378  To do so you can use the 
4379 \begin_inset Quotes sld
4380 \end_inset
4381
4382 unix2dos
4383 \begin_inset Quotes srd
4384 \end_inset
4385
4386  utility freely available on the internet.
4387  Doug Hawkins reported in the sdcc-user list that this works:
4388 \newline
4389
4390 \newline
4391 C:
4392 \backslash
4393 Programming
4394 \backslash
4395 SDCC> unix2dos sdcc.dsw
4396 \newline
4397 C:
4398 \backslash
4399 Programming
4400 \backslash
4401 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4402 \newline
4403
4404 \newline
4405 In order to build SDCC with MSVC
4406  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4407  One good place to get them is 
4408 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4409
4410 \end_inset
4411
4412
4413 \newline
4414
4415 \newline
4416 Download the file UnxUtils
4417 \begin_inset LatexCommand \index{UnxUtils}
4418
4419 \end_inset
4420
4421 .zip.
4422  Now you have to install the utilities and setup MSVC so it can locate the
4423  required programs.
4424  Here there are two alternatives (choose one!):
4425 \end_layout
4426
4427 \begin_layout Enumerate
4428 The easy way:
4429 \newline
4430
4431 \newline
4432 a) Extract UnxUtils.zip to your C:
4433 \backslash
4434  hard disk PRESERVING the original paths, otherwise bison won't work.
4435  (If you are using WinZip make certain that 'Use folder names' is selected)
4436 \newline
4437
4438 \newline
4439 b)
4440  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4441  'Show directories for:' select 'Executable files', and in the directories
4442  window add a new path: 'C:
4443 \backslash
4444 user
4445 \backslash
4446 local
4447 \backslash
4448 wbin', click ok.
4449 \newline
4450
4451 \newline
4452 (As a side effect, you get a bunch of Unix utilities that
4453  could be useful, such as diff and patch.)
4454 \end_layout
4455
4456 \begin_layout Enumerate
4457 A more compact way:
4458 \newline
4459
4460 \newline
4461 This one avoids extracting a bunch of files you may not
4462  use, but requires some extra work:
4463 \newline
4464
4465 \newline
4466 a) Create a directory were to put the
4467  tools needed, or use a directory already present.
4468  Say for example 'C:
4469 \backslash
4470 util'.
4471 \newline
4472
4473 \newline
4474 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4475  gawk.exe to such directory WITHOUT preserving the original paths.
4476  (If you are using WinZip make certain that 'Use folder names' is not selected)
4477 \newline
4478
4479 \newline
4480 c
4481 ) Rename bison.exe to '_bison.exe'.
4482 \newline
4483
4484 \newline
4485 d) Create a batch file 'bison.bat' in 'C:
4486 \backslash
4487 util
4488 \backslash
4489 ' and add these lines: 
4490 \newline
4491 \InsetSpace ~
4492 \InsetSpace ~
4493 set BISON_SIMPLE=C:
4494 \backslash
4495 util
4496 \backslash
4497 bison.simple 
4498 \newline
4499 \InsetSpace ~
4500 \InsetSpace ~
4501 set BISON_HAIRY=C:
4502 \backslash
4503 util
4504 \backslash
4505 bison.hairy
4506 \newline
4507 \InsetSpace ~
4508 \InsetSpace ~
4509 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4510 \newline
4511
4512 \newline
4513 Steps 'c' and 'd' are needed
4514  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4515  reside in some weird Unix directory, '/usr/local/share/' I think.
4516  So it is necessary to tell bison where those files are located if they
4517  are not in such directory.
4518  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4519 \newline
4520
4521 \newline
4522 e
4523 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4524  in 'Show directories for:' select 'Executable files', and in the directories
4525  window add a new path: 'c:
4526 \backslash
4527 util', click ok.
4528  Note that you can use any other path instead of 'c:
4529 \backslash
4530 util', even the path where the Visual C++ tools are, probably: 'C:
4531 \backslash
4532 Program Files
4533 \backslash
4534 Microsoft Visual Studio
4535 \backslash
4536 Common
4537 \backslash
4538 Tools'.
4539  So you don't have to execute step 'e' :)
4540 \end_layout
4541
4542 \begin_layout Standard
4543 That is it.
4544  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4545  the executables from sdcc
4546 \backslash
4547 bin_vc to sdcc
4548 \backslash
4549 bin, and you can compile using SDCC.
4550 \end_layout
4551
4552 \begin_layout Subsection
4553 Building SDCC Using Borland
4554 \end_layout
4555
4556 \begin_layout Enumerate
4557 From the sdcc directory, run the command "make -f Makefile.bcc".
4558  This should regenerate all the .exe files in the bin directory except for
4559  SDCDB and ucSim.
4560 \end_layout
4561
4562 \begin_layout Enumerate
4563 If you modify any source files and need to rebuild, be aware that the dependenci
4564 es may not be correctly calculated.
4565  The safest option is to delete all .obj files and run the build again.
4566  From a Cygwin BASH prompt, this can easily be done with the command (be
4567  sure you are in the sdcc directory):
4568 \newline
4569
4570 \newline
4571
4572 \family sans
4573 \series bold
4574 find .
4575  
4576 \backslash
4577 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4578 \backslash
4579 ) -print -exec rm {} 
4580 \backslash
4581 ;
4582 \family default
4583 \series default
4584
4585 \newline
4586
4587 \newline
4588 or on Windows NT/2000/XP from the command prompt with the command:
4589 \newline
4590
4591 \family sans
4592 \series bold
4593
4594 \newline
4595 del /s *.obj *.lib *.rul
4596 \family default
4597 \series default
4598  from the sdcc directory.
4599 \end_layout
4600
4601 \begin_layout Subsection
4602 Windows Install Using a ZIP Package
4603 \end_layout
4604
4605 \begin_layout Enumerate
4606 Download the binary zip package from 
4607 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4608
4609 \end_inset
4610
4611  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4612  This should unpack to a group of sub-directories.
4613  An example directory structure after unpacking the mingw32 package is:
4614  c:
4615 \backslash
4616 sdcc
4617 \backslash
4618 bin for the executables, c:
4619 \backslash
4620 sdcc
4621 \backslash
4622 include and c:
4623 \backslash
4624 sdcc
4625 \backslash
4626 lib for the include and libraries.
4627 \end_layout
4628
4629 \begin_layout Enumerate
4630 Adjust your environment variable PATH to include the location of the bin
4631  directory or start sdcc using the full path.
4632 \end_layout
4633
4634 \begin_layout Subsection
4635 Windows Install Using the Setup Program
4636 \begin_inset LatexCommand \label{sub:Windows-Install}
4637
4638 \end_inset
4639
4640
4641 \end_layout
4642
4643 \begin_layout Standard
4644 Download the setup program 
4645 \emph on
4646 sdcc-x.y.z-setup.exe
4647 \emph default
4648  for an official release from 
4649 \newline
4650
4651 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4652
4653 \end_inset
4654
4655  or a setup program for one of the snapshots 
4656 \emph on
4657 sdcc-yyyymmdd-xxxx-setup.exe
4658 \emph default
4659  from 
4660 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4661
4662 \end_inset
4663
4664  and execute it.
4665  A windows typical installer will guide you through the installation process.
4666 \end_layout
4667
4668 \begin_layout Subsection
4669 VPATH
4670 \begin_inset LatexCommand \index{VPATH}
4671
4672 \end_inset
4673
4674  feature
4675 \end_layout
4676
4677 \begin_layout Standard
4678 SDCC supports the VPATH feature provided by configure and make.
4679  It allows to separate the source and build trees.
4680  Here's an example:
4681 \end_layout
4682
4683 \begin_layout Standard
4684
4685 \family typewriter
4686 cd ~\InsetSpace ~
4687 \InsetSpace ~
4688 \InsetSpace ~
4689 \InsetSpace ~
4690 \InsetSpace ~
4691 \InsetSpace ~
4692 \InsetSpace ~
4693 \InsetSpace ~
4694 \InsetSpace ~
4695 \InsetSpace ~
4696 \InsetSpace ~
4697 \InsetSpace ~
4698 \InsetSpace ~
4699 \InsetSpace ~
4700 \InsetSpace ~
4701 \InsetSpace ~
4702 \InsetSpace ~
4703 \InsetSpace ~
4704 \InsetSpace ~
4705 \InsetSpace ~
4706 \InsetSpace ~
4707 # cd $HOME
4708 \end_layout
4709
4710 \begin_layout Standard
4711
4712 \family typewriter
4713 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4714 # extract source to directory sdcc
4715 \end_layout
4716
4717 \begin_layout Standard
4718
4719 \family typewriter
4720 mkdir sdcc.build\InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 # put output in sdcc.build
4730 \end_layout
4731
4732 \begin_layout Standard
4733
4734 \family typewriter
4735 cd sdcc.build
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 ../sdcc/configure\InsetSpace ~
4742 \InsetSpace ~
4743 \InsetSpace ~
4744 \InsetSpace ~
4745 \InsetSpace ~
4746 \InsetSpace ~
4747 \InsetSpace ~
4748 \InsetSpace ~
4749 # configure is doing all the magic!
4750 \end_layout
4751
4752 \begin_layout Standard
4753
4754 \family typewriter
4755 make
4756 \end_layout
4757
4758 \begin_layout Standard
4759 \noindent
4760 That's it! 
4761 \series bold
4762 configure
4763 \series default
4764  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4765  It automagically computes the variables srcdir, top_srcdir and top_buildir
4766  for each directory.
4767  After running 
4768 \series bold
4769 make
4770 \series default
4771  the generated files will be in ~/sdcc.build, while the source files stay
4772  in ~/sdcc.
4773 \newline
4774 This is not only usefull for building different binaries, e.g.
4775  when cross compiling.
4776  It also gives you a much better overview in the source tree when all the
4777  generated files are not scattered between the source files.
4778  And the best thing is: if you want to change a file you can leave the original
4779  file untouched in the source directory.
4780  Simply copy it to the build directory, edit it, enter `make clean', `rm
4781  Makefile.dep' and `make'.
4782  
4783 \series bold
4784 make
4785 \series default
4786  will do the rest for you!
4787 \end_layout
4788
4789 \begin_layout Section
4790 Building the Documentation
4791 \end_layout
4792
4793 \begin_layout Standard
4794 Add -
4795 \begin_inset ERT
4796 status collapsed
4797
4798 \begin_layout Standard
4799
4800
4801 \backslash
4802 /
4803 \end_layout
4804
4805 \end_inset
4806
4807 -enable-doc to the configure arguments to build the documentation together
4808  with all the other stuff.
4809  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4810  dvips and makeindex) to get the job done.
4811  Another possibility is to change to the doc directory and to type 
4812 \family sans
4813 \series bold
4814
4815 \begin_inset Quotes srd
4816 \end_inset
4817
4818 make
4819 \begin_inset Quotes srd
4820 \end_inset
4821
4822
4823 \family default
4824 \series default
4825  there.
4826  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4827 x).
4828  Using LyX 
4829 \begin_inset LatexCommand \url{http://www.lyx.org}
4830
4831 \end_inset
4832
4833  as editor is straightforward.
4834  Prebuilt documentation in html and pdf format is available from 
4835 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4836
4837 \end_inset
4838
4839 .
4840 \end_layout
4841
4842 \begin_layout Section
4843 Reading the Documentation
4844 \begin_inset LatexCommand \index{Documentation}
4845
4846 \end_inset
4847
4848
4849 \end_layout
4850
4851 \begin_layout Standard
4852 Currently reading the document in pdf format is recommended, as for unknown
4853  reason the hyperlinks are working there whereas in the html version they
4854  are not
4855 \begin_inset Foot
4856 status open
4857
4858 \begin_layout Standard
4859 If you should know why please drop us a note
4860 \end_layout
4861
4862 \end_inset
4863
4864 .
4865  
4866 \newline
4867 You'll find the pdf version
4868 \begin_inset LatexCommand \index{PDF version of this document}
4869
4870 \end_inset
4871
4872  at 
4873 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4874
4875 \end_inset
4876
4877 .
4878  
4879 \newline
4880 A html version
4881 \begin_inset LatexCommand \index{HTML version of this document}
4882
4883 \end_inset
4884
4885  should be online at 
4886 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4887
4888 \end_inset
4889
4890 .
4891 \newline
4892 This documentation is in some aspects different from a commercial documentation:
4893  
4894 \end_layout
4895
4896 \begin_layout Itemize
4897 It tries to document SDCC for several processor architectures in one document
4898  (commercially these probably would be separate documents/products).
4899  This document
4900 \begin_inset LatexCommand \index{Status of documentation}
4901
4902 \end_inset
4903
4904  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4905 on about f.e.
4906  Z80, PIC14, PIC16 and HC08.
4907 \end_layout
4908
4909 \begin_layout Itemize
4910 There are many references pointing away from this documentation.
4911  Don't let this distract you.
4912  If there f.e.
4913  was a reference like 
4914 \begin_inset LatexCommand \url{http://www.opencores.org}
4915
4916 \end_inset
4917
4918  together with a statement 
4919 \begin_inset Quotes sld
4920 \end_inset
4921
4922 some processors which are targetted by SDCC can be implemented in a 
4923 \emph on
4924 f
4925 \emph default
4926 ield 
4927 \emph on
4928 p
4929 \emph default
4930 rogrammable 
4931 \emph on
4932 g
4933 \emph default
4934 ate 
4935 \emph on
4936 a
4937 \emph default
4938 rray
4939 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4940
4941 \end_inset
4942
4943
4944 \begin_inset Quotes srd
4945 \end_inset
4946
4947  or 
4948 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4949
4950 \end_inset
4951
4952
4953 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4954
4955 \end_inset
4956
4957  
4958 \begin_inset Quotes sld
4959 \end_inset
4960
4961 have you ever heard of an open source compiler that compiles a subset of
4962  C for an FPGA?
4963 \begin_inset Quotes srd
4964 \end_inset
4965
4966  we expect you to have a quick look there and come back.
4967  If you read this you are on the right track.
4968 \end_layout
4969
4970 \begin_layout Itemize
4971 Some sections attribute more space to problems, restrictions and warnings
4972  than to the solution.
4973 \end_layout
4974
4975 \begin_layout Itemize
4976 The installation section and the section about the debugger is intimidating.
4977 \end_layout
4978
4979 \begin_layout Itemize
4980 There are still lots of typos and there are more different writing styles
4981  than pictures.
4982 \end_layout
4983
4984 \begin_layout Section
4985 Testing the SDCC Compiler
4986 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4987
4988 \end_inset
4989
4990
4991 \end_layout
4992
4993 \begin_layout Standard
4994 The first thing you should do after installing your SDCC compiler is to
4995  see if it runs.
4996  Type 
4997 \family sans
4998 \series bold
4999 "sdcc -
5000 \begin_inset ERT
5001 status collapsed
5002
5003 \begin_layout Standard
5004
5005
5006 \backslash
5007 /
5008 \end_layout
5009
5010 \end_inset
5011
5012 -version"
5013 \begin_inset LatexCommand \index{version}
5014
5015 \end_inset
5016
5017
5018 \family default
5019 \series default
5020  at the prompt, and the program should run and output its version like:
5021  
5022 \newline
5023
5024 \family typewriter
5025 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5026  (UNIX)
5027 \end_layout
5028
5029 \begin_layout Standard
5030 If it doesn't run, or gives a message about not finding sdcc program, then
5031  you need to check over your installation.
5032  Make sure that the sdcc bin directory is in your executable search path
5033  defined by the PATH environment setting (
5034 \series medium
5035 see 
5036 \series default
5037 section 
5038 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5039
5040 \end_inset
5041
5042 \InsetSpace ~
5043
5044 \series medium
5045 Install trouble-shooting for suggestions
5046 \series default
5047 ).
5048  Make sure that the sdcc program is in the bin folder, if not perhaps something
5049  did not install correctly.
5050 \newline
5051
5052 \newline
5053
5054 \series medium
5055 SDCC 
5056 \series default
5057 is commonly installed as described in section 
5058 \begin_inset Quotes sld
5059 \end_inset
5060
5061 Install and search paths
5062 \begin_inset Quotes srd
5063 \end_inset
5064
5065 .
5066 \newline
5067
5068 \newline
5069
5070 \series medium
5071 Make sure the compiler works on a very simple example.
5072  Type in the following test.c program using your favorite 
5073 \series default
5074 ASCII 
5075 \series medium
5076 editor:
5077 \end_layout
5078
5079 \begin_layout Verse
5080
5081 \family typewriter
5082 char test;
5083 \newline
5084
5085 \newline
5086 void main(void) {
5087 \newline
5088 \InsetSpace ~
5089 \InsetSpace ~
5090 \InsetSpace ~
5091 \InsetSpace ~
5092 test=0;
5093 \newline
5094 }
5095 \end_layout
5096
5097 \begin_layout Standard
5098
5099 \series medium
5100 Compile this using the following command: 
5101 \family sans
5102 \series bold
5103 "sdcc -c test.c".
5104
5105 \family default
5106 \series default
5107  
5108 \series medium
5109 If all goes well, the compiler will generate a test.asm and test.rel file.
5110  Congratulations, you've just compiled your first program with SDCC.
5111  We used the -c option to tell SDCC not to link the generated code, just
5112  to keep things simple for this step.
5113 \series default
5114
5115 \newline
5116
5117 \newline
5118
5119 \series medium
5120 The next step is to try it with the linker.
5121  Type in 
5122 \family sans
5123 \series bold
5124 "sdcc test.c
5125 \family default
5126 \series default
5127 "
5128 \series medium
5129 .
5130  If all goes well the compiler will link with the libraries and produce
5131  a test.ihx output file.
5132  If this step fails
5133 \series default
5134  
5135 \series medium
5136 (no test.ihx, and the linker generates warnings), then the problem is most
5137  likely that 
5138 \series default
5139 SDCC
5140 \series medium
5141  cannot find the 
5142 \series default
5143 /
5144 \series medium
5145 usr/local/share/sdcc/lib directory
5146 \series default
5147  
5148 \series medium
5149 (see 
5150 \series default
5151 section 
5152 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5153
5154 \end_inset
5155
5156 \InsetSpace ~
5157
5158 \series medium
5159 Install trouble-shooting for suggestions).
5160 \series default
5161
5162 \newline
5163
5164 \newline
5165
5166 \series medium
5167 The final test is to ensure 
5168 \series default
5169 SDCC
5170 \series medium
5171  can use the 
5172 \series default
5173 standard
5174 \series medium
5175  header files and libraries.
5176  Edit test.c and change it to the following:
5177 \end_layout
5178
5179 \begin_layout Verse
5180
5181 \family typewriter
5182 #include <string.h>
5183 \newline
5184
5185 \newline
5186 char str1[10];
5187 \newline
5188
5189 \newline
5190 void main(void) {
5191 \newline
5192 \InsetSpace ~
5193 \InsetSpace ~
5194 strcpy(str1, "testing");
5195 \newline
5196 }
5197 \end_layout
5198
5199 \begin_layout Standard
5200
5201 \series medium
5202 Compile this by typing 
5203 \family sans
5204 \series bold
5205 "sdcc test.c"
5206 \family default
5207 \series medium
5208 .
5209  This should generate a test.ihx output file, and it should give no warnings
5210  such as not finding the string.h file.
5211  If it cannot find the string.h file, then the problem is that 
5212 \series default
5213 SDCC
5214 \series medium
5215  cannot find the /usr/local/share/sdcc/include directory
5216 \series default
5217  
5218 \series medium
5219 (see the 
5220 \series default
5221 section 
5222 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5223
5224 \end_inset
5225
5226 \InsetSpace ~
5227
5228 \series medium
5229 Install trouble-shooting section for suggestions).
5230
5231 \series default
5232  Use option 
5233 \series bold
5234 -
5235 \begin_inset ERT
5236 status collapsed
5237
5238 \begin_layout Standard
5239
5240
5241 \backslash
5242 /
5243 \end_layout
5244
5245 \end_inset
5246
5247 -print-search-dirs
5248 \series default
5249
5250 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5251
5252 \end_inset
5253
5254  to find exactly where SDCC is looking for the include and lib files.
5255 \end_layout
5256
5257 \begin_layout Section
5258 Install Trouble-shooting
5259 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5260
5261 \end_inset
5262
5263
5264 \begin_inset LatexCommand \index{Install trouble-shooting}
5265
5266 \end_inset
5267
5268
5269 \end_layout
5270
5271 \begin_layout Subsection
5272 If SDCC does not build correctly
5273 \end_layout
5274
5275 \begin_layout Standard
5276 A thing to try is starting from scratch by unpacking the .tgz source package
5277  again in an empty directory.
5278  Configure it like:
5279 \newline
5280
5281 \newline
5282
5283 \family sans
5284 \series bold
5285 ./configure 2>&1 | tee configure.log
5286 \family default
5287 \series default
5288
5289 \newline
5290
5291 \newline
5292 and build it like:
5293 \newline
5294
5295 \newline
5296
5297 \family sans
5298 \series bold
5299 make 2>&1 | tee make.log
5300 \family default
5301 \series default
5302
5303 \newline
5304
5305 \newline
5306 If anything goes wrong, you can review the log files to locate the problem.
5307  Or a relevant part of this can be attached to an email that could be helpful
5308  when requesting help from the mailing list.
5309 \end_layout
5310
5311 \begin_layout Subsection
5312 What the 
5313 \begin_inset Quotes sld
5314 \end_inset
5315
5316 ./configure
5317 \begin_inset Quotes srd
5318 \end_inset
5319
5320  does
5321 \end_layout
5322
5323 \begin_layout Standard
5324 The 
5325 \begin_inset Quotes sld
5326 \end_inset
5327
5328 ./configure
5329 \begin_inset Quotes srd
5330 \end_inset
5331
5332  command is a script that analyzes your system and performs some configuration
5333  to ensure the source package compiles on your system.
5334  It will take a few minutes to run, and will compile a few tests to determine
5335  what compiler features are installed.
5336 \end_layout
5337
5338 \begin_layout Subsection
5339 What the 
5340 \begin_inset Quotes sld
5341 \end_inset
5342
5343 make
5344 \begin_inset Quotes srd
5345 \end_inset
5346
5347  does
5348 \end_layout
5349
5350 \begin_layout Standard
5351 This runs the GNU make tool, which automatically compiles all the source
5352  packages into the final installed binary executables.
5353 \end_layout
5354
5355 \begin_layout Subsection
5356 What the 
5357 \begin_inset Quotes sld
5358 \end_inset
5359
5360 make install
5361 \begin_inset Quotes erd
5362 \end_inset
5363
5364  command does.
5365 \end_layout
5366
5367 \begin_layout Standard
5368 This will install the compiler, other executables libraries and include
5369  files into the appropriate directories.
5370  See sections 
5371 \begin_inset LatexCommand \ref{sub:Install-paths}
5372
5373 \end_inset
5374
5375 ,\InsetSpace ~
5376
5377 \begin_inset LatexCommand \ref{sub:Search-Paths}
5378
5379 \end_inset
5380
5381 \InsetSpace ~
5382 about install and search paths.
5383 \newline
5384 On most systems you will need super-user privilege
5385 s to do this.
5386 \end_layout
5387
5388 \begin_layout Section
5389 Components of SDCC
5390 \end_layout
5391
5392 \begin_layout Standard
5393 SDCC is not just a compiler, but a collection of tools by various developers.
5394  These include linkers, assemblers, simulators and other components.
5395  Here is a summary of some of the components.
5396  Note that the included simulator and assembler have separate documentation
5397  which you can find in the source package in their respective directories.
5398  As SDCC grows to include support for other processors, other packages from
5399  various developers are included and may have their own sets of documentation.
5400 \newline
5401
5402 \newline
5403 You
5404  might want to look at the files which are installed in <installdir>.
5405  At the time of this writing, we find the following programs for gcc-builds:
5406 \newline
5407
5408  
5409 \newline
5410 In <installdir>/bin:
5411 \end_layout
5412
5413 \begin_layout Itemize
5414 sdcc - The compiler.
5415 \end_layout
5416
5417 \begin_layout Itemize
5418 sdcpp - The C preprocessor.
5419 \end_layout
5420
5421 \begin_layout Itemize
5422 asx8051 - The assembler for 8051 type processors.
5423 \end_layout
5424
5425 \begin_layout Itemize
5426 as-z80
5427 \series bold
5428
5429 \series default
5430 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5431 \end_layout
5432
5433 \begin_layout Itemize
5434 aslink -The linker for 8051 type processors.
5435 \end_layout
5436
5437 \begin_layout Itemize
5438 link-z80
5439 \series bold
5440
5441 \series default
5442 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 s51 - The ucSim 8051 simulator.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 sdcdb - The source debugger.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 packihx - A tool to pack (compress) Intel hex files.
5455 \end_layout
5456
5457 \begin_layout Standard
5458 In <installdir>/share/sdcc/include
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 the include files
5463 \end_layout
5464
5465 \begin_layout Standard
5466 In <installdir>/share/sdcc/lib
5467 \end_layout
5468
5469 \begin_layout Itemize
5470 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5471  relocatables.
5472 \end_layout
5473
5474 \begin_layout Standard
5475 In <installdir>/share/sdcc/doc
5476 \end_layout
5477
5478 \begin_layout Itemize
5479 the documentation
5480 \end_layout
5481
5482 \begin_layout Standard
5483 As development for other processors proceeds, this list will expand to include
5484  executables to support processors like AVR, PIC, etc.
5485 \end_layout
5486
5487 \begin_layout Subsection
5488 sdcc - The Compiler
5489 \end_layout
5490
5491 \begin_layout Standard
5492 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5493  the assembler and linkage editor.
5494 \end_layout
5495
5496 \begin_layout Subsection
5497 sdcpp - The C-Preprocessor
5498 \end_layout
5499
5500 \begin_layout Standard
5501 The preprocessor
5502 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5503
5504 \end_inset
5505
5506  is a modified version of the GNU cpp
5507 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5508
5509 \end_inset
5510
5511  preprocessor 
5512 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5513
5514 \end_inset
5515
5516 .
5517  The C preprocessor is used to pull in #include sources, process #ifdef
5518  statements, #defines and so on.
5519 \end_layout
5520
5521 \begin_layout Subsection
5522 as
5523 \emph on
5524 xxxx
5525 \emph default
5526 , aslink, link-
5527 \emph on
5528 xxx
5529 \emph default
5530  - The Assemblers and Linkage Editors
5531 \end_layout
5532
5533 \begin_layout Standard
5534 This is retargettable assembler & linkage editor, it was developed by Alan
5535  Baldwin.
5536  John Hartman created the version for 8051, and I (Sandeep) have made some
5537  enhancements and bug fixes for it to work properly with SDCC.
5538 \end_layout
5539
5540 \begin_layout Subsection
5541 s51 - The Simulator
5542 \end_layout
5543
5544 \begin_layout Standard
5545 S51
5546 \begin_inset LatexCommand \index{s51}
5547
5548 \end_inset
5549
5550  is a free open source simulator developed by Daniel Drotos.
5551  The simulator is built as part of the build process.
5552  For more information visit Daniel's web site at: 
5553 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5554
5555 \end_inset
5556
5557 .
5558  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5559  XA51 family.
5560 \end_layout
5561
5562 \begin_layout Subsection
5563 sdcdb - Source Level Debugger
5564 \end_layout
5565
5566 \begin_layout Standard
5567 SDCDB
5568 \begin_inset LatexCommand \index{SDCDB (debugger)}
5569
5570 \end_inset
5571
5572  is the companion source level debugger.
5573  More about SDCDB in section 
5574 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5575
5576 \end_inset
5577
5578 .
5579  The current version of the debugger uses Daniel's Simulator S51
5580 \begin_inset LatexCommand \index{s51}
5581
5582 \end_inset
5583
5584 , but can be easily changed to use other simulators.
5585 \end_layout
5586
5587 \begin_layout Chapter
5588 Using SDCC
5589 \end_layout
5590
5591 \begin_layout Section
5592 Compiling
5593 \end_layout
5594
5595 \begin_layout Subsection
5596 Single Source File Projects
5597 \end_layout
5598
5599 \begin_layout Standard
5600 For single source file 8051 projects the process is very simple.
5601  Compile your programs with the following command 
5602 \family sans
5603 \series bold
5604 "sdcc sourcefile.c".
5605
5606 \family default
5607 \series default
5608  This will compile, assemble and link your source file.
5609  Output files are as follows:
5610 \end_layout
5611
5612 \begin_layout Itemize
5613 sourcefile.asm
5614 \begin_inset LatexCommand \index{<file>.asm}
5615
5616 \end_inset
5617
5618  - Assembler source
5619 \begin_inset LatexCommand \index{Assembler source}
5620
5621 \end_inset
5622
5623  file created by the compiler
5624 \end_layout
5625
5626 \begin_layout Itemize
5627 sourcefile.lst
5628 \begin_inset LatexCommand \index{<file>.lst}
5629
5630 \end_inset
5631
5632  - Assembler listing
5633 \begin_inset LatexCommand \index{Assembler listing}
5634
5635 \end_inset
5636
5637  file created by the Assembler
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.rst
5642 \begin_inset LatexCommand \index{<file>.rst}
5643
5644 \end_inset
5645
5646  - Assembler listing
5647 \begin_inset LatexCommand \index{Assembler listing}
5648
5649 \end_inset
5650
5651  file updated with linkedit information, created by linkage editor
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.sym
5656 \begin_inset LatexCommand \index{<file>.sym}
5657
5658 \end_inset
5659
5660  - symbol listing
5661 \begin_inset LatexCommand \index{Symbol listing}
5662
5663 \end_inset
5664
5665  for the sourcefile, created by the assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rel
5670 \begin_inset LatexCommand \index{<file>.rel}
5671
5672 \end_inset
5673
5674  or sourcefile.o
5675 \begin_inset LatexCommand \index{<file>.o}
5676
5677 \end_inset
5678
5679  - Object file
5680 \begin_inset LatexCommand \index{Object file}
5681
5682 \end_inset
5683
5684  created by the assembler, input to Linkage editor
5685 \end_layout
5686
5687 \begin_layout Itemize
5688 sourcefile.map
5689 \begin_inset LatexCommand \index{<file>.map}
5690
5691 \end_inset
5692
5693  - The memory map
5694 \begin_inset LatexCommand \index{Memory map}
5695
5696 \end_inset
5697
5698  for the load module, created by the Linker
5699 \end_layout
5700
5701 \begin_layout Itemize
5702 sourcefile.mem
5703 \begin_inset LatexCommand \index{<file>.mem}
5704
5705 \end_inset
5706
5707  - A file with a summary of the memory usage
5708 \end_layout
5709
5710 \begin_layout Itemize
5711 sourcefile.ihx
5712 \begin_inset LatexCommand \index{<file>.ihx}
5713
5714 \end_inset
5715
5716  - The load module in Intel hex format
5717 \begin_inset LatexCommand \index{Intel hex format}
5718
5719 \end_inset
5720
5721  (you can select the Motorola S19 format
5722 \begin_inset LatexCommand \index{Motorola S19 format}
5723
5724 \end_inset
5725
5726  with -
5727 \begin_inset ERT
5728 status collapsed
5729
5730 \begin_layout Standard
5731
5732
5733 \backslash
5734 /
5735 \end_layout
5736
5737 \end_inset
5738
5739 -out-fmt-s19
5740 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5741
5742 \end_inset
5743
5744 .
5745  If you need another format you might want to use 
5746 \family sans
5747 \shape italic
5748 objdump
5749 \family default
5750 \shape default
5751
5752 \begin_inset LatexCommand \index{objdump (tool)}
5753
5754 \end_inset
5755
5756  or
5757 \family sans
5758 \shape italic
5759  srecord
5760 \family default
5761 \shape default
5762
5763 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5764
5765 \end_inset
5766
5767
5768 \begin_inset Note Note
5769 status collapsed
5770
5771 \begin_layout Standard
5772 hyperlinks needed
5773 \end_layout
5774
5775 \end_inset
5776
5777  - see also section 
5778 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5779
5780 \end_inset
5781
5782 ).
5783  Both formats are documented in the documentation of srecord
5784 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5785
5786 \end_inset
5787
5788
5789 \end_layout
5790
5791 \begin_layout Itemize
5792 sourcefile.adb
5793 \begin_inset LatexCommand \index{<file>.adb}
5794
5795 \end_inset
5796
5797  - An intermediate file containing debug information needed to create the
5798  .cdb file (with -
5799 \begin_inset ERT
5800 status collapsed
5801
5802 \begin_layout Standard
5803
5804
5805 \backslash
5806 /
5807 \end_layout
5808
5809 \end_inset
5810
5811 -debug
5812 \begin_inset LatexCommand \index{-\/-debug}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.cdb
5821 \begin_inset LatexCommand \index{<file>.cdb}
5822
5823 \end_inset
5824
5825  - An optional file (with -
5826 \begin_inset ERT
5827 status collapsed
5828
5829 \begin_layout Standard
5830
5831
5832 \backslash
5833 /
5834 \end_layout
5835
5836 \end_inset
5837
5838 -debug) containing debug information.
5839  The format is documented in cdbfileformat.pdf
5840 \end_layout
5841
5842 \begin_layout Itemize
5843 sourcefile.
5844  - (no extension)
5845 \begin_inset LatexCommand \index{<file> (no extension)}
5846
5847 \end_inset
5848
5849  An optional AOMF or AOMF51
5850 \begin_inset LatexCommand \index{AOMF, AOMF51}
5851
5852 \end_inset
5853
5854  
5855 \begin_inset LatexCommand \label{OMF file}
5856
5857 \end_inset
5858
5859 file containing debug information (generated with option -
5860 \begin_inset ERT
5861 status collapsed
5862
5863 \begin_layout Standard
5864
5865
5866 \backslash
5867 /
5868 \end_layout
5869
5870 \end_inset
5871
5872 -debug).
5873  The (Intel)
5874 \emph on
5875  a
5876 \emph default
5877 bsolute 
5878 \emph on
5879 o
5880 \emph default
5881 bject 
5882 \emph on
5883 m
5884 \emph default
5885 odule 
5886 \emph on
5887 f
5888 \emph default
5889 ormat is a subformat of the OMF51 format and is commonly used by third party
5890  tools (debuggers
5891 \begin_inset LatexCommand \index{Debugger}
5892
5893 \end_inset
5894
5895 , simulators, emulators).
5896 \end_layout
5897
5898 \begin_layout Itemize
5899 sourcefile.dump*
5900 \begin_inset LatexCommand \index{<file>.dump*}
5901
5902 \end_inset
5903
5904  - Dump file to debug the compiler it self (generated with option -
5905 \begin_inset ERT
5906 status collapsed
5907
5908 \begin_layout Standard
5909
5910
5911 \backslash
5912 /
5913 \end_layout
5914
5915 \end_inset
5916
5917 -dumpall) (see section 
5918 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5919
5920 \end_inset
5921
5922 \InsetSpace ~
5923  and section 
5924 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5925
5926 \end_inset
5927
5928 \InsetSpace ~
5929
5930 \begin_inset Quotes sld
5931 \end_inset
5932
5933 Anatomy of the compiler
5934 \begin_inset Quotes srd
5935 \end_inset
5936
5937 ).
5938 \end_layout
5939
5940 \begin_layout Subsection
5941 Postprocessing the Intel Hex
5942 \begin_inset LatexCommand \index{Intel hex format}
5943
5944 \end_inset
5945
5946  file
5947 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5948
5949 \end_inset
5950
5951
5952 \end_layout
5953
5954 \begin_layout Standard
5955 In most cases this won't be needed but the Intel Hex file
5956 \begin_inset LatexCommand \index{<file>.ihx}
5957
5958 \end_inset
5959
5960  which is generated by SDCC might include lines of varying length and the
5961  addresses within the file are not guaranteed to be strictly ascending.
5962  If your toolchain or a bootloader does not like this you can use the tool
5963  
5964 \family typewriter
5965 packihx
5966 \family default
5967
5968 \begin_inset LatexCommand \index{packihx (tool)}
5969
5970 \end_inset
5971
5972  which is part of the SDCC distribution: 
5973 \newline
5974
5975 \newline
5976
5977 \family sans
5978 \series bold
5979  packihx sourcefile.ihx >sourcefile.hex
5980 \family default
5981 \series default
5982
5983 \newline
5984
5985 \newline
5986 The separately available
5987 \emph on
5988  srecord
5989 \emph default
5990
5991 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5992
5993 \end_inset
5994
5995  package additionally allows to set undefined locations to a predefined
5996  value, to insert checksums
5997 \begin_inset LatexCommand \index{checksum}
5998
5999 \end_inset
6000
6001  of various flavours (crc, add, xor) and to perform other manipulations
6002  (convert, split, crop, offset, ...).
6003  
6004 \newline
6005
6006 \newline
6007
6008 \family sans
6009 \series bold
6010 srec_cat\InsetSpace ~
6011 \InsetSpace ~
6012 sourcefile.ihx -intel\InsetSpace ~
6013 \InsetSpace ~
6014 -o sourcefile.hex -intel
6015 \newline
6016
6017 \newline
6018
6019 \family default
6020 \series default
6021 An example for a more complex command line
6022 \begin_inset Foot
6023 status open
6024
6025 \begin_layout Standard
6026 the command backfills
6027 \begin_inset LatexCommand \index{backfill unused memory}
6028
6029 \end_inset
6030
6031  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6032  block is zero.
6033  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6034  will be interpreted as an 
6035 \family typewriter
6036 lcall
6037 \family default
6038  to address 
6039 \family typewriter
6040 0x1212
6041 \family default
6042  (where an emergency routine could sit).
6043 \end_layout
6044
6045 \end_inset
6046
6047  could look like:
6048 \newline
6049
6050 \newline
6051
6052 \family sans
6053 \series bold
6054 \size footnotesize
6055 srec_cat\InsetSpace ~
6056 sourcefile.ihx -intel\InsetSpace ~
6057 \InsetSpace ~
6058 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6059 -little-endian-checksum-nega
6060 tive 0xfffe 0x02 0x02\InsetSpace ~
6061 \InsetSpace ~
6062 -o sourcefile.hex -intel
6063 \size default
6064
6065 \newline
6066
6067 \newline
6068
6069 \family default
6070 \series default
6071 The srecord package is available at 
6072 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6073
6074 \end_inset
6075
6076  .
6077 \end_layout
6078
6079 \begin_layout Subsection
6080 Projects with Multiple Source Files
6081 \end_layout
6082
6083 \begin_layout Standard
6084 SDCC can compile only ONE file at a time.
6085  Let us for example assume that you have a project containing the following
6086  files:
6087 \newline
6088
6089 \newline
6090 foo1.c (contains some functions)
6091 \newline
6092 foo2.c (contains some more functions)
6093 \newline
6094 foomai
6095 n.c (contains more functions and the function main)
6096 \newline
6097
6098 \size footnotesize
6099
6100 \newline
6101
6102 \size default
6103 The first two files will need to be compiled separately with the commands:
6104 \size footnotesize
6105  
6106 \size default
6107
6108 \newline
6109
6110 \newline
6111
6112 \family sans
6113 \series bold
6114 sdcc\InsetSpace ~
6115 -c\InsetSpace ~
6116 foo1.c
6117 \family default
6118 \series default
6119 \size footnotesize
6120
6121 \newline
6122
6123 \family sans
6124 \series bold
6125 \size default
6126 sdcc\InsetSpace ~
6127 -c\InsetSpace ~
6128 foo2.c
6129 \family default
6130 \series default
6131
6132 \newline
6133
6134 \newline
6135 Then compile the source file containing the 
6136 \emph on
6137 main()
6138 \emph default
6139  function and link
6140 \begin_inset LatexCommand \index{Linker}
6141
6142 \end_inset
6143
6144  the files together with the following command: 
6145 \newline
6146
6147 \newline
6148
6149 \family sans
6150 \series bold
6151 sdcc\InsetSpace ~
6152 foomain.c\InsetSpace ~
6153 foo1.rel\InsetSpace ~
6154 foo2.rel
6155 \family default
6156 \series default
6157
6158 \begin_inset LatexCommand \index{<file>.rel}
6159
6160 \end_inset
6161
6162
6163 \newline
6164
6165 \newline
6166 Alternatively, 
6167 \emph on
6168 foomain.c 
6169 \emph default
6170 can be separately compiled as well: 
6171 \family sans
6172 \series bold
6173
6174 \newline
6175
6176 \newline
6177 sdcc\InsetSpace ~
6178 -c\InsetSpace ~
6179 foomain.c
6180 \newline
6181 sdcc foomain.rel foo1.rel foo2.rel
6182 \newline
6183
6184 \newline
6185
6186 \family default
6187 \series default
6188 The file containing the 
6189 \emph on
6190 main()
6191 \emph default
6192  function
6193 \emph on
6194  
6195 \emph default
6196 \noun on
6197 must
6198 \noun default
6199  be the 
6200 \noun on
6201 first
6202 \noun default
6203  file specified in the command line, since the linkage editor processes
6204  file in the order they are presented to it.
6205  The linker is invoked from SDCC using a script file with extension .lnk
6206 \begin_inset LatexCommand \index{<file>.lnk}
6207
6208 \end_inset
6209
6210 .
6211  You can view this file to troubleshoot linking problems such as those arising
6212  from missing libraries.
6213 \end_layout
6214
6215 \begin_layout Subsection
6216 Projects with Additional Libraries
6217 \begin_inset LatexCommand \index{Libraries}
6218
6219 \end_inset
6220
6221
6222 \end_layout
6223
6224 \begin_layout Standard
6225 Some reusable routines may be compiled into a library, see the documentation
6226  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6227  for how to create a 
6228 \emph on
6229 .lib
6230 \begin_inset LatexCommand \index{<file>.lib}
6231
6232 \end_inset
6233
6234
6235 \emph default
6236  library file.
6237  Libraries created in this manner can be included in the command line.
6238  Make sure you include the -L <library-path> option to tell the linker where
6239  to look for these files if they are not in the current directory.
6240  Here is an example, assuming you have the source file 
6241 \emph on
6242 foomain.c
6243 \emph default
6244  and a library
6245 \emph on
6246  foolib.lib
6247 \emph default
6248  in the directory 
6249 \emph on
6250 mylib
6251 \emph default
6252  (if that is not the same as your current project):
6253 \newline
6254
6255 \newline
6256
6257 \family sans
6258 \series bold
6259 sdcc foomain.c foolib.lib -L mylib
6260 \newline
6261
6262 \newline
6263
6264 \family default
6265 \series default
6266 Note here that
6267 \emph on
6268  mylib
6269 \emph default
6270  must be an absolute path name.
6271 \newline
6272
6273 \newline
6274 The most efficient way to use libraries is
6275  to keep separate modules in separate source files.
6276  The lib file now should name all the modules.rel
6277 \begin_inset LatexCommand \index{<file>.rel}
6278
6279 \end_inset
6280
6281  files.
6282  For an example see the standard library file 
6283 \emph on
6284 libsdcc.lib
6285 \emph default
6286  in the directory <installdir>/share/lib/small.
6287 \end_layout
6288
6289 \begin_layout Subsection
6290 Using sdcclib to Create and Manage Libraries
6291 \begin_inset LatexCommand \index{sdcclib}
6292
6293 \end_inset
6294
6295
6296 \end_layout
6297
6298 \begin_layout Standard
6299 Alternatively, instead of having a .rel file for each entry on the library
6300  file as described in the preceding section, sdcclib can be used to embed
6301  all the modules belonging to such library in the library file itself.
6302  This results in a larger library file, but it greatly reduces the number
6303  of disk files accessed by the linker.
6304   Additionally, the packed library file contains an index of all include
6305  modules and symbols that significantly speeds up the linking process.
6306  To display a list of options supported by sdcclib type:
6307 \newline
6308
6309 \end_layout
6310
6311 \begin_layout Standard
6312
6313 \family sans
6314 \series bold
6315 sdcclib -?
6316 \begin_inset LatexCommand \index{sdcclib}
6317
6318 \end_inset
6319
6320
6321 \newline
6322
6323 \newline
6324
6325 \family default
6326 \series default
6327 To create a new library file, start by compiling all the required modules.
6328  For example:
6329 \newline
6330
6331 \end_layout
6332
6333 \begin_layout Standard
6334
6335 \family sans
6336 \series bold
6337 sdcc -c _divsint.c
6338 \end_layout
6339
6340 \begin_layout Standard
6341
6342 \family sans
6343 \series bold
6344 sdcc -c _divuint.c
6345 \end_layout
6346
6347 \begin_layout Standard
6348
6349 \family sans
6350 \series bold
6351 sdcc -c _modsint.c
6352 \end_layout
6353
6354 \begin_layout Standard
6355
6356 \family sans
6357 \series bold
6358 sdcc -c _moduint.c
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _mulint.c
6366 \newline
6367
6368 \end_layout
6369
6370 \begin_layout Standard
6371 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6372  and _mulint.rel.
6373  The next step is to add the .rel files to the library file:
6374 \newline
6375
6376 \end_layout
6377
6378 \begin_layout Standard
6379
6380 \family sans
6381 \series bold
6382 sdcclib libint.lib _divsint.rel
6383 \family default
6384
6385 \begin_inset LatexCommand \index{sdcclib}
6386
6387 \end_inset
6388
6389
6390 \end_layout
6391
6392 \begin_layout Standard
6393
6394 \family sans
6395 \series bold
6396 sdcclib libint.lib _divuint.rel
6397 \end_layout
6398
6399 \begin_layout Standard
6400
6401 \family sans
6402 \series bold
6403 sdcclib libint.lib _modsint.rel
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _moduint.rel
6411 \end_layout
6412
6413 \begin_layout Standard
6414
6415 \family sans
6416 \series bold
6417 sdcclib libint.lib _mulint.rel
6418 \family default
6419 \series default
6420
6421 \newline
6422
6423 \end_layout
6424
6425 \begin_layout Standard
6426 Or, if you preffer:
6427 \family sans
6428 \series bold
6429
6430 \newline
6431
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6439 \family default
6440 \series default
6441
6442 \newline
6443
6444 \end_layout
6445
6446 \begin_layout Standard
6447 If the file already exists in the library, it will be replaced.
6448  If a list of .rel files is available, you can tell sdcclib to add those
6449  files to a library.
6450  For example, if the file 'myliblist.txt' contains
6451 \family sans
6452 \series bold
6453
6454 \newline
6455
6456 \end_layout
6457
6458 \begin_layout Standard
6459
6460 \family sans
6461 \series bold
6462 _divsint.rel
6463 \end_layout
6464
6465 \begin_layout Standard
6466
6467 \family sans
6468 \series bold
6469 _divuint.rel
6470 \end_layout
6471
6472 \begin_layout Standard
6473
6474 \family sans
6475 \series bold
6476 _modsint.rel
6477 \end_layout
6478
6479 \begin_layout Standard
6480
6481 \family sans
6482 \series bold
6483 _moduint.rel
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _mulint.rel
6491 \family default
6492 \series default
6493
6494 \newline
6495
6496 \end_layout
6497
6498 \begin_layout Standard
6499 Use
6500 \family sans
6501 \series bold
6502
6503 \newline
6504
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 sdcclib -l libint.lib myliblist.txt
6512 \family default
6513 \series default
6514
6515 \newline
6516
6517 \end_layout
6518
6519 \begin_layout Standard
6520 Additionally, you can instruct sdcclib to compiles the files before adding
6521  them to the library.
6522  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6523  For example:
6524 \family sans
6525 \series bold
6526
6527 \newline
6528
6529 \end_layout
6530
6531 \begin_layout Standard
6532
6533 \family sans
6534 \series bold
6535 set SDCCLIB_CC=sdcc -c
6536 \end_layout
6537
6538 \begin_layout Standard
6539
6540 \family sans
6541 \series bold
6542 sdcclib -l libint.lib myliblist.txt
6543 \family default
6544 \series default
6545
6546 \newline
6547
6548 \end_layout
6549
6550 \begin_layout Standard
6551 To see what modules and symbols are included in the library, options -s
6552  and -m are available.
6553  For example:
6554 \newline
6555
6556 \newline
6557
6558 \family sans
6559 \series bold
6560 sdcclib -s libint.lib
6561 \family default
6562
6563 \begin_inset LatexCommand \index{sdcclib}
6564
6565 \end_inset
6566
6567
6568 \newline
6569
6570 \family typewriter
6571 \series default
6572 _divsint.rel:
6573 \end_layout
6574
6575 \begin_layout Standard
6576
6577 \family typewriter
6578 __divsint_a_1_1
6579 \end_layout
6580
6581 \begin_layout Standard
6582
6583 \family typewriter
6584 __divsint_PARM_2
6585 \end_layout
6586
6587 \begin_layout Standard
6588
6589 \family typewriter
6590 __divsint
6591 \newline
6592 _divuint.rel:
6593 \end_layout
6594
6595 \begin_layout Standard
6596
6597 \family typewriter
6598 __divuint_a_1_1
6599 \end_layout
6600
6601 \begin_layout Standard
6602
6603 \family typewriter
6604 __divuint_PARM_2
6605 \end_layout
6606
6607 \begin_layout Standard
6608
6609 \family typewriter
6610 __divuint_reste_1_1
6611 \end_layout
6612
6613 \begin_layout Standard
6614
6615 \family typewriter
6616 __divuint_count_1_1
6617 \end_layout
6618
6619 \begin_layout Standard
6620
6621 \family typewriter
6622 __divuint
6623 \newline
6624 _modsint.rel:
6625 \end_layout
6626
6627 \begin_layout Standard
6628
6629 \family typewriter
6630 __modsint_a_1_1
6631 \end_layout
6632
6633 \begin_layout Standard
6634
6635 \family typewriter
6636 __modsint_PARM_2
6637 \end_layout
6638
6639 \begin_layout Standard
6640
6641 \family typewriter
6642 __modsint
6643 \newline
6644 _moduint.rel:
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __moduint_a_1_1
6651 \end_layout
6652
6653 \begin_layout Standard
6654
6655 \family typewriter
6656 __moduint_PARM_2
6657 \end_layout
6658
6659 \begin_layout Standard
6660
6661 \family typewriter
6662 __moduint_count_1_1
6663 \end_layout
6664
6665 \begin_layout Standard
6666
6667 \family typewriter
6668 __moduint
6669 \newline
6670 _mulint.rel:
6671 \end_layout
6672
6673 \begin_layout Standard
6674
6675 \family typewriter
6676 __mulint_PARM_2
6677 \end_layout
6678
6679 \begin_layout Standard
6680
6681 \family typewriter
6682 __mulint
6683 \family default
6684 \series bold
6685
6686 \newline
6687
6688 \end_layout
6689
6690 \begin_layout Standard
6691 If the source files are compiled using -
6692 \begin_inset ERT
6693 status collapsed
6694
6695 \begin_layout Standard
6696
6697
6698 \backslash
6699 /
6700 \end_layout
6701
6702 \end_inset
6703
6704 -debug
6705 \begin_inset LatexCommand \index{-\/-debug}
6706
6707 \end_inset
6708
6709 , the corresponding debug information file .adb will be include in the library
6710  file as well.
6711  The library files created with sdcclib are plain text files, so they can
6712  be viewed with a text editor.
6713  It is not recomended to modify a library file created with sdcclib using
6714  a text editor, as there are file indexes numbers located accross the file
6715  used by the linker to quickly locate the required module to link.
6716  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6717  it can be safely deleted, since all the information required for linking
6718  is embedded in the library file itself.
6719  Library files created using sdcclib are used as described in the preceding
6720  sections.
6721 \begin_inset VSpace bigskip
6722 \end_inset
6723
6724
6725 \end_layout
6726
6727 \begin_layout Section
6728 Command Line Options
6729 \begin_inset LatexCommand \index{Command Line Options}
6730
6731 \end_inset
6732
6733
6734 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6735
6736 \end_inset
6737
6738
6739 \end_layout
6740
6741 \begin_layout Subsection
6742 Processor Selection Options
6743 \begin_inset LatexCommand \index{Options processor selection}
6744
6745 \end_inset
6746
6747
6748 \begin_inset LatexCommand \index{Processor selection options}
6749
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout List
6756 \labelwidthstring 00.00.0000
6757
6758 \series bold
6759 -mmcs51
6760 \begin_inset LatexCommand \index{-mmcs51}
6761
6762 \end_inset
6763
6764
6765 \series default
6766  Generate code for the Intel MCS51
6767 \begin_inset LatexCommand \index{MCS51}
6768
6769 \end_inset
6770
6771  family of processors.
6772  This is the default processor target.
6773 \end_layout
6774
6775 \begin_layout List
6776 \labelwidthstring 00.00.0000
6777
6778 \series bold
6779 -mds390
6780 \begin_inset LatexCommand \index{-mds390}
6781
6782 \end_inset
6783
6784
6785 \series default
6786  Generate code for the Dallas DS80C390
6787 \begin_inset LatexCommand \index{DS80C390}
6788
6789 \end_inset
6790
6791  processor.
6792 \end_layout
6793
6794 \begin_layout List
6795 \labelwidthstring 00.00.0000
6796
6797 \series bold
6798 -mds400
6799 \begin_inset LatexCommand \index{-mds400}
6800
6801 \end_inset
6802
6803
6804 \series default
6805  Generate code for the Dallas DS80C400
6806 \begin_inset LatexCommand \index{DS80C400}
6807
6808 \end_inset
6809
6810  processor.
6811 \end_layout
6812
6813 \begin_layout List
6814 \labelwidthstring 00.00.0000
6815
6816 \series bold
6817 -mhc08
6818 \begin_inset LatexCommand \index{-mhc08}
6819
6820 \end_inset
6821
6822
6823 \series default
6824  Generate code for the Freescale/Motorola HC08
6825 \begin_inset LatexCommand \index{HC08}
6826
6827 \end_inset
6828
6829  family of processors.
6830 \end_layout
6831
6832 \begin_layout List
6833 \labelwidthstring 00.00.0000
6834
6835 \series bold
6836 -mz80
6837 \begin_inset LatexCommand \index{-mz80}
6838
6839 \end_inset
6840
6841
6842 \series default
6843  Generate code for the Zilog Z80
6844 \begin_inset LatexCommand \index{Z80}
6845
6846 \end_inset
6847
6848  family of processors.
6849 \end_layout
6850
6851 \begin_layout List
6852 \labelwidthstring 00.00.0000
6853
6854 \series bold
6855 -mgbz80
6856 \begin_inset LatexCommand \index{-mgbz80}
6857
6858 \end_inset
6859
6860
6861 \series default
6862  Generate code for the GameBoy Z80
6863 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6864
6865 \end_inset
6866
6867  processor (Not actively maintained).
6868 \end_layout
6869
6870 \begin_layout List
6871 \labelwidthstring 00.00.0000
6872
6873 \series bold
6874 -mavr
6875 \begin_inset LatexCommand \index{-mavr}
6876
6877 \end_inset
6878
6879
6880 \series default
6881  Generate code for the Atmel AVR
6882 \begin_inset LatexCommand \index{AVR}
6883
6884 \end_inset
6885
6886  processor (Not maintained, not complete).
6887  AVR users should probably have a look at winavr 
6888 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6889
6890 \end_inset
6891
6892  or 
6893 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6894
6895 \end_inset
6896
6897 , which is based on AVR-port of the gcc compiler.
6898 \end_layout
6899
6900 \begin_layout Standard
6901 \begin_inset Note Note
6902 status collapsed
6903
6904 \begin_layout Standard
6905 I think it is fair to direct users there for now.
6906  Open source is also about avoiding unnecessary work .
6907  But I didn't find the 'official' link.
6908 \end_layout
6909
6910 \end_inset
6911
6912
6913 \end_layout
6914
6915 \begin_layout List
6916 \labelwidthstring 00.00.0000
6917
6918 \series bold
6919 -mpic14
6920 \begin_inset LatexCommand \index{-mpic14}
6921
6922 \end_inset
6923
6924
6925 \series default
6926  Generate code for the Microchip PIC 14
6927 \begin_inset LatexCommand \index{PIC14}
6928
6929 \end_inset
6930
6931 -bit processors (p16f84 and variants.
6932  In development, not complete).
6933 \end_layout
6934
6935 \begin_layout Standard
6936 \begin_inset Note Note
6937 status collapsed
6938
6939 \begin_layout Standard
6940 p16f627 p16f628 p16f84 p16f873 p16f877?
6941 \end_layout
6942
6943 \end_inset
6944
6945
6946 \end_layout
6947
6948 \begin_layout List
6949 \labelwidthstring 00.00.0000
6950
6951 \series bold
6952 -mpic16
6953 \begin_inset LatexCommand \index{-mpic16}
6954
6955 \end_inset
6956
6957
6958 \series default
6959  Generate code for the Microchip PIC 16
6960 \begin_inset LatexCommand \index{PIC16}
6961
6962 \end_inset
6963
6964 -bit processors (p18f452 and variants.
6965  In development, not complete).
6966 \end_layout
6967
6968 \begin_layout List
6969 \labelwidthstring 00.00.0000
6970
6971 \series bold
6972 -mtlcs900h
6973 \series default
6974  Generate code for the Toshiba TLCS-900H
6975 \begin_inset LatexCommand \index{TLCS-900H}
6976
6977 \end_inset
6978
6979  processor (Not maintained, not complete).
6980 \end_layout
6981
6982 \begin_layout List
6983 \labelwidthstring 00.00.0000
6984
6985 \series bold
6986 -mxa51
6987 \begin_inset LatexCommand \index{-mxa51}
6988
6989 \end_inset
6990
6991
6992 \series default
6993  Generate code for the Phillips XA51
6994 \begin_inset LatexCommand \index{XA51}
6995
6996 \end_inset
6997
6998  processor (Not maintained, not complete).
6999 \end_layout
7000
7001 \begin_layout Standard
7002 \begin_inset VSpace bigskip
7003 \end_inset
7004
7005
7006 \end_layout
7007
7008 \begin_layout Subsection
7009 Preprocessor Options
7010 \begin_inset LatexCommand \index{Options preprocessor}
7011
7012 \end_inset
7013
7014
7015 \begin_inset LatexCommand \index{Preprocessor options}
7016
7017 \end_inset
7018
7019
7020 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7021
7022 \end_inset
7023
7024
7025 \end_layout
7026
7027 \begin_layout List
7028 \labelwidthstring 00.00.0000
7029
7030 \series bold
7031 -I<path>
7032 \begin_inset LatexCommand \index{-I<path>}
7033
7034 \end_inset
7035
7036
7037 \series default
7038  The additional location where the preprocessor will look for <..h> or 
7039 \begin_inset Quotes eld
7040 \end_inset
7041
7042 ..h
7043 \begin_inset Quotes erd
7044 \end_inset
7045
7046  files.
7047 \end_layout
7048
7049 \begin_layout List
7050 \labelwidthstring 00.00.0000
7051
7052 \series bold
7053 -D<macro[=value]>
7054 \begin_inset LatexCommand \index{-D<macro[=value]>}
7055
7056 \end_inset
7057
7058
7059 \series default
7060  Command line definition of macros.
7061  Passed to the preprocessor.
7062 \end_layout
7063
7064 \begin_layout List
7065 \labelwidthstring 00.00.0000
7066
7067 \series bold
7068 -M
7069 \begin_inset LatexCommand \index{-M}
7070
7071 \end_inset
7072
7073
7074 \series default
7075  Tell the preprocessor to output a rule suitable for make describing the
7076  dependencies of each object file.
7077  For each source file, the preprocessor outputs one make-rule whose target
7078  is the object file name for that source file and whose dependencies are
7079  all the files `#include'd in it.
7080  This rule may be a single line or may be continued with `
7081 \backslash
7082 '-newline if it is long.
7083  The list of rules is printed on standard output instead of the preprocessed
7084  C program.
7085  `-M' implies `-E
7086 \begin_inset LatexCommand \index{-E}
7087
7088 \end_inset
7089
7090 '.
7091 \end_layout
7092
7093 \begin_layout List
7094 \labelwidthstring 00.00.0000
7095
7096 \series bold
7097 -C
7098 \begin_inset LatexCommand \index{-C}
7099
7100 \end_inset
7101
7102
7103 \series default
7104  Tell the preprocessor not to discard comments.
7105  Used with the `-E' option.
7106 \end_layout
7107
7108 \begin_layout List
7109 \labelwidthstring 00.00.0000
7110
7111 \series bold
7112 -MM
7113 \begin_inset LatexCommand \index{-MM}
7114
7115 \end_inset
7116
7117
7118 \size large
7119 \bar under
7120  
7121 \series default
7122 \size default
7123 \bar default
7124 Like `-M' but the output mentions only the user header files included with
7125  `#include 
7126 \begin_inset Quotes eld
7127 \end_inset
7128
7129 file"'.
7130  System header files included with `#include <file>' are omitted.
7131 \end_layout
7132
7133 \begin_layout List
7134 \labelwidthstring 00.00.0000
7135
7136 \series bold
7137 -Aquestion(answer)
7138 \begin_inset LatexCommand \index{-Aquestion(answer)}
7139
7140 \end_inset
7141
7142
7143 \series default
7144  Assert the answer answer for question, in case it is tested with a preprocessor
7145  conditional such as `#if #question(answer)'.
7146  `-A-' disables the standard assertions that normally describe the target
7147  machine.
7148 \end_layout
7149
7150 \begin_layout List
7151 \labelwidthstring 00.00.0000
7152
7153 \series bold
7154 -Umacro
7155 \begin_inset LatexCommand \index{-Umacro}
7156
7157 \end_inset
7158
7159
7160 \series default
7161  Undefine macro macro.
7162  `-U' options are evaluated after all `-D' options, but before any `-include'
7163  and `-imacros' options.
7164 \end_layout
7165
7166 \begin_layout List
7167 \labelwidthstring 00.00.0000
7168
7169 \series bold
7170 -dM
7171 \begin_inset LatexCommand \index{-dM}
7172
7173 \end_inset
7174
7175
7176 \series default
7177  Tell the preprocessor to output only a list of the macro definitions that
7178  are in effect at the end of preprocessing.
7179  Used with the `-E' option.
7180 \end_layout
7181
7182 \begin_layout List
7183 \labelwidthstring 00.00.0000
7184
7185 \series bold
7186 -dD
7187 \begin_inset LatexCommand \index{-dD}
7188
7189 \end_inset
7190
7191
7192 \series default
7193  Tell the preprocessor to pass all macro definitions into the output, in
7194  their proper sequence in the rest of the output.
7195 \end_layout
7196
7197 \begin_layout List
7198 \labelwidthstring 00.00.0000
7199
7200 \series bold
7201 -dN
7202 \begin_inset LatexCommand \index{-dN}
7203
7204 \end_inset
7205
7206
7207 \size large
7208 \bar under
7209  
7210 \series default
7211 \size default
7212 \bar default
7213 Like `-dD' except that the macro arguments and contents are omitted.
7214  Only `#define name' is included in the output.
7215 \end_layout
7216
7217 \begin_layout List
7218 \labelwidthstring 00.00.0000
7219
7220 \series bold
7221 -pedantic-parse-number
7222 \begin_inset LatexCommand \index{pedantic}
7223
7224 \end_inset
7225
7226
7227 \begin_inset LatexCommand \index{-pedantic-parse-number}
7228
7229 \end_inset
7230
7231
7232 \size large
7233 \bar under
7234
7235 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7236
7237 \end_inset
7238
7239  
7240 \series default
7241 \size default
7242 \bar default
7243 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7244  and the macro LO_B(3) gets expanded.
7245  See also #pragma pedantic_parse_number 
7246 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7247
7248 \end_inset
7249
7250  in section
7251 \begin_inset LatexCommand \ref{sec:Pragmas}
7252
7253 \end_inset
7254
7255  
7256 \emph on
7257 Note: this functionality is not in conformance with C99 standard!
7258 \end_layout
7259
7260 \begin_layout List
7261 \labelwidthstring 00.00.0000
7262
7263 \series bold
7264 -Wp\InsetSpace ~
7265 preprocessorOption[,preprocessorOption]
7266 \series default
7267
7268 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7269
7270 \end_inset
7271
7272 ...
7273  Pass the preprocessorOption to the preprocessor 
7274 \family typewriter
7275 sdcpp
7276 \family default
7277
7278 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7279
7280 \end_inset
7281
7282 .
7283  SDCC uses an adapted version of the preprocessor 
7284 \emph on
7285 cpp
7286 \emph default
7287  of the GNU Compiler Collection
7288 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7289
7290 \end_inset
7291
7292  (
7293 \emph on
7294 gcc
7295 \emph default
7296  
7297 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7298
7299 \end_inset
7300
7301 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7302 4.1.1\InsetSpace ~
7303 CPP\InsetSpace ~
7304 Manual
7305  at 
7306 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7307
7308 \end_inset
7309
7310 .
7311 \end_layout
7312
7313 \begin_layout Standard
7314 \begin_inset VSpace bigskip
7315 \end_inset
7316
7317
7318 \end_layout
7319
7320 \begin_layout Subsection
7321 Linker Options
7322 \begin_inset LatexCommand \index{Options linker}
7323
7324 \end_inset
7325
7326
7327 \begin_inset LatexCommand \index{Linker options}
7328
7329 \end_inset
7330
7331
7332 \end_layout
7333
7334 \begin_layout List
7335 \labelwidthstring 00.00.0000
7336
7337 \series bold
7338 -L\InsetSpace ~
7339 -
7340 \series default
7341
7342 \begin_inset ERT
7343 status collapsed
7344
7345 \begin_layout Standard
7346
7347
7348 \backslash
7349 /
7350 \end_layout
7351
7352 \end_inset
7353
7354
7355 \series bold
7356 -lib-path
7357 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7358
7359 \end_inset
7360
7361
7362 \begin_inset LatexCommand \index{-L -\/-lib-path}
7363
7364 \end_inset
7365
7366
7367 \series default
7368 \InsetSpace ~
7369 <absolute path to additional libraries> This option is passed to the linkage
7370  editor's additional libraries
7371 \begin_inset LatexCommand \index{Libraries}
7372
7373 \end_inset
7374
7375  search path.
7376  The path name must be absolute.
7377  Additional library files may be specified in the command line.
7378  See section Compiling programs for more details.
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 -xram-loc
7399 \series default
7400
7401 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7402
7403 \end_inset
7404
7405 \InsetSpace ~
7406 <Value> The start location of the external ram
7407 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7408
7409 \end_inset
7410
7411 , default value is 0.
7412  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7413 \begin_inset ERT
7414 status collapsed
7415
7416 \begin_layout Standard
7417
7418
7419 \backslash
7420 /
7421 \end_layout
7422
7423 \end_inset
7424
7425 -xram-loc 0x8000 or -
7426 \begin_inset ERT
7427 status collapsed
7428
7429 \begin_layout Standard
7430
7431
7432 \backslash
7433 /
7434 \end_layout
7435
7436 \end_inset
7437
7438 -xram-loc 32768.
7439 \end_layout
7440
7441 \begin_layout List
7442 \labelwidthstring 00.00.0000
7443
7444 \series bold
7445 -
7446 \begin_inset ERT
7447 status collapsed
7448
7449 \begin_layout Standard
7450
7451
7452 \backslash
7453 /
7454 \end_layout
7455
7456 \end_inset
7457
7458 -code-loc
7459 \series default
7460
7461 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7462
7463 \end_inset
7464
7465 \InsetSpace ~
7466 <Value> The start location of the code
7467 \begin_inset LatexCommand \index{code}
7468
7469 \end_inset
7470
7471  segment, default value 0.
7472  Note when this option is used the interrupt vector table
7473 \begin_inset LatexCommand \index{interrupt vector table}
7474
7475 \end_inset
7476
7477  is also relocated to the given address.
7478  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7479 \begin_inset ERT
7480 status collapsed
7481
7482 \begin_layout Standard
7483
7484
7485 \backslash
7486 /
7487 \end_layout
7488
7489 \end_inset
7490
7491 -code-loc 0x8000 or -
7492 \begin_inset ERT
7493 status collapsed
7494
7495 \begin_layout Standard
7496
7497
7498 \backslash
7499 /
7500 \end_layout
7501
7502 \end_inset
7503
7504 -code-loc 32768.
7505 \end_layout
7506
7507 \begin_layout List
7508 \labelwidthstring 00.00.0000
7509
7510 \series bold
7511 -
7512 \begin_inset ERT
7513 status collapsed
7514
7515 \begin_layout Standard
7516
7517
7518 \backslash
7519 /
7520 \end_layout
7521
7522 \end_inset
7523
7524 -stack-loc
7525 \series default
7526
7527 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7528
7529 \end_inset
7530
7531 \InsetSpace ~
7532 <Value> By default the stack
7533 \begin_inset LatexCommand \index{stack}
7534
7535 \end_inset
7536
7537  is placed after the data segment.
7538  Using this option the stack can be placed anywhere in the internal memory
7539  space of the 8051.
7540  The value entered can be in Hexadecimal or Decimal format, e.g.
7541  -
7542 \begin_inset ERT
7543 status collapsed
7544
7545 \begin_layout Standard
7546
7547
7548 \backslash
7549 /
7550 \end_layout
7551
7552 \end_inset
7553
7554 -stack-loc 0x20 or -
7555 \begin_inset ERT
7556 status collapsed
7557
7558 \begin_layout Standard
7559
7560
7561 \backslash
7562 /
7563 \end_layout
7564
7565 \end_inset
7566
7567 -stack-loc 32.
7568  Since the sp register is incremented before a push or call, the initial
7569  sp will be set to one byte prior the provided value.
7570  The provided value should not overlap any other memory areas such as used
7571  register banks or the data segment and with enough space for the current
7572  application.
7573  The 
7574 \series bold
7575 -
7576 \begin_inset ERT
7577 status collapsed
7578
7579 \begin_layout Standard
7580
7581
7582 \backslash
7583 /
7584 \end_layout
7585
7586 \end_inset
7587
7588 -pack-iram
7589 \series default
7590 \InsetSpace ~
7591
7592 \begin_inset LatexCommand \index{-\/-pack-iram}
7593
7594 \end_inset
7595
7596  option (which is now a default setting) will override this setting, so
7597  you should also specify the 
7598 \series bold
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 -no-pack-iram
7613 \series default
7614 \InsetSpace ~
7615
7616 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7617
7618 \end_inset
7619
7620  option if you need to manually place the stack.
7621 \end_layout
7622
7623 \begin_layout List
7624 \labelwidthstring 00.00.0000
7625
7626 \series bold
7627 -
7628 \begin_inset ERT
7629 status collapsed
7630
7631 \begin_layout Standard
7632
7633
7634 \backslash
7635 /
7636 \end_layout
7637
7638 \end_inset
7639
7640 -xstack-loc
7641 \series default
7642
7643 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7644
7645 \end_inset
7646
7647 \InsetSpace ~
7648 <Value> By default the external stack
7649 \begin_inset LatexCommand \index{xstack}
7650
7651 \end_inset
7652
7653  is placed after the pdata
7654 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7655
7656 \end_inset
7657
7658  segment.
7659  Using this option the xstack can be placed anywhere in the external memory
7660  space of the 8051.
7661  The value entered can be in Hexadecimal or Decimal format, e.g.
7662  -
7663 \begin_inset ERT
7664 status collapsed
7665
7666 \begin_layout Standard
7667
7668
7669 \backslash
7670 /
7671 \end_layout
7672
7673 \end_inset
7674
7675 -xstack-loc 0x8000 or -
7676 \begin_inset ERT
7677 status collapsed
7678
7679 \begin_layout Standard
7680
7681
7682 \backslash
7683 /
7684 \end_layout
7685
7686 \end_inset
7687
7688 -stack-loc 32768.
7689  The provided value should not overlap any other memory areas such as the
7690  pdata or xdata segment and with enough space for the current application.
7691 \end_layout
7692
7693 \begin_layout List
7694 \labelwidthstring 00.00.0000
7695
7696 \series bold
7697 -
7698 \begin_inset ERT
7699 status collapsed
7700
7701 \begin_layout Standard
7702
7703
7704 \backslash
7705 /
7706 \end_layout
7707
7708 \end_inset
7709
7710 -data-loc
7711 \series default
7712
7713 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7714
7715 \end_inset
7716
7717 \InsetSpace ~
7718 <Value> The start location of the internal ram data
7719 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7720
7721 \end_inset
7722
7723  segment.
7724  The value entered can be in Hexadecimal or Decimal format, eg.
7725  -
7726 \begin_inset ERT
7727 status collapsed
7728
7729 \begin_layout Standard
7730
7731
7732 \backslash
7733 /
7734 \end_layout
7735
7736 \end_inset
7737
7738 -data-loc 0x20 or -
7739 \begin_inset ERT
7740 status collapsed
7741
7742 \begin_layout Standard
7743
7744
7745 \backslash
7746 /
7747 \end_layout
7748
7749 \end_inset
7750
7751 -data-loc 32.
7752  (By default, the start location of the internal ram data segment  is set
7753  as low as possible in memory, taking into account the used register banks
7754  and the bit segment at address 0x20.
7755  For example if register banks 0 and 1 are used without bit variables, the
7756  data segment will be set, if -
7757 \begin_inset ERT
7758 status collapsed
7759
7760 \begin_layout Standard
7761
7762
7763 \backslash
7764 /
7765 \end_layout
7766
7767 \end_inset
7768
7769 -data-loc is not used, to location 0x10.)
7770 \end_layout
7771
7772 \begin_layout List
7773 \labelwidthstring 00.00.0000
7774
7775 \series bold
7776 -
7777 \begin_inset ERT
7778 status collapsed
7779
7780 \begin_layout Standard
7781
7782
7783 \backslash
7784 /
7785 \end_layout
7786
7787 \end_inset
7788
7789 -idata-loc
7790 \series default
7791
7792 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7793
7794 \end_inset
7795
7796 \InsetSpace ~
7797 <Value> The start location of the indirectly addressable internal ram
7798 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7799
7800 \end_inset
7801
7802  of the 8051, default value is 0x80.
7803  The value entered can be in Hexadecimal or Decimal format, eg.
7804  -
7805 \begin_inset ERT
7806 status collapsed
7807
7808 \begin_layout Standard
7809
7810
7811 \backslash
7812 /
7813 \end_layout
7814
7815 \end_inset
7816
7817 -idata-loc 0x88 or -
7818 \begin_inset ERT
7819 status collapsed
7820
7821 \begin_layout Standard
7822
7823
7824 \backslash
7825 /
7826 \end_layout
7827
7828 \end_inset
7829
7830 -idata-loc 136.
7831 \end_layout
7832
7833 \begin_layout List
7834 \labelwidthstring 00.00.0000
7835
7836 \series bold
7837 -
7838 \begin_inset ERT
7839 status collapsed
7840
7841 \begin_layout Standard
7842
7843
7844 \backslash
7845 /
7846 \end_layout
7847
7848 \end_inset
7849
7850 -bit-loc
7851 \series default
7852 \InsetSpace ~
7853 <Value> The start location of the bit
7854 \begin_inset LatexCommand \index{bit}
7855
7856 \end_inset
7857
7858  addressable internal ram of the 8051.
7859  This is 
7860 \emph on
7861 not
7862 \emph default
7863  implemented yet.
7864  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7865 -bBSEG=<Value>.
7866 \end_layout
7867
7868 \begin_layout List
7869 \labelwidthstring 00.00.0000
7870
7871 \series bold
7872 -
7873 \begin_inset ERT
7874 status collapsed
7875
7876 \begin_layout Standard
7877
7878
7879 \backslash
7880 /
7881 \end_layout
7882
7883 \end_inset
7884
7885 -out-fmt-ihx
7886 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7887
7888 \end_inset
7889
7890
7891 \bar under
7892  
7893 \series default
7894 \bar default
7895 The linker output (final object code) is in Intel Hex format.
7896 \begin_inset LatexCommand \index{Intel hex format}
7897
7898 \end_inset
7899
7900  This is the default option.
7901  The format itself is documented in the documentation of srecord
7902 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7903
7904 \end_inset
7905
7906 .
7907 \end_layout
7908
7909 \begin_layout List
7910 \labelwidthstring 00.00.0000
7911
7912 \series bold
7913 -
7914 \begin_inset ERT
7915 status collapsed
7916
7917 \begin_layout Standard
7918
7919
7920 \backslash
7921 /
7922 \end_layout
7923
7924 \end_inset
7925
7926 -out-fmt-s19
7927 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7928
7929 \end_inset
7930
7931
7932 \bar under
7933  
7934 \series default
7935 \bar default
7936 The linker output (final object code) is in Motorola S19 format
7937 \begin_inset LatexCommand \index{Motorola S19 format}
7938
7939 \end_inset
7940
7941 .
7942  The format itself is documented in the documentation of srecord.
7943 \end_layout
7944
7945 \begin_layout List
7946 \labelwidthstring 00.00.0000
7947
7948 \series bold
7949 -
7950 \begin_inset ERT
7951 status collapsed
7952
7953 \begin_layout Standard
7954
7955
7956 \backslash
7957 /
7958 \end_layout
7959
7960 \end_inset
7961
7962 -out-fmt-elf
7963 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7964
7965 \end_inset
7966
7967
7968 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7969
7970 \end_inset
7971
7972
7973 \bar under
7974  
7975 \series default
7976 \bar default
7977 The linker output (final object code) is in ELF format
7978 \begin_inset LatexCommand \index{ELF format}
7979
7980 \end_inset
7981
7982 .
7983  (Currently only supported for the HC08
7984 \begin_inset LatexCommand \index{HC08}
7985
7986 \end_inset
7987
7988  processors)
7989 \end_layout
7990
7991 \begin_layout List
7992 \labelwidthstring 00.00.0000
7993
7994 \series bold
7995 -Wl\InsetSpace ~
7996 linkOption[,linkOption]
7997 \series default
7998
7999 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8000
8001 \end_inset
8002
8003 ...
8004  Pass the linkOption to the linker.
8005  If a bootloader is used an option like 
8006 \begin_inset Quotes sld
8007 \end_inset
8008
8009 -Wl\InsetSpace ~
8010 -bCSEG=0x1000
8011 \begin_inset Quotes srd
8012 \end_inset
8013
8014  would be typical to set the start of the code segment.
8015  See also #pragma constseg and #pragma codeseg in section 
8016 \begin_inset LatexCommand \ref{sec:Pragmas}
8017
8018 \end_inset
8019
8020  .
8021  File sdcc/as/doc/asxhtm.html has more on linker options.
8022 \end_layout
8023
8024 \begin_layout Standard
8025 \begin_inset VSpace bigskip
8026 \end_inset
8027
8028
8029 \end_layout
8030
8031 \begin_layout Subsection
8032 MCS51 Options
8033 \begin_inset LatexCommand \index{Options MCS51}
8034
8035 \end_inset
8036
8037
8038 \begin_inset LatexCommand \index{MCS51 options}
8039
8040 \end_inset
8041
8042
8043 \end_layout
8044
8045 \begin_layout List
8046 \labelwidthstring 00.00.0000
8047
8048 \series bold
8049 -
8050 \begin_inset ERT
8051 status collapsed
8052
8053 \begin_layout Standard
8054
8055
8056 \backslash
8057 /
8058 \end_layout
8059
8060 \end_inset
8061
8062 -model-small
8063 \begin_inset LatexCommand \index{-\/-model-small}
8064
8065 \end_inset
8066
8067
8068 \series default
8069 \size large
8070 \emph on
8071  
8072 \size default
8073 \emph default
8074 Generate code for Small Model programs, see section Memory Models for more
8075  details.
8076  This is the default model.
8077 \end_layout
8078
8079 \begin_layout List
8080 \labelwidthstring 00.00.0000
8081
8082 \series bold
8083 -
8084 \begin_inset ERT
8085 status collapsed
8086
8087 \begin_layout Standard
8088
8089
8090 \backslash
8091 /
8092 \end_layout
8093
8094 \end_inset
8095
8096 -model-medium
8097 \begin_inset LatexCommand \index{-\/-model-medium}
8098
8099 \end_inset
8100
8101
8102 \series default
8103  Generate code for Medium model programs, see section Memory Models for
8104  more details.
8105  If this option is used all source files in the project have to be compiled
8106  with this option.
8107  It must also be used when invoking the linker.
8108 \end_layout
8109
8110 \begin_layout List
8111 \labelwidthstring 00.00.0000
8112
8113 \series bold
8114 -
8115 \begin_inset ERT
8116 status collapsed
8117
8118 \begin_layout Standard
8119
8120
8121 \backslash
8122 /
8123 \end_layout
8124
8125 \end_inset
8126
8127 -model-large
8128 \begin_inset LatexCommand \index{-\/-model-large}
8129
8130 \end_inset
8131
8132
8133 \series default
8134  Generate code for Large model programs, see section Memory Models for more
8135  details.
8136  If this option is used all source files in the project have to be compiled
8137  with this option.
8138  It must also be used when invoking the linker.
8139 \end_layout
8140
8141 \begin_layout List
8142 \labelwidthstring 00.00.0000
8143
8144 \series bold
8145 -
8146 \begin_inset ERT
8147 status collapsed
8148
8149 \begin_layout Standard
8150
8151
8152 \backslash
8153 /
8154 \end_layout
8155
8156 \end_inset
8157
8158 -xstack
8159 \begin_inset LatexCommand \index{-\/-xstack}
8160
8161 \end_inset
8162
8163
8164 \series default
8165  Uses a pseudo stack in the pdata
8166 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8167
8168 \end_inset
8169
8170  area (usually the first 256 bytes in the external ram) for allocating variables
8171  and passing parameters.
8172  See section 
8173 \begin_inset LatexCommand \ref{sub:External-Stack}
8174
8175 \end_inset
8176
8177 \InsetSpace ~
8178  External Stack for more details.
8179 \end_layout
8180
8181 \begin_layout List
8182 \labelwidthstring 00.00.0000
8183
8184 \series bold
8185 -
8186 \begin_inset ERT
8187 status collapsed
8188
8189 \begin_layout Standard
8190
8191
8192 \backslash
8193 /
8194 \end_layout
8195
8196 \end_inset
8197
8198 -iram-size
8199 \series default
8200 \InsetSpace ~
8201 <Value>
8202 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8203
8204 \end_inset
8205
8206  Causes the linker to check if the internal ram usage is within limits of
8207  the given value.
8208 \end_layout
8209
8210 \begin_layout List
8211 \labelwidthstring 00.00.0000
8212
8213 \series bold
8214 -
8215 \begin_inset ERT
8216 status collapsed
8217
8218 \begin_layout Standard
8219
8220
8221 \backslash
8222 /
8223 \end_layout
8224
8225 \end_inset
8226
8227 -xram-size
8228 \series default
8229 \InsetSpace ~
8230 <Value>
8231 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8232
8233 \end_inset
8234
8235  Causes the linker to check if the external ram usage is within limits of
8236  the given value.
8237 \end_layout
8238
8239 \begin_layout List
8240 \labelwidthstring 00.00.0000
8241
8242 \series bold
8243 -
8244 \begin_inset ERT
8245 status collapsed
8246
8247 \begin_layout Standard
8248
8249
8250 \backslash
8251 /
8252 \end_layout
8253
8254 \end_inset
8255
8256 -code-size
8257 \series default
8258 \InsetSpace ~
8259 <Value>
8260 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8261
8262 \end_inset
8263
8264  Causes the linker to check if the code memory usage is within limits of
8265  the given value.
8266 \end_layout
8267
8268 \begin_layout List
8269 \labelwidthstring 00.00.0000
8270
8271 \series bold
8272 -
8273 \begin_inset ERT
8274 status collapsed
8275
8276 \begin_layout Standard
8277
8278
8279 \backslash
8280 /
8281 \end_layout
8282
8283 \end_inset
8284
8285 -stack-size
8286 \series default
8287 \InsetSpace ~
8288 <Value>
8289 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8290
8291 \end_inset
8292
8293  Causes the linker to check if there is at minimum <Value> bytes for stack.
8294 \end_layout
8295
8296 \begin_layout List
8297 \labelwidthstring 00.00.0000
8298
8299 \series bold
8300 -
8301 \begin_inset ERT
8302 status collapsed
8303
8304 \begin_layout Standard
8305
8306
8307 \backslash
8308 /
8309 \end_layout
8310
8311 \end_inset
8312
8313 -pack-iram
8314 \series default
8315 \InsetSpace ~
8316
8317 \begin_inset LatexCommand \index{-\/-pack-iram}
8318
8319 \end_inset
8320
8321  Causes the linker to use unused register banks for data variables and pack
8322  data, idata and stack together.
8323  This is the default now.
8324 \end_layout
8325
8326 \begin_layout List
8327 \labelwidthstring 00.00.0000
8328
8329 \series bold
8330 -
8331 \begin_inset ERT
8332 status collapsed
8333
8334 \begin_layout Standard
8335
8336
8337 \backslash
8338 /
8339 \end_layout
8340
8341 \end_inset
8342
8343 -no-pack-iram
8344 \series default
8345 \InsetSpace ~
8346
8347 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8348
8349 \end_inset
8350
8351  Causes the linker to use old style for allocating memory areas.
8352 \end_layout
8353
8354 \begin_layout List
8355 \labelwidthstring 00.00.0000
8356
8357 \series bold
8358 -
8359 \begin_inset ERT
8360 status collapsed
8361
8362 \begin_layout Standard
8363
8364
8365 \backslash
8366 /
8367 \end_layout
8368
8369 \end_inset
8370
8371 -acall-ajmp
8372 \series default
8373 \InsetSpace ~
8374
8375 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8376
8377 \end_inset
8378
8379  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8380  acall/ajmp.
8381  Only use this option if your code is in the same 2k block of memory.
8382  You may need to use this option for some 8051 derivatives which lack the
8383  lcall/ljmp instructions..
8384 \end_layout
8385
8386 \begin_layout Standard
8387 \begin_inset VSpace bigskip
8388 \end_inset
8389
8390
8391 \end_layout
8392
8393 \begin_layout Subsection
8394 DS390 / DS400 Options
8395 \begin_inset LatexCommand \index{Options DS390}
8396
8397 \end_inset
8398
8399
8400 \begin_inset LatexCommand \index{DS390}
8401
8402 \end_inset
8403
8404
8405 \end_layout
8406
8407 \begin_layout List
8408 \labelwidthstring 00.00.0000
8409
8410 \series bold
8411 -
8412 \begin_inset ERT
8413 status collapsed
8414
8415 \begin_layout Standard
8416
8417
8418 \backslash
8419 /
8420 \end_layout
8421
8422 \end_inset
8423
8424 -model-flat24
8425 \series default
8426
8427 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8428
8429 \end_inset
8430
8431
8432 \size large
8433 \emph on
8434  
8435 \size default
8436 \emph default
8437 Generate 24-bit flat mode code.
8438  This is the one and only that the ds390 code generator supports right now
8439  and is default when using 
8440 \emph on
8441 -mds390
8442 \emph default
8443 .
8444  See section Memory Models for more details.
8445 \end_layout
8446
8447 \begin_layout List
8448 \labelwidthstring 00.00.0000
8449
8450 \series bold
8451 -
8452 \begin_inset ERT
8453 status collapsed
8454
8455 \begin_layout Standard
8456
8457
8458 \backslash
8459 /
8460 \end_layout
8461
8462 \end_inset
8463
8464 -protect-sp-update
8465 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8466
8467 \end_inset
8468
8469
8470 \series default
8471  disable interrupts during ESP:SP updates.
8472 \end_layout
8473
8474 \begin_layout List
8475 \labelwidthstring 00.00.0000
8476
8477 \series bold
8478 -
8479 \begin_inset ERT
8480 status collapsed
8481
8482 \begin_layout Standard
8483
8484
8485 \backslash
8486 /
8487 \end_layout
8488
8489 \end_inset
8490
8491 -stack-10bit
8492 \series default
8493
8494 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8495
8496 \end_inset
8497
8498  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8499  This is the one and only that the ds390 code generator supports right now
8500  and is default when using 
8501 \emph on
8502 -mds390
8503 \emph default
8504 .
8505  In this mode, the stack is located in the lower 1K of the internal RAM,
8506  which is mapped to 0x400000.
8507  Note that the support is incomplete, since it still uses a single byte
8508  as the stack pointer.
8509  This means that only the lower 256 bytes of the potential 1K stack space
8510  will actually be used.
8511  However, this does allow you to reclaim the precious 256 bytes of low RAM
8512  for use for the DATA and IDATA segments.
8513  The compiler will not generate any code to put the processor into 10 bit
8514  stack mode.
8515  It is important to ensure that the processor is in this mode before calling
8516  any re-entrant functions compiled with this option.
8517  In principle, this should work with the 
8518 \emph on
8519 -
8520 \begin_inset ERT
8521 status collapsed
8522
8523 \begin_layout Standard
8524
8525
8526 \backslash
8527 /
8528 \end_layout
8529
8530 \end_inset
8531
8532 -stack-auto
8533 \begin_inset LatexCommand \index{-\/-stack-auto}
8534
8535 \end_inset
8536
8537
8538 \emph default
8539  option, but that has not been tested.
8540  It is incompatible with the 
8541 \emph on
8542 -
8543 \begin_inset ERT
8544 status collapsed
8545
8546 \begin_layout Standard
8547
8548
8549 \backslash
8550 /
8551 \end_layout
8552
8553 \end_inset
8554
8555 -xstack
8556 \begin_inset LatexCommand \index{-\/-xstack}
8557
8558 \end_inset
8559
8560
8561 \emph default
8562  option.
8563  It also only makes sense if the processor is in 24 bit contiguous addressing
8564  mode (see the 
8565 \emph on
8566 -
8567 \begin_inset ERT
8568 status collapsed
8569
8570 \begin_layout Standard
8571
8572
8573 \backslash
8574 /
8575 \end_layout
8576
8577 \end_inset
8578
8579 -model-flat24 option
8580 \emph default
8581 ).
8582 \series bold
8583
8584 \begin_inset Note Note
8585 status collapsed
8586
8587 \begin_layout List
8588 \labelwidthstring 00.00.0000
8589
8590 \series bold
8591 -
8592 \begin_inset ERT
8593 status open
8594
8595 \begin_layout Standard
8596
8597
8598 \backslash
8599 /
8600 \end_layout
8601
8602 \end_inset
8603
8604 -stack-8-bit - switches off the 10-bit mode
8605 \end_layout
8606
8607 \end_inset
8608
8609
8610 \end_layout
8611
8612 \begin_layout List
8613 \labelwidthstring 00.00.0000
8614
8615 \series bold
8616 -
8617 \begin_inset ERT
8618 status collapsed
8619
8620 \begin_layout Standard
8621
8622
8623 \backslash
8624 /
8625 \end_layout
8626
8627 \end_inset
8628
8629 -stack-probe
8630 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8631
8632 \end_inset
8633
8634
8635 \series default
8636  insert call to function __stack_probe at each function prologue.
8637 \end_layout
8638
8639 \begin_layout List
8640 \labelwidthstring 00.00.0000
8641
8642 \series bold
8643 -
8644 \begin_inset ERT
8645 status open
8646
8647 \begin_layout Standard
8648
8649
8650 \backslash
8651 /
8652 \end_layout
8653
8654 \end_inset
8655
8656 -tini-libid
8657 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8658
8659 \end_inset
8660
8661
8662 \series default
8663  <nnnn> LibraryID used in -mTININative.
8664  
8665 \end_layout
8666
8667 \begin_layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status collapsed
8674
8675 \begin_layout Standard
8676
8677
8678 \backslash
8679 /
8680 \end_layout
8681
8682 \end_inset
8683
8684 -use-accelerator
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8686
8687 \end_inset
8688
8689
8690 \series default
8691  generate code for DS390 Arithmetic Accelerator.
8692  
8693 \end_layout
8694
8695 \begin_layout Standard
8696 \begin_inset VSpace bigskip
8697 \end_inset
8698
8699
8700 \end_layout
8701
8702 \begin_layout Subsection
8703 Z80 Options
8704 \begin_inset LatexCommand \index{Options Z80}
8705
8706 \end_inset
8707
8708
8709 \begin_inset LatexCommand \index{Z80}
8710
8711 \end_inset
8712
8713
8714 \end_layout
8715
8716 \begin_layout List
8717 \labelwidthstring 00.00.0000
8718
8719 \series bold
8720 -
8721 \begin_inset ERT
8722 status collapsed
8723
8724 \begin_layout Standard
8725
8726
8727 \backslash
8728 /
8729 \end_layout
8730
8731 \end_inset
8732
8733 -callee-saves-bc
8734 \series default
8735
8736 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8737
8738 \end_inset
8739
8740
8741 \size large
8742 \emph on
8743  
8744 \size default
8745 \emph default
8746 Force a called function to always save BC.
8747 \end_layout
8748
8749 \begin_layout List
8750 \labelwidthstring 00.00.0000
8751
8752 \series bold
8753 -
8754 \begin_inset ERT
8755 status collapsed
8756
8757 \begin_layout Standard
8758
8759
8760 \backslash
8761 /
8762 \end_layout
8763
8764 \end_inset
8765
8766 -no-std-crt0
8767 \series default
8768
8769 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8770
8771 \end_inset
8772
8773  When linking, skip the standard crt0.o object file.
8774  You must provide your own crt0.o for your system when linking.
8775 \end_layout
8776
8777 \begin_layout List
8778 \labelwidthstring 00.00.0000
8779
8780 \series bold
8781 -
8782 \begin_inset ERT
8783 status collapsed
8784
8785 \begin_layout Standard
8786
8787
8788 \backslash
8789 /
8790 \end_layout
8791
8792 \end_inset
8793
8794 -portmode=
8795 \series default
8796 <Value>
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8798
8799 \end_inset
8800
8801  Determinate PORT I/O mode (<Value> is z80 or z180).
8802 \end_layout
8803
8804 \begin_layout List
8805 \labelwidthstring 00.00.0000
8806
8807 \series bold
8808 -
8809 \begin_inset ERT
8810 status collapsed
8811
8812 \begin_layout Standard
8813
8814
8815 \backslash
8816 /
8817 \end_layout
8818
8819 \end_inset
8820
8821 -asm=
8822 \series default
8823 <Value>
8824 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8825
8826 \end_inset
8827
8828  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8829 \end_layout
8830
8831 \begin_layout List
8832 \labelwidthstring 00.00.0000
8833
8834 \series bold
8835 -
8836 \begin_inset ERT
8837 status collapsed
8838
8839 \begin_layout Standard
8840
8841
8842 \backslash
8843 /
8844 \end_layout
8845
8846 \end_inset
8847
8848 -codeseg
8849 \series default
8850 \InsetSpace ~
8851 <Value>
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8853
8854 \end_inset
8855
8856  Use <Value> for the code segment name.
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -constseg
8877 \series default
8878 \InsetSpace ~
8879 <Value>
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8881
8882 \end_inset
8883
8884  Use <Value> for the const segment name.
8885 \end_layout
8886
8887 \begin_layout List
8888 \labelwidthstring 00.00.0000
8889 \begin_inset VSpace bigskip
8890 \end_inset
8891
8892
8893 \end_layout
8894
8895 \begin_layout Subsection
8896 GBZ80 Options
8897 \begin_inset LatexCommand \index{Options GBZ80}
8898
8899 \end_inset
8900
8901
8902 \begin_inset LatexCommand \index{GBZ80}
8903
8904 \end_inset
8905
8906
8907 \end_layout
8908
8909 \begin_layout List
8910 \labelwidthstring 00.00.0000
8911
8912 \series bold
8913 -
8914 \begin_inset ERT
8915 status collapsed
8916
8917 \begin_layout Standard
8918
8919
8920 \backslash
8921 /
8922 \end_layout
8923
8924 \end_inset
8925
8926 -callee-saves-bc
8927 \series default
8928
8929 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8930
8931 \end_inset
8932
8933
8934 \size large
8935 \emph on
8936  
8937 \size default
8938 \emph default
8939 Force a called function to always save BC.
8940 \end_layout
8941
8942 \begin_layout List
8943 \labelwidthstring 00.00.0000
8944
8945 \series bold
8946 -bo
8947 \series default
8948 \InsetSpace ~
8949 <Num>
8950 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8951
8952 \end_inset
8953
8954  Use code bank <Num>.
8955 \end_layout
8956
8957 \begin_layout List
8958 \labelwidthstring 00.00.0000
8959
8960 \series bold
8961 -ba
8962 \series default
8963 \InsetSpace ~
8964 <Num>
8965 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8966
8967 \end_inset
8968
8969  Use data bank <Num>.
8970 \end_layout
8971
8972 \begin_layout List
8973 \labelwidthstring 00.00.0000
8974
8975 \series bold
8976 -
8977 \begin_inset ERT
8978 status collapsed
8979
8980 \begin_layout Standard
8981
8982
8983 \backslash
8984 /
8985 \end_layout
8986
8987 \end_inset
8988
8989 -codeseg
8990 \series default
8991 \InsetSpace ~
8992 <Value>
8993 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8994
8995 \end_inset
8996
8997  Use <Value> for the code segment name.
8998 \end_layout
8999
9000 \begin_layout List
9001 \labelwidthstring 00.00.0000
9002
9003 \series bold
9004 -
9005 \begin_inset ERT
9006 status collapsed
9007
9008 \begin_layout Standard
9009
9010
9011 \backslash
9012 /
9013 \end_layout
9014
9015 \end_inset
9016
9017 -constseg
9018 \series default
9019 \InsetSpace ~
9020 <Value>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9022
9023 \end_inset
9024
9025  Use <Value> for the const segment name.
9026 \end_layout
9027
9028 \begin_layout Standard
9029 \begin_inset VSpace bigskip
9030 \end_inset
9031
9032
9033 \end_layout
9034
9035 \begin_layout Subsection
9036 Optimization Options
9037 \begin_inset LatexCommand \index{Options optimization}
9038
9039 \end_inset
9040
9041
9042 \begin_inset LatexCommand \index{Optimization options}
9043
9044 \end_inset
9045
9046
9047 \end_layout
9048
9049 \begin_layout List
9050 \labelwidthstring 00.00.0000
9051
9052 \series bold
9053 -
9054 \begin_inset ERT
9055 status collapsed
9056
9057 \begin_layout Standard
9058
9059
9060 \backslash
9061 /
9062 \end_layout
9063
9064 \end_inset
9065
9066 -nogcse
9067 \begin_inset LatexCommand \index{-\/-nogcse}
9068
9069 \end_inset
9070
9071
9072 \series default
9073  Will not do global subexpression elimination, this option may be used when
9074  the compiler creates undesirably large stack/data spaces to store compiler
9075  temporaries (
9076 \emph on
9077 s
9078 \emph default
9079 pill 
9080 \emph on
9081 loc
9082 \emph default
9083 ations, sloc
9084 \begin_inset LatexCommand \index{sloc (spill location)}
9085
9086 \end_inset
9087
9088 ).
9089  A warning message will be generated when this happens and the compiler
9090  will indicate the number of extra bytes it allocated.
9091  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9092 nogcse
9093 \begin_inset LatexCommand \index{\#pragma nogcse}
9094
9095 \end_inset
9096
9097  can be used to turn off global subexpression elimination
9098 \begin_inset LatexCommand \index{Subexpression elimination}
9099
9100 \end_inset
9101
9102  for a given function only.
9103 \end_layout
9104
9105 \begin_layout List
9106 \labelwidthstring 00.00.0000
9107
9108 \series bold
9109 -
9110 \begin_inset ERT
9111 status collapsed
9112
9113 \begin_layout Standard
9114
9115
9116 \backslash
9117 /
9118 \end_layout
9119
9120 \end_inset
9121
9122 -noinvariant
9123 \begin_inset LatexCommand \index{-\/-noinvariant}
9124
9125 \end_inset
9126
9127
9128 \series default
9129  Will not do loop invariant optimizations, this may be turned off for reasons
9130  explained for the previous option.
9131  For more details of loop optimizations performed see Loop Invariants in
9132  section 
9133 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9134
9135 \end_inset
9136
9137 .
9138  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9139 noinvariant
9140 \begin_inset LatexCommand \index{\#pragma noinvariant}
9141
9142 \end_inset
9143
9144  can be used to turn off invariant optimizations for a given function only.
9145 \end_layout
9146
9147 \begin_layout List
9148 \labelwidthstring 00.00.0000
9149
9150 \series bold
9151 -
9152 \begin_inset ERT
9153 status collapsed
9154
9155 \begin_layout Standard
9156
9157
9158 \backslash
9159 /
9160 \end_layout
9161
9162 \end_inset
9163
9164 -noinduction
9165 \begin_inset LatexCommand \index{-\/-noinduction}
9166
9167 \end_inset
9168
9169
9170 \series default
9171  Will not do loop induction optimizations, see section strength reduction
9172  for more details.
9173  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9174 noinduction
9175 \begin_inset LatexCommand \index{\#pragma noinduction}
9176
9177 \end_inset
9178
9179  can be used to turn off induction optimizations for a given function only.
9180 \end_layout
9181
9182 \begin_layout List
9183 \labelwidthstring 00.00.0000
9184
9185 \series bold
9186 -
9187 \begin_inset ERT
9188 status collapsed
9189
9190 \begin_layout Standard
9191
9192
9193 \backslash
9194 /
9195 \end_layout
9196
9197 \end_inset
9198
9199 -nojtbound
9200 \begin_inset LatexCommand \index{-\/-nojtbound}
9201
9202 \end_inset
9203
9204
9205 \size large
9206 \bar under
9207  
9208 \series default
9209 \size default
9210 \bar default
9211  Will not generate boundary condition check when switch statements
9212 \begin_inset LatexCommand \index{switch statement}
9213
9214 \end_inset
9215
9216  are implemented using jump-tables.
9217  See section 
9218 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9219
9220 \end_inset
9221
9222 \InsetSpace ~
9223 Switch Statements for more details.
9224  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9225 nojtbound
9226 \begin_inset LatexCommand \index{\#pragma nojtbound}
9227
9228 \end_inset
9229
9230  can be used to turn off boundary checking for jump tables for a given function
9231  only.
9232 \end_layout
9233
9234 \begin_layout List
9235 \labelwidthstring 00.00.0000
9236
9237 \series bold
9238 -
9239 \begin_inset ERT
9240 status collapsed
9241
9242 \begin_layout Standard
9243
9244
9245 \backslash
9246 /
9247 \end_layout
9248
9249 \end_inset
9250
9251 -noloopreverse
9252 \begin_inset LatexCommand \index{-\/-noloopreverse}
9253
9254 \end_inset
9255
9256
9257 \series default
9258 \size large
9259  
9260 \size default
9261 Will not do loop reversal 
9262 \begin_inset LatexCommand \index{Loop reversing}
9263
9264 \end_inset
9265
9266 optimization.
9267 \end_layout
9268
9269 \begin_layout List
9270 \labelwidthstring 00.00.0000
9271 -
9272 \begin_inset ERT
9273 status collapsed
9274
9275 \begin_layout Standard
9276
9277
9278 \backslash
9279 /
9280 \end_layout
9281
9282 \end_inset
9283
9284 -
9285 \series bold
9286 nolabelopt
9287 \series default
9288  
9289 \begin_inset LatexCommand \index{-\/-nolabelopt }
9290
9291 \end_inset
9292
9293 Will not optimize labels (makes the dumpfiles more readable).
9294 \end_layout
9295
9296 \begin_layout List
9297 \labelwidthstring 00.00.0000
9298
9299 \series bold
9300 -
9301 \begin_inset ERT
9302 status collapsed
9303
9304 \begin_layout Standard
9305
9306
9307 \backslash
9308 /
9309 \end_layout
9310
9311 \end_inset
9312
9313 -no-xinit-opt
9314 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9315
9316 \end_inset
9317
9318
9319 \series default
9320  Will not memcpy initialized data from code space into xdata space.
9321  This saves a few bytes in code space if you don't have initialized data
9322 \begin_inset LatexCommand \index{Variable initialization}
9323
9324 \end_inset
9325
9326 .
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 -nooverlay
9347 \begin_inset LatexCommand \index{-\/-nooverlay}
9348
9349 \end_inset
9350
9351
9352 \series default
9353   The compiler will not overlay parameters and local variables of any function,
9354  see section Parameters and local variables for more details.
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 -no-peep
9375 \begin_inset LatexCommand \index{-\/-no-peep}
9376
9377 \end_inset
9378
9379
9380 \series default
9381  Disable peep-hole optimization with built-in rules.
9382 \end_layout
9383
9384 \begin_layout List
9385 \labelwidthstring 00.00.0000
9386
9387 \series bold
9388 -
9389 \begin_inset ERT
9390 status collapsed
9391
9392 \begin_layout Standard
9393
9394
9395 \backslash
9396 /
9397 \end_layout
9398
9399 \end_inset
9400
9401 -peep-file
9402 \series default
9403
9404 \begin_inset LatexCommand \index{-\/-peep-file}
9405
9406 \end_inset
9407
9408 \InsetSpace ~
9409 <filename> This option can be used to use additional rules to be used by
9410  the peep hole optimizer.
9411  See section 
9412 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9413
9414 \end_inset
9415
9416 \InsetSpace ~
9417 Peep Hole optimizations for details on how to write these rules.
9418 \end_layout
9419
9420 \begin_layout List
9421 \labelwidthstring 00.00.0000
9422
9423 \series bold
9424 -
9425 \begin_inset ERT
9426 status collapsed
9427
9428 \begin_layout Standard
9429
9430
9431 \backslash
9432 /
9433 \end_layout
9434
9435 \end_inset
9436
9437 -peep-asm
9438 \begin_inset LatexCommand \index{-\/-peep-asm}
9439
9440 \end_inset
9441
9442
9443 \series default
9444  Pass the inline assembler code through the peep hole optimizer.
9445  This can cause unexpected changes to inline assembler code, please go through
9446  the peephole optimizer
9447 \begin_inset LatexCommand \index{Peephole optimizer}
9448
9449 \end_inset
9450
9451  rules defined in the source file tree '<target>/peeph.def' before using
9452  this option.
9453 \end_layout
9454
9455 \begin_layout List
9456 \labelwidthstring 00.00.0000
9457
9458 \series bold
9459 -
9460 \begin_inset ERT
9461 status collapsed
9462
9463 \begin_layout Standard
9464
9465
9466 \backslash
9467 /
9468 \end_layout
9469
9470 \end_inset
9471
9472 -opt-code-speed
9473 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9474
9475 \end_inset
9476
9477
9478 \series default
9479  The compiler will optimize code generation towards fast code, possibly
9480  at the expense of code size.
9481 \end_layout
9482
9483 \begin_layout List
9484 \labelwidthstring 00.00.0000
9485
9486 \series bold
9487 -
9488 \begin_inset ERT
9489 status collapsed
9490
9491 \begin_layout Standard
9492
9493
9494 \backslash
9495 /
9496 \end_layout
9497
9498 \end_inset
9499
9500 -opt-code-size
9501 \begin_inset LatexCommand \index{-\/-opt-code-size}
9502
9503 \end_inset
9504
9505
9506 \series default
9507  The compiler will optimize code generation towards compact code, possibly
9508  at the expense of code speed.
9509 \end_layout
9510
9511 \begin_layout Standard
9512 \begin_inset VSpace bigskip
9513 \end_inset
9514
9515
9516 \end_layout
9517
9518 \begin_layout Subsection
9519 Other Options
9520 \begin_inset LatexCommand \index{Options other}
9521
9522 \end_inset
9523
9524
9525 \end_layout
9526
9527 \begin_layout List
9528 \labelwidthstring 00.00.0000
9529
9530 \series bold
9531 -c\InsetSpace ~
9532 -
9533 \begin_inset ERT
9534 status collapsed
9535
9536 \begin_layout Standard
9537
9538
9539 \backslash
9540 /
9541 \end_layout
9542
9543 \end_inset
9544
9545 -compile-only
9546 \begin_inset LatexCommand \index{-\/-compile-only}
9547
9548 \end_inset
9549
9550
9551 \begin_inset LatexCommand \index{-c -\/-compile-only}
9552
9553 \end_inset
9554
9555
9556 \series default
9557  will compile and assemble the source, but will not call the linkage editor.
9558 \end_layout
9559
9560 \begin_layout List
9561 \labelwidthstring 00.00.0000
9562
9563 \series bold
9564 -
9565 \series default
9566
9567 \begin_inset ERT
9568 status collapsed
9569
9570 \begin_layout Standard
9571
9572
9573 \backslash
9574 /
9575 \end_layout
9576
9577 \end_inset
9578
9579
9580 \series bold
9581 -c1mode
9582 \begin_inset LatexCommand \index{-\/-c1mode}
9583
9584 \end_inset
9585
9586
9587 \series default
9588  reads the preprocessed source from standard input and compiles it.
9589  The file name for the assembler output must be specified using the -o option.
9590 \end_layout
9591
9592 \begin_layout List
9593 \labelwidthstring 00.00.0000
9594
9595 \series bold
9596 -E
9597 \begin_inset LatexCommand \index{-E}
9598
9599 \end_inset
9600
9601
9602 \series default
9603  Run only the C preprocessor.
9604  Preprocess all the C source files specified and output the results to standard
9605  output.
9606 \end_layout
9607
9608 \begin_layout List
9609 \labelwidthstring 00.00.0000
9610
9611 \series bold
9612 -o\InsetSpace ~
9613 <path/file>
9614 \begin_inset LatexCommand \index{-o <path/file>}
9615
9616 \end_inset
9617
9618  
9619 \series default
9620 The output path where everything will be placed or the file name used for
9621  all generated output files.
9622  If the parameter is a path, it must have a trailing slash (or backslash
9623  for the Windows binaries) to be recognized as a path.
9624
9625 \emph on
9626  
9627 \emph default
9628 Note for Windows users: if the path contains spaces, it should be surrounded
9629  by quotes.
9630  The trailing backslash should be doubled in order to prevent escaping the
9631  final quote, for example: 
9632 \emph on
9633 -o 
9634 \begin_inset Quotes sld
9635 \end_inset
9636
9637 F:
9638 \backslash
9639 Projects
9640 \backslash
9641 test3
9642 \backslash
9643 output 1
9644 \backslash
9645
9646 \backslash
9647
9648 \begin_inset Quotes srd
9649 \end_inset
9650
9651
9652 \emph default
9653  or put after the final quote, for example: 
9654 \emph on
9655 -o 
9656 \begin_inset Quotes sld
9657 \end_inset
9658
9659 F:
9660 \backslash
9661 Projects
9662 \backslash
9663 test3
9664 \backslash
9665 output 1
9666 \begin_inset Quotes srd
9667 \end_inset
9668
9669
9670 \backslash
9671
9672 \emph default
9673 .
9674  The path using slashes for directory delimiters can be used too, for example:
9675  
9676 \emph on
9677 -o 
9678 \begin_inset Quotes sld
9679 \end_inset
9680
9681 F:/Projects/test3/output 1/
9682 \begin_inset Quotes srd
9683 \end_inset
9684
9685
9686 \emph default
9687 .
9688 \end_layout
9689
9690 \begin_layout List
9691 \labelwidthstring 00.00.0000
9692
9693 \series bold
9694 -
9695 \begin_inset ERT
9696 status collapsed
9697
9698 \begin_layout Standard
9699
9700
9701 \backslash
9702 /
9703 \end_layout
9704
9705 \end_inset
9706
9707 -stack-auto
9708 \begin_inset LatexCommand \index{-\/-stack-auto}
9709
9710 \end_inset
9711
9712
9713 \series default
9714 \size large
9715 \emph on
9716  
9717 \size default
9718 \emph default
9719 All functions in the source file will be compiled as 
9720 \emph on
9721 reentrant
9722 \emph default
9723
9724 \begin_inset LatexCommand \index{reentrant}
9725
9726 \end_inset
9727
9728 , i.e.
9729  the parameters and local variables will be allocated on the stack
9730 \begin_inset LatexCommand \index{stack}
9731
9732 \end_inset
9733
9734 .
9735  See section 
9736 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9737
9738 \end_inset
9739
9740  Parameters and Local Variables for more details.
9741  If this option is used all source files in the project should be compiled
9742  with this option.
9743  It automatically implies -
9744 \series bold
9745
9746 \begin_inset ERT
9747 status open
9748
9749 \begin_layout Standard
9750
9751
9752 \backslash
9753 /
9754 \end_layout
9755
9756 \end_inset
9757
9758
9759 \series default
9760 -int-long-reent and -
9761 \series bold
9762
9763 \begin_inset ERT
9764 status open
9765
9766 \begin_layout Standard
9767
9768
9769 \backslash
9770 /
9771 \end_layout
9772
9773 \end_inset
9774
9775
9776 \series default
9777 -float-reent.
9778  
9779 \end_layout
9780
9781 \begin_layout List
9782 \labelwidthstring 00.00.0000
9783
9784 \series bold
9785 -
9786 \begin_inset ERT
9787 status collapsed
9788
9789 \begin_layout Standard
9790
9791
9792 \backslash
9793 /
9794 \end_layout
9795
9796 \end_inset
9797
9798 -callee-saves
9799 \begin_inset LatexCommand \index{-\/-callee-saves}
9800
9801 \end_inset
9802
9803  
9804 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9805
9806 \end_inset
9807
9808 function1[,function2][,function3]....
9809
9810 \series default
9811  The compiler by default uses a caller saves convention for register saving
9812  across function calls, however this can cause unnecessary register pushing
9813  and popping when calling small functions from larger functions.
9814  This option can be used to switch the register saving convention for the
9815  function names specified.
9816  The compiler will not save registers when calling these functions, no extra
9817  code will be generated at the entry and exit (function prologue
9818 \series bold
9819
9820 \begin_inset LatexCommand \index{function prologue}
9821
9822 \end_inset
9823
9824
9825 \series default
9826  and epilogue
9827 \series bold
9828
9829 \begin_inset LatexCommand \index{function epilogue}
9830
9831 \end_inset
9832
9833
9834 \series default
9835 ) for these functions to save and restore the registers used by these functions,
9836  this can SUBSTANTIALLY reduce code and improve run time performance of
9837  the generated code.
9838  In the future the compiler (with inter procedural analysis) will be able
9839  to determine the appropriate scheme to use for each function call.
9840  DO NOT use this option for built-in functions such as _mulint..., if this
9841  option is used for a library function the appropriate library function
9842  needs to be recompiled with the same option.
9843  If the project consists of multiple source files then all the source file
9844  should be compiled with the same -
9845 \begin_inset ERT
9846 status collapsed
9847
9848 \begin_layout Standard
9849
9850
9851 \backslash
9852 /
9853 \end_layout
9854
9855 \end_inset
9856
9857 -callee-saves option string.
9858  Also see #pragma\InsetSpace ~
9859 callee_saves 
9860 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9861
9862 \end_inset
9863
9864  
9865 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9866
9867 \end_inset
9868
9869 .
9870 \end_layout
9871
9872 \begin_layout List
9873 \labelwidthstring 00.00.0000
9874
9875 \series bold
9876 -
9877 \begin_inset ERT
9878 status collapsed
9879
9880 \begin_layout Standard
9881
9882
9883 \backslash
9884 /
9885 \end_layout
9886
9887 \end_inset
9888
9889 -all-callee-saves
9890 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9891
9892 \end_inset
9893
9894  
9895 \series default
9896 Function of
9897 \series bold
9898  
9899 \series default
9900 -
9901 \begin_inset ERT
9902 status collapsed
9903
9904 \begin_layout Standard
9905
9906
9907 \backslash
9908 /
9909 \end_layout
9910
9911 \end_inset
9912
9913 -callee-saves will be applied to all functions by default.
9914 \end_layout
9915
9916 \begin_layout List
9917 \labelwidthstring 00.00.0000
9918
9919 \series bold
9920 -
9921 \begin_inset ERT
9922 status collapsed
9923
9924 \begin_layout Standard
9925
9926
9927 \backslash
9928 /
9929 \end_layout
9930
9931 \end_inset
9932
9933 -debug
9934 \begin_inset LatexCommand \index{-\/-debug}
9935
9936 \end_inset
9937
9938
9939 \bar under
9940  
9941 \series default
9942 \bar default
9943 When this option is used the compiler will generate debug information.
9944  The debug information collected in a file with .cdb extension can be used
9945  with the SDCDB.
9946  For more information see documentation for SDCDB.
9947  Another file with no extension contains debug information in AOMF or AOMF51
9948 \begin_inset LatexCommand \index{AOMF, AOMF51}
9949
9950 \end_inset
9951
9952  format which is commonly used by third party tools.
9953 \end_layout
9954
9955 \begin_layout List
9956 \labelwidthstring 00.00.0000
9957
9958 \series bold
9959 -S
9960 \begin_inset LatexCommand \index{-S}
9961
9962 \end_inset
9963
9964
9965 \size large
9966 \bar under
9967  
9968 \series default
9969 \size default
9970 \bar default
9971 Stop after the stage of compilation proper; do not assemble.
9972  The output is an assembler code file for the input file specified.
9973 \end_layout
9974
9975 \begin_layout List
9976 \labelwidthstring 00.00.0000
9977
9978 \series bold
9979 -
9980 \begin_inset ERT
9981 status collapsed
9982
9983 \begin_layout Standard
9984
9985
9986 \backslash
9987 /
9988 \end_layout
9989
9990 \end_inset
9991
9992 -int-long-reent
9993 \begin_inset LatexCommand \index{-\/-int-long-reent}
9994
9995 \end_inset
9996
9997
9998 \series default
9999  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10000  Note by default these libraries are compiled as non-reentrant.
10001  See section Installation for more details.
10002 \end_layout
10003
10004 \begin_layout List
10005 \labelwidthstring 00.00.0000
10006
10007 \series bold
10008 -
10009 \begin_inset ERT
10010 status collapsed
10011
10012 \begin_layout Standard
10013
10014
10015 \backslash
10016 /
10017 \end_layout
10018
10019 \end_inset
10020
10021 -cyclomatic
10022 \begin_inset LatexCommand \index{-\/-cyclomatic}
10023
10024 \end_inset
10025
10026
10027 \bar under
10028  
10029 \series default
10030 \bar default
10031 This option will cause the compiler to generate an information message for
10032  each function in the source file.
10033  The message contains some 
10034 \emph on
10035 important
10036 \emph default
10037  information about the function.
10038  The number of edges and nodes the compiler detected in the control flow
10039  graph of the function, and most importantly the 
10040 \emph on
10041 cyclomatic complexity
10042 \begin_inset LatexCommand \index{Cyclomatic complexity}
10043
10044 \end_inset
10045
10046
10047 \emph default
10048  see section on Cyclomatic Complexity for more details.
10049 \end_layout
10050
10051 \begin_layout List
10052 \labelwidthstring 00.00.0000
10053
10054 \series bold
10055 -
10056 \begin_inset ERT
10057 status collapsed
10058
10059 \begin_layout Standard
10060
10061
10062 \backslash
10063 /
10064 \end_layout
10065
10066 \end_inset
10067
10068 -float-reent
10069 \begin_inset LatexCommand \index{-\/-float-reent}
10070
10071 \end_inset
10072
10073
10074 \series default
10075  Floating point library is compiled as reentrant
10076 \begin_inset LatexCommand \index{reentrant}
10077
10078 \end_inset
10079
10080 .
10081  See section Installation for more details.
10082 \end_layout
10083
10084 \begin_layout List
10085 \labelwidthstring 00.00.0000
10086
10087 \series bold
10088 -
10089 \begin_inset ERT
10090 status collapsed
10091
10092 \begin_layout Standard
10093
10094
10095 \backslash
10096 /
10097 \end_layout
10098
10099 \end_inset
10100
10101 -funsigned-char
10102 \begin_inset LatexCommand \index{-\/-funsigned-char}
10103
10104 \end_inset
10105
10106
10107 \series default
10108  The default signedness for every type is
10109 \family typewriter
10110  signed
10111 \family default
10112 .
10113  In some embedded environments the default signedness of
10114 \family typewriter
10115  char
10116 \family default
10117  is
10118 \family typewriter
10119  unsigned
10120 \family default
10121 .
10122  To set the signess for characters to unsigned, use the option -
10123 \series bold
10124
10125 \begin_inset ERT
10126 status open
10127
10128 \begin_layout Standard
10129
10130
10131 \backslash
10132 /
10133 \end_layout
10134
10135 \end_inset
10136
10137
10138 \series default
10139 -funsigned-char.
10140  If this option is set and no signedness keyword (unsigned/signed) is given,
10141  a char will be signed.
10142  All other types are unaffected.
10143 \end_layout
10144
10145 \begin_layout List
10146 \labelwidthstring 00.00.0000
10147
10148 \series bold
10149 -
10150 \begin_inset ERT
10151 status collapsed
10152
10153 \begin_layout Standard
10154
10155
10156 \backslash
10157 /
10158 \end_layout
10159
10160 \end_inset
10161
10162 -main-return
10163 \begin_inset LatexCommand \index{-\/-main-return}
10164
10165 \end_inset
10166
10167
10168 \series default
10169  This option can be used if the code generated is called by a monitor program
10170  or if the main routine includes an endless loop.
10171  This option results in slightly smaller code and saves two bytes of stack
10172  space.
10173  The return from the 'main'
10174 \begin_inset LatexCommand \index{main return}
10175
10176 \end_inset
10177
10178  function will return to the function calling main.
10179  The default setting is to lock up i.e.
10180  generate a '
10181 \family typewriter
10182 sjmp .
10183 \family default
10184 '.
10185 \end_layout
10186
10187 \begin_layout List
10188 \labelwidthstring 00.00.0000
10189
10190 \series bold
10191 -
10192 \begin_inset ERT
10193 status collapsed
10194
10195 \begin_layout Standard
10196
10197
10198 \backslash
10199 /
10200 \end_layout
10201
10202 \end_inset
10203
10204 -nostdinc
10205 \begin_inset LatexCommand \index{-\/-nostdinc}
10206
10207 \end_inset
10208
10209
10210 \series default
10211  This will prevent the compiler from passing on the default include path
10212  to the preprocessor.
10213 \end_layout
10214
10215 \begin_layout List
10216 \labelwidthstring 00.00.0000
10217
10218 \series bold
10219 -
10220 \begin_inset ERT
10221 status collapsed
10222
10223 \begin_layout Standard
10224
10225
10226 \backslash
10227 /
10228 \end_layout
10229
10230 \end_inset
10231
10232 -nostdlib
10233 \begin_inset LatexCommand \index{-\/-nostdlib}
10234
10235 \end_inset
10236
10237
10238 \series default
10239  This will prevent the compiler from passing on the default library
10240 \begin_inset LatexCommand \index{Libraries}
10241
10242 \end_inset
10243
10244  path to the linker.
10245 \end_layout
10246
10247 \begin_layout List
10248 \labelwidthstring 00.00.0000
10249
10250 \series bold
10251 -
10252 \begin_inset ERT
10253 status collapsed
10254
10255 \begin_layout Standard
10256
10257
10258 \backslash
10259 /
10260 \end_layout
10261
10262 \end_inset
10263
10264 -verbose
10265 \begin_inset LatexCommand \index{-\/-verbose}
10266
10267 \end_inset
10268
10269
10270 \series default
10271  Shows the various actions the compiler is performing.
10272 \end_layout
10273
10274 \begin_layout List
10275 \labelwidthstring 00.00.0000
10276
10277 \series bold
10278 -V
10279 \begin_inset LatexCommand \index{-V}
10280
10281 \end_inset
10282
10283
10284 \series default
10285  Shows the actual commands the compiler is executing.
10286 \end_layout
10287
10288 \begin_layout List
10289 \labelwidthstring 00.00.0000
10290
10291 \series bold
10292 -
10293 \begin_inset ERT
10294 status collapsed
10295
10296 \begin_layout Standard
10297
10298
10299 \backslash
10300 /
10301 \end_layout
10302
10303 \end_inset
10304
10305 -no-c-code-in-asm
10306 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10307
10308 \end_inset
10309
10310
10311 \series default
10312  Hides your ugly and inefficient c-code from the asm file, so you can always
10313  blame the compiler :)
10314 \end_layout
10315
10316 \begin_layout List
10317 \labelwidthstring 00.00.0000
10318
10319 \series bold
10320 -
10321 \begin_inset ERT
10322 status collapsed
10323
10324 \begin_layout Standard
10325
10326
10327 \backslash
10328 /
10329 \end_layout
10330
10331 \end_inset
10332
10333 -fverbose-asm
10334 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10335
10336 \end_inset
10337
10338
10339 \series default
10340  Include code generator and peep-hole comments in the generated asm files.
10341 \end_layout
10342
10343 \begin_layout List
10344 \labelwidthstring 00.00.0000
10345
10346 \series bold
10347 -
10348 \begin_inset ERT
10349 status collapsed
10350
10351 \begin_layout Standard
10352
10353
10354 \backslash
10355 /
10356 \end_layout
10357
10358 \end_inset
10359
10360 -no-peep-comments
10361 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10362
10363 \end_inset
10364
10365
10366 \series default
10367  Don't include peep-hole comments in the generated asm files even if -
10368 \series bold
10369
10370 \begin_inset ERT
10371 status open
10372
10373 \begin_layout Standard
10374
10375
10376 \backslash
10377 /
10378 \end_layout
10379
10380 \end_inset
10381
10382
10383 \series default
10384 -fverbose-asm option is specified.
10385 \end_layout
10386
10387 \begin_layout List
10388 \labelwidthstring 00.00.0000
10389
10390 \series bold
10391 -
10392 \begin_inset ERT
10393 status collapsed
10394
10395 \begin_layout Standard
10396
10397
10398 \backslash
10399 /
10400 \end_layout
10401
10402 \end_inset
10403
10404 -i-code-in-asm
10405 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10406
10407 \end_inset
10408
10409
10410 \series default
10411  Include i-codes in the asm file.
10412  Sounds like noise but is most helpful for debugging the compiler itself.
10413 \end_layout
10414
10415 \begin_layout List
10416 \labelwidthstring 00.00.0000
10417
10418 \series bold
10419 -
10420 \begin_inset ERT
10421 status collapsed
10422
10423 \begin_layout Standard
10424
10425
10426 \backslash
10427 /
10428 \end_layout
10429
10430 \end_inset
10431
10432 -less-pedantic
10433 \begin_inset LatexCommand \index{pedantic}
10434
10435 \end_inset
10436
10437
10438 \begin_inset LatexCommand \index{-\/-less-pedantic}
10439
10440 \end_inset
10441
10442
10443 \series default
10444
10445 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10446
10447 \end_inset
10448
10449  Disable some of the more pedantic warnings
10450 \begin_inset LatexCommand \index{Warnings}
10451
10452 \end_inset
10453
10454 .
10455  For more details, see the less_pedantic pragma 
10456 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10457
10458 \end_inset
10459
10460 .
10461 \end_layout
10462
10463 \begin_layout List
10464 \labelwidthstring 00.00.0000
10465
10466 \series bold
10467 -
10468 \begin_inset ERT
10469 status collapsed
10470
10471 \begin_layout Standard
10472
10473
10474 \backslash
10475 /
10476 \end_layout
10477
10478 \end_inset
10479
10480 -disable-warning\InsetSpace ~
10481 <nnnn>
10482 \begin_inset LatexCommand \index{-\/-disable-warning}
10483
10484 \end_inset
10485
10486
10487 \series default
10488  Disable specific warning with number <nnnn>.
10489 \end_layout
10490
10491 \begin_layout List
10492 \labelwidthstring 00.00.0000
10493
10494 \series bold
10495 -
10496 \begin_inset ERT
10497 status collapsed
10498
10499 \begin_layout Standard
10500
10501
10502 \backslash
10503 /
10504 \end_layout
10505
10506 \end_inset
10507
10508 -Werror
10509 \begin_inset LatexCommand \index{-\/-Werror}
10510
10511 \end_inset
10512
10513
10514 \series default
10515  Treat all warnings as errors.
10516 \end_layout
10517
10518 \begin_layout List
10519 \labelwidthstring 00.00.0000
10520
10521 \series bold
10522 -
10523 \begin_inset ERT
10524 status collapsed
10525
10526 \begin_layout Standard
10527
10528
10529 \backslash
10530 /
10531 \end_layout
10532
10533 \end_inset
10534
10535 -print-search-dirs
10536 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10537
10538 \end_inset
10539
10540
10541 \series default
10542  Display the directories in the compiler's search path
10543 \end_layout
10544
10545 \begin_layout List
10546 \labelwidthstring 00.00.0000
10547
10548 \series bold
10549 -
10550 \begin_inset ERT
10551 status collapsed
10552
10553 \begin_layout Standard
10554
10555
10556 \backslash
10557 /
10558 \end_layout
10559
10560 \end_inset
10561
10562 -vc
10563 \begin_inset LatexCommand \index{-\/-vc}
10564
10565 \end_inset
10566
10567
10568 \series default
10569  Display errors and warnings using MSVC style, so you can use SDCC with
10570  the visual studio IDE
10571 \begin_inset LatexCommand \index{IDE}
10572
10573 \end_inset
10574
10575 .
10576  With SDCC both offering a GCC-like (the default) and a MSVC-like
10577 \begin_inset LatexCommand \index{MSVC output style}
10578
10579 \end_inset
10580
10581  output style, integration into most programming editors should be straightforwa
10582 rd.
10583 \end_layout
10584
10585 \begin_layout List
10586 \labelwidthstring 00.00.0000
10587
10588 \series bold
10589 -
10590 \begin_inset ERT
10591 status collapsed
10592
10593 \begin_layout Standard
10594
10595
10596 \backslash
10597 /
10598 \end_layout
10599
10600 \end_inset
10601
10602 -use-stdout
10603 \begin_inset LatexCommand \index{-\/-use-stdout}
10604
10605 \end_inset
10606
10607
10608 \series default
10609  Send errors and warnings to stdout instead of stderr.
10610 \end_layout
10611
10612 \begin_layout List
10613 \labelwidthstring 00.00.0000
10614
10615 \series bold
10616 -Wa\InsetSpace ~
10617 asmOption[,asmOption]
10618 \series default
10619
10620 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10621
10622 \end_inset
10623
10624 ...
10625  Pass the asmOption to the assembler
10626 \begin_inset LatexCommand \index{Options assembler}
10627
10628 \end_inset
10629
10630
10631 \begin_inset LatexCommand \index{Assembler options}
10632
10633 \end_inset
10634
10635 .
10636  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10637 \end_layout
10638
10639 \begin_layout List
10640 \labelwidthstring 00.00.0000
10641
10642 \series bold
10643 -
10644 \begin_inset ERT
10645 status collapsed
10646
10647 \begin_layout Standard
10648
10649
10650 \backslash
10651 /
10652 \end_layout
10653
10654 \end_inset
10655
10656 -std-sdcc89
10657 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10658
10659 \end_inset
10660
10661
10662 \series default
10663  Generally follow the C89 standard, but allow SDCC features that conflict
10664  with the standard (default).
10665 \end_layout
10666
10667 \begin_layout List
10668 \labelwidthstring 00.00.0000
10669
10670 \series bold
10671 -
10672 \begin_inset ERT
10673 status collapsed
10674
10675 \begin_layout Standard
10676
10677
10678 \backslash
10679 /
10680 \end_layout
10681
10682 \end_inset
10683
10684 -std-c89
10685 \begin_inset LatexCommand \index{-\/-std-c89}
10686
10687 \end_inset
10688
10689
10690 \series default
10691  Follow the C89 standard and disable SDCC features that conflict with the
10692  standard.
10693 \end_layout
10694
10695 \begin_layout List
10696 \labelwidthstring 00.00.0000
10697
10698 \series bold
10699 -
10700 \begin_inset ERT
10701 status collapsed
10702
10703 \begin_layout Standard
10704
10705
10706 \backslash
10707 /
10708 \end_layout
10709
10710 \end_inset
10711
10712 -std-sdcc99
10713 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10714
10715 \end_inset
10716
10717
10718 \series default
10719  Generally follow the C99 standard, but allow SDCC features that conflict
10720  with the standard (incomplete support).
10721 \end_layout
10722
10723 \begin_layout List
10724 \labelwidthstring 00.00.0000
10725
10726 \series bold
10727 -
10728 \begin_inset ERT
10729 status collapsed
10730
10731 \begin_layout Standard
10732
10733
10734 \backslash
10735 /
10736 \end_layout
10737
10738 \end_inset
10739
10740 -std-c99
10741 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10742
10743 \end_inset
10744
10745
10746 \series default
10747  Follow the C99 standard and disable SDCC features that conflict with the
10748  standard (incomplete support).
10749 \end_layout
10750
10751 \begin_layout List
10752 \labelwidthstring 00.00.0000
10753
10754 \series bold
10755 -
10756 \begin_inset ERT
10757 status collapsed
10758
10759 \begin_layout Standard
10760
10761
10762 \backslash
10763 /
10764 \end_layout
10765
10766 \end_inset
10767
10768 -codeseg
10769 \series default
10770
10771 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10772
10773 \end_inset
10774
10775 \InsetSpace ~
10776 <Name> The name to be used for the code
10777 \begin_inset LatexCommand \index{code}
10778
10779 \end_inset
10780
10781  segment, default CSEG.
10782  This is useful if you need to tell the compiler to put the code in a special
10783  segment so you can later on tell the linker to put this segment in a special
10784  place in memory.
10785  Can be used for instance when using bank switching to put the code in a
10786  bank.
10787 \end_layout
10788
10789 \begin_layout List
10790 \labelwidthstring 00.00.0000
10791
10792 \series bold
10793 -
10794 \begin_inset ERT
10795 status collapsed
10796
10797 \begin_layout Standard
10798
10799
10800 \backslash
10801 /
10802 \end_layout
10803
10804 \end_inset
10805
10806 -constseg
10807 \series default
10808
10809 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10810
10811 \end_inset
10812
10813 \InsetSpace ~
10814 <Name> The name to be used for the const
10815 \begin_inset LatexCommand \index{const}
10816
10817 \end_inset
10818
10819  segment, default CONST.
10820  This is useful if you need to tell the compiler to put the const data in
10821  a special segment so you can later on tell the linker to put this segment
10822  in a special place in memory.
10823  Can be used for instance when using bank switching to put the const data
10824  in a bank.
10825 \end_layout
10826
10827 \begin_layout List
10828 \labelwidthstring 00.00.0000
10829
10830 \series bold
10831 -
10832 \begin_inset ERT
10833 status collapsed
10834
10835 \begin_layout Standard
10836
10837
10838 \backslash
10839 /
10840 \end_layout
10841
10842 \end_inset
10843
10844 -fdollars-in-identifiers
10845 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10846
10847 \end_inset
10848
10849
10850 \series default
10851  Permit '$' as an identifier character.
10852 \end_layout
10853
10854 \begin_layout List
10855 \labelwidthstring 00.00.0000
10856
10857 \series bold
10858 -
10859 \begin_inset ERT
10860 status collapsed
10861
10862 \begin_layout Standard
10863
10864
10865 \backslash
10866 /
10867 \end_layout
10868
10869 \end_inset
10870
10871 -more-pedantic
10872 \series default
10873
10874 \begin_inset LatexCommand \index{-\/-more-pedantic}
10875
10876 \end_inset
10877
10878
10879 \begin_inset LatexCommand \index{pedantic}
10880
10881 \end_inset
10882
10883  Actually this is 
10884 \series bold
10885 \emph on
10886 not
10887 \series default
10888 \emph default
10889  a SDCC compiler option but if you want 
10890 \emph on
10891 more
10892 \emph default
10893  warnings you can use a separate tool dedicated to syntax checking like
10894  splint
10895 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10896
10897 \end_inset
10898
10899
10900 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10901
10902 \end_inset
10903
10904  
10905 \begin_inset LatexCommand \url{http://www.splint.org}
10906
10907 \end_inset
10908
10909 .
10910  To make your source files parseable by splint you will have to include
10911  
10912 \family sans
10913 lint.h
10914 \family default
10915
10916 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10917
10918 \end_inset
10919
10920  in your source file and add brackets around extended keywords (like 
10921 \family sans
10922
10923 \begin_inset Quotes sld
10924 \end_inset
10925
10926 __at\InsetSpace ~
10927
10928 \series bold
10929 (
10930 \series default
10931 0xab
10932 \series bold
10933 )
10934 \series default
10935
10936 \begin_inset Quotes srd
10937 \end_inset
10938
10939
10940 \family default
10941  and 
10942 \family sans
10943
10944 \begin_inset Quotes sld
10945 \end_inset
10946
10947 __interrupt\InsetSpace ~
10948 (2)
10949 \begin_inset Quotes srd
10950 \end_inset
10951
10952
10953 \family default
10954 ).
10955  
10956 \newline
10957 Splint has an excellent on line manual at 
10958 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10959
10960 \end_inset
10961
10962  and it's capabilities go beyond pure syntax checking.
10963  You'll need to tell splint the location of SDCC's include files so a typical
10964  command line could look like this: 
10965 \newline
10966
10967 \family sans
10968 splint\InsetSpace ~
10969 -I\InsetSpace ~
10970 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10971 \InsetSpace ~
10972 myprogram.c
10973 \end_layout
10974
10975 \begin_layout List
10976 \labelwidthstring 00.00.0000
10977
10978 \series bold
10979 -
10980 \begin_inset ERT
10981 status collapsed
10982
10983 \begin_layout Standard
10984
10985
10986 \backslash
10987 /
10988 \end_layout
10989
10990 \end_inset
10991
10992 -short-is-8bits
10993 \series default
10994
10995 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10996
10997 \end_inset
10998
10999
11000 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11001
11002 \end_inset
11003
11004  Treat short as 8-bit (for backward compatibility with older versions of
11005  compiler - see section 
11006 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11007
11008 \end_inset
11009
11010 )
11011 \end_layout
11012
11013 \begin_layout Standard
11014 \begin_inset VSpace bigskip
11015 \end_inset
11016
11017
11018 \end_layout
11019
11020 \begin_layout Subsection
11021 Intermediate Dump Options
11022 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11023
11024 \end_inset
11025
11026
11027 \begin_inset LatexCommand \index{Options intermediate dump}
11028
11029 \end_inset
11030
11031
11032 \begin_inset LatexCommand \index{Intermediate dump options}
11033
11034 \end_inset
11035
11036
11037 \end_layout
11038
11039 \begin_layout Standard
11040 The following options are provided for the purpose of retargetting and debugging
11041  the compiler.
11042  They provide a means to dump the intermediate code (iCode
11043 \begin_inset LatexCommand \index{iCode}
11044
11045 \end_inset
11046
11047 ) generated by the compiler in human readable form at various stages of
11048  the compilation process.
11049  More on iCodes see chapter 
11050 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11051
11052 \end_inset
11053
11054  
11055 \begin_inset Quotes srd
11056 \end_inset
11057
11058 The anatomy of the compiler
11059 \begin_inset Quotes srd
11060 \end_inset
11061
11062 .
11063 \end_layout
11064
11065 \begin_layout List
11066 \labelwidthstring 00.00.0000
11067
11068 \series bold
11069 -
11070 \begin_inset ERT
11071 status collapsed
11072
11073 \begin_layout Standard
11074
11075
11076 \backslash
11077 /
11078 \end_layout
11079
11080 \end_inset
11081
11082 -dumpraw
11083 \begin_inset LatexCommand \index{-\/-dumpraw}
11084
11085 \end_inset
11086
11087
11088 \series default
11089  This option will cause the compiler to dump the intermediate code into
11090  a file of named 
11091 \emph on
11092 <source filename>.dumpraw
11093 \emph default
11094  just after the intermediate code has been generated for a function, i.e.
11095  before any optimizations are done.
11096  The basic blocks
11097 \begin_inset LatexCommand \index{Basic blocks}
11098
11099 \end_inset
11100
11101  at this stage ordered in the depth first number, so they may not be in
11102  sequence of execution.
11103 \end_layout
11104
11105 \begin_layout List
11106 \labelwidthstring 00.00.0000
11107
11108 \series bold
11109 -
11110 \begin_inset ERT
11111 status collapsed
11112
11113 \begin_layout Standard
11114
11115
11116 \backslash
11117 /
11118 \end_layout
11119
11120 \end_inset
11121
11122 -dumpgcse
11123 \begin_inset LatexCommand \index{-\/-dumpgcse}
11124
11125 \end_inset
11126
11127
11128 \series default
11129  Will create a dump of iCodes, after global subexpression elimination
11130 \begin_inset LatexCommand \index{Global subexpression elimination}
11131
11132 \end_inset
11133
11134 , into a file named 
11135 \emph on
11136 <source filename>.dumpgcse.
11137 \end_layout
11138
11139 \begin_layout List
11140 \labelwidthstring 00.00.0000
11141
11142 \series bold
11143 -
11144 \begin_inset ERT
11145 status collapsed
11146
11147 \begin_layout Standard
11148
11149
11150 \backslash
11151 /
11152 \end_layout
11153
11154 \end_inset
11155
11156 -dumpdeadcode
11157 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11158
11159 \end_inset
11160
11161
11162 \series default
11163  Will create a dump of iCodes, after deadcode elimination
11164 \begin_inset LatexCommand \index{Dead-code elimination}
11165
11166 \end_inset
11167
11168 , into a file named 
11169 \emph on
11170 <source filename>.dumpdeadcode.
11171 \end_layout
11172
11173 \begin_layout List
11174 \labelwidthstring 00.00.0000
11175
11176 \series bold
11177 -
11178 \begin_inset ERT
11179 status collapsed
11180
11181 \begin_layout Standard
11182
11183
11184 \backslash
11185 /
11186 \end_layout
11187
11188 \end_inset
11189
11190 -dumploop
11191 \begin_inset LatexCommand \index{-\/-dumploop}
11192
11193 \end_inset
11194
11195
11196 \series default
11197 \size large
11198  
11199 \size default
11200 Will create a dump of iCodes, after loop optimizations
11201 \begin_inset LatexCommand \index{Loop optimization}
11202
11203 \end_inset
11204
11205 , into a file named 
11206 \emph on
11207 <source filename>.dumploop.
11208 \end_layout
11209
11210 \begin_layout List
11211 \labelwidthstring 00.00.0000
11212
11213 \series bold
11214 -
11215 \begin_inset ERT
11216 status collapsed
11217
11218 \begin_layout Standard
11219
11220
11221 \backslash
11222 /
11223 \end_layout
11224
11225 \end_inset
11226
11227 -dumprange
11228 \begin_inset LatexCommand \index{-\/-dumprange}
11229
11230 \end_inset
11231
11232
11233 \series default
11234 \size large
11235  
11236 \size default
11237 Will create a dump of iCodes, after live range analysis
11238 \begin_inset LatexCommand \index{Live range analysis}
11239
11240 \end_inset
11241
11242 , into a file named 
11243 \emph on
11244 <source filename>.dumprange.
11245 \end_layout
11246
11247 \begin_layout List
11248 \labelwidthstring 00.00.0000
11249
11250 \series bold
11251 -
11252 \begin_inset ERT
11253 status collapsed
11254
11255 \begin_layout Standard
11256
11257
11258 \backslash
11259 /
11260 \end_layout
11261
11262 \end_inset
11263
11264 -dumlrange
11265 \begin_inset LatexCommand \index{-\/-dumlrange}
11266
11267 \end_inset
11268
11269
11270 \series default
11271  Will dump the life ranges
11272 \begin_inset LatexCommand \index{Live range analysis}
11273
11274 \end_inset
11275
11276  for all symbols.
11277 \end_layout
11278
11279 \begin_layout List
11280 \labelwidthstring 00.00.0000
11281
11282 \series bold
11283 -
11284 \begin_inset ERT
11285 status collapsed
11286
11287 \begin_layout Standard
11288
11289
11290 \backslash
11291 /
11292 \end_layout
11293
11294 \end_inset
11295
11296 -dumpregassign
11297 \begin_inset LatexCommand \index{-\/-dumpregassign}
11298
11299 \end_inset
11300
11301
11302 \bar under
11303  
11304 \series default
11305 \bar default
11306 Will create a dump of iCodes, after register assignment
11307 \begin_inset LatexCommand \index{Register assignment}
11308
11309 \end_inset
11310
11311 , into a file named 
11312 \emph on
11313 <source filename>.dumprassgn.
11314 \end_layout
11315
11316 \begin_layout List
11317 \labelwidthstring 00.00.0000
11318
11319 \series bold
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 -dumplrange
11334 \begin_inset LatexCommand \index{-\/-dumplrange}
11335
11336 \end_inset
11337
11338
11339 \series default
11340  Will create a dump of the live ranges of iTemp's
11341 \end_layout
11342
11343 \begin_layout List
11344 \labelwidthstring 00.00.0000
11345
11346 \series bold
11347 -
11348 \begin_inset ERT
11349 status collapsed
11350
11351 \begin_layout Standard
11352
11353
11354 \backslash
11355 /
11356 \end_layout
11357
11358 \end_inset
11359
11360 -dumpall
11361 \begin_inset LatexCommand \index{-\/-dumpall}
11362
11363 \end_inset
11364
11365
11366 \size large
11367 \bar under
11368  
11369 \series default
11370 \size default
11371 \bar default
11372 Will cause all the above mentioned dumps to be created.
11373 \end_layout
11374
11375 \begin_layout Standard
11376 \begin_inset VSpace bigskip
11377 \end_inset
11378
11379
11380 \end_layout
11381
11382 \begin_layout Subsection
11383 Redirecting output on Windows Shells
11384 \end_layout
11385
11386 \begin_layout Standard
11387 By default SDCC writes its error messages to 
11388 \begin_inset Quotes sld
11389 \end_inset
11390
11391 standard error
11392 \begin_inset Quotes srd
11393 \end_inset
11394
11395 .
11396  To force all messages to 
11397 \begin_inset Quotes sld
11398 \end_inset
11399
11400 standard output
11401 \begin_inset Quotes srd
11402 \end_inset
11403
11404  use 
11405 \series bold
11406 -
11407 \series default
11408 \emph on
11409
11410 \begin_inset ERT
11411 status collapsed
11412
11413 \begin_layout Standard
11414
11415
11416 \backslash
11417 /
11418 \end_layout
11419
11420 \end_inset
11421
11422
11423 \series bold
11424 \emph default
11425 -
11426 \series default
11427 use-stdout
11428 \begin_inset LatexCommand \index{-\/-use-stdout}
11429
11430 \end_inset
11431
11432 .
11433  Additionally, if you happen to have visual studio installed in your windows
11434  machine, you can use it to compile your sources using a custom build and
11435  the SDCC -
11436 \emph on
11437
11438 \begin_inset ERT
11439 status collapsed
11440
11441 \begin_layout Standard
11442
11443
11444 \backslash
11445 /
11446 \end_layout
11447
11448 \end_inset
11449
11450
11451 \emph default
11452 -vc
11453 \begin_inset LatexCommand \index{-\/-vc}
11454
11455 \end_inset
11456
11457  option.
11458  Something like this should work:
11459 \newline
11460
11461 \newline
11462
11463 \series bold
11464 c:
11465 \backslash
11466 sdcc
11467 \backslash
11468 bin
11469 \backslash
11470 sdcc.exe -
11471 \series default
11472 \emph on
11473
11474 \begin_inset ERT
11475 status collapsed
11476
11477 \begin_layout Standard
11478
11479
11480 \backslash
11481 /
11482 \end_layout
11483
11484 \end_inset
11485
11486
11487 \series bold
11488 \emph default
11489 -vc -
11490 \series default
11491 \emph on
11492
11493 \begin_inset ERT
11494 status collapsed
11495
11496 \begin_layout Standard
11497
11498
11499 \backslash
11500 /
11501 \end_layout
11502
11503 \end_inset
11504
11505
11506 \series bold
11507 \emph default
11508 -model-large -c $(InputPath)
11509 \series default
11510
11511 \begin_inset VSpace bigskip
11512 \end_inset
11513
11514
11515 \end_layout
11516
11517 \begin_layout Section
11518 Environment variables
11519 \begin_inset LatexCommand \index{Environment variables}
11520
11521 \end_inset
11522
11523
11524 \end_layout
11525
11526 \begin_layout Standard
11527 SDCC recognizes the following environment variables:
11528 \end_layout
11529
11530 \begin_layout List
11531 \labelwidthstring 00.00.0000
11532
11533 \series bold
11534 SDCC_LEAVE_SIGNALS
11535 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11536
11537 \end_inset
11538
11539
11540 \series default
11541  SDCC installs a signal handler
11542 \begin_inset LatexCommand \index{signal handler}
11543
11544 \end_inset
11545
11546  to be able to delete temporary files after an user break (^C) or an exception.
11547  If this environment variable is set, SDCC won't install the signal handler
11548  in order to be able to debug SDCC.
11549 \end_layout
11550
11551 \begin_layout List
11552 \labelwidthstring 00.00.0000
11553
11554 \series bold
11555 TMP,\InsetSpace ~
11556 TEMP,\InsetSpace ~
11557 TMPDIR
11558 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11559
11560 \end_inset
11561
11562
11563 \series default
11564  Path, where temporary files will be created.
11565  The order of the variables is the search order.
11566  In a standard *nix environment these variables are not set, and there's
11567  no need to set them.
11568  On Windows it's recommended to set one of them.
11569 \end_layout
11570
11571 \begin_layout List
11572 \labelwidthstring 00.00.0000
11573
11574 \series bold
11575 SDCC_HOME
11576 \begin_inset LatexCommand \index{SDCC\_HOME}
11577
11578 \end_inset
11579
11580
11581 \series default
11582  Path, see section 
11583 \begin_inset LatexCommand \ref{sub:Install-paths}
11584
11585 \end_inset
11586
11587 \InsetSpace ~
11588
11589 \begin_inset Quotes sld
11590 \end_inset
11591
11592  Install Paths
11593 \begin_inset Quotes srd
11594 \end_inset
11595
11596 .
11597 \end_layout
11598
11599 \begin_layout List
11600 \labelwidthstring 00.00.0000
11601
11602 \series bold
11603 SDCC_INCLUDE
11604 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11605
11606 \end_inset
11607
11608
11609 \series default
11610  Path, see section 
11611 \begin_inset LatexCommand \ref{sub:Search-Paths}
11612
11613 \end_inset
11614
11615 \InsetSpace ~
11616
11617 \begin_inset Quotes sld
11618 \end_inset
11619
11620 Search Paths
11621 \begin_inset Quotes srd
11622 \end_inset
11623
11624 .
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 SDCC_LIB
11632 \begin_inset LatexCommand \index{SDCC\_LIB}
11633
11634 \end_inset
11635
11636
11637 \series default
11638  Path, see section 
11639 \begin_inset LatexCommand \ref{sub:Search-Paths}
11640
11641 \end_inset
11642
11643 \InsetSpace ~
11644
11645 \begin_inset Quotes sld
11646 \end_inset
11647
11648 Search Paths
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 ..
11653 \end_layout
11654
11655 \begin_layout Standard
11656 There are some more environment variables recognized by SDCC, but these
11657  are solely used for debugging purposes.
11658  They can change or disappear very quickly, and will never be documented.
11659 \begin_inset VSpace bigskip
11660 \end_inset
11661
11662
11663 \end_layout
11664
11665 \begin_layout Section
11666 Storage Class Language Extensions
11667 \end_layout
11668
11669 \begin_layout Subsection
11670 MCS51/DS390 Storage Class
11671 \begin_inset LatexCommand \index{Storage class}
11672
11673 \end_inset
11674
11675  Language Extensions
11676 \end_layout
11677
11678 \begin_layout Standard
11679 In addition to the ANSI storage classes SDCC allows the following MCS51
11680  specific storage classes:
11681 \end_layout
11682
11683 \begin_layout Subsubsection
11684 data
11685 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11686
11687 \end_inset
11688
11689
11690 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11691
11692 \end_inset
11693
11694  / near
11695 \begin_inset LatexCommand \index{near (storage class)}
11696
11697 \end_inset
11698
11699
11700 \begin_inset LatexCommand \index{\_\_near (storage class)}
11701
11702 \end_inset
11703
11704
11705 \end_layout
11706
11707 \begin_layout Standard
11708 This is the 
11709 \series bold
11710 default
11711 \series default
11712  storage class for the Small Memory model (
11713 \emph on
11714 data
11715 \emph default
11716  and 
11717 \emph on
11718 near
11719 \emph default
11720  or the more ANSI-C compliant forms 
11721 \emph on
11722 __data
11723 \emph default
11724  and 
11725 \emph on
11726 __near
11727 \emph default
11728  can be used synonymously).
11729  Variables declared with this storage class will be allocated in the directly
11730  addressable portion of the internal RAM of a 8051, e.g.:
11731 \end_layout
11732
11733 \begin_layout Verse
11734
11735 \family typewriter
11736 __data unsigned char test_data;
11737 \end_layout
11738
11739 \begin_layout Standard
11740 Writing 0x01 to this variable generates the assembly code:
11741 \end_layout
11742
11743 \begin_layout Verse
11744
11745 \family typewriter
11746 75*00 01\InsetSpace ~
11747 \InsetSpace ~
11748 \InsetSpace ~
11749 mov\InsetSpace ~
11750 \InsetSpace ~
11751 _test_data,#0x01
11752 \end_layout
11753
11754 \begin_layout Subsubsection
11755 xdata
11756 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11757
11758 \end_inset
11759
11760
11761 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11762
11763 \end_inset
11764
11765  / far
11766 \begin_inset LatexCommand \index{far (storage class)}
11767
11768 \end_inset
11769
11770
11771 \begin_inset LatexCommand \index{\_\_far (storage class)}
11772
11773 \end_inset
11774
11775
11776 \end_layout
11777
11778 \begin_layout Standard
11779 Variables declared with this storage class will be placed in the external
11780  RAM.
11781  This is the 
11782 \series bold
11783 default
11784 \series default
11785  storage class for the Large Memory model, e.g.:
11786 \end_layout
11787
11788 \begin_layout Verse
11789
11790 \family typewriter
11791 __xdata unsigned char test_xdata;
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 90s00r00\InsetSpace ~
11802 \InsetSpace ~
11803 \InsetSpace ~
11804 mov\InsetSpace ~
11805 \InsetSpace ~
11806 dptr,#_test_xdata 
11807 \newline
11808 74\InsetSpace ~
11809 01\InsetSpace ~
11810 \InsetSpace ~
11811 \InsetSpace ~
11812 \InsetSpace ~
11813 \InsetSpace ~
11814 \InsetSpace ~
11815 mov\InsetSpace ~
11816 \InsetSpace ~
11817 a,#0x01 
11818 \newline
11819 F0\InsetSpace ~
11820 \InsetSpace ~
11821 \InsetSpace ~
11822 \InsetSpace ~
11823 \InsetSpace ~
11824 \InsetSpace ~
11825 \InsetSpace ~
11826 \InsetSpace ~
11827 \InsetSpace ~
11828 movx\InsetSpace ~
11829 @dptr,a 
11830 \end_layout
11831
11832 \begin_layout Subsubsection
11833 idata
11834 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11835
11836 \end_inset
11837
11838
11839 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11840
11841 \end_inset
11842
11843
11844 \end_layout
11845
11846 \begin_layout Standard
11847 Variables declared with this storage class will be allocated into the indirectly
11848  addressable portion of the internal ram of a 8051, e.g.:
11849 \end_layout
11850
11851 \begin_layout Verse
11852
11853 \family typewriter
11854 __idata unsigned char test_idata;
11855 \end_layout
11856
11857 \begin_layout Standard
11858 Writing 0x01 to this variable generates the assembly code:
11859 \end_layout
11860
11861 \begin_layout Verse
11862
11863 \family typewriter
11864 78r00\InsetSpace ~
11865 \InsetSpace ~
11866 \InsetSpace ~
11867 \InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 \InsetSpace ~
11871 mov\InsetSpace ~
11872 \InsetSpace ~
11873 r0,#_test_idata
11874 \newline
11875 76\InsetSpace ~
11876 01\InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 \InsetSpace ~
11882 \InsetSpace ~
11883 mov\InsetSpace ~
11884 \InsetSpace ~
11885 @r0,#0x01
11886 \end_layout
11887
11888 \begin_layout Standard
11889 Please note, the first 128 byte of idata physically access the same RAM
11890  as the data memory.
11891  The original 8051 had 128 byte idata memory, nowadays most devices have
11892  256 byte idata memory.
11893  The stack
11894 \begin_inset LatexCommand \index{stack}
11895
11896 \end_inset
11897
11898  is located in idata memory.
11899 \end_layout
11900
11901 \begin_layout Subsubsection
11902 pdata
11903 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11904
11905 \end_inset
11906
11907
11908 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11909
11910 \end_inset
11911
11912
11913 \end_layout
11914
11915 \begin_layout Standard
11916 Paged xdata access is just as straightforward as using the other addressing
11917  modes of a 8051.
11918  It is typically located at the start of xdata and has a maximum size of
11919  256 bytes.
11920  The following example writes 0x01 to the pdata variable.
11921  Please note, pdata access physically accesses xdata memory.
11922  The high byte of the address is determined by port P2 
11923 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11924
11925 \end_inset
11926
11927 (or in case of some 8051 variants by a separate Special Function Register,
11928  see section 
11929 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11930
11931 \end_inset
11932
11933 ).
11934  This is the 
11935 \series bold
11936 default
11937 \series default
11938  storage class for the Medium Memory model, e.g.:
11939 \end_layout
11940
11941 \begin_layout Verse
11942
11943 \family typewriter
11944 __pdata unsigned char test_pdata;
11945 \end_layout
11946
11947 \begin_layout Standard
11948 Writing 0x01 to this variable generates the assembly code:
11949 \end_layout
11950
11951 \begin_layout Verse
11952
11953 \family typewriter
11954 78r00\InsetSpace ~
11955 \InsetSpace ~
11956 \InsetSpace ~
11957 \InsetSpace ~
11958 \InsetSpace ~
11959 \InsetSpace ~
11960 mov r0,#_test_pdata
11961 \newline
11962 74 01\InsetSpace ~
11963 \InsetSpace ~
11964 \InsetSpace ~
11965 \InsetSpace ~
11966 \InsetSpace ~
11967 \InsetSpace ~
11968 mov a,#0x01 
11969 \newline
11970 F2\InsetSpace ~
11971 \InsetSpace ~
11972 \InsetSpace ~
11973 \InsetSpace ~
11974 \InsetSpace ~
11975 \InsetSpace ~
11976 \InsetSpace ~
11977 \InsetSpace ~
11978 \InsetSpace ~
11979 movx @r0,a
11980 \end_layout
11981
11982 \begin_layout Standard
11983 If the -
11984 \begin_inset ERT
11985 status collapsed
11986
11987 \begin_layout Standard
11988
11989
11990 \backslash
11991 /
11992 \end_layout
11993
11994 \end_inset
11995
11996 -xstack
11997 \begin_inset LatexCommand \index{-\/-xstack}
11998
11999 \end_inset
12000
12001  option is used the pdata memory area is followed by the xstack memory area
12002  and the sum of their sizes is limited to 256 bytes.
12003 \end_layout
12004
12005 \begin_layout Subsubsection
12006 code
12007 \begin_inset LatexCommand \index{code}
12008
12009 \end_inset
12010
12011
12012 \begin_inset LatexCommand \index{\_\_code}
12013
12014 \end_inset
12015
12016
12017 \end_layout
12018
12019 \begin_layout Standard
12020 'Variables' declared with this storage class will be placed in the code
12021  memory:
12022 \end_layout
12023
12024 \begin_layout Verse
12025
12026 \family typewriter
12027 __code unsigned char test_code;
12028 \end_layout
12029
12030 \begin_layout Standard
12031 Read access to this variable generates the assembly code:
12032 \end_layout
12033
12034 \begin_layout Verse
12035
12036 \family typewriter
12037 90s00r6F\InsetSpace ~
12038 \InsetSpace ~
12039 \InsetSpace ~
12040 mov dptr,#_test_code
12041 \newline
12042 E4\InsetSpace ~
12043 \InsetSpace ~
12044 \InsetSpace ~
12045 \InsetSpace ~
12046 \InsetSpace ~
12047 \InsetSpace ~
12048 \InsetSpace ~
12049 \InsetSpace ~
12050 \InsetSpace ~
12051 clr a
12052 \newline
12053 93\InsetSpace ~
12054 \InsetSpace ~
12055 \InsetSpace ~
12056 \InsetSpace ~
12057 \InsetSpace ~
12058 \InsetSpace ~
12059 \InsetSpace ~
12060 \InsetSpace ~
12061 \InsetSpace ~
12062 movc a,@a+dptr 
12063 \end_layout
12064
12065 \begin_layout Standard
12066
12067 \family typewriter
12068 char
12069 \family default
12070  indexed arrays of characters in code memory can be accessed efficiently:
12071 \end_layout
12072
12073 \begin_layout Verse
12074
12075 \family typewriter
12076 __code char test_array[] = {'c','h','e','a','p'}; 
12077 \end_layout
12078
12079 \begin_layout Standard
12080 Read access to this array using an 8-bit unsigned index generates the assembly
12081  code:
12082 \end_layout
12083
12084 \begin_layout Verse
12085
12086 \family typewriter
12087 E5*00\InsetSpace ~
12088 \InsetSpace ~
12089 \InsetSpace ~
12090 \InsetSpace ~
12091 \InsetSpace ~
12092 \InsetSpace ~
12093 mov a,_index 
12094 \end_layout
12095
12096 \begin_layout Verse
12097
12098 \family typewriter
12099 90s00r41\InsetSpace ~
12100 \InsetSpace ~
12101 \InsetSpace ~
12102 mov dptr,#_test_array
12103 \end_layout
12104
12105 \begin_layout Verse
12106
12107 \family typewriter
12108 93\InsetSpace ~
12109 \InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 movc a,@a+dptr 
12118 \end_layout
12119
12120 \begin_layout Subsubsection
12121 bit
12122 \begin_inset LatexCommand \index{bit}
12123
12124 \end_inset
12125
12126
12127 \begin_inset LatexCommand \index{\_\_bit}
12128
12129 \end_inset
12130
12131
12132 \end_layout
12133
12134 \begin_layout Standard
12135 This is a data-type and a storage class specifier.
12136  When a variable is declared as a bit, it is allocated into the bit addressable
12137  memory of 8051, e.g.:
12138 \end_layout
12139
12140 \begin_layout Verse
12141
12142 \family typewriter
12143 __bit test_bit;
12144 \end_layout
12145
12146 \begin_layout Standard
12147 Writing 1 to this variable generates the assembly code:
12148 \end_layout
12149
12150 \begin_layout Verse
12151
12152 \family typewriter
12153 D2*00\InsetSpace ~
12154 \InsetSpace ~
12155 \InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 \InsetSpace ~
12159 \InsetSpace ~
12160 setb\InsetSpace ~
12161 _test_bit
12162 \end_layout
12163
12164 \begin_layout Standard
12165 The bit addressable memory consists of 128 bits which are located from 0x20
12166  to 0x2f in data memory.
12167  
12168 \newline
12169 Apart from this 8051 specific storage class most architectures support
12170  ANSI-C bitfields
12171 \begin_inset LatexCommand \index{bitfields}
12172
12173 \end_inset
12174
12175
12176 \begin_inset Foot
12177 status open
12178
12179 \begin_layout Standard
12180 Not really meant as examples, but nevertheless showing what bitfields are
12181  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12182 \end_layout
12183
12184 \end_inset
12185
12186 .
12187  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12188  signed modifier are implemented as unsigned.
12189 \end_layout
12190
12191 \begin_layout Subsubsection
12192 sfr
12193 \begin_inset LatexCommand \index{sfr}
12194
12195 \end_inset
12196
12197
12198 \begin_inset LatexCommand \index{\_\_sfr}
12199
12200 \end_inset
12201
12202  / sfr16
12203 \begin_inset LatexCommand \index{sfr16}
12204
12205 \end_inset
12206
12207
12208 \begin_inset LatexCommand \index{\_\_sfr16}
12209
12210 \end_inset
12211
12212  / sfr32
12213 \begin_inset LatexCommand \index{sfr32}
12214
12215 \end_inset
12216
12217
12218 \begin_inset LatexCommand \index{\_\_sfr32}
12219
12220 \end_inset
12221
12222  / sbit
12223 \begin_inset LatexCommand \index{\_\_sbit}
12224
12225 \end_inset
12226
12227
12228 \begin_inset LatexCommand \index{sbit}
12229
12230 \end_inset
12231
12232
12233 \end_layout
12234
12235 \begin_layout Standard
12236 Like the bit keyword, 
12237 \emph on
12238 sfr / sfr16 / sfr32 / sbit 
12239 \emph default
12240 signify both a data-type and storage class, they are used to describe the
12241  
12242 \emph on
12243 s
12244 \emph default
12245 pecial 
12246 \emph on
12247 f
12248 \emph default
12249 unction 
12250 \emph on
12251 r
12252 \emph default
12253 egisters and 
12254 \emph on
12255 s
12256 \emph default
12257 pecial 
12258 \emph on
12259 bit
12260 \emph default
12261  variables of a 8051, eg:
12262 \end_layout
12263
12264 \begin_layout Verse
12265
12266 \family typewriter
12267 __sfr __at
12268 \begin_inset LatexCommand \index{at}
12269
12270 \end_inset
12271
12272
12273 \begin_inset LatexCommand \index{\_\_at}
12274
12275 \end_inset
12276
12277  (0x80) P0;\InsetSpace ~
12278  /* special function register P0 at location 0x80 */
12279 \newline
12280
12281 \newline
12282 /* 16 bit
12283  special function register combination for timer 0
12284 \newline
12285 \InsetSpace ~
12286 \InsetSpace ~
12287  with the high byte at
12288  location 0x8C and the low byte at location 0x8A */
12289 \newline
12290 __sfr16 __at (0x8C8A)
12291  TMR0;
12292 \newline
12293
12294 \newline
12295 __sbit __at
12296 \begin_inset LatexCommand \index{at}
12297
12298 \end_inset
12299
12300
12301 \begin_inset LatexCommand \index{\_\_at}
12302
12303 \end_inset
12304
12305  (0xd7) CY;\InsetSpace ~
12306  /* CY (Carry Flag
12307 \begin_inset LatexCommand \index{Flags}
12308
12309 \end_inset
12310
12311
12312 \begin_inset LatexCommand \index{Carry flag}
12313
12314 \end_inset
12315
12316 ) */
12317 \end_layout
12318
12319 \begin_layout Standard
12320 Special function registers which are located on an address dividable by
12321  8 are bit-addressable, an
12322 \emph on
12323  sbit
12324 \emph default
12325  addresses a specific bit within these sfr.
12326 \newline
12327 16 Bit and 32 bit special function
12328  register combinations which require a certain access order are better not
12329  declared using 
12330 \emph on
12331 sfr16
12332 \emph default
12333  or 
12334 \emph on
12335 sfr32.
12336
12337 \emph default
12338  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12339  this is not guaranteed.
12340 \newline
12341
12342 \end_layout
12343
12344 \begin_layout Standard
12345 Please note, if you use a header file which was written for another compiler
12346  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12347  likely be 
12348 \emph on
12349 not 
12350 \emph default
12351 compatible.
12352  Specifically the syntax 
12353 \family typewriter
12354 \InsetSpace ~
12355 sfr P0 = 0x80;\InsetSpace ~
12356
12357 \family default
12358  is compiled 
12359 \emph on
12360 without warning
12361 \emph default
12362  by SDCC to an assignment of 0x80 to a variable called P0 
12363 \family typewriter
12364
12365 \begin_inset Marginal
12366 status collapsed
12367
12368 \begin_layout Standard
12369
12370 \series bold
12371 \InsetSpace ~
12372 !
12373 \end_layout
12374
12375 \end_inset
12376
12377 .
12378  
12379 \family default
12380 Nevertheless it is possible to write header files
12381 \begin_inset LatexCommand \index{Header files}
12382
12383 \end_inset
12384
12385
12386 \begin_inset LatexCommand \index{Include files}
12387
12388 \end_inset
12389
12390  which can be shared among different compilers (see section 
12391 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12392
12393 \end_inset
12394
12395 ).
12396  
12397 \end_layout
12398
12399 \begin_layout Subsubsection
12400 Pointers
12401 \begin_inset LatexCommand \index{Pointer}
12402
12403 \end_inset
12404
12405  to MCS51/DS390 specific memory spaces
12406 \end_layout
12407
12408 \begin_layout Standard
12409 SDCC allows (via language extensions) pointers to explicitly point to any
12410  of the memory spaces
12411 \begin_inset LatexCommand \index{Memory model}
12412
12413 \end_inset
12414
12415  of the 8051.
12416  In addition to the explicit pointers, the compiler uses (by default) generic
12417  pointers which can be used to point to any of the memory spaces.
12418 \newline
12419
12420 \newline
12421 Pointer
12422  declaration examples:
12423 \end_layout
12424
12425 \begin_layout Verse
12426
12427 \family typewriter
12428 /* pointer physically in internal ram pointing to object in external ram
12429  */ 
12430 \newline
12431 __xdata unsigned char * __data p;
12432 \newline
12433
12434 \newline
12435 /* pointer physically in external ram
12436  pointing to object in internal ram */ 
12437 \newline
12438 __data unsigned char * __xdata p;
12439 \newline
12440
12441 \newline
12442 /*
12443  pointer physically in code rom pointing to data in xdata space */ 
12444 \newline
12445 __xdata
12446  unsigned char * __code p;
12447 \newline
12448
12449 \newline
12450 /* pointer physically in code space pointing to
12451  data in code space */ 
12452 \newline
12453 __code unsigned char * __code p;
12454 \newline
12455
12456 \newline
12457 /* generic pointer
12458  physically located in xdata space */
12459 \newline
12460 unsigned char * __xdata p;
12461 \newline
12462
12463 \newline
12464 /* generic
12465  pointer physically located in default memory space */
12466 \newline
12467 unsigned char * p;
12468 \newline
12469
12470 \newline
12471 /*
12472  the following is a function pointer
12473 \begin_inset LatexCommand \index{function pointer}
12474
12475 \end_inset
12476
12477  physically located in data space */
12478 \newline
12479 char (* __data fp)(void);
12480 \end_layout
12481
12482 \begin_layout Standard
12483 Well you get the idea.
12484  
12485 \newline
12486
12487 \newline
12488 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12489 \emph on
12490 generic
12491 \emph default
12492  pointers.
12493  
12494 \size small
12495
12496 \newline
12497
12498 \newline
12499
12500 \size default
12501 The highest order byte of the 
12502 \emph on
12503 generic
12504 \emph default
12505  pointers contains the data space information.
12506  Assembler support routines are called whenever data is stored or retrieved
12507  using 
12508 \emph on
12509 generic
12510 \emph default
12511  pointers.
12512  These are useful for developing reusable library
12513 \begin_inset LatexCommand \index{Libraries}
12514
12515 \end_inset
12516
12517  routines.
12518  Explicitly specifying the pointer
12519 \begin_inset LatexCommand \index{pointer}
12520
12521 \end_inset
12522
12523  type will generate the most efficient code.
12524 \end_layout
12525
12526 \begin_layout Subsubsection
12527 Notes on MCS51 memory
12528 \begin_inset LatexCommand \index{MCS51 memory}
12529
12530 \end_inset
12531
12532  layout
12533 \end_layout
12534
12535 \begin_layout Standard
12536 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12537  RAM memory which is structured as follows:
12538 \newline
12539
12540 \newline
12541 - Bytes 00-1F - 32 bytes to hold
12542  up to 4 banks of the registers R0 to R7, 
12543 \newline
12544 - Bytes 20-2F - 16 bytes to hold
12545  128 bit
12546 \begin_inset LatexCommand \index{bit}
12547
12548 \end_inset
12549
12550  variables and, 
12551 \newline
12552 - Bytes 30-7F - 80 bytes for general purpose use.
12553 \newline
12554
12555 \end_layout
12556
12557 \begin_layout Standard
12558 Additionally some members of the MCS51 family may have up to 128 bytes of
12559  additional, indirectly addressable, internal RAM memory (
12560 \emph on
12561 idata
12562 \emph default
12563
12564 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12565
12566 \end_inset
12567
12568
12569 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12570
12571 \end_inset
12572
12573 ).
12574  Furthermore, some chips may have some built in external memory (
12575 \emph on
12576 xdata
12577 \emph default
12578
12579 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12580
12581 \end_inset
12582
12583
12584 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12585
12586 \end_inset
12587
12588 ) which should not be confused with the internal, directly addressable RAM
12589  memory (
12590 \emph on
12591 data
12592 \emph default
12593
12594 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12595
12596 \end_inset
12597
12598
12599 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12600
12601 \end_inset
12602
12603 ).
12604  Sometimes this built in 
12605 \emph on
12606 xdata
12607 \emph default
12608  memory has to be activated before using it (you can probably find this
12609  information on the datasheet of the microcontroller your are using, see
12610  also section 
12611 \begin_inset LatexCommand \ref{sub:Startup-Code}
12612
12613 \end_inset
12614
12615 \InsetSpace ~
12616 Startup-Code).
12617 \end_layout
12618
12619 \begin_layout Standard
12620 Normally SDCC will only use the first bank
12621 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12622
12623 \end_inset
12624
12625  of registers (register bank 0), but it is possible to specify that other
12626  banks of registers (keyword 
12627 \emph on
12628 using
12629 \emph default
12630  
12631 \emph on
12632
12633 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12634
12635 \end_inset
12636
12637
12638 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12639
12640 \end_inset
12641
12642
12643 \emph default
12644 ) should be used for example in interrupt
12645 \begin_inset LatexCommand \index{interrupt}
12646
12647 \end_inset
12648
12649
12650 \begin_inset LatexCommand \index{\_\_interrupt}
12651
12652 \end_inset
12653
12654  routines.
12655  By default, the compiler will place the stack after the last byte of allocated
12656  memory for variables.
12657  For example, if the first 2 banks of registers are used, and only four
12658  bytes are used for 
12659 \emph on
12660 data
12661 \emph default
12662  variables, it will position the base of the internal stack at address 20
12663  (0x14).
12664  This implies that as the stack
12665 \begin_inset LatexCommand \index{stack}
12666
12667 \end_inset
12668
12669  grows, it will use up the remaining register banks, and the 16 bytes used
12670  by the 128 bit variables, and 80 bytes for general purpose use.
12671  If any bit variables are used, the data variables will be placed in unused
12672  register banks and after the byte holding the last bit variable.
12673  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12674  (two bytes used), 
12675 \emph on
12676 data
12677 \emph default
12678  variables will be placed starting from address 0x10 to 0x20 and continue
12679  at address 0x22.
12680  You can also use -
12681 \begin_inset ERT
12682 status collapsed
12683
12684 \begin_layout Standard
12685
12686
12687 \backslash
12688 /
12689 \end_layout
12690
12691 \end_inset
12692
12693 -data-loc
12694 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12695
12696 \end_inset
12697
12698  to specify the start address of the 
12699 \emph on
12700 data
12701 \emph default
12702  and -
12703 \begin_inset ERT
12704 status collapsed
12705
12706 \begin_layout Standard
12707
12708
12709 \backslash
12710 /
12711 \end_layout
12712
12713 \end_inset
12714
12715 -iram-size
12716 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12717
12718 \end_inset
12719
12720  to specify the size of the total internal RAM (
12721 \emph on
12722 data
12723 \emph default
12724 +
12725 \emph on
12726 idata
12727 \emph default
12728 ).
12729  
12730 \newline
12731
12732 \end_layout
12733
12734 \begin_layout Standard
12735 By default the 8051 linker will place the stack after the last byte of (i)data
12736  variables.
12737  Option -
12738 \begin_inset ERT
12739 status collapsed
12740
12741 \begin_layout Standard
12742
12743
12744 \backslash
12745 /
12746 \end_layout
12747
12748 \end_inset
12749
12750 -stack-loc
12751 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12752
12753 \end_inset
12754
12755  allows you to specify the start of the stack, i.e.
12756  you could start it after any data in the general purpose area.
12757  If your microcontroller has additional indirectly addressable internal
12758  RAM (
12759 \emph on
12760 idata
12761 \emph default
12762 ) you can place the stack on it.
12763  You may also need to use -
12764 \begin_inset ERT
12765 status collapsed
12766
12767 \begin_layout Standard
12768
12769
12770 \backslash
12771 /
12772 \end_layout
12773
12774 \end_inset
12775
12776 -xdata-loc
12777 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12778
12779 \end_inset
12780
12781  to set the start address of the external RAM (
12782 \emph on
12783 xdata
12784 \emph default
12785 ) and -
12786 \begin_inset ERT
12787 status collapsed
12788
12789 \begin_layout Standard
12790
12791
12792 \backslash
12793 /
12794 \end_layout
12795
12796 \end_inset
12797
12798 -xram-size
12799 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12800
12801 \end_inset
12802
12803  to specify its size.
12804  Same goes for the code memory, using -
12805 \begin_inset ERT
12806 status collapsed
12807
12808 \begin_layout Standard
12809
12810
12811 \backslash
12812 /
12813 \end_layout
12814
12815 \end_inset
12816
12817 -code-loc
12818 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12819
12820 \end_inset
12821
12822  and -
12823 \begin_inset ERT
12824 status collapsed
12825
12826 \begin_layout Standard
12827
12828
12829 \backslash
12830 /
12831 \end_layout
12832
12833 \end_inset
12834
12835 -code-size
12836 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12837
12838 \end_inset
12839
12840 .
12841  If in doubt, don't specify any options and see if the resulting memory
12842  layout is appropriate, then you can adjust it.
12843 \end_layout
12844
12845 \begin_layout Standard
12846 The linker generates two files with memory allocation information.
12847  The first, with extension .map
12848 \begin_inset LatexCommand \index{<file>.map}
12849
12850 \end_inset
12851
12852  shows all the variables and segments.
12853  The second with extension .mem
12854 \begin_inset LatexCommand \index{<file>.mem}
12855
12856 \end_inset
12857
12858  shows the final memory layout.
12859  The linker will complain either if memory segments overlap, there is not
12860  enough memory, or there is not enough space for stack.
12861  If you get any linking warnings and/or errors related to stack or segments
12862  allocation, take a look at either the .map or .mem files to find out what
12863  the problem is.
12864  The .mem file may even suggest a solution to the problem.
12865 \begin_inset VSpace bigskip
12866 \end_inset
12867
12868
12869 \end_layout
12870
12871 \begin_layout Subsection
12872 Z80/Z180 Storage Class
12873 \begin_inset LatexCommand \index{Z80!Storage class}
12874
12875 \end_inset
12876
12877  Language Extensions
12878 \end_layout
12879
12880 \begin_layout Subsubsection
12881 sfr
12882 \begin_inset LatexCommand \index{sfr}
12883
12884 \end_inset
12885
12886
12887 \begin_inset LatexCommand \index{\_\_sfr}
12888
12889 \end_inset
12890
12891  (in/out to 8-bit addresses)
12892 \end_layout
12893
12894 \begin_layout Standard
12895 The Z80
12896 \begin_inset LatexCommand \index{Z80}
12897
12898 \end_inset
12899
12900  family has separate address spaces for memory and 
12901 \emph on
12902 i
12903 \emph default
12904 nput/
12905 \emph on
12906 o
12907 \emph default
12908 utput memory.
12909  I/O memory
12910 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12911
12912 \end_inset
12913
12914
12915 \begin_inset LatexCommand \index{Z80!I/O memory}
12916
12917 \end_inset
12918
12919
12920 \begin_inset LatexCommand \index{Z180!I/O memory}
12921
12922 \end_inset
12923
12924  is accessed with special instructions, e.g.:
12925 \end_layout
12926
12927 \begin_layout Verse
12928
12929 \family typewriter
12930 sfr at 0x78 IoPort;\InsetSpace ~
12931 \InsetSpace ~
12932 /* define a var in I/O space at 78h called IoPort */
12933  
12934 \end_layout
12935
12936 \begin_layout Standard
12937 Writing 0x01 to this variable generates the assembly code:
12938 \end_layout
12939
12940 \begin_layout Verse
12941
12942 \family typewriter
12943 3E 01\InsetSpace ~
12944 \InsetSpace ~
12945 \InsetSpace ~
12946 \InsetSpace ~
12947 \InsetSpace ~
12948 \InsetSpace ~
12949 ld a,#0x01
12950 \newline
12951 D3 78\InsetSpace ~
12952 \InsetSpace ~
12953 \InsetSpace ~
12954 \InsetSpace ~
12955 \InsetSpace ~
12956 \InsetSpace ~
12957 out (_IoPort),a 
12958 \end_layout
12959
12960 \begin_layout Subsubsection
12961 banked sfr
12962 \begin_inset LatexCommand \index{sfr}
12963
12964 \end_inset
12965
12966
12967 \begin_inset LatexCommand \index{\_\_sfr}
12968
12969 \end_inset
12970
12971  (in/out to 16-bit addresses)
12972 \end_layout
12973
12974 \begin_layout Standard
12975 The keyword 
12976 \emph on
12977 banked
12978 \emph default
12979  is used to support 16 bit addresses in I/O memory e.g.:
12980 \end_layout
12981
12982 \begin_layout Verse
12983
12984 \family typewriter
12985 sfr banked at
12986 \begin_inset LatexCommand \index{at}
12987
12988 \end_inset
12989
12990
12991 \begin_inset LatexCommand \index{\_\_at}
12992
12993 \end_inset
12994
12995  0x123 IoPort; 
12996 \end_layout
12997
12998 \begin_layout Standard
12999 Writing 0x01 to this variable generates the assembly code:
13000 \end_layout
13001
13002 \begin_layout Verse
13003
13004 \family typewriter
13005 01 23 01\InsetSpace ~
13006 \InsetSpace ~
13007 \InsetSpace ~
13008 ld bc,#_IoPort
13009 \newline
13010 3E 01\InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 \InsetSpace ~
13016 ld a,#0x01 
13017 \newline
13018 ED 79\InsetSpace ~
13019 \InsetSpace ~
13020 \InsetSpace ~
13021 \InsetSpace ~
13022 \InsetSpace ~
13023 \InsetSpace ~
13024 out (c),a 
13025 \end_layout
13026
13027 \begin_layout Subsubsection
13028 sfr
13029 \begin_inset LatexCommand \index{sfr}
13030
13031 \end_inset
13032
13033
13034 \begin_inset LatexCommand \index{\_\_sfr}
13035
13036 \end_inset
13037
13038  (in0/out0 to 8 bit addresses on Z180
13039 \begin_inset LatexCommand \index{Z180}
13040
13041 \end_inset
13042
13043 /HD64180
13044 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13045
13046 \end_inset
13047
13048 )
13049 \end_layout
13050
13051 \begin_layout Standard
13052 The compiler option -
13053 \begin_inset ERT
13054 status collapsed
13055
13056 \begin_layout Standard
13057
13058
13059 \backslash
13060 /
13061 \end_layout
13062
13063 \end_inset
13064
13065 -portmode
13066 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13067
13068 \end_inset
13069
13070 =180 (80) and a compiler #pragma\InsetSpace ~
13071 portmode
13072 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13073
13074 \end_inset
13075
13076  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13077 ns 
13078 \family typewriter
13079 in0/out0
13080 \family default
13081  instead of 
13082 \family typewriter
13083 in/out
13084 \family default
13085 .
13086  If you include the file z180.h this will be set automatically.
13087 \begin_inset VSpace bigskip
13088 \end_inset
13089
13090
13091 \end_layout
13092
13093 \begin_layout Subsection
13094 HC08 Storage Class
13095 \begin_inset LatexCommand \index{HC08!Storage class}
13096
13097 \end_inset
13098
13099  Language Extensions
13100 \end_layout
13101
13102 \begin_layout Subsubsection
13103 data
13104 \begin_inset LatexCommand \index{data (hc08 storage class)}
13105
13106 \end_inset
13107
13108
13109 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13110
13111 \end_inset
13112
13113  
13114 \end_layout
13115
13116 \begin_layout Standard
13117 The data storage class declares a variable that resides in the first 256
13118  bytes of memory (the direct page).
13119  The HC08
13120 \begin_inset LatexCommand \index{HC08}
13121
13122 \end_inset
13123
13124  is most efficient at accessing variables (especially pointers) stored here.
13125 \end_layout
13126
13127 \begin_layout Subsubsection
13128 xdata
13129 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13130
13131 \end_inset
13132
13133
13134 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13135
13136 \end_inset
13137
13138  
13139 \end_layout
13140
13141 \begin_layout Standard
13142 The xdata storage class declares a variable that can reside anywhere in
13143  memory.
13144  This is the default if no storage class is specified.
13145  
13146 \begin_inset VSpace bigskip
13147 \end_inset
13148
13149
13150 \end_layout
13151
13152 \begin_layout Section
13153 Absolute Addressing
13154 \begin_inset LatexCommand \index{Absolute addressing}
13155
13156 \end_inset
13157
13158
13159 \end_layout
13160
13161 \begin_layout Standard
13162 Data items can be assigned an absolute address with the 
13163 \emph on
13164 at
13165 \begin_inset LatexCommand \index{at}
13166
13167 \end_inset
13168
13169
13170 \begin_inset LatexCommand \index{\_\_at}
13171
13172 \end_inset
13173
13174  <address>
13175 \emph default
13176  keyword, in addition to a storage class, e.g.:
13177 \end_layout
13178
13179 \begin_layout Verse
13180
13181 \family typewriter
13182 xdata
13183 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13184
13185 \end_inset
13186
13187
13188 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13189
13190 \end_inset
13191
13192  at
13193 \begin_inset LatexCommand \index{at}
13194
13195 \end_inset
13196
13197
13198 \begin_inset LatexCommand \index{\_\_at}
13199
13200 \end_inset
13201
13202  0x7ffe unsigned int chksum;
13203 \end_layout
13204
13205 \begin_layout Standard
13206 or, better conforming to ISO/IEC 9899 C:
13207 \end_layout
13208
13209 \begin_layout Verse
13210
13211 \family typewriter
13212 __xdata __at (0x7ffe) unsigned int chksum;
13213 \end_layout
13214
13215 \begin_layout Standard
13216 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13217  of the external ram.
13218  The compiler does 
13219 \emph on
13220 not
13221 \emph default
13222  reserve any space for variables declared in this way
13223 \begin_inset Marginal
13224 status collapsed
13225
13226 \begin_layout Standard
13227
13228 \series bold
13229 \InsetSpace ~
13230 !
13231 \end_layout
13232
13233 \end_inset
13234
13235  (they are implemented with an equate in the assembler).
13236  Thus it is left to the programmer to make sure there are no overlaps with
13237  other variables that are declared without the absolute address.
13238  The assembler listing file (.lst
13239 \begin_inset LatexCommand \index{<file>.lst}
13240
13241 \end_inset
13242
13243 ) and the linker output files (.rst
13244 \begin_inset LatexCommand \index{<file>.rst}
13245
13246 \end_inset
13247
13248 ) and (.map
13249 \begin_inset LatexCommand \index{<file>.map}
13250
13251 \end_inset
13252
13253 ) are good places to look for such overlaps.
13254 \end_layout
13255
13256 \begin_layout Standard
13257 If however you provide an initializer
13258 \begin_inset LatexCommand \index{Variable initialization}
13259
13260 \end_inset
13261
13262  actual memory allocation will take place and overlaps will be detected
13263  by the linker.
13264  E.g.:
13265 \end_layout
13266
13267 \begin_layout Verse
13268
13269 \family typewriter
13270 __code __at (0x7ff0) char Id[5] = 
13271 \begin_inset Quotes sld
13272 \end_inset
13273
13274 SDCC
13275 \begin_inset Quotes srd
13276 \end_inset
13277
13278 ;
13279 \end_layout
13280
13281 \begin_layout Standard
13282 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13283  in code memory.
13284 \end_layout
13285
13286 \begin_layout Standard
13287 In case of memory mapped I/O devices the keyword 
13288 \emph on
13289 volatile
13290 \emph default
13291  has to be used to tell the compiler that accesses might not be removed:
13292 \end_layout
13293
13294 \begin_layout Verse
13295
13296 \family typewriter
13297 volatile
13298 \begin_inset LatexCommand \index{volatile}
13299
13300 \end_inset
13301
13302  __xdata
13303 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13304
13305 \end_inset
13306
13307  __at
13308 \begin_inset LatexCommand \index{at}
13309
13310 \end_inset
13311
13312  (0x8000) unsigned char PORTA_8255;
13313 \end_layout
13314
13315 \begin_layout Standard
13316 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13317 r) array
13318 \family typewriter
13319 \size footnotesize
13320
13321 \begin_inset LatexCommand \index{Aligned array}
13322
13323 \end_inset
13324
13325
13326 \family default
13327 \size default
13328  starts at a block (256 byte) boundary
13329 \begin_inset LatexCommand \index{block boundary}
13330
13331 \end_inset
13332
13333  (section 
13334 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13335
13336 \end_inset
13337
13338  has an example).
13339 \newline
13340 Absolute addresses can be specified for variables in all
13341  storage classes, e.g.:
13342 \end_layout
13343
13344 \begin_layout Verse
13345
13346 \family typewriter
13347 __bit
13348 \begin_inset LatexCommand \index{bit}
13349
13350 \end_inset
13351
13352  __at
13353 \begin_inset LatexCommand \index{at}
13354
13355 \end_inset
13356
13357  (0x02) bvar;
13358 \end_layout
13359
13360 \begin_layout Standard
13361 The above example will allocate the variable at offset 0x02 in the bit-addressab
13362 le space.
13363  There is no real advantage to assigning absolute addresses to variables
13364  in this manner, unless you want strict control over all the variables allocated.
13365  One possible use would be to write hardware portable code.
13366  For example, if you have a routine that uses one or more of the microcontroller
13367  I/O pins, and such pins are different for two different hardwares, you
13368  can declare the I/O pins in your routine using:
13369 \end_layout
13370
13371 \begin_layout Verse
13372
13373 \family typewriter
13374 extern volatile
13375 \begin_inset LatexCommand \index{volatile}
13376
13377 \end_inset
13378
13379  __bit MOSI;\InsetSpace ~
13380 \InsetSpace ~
13381 \InsetSpace ~
13382 \InsetSpace ~
13383 /* master out, slave in */
13384 \newline
13385 extern volatile __bit MISO;\InsetSpace ~
13386 \InsetSpace ~
13387 \InsetSpace ~
13388 \InsetSpace ~
13389 /* master
13390  in, slave out */
13391 \newline
13392 extern volatile __bit MCLK;\InsetSpace ~
13393 \InsetSpace ~
13394 \InsetSpace ~
13395 \InsetSpace ~
13396 /* master clock */
13397 \newline
13398
13399 \newline
13400 /* Input and
13401  Output of a byte on a 3-wire serial bus.
13402 \newline
13403 \InsetSpace ~
13404 \InsetSpace ~
13405 \InsetSpace ~
13406 If needed adapt polarity of clock,
13407  polarity of data and bit order
13408 \newline
13409 \InsetSpace ~
13410 */
13411 \newline
13412 unsigned char spi_io(unsigned char out_byte)
13413  
13414 \newline
13415
13416 \newline
13417 \InsetSpace ~
13418 \InsetSpace ~
13419 \InsetSpace ~
13420 \InsetSpace ~
13421 unsigned char i=8;
13422 \newline
13423 \InsetSpace ~
13424 \InsetSpace ~
13425 \InsetSpace ~
13426 \InsetSpace ~
13427 do { 
13428 \newline
13429 \InsetSpace ~
13430 \InsetSpace ~
13431 \InsetSpace ~
13432 \InsetSpace ~
13433 \InsetSpace ~
13434 \InsetSpace ~
13435 \InsetSpace ~
13436 \InsetSpace ~
13437 MOSI = out_byte & 0x80; 
13438 \newline
13439 \InsetSpace ~
13440 \InsetSpace ~
13441 \InsetSpace ~
13442 \InsetSpace ~
13443 \InsetSpace ~
13444 \InsetSpace ~
13445 \InsetSpace ~
13446 \InsetSpace ~
13447 out_byte <<= 1;
13448 \newline
13449 \InsetSpace ~
13450 \InsetSpace ~
13451 \InsetSpace ~
13452 \InsetSpace ~
13453 \InsetSpace ~
13454 \InsetSpace ~
13455 \InsetSpace ~
13456 \InsetSpace ~
13457 MCLK =
13458  1; 
13459 \newline
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 \InsetSpace ~
13463 \InsetSpace ~
13464 \InsetSpace ~
13465 \InsetSpace ~
13466 \InsetSpace ~
13467 \InsetSpace ~
13468 /* _asm nop _endasm; */\InsetSpace ~
13469 \InsetSpace ~
13470 \InsetSpace ~
13471 \InsetSpace ~
13472 \InsetSpace ~
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 \InsetSpace ~
13476 /* for slow peripherals */
13477 \newline
13478 \InsetSpace ~
13479 \InsetSpace ~
13480 \InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 \InsetSpace ~
13484 \InsetSpace ~
13485 \InsetSpace ~
13486 if(MISO) 
13487 \newline
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 \InsetSpace ~
13494 \InsetSpace ~
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 out_byte +=
13501  1; 
13502 \newline
13503 \InsetSpace ~
13504 \InsetSpace ~
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 MCLK = 0; 
13512 \newline
13513 \InsetSpace ~
13514 \InsetSpace ~
13515 \InsetSpace ~
13516 \InsetSpace ~
13517 } while(--i);
13518 \newline
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 return out_byte; 
13524 \newline
13525 }
13526 \end_layout
13527
13528 \begin_layout Standard
13529 Then, someplace in the code for the first hardware you would use
13530 \end_layout
13531
13532 \begin_layout Verse
13533
13534 \family typewriter
13535 __bit __at
13536 \begin_inset LatexCommand \index{at}
13537
13538 \end_inset
13539
13540
13541 \begin_inset LatexCommand \index{\_\_at}
13542
13543 \end_inset
13544
13545  (0x80) MOSI;\InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 /* I/O port 0, bit 0 */
13550 \newline
13551 __bit __at (0x81) MISO;\InsetSpace ~
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 /* I/O port 0,
13556  bit 1 */
13557 \newline
13558 __bit __at (0x82) MCLK;\InsetSpace ~
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 /* I/O port 0, bit 2 */
13563 \end_layout
13564
13565 \begin_layout Standard
13566 Similarly, for the second hardware you would use
13567 \end_layout
13568
13569 \begin_layout Verse
13570
13571 \family typewriter
13572 __bit __at (0x83) MOSI;\InsetSpace ~
13573 \InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 /* I/O port 0, bit 3 */
13577 \newline
13578 __bit __at (0x91) MISO;\InsetSpace ~
13579 \InsetSpace ~
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 /*
13583  I/O port 1, bit 1 */
13584 \newline
13585 __bit
13586 \begin_inset LatexCommand \index{bit}
13587
13588 \end_inset
13589
13590  __at (0x92) MCLK;\InsetSpace ~
13591 \InsetSpace ~
13592 \InsetSpace ~
13593 \InsetSpace ~
13594 /* I/O port 1, bit 2 */
13595 \end_layout
13596
13597 \begin_layout Standard
13598 and you can use the same hardware dependent routine without changes, as
13599  for example in a library.
13600  This is somehow similar to sbit, but only one absolute address has to be
13601  specified in the whole project.
13602 \begin_inset VSpace bigskip
13603 \end_inset
13604
13605
13606 \end_layout
13607
13608 \begin_layout Section
13609 Parameters
13610 \begin_inset LatexCommand \index{Parameters}
13611
13612 \end_inset
13613
13614
13615 \begin_inset LatexCommand \index{function parameter}
13616
13617 \end_inset
13618
13619  & Local Variables
13620 \begin_inset LatexCommand \index{local variables}
13621
13622 \end_inset
13623
13624
13625 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13626
13627 \end_inset
13628
13629
13630 \end_layout
13631
13632 \begin_layout Standard
13633 Automatic (local) variables and parameters to functions can either be placed
13634  on the stack or in data-space.
13635  The default action of the compiler is to place these variables in the internal
13636  RAM (for small model) or external RAM (for medium or large model).
13637  This in fact makes them similar to 
13638 \emph on
13639 static
13640 \begin_inset LatexCommand \index{static}
13641
13642 \end_inset
13643
13644
13645 \emph default
13646  so by default functions are non-reentrant
13647 \begin_inset LatexCommand \index{reentrant}
13648
13649 \end_inset
13650
13651 .
13652  
13653 \newline
13654
13655 \newline
13656 They can be placed on the stack
13657 \begin_inset LatexCommand \index{stack}
13658
13659 \end_inset
13660
13661  by using the
13662 \emph on
13663  -
13664 \begin_inset ERT
13665 status collapsed
13666
13667 \begin_layout Standard
13668
13669
13670 \backslash
13671 /
13672 \end_layout
13673
13674 \end_inset
13675
13676 -stack-auto
13677 \begin_inset LatexCommand \index{-\/-stack-auto}
13678
13679 \end_inset
13680
13681
13682 \emph default
13683  option, by using 
13684 \emph on
13685 #pragma\InsetSpace ~
13686 stackauto
13687 \emph default
13688
13689 \begin_inset LatexCommand \index{\#pragma stackauto}
13690
13691 \end_inset
13692
13693  or by using the 
13694 \emph on
13695 reentrant
13696 \begin_inset LatexCommand \index{reentrant}
13697
13698 \end_inset
13699
13700
13701 \emph default
13702  keyword in the function declaration, e.g.:
13703 \end_layout
13704
13705 \begin_layout Verse
13706
13707 \family typewriter
13708 unsigned char foo(char i) __reentrant 
13709 \newline
13710
13711 \newline
13712 \InsetSpace ~
13713 \InsetSpace ~
13714 \InsetSpace ~
13715 \InsetSpace ~
13716 ...
13717  
13718 \newline
13719 }
13720 \end_layout
13721
13722 \begin_layout Standard
13723 Since stack space on 8051 is limited, the 
13724 \emph on
13725 reentrant 
13726 \emph default
13727 keyword or the
13728 \emph on
13729  -
13730 \begin_inset ERT
13731 status collapsed
13732
13733 \begin_layout Standard
13734
13735
13736 \backslash
13737 /
13738 \end_layout
13739
13740 \end_inset
13741
13742 -stack-auto
13743 \emph default
13744  option should be used sparingly.
13745  Note that the reentrant keyword just means that the parameters & local
13746  variables will be allocated to the stack, it 
13747 \emph on
13748 does not
13749 \emph default
13750  mean that the function is register bank
13751 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13752
13753 \end_inset
13754
13755  independent.
13756 \newline
13757
13758 \newline
13759 Local variables
13760 \begin_inset LatexCommand \index{local variables}
13761
13762 \end_inset
13763
13764  can be assigned storage classes and absolute
13765 \begin_inset LatexCommand \index{Absolute addressing}
13766
13767 \end_inset
13768
13769  addresses, e.g.: 
13770 \end_layout
13771
13772 \begin_layout Verse
13773
13774 \family typewriter
13775 unsigned char foo() 
13776 \newline
13777 {
13778 \newline
13779 \InsetSpace ~
13780 \InsetSpace ~
13781 \InsetSpace ~
13782 \InsetSpace ~
13783 __xdata unsigned char i;
13784 \newline
13785 \InsetSpace ~
13786 \InsetSpace ~
13787 \InsetSpace ~
13788 \InsetSpace ~
13789 __bit bvar;
13790 \newline
13791 \InsetSpace ~
13792 \InsetSpace ~
13793 \InsetSpace ~
13794 \InsetSpace ~
13795 __data __at
13796 \begin_inset LatexCommand \index{at}
13797
13798 \end_inset
13799
13800  (0x31) unsigned char j;
13801 \newline
13802 \InsetSpace ~
13803 \InsetSpace ~
13804 \InsetSpace ~
13805 \InsetSpace ~
13806 ...
13807  
13808 \newline
13809 }
13810 \end_layout
13811
13812 \begin_layout Standard
13813 In the above example the variable 
13814 \emph on
13815 i
13816 \emph default
13817  will be allocated in the external ram, 
13818 \emph on
13819 bvar
13820 \emph default
13821  in bit addressable space and
13822 \emph on
13823  j
13824 \emph default
13825  in internal ram.
13826  When compiled with 
13827 \emph on
13828 -
13829 \begin_inset ERT
13830 status collapsed
13831
13832 \begin_layout Standard
13833
13834
13835 \backslash
13836 /
13837 \end_layout
13838
13839 \end_inset
13840
13841 -stack-auto
13842 \emph default
13843  or when a function is declared as 
13844 \emph on
13845 reentrant
13846 \emph default
13847  this should only be done for static variables.
13848 \end_layout
13849
13850 \begin_layout Standard
13851 Parameters
13852 \begin_inset LatexCommand \index{function parameter}
13853
13854 \end_inset
13855
13856  however are not allowed any storage class
13857 \begin_inset LatexCommand \index{Storage class}
13858
13859 \end_inset
13860
13861 , (storage classes for parameters will be ignored), their allocation is
13862  governed by the memory model in use, and the reentrancy options.
13863 \end_layout
13864
13865 \begin_layout Standard
13866 It is however allowed to use bit parameters in reentrant functions and also
13867  non-static local bit variables are supported.
13868  Efficient use is limited to 8 semi-bitregisters in bit space.
13869  They are pushed and popped to stack
13870 \begin_inset LatexCommand \index{stack}
13871
13872 \end_inset
13873
13874  as a single byte just like the normal registers.
13875 \end_layout
13876
13877 \begin_layout Section
13878 Overlaying
13879 \begin_inset LatexCommand \label{sub:Overlaying}
13880
13881 \end_inset
13882
13883
13884 \begin_inset LatexCommand \index{Overlaying}
13885
13886 \end_inset
13887
13888
13889 \end_layout
13890
13891 \begin_layout Standard
13892 For non-reentrant
13893 \begin_inset LatexCommand \index{reentrant}
13894
13895 \end_inset
13896
13897  functions SDCC will try to reduce internal ram space usage by overlaying
13898  parameters and local variables of a function (if possible).
13899  Parameters and local variables
13900 \begin_inset LatexCommand \index{local variables}
13901
13902 \end_inset
13903
13904  of a function will be allocated to an overlayable segment if the function
13905  has 
13906 \emph on
13907 no other function calls and the function is non-reentrant and the memory
13908  model
13909 \begin_inset LatexCommand \index{Memory model}
13910
13911 \end_inset
13912
13913  is small.
13914
13915 \emph default
13916  If an explicit storage class
13917 \begin_inset LatexCommand \index{Storage class}
13918
13919 \end_inset
13920
13921  is specified for a local variable, it will NOT be overlayed.
13922 \end_layout
13923
13924 \begin_layout Standard
13925 Note that the compiler (not the linkage editor) makes the decision for overlayin
13926 g the data items.
13927  Functions that are called from an interrupt service routine
13928 \begin_inset Marginal
13929 status collapsed
13930
13931 \begin_layout Standard
13932
13933 \series bold
13934 !
13935 \end_layout
13936
13937 \end_inset
13938
13939  should be preceded by a #pragma\InsetSpace ~
13940 nooverlay
13941 \begin_inset LatexCommand \index{\#pragma nooverlay}
13942
13943 \end_inset
13944
13945  if they are not reentrant.
13946 \end_layout
13947
13948 \begin_layout Standard
13949 Also note that the compiler does not do any processing of inline assembler
13950  code, so the compiler might incorrectly assign local variables and parameters
13951  of a function into the overlay segment if the inline assembler code calls
13952  other c-functions that might use the overlay.
13953  In that case the #pragma\InsetSpace ~
13954 nooverlay should be used.
13955 \end_layout
13956
13957 \begin_layout Standard
13958 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13959 tion
13960 \begin_inset LatexCommand \index{Multiplication}
13961
13962 \end_inset
13963
13964  or division
13965 \begin_inset LatexCommand \index{Division}
13966
13967 \end_inset
13968
13969  will NOT be overlayed since these are implemented using external functions,
13970  e.g.:
13971 \end_layout
13972
13973 \begin_layout Verse
13974
13975 \family typewriter
13976 #pragma save 
13977 \newline
13978 #pragma nooverlay
13979 \begin_inset LatexCommand \index{\#pragma nooverlay}
13980
13981 \end_inset
13982
13983  
13984 \newline
13985 void set_error(unsigned char errcd) 
13986 \newline
13987 {
13988 \newline
13989 \InsetSpace ~
13990 \InsetSpace ~
13991 \InsetSpace ~
13992 \InsetSpace ~
13993 P3 = errcd;
13994 \newline
13995
13996 \newline
13997 #pragma restore 
13998 \newline
13999
14000 \newline
14001 void
14002  some_isr () __interrupt
14003 \begin_inset LatexCommand \index{interrupt}
14004
14005 \end_inset
14006
14007  (2)
14008 \newline
14009 {
14010 \newline
14011 \InsetSpace ~
14012 \InsetSpace ~
14013 \InsetSpace ~
14014 \InsetSpace ~
14015 ...
14016 \newline
14017 \InsetSpace ~
14018 \InsetSpace ~
14019 \InsetSpace ~
14020 \InsetSpace ~
14021 set_error(10);
14022 \newline
14023 \InsetSpace ~
14024 \InsetSpace ~
14025 \InsetSpace ~
14026 \InsetSpace ~
14027 ...
14028  
14029 \newline
14030 }
14031 \end_layout
14032
14033 \begin_layout Standard
14034 In the above example the parameter 
14035 \emph on
14036 errcd
14037 \emph default
14038  for the function 
14039 \emph on
14040 set_error
14041 \emph default
14042  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14043 nooverlay was
14044  not present, this could cause unpredictable runtime behavior when called
14045  from an interrupt service routine.
14046  The #pragma\InsetSpace ~
14047 nooverlay ensures that the parameters and local variables for
14048  the function are NOT overlayed.
14049 \begin_inset VSpace bigskip
14050 \end_inset
14051
14052
14053 \end_layout
14054
14055 \begin_layout Section
14056 Interrupt Service Routines
14057 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14058
14059 \end_inset
14060
14061
14062 \end_layout
14063
14064 \begin_layout Subsection
14065 General Information
14066 \end_layout
14067
14068 \begin_layout Standard
14069 SDCC allows 
14070 \emph on
14071 i
14072 \emph default
14073 nterrupt 
14074 \emph on
14075 s
14076 \emph default
14077 ervice 
14078 \emph on
14079 r
14080 \emph default
14081 outines to be coded in C, with some extended keywords.
14082 \end_layout
14083
14084 \begin_layout Verse
14085
14086 \family typewriter
14087 void timer_isr (void) __interrupt (1) __using (1) 
14088 \newline
14089
14090 \newline
14091 \InsetSpace ~
14092 \InsetSpace ~
14093 \InsetSpace ~
14094 \InsetSpace ~
14095 ...
14096  
14097 \newline
14098 }
14099 \end_layout
14100
14101 \begin_layout Standard
14102 The optional number following the 
14103 \emph on
14104 interrupt
14105 \begin_inset LatexCommand \index{interrupt}
14106
14107 \end_inset
14108
14109
14110 \begin_inset LatexCommand \index{\_\_interrupt}
14111
14112 \end_inset
14113
14114
14115 \emph default
14116  keyword is the interrupt number this routine will service.
14117  When present, the compiler will insert a call to this routine in the interrupt
14118  vector table
14119 \begin_inset LatexCommand \index{interrupt vector table}
14120
14121 \end_inset
14122
14123  for the interrupt number specified.
14124  If you have multiple source files in your project, interrupt service routines
14125  can be present in any of them, but a prototype of the isr MUST be present
14126  or included in the file that contains the function 
14127 \emph on
14128 main
14129 \emph default
14130 .
14131  The optional (8051 specific) keyword 
14132 \emph on
14133 using
14134 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14135
14136 \end_inset
14137
14138
14139 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14140
14141 \end_inset
14142
14143
14144 \emph default
14145  can be used to tell the compiler to use the specified register bank when
14146  generating code for this function.
14147  
14148 \newline
14149 Interrupt service routines open the door for some very interesting bugs:
14150 \end_layout
14151
14152 \begin_layout Subsubsection
14153 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14154
14155 \end_inset
14156
14157 Common interrupt pitfall: variable not declared 
14158 \emph on
14159 volatile
14160 \end_layout
14161
14162 \begin_layout Standard
14163 If an interrupt service routine changes variables which are accessed by
14164  other functions these variables have to be declared 
14165 \emph on
14166 volatile
14167 \emph default
14168
14169 \begin_inset LatexCommand \index{volatile}
14170
14171 \end_inset
14172
14173 .
14174  See 
14175 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14176
14177 \end_inset
14178
14179  .
14180 \end_layout
14181
14182 \begin_layout Subsubsection
14183 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14184
14185 \end_inset
14186
14187 Common interrupt pitfall: 
14188 \emph on
14189 non-atomic access
14190 \end_layout
14191
14192 \begin_layout Standard
14193 If the access to these variables is not 
14194 \emph on
14195 atomic
14196 \begin_inset LatexCommand \index{atomic}
14197
14198 \end_inset
14199
14200
14201 \emph default
14202  (i.e.
14203  the processor needs more than one instruction for the access and could
14204  be interrupted while accessing the variable) the interrupt must be disabled
14205  during the access to avoid inconsistent data.
14206  
14207 \newline
14208 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14209  and should be protected by disabling interrupts.
14210  You're not automatically on the safe side if you use 8 bit variables though.
14211  We need an example here: f.e.
14212  on the 8051 the harmless looking 
14213 \begin_inset Quotes srd
14214 \end_inset
14215
14216
14217 \family typewriter
14218 flags\InsetSpace ~
14219 |=\InsetSpace ~
14220 0x80;
14221 \family default
14222
14223 \begin_inset Quotes sld
14224 \end_inset
14225
14226  is not atomic if 
14227 \family typewriter
14228 flags
14229 \family default
14230  resides in xdata.
14231  Setting 
14232 \begin_inset Quotes srd
14233 \end_inset
14234
14235
14236 \family typewriter
14237 flags\InsetSpace ~
14238 |=\InsetSpace ~
14239 0x40;
14240 \family default
14241
14242 \begin_inset Quotes sld
14243 \end_inset
14244
14245  from within an interrupt routine might get lost if the interrupt occurs
14246  at the wrong time.
14247  
14248 \begin_inset Quotes sld
14249 \end_inset
14250
14251
14252 \family typewriter
14253 counter\InsetSpace ~
14254 +=\InsetSpace ~
14255 8;
14256 \family default
14257
14258 \begin_inset Quotes srd
14259 \end_inset
14260
14261  is not atomic on the 8051 even if 
14262 \family typewriter
14263 counter
14264 \family default
14265  is located in data memory.
14266 \newline
14267 Bugs like these are hard to reproduce and can
14268  cause a lot of trouble.
14269  
14270 \end_layout
14271
14272 \begin_layout Subsubsection
14273 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14274
14275 \end_inset
14276
14277 Common interrupt pitfall: 
14278 \emph on
14279 stack overflow
14280 \end_layout
14281
14282 \begin_layout Standard
14283 The return address and the registers used in the interrupt service routine
14284  are saved on the stack
14285 \begin_inset LatexCommand \index{stack}
14286
14287 \end_inset
14288
14289  so there must be sufficient stack space.
14290  If there isn't variables or registers (or even the return address itself)
14291  will be corrupted.
14292  This 
14293 \emph on
14294 stack overflow
14295 \emph default
14296
14297 \begin_inset LatexCommand \index{stack overflow}
14298
14299 \end_inset
14300
14301  is most likely to happen if the interrupt occurs during the 
14302 \begin_inset Quotes sld
14303 \end_inset
14304
14305 deepest
14306 \begin_inset Quotes srd
14307 \end_inset
14308
14309  subroutine when the stack is already in use for f.e.
14310  many return addresses.
14311 \end_layout
14312
14313 \begin_layout Subsubsection
14314 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14315
14316 \end_inset
14317
14318 Common interrupt pitfall: 
14319 \emph on
14320 use of non-reentrant functions
14321 \end_layout
14322
14323 \begin_layout Standard
14324 A special note here, int (16 bit) and long (32 bit) integer division
14325 \begin_inset LatexCommand \index{Division}
14326
14327 \end_inset
14328
14329 , multiplication
14330 \begin_inset LatexCommand \index{Multiplication}
14331
14332 \end_inset
14333
14334  & modulus
14335 \begin_inset LatexCommand \index{Modulus}
14336
14337 \end_inset
14338
14339  and floating-point
14340 \begin_inset LatexCommand \index{Floating point support}
14341
14342 \end_inset
14343
14344  operations are implemented using external support routines.
14345  If an interrupt service routine needs to do any of these operations then
14346  the support routines (as mentioned in a following section) will have to
14347  be recompiled using the
14348 \emph on
14349  -
14350 \begin_inset ERT
14351 status collapsed
14352
14353 \begin_layout Standard
14354
14355
14356 \backslash
14357 /
14358 \end_layout
14359
14360 \end_inset
14361
14362 -stack-auto
14363 \begin_inset LatexCommand \index{-\/-stack-auto}
14364
14365 \end_inset
14366
14367
14368 \emph default
14369  option and the source file will need to be compiled using the 
14370 \emph on
14371 -
14372 \begin_inset ERT
14373 status collapsed
14374
14375 \begin_layout Standard
14376
14377
14378 \backslash
14379 /
14380 \end_layout
14381
14382 \end_inset
14383
14384 -int-long-reent
14385 \emph default
14386
14387 \begin_inset LatexCommand \index{-\/-int-long-reent}
14388
14389 \end_inset
14390
14391  compiler option.
14392  
14393 \newline
14394 Note, the type promotion
14395 \begin_inset LatexCommand \index{type promotion}
14396
14397 \end_inset
14398
14399  required by ANSI C can cause 16 bit routines to be used
14400 \begin_inset Marginal
14401 status collapsed
14402
14403 \begin_layout Standard
14404
14405 \series bold
14406 \InsetSpace ~
14407 !
14408 \end_layout
14409
14410 \end_inset
14411
14412  without the programmer being aware of it.
14413  See f.e.
14414  the cast 
14415 \family typewriter
14416 (unsigned char)(tail-1)
14417 \family default
14418  within the if clause in section 
14419 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14420
14421 \end_inset
14422
14423 .
14424 \end_layout
14425
14426 \begin_layout Standard
14427 Calling other functions from an interrupt service routine is not recommended,
14428  avoid it if possible.
14429  Note that when some function is called from an interrupt service routine
14430  it should be preceded by a #pragma\InsetSpace ~
14431 nooverlay
14432 \begin_inset LatexCommand \index{\#pragma nooverlay}
14433
14434 \end_inset
14435
14436  if it is not reentrant.
14437  Furthermore nonreentrant functions should not be called from the main program
14438  while the interrupt service routine might be active.
14439  They also must not be called from low priority interrupt service routines
14440  while a high priority interrupt service routine might be active.
14441  You could use semaphores or make the function
14442 \emph on
14443  critical
14444 \emph default
14445  if all parameters are passed in registers.
14446 \newline
14447  Also see section 
14448 \begin_inset LatexCommand \ref{sub:Overlaying}
14449
14450 \end_inset
14451
14452 \InsetSpace ~
14453 about Overlaying and section 
14454 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14455
14456 \end_inset
14457
14458 \InsetSpace ~
14459 about Functions using private register banks.
14460 \begin_inset VSpace bigskip
14461 \end_inset
14462
14463
14464 \end_layout
14465
14466 \begin_layout Subsection
14467 MCS51/DS390 Interrupt Service Routines
14468 \end_layout
14469
14470 \begin_layout Standard
14471 Interrupt
14472 \begin_inset LatexCommand \index{interrupt}
14473
14474 \end_inset
14475
14476  numbers and the corresponding address & descriptions for the Standard 8051/8052
14477  are listed below.
14478  SDCC will automatically adjust the 
14479 \begin_inset LatexCommand \index{interrupt vector table}
14480
14481 \end_inset
14482
14483  to the maximum interrupt number specified.
14484 \newline
14485
14486 \end_layout
14487
14488 \begin_layout Standard
14489 \align center
14490 \begin_inset Tabular
14491 <lyxtabular version="3" rows="9" columns="3">
14492 <features>
14493 <column alignment="center" valignment="top" leftline="true" width="0in">
14494 <column alignment="left" valignment="top" leftline="true" width="0in">
14495 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14496 <row topline="true" bottomline="true">
14497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14498 \begin_inset Text
14499
14500 \begin_layout Standard
14501 Interrupt #
14502 \end_layout
14503
14504 \end_inset
14505 </cell>
14506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14507 \begin_inset Text
14508
14509 \begin_layout Standard
14510 Description
14511 \end_layout
14512
14513 \end_inset
14514 </cell>
14515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14516 \begin_inset Text
14517
14518 \begin_layout Standard
14519 Vector Address
14520 \end_layout
14521
14522 \end_inset
14523 </cell>
14524 </row>
14525 <row topline="true">
14526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14527 \begin_inset Text
14528
14529 \begin_layout Standard
14530 0
14531 \end_layout
14532
14533 \end_inset
14534 </cell>
14535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14536 \begin_inset Text
14537
14538 \begin_layout Standard
14539 External 0
14540 \end_layout
14541
14542 \end_inset
14543 </cell>
14544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14545 \begin_inset Text
14546
14547 \begin_layout Standard
14548 0x0003
14549 \end_layout
14550
14551 \end_inset
14552 </cell>
14553 </row>
14554 <row topline="true">
14555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14556 \begin_inset Text
14557
14558 \begin_layout Standard
14559 1
14560 \end_layout
14561
14562 \end_inset
14563 </cell>
14564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14565 \begin_inset Text
14566
14567 \begin_layout Standard
14568 Timer 0
14569 \end_layout
14570
14571 \end_inset
14572 </cell>
14573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14574 \begin_inset Text
14575
14576 \begin_layout Standard
14577 0x000b
14578 \end_layout
14579
14580 \end_inset
14581 </cell>
14582 </row>
14583 <row topline="true">
14584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14585 \begin_inset Text
14586
14587 \begin_layout Standard
14588 2
14589 \end_layout
14590
14591 \end_inset
14592 </cell>
14593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14594 \begin_inset Text
14595
14596 \begin_layout Standard
14597 External 1
14598 \end_layout
14599
14600 \end_inset
14601 </cell>
14602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14603 \begin_inset Text
14604
14605 \begin_layout Standard
14606 0x0013
14607 \end_layout
14608
14609 \end_inset
14610 </cell>
14611 </row>
14612 <row topline="true">
14613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14614 \begin_inset Text
14615
14616 \begin_layout Standard
14617 3
14618 \end_layout
14619
14620 \end_inset
14621 </cell>
14622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14623 \begin_inset Text
14624
14625 \begin_layout Standard
14626 Timer 1
14627 \end_layout
14628
14629 \end_inset
14630 </cell>
14631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14632 \begin_inset Text
14633
14634 \begin_layout Standard
14635 0x001b
14636 \end_layout
14637
14638 \end_inset
14639 </cell>
14640 </row>
14641 <row topline="true">
14642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14643 \begin_inset Text
14644
14645 \begin_layout Standard
14646 4
14647 \end_layout
14648
14649 \end_inset
14650 </cell>
14651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14652 \begin_inset Text
14653
14654 \begin_layout Standard
14655 Serial
14656 \end_layout
14657
14658 \end_inset
14659 </cell>
14660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14661 \begin_inset Text
14662
14663 \begin_layout Standard
14664 0x0023
14665 \end_layout
14666
14667 \end_inset
14668 </cell>
14669 </row>
14670 <row topline="true">
14671 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14672 \begin_inset Text
14673
14674 \begin_layout Standard
14675 5
14676 \end_layout
14677
14678 \end_inset
14679 </cell>
14680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14681 \begin_inset Text
14682
14683 \begin_layout Standard
14684 Timer 2 (8052)
14685 \end_layout
14686
14687 \end_inset
14688 </cell>
14689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14690 \begin_inset Text
14691
14692 \begin_layout Standard
14693 0x002b
14694 \end_layout
14695
14696 \end_inset
14697 </cell>
14698 </row>
14699 <row topline="true">
14700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14701 \begin_inset Text
14702
14703 \begin_layout Standard
14704 ...
14705 \end_layout
14706
14707 \end_inset
14708 </cell>
14709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14710 \begin_inset Text
14711
14712 \begin_layout Standard
14713
14714 \end_layout
14715
14716 \end_inset
14717 </cell>
14718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14719 \begin_inset Text
14720
14721 \begin_layout Standard
14722 ...
14723 \end_layout
14724
14725 \end_inset
14726 </cell>
14727 </row>
14728 <row topline="true" bottomline="true">
14729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14730 \begin_inset Text
14731
14732 \begin_layout Standard
14733 n
14734 \end_layout
14735
14736 \end_inset
14737 </cell>
14738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14739 \begin_inset Text
14740
14741 \begin_layout Standard
14742
14743 \end_layout
14744
14745 \end_inset
14746 </cell>
14747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14748 \begin_inset Text
14749
14750 \begin_layout Standard
14751 0x0003 + 8*n
14752 \end_layout
14753
14754 \end_inset
14755 </cell>
14756 </row>
14757 </lyxtabular>
14758
14759 \end_inset
14760
14761
14762 \newline
14763
14764 \end_layout
14765
14766 \begin_layout Standard
14767 If the interrupt service routine is defined without 
14768 \emph on
14769 using
14770 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14771
14772 \end_inset
14773
14774
14775 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14776
14777 \end_inset
14778
14779
14780 \emph default
14781  a register bank or with register bank 0 (
14782 \emph on
14783 using
14784 \emph default
14785  0), the compiler will save the registers used by itself on the stack upon
14786  entry and restore them at exit, however if such an interrupt service routine
14787  calls another function then the entire register bank will be saved on the
14788  stack.
14789  This scheme may be advantageous for small interrupt service routines which
14790  have low register usage.
14791 \end_layout
14792
14793 \begin_layout Standard
14794 If the interrupt service routine is defined to be using a specific register
14795  bank then only 
14796 \emph on
14797 a, b, dptr
14798 \emph default
14799  & psw are saved and restored, if such an interrupt service routine calls
14800  another function (using another register bank) then the entire register
14801  bank of the called function will be saved on the stack
14802 \begin_inset LatexCommand \index{stack}
14803
14804 \end_inset
14805
14806 .
14807  This scheme is recommended for larger interrupt service routines.
14808 \begin_inset VSpace bigskip
14809 \end_inset
14810
14811
14812 \end_layout
14813
14814 \begin_layout Subsection
14815 HC08
14816 \begin_inset LatexCommand \index{HC08}
14817
14818 \end_inset
14819
14820  Interrupt Service Routines
14821 \end_layout
14822
14823 \begin_layout Standard
14824 Since the number of interrupts
14825 \begin_inset LatexCommand \index{HC08!interrupt}
14826
14827 \end_inset
14828
14829  available is chip specific and the interrupt vector table always ends at
14830  the last byte of memory, the interrupt numbers corresponds to the interrupt
14831  vectors in reverse order of address.
14832  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14833  2 will use the interrupt vector at 0xfffa, and so on.
14834  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14835  this way; instead see section 
14836 \begin_inset LatexCommand \ref{sub:Startup-Code}
14837
14838 \end_inset
14839
14840  for details on customizing startup.
14841 \begin_inset VSpace bigskip
14842 \end_inset
14843
14844
14845 \end_layout
14846
14847 \begin_layout Subsection
14848 Z80 Interrupt Service Routines
14849 \end_layout
14850
14851 \begin_layout Standard
14852 The Z80
14853 \begin_inset LatexCommand \index{Z80}
14854
14855 \end_inset
14856
14857  uses several different methods for determining the correct interrupt
14858 \begin_inset LatexCommand \index{Z80!interrupt}
14859
14860 \end_inset
14861
14862  vector depending on the hardware implementation.
14863  Therefore, SDCC ignores the optional interrupt number and does not attempt
14864  to generate an interrupt vector table.
14865 \end_layout
14866
14867 \begin_layout Standard
14868 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14869  instruction to return from the interrupt.
14870  To write an interrupt handler for the non-maskable interrupt, which needs
14871  a RETN instruction instead, add the 
14872 \emph on
14873 critical
14874 \emph default
14875  keyword:
14876 \end_layout
14877
14878 \begin_layout Verse
14879
14880 \family typewriter
14881 void nmi_isr (void) critical interrupt
14882 \newline
14883
14884 \newline
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 ...
14890  
14891 \newline
14892 }
14893 \end_layout
14894
14895 \begin_layout Standard
14896 However if you need to create a non-interruptable interrupt service routine
14897  you would also require the 
14898 \emph on
14899 critical
14900 \emph default
14901  keyword.
14902  To distinguish between this and an nmi_isr you must provide an interrupt
14903  number.
14904 \begin_inset VSpace bigskip
14905 \end_inset
14906
14907
14908 \end_layout
14909
14910 \begin_layout Section
14911 Enabling and Disabling Interrupts
14912 \end_layout
14913
14914 \begin_layout Subsection
14915 Critical Functions and Critical Statements
14916 \end_layout
14917
14918 \begin_layout Standard
14919 A special keyword may be associated with a block or a function declaring
14920  it as 
14921 \emph on
14922 critical
14923 \emph default
14924 .
14925  SDCC will generate code to disable all interrupts
14926 \begin_inset LatexCommand \index{interrupt}
14927
14928 \end_inset
14929
14930  upon entry to a critical function and restore the interrupt enable to the
14931  previous state before returning.
14932  Nesting critical functions will need one additional byte on the stack
14933 \begin_inset LatexCommand \index{stack}
14934
14935 \end_inset
14936
14937  for each call.
14938 \end_layout
14939
14940 \begin_layout Verse
14941
14942 \family typewriter
14943 int foo () __critical
14944 \begin_inset LatexCommand \index{critical}
14945
14946 \end_inset
14947
14948
14949 \begin_inset LatexCommand \index{\_\_critical}
14950
14951 \end_inset
14952
14953  
14954 \newline
14955
14956 \newline
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 ...
14962  
14963 \newline
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 ...
14969  
14970 \newline
14971 }
14972 \end_layout
14973
14974 \begin_layout Standard
14975 The critical attribute maybe used with other attributes like 
14976 \emph on
14977 reentrant.
14978 \emph default
14979
14980 \newline
14981 The keyword 
14982 \emph on
14983 critical
14984 \emph default
14985  may also be used to disable interrupts more locally:
14986 \end_layout
14987
14988 \begin_layout Verse
14989
14990 \family typewriter
14991 __critical{ i++; }
14992 \end_layout
14993
14994 \begin_layout Standard
14995 More than one statement could have been included in the block.
14996 \end_layout
14997
14998 \begin_layout Subsection
14999 Enabling and Disabling Interrupts directly
15000 \end_layout
15001
15002 \begin_layout Standard
15003 Interrupts
15004 \begin_inset LatexCommand \index{interrupt}
15005
15006 \end_inset
15007
15008  can also be disabled and enabled directly (8051):
15009 \end_layout
15010
15011 \begin_layout Verse
15012
15013 \family typewriter
15014 EA = 0;\InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 or:\InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 EA_SAVE = EA;
15038 \end_layout
15039
15040 \begin_layout Verse
15041
15042 \family typewriter
15043 ...\InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 \InsetSpace ~
15049 \InsetSpace ~
15050 \InsetSpace ~
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 \InsetSpace ~
15060 \InsetSpace ~
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 \InsetSpace ~
15070 \InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 EA = 0;
15074 \end_layout
15075
15076 \begin_layout Verse
15077
15078 \family typewriter
15079 EA = 1;\InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 \InsetSpace ~
15104 \InsetSpace ~
15105 ...
15106 \end_layout
15107
15108 \begin_layout Verse
15109
15110 \family typewriter
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 \InsetSpace ~
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 EA = EA_SAVE;
15145 \end_layout
15146
15147 \begin_layout Standard
15148 On other architectures which have seperate opcodes for enabling and disabling
15149  interrupts you might want to make use of defines with inline assembly
15150 \begin_inset LatexCommand \index{Assembler routines}
15151
15152 \end_inset
15153
15154  (HC08
15155 \begin_inset LatexCommand \index{HC08!interrupt}
15156
15157 \end_inset
15158
15159 ):
15160 \end_layout
15161
15162 \begin_layout Verse
15163
15164 \family typewriter
15165 #define CLI _asm
15166 \begin_inset LatexCommand \index{\_asm}
15167
15168 \end_inset
15169
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 cli\InsetSpace ~
15173 \InsetSpace ~
15174 _endasm
15175 \begin_inset LatexCommand \index{\_endasm}
15176
15177 \end_inset
15178
15179
15180 \end_layout
15181
15182 \begin_layout Verse
15183
15184 \family typewriter
15185 #define SEI _asm\InsetSpace ~
15186 \InsetSpace ~
15187 sei\InsetSpace ~
15188 \InsetSpace ~
15189 _endasm; 
15190 \end_layout
15191
15192 \begin_layout Verse
15193
15194 \family typewriter
15195 ...
15196 \end_layout
15197
15198 \begin_layout Standard
15199 Note: it is sometimes sufficient to disable only a specific interrupt source
15200  like f.e.
15201  a timer or serial interrupt by manipulating an 
15202 \emph on
15203 interrupt mask
15204 \begin_inset LatexCommand \index{interrupt mask}
15205
15206 \end_inset
15207
15208
15209 \emph default
15210  register.
15211  
15212 \end_layout
15213
15214 \begin_layout Standard
15215 Usually the time during which interrupts are disabled should be kept as
15216  short as possible.
15217  This minimizes both 
15218 \emph on
15219 interrupt latency
15220 \emph default
15221
15222 \begin_inset LatexCommand \index{interrupt latency}
15223
15224 \end_inset
15225
15226  (the time between the occurrence of the interrupt and the execution of
15227  the first code in the interrupt routine) and 
15228 \emph on
15229 interrupt jitter
15230 \emph default
15231
15232 \begin_inset LatexCommand \index{interrupt jitter}
15233
15234 \end_inset
15235
15236  (the difference between the shortest and the longest interrupt latency).
15237  These really are something different, f.e.
15238  a serial interrupt has to be served before its buffer overruns so it cares
15239  for the maximum interrupt latency, whereas it does not care about jitter.
15240  On a loudspeaker driven via a digital to analog converter which is fed
15241  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15242  a much smaller jitter will be very audible.
15243 \end_layout
15244
15245 \begin_layout Standard
15246 You can reenable interrupts within an interrupt routine and on some architecture
15247 s you can make use of two (or more) levels of 
15248 \emph on
15249 interrupt priorities
15250 \emph default
15251
15252 \begin_inset LatexCommand \index{interrupt priority}
15253
15254 \end_inset
15255
15256 .
15257  On some architectures which don't support interrupt priorities these can
15258  be implemented by manipulating the interrupt mask and reenabling interrupts
15259  within the interrupt routine.
15260  Check there is sufficient space on the stack
15261 \begin_inset LatexCommand \index{stack}
15262
15263 \end_inset
15264
15265  and don't add complexity unless you have to.
15266  
15267 \end_layout
15268
15269 \begin_layout Subsection
15270 Semaphore
15271 \begin_inset LatexCommand \index{semaphore}
15272
15273 \end_inset
15274
15275  locking (mcs51/ds390)
15276 \end_layout
15277
15278 \begin_layout Standard
15279 Some architectures (mcs51/ds390) have an atomic
15280 \begin_inset LatexCommand \index{atomic}
15281
15282 \end_inset
15283
15284  bit test and
15285 \emph on
15286  
15287 \emph default
15288 clear
15289 \emph on
15290  
15291 \emph default
15292 instruction.
15293  These type of instructions are typically used in preemptive multitasking
15294  systems, where a routine f.e.
15295  claims the use of a data structure ('acquires a lock
15296 \begin_inset LatexCommand \index{lock}
15297
15298 \end_inset
15299
15300  on it'), makes some modifications and then releases the lock when the data
15301  structure is consistent again.
15302  The instruction may also be used if interrupt and non-interrupt code have
15303  to compete for a resource.
15304  With the atomic bit test and clear instruction interrupts
15305 \begin_inset LatexCommand \index{interrupt}
15306
15307 \end_inset
15308
15309  don't have to be disabled for the locking operation.
15310  
15311 \end_layout
15312
15313 \begin_layout Standard
15314 SDCC generates this instruction if the source follows this pattern:
15315 \end_layout
15316
15317 \begin_layout Verse
15318
15319 \family typewriter
15320 volatile
15321 \begin_inset LatexCommand \index{volatile}
15322
15323 \end_inset
15324
15325  bit resource_is_free; 
15326 \newline
15327
15328 \newline
15329 if (resource_is_free) 
15330 \newline
15331 \InsetSpace ~
15332 \InsetSpace ~
15333
15334 \newline
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 resource_is_free=0; 
15340 \newline
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 ...
15346  
15347 \newline
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 \InsetSpace ~
15352 resource_is_free=1;
15353 \newline
15354 \InsetSpace ~
15355 \InsetSpace ~
15356
15357 \end_layout
15358
15359 \begin_layout Standard
15360 Note, mcs51 and ds390 support only an atomic
15361 \begin_inset LatexCommand \index{atomic}
15362
15363 \end_inset
15364
15365  bit test and 
15366 \emph on
15367 clear
15368 \emph default
15369  instruction (as opposed to atomic bit test and 
15370 \emph on
15371 set).
15372 \end_layout
15373
15374 \begin_layout Section
15375 Functions using private register banks
15376 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15377
15378 \end_inset
15379
15380  (mcs51/ds390)
15381 \end_layout
15382
15383 \begin_layout Standard
15384 Some architectures have support for quickly changing register sets.
15385  SDCC supports this feature with the 
15386 \emph on
15387 using
15388 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15389
15390 \end_inset
15391
15392
15393 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15394
15395 \end_inset
15396
15397
15398 \emph default
15399  attribute (which tells the compiler to use a register bank
15400 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15401
15402 \end_inset
15403
15404  other than the default bank zero).
15405  It should only be applied to 
15406 \emph on
15407 interrupt
15408 \begin_inset LatexCommand \index{interrupt}
15409
15410 \end_inset
15411
15412
15413 \emph default
15414  functions (see footnote below).
15415  This will in most circumstances make the generated ISR code more efficient
15416  since it will not have to save registers on the stack.
15417 \end_layout
15418
15419 \begin_layout Standard
15420 The 
15421 \emph on
15422 using
15423 \emph default
15424  attribute will have no effect on the generated code for a 
15425 \emph on
15426 non-interrupt
15427 \emph default
15428  function (but may occasionally be useful anyway
15429 \begin_inset Foot
15430 status open
15431
15432 \begin_layout Standard
15433 possible exception: if a function is called ONLY from 'interrupt' functions
15434  using a particular bank, it can be declared with the same 'using' attribute
15435  as the calling 'interrupt' functions.
15436  For instance, if you have several ISRs using bank one, and all of them
15437  call memcpy(), it might make sense to create a specialized version of memcpy()
15438  'using 1', since this would prevent the ISR from having to save bank zero
15439  to the stack on entry and switch to bank zero before calling the function
15440 \end_layout
15441
15442 \end_inset
15443
15444 ).
15445 \newline
15446
15447 \emph on
15448 (pending: Note, nowadays the 
15449 \emph default
15450 using
15451 \emph on
15452  attribute has an effect on
15453 \emph default
15454  
15455 \emph on
15456 the generated code for a 
15457 \emph default
15458 non-interrupt
15459 \emph on
15460  function
15461 \emph default
15462 .
15463 \emph on
15464 )
15465 \end_layout
15466
15467 \begin_layout Standard
15468 An 
15469 \emph on
15470 interrupt
15471 \emph default
15472  function using a non-zero bank will assume that it can trash that register
15473  bank, and will not save it.
15474  Since high-priority interrupts
15475 \begin_inset LatexCommand \index{interrupts}
15476
15477 \end_inset
15478
15479
15480 \begin_inset LatexCommand \index{interrupt priority}
15481
15482 \end_inset
15483
15484  can interrupt low-priority ones on the 8051 and friends, this means that
15485  if a high-priority ISR 
15486 \emph on
15487 using
15488 \emph default
15489  a particular bank occurs while processing a low-priority ISR 
15490 \emph on
15491 using
15492 \emph default
15493  the same bank, terrible and bad things can happen.
15494  To prevent this, no single register bank should be 
15495 \emph on
15496 used
15497 \emph default
15498  by both a high priority and a low priority ISR.
15499  This is probably most easily done by having all high priority ISRs use
15500  one bank and all low priority ISRs use another.
15501  If you have an ISR which can change priority at runtime, you're on your
15502  own: I suggest using the default bank zero and taking the small performance
15503  hit.
15504 \end_layout
15505
15506 \begin_layout Standard
15507 It is most efficient if your ISR calls no other functions.
15508  If your ISR must call other functions, it is most efficient if those functions
15509  use the same bank as the ISR (see note 1 below); the next best is if the
15510  called functions use bank zero.
15511  It is very inefficient to call a function using a different, non-zero bank
15512  from an ISR.
15513  
15514 \begin_inset VSpace bigskip
15515 \end_inset
15516
15517
15518 \end_layout
15519
15520 \begin_layout Section
15521 Startup Code
15522 \begin_inset LatexCommand \label{sub:Startup-Code}
15523
15524 \end_inset
15525
15526
15527 \begin_inset LatexCommand \index{Startup code}
15528
15529 \end_inset
15530
15531
15532 \end_layout
15533
15534 \begin_layout Subsection
15535 MCS51/DS390 Startup Code
15536 \end_layout
15537
15538 \begin_layout Standard
15539 The compiler triggers the linker to link certain initialization modules
15540  from the runtime library
15541 \begin_inset LatexCommand \index{Runtime library}
15542
15543 \end_inset
15544
15545  called crt<something>.
15546  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15547  GSINIT5) is not linked unless the -
15548 \series bold
15549
15550 \begin_inset ERT
15551 status open
15552
15553 \begin_layout Standard
15554
15555
15556 \backslash
15557 /
15558 \end_layout
15559
15560 \end_inset
15561
15562
15563 \series default
15564 -xstack option is used.
15565  These modules are highly entangled by the use of special segments/areas,
15566  but a common layout is shown below:
15567 \end_layout
15568
15569 \begin_layout Verse
15570
15571 \family typewriter
15572 \series bold
15573 \size footnotesize
15574 (main.asm)
15575 \end_layout
15576
15577 \begin_layout Verse
15578
15579 \family typewriter
15580 \size footnotesize
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 .area HOME (CODE)
15590 \newline
15591 __interrupt_vect:
15592 \newline
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 ljmp __sdcc_gsinit_startup
15602 \end_layout
15603
15604 \begin_layout Verse
15605
15606 \family typewriter
15607 \series bold
15608 \size footnotesize
15609 (crtstart.asm)
15610 \end_layout
15611
15612 \begin_layout Verse
15613
15614 \family typewriter
15615 \size footnotesize
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 .area GSINIT0 (CODE)
15625 \newline
15626 __sdcc_gsinit_startup::
15627 \newline
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 \InsetSpace ~
15632 \InsetSpace ~
15633 \InsetSpace ~
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 mov sp,#__start__stack - 1
15637 \end_layout
15638
15639 \begin_layout Verse
15640
15641 \family typewriter
15642 \series bold
15643 \size footnotesize
15644 (crtxstack.asm)
15645 \end_layout
15646
15647 \begin_layout Verse
15648
15649 \family typewriter
15650 \size footnotesize
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 .area GSINIT1 (CODE)
15660 \newline
15661 __sdcc_init_xstack::
15662 \newline
15663 ; Need to initialize in GSINIT1 in
15664  case the user's __sdcc_external_startup uses the xstack.
15665 \newline
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 mov __XPAGE,#(__start__x
15675 stack >> 8)
15676 \newline
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 mov _spx,#__start__xstack
15686 \end_layout
15687
15688 \begin_layout Verse
15689
15690 \family typewriter
15691 \series bold
15692 \size footnotesize
15693 (crtstart.asm)
15694 \end_layout
15695
15696 \begin_layout Verse
15697
15698 \family typewriter
15699 \size footnotesize
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 .area GSINIT2 (CODE)
15709 \newline
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 lcall __sdcc_external_startup
15719 \newline
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 mov a,dpl
15729 \newline
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 jz __sdcc_init_data
15739 \newline
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 ljmp
15749  __sdcc_program_startup
15750 \newline
15751 __sdcc_init_data:
15752 \end_layout
15753
15754 \begin_layout Verse
15755
15756 \family typewriter
15757 \series bold
15758 \size footnotesize
15759 (crtxinit.asm)
15760 \end_layout
15761
15762 \begin_layout Verse
15763
15764 \family typewriter
15765 \size footnotesize
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 .area GSINIT3 (CODE)
15775 \newline
15776 __mcs51_genXINIT::
15777 \newline
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 \InsetSpace ~
15785 \InsetSpace ~
15786 mov r1,#l_XINIT
15787 \newline
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 mov a,r1
15797 \newline
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 orl a,#(l_XINIT
15807  >> 8)
15808 \newline
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 jz 00003$
15818 \newline
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 mov r2,#((l_XINIT+255) >> 8)
15828 \newline
15829 \InsetSpace ~
15830 \InsetSpace ~
15831 \InsetSpace ~
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 mov dptr,#s_XINIT
15838 \newline
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 mov r0,#s_XISEG
15848 \newline
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 mov
15858  __XPAGE,#(s_XISEG >> 8)
15859 \newline
15860 00001$:\InsetSpace ~
15861 clr a
15862 \newline
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 movc a,@a+dptr
15872 \newline
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 movx @r0,a
15882 \newline
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 inc dptr
15892 \newline
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 inc
15902  r0
15903 \newline
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 cjne r0,#0,00002$
15913 \newline
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 inc __XPAGE
15923 \newline
15924 00002$:\InsetSpace ~
15925 djnz r1,00001$
15926 \newline
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 djnz r2,00001$
15936 \newline
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 mov __XPAGE,#0
15946 xFF
15947 \newline
15948 00003$:
15949 \end_layout
15950
15951 \begin_layout Verse
15952
15953 \family typewriter
15954 \series bold
15955 \size footnotesize
15956 (crtclear.asm)
15957 \end_layout
15958
15959 \begin_layout Verse
15960
15961 \family typewriter
15962 \size footnotesize
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 .area GSINIT4 (CODE)
15972 \newline
15973 __mcs51_genRAMCLEAR::
15974 \newline
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 clr a
15984 \newline
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 mov r0,#(l_IRAM-1)
15994 \newline
15995 00004$:\InsetSpace ~
15996 mov
15997  @r0,a
15998 \newline
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 djnz r0,00004$
16008 \newline
16009 ; _mcs51_genRAMCLEAR() end
16010 \end_layout
16011
16012 \begin_layout Verse
16013
16014 \family typewriter
16015 \series bold
16016 \size footnotesize
16017 (crtxclear.asm)
16018 \end_layout
16019
16020 \begin_layout Verse
16021
16022 \family typewriter
16023 \size footnotesize
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 .area GSINIT4 (CODE)
16033 \newline
16034 __mcs51_genXRAMCLEAR::
16035 \newline
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 mov r0,#l_PSEG
16045 \newline
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 mov a,r0
16055 \newline
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 \InsetSpace ~
16064 orl a,#(l_PSEG
16065  >> 8)
16066 \newline
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 \InsetSpace ~
16073 \InsetSpace ~
16074 \InsetSpace ~
16075 jz 00006$
16076 \newline
16077 \InsetSpace ~
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 mov r1,#s_PSEG
16086 \newline
16087 \InsetSpace ~
16088 \InsetSpace ~
16089 \InsetSpace ~
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 mov __XPAGE,#(s_PSEG >> 8)
16096 \newline
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 \InsetSpace ~
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 clr a
16106 \newline
16107 00005$:\InsetSpace ~
16108 movx
16109  @r1,a
16110 \newline
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 inc r1
16120 \newline
16121 \InsetSpace ~
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 djnz r0,00005$
16130 \newline
16131 00006$:
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 mov r0,#l_XSEG
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov a,r0
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 orl a,#(l_XSEG >>
16162  8)
16163 \newline
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 jz 00008$
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 mov r1,#((l_XSEG + 255) >> 8)
16183 \newline
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 mov dptr,#s_XSEG
16193 \newline
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 clr a
16203 \newline
16204 00007$:\InsetSpace ~
16205 movx
16206  @dptr,a
16207 \newline
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 inc dptr
16217 \newline
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 djnz r0,00007$
16227 \newline
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 djnz r1,00007$
16237 \newline
16238 00008$:
16239 \end_layout
16240
16241 \begin_layout Verse
16242
16243 \family typewriter
16244 \series bold
16245 \size footnotesize
16246 (crtxstack.asm)
16247 \end_layout
16248
16249 \begin_layout Verse
16250
16251 \family typewriter
16252 \size footnotesize
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 .area GSINIT5 (CODE)
16262 \newline
16263 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16264  modifies __XPAGE
16265 \newline
16266 ; and __mcs51_genRAMCLEAR modifies _spx.
16267 \newline
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 \InsetSpace ~
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 mov __XPAGE,#(__start__x
16277 stack >> 8)
16278 \newline
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 mov _spx,#__start__xstack
16288 \end_layout
16289
16290 \begin_layout Verse
16291
16292 \family typewriter
16293 \series bold
16294 \size footnotesize
16295 (application modules)
16296 \end_layout
16297
16298 \begin_layout Verse
16299
16300 \family typewriter
16301 \size footnotesize
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 \InsetSpace ~
16308 \InsetSpace ~
16309 \InsetSpace ~
16310 .area GSINIT (CODE)
16311 \end_layout
16312
16313 \begin_layout Verse
16314
16315 \family typewriter
16316 \series bold
16317 \size footnotesize
16318 (main.asm)
16319 \end_layout
16320
16321 \begin_layout Verse
16322
16323 \family typewriter
16324 \size footnotesize
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 .area GSFINAL (CODE)
16334 \newline
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 ljmp __sdcc_program_startup
16344 \newline
16345 ;---------------------------------
16346 -----------------------
16347 \newline
16348 ; Home
16349 \newline
16350 ;--------------------------------------------------
16351 ------
16352 \newline
16353 \InsetSpace ~
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 .area HOME (CODE)
16362 \newline
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 \InsetSpace ~
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 .area CSEG (CODE)
16372 \newline
16373 __sdcc_program_startup:
16374 \newline
16375 \InsetSpace ~
16376 \InsetSpace ~
16377 \InsetSpace ~
16378 \InsetSpace ~
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 lcall _main
16384 \newline
16385 ;
16386  return from main will lock up
16387 \newline
16388 \InsetSpace ~
16389 \InsetSpace ~
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 sjmp .
16397 \end_layout
16398
16399 \begin_layout Standard
16400 One of these modules (crtstart.asm) contains a call to the C routine 
16401 \emph on
16402 _sdcc_external_startup()
16403 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16404
16405 \end_inset
16406
16407
16408 \series bold
16409 \emph default
16410  
16411 \series default
16412 at the start of the CODE area.
16413  This routine is also in the runtime library
16414 \begin_inset LatexCommand \index{Runtime library}
16415
16416 \end_inset
16417
16418  and returns 0 by default.
16419  If this routine returns a non-zero value, the static & global variable
16420  initialization will be skipped and the function main will be invoked.
16421  Otherwise static & global variables will be initialized before the function
16422  main is invoked.
16423  You could add an 
16424 \emph on
16425 _sdcc_external_startup()
16426 \emph default
16427  routine to your program to override the default if you need to setup hardware
16428  or perform some other critical operation prior to static & global variable
16429  initialization
16430 \begin_inset LatexCommand \index{Variable initialization}
16431
16432 \end_inset
16433
16434 .
16435  On some mcs51 variants xdata
16436 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16437
16438 \end_inset
16439
16440  memory has to be explicitly enabled before it can be accessed or if the
16441  watchdog
16442 \begin_inset LatexCommand \index{watchdog}
16443
16444 \end_inset
16445
16446  needs to be disabled, this is the place to do it.
16447  The startup code clears all internal data memory, 256 bytes by default,
16448  but from 0 to n-1 if 
16449 \emph on
16450 -
16451 \begin_inset ERT
16452 status collapsed
16453
16454 \begin_layout Standard
16455
16456
16457 \backslash
16458 /
16459 \end_layout
16460
16461 \end_inset
16462
16463 -iram-size
16464 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16465
16466 \end_inset
16467
16468 n
16469 \emph default
16470  is used.
16471  (recommended for Chipcon CC1010).
16472 \end_layout
16473
16474 \begin_layout Standard
16475 See also the compiler options 
16476 \emph on
16477 -
16478 \begin_inset ERT
16479 status collapsed
16480
16481 \begin_layout Standard
16482
16483
16484 \backslash
16485 /
16486 \end_layout
16487
16488 \end_inset
16489
16490 -no-xinit
16491 \emph default
16492 -
16493 \emph on
16494 opt
16495 \emph default
16496
16497 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16498
16499 \end_inset
16500
16501
16502 \emph on
16503 -
16504 \begin_inset ERT
16505 status collapsed
16506
16507 \begin_layout Standard
16508
16509
16510 \backslash
16511 /
16512 \end_layout
16513
16514 \end_inset
16515
16516 -main-return
16517 \emph default
16518
16519 \begin_inset LatexCommand \index{-\/-main-return}
16520
16521 \end_inset
16522
16523  and section 
16524 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16525
16526 \end_inset
16527
16528  about MCS51-variants.
16529 \newline
16530
16531 \end_layout
16532
16533 \begin_layout Standard
16534 While these initialization modules are meant as generic startup code there
16535  might be the need for customization.
16536  Let's assume the return value of 
16537 \emph on
16538 _sdcc_external_startup()
16539 \emph default
16540  in 
16541 \emph on
16542 crtstart.asm
16543 \emph default
16544  should not be checked (or 
16545 \emph on
16546 _sdcc_external_startup()
16547 \emph default
16548  should not be called at all).
16549  The recommended way would be to copy 
16550 \emph on
16551 crtstart.asm
16552 \emph default
16553  (f.e.
16554  from 
16555 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16556
16557 \end_inset
16558
16559 ) into the source directory, adapt it there, then assemble it with 
16560 \emph on
16561 asx8051 -plosgff
16562 \begin_inset Foot
16563 status open
16564
16565 \begin_layout Standard
16566 \begin_inset Quotes sld
16567 \end_inset
16568
16569 -plosgff
16570 \begin_inset Quotes srd
16571 \end_inset
16572
16573  are the assembler options used in 
16574 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16575
16576 \end_inset
16577
16578
16579 \end_layout
16580
16581 \end_inset
16582
16583  crtstart.asm
16584 \emph default
16585  and when linking your project explicitely specify 
16586 \emph on
16587 crtstart.rel
16588 \emph default
16589 .
16590  As a bonus a listing of the relocated object file 
16591 \emph on
16592 crtstart.rst
16593 \emph default
16594  is generated.
16595 \end_layout
16596
16597 \begin_layout Standard
16598 \begin_inset VSpace bigskip
16599 \end_inset
16600
16601
16602 \end_layout
16603
16604 \begin_layout Subsection
16605 HC08 Startup Code
16606 \end_layout
16607
16608 \begin_layout Standard
16609 The HC08
16610 \begin_inset LatexCommand \index{HC08}
16611
16612 \end_inset
16613
16614  startup code follows the same scheme as the MCS51 startup code.
16615 \begin_inset VSpace bigskip
16616 \end_inset
16617
16618
16619 \end_layout
16620
16621 \begin_layout Subsection
16622 Z80 Startup Code
16623 \end_layout
16624
16625 \begin_layout Standard
16626 On the Z80
16627 \begin_inset LatexCommand \index{Z80}
16628
16629 \end_inset
16630
16631  the startup code is inserted by linking with crt0.o which is generated from
16632  sdcc/device/lib/z80/crt0.s.
16633  If you need a different startup code you can use the compiler option 
16634 \emph on
16635 -
16636 \series bold
16637 \emph default
16638
16639 \begin_inset ERT
16640 status collapsed
16641
16642 \begin_layout Standard
16643
16644
16645 \backslash
16646 /
16647 \end_layout
16648
16649 \end_inset
16650
16651
16652 \series default
16653 \emph on
16654 -no-std-crt0
16655 \emph default
16656
16657 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16658
16659 \end_inset
16660
16661  and provide your own crt0.o.
16662  
16663 \begin_inset VSpace bigskip
16664 \end_inset
16665
16666
16667 \end_layout
16668
16669 \begin_layout Section
16670 Inline Assembler Code
16671 \begin_inset LatexCommand \index{Assembler routines}
16672
16673 \end_inset
16674
16675
16676 \end_layout
16677
16678 \begin_layout Subsection
16679 A Step by Step Introduction
16680 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16681
16682 \end_inset
16683
16684
16685 \end_layout
16686
16687 \begin_layout Standard
16688 Starting from a small snippet of c-code this example shows for the MCS51
16689  how to use inline assembly, access variables, a function parameter and
16690  an array in xdata memory.
16691  The example uses an MCS51 here but is easily adapted for other architectures.
16692  This is a buffer routine which should be optimized:
16693 \end_layout
16694
16695 \begin_layout Verse
16696
16697 \family typewriter
16698 \size footnotesize
16699 unsigned char __far
16700 \begin_inset LatexCommand \index{far (storage class)}
16701
16702 \end_inset
16703
16704
16705 \begin_inset LatexCommand \index{\_\_far (storage class)}
16706
16707 \end_inset
16708
16709  __at
16710 \begin_inset LatexCommand \index{at}
16711
16712 \end_inset
16713
16714
16715 \begin_inset LatexCommand \index{\_\_at}
16716
16717 \end_inset
16718
16719 (0x7f00) buf[0x100];
16720 \begin_inset LatexCommand \index{Aligned array}
16721
16722 \end_inset
16723
16724
16725 \newline
16726 unsigned char head, tail;\InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 \InsetSpace ~
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 \InsetSpace ~
16735 \InsetSpace ~
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 /* if interrupts
16744 \begin_inset LatexCommand \index{interrupt}
16745
16746 \end_inset
16747
16748  are involved see
16749 \newline
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 section 
16796 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16797
16798 \end_inset
16799
16800  about
16801 \series bold
16802  volatile
16803 \series default
16804  */
16805 \newline
16806
16807 \newline
16808 void to_buffer( unsigned char c ) 
16809 \newline
16810 {
16811 \newline
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 if( head != (unsigned char)(tail-1)
16817  )\InsetSpace ~
16818 /* cast 
16819 \series bold
16820 needed
16821 \series default
16822  to avoid promotion
16823 \begin_inset LatexCommand \index{promotion to signed int}
16824
16825 \end_inset
16826
16827
16828 \begin_inset LatexCommand \index{type promotion}
16829
16830 \end_inset
16831
16832  to integer */
16833 \begin_inset Marginal
16834 status collapsed
16835
16836 \begin_layout Standard
16837
16838 \series bold
16839 \InsetSpace ~
16840 !
16841 \end_layout
16842
16843 \end_inset
16844
16845
16846 \newline
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 buf[ head++ ] = c;\InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 /* access to a 256 byte aligned array */
16872 \newline
16873
16874 \end_layout
16875
16876 \begin_layout Standard
16877 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16878  then a corresponding buffer.asm file is generated.
16879  We define a new function 
16880 \family typewriter
16881 to_buffer_asm()
16882 \family default
16883  in file buffer.c in which we cut and paste the generated code, removing
16884  unwanted comments and some ':'.
16885  Then add 
16886 \begin_inset Quotes sld
16887 \end_inset
16888
16889
16890 \series bold
16891 _asm
16892 \series default
16893
16894 \begin_inset Quotes srd
16895 \end_inset
16896
16897  and 
16898 \begin_inset Quotes sld
16899 \end_inset
16900
16901
16902 \series bold
16903 _endasm;
16904 \series default
16905
16906 \begin_inset Quotes srd
16907 \end_inset
16908
16909
16910 \begin_inset Foot
16911 status open
16912
16913 \begin_layout Standard
16914 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16915  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16916  has to be used.
16917  The latter is also used in the library functions.
16918 \end_layout
16919
16920 \end_inset
16921
16922  to the beginning and the end of the function body:
16923 \end_layout
16924
16925 \begin_layout Verse
16926
16927 \family typewriter
16928 \size footnotesize
16929 /* With a cut and paste from the .asm file, we have something to start with.
16930 \newline
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 The
16935  function is not yet OK! (registers aren't saved) */ 
16936 \newline
16937 void to_buffer_asm(
16938  unsigned char c ) 
16939 \newline
16940
16941 \newline
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 \InsetSpace ~
16946 _asm
16947 \begin_inset LatexCommand \index{\_asm}
16948
16949 \end_inset
16950
16951
16952 \begin_inset LatexCommand \index{\_\_asm}
16953
16954 \end_inset
16955
16956
16957 \newline
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 mov\InsetSpace ~
16963 \InsetSpace ~
16964 r2,dpl 
16965 \newline
16966 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16967 /* cast 
16968 \series bold
16969 needed
16970 \series default
16971  to avoid promotion
16972 \begin_inset LatexCommand \index{promotion to signed int}
16973
16974 \end_inset
16975
16976
16977 \begin_inset LatexCommand \index{type promotion}
16978
16979 \end_inset
16980
16981  to integer */
16982 \newline
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 mov\InsetSpace ~
16988 \InsetSpace ~
16989 a,_tail 
16990 \newline
16991 \InsetSpace ~
16992 \InsetSpace ~
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 dec\InsetSpace ~
16996 \InsetSpace ~
16997
16998 \newline
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 mov\InsetSpace ~
17004 \InsetSpace ~
17005 r3,a 
17006 \newline
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 mov\InsetSpace ~
17012 \InsetSpace ~
17013 a,_head 
17014 \newline
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 cjne a,ar3,00106$ 
17020 \newline
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 \InsetSpace ~
17024 \InsetSpace ~
17025 ret
17026 \newline
17027 00106$:
17028  
17029 \newline
17030 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17031 \begin_inset LatexCommand \index{Aligned array}
17032
17033 \end_inset
17034
17035
17036 \newline
17037 \InsetSpace ~
17038 \InsetSpace ~
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 mov\InsetSpace ~
17042 \InsetSpace ~
17043 r3,_head 
17044 \newline
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 inc\InsetSpace ~
17050 \InsetSpace ~
17051 _head 
17052 \newline
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 mov\InsetSpace ~
17058 \InsetSpace ~
17059 dpl,r3 
17060 \newline
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 mov\InsetSpace ~
17066 \InsetSpace ~
17067 dph,#(_buf >> 8) 
17068 \newline
17069 \InsetSpace ~
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 mov\InsetSpace ~
17074 \InsetSpace ~
17075 a,r2 
17076 \newline
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 movx @dptr,a
17082  
17083 \newline
17084 00103$: 
17085 \newline
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 ret
17091 \newline
17092 \InsetSpace ~
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 _endasm
17097 \begin_inset LatexCommand \index{\_endasm}
17098
17099 \end_inset
17100
17101
17102 \begin_inset LatexCommand \index{\_\_endasm}
17103
17104 \end_inset
17105
17106 ;
17107 \newline
17108
17109 \end_layout
17110
17111 \begin_layout Standard
17112 The new file buffer.c should compile with only one warning about the unreferenced
17113  function argument 'c'.
17114  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17115  (1) and finally have:
17116 \end_layout
17117
17118 \begin_layout Verse
17119
17120 \family typewriter
17121 \size footnotesize
17122 unsigned char __far __at(0x7f00) buf[0x100];
17123 \newline
17124 unsigned char head, tail;
17125 \newline
17126 #define
17127  USE_ASSEMBLY (1)
17128 \newline
17129
17130 \newline
17131 #if !USE_ASSEMBLY
17132 \newline
17133
17134 \newline
17135 void to_buffer( unsigned char c )
17136 \newline
17137 {
17138 \newline
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 if(
17144  head != (unsigned char)(tail-1) )
17145 \newline
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 buf[ head++ ] = c;
17155 \newline
17156 }
17157 \newline
17158
17159 \newline
17160 #else
17161 \newline
17162
17163 \newline
17164 void to_buffer(
17165  unsigned char c )
17166 \newline
17167 {
17168 \newline
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 c; // to avoid warning: unreferenced function argument
17174 \newline
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 _asm
17180 \begin_inset LatexCommand \index{\_asm}
17181
17182 \end_inset
17183
17184
17185 \begin_inset LatexCommand \index{\_\_asm}
17186
17187 \end_inset
17188
17189
17190 \newline
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 ; save used registers here.
17200  
17201 \newline
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 ; If we were still using r2,r3 we would have to push them here.
17211  
17212 \newline
17213 ; if( head != (unsigned char)(tail-1) )
17214 \newline
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 \InsetSpace ~
17222 \InsetSpace ~
17223 mov\InsetSpace ~
17224  a,_tail
17225 \newline
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 dec\InsetSpace ~
17235  a
17236 \newline
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 xrl\InsetSpace ~
17246  a,_head
17247 \newline
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 \InsetSpace ~
17256 ; we
17257  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17258 \newline
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 \InsetSpace ~
17267 jz\InsetSpace ~
17268 \InsetSpace ~
17269  t_b_end$
17270 \newline
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 ;
17280 \newline
17281 ;
17282  buf[ head++ ] = c;
17283 \newline
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 \InsetSpace ~
17291 \InsetSpace ~
17292 mov\InsetSpace ~
17293  a,dpl \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 ; dpl holds lower byte of function argument
17301 \newline
17302 \InsetSpace ~
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 mov\InsetSpace ~
17311
17312  dpl,_head \InsetSpace ~
17313 \InsetSpace ~
17314 \InsetSpace ~
17315 ; buf is 0x100 byte aligned so head can be used directly
17316 \newline
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 \InsetSpace ~
17324 \InsetSpace ~
17325 mov\InsetSpace ~
17326  dph,#(_bu
17327 f>>8)
17328 \newline
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 \InsetSpace ~
17336 \InsetSpace ~
17337 movx @dptr,a
17338 \newline
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 inc \InsetSpace ~
17348 _head
17349 \newline
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 \InsetSpace ~
17357 \InsetSpace ~
17358 ; we could do an ANL _head,#0x0f here to use a
17359  smaller buffer (see above)
17360 \newline
17361 t_b_end$:
17362 \newline
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 \InsetSpace ~
17367 \InsetSpace ~
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 ; restore used registers here 
17372 \newline
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 _endasm
17378 \begin_inset LatexCommand \index{\_endasm}
17379
17380 \end_inset
17381
17382
17383 \begin_inset LatexCommand \index{\_\_endasm}
17384
17385 \end_inset
17386
17387 ;
17388 \newline
17389 }
17390 \newline
17391 #endif
17392 \end_layout
17393
17394 \begin_layout Standard
17395 The inline assembler code can contain any valid code understood by the assembler
17396 , this includes any assembler directives and comment lines.
17397  The assembler does not like some characters like ':' or ''' in comments.
17398  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17399 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17400
17401 \end_inset
17402
17403
17404 \begin_inset LatexCommand \index{Assembler documentation}
17405
17406 \end_inset
17407
17408  or online at 
17409 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17410
17411 \end_inset
17412
17413 \InsetSpace ~
17414 .
17415 \end_layout
17416
17417 \begin_layout Standard
17418 The compiler does not do any validation of the code within the 
17419 \family typewriter
17420 _asm
17421 \begin_inset LatexCommand \index{\_asm}
17422
17423 \end_inset
17424
17425
17426 \begin_inset LatexCommand \index{\_\_asm}
17427
17428 \end_inset
17429
17430  ...
17431  _endasm
17432 \size footnotesize
17433
17434 \begin_inset LatexCommand \index{\_endasm}
17435
17436 \end_inset
17437
17438
17439 \begin_inset LatexCommand \index{\_\_endasm}
17440
17441 \end_inset
17442
17443
17444 \size default
17445 ;
17446 \family default
17447  keyword pair.
17448  Specifically it will not know which registers are used and thus register
17449  pushing/popping
17450 \begin_inset LatexCommand \index{push/pop}
17451
17452 \end_inset
17453
17454  has to be done manually.
17455  
17456 \end_layout
17457
17458 \begin_layout Standard
17459 It is recommended that each assembly instruction (including labels) be placed
17460  in a separate line (as the example shows).
17461  When the -
17462 \begin_inset ERT
17463 status collapsed
17464
17465 \begin_layout Standard
17466
17467
17468 \backslash
17469 /
17470 \end_layout
17471
17472 \end_inset
17473
17474 -
17475 \emph on
17476 peep-asm
17477 \begin_inset LatexCommand \index{-\/-peep-asm}
17478
17479 \end_inset
17480
17481
17482 \emph default
17483  command line option is used, the inline assembler code will be passed through
17484  the peephole optimizer
17485 \begin_inset LatexCommand \index{Peephole optimizer}
17486
17487 \end_inset
17488
17489 .
17490  There are only a few (if any) cases where this option makes sense, it might
17491  cause some unexpected changes in the inline assembler code.
17492  Please go through the peephole optimizer rules defined in file 
17493 \emph on
17494 SDCCpeeph.def
17495 \emph default
17496  before using this option.
17497 \end_layout
17498
17499 \begin_layout Subsection
17500 Naked Functions
17501 \begin_inset LatexCommand \label{sub:Naked-Functions}
17502
17503 \end_inset
17504
17505
17506 \begin_inset LatexCommand \index{Naked functions}
17507
17508 \end_inset
17509
17510
17511 \end_layout
17512
17513 \begin_layout Standard
17514 A special keyword may be associated with a function declaring it as 
17515 \emph on
17516 _naked
17517 \begin_inset LatexCommand \index{\_naked}
17518
17519 \end_inset
17520
17521
17522 \begin_inset LatexCommand \index{\_\_naked}
17523
17524 \end_inset
17525
17526 .
17527  
17528 \emph default
17529 The 
17530 \emph on
17531 _naked
17532 \emph default
17533  function modifier attribute prevents the compiler from generating prologue
17534 \begin_inset LatexCommand \index{function prologue}
17535
17536 \end_inset
17537
17538  and epilogue
17539 \begin_inset LatexCommand \index{function epilogue}
17540
17541 \end_inset
17542
17543  code for that function.
17544  This means that the user is entirely responsible for such things as saving
17545  any registers that may need to be preserved, selecting the proper register
17546  bank, generating the 
17547 \emph on
17548 return
17549 \emph default
17550  instruction at the end, etc.
17551  Practically, this means that the contents of the function must be written
17552  in inline assembler.
17553  This is particularly useful for interrupt functions, which can have a large
17554  (and often unnecessary) prologue/epilogue.
17555  For example, compare the code generated by these two functions:
17556 \end_layout
17557
17558 \begin_layout Verse
17559
17560 \family typewriter
17561 volatile
17562 \begin_inset LatexCommand \index{volatile}
17563
17564 \end_inset
17565
17566  data unsigned char counter;
17567 \newline
17568
17569 \newline
17570 void simpleInterrupt(void) __interrupt
17571 \begin_inset LatexCommand \index{interrupt}
17572
17573 \end_inset
17574
17575
17576 \begin_inset LatexCommand \index{\_\_interrupt}
17577
17578 \end_inset
17579
17580  (1)
17581 \newline
17582 {
17583 \newline
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 counter++;
17589 \newline
17590 }
17591 \newline
17592
17593 \newline
17594 void nakedInterrupt(void) __interrupt (2) __naked
17595 \newline
17596 {
17597 \newline
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 _asm
17603 \begin_inset LatexCommand \index{\_asm}
17604
17605 \end_inset
17606
17607
17608 \begin_inset LatexCommand \index{\_\_asm}
17609
17610 \end_inset
17611
17612
17613 \newline
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 \InsetSpace ~
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 inc\InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 _counter ; does not change flags, no need to save psw
17626 \newline
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 reti\InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 \InsetSpace ~
17637 ; MUST explicitly
17638  include ret or reti in _naked function.
17639 \newline
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 _endasm
17645 \begin_inset LatexCommand \index{\_endasm}
17646
17647 \end_inset
17648
17649
17650 \begin_inset LatexCommand \index{\_\_endasm}
17651
17652 \end_inset
17653
17654 ;
17655 \newline
17656 }
17657 \end_layout
17658
17659 \begin_layout Standard
17660 For an 8051 target, the generated simpleInterrupt looks like:
17661 \end_layout
17662
17663 \begin_layout Verse
17664
17665 \family typewriter
17666 Note, this is an 
17667 \emph on
17668 outdated
17669 \emph default
17670  example, recent versions of SDCC generate
17671 \newline
17672 the 
17673 \emph on
17674 same
17675 \emph default
17676  code for simpleInterrupt() and nakedInterrupt()!
17677 \newline
17678
17679 \newline
17680 _simpleInterrupt:
17681 \newline
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 push\InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 acc
17691 \newline
17692 \InsetSpace ~
17693 \InsetSpace ~
17694 \InsetSpace ~
17695 \InsetSpace ~
17696 push\InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 b
17701 \newline
17702 \InsetSpace ~
17703 \InsetSpace ~
17704 \InsetSpace ~
17705 \InsetSpace ~
17706 pu
17707 sh\InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 \InsetSpace ~
17711 dpl
17712 \newline
17713 \InsetSpace ~
17714 \InsetSpace ~
17715 \InsetSpace ~
17716 \InsetSpace ~
17717 push\InsetSpace ~
17718 \InsetSpace ~
17719 \InsetSpace ~
17720 \InsetSpace ~
17721 dph
17722 \newline
17723 \InsetSpace ~
17724 \InsetSpace ~
17725 \InsetSpace ~
17726 \InsetSpace ~
17727 push\InsetSpace ~
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 psw
17732 \newline
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 mov\InsetSpace ~
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 psw,#0x00
17743 \newline
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 inc\InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 _counter
17754 \newline
17755 \InsetSpace ~
17756 \InsetSpace ~
17757 \InsetSpace ~
17758 \InsetSpace ~
17759 pop\InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 psw
17765 \newline
17766 \InsetSpace ~
17767 \InsetSpace ~
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 pop\InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 \InsetSpace ~
17774 \InsetSpace ~
17775 dph
17776 \newline
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 pop\InsetSpace ~
17782 \InsetSpace ~
17783 \InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 dpl
17787 \newline
17788 \InsetSpace ~
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 pop\InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 b
17798 \newline
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 pop\InsetSpace ~
17804 \InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 acc
17809 \newline
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 reti
17815 \end_layout
17816
17817 \begin_layout Standard
17818 whereas nakedInterrupt looks like:
17819 \end_layout
17820
17821 \begin_layout Verse
17822
17823 \family typewriter
17824 _nakedInterrupt:
17825 \newline
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 inc\InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 _counter ; does not change flags, no need to save psw
17835 \newline
17836 \InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 reti\InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 ;
17853  MUST explicitly include ret or reti in _naked function
17854 \end_layout
17855
17856 \begin_layout Standard
17857 The related directive #pragma exclude
17858 \begin_inset LatexCommand \index{\#pragma exclude}
17859
17860 \end_inset
17861
17862  allows a more fine grained control over pushing & popping
17863 \begin_inset LatexCommand \index{push/pop}
17864
17865 \end_inset
17866
17867  the registers.
17868 \end_layout
17869
17870 \begin_layout Standard
17871 While there is nothing preventing you from writing C code inside a 
17872 \family typewriter
17873 _naked
17874 \family default
17875  function, there are many ways to shoot yourself in the foot doing this,
17876  and it is recommended that you stick to inline assembler.
17877 \end_layout
17878
17879 \begin_layout Subsection
17880 Use of Labels within Inline Assembler
17881 \end_layout
17882
17883 \begin_layout Standard
17884 SDCC allows the use of in-line assembler with a few restrictions regarding
17885  labels.
17886  All labels defined within inline assembler code have to be of the form
17887  
17888 \emph on
17889 nnnnn$
17890 \emph default
17891  where nnnnn is a number less than 100 (which implies a limit of utmost
17892  100 inline assembler labels 
17893 \emph on
17894 per function
17895 \emph default
17896 \noun on
17897 )
17898 \noun default
17899 .
17900 \begin_inset Foot
17901 status open
17902
17903 \begin_layout Standard
17904 This is a slightly more stringent rule than absolutely necessary, but stays
17905  always on the safe side.
17906  Labels in the form of nnnnn$ are local labels in the assembler, locality
17907  of which is confined within two labels of the standard form.
17908  The compiler uses the same form for labels within a function (but starting
17909  from nnnnn=00100); and places always a standard label at the beginning
17910  of a function, thus limiting the locality of labels within the scope of
17911  the function.
17912  So, if the inline assembler part would be embedded into C-code, an improperly
17913  placed non-local label in the assembler would break up the reference space
17914  for labels created by the compiler for the C-code, leading to an assembling
17915  error.
17916 \end_layout
17917
17918 \begin_layout Standard
17919 The numeric part of local labels does not need to have 5 digits (although
17920  this is the form of labels output by the compiler), any valid integer will
17921  do.
17922  Please refer to the assemblers documentation for further details.
17923 \end_layout
17924
17925 \end_inset
17926
17927  
17928 \end_layout
17929
17930 \begin_layout Verse
17931
17932 \family typewriter
17933 _asm
17934 \begin_inset LatexCommand \index{\_asm}
17935
17936 \end_inset
17937
17938
17939 \begin_inset LatexCommand \index{\_\_asm}
17940
17941 \end_inset
17942
17943  
17944 \newline
17945 \InsetSpace ~
17946 \InsetSpace ~
17947 \InsetSpace ~
17948 \InsetSpace ~
17949 mov\InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 \InsetSpace ~
17954 b,#10 
17955 \newline
17956 00001$: 
17957 \newline
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 \InsetSpace ~
17962 djnz\InsetSpace ~
17963 \InsetSpace ~
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 b,00001$ 
17967 \newline
17968 _endasm
17969 \begin_inset LatexCommand \index{\_endasm}
17970
17971 \end_inset
17972
17973
17974 \begin_inset LatexCommand \index{\_\_endasm}
17975
17976 \end_inset
17977
17978  ;
17979 \end_layout
17980
17981 \begin_layout Standard
17982 Inline assembler code cannot reference any C-labels, however it can reference
17983  labels
17984 \begin_inset LatexCommand \index{Labels}
17985
17986 \end_inset
17987
17988  defined by the inline assembler, e.g.:
17989 \end_layout
17990
17991 \begin_layout Verse
17992
17993 \family typewriter
17994 foo() { 
17995 \newline
17996 \InsetSpace ~
17997 \InsetSpace ~
17998 \InsetSpace ~
17999 \InsetSpace ~
18000 /* some c code */ 
18001 \newline
18002 \InsetSpace ~
18003 \InsetSpace ~
18004 \InsetSpace ~
18005 \InsetSpace ~
18006 _asm 
18007 \newline
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 \InsetSpace ~
18011 \InsetSpace ~
18012 \InsetSpace ~
18013 \InsetSpace ~
18014 ; some assembler code 
18015 \newline
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 \InsetSpace ~
18019 \InsetSpace ~
18020 \InsetSpace ~
18021 \InsetSpace ~
18022 ljmp 0003$ 
18023 \newline
18024 \InsetSpace ~
18025 \InsetSpace ~
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 _endasm;
18029  
18030 \newline
18031 \InsetSpace ~
18032 \InsetSpace ~
18033 \InsetSpace ~
18034 \InsetSpace ~
18035 /* some more c code */ 
18036 \newline
18037 clabel:\InsetSpace ~
18038 \InsetSpace ~
18039 /* inline assembler cannot reference this
18040  label */ 
18041 \begin_inset Foot
18042 status open
18043
18044 \begin_layout Standard
18045 Here, the C-label 
18046 \family typewriter
18047 clabel
18048 \family default
18049  is translated by the compiler into a local label, so the locality of labels
18050  within the function is not broken.
18051 \end_layout
18052
18053 \end_inset
18054
18055
18056 \newline
18057 \InsetSpace ~
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 _asm
18062 \newline
18063 \InsetSpace ~
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 0003$: ;label (can be referenced by inline assembler only) 
18068 \newline
18069 \InsetSpace ~
18070 \InsetSpace ~
18071 \InsetSpace ~
18072 \InsetSpace ~
18073 _endasm
18074 \begin_inset LatexCommand \index{\_endasm}
18075
18076 \end_inset
18077
18078
18079 \begin_inset LatexCommand \index{\_\_endasm}
18080
18081 \end_inset
18082
18083  ; 
18084 \newline
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 /* some more c code */
18090 \newline
18091 }
18092 \end_layout
18093
18094 \begin_layout Standard
18095 In other words inline assembly code can access labels defined in inline
18096  assembly within the scope of the function.
18097  The same goes the other way, i.e.
18098  labels defines in inline assembly can not be accessed by C statements.
18099 \end_layout
18100
18101 \begin_layout Section
18102 Interfacing with Assembler Code
18103 \begin_inset LatexCommand \index{Assembler routines}
18104
18105 \end_inset
18106
18107
18108 \end_layout
18109
18110 \begin_layout Subsection
18111 Global Registers used for Parameter Passing
18112 \begin_inset LatexCommand \index{Parameter passing}
18113
18114 \end_inset
18115
18116
18117 \end_layout
18118
18119 \begin_layout Standard
18120 The compiler always uses the global registers 
18121 \emph on
18122 DPL, DPH
18123 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18124
18125 \end_inset
18126
18127
18128 \begin_inset LatexCommand \index{DPTR}
18129
18130 \end_inset
18131
18132 , B
18133 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18134
18135 \end_inset
18136
18137  
18138 \emph default
18139 and
18140 \emph on
18141  ACC
18142 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18143
18144 \end_inset
18145
18146
18147 \emph default
18148  to pass the first (non-bit) parameter to a function, and also to pass the
18149  return value 
18150 \begin_inset LatexCommand \index{return value}
18151
18152 \end_inset
18153
18154 of function; according to the following scheme: one byte return value in
18155  
18156 \emph on
18157 DPL
18158 \emph default
18159 , two byte value in 
18160 \emph on
18161 DPL
18162 \emph default
18163  (LSB) and 
18164 \emph on
18165 DPH
18166 \emph default
18167  (MSB).
18168  three byte values (generic pointers) in 
18169 \emph on
18170 DPH
18171 \emph default
18172
18173 \emph on
18174 DPL
18175 \emph default
18176  and 
18177 \emph on
18178 B
18179 \emph default
18180 , and four byte values in 
18181 \emph on
18182 DPH
18183 \emph default
18184
18185 \emph on
18186 DPL
18187 \emph default
18188 ,
18189 \emph on
18190  B
18191 \emph default
18192  and 
18193 \emph on
18194 ACC
18195 \emph default
18196 .
18197  Generic pointers
18198 \begin_inset LatexCommand \index{generic pointer}
18199
18200 \end_inset
18201
18202  contain type of accessed memory in 
18203 \emph on
18204 B
18205 \emph default
18206
18207 \series bold
18208 0x00
18209 \series default
18210  -- xdata/far, 
18211 \series bold
18212 0x40
18213 \series default
18214  -- idata/near -- , 
18215 \series bold
18216 0x60
18217 \series default
18218  -- pdata, 
18219 \series bold
18220 0x80
18221 \series default
18222  -- code
18223 \begin_inset Note Note
18224 status collapsed
18225
18226 \begin_layout Standard
18227 This might not be the case of certain memory models (medium???)
18228 \end_layout
18229
18230 \end_inset
18231
18232 .
18233 \end_layout
18234
18235 \begin_layout Standard
18236 The second parameter onwards is either allocated on the stack (for reentrant
18237  routines or if -
18238 \begin_inset ERT
18239 status collapsed
18240
18241 \begin_layout Standard
18242
18243
18244 \backslash
18245 /
18246 \end_layout
18247
18248 \end_inset
18249
18250 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18251 \end_layout
18252
18253 \begin_layout Standard
18254 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18255  space for reentrant functions or allocated directly in bit memory otherwise.
18256 \end_layout
18257
18258 \begin_layout Standard
18259 Functions (with two or more parameters or bit parameters) that are called
18260  through function pointers
18261 \begin_inset LatexCommand \index{function pointers}
18262
18263 \end_inset
18264
18265  must therefor be reentrant so the compiler knows how to pass the parameters.
18266 \end_layout
18267
18268 \begin_layout Subsection
18269 Registers usage
18270 \end_layout
18271
18272 \begin_layout Standard
18273 Unless the called function is declared as 
18274 \family typewriter
18275 _naked
18276 \family default
18277
18278 \begin_inset LatexCommand \index{naked}
18279
18280 \end_inset
18281
18282 , or the -
18283 \begin_inset ERT
18284 status collapsed
18285
18286 \begin_layout Standard
18287
18288
18289 \backslash
18290 /
18291 \end_layout
18292
18293 \end_inset
18294
18295 -callee-saves
18296 \begin_inset LatexCommand \index{-\/-callee-saves}
18297
18298 \end_inset
18299
18300 /-
18301 \begin_inset ERT
18302 status collapsed
18303
18304 \begin_layout Standard
18305
18306
18307 \backslash
18308 /
18309 \end_layout
18310
18311 \end_inset
18312
18313 -all-callee-saves command line option or the corresponding callee_saves
18314  pragma are used, the caller will save the registers (
18315 \emph on
18316 R0-R7
18317 \emph default
18318 ) around the call, so the called function can destroy they content freely.
18319 \end_layout
18320
18321 \begin_layout Standard
18322 If the called function is not declared as 
18323 \family typewriter
18324 _naked
18325 \family default
18326 , the caller will swap register banks around the call, if caller and callee
18327  use different register banks (having them defined by the 
18328 \family typewriter
18329 _using
18330 \family default
18331  modifier).
18332  
18333 \end_layout
18334
18335 \begin_layout Standard
18336 The called function can also use 
18337 \emph on
18338 DPL
18339 \emph default
18340
18341 \emph on
18342 DPH
18343 \emph default
18344
18345 \emph on
18346 B
18347 \emph default
18348  and 
18349 \emph on
18350 ACC
18351 \emph default
18352  observing that they are used for parameter/return value passing.
18353 \end_layout
18354
18355 \begin_layout Subsection
18356 Assembler Routine (non-reentrant)
18357 \end_layout
18358
18359 \begin_layout Standard
18360 In the following example
18361 \begin_inset LatexCommand \index{reentrant}
18362
18363 \end_inset
18364
18365
18366 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18367
18368 \end_inset
18369
18370  the function c_func calls an assembler routine asm_func, which takes two
18371  parameters
18372 \begin_inset LatexCommand \index{function parameter}
18373
18374 \end_inset
18375
18376 .
18377 \end_layout
18378
18379 \begin_layout Verse
18380
18381 \family typewriter
18382 extern int asm_func(unsigned char, unsigned char);
18383 \newline
18384
18385 \newline
18386 int c_func (unsigned char
18387  i, unsigned char j)
18388 \newline
18389 {
18390 \newline
18391 \InsetSpace ~
18392 \InsetSpace ~
18393 \InsetSpace ~
18394 \InsetSpace ~
18395 return asm_func(i,j);
18396 \newline
18397 }
18398 \newline
18399
18400 \newline
18401 int main()
18402 \newline
18403 {
18404 \newline
18405 \InsetSpace ~
18406 \InsetSpace ~
18407 \InsetSpace ~
18408 \InsetSpace ~
18409 return c_func(10,9);
18410 \newline
18411 }
18412 \end_layout
18413
18414 \begin_layout Standard
18415 The corresponding assembler function is:
18416 \end_layout
18417
18418 \begin_layout Verse
18419
18420 \family typewriter
18421 .globl _asm_func_PARM_2 
18422 \newline
18423 \InsetSpace ~
18424 \InsetSpace ~
18425 \InsetSpace ~
18426 \InsetSpace ~
18427 \InsetSpace ~
18428 \InsetSpace ~
18429 \InsetSpace ~
18430 \InsetSpace ~
18431 .globl _asm_func 
18432 \newline
18433 \InsetSpace ~
18434 \InsetSpace ~
18435 \InsetSpace ~
18436 \InsetSpace ~
18437 \InsetSpace ~
18438 \InsetSpace ~
18439 \InsetSpace ~
18440 \InsetSpace ~
18441 .area OSEG 
18442 \newline
18443 _asm_func_PARM_2:
18444 \newline
18445 \InsetSpace ~
18446 \InsetSpace ~
18447 \InsetSpace ~
18448 \InsetSpace ~
18449 \InsetSpace ~
18450 \InsetSpace ~
18451 \InsetSpace ~
18452 \InsetSpace ~
18453 .ds   
18454  1 
18455 \newline
18456 \InsetSpace ~
18457 \InsetSpace ~
18458 \InsetSpace ~
18459 \InsetSpace ~
18460 \InsetSpace ~
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 .area CSEG 
18465 \newline
18466 _asm_func: 
18467 \newline
18468 \InsetSpace ~
18469 \InsetSpace ~
18470 \InsetSpace ~
18471 \InsetSpace ~
18472 \InsetSpace ~
18473 \InsetSpace ~
18474 \InsetSpace ~
18475 \InsetSpace ~
18476 mov\InsetSpace ~
18477 \InsetSpace ~
18478 \InsetSpace ~
18479 \InsetSpace ~
18480 a,dpl 
18481 \newline
18482 \InsetSpace ~
18483 \InsetSpace ~
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 \InsetSpace ~
18488 \InsetSpace ~
18489 \InsetSpace ~
18490 add\InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 a,_asm_func_PARM_2 
18495 \newline
18496 \InsetSpace ~
18497 \InsetSpace ~
18498 \InsetSpace ~
18499 \InsetSpace ~
18500 \InsetSpace ~
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 mov\InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 dpl,a 
18509 \newline
18510 \InsetSpace ~
18511 \InsetSpace ~
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 mov\InsetSpace ~
18519 \InsetSpace ~
18520 \InsetSpace ~
18521 \InsetSpace ~
18522 dph
18523 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18524
18525 \end_inset
18526
18527 ,#0x00 
18528 \newline
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 \InsetSpace ~
18533 \InsetSpace ~
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 ret
18538 \end_layout
18539
18540 \begin_layout Standard
18541 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18542  the parameter number starting from 1, and counting from the left.
18543  The first parameter is passed in 
18544 \emph on
18545 DPH
18546 \emph default
18547
18548 \emph on
18549 DPL
18550 \emph default
18551
18552 \emph on
18553 B
18554 \emph default
18555  and 
18556 \emph on
18557 ACC
18558 \emph default
18559  according to the description above.
18560  The variable name for the second parameter will be _<function_name>_PARM_2.
18561 \newline
18562
18563 \newline
18564 Assem
18565 ble the assembler routine with the following command:
18566 \newline
18567
18568 \newline
18569
18570 \family sans
18571 \series bold
18572 asx8051 -losg asmfunc.asm
18573 \newline
18574
18575 \newline
18576
18577 \family default
18578 \series default
18579 Then compile and link the assembler routine to the C source file with the
18580  following command:
18581 \newline
18582
18583 \newline
18584
18585 \family sans
18586 \series bold
18587 sdcc cfunc.c asmfunc.rel
18588 \end_layout
18589
18590 \begin_layout Subsection
18591 Assembler Routine (reentrant)
18592 \end_layout
18593
18594 \begin_layout Standard
18595 In this case
18596 \begin_inset LatexCommand \index{reentrant}
18597
18598 \end_inset
18599
18600
18601 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18602
18603 \end_inset
18604
18605  the second parameter
18606 \begin_inset LatexCommand \index{function parameter}
18607
18608 \end_inset
18609
18610  onwards will be passed on the stack, the parameters are pushed from right
18611  to left i.e.
18612  before the call the second leftmost parameter will be on the top of the
18613  stack (the leftmost parameter is passed in registers).
18614  Here is an example:
18615 \end_layout
18616
18617 \begin_layout Verse
18618
18619 \family typewriter
18620 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18621 \newline
18622
18623 \newline
18624 int
18625  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18626 \newline
18627 {
18628  
18629 \newline
18630 \InsetSpace ~
18631 \InsetSpace ~
18632 \InsetSpace ~
18633 \InsetSpace ~
18634 return asm_func(i,j,k); 
18635 \newline
18636
18637 \newline
18638
18639 \newline
18640 int main() 
18641 \newline
18642
18643 \newline
18644 \InsetSpace ~
18645 \InsetSpace ~
18646 \InsetSpace ~
18647 \InsetSpace ~
18648 return c_func(10,9,8); 
18649 \newline
18650 }
18651 \end_layout
18652
18653 \begin_layout Standard
18654 The corresponding (unoptimized) assembler routine is:
18655 \end_layout
18656
18657 \begin_layout Verse
18658
18659 \family typewriter
18660 .globl _asm_func 
18661 \newline
18662 _asm_func: 
18663 \newline
18664 \InsetSpace ~
18665 \InsetSpace ~
18666 \InsetSpace ~
18667 \InsetSpace ~
18668 push\InsetSpace ~
18669 _bp 
18670 \newline
18671 \InsetSpace ~
18672 \InsetSpace ~
18673 \InsetSpace ~
18674 \InsetSpace ~
18675 mov\InsetSpace ~
18676 \InsetSpace ~
18677 _bp,sp\InsetSpace ~
18678 \InsetSpace ~
18679 \InsetSpace ~
18680 \InsetSpace ~
18681 \InsetSpace ~
18682 \InsetSpace ~
18683 ;stack contains: _bp, return
18684  address, second parameter, third parameter
18685 \newline
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 \InsetSpace ~
18690 mov\InsetSpace ~
18691 \InsetSpace ~
18692 r2,dpl
18693 \newline
18694 \InsetSpace ~
18695 \InsetSpace ~
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 mov\InsetSpace ~
18699 \InsetSpace ~
18700 a,_bp
18701 \newline
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 \InsetSpace ~
18705 \InsetSpace ~
18706 add\InsetSpace ~
18707 \InsetSpace ~
18708 a,#0xfd\InsetSpace ~
18709 \InsetSpace ~
18710 \InsetSpace ~
18711 \InsetSpace ~
18712 \InsetSpace ~
18713 ;calculate
18714  pointer to the second parameter
18715 \newline
18716 \InsetSpace ~
18717 \InsetSpace ~
18718 \InsetSpace ~
18719 \InsetSpace ~
18720 mov\InsetSpace ~
18721 \InsetSpace ~
18722 r0,a 
18723 \newline
18724 \InsetSpace ~
18725 \InsetSpace ~
18726 \InsetSpace ~
18727 \InsetSpace ~
18728 mov\InsetSpace ~
18729 \InsetSpace ~
18730 a,_bp 
18731 \newline
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 \InsetSpace ~
18735 \InsetSpace ~
18736 add\InsetSpace ~
18737 \InsetSpace ~
18738 a,#0xfc\InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 \InsetSpace ~
18742 \InsetSpace ~
18743 ;calculate pointer
18744  to the rightmost parameter
18745 \newline
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 \InsetSpace ~
18750 mov\InsetSpace ~
18751 \InsetSpace ~
18752 r1,a 
18753 \newline
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 \InsetSpace ~
18757 \InsetSpace ~
18758 mov\InsetSpace ~
18759 \InsetSpace ~
18760 a,@r0
18761 \newline
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 \InsetSpace ~
18765 \InsetSpace ~
18766 add\InsetSpace ~
18767 \InsetSpace ~
18768 a,@r1
18769 \newline
18770 \InsetSpace ~
18771 \InsetSpace ~
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 add\InsetSpace ~
18775 \InsetSpace ~
18776 a,r2\InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 \InsetSpace ~
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 ;calculate the
18785  result (= sum of all three parameters)
18786 \newline
18787 \InsetSpace ~
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 mov\InsetSpace ~
18792 \InsetSpace ~
18793 dpl,a\InsetSpace ~
18794 \InsetSpace ~
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 \InsetSpace ~
18800 ;return value goes into dptr
18801  (cast into int)
18802 \newline
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 \InsetSpace ~
18807 mov\InsetSpace ~
18808 \InsetSpace ~
18809 dph,#0x00 
18810 \newline
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 \InsetSpace ~
18815 mov\InsetSpace ~
18816 \InsetSpace ~
18817 sp,_bp 
18818 \newline
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 \InsetSpace ~
18823 pop\InsetSpace ~
18824 \InsetSpace ~
18825 _bp 
18826 \newline
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 \InsetSpace ~
18831 ret
18832 \end_layout
18833
18834 \begin_layout Standard
18835 The compiling and linking procedure remains the same, however note the extra
18836  entry & exit linkage required for the assembler code, _bp is the stack
18837  frame pointer and is used to compute the offset into the stack for parameters
18838  and local variables.
18839 \begin_inset VSpace bigskip
18840 \end_inset
18841
18842
18843 \end_layout
18844
18845 \begin_layout Section
18846 int (16 bit)
18847 \begin_inset LatexCommand \index{int (16 bit)}
18848
18849 \end_inset
18850
18851  and long (32 bit)
18852 \begin_inset LatexCommand \index{long (32 bit)}
18853
18854 \end_inset
18855
18856  Support
18857 \end_layout
18858
18859 \begin_layout Standard
18860 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18861  multiplication and modulus operations are implemented by support routines.
18862  These support routines are all developed in ANSI-C to facilitate porting
18863  to other MCUs, although some model specific assembler optimizations are
18864  used.
18865  The following files contain the described routines, all of them can be
18866  found in <installdir>/share/sdcc/lib.
18867 \newline
18868
18869 \end_layout
18870
18871 \begin_layout Standard
18872 \align center
18873 \begin_inset Tabular
18874 <lyxtabular version="3" rows="11" columns="2">
18875 <features>
18876 <column alignment="left" valignment="top" leftline="true" width="0">
18877 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18878 <row topline="true" bottomline="true">
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18880 \begin_inset Text
18881
18882 \begin_layout Standard
18883
18884 \series bold
18885 Function
18886 \end_layout
18887
18888 \end_inset
18889 </cell>
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18891 \begin_inset Text
18892
18893 \begin_layout Standard
18894
18895 \series bold
18896 Description
18897 \end_layout
18898
18899 \end_inset
18900 </cell>
18901 </row>
18902 <row topline="true">
18903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18904 \begin_inset Text
18905
18906 \begin_layout Standard
18907 _mulint.c 
18908 \end_layout
18909
18910 \end_inset
18911 </cell>
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18913 \begin_inset Text
18914
18915 \begin_layout Standard
18916 16 bit multiplication
18917 \end_layout
18918
18919 \end_inset
18920 </cell>
18921 </row>
18922 <row topline="true">
18923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18924 \begin_inset Text
18925
18926 \begin_layout Standard
18927 _divsint.c 
18928 \end_layout
18929
18930 \end_inset
18931 </cell>
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18933 \begin_inset Text
18934
18935 \begin_layout Standard
18936  signed 16 bit division (calls _divuint)
18937 \end_layout
18938
18939 \end_inset
18940 </cell>
18941 </row>
18942 <row topline="true">
18943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18944 \begin_inset Text
18945
18946 \begin_layout Standard
18947 _divuint.c 
18948 \end_layout
18949
18950 \end_inset
18951 </cell>
18952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18953 \begin_inset Text
18954
18955 \begin_layout Standard
18956  unsigned 16 bit division
18957 \end_layout
18958
18959 \end_inset
18960 </cell>
18961 </row>
18962 <row topline="true">
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18964 \begin_inset Text
18965
18966 \begin_layout Standard
18967 _modsint.c
18968 \end_layout
18969
18970 \end_inset
18971 </cell>
18972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18973 \begin_inset Text
18974
18975 \begin_layout Standard
18976 signed 16 bit modulus (calls _moduint)
18977 \end_layout
18978
18979 \end_inset
18980 </cell>
18981 </row>
18982 <row topline="true">
18983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18984 \begin_inset Text
18985
18986 \begin_layout Standard
18987 _moduint.c
18988 \end_layout
18989
18990 \end_inset
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \begin_layout Standard
18996 unsigned 16 bit modulus
18997 \end_layout
18998
18999 \end_inset
19000 </cell>
19001 </row>
19002 <row topline="true">
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19004 \begin_inset Text
19005
19006 \begin_layout Standard
19007 _mullong.c
19008 \end_layout
19009
19010 \end_inset
19011 </cell>
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19013 \begin_inset Text
19014
19015 \begin_layout Standard
19016 32 bit multiplication
19017 \end_layout
19018
19019 \end_inset
19020 </cell>
19021 </row>
19022 <row topline="true">
19023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19024 \begin_inset Text
19025
19026 \begin_layout Standard
19027 _divslong.c 
19028 \end_layout
19029
19030 \end_inset
19031 </cell>
19032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19033 \begin_inset Text
19034
19035 \begin_layout Standard
19036  signed 32 division (calls _divulong)
19037 \end_layout
19038
19039 \end_inset
19040 </cell>
19041 </row>
19042 <row topline="true">
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19044 \begin_inset Text
19045
19046 \begin_layout Standard
19047 _divulong.c 
19048 \end_layout
19049
19050 \end_inset
19051 </cell>
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19053 \begin_inset Text
19054
19055 \begin_layout Standard
19056 unsigned 32 division
19057 \end_layout
19058
19059 \end_inset
19060 </cell>
19061 </row>
19062 <row topline="true">
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19064 \begin_inset Text
19065
19066 \begin_layout Standard
19067 _modslong.c
19068 \end_layout
19069
19070 \end_inset
19071 </cell>
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19073 \begin_inset Text
19074
19075 \begin_layout Standard
19076  signed 32 bit modulus (calls _modulong)
19077 \end_layout
19078
19079 \end_inset
19080 </cell>
19081 </row>
19082 <row topline="true" bottomline="true">
19083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19084 \begin_inset Text
19085
19086 \begin_layout Standard
19087 _modulong.c
19088 \end_layout
19089
19090 \end_inset
19091 </cell>
19092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19093 \begin_inset Text
19094
19095 \begin_layout Standard
19096 unsigned 32 bit modulus
19097 \end_layout
19098
19099 \end_inset
19100 </cell>
19101 </row>
19102 </lyxtabular>
19103
19104 \end_inset
19105
19106
19107 \newline
19108
19109 \end_layout
19110
19111 \begin_layout Standard
19112 Since they are compiled as 
19113 \emph on
19114 non-reentrant
19115 \emph default
19116
19117 \begin_inset LatexCommand \index{reentrant}
19118
19119 \end_inset
19120
19121 , interrupt
19122 \begin_inset LatexCommand \index{interrupt}
19123
19124 \end_inset
19125
19126  service routines should not do any of the above operations.
19127  If this is unavoidable then the above routines will need to be compiled
19128  with the 
19129 \emph on
19130 -
19131 \begin_inset ERT
19132 status collapsed
19133
19134 \begin_layout Standard
19135
19136
19137 \backslash
19138 /
19139 \end_layout
19140
19141 \end_inset
19142
19143 -stack-auto
19144 \begin_inset LatexCommand \index{-\/-stack-auto}
19145
19146 \end_inset
19147
19148
19149 \emph default
19150  option, after which the source program will have to be compiled with 
19151 \emph on
19152 -
19153 \begin_inset ERT
19154 status collapsed
19155
19156 \begin_layout Standard
19157
19158
19159 \backslash
19160 /
19161 \end_layout
19162
19163 \end_inset
19164
19165 -int-long-reent
19166 \begin_inset LatexCommand \index{-\/-int-long-reent}
19167
19168 \end_inset
19169
19170
19171 \emph default
19172  option.
19173  Notice that you don't have to call these routines directly.
19174  The compiler will use them automatically every time an integer operation
19175  is required.
19176 \end_layout
19177
19178 \begin_layout Section
19179 Floating Point Support
19180 \begin_inset LatexCommand \index{Floating point support}
19181
19182 \end_inset
19183
19184
19185 \end_layout
19186
19187 \begin_layout Standard
19188 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19189  The floating point support routines are derived from gcc's floatlib.c and
19190  consist of the following routines:
19191 \newline
19192
19193 \end_layout
19194
19195 \begin_layout Standard
19196 \align center
19197
19198 \size footnotesize
19199 \begin_inset Tabular
19200 <lyxtabular version="3" rows="17" columns="2">
19201 <features>
19202 <column alignment="left" valignment="top" leftline="true" width="0">
19203 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19204 <row topline="true" bottomline="true">
19205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19206 \begin_inset Text
19207
19208 \begin_layout Standard
19209
19210 \family roman
19211 \series medium
19212 \shape up
19213 \size normal
19214 \emph off
19215 \bar no
19216 \noun off
19217 \color none
19218 Function 
19219 \end_layout
19220
19221 \end_inset
19222 </cell>
19223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19224 \begin_inset Text
19225
19226 \begin_layout Standard
19227 Description
19228 \end_layout
19229
19230 \end_inset
19231 </cell>
19232 </row>
19233 <row topline="true">
19234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19235 \begin_inset Text
19236
19237 \begin_layout Standard
19238
19239 \family roman
19240 \series medium
19241 \shape up
19242 \size normal
19243 \emph off
19244 \bar no
19245 \noun off
19246 \color none
19247 _fsadd.c
19248 \end_layout
19249
19250 \end_inset
19251 </cell>
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19253 \begin_inset Text
19254
19255 \begin_layout Standard
19256
19257 \family roman
19258 \series medium
19259 \shape up
19260 \size normal
19261 \emph off
19262 \bar no
19263 \noun off
19264 \color none
19265 add floating point numbers
19266 \end_layout
19267
19268 \end_inset
19269 </cell>
19270 </row>
19271 <row topline="true">
19272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19273 \begin_inset Text
19274
19275 \begin_layout Standard
19276
19277 \family roman
19278 \series medium
19279 \shape up
19280 \size normal
19281 \emph off
19282 \bar no
19283 \noun off
19284 \color none
19285 _fssub.c 
19286 \end_layout
19287
19288 \end_inset
19289 </cell>
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294
19295 \family roman
19296 \series medium
19297 \shape up
19298 \size normal
19299 \emph off
19300 \bar no
19301 \noun off
19302 \color none
19303 subtract floating point numbers 
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 </row>
19309 <row topline="true">
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19311 \begin_inset Text
19312
19313 \begin_layout Standard
19314
19315 \family roman
19316 \series medium
19317 \shape up
19318 \size normal
19319 \emph off
19320 \bar no
19321 \noun off
19322 \color none
19323 _fsdiv.c 
19324 \end_layout
19325
19326 \end_inset
19327 </cell>
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332
19333 \family roman
19334 \series medium
19335 \shape up
19336 \size normal
19337 \emph off
19338 \bar no
19339 \noun off
19340 \color none
19341 divide floating point numbers 
19342 \end_layout
19343
19344 \end_inset
19345 </cell>
19346 </row>
19347 <row topline="true">
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19349 \begin_inset Text
19350
19351 \begin_layout Standard
19352
19353 \family roman
19354 \series medium
19355 \shape up
19356 \size normal
19357 \emph off
19358 \bar no
19359 \noun off
19360 \color none
19361 _fsmul.c 
19362 \end_layout
19363
19364 \end_inset
19365 </cell>
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19367 \begin_inset Text
19368
19369 \begin_layout Standard
19370
19371 \family roman
19372 \series medium
19373 \shape up
19374 \size normal
19375 \emph off
19376 \bar no
19377 \noun off
19378 \color none
19379 multiply floating point numbers 
19380 \end_layout
19381
19382 \end_inset
19383 </cell>
19384 </row>
19385 <row topline="true">
19386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19387 \begin_inset Text
19388
19389 \begin_layout Standard
19390
19391 \family roman
19392 \series medium
19393 \shape up
19394 \size normal
19395 \emph off
19396 \bar no
19397 \noun off
19398 \color none
19399 _fs2uchar.c
19400 \end_layout
19401
19402 \end_inset
19403 </cell>
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19405 \begin_inset Text
19406
19407 \begin_layout Standard
19408
19409 \family roman
19410 \series medium
19411 \shape up
19412 \size normal
19413 \emph off
19414 \bar no
19415 \noun off
19416 \color none
19417 convert floating point to unsigned char
19418 \end_layout
19419
19420 \end_inset
19421 </cell>
19422 </row>
19423 <row topline="true">
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19425 \begin_inset Text
19426
19427 \begin_layout Standard
19428
19429 \family roman
19430 \series medium
19431 \shape up
19432 \size normal
19433 \emph off
19434 \bar no
19435 \noun off
19436 \color none
19437 _fs2char.c
19438 \end_layout
19439
19440 \end_inset
19441 </cell>
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19443 \begin_inset Text
19444
19445 \begin_layout Standard
19446
19447 \family roman
19448 \series medium
19449 \shape up
19450 \size normal
19451 \emph off
19452 \bar no
19453 \noun off
19454 \color none
19455 convert floating point to signed char
19456 \end_layout
19457
19458 \end_inset
19459 </cell>
19460 </row>
19461 <row topline="true">
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19463 \begin_inset Text
19464
19465 \begin_layout Standard
19466
19467 \family roman
19468 \series medium
19469 \shape up
19470 \size normal
19471 \emph off
19472 \bar no
19473 \noun off
19474 \color none
19475 _fs2uint.c
19476 \end_layout
19477
19478 \end_inset
19479 </cell>
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \begin_layout Standard
19484
19485 \family roman
19486 \series medium
19487 \shape up
19488 \size normal
19489 \emph off
19490 \bar no
19491 \noun off
19492 \color none
19493 convert floating point to unsigned int
19494 \end_layout
19495
19496 \end_inset
19497 </cell>
19498 </row>
19499 <row topline="true">
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_inset Text
19502
19503 \begin_layout Standard
19504
19505 \family roman
19506 \series medium
19507 \shape up
19508 \size normal
19509 \emph off
19510 \bar no
19511 \noun off
19512 \color none
19513 _fs2int.c
19514 \end_layout
19515
19516 \end_inset
19517 </cell>
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \begin_layout Standard
19522
19523 \family roman
19524 \series medium
19525 \shape up
19526 \size normal
19527 \emph off
19528 \bar no
19529 \noun off
19530 \color none
19531 convert floating point to signed int
19532 \end_layout
19533
19534 \end_inset
19535 </cell>
19536 </row>
19537 <row topline="true">
19538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19539 \begin_inset Text
19540
19541 \begin_layout Standard
19542
19543 \family roman
19544 \series medium
19545 \shape up
19546 \size normal
19547 \emph off
19548 \bar no
19549 \noun off
19550 \color none
19551 _fs2ulong.
19552 \family default
19553 \series default
19554 \shape default
19555 \size default
19556 \emph default
19557 \bar default
19558 \noun default
19559 c
19560 \end_layout
19561
19562 \end_inset
19563 </cell>
19564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19565 \begin_inset Text
19566
19567 \begin_layout Standard
19568
19569 \family roman
19570 \series medium
19571 \shape up
19572 \size normal
19573 \emph off
19574 \bar no
19575 \noun off
19576 \color none
19577 convert floating point to unsigned long
19578 \end_layout
19579
19580 \end_inset
19581 </cell>
19582 </row>
19583 <row topline="true">
19584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19585 \begin_inset Text
19586
19587 \begin_layout Standard
19588
19589 \family roman
19590 \series medium
19591 \shape up
19592 \size normal
19593 \emph off
19594 \bar no
19595 \noun off
19596 \color none
19597 _fs2long.c
19598 \end_layout
19599
19600 \end_inset
19601 </cell>
19602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19603 \begin_inset Text
19604
19605 \begin_layout Standard
19606
19607 \family roman
19608 \series medium
19609 \shape up
19610 \size normal
19611 \emph off
19612 \bar no
19613 \noun off
19614 \color none
19615 convert floating point to signed long
19616 \end_layout
19617
19618 \end_inset
19619 </cell>
19620 </row>
19621 <row topline="true">
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19623 \begin_inset Text
19624
19625 \begin_layout Standard
19626
19627 \family roman
19628 \series medium
19629 \shape up
19630 \size normal
19631 \emph off
19632 \bar no
19633 \noun off
19634 \color none
19635 _uchar2fs.c
19636 \end_layout
19637
19638 \end_inset
19639 </cell>
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19641 \begin_inset Text
19642
19643 \begin_layout Standard
19644
19645 \family roman
19646 \series medium
19647 \shape up
19648 \size normal
19649 \emph off
19650 \bar no
19651 \noun off
19652 \color none
19653 convert unsigned char to floating point
19654 \end_layout
19655
19656 \end_inset
19657 </cell>
19658 </row>
19659 <row topline="true">
19660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19661 \begin_inset Text
19662
19663 \begin_layout Standard
19664
19665 \family roman
19666 \series medium
19667 \shape up
19668 \size normal
19669 \emph off
19670 \bar no
19671 \noun off
19672 \color none
19673 _char2fs.c
19674 \end_layout
19675
19676 \end_inset
19677 </cell>
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \begin_layout Standard
19682
19683 \family roman
19684 \series medium
19685 \shape up
19686 \size normal
19687 \emph off
19688 \bar no
19689 \noun off
19690 \color none
19691 convert char to floating point number
19692 \end_layout
19693
19694 \end_inset
19695 </cell>
19696 </row>
19697 <row topline="true">
19698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19699 \begin_inset Text
19700
19701 \begin_layout Standard
19702
19703 \family roman
19704 \series medium
19705 \shape up
19706 \size normal
19707 \emph off
19708 \bar no
19709 \noun off
19710 \color none
19711 _uint2fs.c
19712 \end_layout
19713
19714 \end_inset
19715 </cell>
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19717 \begin_inset Text
19718
19719 \begin_layout Standard
19720
19721 \family roman
19722 \series medium
19723 \shape up
19724 \size normal
19725 \emph off
19726 \bar no
19727 \noun off
19728 \color none
19729 convert unsigned int to floating point
19730 \end_layout
19731
19732 \end_inset
19733 </cell>
19734 </row>
19735 <row topline="true">
19736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19737 \begin_inset Text
19738
19739 \begin_layout Standard
19740
19741 \family roman
19742 \series medium
19743 \shape up
19744 \size normal
19745 \emph off
19746 \bar no
19747 \noun off
19748 \color none
19749 _int2fs.c
19750 \end_layout
19751
19752 \end_inset
19753 </cell>
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \begin_layout Standard
19758
19759 \family roman
19760 \series medium
19761 \shape up
19762 \size normal
19763 \emph off
19764 \bar no
19765 \noun off
19766 \color none
19767 convert int to floating point numbers
19768 \end_layout
19769
19770 \end_inset
19771 </cell>
19772 </row>
19773 <row topline="true">
19774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19775 \begin_inset Text
19776
19777 \begin_layout Standard
19778
19779 \family roman
19780 \series medium
19781 \shape up
19782 \size normal
19783 \emph off
19784 \bar no
19785 \noun off
19786 \color none
19787 _ulong2fs.c
19788 \end_layout
19789
19790 \end_inset
19791 </cell>
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19793 \begin_inset Text
19794
19795 \begin_layout Standard
19796
19797 \family roman
19798 \series medium
19799 \shape up
19800 \size normal
19801 \emph off
19802 \bar no
19803 \noun off
19804 \color none
19805 convert unsigned long to floating point number
19806 \end_layout
19807
19808 \end_inset
19809 </cell>
19810 </row>
19811 <row topline="true" bottomline="true">
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19813 \begin_inset Text
19814
19815 \begin_layout Standard
19816
19817 \family roman
19818 \series medium
19819 \shape up
19820 \size normal
19821 \emph off
19822 \bar no
19823 \noun off
19824 \color none
19825 _long2fs.c
19826 \end_layout
19827
19828 \end_inset
19829 </cell>
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \begin_layout Standard
19834
19835 \family roman
19836 \series medium
19837 \shape up
19838 \size normal
19839 \emph off
19840 \bar no
19841 \noun off
19842 \color none
19843 convert long to floating point number
19844 \end_layout
19845
19846 \end_inset
19847 </cell>
19848 </row>
19849 </lyxtabular>
19850
19851 \end_inset
19852
19853
19854 \newline
19855
19856 \end_layout
19857
19858 \begin_layout Standard
19859 These support routines are developed in ANSI-C so there is room for space
19860  and speed improvement
19861 \begin_inset Foot
19862 status open
19863
19864 \begin_layout Standard
19865 These floating point routines (
19866 \emph on
19867 not
19868 \emph default
19869  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19870  
19871 \end_layout
19872
19873 \end_inset
19874
19875 .
19876  Note if all these routines are used simultaneously the data space might
19877  overflow.
19878  For serious floating point usage the large model might be needed.
19879  Also notice that you don't have to call this routines directly.
19880  The compiler will use them automatically every time a floating point operation
19881  is required.
19882 \begin_inset VSpace bigskip
19883 \end_inset
19884
19885
19886 \end_layout
19887
19888 \begin_layout Section
19889 Library Routines
19890 \begin_inset LatexCommand \index{Libraries}
19891
19892 \end_inset
19893
19894
19895 \end_layout
19896
19897 \begin_layout Standard
19898
19899 \emph on
19900 <pending: this is messy and incomplete - a little more information is in
19901  sdcc/doc/libdoc.txt
19902 \emph default
19903  >
19904 \end_layout
19905
19906 \begin_layout Subsection
19907 Compiler support routines (_gptrget, _mulint etc.)
19908 \end_layout
19909
19910 \begin_layout Subsection
19911 Stdclib functions (puts, printf, strcat etc.)
19912 \end_layout
19913
19914 \begin_layout Subsubsection
19915 <stdio.h>
19916 \end_layout
19917
19918 \begin_layout Paragraph
19919 getchar(), putchar()
19920 \end_layout
19921
19922 \begin_layout Standard
19923 \begin_inset LatexCommand \index{<stdio.h>}
19924
19925 \end_inset
19926
19927 As usual on embedded systems you have to provide your own 
19928 \family typewriter
19929 getchar()
19930 \begin_inset LatexCommand \index{getchar()}
19931
19932 \end_inset
19933
19934  
19935 \family default
19936 and 
19937 \family typewriter
19938 putchar()
19939 \begin_inset LatexCommand \index{putchar()}
19940
19941 \end_inset
19942
19943
19944 \family default
19945  routines.
19946  SDCC does not know whether the system connects to a serial line with or
19947  without handshake, LCD, keyboard or other device.
19948  And whether a 
19949 \family typewriter
19950 lf
19951 \family default
19952  to 
19953 \family typewriter
19954 crlf
19955 \family default
19956  conversion within 
19957 \family typewriter
19958 putchar()
19959 \family default
19960  is intended.
19961  You'll find examples for serial routines f.e.
19962  in sdcc/device/lib.
19963  For the mcs51 this minimalistic polling 
19964 \family typewriter
19965 putchar()
19966 \family default
19967  routine might be a start:
19968 \end_layout
19969
19970 \begin_layout Verse
19971
19972 \family typewriter
19973 void putchar (char c) { 
19974 \newline
19975 \InsetSpace ~
19976 \InsetSpace ~
19977 \InsetSpace ~
19978 \InsetSpace ~
19979 while (!TI)\InsetSpace ~
19980 \InsetSpace ~
19981 \InsetSpace ~
19982  /* assumes UART is initialized */
19983 \newline
19984 \InsetSpace ~
19985 \InsetSpace ~
19986 \InsetSpace ~
19987 \InsetSpace ~
19988 \InsetSpace ~
19989 \InsetSpace ~
19990 \InsetSpace ~
19991 \InsetSpace ~
19992 ;
19993 \newline
19994 \InsetSpace ~
19995 \InsetSpace ~
19996 \InsetSpace ~
19997 \InsetSpace ~
19998 TI
19999  = 0;
20000 \newline
20001 \InsetSpace ~
20002 \InsetSpace ~
20003 \InsetSpace ~
20004 \InsetSpace ~
20005 SBUF = c;
20006 \newline
20007 }
20008 \end_layout
20009
20010 \begin_layout Paragraph
20011 printf()
20012 \end_layout
20013
20014 \begin_layout Standard
20015 The default
20016 \family typewriter
20017  printf()
20018 \begin_inset LatexCommand \index{printf()}
20019
20020 \end_inset
20021
20022
20023 \family default
20024  implementation in
20025 \family typewriter
20026  printf_large.c
20027 \family default
20028  does not support float (except on ds390).
20029  To enable this recompile it with the option 
20030 \emph on
20031 -
20032 \begin_inset ERT
20033 status collapsed
20034
20035 \begin_layout Standard
20036
20037
20038 \backslash
20039 /
20040 \end_layout
20041
20042 \end_inset
20043
20044 DUSE_FLOATS=1
20045 \begin_inset LatexCommand \index{USE\_FLOATS}
20046
20047 \end_inset
20048
20049
20050 \emph default
20051  on the command line.
20052  Use
20053 \emph on
20054  -
20055 \begin_inset ERT
20056 status collapsed
20057
20058 \begin_layout Standard
20059
20060
20061 \backslash
20062 /
20063 \end_layout
20064
20065 \end_inset
20066
20067 -model-large
20068 \begin_inset LatexCommand \index{-\/-model-large}
20069
20070 \end_inset
20071
20072
20073 \emph default
20074  for the mcs51 port, since this uses a lot of memory.
20075 \end_layout
20076
20077 \begin_layout Standard
20078 If you're short on code memory you might want to use 
20079 \family typewriter
20080 printf_small()
20081 \begin_inset LatexCommand \index{printf\_small()}
20082
20083 \end_inset
20084
20085
20086 \family default
20087  
20088 \emph on
20089 instead
20090 \emph default
20091  of
20092 \family typewriter
20093  printf().
20094
20095 \family default
20096  For the mcs51 there additionally are assembly versions 
20097 \family typewriter
20098 printf_tiny()
20099 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20100
20101 \end_inset
20102
20103
20104 \family default
20105  (subset of printf using less than 270 bytes) and 
20106 \family typewriter
20107 printf_fast()
20108 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20109
20110 \end_inset
20111
20112  
20113 \family default
20114 and
20115 \family typewriter
20116  printf_fast_f()
20117 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20118
20119 \end_inset
20120
20121
20122 \family default
20123  (floating-point aware version of printf_fast) which should fit the requirements
20124  of many embedded systems (printf_fast() can be customized by unsetting
20125  #defines to 
20126 \emph on
20127 not
20128 \emph default
20129  support long variables and field widths).
20130  Be sure to use only one of these printf options within a project.
20131 \newline
20132
20133 \end_layout
20134
20135 \begin_layout Standard
20136 Feature matrix of different 
20137 \emph on
20138 printf
20139 \emph default
20140  options on mcs51.
20141 \end_layout
20142
20143 \begin_layout Standard
20144 \begin_inset Tabular
20145 <lyxtabular version="3" rows="14" columns="7">
20146 <features islongtable="true">
20147 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20148 <column alignment="center" valignment="top" leftline="true" width="0">
20149 <column alignment="center" valignment="top" leftline="true" width="12col%">
20150 <column alignment="center" valignment="top" leftline="true" width="10col%">
20151 <column alignment="center" valignment="top" leftline="true" width="0">
20152 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20153 <column alignment="center" valignment="top" rightline="true" width="0">
20154 <row topline="true" bottomline="true" endhead="true">
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20156 \begin_inset Text
20157
20158 \begin_layout Standard
20159
20160 \series bold
20161 \size large
20162 mcs51
20163 \end_layout
20164
20165 \end_inset
20166 </cell>
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_inset Text
20169
20170 \begin_layout Standard
20171 printf
20172 \begin_inset LatexCommand \index{printf}
20173
20174 \end_inset
20175
20176
20177 \end_layout
20178
20179 \end_inset
20180 </cell>
20181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20182 \begin_inset Text
20183
20184 \begin_layout Standard
20185 printf 
20186 \size scriptsize
20187 USE_FLOATS=1
20188 \end_layout
20189
20190 \end_inset
20191 </cell>
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20193 \begin_inset Text
20194
20195 \begin_layout Standard
20196 printf_small
20197 \end_layout
20198
20199 \end_inset
20200 </cell>
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20202 \begin_inset Text
20203
20204 \begin_layout Standard
20205 printf_fast
20206 \end_layout
20207
20208 \end_inset
20209 </cell>
20210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20211 \begin_inset Text
20212
20213 \begin_layout Standard
20214 printf_fast_f
20215 \end_layout
20216
20217 \end_inset
20218 </cell>
20219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20220 \begin_inset Text
20221
20222 \begin_layout Standard
20223 printf_tiny
20224 \end_layout
20225
20226 \end_inset
20227 </cell>
20228 </row>
20229 <row topline="true" endhead="true">
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20231 \begin_inset Text
20232
20233 \begin_layout Standard
20234 filename
20235 \end_layout
20236
20237 \end_inset
20238 </cell>
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_inset Text
20241
20242 \begin_layout Standard
20243
20244 \size scriptsize
20245 printf_large.c
20246 \end_layout
20247
20248 \end_inset
20249 </cell>
20250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_inset Text
20252
20253 \begin_layout Standard
20254
20255 \size scriptsize
20256 printf_large.c
20257 \end_layout
20258
20259 \end_inset
20260 </cell>
20261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20262 \begin_inset Text
20263
20264 \begin_layout Standard
20265
20266 \size scriptsize
20267 printfl.c
20268 \end_layout
20269
20270 \end_inset
20271 </cell>
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20273 \begin_inset Text
20274
20275 \begin_layout Standard
20276
20277 \size scriptsize
20278 printf_fast.c
20279 \end_layout
20280
20281 \end_inset
20282 </cell>
20283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20284 \begin_inset Text
20285
20286 \begin_layout Standard
20287
20288 \size scriptsize
20289 printf_fast_f.c
20290 \end_layout
20291
20292 \end_inset
20293 </cell>
20294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20295 \begin_inset Text
20296
20297 \begin_layout Standard
20298
20299 \size scriptsize
20300 printf_tiny.c
20301 \end_layout
20302
20303 \end_inset
20304 </cell>
20305 </row>
20306 <row topline="true" endhead="true">
20307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20308 \begin_inset Text
20309
20310 \begin_layout Standard
20311 \begin_inset Quotes sld
20312 \end_inset
20313
20314 Hello World
20315 \begin_inset Quotes srd
20316 \end_inset
20317
20318  size
20319 \end_layout
20320
20321 \begin_layout Standard
20322 small / large
20323 \end_layout
20324
20325 \end_inset
20326 </cell>
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20328 \begin_inset Text
20329
20330 \begin_layout Standard
20331 1.7k / 2.4k
20332 \end_layout
20333
20334 \end_inset
20335 </cell>
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \begin_layout Standard
20340 4.3k / 5.6k
20341 \end_layout
20342
20343 \end_inset
20344 </cell>
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20346 \begin_inset Text
20347
20348 \begin_layout Standard
20349 1.2k / 1.8k
20350 \end_layout
20351
20352 \end_inset
20353 </cell>
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20355 \begin_inset Text
20356
20357 \begin_layout Standard
20358 1.3k / 1.3k
20359 \end_layout
20360
20361 \end_inset
20362 </cell>
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 1.9k / 1.9k
20368 \end_layout
20369
20370 \end_inset
20371 </cell>
20372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20373 \begin_inset Text
20374
20375 \begin_layout Standard
20376 0.44k / 0.44k
20377 \end_layout
20378
20379 \end_inset
20380 </cell>
20381 </row>
20382 <row topline="true" endhead="true">
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 code size
20388 \end_layout
20389
20390 \begin_layout Standard
20391 small / large
20392 \end_layout
20393
20394 \end_inset
20395 </cell>
20396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20397 \begin_inset Text
20398
20399 \begin_layout Standard
20400 1.4k / 2.0k
20401 \end_layout
20402
20403 \end_inset
20404 </cell>
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20406 \begin_inset Text
20407
20408 \begin_layout Standard
20409 2.8k / 3.7k
20410 \end_layout
20411
20412 \end_inset
20413 </cell>
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20415 \begin_inset Text
20416
20417 \begin_layout Standard
20418 0.45k / 0.47k (+ _ltoa)
20419 \end_layout
20420
20421 \end_inset
20422 </cell>
20423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20424 \begin_inset Text
20425
20426 \begin_layout Standard
20427 1.2k / 1.2k
20428 \end_layout
20429
20430 \end_inset
20431 </cell>
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20433 \begin_inset Text
20434
20435 \begin_layout Standard
20436 1.6k / 1.6k
20437 \end_layout
20438
20439 \end_inset
20440 </cell>
20441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20442 \begin_inset Text
20443
20444 \begin_layout Standard
20445 0.26k / 0.26k
20446 \end_layout
20447
20448 \end_inset
20449 </cell>
20450 </row>
20451 <row topline="true">
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456 formats
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 cdi
20466 \emph on
20467 o
20468 \emph default
20469 psux
20470 \end_layout
20471
20472 \end_inset
20473 </cell>
20474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20475 \begin_inset Text
20476
20477 \begin_layout Standard
20478
20479 \family roman
20480 \series medium
20481 \shape up
20482 \size normal
20483 \emph off
20484 \bar no
20485 \noun off
20486 \color none
20487 cd
20488 \family default
20489 \series default
20490 \shape default
20491 \size default
20492 \emph default
20493 \bar default
20494 \noun default
20495 f
20496 \family roman
20497 \series medium
20498 \shape up
20499 \size normal
20500 \emph off
20501 \bar no
20502 \noun off
20503 i
20504 \family default
20505 \series default
20506 \shape default
20507 \size default
20508 \emph on
20509 \bar default
20510 \noun default
20511 o
20512 \family roman
20513 \series medium
20514 \shape up
20515 \size normal
20516 \emph off
20517 \bar no
20518 \noun off
20519 psux
20520 \end_layout
20521
20522 \end_inset
20523 </cell>
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20525 \begin_inset Text
20526
20527 \begin_layout Standard
20528 c
20529 \family roman
20530 \series medium
20531 \shape up
20532 \size normal
20533 \emph off
20534 \bar no
20535 \noun off
20536 \color none
20537 d
20538 \family default
20539 \series default
20540 \shape default
20541 \size default
20542 \emph on
20543 \bar default
20544 \noun default
20545 o
20546 \family roman
20547 \series medium
20548 \shape up
20549 \size normal
20550 \emph off
20551 \bar no
20552 \noun off
20553 s
20554 \family default
20555 \series default
20556 \shape default
20557 \size default
20558 \emph default
20559 \bar default
20560 \noun default
20561 x
20562 \end_layout
20563
20564 \end_inset
20565 </cell>
20566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20567 \begin_inset Text
20568
20569 \begin_layout Standard
20570 cdsux
20571 \end_layout
20572
20573 \end_inset
20574 </cell>
20575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20576 \begin_inset Text
20577
20578 \begin_layout Standard
20579 cdfsux
20580 \end_layout
20581
20582 \end_inset
20583 </cell>
20584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20585 \begin_inset Text
20586
20587 \begin_layout Standard
20588 cdsux
20589 \end_layout
20590
20591 \end_inset
20592 </cell>
20593 </row>
20594 <row topline="true">
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20596 \begin_inset Text
20597
20598 \begin_layout Standard
20599 long (32 bit) support
20600 \end_layout
20601
20602 \end_inset
20603 </cell>
20604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20605 \begin_inset Text
20606
20607 \begin_layout Standard
20608 x
20609 \end_layout
20610
20611 \end_inset
20612 </cell>
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20614 \begin_inset Text
20615
20616 \begin_layout Standard
20617 x
20618 \end_layout
20619
20620 \end_inset
20621 </cell>
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 \begin_inset Text
20624
20625 \begin_layout Standard
20626 x
20627 \end_layout
20628
20629 \end_inset
20630 </cell>
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20632 \begin_inset Text
20633
20634 \begin_layout Standard
20635 x
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \begin_layout Standard
20644
20645 \family roman
20646 \series medium
20647 \shape up
20648 \size normal
20649 \emph off
20650 \bar no
20651 \noun off
20652 \color none
20653 x
20654 \end_layout
20655
20656 \end_inset
20657 </cell>
20658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20659 \begin_inset Text
20660
20661 \begin_layout Standard
20662 -
20663 \end_layout
20664
20665 \end_inset
20666 </cell>
20667 </row>
20668 <row topline="true">
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \begin_layout Standard
20673 byte arguments on stack
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 b
20683 \end_layout
20684
20685 \end_inset
20686 </cell>
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20688 \begin_inset Text
20689
20690 \begin_layout Standard
20691 b
20692 \end_layout
20693
20694 \end_inset
20695 </cell>
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20697 \begin_inset Text
20698
20699 \begin_layout Standard
20700 -
20701 \end_layout
20702
20703 \end_inset
20704 </cell>
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20706 \begin_inset Text
20707
20708 \begin_layout Standard
20709 -
20710 \end_layout
20711
20712 \end_inset
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \begin_layout Standard
20718 -
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20724 \begin_inset Text
20725
20726 \begin_layout Standard
20727 -
20728 \end_layout
20729
20730 \end_inset
20731 </cell>
20732 </row>
20733 <row topline="true">
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20735 \begin_inset Text
20736
20737 \begin_layout Standard
20738 float format
20739 \begin_inset LatexCommand \index{Floating point support}
20740
20741 \end_inset
20742
20743
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 -
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 %f
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 -
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 -
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 %f
20789 \begin_inset Foot
20790 status collapsed
20791
20792 \begin_layout Standard
20793 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20794 \end_layout
20795
20796 \end_inset
20797
20798
20799 \end_layout
20800
20801 \end_inset
20802 </cell>
20803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20804 \begin_inset Text
20805
20806 \begin_layout Standard
20807 -
20808 \end_layout
20809
20810 \end_inset
20811 </cell>
20812 </row>
20813 <row topline="true">
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20815 \begin_inset Text
20816
20817 \begin_layout Standard
20818 float formats %e %g
20819 \end_layout
20820
20821 \end_inset
20822 </cell>
20823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20824 \begin_inset Text
20825
20826 \begin_layout Standard
20827 -
20828 \end_layout
20829
20830 \end_inset
20831 </cell>
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20833 \begin_inset Text
20834
20835 \begin_layout Standard
20836 -
20837 \end_layout
20838
20839 \end_inset
20840 </cell>
20841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20842 \begin_inset Text
20843
20844 \begin_layout Standard
20845 -
20846 \end_layout
20847
20848 \end_inset
20849 </cell>
20850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20851 \begin_inset Text
20852
20853 \begin_layout Standard
20854 -
20855 \end_layout
20856
20857 \end_inset
20858 </cell>
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20860 \begin_inset Text
20861
20862 \begin_layout Standard
20863 -
20864 \end_layout
20865
20866 \end_inset
20867 </cell>
20868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20869 \begin_inset Text
20870
20871 \begin_layout Standard
20872 -
20873 \end_layout
20874
20875 \end_inset
20876 </cell>
20877 </row>
20878 <row topline="true" bottomline="true">
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20880 \begin_inset Text
20881
20882 \begin_layout Standard
20883 field width
20884 \end_layout
20885
20886 \end_inset
20887 </cell>
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20889 \begin_inset Text
20890
20891 \begin_layout Standard
20892 x
20893 \end_layout
20894
20895 \end_inset
20896 </cell>
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20898 \begin_inset Text
20899
20900 \begin_layout Standard
20901 x
20902 \end_layout
20903
20904 \end_inset
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \begin_layout Standard
20910 -
20911 \end_layout
20912
20913 \end_inset
20914 </cell>
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20916 \begin_inset Text
20917
20918 \begin_layout Standard
20919 x
20920 \end_layout
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \begin_layout Standard
20928 x
20929 \end_layout
20930
20931 \end_inset
20932 </cell>
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20934 \begin_inset Text
20935
20936 \begin_layout Standard
20937 -
20938 \end_layout
20939
20940 \end_inset
20941 </cell>
20942 </row>
20943 <row bottomline="true">
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \begin_layout Standard
20948 string speed
20949 \begin_inset Foot
20950 status collapsed
20951
20952 \begin_layout Standard
20953 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20954 \backslash
20955 r', '
20956 \backslash
20957 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20958 \end_layout
20959
20960 \end_inset
20961
20962 ,
20963 \end_layout
20964
20965 \begin_layout Standard
20966 small / large
20967 \end_layout
20968
20969 \end_inset
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \begin_layout Standard
20975 1.52 / 2.59 ms
20976 \end_layout
20977
20978 \end_inset
20979 </cell>
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20981 \begin_inset Text
20982
20983 \begin_layout Standard
20984 1.53 / 2.62 ms
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 0.92 / 0.93 ms
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 0.45 / 0.45 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 0.46 / 0.46 ms
21012 \end_layout
21013
21014 \end_inset
21015 </cell>
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \begin_layout Standard
21020 0.45 / 0.45 ms
21021 \end_layout
21022
21023 \end_inset
21024 </cell>
21025 </row>
21026 <row bottomline="true">
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \begin_layout Standard
21031 int speed
21032 \begin_inset Foot
21033 status collapsed
21034
21035 \begin_layout Standard
21036 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21037  putchar()
21038 \end_layout
21039
21040 \end_inset
21041
21042 ,
21043 \end_layout
21044
21045 \begin_layout Standard
21046 small / large
21047 \end_layout
21048
21049 \end_inset
21050 </cell>
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21052 \begin_inset Text
21053
21054 \begin_layout Standard
21055 3.01 / 3.61 ms
21056 \end_layout
21057
21058 \end_inset
21059 </cell>
21060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21061 \begin_inset Text
21062
21063 \begin_layout Standard
21064 3.01 / 3.61 ms
21065 \end_layout
21066
21067 \end_inset
21068 </cell>
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \begin_layout Standard
21073 3.51 / 18.13 ms
21074 \end_layout
21075
21076 \end_inset
21077 </cell>
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21079 \begin_inset Text
21080
21081 \begin_layout Standard
21082 0.22 / 0.22 ms
21083 \end_layout
21084
21085 \end_inset
21086 </cell>
21087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21088 \begin_inset Text
21089
21090 \begin_layout Standard
21091 0.23 / 0.23 ms
21092 \end_layout
21093
21094 \end_inset
21095 </cell>
21096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21097 \begin_inset Text
21098
21099 \begin_layout Standard
21100 0.25 / 0.25 ms
21101 \begin_inset Foot
21102 status collapsed
21103
21104 \begin_layout Standard
21105 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21106 \end_layout
21107
21108 \end_inset
21109
21110
21111 \end_layout
21112
21113 \end_inset
21114 </cell>
21115 </row>
21116 <row bottomline="true">
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_inset Text
21119
21120 \begin_layout Standard
21121 long speed
21122 \begin_inset Foot
21123 status collapsed
21124
21125 \begin_layout Standard
21126 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21127  empty putchar()
21128 \end_layout
21129
21130 \end_inset
21131
21132 ,
21133 \end_layout
21134
21135 \begin_layout Standard
21136 small / large
21137 \end_layout
21138
21139 \end_inset
21140 </cell>
21141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21142 \begin_inset Text
21143
21144 \begin_layout Standard
21145 5.37 / 6.31 ms
21146 \end_layout
21147
21148 \end_inset
21149 </cell>
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21151 \begin_inset Text
21152
21153 \begin_layout Standard
21154 5.37 / 6.31 ms
21155 \end_layout
21156
21157 \end_inset
21158 </cell>
21159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21160 \begin_inset Text
21161
21162 \begin_layout Standard
21163 8.71 / 40.65 ms
21164 \end_layout
21165
21166 \end_inset
21167 </cell>
21168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21169 \begin_inset Text
21170
21171 \begin_layout Standard
21172 0.40 / 0.40 ms
21173 \end_layout
21174
21175 \end_inset
21176 </cell>
21177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21178 \begin_inset Text
21179
21180 \begin_layout Standard
21181 0.40 / 0.40 ms
21182 \end_layout
21183
21184 \end_inset
21185 </cell>
21186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21187 \begin_inset Text
21188
21189 \begin_layout Standard
21190 -
21191 \end_layout
21192
21193 \end_inset
21194 </cell>
21195 </row>
21196 <row bottomline="true">
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21198 \begin_inset Text
21199
21200 \begin_layout Standard
21201 float speed
21202 \begin_inset Foot
21203 status collapsed
21204
21205 \begin_layout Standard
21206 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21207  empty putchar()
21208 \end_layout
21209
21210 \end_inset
21211
21212 ,
21213 \end_layout
21214
21215 \begin_layout Standard
21216 small / large
21217 \end_layout
21218
21219 \end_inset
21220 </cell>
21221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21222 \begin_inset Text
21223
21224 \begin_layout Standard
21225 -
21226 \end_layout
21227
21228 \end_inset
21229 </cell>
21230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21231 \begin_inset Text
21232
21233 \begin_layout Standard
21234 7.49 / 22.47 ms
21235 \end_layout
21236
21237 \end_inset
21238 </cell>
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21240 \begin_inset Text
21241
21242 \begin_layout Standard
21243 -
21244 \end_layout
21245
21246 \end_inset
21247 </cell>
21248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21249 \begin_inset Text
21250
21251 \begin_layout Standard
21252 -
21253 \end_layout
21254
21255 \end_inset
21256 </cell>
21257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21258 \begin_inset Text
21259
21260 \begin_layout Standard
21261 1.04 / 1.04 ms
21262 \end_layout
21263
21264 \end_inset
21265 </cell>
21266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21267 \begin_inset Text
21268
21269 \begin_layout Standard
21270 -
21271 \end_layout
21272
21273 \end_inset
21274 </cell>
21275 </row>
21276 </lyxtabular>
21277
21278 \end_inset
21279
21280
21281 \end_layout
21282
21283 \begin_layout Subsubsection
21284 <malloc.h>
21285 \begin_inset LatexCommand \index{malloc.h}
21286
21287 \end_inset
21288
21289
21290 \end_layout
21291
21292 \begin_layout Standard
21293 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21294  using dynamic memory allocation
21295 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21296
21297 \end_inset
21298
21299  and a default heap
21300 \begin_inset LatexCommand \index{heap (malloc)}
21301
21302 \end_inset
21303
21304  space of 1024 bytes is provided for malloc to allocate memory from.
21305  If you need a different heap size you need to recompile _heap.c with the
21306  required size defined in HEAP_SIZE.
21307  It is recommended to make a copy of this file into your project directory
21308  and compile it there with:
21309 \end_layout
21310
21311 \begin_layout Verse
21312
21313 \family typewriter
21314 sdcc -c _heap.c -D HEAD_SIZE=2048
21315 \end_layout
21316
21317 \begin_layout Standard
21318 And then link it with:
21319 \end_layout
21320
21321 \begin_layout Verse
21322
21323 \family typewriter
21324 sdcc main.rel _heap.rel
21325 \end_layout
21326
21327 \begin_layout Subsection
21328 Math functions (sinf, powf, sqrtf etc.)
21329 \end_layout
21330
21331 \begin_layout Subsubsection
21332 <math.h>
21333 \end_layout
21334
21335 \begin_layout Standard
21336 See definitions in file <math.h>.
21337 \end_layout
21338
21339 \begin_layout Subsection
21340 Other libraries
21341 \end_layout
21342
21343 \begin_layout Standard
21344 Libraries
21345 \begin_inset LatexCommand \index{Libraries}
21346
21347 \end_inset
21348
21349  included in SDCC should have a license at least as liberal as the GNU Lesser
21350  General Public License
21351 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21352
21353 \end_inset
21354
21355  
21356 \emph on
21357 LGPL
21358 \emph default
21359 .
21360 \end_layout
21361
21362 \begin_layout Standard
21363 \begin_inset Note Note
21364 status collapsed
21365
21366 \begin_layout Standard
21367 license statements for the libraries are missing.
21368  sdcc/device/lib/ser_ir.c
21369 \end_layout
21370
21371 \begin_layout Standard
21372 or _decdptr f.e.
21373  come with a GPL (as opposed to LGPL) License - this will not be liberal
21374  enough for many embedded programmers.
21375 \end_layout
21376
21377 \end_inset
21378
21379
21380 \end_layout
21381
21382 \begin_layout Standard
21383 If you have ported some library or want to share experience about some code
21384  which f.e.
21385  falls into any of these categories Busses (I
21386 \begin_inset Formula $^{\textrm{2}}$
21387 \end_inset
21388
21389 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21390  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21391  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21392 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21393
21394 \end_inset
21395
21396 \InsetSpace ~
21397 would certainly like to hear about it.
21398 \end_layout
21399
21400 \begin_layout Standard
21401 Programmers coding for embedded systems are not especially famous for being
21402  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21403 e these references are very valuable.
21404  Let's help to create a climate where information is shared.
21405 \begin_inset VSpace bigskip
21406 \end_inset
21407
21408
21409 \end_layout
21410
21411 \begin_layout Section
21412 Memory Models
21413 \end_layout
21414
21415 \begin_layout Subsection
21416 MCS51 Memory Models
21417 \begin_inset LatexCommand \index{Memory model}
21418
21419 \end_inset
21420
21421
21422 \begin_inset LatexCommand \index{MCS51 memory model}
21423
21424 \end_inset
21425
21426
21427 \end_layout
21428
21429 \begin_layout Subsubsection
21430 Small, Medium and Large
21431 \end_layout
21432
21433 \begin_layout Standard
21434 SDCC allows three memory models for MCS51 code, 
21435 \shape slanted
21436 small, medium
21437 \shape default
21438  and 
21439 \shape slanted
21440 large
21441 \shape default
21442 .
21443  Modules compiled with different memory models should 
21444 \emph on
21445 never
21446 \emph default
21447  be combined together or the results would be unpredictable.
21448  The library routines supplied with the compiler are compiled as small,
21449  medium and large.
21450  The compiled library modules are contained in separate directories as small,
21451  medium and large so that you can link to the appropriate set.
21452 \end_layout
21453
21454 \begin_layout Standard
21455 When the medium or large model is used all variables declared without a
21456  storage class will be allocated into the external ram, this includes all
21457  parameters and local variables (for non-reentrant
21458 \begin_inset LatexCommand \index{reentrant}
21459
21460 \end_inset
21461
21462  functions).
21463  When the small model is used variables without storage class are allocated
21464  in the internal ram.
21465 \end_layout
21466
21467 \begin_layout Standard
21468 Judicious usage of the processor specific storage classes
21469 \begin_inset LatexCommand \index{Storage class}
21470
21471 \end_inset
21472
21473  and the 'reentrant' function type will yield much more efficient code,
21474  than using the large model.
21475  Several optimizations are disabled when the program is compiled using the
21476  large model, it is therefore recommended that the small model be used unless
21477  absolutely required.
21478 \end_layout
21479
21480 \begin_layout Subsubsection
21481 External Stack
21482 \begin_inset LatexCommand \label{sub:External-Stack}
21483
21484 \end_inset
21485
21486
21487 \begin_inset LatexCommand \index{stack}
21488
21489 \end_inset
21490
21491
21492 \begin_inset LatexCommand \index{External stack (mcs51)}
21493
21494 \end_inset
21495
21496
21497 \end_layout
21498
21499 \begin_layout Standard
21500 The external stack (-
21501 \begin_inset ERT
21502 status collapsed
21503
21504 \begin_layout Standard
21505
21506
21507 \backslash
21508 /
21509 \end_layout
21510
21511 \end_inset
21512
21513 -xstack option
21514 \begin_inset LatexCommand \index{-\/-xstack}
21515
21516 \end_inset
21517
21518 ) is located in pdata
21519 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21520
21521 \end_inset
21522
21523  memory (usually at the start of the external ram segment) and uses all
21524  unused space in pdata (max.
21525  256 bytes).
21526  When -
21527 \begin_inset ERT
21528 status collapsed
21529
21530 \begin_layout Standard
21531
21532
21533 \backslash
21534 /
21535 \end_layout
21536
21537 \end_inset
21538
21539 -xstack option is used to compile the program, the parameters and local
21540  variables
21541 \begin_inset LatexCommand \index{local variables}
21542
21543 \end_inset
21544
21545  of all reentrant functions are allocated in this area.
21546  This option is provided for programs with large stack space requirements.
21547  When used with the -
21548 \begin_inset ERT
21549 status collapsed
21550
21551 \begin_layout Standard
21552
21553
21554 \backslash
21555 /
21556 \end_layout
21557
21558 \end_inset
21559
21560 -stack-auto
21561 \begin_inset LatexCommand \index{-\/-stack-auto}
21562
21563 \end_inset
21564
21565  option, all parameters and local variables are allocated on the external
21566  stack (note: support libraries will need to be recompiled with the same
21567  options.
21568  There is a predefined target in the library makefile).
21569 \end_layout
21570
21571 \begin_layout Standard
21572 The compiler outputs the higher order address byte of the external ram segment
21573  into port P2
21574 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21575
21576 \end_inset
21577
21578  (see also section 
21579 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21580
21581 \end_inset
21582
21583 ), therefore when using the External Stack option, this port 
21584 \emph on
21585 may not
21586 \emph default
21587  be used by the application program.
21588 \end_layout
21589
21590 \begin_layout Subsection
21591 DS390 Memory Model
21592 \begin_inset LatexCommand \index{Memory model}
21593
21594 \end_inset
21595
21596
21597 \begin_inset LatexCommand \index{DS390 memory model}
21598
21599 \end_inset
21600
21601
21602 \end_layout
21603
21604 \begin_layout Standard
21605 The only model supported is Flat 24
21606 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21607
21608 \end_inset
21609
21610 .
21611  This generates code for the 24 bit contiguous addressing mode of the Dallas
21612  DS80C390 part.
21613  In this mode, up to four meg of external RAM or code space can be directly
21614  addressed.
21615  See the data sheets at www.dalsemi.com for further information on this part.
21616 \newline
21617
21618 \newline
21619 Note
21620  that the compiler does not generate any code to place the processor into
21621  24 bitmode (although 
21622 \emph on
21623 tinibios
21624 \emph default
21625  in the ds390 libraries will do that for you).
21626  If you don't use 
21627 \emph on
21628 tinibios
21629 \emph default
21630
21631 \begin_inset LatexCommand \index{Tinibios (DS390)}
21632
21633 \end_inset
21634
21635 , the boot loader or similar code must ensure that the processor is in 24
21636  bit contiguous addressing mode before calling the SDCC startup code.
21637 \newline
21638
21639 \newline
21640 Like
21641  the 
21642 \emph on
21643 -
21644 \begin_inset ERT
21645 status collapsed
21646
21647 \begin_layout Standard
21648
21649
21650 \backslash
21651 /
21652 \end_layout
21653
21654 \end_inset
21655
21656 -model-large
21657 \emph default
21658  option, variables will by default be placed into the XDATA segment.
21659  
21660 \newline
21661
21662 \newline
21663 Segments may be placed anywhere in the 4 meg address space using the usual
21664  -
21665 \begin_inset ERT
21666 status collapsed
21667
21668 \begin_layout Standard
21669
21670
21671 \backslash
21672 /
21673 \end_layout
21674
21675 \end_inset
21676
21677 -*-loc options.
21678  Note that if any segments are located above 64K, the -r flag must be passed
21679  to the linker to generate the proper segment relocations, and the Intel
21680  HEX output format must be used.
21681  The -r flag can be passed to the linker by using the option 
21682 \emph on
21683 -Wl-r
21684 \emph default
21685  on the SDCC command line.
21686  However, currently the linker can not handle code segments > 64k.
21687 \end_layout
21688
21689 \begin_layout Section
21690 Pragmas
21691 \begin_inset LatexCommand \label{sec:Pragmas}
21692
21693 \end_inset
21694
21695
21696 \begin_inset LatexCommand \index{Pragmas}
21697
21698 \end_inset
21699
21700
21701 \end_layout
21702
21703 \begin_layout Standard
21704 Pragmas are used to turn on and/or off certain compiler options.
21705  Some of them are closely related to corresponding command-line options
21706  (see section 
21707 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21708
21709 \end_inset
21710
21711 ).
21712 \newline
21713 Pragmas should be placed before and/or after a function, placing pragmas
21714  inside a function body could have unpredictable results.
21715 \newline
21716
21717 \newline
21718 SDCC supports the
21719  following #pragma directives:
21720 \end_layout
21721
21722 \begin_layout Itemize
21723
21724 \series bold
21725 save
21726 \series default
21727
21728 \begin_inset LatexCommand \index{\#pragma save}
21729
21730 \end_inset
21731
21732  - this will save most current options to the save/restore stack.
21733  See #pragma\InsetSpace ~
21734 restore.
21735 \end_layout
21736
21737 \begin_layout Itemize
21738
21739 \series bold
21740 restore
21741 \series default
21742
21743 \begin_inset LatexCommand \index{\#pragma restore}
21744
21745 \end_inset
21746
21747  - will restore saved options from the last save.
21748  saves & restores can be nested.
21749  SDCC uses a save/restore stack: save pushes current options to the stack,
21750  restore pulls current options from the stack.
21751  See #pragma\InsetSpace ~
21752 save.
21753 \newline
21754
21755 \end_layout
21756
21757 \begin_layout Itemize
21758
21759 \series bold
21760 callee_saves
21761 \series default
21762
21763 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21764
21765 \end_inset
21766
21767
21768 \begin_inset LatexCommand \index{function prologue}
21769
21770 \end_inset
21771
21772  function1[,function2[,function3...]] 
21773 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21774
21775 \end_inset
21776
21777 - The compiler by default uses a caller saves convention for register saving
21778  across function calls, however this can cause unnecessary register pushing
21779  and popping
21780 \begin_inset LatexCommand \index{push/pop}
21781
21782 \end_inset
21783
21784  when calling small functions from larger functions.
21785  This option can be used to switch off the register saving convention for
21786  the function names specified.
21787  The compiler will not save registers when calling these functions, extra
21788  code need to be manually inserted at the entry and exit for these functions
21789  to save and restore the registers used by these functions, this can SUBSTANTIAL
21790 LY reduce code and improve run time performance of the generated code.
21791  In the future the compiler (with inter procedural analysis) may be able
21792  to determine the appropriate scheme to use for each function call.
21793  If -
21794 \begin_inset ERT
21795 status collapsed
21796
21797 \begin_layout Standard
21798
21799
21800 \backslash
21801 /
21802 \end_layout
21803
21804 \end_inset
21805
21806 -callee-saves command line option is used (see page 
21807 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21808
21809 \end_inset
21810
21811 ), the function names specified in #pragma\InsetSpace ~
21812 callee_saves
21813 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21814
21815 \end_inset
21816
21817  is appended to the list of functions specified in the command line.
21818 \end_layout
21819
21820 \begin_layout Itemize
21821
21822 \series bold
21823 exclude
21824 \series default
21825
21826 \begin_inset LatexCommand \index{\#pragma exclude}
21827
21828 \end_inset
21829
21830  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21831  of pairs of push/pop
21832 \begin_inset LatexCommand \index{push/pop}
21833
21834 \end_inset
21835
21836  instructions in 
21837 \emph on
21838 I
21839 \emph default
21840 nterrupt
21841 \begin_inset LatexCommand \index{interrupt}
21842
21843 \end_inset
21844
21845  
21846 \emph on
21847 S
21848 \emph default
21849 ervice 
21850 \emph on
21851 R
21852 \emph default
21853 outines.
21854  The directive should be placed immediately before the ISR function definition
21855  and it affects ALL ISR functions following it.
21856  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21857 exclude\InsetSpace ~
21858 none
21859 \begin_inset LatexCommand \index{\#pragma exclude}
21860
21861 \end_inset
21862
21863 .
21864  See also the related keyword _naked
21865 \begin_inset LatexCommand \index{\_naked}
21866
21867 \end_inset
21868
21869
21870 \begin_inset LatexCommand \index{\_\_naked}
21871
21872 \end_inset
21873
21874 .
21875 \end_layout
21876
21877 \begin_layout Itemize
21878
21879 \series bold
21880 less_pedantic
21881 \series default
21882
21883 \begin_inset LatexCommand \index{pedantic}
21884
21885 \end_inset
21886
21887
21888 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21889
21890 \end_inset
21891
21892  
21893 \begin_inset LatexCommand \label{ite:less_pedantic}
21894
21895 \end_inset
21896
21897 - the compiler will not warn you anymore for obvious mistakes, you're on
21898  your own now ;-( .
21899  See also the command line option -
21900 \begin_inset ERT
21901 status collapsed
21902
21903 \begin_layout Standard
21904
21905
21906 \backslash
21907 /
21908 \end_layout
21909
21910 \end_inset
21911
21912 -less-pedantic 
21913 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21914
21915 \end_inset
21916
21917 .
21918  
21919 \newline
21920 More specifically, the following warnings will be disabled: 
21921 \shape italic
21922 comparison is always [true/false] due to limited range of data type
21923 \shape default
21924  (94); 
21925 \shape italic
21926 overflow in implicit constant conversion
21927 \shape default
21928  (158); [the (in)famous] 
21929 \shape italic
21930 conditional flow changed by optimizer: so said EVELYN the modified DOG
21931 \shape default
21932  (110); 
21933 \shape italic
21934 function '[function name]' must return value
21935 \shape default
21936  (59).
21937  
21938 \newline
21939 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21940  level) are disabled, too, namely: 
21941 \shape italic
21942 constant value '[
21943 \begin_inset Note Note
21944 status collapsed
21945
21946 \begin_layout Standard
21947 dunno what comes here - this warning appears to be unused altogether
21948 \end_layout
21949
21950 \end_inset
21951
21952 ]', out of range
21953 \shape default
21954  (81); 
21955 \shape italic
21956 [left/right] shifting more than size of object changed to zero
21957 \shape default
21958  (116); 
21959 \shape italic
21960 unreachable code
21961 \shape default
21962  (126); 
21963 \shape italic
21964 integer overflow in expression
21965 \shape default
21966  (165); 
21967 \shape italic
21968 unmatched #pragma save and #pragma restore
21969 \shape default
21970  (170); 
21971 \shape italic
21972 comparison of 'signed char' with 'unsigned char' requires promotion to int
21973 \shape default
21974  (185); 
21975 \shape italic
21976 ISO C90 does not support flexible array members
21977 \shape default
21978  (187); 
21979 \shape italic
21980 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21981 nam
21982 e]':\InsetSpace ~
21983 [
21984 \begin_inset Note Note
21985 status collapsed
21986
21987 \begin_layout Standard
21988 appears to be always blank - what was supposed to be here?
21989 \end_layout
21990
21991 \end_inset
21992
21993 ]
21994 \shape default
21995  (114); 
21996 \shape italic
21997 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21998  complexity [number]
21999 \shape default
22000  (121).
22001 \end_layout
22002
22003 \begin_layout Itemize
22004
22005 \series bold
22006 disable_warning
22007 \series default
22008  <nnnn>
22009 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22010
22011 \end_inset
22012
22013  - the compiler will not warn you anymore about warning number <nnnn>.
22014 \end_layout
22015
22016 \begin_layout Itemize
22017
22018 \series bold
22019 nogcse
22020 \series default
22021
22022 \begin_inset LatexCommand \index{\#pragma nogcse}
22023
22024 \end_inset
22025
22026  - will stop global common subexpression elimination.
22027 \end_layout
22028
22029 \begin_layout Itemize
22030
22031 \series bold
22032 noinduction
22033 \series default
22034
22035 \begin_inset LatexCommand \index{\#pragma noinduction}
22036
22037 \end_inset
22038
22039  - will stop loop induction optimizations.
22040 \end_layout
22041
22042 \begin_layout Itemize
22043
22044 \series bold
22045 noinvariant
22046 \series default
22047
22048 \begin_inset LatexCommand \index{\#pragma noinvariant}
22049
22050 \end_inset
22051
22052  - will not do loop invariant optimizations.
22053  For more details see Loop Invariants in section
22054 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22055
22056 \end_inset
22057
22058 .
22059 \end_layout
22060
22061 \begin_layout Itemize
22062
22063 \series bold
22064 noiv
22065 \series default
22066
22067 \begin_inset LatexCommand \index{\#pragma noiv}
22068
22069 \end_inset
22070
22071  - Do not generate interrupt
22072 \begin_inset LatexCommand \index{interrupt}
22073
22074 \end_inset
22075
22076  vector table
22077 \begin_inset LatexCommand \index{interrupt vector table}
22078
22079 \end_inset
22080
22081  entries for all ISR functions defined after the pragma.
22082  This is useful in cases where the interrupt vector table must be defined
22083  manually, or when there is a secondary, manually defined interrupt vector
22084  table (e.g.
22085  for the autovector feature of the Cypress EZ-USB FX2).
22086  More elegantly this can be achieved by obmitting the optional interrupt
22087  number after the interrupt keyword, see section 
22088 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22089
22090 \end_inset
22091
22092 \InsetSpace ~
22093 about interrupts.
22094 \end_layout
22095
22096 \begin_layout Itemize
22097
22098 \series bold
22099 nojtbound
22100 \series default
22101
22102 \begin_inset LatexCommand \index{\#pragma nojtbound}
22103
22104 \end_inset
22105
22106  - will not generate code for boundary value checking, when switch statements
22107  are turned into jump-tables (dangerous).
22108  For more details see section 
22109 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22110
22111 \end_inset
22112
22113 .
22114 \end_layout
22115
22116 \begin_layout Itemize
22117
22118 \series bold
22119 noloopreverse
22120 \series default
22121
22122 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22123
22124 \end_inset
22125
22126  - Will not do loop reversal optimization
22127 \end_layout
22128
22129 \begin_layout Itemize
22130
22131 \series bold
22132 nooverlay
22133 \series default
22134
22135 \begin_inset LatexCommand \index{\#pragma nooverlay}
22136
22137 \end_inset
22138
22139  - the compiler will not overlay the parameters and local variables of a
22140  function.
22141 \end_layout
22142
22143 \begin_layout Itemize
22144
22145 \series bold
22146 stackauto
22147 \series default
22148
22149 \begin_inset LatexCommand \index{\#pragma stackauto}
22150
22151 \end_inset
22152
22153 - See option -
22154 \begin_inset ERT
22155 status collapsed
22156
22157 \begin_layout Standard
22158
22159
22160 \backslash
22161 /
22162 \end_layout
22163
22164 \end_inset
22165
22166 -stack-auto
22167 \begin_inset LatexCommand \index{-\/-stack-auto}
22168
22169 \end_inset
22170
22171  and section 
22172 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22173
22174 \end_inset
22175
22176  Parameters and Local Variables.
22177 \end_layout
22178
22179 \begin_layout Itemize
22180
22181 \series bold
22182 opt_code_speed
22183 \series default
22184  
22185 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22186
22187 \end_inset
22188
22189 - The compiler will optimize code generation towards fast code, possibly
22190  at the expense of code size.
22191  Currently this has little effect.
22192 \end_layout
22193
22194 \begin_layout Itemize
22195
22196 \series bold
22197 opt_code_size
22198 \series default
22199  
22200 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22201
22202 \end_inset
22203
22204 - The compiler will optimize code generation towards compact code, possibly
22205  at the expense of code speed.
22206  Currently this has little effect.
22207 \end_layout
22208
22209 \begin_layout Itemize
22210
22211 \series bold
22212 opt_code_balanced
22213 \series default
22214  
22215 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22216
22217 \end_inset
22218
22219 - The compiler will attempt to generate code that is both compact and fast,
22220  as long as meeting one goal is not a detriment to the other (this is the
22221  default).
22222  
22223 \end_layout
22224
22225 \begin_layout Itemize
22226
22227 \series bold
22228 std_sdcc89
22229 \series default
22230  
22231 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22232
22233 \end_inset
22234
22235 - Generally follow the C89 standard, but allow SDCC features that conflict
22236  with the standard (default).
22237 \end_layout
22238
22239 \begin_layout Itemize
22240
22241 \series bold
22242 std_c89
22243 \series default
22244  
22245 \begin_inset LatexCommand \index{\#pragma std\_c89}
22246
22247 \end_inset
22248
22249 - Follow the C89 standard and disable SDCC features that conflict with the
22250  standard.
22251 \end_layout
22252
22253 \begin_layout Itemize
22254
22255 \series bold
22256 std_sdcc99
22257 \series default
22258  
22259 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22260
22261 \end_inset
22262
22263 - Generally follow the C99 standard, but allow SDCC features that conflict
22264  with the standard (incomplete support).
22265 \end_layout
22266
22267 \begin_layout Itemize
22268
22269 \series bold
22270 std_c99
22271 \series default
22272  
22273 \begin_inset LatexCommand \index{\#pragma std\_c99}
22274
22275 \end_inset
22276
22277 - Follow the C99 standard and disable SDCC features that conflict with the
22278  standard (incomplete support).
22279 \end_layout
22280
22281 \begin_layout Itemize
22282
22283 \series bold
22284 codeseg
22285 \series default
22286  <name>
22287 \begin_inset LatexCommand \index{\#pragma codeseg}
22288
22289 \end_inset
22290
22291 - Use this name (max.
22292  8 characters) for the code segment.
22293  See option -
22294 \begin_inset ERT
22295 status collapsed
22296
22297 \begin_layout Standard
22298
22299
22300 \backslash
22301 /
22302 \end_layout
22303
22304 \end_inset
22305
22306 -codeseg.
22307 \end_layout
22308
22309 \begin_layout Itemize
22310
22311 \series bold
22312 constseg
22313 \series default
22314  <name>
22315 \begin_inset LatexCommand \index{\#pragma constseg}
22316
22317 \end_inset
22318
22319 - Use this name (max.
22320  8 characters) for the const segment.
22321  See option -
22322 \begin_inset ERT
22323 status collapsed
22324
22325 \begin_layout Standard
22326
22327
22328 \backslash
22329 /
22330 \end_layout
22331
22332 \end_inset
22333
22334 -constseg.
22335 \end_layout
22336
22337 \begin_layout Standard
22338 The preprocessor SDCPP
22339 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22340
22341 \end_inset
22342
22343  supports the following #pragma directives:
22344 \end_layout
22345
22346 \begin_layout Itemize
22347
22348 \series bold
22349 pedantic_parse_number
22350 \series default
22351
22352 \begin_inset LatexCommand \index{pedantic}
22353
22354 \end_inset
22355
22356
22357 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22358
22359 \end_inset
22360
22361  (+ | -) 
22362 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22363
22364 \end_inset
22365
22366 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22367  properly and the macro LO_B(3) gets expanded.
22368  Default is off.
22369  See also the -
22370 \begin_inset ERT
22371 status collapsed
22372
22373 \begin_layout Standard
22374
22375
22376 \backslash
22377 /
22378 \end_layout
22379
22380 \end_inset
22381
22382 -pedantic-parse-number command line option 
22383 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22384
22385 \end_inset
22386
22387 .
22388  
22389 \newline
22390 Below is an example on how to use this pragma.
22391
22392 \emph on
22393  Note: this functionality is not in conformance with standard!
22394 \end_layout
22395
22396 \begin_layout Verse
22397
22398 \family typewriter
22399 #pragma pedantic_parse_number +
22400 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22401
22402 \end_inset
22403
22404
22405 \newline
22406
22407 \newline
22408 #define LO_B(x) ((x) & 0xff)
22409 \newline
22410
22411 \newline
22412 unsigned char foo(void)
22413 \newline
22414 {
22415 \newline
22416 \InsetSpace ~
22417 \InsetSpace ~
22418 \InsetSpace ~
22419 unsigned char c=0xfe-LO_B(3)
22420 ;
22421 \newline
22422
22423 \newline
22424 \InsetSpace ~
22425 \InsetSpace ~
22426 \InsetSpace ~
22427 return c;
22428 \newline
22429 }
22430 \newline
22431
22432 \end_layout
22433
22434 \begin_layout Itemize
22435
22436 \series bold
22437 preproc_asm
22438 \series default
22439
22440 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22441
22442 \end_inset
22443
22444  (+ | -) - switch _asm _endasm block preprocessing on / off.
22445  Default is on.
22446  You use this prama to define multilines of assembly code.
22447  This will prevent the preprocessor from changing the formating required
22448  by assembly code.
22449  Below is an example on how to use this pragma.
22450 \end_layout
22451
22452 \begin_layout Verse
22453
22454 \family typewriter
22455 #pragma preproc_asm -
22456 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22457
22458 \end_inset
22459
22460
22461 \newline
22462 #define MYDELAY _asm
22463 \newline
22464 \InsetSpace ~
22465 \InsetSpace ~
22466 \InsetSpace ~
22467 nop ;my assembly comment...
22468 \newline
22469 \InsetSpace ~
22470 \InsetSpace ~
22471 \InsetSpace ~
22472 nop
22473 \newline
22474 \InsetSpace ~
22475 \InsetSpace ~
22476 \InsetSpace ~
22477 nop
22478 \newline
22479 _endasm
22480 \newline
22481 #pragma preproc_asm
22482  +
22483 \newline
22484
22485 \newline
22486 void foo (void) 
22487 \newline
22488
22489 \newline
22490 \InsetSpace ~
22491 \InsetSpace ~
22492 \InsetSpace ~
22493  ...
22494  
22495 \newline
22496 \InsetSpace ~
22497 \InsetSpace ~
22498 \InsetSpace ~
22499  MYDELAY;
22500 \newline
22501 \InsetSpace ~
22502 \InsetSpace ~
22503 \InsetSpace ~
22504  ...
22505  
22506 \newline
22507
22508 \newline
22509
22510 \end_layout
22511
22512 \begin_layout Itemize
22513
22514 \series bold
22515 sdcc_hash
22516 \series default
22517
22518 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22519
22520 \end_inset
22521
22522  (+ | -) - Allow "naked" hash in macro definition, for example:
22523 \newline
22524
22525 \family typewriter
22526 #define DIR_LO(x) #(x & 0xff)
22527 \family default
22528
22529 \newline
22530 Default is off.
22531  Below is an example on how to use this pragma.
22532 \end_layout
22533
22534 \begin_layout Verse
22535
22536 \family typewriter
22537 #pragma preproc_asm +
22538 \newline
22539 #pragma sdcc_hash +
22540 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22541
22542 \end_inset
22543
22544
22545 \newline
22546
22547 \newline
22548 #define ROMCALL(x) 
22549 \backslash
22550
22551 \newline
22552 \InsetSpace ~
22553 \InsetSpace ~
22554 \InsetSpace ~
22555 mov R6_B3, #(x & 0xff) 
22556 \backslash
22557
22558 \newline
22559 \InsetSpace ~
22560 \InsetSpace ~
22561 \InsetSpace ~
22562 mov R7_B3, #((x >> 8) & 0xff) 
22563 \backslash
22564
22565 \newline
22566 \InsetSpace ~
22567 \InsetSpace ~
22568 \InsetSpace ~
22569 lcall __romcall
22570 \newline
22571
22572 \newline
22573 ...
22574 \newline
22575 _asm
22576 \newline
22577 ROMCALL(72)
22578 \newline
22579 _endasm;
22580 \newline
22581 ...
22582 \newline
22583
22584 \end_layout
22585
22586 \begin_layout Standard
22587 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22588 ons which might cause the compiler to generate extra stack and/or data space
22589  to store compiler generated temporary variables.
22590  This usually happens in large functions.
22591  Pragma directives should be used as shown in the following example, they
22592  are used to control options and optimizations for a given function.
22593  
22594 \end_layout
22595
22596 \begin_layout Verse
22597
22598 \family typewriter
22599 #pragma save
22600 \begin_inset LatexCommand \index{\#pragma save}
22601
22602 \end_inset
22603
22604  \InsetSpace ~
22605 \InsetSpace ~
22606 \InsetSpace ~
22607 \InsetSpace ~
22608 \InsetSpace ~
22609 \InsetSpace ~
22610 \InsetSpace ~
22611 /* save the current settings */ 
22612 \newline
22613 #pragma nogcse
22614 \begin_inset LatexCommand \index{\#pragma nogcse}
22615
22616 \end_inset
22617
22618  \InsetSpace ~
22619 \InsetSpace ~
22620 \InsetSpace ~
22621 \InsetSpace ~
22622 \InsetSpace ~
22623 /* turnoff global subexpression elimination */ 
22624 \newline
22625 #pragma noinduction
22626 \begin_inset LatexCommand \index{\#pragma noinduction}
22627
22628 \end_inset
22629
22630  /* turn off induction optimizations */ 
22631 \newline
22632 int foo () 
22633 \newline
22634
22635 \newline
22636 \InsetSpace ~
22637  \InsetSpace ~
22638  ...
22639  
22640 \newline
22641 \InsetSpace ~
22642  \InsetSpace ~
22643  /* large code */ 
22644 \newline
22645 \InsetSpace ~
22646  \InsetSpace ~
22647  ...
22648  
22649 \newline
22650
22651 \newline
22652 #pragma restore
22653 \begin_inset LatexCommand \index{\#pragma restore}
22654
22655 \end_inset
22656
22657  /* turn the optimizations back on */
22658 \end_layout
22659
22660 \begin_layout Standard
22661 The compiler will generate a warning message when extra space is allocated.
22662  It is strongly recommended that the save and restore pragmas be used when
22663  changing options for a function.
22664 \newline
22665
22666 \newline
22667
22668 \newline
22669
22670 \end_layout
22671
22672 \begin_layout Section
22673 Defines Created by the Compiler
22674 \end_layout
22675
22676 \begin_layout Standard
22677 The compiler creates the following #defines
22678 \begin_inset LatexCommand \index{\#defines}
22679
22680 \end_inset
22681
22682
22683 \begin_inset LatexCommand \index{Defines created by the compiler}
22684
22685 \end_inset
22686
22687 :
22688 \newline
22689
22690 \end_layout
22691
22692 \begin_layout Standard
22693 \begin_inset Tabular
22694 <lyxtabular version="3" rows="15" columns="2">
22695 <features>
22696 <column alignment="left" valignment="top" leftline="true" width="3in">
22697 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22698 <row topline="true" bottomline="true">
22699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22700 \begin_inset Text
22701
22702 \begin_layout Standard
22703
22704 \series bold
22705 #define
22706 \end_layout
22707
22708 \end_inset
22709 </cell>
22710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22711 \begin_inset Text
22712
22713 \begin_layout Standard
22714
22715 \series bold
22716 Description
22717 \end_layout
22718
22719 \end_inset
22720 </cell>
22721 </row>
22722 <row topline="true">
22723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22724 \begin_inset Text
22725
22726 \begin_layout Standard
22727 SDCC
22728 \begin_inset LatexCommand \index{SDCC}
22729
22730 \end_inset
22731
22732  
22733 \end_layout
22734
22735 \end_inset
22736 </cell>
22737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22738 \begin_inset Text
22739
22740 \begin_layout Standard
22741 Always defined.
22742  Since version 2.5.6 the version number as an int (ex.
22743  256)
22744 \end_layout
22745
22746 \end_inset
22747 </cell>
22748 </row>
22749 <row topline="true">
22750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22751 \begin_inset Text
22752
22753 \begin_layout Standard
22754 SDCC_mcs51
22755 \begin_inset LatexCommand \index{SDCC\_mcs51}
22756
22757 \end_inset
22758
22759  or SDCC_ds390
22760 \begin_inset LatexCommand \index{SDCC\_ds390}
22761
22762 \end_inset
22763
22764  or SDCC_z80
22765 \begin_inset LatexCommand \index{SDCC\_z80}
22766
22767 \end_inset
22768
22769 , etc.
22770 \end_layout
22771
22772 \end_inset
22773 </cell>
22774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22775 \begin_inset Text
22776
22777 \begin_layout Standard
22778 depending on the model used (e.g.: -mds390)
22779 \end_layout
22780
22781 \end_inset
22782 </cell>
22783 </row>
22784 <row topline="true">
22785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22786 \begin_inset Text
22787
22788 \begin_layout Standard
22789 __mcs51
22790 \begin_inset LatexCommand \index{\_\_mcs51}
22791
22792 \end_inset
22793
22794 , __ds390
22795 \begin_inset LatexCommand \index{\_\_ds390}
22796
22797 \end_inset
22798
22799 , __hc08
22800 \begin_inset LatexCommand \index{\_\_hc08}
22801
22802 \end_inset
22803
22804 , __z80
22805 \begin_inset LatexCommand \index{\_\_z80}
22806
22807 \end_inset
22808
22809 , etc
22810 \end_layout
22811
22812 \end_inset
22813 </cell>
22814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22815 \begin_inset Text
22816
22817 \begin_layout Standard
22818 depending on the model used (e.g.
22819  -mz80)
22820 \end_layout
22821
22822 \end_inset
22823 </cell>
22824 </row>
22825 <row topline="true">
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22827 \begin_inset Text
22828
22829 \begin_layout Standard
22830 SDCC_STACK_AUTO
22831 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22832
22833 \end_inset
22834
22835
22836 \end_layout
22837
22838 \end_inset
22839 </cell>
22840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22841 \begin_inset Text
22842
22843 \begin_layout Standard
22844 when 
22845 \emph on
22846 -
22847 \begin_inset ERT
22848 status collapsed
22849
22850 \begin_layout Standard
22851
22852
22853 \backslash
22854 /
22855 \end_layout
22856
22857 \end_inset
22858
22859 -stack-auto
22860 \emph default
22861  option is used
22862 \end_layout
22863
22864 \end_inset
22865 </cell>
22866 </row>
22867 <row topline="true">
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22869 \begin_inset Text
22870
22871 \begin_layout Standard
22872 SDCC_MODEL_SMALL
22873 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22874
22875 \end_inset
22876
22877
22878 \end_layout
22879
22880 \end_inset
22881 </cell>
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22883 \begin_inset Text
22884
22885 \begin_layout Standard
22886 when 
22887 \emph on
22888 -
22889 \begin_inset ERT
22890 status collapsed
22891
22892 \begin_layout Standard
22893
22894
22895 \backslash
22896 /
22897 \end_layout
22898
22899 \end_inset
22900
22901 -model-small
22902 \emph default
22903  is used
22904 \end_layout
22905
22906 \end_inset
22907 </cell>
22908 </row>
22909 <row topline="true">
22910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22911 \begin_inset Text
22912
22913 \begin_layout Standard
22914 SDCC_MODEL_MEDIUM
22915 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22916
22917 \end_inset
22918
22919
22920 \end_layout
22921
22922 \end_inset
22923 </cell>
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22925 \begin_inset Text
22926
22927 \begin_layout Standard
22928 when 
22929 \emph on
22930 -
22931 \begin_inset ERT
22932 status collapsed
22933
22934 \begin_layout Standard
22935
22936
22937 \backslash
22938 /
22939 \end_layout
22940
22941 \end_inset
22942
22943 -model-medium
22944 \emph default
22945  is used
22946 \end_layout
22947
22948 \end_inset
22949 </cell>
22950 </row>
22951 <row topline="true">
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22953 \begin_inset Text
22954
22955 \begin_layout Standard
22956 SDCC_MODEL_LARGE
22957 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22958
22959 \end_inset
22960
22961
22962 \end_layout
22963
22964 \end_inset
22965 </cell>
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22967 \begin_inset Text
22968
22969 \begin_layout Standard
22970 when 
22971 \emph on
22972 -
22973 \begin_inset ERT
22974 status collapsed
22975
22976 \begin_layout Standard
22977
22978
22979 \backslash
22980 /
22981 \end_layout
22982
22983 \end_inset
22984
22985 -model-large
22986 \emph default
22987  is used
22988 \end_layout
22989
22990 \end_inset
22991 </cell>
22992 </row>
22993 <row topline="true">
22994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22995 \begin_inset Text
22996
22997 \begin_layout Standard
22998 SDCC_USE_XSTACK
22999 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23000
23001 \end_inset
23002
23003
23004 \end_layout
23005
23006 \end_inset
23007 </cell>
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 when 
23013 \emph on
23014 -
23015 \begin_inset ERT
23016 status collapsed
23017
23018 \begin_layout Standard
23019
23020
23021 \backslash
23022 /
23023 \end_layout
23024
23025 \end_inset
23026
23027 -xstack
23028 \emph default
23029  option is used
23030 \end_layout
23031
23032 \end_inset
23033 </cell>
23034 </row>
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23037 \begin_inset Text
23038
23039 \begin_layout Standard
23040 SDCC_STACK_TENBIT
23041 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23042
23043 \end_inset
23044
23045  
23046 \end_layout
23047
23048 \end_inset
23049 </cell>
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \begin_layout Standard
23054 when 
23055 \emph on
23056 -mds390
23057 \emph default
23058  is used
23059 \end_layout
23060
23061 \end_inset
23062 </cell>
23063 </row>
23064 <row topline="true">
23065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23066 \begin_inset Text
23067
23068 \begin_layout Standard
23069 SDCC_MODEL_FLAT24
23070 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23071
23072 \end_inset
23073
23074
23075 \end_layout
23076
23077 \end_inset
23078 </cell>
23079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23080 \begin_inset Text
23081
23082 \begin_layout Standard
23083 when 
23084 \emph on
23085 -mds390
23086 \emph default
23087  is used
23088 \end_layout
23089
23090 \end_inset
23091 </cell>
23092 </row>
23093 <row topline="true">
23094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 \begin_inset Text
23096
23097 \begin_layout Standard
23098 SDCC_REVISION
23099 \begin_inset LatexCommand \index{SDCC\_REVISION}
23100
23101 \end_inset
23102
23103
23104 \end_layout
23105
23106 \end_inset
23107 </cell>
23108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23109 \begin_inset Text
23110
23111 \begin_layout Standard
23112 Always defined.
23113  SDCC revision number
23114 \end_layout
23115
23116 \end_inset
23117 </cell>
23118 </row>
23119 <row topline="true">
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23121 \begin_inset Text
23122
23123 \begin_layout Standard
23124 SDCC_PARMS_IN_BANK1
23125 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23126
23127 \end_inset
23128
23129
23130 \end_layout
23131
23132 \end_inset
23133 </cell>
23134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23135 \begin_inset Text
23136
23137 \begin_layout Standard
23138 when 
23139 \emph on
23140 -
23141 \begin_inset ERT
23142 status collapsed
23143
23144 \begin_layout Standard
23145
23146
23147 \backslash
23148 /
23149 \end_layout
23150
23151 \end_inset
23152
23153 -parms-in-bank1
23154 \emph default
23155  is used
23156 \end_layout
23157
23158 \end_inset
23159 </cell>
23160 </row>
23161 <row topline="true">
23162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23163 \begin_inset Text
23164
23165 \begin_layout Standard
23166 SDCC_FLOAT_REENT
23167 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23168
23169 \end_inset
23170
23171
23172 \end_layout
23173
23174 \end_inset
23175 </cell>
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 when 
23181 \emph on
23182 -
23183 \begin_inset ERT
23184 status collapsed
23185
23186 \begin_layout Standard
23187
23188
23189 \backslash
23190 /
23191 \end_layout
23192
23193 \end_inset
23194
23195 -float-reent
23196 \emph default
23197  is used
23198 \end_layout
23199
23200 \end_inset
23201 </cell>
23202 </row>
23203 <row topline="true" bottomline="true">
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23205 \begin_inset Text
23206
23207 \begin_layout Standard
23208 SDCC_INT_LONG_REENT
23209 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23210
23211 \end_inset
23212
23213
23214 \end_layout
23215
23216 \end_inset
23217 </cell>
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23219 \begin_inset Text
23220
23221 \begin_layout Standard
23222 when 
23223 \emph on
23224 -
23225 \begin_inset ERT
23226 status collapsed
23227
23228 \begin_layout Standard
23229
23230
23231 \backslash
23232 /
23233 \end_layout
23234
23235 \end_inset
23236
23237 -int-long-reent
23238 \emph default
23239  is used
23240 \end_layout
23241
23242 \end_inset
23243 </cell>
23244 </row>
23245 </lyxtabular>
23246
23247 \end_inset
23248
23249
23250 \end_layout
23251
23252 \begin_layout Chapter
23253 Notes on supported Processors
23254 \end_layout
23255
23256 \begin_layout Section
23257 MCS51 variants
23258 \begin_inset LatexCommand \label{sub:MCS51-variants}
23259
23260 \end_inset
23261
23262
23263 \begin_inset LatexCommand \index{MCS51 variants}
23264
23265 \end_inset
23266
23267
23268 \end_layout
23269
23270 \begin_layout Standard
23271 MCS51 processors are available from many vendors and come in many different
23272  flavours.
23273  While they might differ considerably in respect to Special Function Registers
23274  the core MCS51 is usually not modified or is kept compatible.
23275  
23276 \end_layout
23277
23278 \begin_layout Subsection
23279 pdata access by SFR 
23280 \end_layout
23281
23282 \begin_layout Standard
23283 With the upcome of devices with internal xdata and flash memory devices
23284  using port P2
23285 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23286
23287 \end_inset
23288
23289  as dedicated I/O port is becoming more popular.
23290  Switching the high byte for pdata
23291 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23292
23293 \end_inset
23294
23295  access which was formerly done by port P2 is then achieved by a Special
23296  Function Register
23297 \begin_inset LatexCommand \index{sfr}
23298
23299 \end_inset
23300
23301 .
23302  In well-established MCS51 tradition the address of this 
23303 \emph on
23304 sfr
23305 \emph default
23306  is where the chip designers decided to put it.
23307  Needless to say that they didn't agree on a common name either.
23308  So that the startup code can correctly initialize xdata variables, you
23309  should define an sfr with the name _XPAGE
23310 \family typewriter
23311
23312 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23313
23314 \end_inset
23315
23316
23317 \family default
23318  at the appropriate location if the default, port P2, is not used for this.
23319  Some examples are:
23320 \end_layout
23321
23322 \begin_layout Verse
23323
23324 \family typewriter
23325 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23326  MPAGE */
23327 \end_layout
23328
23329 \begin_layout Verse
23330
23331 \family typewriter
23332 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23333  a.k.a.
23334  MPAGE */
23335 \end_layout
23336
23337 \begin_layout Verse
23338
23339 \family typewriter
23340 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23341  XPAGE */
23342 \end_layout
23343
23344 \begin_layout Verse
23345
23346 \family typewriter
23347 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23348  EMI0CN */
23349 \end_layout
23350
23351 \begin_layout Verse
23352
23353 \family typewriter
23354 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23355  EMI0CN */
23356 \end_layout
23357
23358 \begin_layout Standard
23359 For more exotic implementations further customizations may be needed.
23360  See section 
23361 \begin_inset LatexCommand \ref{sub:Startup-Code}
23362
23363 \end_inset
23364
23365  for other possibilities.
23366 \end_layout
23367
23368 \begin_layout Subsection
23369 Other Features available by SFR
23370 \end_layout
23371
23372 \begin_layout Standard
23373 Some MCS51 variants offer features like Double DPTR
23374 \begin_inset LatexCommand \index{DPTR}
23375
23376 \end_inset
23377
23378 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23379  These are currently not used for the MCS51 port.
23380  If you absolutely need them you can fall back to inline assembly or submit
23381  a patch to SDCC.
23382 \begin_inset VSpace bigskip
23383 \end_inset
23384
23385
23386 \end_layout
23387
23388 \begin_layout Section
23389 DS400 port
23390 \end_layout
23391
23392 \begin_layout Standard
23393 The DS80C400
23394 \begin_inset LatexCommand \index{DS80C400}
23395
23396 \end_inset
23397
23398
23399 \begin_inset LatexCommand \index{DS400}
23400
23401 \end_inset
23402
23403  microcontroller has a rich set of peripherals.
23404  In its built-in ROM library it includes functions to access some of the
23405  features, among them is a TCP stack with IP4 and IP6 support.
23406  Library headers (currently in beta status) and other files are provided
23407  at 
23408 \size footnotesize
23409
23410 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23411
23412 \end_inset
23413
23414 .
23415  
23416 \begin_inset VSpace bigskip
23417 \end_inset
23418
23419
23420 \end_layout
23421
23422 \begin_layout Section
23423 The Z80 and gbz80 port
23424 \end_layout
23425
23426 \begin_layout Standard
23427 SDCC can target both the Zilog Z80
23428 \begin_inset LatexCommand \index{Z80}
23429
23430 \end_inset
23431
23432  and the Nintendo Gameboy's Z80-like gbz80
23433 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23434
23435 \end_inset
23436
23437 .
23438  The Z80 port is passed through the same 
23439 \emph on
23440 regressions tests
23441 \begin_inset LatexCommand \index{Regression test}
23442
23443 \end_inset
23444
23445
23446 \emph default
23447  (see section 
23448 \begin_inset LatexCommand \ref{sec:Quality-control}
23449
23450 \end_inset
23451
23452 ) as the MCS51 and DS390 ports, so floating point support, support for long
23453  variables and bitfield support is fine.
23454  See mailing lists and forums about interrupt routines.
23455 \end_layout
23456
23457 \begin_layout Standard
23458 As always, the code is the authoritative reference - see z80/ralloc.c and
23459  z80/gen.c.
23460  The stack
23461 \begin_inset LatexCommand \index{Z80!stack}
23462
23463 \end_inset
23464
23465  frame is similar to that generated by the IAR Z80 compiler.
23466  IX is used as the base pointer, HL and IY are used as a temporary registers,
23467  and BC and DE are available for holding variables.
23468  Return values
23469 \begin_inset LatexCommand \index{Z80!return value}
23470
23471 \end_inset
23472
23473  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23474  bytes).
23475  The gbz80 port use the same set of registers for the return values, but
23476  in a different order of significance: E (one byte), DE (two bytes), or
23477  HLDE (four bytes).
23478 \begin_inset VSpace bigskip
23479 \end_inset
23480
23481
23482 \end_layout
23483
23484 \begin_layout Section
23485 The HC08 port
23486 \end_layout
23487
23488 \begin_layout Standard
23489 The port to the Freescale/Motorola HC08
23490 \begin_inset LatexCommand \index{HC08}
23491
23492 \end_inset
23493
23494  family has been added in October 2003, and is still undergoing some basic
23495  development.
23496  The code generator is complete, but the register allocation is still quite
23497  unoptimized.
23498  Some of the SDCC's standard C library functions have embedded non-HC08
23499  inline assembly and so are not yet usable.
23500 \end_layout
23501
23502 \begin_layout Standard
23503 The HC08 port passes the regression test suite (see section 
23504 \begin_inset LatexCommand \ref{sec:Quality-control}
23505
23506 \end_inset
23507
23508 ).
23509 \begin_inset VSpace bigskip
23510 \end_inset
23511
23512
23513 \newpage
23514
23515 \end_layout
23516
23517 \begin_layout Section
23518 The PIC14
23519 \begin_inset LatexCommand \index{PIC14}
23520
23521 \end_inset
23522
23523  port
23524 \end_layout
23525
23526 \begin_layout Standard
23527 The PIC14 port adds support for Microchip
23528 \begin_inset LatexCommand \index{Microchip}
23529
23530 \end_inset
23531
23532
23533 \begin_inset Formula $^{\text{TM}}$
23534 \end_inset
23535
23536  PIC
23537 \begin_inset LatexCommand \index{PIC14}
23538
23539 \end_inset
23540
23541
23542 \begin_inset Formula $^{\text{TM}}$
23543 \end_inset
23544
23545  MCUs with 14 bit wide instructions.
23546  This port is not yet mature and still lacks many features.
23547  However, it can work for simple code.
23548 \end_layout
23549
23550 \begin_layout Standard
23551 Currently supported devices include:
23552 \end_layout
23553
23554 \begin_layout Standard
23555 12F: 629, 635, 675, 683
23556 \end_layout
23557
23558 \begin_layout Standard
23559 16C: 432, 433
23560 \end_layout
23561
23562 \begin_layout Standard
23563 16C: 554, 557, 558
23564 \end_layout
23565
23566 \begin_layout Standard
23567 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23568 \end_layout
23569
23570 \begin_layout Standard
23571 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23572  781, 782
23573 \end_layout
23574
23575 \begin_layout Standard
23576 16C: 925, 926
23577 \end_layout
23578
23579 \begin_layout Standard
23580 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23581  689, 690
23582 \end_layout
23583
23584 \begin_layout Standard
23585 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23586 \end_layout
23587
23588 \begin_layout Standard
23589 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23590  877, 877a, 88
23591 \end_layout
23592
23593 \begin_layout Standard
23594 16F: 913, 914, 916, 917
23595 \end_layout
23596
23597 \begin_layout Standard
23598 An up-to-date list of currently supported devices can be obtained via 
23599 \family typewriter
23600 sdcc -mpic14 -phelp foo.c
23601 \family default
23602  (foo.c must exist...).
23603 \end_layout
23604
23605 \begin_layout Subsection
23606 PIC Code Pages
23607 \begin_inset LatexCommand \index{code page (pic14)}
23608
23609 \end_inset
23610
23611  and Memory Banks
23612 \begin_inset LatexCommand \index{Memory bank (pic14)}
23613
23614 \end_inset
23615
23616
23617 \end_layout
23618
23619 \begin_layout Standard
23620 The linker organizes allocation for the code page and RAM banks.
23621  It does not have intimate knowledge of the code flow.
23622  It will put all the code section of a single .asm file into a single code
23623  page.
23624  In order to make use of multiple code pages, separate asm files must be
23625  used.
23626  The compiler assigns all 
23627 \emph on
23628 static
23629 \emph default
23630  functions of a single .c file into the same code page.
23631 \newline
23632
23633 \newline
23634 To get the best results,
23635  follow these guidelines:
23636 \end_layout
23637
23638 \begin_layout Enumerate
23639 Make local functions static, as non static functions require code page selection
23640  overhead.
23641 \newline
23642 Due to the way sdcc handles functions, place called functions prior
23643  to calling functions in the file wherever possible: Otherwise sdcc will
23644  insert unneccessary pagesel directives around the call, believing that
23645  the called function is externally defined.
23646 \end_layout
23647
23648 \begin_layout Enumerate
23649 For devices that have multiple code pages it is more efficient to use the
23650  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23651  but only 2 files for the 16F874.
23652  This way the linker can put the code for each file into different code
23653  pages and there will be less page selection overhead.
23654 \end_layout
23655
23656 \begin_layout Enumerate
23657 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23658  instruction set), use `unsigned char' wherever possible instead of `int'.
23659 \end_layout
23660
23661 \begin_layout Subsection
23662 Adding New Devices to the Port 
23663 \end_layout
23664
23665 \begin_layout Standard
23666 Adding support for a new 14
23667 \begin_inset ERT
23668 status open
23669
23670 \begin_layout Standard
23671
23672
23673 \backslash
23674 ,
23675 \end_layout
23676
23677 \end_inset
23678
23679 bit PIC MCU requires the following steps:
23680 \end_layout
23681
23682 \begin_layout Enumerate
23683 Create a new device description.
23684 \newline
23685 Each device is described in two files: pic16f*.h
23686  and pic16f*.c.
23687  These files primarily define SFRs, structs to access their bits, and symbolic
23688  configuration options.
23689  Both files can be generated from gputils' .inc files using the perl script
23690  
23691 \family typewriter
23692 support/scripts/inc2h.pl
23693 \family default
23694 .
23695  This file also contains further instructions on how to proceed.
23696 \end_layout
23697
23698 \begin_layout Enumerate
23699 Copy the .h file into SDCC's include path and either add the .c file to your
23700  project or copy it to 
23701 \family typewriter
23702 device/lib/pic/libdev
23703 \family default
23704 .
23705  Afterwards, rebuild and install the libraries.
23706 \end_layout
23707
23708 \begin_layout Enumerate
23709 Edit pic14devices.txt in SDCC's include path (
23710 \family typewriter
23711 device/include/pic/
23712 \family default
23713  in the source tree or 
23714 \family typewriter
23715 /usr/local/share/sdcc/include/pic
23716 \family default
23717  after installation).
23718 \newline
23719 You need to add a device specification here to make
23720  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23721  the compiler.
23722  Probably you can copy and modify an existing entry.
23723  The file format is documented at the top of the file.
23724 \end_layout
23725
23726 \begin_layout Subsection
23727 Interrupt Code
23728 \end_layout
23729
23730 \begin_layout Standard
23731 For the interrupt function, use the keyword `__interrupt'
23732 \begin_inset LatexCommand \index{PIC14!interrupt}
23733
23734 \end_inset
23735
23736  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23737  there to avoid a syntax error - it ought to be fixed).
23738  E.g.:
23739 \end_layout
23740
23741 \begin_layout Verse
23742
23743 \family typewriter
23744 void Intr(void) __interrupt 0
23745 \newline
23746 {
23747 \newline
23748 \InsetSpace ~
23749 \InsetSpace ~
23750 T0IF = 0; /* Clear timer interrupt */
23751 \newline
23752 }
23753 \end_layout
23754
23755 \begin_layout Subsection
23756 Linking and Assembling
23757 \end_layout
23758
23759 \begin_layout Standard
23760 For assembling you can use either GPUTILS'
23761 \begin_inset LatexCommand \index{gputils (pic tools)}
23762
23763 \end_inset
23764
23765  gpasm.exe or MPLAB's mpasmwin.exe.
23766  GPUTILS are available from 
23767 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23768
23769 \end_inset
23770
23771 .
23772  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23773  If you use MPLAB and an interrupt function then the linker script file
23774  vectors section will need to be enlarged to link with mplink.
23775 \newline
23776
23777 \newline
23778 Here is a 
23779 \family typewriter
23780 Makefile
23781 \family default
23782  using GPUTILS:
23783 \end_layout
23784
23785 \begin_layout Verse
23786
23787 \family typewriter
23788 .c.o:
23789 \newline
23790 \InsetSpace ~
23791 \InsetSpace ~
23792 \InsetSpace ~
23793 \InsetSpace ~
23794 \InsetSpace ~
23795 \InsetSpace ~
23796 \InsetSpace ~
23797 \InsetSpace ~
23798 sdcc -V -mpic14 -p16f877 -c $< 
23799 \newline
23800
23801 \newline
23802 $(PRJ).hex: $(OBJS) 
23803 \newline
23804 \InsetSpace ~
23805 \InsetSpace ~
23806 \InsetSpace ~
23807 \InsetSpace ~
23808 \InsetSpace ~
23809 \InsetSpace ~
23810 \InsetSpace ~
23811 \InsetSpace ~
23812 gplink -m -s $(PRJ).lkr
23813  -o $(PRJ).hex $(OBJS) libsdcc.lib
23814 \end_layout
23815
23816 \begin_layout Standard
23817 Here is a 
23818 \family typewriter
23819 Makefile
23820 \family default
23821  using MPLAB:
23822 \end_layout
23823
23824 \begin_layout Verse
23825
23826 \family typewriter
23827 .c.o: 
23828 \newline
23829 \InsetSpace ~
23830 \InsetSpace ~
23831 \InsetSpace ~
23832 \InsetSpace ~
23833 \InsetSpace ~
23834 \InsetSpace ~
23835 \InsetSpace ~
23836 \InsetSpace ~
23837 sdcc -S -V -mpic14 -p16f877 $< 
23838 \newline
23839 \InsetSpace ~
23840 \InsetSpace ~
23841 \InsetSpace ~
23842 \InsetSpace ~
23843 \InsetSpace ~
23844 \InsetSpace ~
23845 \InsetSpace ~
23846 \InsetSpace ~
23847 mpasmwin /q /o $*.asm
23848 \newline
23849
23850 \newline
23851 $(PRJ).hex: $(OBJS)
23852  
23853 \newline
23854 \InsetSpace ~
23855 \InsetSpace ~
23856 \InsetSpace ~
23857 \InsetSpace ~
23858 \InsetSpace ~
23859 \InsetSpace ~
23860 \InsetSpace ~
23861 \InsetSpace ~
23862 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23863 \end_layout
23864
23865 \begin_layout Standard
23866 Please note that indentations within a
23867 \family typewriter
23868  Makefile
23869 \family default
23870  have to be done with a tabulator character.
23871 \end_layout
23872
23873 \begin_layout Subsection
23874 Command-Line Options
23875 \end_layout
23876
23877 \begin_layout Standard
23878 Besides the switches common to all SDCC backends, the PIC14 port accepts
23879  the following options (for an updated list see sdcc -
23880 \begin_inset ERT
23881 status collapsed
23882
23883 \begin_layout Standard
23884
23885
23886 \backslash
23887 /
23888 \end_layout
23889
23890 \end_inset
23891
23892 -help):
23893 \end_layout
23894
23895 \begin_layout Description
23896 -
23897 \begin_inset ERT
23898 status collapsed
23899
23900 \begin_layout Standard
23901
23902
23903 \backslash
23904 /
23905 \end_layout
23906
23907 \end_inset
23908
23909 -debug-xtra
23910 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23911
23912 \end_inset
23913
23914  emit debug info in assembly output
23915 \end_layout
23916
23917 \begin_layout Description
23918 -
23919 \begin_inset ERT
23920 status collapsed
23921
23922 \begin_layout Standard
23923
23924
23925 \backslash
23926 /
23927 \end_layout
23928
23929 \end_inset
23930
23931 -no-pcode-opt
23932 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23933
23934 \end_inset
23935
23936  disable (slightly faulty) optimization on pCode
23937 \end_layout
23938
23939 \begin_layout Description
23940 -
23941 \begin_inset ERT
23942 status collapsed
23943
23944 \begin_layout Standard
23945
23946
23947 \backslash
23948 /
23949 \end_layout
23950
23951 \end_inset
23952
23953 -stack-loc
23954 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23955
23956 \end_inset
23957
23958  sets the lowest address of the argument passing stack (defaults to a suitably
23959  large shared databank to reduce BANKSEL overhead)
23960 \end_layout
23961
23962 \begin_layout Description
23963 -
23964 \begin_inset ERT
23965 status collapsed
23966
23967 \begin_layout Standard
23968
23969
23970 \backslash
23971 /
23972 \end_layout
23973
23974 \end_inset
23975
23976 -stack-size
23977 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23978
23979 \end_inset
23980
23981  sets the size if the argument passing stack (default: 16, minimum: 4)
23982 \end_layout
23983
23984 \begin_layout Subsection
23985 Environment Variables
23986 \end_layout
23987
23988 \begin_layout Standard
23989 The PIC14 port recognizes the following environment variables:
23990 \end_layout
23991
23992 \begin_layout Description
23993 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23994  register (the ones called r0xNNNN) in a section of its own.
23995  By default (if this variable is unset), sdcc tries to cluster registers
23996  in sections in order to reduce the BANKSEL overhead when accessing them.
23997 \end_layout
23998
23999 \begin_layout Subsection
24000 The Library
24001 \end_layout
24002
24003 \begin_layout Standard
24004 The PIC14 library currently only contains support routines required by the
24005  compiler to implement multiplication, division, and floating point support.
24006  No libc-like replacement is available at the moment, though many of the
24007  common sdcc library sources (in 
24008 \family typewriter
24009 device/lib
24010 \family default
24011 ) should also compile with the PIC14 port.
24012 \end_layout
24013
24014 \begin_layout Subsubsection
24015 error: missing definition for symbol ``__gptrget1''
24016 \end_layout
24017
24018 \begin_layout Standard
24019 The PIC14 port uses library routines to provide more complex operations
24020  like multiplication, division/modulus and (generic) pointer dereferencing.
24021  In order to add these routines to your project, you must link with PIC14's
24022  
24023 \family typewriter
24024 libsdcc.lib
24025 \family default
24026 .
24027  For single source file projects this is done automatically, more complex
24028  projects must add 
24029 \family typewriter
24030 libsdcc.lib
24031 \family default
24032  to the linker's arguments.
24033  Make sure you also add an include path for the library (using the -I switch
24034  to the linker)!
24035 \end_layout
24036
24037 \begin_layout Subsubsection
24038 Processor mismatch in file ``XXX''.
24039 \end_layout
24040
24041 \begin_layout Standard
24042 This warning can usually be ignored due to the very good compatibility amongst
24043  14
24044 \begin_inset ERT
24045 status open
24046
24047 \begin_layout Standard
24048
24049
24050 \backslash
24051 ,
24052 \end_layout
24053
24054 \end_inset
24055
24056 bit PIC
24057 \begin_inset LatexCommand \index{PIC14}
24058
24059 \end_inset
24060
24061  devices.
24062 \end_layout
24063
24064 \begin_layout Standard
24065 You might also consider recompiling the library for your specific device
24066  by changing the ARCH=p16f877 (default target) entry in 
24067 \family typewriter
24068 device/lib/pic/Makefile.in
24069 \family default
24070  and 
24071 \family typewriter
24072 device/lib/pic/Makefile
24073 \family default
24074  to reflect your device.
24075  This might even improve performance for smaller devices as unneccesary
24076  BANKSELs might be removed.
24077 \end_layout
24078
24079 \begin_layout Subsection
24080 Known Bugs
24081 \end_layout
24082
24083 \begin_layout Subsubsection
24084 Function arguments
24085 \end_layout
24086
24087 \begin_layout Standard
24088 Functions with variable argument lists (like printf) are not yet supported.
24089  Similarly, taking the argument of the first argument passed into a function
24090  does not work: It is currently passed in WREG and has no address...
24091 \end_layout
24092
24093 \begin_layout Subsubsection
24094 Regression tests fail
24095 \end_layout
24096
24097 \begin_layout Standard
24098 Though the small subset of regression tests in src/regression passes, SDCC
24099  regression test suite does not, indicating that there are still major bugs
24100  in the port.
24101  However, many smaller projects have successfully used SDCC in the past...
24102 \end_layout
24103
24104 \begin_layout Standard
24105
24106 \size footnotesize
24107
24108 \newpage
24109
24110 \end_layout
24111
24112 \begin_layout Section
24113 The PIC16
24114 \begin_inset LatexCommand \index{PIC16}
24115
24116 \end_inset
24117
24118  port
24119 \end_layout
24120
24121 \begin_layout Standard
24122 The PIC16 port adds support for Microchip
24123 \begin_inset LatexCommand \index{Microchip}
24124
24125 \end_inset
24126
24127
24128 \begin_inset Formula $^{\text{TM}}$
24129 \end_inset
24130
24131  PIC
24132 \begin_inset LatexCommand \index{PIC}
24133
24134 \end_inset
24135
24136
24137 \begin_inset Formula $^{\text{TM}}$
24138 \end_inset
24139
24140  MCUs with 16 bit wide instructions.
24141  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24142 ; devices supported by the port include:
24143 \end_layout
24144
24145 \begin_layout Standard
24146 18F: 242, 248, 252, 258, 442, 448, 452, 458
24147 \end_layout
24148
24149 \begin_layout Standard
24150 18F: 1220, 1320
24151 \end_layout
24152
24153 \begin_layout Standard
24154 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24155  2620
24156 \end_layout
24157
24158 \begin_layout Standard
24159 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24160  45j10, 4620
24161 \end_layout
24162
24163 \begin_layout Standard
24164 18F: 6520, 6620, 6680, 6720
24165 \end_layout
24166
24167 \begin_layout Standard
24168 18F: 8520, 8620, 8680, 8720
24169 \end_layout
24170
24171 \begin_layout Subsection
24172 Global Options
24173 \end_layout
24174
24175 \begin_layout Standard
24176 PIC16 port supports the standard command line arguments as supposed, with
24177  the exception of certain cases that will be mentioned in the following
24178  list:
24179 \end_layout
24180
24181 \begin_layout Description
24182 -
24183 \begin_inset ERT
24184 status collapsed
24185
24186 \begin_layout Standard
24187
24188
24189 \backslash
24190 /
24191 \end_layout
24192
24193 \end_inset
24194
24195 -callee-saves
24196 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24197
24198 \end_inset
24199
24200  See -
24201 \begin_inset ERT
24202 status collapsed
24203
24204 \begin_layout Standard
24205
24206
24207 \backslash
24208 /
24209 \end_layout
24210
24211 \end_inset
24212
24213 -all-callee-saves
24214 \end_layout
24215
24216 \begin_layout Description
24217 -
24218 \begin_inset ERT
24219 status collapsed
24220
24221 \begin_layout Standard
24222
24223
24224 \backslash
24225 /
24226 \end_layout
24227
24228 \end_inset
24229
24230 -fommit-frame-pointer
24231 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24232
24233 \end_inset
24234
24235  Frame pointer will be omitted when the function uses no local variables.
24236 \end_layout
24237
24238 \begin_layout Subsection
24239 Port Specific Options
24240 \begin_inset LatexCommand \index{Options PIC16}
24241
24242 \end_inset
24243
24244
24245 \end_layout
24246
24247 \begin_layout Standard
24248 The port specific options appear after the global options in the sdcc -
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 -help output.
24262 \end_layout
24263
24264 \begin_layout Subsubsection
24265 Code Generation Options
24266 \end_layout
24267
24268 \begin_layout Standard
24269 These options influence the generated assembler code.
24270 \end_layout
24271
24272 \begin_layout Description
24273 -
24274 \begin_inset ERT
24275 status collapsed
24276
24277 \begin_layout Standard
24278
24279
24280 \backslash
24281 /
24282 \end_layout
24283
24284 \end_inset
24285
24286 -pstack-model=[model] Used in conjuction with the command above.
24287  Defines the stack model to be used, valid stack models are:
24288 \end_layout
24289
24290 \begin_deeper
24291 \begin_layout List
24292 \labelwidthstring 00.00.0000
24293
24294 \emph on
24295 small
24296 \emph default
24297  Selects small stack model.
24298  8 bit stack and frame pointers.
24299  Supports 256 bytes stack size.
24300 \end_layout
24301
24302 \begin_layout List
24303 \labelwidthstring 00.00.0000
24304
24305 \emph on
24306 large
24307 \emph default
24308  Selects large stack model.
24309  16 bit stack and frame pointers.
24310  Supports 65536 bytes stack size.
24311 \end_layout
24312
24313 \end_deeper
24314 \begin_layout Description
24315 -
24316 \begin_inset ERT
24317 status collapsed
24318
24319 \begin_layout Standard
24320
24321
24322 \backslash
24323 /
24324 \end_layout
24325
24326 \end_inset
24327
24328 -pno-banksel Do not generate BANKSEL assembler directives.
24329 \end_layout
24330
24331 \begin_layout Description
24332 -
24333 \begin_inset ERT
24334 status collapsed
24335
24336 \begin_layout Standard
24337
24338
24339 \backslash
24340 /
24341 \end_layout
24342
24343 \end_inset
24344
24345 -extended Enable extended instruction set/literal offset addressing mode.
24346  Use with care!
24347 \end_layout
24348
24349 \begin_layout Subsubsection
24350 Optimization Options
24351 \end_layout
24352
24353 \begin_layout Description
24354 -
24355 \begin_inset ERT
24356 status collapsed
24357
24358 \begin_layout Standard
24359
24360
24361 \backslash
24362 /
24363 \end_layout
24364
24365 \end_inset
24366
24367 -obanksel=n Set optimization level for inserting BANKSELs.
24368 \newline
24369
24370 \end_layout
24371
24372 \begin_deeper
24373 \begin_layout List
24374 \labelwidthstring 00.00.0000
24375 0 no optimization
24376 \end_layout
24377
24378 \begin_layout List
24379 \labelwidthstring 00.00.0000
24380 1 checks previous used register and if it is the same then does not emit
24381  BANKSEL, accounts only for labels.
24382 \end_layout
24383
24384 \begin_layout List
24385 \labelwidthstring 00.00.0000
24386 2 tries to check the location of (even different) symbols and removes BANKSELs
24387  if they are in the same bank.
24388  
24389 \newline
24390
24391 \emph on
24392 Important: There might be problems if the linker script has data sections
24393  across bank borders!
24394 \end_layout
24395
24396 \end_deeper
24397 \begin_layout Description
24398 -
24399 \begin_inset ERT
24400 status collapsed
24401
24402 \begin_layout Standard
24403
24404
24405 \backslash
24406 /
24407 \end_layout
24408
24409 \end_inset
24410
24411 -denable-peeps Force the usage of peepholes.
24412  Use with care.
24413 \end_layout
24414
24415 \begin_layout Description
24416 -
24417 \begin_inset ERT
24418 status collapsed
24419
24420 \begin_layout Standard
24421
24422
24423 \backslash
24424 /
24425 \end_layout
24426
24427 \end_inset
24428
24429 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24430 \end_layout
24431
24432 \begin_layout Description
24433 -
24434 \begin_inset ERT
24435 status collapsed
24436
24437 \begin_layout Standard
24438
24439
24440 \backslash
24441 /
24442 \end_layout
24443
24444 \end_inset
24445
24446 -optimize-cmp Try to optimize some compares.
24447 \end_layout
24448
24449 \begin_layout Description
24450 -
24451 \begin_inset ERT
24452 status collapsed
24453
24454 \begin_layout Standard
24455
24456
24457 \backslash
24458 /
24459 \end_layout
24460
24461 \end_inset
24462
24463 -optimize-df Analyze the dataflow of the generated code and improve it.
24464 \end_layout
24465
24466 \begin_layout Subsubsection
24467 Assembling Options
24468 \end_layout
24469
24470 \begin_layout Description
24471 -
24472 \begin_inset ERT
24473 status collapsed
24474
24475 \begin_layout Standard
24476
24477
24478 \backslash
24479 /
24480 \end_layout
24481
24482 \end_inset
24483
24484 -asm= Sets the full path and name of an external assembler to call.
24485 \end_layout
24486
24487 \begin_layout Description
24488 -
24489 \begin_inset ERT
24490 status collapsed
24491
24492 \begin_layout Standard
24493
24494
24495 \backslash
24496 /
24497 \end_layout
24498
24499 \end_inset
24500
24501 -mplab-comp MPLAB
24502 \begin_inset LatexCommand \index{PIC16!MPLAB}
24503
24504 \end_inset
24505
24506  compatibility option.
24507  Currently only suppresses special gpasm directives.
24508 \end_layout
24509
24510 \begin_layout Subsubsection
24511 Linking Options
24512 \end_layout
24513
24514 \begin_layout Description
24515 -
24516 \begin_inset ERT
24517 status collapsed
24518
24519 \begin_layout Standard
24520
24521
24522 \backslash
24523 /
24524 \end_layout
24525
24526 \end_inset
24527
24528 -link= Sets the full path and name of an external linker to call.
24529 \end_layout
24530
24531 \begin_layout Description
24532 -
24533 \begin_inset ERT
24534 status collapsed
24535
24536 \begin_layout Standard
24537
24538
24539 \backslash
24540 /
24541 \end_layout
24542
24543 \end_inset
24544
24545 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24546  unitialized data variables with [kword].
24547  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24548 \end_layout
24549
24550 \begin_layout Description
24551 -
24552 \begin_inset ERT
24553 status collapsed
24554
24555 \begin_layout Standard
24556
24557
24558 \backslash
24559 /
24560 \end_layout
24561
24562 \end_inset
24563
24564 -ivt-loc=n Place the interrupt vector table at address 
24565 \emph on
24566 n
24567 \emph default
24568 .
24569  Useful for bootloaders.
24570 \end_layout
24571
24572 \begin_layout Description
24573 -
24574 \begin_inset ERT
24575 status collapsed
24576
24577 \begin_layout Standard
24578
24579
24580 \backslash
24581 /
24582 \end_layout
24583
24584 \end_inset
24585
24586 -nodefaultlibs Do not link default libraries when linking.
24587 \end_layout
24588
24589 \begin_layout Description
24590 -
24591 \begin_inset ERT
24592 status collapsed
24593
24594 \begin_layout Standard
24595
24596
24597 \backslash
24598 /
24599 \end_layout
24600
24601 \end_inset
24602
24603 -use-crt= Use a custom run-time module instead of the defaults.
24604 \end_layout
24605
24606 \begin_layout Description
24607 -
24608 \begin_inset ERT
24609 status collapsed
24610
24611 \begin_layout Standard
24612
24613
24614 \backslash
24615 /
24616 \end_layout
24617
24618 \end_inset
24619
24620 -no-crt Don't link the default run-time modules
24621 \end_layout
24622
24623 \begin_layout Subsubsection
24624 Debugging Options
24625 \end_layout
24626
24627 \begin_layout Standard
24628 Debugging options enable extra debugging information in the output files.
24629 \end_layout
24630
24631 \begin_layout Description
24632 -
24633 \begin_inset ERT
24634 status collapsed
24635
24636 \begin_layout Standard
24637
24638
24639 \backslash
24640 /
24641 \end_layout
24642
24643 \end_inset
24644
24645 -debug-xtra Similar to -
24646 \begin_inset ERT
24647 status collapsed
24648
24649 \begin_layout Standard
24650
24651
24652 \backslash
24653 /
24654 \end_layout
24655
24656 \end_inset
24657
24658 -debug
24659 \begin_inset LatexCommand \index{-\/-debug}
24660
24661 \end_inset
24662
24663 , but dumps more information.
24664 \end_layout
24665
24666 \begin_layout Description
24667 -
24668 \begin_inset ERT
24669 status collapsed
24670
24671 \begin_layout Standard
24672
24673
24674 \backslash
24675 /
24676 \end_layout
24677
24678 \end_inset
24679
24680 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24681  information.
24682  <source> is the name of the file being compiled.
24683 \end_layout
24684
24685 \begin_layout Description
24686 -
24687 \begin_inset ERT
24688 status collapsed
24689
24690 \begin_layout Standard
24691
24692
24693 \backslash
24694 /
24695 \end_layout
24696
24697 \end_inset
24698
24699 -pcode-verbose Enable pcode debugging information in translation.
24700 \end_layout
24701
24702 \begin_layout Description
24703 -
24704 \begin_inset ERT
24705 status collapsed
24706
24707 \begin_layout Standard
24708
24709
24710 \backslash
24711 /
24712 \end_layout
24713
24714 \end_inset
24715
24716 -calltree Dump call tree in .calltree file.
24717 \end_layout
24718
24719 \begin_layout Description
24720 -
24721 \begin_inset ERT
24722 status collapsed
24723
24724 \begin_layout Standard
24725
24726
24727 \backslash
24728 /
24729 \end_layout
24730
24731 \end_inset
24732
24733 -gstack Trace push/pops for stack pointer overflow.
24734 \end_layout
24735
24736 \begin_layout Subsection
24737 Enviroment Variables
24738 \end_layout
24739
24740 \begin_layout Standard
24741 There is a number of enviromental variables that can be used when running
24742  SDCC to enable certain optimizations or force a specific program behaviour.
24743  these variables are primarily for debugging purposes so they can be enabled/dis
24744 abled at will.
24745 \end_layout
24746
24747 \begin_layout Standard
24748 Currently there is only two such variables available:
24749 \end_layout
24750
24751 \begin_layout Description
24752 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24753  bitfields is optimized by directly loading FSR0 with the address of the
24754  bitfield structure.
24755  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24756  then load FSR0.
24757  This step saves data ram and code space for functions that make heavy use
24758  of bitfields.
24759  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24760  option).
24761  
24762 \end_layout
24763
24764 \begin_layout Description
24765 NO_REG_OPT Do not perform pCode registers optimization.
24766  This should be used for debugging purposes.
24767  If bugs in the pcode optimizer are found, users can benefit from temporarily
24768  disabling the optimizer until the bug is fixed.
24769 \end_layout
24770
24771 \begin_layout Subsection
24772 Preprocessor Macros
24773 \end_layout
24774
24775 \begin_layout Standard
24776 PIC16
24777 \begin_inset LatexCommand \index{PIC16}
24778
24779 \end_inset
24780
24781  port defines the following preprocessor macros while translating a source.
24782 \end_layout
24783
24784 \begin_layout Standard
24785 \align center
24786 \begin_inset Tabular
24787 <lyxtabular version="3" rows="6" columns="2">
24788 <features>
24789 <column alignment="center" valignment="top" leftline="true" width="0">
24790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24791 <row topline="true" bottomline="true">
24792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24793 \begin_inset Text
24794
24795 \begin_layout Standard
24796 Macro
24797 \end_layout
24798
24799 \end_inset
24800 </cell>
24801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24802 \begin_inset Text
24803
24804 \begin_layout Standard
24805 Description
24806 \end_layout
24807
24808 \end_inset
24809 </cell>
24810 </row>
24811 <row topline="true">
24812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24813 \begin_inset Text
24814
24815 \begin_layout Standard
24816 SDCC_pic16
24817 \end_layout
24818
24819 \end_inset
24820 </cell>
24821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24822 \begin_inset Text
24823
24824 \begin_layout Standard
24825 Port identification
24826 \end_layout
24827
24828 \end_inset
24829 </cell>
24830 </row>
24831 <row topline="true">
24832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24833 \begin_inset Text
24834
24835 \begin_layout Standard
24836 _
24837 \begin_inset ERT
24838 status collapsed
24839
24840 \begin_layout Standard
24841
24842
24843 \backslash
24844 /
24845 \end_layout
24846
24847 \end_inset
24848
24849 _pic16
24850 \end_layout
24851
24852 \end_inset
24853 </cell>
24854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24855 \begin_inset Text
24856
24857 \begin_layout Standard
24858 Port identification (same as above)
24859 \end_layout
24860
24861 \end_inset
24862 </cell>
24863 </row>
24864 <row topline="true">
24865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24866 \begin_inset Text
24867
24868 \begin_layout Standard
24869 pic18fxxxx
24870 \end_layout
24871
24872 \end_inset
24873 </cell>
24874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24875 \begin_inset Text
24876
24877 \begin_layout Standard
24878 MCU Identification.
24879  
24880 \emph on
24881 xxxx
24882 \emph default
24883  is the microcontrol identification number, i.e.
24884  452, 6620, etc
24885 \end_layout
24886
24887 \end_inset
24888 </cell>
24889 </row>
24890 <row topline="true">
24891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24892 \begin_inset Text
24893
24894 \begin_layout Standard
24895 _
24896 \begin_inset ERT
24897 status collapsed
24898
24899 \begin_layout Standard
24900
24901
24902 \backslash
24903 /
24904 \end_layout
24905
24906 \end_inset
24907
24908 _18Fxxxx
24909 \end_layout
24910
24911 \end_inset
24912 </cell>
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24914 \begin_inset Text
24915
24916 \begin_layout Standard
24917 MCU Identification (same as above)
24918 \end_layout
24919
24920 \end_inset
24921 </cell>
24922 </row>
24923 <row topline="true" bottomline="true">
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24925 \begin_inset Text
24926
24927 \begin_layout Standard
24928 STACK_MODEL_nnn
24929 \end_layout
24930
24931 \end_inset
24932 </cell>
24933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24934 \begin_inset Text
24935
24936 \begin_layout Standard
24937 nnn = SMALL or LARGE respectively according to the stack model used
24938 \end_layout
24939
24940 \end_inset
24941 </cell>
24942 </row>
24943 </lyxtabular>
24944
24945 \end_inset
24946
24947
24948 \end_layout
24949
24950 \begin_layout Standard
24951 In addition the following macros are defined when calling assembler:
24952 \end_layout
24953
24954 \begin_layout Standard
24955 \align center
24956 \begin_inset Tabular
24957 <lyxtabular version="3" rows="4" columns="2">
24958 <features>
24959 <column alignment="center" valignment="top" leftline="true" width="0">
24960 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24961 <row topline="true" bottomline="true">
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24963 \begin_inset Text
24964
24965 \begin_layout Standard
24966 Macro
24967 \end_layout
24968
24969 \end_inset
24970 </cell>
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24972 \begin_inset Text
24973
24974 \begin_layout Standard
24975 Description
24976 \end_layout
24977
24978 \end_inset
24979 </cell>
24980 </row>
24981 <row topline="true">
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24983 \begin_inset Text
24984
24985 \begin_layout Standard
24986 __18Fxxxx
24987 \end_layout
24988
24989 \end_inset
24990 </cell>
24991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24992 \begin_inset Text
24993
24994 \begin_layout Standard
24995 MCU Identification.
24996  
24997 \emph on
24998 xxxx
24999 \emph default
25000  is the microcontrol identification number, i.e.
25001  452, 6620, etc
25002 \end_layout
25003
25004 \end_inset
25005 </cell>
25006 </row>
25007 <row topline="true">
25008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25009 \begin_inset Text
25010
25011 \begin_layout Standard
25012 SDCC_MODEL_nnn
25013 \end_layout
25014
25015 \end_inset
25016 </cell>
25017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25018 \begin_inset Text
25019
25020 \begin_layout Standard
25021 nnn = SMALL or LARGE respectively according to the memory model used for
25022  SDCC
25023 \end_layout
25024
25025 \end_inset
25026 </cell>
25027 </row>
25028 <row topline="true" bottomline="true">
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25030 \begin_inset Text
25031
25032 \begin_layout Standard
25033 STACK_MODEL_nnn
25034 \end_layout
25035
25036 \end_inset
25037 </cell>
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25039 \begin_inset Text
25040
25041 \begin_layout Standard
25042 nnn = SMALL or LARGE respectively according to the stack model used
25043 \end_layout
25044
25045 \end_inset
25046 </cell>
25047 </row>
25048 </lyxtabular>
25049
25050 \end_inset
25051
25052
25053 \end_layout
25054
25055 \begin_layout Subsection
25056 Directories
25057 \end_layout
25058
25059 \begin_layout Standard
25060 PIC16
25061 \begin_inset LatexCommand \index{PIC16}
25062
25063 \end_inset
25064
25065  port uses the following directories for searching header files and libraries.
25066 \end_layout
25067
25068 \begin_layout Standard
25069 \align center
25070 \begin_inset Tabular
25071 <lyxtabular version="3" rows="3" columns="4">
25072 <features>
25073 <column alignment="center" valignment="top" leftline="true" width="0">
25074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25075 <column alignment="center" valignment="top" width="0">
25076 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25077 <row topline="true" bottomline="true">
25078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25079 \begin_inset Text
25080
25081 \begin_layout Standard
25082 Directory
25083 \end_layout
25084
25085 \end_inset
25086 </cell>
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25088 \begin_inset Text
25089
25090 \begin_layout Standard
25091 Description
25092 \end_layout
25093
25094 \end_inset
25095 </cell>
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25097 \begin_inset Text
25098
25099 \begin_layout Standard
25100 Target
25101 \end_layout
25102
25103 \end_inset
25104 </cell>
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25106 \begin_inset Text
25107
25108 \begin_layout Standard
25109 Command prefix
25110 \end_layout
25111
25112 \end_inset
25113 </cell>
25114 </row>
25115 <row topline="true">
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25117 \begin_inset Text
25118
25119 \begin_layout Standard
25120 PREFIX/sdcc/include/pic16
25121 \end_layout
25122
25123 \end_inset
25124 </cell>
25125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25126 \begin_inset Text
25127
25128 \begin_layout Standard
25129 PIC16 specific headers
25130 \end_layout
25131
25132 \end_inset
25133 </cell>
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25135 \begin_inset Text
25136
25137 \begin_layout Standard
25138 Compiler
25139 \end_layout
25140
25141 \end_inset
25142 </cell>
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25144 \begin_inset Text
25145
25146 \begin_layout Standard
25147 -I
25148 \end_layout
25149
25150 \end_inset
25151 </cell>
25152 </row>
25153 <row topline="true" bottomline="true">
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25155 \begin_inset Text
25156
25157 \begin_layout Standard
25158 PREFIX/sdcc/lib/pic16
25159 \end_layout
25160
25161 \end_inset
25162 </cell>
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25164 \begin_inset Text
25165
25166 \begin_layout Standard
25167 PIC16 specific libraries
25168 \end_layout
25169
25170 \end_inset
25171 </cell>
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25173 \begin_inset Text
25174
25175 \begin_layout Standard
25176 Linker
25177 \end_layout
25178
25179 \end_inset
25180 </cell>
25181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25182 \begin_inset Text
25183
25184 \begin_layout Standard
25185 -L
25186 \end_layout
25187
25188 \end_inset
25189 </cell>
25190 </row>
25191 </lyxtabular>
25192
25193 \end_inset
25194
25195
25196 \end_layout
25197
25198 \begin_layout Subsection
25199 Pragmas
25200 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25201
25202 \end_inset
25203
25204
25205 \end_layout
25206
25207 \begin_layout Standard
25208 The PIC16
25209 \begin_inset LatexCommand \index{PIC16}
25210
25211 \end_inset
25212
25213  port currently supports the following pragmas:
25214 \end_layout
25215
25216 \begin_layout Description
25217 stack
25218 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25219
25220 \end_inset
25221
25222  This forces the code generator to initialize the stack & frame pointers
25223  at a specific address.
25224  This is an ad hoc solution for cases where no STACK directive is available
25225  in the linker script or gplink is not instructed to create a stack section.
25226 \newline
25227 The
25228  stack pragma should be used only once in a project.
25229  Multiple pragmas may result in indeterminate behaviour of the program.
25230 \begin_inset Foot
25231 status open
25232
25233 \begin_layout Standard
25234 The old format (ie.
25235  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25236  cross page boundaries (or even exceed the available data RAM) and crash
25237  the program.
25238  Make sure that stack does not cross page boundaries when using the SMALL
25239  stack model.
25240 \end_layout
25241
25242 \end_inset
25243
25244
25245 \newline
25246 The format is as follows:
25247 \newline
25248
25249 \end_layout
25250
25251 \begin_layout LyX-Code
25252 #pragma stack bottom_address [stack_size]
25253 \newline
25254
25255 \end_layout
25256
25257 \begin_layout Standard
25258
25259 \emph on
25260 bottom_address
25261 \emph default
25262  is the lower bound of the stack section.
25263  The stack pointer initially will point at address (bottom_address+stack_size-1).
25264 \end_layout
25265
25266 \begin_layout LyX-Code
25267 Example:
25268 \end_layout
25269
25270 \begin_layout LyX-Code
25271
25272 \end_layout
25273
25274 \begin_layout LyX-Code
25275 /* initializes stack of 100 bytes at RAM address 0x200 */
25276 \end_layout
25277
25278 \begin_layout LyX-Code
25279 #pragma stack 0x200 100
25280 \end_layout
25281
25282 \begin_layout Standard
25283 If the stack_size field is omitted then a stack is created with the default
25284  size of 64.
25285  This size might be enough for most programs, but its not enough for operations
25286  with deep function nesting or excessive stack usage.
25287 \end_layout
25288
25289 \begin_layout Description
25290 code
25291 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25292
25293 \end_inset
25294
25295  Force a function to a static FLASH address.
25296 \end_layout
25297
25298 \begin_layout LyX-Code
25299 Example:
25300 \end_layout
25301
25302 \begin_layout LyX-Code
25303
25304 \end_layout
25305
25306 \begin_layout LyX-Code
25307 /* place function test_func at 0x4000 */
25308 \end_layout
25309
25310 \begin_layout LyX-Code
25311 #pragma code test_func 0x4000
25312 \end_layout
25313
25314 \begin_layout LyX-Code
25315
25316 \end_layout
25317
25318 \begin_layout Description
25319 library instructs the linker to use a library module.
25320 \newline
25321 Usage:
25322 \end_layout
25323
25324 \begin_layout LyX-Code
25325 #pragma library module_name
25326 \end_layout
25327
25328 \begin_layout Standard
25329
25330 \emph on
25331 module_name
25332 \emph default
25333  can be any library or object file (including its path).
25334  Note that there are four reserved keywords which have special meaning.
25335  These are:
25336 \end_layout
25337
25338 \begin_layout Standard
25339 \align center
25340 \begin_inset Tabular
25341 <lyxtabular version="3" rows="6" columns="3">
25342 <features>
25343 <column alignment="center" valignment="top" leftline="true" width="0">
25344 <column alignment="block" valignment="top" leftline="true" width="20page%">
25345 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25346 <row topline="true" bottomline="true">
25347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25348 \begin_inset Text
25349
25350 \begin_layout Standard
25351 Keyword
25352 \end_layout
25353
25354 \end_inset
25355 </cell>
25356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25357 \begin_inset Text
25358
25359 \begin_layout Standard
25360 Description
25361 \end_layout
25362
25363 \end_inset
25364 </cell>
25365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25366 \begin_inset Text
25367
25368 \begin_layout Standard
25369 Module to link
25370 \end_layout
25371
25372 \end_inset
25373 </cell>
25374 </row>
25375 <row topline="true">
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25377 \begin_inset Text
25378
25379 \begin_layout Standard
25380
25381 \series bold
25382 ignore
25383 \end_layout
25384
25385 \end_inset
25386 </cell>
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25388 \begin_inset Text
25389
25390 \begin_layout Standard
25391 ignore all library pragmas
25392 \end_layout
25393
25394 \end_inset
25395 </cell>
25396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25397 \begin_inset Text
25398
25399 \begin_layout Standard
25400
25401 \emph on
25402 (none)
25403 \end_layout
25404
25405 \end_inset
25406 </cell>
25407 </row>
25408 <row topline="true">
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25410 \begin_inset Text
25411
25412 \begin_layout Standard
25413
25414 \series bold
25415 c
25416 \end_layout
25417
25418 \end_inset
25419 </cell>
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25421 \begin_inset Text
25422
25423 \begin_layout Standard
25424 link the C library
25425 \end_layout
25426
25427 \end_inset
25428 </cell>
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25430 \begin_inset Text
25431
25432 \begin_layout Standard
25433
25434 \emph on
25435 libc18f
25436 \emph default
25437 .lib
25438 \end_layout
25439
25440 \end_inset
25441 </cell>
25442 </row>
25443 <row topline="true">
25444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25445 \begin_inset Text
25446
25447 \begin_layout Standard
25448
25449 \series bold
25450 math
25451 \end_layout
25452
25453 \end_inset
25454 </cell>
25455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25456 \begin_inset Text
25457
25458 \begin_layout Standard
25459 link the Math libarary
25460 \end_layout
25461
25462 \end_inset
25463 </cell>
25464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25465 \begin_inset Text
25466
25467 \begin_layout Standard
25468
25469 \emph on
25470 libm18f
25471 \emph default
25472 .lib
25473 \end_layout
25474
25475 \end_inset
25476 </cell>
25477 </row>
25478 <row topline="true">
25479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25480 \begin_inset Text
25481
25482 \begin_layout Standard
25483
25484 \series bold
25485 io
25486 \end_layout
25487
25488 \end_inset
25489 </cell>
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25491 \begin_inset Text
25492
25493 \begin_layout Standard
25494 link the I/O library
25495 \end_layout
25496
25497 \end_inset
25498 </cell>
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25500 \begin_inset Text
25501
25502 \begin_layout Standard
25503
25504 \emph on
25505 libio18f*
25506 \emph default
25507 .lib
25508 \end_layout
25509
25510 \end_inset
25511 </cell>
25512 </row>
25513 <row topline="true" bottomline="true">
25514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25515 \begin_inset Text
25516
25517 \begin_layout Standard
25518
25519 \series bold
25520 debug
25521 \end_layout
25522
25523 \end_inset
25524 </cell>
25525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25526 \begin_inset Text
25527
25528 \begin_layout Standard
25529 link the debug library
25530 \end_layout
25531
25532 \end_inset
25533 </cell>
25534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25535 \begin_inset Text
25536
25537 \begin_layout Standard
25538
25539 \emph on
25540 libdebug
25541 \emph default
25542 .lib
25543 \end_layout
25544
25545 \end_inset
25546 </cell>
25547 </row>
25548 </lyxtabular>
25549
25550 \end_inset
25551
25552
25553 \newline
25554 * is the device number, i.e.
25555  452 for PIC18F452 MCU.
25556 \end_layout
25557
25558 \begin_layout Standard
25559 This feature allows for linking with specific libraries withoug having to
25560  explicit name them in the command line.
25561  Note that the 
25562 \noun on
25563 ignore
25564 \noun default
25565  keyword will reject all modules specified by the library pragma.
25566 \end_layout
25567
25568 \begin_layout Description
25569 udata The pragma udata instructs the compiler to emit code so that linker
25570  will place a variable at a specific memory bank.
25571 \end_layout
25572
25573 \begin_layout LyX-Code
25574 Example:
25575 \end_layout
25576
25577 \begin_layout LyX-Code
25578
25579 \end_layout
25580
25581 \begin_layout LyX-Code
25582 /* places variable foo at bank2 */
25583 \end_layout
25584
25585 \begin_layout LyX-Code
25586 #pragma udata bank2 foo
25587 \end_layout
25588
25589 \begin_layout LyX-Code
25590 char foo;
25591 \end_layout
25592
25593 \begin_layout Standard
25594 In order for this pragma to work extra SECTION directives should be added
25595  in the .lkr script.
25596  In the following example a sample .lkr file is shown:
25597 \end_layout
25598
25599 \begin_layout LyX-Code
25600
25601 \end_layout
25602
25603 \begin_layout LyX-Code
25604 // Sample linker script for the PIC18F452 processor
25605 \end_layout
25606
25607 \begin_layout LyX-Code
25608 LIBPATH .
25609 \end_layout
25610
25611 \begin_layout LyX-Code
25612 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25613 \end_layout
25614
25615 \begin_layout LyX-Code
25616 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25617 \end_layout
25618
25619 \begin_layout LyX-Code
25620 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25621 \end_layout
25622
25623 \begin_layout LyX-Code
25624 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25625 \end_layout
25626
25627 \begin_layout LyX-Code
25628 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25629 \end_layout
25630
25631 \begin_layout LyX-Code
25632 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25633 \end_layout
25634
25635 \begin_layout LyX-Code
25636 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25637 \end_layout
25638
25639 \begin_layout LyX-Code
25640
25641 \end_layout
25642
25643 \begin_layout LyX-Code
25644 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25645 \end_layout
25646
25647 \begin_layout LyX-Code
25648 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25649 \end_layout
25650
25651 \begin_layout LyX-Code
25652 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25653 \end_layout
25654
25655 \begin_layout LyX-Code
25656 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25657 \end_layout
25658
25659 \begin_layout LyX-Code
25660 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25661 \end_layout
25662
25663 \begin_layout LyX-Code
25664 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25665 \end_layout
25666
25667 \begin_layout LyX-Code
25668 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25669 \end_layout
25670
25671 \begin_layout LyX-Code
25672
25673 \end_layout
25674
25675 \begin_layout LyX-Code
25676 SECTION    NAME=CONFIG     ROM=config
25677 \end_layout
25678
25679 \begin_layout LyX-Code
25680
25681 \end_layout
25682
25683 \begin_layout LyX-Code
25684 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25685 \end_layout
25686
25687 \begin_layout LyX-Code
25688 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25689 \end_layout
25690
25691 \begin_layout LyX-Code
25692 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25693 \end_layout
25694
25695 \begin_layout LyX-Code
25696 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25697 \end_layout
25698
25699 \begin_layout LyX-Code
25700 SECTION    NAME=bank4      RAM=gpr4
25701 \end_layout
25702
25703 \begin_layout LyX-Code
25704 SECTION    NAME=bank5      RAM=gpr5
25705 \end_layout
25706
25707 \begin_layout Standard
25708 The linker will recognise the section name set in the pragma statement and
25709  will position the variable at the memory bank set with the RAM field at
25710  the SECTION line in the linker script file.
25711 \end_layout
25712
25713 \begin_layout Subsection
25714 Header Files
25715 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25716
25717 \end_inset
25718
25719
25720 \end_layout
25721
25722 \begin_layout Standard
25723 There is one main header file
25724 \begin_inset LatexCommand \index{PIC16!Header files}
25725
25726 \end_inset
25727
25728  that can be included to the source files using the pic16
25729 \begin_inset LatexCommand \index{PIC16}
25730
25731 \end_inset
25732
25733  port.
25734  That file is the 
25735 \series bold
25736 pic18fregs.h
25737 \series default
25738 .
25739  This header file contains the definitions for the processor special registers,
25740  so it is necessary if the source accesses them.
25741  It can be included by adding the following line in the beginning of the
25742  file:
25743 \end_layout
25744
25745 \begin_layout LyX-Code
25746 #include <pic18fregs.h>
25747 \end_layout
25748
25749 \begin_layout Standard
25750 The specific microcontroller is selected within the pic18fregs.h automatically,
25751  so the same source can be used with a variety of devices.
25752 \end_layout
25753
25754 \begin_layout Subsection
25755 Libraries
25756 \end_layout
25757
25758 \begin_layout Standard
25759 The libraries
25760 \begin_inset LatexCommand \index{PIC16!Libraries}
25761
25762 \end_inset
25763
25764  that PIC16
25765 \begin_inset LatexCommand \index{PIC16}
25766
25767 \end_inset
25768
25769  port depends on are the microcontroller device libraries which contain
25770  the symbol definitions for the microcontroller special function registers.
25771  These libraries have the format pic18fxxxx.lib, where 
25772 \emph on
25773 xxxx
25774 \emph default
25775  is the microcontroller identification number.
25776  The specific library is selected automatically by the compiler at link
25777  stage according to the selected device.
25778 \end_layout
25779
25780 \begin_layout Standard
25781 Libraries are created with gplib which is part of the gputils package 
25782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25783
25784 \end_inset
25785
25786 .
25787 \end_layout
25788
25789 \begin_layout Subsubsection*
25790 Building the libraries
25791 \end_layout
25792
25793 \begin_layout Standard
25794 Before using SDCC/pic16 there are some libraries that need to be compiled.
25795  This process is not done automatically by SDCC since not all users use
25796  SDCC for pic16 projects.
25797  So each user should compile the libraries separately.
25798 \end_layout
25799
25800 \begin_layout Standard
25801 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25802 \end_layout
25803
25804 \begin_layout LyX-Code
25805 cd device/lib/pic16
25806 \end_layout
25807
25808 \begin_layout LyX-Code
25809 ./configure
25810 \end_layout
25811
25812 \begin_layout LyX-Code
25813 make
25814 \end_layout
25815
25816 \begin_layout LyX-Code
25817 cd ..
25818 \end_layout
25819
25820 \begin_layout LyX-Code
25821 make model-pic16
25822 \end_layout
25823
25824 \begin_layout LyX-Code
25825 su -c 'make install'     # install the libraries, you need the root password
25826 \end_layout
25827
25828 \begin_layout Standard
25829 If you need to install the headers too, do:
25830 \end_layout
25831
25832 \begin_layout LyX-Code
25833 cd device/include
25834 \end_layout
25835
25836 \begin_layout LyX-Code
25837 su -c 'make install'     # install the headers, you need the root password
25838 \end_layout
25839
25840 \begin_layout Standard
25841 There exist a special target to build the I/O libraries.
25842  This target is not automatically build because it will build the I/O library
25843  for 
25844 \emph on
25845 every
25846 \emph default
25847  supported device.
25848  This way building will take quite a lot of time.
25849  Users are advised to edit the 
25850 \series bold
25851 device/lib/pic16/pics.build
25852 \series default
25853  file and then execute:
25854 \end_layout
25855
25856 \begin_layout LyX-Code
25857 make lib-io
25858 \end_layout
25859
25860 \begin_layout Subsection
25861 Adding New Devices to the Port
25862 \end_layout
25863
25864 \begin_layout Standard
25865 Adding support for a new 16
25866 \begin_inset ERT
25867 status open
25868
25869 \begin_layout Standard
25870
25871
25872 \backslash
25873 ,
25874 \end_layout
25875
25876 \end_inset
25877
25878 bit PIC MCU requires the following steps:
25879 \end_layout
25880
25881 \begin_layout Enumerate
25882 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25883 \newline
25884
25885 \family typewriter
25886 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25887 inc
25888 \end_layout
25889
25890 \begin_layout Enumerate
25891
25892 \family typewriter
25893 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25894 \end_layout
25895
25896 \begin_layout Enumerate
25897
25898 \family typewriter
25899 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25900 \end_layout
25901
25902 \begin_layout Enumerate
25903 Add DEVICE to 
25904 \family typewriter
25905 /path/to/sdcc/device/lib/pic16/pics.all
25906 \family default
25907  (and 
25908 \family typewriter
25909 .build
25910 \family default
25911 ).
25912 \newline
25913 Note: No 18f prefix here!
25914 \end_layout
25915
25916 \begin_layout Enumerate
25917 Adjust 
25918 \family typewriter
25919 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25920 \family default
25921
25922 \newline
25923 Add your DEVICE if it does not compile in 
25924 \family typewriter
25925 adc
25926 \family default
25927
25928 \family typewriter
25929 i2c
25930 \family default
25931 , or 
25932 \family typewriter
25933 usart
25934 \family default
25935 .
25936 \end_layout
25937
25938 \begin_layout Enumerate
25939 Edit 
25940 \family typewriter
25941 /path/to/sdcc/device/include/pic16/pic18fregs.h
25942 \family default
25943 .
25944  The file format is self-explanatory, just add
25945 \newline
25946
25947 \family typewriter
25948 #elif defined(picDEVICE)
25949 \newline
25950 # include <picDEVICE.h>
25951 \family default
25952
25953 \newline
25954 at the right place (keep it sorted).
25955 \end_layout
25956
25957 \begin_layout Enumerate
25958 Edit 
25959 \family typewriter
25960 /path/to/sdcc/src/pic16/devices.inc
25961 \family default
25962 .
25963  Copy and modify an existing entry and insert it at the correct place (keep
25964  the file sorted).
25965  The file is hardly documented, look at the entries for the 18f2221...
25966 \end_layout
25967
25968 \begin_layout Enumerate
25969 Recompile SDCC, including the pic16 libraries.
25970 \end_layout
25971
25972 \begin_layout Subsection
25973 Memory Models
25974 \end_layout
25975
25976 \begin_layout Standard
25977 The following memory models are supported by the PIC16 port:
25978 \end_layout
25979
25980 \begin_layout Itemize
25981 small model
25982 \end_layout
25983
25984 \begin_layout Itemize
25985 large model
25986 \end_layout
25987
25988 \begin_layout Standard
25989 Memory model affects the default size of pointers within the source.
25990  The sizes are shown in the next table:
25991 \end_layout
25992
25993 \begin_layout Standard
25994 \align center
25995 \begin_inset Tabular
25996 <lyxtabular version="3" rows="3" columns="3">
25997 <features>
25998 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25999 <column alignment="center" valignment="top" leftline="true" width="0">
26000 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26001 <row topline="true" bottomline="true">
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26003 \begin_inset Text
26004
26005 \begin_layout Standard
26006 Pointer sizes according to memory model
26007 \end_layout
26008
26009 \end_inset
26010 </cell>
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26012 \begin_inset Text
26013
26014 \begin_layout Standard
26015 small model
26016 \end_layout
26017
26018 \end_inset
26019 </cell>
26020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26021 \begin_inset Text
26022
26023 \begin_layout Standard
26024 large model
26025 \end_layout
26026
26027 \end_inset
26028 </cell>
26029 </row>
26030 <row topline="true" bottomline="true">
26031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26032 \begin_inset Text
26033
26034 \begin_layout Standard
26035 code pointers
26036 \end_layout
26037
26038 \end_inset
26039 </cell>
26040 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26041 \begin_inset Text
26042
26043 \begin_layout Standard
26044 16-bits
26045 \end_layout
26046
26047 \end_inset
26048 </cell>
26049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26050 \begin_inset Text
26051
26052 \begin_layout Standard
26053 24-bits
26054 \end_layout
26055
26056 \end_inset
26057 </cell>
26058 </row>
26059 <row topline="true" bottomline="true">
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26061 \begin_inset Text
26062
26063 \begin_layout Standard
26064 data pointers
26065 \end_layout
26066
26067 \end_inset
26068 </cell>
26069 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26070 \begin_inset Text
26071
26072 \begin_layout Standard
26073 16-bits
26074 \end_layout
26075
26076 \end_inset
26077 </cell>
26078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26079 \begin_inset Text
26080
26081 \begin_layout Standard
26082 16-bits
26083 \end_layout
26084
26085 \end_inset
26086 </cell>
26087 </row>
26088 </lyxtabular>
26089
26090 \end_inset
26091
26092
26093 \end_layout
26094
26095 \begin_layout Standard
26096 It is advisable that all sources within a project are compiled with the
26097  same memory model.
26098  If one wants to override the default memory model, this can be done by
26099  declaring a pointer as 
26100 \series bold
26101 far
26102 \series default
26103  or 
26104 \series bold
26105 near
26106 \series default
26107 .
26108  Far selects large memory model's pointers, while near selects small memory
26109  model's pointers.
26110 \end_layout
26111
26112 \begin_layout Standard
26113 The standard device libraries (see 
26114 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26115
26116 \end_inset
26117
26118 ) contain no reference to pointers, so they can be used with both memory
26119  models.
26120 \end_layout
26121
26122 \begin_layout Subsection
26123 Stack
26124 \end_layout
26125
26126 \begin_layout Standard
26127 The stack
26128 \begin_inset LatexCommand \index{PIC16!stack}
26129
26130 \end_inset
26131
26132  implementation for the PIC16 port uses two indirect registers, FSR1 and
26133  FSR2.
26134 \end_layout
26135
26136 \begin_layout Description
26137 FSR1 is assigned as stack pointer
26138 \end_layout
26139
26140 \begin_layout Description
26141 FSR2 is assigned as frame pointer
26142 \end_layout
26143
26144 \begin_layout Standard
26145 The following stack models are supported by the PIC16 port
26146 \end_layout
26147
26148 \begin_layout Itemize
26149
26150 \noun on
26151 small
26152 \noun default
26153  model
26154 \end_layout
26155
26156 \begin_layout Itemize
26157
26158 \noun on
26159 large
26160 \noun default
26161  model
26162 \end_layout
26163
26164 \begin_layout Standard
26165
26166 \noun on
26167 Small
26168 \noun default
26169  model means that only the FSRxL byte is used to access stack and frame,
26170  while 
26171 \emph on
26172 \noun on
26173 large
26174 \emph default
26175 \noun default
26176  uses both FSRxL and FSRxH registers.
26177  The following table shows the stack/frame pointers sizes according to stack
26178  model and the maximum space they can address:
26179 \end_layout
26180
26181 \begin_layout Standard
26182 \align center
26183 \begin_inset Tabular
26184 <lyxtabular version="3" rows="3" columns="3">
26185 <features>
26186 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26187 <column alignment="center" valignment="top" leftline="true" width="0">
26188 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26189 <row topline="true" bottomline="true">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \begin_layout Standard
26194 Stack & Frame pointer sizes according to stack model
26195 \end_layout
26196
26197 \end_inset
26198 </cell>
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26200 \begin_inset Text
26201
26202 \begin_layout Standard
26203 small
26204 \end_layout
26205
26206 \end_inset
26207 </cell>
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26209 \begin_inset Text
26210
26211 \begin_layout Standard
26212 large
26213 \end_layout
26214
26215 \end_inset
26216 </cell>
26217 </row>
26218 <row topline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26220 \begin_inset Text
26221
26222 \begin_layout Standard
26223 Stack pointer FSR1
26224 \end_layout
26225
26226 \end_inset
26227 </cell>
26228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26229 \begin_inset Text
26230
26231 \begin_layout Standard
26232 8-bits
26233 \end_layout
26234
26235 \end_inset
26236 </cell>
26237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26238 \begin_inset Text
26239
26240 \begin_layout Standard
26241 16-bits
26242 \end_layout
26243
26244 \end_inset
26245 </cell>
26246 </row>
26247 <row topline="true" bottomline="true">
26248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26249 \begin_inset Text
26250
26251 \begin_layout Standard
26252 Frame pointer FSR2
26253 \end_layout
26254
26255 \end_inset
26256 </cell>
26257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26258 \begin_inset Text
26259
26260 \begin_layout Standard
26261 8-bits
26262 \end_layout
26263
26264 \end_inset
26265 </cell>
26266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26267 \begin_inset Text
26268
26269 \begin_layout Standard
26270 16-bits
26271 \end_layout
26272
26273 \end_inset
26274 </cell>
26275 </row>
26276 </lyxtabular>
26277
26278 \end_inset
26279
26280
26281 \end_layout
26282
26283 \begin_layout Standard
26284
26285 \noun on
26286 Large 
26287 \noun default
26288 stack model is currently not working properly throughout the code generator.
26289  So its use is not advised.
26290  Also there are some other points that need special care:
26291 \newline
26292
26293 \end_layout
26294
26295 \begin_layout Enumerate
26296 Do not create stack sections with size more than one physical bank (that
26297  is 256 bytes)
26298 \end_layout
26299
26300 \begin_layout Enumerate
26301 Stack sections should no cross physical bank limits (i.e.
26302  #pragma stack 0x50 0x100)
26303 \end_layout
26304
26305 \begin_layout Standard
26306 These limitations are caused by the fact that only FSRxL is modified when
26307  using SMALL stack model, so no more than 256 bytes of stack can be used.
26308  This problem will disappear after LARGE model is fully implemented.
26309 \end_layout
26310
26311 \begin_layout Subsection
26312 Functions
26313 \end_layout
26314
26315 \begin_layout Standard
26316 In addition to the standard SDCC function keywords, PIC16
26317 \begin_inset LatexCommand \index{PIC16}
26318
26319 \end_inset
26320
26321  port makes available two more:
26322 \end_layout
26323
26324 \begin_layout Description
26325 wparam
26326 \begin_inset LatexCommand \index{PIC16!wparam}
26327
26328 \end_inset
26329
26330  Use the WREG to pass one byte of the first function argument.
26331  This improves speed but you may not use this for functions with arguments
26332  that are called via function pointers, otherwise the first byte of the
26333  first parameter will get lost.
26334  Usage:
26335 \end_layout
26336
26337 \begin_layout LyX-Code
26338 void func_wparam(int a) wparam
26339 \end_layout
26340
26341 \begin_layout LyX-Code
26342 {
26343 \end_layout
26344
26345 \begin_layout LyX-Code
26346     /* WREG hold the lower part of a */
26347 \end_layout
26348
26349 \begin_layout LyX-Code
26350     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26351  */
26352 \end_layout
26353
26354 \begin_layout LyX-Code
26355 ...
26356 \end_layout
26357
26358 \begin_layout LyX-Code
26359 }
26360 \end_layout
26361
26362 \begin_layout Description
26363 shadowregs
26364 \begin_inset LatexCommand \index{PIC16!shadowregs}
26365
26366 \end_inset
26367
26368  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26369  hardware shadow registers which hold the values of WREG, STATUS and BSR
26370  registers.
26371  This can be done by adding the keyword 
26372 \emph on
26373 shadowregs
26374 \emph default
26375  before the 
26376 \emph on
26377 interrupt
26378 \emph default
26379  keyword in the function's header.
26380 \end_layout
26381
26382 \begin_layout LyX-Code
26383 void isr_shadow(void) shadowregs interrupt 1
26384 \end_layout
26385
26386 \begin_layout LyX-Code
26387 {
26388 \end_layout
26389
26390 \begin_layout LyX-Code
26391 ...
26392 \end_layout
26393
26394 \begin_layout LyX-Code
26395 }
26396 \end_layout
26397
26398 \begin_layout Standard
26399
26400 \emph on
26401 shadowregs
26402 \emph default
26403  instructs the code generator not to store/restore WREG, STATUS, BSR when
26404  entering/exiting the ISR.
26405 \end_layout
26406
26407 \begin_layout Subsection
26408 Function return values
26409 \end_layout
26410
26411 \begin_layout Standard
26412 Return values from functions are placed to the appropriate registers following
26413  a modified Microchip policy optimized for SDCC.
26414  The following table shows these registers:
26415 \end_layout
26416
26417 \begin_layout Standard
26418 \align center
26419 \begin_inset Tabular
26420 <lyxtabular version="3" rows="6" columns="2">
26421 <features>
26422 <column alignment="center" valignment="top" leftline="true" width="0">
26423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26426 \begin_inset Text
26427
26428 \begin_layout Standard
26429 size
26430 \end_layout
26431
26432 \end_inset
26433 </cell>
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26435 \begin_inset Text
26436
26437 \begin_layout Standard
26438 destination register
26439 \end_layout
26440
26441 \end_inset
26442 </cell>
26443 </row>
26444 <row topline="true">
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26446 \begin_inset Text
26447
26448 \begin_layout Standard
26449 8 bits
26450 \end_layout
26451
26452 \end_inset
26453 </cell>
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26455 \begin_inset Text
26456
26457 \begin_layout Standard
26458 WREG
26459 \end_layout
26460
26461 \end_inset
26462 </cell>
26463 </row>
26464 <row topline="true">
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26466 \begin_inset Text
26467
26468 \begin_layout Standard
26469 16 bits
26470 \end_layout
26471
26472 \end_inset
26473 </cell>
26474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26475 \begin_inset Text
26476
26477 \begin_layout Standard
26478 PRODL:WREG
26479 \end_layout
26480
26481 \end_inset
26482 </cell>
26483 </row>
26484 <row topline="true">
26485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26486 \begin_inset Text
26487
26488 \begin_layout Standard
26489 24 bits
26490 \end_layout
26491
26492 \end_inset
26493 </cell>
26494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26495 \begin_inset Text
26496
26497 \begin_layout Standard
26498 PRODH:PRODL:WREG
26499 \end_layout
26500
26501 \end_inset
26502 </cell>
26503 </row>
26504 <row topline="true">
26505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26506 \begin_inset Text
26507
26508 \begin_layout Standard
26509 32 bits
26510 \end_layout
26511
26512 \end_inset
26513 </cell>
26514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26515 \begin_inset Text
26516
26517 \begin_layout Standard
26518 FSR0L:PRODH:PRODL:WREG
26519 \end_layout
26520
26521 \end_inset
26522 </cell>
26523 </row>
26524 <row topline="true" bottomline="true">
26525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26526 \begin_inset Text
26527
26528 \begin_layout Standard
26529 >32 bits
26530 \end_layout
26531
26532 \end_inset
26533 </cell>
26534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26535 \begin_inset Text
26536
26537 \begin_layout Standard
26538 on stack, FSR0 points to the beginning
26539 \end_layout
26540
26541 \end_inset
26542 </cell>
26543 </row>
26544 </lyxtabular>
26545
26546 \end_inset
26547
26548
26549 \end_layout
26550
26551 \begin_layout Subsection
26552 Interrupts
26553 \end_layout
26554
26555 \begin_layout Standard
26556 An interrupt
26557 \begin_inset LatexCommand \index{PIC16!interrupt}
26558
26559 \end_inset
26560
26561  service routine (ISR) is declared using the 
26562 \emph on
26563 interrupt
26564 \emph default
26565  keyword.
26566 \end_layout
26567
26568 \begin_layout LyX-Code
26569 void isr(void) interrupt 
26570 \emph on
26571 n
26572 \end_layout
26573
26574 \begin_layout LyX-Code
26575 {
26576 \end_layout
26577
26578 \begin_layout LyX-Code
26579 ...
26580 \end_layout
26581
26582 \begin_layout LyX-Code
26583 }
26584 \end_layout
26585
26586 \begin_layout Standard
26587
26588 \emph on
26589 n
26590 \emph default
26591  is the interrupt number, which for PIC18F devices can be:
26592 \end_layout
26593
26594 \begin_layout Standard
26595 \align center
26596 \begin_inset Tabular
26597 <lyxtabular version="3" rows="4" columns="3">
26598 <features>
26599 <column alignment="center" valignment="top" leftline="true" width="0">
26600 <column alignment="center" valignment="top" leftline="true" width="0">
26601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26602 <row topline="true" bottomline="true">
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26604 \begin_inset Text
26605
26606 \begin_layout Standard
26607
26608 \emph on
26609 n
26610 \end_layout
26611
26612 \end_inset
26613 </cell>
26614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26615 \begin_inset Text
26616
26617 \begin_layout Standard
26618 Interrupt Vector
26619 \end_layout
26620
26621 \end_inset
26622 </cell>
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26624 \begin_inset Text
26625
26626 \begin_layout Standard
26627 Interrupt Vector Address
26628 \end_layout
26629
26630 \end_inset
26631 </cell>
26632 </row>
26633 <row topline="true">
26634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26635 \begin_inset Text
26636
26637 \begin_layout Standard
26638 0
26639 \end_layout
26640
26641 \end_inset
26642 </cell>
26643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26644 \begin_inset Text
26645
26646 \begin_layout Standard
26647 RESET vector
26648 \end_layout
26649
26650 \end_inset
26651 </cell>
26652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26653 \begin_inset Text
26654
26655 \begin_layout Standard
26656 0x000000
26657 \end_layout
26658
26659 \end_inset
26660 </cell>
26661 </row>
26662 <row topline="true">
26663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26664 \begin_inset Text
26665
26666 \begin_layout Standard
26667
26668 \family roman
26669 \series medium
26670 \shape up
26671 \size normal
26672 \emph off
26673 \bar no
26674 \noun off
26675 \color none
26676 1
26677 \end_layout
26678
26679 \end_inset
26680 </cell>
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26682 \begin_inset Text
26683
26684 \begin_layout Standard
26685
26686 \family roman
26687 \series medium
26688 \shape up
26689 \size normal
26690 \emph off
26691 \bar no
26692 \noun off
26693 \color none
26694 HIGH priority interrupts
26695 \end_layout
26696
26697 \end_inset
26698 </cell>
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \begin_layout Standard
26703 0x000008
26704 \end_layout
26705
26706 \end_inset
26707 </cell>
26708 </row>
26709 <row topline="true" bottomline="true">
26710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26711 \begin_inset Text
26712
26713 \begin_layout Standard
26714 2
26715 \end_layout
26716
26717 \end_inset
26718 </cell>
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26720 \begin_inset Text
26721
26722 \begin_layout Standard
26723 LOW priority interrupts
26724 \end_layout
26725
26726 \end_inset
26727 </cell>
26728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26729 \begin_inset Text
26730
26731 \begin_layout Standard
26732 0x000018
26733 \end_layout
26734
26735 \end_inset
26736 </cell>
26737 </row>
26738 </lyxtabular>
26739
26740 \end_inset
26741
26742
26743 \end_layout
26744
26745 \begin_layout Standard
26746 When generating assembly code for ISR the code generator places a 
26747 \noun on
26748 goto 
26749 \noun default
26750 instruction at the 
26751 \emph on
26752 Interrupt Vector Address
26753 \emph default
26754  which points at the genetated ISR.
26755  This single GOTO instruction is part of an automatically generated 
26756 \emph on
26757 interrupt entry point
26758 \emph default
26759  function.
26760  The actuall ISR code is placed as normally would in the code space.
26761  Upon interrupt request, the GOTO instruction is executed which jumps to
26762  the ISR code.
26763  When declaring interrupt functions as _naked this GOTO instruction is 
26764 \series bold
26765 not
26766 \series default
26767  generated.
26768  The whole interrupt functions is therefore placed at the Interrupt Vector
26769  Address of the specific interrupt.
26770  This is not a problem for the LOW priority interrupts, but it is a problem
26771  for the RESET and the HIGH priority interrupts because code may be written
26772  at the next interrupt's vector address and cause undeterminate program
26773  behaviour if that interrupt is raised.
26774 \begin_inset Foot
26775 status open
26776
26777 \begin_layout Standard
26778 This is not a problem when
26779 \end_layout
26780
26781 \begin_layout Enumerate
26782 this is a HIGH interrupt ISR and LOW interrupts are 
26783 \emph on
26784 disabled
26785 \emph default
26786  or not used.
26787 \end_layout
26788
26789 \begin_layout Enumerate
26790 when the ISR is small enough not to reach the next interrupt's vector address.
26791 \end_layout
26792
26793 \end_inset
26794
26795
26796 \end_layout
26797
26798 \begin_layout Standard
26799
26800 \emph on
26801 n
26802 \emph default
26803  may be omitted.
26804  This way a function is generated similar to an ISR, but it is not assigned
26805  to any interrupt.
26806 \end_layout
26807
26808 \begin_layout Standard
26809 When entering an interrupt, currently the PIC16
26810 \begin_inset LatexCommand \index{PIC16}
26811
26812 \end_inset
26813
26814  port automatically saves the following registers:
26815 \end_layout
26816
26817 \begin_layout Itemize
26818 WREG
26819 \end_layout
26820
26821 \begin_layout Itemize
26822 STATUS
26823 \end_layout
26824
26825 \begin_layout Itemize
26826 BSR
26827 \end_layout
26828
26829 \begin_layout Itemize
26830 PROD (PRODL and PRODH)
26831 \end_layout
26832
26833 \begin_layout Itemize
26834 FSR0 (FSR0L and FSR0H)
26835 \end_layout
26836
26837 \begin_layout Standard
26838 These registers are restored upon return from the interrupt routine.
26839 \begin_inset Foot
26840 status open
26841
26842 \begin_layout Standard
26843 NOTE that when the _naked attribute is specified for an interrupt routine,
26844  then NO registers are stored or restored.
26845 \end_layout
26846
26847 \end_inset
26848
26849
26850 \end_layout
26851
26852 \begin_layout Subsection
26853 Generic Pointers
26854 \end_layout
26855
26856 \begin_layout Standard
26857 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26858  There are 3 types of generic pointers currently implemented data, code
26859  and eeprom pointers.
26860  They are differentiated by the value of the 7th and 6th bits of the upper
26861  byte:
26862 \end_layout
26863
26864 \begin_layout Standard
26865 \align center
26866 \begin_inset Tabular
26867 <lyxtabular version="3" rows="5" columns="5">
26868 <features>
26869 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26870 <column alignment="center" valignment="top" width="0">
26871 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26872 <column alignment="center" valignment="top" width="0">
26873 <column alignment="left" valignment="top" rightline="true" width="0">
26874 <row topline="true" bottomline="true">
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \begin_layout Standard
26879 pointer type
26880 \end_layout
26881
26882 \end_inset
26883 </cell>
26884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26885 \begin_inset Text
26886
26887 \begin_layout Standard
26888 7th bit
26889 \end_layout
26890
26891 \end_inset
26892 </cell>
26893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26894 \begin_inset Text
26895
26896 \begin_layout Standard
26897 6th bit
26898 \end_layout
26899
26900 \end_inset
26901 </cell>
26902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26903 \begin_inset Text
26904
26905 \begin_layout Standard
26906 rest of the pointer
26907 \end_layout
26908
26909 \end_inset
26910 </cell>
26911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26912 \begin_inset Text
26913
26914 \begin_layout Standard
26915 description
26916 \end_layout
26917
26918 \end_inset
26919 </cell>
26920 </row>
26921 <row topline="true" bottomline="true">
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26923 \begin_inset Text
26924
26925 \begin_layout Standard
26926 data 
26927 \end_layout
26928
26929 \end_inset
26930 </cell>
26931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26932 \begin_inset Text
26933
26934 \begin_layout Standard
26935 1
26936 \end_layout
26937
26938 \end_inset
26939 </cell>
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26941 \begin_inset Text
26942
26943 \begin_layout Standard
26944 0
26945 \end_layout
26946
26947 \end_inset
26948 </cell>
26949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26950 \begin_inset Text
26951
26952 \begin_layout Standard
26953
26954 \family typewriter
26955 \shape slanted
26956 \emph on
26957 uuuuuu uuuuxxxx xxxxxxxx
26958 \end_layout
26959
26960 \end_inset
26961 </cell>
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 \begin_inset Text
26964
26965 \begin_layout Standard
26966 a 12-bit data pointer in data RAM memory
26967 \end_layout
26968
26969 \end_inset
26970 </cell>
26971 </row>
26972 <row bottomline="true">
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26974 \begin_inset Text
26975
26976 \begin_layout Standard
26977 code
26978 \end_layout
26979
26980 \end_inset
26981 </cell>
26982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26983 \begin_inset Text
26984
26985 \begin_layout Standard
26986 0
26987 \end_layout
26988
26989 \end_inset
26990 </cell>
26991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 \begin_inset Text
26993
26994 \begin_layout Standard
26995 0
26996 \end_layout
26997
26998 \end_inset
26999 </cell>
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27001 \begin_inset Text
27002
27003 \begin_layout Standard
27004
27005 \family typewriter
27006 \shape slanted
27007 \emph on
27008 uxxxxx xxxxxxxx xxxxxxxx
27009 \end_layout
27010
27011 \end_inset
27012 </cell>
27013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27014 \begin_inset Text
27015
27016 \begin_layout Standard
27017 a 21-bit code pointer in FLASH memory
27018 \end_layout
27019
27020 \end_inset
27021 </cell>
27022 </row>
27023 <row bottomline="true">
27024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27025 \begin_inset Text
27026
27027 \begin_layout Standard
27028 eeprom
27029 \end_layout
27030
27031 \end_inset
27032 </cell>
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27034 \begin_inset Text
27035
27036 \begin_layout Standard
27037 0
27038 \end_layout
27039
27040 \end_inset
27041 </cell>
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27043 \begin_inset Text
27044
27045 \begin_layout Standard
27046 1
27047 \end_layout
27048
27049 \end_inset
27050 </cell>
27051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27052 \begin_inset Text
27053
27054 \begin_layout Standard
27055
27056 \family typewriter
27057 \shape slanted
27058 \emph on
27059 uuuuuu uuuuuuxx xxxxxxxx
27060 \end_layout
27061
27062 \end_inset
27063 </cell>
27064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27065 \begin_inset Text
27066
27067 \begin_layout Standard
27068 a 10-bit eeprom pointer in EEPROM memory
27069 \end_layout
27070
27071 \end_inset
27072 </cell>
27073 </row>
27074 <row bottomline="true">
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 \begin_inset Text
27077
27078 \begin_layout Standard
27079 (unimplemented)
27080 \end_layout
27081
27082 \end_inset
27083 </cell>
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27085 \begin_inset Text
27086
27087 \begin_layout Standard
27088 1
27089 \end_layout
27090
27091 \end_inset
27092 </cell>
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27094 \begin_inset Text
27095
27096 \begin_layout Standard
27097 1
27098 \end_layout
27099
27100 \end_inset
27101 </cell>
27102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27103 \begin_inset Text
27104
27105 \begin_layout Standard
27106
27107 \family typewriter
27108 \shape slanted
27109 \emph on
27110 xxxxxx xxxxxxxx xxxxxxxx
27111 \end_layout
27112
27113 \end_inset
27114 </cell>
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_inset Text
27117
27118 \begin_layout Standard
27119 unimplemented pointer type
27120 \end_layout
27121
27122 \end_inset
27123 </cell>
27124 </row>
27125 </lyxtabular>
27126
27127 \end_inset
27128
27129
27130 \end_layout
27131
27132 \begin_layout Standard
27133 Generic pointer are read and written with a set of library functions which
27134  read/write 1, 2, 3, 4 bytes.
27135 \end_layout
27136
27137 \begin_layout Subsection
27138 PIC16 C Libraries
27139 \end_layout
27140
27141 \begin_layout Subsubsection
27142 Standard I/O Streams
27143 \end_layout
27144
27145 \begin_layout Standard
27146 In the 
27147 \emph on
27148 stdio.h
27149 \emph default
27150  the type FILE is defined as:
27151 \end_layout
27152
27153 \begin_layout LyX-Code
27154 typedef char * FILE;
27155 \end_layout
27156
27157 \begin_layout Standard
27158 This type is the stream type implemented I/O in the PIC18F devices.
27159  Also the standard input and output streams are declared in stdio.h:
27160 \end_layout
27161
27162 \begin_layout LyX-Code
27163 extern FILE * stdin;
27164 \end_layout
27165
27166 \begin_layout LyX-Code
27167 extern FILE * stdout;
27168 \end_layout
27169
27170 \begin_layout Standard
27171 The FILE type is actually a generic pointer which defines one more type
27172  of generic pointers, the 
27173 \emph on
27174 stream 
27175 \emph default
27176 pointer.
27177  This new type has the format:
27178 \end_layout
27179
27180 \begin_layout Standard
27181 \align center
27182 \begin_inset Tabular
27183 <lyxtabular version="3" rows="2" columns="7">
27184 <features>
27185 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27186 <column alignment="center" valignment="top" width="0">
27187 <column alignment="center" valignment="top" leftline="true" width="0">
27188 <column alignment="center" valignment="top" leftline="true" width="0">
27189 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27190 <column alignment="center" valignment="top" width="0">
27191 <column alignment="left" valignment="top" rightline="true" width="0">
27192 <row topline="true" bottomline="true">
27193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27194 \begin_inset Text
27195
27196 \begin_layout Standard
27197 pointer type
27198 \end_layout
27199
27200 \end_inset
27201 </cell>
27202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27203 \begin_inset Text
27204
27205 \begin_layout Standard
27206 <7:6>
27207 \end_layout
27208
27209 \end_inset
27210 </cell>
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27212 \begin_inset Text
27213
27214 \begin_layout Standard
27215 <5>
27216 \end_layout
27217
27218 \end_inset
27219 </cell>
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27221 \begin_inset Text
27222
27223 \begin_layout Standard
27224 <4>
27225 \end_layout
27226
27227 \end_inset
27228 </cell>
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27230 \begin_inset Text
27231
27232 \begin_layout Standard
27233 <3:0>
27234 \end_layout
27235
27236 \end_inset
27237 </cell>
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27239 \begin_inset Text
27240
27241 \begin_layout Standard
27242 rest of the pointer
27243 \end_layout
27244
27245 \end_inset
27246 </cell>
27247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27248 \begin_inset Text
27249
27250 \begin_layout Standard
27251 descrption
27252 \end_layout
27253
27254 \end_inset
27255 </cell>
27256 </row>
27257 <row topline="true" bottomline="true">
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27259 \begin_inset Text
27260
27261 \begin_layout Standard
27262 stream
27263 \end_layout
27264
27265 \end_inset
27266 </cell>
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27268 \begin_inset Text
27269
27270 \begin_layout Standard
27271 00
27272 \end_layout
27273
27274 \end_inset
27275 </cell>
27276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27277 \begin_inset Text
27278
27279 \begin_layout Standard
27280 1
27281 \end_layout
27282
27283 \end_inset
27284 </cell>
27285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27286 \begin_inset Text
27287
27288 \begin_layout Standard
27289 0
27290 \end_layout
27291
27292 \end_inset
27293 </cell>
27294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27295 \begin_inset Text
27296
27297 \begin_layout Standard
27298 nnnn
27299 \end_layout
27300
27301 \end_inset
27302 </cell>
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27304 \begin_inset Text
27305
27306 \begin_layout Standard
27307
27308 \family typewriter
27309 \shape slanted
27310 \emph on
27311 uuuuuuuu uuuuuuuu
27312 \end_layout
27313
27314 \end_inset
27315 </cell>
27316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27317 \begin_inset Text
27318
27319 \begin_layout Standard
27320 upper byte high nubble is 0x2n, the rest are zeroes
27321 \end_layout
27322
27323 \end_inset
27324 </cell>
27325 </row>
27326 </lyxtabular>
27327
27328 \end_inset
27329
27330
27331 \end_layout
27332
27333 \begin_layout Standard
27334 Currently implemented there are 3 types of streams defined:
27335 \end_layout
27336
27337 \begin_layout Standard
27338 \align center
27339 \begin_inset Tabular
27340 <lyxtabular version="3" rows="4" columns="4">
27341 <features>
27342 <column alignment="center" valignment="top" leftline="true" width="0">
27343 <column alignment="center" valignment="top" leftline="true" width="0">
27344 <column alignment="center" valignment="top" leftline="true" width="0">
27345 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27346 <row topline="true" bottomline="true">
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27348 \begin_inset Text
27349
27350 \begin_layout Standard
27351 stream type
27352 \end_layout
27353
27354 \end_inset
27355 </cell>
27356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27357 \begin_inset Text
27358
27359 \begin_layout Standard
27360 value
27361 \end_layout
27362
27363 \end_inset
27364 </cell>
27365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27366 \begin_inset Text
27367
27368 \begin_layout Standard
27369 module
27370 \end_layout
27371
27372 \end_inset
27373 </cell>
27374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27375 \begin_inset Text
27376
27377 \begin_layout Standard
27378 description
27379 \end_layout
27380
27381 \end_inset
27382 </cell>
27383 </row>
27384 <row topline="true">
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27386 \begin_inset Text
27387
27388 \begin_layout Standard
27389 STREAM_USART
27390 \end_layout
27391
27392 \end_inset
27393 </cell>
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27395 \begin_inset Text
27396
27397 \begin_layout Standard
27398
27399 \family typewriter
27400 0x200000UL
27401 \end_layout
27402
27403 \end_inset
27404 </cell>
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27406 \begin_inset Text
27407
27408 \begin_layout Standard
27409 USART
27410 \end_layout
27411
27412 \end_inset
27413 </cell>
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27415 \begin_inset Text
27416
27417 \begin_layout Standard
27418 Writes/Reads characters via the USART peripheral
27419 \end_layout
27420
27421 \end_inset
27422 </cell>
27423 </row>
27424 <row topline="true">
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27426 \begin_inset Text
27427
27428 \begin_layout Standard
27429 STREAM_MSSP
27430 \end_layout
27431
27432 \end_inset
27433 </cell>
27434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27435 \begin_inset Text
27436
27437 \begin_layout Standard
27438
27439 \family typewriter
27440 0x210000UL
27441 \end_layout
27442
27443 \end_inset
27444 </cell>
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27446 \begin_inset Text
27447
27448 \begin_layout Standard
27449 MSSP
27450 \end_layout
27451
27452 \end_inset
27453 </cell>
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27455 \begin_inset Text
27456
27457 \begin_layout Standard
27458 Writes/Reads characters via the MSSP peripheral
27459 \end_layout
27460
27461 \end_inset
27462 </cell>
27463 </row>
27464 <row topline="true" bottomline="true">
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27466 \begin_inset Text
27467
27468 \begin_layout Standard
27469 STREAM_USER
27470 \end_layout
27471
27472 \end_inset
27473 </cell>
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27475 \begin_inset Text
27476
27477 \begin_layout Standard
27478
27479 \family typewriter
27480 0x2f0000UL
27481 \end_layout
27482
27483 \end_inset
27484 </cell>
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27486 \begin_inset Text
27487
27488 \begin_layout Standard
27489 (none)
27490 \end_layout
27491
27492 \end_inset
27493 </cell>
27494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27495 \begin_inset Text
27496
27497 \begin_layout Standard
27498 Writes/Reads characters via used defined functions
27499 \end_layout
27500
27501 \end_inset
27502 </cell>
27503 </row>
27504 </lyxtabular>
27505
27506 \end_inset
27507
27508
27509 \end_layout
27510
27511 \begin_layout Standard
27512 The stream identifiers are declared as macros in the stdio.h header.
27513 \end_layout
27514
27515 \begin_layout Standard
27516 In the libc library there exist the functions that are used to write to
27517  each of the above streams.
27518  These are
27519 \end_layout
27520
27521 \begin_layout Description
27522 _
27523 \begin_inset ERT
27524 status collapsed
27525
27526 \begin_layout Standard
27527
27528
27529 \backslash
27530 /
27531 \end_layout
27532
27533 \end_inset
27534
27535 _stream_usart_putchar writes a character at the USART stream
27536 \end_layout
27537
27538 \begin_layout Description
27539 _
27540 \begin_inset ERT
27541 status collapsed
27542
27543 \begin_layout Standard
27544
27545
27546 \backslash
27547 /
27548 \end_layout
27549
27550 \end_inset
27551
27552 _stream_mssp_putchar writes a character at the MSSP stream
27553 \end_layout
27554
27555 \begin_layout Description
27556 putchar dummy function.
27557  This writes a character to a user specified manner.
27558 \end_layout
27559
27560 \begin_layout Standard
27561 In order to increase performance 
27562 \emph on
27563 putchar 
27564 \emph default
27565 is declared in stdio.h as having its parameter in WREG (it has the wparam
27566  keyword).
27567  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27568  in a user-friendly way.
27569  
27570 \emph on
27571 arg
27572 \emph default
27573  is the name of the variable that holds the character to print.
27574  An example follows:
27575 \end_layout
27576
27577 \begin_layout LyX-Code
27578 #include <pic18fregs.h>
27579 \newline
27580 #include <stdio.h>
27581 \newline
27582
27583 \newline
27584 PUTCHAR( c )
27585 \end_layout
27586
27587 \begin_layout LyX-Code
27588 {
27589 \end_layout
27590
27591 \begin_layout LyX-Code
27592     PORTA = c;    /* dump character c to PORTA */
27593 \end_layout
27594
27595 \begin_layout LyX-Code
27596
27597 \newline
27598
27599 \newline
27600 void main(void)
27601 \end_layout
27602
27603 \begin_layout LyX-Code
27604 {
27605 \end_layout
27606
27607 \begin_layout LyX-Code
27608     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27609 \end_layout
27610
27611 \begin_layout LyX-Code
27612                               * by default to STREAM_USER */
27613 \end_layout
27614
27615 \begin_layout LyX-Code
27616     printf (
27617 \begin_inset Quotes sld
27618 \end_inset
27619
27620 This is a printf test
27621 \backslash
27622 n
27623 \begin_inset Quotes srd
27624 \end_inset
27625
27626 );
27627 \end_layout
27628
27629 \begin_layout LyX-Code
27630 }
27631 \end_layout
27632
27633 \begin_layout LyX-Code
27634
27635 \end_layout
27636
27637 \begin_layout Subsubsection
27638 Printing functions
27639 \end_layout
27640
27641 \begin_layout Standard
27642 PIC16 contains an implementation of the printf-family of functions.
27643  There exist the following functions:
27644 \end_layout
27645
27646 \begin_layout LyX-Code
27647 extern unsigned int sprintf(char *buf, char *fmt, ...);
27648 \end_layout
27649
27650 \begin_layout LyX-Code
27651 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27652 \end_layout
27653
27654 \begin_layout LyX-Code
27655
27656 \end_layout
27657
27658 \begin_layout LyX-Code
27659 extern unsigned int printf(char *fmt, ...);
27660 \end_layout
27661
27662 \begin_layout LyX-Code
27663 extern unsigned int vprintf(char *fmt, va_lista ap);
27664 \end_layout
27665
27666 \begin_layout LyX-Code
27667
27668 \end_layout
27669
27670 \begin_layout LyX-Code
27671 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27672 \end_layout
27673
27674 \begin_layout LyX-Code
27675 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27676 \end_layout
27677
27678 \begin_layout Standard
27679 For sprintf and vsprintf 
27680 \emph on
27681 buf 
27682 \emph default
27683 should normally be a data pointer where the resulting string will be placed.
27684  No range checking is done so the user should allocate the necessery buffer.
27685  For fprintf and vfprintf 
27686 \emph on
27687 fp
27688 \emph default
27689  should be a stream pointer (i.e.
27690  stdout, STREAM_MSSP, etc...).
27691 \end_layout
27692
27693 \begin_layout Subsubsection
27694 Signals
27695 \end_layout
27696
27697 \begin_layout Standard
27698 The PIC18F family of microcontrollers supports a number of interrupt sources.
27699  A list of these interrupts is shown in the following table:
27700 \end_layout
27701
27702 \begin_layout Standard
27703 \align center
27704 \begin_inset Tabular
27705 <lyxtabular version="3" rows="11" columns="4">
27706 <features>
27707 <column alignment="left" valignment="top" leftline="true" width="0">
27708 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27709 <column alignment="left" valignment="top" leftline="true" width="0">
27710 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27711 <row topline="true" bottomline="true">
27712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27713 \begin_inset Text
27714
27715 \begin_layout Standard
27716 signal name
27717 \end_layout
27718
27719 \end_inset
27720 </cell>
27721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27722 \begin_inset Text
27723
27724 \begin_layout Standard
27725 description
27726 \end_layout
27727
27728 \end_inset
27729 </cell>
27730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27731 \begin_inset Text
27732
27733 \begin_layout Standard
27734 signal name
27735 \end_layout
27736
27737 \end_inset
27738 </cell>
27739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27740 \begin_inset Text
27741
27742 \begin_layout Standard
27743 descritpion
27744 \end_layout
27745
27746 \end_inset
27747 </cell>
27748 </row>
27749 <row topline="true">
27750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27751 \begin_inset Text
27752
27753 \begin_layout Standard
27754 SIG_RB
27755 \end_layout
27756
27757 \end_inset
27758 </cell>
27759 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27760 \begin_inset Text
27761
27762 \begin_layout Standard
27763 PORTB change interrupt
27764 \end_layout
27765
27766 \end_inset
27767 </cell>
27768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27769 \begin_inset Text
27770
27771 \begin_layout Standard
27772 SIG_EE
27773 \end_layout
27774
27775 \end_inset
27776 </cell>
27777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27778 \begin_inset Text
27779
27780 \begin_layout Standard
27781 EEPROM/FLASH write complete interrupt
27782 \end_layout
27783
27784 \end_inset
27785 </cell>
27786 </row>
27787 <row topline="true">
27788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27789 \begin_inset Text
27790
27791 \begin_layout Standard
27792 SIG_INT0
27793 \end_layout
27794
27795 \end_inset
27796 </cell>
27797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27798 \begin_inset Text
27799
27800 \begin_layout Standard
27801 INT0 external interrupt
27802 \end_layout
27803
27804 \end_inset
27805 </cell>
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27807 \begin_inset Text
27808
27809 \begin_layout Standard
27810 SIG_BCOL
27811 \end_layout
27812
27813 \end_inset
27814 </cell>
27815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27816 \begin_inset Text
27817
27818 \begin_layout Standard
27819 Bus collision interrupt
27820 \end_layout
27821
27822 \end_inset
27823 </cell>
27824 </row>
27825 <row topline="true">
27826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27827 \begin_inset Text
27828
27829 \begin_layout Standard
27830 SIG_INT1
27831 \end_layout
27832
27833 \end_inset
27834 </cell>
27835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27836 \begin_inset Text
27837
27838 \begin_layout Standard
27839 INT1 external interrupt
27840 \end_layout
27841
27842 \end_inset
27843 </cell>
27844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27845 \begin_inset Text
27846
27847 \begin_layout Standard
27848 SIG_LVD
27849 \end_layout
27850
27851 \end_inset
27852 </cell>
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27854 \begin_inset Text
27855
27856 \begin_layout Standard
27857 Low voltage detect interrupt
27858 \end_layout
27859
27860 \end_inset
27861 </cell>
27862 </row>
27863 <row topline="true">
27864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27865 \begin_inset Text
27866
27867 \begin_layout Standard
27868 SIG_INT2
27869 \end_layout
27870
27871 \end_inset
27872 </cell>
27873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27874 \begin_inset Text
27875
27876 \begin_layout Standard
27877 INT2 external interrupt
27878 \end_layout
27879
27880 \end_inset
27881 </cell>
27882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27883 \begin_inset Text
27884
27885 \begin_layout Standard
27886 SIG_PSP
27887 \end_layout
27888
27889 \end_inset
27890 </cell>
27891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27892 \begin_inset Text
27893
27894 \begin_layout Standard
27895 Parallel slave port interrupt
27896 \end_layout
27897
27898 \end_inset
27899 </cell>
27900 </row>
27901 <row topline="true">
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27903 \begin_inset Text
27904
27905 \begin_layout Standard
27906 SIG_CCP1
27907 \end_layout
27908
27909 \end_inset
27910 </cell>
27911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27912 \begin_inset Text
27913
27914 \begin_layout Standard
27915 CCP1 module interrupt
27916 \end_layout
27917
27918 \end_inset
27919 </cell>
27920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27921 \begin_inset Text
27922
27923 \begin_layout Standard
27924 SIG_AD
27925 \end_layout
27926
27927 \end_inset
27928 </cell>
27929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27930 \begin_inset Text
27931
27932 \begin_layout Standard
27933 AD convertion complete interrupt
27934 \end_layout
27935
27936 \end_inset
27937 </cell>
27938 </row>
27939 <row topline="true">
27940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27941 \begin_inset Text
27942
27943 \begin_layout Standard
27944 SIG_CCP2
27945 \end_layout
27946
27947 \end_inset
27948 </cell>
27949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27950 \begin_inset Text
27951
27952 \begin_layout Standard
27953 CCP2 module interrupt
27954 \end_layout
27955
27956 \end_inset
27957 </cell>
27958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27959 \begin_inset Text
27960
27961 \begin_layout Standard
27962 SIG_RC
27963 \end_layout
27964
27965 \end_inset
27966 </cell>
27967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27968 \begin_inset Text
27969
27970 \begin_layout Standard
27971 USART receive interrupt
27972 \end_layout
27973
27974 \end_inset
27975 </cell>
27976 </row>
27977 <row topline="true">
27978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27979 \begin_inset Text
27980
27981 \begin_layout Standard
27982 SIG_TMR0
27983 \end_layout
27984
27985 \end_inset
27986 </cell>
27987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27988 \begin_inset Text
27989
27990 \begin_layout Standard
27991 TMR0 overflow interrupt
27992 \end_layout
27993
27994 \end_inset
27995 </cell>
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27997 \begin_inset Text
27998
27999 \begin_layout Standard
28000 SIG_TX
28001 \end_layout
28002
28003 \end_inset
28004 </cell>
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28006 \begin_inset Text
28007
28008 \begin_layout Standard
28009 USART transmit interrupt
28010 \end_layout
28011
28012 \end_inset
28013 </cell>
28014 </row>
28015 <row topline="true">
28016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28017 \begin_inset Text
28018
28019 \begin_layout Standard
28020 SIG_TMR1
28021 \end_layout
28022
28023 \end_inset
28024 </cell>
28025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28026 \begin_inset Text
28027
28028 \begin_layout Standard
28029 TMR1 overflow interrupt
28030 \end_layout
28031
28032 \end_inset
28033 </cell>
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28035 \begin_inset Text
28036
28037 \begin_layout Standard
28038 SIG_MSSP
28039 \end_layout
28040
28041 \end_inset
28042 </cell>
28043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28044 \begin_inset Text
28045
28046 \begin_layout Standard
28047 SSP receive/transmit interrupt
28048 \end_layout
28049
28050 \end_inset
28051 </cell>
28052 </row>
28053 <row topline="true">
28054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28055 \begin_inset Text
28056
28057 \begin_layout Standard
28058 SIG_TMR2
28059 \end_layout
28060
28061 \end_inset
28062 </cell>
28063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28064 \begin_inset Text
28065
28066 \begin_layout Standard
28067 TMR2 matches PR2 interrupt
28068 \end_layout
28069
28070 \end_inset
28071 </cell>
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28073 \begin_inset Text
28074
28075 \begin_layout Standard
28076
28077 \end_layout
28078
28079 \end_inset
28080 </cell>
28081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28082 \begin_inset Text
28083
28084 \begin_layout Standard
28085
28086 \end_layout
28087
28088 \end_inset
28089 </cell>
28090 </row>
28091 <row topline="true" bottomline="true">
28092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28093 \begin_inset Text
28094
28095 \begin_layout Standard
28096 SIG_TMR3
28097 \end_layout
28098
28099 \end_inset
28100 </cell>
28101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28102 \begin_inset Text
28103
28104 \begin_layout Standard
28105 TMR3 overflow interrupt
28106 \end_layout
28107
28108 \end_inset
28109 </cell>
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28111 \begin_inset Text
28112
28113 \begin_layout Standard
28114
28115 \end_layout
28116
28117 \end_inset
28118 </cell>
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28120 \begin_inset Text
28121
28122 \begin_layout Standard
28123
28124 \end_layout
28125
28126 \end_inset
28127 </cell>
28128 </row>
28129 </lyxtabular>
28130
28131 \end_inset
28132
28133
28134 \end_layout
28135
28136 \begin_layout Standard
28137 The prototypes for these names are defined in the header file 
28138 \emph on
28139 signal.h
28140 \emph default
28141  .
28142 \end_layout
28143
28144 \begin_layout Standard
28145 In order to simplify signal handling, a number of macros is provided:
28146 \end_layout
28147
28148 \begin_layout List
28149 \labelwidthstring 00.00.0000
28150 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28151  high priority interrupts.
28152  
28153 \emph on
28154 name
28155 \emph default
28156  is the function name to use.
28157 \end_layout
28158
28159 \begin_layout List
28160 \labelwidthstring 00.00.0000
28161 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28162  low priority interrupt.
28163  
28164 \emph on
28165 name
28166 \emph default
28167  is the function name to use.
28168 \end_layout
28169
28170 \begin_layout List
28171 \labelwidthstring 00.00.0000
28172 DEF_HANDLER(sig,handler) define a handler for signal 
28173 \emph on
28174 sig.
28175 \end_layout
28176
28177 \begin_layout List
28178 \labelwidthstring 00.00.0000
28179 END_DEF end the declaration of the dispatch table.
28180 \end_layout
28181
28182 \begin_layout Standard
28183 Additionally there are two more macros to simplify the declaration of the
28184  signal handler:
28185 \end_layout
28186
28187 \begin_layout List
28188 \labelwidthstring 00.00.0000
28189
28190 \series medium
28191 SIGHANDLER(handler) 
28192 \series default
28193 this declares the function prototype for the 
28194 \emph on
28195 handler
28196 \emph default
28197  function.
28198 \end_layout
28199
28200 \begin_layout List
28201 \labelwidthstring 00.00.0000
28202 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28203 \end_layout
28204
28205 \begin_layout Standard
28206 An example of using the macros above is shown below:
28207 \end_layout
28208
28209 \begin_layout LyX-Code
28210 #include <pic18fregs.h>
28211 \end_layout
28212
28213 \begin_layout LyX-Code
28214 #include <signal.h>
28215 \newline
28216
28217 \newline
28218 DEF_INTHIGH(high_int)
28219 \end_layout
28220
28221 \begin_layout LyX-Code
28222 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28223 \end_layout
28224
28225 \begin_layout LyX-Code
28226 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28227 \end_layout
28228
28229 \begin_layout LyX-Code
28230 END_DEF
28231 \newline
28232
28233 \newline
28234 SIGHANDLER(_tmr0_handler)
28235 \end_layout
28236
28237 \begin_layout LyX-Code
28238 {
28239 \end_layout
28240
28241 \begin_layout LyX-Code
28242   /* action to be taken when timer 0 overflows */
28243 \end_layout
28244
28245 \begin_layout LyX-Code
28246 }
28247 \newline
28248
28249 \newline
28250 SIGHANDLERNAKED(_bcol_handler)
28251 \end_layout
28252
28253 \begin_layout LyX-Code
28254 {
28255 \end_layout
28256
28257 \begin_layout LyX-Code
28258   _asm
28259 \end_layout
28260
28261 \begin_layout LyX-Code
28262     /* action to be taken when bus collision occurs */
28263 \end_layout
28264
28265 \begin_layout LyX-Code
28266     retfie
28267 \end_layout
28268
28269 \begin_layout LyX-Code
28270  _endasm;
28271 \end_layout
28272
28273 \begin_layout LyX-Code
28274 }
28275 \end_layout
28276
28277 \begin_layout Standard
28278
28279 \series bold
28280 NOTES:
28281 \series default
28282  Special care should be taken when using the above scheme:
28283 \end_layout
28284
28285 \begin_layout Itemize
28286 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28287 \end_layout
28288
28289 \begin_layout Itemize
28290 when declaring SIGHANDLERNAKED handler never forget to use 
28291 \emph on
28292 retfie
28293 \emph default
28294  for proper returning.
28295 \end_layout
28296
28297 \begin_layout Subsection
28298 PIC16 Port -- Tips
28299 \end_layout
28300
28301 \begin_layout Standard
28302 Here you can find some general tips for compiling programs with SDCC/pic16.
28303 \end_layout
28304
28305 \begin_layout Subsubsection
28306 Stack size
28307 \end_layout
28308
28309 \begin_layout Standard
28310 The default stack
28311 \begin_inset LatexCommand \index{PIC16!stack}
28312
28313 \end_inset
28314
28315  size (that is 64 bytes) probably is enough for many programs.
28316  One must take care that when there are many levels of function nesting,
28317  or there is excessive usage of stack, its size should be extended.
28318  An example of such a case is the printf/sprintf family of functions.
28319  If you encounter problems like not being able to print integers, then you
28320  need to set the stack size around the maximum (256 for small stack model).
28321  The following diagram shows what happens when calling printf to print an
28322  integer:
28323 \end_layout
28324
28325 \begin_layout LyX-Code
28326 printf () --> ltoa () --> ultoa () --> divschar ()
28327 \end_layout
28328
28329 \begin_layout Standard
28330 It is should be understood that stack is easily consumed when calling complicate
28331 d functions.
28332  Using command line arguments like -
28333 \begin_inset ERT
28334 status collapsed
28335
28336 \begin_layout Standard
28337
28338
28339 \backslash
28340 /
28341 \end_layout
28342
28343 \end_inset
28344
28345 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28346  stack frames.
28347  Other ways to reduce stack usage may exist.
28348 \end_layout
28349
28350 \begin_layout Subsection
28351 Known Bugs
28352 \end_layout
28353
28354 \begin_layout Standard
28355 The PIC16 Port currently does not pass SDCC's regression test
28356 \begin_inset LatexCommand \index{Regression test (PIC16)}
28357
28358 \end_inset
28359
28360  suite (see section 
28361 \begin_inset LatexCommand \ref{sec:Quality-control}
28362
28363 \end_inset
28364
28365 ) and thus the snapshot build regression tests for the PIC16 target are
28366  currently disabled for all hosts
28367 \emph on
28368 .
28369 \end_layout
28370
28371 \begin_layout Chapter
28372 Debugging
28373 \end_layout
28374
28375 \begin_layout Standard
28376 There are several approaches to debugging your code.
28377  This chapter is meant to show your options and to give detail on some of
28378  them:
28379 \newline
28380
28381 \newline
28382 When writing your code:
28383 \end_layout
28384
28385 \begin_layout Itemize
28386 write your code with debugging in mind (avoid duplicating code, put conceptually
28387  similar variables into structs, use structured code, have strategic points
28388  within your code where all variables are consistent, ...)
28389 \end_layout
28390
28391 \begin_layout Itemize
28392 run a syntax-checking tool like splint
28393 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28394
28395 \end_inset
28396
28397
28398 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28399
28400 \end_inset
28401
28402  (see -
28403 \begin_inset ERT
28404 status collapsed
28405
28406 \begin_layout Standard
28407
28408
28409 \backslash
28410 /
28411 \end_layout
28412
28413 \end_inset
28414
28415 -more-pedantic 
28416 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28417
28418 \end_inset
28419
28420 ) over the code.
28421 \end_layout
28422
28423 \begin_layout Itemize
28424 for the high level code use a C-compiler (like f.e.
28425  GCC) to compile run and debug the code on your host.
28426  See (see -
28427 \begin_inset ERT
28428 status collapsed
28429
28430 \begin_layout Standard
28431
28432
28433 \backslash
28434 /
28435 \end_layout
28436
28437 \end_inset
28438
28439 -more-pedantic 
28440 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28441
28442 \end_inset
28443
28444 ) on how to handle syntax extensions like __xdata, __at(), ...
28445  
28446 \end_layout
28447
28448 \begin_layout Itemize
28449 use another C-compiler to compile code for your target.
28450  Always an option but not recommended:) And not very likely to help you.
28451  If you seriously consider walking this path you should at least occasionally
28452  check portability of your code.
28453  Most commercial compiler vendors will offer an evaluation version so you
28454  can test compile your code or snippets of your code.
28455 \end_layout
28456
28457 \begin_layout Standard
28458 Debugging on a simulator:
28459 \end_layout
28460
28461 \begin_layout Itemize
28462 there is a separate section about SDCDB (section 
28463 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28464
28465 \end_inset
28466
28467 ) below.
28468 \end_layout
28469
28470 \begin_layout Itemize
28471 or (8051 specific) use a freeware/commercial simulator which interfaces
28472  to the AOMF
28473 \begin_inset LatexCommand \index{AOMF, AOMF51}
28474
28475 \end_inset
28476
28477  file (see 
28478 \begin_inset LatexCommand \ref{OMF file}
28479
28480 \end_inset
28481
28482 ) optionally generated by SDCC.
28483 \end_layout
28484
28485 \begin_layout Standard
28486 Debugging On-target: 
28487 \end_layout
28488
28489 \begin_layout Itemize
28490 use a MCU port pin to serially output debug data to the RS232 port of your
28491  host.
28492  You'll probably want some level shifting device typically involving a MAX232
28493  or similar IC.
28494  If the hardware serial port of the MCU is not available search for 'Software
28495  UART' in your favourite search machine.
28496 \end_layout
28497
28498 \begin_layout Itemize
28499 use an on-target monitor.
28500  In this context a monitor is a small program which usually accepts commands
28501  via a serial line and allows to set program counter, to single step through
28502  a program and read/write memory locations.
28503  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28504  
28505 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28506
28507 \end_inset
28508
28509 ).
28510 \end_layout
28511
28512 \begin_layout Itemize
28513 toggle MCU port pins at strategic points within your code and use an oscilloscop
28514 e.
28515  A 
28516 \emph on
28517 digital oscilloscope
28518 \emph default
28519
28520 \begin_inset LatexCommand \index{Oscilloscope}
28521
28522 \end_inset
28523
28524  with deep trace memory is really helpful especially if you have to debug
28525  a realtime application.
28526  If you need to monitor more pins than your oscilloscope provides you can
28527  sometimes get away with a small R-2R network.
28528  On a single channel oscilloscope you could f.e.
28529  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28530 k
28531 \begin_inset Formula $\Omega$
28532 \end_inset
28533
28534  resistor and the other one by a 5\InsetSpace ~
28535 k
28536 \begin_inset Formula $\Omega$
28537 \end_inset
28538
28539  resistor to the oscilloscope probe (check output drive capability of the
28540  pins you want to monitor).
28541  If you need to monitor many more pins a 
28542 \emph on
28543 logic analyzer
28544 \emph default
28545  will be handy.
28546 \end_layout
28547
28548 \begin_layout Itemize
28549 use an ICE (
28550 \emph on
28551 i
28552 \emph default
28553
28554 \emph on
28555 c
28556 \emph default
28557 ircuit 
28558 \emph on
28559 e
28560 \emph default
28561 mulator
28562 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28563
28564 \end_inset
28565
28566 ).
28567  Usually very expensive.
28568  And very nice to have too.
28569  And usually locks you (for years...) to the devices the ICE can emulate.
28570  
28571 \end_layout
28572
28573 \begin_layout Itemize
28574 use a remote debugger.
28575  In most 8-bit systems the symbol information is not available on the target,
28576  and a complete debugger is too bulky for the target system.
28577  Therefore usually a debugger on the host system connects to an on-target
28578  debugging stub which accepts only primitive commands.
28579  
28580 \newline
28581 Terms to enter into your favourite search engine could be 'remote debugging',
28582  'gdb stub' or 'inferior debugger'.
28583  (is there one?)
28584 \end_layout
28585
28586 \begin_layout Itemize
28587 use an on target hardware debugger.
28588  Some of the more modern MCUs include hardware support for setting break
28589  points and monitoring/changing variables by using dedicated hardware pins.
28590  This facility doesn't require additional code to run on the target and
28591  
28592 \emph on
28593 usually
28594 \emph default
28595  doesn't affect runtime behaviour until a breakpoint is hit.
28596  For the mcs51 most hardware debuggers use the AOMF
28597 \begin_inset LatexCommand \index{AOMF, AOMF51}
28598
28599 \end_inset
28600
28601  file (see 
28602 \begin_inset LatexCommand \ref{OMF file}
28603
28604 \end_inset
28605
28606 ) as input file.
28607  
28608 \end_layout
28609
28610 \begin_layout Standard
28611 Last not least:
28612 \end_layout
28613
28614 \begin_layout Itemize
28615 if you are not familiar with any of the following terms you're likely to
28616  run into problems rather sooner than later: 
28617 \emph on
28618 volatile
28619 \emph default
28620
28621 \emph on
28622 atomic
28623 \emph default
28624
28625 \emph on
28626 memory map
28627 \emph default
28628
28629 \emph on
28630 overlay
28631 \emph default
28632 .
28633  As an embedded programmer you 
28634 \emph on
28635 have
28636 \emph default
28637  to know them so why not look them up 
28638 \emph on
28639 before
28640 \emph default
28641  you have problems?)
28642 \end_layout
28643
28644 \begin_layout Itemize
28645 tell someone else about your problem (actually this is a surprisingly effective
28646  means to hunt down the bug even if the listener is not familiar with your
28647  environment).
28648  As 'failure to communicate' is probably one of the job-induced deformations
28649  of an embedded programmer this is highly encouraged.
28650 \end_layout
28651
28652 \begin_layout Section
28653 Debugging with SDCDB
28654 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28655
28656 \end_inset
28657
28658
28659 \begin_inset LatexCommand \index{SDCDB (debugger)}
28660
28661 \end_inset
28662
28663  
28664 \end_layout
28665
28666 \begin_layout Standard
28667 SDCC is distributed with a source level debugger
28668 \begin_inset LatexCommand \index{Debugger}
28669
28670 \end_inset
28671
28672 .
28673  The debugger uses a command line interface, the command repertoire of the
28674  debugger has been kept as close to gdb
28675 \begin_inset LatexCommand \index{gdb}
28676
28677 \end_inset
28678
28679  (the GNU debugger) as possible.
28680  The configuration and build process is part of the standard compiler installati
28681 on, which also builds and installs the debugger in the target directory
28682  specified during configuration.
28683  The debugger allows you debug BOTH at the C source and at the ASM source
28684  level.
28685 \end_layout
28686
28687 \begin_layout Subsection
28688 Compiling for Debugging
28689 \end_layout
28690
28691 \begin_layout Standard
28692 The -
28693 \begin_inset ERT
28694 status collapsed
28695
28696 \begin_layout Standard
28697
28698
28699 \backslash
28700 /
28701 \end_layout
28702
28703 \end_inset
28704
28705 -debug
28706 \begin_inset LatexCommand \index{-\/-debug}
28707
28708 \end_inset
28709
28710  option must be specified for all files for which debug information is to
28711  be generated.
28712  The compiler generates a .adb file for each of these files.
28713  The linker creates the .cdb
28714 \begin_inset LatexCommand \index{<file>.cdb}
28715
28716 \end_inset
28717
28718  file from the .adb
28719 \begin_inset LatexCommand \index{<file>.adb}
28720
28721 \end_inset
28722
28723  files and the address information.
28724  This .cdb is used by the debugger.
28725 \end_layout
28726
28727 \begin_layout Subsection
28728 How the Debugger Works
28729 \end_layout
28730
28731 \begin_layout Standard
28732 When the -
28733 \begin_inset ERT
28734 status collapsed
28735
28736 \begin_layout Standard
28737
28738
28739 \backslash
28740 /
28741 \end_layout
28742
28743 \end_inset
28744
28745 -debug option is specified the compiler generates extra symbol information
28746  some of which are put into the assembler source and some are put into the
28747  .adb file.
28748  Then the linker creates the .cdb file from the individual .adb files with
28749  the address information for the symbols.
28750  The debugger reads the symbolic information generated by the compiler &
28751  the address information generated by the linker.
28752  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28753  execution is controlled by the debugger.
28754  When a command is issued for the debugger, it translates it into appropriate
28755  commands for the simulator.
28756  (Currently SDCDM only connects to the simulator but 
28757 \emph on
28758 newcdb
28759 \emph default
28760  at 
28761 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28762
28763 \end_inset
28764
28765  is an effort to connect directly to the hardware.) 
28766 \end_layout
28767
28768 \begin_layout Subsection
28769 Starting the Debugger SDCDB
28770 \end_layout
28771
28772 \begin_layout Standard
28773 The debugger can be started using the following command line.
28774  (Assume the file you are debugging has the file name foo).
28775 \newline
28776
28777 \newline
28778
28779 \family sans
28780 \series bold
28781 sdcdb foo
28782 \newline
28783
28784 \family default
28785 \series default
28786
28787 \newline
28788 The debugger will look for the following files.
28789 \end_layout
28790
28791 \begin_layout Itemize
28792 foo.c - the source file.
28793 \end_layout
28794
28795 \begin_layout Itemize
28796 foo.cdb - the debugger symbol information file.
28797 \end_layout
28798
28799 \begin_layout Itemize
28800 foo.ihx - the Intel hex format
28801 \begin_inset LatexCommand \index{Intel hex format}
28802
28803 \end_inset
28804
28805  object file.
28806 \end_layout
28807
28808 \begin_layout Subsection
28809 SDCDB Command Line Options
28810 \end_layout
28811
28812 \begin_layout Itemize
28813 -
28814 \begin_inset ERT
28815 status collapsed
28816
28817 \begin_layout Standard
28818
28819
28820 \backslash
28821 /
28822 \end_layout
28823
28824 \end_inset
28825
28826 -directory=<source file directory> this option can used to specify the directory
28827  search list.
28828  The debugger will look into the directory list specified for source, cdb
28829  & ihx files.
28830  The items in the directory list must be separated by ':', e.g.
28831  if the source files can be in the directories /home/src1 and /home/src2,
28832  the -
28833 \begin_inset ERT
28834 status collapsed
28835
28836 \begin_layout Standard
28837
28838
28839 \backslash
28840 /
28841 \end_layout
28842
28843 \end_inset
28844
28845 -directory option should be -
28846 \begin_inset ERT
28847 status collapsed
28848
28849 \begin_layout Standard
28850
28851
28852 \backslash
28853 /
28854 \end_layout
28855
28856 \end_inset
28857
28858 -directory=/home/src1:/home/src2.
28859  Note there can be no spaces in the option.
28860  
28861 \end_layout
28862
28863 \begin_layout Itemize
28864 -cd <directory> - change to the <directory>.
28865 \end_layout
28866
28867 \begin_layout Itemize
28868 -fullname - used by GUI front ends.
28869 \end_layout
28870
28871 \begin_layout Itemize
28872 -cpu <cpu-type> - this argument is passed to the simulator please see the
28873  simulator docs for details.
28874 \end_layout
28875
28876 \begin_layout Itemize
28877 -X <Clock frequency > this options is passed to the simulator please see
28878  the simulator docs for details.
28879 \end_layout
28880
28881 \begin_layout Itemize
28882 -s <serial port file> passed to simulator see the simulator docs for details.
28883 \end_layout
28884
28885 \begin_layout Itemize
28886 -S <serial in,out> passed to simulator see the simulator docs for details.
28887 \end_layout
28888
28889 \begin_layout Itemize
28890 -k <port number> passed to simulator see the simulator docs for details.
28891 \end_layout
28892
28893 \begin_layout Subsection
28894 SDCDB Debugger Commands
28895 \end_layout
28896
28897 \begin_layout Standard
28898 As mentioned earlier the command interface for the debugger has been deliberatel
28899 y kept as close the GNU debugger gdb, as possible.
28900  This will help the integration with existing graphical user interfaces
28901  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28902  If you use a graphical user interface for the debugger you can skip this
28903  section.
28904 \end_layout
28905
28906 \begin_layout Subsubsection*
28907 break [line | file:line | function | file:function]
28908 \end_layout
28909
28910 \begin_layout Standard
28911 Set breakpoint at specified line or function:
28912 \newline
28913
28914 \newline
28915
28916 \family sans
28917 \series bold
28918 sdcdb>break 100 
28919 \newline
28920 sdcdb>break foo.c:100
28921 \newline
28922 sdcdb>break funcfoo
28923 \newline
28924 sdcdb>break foo.c:funcfoo
28925 \end_layout
28926
28927 \begin_layout Subsubsection*
28928 clear [line | file:line | function | file:function ]
28929 \end_layout
28930
28931 \begin_layout Standard
28932 Clear breakpoint at specified line or function:
28933 \newline
28934
28935 \newline
28936
28937 \family sans
28938 \series bold
28939 sdcdb>clear 100
28940 \newline
28941 sdcdb>clear foo.c:100
28942 \newline
28943 sdcdb>clear funcfoo
28944 \newline
28945 sdcdb>clear foo.c:funcfoo
28946 \end_layout
28947
28948 \begin_layout Subsubsection*
28949 continue
28950 \end_layout
28951
28952 \begin_layout Standard
28953 Continue program being debugged, after breakpoint.
28954 \end_layout
28955
28956 \begin_layout Subsubsection*
28957 finish
28958 \end_layout
28959
28960 \begin_layout Standard
28961 Execute till the end of the current function.
28962 \end_layout
28963
28964 \begin_layout Subsubsection*
28965 delete [n]
28966 \end_layout
28967
28968 \begin_layout Standard
28969 Delete breakpoint number 'n'.
28970  If used without any option clear ALL user defined break points.
28971 \end_layout
28972
28973 \begin_layout Subsubsection*
28974 info [break | stack | frame | registers ]
28975 \end_layout
28976
28977 \begin_layout Itemize
28978 info break - list all breakpoints
28979 \end_layout
28980
28981 \begin_layout Itemize
28982 info stack - show the function call stack.
28983 \end_layout
28984
28985 \begin_layout Itemize
28986 info frame - show information about the current execution frame.
28987 \end_layout
28988
28989 \begin_layout Itemize
28990 info registers - show content of all registers.
28991 \end_layout
28992
28993 \begin_layout Subsubsection*
28994 step
28995 \end_layout
28996
28997 \begin_layout Standard
28998 Step program until it reaches a different source line.
28999  Note: pressing <return> repeats the last command.
29000 \end_layout
29001
29002 \begin_layout Subsubsection*
29003 next
29004 \end_layout
29005
29006 \begin_layout Standard
29007 Step program, proceeding through subroutine calls.
29008 \end_layout
29009
29010 \begin_layout Subsubsection*
29011 run
29012 \end_layout
29013
29014 \begin_layout Standard
29015 Start debugged program.
29016 \end_layout
29017
29018 \begin_layout Subsubsection*
29019 ptype variable 
29020 \end_layout
29021
29022 \begin_layout Standard
29023 Print type information of the variable.
29024 \end_layout
29025
29026 \begin_layout Subsubsection*
29027 print variable
29028 \end_layout
29029
29030 \begin_layout Standard
29031 print value of variable.
29032 \end_layout
29033
29034 \begin_layout Subsubsection*
29035 file filename
29036 \end_layout
29037
29038 \begin_layout Standard
29039 load the given file name.
29040  Note this is an alternate method of loading file for debugging.
29041 \end_layout
29042
29043 \begin_layout Subsubsection*
29044 frame
29045 \end_layout
29046
29047 \begin_layout Standard
29048 print information about current frame.
29049 \end_layout
29050
29051 \begin_layout Subsubsection*
29052 set srcmode
29053 \end_layout
29054
29055 \begin_layout Standard
29056 Toggle between C source & assembly source.
29057 \end_layout
29058
29059 \begin_layout Subsubsection*
29060 ! simulator command
29061 \end_layout
29062
29063 \begin_layout Standard
29064 Send the string following '!' to the simulator, the simulator response is
29065  displayed.
29066  Note the debugger does not interpret the command being sent to the simulator,
29067  so if a command like 'go' is sent the debugger can loose its execution
29068  context and may display incorrect values.
29069 \end_layout
29070
29071 \begin_layout Subsubsection*
29072 quit
29073 \end_layout
29074
29075 \begin_layout Standard
29076 "Watch me now.
29077  Iam going Down.
29078  My name is Bobby Brown"
29079 \end_layout
29080
29081 \begin_layout Subsection
29082 Interfacing SDCDB with DDD
29083 \end_layout
29084
29085 \begin_layout Standard
29086 \begin_inset Note Note
29087 status collapsed
29088
29089 \begin_layout Standard
29090 The screenshot was converted from png to eps with: 
29091 \begin_inset Quotes sld
29092 \end_inset
29093
29094 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29095 \begin_inset Quotes srd
29096 \end_inset
29097
29098  which produces a pretty compact eps file which is free from compression
29099  artifacts.
29100 \end_layout
29101
29102 \begin_layout Standard
29103 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29104  as this broke the build system on Sourceforge (pdf-file was broken.
29105  pdflatex does not accept eps files).
29106 \end_layout
29107
29108 \end_inset
29109
29110
29111 \end_layout
29112
29113 \begin_layout Standard
29114 The 
29115 \emph on
29116 p
29117 \emph default
29118 ortable 
29119 \emph on
29120 n
29121 \emph default
29122 etwork 
29123 \emph on
29124 g
29125 \emph default
29126 raphics File 
29127 \size footnotesize
29128
29129 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29130
29131 \end_inset
29132
29133
29134 \size default
29135  shows a screenshot of a debugging session with DDD
29136 \begin_inset LatexCommand \index{DDD (debugger)}
29137
29138 \end_inset
29139
29140  (Unix only) on a simulated 8032.
29141  The debugging session might not run as smoothly as the screenshot suggests.
29142  The debugger allows setting of breakpoints, displaying and changing variables,
29143  single stepping through C and assembler code.
29144  
29145 \newline
29146 The source was compiled with 
29147 \family sans
29148 \series bold
29149
29150 \newline
29151
29152 \newline
29153 sdcc -
29154 \family default
29155 \series default
29156
29157 \begin_inset ERT
29158 status collapsed
29159
29160 \begin_layout Standard
29161
29162
29163 \backslash
29164 /
29165 \end_layout
29166
29167 \end_inset
29168
29169
29170 \family sans
29171 \series bold
29172 -debug ddd_example.c
29173 \family default
29174 \series default
29175  
29176 \family sans
29177 \series bold
29178
29179 \newline
29180
29181 \family default
29182 \series default
29183
29184 \newline
29185 and DDD was invoked with 
29186 \family sans
29187 \series bold
29188
29189 \newline
29190
29191 \newline
29192 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29193 \end_layout
29194
29195 \begin_layout Standard
29196 \begin_inset Note Note
29197 status open
29198
29199 \begin_layout Standard
29200 Check that the double quotes or an apostroph within the command line survive
29201  the LyX tool chain.
29202  Previously the apostrophs got slanted in the PDF output so a cut and paste
29203  did not work.
29204 \end_layout
29205
29206 \end_inset
29207
29208
29209 \end_layout
29210
29211 \begin_layout Subsection
29212 Interfacing SDCDB with XEmacs
29213 \begin_inset LatexCommand \index{XEmacs}
29214
29215 \end_inset
29216
29217
29218 \begin_inset LatexCommand \index{Emacs}
29219
29220 \end_inset
29221
29222
29223 \end_layout
29224
29225 \begin_layout Standard
29226 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29227  sdcdb.el and sdcdbsrc.el.
29228  These two files can be found in the $(prefix)/bin directory after the installat
29229 ion is complete.
29230  These files need to be loaded into XEmacs for the interface to work.
29231  This can be done at XEmacs startup time by inserting the following into
29232  your '.xemacs' file (which can be found in your HOME directory): 
29233 \newline
29234
29235 \newline
29236
29237 \family typewriter
29238 (load-file sdcdbsrc.el) 
29239 \family default
29240
29241 \newline
29242
29243 \newline
29244 .xemacs is a lisp file so the () around the command is REQUIRED.
29245  The files can also be loaded dynamically while XEmacs is running, set the
29246  environment variable 'EMACSLOADPATH' to the installation bin directory
29247  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29248  To start the interface enter the following command: 
29249 \newline
29250
29251 \newline
29252
29253 \family sans
29254 \series bold
29255 ESC-x sdcdbsrc
29256 \family default
29257 \series default
29258
29259 \newline
29260
29261 \newline
29262 You will prompted to enter the file name to be debugged.
29263  
29264 \newline
29265
29266 \newline
29267 The command line options that are passed to the simulator directly are
29268  bound to default values in the file sdcdbsrc.el.
29269  The variables are listed below, these values maybe changed as required.
29270 \end_layout
29271
29272 \begin_layout Itemize
29273 sdcdbsrc-cpu-type '51
29274 \end_layout
29275
29276 \begin_layout Itemize
29277 sdcdbsrc-frequency '11059200
29278 \end_layout
29279
29280 \begin_layout Itemize
29281 sdcdbsrc-serial nil
29282 \end_layout
29283
29284 \begin_layout Standard
29285 The following is a list of key mapping for the debugger interface.
29286 \end_layout
29287
29288 \begin_layout Standard
29289 \InsetSpace ~
29290
29291 \family typewriter
29292
29293 \newline
29294 ;;\InsetSpace ~
29295 Current Listing :: 
29296 \newline
29297 ;;key\InsetSpace ~
29298 \InsetSpace ~
29299 \InsetSpace ~
29300 \InsetSpace ~
29301 \InsetSpace ~
29302 \InsetSpace ~
29303 \InsetSpace ~
29304 \InsetSpace ~
29305 \InsetSpace ~
29306 \InsetSpace ~
29307 \InsetSpace ~
29308 \InsetSpace ~
29309 \InsetSpace ~
29310 \InsetSpace ~
29311 binding\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 Comment 
29334 \newline
29335 ;;---\InsetSpace ~
29336 \InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 \InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 \InsetSpace ~
29347 \InsetSpace ~
29348 \InsetSpace ~
29349 -------\InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 \InsetSpace ~
29364 \InsetSpace ~
29365 \InsetSpace ~
29366 \InsetSpace ~
29367 \InsetSpace ~
29368 \InsetSpace ~
29369 \InsetSpace ~
29370 \InsetSpace ~
29371 -------
29372 \newline
29373 ;; 
29374 \newline
29375 ;;\InsetSpace ~
29376 n\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 sdcdb-next-fro
29392 m-src\InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 \InsetSpace ~
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 SDCDB next command 
29403 \newline
29404 ;;\InsetSpace ~
29405 b\InsetSpace ~
29406 \InsetSpace ~
29407 \InsetSpace ~
29408 \InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 \InsetSpace ~
29415 \InsetSpace ~
29416 \InsetSpace ~
29417 \InsetSpace ~
29418 \InsetSpace ~
29419 \InsetSpace ~
29420 sdcdb-back-from-src\InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 \InsetSpace ~
29424 \InsetSpace ~
29425 \InsetSpace ~
29426 \InsetSpace ~
29427 \InsetSpace ~
29428 \InsetSpace ~
29429 \InsetSpace ~
29430 SDCDB back command 
29431 \newline
29432 ;;\InsetSpace ~
29433 c\InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 \InsetSpace ~
29439 \InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 \InsetSpace ~
29447 \InsetSpace ~
29448 sdcdb-cont-f
29449 rom-src\InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 \InsetSpace ~
29459 SDCDB continue command
29460 \newline
29461 ;;\InsetSpace ~
29462 s\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 sdcdb-step-from-src\InsetSpace ~
29478 \InsetSpace ~
29479 \InsetSpace ~
29480 \InsetSpace ~
29481 \InsetSpace ~
29482 \InsetSpace ~
29483 \InsetSpace ~
29484 \InsetSpace ~
29485 \InsetSpace ~
29486 \InsetSpace ~
29487 SDCDB step command 
29488 \newline
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 \InsetSpace ~
29504 \InsetSpace ~
29505 sdcdb-w
29506 hatis-c-sexp\InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 \InsetSpace ~
29516 SDCDB ptypecommand for data at 
29517 \newline
29518 ;;\InsetSpace ~
29519 \InsetSpace ~
29520 \InsetSpace ~
29521 \InsetSpace ~
29522 \InsetSpace ~
29523 \InsetSpace ~
29524 \InsetSpace ~
29525 \InsetSpace ~
29526 \InsetSpace ~
29527 \InsetSpace ~
29528 \InsetSpace ~
29529 \InsetSpace ~
29530 \InsetSpace ~
29531 \InsetSpace ~
29532 \InsetSpace ~
29533 \InsetSpace ~
29534 \InsetSpace ~
29535 \InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 \InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 \InsetSpace ~
29544 \InsetSpace ~
29545 \InsetSpace ~
29546 \InsetSpace ~
29547 \InsetSpace ~
29548 \InsetSpace ~
29549 \InsetSpace ~
29550 \InsetSpace ~
29551 \InsetSpace ~
29552 \InsetSpace ~
29553 \InsetSpace ~
29554 \InsetSpace ~
29555 \InsetSpace ~
29556 \InsetSpace ~
29557 \InsetSpace ~
29558 \InsetSpace ~
29559 \InsetSpace ~
29560 \InsetSpace ~
29561 \InsetSpace ~
29562 \InsetSpace ~
29563 \InsetSpace ~
29564 \InsetSpace ~
29565 buffer point 
29566 \newline
29567 ;;\InsetSpace ~
29568 x\InsetSpace ~
29569 \InsetSpace ~
29570 \InsetSpace ~
29571 \InsetSpace ~
29572 \InsetSpace ~
29573 \InsetSpace ~
29574 \InsetSpace ~
29575 \InsetSpace ~
29576 \InsetSpace ~
29577 \InsetSpace ~
29578 \InsetSpace ~
29579 \InsetSpace ~
29580 \InsetSpace ~
29581 \InsetSpace ~
29582 \InsetSpace ~
29583 sdcdbsrc-delete\InsetSpace ~
29584 \InsetSpace ~
29585 \InsetSpace ~
29586 \InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 \InsetSpace ~
29592 \InsetSpace ~
29593 \InsetSpace ~
29594 \InsetSpace ~
29595 \InsetSpace ~
29596 \InsetSpace ~
29597 SDCD
29598 B Delete all breakpoints if no arg 
29599 \newline
29600 ;;\InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 \InsetSpace ~
29618 \InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 given or delete arg (C-u arg x) 
29648 \newline
29649 ;;\InsetSpace ~
29650 m\InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 \InsetSpace ~
29658 \InsetSpace ~
29659 \InsetSpace ~
29660 \InsetSpace ~
29661 \InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 sdcdbsrc
29666 -frame\InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 \InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 SDCDB Display current frame if no arg, 
29682 \newline
29683 ;;\InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 \InsetSpace ~
29687 \InsetSpace ~
29688 \InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 \InsetSpace ~
29692 \InsetSpace ~
29693 \InsetSpace ~
29694 \InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 \InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 \InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 given or display frame arg
29731  
29732 \newline
29733 ;;\InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 \InsetSpace ~
29751 \InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
29761 \InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 buffer point 
29781 \newline
29782 ;;\InsetSpace ~
29783 !\InsetSpace ~
29784 \InsetSpace ~
29785 \InsetSpace ~
29786 \InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 \InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 sdcdbsrc-goto-sdcdb\InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 \InsetSpace ~
29808 Goto the SDCDB output buffer 
29809 \newline
29810 ;;\InsetSpace ~
29811 p\InsetSpace ~
29812 \InsetSpace ~
29813 \InsetSpace ~
29814 \InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 \InsetSpace ~
29819 \InsetSpace ~
29820 \InsetSpace ~
29821 \InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 sdcdb-prin
29827 t-c-sexp\InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 \InsetSpace ~
29837 \InsetSpace ~
29838 SDCDB print command for data at 
29839 \newline
29840 ;;\InsetSpace ~
29841 \InsetSpace ~
29842 \InsetSpace ~
29843 \InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 \InsetSpace ~
29847 \InsetSpace ~
29848 \InsetSpace ~
29849 \InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 \InsetSpace ~
29867 \InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 buffer point 
29888 \newline
29889 ;;\InsetSpace ~
29890 g\InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 sdcdbsrc-goto-sdcdb\InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 Got
29916 o the SDCDB output buffer 
29917 \newline
29918 ;;\InsetSpace ~
29919 t\InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 sdcdbsrc-mode\InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 \InsetSpace ~
29945 \InsetSpace ~
29946 \InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 Toggles Sdcdbsrc mode (turns it
29951  off) 
29952 \newline
29953 ;; 
29954 \newline
29955 ;;\InsetSpace ~
29956 C-c\InsetSpace ~
29957 C-f\InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 sdcdb-finish-from-src\InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 SDCDB finish command 
29975 \newline
29976 ;; 
29977 \newline
29978 ;;\InsetSpace ~
29979 C-x\InsetSpace ~
29980 SPC\InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 sdcdb-brea
29990 k\InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 Set break for line with point 
30009 \newline
30010 ;;\InsetSpace ~
30011 ESC\InsetSpace ~
30012 t\InsetSpace ~
30013 \InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 sdcdbsrc-mode\InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 Toggle Sdcdbsrc mode 
30040 \newline
30041 ;;\InsetSpace ~
30042 ESC\InsetSpace ~
30043 m\InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046 \InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 sdc
30055 dbsrc-srcmode\InsetSpace ~
30056 \InsetSpace ~
30057 \InsetSpace ~
30058 \InsetSpace ~
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 \InsetSpace ~
30063 \InsetSpace ~
30064 \InsetSpace ~
30065 \InsetSpace ~
30066 \InsetSpace ~
30067 \InsetSpace ~
30068 Toggle list mode 
30069 \newline
30070 ;; 
30071 \newline
30072
30073 \family default
30074
30075 \newpage
30076
30077 \end_layout
30078
30079 \begin_layout Chapter
30080 TIPS
30081 \end_layout
30082
30083 \begin_layout Standard
30084 Here are a few guidelines that will help the compiler generate more efficient
30085  code, some of the tips are specific to this compiler others are generally
30086  good programming practice.
30087 \end_layout
30088
30089 \begin_layout Itemize
30090 Use the smallest data type to represent your data-value.
30091  If it is known in advance that the value is going to be less than 256 then
30092  use an 'unsigned char' instead of a 'short' or 'int'.
30093  Please note, that ANSI C requires both signed and unsigned chars to be
30094  promoted to 'signed int'
30095 \begin_inset LatexCommand \index{promotion to signed int}
30096
30097 \end_inset
30098
30099
30100 \begin_inset Marginal
30101 status collapsed
30102
30103 \begin_layout Standard
30104
30105 \series bold
30106 \InsetSpace ~
30107 !
30108 \end_layout
30109
30110 \end_inset
30111
30112  before doing any operation.
30113  This promotion
30114 \begin_inset LatexCommand \index{type promotion}
30115
30116 \end_inset
30117
30118
30119 \begin_inset LatexCommand \label{type promotion}
30120
30121 \end_inset
30122
30123  can be omitted, if the result is the same.
30124  The effect of the promotion rules together with the sign-extension is often
30125  surprising:
30126 \end_layout
30127
30128 \begin_deeper
30129 \begin_layout Verse
30130
30131 \family typewriter
30132 unsigned char uc = 0xfe;
30133 \newline
30134 if (uc * uc < 0) /* this is true! */
30135 \newline
30136 {
30137 \newline
30138 \InsetSpace ~
30139 \InsetSpace ~
30140 \InsetSpace ~
30141 \InsetSpace ~
30142 ....
30143 \newline
30144 }
30145 \end_layout
30146
30147 \begin_layout Standard
30148
30149 \family typewriter
30150 uc * uc
30151 \family default
30152  is evaluated as 
30153 \family typewriter
30154 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30155 \family default
30156 .
30157  
30158 \newline
30159 Another one:
30160 \end_layout
30161
30162 \begin_layout Verse
30163
30164 \family typewriter
30165 (unsigned char) -12 / (signed char) -3 = ...
30166 \end_layout
30167
30168 \begin_layout Standard
30169 No, the result is not 4:
30170 \end_layout
30171
30172 \begin_layout Verse
30173
30174 \family typewriter
30175 (int) (unsigned char) -12 / (int) (signed char) -3 =
30176 \newline
30177 (int) (unsigned char)
30178  0xf4 / (int) (signed char) 0xfd =
30179 \newline
30180 (int) 0x00f4 / (int) 0xfffd =
30181 \newline
30182 (int) 0x00f4
30183  / (int) 0xfffd =
30184 \newline
30185 (int) 244 / (int) -3 =
30186 \newline
30187 (int) -81 = (int) 0xffaf;
30188 \end_layout
30189
30190 \begin_layout Standard
30191 Don't complain, that gcc gives you a different result.
30192  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30193  Therefore the results are different.
30194 \newline
30195 From 
30196 \begin_inset Quotes sld
30197 \end_inset
30198
30199 comp.lang.c FAQ
30200 \begin_inset Quotes srd
30201 \end_inset
30202
30203 :
30204 \end_layout
30205
30206 \begin_layout Quote
30207
30208 \emph on
30209 If well-defined overflow characteristics are important and negative values
30210  are not, or if you want to steer clear of sign-extension problems when
30211  manipulating bits or bytes, use one of the corresponding unsigned types.
30212  (Beware when mixing signed and unsigned values in expressions, though.)
30213 \newline
30214 Although
30215  character types (especially unsigned char) can be used as "tiny" integers,
30216  doing so is sometimes more trouble than it's worth, due to unpredictable
30217  sign extension and increased code size.
30218 \end_layout
30219
30220 \end_deeper
30221 \begin_layout Itemize
30222 Use unsigned when it is known in advance that the value is not going to
30223  be negative.
30224  This helps especially if you are doing division or multiplication, bit-shifting
30225  or are using an array index.
30226 \end_layout
30227
30228 \begin_layout Itemize
30229 NEVER jump into a LOOP.
30230 \end_layout
30231
30232 \begin_layout Itemize
30233 Declare the variables to be local
30234 \begin_inset LatexCommand \index{local variables}
30235
30236 \end_inset
30237
30238  whenever possible, especially loop control variables (induction).
30239 \end_layout
30240
30241 \begin_layout Itemize
30242 Have a look at the assembly listing to get a 
30243 \begin_inset Quotes sld
30244 \end_inset
30245
30246 feeling
30247 \begin_inset Quotes srd
30248 \end_inset
30249
30250  for the code generation.
30251 \end_layout
30252
30253 \begin_layout Section
30254 Porting code from or to other compilers
30255 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30256
30257 \end_inset
30258
30259
30260 \end_layout
30261
30262 \begin_layout Itemize
30263 check whether endianness of the compilers differs and adapt where needed.
30264 \end_layout
30265
30266 \begin_layout Itemize
30267 check the device specific header files
30268 \begin_inset LatexCommand \index{Header files}
30269
30270 \end_inset
30271
30272
30273 \begin_inset LatexCommand \index{Include files}
30274
30275 \end_inset
30276
30277  for compiler specific syntax.
30278  Eventually include the file <compiler.h
30279 \begin_inset LatexCommand \index{compiler.h (include file)}
30280
30281 \end_inset
30282
30283
30284 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30285
30286 \end_inset
30287
30288  to allow using common header files.
30289  (see f.e.
30290  cc2510fx.h 
30291 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30292
30293 \end_inset
30294
30295 ).
30296 \end_layout
30297
30298 \begin_layout Itemize
30299 check whether the startup code contains the correct initialization (watchdog,
30300  peripherals).
30301 \end_layout
30302
30303 \begin_layout Itemize
30304 check whether the sizes of short, int, long match.
30305 \end_layout
30306
30307 \begin_layout Itemize
30308 check if some 16 or 32 bit hardware registers require a specific addressing
30309  order (least significant or most significant byte first) and adapt if needed
30310  (
30311 \emph on
30312 first
30313 \emph default
30314  and 
30315 \emph on
30316 last
30317 \emph default
30318  relate to time and not to lower/upper memory location here, so this is
30319  
30320 \emph on
30321 not
30322 \emph default
30323  the same as endianness).
30324 \end_layout
30325
30326 \begin_layout Itemize
30327 check whether the keyword 
30328 \emph on
30329 volatile
30330 \emph default
30331  is used where needed.
30332  The compilers might differ in their optimization characteristics (as different
30333  versions of the same compiler might also use more clever optimizations
30334  this is good idea anyway).
30335  See section 
30336 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30337
30338 \end_inset
30339
30340 .
30341 \end_layout
30342
30343 \begin_layout Itemize
30344 check that the compilers are not told to supress warnings.
30345 \end_layout
30346
30347 \begin_layout Itemize
30348 check and convert compiler specific extensions (interrupts, memory areas,
30349  pragmas etc.).
30350 \end_layout
30351
30352 \begin_layout Itemize
30353 check for differences in type promotion.
30354  Especially check for math operations on 
30355 \family typewriter
30356 char
30357 \family default
30358  or 
30359 \family typewriter
30360 unsigned char
30361 \family default
30362  variables.
30363  For the sake of C99 compatibility SDCC will probably promote these to 
30364 \family typewriter
30365 int
30366 \family default
30367  more often than other compilers.
30368  Eventually insert explicit casts to 
30369 \family typewriter
30370 (char) 
30371 \family default
30372 or
30373 \family typewriter
30374  (unsigned char)
30375 \family default
30376 .
30377  Also check that the ~\InsetSpace ~
30378 operator
30379 \begin_inset LatexCommand \index{\~\/ Operator}
30380
30381 \end_inset
30382
30383  is not used on 
30384 \family typewriter
30385 bit
30386 \begin_inset LatexCommand \index{bit}
30387
30388 \end_inset
30389
30390
30391 \family default
30392  variables, use the !\InsetSpace ~
30393 operator instead.
30394  See sections 
30395 \begin_inset LatexCommand \ref{type promotion}
30396
30397 \end_inset
30398
30399  and 
30400 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30401
30402 \end_inset
30403
30404 .
30405 \end_layout
30406
30407 \begin_layout Itemize
30408 check the assembly code generated for interrupt routines (f.e.
30409  for calls to possibly non-reentrant library functions).
30410 \end_layout
30411
30412 \begin_layout Itemize
30413 check whether timing loops result in proper timing (or preferably consider
30414  a rewrite of the code with timer based delays instead).
30415 \end_layout
30416
30417 \begin_layout Itemize
30418 check for differences in printf parameters (some compilers push (va_arg
30419 \begin_inset LatexCommand \index{vararg, va\_arg}
30420
30421 \end_inset
30422
30423 ) char variables as 
30424 \family typewriter
30425 int
30426 \family default
30427  others push them as 
30428 \family typewriter
30429 char
30430 \family default
30431 .
30432  See section 
30433 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30434
30435 \end_inset
30436
30437 ).
30438 \end_layout
30439
30440 \begin_layout Itemize
30441 check the resulting memory map
30442 \begin_inset LatexCommand \index{Memory map}
30443
30444 \end_inset
30445
30446 .
30447  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30448 ly idata, pdata, xdata).
30449  Eventually check if unexpected library functions are included.
30450 \end_layout
30451
30452 \begin_layout Section
30453 Tools
30454 \begin_inset LatexCommand \index{Tools}
30455
30456 \end_inset
30457
30458  included in the distribution
30459 \end_layout
30460
30461 \begin_layout Standard
30462 \align left
30463 \begin_inset Tabular
30464 <lyxtabular version="3" rows="12" columns="3">
30465 <features>
30466 <column alignment="left" valignment="top" leftline="true" width="0pt">
30467 <column alignment="left" valignment="top" leftline="true" width="0pt">
30468 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30469 <row topline="true" bottomline="true">
30470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30471 \begin_inset Text
30472
30473 \begin_layout Standard
30474
30475 \series bold
30476 Name
30477 \end_layout
30478
30479 \end_inset
30480 </cell>
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30482 \begin_inset Text
30483
30484 \begin_layout Standard
30485
30486 \series bold
30487 Purpose
30488 \end_layout
30489
30490 \end_inset
30491 </cell>
30492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30493 \begin_inset Text
30494
30495 \begin_layout Standard
30496
30497 \series bold
30498 Directory
30499 \end_layout
30500
30501 \end_inset
30502 </cell>
30503 </row>
30504 <row topline="true">
30505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30506 \begin_inset Text
30507
30508 \begin_layout Standard
30509 uCsim
30510 \begin_inset LatexCommand \index{uCsim}
30511
30512 \end_inset
30513
30514
30515 \end_layout
30516
30517 \end_inset
30518 </cell>
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30520 \begin_inset Text
30521
30522 \begin_layout Standard
30523 Simulator for various architectures
30524 \end_layout
30525
30526 \end_inset
30527 </cell>
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30529 \begin_inset Text
30530
30531 \begin_layout Standard
30532 sdcc/sim/ucsim
30533 \end_layout
30534
30535 \end_inset
30536 </cell>
30537 </row>
30538 <row topline="true">
30539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30540 \begin_inset Text
30541
30542 \begin_layout Standard
30543 keil2sdcc.pl
30544 \end_layout
30545
30546 \end_inset
30547 </cell>
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30549 \begin_inset Text
30550
30551 \begin_layout Standard
30552 header file
30553 \begin_inset LatexCommand \index{Header files}
30554
30555 \end_inset
30556
30557
30558 \begin_inset LatexCommand \index{Include files}
30559
30560 \end_inset
30561
30562  conversion
30563 \end_layout
30564
30565 \end_inset
30566 </cell>
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30568 \begin_inset Text
30569
30570 \begin_layout Standard
30571 sdcc/support/scripts
30572 \end_layout
30573
30574 \end_inset
30575 </cell>
30576 </row>
30577 <row topline="true">
30578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30579 \begin_inset Text
30580
30581 \begin_layout Standard
30582 mh2h.c
30583 \end_layout
30584
30585 \end_inset
30586 </cell>
30587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30588 \begin_inset Text
30589
30590 \begin_layout Standard
30591 header file conversion
30592 \end_layout
30593
30594 \end_inset
30595 </cell>
30596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30597 \begin_inset Text
30598
30599 \begin_layout Standard
30600 sdcc/support/scripts
30601 \end_layout
30602
30603 \end_inset
30604 </cell>
30605 </row>
30606 <row topline="true">
30607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30608 \begin_inset Text
30609
30610 \begin_layout Standard
30611 as-gbz80
30612 \end_layout
30613
30614 \end_inset
30615 </cell>
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30617 \begin_inset Text
30618
30619 \begin_layout Standard
30620 Assembler
30621 \end_layout
30622
30623 \end_inset
30624 </cell>
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30626 \begin_inset Text
30627
30628 \begin_layout Standard
30629
30630 \family roman
30631 \series medium
30632 \shape up
30633 \size normal
30634 \emph off
30635 \bar no
30636 \noun off
30637 \color none
30638 sdcc/bin
30639 \end_layout
30640
30641 \end_inset
30642 </cell>
30643 </row>
30644 <row topline="true">
30645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30646 \begin_inset Text
30647
30648 \begin_layout Standard
30649 as-z80
30650 \end_layout
30651
30652 \end_inset
30653 </cell>
30654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30655 \begin_inset Text
30656
30657 \begin_layout Standard
30658 Assembler
30659 \end_layout
30660
30661 \end_inset
30662 </cell>
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30664 \begin_inset Text
30665
30666 \begin_layout Standard
30667
30668 \family roman
30669 \series medium
30670 \shape up
30671 \size normal
30672 \emph off
30673 \bar no
30674 \noun off
30675 \color none
30676 sdcc/bin
30677 \end_layout
30678
30679 \end_inset
30680 </cell>
30681 </row>
30682 <row topline="true">
30683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30684 \begin_inset Text
30685
30686 \begin_layout Standard
30687 asx8051
30688 \end_layout
30689
30690 \end_inset
30691 </cell>
30692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30693 \begin_inset Text
30694
30695 \begin_layout Standard
30696 Assembler
30697 \end_layout
30698
30699 \end_inset
30700 </cell>
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30702 \begin_inset Text
30703
30704 \begin_layout Standard
30705
30706 \family roman
30707 \series medium
30708 \shape up
30709 \size normal
30710 \emph off
30711 \bar no
30712 \noun off
30713 \color none
30714 sdcc/bin
30715 \end_layout
30716
30717 \end_inset
30718 </cell>
30719 </row>
30720 <row topline="true">
30721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30722 \begin_inset Text
30723
30724 \begin_layout Standard
30725 SDCDB
30726 \end_layout
30727
30728 \end_inset
30729 </cell>
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30731 \begin_inset Text
30732
30733 \begin_layout Standard
30734 Simulator
30735 \end_layout
30736
30737 \end_inset
30738 </cell>
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30740 \begin_inset Text
30741
30742 \begin_layout Standard
30743
30744 \family roman
30745 \series medium
30746 \shape up
30747 \size normal
30748 \emph off
30749 \bar no
30750 \noun off
30751 \color none
30752 sdcc/bin
30753 \end_layout
30754
30755 \end_inset
30756 </cell>
30757 </row>
30758 <row topline="true">
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30760 \begin_inset Text
30761
30762 \begin_layout Standard
30763 aslink
30764 \end_layout
30765
30766 \end_inset
30767 </cell>
30768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30769 \begin_inset Text
30770
30771 \begin_layout Standard
30772 Linker
30773 \end_layout
30774
30775 \end_inset
30776 </cell>
30777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30778 \begin_inset Text
30779
30780 \begin_layout Standard
30781
30782 \family roman
30783 \series medium
30784 \shape up
30785 \size normal
30786 \emph off
30787 \bar no
30788 \noun off
30789 \color none
30790 sdcc/bin
30791 \end_layout
30792
30793 \end_inset
30794 </cell>
30795 </row>
30796 <row topline="true">
30797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30798 \begin_inset Text
30799
30800 \begin_layout Standard
30801 link-z80
30802 \end_layout
30803
30804 \end_inset
30805 </cell>
30806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30807 \begin_inset Text
30808
30809 \begin_layout Standard
30810 Linker
30811 \end_layout
30812
30813 \end_inset
30814 </cell>
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30816 \begin_inset Text
30817
30818 \begin_layout Standard
30819
30820 \family roman
30821 \series medium
30822 \shape up
30823 \size normal
30824 \emph off
30825 \bar no
30826 \noun off
30827 \color none
30828 sdcc/bin
30829 \end_layout
30830
30831 \end_inset
30832 </cell>
30833 </row>
30834 <row topline="true">
30835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30836 \begin_inset Text
30837
30838 \begin_layout Standard
30839 link-gbz80
30840 \end_layout
30841
30842 \end_inset
30843 </cell>
30844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30845 \begin_inset Text
30846
30847 \begin_layout Standard
30848 Linker
30849 \end_layout
30850
30851 \end_inset
30852 </cell>
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30854 \begin_inset Text
30855
30856 \begin_layout Standard
30857
30858 \family roman
30859 \series medium
30860 \shape up
30861 \size normal
30862 \emph off
30863 \bar no
30864 \noun off
30865 \color none
30866 sdcc/bin
30867 \end_layout
30868
30869 \end_inset
30870 </cell>
30871 </row>
30872 <row topline="true" bottomline="true">
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30874 \begin_inset Text
30875
30876 \begin_layout Standard
30877 packihx
30878 \end_layout
30879
30880 \end_inset
30881 </cell>
30882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30883 \begin_inset Text
30884
30885 \begin_layout Standard
30886 Intel Hex packer 
30887 \begin_inset LatexCommand \index{packihx (tool)}
30888
30889 \end_inset
30890
30891
30892 \end_layout
30893
30894 \end_inset
30895 </cell>
30896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30897 \begin_inset Text
30898
30899 \begin_layout Standard
30900
30901 \family roman
30902 \series medium
30903 \shape up
30904 \size normal
30905 \emph off
30906 \bar no
30907 \noun off
30908 \color none
30909 sdcc/bin
30910 \end_layout
30911
30912 \end_inset
30913 </cell>
30914 </row>
30915 </lyxtabular>
30916
30917 \end_inset
30918
30919
30920 \newline
30921
30922 \end_layout
30923
30924 \begin_layout Section
30925 Documentation
30926 \begin_inset LatexCommand \index{Documentation}
30927
30928 \end_inset
30929
30930  included in the distribution
30931 \end_layout
30932
30933 \begin_layout Standard
30934 \align left
30935 \begin_inset Tabular
30936 <lyxtabular version="3" rows="10" columns="2">
30937 <features>
30938 <column alignment="block" valignment="top" leftline="true" width="40col%">
30939 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30940 <row topline="true" bottomline="true" endhead="true">
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \begin_layout Standard
30945
30946 \series bold
30947 Subject / Title
30948 \end_layout
30949
30950 \end_inset
30951 </cell>
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30953 \begin_inset Text
30954
30955 \begin_layout Standard
30956
30957 \series bold
30958 Filename / Where to get
30959 \end_layout
30960
30961 \end_inset
30962 </cell>
30963 </row>
30964 <row topline="true">
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30966 \begin_inset Text
30967
30968 \begin_layout Standard
30969 SDCC Compiler User Guide
30970 \end_layout
30971
30972 \end_inset
30973 </cell>
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30975 \begin_inset Text
30976
30977 \begin_layout Standard
30978 You're reading it right now
30979 \emph on
30980  \InsetSpace ~
30981 \InsetSpace ~
30982 \InsetSpace ~
30983
30984 \hfill
30985 online at:
30986 \emph default
30987
30988 \newline
30989
30990 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30991
30992 \end_inset
30993
30994
30995 \end_layout
30996
30997 \end_inset
30998 </cell>
30999 </row>
31000 <row topline="true">
31001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31002 \begin_inset Text
31003
31004 \begin_layout Standard
31005 Changelog of SDCC
31006 \end_layout
31007
31008 \end_inset
31009 </cell>
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31011 \begin_inset Text
31012
31013 \begin_layout Standard
31014 sdcc/Changelog
31015 \emph on
31016  \InsetSpace ~
31017 \InsetSpace ~
31018 \InsetSpace ~
31019
31020 \hfill
31021 online at:
31022 \emph default
31023
31024 \newline
31025
31026 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31027
31028 \end_inset
31029
31030
31031 \end_layout
31032
31033 \end_inset
31034 </cell>
31035 </row>
31036 <row topline="true">
31037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 \begin_inset Text
31039
31040 \begin_layout Standard
31041 ASXXXX
31042 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31043
31044 \end_inset
31045
31046
31047 \begin_inset LatexCommand \index{Assembler documentation}
31048
31049 \end_inset
31050
31051  Assemblers and
31052 \newline
31053 ASLINK
31054 \begin_inset LatexCommand \index{aslink}
31055
31056 \end_inset
31057
31058
31059 \begin_inset LatexCommand \index{Linker documentation}
31060
31061 \end_inset
31062
31063  Relocating Linker
31064 \end_layout
31065
31066 \end_inset
31067 </cell>
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31069 \begin_inset Text
31070
31071 \begin_layout Standard
31072 sdcc/as/doc/asxhtm.html 
31073 \emph on
31074 \InsetSpace ~
31075 \InsetSpace ~
31076 \InsetSpace ~
31077
31078 \hfill
31079 online at:
31080 \emph default
31081
31082 \newline
31083
31084 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31085
31086 \end_inset
31087
31088
31089 \end_layout
31090
31091 \end_inset
31092 </cell>
31093 </row>
31094 <row topline="true">
31095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31096 \begin_inset Text
31097
31098 \begin_layout Standard
31099 SDCC regression test
31100 \begin_inset LatexCommand \index{Regression test}
31101
31102 \end_inset
31103
31104
31105 \end_layout
31106
31107 \end_inset
31108 </cell>
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31110 \begin_inset Text
31111
31112 \begin_layout Standard
31113 sdcc/doc/test_suite_spec.pdf 
31114 \emph on
31115 \InsetSpace ~
31116 \InsetSpace ~
31117 \InsetSpace ~
31118
31119 \hfill
31120 online at:
31121 \emph default
31122
31123 \newline
31124
31125 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31126
31127 \end_inset
31128
31129
31130 \end_layout
31131
31132 \end_inset
31133 </cell>
31134 </row>
31135 <row topline="true">
31136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31137 \begin_inset Text
31138
31139 \begin_layout Standard
31140 Various notes
31141 \end_layout
31142
31143 \end_inset
31144 </cell>
31145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31146 \begin_inset Text
31147
31148 \begin_layout Standard
31149 sdcc/doc/* 
31150 \emph on
31151 \InsetSpace ~
31152 \InsetSpace ~
31153 \InsetSpace ~
31154
31155 \hfill
31156 online at:
31157 \emph default
31158
31159 \newline
31160
31161 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31162
31163 \end_inset
31164
31165
31166 \end_layout
31167
31168 \end_inset
31169 </cell>
31170 </row>
31171 <row topline="true">
31172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31173 \begin_inset Text
31174
31175 \begin_layout Standard
31176 Notes on debugging with SDCDB
31177 \begin_inset LatexCommand \index{SDCDB (debugger)}
31178
31179 \end_inset
31180
31181
31182 \end_layout
31183
31184 \end_inset
31185 </cell>
31186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31187 \begin_inset Text
31188
31189 \begin_layout Standard
31190 sdcc/debugger/README 
31191 \emph on
31192 \InsetSpace ~
31193 \InsetSpace ~
31194 \InsetSpace ~
31195
31196 \hfill
31197 online at
31198 \emph default
31199 :
31200 \newline
31201
31202 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31203
31204 \end_inset
31205
31206
31207 \end_layout
31208
31209 \end_inset
31210 </cell>
31211 </row>
31212 <row topline="true">
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \begin_layout Standard
31217 uCsim
31218 \begin_inset LatexCommand \index{uCsim}
31219
31220 \end_inset
31221
31222  Software simulator for microcontrollers
31223 \end_layout
31224
31225 \end_inset
31226 </cell>
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31228 \begin_inset Text
31229
31230 \begin_layout Standard
31231
31232 \family roman
31233 \series medium
31234 \shape up
31235 \size normal
31236 \emph off
31237 \bar no
31238 \noun off
31239 \color none
31240 sdcc/sim/ucsim/doc
31241 \family default
31242 \series default
31243 \shape default
31244 \size default
31245 \emph default
31246 \bar default
31247 \noun default
31248 /index.html 
31249 \emph on
31250 \InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253
31254 \hfill
31255 online at:
31256 \emph default
31257
31258 \newline
31259
31260 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31261
31262 \end_inset
31263
31264
31265 \end_layout
31266
31267 \end_inset
31268 </cell>
31269 </row>
31270 <row topline="true">
31271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31272 \begin_inset Text
31273
31274 \begin_layout Standard
31275 Temporary notes on the pic16
31276 \begin_inset LatexCommand \index{PIC16}
31277
31278 \end_inset
31279
31280  port
31281 \end_layout
31282
31283 \end_inset
31284 </cell>
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289 sdcc/src/pic16/NOTES 
31290 \emph on
31291 \InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294
31295 \hfill
31296 online at:
31297 \newline
31298
31299 \emph default
31300
31301 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31302
31303 \end_inset
31304
31305
31306 \end_layout
31307
31308 \end_inset
31309 </cell>
31310 </row>
31311 <row topline="true" bottomline="true">
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31313 \begin_inset Text
31314
31315 \begin_layout Standard
31316 SDCC internal documentation (debugging file format)
31317 \end_layout
31318
31319 \end_inset
31320 </cell>
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31322 \begin_inset Text
31323
31324 \begin_layout Standard
31325 sdcc/doc/
31326 \family roman
31327 \series medium
31328 \shape up
31329 \size normal
31330 \emph off
31331 \bar no
31332 \noun off
31333 \color none
31334 cdbfileformat.pd
31335 \family default
31336 \series default
31337 \shape default
31338 \size default
31339 \emph default
31340 \bar default
31341 \noun default
31342 f
31343 \emph on
31344  \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347
31348 \hfill
31349 online at:
31350 \emph default
31351
31352 \newline
31353
31354 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31355
31356 \end_inset
31357
31358
31359 \end_layout
31360
31361 \end_inset
31362 </cell>
31363 </row>
31364 </lyxtabular>
31365
31366 \end_inset
31367
31368
31369 \newline
31370
31371 \end_layout
31372
31373 \begin_layout Section
31374 Related open source tools
31375 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31376
31377 \end_inset
31378
31379
31380 \begin_inset LatexCommand \index{Related tools}
31381
31382 \end_inset
31383
31384
31385 \end_layout
31386
31387 \begin_layout Standard
31388 \align left
31389 \begin_inset Tabular
31390 <lyxtabular version="3" rows="16" columns="3">
31391 <features>
31392 <column alignment="left" valignment="top" leftline="true" width="0pt">
31393 <column alignment="block" valignment="top" leftline="true" width="30line%">
31394 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31395 <row topline="true" bottomline="true">
31396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31397 \begin_inset Text
31398
31399 \begin_layout Standard
31400
31401 \series bold
31402 Name
31403 \end_layout
31404
31405 \end_inset
31406 </cell>
31407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31408 \begin_inset Text
31409
31410 \begin_layout Standard
31411
31412 \series bold
31413 Purpose
31414 \end_layout
31415
31416 \end_inset
31417 </cell>
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31419 \begin_inset Text
31420
31421 \begin_layout Standard
31422
31423 \series bold
31424 Where to get
31425 \end_layout
31426
31427 \end_inset
31428 </cell>
31429 </row>
31430 <row topline="true">
31431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31432 \begin_inset Text
31433
31434 \begin_layout Standard
31435 gpsim
31436 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31437
31438 \end_inset
31439
31440
31441 \end_layout
31442
31443 \end_inset
31444 </cell>
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31446 \begin_inset Text
31447
31448 \begin_layout Standard
31449 PIC simulator
31450 \end_layout
31451
31452 \end_inset
31453 </cell>
31454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31455 \begin_inset Text
31456
31457 \begin_layout Standard
31458 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31459
31460 \end_inset
31461
31462
31463 \end_layout
31464
31465 \end_inset
31466 </cell>
31467 </row>
31468 <row topline="true">
31469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31470 \begin_inset Text
31471
31472 \begin_layout Standard
31473 gputils
31474 \begin_inset LatexCommand \index{gputils (pic tools)}
31475
31476 \end_inset
31477
31478
31479 \end_layout
31480
31481 \end_inset
31482 </cell>
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31484 \begin_inset Text
31485
31486 \begin_layout Standard
31487 GNU PIC utilities
31488 \end_layout
31489
31490 \end_inset
31491 </cell>
31492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31493 \begin_inset Text
31494
31495 \begin_layout Standard
31496 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31497
31498 \end_inset
31499
31500
31501 \end_layout
31502
31503 \end_inset
31504 </cell>
31505 </row>
31506 <row topline="true">
31507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31508 \begin_inset Text
31509
31510 \begin_layout Standard
31511 flP5
31512 \end_layout
31513
31514 \end_inset
31515 </cell>
31516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31517 \begin_inset Text
31518
31519 \begin_layout Standard
31520 PIC programmer
31521 \end_layout
31522
31523 \end_inset
31524 </cell>
31525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31526 \begin_inset Text
31527
31528 \begin_layout Standard
31529 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31530
31531 \end_inset
31532
31533
31534 \end_layout
31535
31536 \end_inset
31537 </cell>
31538 </row>
31539 <row topline="true">
31540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31541 \begin_inset Text
31542
31543 \begin_layout Standard
31544 ec2drv/newcdb
31545 \end_layout
31546
31547 \end_inset
31548 </cell>
31549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31550 \begin_inset Text
31551
31552 \begin_layout Standard
31553 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31554  (Unix only)
31555 \end_layout
31556
31557 \end_inset
31558 </cell>
31559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31560 \begin_inset Text
31561
31562 \begin_layout Standard
31563 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31564
31565 \end_inset
31566
31567
31568 \end_layout
31569
31570 \end_inset
31571 </cell>
31572 </row>
31573 <row topline="true">
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31575 \begin_inset Text
31576
31577 \begin_layout Standard
31578 indent
31579 \begin_inset LatexCommand \index{indent (source formatting tool)}
31580
31581 \end_inset
31582
31583
31584 \end_layout
31585
31586 \end_inset
31587 </cell>
31588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31589 \begin_inset Text
31590
31591 \begin_layout Standard
31592 Formats C source - Master of the white spaces
31593 \end_layout
31594
31595 \end_inset
31596 </cell>
31597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31598 \begin_inset Text
31599
31600 \begin_layout Standard
31601 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31602
31603 \end_inset
31604
31605
31606 \end_layout
31607
31608 \end_inset
31609 </cell>
31610 </row>
31611 <row topline="true">
31612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31613 \begin_inset Text
31614
31615 \begin_layout Standard
31616 srecord
31617 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31618
31619 \end_inset
31620
31621
31622 \end_layout
31623
31624 \end_inset
31625 </cell>
31626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31627 \begin_inset Text
31628
31629 \begin_layout Standard
31630 Object file conversion, checksumming, ...
31631 \end_layout
31632
31633 \end_inset
31634 </cell>
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31636 \begin_inset Text
31637
31638 \begin_layout Standard
31639 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31640
31641 \end_inset
31642
31643
31644 \end_layout
31645
31646 \end_inset
31647 </cell>
31648 </row>
31649 <row topline="true">
31650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31651 \begin_inset Text
31652
31653 \begin_layout Standard
31654 objdump
31655 \begin_inset LatexCommand \index{objdump (tool)}
31656
31657 \end_inset
31658
31659
31660 \end_layout
31661
31662 \end_inset
31663 </cell>
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31665 \begin_inset Text
31666
31667 \begin_layout Standard
31668 Object file conversion, ...
31669 \end_layout
31670
31671 \end_inset
31672 </cell>
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31674 \begin_inset Text
31675
31676 \begin_layout Standard
31677 Part of binutils (should be there anyway)
31678 \end_layout
31679
31680 \end_inset
31681 </cell>
31682 </row>
31683 <row topline="true">
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31685 \begin_inset Text
31686
31687 \begin_layout Standard
31688 cmon51
31689 \end_layout
31690
31691 \end_inset
31692 </cell>
31693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31694 \begin_inset Text
31695
31696 \begin_layout Standard
31697 8051 monitor (hex up-/download, single step, disassemble)
31698 \end_layout
31699
31700 \end_inset
31701 </cell>
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31703 \begin_inset Text
31704
31705 \begin_layout Standard
31706 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31707
31708 \end_inset
31709
31710
31711 \end_layout
31712
31713 \end_inset
31714 </cell>
31715 </row>
31716 <row topline="true">
31717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31718 \begin_inset Text
31719
31720 \begin_layout Standard
31721 doxygen
31722 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31723
31724 \end_inset
31725
31726
31727 \end_layout
31728
31729 \end_inset
31730 </cell>
31731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31732 \begin_inset Text
31733
31734 \begin_layout Standard
31735 Source code documentation system
31736 \end_layout
31737
31738 \end_inset
31739 </cell>
31740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31741 \begin_inset Text
31742
31743 \begin_layout Standard
31744 \begin_inset LatexCommand \url{http://www.doxygen.org}
31745
31746 \end_inset
31747
31748
31749 \end_layout
31750
31751 \end_inset
31752 </cell>
31753 </row>
31754 <row topline="true">
31755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31756 \begin_inset Text
31757
31758 \begin_layout Standard
31759 kdevelop
31760 \end_layout
31761
31762 \end_inset
31763 </cell>
31764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31765 \begin_inset Text
31766
31767 \begin_layout Standard
31768 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31769 \end_layout
31770
31771 \end_inset
31772 </cell>
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31774 \begin_inset Text
31775
31776 \begin_layout Standard
31777 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31778
31779 \end_inset
31780
31781
31782 \end_layout
31783
31784 \end_inset
31785 </cell>
31786 </row>
31787 <row topline="true">
31788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31789 \begin_inset Text
31790
31791 \begin_layout Standard
31792 paulmon
31793 \end_layout
31794
31795 \end_inset
31796 </cell>
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31798 \begin_inset Text
31799
31800 \begin_layout Standard
31801 8051 monitor (hex up-/download, single step, disassemble)
31802 \end_layout
31803
31804 \end_inset
31805 </cell>
31806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31807 \begin_inset Text
31808
31809 \begin_layout Standard
31810 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31811
31812 \end_inset
31813
31814
31815 \end_layout
31816
31817 \end_inset
31818 </cell>
31819 </row>
31820 <row topline="true">
31821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31822 \begin_inset Text
31823
31824 \begin_layout Standard
31825 splint
31826 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31827
31828 \end_inset
31829
31830
31831 \end_layout
31832
31833 \end_inset
31834 </cell>
31835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31836 \begin_inset Text
31837
31838 \begin_layout Standard
31839 Statically checks c sources (see 
31840 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31841
31842 \end_inset
31843
31844 )
31845 \end_layout
31846
31847 \end_inset
31848 </cell>
31849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31850 \begin_inset Text
31851
31852 \begin_layout Standard
31853 \begin_inset LatexCommand \url{http://www.splint.org}
31854
31855 \end_inset
31856
31857
31858 \end_layout
31859
31860 \end_inset
31861 </cell>
31862 </row>
31863 <row topline="true" bottomline="true">
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31865 \begin_inset Text
31866
31867 \begin_layout Standard
31868 ddd
31869 \begin_inset LatexCommand \index{DDD (debugger)}
31870
31871 \end_inset
31872
31873
31874 \end_layout
31875
31876 \end_inset
31877 </cell>
31878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31879 \begin_inset Text
31880
31881 \begin_layout Standard
31882 Debugger, serves nicely as GUI to SDCDB
31883 \begin_inset LatexCommand \index{SDCDB (debugger)}
31884
31885 \end_inset
31886
31887  (Unix only)
31888 \end_layout
31889
31890 \end_inset
31891 </cell>
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31893 \begin_inset Text
31894
31895 \begin_layout Standard
31896 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31897
31898 \end_inset
31899
31900
31901 \end_layout
31902
31903 \end_inset
31904 </cell>
31905 </row>
31906 <row bottomline="true">
31907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31908 \begin_inset Text
31909
31910 \begin_layout Standard
31911 d52
31912 \begin_inset LatexCommand \index{d52}
31913
31914 \end_inset
31915
31916
31917 \begin_inset LatexCommand \index{d52 (disassembler)}
31918
31919 \end_inset
31920
31921
31922 \end_layout
31923
31924 \end_inset
31925 </cell>
31926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31927 \begin_inset Text
31928
31929 \begin_layout Standard
31930 Disassembler, can count instruction cycles
31931 \begin_inset LatexCommand \index{instruction cycles (count)}
31932
31933 \end_inset
31934
31935 , use with options -pnd
31936 \end_layout
31937
31938 \end_inset
31939 </cell>
31940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31941 \begin_inset Text
31942
31943 \begin_layout Standard
31944 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31945
31946 \end_inset
31947
31948
31949 \end_layout
31950
31951 \end_inset
31952 </cell>
31953 </row>
31954 <row bottomline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31956 \begin_inset Text
31957
31958 \begin_layout Standard
31959 cmake
31960 \begin_inset LatexCommand \index{cmake}
31961
31962 \end_inset
31963
31964
31965 \end_layout
31966
31967 \end_inset
31968 </cell>
31969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31970 \begin_inset Text
31971
31972 \begin_layout Standard
31973 Cross platform build system, generates Makefiles
31974 \begin_inset LatexCommand \index{Makefile}
31975
31976 \end_inset
31977
31978  and project workspaces
31979 \begin_inset LatexCommand \index{project workspace}
31980
31981 \end_inset
31982
31983
31984 \end_layout
31985
31986 \end_inset
31987 </cell>
31988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31989 \begin_inset Text
31990
31991 \begin_layout Standard
31992 \begin_inset LatexCommand \url{http://www.cmake.org}
31993
31994 \end_inset
31995
31996  \InsetSpace ~
31997 \InsetSpace ~
31998 \InsetSpace ~
31999 \InsetSpace ~
32000 and a dedicated wiki entry: 
32001 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32002
32003 \end_inset
32004
32005
32006 \end_layout
32007
32008 \end_inset
32009 </cell>
32010 </row>
32011 </lyxtabular>
32012
32013 \end_inset
32014
32015
32016 \newline
32017
32018 \end_layout
32019
32020 \begin_layout Section
32021 Related documentation / recommended reading
32022 \end_layout
32023
32024 \begin_layout Standard
32025 \align left
32026 \begin_inset Tabular
32027 <lyxtabular version="3" rows="7" columns="3">
32028 <features>
32029 <column alignment="left" valignment="top" leftline="true" width="0pt">
32030 <column alignment="left" valignment="top" leftline="true" width="0">
32031 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32032 <row topline="true" bottomline="true">
32033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_inset Text
32035
32036 \begin_layout Standard
32037
32038 \series bold
32039 Name
32040 \end_layout
32041
32042 \end_inset
32043 </cell>
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32045 \begin_inset Text
32046
32047 \begin_layout Standard
32048
32049 \series bold
32050 Subject / Title
32051 \end_layout
32052
32053 \end_inset
32054 </cell>
32055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32056 \begin_inset Text
32057
32058 \begin_layout Standard
32059
32060 \series bold
32061 Where to get
32062 \end_layout
32063
32064 \end_inset
32065 </cell>
32066 </row>
32067 <row topline="true">
32068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32069 \begin_inset Text
32070
32071 \begin_layout Standard
32072
32073 \family roman
32074 \series medium
32075 \shape up
32076 \size normal
32077 \emph off
32078 \bar no
32079 \noun off
32080 \color none
32081 c-refcard.pdf
32082 \end_layout
32083
32084 \end_inset
32085 </cell>
32086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32087 \begin_inset Text
32088
32089 \begin_layout Standard
32090 C Reference Card
32091 \begin_inset LatexCommand \index{C Reference card}
32092
32093 \end_inset
32094
32095 , 2 pages
32096 \end_layout
32097
32098 \end_inset
32099 </cell>
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32101 \begin_inset Text
32102
32103 \begin_layout Standard
32104 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32105
32106 \end_inset
32107
32108
32109 \end_layout
32110
32111 \end_inset
32112 </cell>
32113 </row>
32114 <row topline="true">
32115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32116 \begin_inset Text
32117
32118 \begin_layout Standard
32119 c-faq
32120 \end_layout
32121
32122 \end_inset
32123 </cell>
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32125 \begin_inset Text
32126
32127 \begin_layout Standard
32128 C-FAQ
32129 \begin_inset LatexCommand \index{C FAQ}
32130
32131 \end_inset
32132
32133
32134 \end_layout
32135
32136 \end_inset
32137 </cell>
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32139 \begin_inset Text
32140
32141 \begin_layout Standard
32142 \begin_inset LatexCommand \url{http://www.c-faq.com}
32143
32144 \end_inset
32145
32146
32147 \end_layout
32148
32149 \end_inset
32150 </cell>
32151 </row>
32152 <row topline="true">
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32154 \begin_inset Text
32155
32156 \begin_layout Standard
32157 ISO/IEC 9899:TC2
32158 \end_layout
32159
32160 \end_inset
32161 </cell>
32162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32163 \begin_inset Text
32164
32165 \begin_layout Standard
32166 \begin_inset Quotes sld
32167 \end_inset
32168
32169 C-Standard
32170 \begin_inset Quotes srd
32171 \end_inset
32172
32173
32174 \end_layout
32175
32176 \end_inset
32177 </cell>
32178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32179 \begin_inset Text
32180
32181 \begin_layout Standard
32182
32183 \size footnotesize
32184 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32185
32186 \end_inset
32187
32188
32189 \end_layout
32190
32191 \end_inset
32192 </cell>
32193 </row>
32194 <row topline="true">
32195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32196 \begin_inset Text
32197
32198 \begin_layout Standard
32199 ISO/IEC DTR 18037
32200 \end_layout
32201
32202 \end_inset
32203 </cell>
32204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32205 \begin_inset Text
32206
32207 \begin_layout Standard
32208 \begin_inset Quotes sld
32209 \end_inset
32210
32211 Extensions for Embedded C
32212 \begin_inset Quotes srd
32213 \end_inset
32214
32215
32216 \end_layout
32217
32218 \end_inset
32219 </cell>
32220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32221 \begin_inset Text
32222
32223 \begin_layout Standard
32224
32225 \size footnotesize
32226 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32227
32228 \end_inset
32229
32230
32231 \end_layout
32232
32233 \end_inset
32234 </cell>
32235 </row>
32236 <row topline="true">
32237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32238 \begin_inset Text
32239
32240 \begin_layout Standard
32241
32242 \end_layout
32243
32244 \end_inset
32245 </cell>
32246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32247 \begin_inset Text
32248
32249 \begin_layout Standard
32250 Latest datasheet of target CPU
32251 \end_layout
32252
32253 \end_inset
32254 </cell>
32255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32256 \begin_inset Text
32257
32258 \begin_layout Standard
32259 vendor
32260 \end_layout
32261
32262 \end_inset
32263 </cell>
32264 </row>
32265 <row topline="true" bottomline="true">
32266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32267 \begin_inset Text
32268
32269 \begin_layout Standard
32270
32271 \end_layout
32272
32273 \end_inset
32274 </cell>
32275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32276 \begin_inset Text
32277
32278 \begin_layout Standard
32279 Revision history of datasheet
32280 \end_layout
32281
32282 \end_inset
32283 </cell>
32284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32285 \begin_inset Text
32286
32287 \begin_layout Standard
32288 vendor
32289 \end_layout
32290
32291 \end_inset
32292 </cell>
32293 </row>
32294 </lyxtabular>
32295
32296 \end_inset
32297
32298
32299 \newline
32300
32301 \end_layout
32302
32303 \begin_layout Section
32304 Application notes specifically for SDCC
32305 \end_layout
32306
32307 \begin_layout Standard
32308 SDCC makes no claims about the completeness of this list and about up-to-datenes
32309 s or correctness of the application notes
32310 \begin_inset LatexCommand \index{Application notes}
32311
32312 \end_inset
32313
32314 .
32315 \end_layout
32316
32317 \begin_layout Standard
32318 \align left
32319
32320 \size footnotesize
32321 \begin_inset Tabular
32322 <lyxtabular version="3" rows="7" columns="3">
32323 <features>
32324 <column alignment="block" valignment="top" leftline="true" width="17col%">
32325 <column alignment="block" valignment="top" leftline="true" width="27col%">
32326 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32327 <row topline="true" bottomline="true">
32328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32329 \begin_inset Text
32330
32331 \begin_layout Standard
32332
32333 \series bold
32334 \size footnotesize
32335 Vendor
32336 \end_layout
32337
32338 \end_inset
32339 </cell>
32340 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32341 \begin_inset Text
32342
32343 \begin_layout Standard
32344
32345 \series bold
32346 \size footnotesize
32347 Subject / Title
32348 \end_layout
32349
32350 \end_inset
32351 </cell>
32352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32353 \begin_inset Text
32354
32355 \begin_layout Standard
32356
32357 \series bold
32358 \size footnotesize
32359 Where to get
32360 \end_layout
32361
32362 \end_inset
32363 </cell>
32364 </row>
32365 <row topline="true">
32366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32367 \begin_inset Text
32368
32369 \begin_layout Standard
32370
32371 \size footnotesize
32372 Maxim / Dallas
32373 \end_layout
32374
32375 \end_inset
32376 </cell>
32377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32378 \begin_inset Text
32379
32380 \begin_layout Standard
32381
32382 \size footnotesize
32383 Using the SDCC Compiler for the DS80C400
32384 \begin_inset LatexCommand \index{DS80C400}
32385
32386 \end_inset
32387
32388
32389 \end_layout
32390
32391 \end_inset
32392 </cell>
32393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32394 \begin_inset Text
32395
32396 \begin_layout Standard
32397
32398 \size footnotesize
32399 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32400
32401 \end_inset
32402
32403
32404 \end_layout
32405
32406 \end_inset
32407 </cell>
32408 </row>
32409 <row topline="true">
32410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32411 \begin_inset Text
32412
32413 \begin_layout Standard
32414
32415 \size footnotesize
32416 Maxim / Dallas
32417 \end_layout
32418
32419 \end_inset
32420 </cell>
32421 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32422 \begin_inset Text
32423
32424 \begin_layout Standard
32425
32426 \size footnotesize
32427 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32428 \begin_inset LatexCommand \index{DS89C4x0}
32429
32430 \end_inset
32431
32432  Family of Microcontrollers
32433 \end_layout
32434
32435 \end_inset
32436 </cell>
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32438 \begin_inset Text
32439
32440 \begin_layout Standard
32441
32442 \size footnotesize
32443 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32444
32445 \end_inset
32446
32447
32448 \end_layout
32449
32450 \end_inset
32451 </cell>
32452 </row>
32453 <row topline="true">
32454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32455 \begin_inset Text
32456
32457 \begin_layout Standard
32458
32459 \size footnotesize
32460 Silicon Laboratories / Cygnal
32461 \end_layout
32462
32463 \end_inset
32464 </cell>
32465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32466 \begin_inset Text
32467
32468 \begin_layout Standard
32469
32470 \size footnotesize
32471 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32472 \begin_inset LatexCommand \index{IDE}
32473
32474 \end_inset
32475
32476
32477 \end_layout
32478
32479 \end_inset
32480 </cell>
32481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32482 \begin_inset Text
32483
32484 \begin_layout Standard
32485
32486 \size footnotesize
32487 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32488
32489 \end_inset
32490
32491
32492 \end_layout
32493
32494 \end_inset
32495 </cell>
32496 </row>
32497 <row topline="true">
32498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32499 \begin_inset Text
32500
32501 \begin_layout Standard
32502
32503 \size footnotesize
32504 Ramtron / Goal Semiconductor
32505 \end_layout
32506
32507 \end_inset
32508 </cell>
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32510 \begin_inset Text
32511
32512 \begin_layout Standard
32513
32514 \size footnotesize
32515 Interfacing SDCC to Syn and Textpad
32516 \end_layout
32517
32518 \end_inset
32519 </cell>
32520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32521 \begin_inset Text
32522
32523 \begin_layout Standard
32524
32525 \size footnotesize
32526 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32527
32528 \end_inset
32529
32530
32531 \end_layout
32532
32533 \end_inset
32534 </cell>
32535 </row>
32536 <row topline="true">
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 \begin_inset Text
32539
32540 \begin_layout Standard
32541
32542 \size footnotesize
32543 Ramtron / Goal Semiconductor
32544 \end_layout
32545
32546 \end_inset
32547 </cell>
32548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32549 \begin_inset Text
32550
32551 \begin_layout Standard
32552
32553 \size footnotesize
32554 Installing and Configuring SDCC and Crimson Editor 
32555 \end_layout
32556
32557 \end_inset
32558 </cell>
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32560 \begin_inset Text
32561
32562 \begin_layout Standard
32563
32564 \size footnotesize
32565 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32566
32567 \end_inset
32568
32569
32570 \end_layout
32571
32572 \end_inset
32573 </cell>
32574 </row>
32575 <row topline="true" bottomline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32577 \begin_inset Text
32578
32579 \begin_layout Standard
32580
32581 \size footnotesize
32582 Texas Instruments
32583 \end_layout
32584
32585 \end_inset
32586 </cell>
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32588 \begin_inset Text
32589
32590 \begin_layout Standard
32591
32592 \size footnotesize
32593 MSC12xx Programming with SDCC
32594 \end_layout
32595
32596 \end_inset
32597 </cell>
32598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32599 \begin_inset Text
32600
32601 \begin_layout Standard
32602
32603 \size footnotesize
32604 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32605
32606 \end_inset
32607
32608
32609 \end_layout
32610
32611 \end_inset
32612 </cell>
32613 </row>
32614 </lyxtabular>
32615
32616 \end_inset
32617
32618
32619 \end_layout
32620
32621 \begin_layout Section
32622 Some Questions
32623 \end_layout
32624
32625 \begin_layout Standard
32626 Some questions answered, some pointers given - it might be time to in turn
32627  ask 
32628 \emph on
32629 you
32630 \emph default
32631  some questions: 
32632 \end_layout
32633
32634 \begin_layout Itemize
32635 can you solve your project with the selected microcontroller? Would you
32636  find out early or rather late that your target is too small/slow/whatever?
32637  Can you switch to a slightly better device if it doesn't fit?
32638 \end_layout
32639
32640 \begin_layout Itemize
32641 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32642  and/or another programming language be more adequate? Would an operating
32643  system on the target device help?
32644 \end_layout
32645
32646 \begin_layout Itemize
32647 if you solved the problem, will the marketing department be happy?
32648 \end_layout
32649
32650 \begin_layout Itemize
32651 if the marketing department is happy, will customers be happy?
32652 \end_layout
32653
32654 \begin_layout Itemize
32655 if you're the project manager, marketing department and maybe even the customer
32656  in one person, have you tried to see the project from the outside?
32657 \end_layout
32658
32659 \begin_layout Itemize
32660 is the project done if you think it is done? Or is just that other interface/pro
32661 tocol/feature/configuration/option missing? How about website, manual(s),
32662  internationali(z|s)ation, packaging, labels, 2nd source for components,
32663  electromagnetic compatability/interference, documentation for production,
32664  production test software, update mechanism, patent issues?
32665 \end_layout
32666
32667 \begin_layout Itemize
32668 is your project adequately positioned in that magic triangle: fame, fortune,
32669  fun?
32670 \end_layout
32671
32672 \begin_layout Standard
32673 Maybe not all answers to these questions are known and some answers may
32674  even be 
32675 \emph on
32676 no
32677 \emph default
32678 , nevertheless knowing these questions may help you to avoid burnout
32679 \begin_inset Foot
32680 status open
32681
32682 \begin_layout Standard
32683 burnout is bad for electronic devices, programmers and motorcycle tyres
32684 \end_layout
32685
32686 \end_inset
32687
32688 .
32689  Chances are you didn't want to hear some of them...
32690 \end_layout
32691
32692 \begin_layout Chapter
32693 Support
32694 \begin_inset LatexCommand \index{Support}
32695
32696 \end_inset
32697
32698
32699 \end_layout
32700
32701 \begin_layout Standard
32702 SDCC has grown to be a large project.
32703  The compiler alone (without the preprocessor, assembler and linker) is
32704  well over 150,000 lines of code (blank stripped).
32705  The open source nature of this project is a key to its continued growth
32706  and support.
32707  You gain the benefit and support of many active software developers and
32708  end users.
32709  Is SDCC perfect? No, that's why we need your help.
32710  The developers take pride in fixing reported bugs.
32711  You can help by reporting the bugs and helping other SDCC users.
32712  There are lots of ways to contribute, and we encourage you to take part
32713  in making SDCC a great software package.
32714  
32715 \end_layout
32716
32717 \begin_layout Standard
32718 The SDCC project is hosted on the SDCC sourceforge site at 
32719 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32720
32721 \end_inset
32722
32723 .
32724  You'll find the complete set of mailing lists
32725 \begin_inset LatexCommand \index{Mailing list(s)}
32726
32727 \end_inset
32728
32729 , forums, bug reporting system, patch submission
32730 \begin_inset LatexCommand \index{Patch submission}
32731
32732 \end_inset
32733
32734  system, download
32735 \begin_inset LatexCommand \index{download}
32736
32737 \end_inset
32738
32739  area and Subversion code repository
32740 \begin_inset LatexCommand \index{Subversion code repository}
32741
32742 \end_inset
32743
32744  there.
32745 \end_layout
32746
32747 \begin_layout Section
32748 Reporting Bugs
32749 \begin_inset LatexCommand \index{Bug reporting}
32750
32751 \end_inset
32752
32753
32754 \begin_inset LatexCommand \index{Reporting bugs}
32755
32756 \end_inset
32757
32758
32759 \end_layout
32760
32761 \begin_layout Standard
32762 The recommended way of reporting bugs is using the infrastructure of the
32763  sourceforge site.
32764  You can follow the status of bug reports there and have an overview about
32765  the known bugs.
32766 \end_layout
32767
32768 \begin_layout Standard
32769 Bug reports are automatically forwarded to the developer mailing list and
32770  will be fixed ASAP.
32771  When reporting a bug, it is very useful to include a small test program
32772  (the smaller the better) which reproduces the problem.
32773  If you can isolate the problem by looking at the generated assembly code,
32774  this can be very helpful.
32775  Compiling your program with the -
32776 \begin_inset ERT
32777 status collapsed
32778
32779 \begin_layout Standard
32780
32781
32782 \backslash
32783 /
32784 \end_layout
32785
32786 \end_inset
32787
32788 -dumpall
32789 \begin_inset LatexCommand \index{-\/-dumpall}
32790
32791 \end_inset
32792
32793  option can sometimes be useful in locating optimization problems.
32794  When reporting a bug please make sure you:
32795 \end_layout
32796
32797 \begin_layout Enumerate
32798 Attach the code you are compiling with SDCC.
32799  
32800 \end_layout
32801
32802 \begin_layout Enumerate
32803 Specify the exact command you use to run SDCC, or attach your Makefile.
32804  
32805 \end_layout
32806
32807 \begin_layout Enumerate
32808 Specify the SDCC version (type "
32809 \family sans
32810 \series bold
32811 sdcc -v
32812 \family default
32813 \series default
32814 "), your platform, and operating system.
32815  
32816 \end_layout
32817
32818 \begin_layout Enumerate
32819 Provide an exact copy of any error message or incorrect output.
32820  
32821 \end_layout
32822
32823 \begin_layout Enumerate
32824 Put something meaningful in the subject of your message.
32825 \end_layout
32826
32827 \begin_layout Standard
32828 Please attempt to include these 5 important parts, as applicable, in all
32829  requests for support or when reporting any problems or bugs with SDCC.
32830  Though this will make your message lengthy, it will greatly improve your
32831  chance that SDCC users and developers will be able to help you.
32832  Some SDCC developers are frustrated by bug reports without code provided
32833  that they can use to reproduce and ultimately fix the problem, so please
32834  be sure to provide sample code if you are reporting a bug! 
32835 \end_layout
32836
32837 \begin_layout Standard
32838 Please have a short check that you are using a recent version of SDCC and
32839  the bug is not yet known.
32840  This is the link for reporting bugs: 
32841 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32842
32843 \end_inset
32844
32845 .
32846  With SDCC on average having more than 200 downloads
32847 \begin_inset LatexCommand \index{download}
32848
32849 \end_inset
32850
32851  on sourceforge per day
32852 \begin_inset Foot
32853 status open
32854
32855 \begin_layout Standard
32856 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32857  between 2002 and 2005.
32858  This does not include other methods of distribution.
32859 \end_layout
32860
32861 \end_inset
32862
32863  there must be some users.
32864  So it's not exactly easy to find a new bug.
32865  If you find one we need it: 
32866 \emph on
32867 reporting bugs is good
32868 \emph default
32869 .
32870 \end_layout
32871
32872 \begin_layout Section
32873 Requesting Features
32874 \begin_inset LatexCommand \label{sub:Requesting-Features}
32875
32876 \end_inset
32877
32878
32879 \begin_inset LatexCommand \index{Feature request}
32880
32881 \end_inset
32882
32883
32884 \begin_inset LatexCommand \index{Requesting features}
32885
32886 \end_inset
32887
32888
32889 \end_layout
32890
32891 \begin_layout Standard
32892 Like bug reports feature requests are forwarded to the developer mailing
32893  list.
32894  This is the link for requesting features: 
32895 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32896
32897 \end_inset
32898
32899 .
32900 \end_layout
32901
32902 \begin_layout Section
32903 Submitting patches
32904 \end_layout
32905
32906 \begin_layout Standard
32907 Like bug reports contributed patches are forwarded to the developer mailing
32908  list.
32909  This is the link for submitting patches
32910 \begin_inset LatexCommand \index{Patch submission}
32911
32912 \end_inset
32913
32914
32915 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32916
32917 \end_inset
32918
32919 .
32920 \end_layout
32921
32922 \begin_layout Standard
32923 You need to specify some parameters to the 
32924 \family typewriter
32925 diff
32926 \family default
32927  command for the patches to be useful.
32928  If you modified more than one file a patch created f.e.
32929  with 
32930 \family sans
32931 \series bold
32932
32933 \begin_inset Quotes sld
32934 \end_inset
32935
32936 diff -Naur unmodified_directory modified_directory >my_changes.patch
32937 \begin_inset Quotes srd
32938 \end_inset
32939
32940
32941 \family default
32942 \series default
32943  will be fine, otherwise 
32944 \family sans
32945 \series bold
32946
32947 \begin_inset Quotes sld
32948 \end_inset
32949
32950 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32951 \begin_inset Quotes srd
32952 \end_inset
32953
32954
32955 \series default
32956  
32957 \family default
32958 will do.
32959 \end_layout
32960
32961 \begin_layout Section
32962 Getting Help
32963 \end_layout
32964
32965 \begin_layout Standard
32966 These links should take you directly to the 
32967 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32968
32969 \end_inset
32970
32971
32972 \begin_inset Foot
32973 status open
32974
32975 \begin_layout Standard
32976 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32977  automated messages (mid 2003)
32978 \end_layout
32979
32980 \end_inset
32981
32982  and the 
32983 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32984
32985 \end_inset
32986
32987 , lists
32988 \begin_inset LatexCommand \index{Mailing list(s)}
32989
32990 \end_inset
32991
32992  and forums are archived and searchable so if you are lucky someone already
32993  had a similar problem.
32994  While mails to the lists themselves are delivered promptly their web front
32995  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32996  if you're seriously using SDCC please consider subscribing to the lists.
32997 \end_layout
32998
32999 \begin_layout Section
33000 ChangeLog
33001 \end_layout
33002
33003 \begin_layout Standard
33004 You can follow the status of the Subversion version
33005 \begin_inset LatexCommand \index{version}
33006
33007 \end_inset
33008
33009  of SDCC by watching the Changelog
33010 \begin_inset LatexCommand \index{Changelog}
33011
33012 \end_inset
33013
33014  in the Subversion repository
33015 \size footnotesize
33016  
33017 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33018
33019 \end_inset
33020
33021 .
33022 \end_layout
33023
33024 \begin_layout Section
33025 Subversion Source Code Repository
33026 \end_layout
33027
33028 \begin_layout Standard
33029 The output of 
33030 \family sans
33031 \series bold
33032 sdcc -
33033 \family default
33034
33035 \begin_inset ERT
33036 status open
33037
33038 \begin_layout Standard
33039
33040
33041 \backslash
33042 /
33043 \end_layout
33044
33045 \end_inset
33046
33047
33048 \family sans
33049 -version
33050 \family default
33051 \series default
33052  or the filenames of the snapshot versions of SDCC include date and its
33053  Subversion
33054 \begin_inset LatexCommand \index{Subversion code repository}
33055
33056 \end_inset
33057
33058  number.
33059  Subversion allows to download the source of recent or previous versions
33060  
33061 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33062
33063 \end_inset
33064
33065  (by number or by date).
33066  An on-line source code browser and detailled instructions are also available
33067  there.
33068  SDCC versions starting from 1999 up to now are available (currently the
33069  versions prior to the conversion from cvs
33070 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33071
33072 \end_inset
33073
33074  to Subversion (April 2006) are either by accessible by Subversion or by
33075  cvs).
33076 \end_layout
33077
33078 \begin_layout Section
33079 Release policy
33080 \begin_inset LatexCommand \index{Release policy}
33081
33082 \end_inset
33083
33084
33085 \end_layout
33086
33087 \begin_layout Standard
33088 Historically there often were long delays between official releases and
33089  the sourceforge download area tends to get not updated at all.
33090  Excuses in the past might have referred to problems with live range analysis,
33091  but as this was fixed a while ago, the current problem is that another
33092  excuse has to be found.
33093  Kidding aside, we have to get better there! On the other hand there are
33094  daily snapshots available at 
33095 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33096
33097 \end_inset
33098
33099 , and you can always build the very last version (hopefully with many bugs
33100  fixed, and features added) from the source code available at 
33101 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33102
33103 \end_inset
33104
33105 .
33106  The SDCC Wiki
33107 \begin_inset LatexCommand \index{wiki}
33108
33109 \end_inset
33110
33111
33112 \begin_inset LatexCommand \index{SDCC Wiki}
33113
33114 \end_inset
33115
33116  at 
33117 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33118
33119 \end_inset
33120
33121  also holds some information about past and future releases.
33122 \end_layout
33123
33124 \begin_layout Section
33125 Examples
33126 \begin_inset LatexCommand \index{Examples}
33127
33128 \end_inset
33129
33130
33131 \end_layout
33132
33133 \begin_layout Standard
33134 You'll find some small examples in the directory 
33135 \emph on
33136 sdcc/device/examples/.
33137  
33138 \emph default
33139 More examples and libraries are available at
33140 \emph on
33141  The SDCC Open Knowledge Resource 
33142 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33143
33144 \end_inset
33145
33146  
33147 \emph default
33148 web site or at 
33149 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33150
33151 \end_inset
33152
33153 .
33154 \end_layout
33155
33156 \begin_layout Standard
33157 \begin_inset Note Note
33158 status collapsed
33159
33160 \begin_layout Standard
33161 I did insert a reference to Paul's web site here although it seems rather
33162  dedicated to a specific 8032 board (I think it's okay because it f.e.
33163  shows LCD/Harddisc interface and has a free 8051 monitor.
33164  Independent 8032 board vendors face hard competition of heavily subsidized
33165  development boards anyway).
33166 \end_layout
33167
33168 \begin_layout Standard
33169 Maybe we should include some links to real world applications.
33170  Preferably pointer to pointers (one for each architecture) so this stays
33171  manageable here?
33172 \end_layout
33173
33174 \end_inset
33175
33176
33177 \end_layout
33178
33179 \begin_layout Section
33180 Quality control
33181 \begin_inset LatexCommand \label{sec:Quality-control}
33182
33183 \end_inset
33184
33185
33186 \begin_inset LatexCommand \index{Quality control}
33187
33188 \end_inset
33189
33190
33191 \end_layout
33192
33193 \begin_layout Standard
33194 The compiler is passed through snaphot build compile and build checks.
33195  The so called 
33196 \shape italic
33197 regression tests
33198 \shape default
33199
33200 \begin_inset LatexCommand \index{Regression test}
33201
33202 \end_inset
33203
33204  check that SDCC itself compiles flawlessly on several host platforms (i386,
33205  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33206  and checks the quality of the code generated by SDCC by running the code
33207  for several target platforms through simulators.
33208  The regression test suite comprises more than 100 files which expand to
33209  more than 500 test cases which include more than 4500 tests.
33210  The results of these tests are published daily on SDCC's snapshot page
33211  (click on the red or green symbols on the right side of 
33212 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33213
33214 \end_inset
33215
33216 ).
33217 \end_layout
33218
33219 \begin_layout Standard
33220 There is a separate document 
33221 \shape italic
33222 test_suite.pdf 
33223 \begin_inset LatexCommand \index{Test suite}
33224
33225 \end_inset
33226
33227
33228 \shape default
33229  
33230 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33231
33232 \end_inset
33233
33234  about the regression test suite.
33235 \end_layout
33236
33237 \begin_layout Standard
33238 You'll find the test code in the directory 
33239 \shape italic
33240 sdcc/support/regression
33241 \shape default
33242 .
33243  You can run these tests manually by running 
33244 \family sans
33245 make
33246 \family default
33247  in this directory (or f.e.
33248  
33249 \family sans
33250 \series bold
33251
33252 \begin_inset Quotes sld
33253 \end_inset
33254
33255 make test-mcs51
33256 \begin_inset Quotes srd
33257 \end_inset
33258
33259
33260 \family default
33261 \series default
33262  if you don't want to run the complete tests).
33263  The test code might also be interesting if you want to look for examples
33264 \begin_inset LatexCommand \index{Examples}
33265
33266 \end_inset
33267
33268  checking corner cases of SDCC or if you plan to submit patches
33269 \begin_inset LatexCommand \index{Patch submission}
33270
33271 \end_inset
33272
33273 .
33274 \end_layout
33275
33276 \begin_layout Standard
33277 The PIC14 port uses a different set of regression tests 
33278 \begin_inset LatexCommand \index{Regression test (PIC14)}
33279
33280 \end_inset
33281
33282 , you'll find them in the directory 
33283 \shape italic
33284 sdcc/src/regression
33285 \shape default
33286 .
33287 \end_layout
33288
33289 \begin_layout Section
33290 Use of SDCC in Education
33291 \end_layout
33292
33293 \begin_layout Standard
33294 In short: 
33295 \emph on
33296 highly
33297 \emph default
33298  encouraged
33299 \begin_inset Foot
33300 status open
33301
33302 \begin_layout Standard
33303 the phrase "use in education" might evoke the association "
33304 \emph on
33305 only
33306 \emph default
33307  fit for use in education".
33308  This connotation is not intended but nevertheless risked as the licensing
33309  of SDCC makes it difficult to offer educational discounts
33310 \end_layout
33311
33312 \end_inset
33313
33314 .
33315  If your rationales are to:
33316 \end_layout
33317
33318 \begin_layout Enumerate
33319 give students a chance to understand the 
33320 \emph on
33321 complete
33322 \emph default
33323  steps of code generation
33324 \end_layout
33325
33326 \begin_layout Enumerate
33327 have a curriculum that can be extended for years.
33328  Then you could use an fpga board as target and your curriculum will seamlessly
33329  extend from logic synthesis (
33330 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33331
33332 \end_inset
33333
33334
33335 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33336
33337 \end_inset
33338
33339 ), over assembly programming, to C to FPGA compilers (
33340 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33341
33342 \end_inset
33343
33344 ) and to C.
33345 \end_layout
33346
33347 \begin_layout Enumerate
33348 be able to insert excursions about skills like using a revision control
33349  system, submitting/applying patches, using a type-setting (as opposed to
33350  word-processing) engine LyX/LaTeX, using 
33351 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33352
33353 \end_inset
33354
33355 , following some 
33356 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33357
33358 \end_inset
33359
33360 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33361  Source Software, CPU simulation, compiler regression tests
33362 \begin_inset LatexCommand \index{Regression test}
33363
33364 \end_inset
33365
33366 .
33367  
33368 \newline
33369 And if there should be a shortage of ideas then you can always point students
33370  to the ever-growing feature request list 
33371 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33372
33373 \end_inset
33374
33375 .
33376 \end_layout
33377
33378 \begin_layout Enumerate
33379 not tie students to a specific host platform and instead allow them to use
33380  a host platform of 
33381 \emph on
33382 their
33383 \emph default
33384  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33385  and eventually 
33386 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33387
33388 \end_inset
33389
33390 )
33391 \end_layout
33392
33393 \begin_layout Enumerate
33394 not encourage students to use illegal copies of educational software
33395 \end_layout
33396
33397 \begin_layout Enumerate
33398 be immune to licensing/availability/price changes of the chosen tool chain
33399 \end_layout
33400
33401 \begin_layout Enumerate
33402 be able to change to a new target platform without having to adopt a new
33403  tool chain
33404 \end_layout
33405
33406 \begin_layout Enumerate
33407 have complete control over and insight into the tool chain
33408 \end_layout
33409
33410 \begin_layout Enumerate
33411 make your students aware about the pros and cons of open source software
33412  development
33413 \end_layout
33414
33415 \begin_layout Enumerate
33416 give back to the public as you are probably at least partially publically
33417  funded
33418 \end_layout
33419
33420 \begin_layout Enumerate
33421 give students a chance to publically prove their skills and to possibly
33422  see a world wide impact
33423 \end_layout
33424
33425 \begin_layout Standard
33426 then SDCC is probably among the first choices.
33427  Well, probably SDCC might be the only choice.
33428 \newpage
33429
33430 \end_layout
33431
33432 \begin_layout Chapter
33433 SDCC Technical Data
33434 \end_layout
33435
33436 \begin_layout Section
33437 Optimizations
33438 \begin_inset LatexCommand \index{Optimizations}
33439
33440 \end_inset
33441
33442
33443 \end_layout
33444
33445 \begin_layout Standard
33446 SDCC performs a host of standard optimizations in addition to some MCU specific
33447  optimizations.
33448  
33449 \end_layout
33450
33451 \begin_layout Subsection
33452 Sub-expression Elimination
33453 \begin_inset LatexCommand \index{Subexpression elimination}
33454
33455 \end_inset
33456
33457
33458 \end_layout
33459
33460 \begin_layout Standard
33461 The compiler does local and 
33462 \emph on
33463 g
33464 \emph default
33465 lobal 
33466 \emph on
33467 c
33468 \emph default
33469 ommon 
33470 \emph on
33471 s
33472 \emph default
33473 ubexpression 
33474 \emph on
33475 e
33476 \emph default
33477 limination, e.g.: 
33478 \end_layout
33479
33480 \begin_layout Verse
33481
33482 \family typewriter
33483 i = x + y + 1; 
33484 \newline
33485 j = x + y;
33486 \end_layout
33487
33488 \begin_layout Standard
33489 will be translated to
33490 \end_layout
33491
33492 \begin_layout Verse
33493
33494 \family typewriter
33495 iTemp = x + y; 
33496 \newline
33497 i = iTemp + 1; 
33498 \newline
33499 j = iTemp;
33500 \end_layout
33501
33502 \begin_layout Standard
33503 Some subexpressions are not as obvious as the above example, e.g.:
33504 \end_layout
33505
33506 \begin_layout Verse
33507
33508 \family typewriter
33509 a->b[i].c = 10; 
33510 \newline
33511 a->b[i].d = 11;
33512 \end_layout
33513
33514 \begin_layout Standard
33515 In this case the address arithmetic a->b[i] will be computed only once;
33516  the equivalent code in C would be.
33517 \end_layout
33518
33519 \begin_layout Verse
33520
33521 \family typewriter
33522 iTemp = a->b[i]; 
33523 \newline
33524 iTemp.c = 10; 
33525 \newline
33526 iTemp.d = 11;
33527 \end_layout
33528
33529 \begin_layout Standard
33530 The compiler will try to keep these temporary variables in registers.
33531 \end_layout
33532
33533 \begin_layout Subsection
33534 Dead-Code Elimination
33535 \begin_inset LatexCommand \index{Dead-code elimination}
33536
33537 \end_inset
33538
33539
33540 \end_layout
33541
33542 \begin_layout Verse
33543
33544 \family typewriter
33545 int global;
33546 \newline
33547
33548 \newline
33549 void f () { 
33550 \newline
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 int i; 
33554 \newline
33555 \InsetSpace ~
33556 \InsetSpace ~
33557 i = 1; \InsetSpace ~
33558 \InsetSpace ~
33559 \InsetSpace ~
33560 \InsetSpace ~
33561 \InsetSpace ~
33562 /* dead store */ 
33563 \newline
33564 \InsetSpace ~
33565 \InsetSpace ~
33566 global = 1;\InsetSpace ~
33567 /* dead
33568  store */ 
33569 \newline
33570 \InsetSpace ~
33571 \InsetSpace ~
33572 global = 2; 
33573 \newline
33574 \InsetSpace ~
33575 \InsetSpace ~
33576 return; 
33577 \newline
33578 \InsetSpace ~
33579 \InsetSpace ~
33580 global = 3;\InsetSpace ~
33581 /* unreachable */ 
33582 \newline
33583 }
33584 \end_layout
33585
33586 \begin_layout Standard
33587 will be changed to
33588 \end_layout
33589
33590 \begin_layout Verse
33591
33592 \family typewriter
33593 int global;
33594 \newline
33595
33596 \newline
33597 void f () {
33598 \newline
33599 \InsetSpace ~
33600 \InsetSpace ~
33601 global = 2; 
33602 \newline
33603 }
33604 \end_layout
33605
33606 \begin_layout Subsection
33607 Copy-Propagation
33608 \begin_inset LatexCommand \index{Copy propagation}
33609
33610 \end_inset
33611
33612
33613 \end_layout
33614
33615 \begin_layout Verse
33616
33617 \family typewriter
33618 int f() { 
33619 \newline
33620 \InsetSpace ~
33621 \InsetSpace ~
33622 int i, j; 
33623 \newline
33624 \InsetSpace ~
33625 \InsetSpace ~
33626 i = 10; 
33627 \newline
33628 \InsetSpace ~
33629 \InsetSpace ~
33630 j = i; 
33631 \newline
33632 \InsetSpace ~
33633 \InsetSpace ~
33634 return j; 
33635 \newline
33636 }
33637 \end_layout
33638
33639 \begin_layout Standard
33640 will be changed to 
33641 \end_layout
33642
33643 \begin_layout Verse
33644
33645 \family typewriter
33646 int f() { 
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 int i, j; 
33651 \newline
33652 \InsetSpace ~
33653 \InsetSpace ~
33654 i = 10; 
33655 \newline
33656 \InsetSpace ~
33657 \InsetSpace ~
33658 j = 10; 
33659 \newline
33660 \InsetSpace ~
33661 \InsetSpace ~
33662 return 10; 
33663 \newline
33664 }
33665 \end_layout
33666
33667 \begin_layout Standard
33668 Note: the dead stores created by this copy propagation will be eliminated
33669  by dead-code elimination.
33670 \end_layout
33671
33672 \begin_layout Subsection
33673 Loop Optimizations
33674 \begin_inset LatexCommand \index{Loop optimization}
33675
33676 \end_inset
33677
33678
33679 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33680
33681 \end_inset
33682
33683
33684 \end_layout
33685
33686 \begin_layout Standard
33687 Two types of loop optimizations are done by SDCC 
33688 \emph on
33689 loop invariant
33690 \emph default
33691  lifting and
33692 \emph on
33693  strength reduction
33694 \emph default
33695  of loop induction variables.
33696  In addition to the strength reduction the optimizer marks the induction
33697  variables and the register allocator tries to keep the induction variables
33698  in registers for the duration of the loop.
33699  Because of this preference of the register allocator
33700 \begin_inset LatexCommand \index{Register allocation}
33701
33702 \end_inset
33703
33704 , loop induction optimization causes an increase in register pressure, which
33705  may cause unwanted spilling of other temporary variables into the stack
33706 \begin_inset LatexCommand \index{stack}
33707
33708 \end_inset
33709
33710  / data space.
33711  The compiler will generate a warning message when it is forced to allocate
33712  extra space either on the stack or data space.
33713  If this extra space allocation is undesirable then induction optimization
33714  can be eliminated either for the entire source file (with -
33715 \begin_inset ERT
33716 status collapsed
33717
33718 \begin_layout Standard
33719
33720
33721 \backslash
33722 /
33723 \end_layout
33724
33725 \end_inset
33726
33727 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33728 noinduction
33729 \begin_inset LatexCommand \index{\#pragma noinduction}
33730
33731 \end_inset
33732
33733 .
33734 \newline
33735
33736 \newline
33737 Loop Invariant:
33738 \end_layout
33739
33740 \begin_layout Verse
33741
33742 \family typewriter
33743 for (i = 0 ; i < 100 ; i ++) 
33744 \newline
33745 \InsetSpace ~
33746 \InsetSpace ~
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 f += k + l;
33750 \end_layout
33751
33752 \begin_layout Standard
33753 changed to
33754 \end_layout
33755
33756 \begin_layout Verse
33757
33758 \family typewriter
33759 itemp = k + l; 
33760 \newline
33761 for (i = 0; i < 100; i++) 
33762 \newline
33763 \InsetSpace ~
33764 \InsetSpace ~
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 f += itemp;
33768 \end_layout
33769
33770 \begin_layout Standard
33771 As mentioned previously some loop invariants are not as apparent, all static
33772  address computations are also moved out of the loop.
33773 \newline
33774
33775 \newline
33776 Strength Reduction
33777 \begin_inset LatexCommand \index{Strength reduction}
33778
33779 \end_inset
33780
33781 , this optimization substitutes an expression by a cheaper expression:
33782 \end_layout
33783
33784 \begin_layout Verse
33785
33786 \family typewriter
33787 for (i=0;i < 100; i++)
33788 \newline
33789 \InsetSpace ~
33790 \InsetSpace ~
33791 \InsetSpace ~
33792 \InsetSpace ~
33793 ar[i*5] = i*3;
33794 \end_layout
33795
33796 \begin_layout Standard
33797 changed to
33798 \end_layout
33799
33800 \begin_layout Verse
33801
33802 \family typewriter
33803 itemp1 = 0; 
33804 \newline
33805 itemp2 = 0; 
33806 \newline
33807 for (i=0;i< 100;i++) { 
33808 \newline
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 ar[itemp1] = itemp2; 
33814 \newline
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 itemp1
33820  += 5; 
33821 \newline
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 itemp2 += 3; 
33827 \newline
33828 }
33829 \end_layout
33830
33831 \begin_layout Standard
33832 The more expensive multiplication
33833 \begin_inset LatexCommand \index{Multiplication}
33834
33835 \end_inset
33836
33837  is changed to a less expensive addition.
33838 \end_layout
33839
33840 \begin_layout Subsection
33841 Loop Reversing
33842 \begin_inset LatexCommand \index{Loop reversing}
33843
33844 \end_inset
33845
33846
33847 \end_layout
33848
33849 \begin_layout Standard
33850 This optimization is done to reduce the overhead of checking loop boundaries
33851  for every iteration.
33852  Some simple loops can be reversed and implemented using a 
33853 \begin_inset Quotes eld
33854 \end_inset
33855
33856 decrement and jump if not zero
33857 \begin_inset Quotes erd
33858 \end_inset
33859
33860  instruction.
33861  SDCC checks for the following criterion to determine if a loop is reversible
33862  (note: more sophisticated compilers use data-dependency analysis to make
33863  this determination, SDCC uses a more simple minded analysis).
33864 \end_layout
33865
33866 \begin_layout Itemize
33867 The 'for' loop is of the form 
33868 \newline
33869
33870 \newline
33871
33872 \family typewriter
33873 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33874  += 1])
33875 \newline
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 <for body>
33881 \end_layout
33882
33883 \begin_layout Itemize
33884 The <for body> does not contain 
33885 \begin_inset Quotes eld
33886 \end_inset
33887
33888 continue
33889 \begin_inset Quotes erd
33890 \end_inset
33891
33892  or 'break
33893 \begin_inset Quotes erd
33894 \end_inset
33895
33896 .
33897 \end_layout
33898
33899 \begin_layout Itemize
33900 All goto's are contained within the loop.
33901 \end_layout
33902
33903 \begin_layout Itemize
33904 No function calls within the loop.
33905 \end_layout
33906
33907 \begin_layout Itemize
33908 The loop control variable <sym> is not assigned any value within the loop
33909 \end_layout
33910
33911 \begin_layout Itemize
33912 The loop control variable does NOT participate in any arithmetic operation
33913  within the loop.
33914 \end_layout
33915
33916 \begin_layout Itemize
33917 There are NO switch statements in the loop.
33918 \end_layout
33919
33920 \begin_layout Subsection
33921 Algebraic Simplifications
33922 \end_layout
33923
33924 \begin_layout Standard
33925 SDCC does numerous algebraic simplifications, the following is a small sub-set
33926  of these optimizations.
33927 \end_layout
33928
33929 \begin_layout Verse
33930
33931 \family typewriter
33932 i = j + 0;\InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936  /* changed to: */\InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940  i = j; 
33941 \newline
33942 i /= 2;\InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949  /* changed to: */\InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953  i >>= 1; 
33954 \newline
33955 i
33956  = j - j;\InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960  /* changed to: */\InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964  i = 0; 
33965 \newline
33966 i = j / 1;\InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 \InsetSpace ~
33970  /* changed to: */\InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974  i = j;
33975 \end_layout
33976
33977 \begin_layout Standard
33978 Note the subexpressions
33979 \begin_inset LatexCommand \index{Subexpression}
33980
33981 \end_inset
33982
33983  given above are generally introduced by macro expansions or as a result
33984  of copy/constant propagation.
33985 \end_layout
33986
33987 \begin_layout Subsection
33988 'switch' Statements
33989 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33990
33991 \end_inset
33992
33993
33994 \begin_inset LatexCommand \index{switch statement}
33995
33996 \end_inset
33997
33998
33999 \end_layout
34000
34001 \begin_layout Standard
34002 SDCC can optimize switch statements to jump tables
34003 \begin_inset LatexCommand \index{jump tables}
34004
34005 \end_inset
34006
34007 .
34008  It makes the decision based on an estimate of the generated code size.
34009  SDCC is quite liberal in the requirements for jump table generation: 
34010 \end_layout
34011
34012 \begin_layout Itemize
34013 The labels need not be in order, and the starting number need not be one
34014  or zero, the case labels are in numerical sequence or not too many case
34015  labels are missing.
34016 \end_layout
34017
34018 \begin_deeper
34019 \begin_layout Verse
34020
34021 \family typewriter
34022 switch(i) {\InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 \InsetSpace ~
34044 \InsetSpace ~
34045 \InsetSpace ~
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 switch (i) { 
34049 \newline
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 case 4: ...\InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 case 0: ...
34080  
34081 \newline
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 case 5: ...\InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 case 1: ...
34112  
34113 \newline
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 case 3: ...\InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 \InsetSpace ~
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143
34144 \newline
34145 \InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 case 6: ...\InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 case 3: ...
34175  
34176 \newline
34177 \InsetSpace ~
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 case 7: ...\InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 case 4: ...
34207  
34208 \newline
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 case 8: ...\InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 case 5: ...
34239  
34240 \newline
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244 case 9: ...\InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 case 6: ...
34271  
34272 \newline
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 case 10: ...\InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281 \InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289 \InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 \InsetSpace ~
34300 \InsetSpace ~
34301 case 7: ...
34302  
34303 \newline
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 case 11: ...\InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 case 8: ...
34333  
34334 \newline
34335 }\InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 }
34372 \end_layout
34373
34374 \begin_layout Standard
34375 Both the above switch statements will be implemented using a jump-table.
34376  The example to the right side is slightly more efficient as the check for
34377  the lower boundary of the jump-table is not needed.
34378 \end_layout
34379
34380 \end_deeper
34381 \begin_layout Itemize
34382 The number of case labels is not larger than supported by the target architectur
34383 e.
34384 \end_layout
34385
34386 \begin_layout Itemize
34387 If the case labels are not in numerical sequence ('gaps' between cases)
34388  SDCC checks whether a jump table with additionally inserted dummy cases
34389  is still attractive.
34390  
34391 \end_layout
34392
34393 \begin_layout Itemize
34394 If the starting number is not zero and a check for the lower boundary of
34395  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34396  ...
34397  .
34398 \end_layout
34399
34400 \begin_layout Standard
34401 Switch statements which have large gaps in the numeric sequence or those
34402  that have too many case labels can be split into more than one switch statement
34403  for efficient code generation, e.g.:
34404 \end_layout
34405
34406 \begin_layout Verse
34407
34408 \family typewriter
34409 switch (i) { 
34410 \newline
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 case 1: ...
34414  
34415 \newline
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 case 2: ...
34419  
34420 \newline
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 case 3: ...
34424  
34425 \newline
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 case 4: ...
34429  
34430 \newline
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 case 5: ...
34434  
34435 \newline
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 case 6: ...
34439  
34440 \newline
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 case 7: ...
34444  
34445 \newline
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 case 101: ...
34449  
34450 \newline
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 case 102: ...
34454  
34455 \newline
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 case 103: ...
34459  
34460 \newline
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 case 104: ...
34464  
34465 \newline
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 case 105: ...
34469  
34470 \newline
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 case 106: ...
34474  
34475 \newline
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 case 107: ...
34479  
34480 \newline
34481 }
34482 \end_layout
34483
34484 \begin_layout Standard
34485 If the above switch statement is broken down into two switch statements
34486 \end_layout
34487
34488 \begin_layout Verse
34489
34490 \family typewriter
34491 switch (i) { 
34492 \newline
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 case 1: ...
34496  
34497 \newline
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 case 2: ...
34501  
34502 \newline
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 case 3: ...
34506  
34507 \newline
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 case 4: ...
34511  
34512 \newline
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 case 5: ...
34516  
34517 \newline
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 case 6: ...
34521  
34522 \newline
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 case 7: ...
34526  
34527 \newline
34528 }
34529 \end_layout
34530
34531 \begin_layout Standard
34532 and
34533 \end_layout
34534
34535 \begin_layout Verse
34536
34537 \family typewriter
34538 switch (i) { 
34539 \newline
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 case 101: ...
34543  
34544 \newline
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 case 102: ...
34548  
34549 \newline
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 case 103: ...
34553  
34554 \newline
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 case 104: ...
34558  
34559 \newline
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 case 105: ...
34563  
34564 \newline
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 case 106: ...
34568  
34569 \newline
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 case 107: ...
34573  
34574 \newline
34575 }
34576 \end_layout
34577
34578 \begin_layout Standard
34579 then both the switch statements will be implemented using jump-tables whereas
34580  the unmodified switch statement will not be.
34581 \end_layout
34582
34583 \begin_layout Standard
34584 \begin_inset Note Note
34585 status collapsed
34586
34587 \begin_layout Standard
34588 There might be reasons which SDCC cannot know about to either favour or
34589  not favour jump tables.
34590  If the target system has to be as quick for the last switch case as for
34591  the first (pro jump table), or if the switch argument is known to be zero
34592  in the majority of the cases (contra jump table).
34593 \end_layout
34594
34595 \end_inset
34596
34597
34598 \end_layout
34599
34600 \begin_layout Standard
34601 The pragma nojtbound
34602 \begin_inset LatexCommand \index{\#pragma nojtbound}
34603
34604 \end_inset
34605
34606  can be used to turn off checking the 
34607 \emph on
34608 j
34609 \emph default
34610 ump 
34611 \emph on
34612 t
34613 \emph default
34614 able 
34615 \emph on
34616 bound
34617 \emph default
34618 aries.
34619  It has no effect if a default label is supplied.
34620  Use of this pragma is dangerous: if the switch
34621 \begin_inset LatexCommand \index{switch statement}
34622
34623 \end_inset
34624
34625  argument is not matched by a case statement the processor will happily
34626  jump into Nirvana.
34627 \end_layout
34628
34629 \begin_layout Subsection
34630 Bit-shifting Operations
34631 \begin_inset LatexCommand \index{Bit shifting}
34632
34633 \end_inset
34634
34635 .
34636 \end_layout
34637
34638 \begin_layout Standard
34639 Bit shifting is one of the most frequently used operation in embedded programmin
34640 g.
34641  SDCC tries to implement bit-shift operations in the most efficient way
34642  possible, e.g.:
34643 \end_layout
34644
34645 \begin_layout Verse
34646
34647 \family typewriter
34648 unsigned char i;
34649 \newline
34650 ...
34651  
34652 \newline
34653 i >>= 4; 
34654 \newline
34655 ...
34656 \end_layout
34657
34658 \begin_layout Standard
34659 generates the following code:
34660 \end_layout
34661
34662 \begin_layout Verse
34663
34664 \family typewriter
34665 mov\InsetSpace ~
34666  a,_i 
34667 \newline
34668 swap a 
34669 \newline
34670 anl\InsetSpace ~
34671  a,#0x0f 
34672 \newline
34673 mov\InsetSpace ~
34674  _i,a
34675 \end_layout
34676
34677 \begin_layout Standard
34678 In general SDCC will never setup a loop if the shift count is known.
34679  Another example:
34680 \end_layout
34681
34682 \begin_layout Verse
34683
34684 \family typewriter
34685 unsigned int i; 
34686 \newline
34687 ...
34688  
34689 \newline
34690 i >>= 9; 
34691 \newline
34692 ...
34693 \end_layout
34694
34695 \begin_layout Standard
34696 will generate:
34697 \end_layout
34698
34699 \begin_layout Verse
34700
34701 \family typewriter
34702 mov\InsetSpace ~
34703 \InsetSpace ~
34704 a,(_i + 1) 
34705 \newline
34706 mov\InsetSpace ~
34707 \InsetSpace ~
34708 (_i + 1),#0x00 
34709 \newline
34710 clr\InsetSpace ~
34711 \InsetSpace ~
34712
34713 \newline
34714 rrc\InsetSpace ~
34715 \InsetSpace ~
34716
34717 \newline
34718 mov\InsetSpace ~
34719 \InsetSpace ~
34720 _i,a
34721 \end_layout
34722
34723 \begin_layout Subsection
34724 Bit-rotation
34725 \begin_inset LatexCommand \index{Bit rotation}
34726
34727 \end_inset
34728
34729
34730 \end_layout
34731
34732 \begin_layout Standard
34733 A special case of the bit-shift operation is bit rotation
34734 \begin_inset LatexCommand \index{rotating bits}
34735
34736 \end_inset
34737
34738 , SDCC recognizes the following expression to be a left bit-rotation:
34739 \end_layout
34740
34741 \begin_layout Verse
34742
34743 \family typewriter
34744 \series bold
34745 unsigned
34746 \series default
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 char i;\InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 /* unsigned is needed for rotation */ 
34761 \newline
34762 ...
34763  
34764 \newline
34765 i = ((i << 1) | (i >> 7)); 
34766 \family default
34767
34768 \newline
34769
34770 \family typewriter
34771 ...
34772 \end_layout
34773
34774 \begin_layout Standard
34775 will generate the following code:
34776 \end_layout
34777
34778 \begin_layout Verse
34779
34780 \family typewriter
34781 mov\InsetSpace ~
34782 \InsetSpace ~
34783 a,_i 
34784 \newline
34785 rl\InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788
34789 \newline
34790 mov\InsetSpace ~
34791 \InsetSpace ~
34792 _i,a
34793 \end_layout
34794
34795 \begin_layout Standard
34796 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34797 ns of this case will also be recognized as bit-rotation, i.e.: 
34798 \end_layout
34799
34800 \begin_layout Verse
34801
34802 \family typewriter
34803 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34804 \end_layout
34805
34806 \begin_layout Subsection
34807 Nibble and Byte Swapping
34808 \end_layout
34809
34810 \begin_layout Standard
34811 Other special cases of the bit-shift operations are nibble or byte swapping
34812 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34813
34814 \end_inset
34815
34816 , SDCC recognizes the following expressions:
34817 \end_layout
34818
34819 \begin_layout Verse
34820
34821 \family typewriter
34822 \series bold
34823 unsigned
34824 \series default
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 char i; 
34828 \newline
34829
34830 \series bold
34831 unsigned
34832 \series default
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 int j; 
34836 \newline
34837 ...
34838  
34839 \newline
34840 i = ((i << 4) | (i >> 4)); 
34841 \family default
34842
34843 \newline
34844
34845 \family typewriter
34846 j = ((j << 8) | (j >> 8)); 
34847 \end_layout
34848
34849 \begin_layout Standard
34850 and generates a swap instruction for the nibble swapping
34851 \begin_inset LatexCommand \index{Nibble swapping}
34852
34853 \end_inset
34854
34855  or move instructions for the byte swapping
34856 \begin_inset LatexCommand \index{Byte swapping}
34857
34858 \end_inset
34859
34860 .
34861  The 
34862 \begin_inset Quotes sld
34863 \end_inset
34864
34865 j
34866 \begin_inset Quotes srd
34867 \end_inset
34868
34869  example can be used to convert from little to big-endian or vice versa.
34870  If you want to change the endianness of a 
34871 \emph on
34872 signed
34873 \emph default
34874  integer you have to cast to 
34875 \family typewriter
34876 (unsigned int)
34877 \family default
34878  first.
34879 \end_layout
34880
34881 \begin_layout Standard
34882 Note that SDCC stores numbers in little-endian
34883 \begin_inset Foot
34884 status open
34885
34886 \begin_layout Standard
34887 Usually 8-bit processors don't care much about endianness.
34888  This is not the case for the standard 8051 which only has an instruction
34889  to increment its 
34890 \emph on
34891 dptr
34892 \emph default
34893
34894 \begin_inset LatexCommand \index{DPTR}
34895
34896 \end_inset
34897
34898 -datapointer
34899 \emph on
34900  
34901 \emph default
34902 so little-endian is the more efficient byte order.
34903 \end_layout
34904
34905 \end_inset
34906
34907
34908 \begin_inset LatexCommand \index{little-endian}
34909
34910 \end_inset
34911
34912
34913 \begin_inset LatexCommand \index{Endianness}
34914
34915 \end_inset
34916
34917  format (i.e.
34918  lowest order first).
34919 \end_layout
34920
34921 \begin_layout Subsection
34922 Highest Order Bit
34923 \begin_inset LatexCommand \index{Highest Order Bit}
34924
34925 \end_inset
34926
34927  / Any Order Bit
34928 \begin_inset LatexCommand \index{Any Order Bit}
34929
34930 \end_inset
34931
34932
34933 \end_layout
34934
34935 \begin_layout Standard
34936 It is frequently required to obtain the highest order bit of an integral
34937  type (long, int, short or char types).
34938  Also obtaining any other order bit is not uncommon.
34939  SDCC recognizes the following expressions to yield the highest order bit
34940  and generates optimized code for it, e.g.:
34941 \end_layout
34942
34943 \begin_layout Verse
34944
34945 \family typewriter
34946 unsigned int gint; 
34947 \newline
34948
34949 \newline
34950 foo () { 
34951 \newline
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 unsigned char hob1, aob1; 
34955 \newline
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 bit hob2, hob3, aob2,
34959  aob3; 
34960 \newline
34961 \InsetSpace ~
34962 \InsetSpace ~
34963 ...
34964  
34965 \newline
34966 \InsetSpace ~
34967 \InsetSpace ~
34968 hob1 = (gint >> 15) & 1; 
34969 \newline
34970 \InsetSpace ~
34971 \InsetSpace ~
34972 hob2 = (gint >> 15) & 1; 
34973 \newline
34974 \InsetSpace ~
34975 \InsetSpace ~
34976 hob3 = gint & 0x8000;
34977  
34978 \newline
34979 \InsetSpace ~
34980 \InsetSpace ~
34981 aob1 = (gint >> 9) & 1; 
34982 \newline
34983 \InsetSpace ~
34984 \InsetSpace ~
34985 aob2 = (gint >> 8) & 1; 
34986 \newline
34987 \InsetSpace ~
34988 \InsetSpace ~
34989 aob3 = gint & 0x0800; 
34990 \newline
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 ..
34994  
34995 \newline
34996 }
34997 \end_layout
34998
34999 \begin_layout Standard
35000 will generate the following code:
35001 \end_layout
35002
35003 \begin_layout Verse
35004
35005 \family typewriter
35006 \InsetSpace ~
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 \InsetSpace ~
35014 \InsetSpace ~
35015 \InsetSpace ~
35016 \InsetSpace ~
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 \InsetSpace ~
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 \InsetSpace ~
35027 \InsetSpace ~
35028 \InsetSpace ~
35029 \InsetSpace ~
35030 \InsetSpace ~
35031  61 ;\InsetSpace ~
35032  hob.c 7 
35033 \newline
35034 000A E5*01\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  62\InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 \InsetSpace ~
35055 \InsetSpace ~
35056 \InsetSpace ~
35057  mov\InsetSpace ~
35058 \InsetSpace ~
35059  a,(_gint + 1) 
35060 \newline
35061 000C 23\InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079  63\InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087  rl\InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090  a 
35091 \newline
35092 000D 54 01\InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100 \InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107
35108  64\InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115 \InsetSpace ~
35116  anl\InsetSpace ~
35117 \InsetSpace ~
35118  a,#0x01 
35119 \newline
35120 000F F5*02\InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126 \InsetSpace ~
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135  65\InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143  mov\InsetSpace ~
35144 \InsetSpace ~
35145  _foo_hob1_1_1,a 
35146 \newline
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 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172  66 ;\InsetSpace ~
35173  hob.c 8 
35174 \newline
35175 0011 E5*01\InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183 \InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190
35191  67\InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199  mov\InsetSpace ~
35200 \InsetSpace ~
35201  a,(_gint + 1) 
35202 \newline
35203 0013 33\InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211 \InsetSpace ~
35212 \InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218 \InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221  68\InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228 \InsetSpace ~
35229  rlc\InsetSpace ~
35230 \InsetSpace ~
35231  a 
35232 \newline
35233 0014 92*00\InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 \InsetSpace ~
35248  69\InsetSpace ~
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253 \InsetSpace ~
35254 \InsetSpace ~
35255 \InsetSpace ~
35256  mov\InsetSpace ~
35257 \InsetSpace ~
35258  _foo_hob2_1_1,c
35259  
35260 \newline
35261 \InsetSpace ~
35262 \InsetSpace ~
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 \InsetSpace ~
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 \InsetSpace ~
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 \InsetSpace ~
35273 \InsetSpace ~
35274 \InsetSpace ~
35275 \InsetSpace ~
35276 \InsetSpace ~
35277 \InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283 \InsetSpace ~
35284 \InsetSpace ~
35285 \InsetSpace ~
35286  66 ;\InsetSpace ~
35287  hob.c 9 
35288 \newline
35289 0016 E5*01\InsetSpace ~
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304  67\InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312  mov\InsetSpace ~
35313 \InsetSpace ~
35314  a,(_gint + 1) 
35315 \newline
35316 0018 33\InsetSpace ~
35317 \InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331 \InsetSpace ~
35332 \InsetSpace ~
35333 \InsetSpace ~
35334  68\InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 \InsetSpace ~
35340 \InsetSpace ~
35341 \InsetSpace ~
35342  rlc\InsetSpace ~
35343 \InsetSpace ~
35344  a 
35345 \newline
35346 0019 92*01\InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361
35362  69\InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370  mov\InsetSpace ~
35371 \InsetSpace ~
35372  _foo_hob3_1_1,c 
35373 \newline
35374 \InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390 \InsetSpace ~
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399  70 ;\InsetSpace ~
35400  hob.c 10 
35401 \newline
35402 001B E5*01\InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417  71\InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425  mov\InsetSpace ~
35426 \InsetSpace ~
35427  a,(_gint + 1) 
35428 \newline
35429 001D
35430  03\InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448  72\InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456  rr\InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459  a 
35460 \newline
35461 001E 54 01\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  73\InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484  anl\InsetSpace ~
35485 \InsetSpace ~
35486  a,#0x01 
35487 \newline
35488 0020 F5*03\InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503  74\InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511  mov\InsetSpace ~
35512 \InsetSpace ~
35513  _foo_aob1_1_1,a
35514  
35515 \newline
35516 \InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541  75 ;\InsetSpace ~
35542  hob.c 11 
35543 \newline
35544 0022 E5*01\InsetSpace ~
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559  76\InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567  mov\InsetSpace ~
35568 \InsetSpace ~
35569  a,(_gint + 1) 
35570 \newline
35571 0024 13\InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589  77\InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597  rrc\InsetSpace ~
35598 \InsetSpace ~
35599  a 
35600 \newline
35601 0025 92*02\InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616
35617  78\InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625  mov\InsetSpace ~
35626 \InsetSpace ~
35627  _foo_aob2_1_1,c 
35628 \newline
35629 \InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644 \InsetSpace ~
35645 \InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654  79 ;\InsetSpace ~
35655  hob.c 12 
35656 \newline
35657 0027 E5*01\InsetSpace ~
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661 \InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672  80\InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680  mov\InsetSpace ~
35681 \InsetSpace ~
35682  a,(_gint + 1) 
35683 \newline
35684 0029
35685  A2 E3\InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700  81\InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708  mov\InsetSpace ~
35709 \InsetSpace ~
35710  c,acc[3] 
35711 \newline
35712 002B 92*03\InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727  82\InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735  mov\InsetSpace ~
35736 \InsetSpace ~
35737  _foo_aob3_1_1,c 
35738 \end_layout
35739
35740 \begin_layout Standard
35741 Other variations of these cases however will 
35742 \emph on
35743 not
35744 \emph default
35745  be recognized.
35746  They are standard C expressions, so I heartily recommend these be the only
35747  way to get the highest order bit, (it is portable).
35748  Of course it will be recognized even if it is embedded in other expressions,
35749  e.g.:
35750 \end_layout
35751
35752 \begin_layout Verse
35753
35754 \family typewriter
35755 xyz = gint + ((gint >> 15) & 1);
35756 \end_layout
35757
35758 \begin_layout Standard
35759 will still be recognized.
35760 \end_layout
35761
35762 \begin_layout Subsection
35763 Higher Order Byte
35764 \begin_inset LatexCommand \index{Higher Order Byte}
35765
35766 \end_inset
35767
35768  / Higher Order Word
35769 \begin_inset LatexCommand \index{Higher Order Word}
35770
35771 \end_inset
35772
35773
35774 \end_layout
35775
35776 \begin_layout Standard
35777 It is also frequently required to obtain a higher order byte or word of
35778  a larger integral type (long, int or short types).
35779  SDCC recognizes the following expressions to yield the higher order byte
35780  or word and generates optimized code for it, e.g.:
35781 \end_layout
35782
35783 \begin_layout Verse
35784
35785 \family typewriter
35786 unsigned int gint; 
35787 \newline
35788 unsigned long int glong; 
35789 \newline
35790
35791 \newline
35792 foo () { 
35793 \newline
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 unsigned char hob1,
35797  hob2; 
35798 \newline
35799 \InsetSpace ~
35800 \InsetSpace ~
35801 unsigned int how1, how2; 
35802 \newline
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 ...
35806  
35807 \newline
35808 \InsetSpace ~
35809 \InsetSpace ~
35810 hob1 = (gint >> 8) & 0xFF; 
35811 \newline
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 hob2 = glong >> 24; 
35815 \newline
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 how1 = (glong >> 16) & 0xFFFF;
35819  
35820 \newline
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 how2 = glong >> 8; 
35824 \newline
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 ..
35828  
35829 \newline
35830 }
35831 \end_layout
35832
35833 \begin_layout Standard
35834 will generate the following code:
35835 \end_layout
35836
35837 \begin_layout Verse
35838
35839 \family typewriter
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 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865  91 ;\InsetSpace ~
35866  hob.c 15 
35867 \newline
35868 0037 85*01*06\InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880  92\InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888  mov\InsetSpace ~
35889 \InsetSpace ~
35890  _foo_hob1_1_1,(_gint + 1) 
35891 \newline
35892 \InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917  93 ;\InsetSpace ~
35918  hob.c
35919  16 
35920 \newline
35921 003A 85*05*07\InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933  94\InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941  mov\InsetSpace ~
35942 \InsetSpace ~
35943  _foo_hob2_1_1,(_glong + 3) 
35944 \newline
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970  95 ;\InsetSpace ~
35971  hob.c 17 
35972 \newline
35973 003D 85*04*08\InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985
35986  96\InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994  mov\InsetSpace ~
35995 \InsetSpace ~
35996  _foo_how1_1_1,(_glong + 2) 
35997 \newline
35998 0040 85*05*09\InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010  97\InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018  mov\InsetSpace ~
36019 \InsetSpace ~
36020  (_foo_how1_1_1 +
36021  1),(_glong + 3) 
36022 \newline
36023 0043 85*03*0A\InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035  98\InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043  mov\InsetSpace ~
36044 \InsetSpace ~
36045  _foo_how2_1_1,(_glong + 1) 
36046 \newline
36047 0046 85*04*0B\InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059
36060  99\InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068  mov\InsetSpace ~
36069 \InsetSpace ~
36070  (_foo_how2_1_1 + 1),(_glong + 2) 
36071 \end_layout
36072
36073 \begin_layout Standard
36074 Again, variations of these cases may 
36075 \emph on
36076 not
36077 \emph default
36078  be recognized.
36079  They are standard C expressions, so I heartily recommend these be the only
36080  way to get the higher order byte/word, (it is portable).
36081  Of course it will be recognized even if it is embedded in other expressions,
36082  e.g.:
36083 \end_layout
36084
36085 \begin_layout Verse
36086
36087 \family typewriter
36088 xyz = gint + ((gint >> 8) & 0xFF);
36089 \end_layout
36090
36091 \begin_layout Standard
36092 will still be recognized.
36093 \end_layout
36094
36095 \begin_layout Subsection
36096 Peephole Optimizer
36097 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36098
36099 \end_inset
36100
36101
36102 \begin_inset LatexCommand \index{Peephole optimizer}
36103
36104 \end_inset
36105
36106
36107 \end_layout
36108
36109 \begin_layout Standard
36110 The compiler uses a rule based, pattern matching and re-writing mechanism
36111  for peep-hole optimization.
36112  It is inspired by 
36113 \emph on
36114 copt
36115 \emph default
36116  a peep-hole optimizer by Christopher W.
36117  Fraser (cwfraser\InsetSpace ~
36118 @\InsetSpace ~
36119 microsoft.com).
36120  A default set of rules are compiled into the compiler, additional rules
36121  may be added with the 
36122 \emph on
36123 -
36124 \begin_inset ERT
36125 status collapsed
36126
36127 \begin_layout Standard
36128
36129
36130 \backslash
36131 /
36132 \end_layout
36133
36134 \end_inset
36135
36136 -peep-file
36137 \begin_inset LatexCommand \index{-\/-peep-file}
36138
36139 \end_inset
36140
36141  <filename>
36142 \emph default
36143  option.
36144  The rule language is best illustrated with examples.
36145 \end_layout
36146
36147 \begin_layout Verse
36148
36149 \family typewriter
36150 replace { 
36151 \newline
36152 \InsetSpace ~
36153 \InsetSpace ~
36154 mov %1,a 
36155 \newline
36156 \InsetSpace ~
36157 \InsetSpace ~
36158 mov a,%1
36159 \newline
36160 } by {
36161 \newline
36162 \InsetSpace ~
36163 \InsetSpace ~
36164 mov %1,a
36165 \newline
36166 }
36167 \end_layout
36168
36169 \begin_layout Standard
36170 The above rule will change the following assembly
36171 \begin_inset LatexCommand \index{Assembler routines}
36172
36173 \end_inset
36174
36175  sequence:
36176 \end_layout
36177
36178 \begin_layout Verse
36179
36180 \family typewriter
36181 mov r1,a 
36182 \newline
36183 mov a,r1
36184 \end_layout
36185
36186 \begin_layout Standard
36187 to
36188 \end_layout
36189
36190 \begin_layout Verse
36191
36192 \family typewriter
36193 mov r1,a
36194 \end_layout
36195
36196 \begin_layout Standard
36197 Note: All occurrences of a 
36198 \emph on
36199 %n
36200 \emph default
36201  (pattern variable) must denote the same string.
36202  With the above rule, the assembly sequence:
36203 \end_layout
36204
36205 \begin_layout Verse
36206
36207 \family typewriter
36208 mov r1,a 
36209 \newline
36210 mov a,r2
36211 \end_layout
36212
36213 \begin_layout Standard
36214 will remain unmodified.
36215 \newline
36216
36217 \newline
36218 Other special case optimizations may be added by the
36219  user (via 
36220 \emph on
36221 -
36222 \begin_inset ERT
36223 status collapsed
36224
36225 \begin_layout Standard
36226
36227
36228 \backslash
36229 /
36230 \end_layout
36231
36232 \end_inset
36233
36234 -peep-file option
36235 \emph default
36236 ).
36237  E.g.
36238  some variants of the 8051 MCU
36239 \begin_inset LatexCommand \index{MCS51 variants}
36240
36241 \end_inset
36242
36243  allow only 
36244 \family typewriter
36245 ajmp
36246 \family default
36247  and 
36248 \family typewriter
36249 acall
36250 \family default
36251 .
36252  The following two rules will change all 
36253 \family typewriter
36254 ljmp
36255 \family default
36256  and 
36257 \family typewriter
36258 lcall
36259 \family default
36260  to 
36261 \family typewriter
36262 ajmp
36263 \family default
36264  and 
36265 \family typewriter
36266 acall
36267 \end_layout
36268
36269 \begin_layout Verse
36270
36271 \family typewriter
36272 replace { lcall %1 } by { acall %1 } 
36273 \newline
36274 replace { ljmp %1 } by { ajmp %1 }
36275 \end_layout
36276
36277 \begin_layout Standard
36278 (NOTE: from version 2.7.3 on, you can use option -
36279 \emph on
36280
36281 \begin_inset ERT
36282 status collapsed
36283
36284 \begin_layout Standard
36285
36286
36287 \backslash
36288 /
36289 \end_layout
36290
36291 \end_inset
36292
36293
36294 \emph default
36295 -acall-ajmp
36296 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36297
36298 \end_inset
36299
36300 , which also takes care of aligning the interrupt vectors properly.)
36301 \newline
36302
36303 \end_layout
36304
36305 \begin_layout Standard
36306 The 
36307 \emph on
36308 inline-assembler code
36309 \emph default
36310  is also passed through the peep hole optimizer, thus the peephole optimizer
36311  can also be used as an assembly level macro expander.
36312  The rules themselves are MCU dependent whereas the rule language infra-structur
36313 e is MCU independent.
36314  Peephole optimization rules for other MCU can be easily programmed using
36315  the rule language.
36316 \newline
36317
36318 \newline
36319 The syntax for a rule is as follows:
36320 \end_layout
36321
36322 \begin_layout Verse
36323
36324 \family typewriter
36325 rule := replace [ restart ] '{' <assembly sequence> '
36326 \backslash
36327 n' 
36328 \newline
36329 \InsetSpace ~
36330  \InsetSpace ~
36331  \InsetSpace ~
36332  \InsetSpace ~
36333  \InsetSpace ~
36334  \InsetSpace ~
36335  \InsetSpace ~
36336  \InsetSpace ~
36337  \InsetSpace ~
36338  \InsetSpace ~
36339  \InsetSpace ~
36340  \InsetSpace ~
36341  \InsetSpace ~
36342  \InsetSpace ~
36343  '}' by '{' '
36344 \backslash
36345 n' 
36346 \newline
36347 \InsetSpace ~
36348  \InsetSpace ~
36349  \InsetSpace ~
36350  \InsetSpace ~
36351  \InsetSpace ~
36352  \InsetSpace ~
36353  \InsetSpace ~
36354  \InsetSpace ~
36355  \InsetSpace ~
36356  \InsetSpace ~
36357  \InsetSpace ~
36358  \InsetSpace ~
36359  \InsetSpace ~
36360  \InsetSpace ~
36361  \InsetSpace ~
36362  \InsetSpace ~
36363  <assembly sequence> '
36364 \backslash
36365 n' 
36366 \newline
36367 \InsetSpace ~
36368  \InsetSpace ~
36369  \InsetSpace ~
36370  \InsetSpace ~
36371  \InsetSpace ~
36372  \InsetSpace ~
36373  \InsetSpace ~
36374  \InsetSpace ~
36375  \InsetSpace ~
36376  \InsetSpace ~
36377  \InsetSpace ~
36378  \InsetSpace ~
36379  \InsetSpace ~
36380  \InsetSpace ~
36381  '}' [if <functionName> ] '
36382 \backslash
36383 n' 
36384 \end_layout
36385
36386 \begin_layout Standard
36387 <assembly sequence> := assembly instruction (each instruction including
36388  labels must be on a separate line).
36389 \newline
36390
36391 \newline
36392 The optimizer will apply to the rules
36393  one by one from the top in the sequence of their appearance, it will terminate
36394  when all rules are exhausted.
36395  If the 'restart' option is specified, then the optimizer will start matching
36396  the rules again from the top, this option for a rule is expensive (performance)
36397 , it is intended to be used in situations where a transformation will trigger
36398  the same rule again.
36399  An example of this (not a good one, it has side effects) is the following
36400  rule:
36401 \end_layout
36402
36403 \begin_layout Verse
36404
36405 \family typewriter
36406 replace restart { 
36407 \newline
36408 \InsetSpace ~
36409 \InsetSpace ~
36410 pop %1 
36411 \newline
36412 \InsetSpace ~
36413 \InsetSpace ~
36414 push %1 } by { 
36415 \newline
36416 \InsetSpace ~
36417 \InsetSpace ~
36418 ; nop 
36419 \newline
36420 }
36421 \end_layout
36422
36423 \begin_layout Standard
36424 Note that the replace pattern cannot be a blank, but can be a comment line.
36425  Without the 'restart' option only the innermost 'pop' 'push' pair would
36426  be eliminated, i.e.:
36427 \end_layout
36428
36429 \begin_layout Verse
36430
36431 \family typewriter
36432 pop ar1 
36433 \newline
36434 pop ar2 
36435 \newline
36436 push ar2 
36437 \newline
36438 push ar1
36439 \end_layout
36440
36441 \begin_layout Standard
36442 would result in:
36443 \end_layout
36444
36445 \begin_layout Verse
36446
36447 \family typewriter
36448 pop ar1 
36449 \newline
36450 ; nop 
36451 \newline
36452 push ar1
36453 \end_layout
36454
36455 \begin_layout Standard
36456
36457 \emph on
36458 with
36459 \emph default
36460  the restart option the rule will be applied again to the resulting code
36461  and then all the pop-push pairs will be eliminated to yield:
36462 \end_layout
36463
36464 \begin_layout Verse
36465
36466 \family typewriter
36467 ; nop 
36468 \newline
36469 ; nop
36470 \end_layout
36471
36472 \begin_layout Standard
36473 A conditional function can be attached to a rule.
36474  Attaching rules are somewhat more involved, let me illustrate this with
36475  an example.
36476 \end_layout
36477
36478 \begin_layout Verse
36479
36480 \family typewriter
36481 replace { 
36482 \newline
36483 \InsetSpace ~
36484  \InsetSpace ~
36485  \InsetSpace ~
36486 ljmp %5 
36487 \newline
36488 %2:
36489 \newline
36490 } by { 
36491 \newline
36492 \InsetSpace ~
36493  \InsetSpace ~
36494  \InsetSpace ~
36495 sjmp %5 
36496 \newline
36497 %2:
36498 \newline
36499 } if labelInRange
36500 \end_layout
36501
36502 \begin_layout Standard
36503 The optimizer does a look-up of a function name table defined in function
36504  
36505 \emph on
36506 callFuncByName
36507 \emph default
36508  in the source file SDCCpeeph.c, with the name 
36509 \emph on
36510 labelInRange
36511 \emph default
36512 .
36513  If it finds a corresponding entry the function is called.
36514  Note there can be no parameters specified for these functions, in this
36515  case the use of 
36516 \emph on
36517 %5
36518 \emph default
36519  is crucial, since the function 
36520 \emph on
36521 labelInRange
36522 \emph default
36523  expects to find the label in that particular variable (the hash table containin
36524 g the variable bindings is passed as a parameter).
36525  If you want to code more such functions, take a close look at the function
36526  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36527  Currently implemented are 
36528 \emph on
36529 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36530  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36531 \emph default
36532 and
36533 \emph on
36534  notVolatile
36535 \emph default
36536 .
36537 \end_layout
36538
36539 \begin_layout Standard
36540 I know this whole thing is a little kludgey, but maybe some day we will
36541  have some better means.
36542  If you are looking at this file, you will see the default rules that are
36543  compiled into the compiler, you can add your own rules in the default set
36544  there if you get tired of specifying the -
36545 \begin_inset ERT
36546 status collapsed
36547
36548 \begin_layout Standard
36549
36550
36551 \backslash
36552 /
36553 \end_layout
36554
36555 \end_inset
36556
36557 -peep-file option.
36558 \end_layout
36559
36560 \begin_layout Section
36561 ANSI-Compliance
36562 \begin_inset LatexCommand \index{ANSI-compliance}
36563
36564 \end_inset
36565
36566
36567 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36568
36569 \end_inset
36570
36571
36572 \end_layout
36573
36574 \begin_layout Standard
36575 The latest publically available version of the standard 
36576 \emph on
36577 ISO/IEC 9899 - Programming languages - C
36578 \emph default
36579  should be available at: 
36580 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36581
36582 \end_inset
36583
36584 .
36585 \newline
36586
36587 \end_layout
36588
36589 \begin_layout Standard
36590 Deviations from the compliance:
36591 \end_layout
36592
36593 \begin_layout Itemize
36594 functions are not reentrant
36595 \begin_inset LatexCommand \index{reentrant}
36596
36597 \end_inset
36598
36599  unless explicitly declared as such or the 
36600 \series bold
36601 -
36602 \begin_inset ERT
36603 status collapsed
36604
36605 \begin_layout Standard
36606
36607
36608 \backslash
36609 /
36610 \end_layout
36611
36612 \end_inset
36613
36614 -stack-auto
36615 \begin_inset LatexCommand \index{-\/-stack-auto}
36616
36617 \end_inset
36618
36619
36620 \series default
36621  command line option is specified.
36622 \end_layout
36623
36624 \begin_layout Itemize
36625 structures
36626 \begin_inset LatexCommand \index{struct}
36627
36628 \end_inset
36629
36630  and unions
36631 \begin_inset LatexCommand \index{union}
36632
36633 \end_inset
36634
36635  cannot be assigned values directly, cannot be passed as function parameters
36636  or assigned to each other and cannot be a return value
36637 \begin_inset LatexCommand \index{return value}
36638
36639 \end_inset
36640
36641  from a function, e.g.:
36642 \end_layout
36643
36644 \begin_deeper
36645 \begin_layout Verse
36646
36647 \family typewriter
36648 struct s { ...
36649  }; 
36650 \newline
36651 struct s s1, s2; 
36652 \newline
36653 foo() 
36654 \newline
36655
36656 \newline
36657 \InsetSpace ~
36658 \InsetSpace ~
36659 \InsetSpace ~
36660 \InsetSpace ~
36661 ...
36662  
36663 \newline
36664 \InsetSpace ~
36665 \InsetSpace ~
36666 \InsetSpace ~
36667 \InsetSpace ~
36668 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36669 \newline
36670 \InsetSpace ~
36671 \InsetSpace ~
36672 \InsetSpace ~
36673 \InsetSpace ~
36674 ...
36675  
36676 \newline
36677 }
36678 \newline
36679
36680 \series bold
36681 struct
36682 \series default
36683  s foo1 (
36684 \series bold
36685 struct
36686 \series default
36687  s parms) /* invalid in SDCC although allowed in ANSI */
36688 \newline
36689
36690 \newline
36691 \InsetSpace ~
36692 \InsetSpace ~
36693 \InsetSpace ~
36694 \InsetSpace ~
36695 struct s rets;
36696  
36697 \newline
36698 \InsetSpace ~
36699 \InsetSpace ~
36700 \InsetSpace ~
36701 \InsetSpace ~
36702 ...
36703  
36704 \newline
36705 \InsetSpace ~
36706 \InsetSpace ~
36707 \InsetSpace ~
36708 \InsetSpace ~
36709 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36710 \newline
36711 }
36712 \end_layout
36713
36714 \end_deeper
36715 \begin_layout Itemize
36716 initialization of structure arrays must be fully braced.
36717 \end_layout
36718
36719 \begin_deeper
36720 \begin_layout Verse
36721
36722 \family typewriter
36723 struct s { char x } a[] = {1, 2};\InsetSpace ~
36724 \InsetSpace ~
36725 \InsetSpace ~
36726 \InsetSpace ~
36727 \InsetSpace ~
36728 /* invalid in SDCC */
36729 \newline
36730 struct s { char x
36731  } a[] = {{1}, {2}}; /* OK */
36732 \end_layout
36733
36734 \end_deeper
36735 \begin_layout Itemize
36736 'long long
36737 \begin_inset LatexCommand \index{long long (not supported)}
36738
36739 \end_inset
36740
36741 ' (64 bit integers
36742 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36743
36744 \end_inset
36745
36746 ) not supported.
36747 \end_layout
36748
36749 \begin_layout Itemize
36750 'double
36751 \begin_inset LatexCommand \index{double (not supported)}
36752
36753 \end_inset
36754
36755 ' precision floating point 
36756 \begin_inset LatexCommand \index{Floating point support}
36757
36758 \end_inset
36759
36760 not supported.
36761 \end_layout
36762
36763 \begin_layout Itemize
36764 Old K&R style
36765 \begin_inset LatexCommand \index{K\&R style}
36766
36767 \end_inset
36768
36769  function declarations are NOT allowed.
36770 \end_layout
36771
36772 \begin_deeper
36773 \begin_layout Verse
36774
36775 \family typewriter
36776 foo(i,j) /* this old style of function declarations */ 
36777 \newline
36778 int i,j; /* is valid
36779  in ANSI but not valid in SDCC */ 
36780 \newline
36781
36782 \newline
36783 \InsetSpace ~
36784 \InsetSpace ~
36785 \InsetSpace ~
36786 \InsetSpace ~
36787 ...
36788  
36789 \newline
36790 }
36791 \end_layout
36792
36793 \end_deeper
36794 \begin_layout Itemize
36795 Most enhancements in C99 are not supported, e.g.:
36796 \end_layout
36797
36798 \begin_deeper
36799 \begin_layout Verse
36800
36801 \family typewriter
36802 for (
36803 \series bold
36804 int
36805 \series default
36806  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36807 \end_layout
36808
36809 \end_deeper
36810 \begin_layout Itemize
36811 But some have been added recently in SDCC 2.7.0.
36812  They must be considered alpha quality however.
36813 \end_layout
36814
36815 \begin_deeper
36816 \begin_layout Verse
36817
36818 \family typewriter
36819 \series bold
36820 inline
36821 \begin_inset LatexCommand \index{inline (not supported)}
36822
36823 \end_inset
36824
36825
36826 \series default
36827  int increment (int a) { return a+1; } /* inlines the increment without
36828  function call overhead */
36829 \newline
36830 int * 
36831 \series bold
36832 restrict
36833 \begin_inset LatexCommand \index{inline (not supported)}
36834
36835 \end_inset
36836
36837
36838 \series default
36839  p; /* accepted but ignored */
36840 \end_layout
36841
36842 \end_deeper
36843 \begin_layout Itemize
36844 Certain words that are valid identifiers in the standard may be reserved
36845  words in SDCC unless the 
36846 \series bold
36847 -
36848 \begin_inset ERT
36849 status collapsed
36850
36851 \begin_layout Standard
36852
36853
36854 \backslash
36855 /
36856 \end_layout
36857
36858 \end_inset
36859
36860 -std-c89
36861 \begin_inset LatexCommand \index{-\/-std-c89}
36862
36863 \end_inset
36864
36865  or -
36866 \begin_inset ERT
36867 status collapsed
36868
36869 \begin_layout Standard
36870
36871
36872 \backslash
36873 /
36874 \end_layout
36875
36876 \end_inset
36877
36878 -std-c99
36879 \begin_inset LatexCommand \index{-\/-std-c99}
36880
36881 \end_inset
36882
36883
36884 \series default
36885  command line options are used.
36886  These may include (depending on the selected processor): 'at', 'banked',
36887  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36888 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36889  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36890  '_naked'.
36891  Compliant equivalents of these keywords are always available in a form
36892  that begin with two underscores
36893 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36894
36895 \end_inset
36896
36897 , f.e.
36898  '__data' instead of 'data'.
36899 \end_layout
36900
36901 \begin_layout Itemize
36902 Integer promotion of variable arguments is not performed if the argument
36903  is explicitly taypecasted unless the
36904 \series bold
36905  -
36906 \begin_inset ERT
36907 status collapsed
36908
36909 \begin_layout Standard
36910
36911
36912 \backslash
36913 /
36914 \end_layout
36915
36916 \end_inset
36917
36918 -std-c89
36919 \begin_inset LatexCommand \index{-\/-std-c89}
36920
36921 \end_inset
36922
36923  or -
36924 \begin_inset ERT
36925 status collapsed
36926
36927 \begin_layout Standard
36928
36929
36930 \backslash
36931 /
36932 \end_layout
36933
36934 \end_inset
36935
36936 -std-c99
36937 \begin_inset LatexCommand \index{-\/-std-c99}
36938
36939 \end_inset
36940
36941
36942 \series default
36943  command line options are used.
36944 \end_layout
36945
36946 \begin_deeper
36947 \begin_layout Verse
36948
36949 \family typewriter
36950 void vararg_func (char *str, ...) { str; }
36951 \newline
36952
36953 \newline
36954 void main (void)
36955 \newline
36956 {
36957 \newline
36958 \InsetSpace ~
36959 \InsetSpace ~
36960 char c = 10;
36961 \newline
36962
36963 \newline
36964 \InsetSpace ~
36965 \InsetSpace ~
36966 /* argument
36967  u is promoted to int before
36968 \newline
36969 \InsetSpace ~
36970 \InsetSpace ~
36971 \InsetSpace ~
36972 * passing to function */
36973 \newline
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 vararg_func ("%c", c);
36977 \newline
36978
36979 \newline
36980 \InsetSpace ~
36981 \InsetSpace ~
36982 /*
36983  argument u is not promoted to int,
36984 \newline
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988 * it is passed as char to function
36989 \newline
36990 \InsetSpace ~
36991 \InsetSpace ~
36992 \InsetSpace ~
36993 * if
36994  --std-cXX is not defined;
36995 \newline
36996 \InsetSpace ~
36997 \InsetSpace ~
36998 \InsetSpace ~
36999 * is promoted to int before passing
37000 \newline
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 \InsetSpace ~
37004 * to function
37005  if --std-cXX is defined */
37006 \newline
37007 \InsetSpace ~
37008 \InsetSpace ~
37009 vararg_func ("%bc", (char)u);
37010 \newline
37011 }
37012 \end_layout
37013
37014 \end_deeper
37015 \begin_layout Section
37016 Cyclomatic Complexity
37017 \begin_inset LatexCommand \index{Cyclomatic complexity}
37018
37019 \end_inset
37020
37021
37022 \end_layout
37023
37024 \begin_layout Standard
37025 Cyclomatic complexity of a function is defined as the number of independent
37026  paths the program can take during execution of the function.
37027  This is an important number since it defines the number test cases you
37028  have to generate to validate the function.
37029  The accepted industry standard for complexity number is 10, if the cyclomatic
37030  complexity reported by SDCC exceeds 10 you should think about simplification
37031  of the function logic.
37032  Note that the complexity level is not related to the number of lines of
37033  code in a function.
37034  Large functions can have low complexity, and small functions can have large
37035  complexity levels.
37036  
37037 \newline
37038
37039 \newline
37040 SDCC uses the following formula to compute the complexity:
37041 \newline
37042
37043 \end_layout
37044
37045 \begin_layout Standard
37046 complexity = (number of edges in control flow graph) - (number of nodes
37047  in control flow graph) + 2;
37048 \newline
37049
37050 \newline
37051 Having said that the industry standard is 10,
37052  you should be aware that in some cases it be may unavoidable to have a
37053  complexity level of less than 10.
37054  For example if you have switch statement with more than 10 case labels,
37055  each case label adds one to the complexity level.
37056  The complexity level is by no means an absolute measure of the algorithmic
37057  complexity of the function, it does however provide a good starting point
37058  for which functions you might look at for further optimization.
37059 \end_layout
37060
37061 \begin_layout Section
37062 Retargetting for other Processors
37063 \end_layout
37064
37065 \begin_layout Standard
37066 The issues for retargetting the compiler are far too numerous to be covered
37067  by this document.
37068  What follows is a brief description of each of the seven phases of the
37069  compiler and its MCU dependency.
37070 \end_layout
37071
37072 \begin_layout Itemize
37073 Parsing the source and building the annotated parse tree.
37074  This phase is largely MCU independent (except for the language extensions).
37075  Syntax & semantic checks are also done in this phase, along with some initial
37076  optimizations like back patching labels and the pattern matching optimizations
37077  like bit-rotation etc.
37078 \end_layout
37079
37080 \begin_layout Itemize
37081 The second phase involves generating an intermediate code which can be easy
37082  manipulated during the later phases.
37083  This phase is entirely MCU independent.
37084  The intermediate code generation assumes the target machine has unlimited
37085  number of registers, and designates them with the name iTemp.
37086  The compiler can be made to dump a human readable form of the code generated
37087  by using the -
37088 \begin_inset ERT
37089 status collapsed
37090
37091 \begin_layout Standard
37092
37093
37094 \backslash
37095 /
37096 \end_layout
37097
37098 \end_inset
37099
37100 -dumpraw option.
37101 \end_layout
37102
37103 \begin_layout Itemize
37104 This phase does the bulk of the standard optimizations and is also MCU independe
37105 nt.
37106  This phase can be broken down into several sub-phases:
37107 \newline
37108
37109 \newline
37110 Break down intermediate
37111  code (iCode) into basic blocks.
37112 \newline
37113 Do control flow & data flow analysis on the
37114  basic blocks.
37115 \newline
37116 Do local common subexpression elimination, then global subexpressio
37117 n elimination
37118 \newline
37119 Dead code elimination
37120 \newline
37121 Loop optimizations
37122 \newline
37123 If loop optimizations
37124  caused any changes then do 'global subexpression elimination' and 'dead
37125  code elimination' again.
37126 \end_layout
37127
37128 \begin_layout Itemize
37129 This phase determines the live-ranges; by live range I mean those iTemp
37130  variables defined by the compiler that still survive after all the optimization
37131 s.
37132  Live range analysis
37133 \begin_inset LatexCommand \index{Live range analysis}
37134
37135 \end_inset
37136
37137  is essential for register allocation, since these computation determines
37138  which of these iTemps will be assigned to registers, and for how long.
37139 \end_layout
37140
37141 \begin_layout Itemize
37142 Phase five is register allocation.
37143  There are two parts to this process.
37144 \newline
37145
37146 \newline
37147 The first part I call 'register packing'
37148  (for lack of a better term).
37149  In this case several MCU specific expression folding is done to reduce
37150  register pressure.
37151 \newline
37152
37153 \newline
37154 The second part is more MCU independent and deals with
37155  allocating registers to the remaining live ranges.
37156  A lot of MCU specific code does creep into this phase because of the limited
37157  number of index registers available in the 8051.
37158 \end_layout
37159
37160 \begin_layout Itemize
37161 The Code generation phase is (unhappily), entirely MCU dependent and very
37162  little (if any at all) of this code can be reused for other MCU.
37163  However the scheme for allocating a homogenized assembler operand for each
37164  iCode operand may be reused.
37165 \end_layout
37166
37167 \begin_layout Itemize
37168 As mentioned in the optimization section the peep-hole optimizer is rule
37169  based system, which can reprogrammed for other MCUs.
37170 \end_layout
37171
37172 \begin_layout Standard
37173 More information is available on SDCC Wiki
37174 \begin_inset LatexCommand \index{wiki}
37175
37176 \end_inset
37177
37178  (preliminary link 
37179 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37180
37181 \end_inset
37182
37183 ) and in the thread 
37184 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37185
37186 \end_inset
37187
37188  .
37189 \end_layout
37190
37191 \begin_layout Chapter
37192 Compiler internals
37193 \begin_inset LatexCommand \index{Compiler internals}
37194
37195 \end_inset
37196
37197
37198 \end_layout
37199
37200 \begin_layout Section
37201 The anatomy of the compiler
37202 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37203
37204 \end_inset
37205
37206
37207 \end_layout
37208
37209 \begin_layout Standard
37210
37211 \shape italic
37212 This is an excerpt from an article published in Circuit Cellar Magazine
37213  in 
37214 \series bold
37215 August 2000
37216 \series default
37217 .
37218  It's a little outdated (the compiler is much more efficient now and user/develo
37219 per friendly), but pretty well exposes the guts of it all.
37220 \shape default
37221
37222 \newline
37223
37224 \newline
37225 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37226  It is fairly easy to retarget for other 8-bit MCU.
37227  Here we take a look at some of the internals of the compiler.
37228  
37229 \end_layout
37230
37231 \begin_layout Paragraph*
37232 Parsing
37233 \begin_inset LatexCommand \index{Parsing}
37234
37235 \end_inset
37236
37237  
37238 \end_layout
37239
37240 \begin_layout Standard
37241 Parsing the input source file and creating an AST (Annotated Syntax Tree
37242 \begin_inset LatexCommand \index{Annotated syntax tree}
37243
37244 \end_inset
37245
37246 ).
37247  This phase also involves propagating types (annotating each node of the
37248  parse tree with type information) and semantic analysis.
37249  There are some MCU specific parsing rules.
37250  For example the storage classes, the extended storage classes are MCU specific
37251  while there may be a xdata storage class for 8051 there is no such storage
37252  class for z80 or Atmel AVR.
37253  SDCC allows MCU specific storage class extensions, i.e.
37254  xdata will be treated as a storage class specifier when parsing 8051 C
37255  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37256  C code.
37257 \end_layout
37258
37259 \begin_layout Paragraph*
37260 Generating iCode
37261 \begin_inset LatexCommand \index{iCode}
37262
37263 \end_inset
37264
37265
37266 \end_layout
37267
37268 \begin_layout Standard
37269 Intermediate code generation.
37270  In this phase the AST is broken down into three-operand form (iCode).
37271  These three operand forms are represented as doubly linked lists.
37272  ICode is the term given to the intermediate form generated by the compiler.
37273  ICode example section shows some examples of iCode generated for some simple
37274  C source functions.
37275 \end_layout
37276
37277 \begin_layout Paragraph*
37278 Optimizations
37279 \begin_inset LatexCommand \index{Optimizations}
37280
37281 \end_inset
37282
37283 .
37284 \end_layout
37285
37286 \begin_layout Standard
37287 Bulk of the target independent optimizations is performed in this phase.
37288  The optimizations include constant propagation, common sub-expression eliminati
37289 on, loop invariant code movement, strength reduction of loop induction variables
37290  and dead-code elimination.
37291 \end_layout
37292
37293 \begin_layout Paragraph*
37294 Live range analysis
37295 \begin_inset LatexCommand \index{Live range analysis}
37296
37297 \end_inset
37298
37299
37300 \end_layout
37301
37302 \begin_layout Standard
37303 During intermediate code generation phase, the compiler assumes the target
37304  machine has infinite number of registers and generates a lot of temporary
37305  variables.
37306  The live range computation determines the lifetime of each of these compiler-ge
37307 nerated temporaries.
37308  A picture speaks a thousand words.
37309  ICode example sections show the live range annotations for each of the
37310  operand.
37311  It is important to note here, each iCode is assigned a number in the order
37312  of its execution in the function.
37313  The live ranges are computed in terms of these numbers.
37314  The from number is the number of the iCode which first defines the operand
37315  and the to number signifies the iCode which uses this operand last.
37316 \end_layout
37317
37318 \begin_layout Paragraph*
37319 Register Allocation
37320 \begin_inset LatexCommand \index{Register allocation}
37321
37322 \end_inset
37323
37324
37325 \end_layout
37326
37327 \begin_layout Standard
37328 The register allocation determines the type and number of registers needed
37329  by each operand.
37330  In most MCUs only a few registers can be used for indirect addressing.
37331  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37332  address the internal ram and DPTR to indirectly address the external ram.
37333  The compiler will try to allocate the appropriate register to pointer variables
37334  if it can.
37335  ICode example section shows the operands annotated with the registers assigned
37336  to them.
37337  The compiler will try to keep operands in registers as much as possible;
37338  there are several schemes the compiler uses to do achieve this.
37339  When the compiler runs out of registers the compiler will check to see
37340  if there are any live operands which is not used or defined in the current
37341  basic block being processed, if there are any found then it will push that
37342  operand and use the registers in this block, the operand will then be popped
37343  at the end of the basic block.
37344  
37345 \end_layout
37346
37347 \begin_layout Standard
37348 There are other MCU specific considerations in this phase.
37349  Some MCUs have an accumulator; very short-lived operands could be assigned
37350  to the accumulator instead of a general-purpose register.
37351 \end_layout
37352
37353 \begin_layout Paragraph*
37354 Code generation
37355 \end_layout
37356
37357 \begin_layout Standard
37358 Figure II gives a table of iCode
37359 \begin_inset LatexCommand \index{iCode}
37360
37361 \end_inset
37362
37363  operations supported by the compiler.
37364  The code generation involves translating these operations into corresponding
37365  assembly code for the processor.
37366  This sounds overly simple but that is the essence of code generation.
37367  Some of the iCode operations are generated on a MCU specific manner for
37368  example, the z80 port does not use registers to pass parameters so the
37369  SEND and RECV iCode operations will not be generated, and it also does
37370  not support JUMPTABLES.
37371  
37372 \newline
37373
37374 \end_layout
37375
37376 \begin_layout Standard
37377
37378 \size footnotesize
37379 Figure II 
37380 \begin_inset Tabular
37381 <lyxtabular version="3" rows="39" columns="4">
37382 <features islongtable="true" headBottomDL="true">
37383 <column alignment="block" valignment="top" leftline="true" width="13col%">
37384 <column alignment="left" valignment="top" leftline="true" width="13col%">
37385 <column alignment="block" valignment="top" leftline="true" width="22col%">
37386 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37387 <row topline="true" bottomline="true" endhead="true">
37388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37389 \begin_inset Text
37390
37391 \begin_layout Standard
37392
37393 \series bold
37394 iCode
37395 \series default
37396
37397 \begin_inset LatexCommand \index{iCode}
37398
37399 \end_inset
37400
37401
37402 \end_layout
37403
37404 \end_inset
37405 </cell>
37406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37407 \begin_inset Text
37408
37409 \begin_layout Standard
37410
37411 \series bold
37412 Operands
37413 \end_layout
37414
37415 \end_inset
37416 </cell>
37417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37418 \begin_inset Text
37419
37420 \begin_layout Standard
37421
37422 \series bold
37423 Description
37424 \end_layout
37425
37426 \end_inset
37427 </cell>
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37429 \begin_inset Text
37430
37431 \begin_layout Standard
37432
37433 \series bold
37434 C Equivalent
37435 \end_layout
37436
37437 \end_inset
37438 </cell>
37439 </row>
37440 <row topline="true">
37441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37442 \begin_inset Text
37443
37444 \begin_layout Standard
37445
37446 \size footnotesize
37447 '!'
37448 \end_layout
37449
37450 \end_inset
37451 </cell>
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37453 \begin_inset Text
37454
37455 \begin_layout Standard
37456
37457 \size footnotesize
37458 IC_LEFT() IC_RESULT()
37459 \end_layout
37460
37461 \end_inset
37462 </cell>
37463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37464 \begin_inset Text
37465
37466 \begin_layout Standard
37467
37468 \size footnotesize
37469 NOT operation 
37470 \end_layout
37471
37472 \end_inset
37473 </cell>
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37475 \begin_inset Text
37476
37477 \begin_layout Standard
37478
37479 \size footnotesize
37480 IC_RESULT = ! IC_LEFT;
37481 \end_layout
37482
37483 \end_inset
37484 </cell>
37485 </row>
37486 <row topline="true">
37487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37488 \begin_inset Text
37489
37490 \begin_layout Standard
37491
37492 \size footnotesize
37493 '~'
37494 \end_layout
37495
37496 \end_inset
37497 </cell>
37498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37499 \begin_inset Text
37500
37501 \begin_layout Standard
37502
37503 \size footnotesize
37504 IC_LEFT() IC_RESULT()
37505 \end_layout
37506
37507 \end_inset
37508 </cell>
37509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37510 \begin_inset Text
37511
37512 \begin_layout Standard
37513
37514 \size footnotesize
37515 Bitwise complement of 
37516 \end_layout
37517
37518 \end_inset
37519 </cell>
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37521 \begin_inset Text
37522
37523 \begin_layout Standard
37524
37525 \size footnotesize
37526 IC_RESULT = ~IC_LEFT;
37527 \end_layout
37528
37529 \end_inset
37530 </cell>
37531 </row>
37532 <row topline="true">
37533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37534 \begin_inset Text
37535
37536 \begin_layout Standard
37537
37538 \size footnotesize
37539 RRC
37540 \end_layout
37541
37542 \end_inset
37543 </cell>
37544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37545 \begin_inset Text
37546
37547 \begin_layout Standard
37548
37549 \size footnotesize
37550 IC_LEFT() IC_RESULT()
37551 \end_layout
37552
37553 \end_inset
37554 </cell>
37555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37556 \begin_inset Text
37557
37558 \begin_layout Standard
37559
37560 \size footnotesize
37561 Rotate right with carry
37562 \end_layout
37563
37564 \end_inset
37565 </cell>
37566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37567 \begin_inset Text
37568
37569 \begin_layout Standard
37570
37571 \size footnotesize
37572 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37573 \end_layout
37574
37575 \end_inset
37576 </cell>
37577 </row>
37578 <row topline="true">
37579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37580 \begin_inset Text
37581
37582 \begin_layout Standard
37583
37584 \size footnotesize
37585 RLC
37586 \end_layout
37587
37588 \end_inset
37589 </cell>
37590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37591 \begin_inset Text
37592
37593 \begin_layout Standard
37594
37595 \size footnotesize
37596 IC_LEFT() IC_RESULT()
37597 \end_layout
37598
37599 \end_inset
37600 </cell>
37601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37602 \begin_inset Text
37603
37604 \begin_layout Standard
37605
37606 \size footnotesize
37607 Rotate left with carry
37608 \end_layout
37609
37610 \end_inset
37611 </cell>
37612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37613 \begin_inset Text
37614
37615 \begin_layout Standard
37616
37617 \size footnotesize
37618 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37619 \end_layout
37620
37621 \end_inset
37622 </cell>
37623 </row>
37624 <row topline="true">
37625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37626 \begin_inset Text
37627
37628 \begin_layout Standard
37629
37630 \size footnotesize
37631 GETHBIT
37632 \end_layout
37633
37634 \end_inset
37635 </cell>
37636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37637 \begin_inset Text
37638
37639 \begin_layout Standard
37640
37641 \size footnotesize
37642 IC_LEFT() IC_RESULT()
37643 \end_layout
37644
37645 \end_inset
37646 </cell>
37647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37648 \begin_inset Text
37649
37650 \begin_layout Standard
37651
37652 \size footnotesize
37653 Get the highest order bit of IC_LEFT
37654 \end_layout
37655
37656 \end_inset
37657 </cell>
37658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37659 \begin_inset Text
37660
37661 \begin_layout Standard
37662
37663 \size footnotesize
37664 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37665 \end_layout
37666
37667 \end_inset
37668 </cell>
37669 </row>
37670 <row topline="true">
37671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37672 \begin_inset Text
37673
37674 \begin_layout Standard
37675
37676 \size footnotesize
37677 UNARYMINUS
37678 \end_layout
37679
37680 \end_inset
37681 </cell>
37682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37683 \begin_inset Text
37684
37685 \begin_layout Standard
37686
37687 \size footnotesize
37688 IC_LEFT() IC_RESULT()
37689 \end_layout
37690
37691 \end_inset
37692 </cell>
37693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37694 \begin_inset Text
37695
37696 \begin_layout Standard
37697
37698 \size footnotesize
37699 Unary minus
37700 \end_layout
37701
37702 \end_inset
37703 </cell>
37704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37705 \begin_inset Text
37706
37707 \begin_layout Standard
37708
37709 \size footnotesize
37710 IC_RESULT = - IC_LEFT;
37711 \end_layout
37712
37713 \end_inset
37714 </cell>
37715 </row>
37716 <row topline="true">
37717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37718 \begin_inset Text
37719
37720 \begin_layout Standard
37721
37722 \size footnotesize
37723 IPUSH
37724 \end_layout
37725
37726 \end_inset
37727 </cell>
37728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37729 \begin_inset Text
37730
37731 \begin_layout Standard
37732
37733 \size footnotesize
37734 IC_LEFT()
37735 \end_layout
37736
37737 \end_inset
37738 </cell>
37739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37740 \begin_inset Text
37741
37742 \begin_layout Standard
37743
37744 \size footnotesize
37745 Push the operand into stack
37746 \end_layout
37747
37748 \end_inset
37749 </cell>
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37751 \begin_inset Text
37752
37753 \begin_layout Standard
37754
37755 \size footnotesize
37756 NONE
37757 \end_layout
37758
37759 \end_inset
37760 </cell>
37761 </row>
37762 <row topline="true">
37763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37764 \begin_inset Text
37765
37766 \begin_layout Standard
37767
37768 \size footnotesize
37769 IPOP
37770 \end_layout
37771
37772 \end_inset
37773 </cell>
37774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37775 \begin_inset Text
37776
37777 \begin_layout Standard
37778
37779 \size footnotesize
37780 IC_LEFT()
37781 \end_layout
37782
37783 \end_inset
37784 </cell>
37785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37786 \begin_inset Text
37787
37788 \begin_layout Standard
37789
37790 \size footnotesize
37791 Pop the operand from the stack 
37792 \end_layout
37793
37794 \end_inset
37795 </cell>
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37797 \begin_inset Text
37798
37799 \begin_layout Standard
37800
37801 \size footnotesize
37802 NONE
37803 \end_layout
37804
37805 \end_inset
37806 </cell>
37807 </row>
37808 <row topline="true">
37809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37810 \begin_inset Text
37811
37812 \begin_layout Standard
37813
37814 \size footnotesize
37815 CALL
37816 \end_layout
37817
37818 \end_inset
37819 </cell>
37820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37821 \begin_inset Text
37822
37823 \begin_layout Standard
37824
37825 \size footnotesize
37826 IC_LEFT() IC_RESULT()
37827 \end_layout
37828
37829 \end_inset
37830 </cell>
37831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37832 \begin_inset Text
37833
37834 \begin_layout Standard
37835
37836 \size footnotesize
37837 Call the function represented by IC_LEFT 
37838 \end_layout
37839
37840 \end_inset
37841 </cell>
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37843 \begin_inset Text
37844
37845 \begin_layout Standard
37846
37847 \size footnotesize
37848 IC_RESULT = IC_LEFT();
37849 \end_layout
37850
37851 \end_inset
37852 </cell>
37853 </row>
37854 <row topline="true">
37855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37856 \begin_inset Text
37857
37858 \begin_layout Standard
37859
37860 \size footnotesize
37861 PCALL
37862 \end_layout
37863
37864 \end_inset
37865 </cell>
37866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37867 \begin_inset Text
37868
37869 \begin_layout Standard
37870
37871 \size footnotesize
37872 IC_LEFT() IC_RESULT()
37873 \end_layout
37874
37875 \end_inset
37876 </cell>
37877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37878 \begin_inset Text
37879
37880 \begin_layout Standard
37881
37882 \size footnotesize
37883 Call via function pointer
37884 \end_layout
37885
37886 \end_inset
37887 </cell>
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37889 \begin_inset Text
37890
37891 \begin_layout Standard
37892
37893 \size footnotesize
37894 IC_RESULT = (*IC_LEFT)();
37895 \end_layout
37896
37897 \end_inset
37898 </cell>
37899 </row>
37900 <row topline="true">
37901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37902 \begin_inset Text
37903
37904 \begin_layout Standard
37905
37906 \size footnotesize
37907 RETURN
37908 \end_layout
37909
37910 \end_inset
37911 </cell>
37912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37913 \begin_inset Text
37914
37915 \begin_layout Standard
37916
37917 \size footnotesize
37918 IC_LEFT()
37919 \end_layout
37920
37921 \end_inset
37922 </cell>
37923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37924 \begin_inset Text
37925
37926 \begin_layout Standard
37927
37928 \size footnotesize
37929 Return the value in operand IC_LEFT 
37930 \end_layout
37931
37932 \end_inset
37933 </cell>
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37935 \begin_inset Text
37936
37937 \begin_layout Standard
37938
37939 \size footnotesize
37940 return IC_LEFT;
37941 \end_layout
37942
37943 \end_inset
37944 </cell>
37945 </row>
37946 <row topline="true">
37947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37948 \begin_inset Text
37949
37950 \begin_layout Standard
37951
37952 \size footnotesize
37953 LABEL
37954 \end_layout
37955
37956 \end_inset
37957 </cell>
37958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37959 \begin_inset Text
37960
37961 \begin_layout Standard
37962
37963 \size footnotesize
37964 IC_LABEL() 
37965 \end_layout
37966
37967 \end_inset
37968 </cell>
37969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37970 \begin_inset Text
37971
37972 \begin_layout Standard
37973
37974 \size footnotesize
37975 Label
37976 \end_layout
37977
37978 \end_inset
37979 </cell>
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37981 \begin_inset Text
37982
37983 \begin_layout Standard
37984
37985 \size footnotesize
37986 IC_LABEL:
37987 \end_layout
37988
37989 \end_inset
37990 </cell>
37991 </row>
37992 <row topline="true">
37993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37994 \begin_inset Text
37995
37996 \begin_layout Standard
37997
37998 \size footnotesize
37999 GOTO
38000 \end_layout
38001
38002 \end_inset
38003 </cell>
38004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38005 \begin_inset Text
38006
38007 \begin_layout Standard
38008
38009 \size footnotesize
38010 IC_LABEL() 
38011 \end_layout
38012
38013 \end_inset
38014 </cell>
38015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38016 \begin_inset Text
38017
38018 \begin_layout Standard
38019
38020 \size footnotesize
38021 Goto label
38022 \end_layout
38023
38024 \end_inset
38025 </cell>
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38027 \begin_inset Text
38028
38029 \begin_layout Standard
38030
38031 \size footnotesize
38032 goto IC_LABEL();
38033 \end_layout
38034
38035 \end_inset
38036 </cell>
38037 </row>
38038 <row topline="true">
38039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38040 \begin_inset Text
38041
38042 \begin_layout Standard
38043
38044 \size footnotesize
38045 '+'
38046 \end_layout
38047
38048 \end_inset
38049 </cell>
38050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38051 \begin_inset Text
38052
38053 \begin_layout Standard
38054
38055 \size footnotesize
38056 IC_LEFT() IC_RIGHT() IC_RESULT()
38057 \end_layout
38058
38059 \end_inset
38060 </cell>
38061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38062 \begin_inset Text
38063
38064 \begin_layout Standard
38065
38066 \size footnotesize
38067 Addition
38068 \end_layout
38069
38070 \end_inset
38071 </cell>
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38073 \begin_inset Text
38074
38075 \begin_layout Standard
38076
38077 \size footnotesize
38078 IC_RESULT = IC_LEFT + IC_RIGHT
38079 \end_layout
38080
38081 \end_inset
38082 </cell>
38083 </row>
38084 <row topline="true">
38085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38086 \begin_inset Text
38087
38088 \begin_layout Standard
38089
38090 \size footnotesize
38091 '-'
38092 \end_layout
38093
38094 \end_inset
38095 </cell>
38096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38097 \begin_inset Text
38098
38099 \begin_layout Standard
38100
38101 \size footnotesize
38102 IC_LEFT() IC_RIGHT() IC_RESULT()
38103 \end_layout
38104
38105 \end_inset
38106 </cell>
38107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38108 \begin_inset Text
38109
38110 \begin_layout Standard
38111
38112 \size footnotesize
38113 Subtraction
38114 \end_layout
38115
38116 \end_inset
38117 </cell>
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38119 \begin_inset Text
38120
38121 \begin_layout Standard
38122
38123 \size footnotesize
38124 IC_RESULT = IC_LEFT - IC_RIGHT 
38125 \end_layout
38126
38127 \end_inset
38128 </cell>
38129 </row>
38130 <row topline="true">
38131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38132 \begin_inset Text
38133
38134 \begin_layout Standard
38135
38136 \size footnotesize
38137 '*'
38138 \end_layout
38139
38140 \end_inset
38141 </cell>
38142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38143 \begin_inset Text
38144
38145 \begin_layout Standard
38146
38147 \size footnotesize
38148 IC_LEFT() IC_RIGHT() IC_RESULT()
38149 \end_layout
38150
38151 \end_inset
38152 </cell>
38153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38154 \begin_inset Text
38155
38156 \begin_layout Standard
38157
38158 \size footnotesize
38159 Multiplication 
38160 \end_layout
38161
38162 \end_inset
38163 </cell>
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38165 \begin_inset Text
38166
38167 \begin_layout Standard
38168
38169 \size footnotesize
38170 IC_RESULT = IC_LEFT * IC_RIGHT;
38171 \end_layout
38172
38173 \end_inset
38174 </cell>
38175 </row>
38176 <row topline="true">
38177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38178 \begin_inset Text
38179
38180 \begin_layout Standard
38181
38182 \size footnotesize
38183 '/'
38184 \end_layout
38185
38186 \end_inset
38187 </cell>
38188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38189 \begin_inset Text
38190
38191 \begin_layout Standard
38192
38193 \size footnotesize
38194 IC_LEFT() IC_RIGHT() IC_RESULT()
38195 \end_layout
38196
38197 \end_inset
38198 </cell>
38199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38200 \begin_inset Text
38201
38202 \begin_layout Standard
38203
38204 \size footnotesize
38205 Division
38206 \end_layout
38207
38208 \end_inset
38209 </cell>
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38211 \begin_inset Text
38212
38213 \begin_layout Standard
38214
38215 \size footnotesize
38216 IC_RESULT = IC_LEFT / IC_RIGHT;
38217 \end_layout
38218
38219 \end_inset
38220 </cell>
38221 </row>
38222 <row topline="true">
38223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_inset Text
38225
38226 \begin_layout Standard
38227
38228 \size footnotesize
38229 '%'
38230 \end_layout
38231
38232 \end_inset
38233 </cell>
38234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38235 \begin_inset Text
38236
38237 \begin_layout Standard
38238
38239 \size footnotesize
38240 IC_LEFT() IC_RIGHT() IC_RESULT()
38241 \end_layout
38242
38243 \end_inset
38244 </cell>
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38246 \begin_inset Text
38247
38248 \begin_layout Standard
38249
38250 \size footnotesize
38251 Modulus
38252 \end_layout
38253
38254 \end_inset
38255 </cell>
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38257 \begin_inset Text
38258
38259 \begin_layout Standard
38260
38261 \size footnotesize
38262 IC_RESULT = IC_LEFT % IC_RIGHT;
38263 \end_layout
38264
38265 \end_inset
38266 </cell>
38267 </row>
38268 <row topline="true">
38269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_inset Text
38271
38272 \begin_layout Standard
38273
38274 \size footnotesize
38275 '<'
38276 \end_layout
38277
38278 \end_inset
38279 </cell>
38280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38281 \begin_inset Text
38282
38283 \begin_layout Standard
38284
38285 \size footnotesize
38286 IC_LEFT() IC_RIGHT() IC_RESULT()
38287 \end_layout
38288
38289 \end_inset
38290 </cell>
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38292 \begin_inset Text
38293
38294 \begin_layout Standard
38295
38296 \size footnotesize
38297 Less than
38298 \end_layout
38299
38300 \end_inset
38301 </cell>
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38303 \begin_inset Text
38304
38305 \begin_layout Standard
38306
38307 \size footnotesize
38308 IC_RESULT = IC_LEFT < IC_RIGHT;
38309 \end_layout
38310
38311 \end_inset
38312 </cell>
38313 </row>
38314 <row topline="true">
38315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38316 \begin_inset Text
38317
38318 \begin_layout Standard
38319
38320 \size footnotesize
38321 '>'
38322 \end_layout
38323
38324 \end_inset
38325 </cell>
38326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38327 \begin_inset Text
38328
38329 \begin_layout Standard
38330
38331 \size footnotesize
38332 IC_LEFT() IC_RIGHT() IC_RESULT()
38333 \end_layout
38334
38335 \end_inset
38336 </cell>
38337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38338 \begin_inset Text
38339
38340 \begin_layout Standard
38341
38342 \size footnotesize
38343 Greater than 
38344 \end_layout
38345
38346 \end_inset
38347 </cell>
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38349 \begin_inset Text
38350
38351 \begin_layout Standard
38352
38353 \size footnotesize
38354 IC_RESULT = IC_LEFT > IC_RIGHT;
38355 \end_layout
38356
38357 \end_inset
38358 </cell>
38359 </row>
38360 <row topline="true">
38361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38362 \begin_inset Text
38363
38364 \begin_layout Standard
38365
38366 \size footnotesize
38367 EQ_OP
38368 \end_layout
38369
38370 \end_inset
38371 </cell>
38372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38373 \begin_inset Text
38374
38375 \begin_layout Standard
38376
38377 \size footnotesize
38378 IC_LEFT() IC_RIGHT() IC_RESULT()
38379 \end_layout
38380
38381 \end_inset
38382 </cell>
38383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38384 \begin_inset Text
38385
38386 \begin_layout Standard
38387
38388 \size footnotesize
38389 Equal to 
38390 \end_layout
38391
38392 \end_inset
38393 </cell>
38394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38395 \begin_inset Text
38396
38397 \begin_layout Standard
38398
38399 \size footnotesize
38400 IC_RESULT = IC_LEFT == IC_RIGHT;
38401 \end_layout
38402
38403 \end_inset
38404 </cell>
38405 </row>
38406 <row topline="true">
38407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38408 \begin_inset Text
38409
38410 \begin_layout Standard
38411
38412 \size footnotesize
38413 AND_OP
38414 \end_layout
38415
38416 \end_inset
38417 </cell>
38418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38419 \begin_inset Text
38420
38421 \begin_layout Standard
38422
38423 \size footnotesize
38424 IC_LEFT() IC_RIGHT() IC_RESULT() 
38425 \end_layout
38426
38427 \end_inset
38428 </cell>
38429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38430 \begin_inset Text
38431
38432 \begin_layout Standard
38433
38434 \size footnotesize
38435 Logical and operation
38436 \end_layout
38437
38438 \end_inset
38439 </cell>
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38441 \begin_inset Text
38442
38443 \begin_layout Standard
38444
38445 \size footnotesize
38446 IC_RESULT = IC_LEFT && IC_RIGHT; 
38447 \end_layout
38448
38449 \end_inset
38450 </cell>
38451 </row>
38452 <row topline="true">
38453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38454 \begin_inset Text
38455
38456 \begin_layout Standard
38457
38458 \size footnotesize
38459 OR_OP
38460 \end_layout
38461
38462 \end_inset
38463 </cell>
38464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38465 \begin_inset Text
38466
38467 \begin_layout Standard
38468
38469 \size footnotesize
38470 IC_LEFT() IC_RIGHT() IC_RESULT() 
38471 \end_layout
38472
38473 \end_inset
38474 </cell>
38475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38476 \begin_inset Text
38477
38478 \begin_layout Standard
38479
38480 \size footnotesize
38481 Logical or operation 
38482 \end_layout
38483
38484 \end_inset
38485 </cell>
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38487 \begin_inset Text
38488
38489 \begin_layout Standard
38490
38491 \size footnotesize
38492 IC_RESULT = IC_LEFT || IC_RIGHT; 
38493 \end_layout
38494
38495 \end_inset
38496 </cell>
38497 </row>
38498 <row topline="true">
38499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_inset Text
38501
38502 \begin_layout Standard
38503
38504 \size footnotesize
38505 '^'
38506 \end_layout
38507
38508 \end_inset
38509 </cell>
38510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38511 \begin_inset Text
38512
38513 \begin_layout Standard
38514
38515 \size footnotesize
38516 IC_LEFT() IC_RIGHT() IC_RESULT() 
38517 \end_layout
38518
38519 \end_inset
38520 </cell>
38521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38522 \begin_inset Text
38523
38524 \begin_layout Standard
38525
38526 \size footnotesize
38527 Exclusive OR
38528 \end_layout
38529
38530 \end_inset
38531 </cell>
38532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38533 \begin_inset Text
38534
38535 \begin_layout Standard
38536
38537 \size footnotesize
38538 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38539 \end_layout
38540
38541 \end_inset
38542 </cell>
38543 </row>
38544 <row topline="true">
38545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38546 \begin_inset Text
38547
38548 \begin_layout Standard
38549
38550 \size footnotesize
38551 '|'
38552 \end_layout
38553
38554 \end_inset
38555 </cell>
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38557 \begin_inset Text
38558
38559 \begin_layout Standard
38560
38561 \size footnotesize
38562 IC_LEFT() IC_RIGHT() IC_RESULT() 
38563 \end_layout
38564
38565 \end_inset
38566 </cell>
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38568 \begin_inset Text
38569
38570 \begin_layout Standard
38571
38572 \size footnotesize
38573 Bitwise OR 
38574 \end_layout
38575
38576 \end_inset
38577 </cell>
38578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38579 \begin_inset Text
38580
38581 \begin_layout Standard
38582
38583 \size footnotesize
38584 IC_RESULT = IC_LEFT | IC_RIGHT;
38585 \end_layout
38586
38587 \end_inset
38588 </cell>
38589 </row>
38590 <row topline="true">
38591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38592 \begin_inset Text
38593
38594 \begin_layout Standard
38595
38596 \size footnotesize
38597 BITWISEAND
38598 \end_layout
38599
38600 \end_inset
38601 </cell>
38602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38603 \begin_inset Text
38604
38605 \begin_layout Standard
38606
38607 \size footnotesize
38608 IC_LEFT() IC_RIGHT() IC_RESULT()
38609 \end_layout
38610
38611 \end_inset
38612 </cell>
38613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38614 \begin_inset Text
38615
38616 \begin_layout Standard
38617
38618 \size footnotesize
38619 Bitwise AND 
38620 \end_layout
38621
38622 \end_inset
38623 </cell>
38624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38625 \begin_inset Text
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 IC_RESULT = IC_LEFT & IC_RIGHT;
38631 \end_layout
38632
38633 \end_inset
38634 </cell>
38635 </row>
38636 <row topline="true">
38637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38638 \begin_inset Text
38639
38640 \begin_layout Standard
38641
38642 \size footnotesize
38643 LEFT_OP
38644 \end_layout
38645
38646 \end_inset
38647 </cell>
38648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38649 \begin_inset Text
38650
38651 \begin_layout Standard
38652
38653 \size footnotesize
38654 IC_LEFT() IC_RIGHT() IC_RESULT()
38655 \end_layout
38656
38657 \end_inset
38658 </cell>
38659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38660 \begin_inset Text
38661
38662 \begin_layout Standard
38663
38664 \size footnotesize
38665 Left shift 
38666 \end_layout
38667
38668 \end_inset
38669 </cell>
38670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38671 \begin_inset Text
38672
38673 \begin_layout Standard
38674
38675 \size footnotesize
38676 IC_RESULT = IC_LEFT << IC_RIGHT 
38677 \end_layout
38678
38679 \end_inset
38680 </cell>
38681 </row>
38682 <row topline="true">
38683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38684 \begin_inset Text
38685
38686 \begin_layout Standard
38687
38688 \size footnotesize
38689 RIGHT_OP
38690 \end_layout
38691
38692 \end_inset
38693 </cell>
38694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38695 \begin_inset Text
38696
38697 \begin_layout Standard
38698
38699 \size footnotesize
38700 IC_LEFT() IC_RIGHT() IC_RESULT()
38701 \end_layout
38702
38703 \end_inset
38704 </cell>
38705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38706 \begin_inset Text
38707
38708 \begin_layout Standard
38709
38710 \size footnotesize
38711 Right shift
38712 \end_layout
38713
38714 \end_inset
38715 </cell>
38716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38717 \begin_inset Text
38718
38719 \begin_layout Standard
38720
38721 \size footnotesize
38722 IC_RESULT = IC_LEFT >> IC_RIGHT 
38723 \end_layout
38724
38725 \end_inset
38726 </cell>
38727 </row>
38728 <row topline="true">
38729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38730 \begin_inset Text
38731
38732 \begin_layout Standard
38733
38734 \size footnotesize
38735 GET_VALUE_
38736 \newline
38737 AT_ ADDRESS
38738 \end_layout
38739
38740 \end_inset
38741 </cell>
38742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38743 \begin_inset Text
38744
38745 \begin_layout Standard
38746
38747 \size footnotesize
38748 IC_LEFT() IC_RESULT()
38749 \end_layout
38750
38751 \end_inset
38752 </cell>
38753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38754 \begin_inset Text
38755
38756 \begin_layout Standard
38757
38758 \size footnotesize
38759 Indirect fetch 
38760 \end_layout
38761
38762 \end_inset
38763 </cell>
38764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38765 \begin_inset Text
38766
38767 \begin_layout Standard
38768
38769 \size footnotesize
38770 IC_RESULT = (*IC_LEFT);
38771 \end_layout
38772
38773 \end_inset
38774 </cell>
38775 </row>
38776 <row topline="true">
38777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38778 \begin_inset Text
38779
38780 \begin_layout Standard
38781
38782 \size footnotesize
38783 POINTER_SET
38784 \end_layout
38785
38786 \end_inset
38787 </cell>
38788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38789 \begin_inset Text
38790
38791 \begin_layout Standard
38792
38793 \size footnotesize
38794 IC_RIGHT() IC_RESULT() 
38795 \end_layout
38796
38797 \end_inset
38798 </cell>
38799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38800 \begin_inset Text
38801
38802 \begin_layout Standard
38803
38804 \size footnotesize
38805 Indirect set
38806 \end_layout
38807
38808 \end_inset
38809 </cell>
38810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38811 \begin_inset Text
38812
38813 \begin_layout Standard
38814
38815 \size footnotesize
38816 (*IC_RESULT) = IC_RIGHT;
38817 \end_layout
38818
38819 \end_inset
38820 </cell>
38821 </row>
38822 <row topline="true">
38823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38824 \begin_inset Text
38825
38826 \begin_layout Standard
38827
38828 \size footnotesize
38829 '='
38830 \end_layout
38831
38832 \end_inset
38833 </cell>
38834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38835 \begin_inset Text
38836
38837 \begin_layout Standard
38838
38839 \size footnotesize
38840 IC_RIGHT() IC_RESULT()
38841 \end_layout
38842
38843 \end_inset
38844 </cell>
38845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38846 \begin_inset Text
38847
38848 \begin_layout Standard
38849
38850 \size footnotesize
38851 Assignment
38852 \end_layout
38853
38854 \end_inset
38855 </cell>
38856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38857 \begin_inset Text
38858
38859 \begin_layout Standard
38860
38861 \size footnotesize
38862 IC_RESULT = IC_RIGHT;
38863 \end_layout
38864
38865 \end_inset
38866 </cell>
38867 </row>
38868 <row topline="true">
38869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38870 \begin_inset Text
38871
38872 \begin_layout Standard
38873
38874 \size footnotesize
38875 IFX
38876 \end_layout
38877
38878 \end_inset
38879 </cell>
38880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38881 \begin_inset Text
38882
38883 \begin_layout Standard
38884
38885 \size footnotesize
38886 IC_COND IC_TRUE IC_LABEL
38887 \end_layout
38888
38889 \end_inset
38890 </cell>
38891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38892 \begin_inset Text
38893
38894 \begin_layout Standard
38895
38896 \size footnotesize
38897 Conditional jump.
38898  If true label is present then jump to true label if condition is true else
38899  jump to false label if condition is false 
38900 \end_layout
38901
38902 \end_inset
38903 </cell>
38904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38905 \begin_inset Text
38906
38907 \begin_layout Standard
38908
38909 \size footnotesize
38910 if (IC_COND) goto IC_TRUE; 
38911 \newline
38912 \InsetSpace ~
38913 \InsetSpace ~
38914 Or 
38915 \newline
38916 If (!IC_COND) goto IC_FALSE;
38917 \end_layout
38918
38919 \end_inset
38920 </cell>
38921 </row>
38922 <row topline="true">
38923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38924 \begin_inset Text
38925
38926 \begin_layout Standard
38927
38928 \size footnotesize
38929 ADDRESS_OF
38930 \end_layout
38931
38932 \end_inset
38933 </cell>
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38935 \begin_inset Text
38936
38937 \begin_layout Standard
38938
38939 \size footnotesize
38940 IC_LEFT() IC_RESULT()
38941 \end_layout
38942
38943 \end_inset
38944 </cell>
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38946 \begin_inset Text
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 Address of 
38952 \end_layout
38953
38954 \end_inset
38955 </cell>
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38957 \begin_inset Text
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 IC_RESULT = &IC_LEFT();
38963 \end_layout
38964
38965 \end_inset
38966 </cell>
38967 </row>
38968 <row topline="true">
38969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38970 \begin_inset Text
38971
38972 \begin_layout Standard
38973
38974 \size footnotesize
38975 JUMPTABLE
38976 \end_layout
38977
38978 \end_inset
38979 </cell>
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38981 \begin_inset Text
38982
38983 \begin_layout Standard
38984
38985 \size footnotesize
38986 IC_JTCOND IC_JTLABELS
38987 \end_layout
38988
38989 \end_inset
38990 </cell>
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38992 \begin_inset Text
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 Jump to list of labels depending on the value of JTCOND
38998 \end_layout
38999
39000 \end_inset
39001 </cell>
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39003 \begin_inset Text
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 Switch statement
39009 \end_layout
39010
39011 \end_inset
39012 </cell>
39013 </row>
39014 <row topline="true">
39015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39016 \begin_inset Text
39017
39018 \begin_layout Standard
39019
39020 \size footnotesize
39021 CAST
39022 \end_layout
39023
39024 \end_inset
39025 </cell>
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39027 \begin_inset Text
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 IC_RIGHT() IC_LEFT() IC_RESULT()
39033 \end_layout
39034
39035 \end_inset
39036 </cell>
39037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39038 \begin_inset Text
39039
39040 \begin_layout Standard
39041
39042 \size footnotesize
39043 Cast types 
39044 \end_layout
39045
39046 \end_inset
39047 </cell>
39048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39049 \begin_inset Text
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39055 \end_layout
39056
39057 \end_inset
39058 </cell>
39059 </row>
39060 <row topline="true">
39061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39062 \begin_inset Text
39063
39064 \begin_layout Standard
39065
39066 \size footnotesize
39067 SEND
39068 \end_layout
39069
39070 \end_inset
39071 </cell>
39072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39073 \begin_inset Text
39074
39075 \begin_layout Standard
39076
39077 \size footnotesize
39078 IC_LEFT()
39079 \end_layout
39080
39081 \end_inset
39082 </cell>
39083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39084 \begin_inset Text
39085
39086 \begin_layout Standard
39087
39088 \size footnotesize
39089 This is used for passing parameters in registers; 
39090 \newline
39091 move IC_LEFT to the next
39092  available parameter register.
39093 \end_layout
39094
39095 \end_inset
39096 </cell>
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39098 \begin_inset Text
39099
39100 \begin_layout Standard
39101
39102 \size footnotesize
39103 None
39104 \end_layout
39105
39106 \end_inset
39107 </cell>
39108 </row>
39109 <row topline="true">
39110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39111 \begin_inset Text
39112
39113 \begin_layout Standard
39114
39115 \size footnotesize
39116 RECV
39117 \end_layout
39118
39119 \end_inset
39120 </cell>
39121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39122 \begin_inset Text
39123
39124 \begin_layout Standard
39125
39126 \size footnotesize
39127 IC_RESULT()
39128 \end_layout
39129
39130 \end_inset
39131 </cell>
39132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39133 \begin_inset Text
39134
39135 \begin_layout Standard
39136
39137 \size footnotesize
39138 This is used for receiving parameters passed in registers;
39139 \newline
39140 Move the values
39141  in the next parameter register to IC_RESULT 
39142 \end_layout
39143
39144 \end_inset
39145 </cell>
39146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39147 \begin_inset Text
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 None
39153 \end_layout
39154
39155 \end_inset
39156 </cell>
39157 </row>
39158 <row topline="true" bottomline="true">
39159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39160 \begin_inset Text
39161
39162 \begin_layout Standard
39163
39164 \shape slanted
39165 \size footnotesize
39166 (some more have been added)
39167 \end_layout
39168
39169 \end_inset
39170 </cell>
39171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39172 \begin_inset Text
39173
39174 \begin_layout Standard
39175
39176 \end_layout
39177
39178 \end_inset
39179 </cell>
39180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39181 \begin_inset Text
39182
39183 \begin_layout Standard
39184
39185 \end_layout
39186
39187 \end_inset
39188 </cell>
39189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39190 \begin_inset Text
39191
39192 \begin_layout Standard
39193
39194 \shape slanted
39195 \size footnotesize
39196 see f.e.
39197  
39198 \family typewriter
39199 gen51Code()
39200 \family default
39201  in 
39202 \family typewriter
39203 src/mcs51/gen.c
39204 \end_layout
39205
39206 \end_inset
39207 </cell>
39208 </row>
39209 </lyxtabular>
39210
39211 \end_inset
39212
39213
39214 \end_layout
39215
39216 \begin_layout Standard
39217 \begin_inset Note Note
39218 status collapsed
39219
39220 \begin_layout Standard
39221 In the original article Figure II was announced to be downloadable on 
39222 \shape italic
39223 Circuit Cellar
39224 \shape default
39225 's web site.
39226  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39227 \end_layout
39228
39229 \end_inset
39230
39231
39232 \end_layout
39233
39234 \begin_layout Paragraph*
39235 ICode Example
39236 \begin_inset LatexCommand \index{iCode}
39237
39238 \end_inset
39239
39240
39241 \end_layout
39242
39243 \begin_layout Standard
39244 This section shows some details of iCode.
39245  The example C code does not do anything useful; it is used as an example
39246  to illustrate the intermediate code generated by the compiler.
39247 \end_layout
39248
39249 \begin_layout Verse
39250
39251 \family typewriter
39252 1.\InsetSpace ~
39253 xdata int * p;
39254 \newline
39255 2.\InsetSpace ~
39256 int gint;
39257 \newline
39258 3.\InsetSpace ~
39259 /* This function does nothing useful.
39260  It is used
39261 \newline
39262 4.\InsetSpace ~
39263 \InsetSpace ~
39264 \InsetSpace ~
39265 \InsetSpace ~
39266 for the purpose of explaining iCode */
39267 \newline
39268 5.\InsetSpace ~
39269 short function (data
39270  int *x)
39271 \newline
39272 6.\InsetSpace ~
39273 {
39274 \newline
39275 7.\InsetSpace ~
39276 \InsetSpace ~
39277 \InsetSpace ~
39278 short i=10; \InsetSpace ~
39279 \InsetSpace ~
39280 /* dead initialization eliminated */
39281 \newline
39282 8.\InsetSpace ~
39283 \InsetSpace ~
39284 \InsetSpace ~
39285 short sum=10;
39286  /* dead initialization eliminated */
39287 \newline
39288 9.\InsetSpace ~
39289 \InsetSpace ~
39290 \InsetSpace ~
39291 short mul;
39292 \newline
39293 10.\InsetSpace ~
39294 \InsetSpace ~
39295 int j ;
39296 \newline
39297 11.\InsetSpace ~
39298 \InsetSpace ~
39299 while (*x) *x++
39300  = *p++; 
39301 \newline
39302 12.\InsetSpace ~
39303 \InsetSpace ~
39304 \InsetSpace ~
39305 \InsetSpace ~
39306 sum = 0 ; 
39307 \newline
39308 13.\InsetSpace ~
39309 \InsetSpace ~
39310 mul = 0;
39311 \newline
39312 14.\InsetSpace ~
39313 \InsetSpace ~
39314 /* compiler detects i,j to be induction
39315  variables */
39316 \newline
39317 15.\InsetSpace ~
39318 \InsetSpace ~
39319 for (i = 0, j = 10 ; i < 10 ; i++, j
39320 \family default
39321 -
39322 \begin_inset ERT
39323 status collapsed
39324
39325 \begin_layout Standard
39326
39327
39328 \backslash
39329 /
39330 \end_layout
39331
39332 \end_inset
39333
39334 -
39335 \family typewriter
39336 ) {
39337 \newline
39338 16.\InsetSpace ~
39339 \InsetSpace ~
39340 \InsetSpace ~
39341 \InsetSpace ~
39342 sum += i;
39343 \newline
39344 17.\InsetSpace ~
39345 \InsetSpace ~
39346 \InsetSpace ~
39347 \InsetSpace ~
39348 mul += i * 3; \InsetSpace ~
39349 \InsetSpace ~
39350 /* this multiplication remains */
39351 \newline
39352 18.\InsetSpace ~
39353 \InsetSpace ~
39354 \InsetSpace ~
39355 \InsetSpace ~
39356 gint +=
39357  j * 3;\InsetSpace ~
39358 \InsetSpace ~
39359 /* this multiplication changed to addition */
39360 \newline
39361 19.\InsetSpace ~
39362 \InsetSpace ~
39363 }
39364 \newline
39365 20.\InsetSpace ~
39366 \InsetSpace ~
39367 return sum+mul;
39368 \newline
39369 21.\InsetSpace ~
39370 }
39371 \end_layout
39372
39373 \begin_layout Standard
39374 In addition to the operands each iCode contains information about the filename
39375  and line it corresponds to in the source file.
39376  The first field in the listing should be interpreted as follows:
39377 \newline
39378
39379 \shape italic
39380 \size footnotesize
39381 Filename(linenumber: iCode Execution sequence number : ICode hash table
39382  key : loop depth of the iCode).
39383 \shape default
39384 \size default
39385
39386 \newline
39387 Then follows the human readable form of the ICode operation.
39388  Each operand of this triplet form can be of three basic types a) compiler
39389  generated temporary b) user defined variable c) a constant value.
39390  Note that local variables and parameters are replaced by compiler generated
39391  temporaries.
39392  Live ranges
39393 \begin_inset LatexCommand \index{Live range analysis}
39394
39395 \end_inset
39396
39397  are computed only for temporaries (i.e.
39398  live ranges are not computed for global variables).
39399  Registers
39400 \begin_inset LatexCommand \index{Register allocation}
39401
39402 \end_inset
39403
39404  are allocated for temporaries only.
39405  Operands are formatted in the following manner:
39406 \newline
39407
39408 \shape italic
39409 \size footnotesize
39410 Operand Name [lr live-from : live-to ] { type information } [ registers
39411  allocated ].
39412 \shape default
39413 \size default
39414
39415 \newline
39416 As mentioned earlier the live ranges are computed in terms of the execution
39417  sequence number of the iCodes, for example 
39418 \newline
39419 the iTemp0 is live from (i.e.
39420  first defined in iCode with execution sequence number 3, and is last used
39421  in the iCode with sequence number 5).
39422  For induction variables such as iTemp21 the live range computation extends
39423  the lifetime from the start to the end of the loop.
39424 \newline
39425 The register allocator
39426  used the live range information to allocate registers, the same registers
39427  may be used for different temporaries if their live ranges do not overlap,
39428  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39429  ranges do not overlap.
39430  In addition the allocator also takes into consideration the type and usage
39431  of a temporary, for example itemp6 is a pointer to near space and is used
39432  as to fetch data from (i.e.
39433  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39434  Some short lived temporaries are allocated to special registers which have
39435  meaning to the code generator e.g.
39436  iTemp13 is allocated to a pseudo register CC which tells the back end that
39437  the temporary is used only for a conditional jump the code generation makes
39438  use of this information to optimize a compare and jump ICode.
39439 \newline
39440 There are several
39441  loop optimizations
39442 \begin_inset LatexCommand \index{Loop optimization}
39443
39444 \end_inset
39445
39446  performed by the compiler.
39447  It can detect induction variables iTemp21(i) and iTemp23(j).
39448  Also note the compiler does selective strength reduction
39449 \begin_inset LatexCommand \index{Strength reduction}
39450
39451 \end_inset
39452
39453 , i.e.
39454  the multiplication of an induction variable in line 18 (gint = j * 3) is
39455  changed to addition, a new temporary iTemp17 is allocated and assigned
39456  a initial value, a constant 3 is then added for each iteration of the loop.
39457  The compiler does not change the multiplication
39458 \begin_inset LatexCommand \index{Multiplication}
39459
39460 \end_inset
39461
39462  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39463 \newline
39464
39465 Note the dead code elimination
39466 \begin_inset LatexCommand \index{Dead-code elimination}
39467
39468 \end_inset
39469
39470  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39471  respectively.
39472 \newline
39473
39474 \end_layout
39475
39476 \begin_layout Standard
39477
39478 \size footnotesize
39479 Sample.c (5:1:0:0) _entry($9) :
39480 \end_layout
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39486 \end_layout
39487
39488 \begin_layout Standard
39489
39490 \size footnotesize
39491 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39492 \end_layout
39493
39494 \begin_layout Standard
39495
39496 \size footnotesize
39497 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39498 \end_layout
39499
39500 \begin_layout Standard
39501
39502 \size footnotesize
39503 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39504  * int}[r2]
39505 \end_layout
39506
39507 \begin_layout Standard
39508
39509 \size footnotesize
39510 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39511 \end_layout
39512
39513 \begin_layout Standard
39514
39515 \size footnotesize
39516 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39517  int}[r0]]
39518 \end_layout
39519
39520 \begin_layout Standard
39521
39522 \size footnotesize
39523 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39524 \end_layout
39525
39526 \begin_layout Standard
39527
39528 \size footnotesize
39529 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39530  * int}
39531 \end_layout
39532
39533 \begin_layout Standard
39534
39535 \size footnotesize
39536 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39537  {short}
39538 \end_layout
39539
39540 \begin_layout Standard
39541
39542 \size footnotesize
39543 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39544  * int}[DPTR]]
39545 \end_layout
39546
39547 \begin_layout Standard
39548
39549 \size footnotesize
39550 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39551 }[r2 r3]
39552 \end_layout
39553
39554 \begin_layout Standard
39555
39556 \size footnotesize
39557 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39558  * int}[r0] + 0x2 {short}
39559 \end_layout
39560
39561 \begin_layout Standard
39562
39563 \size footnotesize
39564 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39565 \end_layout
39566
39567 \begin_layout Standard
39568
39569 \size footnotesize
39570 Sample.c(11:17:21:0)_whilebreak_0($3) :
39571 \end_layout
39572
39573 \begin_layout Standard
39574
39575 \size footnotesize
39576 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39577 \end_layout
39578
39579 \begin_layout Standard
39580
39581 \size footnotesize
39582 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39583 \end_layout
39584
39585 \begin_layout Standard
39586
39587 \size footnotesize
39588 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39589 \end_layout
39590
39591 \begin_layout Standard
39592
39593 \size footnotesize
39594 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39595 \end_layout
39596
39597 \begin_layout Standard
39598
39599 \size footnotesize
39600 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39601 \end_layout
39602
39603 \begin_layout Standard
39604
39605 \size footnotesize
39606 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39607 \end_layout
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 Sample.c(15:24:26:1)_forcond_0($4) :
39613 \end_layout
39614
39615 \begin_layout Standard
39616
39617 \size footnotesize
39618 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39619  < 0xa {short}
39620 \end_layout
39621
39622 \begin_layout Standard
39623
39624 \size footnotesize
39625 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39626 \end_layout
39627
39628 \begin_layout Standard
39629
39630 \size footnotesize
39631 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39632  + ITemp21 [lr21:38]{short}[r4]
39633 \end_layout
39634
39635 \begin_layout Standard
39636
39637 \size footnotesize
39638 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39639  * 0x3 {short}
39640 \end_layout
39641
39642 \begin_layout Standard
39643
39644 \size footnotesize
39645 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39646  + iTemp15 [lr29:30]{short}[r1]
39647 \end_layout
39648
39649 \begin_layout Standard
39650
39651 \size footnotesize
39652 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39653  r0]- 0x3 {short}
39654 \end_layout
39655
39656 \begin_layout Standard
39657
39658 \size footnotesize
39659 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39660 int}[r7 r0]
39661 \end_layout
39662
39663 \begin_layout Standard
39664
39665 \size footnotesize
39666 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39667  + 0x1 {short}
39668 \end_layout
39669
39670 \begin_layout Standard
39671
39672 \size footnotesize
39673 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39674  r6]- 0x1 {short}
39675 \end_layout
39676
39677 \begin_layout Standard
39678
39679 \size footnotesize
39680 Sample.c(19:38:47:1) goto _forcond_0($4)
39681 \end_layout
39682
39683 \begin_layout Standard
39684
39685 \size footnotesize
39686 Sample.c(19:39:48:0)_forbreak_0($7) :
39687 \end_layout
39688
39689 \begin_layout Standard
39690
39691 \size footnotesize
39692 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39693  + ITemp11 [lr19:40]{short}[r3]
39694 \end_layout
39695
39696 \begin_layout Standard
39697
39698 \size footnotesize
39699 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39700 \end_layout
39701
39702 \begin_layout Standard
39703
39704 \size footnotesize
39705 Sample.c(20:42:51:0)_return($8) :
39706 \end_layout
39707
39708 \begin_layout Standard
39709
39710 \size footnotesize
39711 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39712 \size default
39713
39714 \newline
39715
39716 \newline
39717 Finally the code generated for this function:
39718 \newline
39719
39720 \end_layout
39721
39722 \begin_layout Standard
39723
39724 \size footnotesize
39725 .area DSEG (DATA)
39726 \end_layout
39727
39728 \begin_layout Standard
39729
39730 \size footnotesize
39731 _p::
39732 \end_layout
39733
39734 \begin_layout Standard
39735
39736 \size footnotesize
39737 \InsetSpace ~
39738 \InsetSpace ~
39739 .ds 2
39740 \end_layout
39741
39742 \begin_layout Standard
39743
39744 \size footnotesize
39745 _gint::
39746 \end_layout
39747
39748 \begin_layout Standard
39749
39750 \size footnotesize
39751 \InsetSpace ~
39752 \InsetSpace ~
39753 .ds 2
39754 \end_layout
39755
39756 \begin_layout Standard
39757
39758 \size footnotesize
39759 ; sample.c 5
39760 \end_layout
39761
39762 \begin_layout Standard
39763
39764 \size footnotesize
39765 ; ----------------------------------------------
39766 \end_layout
39767
39768 \begin_layout Standard
39769
39770 \size footnotesize
39771 ; function function
39772 \end_layout
39773
39774 \begin_layout Standard
39775
39776 \size footnotesize
39777 ; ----------------------------------------------
39778 \end_layout
39779
39780 \begin_layout Standard
39781
39782 \size footnotesize
39783 _function:
39784 \end_layout
39785
39786 \begin_layout Standard
39787
39788 \size footnotesize
39789 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39790 \end_layout
39791
39792 \begin_layout Standard
39793
39794 \size footnotesize
39795 \InsetSpace ~
39796 \InsetSpace ~
39797 mov r2,dpl
39798 \end_layout
39799
39800 \begin_layout Standard
39801
39802 \size footnotesize
39803 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39804 \end_layout
39805
39806 \begin_layout Standard
39807
39808 \size footnotesize
39809 \InsetSpace ~
39810 \InsetSpace ~
39811 mov ar0,r2
39812 \end_layout
39813
39814 \begin_layout Standard
39815
39816 \size footnotesize
39817 ;_whilecontinue_0($1) :
39818 \end_layout
39819
39820 \begin_layout Standard
39821
39822 \size footnotesize
39823 00101$:
39824 \end_layout
39825
39826 \begin_layout Standard
39827
39828 \size footnotesize
39829 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39830 \end_layout
39831
39832 \begin_layout Standard
39833
39834 \size footnotesize
39835 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39836 \end_layout
39837
39838 \begin_layout Standard
39839
39840 \size footnotesize
39841 \InsetSpace ~
39842 \InsetSpace ~
39843 mov ar2,@r0
39844 \end_layout
39845
39846 \begin_layout Standard
39847
39848 \size footnotesize
39849 \InsetSpace ~
39850 \InsetSpace ~
39851 inc r0
39852 \end_layout
39853
39854 \begin_layout Standard
39855
39856 \size footnotesize
39857 \InsetSpace ~
39858 \InsetSpace ~
39859 mov ar3,@r0
39860 \end_layout
39861
39862 \begin_layout Standard
39863
39864 \size footnotesize
39865 \InsetSpace ~
39866 \InsetSpace ~
39867 dec r0
39868 \end_layout
39869
39870 \begin_layout Standard
39871
39872 \size footnotesize
39873 \InsetSpace ~
39874 \InsetSpace ~
39875 mov a,r2
39876 \end_layout
39877
39878 \begin_layout Standard
39879
39880 \size footnotesize
39881 \InsetSpace ~
39882 \InsetSpace ~
39883 orl a,r3
39884 \end_layout
39885
39886 \begin_layout Standard
39887
39888 \size footnotesize
39889 \InsetSpace ~
39890 \InsetSpace ~
39891 jz 00103$
39892 \end_layout
39893
39894 \begin_layout Standard
39895
39896 \size footnotesize
39897 00114$:
39898 \end_layout
39899
39900 \begin_layout Standard
39901
39902 \size footnotesize
39903 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39904 \end_layout
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 \InsetSpace ~
39910 \InsetSpace ~
39911 mov dpl,_p
39912 \end_layout
39913
39914 \begin_layout Standard
39915
39916 \size footnotesize
39917 \InsetSpace ~
39918 \InsetSpace ~
39919 mov dph,(_p + 1)
39920 \end_layout
39921
39922 \begin_layout Standard
39923
39924 \size footnotesize
39925 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39926 \end_layout
39927
39928 \begin_layout Standard
39929
39930 \size footnotesize
39931 \InsetSpace ~
39932 \InsetSpace ~
39933 mov a,#0x02
39934 \end_layout
39935
39936 \begin_layout Standard
39937
39938 \size footnotesize
39939 \InsetSpace ~
39940 \InsetSpace ~
39941 add a,_p
39942 \end_layout
39943
39944 \begin_layout Standard
39945
39946 \size footnotesize
39947 \InsetSpace ~
39948 \InsetSpace ~
39949 mov _p,a
39950 \end_layout
39951
39952 \begin_layout Standard
39953
39954 \size footnotesize
39955 \InsetSpace ~
39956 \InsetSpace ~
39957 clr a
39958 \end_layout
39959
39960 \begin_layout Standard
39961
39962 \size footnotesize
39963 \InsetSpace ~
39964 \InsetSpace ~
39965 addc a,(_p + 1)
39966 \end_layout
39967
39968 \begin_layout Standard
39969
39970 \size footnotesize
39971 \InsetSpace ~
39972 \InsetSpace ~
39973 mov (_p + 1),a
39974 \end_layout
39975
39976 \begin_layout Standard
39977
39978 \size footnotesize
39979 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39980 \end_layout
39981
39982 \begin_layout Standard
39983
39984 \size footnotesize
39985 \InsetSpace ~
39986 \InsetSpace ~
39987 movx a,@dptr
39988 \end_layout
39989
39990 \begin_layout Standard
39991
39992 \size footnotesize
39993 \InsetSpace ~
39994 \InsetSpace ~
39995 mov r2,a
39996 \end_layout
39997
39998 \begin_layout Standard
39999
40000 \size footnotesize
40001 \InsetSpace ~
40002 \InsetSpace ~
40003 inc dptr
40004 \end_layout
40005
40006 \begin_layout Standard
40007
40008 \size footnotesize
40009 \InsetSpace ~
40010 \InsetSpace ~
40011 movx a,@dptr
40012 \end_layout
40013
40014 \begin_layout Standard
40015
40016 \size footnotesize
40017 \InsetSpace ~
40018 \InsetSpace ~
40019 mov r3,a
40020 \end_layout
40021
40022 \begin_layout Standard
40023
40024 \size footnotesize
40025 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40026 \end_layout
40027
40028 \begin_layout Standard
40029
40030 \size footnotesize
40031 \InsetSpace ~
40032 \InsetSpace ~
40033 mov @r0,ar2
40034 \end_layout
40035
40036 \begin_layout Standard
40037
40038 \size footnotesize
40039 \InsetSpace ~
40040 \InsetSpace ~
40041 inc r0
40042 \end_layout
40043
40044 \begin_layout Standard
40045
40046 \size footnotesize
40047 \InsetSpace ~
40048 \InsetSpace ~
40049 mov @r0,ar3
40050 \end_layout
40051
40052 \begin_layout Standard
40053
40054 \size footnotesize
40055 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40056 \end_layout
40057
40058 \begin_layout Standard
40059
40060 \size footnotesize
40061 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40062 \end_layout
40063
40064 \begin_layout Standard
40065
40066 \size footnotesize
40067 ; 0x2 {short}
40068 \end_layout
40069
40070 \begin_layout Standard
40071
40072 \size footnotesize
40073 \InsetSpace ~
40074 \InsetSpace ~
40075 inc r0
40076 \end_layout
40077
40078 \begin_layout Standard
40079
40080 \size footnotesize
40081 ; goto _whilecontinue_0($1)
40082 \end_layout
40083
40084 \begin_layout Standard
40085
40086 \size footnotesize
40087 \InsetSpace ~
40088 \InsetSpace ~
40089 sjmp 00101$
40090 \end_layout
40091
40092 \begin_layout Standard
40093
40094 \size footnotesize
40095 ; _whilebreak_0($3) :
40096 \end_layout
40097
40098 \begin_layout Standard
40099
40100 \size footnotesize
40101 00103$:
40102 \end_layout
40103
40104 \begin_layout Standard
40105
40106 \size footnotesize
40107 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40108 \end_layout
40109
40110 \begin_layout Standard
40111
40112 \size footnotesize
40113 \InsetSpace ~
40114 \InsetSpace ~
40115 mov r2,#0x00
40116 \end_layout
40117
40118 \begin_layout Standard
40119
40120 \size footnotesize
40121 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40122 \end_layout
40123
40124 \begin_layout Standard
40125
40126 \size footnotesize
40127 \InsetSpace ~
40128 \InsetSpace ~
40129 mov r3,#0x00
40130 \end_layout
40131
40132 \begin_layout Standard
40133
40134 \size footnotesize
40135 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40136 \end_layout
40137
40138 \begin_layout Standard
40139
40140 \size footnotesize
40141 \InsetSpace ~
40142 \InsetSpace ~
40143 mov r4,#0x00
40144 \end_layout
40145
40146 \begin_layout Standard
40147
40148 \size footnotesize
40149 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40150 \end_layout
40151
40152 \begin_layout Standard
40153
40154 \size footnotesize
40155 \InsetSpace ~
40156 \InsetSpace ~
40157 mov r5,#0x0A
40158 \end_layout
40159
40160 \begin_layout Standard
40161
40162 \size footnotesize
40163 \InsetSpace ~
40164 \InsetSpace ~
40165 mov r6,#0x00
40166 \end_layout
40167
40168 \begin_layout Standard
40169
40170 \size footnotesize
40171 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40172 \end_layout
40173
40174 \begin_layout Standard
40175
40176 \size footnotesize
40177 \InsetSpace ~
40178 \InsetSpace ~
40179 mov r7,#0x1E
40180 \end_layout
40181
40182 \begin_layout Standard
40183
40184 \size footnotesize
40185 \InsetSpace ~
40186 \InsetSpace ~
40187 mov r0,#0x00
40188 \end_layout
40189
40190 \begin_layout Standard
40191
40192 \size footnotesize
40193 ; _forcond_0($4) :
40194 \end_layout
40195
40196 \begin_layout Standard
40197
40198 \size footnotesize
40199 00104$:
40200 \end_layout
40201
40202 \begin_layout Standard
40203
40204 \size footnotesize
40205 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40206 \end_layout
40207
40208 \begin_layout Standard
40209
40210 \size footnotesize
40211 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40212 \end_layout
40213
40214 \begin_layout Standard
40215
40216 \size footnotesize
40217 \InsetSpace ~
40218 \InsetSpace ~
40219 clr c
40220 \end_layout
40221
40222 \begin_layout Standard
40223
40224 \size footnotesize
40225 \InsetSpace ~
40226 \InsetSpace ~
40227 mov a,r4
40228 \end_layout
40229
40230 \begin_layout Standard
40231
40232 \size footnotesize
40233 \InsetSpace ~
40234 \InsetSpace ~
40235 xrl a,#0x80
40236 \end_layout
40237
40238 \begin_layout Standard
40239
40240 \size footnotesize
40241 \InsetSpace ~
40242 \InsetSpace ~
40243 subb a,#0x8a
40244 \end_layout
40245
40246 \begin_layout Standard
40247
40248 \size footnotesize
40249 \InsetSpace ~
40250 \InsetSpace ~
40251 jnc 00107$
40252 \end_layout
40253
40254 \begin_layout Standard
40255
40256 \size footnotesize
40257 00115$:
40258 \end_layout
40259
40260 \begin_layout Standard
40261
40262 \size footnotesize
40263 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40264 \end_layout
40265
40266 \begin_layout Standard
40267
40268 \size footnotesize
40269 ; iTemp21 [lr21:38]{short}[r4]
40270 \end_layout
40271
40272 \begin_layout Standard
40273
40274 \size footnotesize
40275 \InsetSpace ~
40276 \InsetSpace ~
40277 mov a,r4
40278 \end_layout
40279
40280 \begin_layout Standard
40281
40282 \size footnotesize
40283 \InsetSpace ~
40284 \InsetSpace ~
40285 add a,r2
40286 \end_layout
40287
40288 \begin_layout Standard
40289
40290 \size footnotesize
40291 \InsetSpace ~
40292 \InsetSpace ~
40293 mov r2,a
40294 \end_layout
40295
40296 \begin_layout Standard
40297
40298 \size footnotesize
40299 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40300 \end_layout
40301
40302 \begin_layout Standard
40303
40304 \size footnotesize
40305 \InsetSpace ~
40306 \InsetSpace ~
40307 mov b,#0x03
40308 \end_layout
40309
40310 \begin_layout Standard
40311
40312 \size footnotesize
40313 \InsetSpace ~
40314 \InsetSpace ~
40315 mov a,r4
40316 \end_layout
40317
40318 \begin_layout Standard
40319
40320 \size footnotesize
40321 \InsetSpace ~
40322 \InsetSpace ~
40323 mul ab
40324 \end_layout
40325
40326 \begin_layout Standard
40327
40328 \size footnotesize
40329 \InsetSpace ~
40330 \InsetSpace ~
40331 mov r1,a
40332 \end_layout
40333
40334 \begin_layout Standard
40335
40336 \size footnotesize
40337 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40338 \end_layout
40339
40340 \begin_layout Standard
40341
40342 \size footnotesize
40343 ; iTemp15 [lr29:30]{short}[r1]
40344 \end_layout
40345
40346 \begin_layout Standard
40347
40348 \size footnotesize
40349 \InsetSpace ~
40350 \InsetSpace ~
40351 add a,r3
40352 \end_layout
40353
40354 \begin_layout Standard
40355
40356 \size footnotesize
40357 \InsetSpace ~
40358 \InsetSpace ~
40359 mov r3,a
40360 \end_layout
40361
40362 \begin_layout Standard
40363
40364 \size footnotesize
40365 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40366 \end_layout
40367
40368 \begin_layout Standard
40369
40370 \size footnotesize
40371 \InsetSpace ~
40372 \InsetSpace ~
40373 mov a,r7
40374 \end_layout
40375
40376 \begin_layout Standard
40377
40378 \size footnotesize
40379 \InsetSpace ~
40380 \InsetSpace ~
40381 add a,#0xfd
40382 \end_layout
40383
40384 \begin_layout Standard
40385
40386 \size footnotesize
40387 \InsetSpace ~
40388 \InsetSpace ~
40389 mov r7,a
40390 \end_layout
40391
40392 \begin_layout Standard
40393
40394 \size footnotesize
40395 \InsetSpace ~
40396 \InsetSpace ~
40397 mov a,r0
40398 \end_layout
40399
40400 \begin_layout Standard
40401
40402 \size footnotesize
40403 \InsetSpace ~
40404 \InsetSpace ~
40405 addc a,#0xff
40406 \end_layout
40407
40408 \begin_layout Standard
40409
40410 \size footnotesize
40411 \InsetSpace ~
40412 \InsetSpace ~
40413 mov r0,a
40414 \end_layout
40415
40416 \begin_layout Standard
40417
40418 \size footnotesize
40419 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40420 \end_layout
40421
40422 \begin_layout Standard
40423
40424 \size footnotesize
40425 \InsetSpace ~
40426 \InsetSpace ~
40427 mov a,r7
40428 \end_layout
40429
40430 \begin_layout Standard
40431
40432 \size footnotesize
40433 \InsetSpace ~
40434 \InsetSpace ~
40435 add a,_gint
40436 \end_layout
40437
40438 \begin_layout Standard
40439
40440 \size footnotesize
40441 \InsetSpace ~
40442 \InsetSpace ~
40443 mov _gint,a
40444 \end_layout
40445
40446 \begin_layout Standard
40447
40448 \size footnotesize
40449 \InsetSpace ~
40450 \InsetSpace ~
40451 mov a,r0
40452 \end_layout
40453
40454 \begin_layout Standard
40455
40456 \size footnotesize
40457 \InsetSpace ~
40458 \InsetSpace ~
40459 addc a,(_gint + 1)
40460 \end_layout
40461
40462 \begin_layout Standard
40463
40464 \size footnotesize
40465 \InsetSpace ~
40466 \InsetSpace ~
40467 mov (_gint + 1),a
40468 \end_layout
40469
40470 \begin_layout Standard
40471
40472 \size footnotesize
40473 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40474 \end_layout
40475
40476 \begin_layout Standard
40477
40478 \size footnotesize
40479 \InsetSpace ~
40480 \InsetSpace ~
40481 inc r4
40482 \end_layout
40483
40484 \begin_layout Standard
40485
40486 \size footnotesize
40487 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40488 \end_layout
40489
40490 \begin_layout Standard
40491
40492 \size footnotesize
40493 \InsetSpace ~
40494 \InsetSpace ~
40495 dec r5
40496 \end_layout
40497
40498 \begin_layout Standard
40499
40500 \size footnotesize
40501 \InsetSpace ~
40502 \InsetSpace ~
40503 cjne r5,#0xff,00104$
40504 \end_layout
40505
40506 \begin_layout Standard
40507
40508 \size footnotesize
40509 \InsetSpace ~
40510 \InsetSpace ~
40511 dec r6
40512 \end_layout
40513
40514 \begin_layout Standard
40515
40516 \size footnotesize
40517 ; goto _forcond_0($4)
40518 \end_layout
40519
40520 \begin_layout Standard
40521
40522 \size footnotesize
40523 \InsetSpace ~
40524 \InsetSpace ~
40525 sjmp 00104$
40526 \end_layout
40527
40528 \begin_layout Standard
40529
40530 \size footnotesize
40531 ; _forbreak_0($7) :
40532 \end_layout
40533
40534 \begin_layout Standard
40535
40536 \size footnotesize
40537 00107$:
40538 \end_layout
40539
40540 \begin_layout Standard
40541
40542 \size footnotesize
40543 ; ret iTemp24 [lr40:41]{short}
40544 \end_layout
40545
40546 \begin_layout Standard
40547
40548 \size footnotesize
40549 \InsetSpace ~
40550 \InsetSpace ~
40551 mov a,r3
40552 \end_layout
40553
40554 \begin_layout Standard
40555
40556 \size footnotesize
40557 \InsetSpace ~
40558 \InsetSpace ~
40559 add a,r2
40560 \end_layout
40561
40562 \begin_layout Standard
40563
40564 \size footnotesize
40565 \InsetSpace ~
40566 \InsetSpace ~
40567 mov dpl,a
40568 \end_layout
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 ; _return($8) :
40574 \end_layout
40575
40576 \begin_layout Standard
40577
40578 \size footnotesize
40579 00108$:
40580 \end_layout
40581
40582 \begin_layout Standard
40583
40584 \size footnotesize
40585 \InsetSpace ~
40586 \InsetSpace ~
40587 ret
40588 \newline
40589
40590 \end_layout
40591
40592 \begin_layout Section
40593 A few words about basic block successors, predecessors and dominators
40594 \end_layout
40595
40596 \begin_layout Standard
40597 Successors are basic blocks
40598 \begin_inset LatexCommand \index{Basic blocks}
40599
40600 \end_inset
40601
40602  that might execute after this basic block.
40603 \newline
40604 Predecessors are basic blocks
40605  that might execute before reaching this basic block.
40606 \newline
40607 Dominators are basic
40608  blocks that WILL execute before reaching this basic block.
40609 \newline
40610
40611 \end_layout
40612
40613 \begin_layout Standard
40614 [basic block 1]
40615 \end_layout
40616
40617 \begin_layout Standard
40618 if (something)
40619 \end_layout
40620
40621 \begin_layout Standard
40622 \InsetSpace ~
40623 \InsetSpace ~
40624 \InsetSpace ~
40625 \InsetSpace ~
40626 [basic block 2]
40627 \end_layout
40628
40629 \begin_layout Standard
40630 else
40631 \end_layout
40632
40633 \begin_layout Standard
40634 \InsetSpace ~
40635 \InsetSpace ~
40636 \InsetSpace ~
40637 \InsetSpace ~
40638 [basic block 3]
40639 \end_layout
40640
40641 \begin_layout Standard
40642 [basic block 4]
40643 \newline
40644
40645 \end_layout
40646
40647 \begin_layout Standard
40648 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40649 \end_layout
40650
40651 \begin_layout Standard
40652 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40653 \end_layout
40654
40655 \begin_layout Standard
40656 c) domVect of [BB4] = BB1 ...
40657  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40658  was executed.
40659 \end_layout
40660
40661 \begin_layout Chapter
40662 Acknowledgments
40663 \end_layout
40664
40665 \begin_layout Standard
40666 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40667
40668 \end_inset
40669
40670
40671 \newline
40672
40673 \newline
40674
40675 \emph on
40676 Thanks to all the other volunteer developers who have helped with coding,
40677  testing, web-page creation, distribution sets, etc.
40678  You know who you are :-)
40679 \emph default
40680
40681 \newline
40682
40683 \newline
40684
40685 \emph on
40686 Thanks to Sourceforge 
40687 \begin_inset LatexCommand \url{http://www.sf.net}
40688
40689 \end_inset
40690
40691  which has hosted the project since 1999 and donates significant download
40692  bandwidth.
40693 \emph default
40694
40695 \newline
40696
40697 \newline
40698
40699 \emph on
40700 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40701  cycles and bandwidth for snapshot builds.
40702 \newline
40703
40704 \end_layout
40705
40706 \begin_layout Standard
40707 This document was initially written by Sandeep Dutta
40708 \end_layout
40709
40710 \begin_layout Standard
40711 All product names mentioned herein may be trademarks
40712 \begin_inset LatexCommand \index{Trademarks}
40713
40714 \end_inset
40715
40716  of their respective companies.
40717  
40718 \end_layout
40719
40720 \begin_layout Section*
40721 Alphabetical index
40722 \end_layout
40723
40724 \begin_layout Standard
40725 To avoid confusion, the installation and building options for SDCC itself
40726  (chapter 2) are not part of the index.
40727 \end_layout
40728
40729 \begin_layout Standard
40730 \begin_inset LatexCommand \printindex{}
40731
40732 \end_inset
40733
40734
40735 \end_layout
40736
40737 \end_body
40738 \end_document