* Small Device C Compiler 2.8.0 released
[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.8.1
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 if
945 \series bold
946  -
947 \begin_inset ERT
948 status collapsed
949
950 \begin_layout Standard
951
952
953 \backslash
954 /
955 \end_layout
956
957 \end_inset
958
959 -std-c89
960 \begin_inset LatexCommand \index{-\/-std-c89}
961
962 \end_inset
963
964  
965 \series default
966 and
967 \series bold
968  -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c99
982 \begin_inset LatexCommand \index{-\/-std-c99}
983
984 \end_inset
985
986
987 \series default
988  command line options are not defined,
989 \newline
990  will push a as two ints if
991 \series bold
992  -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c89
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1007
1008 \end_inset
1009
1010  
1011 \series default
1012 or
1013 \series bold
1014  -
1015 \begin_inset ERT
1016 status collapsed
1017
1018 \begin_layout Standard
1019
1020
1021 \backslash
1022 /
1023 \end_layout
1024
1025 \end_inset
1026
1027 -std-c99
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1029
1030 \end_inset
1031
1032
1033 \series default
1034  command line option is defined.
1035 \end_layout
1036
1037 \begin_layout Itemize
1038 option -
1039 \begin_inset ERT
1040 status collapsed
1041
1042 \begin_layout Standard
1043
1044
1045 \backslash
1046 /
1047 \end_layout
1048
1049 \end_inset
1050
1051 -regextend has been removed.
1052 \end_layout
1053
1054 \begin_layout Itemize
1055 option -
1056 \begin_inset ERT
1057 status collapsed
1058
1059 \begin_layout Standard
1060
1061
1062 \backslash
1063 /
1064 \end_layout
1065
1066 \end_inset
1067
1068 -noregparms has been removed.
1069 \end_layout
1070
1071 \begin_layout Itemize
1072 option -
1073 \begin_inset ERT
1074 status collapsed
1075
1076 \begin_layout Standard
1077
1078
1079 \backslash
1080 /
1081 \end_layout
1082
1083 \end_inset
1084
1085 -stack-after-data has been removed.
1086 \end_layout
1087
1088 \begin_layout Itemize
1089 bit
1090 \begin_inset LatexCommand \index{bit}
1091
1092 \end_inset
1093
1094  and sbit
1095 \begin_inset LatexCommand \index{sbit}
1096
1097 \end_inset
1098
1099
1100 \begin_inset LatexCommand \index{\_\_sbit}
1101
1102 \end_inset
1103
1104  types now consistently behave like the C99 _Bool type with respect to type
1105  conversion
1106 \begin_inset LatexCommand \index{type conversion}
1107
1108 \end_inset
1109
1110
1111 \begin_inset LatexCommand \index{type promotion}
1112
1113 \end_inset
1114
1115 .
1116  The most common incompatibility resulting from this change is related to
1117  bit toggling
1118 \begin_inset LatexCommand \index{Bit toggling}
1119
1120 \end_inset
1121
1122  idioms, e.g.:
1123 \newline
1124
1125 \family typewriter
1126 \InsetSpace ~
1127 \InsetSpace ~
1128 bit b;
1129 \newline
1130 \InsetSpace ~
1131 \InsetSpace ~
1132 b = ~
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1134
1135 \end_inset
1136
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1139 status collapsed
1140
1141 \begin_layout Standard
1142
1143 \series bold
1144 \InsetSpace ~
1145 !
1146 \end_layout
1147
1148 \end_inset
1149
1150
1151 \newline
1152 \InsetSpace ~
1153 \InsetSpace ~
1154 b = !b; /* toggles b */
1155 \newline
1156
1157 \family default
1158 In previous versions, both forms would have toggled the bit.
1159 \end_layout
1160
1161 \begin_layout Standard
1162
1163 \emph on
1164 <pending: more incompatibilities?>
1165 \end_layout
1166
1167 \begin_layout Section
1168 System Requirements
1169 \end_layout
1170
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173  a desire to compute.
1174  The preferred method of installation is to compile SDCC from source using
1175  GNU gcc and make.
1176  For Windows some pre-compiled binary distributions are available for your
1177  convenience.
1178  You should have some experience with command line tools and compiler use.
1179 \end_layout
1180
1181 \begin_layout Section
1182 Other Resources
1183 \end_layout
1184
1185 \begin_layout Standard
1186 The SDCC home page at 
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1188
1189 \end_inset
1190
1191  is a great place to find distribution sets.
1192  You can also find links to the user mailing lists that offer help or discuss
1193  SDCC with other SDCC users.
1194  Web links to other SDCC related sites can also be found here.
1195  This document can be found in the DOC directory of the source package as
1196  a text or HTML file.
1197  A pdf version of this document is available at 
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1199
1200 \end_inset
1201
1202 .
1203  Some of the other tools (simulator and assembler) included with SDCC contain
1204  their own documentation and can be found in the source distribution.
1205  If you want the latest unreleased software, the complete source package
1206  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1207 sdcc/trunk/sdcc.
1208 \end_layout
1209
1210 \begin_layout Section
1211 Wishes for the future
1212 \end_layout
1213
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216  Here are some I can think of:
1217 \newline
1218
1219 \end_layout
1220
1221 \begin_layout Standard
1222
1223 \family typewriter
1224 char KernelFunction3(char p) at 0x340;
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 better code banking
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1234
1235 \end_inset
1236
1237  support for mcs51
1238 \newline
1239
1240 \newline
1241
1242 \family default
1243 If you can think of some more, please see the section 
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1245
1246 \end_inset
1247
1248  about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1250
1251 \end_inset
1252
1253
1254 \begin_inset LatexCommand \index{Feature request}
1255
1256 \end_inset
1257
1258 .
1259 \newline
1260
1261 \end_layout
1262
1263 \begin_layout Chapter
1264 Installing SDCC
1265 \begin_inset LatexCommand \index{Installation}
1266
1267 \end_inset
1268
1269
1270 \end_layout
1271
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section 
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1275
1276 \end_inset
1277
1278  (Unix) or section 
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1280
1281 \end_inset
1282
1283  (Windows).
1284  More detailed instructions follow below.
1285 \end_layout
1286
1287 \begin_layout Section
1288 Configure Options
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1290
1291 \end_inset
1292
1293
1294 \end_layout
1295
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1298  'configure'.
1299  The defaults can be overridden by:
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -prefix see table below
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -exec_prefix see table below
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -bindir see table below
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -datadir see table below
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -datarootdir see table below
1390 \newline
1391
1392 \end_layout
1393
1394 \begin_layout List
1395 \labelwidthstring 00.00.0000
1396 \InsetSpace ~
1397 \InsetSpace ~
1398 docdir environment variable, see table below
1399 \end_layout
1400
1401 \begin_layout List
1402 \labelwidthstring 00.00.0000
1403 \InsetSpace ~
1404 \InsetSpace ~
1405 include_dir_suffix environment variable, see table below
1406 \end_layout
1407
1408 \begin_layout List
1409 \labelwidthstring 00.00.0000
1410 \InsetSpace ~
1411 \InsetSpace ~
1412 lib_dir_suffix environment variable, see table below
1413 \end_layout
1414
1415 \begin_layout List
1416 \labelwidthstring 00.00.0000
1417 \InsetSpace ~
1418 \InsetSpace ~
1419 sdccconf_h_dir_separator environment variable, either / or 
1420 \backslash
1421
1422 \backslash
1423  makes sense here.
1424  This character will only be used in sdccconf.h; don't forget it's a C-header,
1425  therefore a double-backslash is needed there.
1426 \newline
1427
1428 \end_layout
1429
1430 \begin_layout List
1431 \labelwidthstring 00.00.0000
1432 -
1433 \begin_inset ERT
1434 status collapsed
1435
1436 \begin_layout Standard
1437
1438
1439 \backslash
1440 /
1441 \end_layout
1442
1443 \end_inset
1444
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1446 \end_layout
1447
1448 \begin_layout List
1449 \labelwidthstring 00.00.0000
1450 -
1451 \begin_inset ERT
1452 status collapsed
1453
1454 \begin_layout Standard
1455
1456
1457 \backslash
1458 /
1459 \end_layout
1460
1461 \end_inset
1462
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1464 \end_layout
1465
1466 \begin_layout List
1467 \labelwidthstring 00.00.0000
1468 -
1469 \begin_inset ERT
1470 status collapsed
1471
1472 \begin_layout Standard
1473
1474
1475 \backslash
1476 /
1477 \end_layout
1478
1479 \end_inset
1480
1481 -disable-z80-port Excludes the z80 port
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -disable-avr-port Excludes the AVR port
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -disable-ds390-port Excludes the DS390 port
1518 \end_layout
1519
1520 \begin_layout List
1521 \labelwidthstring 00.00.0000
1522 -
1523 \begin_inset ERT
1524 status collapsed
1525
1526 \begin_layout Standard
1527
1528
1529 \backslash
1530 /
1531 \end_layout
1532
1533 \end_inset
1534
1535 -disable-hc08-port Excludes the HC08 port
1536 \end_layout
1537
1538 \begin_layout List
1539 \labelwidthstring 00.00.0000
1540 -
1541 \begin_inset ERT
1542 status collapsed
1543
1544 \begin_layout Standard
1545
1546
1547 \backslash
1548 /
1549 \end_layout
1550
1551 \end_inset
1552
1553 -disable-pic-port Excludes the PIC14 port
1554 \end_layout
1555
1556 \begin_layout List
1557 \labelwidthstring 00.00.0000
1558 -
1559 \begin_inset ERT
1560 status collapsed
1561
1562 \begin_layout Standard
1563
1564
1565 \backslash
1566 /
1567 \end_layout
1568
1569 \end_inset
1570
1571 -disable-pic16-port Excludes the PIC16 port
1572 \end_layout
1573
1574 \begin_layout List
1575 \labelwidthstring 00.00.0000
1576 -
1577 \begin_inset ERT
1578 status collapsed
1579
1580 \begin_layout Standard
1581
1582
1583 \backslash
1584 /
1585 \end_layout
1586
1587 \end_inset
1588
1589 -disable-xa51-port Excludes the XA51 port
1590 \end_layout
1591
1592 \begin_layout List
1593 \labelwidthstring 00.00.0000
1594 -
1595 \begin_inset ERT
1596 status collapsed
1597
1598 \begin_layout Standard
1599
1600
1601 \backslash
1602 /
1603 \end_layout
1604
1605 \end_inset
1606
1607 -disable-ucsim Disables configuring and building of ucsim
1608 \end_layout
1609
1610 \begin_layout List
1611 \labelwidthstring 00.00.0000
1612 -
1613 \begin_inset ERT
1614 status collapsed
1615
1616 \begin_layout Standard
1617
1618
1619 \backslash
1620 /
1621 \end_layout
1622
1623 \end_inset
1624
1625 -disable-device-lib Disables automatically building device libraries
1626 \end_layout
1627
1628 \begin_layout List
1629 \labelwidthstring 00.00.0000
1630 -
1631 \begin_inset ERT
1632 status collapsed
1633
1634 \begin_layout Standard
1635
1636
1637 \backslash
1638 /
1639 \end_layout
1640
1641 \end_inset
1642
1643 -disable-packihx Disables building packihx
1644 \newline
1645
1646 \end_layout
1647
1648 \begin_layout List
1649 \labelwidthstring 00.00.0000
1650 -
1651 \begin_inset ERT
1652 status collapsed
1653
1654 \begin_layout Standard
1655
1656
1657 \backslash
1658 /
1659 \end_layout
1660
1661 \end_inset
1662
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1664 \end_layout
1665
1666 \begin_layout List
1667 \labelwidthstring 00.00.0000
1668 -
1669 \begin_inset ERT
1670 status collapsed
1671
1672 \begin_layout Standard
1673
1674
1675 \backslash
1676 /
1677 \end_layout
1678
1679 \end_inset
1680
1681 -enable-libgc Use the Bohem memory allocator.
1682  Lower runtime footprint.
1683 \end_layout
1684
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687  the tools and their arguments can be influenced.
1688  Please see `configure -
1689 \begin_inset ERT
1690 status collapsed
1691
1692 \begin_layout Standard
1693
1694
1695 \backslash
1696 /
1697 \end_layout
1698
1699 \end_inset
1700
1701 -help' and the man/info pages of `configure' for details.
1702 \newline
1703
1704 \newline
1705 The names of the
1706  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708  SDCC_LIB_NAME are defined by `configure' too.
1709  At the moment it's not possible to change the default settings (it was
1710  simply never required).
1711 \newline
1712
1713 \newline
1714 These configure options are compiled into the binaries,
1715  and can only be changed by rerunning 'configure' and recompiling SDCC.
1716  The configure options are written in 
1717 \emph on
1718 italics
1719 \emph default
1720  to distinguish them from run time environment variables (see section search
1721  paths).
1722 \newline
1723
1724 \newline
1725 The settings for 
1726 \begin_inset Quotes sld
1727 \end_inset
1728
1729 Win32 builds
1730 \begin_inset Quotes srd
1731 \end_inset
1732
1733  are used by the SDCC team to build the official Win32 binaries.
1734  The SDCC team uses Mingw32 to build the official Windows binaries, because
1735  it's
1736 \end_layout
1737
1738 \begin_layout Enumerate
1739 open source, 
1740 \end_layout
1741
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1748  Farm.
1749 \end_layout
1750
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1755  for Win32.
1756 \newline
1757
1758 \newline
1759 These defaults are:
1760 \newline
1761
1762 \end_layout
1763
1764 \begin_layout Standard
1765 \align center
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1768 <features>
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777 Variable
1778 \end_layout
1779
1780 \end_inset
1781 </cell>
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786 default
1787 \end_layout
1788
1789 \end_inset
1790 </cell>
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1792 \begin_inset Text
1793
1794 \begin_layout Standard
1795 Win32 builds
1796 \end_layout
1797
1798 \end_inset
1799 </cell>
1800 </row>
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_inset Text
1804
1805 \begin_layout Standard
1806
1807 \emph on
1808 PREFIX
1809 \end_layout
1810
1811 \end_inset
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \begin_layout Standard
1817 /usr/local
1818 \end_layout
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \begin_layout Standard
1826
1827 \backslash
1828 sdcc
1829 \end_layout
1830
1831 \end_inset
1832 </cell>
1833 </row>
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \begin_layout Standard
1839
1840 \emph on
1841 EXEC_PREFIX
1842 \end_layout
1843
1844 \end_inset
1845 </cell>
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \begin_layout Standard
1850
1851 \emph on
1852 $PREFIX
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1858 \begin_inset Text
1859
1860 \begin_layout Standard
1861
1862 \emph on
1863 $PREFIX
1864 \end_layout
1865
1866 \end_inset
1867 </cell>
1868 </row>
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874
1875 \emph on
1876 BINDIR
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \begin_layout Standard
1885
1886 \emph on
1887 $EXEC_PREFIX
1888 \emph default
1889 /bin
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $EXEC_PREFIX
1901 \emph default
1902
1903 \backslash
1904 bin
1905 \end_layout
1906
1907 \end_inset
1908 </cell>
1909 </row>
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915
1916 \emph on
1917 DATADIR
1918 \end_layout
1919
1920 \end_inset
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \begin_layout Standard
1926
1927 \emph on
1928 $DATAROOTDIR
1929 \end_layout
1930
1931 \end_inset
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \begin_layout Standard
1937
1938 \emph on
1939 $DATAROOTDIR
1940 \end_layout
1941
1942 \end_inset
1943 </cell>
1944 </row>
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950
1951 \emph on
1952 DATAROOTDIR
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 $PREFIX
1964 \emph default
1965 /share
1966 \end_layout
1967
1968 \end_inset
1969 </cell>
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 \begin_inset Text
1972
1973 \begin_layout Standard
1974
1975 \emph on
1976 $PREFIX
1977 \end_layout
1978
1979 \end_inset
1980 </cell>
1981 </row>
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \begin_layout Standard
1987
1988 \emph on
1989 DOCDIR
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998
1999 \emph on
2000 $DATAROOTDIR
2001 \emph default
2002 /sdcc/doc
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 $DATAROOTDIR
2014 \emph default
2015
2016 \backslash
2017 doc
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 INCLUDE_DIR_SUFFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 sdcc/include
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048 include
2049 \end_layout
2050
2051 \end_inset
2052 </cell>
2053 </row>
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_inset Text
2057
2058 \begin_layout Standard
2059
2060 \emph on
2061 LIB_DIR_SUFFIX
2062 \end_layout
2063
2064 \end_inset
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \begin_layout Standard
2070 sdcc/lib
2071 \end_layout
2072
2073 \end_inset
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \begin_layout Standard
2079 lib
2080 \end_layout
2081
2082 \end_inset
2083 </cell>
2084 </row>
2085 </lyxtabular>
2086
2087 \end_inset
2088
2089
2090 \newline
2091
2092 \end_layout
2093
2094 \begin_layout Standard
2095 \noindent
2096 'configure' also computes relative paths.
2097  This is needed for full relocatability of a binary package and to complete
2098  search paths (see section search paths below):
2099 \newline
2100  
2101 \end_layout
2102
2103 \begin_layout Standard
2104 \align center
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2107 <features>
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \begin_layout Standard
2116 Variable (computed)
2117 \end_layout
2118
2119 \end_inset
2120 </cell>
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2122 \begin_inset Text
2123
2124 \begin_layout Standard
2125 default
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2131 \begin_inset Text
2132
2133 \begin_layout Standard
2134 Win32 builds
2135 \end_layout
2136
2137 \end_inset
2138 </cell>
2139 </row>
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \begin_layout Standard
2145
2146 \emph on
2147 BIN2DATA_DIR
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 ../share
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 ..
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176
2177 \emph on
2178 PREFIX2BIN_DIR
2179 \end_layout
2180
2181 \end_inset
2182 </cell>
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2184 \begin_inset Text
2185
2186 \begin_layout Standard
2187 bin
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196 bin
2197 \end_layout
2198
2199 \end_inset
2200 </cell>
2201 </row>
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_inset Text
2205
2206 \begin_layout Standard
2207
2208 \emph on
2209 PREFIX2DATA_DIR
2210 \end_layout
2211
2212 \end_inset
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \begin_layout Standard
2218 share/sdcc
2219 \end_layout
2220
2221 \end_inset
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \begin_layout Standard
2227
2228 \end_layout
2229
2230 \end_inset
2231 </cell>
2232 </row>
2233 </lyxtabular>
2234
2235 \end_inset
2236
2237
2238 \newline
2239
2240 \end_layout
2241
2242 \begin_layout Standard
2243 \noindent
2244 Examples:
2245 \end_layout
2246
2247 \begin_layout LyX-Code
2248 ./configure
2249 \newline
2250 ./configure -
2251 \begin_inset ERT
2252 status collapsed
2253
2254 \begin_layout Standard
2255
2256
2257 \backslash
2258 /
2259 \end_layout
2260
2261 \end_inset
2262
2263 -prefix=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267 /usr/bin
2268 \begin_inset Quotes srd
2269 \end_inset
2270
2271  -
2272 \begin_inset ERT
2273 status collapsed
2274
2275 \begin_layout Standard
2276
2277
2278 \backslash
2279 /
2280 \end_layout
2281
2282 \end_inset
2283
2284 -datarootdir=
2285 \begin_inset Quotes srd
2286 \end_inset
2287
2288 /usr/share
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292
2293 \newline
2294 ./configure -
2295 \begin_inset ERT
2296 status collapsed
2297
2298 \begin_layout Standard
2299
2300
2301 \backslash
2302 /
2303 \end_layout
2304
2305 \end_inset
2306
2307 -disable-avr-port -
2308 \begin_inset ERT
2309 status collapsed
2310
2311 \begin_layout Standard
2312
2313
2314 \backslash
2315 /
2316 \end_layout
2317
2318 \end_inset
2319
2320 -disable-xa51-port
2321 \end_layout
2322
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2325 32'):
2326 \end_layout
2327
2328 \begin_layout LyX-Code
2329 ./configure 
2330 \backslash
2331
2332 \newline
2333 CC=
2334 \begin_inset Quotes srd
2335 \end_inset
2336
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341  CXX=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  
2350 \backslash
2351  
2352 \newline
2353 RANLIB=
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361  
2362 \backslash
2363
2364 \newline
2365 STRIP=
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2371 \end_inset
2372
2373  
2374 \backslash
2375
2376 \newline
2377 -
2378 \begin_inset ERT
2379 status collapsed
2380
2381 \begin_layout Standard
2382
2383
2384 \backslash
2385 /
2386 \end_layout
2387
2388 \end_inset
2389
2390 -prefix=
2391 \begin_inset Quotes srd
2392 \end_inset
2393
2394 /sdcc
2395 \begin_inset Quotes srd
2396 \end_inset
2397
2398  
2399 \backslash
2400
2401 \newline
2402 -
2403 \begin_inset ERT
2404 status collapsed
2405
2406 \begin_layout Standard
2407
2408
2409 \backslash
2410 /
2411 \end_layout
2412
2413 \end_inset
2414
2415 -datarootdir=
2416 \begin_inset Quotes srd
2417 \end_inset
2418
2419 /sdcc
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423  
2424 \backslash
2425
2426 \newline
2427 docdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431
2432 \backslash
2433 ${datarootdir}/doc
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437  
2438 \backslash
2439
2440 \newline
2441 include_dir_suffix=
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445 include
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451
2452 \newline
2453 lib_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 lib
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469
2470 \backslash
2471
2472 \backslash
2473
2474 \backslash
2475
2476 \backslash
2477
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481  
2482 \backslash
2483
2484 \newline
2485 -
2486 \begin_inset ERT
2487 status collapsed
2488
2489 \begin_layout Standard
2490
2491
2492 \backslash
2493 /
2494 \end_layout
2495
2496 \end_inset
2497
2498 -disable-device-lib
2499 \backslash
2500
2501 \newline
2502 -
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -host=i586-mingw32msvc
2516 \backslash
2517
2518 \newline
2519 -
2520 \begin_inset ERT
2521 status collapsed
2522
2523 \begin_layout Standard
2524
2525
2526 \backslash
2527 /
2528 \end_layout
2529
2530 \end_inset
2531
2532 -build=unknown-unknown-linux-gnu
2533 \end_layout
2534
2535 \begin_layout Standard
2536 To 
2537 \begin_inset Quotes sld
2538 \end_inset
2539
2540 cross
2541 \begin_inset Quotes srd
2542 \end_inset
2543
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2545 ):
2546 \end_layout
2547
2548 \begin_layout LyX-Code
2549 ./configure -C 
2550 \backslash
2551
2552 \newline
2553 -
2554 \begin_inset ERT
2555 status collapsed
2556
2557 \begin_layout Standard
2558
2559
2560 \backslash
2561 /
2562 \end_layout
2563
2564 \end_inset
2565
2566 -prefix=
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570 /sdcc
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574  
2575 \backslash
2576
2577 \newline
2578 -
2579 \begin_inset ERT
2580 status collapsed
2581
2582 \begin_layout Standard
2583
2584
2585 \backslash
2586 /
2587 \end_layout
2588
2589 \end_inset
2590
2591 -datarootdir=
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595 /sdcc
2596 \begin_inset Quotes srd
2597 \end_inset
2598
2599  
2600 \backslash
2601
2602 \newline
2603 docdir=
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607
2608 \backslash
2609 ${datarootdir}/doc
2610 \begin_inset Quotes srd
2611 \end_inset
2612
2613  
2614 \backslash
2615  
2616 \newline
2617 include_dir_suffix=
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621 include
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625  
2626 \backslash
2627
2628 \newline
2629 lib_dir_suffix=
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633 lib
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637  
2638 \backslash
2639
2640 \newline
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645
2646 \backslash
2647
2648 \backslash
2649
2650 \backslash
2651
2652 \backslash
2653
2654 \begin_inset Quotes srd
2655 \end_inset
2656
2657  
2658 \backslash
2659
2660 \newline
2661 CC=
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665 gcc -mno-cygwin
2666 \begin_inset Quotes srd
2667 \end_inset
2668
2669  
2670 \backslash
2671
2672 \newline
2673 CXX=
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677 g++ -mno-cygwin
2678 \begin_inset Quotes srd
2679 \end_inset
2680
2681  
2682 \end_layout
2683
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2686  The option '-
2687 \begin_inset ERT
2688 status collapsed
2689
2690 \begin_layout Standard
2691
2692
2693 \backslash
2694 /
2695 \end_layout
2696
2697 \end_inset
2698
2699 -C' turns on caching, which gives a little bit extra speed.
2700  However if options are changed, it can be necessary to delete the config.cache
2701  file.
2702 \end_layout
2703
2704 \begin_layout Section
2705 Install paths
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2707
2708 \end_inset
2709
2710
2711 \begin_inset LatexCommand \index{Install paths}
2712
2713 \end_inset
2714
2715
2716 \end_layout
2717
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2720 \end_inset
2721
2722
2723 \end_layout
2724
2725 \begin_layout Standard
2726 \align center
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2729 <features>
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739
2740 \series bold
2741 Description
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_inset Text
2748
2749 \begin_layout Standard
2750
2751 \series bold
2752 Path
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \series bold
2763 Default
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772
2773 \series bold
2774 Win32 builds
2775 \end_layout
2776
2777 \end_inset
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \begin_layout Standard
2785 Binary files*
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_inset Text
2792
2793 \begin_layout Standard
2794
2795 \emph on
2796 $EXEC_PREFIX
2797 \end_layout
2798
2799 \end_inset
2800 </cell>
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \begin_layout Standard
2805 /usr/local/bin
2806 \end_layout
2807
2808 \end_inset
2809 </cell>
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_inset Text
2812
2813 \begin_layout Standard
2814
2815 \backslash
2816 sdcc
2817 \backslash
2818 bin
2819 \end_layout
2820
2821 \end_inset
2822 </cell>
2823 </row>
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \begin_layout Standard
2829 Include files
2830 \end_layout
2831
2832 \end_inset
2833 </cell>
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2835 \begin_inset Text
2836
2837 \begin_layout Standard
2838
2839 \emph on
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2841 \end_layout
2842
2843 \end_inset
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2850 \end_layout
2851
2852 \end_inset
2853 </cell>
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2855 \begin_inset Text
2856
2857 \begin_layout Standard
2858
2859 \backslash
2860 sdcc
2861 \backslash
2862 include
2863 \end_layout
2864
2865 \end_inset
2866 </cell>
2867 </row>
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \begin_layout Standard
2873 Library file**
2874 \end_layout
2875
2876 \end_inset
2877 </cell>
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_inset Text
2880
2881 \begin_layout Standard
2882
2883 \emph on
2884 $DATADIR/$LIB_DIR_SUFFIX
2885 \end_layout
2886
2887 \end_inset
2888 </cell>
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_inset Text
2891
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2894 \end_layout
2895
2896 \end_inset
2897 </cell>
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \begin_layout Standard
2902
2903 \backslash
2904 sdcc
2905 \backslash
2906 lib
2907 \end_layout
2908
2909 \end_inset
2910 </cell>
2911 </row>
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_inset Text
2915
2916 \begin_layout Standard
2917 Documentation
2918 \end_layout
2919
2920 \end_inset
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \begin_layout Standard
2926
2927 \emph on
2928 $DOCDIR
2929 \end_layout
2930
2931 \end_inset
2932 </cell>
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2934 \begin_inset Text
2935
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2938 \end_layout
2939
2940 \end_inset
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \begin_layout Standard
2946
2947 \backslash
2948 sdcc
2949 \backslash
2950 doc
2951 \end_layout
2952
2953 \end_inset
2954 </cell>
2955 </row>
2956 </lyxtabular>
2957
2958 \end_inset
2959
2960
2961 \end_layout
2962
2963 \begin_layout Verse
2964
2965 \size footnotesize
2966 *compiler, preprocessor, assembler, and linker
2967 \newline
2968 **the 
2969 \shape italic
2970 model
2971 \shape default
2972  is auto-appended by the compiler, e.g.
2973  small, large, z80, ds390 etc
2974 \end_layout
2975
2976 \begin_layout Standard
2977 \noindent
2978 The install paths can still be changed during `make install' with e.g.:
2979 \end_layout
2980
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2983 \end_layout
2984
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2987 \newline
2988
2989 \newline
2990 Moreove
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2993
2994 \end_inset
2995
2996 :
2997 \end_layout
2998
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3001 \end_layout
3002
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3005 \end_layout
3006
3007 \begin_layout Section
3008 Search Paths
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3010
3011 \end_inset
3012
3013
3014 \begin_inset LatexCommand \index{Search path}
3015
3016 \end_inset
3017
3018
3019 \end_layout
3020
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3023  (in 
3024 \emph on
3025 italics
3026 \emph default
3027 , see section above).
3028  Further search paths are determined by environment variables during runtime.
3029  
3030 \newline
3031 The paths searched when running the compiler are as follows (the first
3032  catch wins):
3033 \newline
3034
3035 \newline
3036 1.
3037  Binary files (preprocessor, assembler and linker)
3038 \newline
3039
3040 \end_layout
3041
3042 \begin_layout Standard
3043 \align center
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3046 <features>
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \begin_layout Standard
3055 Search path
3056 \end_layout
3057
3058 \end_inset
3059 </cell>
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 default
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 Win32 builds
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 </row>
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 $SDCC_HOME/
3085 \emph on
3086 $PPREFIX2BIN_DIR
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 $SDCC_HOME/bin
3096 \end_layout
3097
3098 \end_inset
3099 </cell>
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 \begin_inset Text
3102
3103 \begin_layout Standard
3104 $SDCC_HOME
3105 \backslash
3106 bin
3107 \end_layout
3108
3109 \end_inset
3110 </cell>
3111 </row>
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126 Path of argv[0]
3127 \end_layout
3128
3129 \end_inset
3130 </cell>
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3132 \begin_inset Text
3133
3134 \begin_layout Standard
3135 Path of argv[0]
3136 \end_layout
3137
3138 \end_inset
3139 </cell>
3140 </row>
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 $PATH
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3152 \begin_inset Text
3153
3154 \begin_layout Standard
3155 $PATH
3156 \end_layout
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \begin_layout Standard
3164 $PATH
3165 \end_layout
3166
3167 \end_inset
3168 </cell>
3169 </row>
3170 </lyxtabular>
3171
3172 \end_inset
3173
3174  
3175 \newline
3176
3177 \end_layout
3178
3179 \begin_layout Standard
3180 \noindent
3181 2.
3182  Include files
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \align center
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3191 <features>
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3197 \begin_inset Text
3198
3199 \begin_layout Standard
3200 Search path
3201 \end_layout
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \begin_layout Standard
3209 default
3210 \end_layout
3211
3212 \end_inset
3213 </cell>
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3215 \begin_inset Text
3216
3217 \begin_layout Standard
3218 Win32 builds
3219 \end_layout
3220
3221 \end_inset
3222 </cell>
3223 </row>
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3226 \begin_inset Text
3227
3228 \begin_layout Standard
3229 -
3230 \begin_inset ERT
3231 status collapsed
3232
3233 \begin_layout Standard
3234
3235
3236 \backslash
3237 /
3238 \end_layout
3239
3240 \end_inset
3241
3242 -I dir
3243 \end_layout
3244
3245 \end_inset
3246 </cell>
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3248 \begin_inset Text
3249
3250 \begin_layout Standard
3251 -
3252 \begin_inset ERT
3253 status collapsed
3254
3255 \begin_layout Standard
3256
3257
3258 \backslash
3259 /
3260 \end_layout
3261
3262 \end_inset
3263
3264 -I dir
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 -
3274 \begin_inset ERT
3275 status collapsed
3276
3277 \begin_layout Standard
3278
3279
3280 \backslash
3281 /
3282 \end_layout
3283
3284 \end_inset
3285
3286 -I dir
3287 \end_layout
3288
3289 \end_inset
3290 </cell>
3291 </row>
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 $SDCC_INCLUDE
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_inset Text
3304
3305 \begin_layout Standard
3306 $SDCC_INCLUDE
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 $SDCC_INCLUDE
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME/
3327 \newline
3328
3329 \emph on
3330 $PREFIX2DATA_DIR/
3331 \newline
3332 $INCLUDE_DIR_SUFFIX
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_inset Text
3339
3340 \begin_layout Standard
3341 $SDCC_ HOME/
3342 \newline
3343 share/sdcc/
3344 \newline
3345 include
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3351 \begin_inset Text
3352
3353 \begin_layout Standard
3354 $SDCC_HOME
3355 \backslash
3356 include
3357 \end_layout
3358
3359 \end_inset
3360 </cell>
3361 </row>
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3364 \begin_inset Text
3365
3366 \begin_layout Standard
3367 path(argv[0])/
3368 \newline
3369
3370 \emph on
3371 $BIN2DATADIR/
3372 \emph default
3373
3374 \newline
3375
3376 \emph on
3377 $INCLUDE_DIR_SUFFIX
3378 \end_layout
3379
3380 \end_inset
3381 </cell>
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3383 \begin_inset Text
3384
3385 \begin_layout Standard
3386 path(argv[0])/
3387 \newline
3388 ../sdcc/include
3389 \newline
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400 \InsetSpace ~
3401 \InsetSpace ~
3402 \InsetSpace ~
3403 \InsetSpace ~
3404 \InsetSpace ~
3405 \InsetSpace ~
3406 \InsetSpace ~
3407 \InsetSpace ~
3408 \InsetSpace ~
3409 \InsetSpace ~
3410 \InsetSpace ~
3411 \InsetSpace ~
3412 \InsetSpace ~
3413 \InsetSpace ~
3414 \InsetSpace ~
3415 \InsetSpace ~
3416 \InsetSpace ~
3417 \InsetSpace ~
3418 \InsetSpace ~
3419 \InsetSpace ~
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428
3429 \end_layout
3430
3431 \end_inset
3432 </cell>
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3434 \begin_inset Text
3435
3436 \begin_layout Standard
3437 path(argv[0])
3438 \backslash
3439 ..
3440 \backslash
3441 include
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 </row>
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452
3453 \emph on
3454 $DATADIR/
3455 \emph default
3456
3457 \newline
3458
3459 \emph on
3460 $INCLUDE_DIR_SUFFIX
3461 \end_layout
3462
3463 \end_inset
3464 </cell>
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3466 \begin_inset Text
3467
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3470 \newline
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 (not on Win32)
3481 \end_layout
3482
3483 \end_inset
3484 </cell>
3485 </row>
3486 </lyxtabular>
3487
3488 \end_inset
3489
3490  
3491 \newline
3492
3493 \end_layout
3494
3495 \begin_layout Standard
3496 \noindent
3497 The option -
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 -nostdinc disables the last two search paths.
3511 \newline
3512
3513 \newline
3514 3.
3515  Library files 
3516 \newline
3517
3518 \end_layout
3519
3520 \begin_layout Standard
3521 With the exception of 
3522 \begin_inset Quotes sld
3523 \end_inset
3524
3525 -
3526 \begin_inset ERT
3527 status collapsed
3528
3529 \begin_layout Standard
3530
3531
3532 \backslash
3533 /
3534 \end_layout
3535
3536 \end_inset
3537
3538 -L dir
3539 \begin_inset Quotes srd
3540 \end_inset
3541
3542  the 
3543 \shape italic
3544 model
3545 \shape default
3546  is auto-appended by the compiler (e.g.
3547  small, large, z80, ds390 etc.).
3548  
3549 \newline
3550
3551 \end_layout
3552
3553 \begin_layout Standard
3554 \align center
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3557 <features>
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_inset Text
3564
3565 \begin_layout Standard
3566 Search path
3567 \end_layout
3568
3569 \end_inset
3570 </cell>
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_inset Text
3573
3574 \begin_layout Standard
3575 default
3576 \end_layout
3577
3578 \end_inset
3579 </cell>
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3581 \begin_inset Text
3582
3583 \begin_layout Standard
3584 Win32 builds
3585 \end_layout
3586
3587 \end_inset
3588 </cell>
3589 </row>
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3592 \begin_inset Text
3593
3594 \begin_layout Standard
3595 -
3596 \begin_inset ERT
3597 status collapsed
3598
3599 \begin_layout Standard
3600
3601
3602 \backslash
3603 /
3604 \end_layout
3605
3606 \end_inset
3607
3608 -L dir
3609 \end_layout
3610
3611 \end_inset
3612 </cell>
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3614 \begin_inset Text
3615
3616 \begin_layout Standard
3617 -
3618 \begin_inset ERT
3619 status collapsed
3620
3621 \begin_layout Standard
3622
3623
3624 \backslash
3625 /
3626 \end_layout
3627
3628 \end_inset
3629
3630 -L dir
3631 \end_layout
3632
3633 \end_inset
3634 </cell>
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3636 \begin_inset Text
3637
3638 \begin_layout Standard
3639 -
3640 \begin_inset ERT
3641 status collapsed
3642
3643 \begin_layout Standard
3644
3645
3646 \backslash
3647 /
3648 \end_layout
3649
3650 \end_inset
3651
3652 -L dir
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 </row>
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 $SDCC_LIB/
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3673 \begin_inset Text
3674
3675 \begin_layout Standard
3676 $SDCC_LIB/
3677 \newline
3678
3679 \emph on
3680 <model>
3681 \end_layout
3682
3683 \end_inset
3684 </cell>
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3686 \begin_inset Text
3687
3688 \begin_layout Standard
3689 $SDCC_LIB
3690 \backslash
3691
3692 \newline
3693
3694 \emph on
3695 <model>
3696 \end_layout
3697
3698 \end_inset
3699 </cell>
3700 </row>
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_HOME/
3707 \newline
3708
3709 \emph on
3710 $PREFIX2DATA_DIR/
3711 \newline
3712 $LIB_DIR_SUFFIX/<model>
3713 \end_layout
3714
3715 \end_inset
3716 </cell>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721 $SDCC_HOME/
3722 \newline
3723 share/sdcc/
3724 \newline
3725 lib/
3726 \emph on
3727 <model>
3728 \end_layout
3729
3730 \end_inset
3731 </cell>
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME
3737 \backslash
3738 lib
3739 \backslash
3740
3741 \emph on
3742
3743 \newline
3744 <model>
3745 \end_layout
3746
3747 \end_inset
3748 </cell>
3749 </row>
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3752 \begin_inset Text
3753
3754 \begin_layout Standard
3755 path(argv[0])/
3756 \newline
3757
3758 \emph on
3759 $BIN2DATADIR/
3760 \emph default
3761
3762 \newline
3763
3764 \emph on
3765 $LIB_DIR_SUFFIX/<model>
3766 \end_layout
3767
3768 \end_inset
3769 </cell>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3771 \begin_inset Text
3772
3773 \begin_layout Standard
3774 path(argv[0])/
3775 \newline
3776 ../sdcc/lib/
3777 \emph on
3778 <model>
3779 \newline
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791 \InsetSpace ~
3792 \InsetSpace ~
3793 \InsetSpace ~
3794 \InsetSpace ~
3795 \InsetSpace ~
3796 \InsetSpace ~
3797 \InsetSpace ~
3798 \InsetSpace ~
3799 \InsetSpace ~
3800 \InsetSpace ~
3801 \InsetSpace ~
3802 \InsetSpace ~
3803 \InsetSpace ~
3804 \InsetSpace ~
3805 \InsetSpace ~
3806 \InsetSpace ~
3807 \InsetSpace ~
3808 \InsetSpace ~
3809 \InsetSpace ~
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819
3820 \end_layout
3821
3822 \end_inset
3823 </cell>
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3825 \begin_inset Text
3826
3827 \begin_layout Standard
3828 path(argv[0])
3829 \backslash
3830
3831 \newline
3832 ..
3833 \backslash
3834 lib
3835 \backslash
3836
3837 \emph on
3838 <model>
3839 \newline
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849 \InsetSpace ~
3850 \InsetSpace ~
3851 \InsetSpace ~
3852 \InsetSpace ~
3853 \InsetSpace ~
3854 \InsetSpace ~
3855 \InsetSpace ~
3856 \InsetSpace ~
3857 \InsetSpace ~
3858 \InsetSpace ~
3859 \InsetSpace ~
3860 \InsetSpace ~
3861 \InsetSpace ~
3862 \InsetSpace ~
3863 \InsetSpace ~
3864 \InsetSpace ~
3865 \InsetSpace ~
3866 \InsetSpace ~
3867 \InsetSpace ~
3868 \InsetSpace ~
3869 \InsetSpace ~
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 </row>
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3883 \begin_inset Text
3884
3885 \begin_layout Standard
3886
3887 \emph on
3888 $DATADIR/
3889 \newline
3890 $LIB_DIR_SUFFIX/<model>
3891 \end_layout
3892
3893 \end_inset
3894 </cell>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3900 \newline
3901 lib/
3902 \emph on
3903 <model>
3904 \end_layout
3905
3906 \end_inset
3907 </cell>
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3909 \begin_inset Text
3910
3911 \begin_layout Standard
3912 (not on Win32)
3913 \end_layout
3914
3915 \end_inset
3916 </cell>
3917 </row>
3918 </lyxtabular>
3919
3920 \end_inset
3921
3922
3923 \newline
3924
3925 \end_layout
3926
3927 \begin_layout Standard
3928 \begin_inset Note Note
3929 status collapsed
3930
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933  the HTML output (last line)!
3934 \end_layout
3935
3936 \end_inset
3937
3938
3939 \end_layout
3940
3941 \begin_layout Standard
3942 \InsetSpace ~
3943
3944 \newline
3945 The option -
3946 \begin_inset ERT
3947 status collapsed
3948
3949 \begin_layout Standard
3950
3951
3952 \backslash
3953 /
3954 \end_layout
3955
3956 \end_inset
3957
3958 -nostdlib disables the last two search paths.
3959 \end_layout
3960
3961 \begin_layout Section
3962 Building SDCC
3963 \begin_inset LatexCommand \index{Building SDCC}
3964
3965 \end_inset
3966
3967
3968 \end_layout
3969
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3973
3974 \end_inset
3975
3976
3977 \end_layout
3978
3979 \begin_layout Enumerate
3980
3981 \series medium
3982 Download the source package
3983 \series default
3984  either from the SDCC Subversion repository or from snapshot builds
3985 \series medium
3986 , it will be named something like sdcc
3987 \series default
3988 -src
3989 \series medium
3990 -yyyymmdd-rrrr.t
3991 \series default
3992 ar.
3993 \series medium
3994 bz2
3995 \series default
3996  
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3998
3999 \end_inset
4000
4001 .
4002 \end_layout
4003
4004 \begin_layout Enumerate
4005
4006 \series medium
4007 Bring up a command line terminal, such as xterm.
4008 \end_layout
4009
4010 \begin_layout Enumerate
4011
4012 \series medium
4013 Unpack the file using a command like: 
4014 \family sans
4015 \series bold
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4018 \end_inset
4019
4020
4021 \family default
4022 \series medium
4023 , this will create a sub-directory called sdcc with all of the sources.
4024 \end_layout
4025
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type: 
4028 \family sans
4029 \series bold
4030 "cd sdcc
4031 \series default
4032 ".
4033 \end_layout
4034
4035 \begin_layout Enumerate
4036
4037 \series medium
4038 Type 
4039 \family sans
4040 \series bold
4041 "./configure
4042 \family default
4043 \series default
4044 ".
4045  This configures the package for compilation on your system.
4046 \end_layout
4047
4048 \begin_layout Enumerate
4049
4050 \series medium
4051 Type 
4052 \family sans
4053 \series bold
4054 "make
4055 \family default
4056 \series default
4057 "
4058 \series medium
4059 .
4060
4061 \series default
4062  All of the source packages will compile, this can take a while.
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "make install"
4072 \family default
4073 \series default
4074  as root
4075 \series medium
4076 .
4077
4078 \series default
4079  This copies the binary executables, the include files, the libraries and
4080  the documentation to the install directories.
4081  Proceed with section 
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4083
4084 \end_inset
4085
4086 .
4087 \end_layout
4088
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4091 \end_layout
4092
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4095 \newline
4096
4097 \newline
4098 On Mac OS X 10.2.x it was reported, that the
4099  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100  Fortunately there's also gcc 2.9.x installed, which works fine.
4101  This compiler can be selected by running 'configure' with:
4102 \end_layout
4103
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4106 \end_layout
4107
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4110  Xcode.
4111  Run 'configure' with:
4112 \end_layout
4113
4114 \begin_layout LyX-Code
4115 ./configure 
4116 \backslash
4117
4118 \end_layout
4119
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4122  ppc" 
4123 \backslash
4124
4125 \end_layout
4126
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4129  ppc" 
4130 \backslash
4131
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4136 \end_layout
4137
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4140 \end_layout
4141
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144  See section 'Configure Options'.
4145 \end_layout
4146
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4149 \end_layout
4150
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4153  for Linux.
4154 \newline
4155
4156 \newline
4157 On Cygwin a 
4158 \begin_inset Quotes sld
4159 \end_inset
4160
4161 native
4162 \begin_inset Quotes srd
4163 \end_inset
4164
4165  Win32-binary can be built, which will not need the Cygwin-DLL.
4166  For the necessary 'configure' options see section 'configure options' or
4167  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4168 \newline
4169
4170 \newline
4171 In order to install
4172  Cygwin on Windows download setup.exe from 
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4174
4175 \end_inset
4176
4177 .
4178  Run it, set the 
4179 \begin_inset Quotes sld
4180 \end_inset
4181
4182 default text file type
4183 \begin_inset Quotes srd
4184 \end_inset
4185
4186  to 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 unix
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  and download/install at least the following packages.
4195  Some packages are selected by default, others will be automatically selected
4196  because of dependencies with the manually selected packages.
4197  Never deselect these packages!
4198 \end_layout
4199
4200 \begin_layout Itemize
4201 flex
4202 \end_layout
4203
4204 \begin_layout Itemize
4205 bison
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 make
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4226  later
4227 \end_layout
4228
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4231  later
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4236 \end_layout
4237
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 python ; for the regression tests
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI 
4248 \begin_inset Quotes sld
4249 \end_inset
4250
4251 insight
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255
4256 \end_layout
4257
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4260 \end_layout
4261
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264  use autoconf-stable!
4265 \end_layout
4266
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269  Replace in your cygwin.bat the line
4270 \end_layout
4271
4272 \begin_layout LyX-Code
4273 bash -
4274 \begin_inset ERT
4275 status collapsed
4276
4277 \begin_layout Standard
4278
4279
4280 \backslash
4281 /
4282 \end_layout
4283
4284 \end_inset
4285
4286 -login -i 
4287 \end_layout
4288
4289 \begin_layout Standard
4290 with (one line):
4291 \end_layout
4292
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4295 \end_layout
4296
4297 \begin_layout LyX-Code
4298      -bg black -fg white -geometry 100x65 -e bash -
4299 \begin_inset ERT
4300 status collapsed
4301
4302 \begin_layout Standard
4303
4304
4305 \backslash
4306 /
4307 \end_layout
4308
4309 \end_inset
4310
4311 -login
4312 \end_layout
4313
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316  works with shift-insert.
4317 \newline
4318
4319 \newline
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322  Using // invokes a network lookup which is very slow.
4323  If you think 
4324 \begin_inset Quotes sld
4325 \end_inset
4326
4327 cygdrive
4328 \begin_inset Quotes srd
4329 \end_inset
4330
4331  is too long, you can change it with e.g.
4332 \end_layout
4333
4334 \begin_layout LyX-Code
4335 mount -s -u -c /mnt
4336 \end_layout
4337
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340  Life is much easier, if you store the source tree on a drive which is mounted
4341  in binary mode.
4342  And use an editor which can handle LF-only line endings.
4343  Make sure not to commit files with windows line endings.
4344  The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4346
4347 \end_inset
4348
4349  used in the project is 8.
4350  Although a tabulator spacing of 8 is a sensible choice for programmers
4351  (it's a power of 2 and allows to display 8/16 bit signed variables without
4352  loosing columns) the plan is to move towards using only spaces in the source.
4353 \end_layout
4354
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4357 \end_layout
4358
4359 \begin_layout Standard
4360
4361 \series medium
4362 Download the source package
4363 \series default
4364  either from the SDCC Subversion repository or from the 
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4366
4367 \end_inset
4368
4369
4370 \series medium
4371 , it will be named something like sdcc
4372 \series default
4373 -src
4374 \series medium
4375 -yyyymmdd-rrrr.tar.bz2.
4376
4377 \series default
4378  SDCC is distributed with all the projects, workspaces, and files you need
4379  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380  The workspace name is 'sdcc.dsw'.
4381  Please note that as it is now, all the executables are created in a folder
4382  called sdcc
4383 \backslash
4384 bin_vc.
4385  Once built you need to copy the executables from sdcc
4386 \backslash
4387 bin_vc to sdcc
4388 \backslash
4389 bin before running SDCC.
4390  
4391 \newline
4392
4393 \newline
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396  When using the Subversion repository it's easiest to configure the svn
4397  client to convert automatically for you.
4398  If however you are getting a message such as "This makefile was not generated
4399  by Developer Studio etc.
4400  etc.
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405  need to convert the Unix style line endings to DOS style line endings.
4406  To do so you can use the 
4407 \begin_inset Quotes sld
4408 \end_inset
4409
4410 unix2dos
4411 \begin_inset Quotes srd
4412 \end_inset
4413
4414  utility freely available on the internet.
4415  Doug Hawkins reported in the sdcc-user list that this works:
4416 \newline
4417
4418 \newline
4419 C:
4420 \backslash
4421 Programming
4422 \backslash
4423 SDCC> unix2dos sdcc.dsw
4424 \newline
4425 C:
4426 \backslash
4427 Programming
4428 \backslash
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4430 \newline
4431
4432 \newline
4433 In order to build SDCC with MSVC
4434  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435  One good place to get them is 
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4437
4438 \end_inset
4439
4440
4441 \newline
4442
4443 \newline
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4446
4447 \end_inset
4448
4449 .zip.
4450  Now you have to install the utilities and setup MSVC so it can locate the
4451  required programs.
4452  Here there are two alternatives (choose one!):
4453 \end_layout
4454
4455 \begin_layout Enumerate
4456 The easy way:
4457 \newline
4458
4459 \newline
4460 a) Extract UnxUtils.zip to your C:
4461 \backslash
4462  hard disk PRESERVING the original paths, otherwise bison won't work.
4463  (If you are using WinZip make certain that 'Use folder names' is selected)
4464 \newline
4465
4466 \newline
4467 b)
4468  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469  'Show directories for:' select 'Executable files', and in the directories
4470  window add a new path: 'C:
4471 \backslash
4472 user
4473 \backslash
4474 local
4475 \backslash
4476 wbin', click ok.
4477 \newline
4478
4479 \newline
4480 (As a side effect, you get a bunch of Unix utilities that
4481  could be useful, such as diff and patch.)
4482 \end_layout
4483
4484 \begin_layout Enumerate
4485 A more compact way:
4486 \newline
4487
4488 \newline
4489 This one avoids extracting a bunch of files you may not
4490  use, but requires some extra work:
4491 \newline
4492
4493 \newline
4494 a) Create a directory were to put the
4495  tools needed, or use a directory already present.
4496  Say for example 'C:
4497 \backslash
4498 util'.
4499 \newline
4500
4501 \newline
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503  gawk.exe to such directory WITHOUT preserving the original paths.
4504  (If you are using WinZip make certain that 'Use folder names' is not selected)
4505 \newline
4506
4507 \newline
4508 c
4509 ) Rename bison.exe to '_bison.exe'.
4510 \newline
4511
4512 \newline
4513 d) Create a batch file 'bison.bat' in 'C:
4514 \backslash
4515 util
4516 \backslash
4517 ' and add these lines: 
4518 \newline
4519 \InsetSpace ~
4520 \InsetSpace ~
4521 set BISON_SIMPLE=C:
4522 \backslash
4523 util
4524 \backslash
4525 bison.simple 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_HAIRY=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.hairy
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4538 \newline
4539
4540 \newline
4541 Steps 'c' and 'd' are needed
4542  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543  reside in some weird Unix directory, '/usr/local/share/' I think.
4544  So it is necessary to tell bison where those files are located if they
4545  are not in such directory.
4546  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4547 \newline
4548
4549 \newline
4550 e
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552  in 'Show directories for:' select 'Executable files', and in the directories
4553  window add a new path: 'c:
4554 \backslash
4555 util', click ok.
4556  Note that you can use any other path instead of 'c:
4557 \backslash
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4559 \backslash
4560 Program Files
4561 \backslash
4562 Microsoft Visual Studio
4563 \backslash
4564 Common
4565 \backslash
4566 Tools'.
4567  So you don't have to execute step 'e' :)
4568 \end_layout
4569
4570 \begin_layout Standard
4571 That is it.
4572  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573  the executables from sdcc
4574 \backslash
4575 bin_vc to sdcc
4576 \backslash
4577 bin, and you can compile using SDCC.
4578 \end_layout
4579
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4582 \end_layout
4583
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586  This should regenerate all the .exe files in the bin directory except for
4587  SDCDB and ucSim.
4588 \end_layout
4589
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593  The safest option is to delete all .obj files and run the build again.
4594  From a Cygwin BASH prompt, this can easily be done with the command (be
4595  sure you are in the sdcc directory):
4596 \newline
4597
4598 \newline
4599
4600 \family sans
4601 \series bold
4602 find .
4603  
4604 \backslash
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4606 \backslash
4607 ) -print -exec rm {} 
4608 \backslash
4609 ;
4610 \family default
4611 \series default
4612
4613 \newline
4614
4615 \newline
4616 or on Windows NT/2000/XP from the command prompt with the command:
4617 \newline
4618
4619 \family sans
4620 \series bold
4621
4622 \newline
4623 del /s *.obj *.lib *.rul
4624 \family default
4625 \series default
4626  from the sdcc directory.
4627 \end_layout
4628
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4631 \end_layout
4632
4633 \begin_layout Enumerate
4634 Download the binary zip package from 
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4636
4637 \end_inset
4638
4639  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640  This should unpack to a group of sub-directories.
4641  An example directory structure after unpacking the mingw32 package is:
4642  c:
4643 \backslash
4644 sdcc
4645 \backslash
4646 bin for the executables, c:
4647 \backslash
4648 sdcc
4649 \backslash
4650 include and c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 lib for the include and libraries.
4655 \end_layout
4656
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659  directory or start sdcc using the full path.
4660 \end_layout
4661
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4665
4666 \end_inset
4667
4668
4669 \end_layout
4670
4671 \begin_layout Standard
4672 Download the setup program 
4673 \emph on
4674 sdcc-x.y.z-setup.exe
4675 \emph default
4676  for an official release from 
4677 \newline
4678
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4680
4681 \end_inset
4682
4683  or a setup program for one of the snapshots 
4684 \emph on
4685 sdcc-yyyymmdd-xxxx-setup.exe
4686 \emph default
4687  from 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4689
4690 \end_inset
4691
4692  and execute it.
4693  A windows typical installer will guide you through the installation process.
4694 \end_layout
4695
4696 \begin_layout Subsection
4697 VPATH
4698 \begin_inset LatexCommand \index{VPATH}
4699
4700 \end_inset
4701
4702  feature
4703 \end_layout
4704
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707  It allows to separate the source and build trees.
4708  Here's an example:
4709 \end_layout
4710
4711 \begin_layout Standard
4712
4713 \family typewriter
4714 cd ~\InsetSpace ~
4715 \InsetSpace ~
4716 \InsetSpace ~
4717 \InsetSpace ~
4718 \InsetSpace ~
4719 \InsetSpace ~
4720 \InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 \InsetSpace ~
4730 \InsetSpace ~
4731 \InsetSpace ~
4732 \InsetSpace ~
4733 \InsetSpace ~
4734 \InsetSpace ~
4735 # cd $HOME
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4743 \end_layout
4744
4745 \begin_layout Standard
4746
4747 \family typewriter
4748 mkdir sdcc.build\InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 # put output in sdcc.build
4758 \end_layout
4759
4760 \begin_layout Standard
4761
4762 \family typewriter
4763 cd sdcc.build
4764 \end_layout
4765
4766 \begin_layout Standard
4767
4768 \family typewriter
4769 ../sdcc/configure\InsetSpace ~
4770 \InsetSpace ~
4771 \InsetSpace ~
4772 \InsetSpace ~
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 \InsetSpace ~
4777 # configure is doing all the magic!
4778 \end_layout
4779
4780 \begin_layout Standard
4781
4782 \family typewriter
4783 make
4784 \end_layout
4785
4786 \begin_layout Standard
4787 \noindent
4788 That's it! 
4789 \series bold
4790 configure
4791 \series default
4792  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793  It automagically computes the variables srcdir, top_srcdir and top_buildir
4794  for each directory.
4795  After running 
4796 \series bold
4797 make
4798 \series default
4799  the generated files will be in ~/sdcc.build, while the source files stay
4800  in ~/sdcc.
4801 \newline
4802 This is not only usefull for building different binaries, e.g.
4803  when cross compiling.
4804  It also gives you a much better overview in the source tree when all the
4805  generated files are not scattered between the source files.
4806  And the best thing is: if you want to change a file you can leave the original
4807  file untouched in the source directory.
4808  Simply copy it to the build directory, edit it, enter `make clean', `rm
4809  Makefile.dep' and `make'.
4810  
4811 \series bold
4812 make
4813 \series default
4814  will do the rest for you!
4815 \end_layout
4816
4817 \begin_layout Section
4818 Building the Documentation
4819 \end_layout
4820
4821 \begin_layout Standard
4822 Add -
4823 \begin_inset ERT
4824 status collapsed
4825
4826 \begin_layout Standard
4827
4828
4829 \backslash
4830 /
4831 \end_layout
4832
4833 \end_inset
4834
4835 -enable-doc to the configure arguments to build the documentation together
4836  with all the other stuff.
4837  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838  dvips and makeindex) to get the job done.
4839  Another possibility is to change to the doc directory and to type 
4840 \family sans
4841 \series bold
4842
4843 \begin_inset Quotes srd
4844 \end_inset
4845
4846 make
4847 \begin_inset Quotes srd
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  there.
4854  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4855 x).
4856  Using LyX 
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4858
4859 \end_inset
4860
4861  as editor is straightforward.
4862  Prebuilt documentation in html and pdf format is available from 
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4864
4865 \end_inset
4866
4867 .
4868 \end_layout
4869
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4873
4874 \end_inset
4875
4876
4877 \end_layout
4878
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881  reason the hyperlinks are working there whereas in the html version they
4882  are not
4883 \begin_inset Foot
4884 status open
4885
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4888 \end_layout
4889
4890 \end_inset
4891
4892 .
4893  
4894 \newline
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4897
4898 \end_inset
4899
4900  at 
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4902
4903 \end_inset
4904
4905 .
4906  
4907 \newline
4908 A html version
4909 \begin_inset LatexCommand \index{HTML version of this document}
4910
4911 \end_inset
4912
4913  should be online at 
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4915
4916 \end_inset
4917
4918 .
4919 \newline
4920 This documentation is in some aspects different from a commercial documentation:
4921  
4922 \end_layout
4923
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926  (commercially these probably would be separate documents/products).
4927  This document
4928 \begin_inset LatexCommand \index{Status of documentation}
4929
4930 \end_inset
4931
4932  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4933 on about f.e.
4934  Z80, PIC14, PIC16 and HC08.
4935 \end_layout
4936
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939  Don't let this distract you.
4940  If there f.e.
4941  was a reference like 
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4943
4944 \end_inset
4945
4946  together with a statement 
4947 \begin_inset Quotes sld
4948 \end_inset
4949
4950 some processors which are targetted by SDCC can be implemented in a 
4951 \emph on
4952 f
4953 \emph default
4954 ield 
4955 \emph on
4956 p
4957 \emph default
4958 rogrammable 
4959 \emph on
4960 g
4961 \emph default
4962 ate 
4963 \emph on
4964 a
4965 \emph default
4966 rray
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4968
4969 \end_inset
4970
4971
4972 \begin_inset Quotes srd
4973 \end_inset
4974
4975  or 
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4977
4978 \end_inset
4979
4980
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4982
4983 \end_inset
4984
4985  
4986 \begin_inset Quotes sld
4987 \end_inset
4988
4989 have you ever heard of an open source compiler that compiles a subset of
4990  C for an FPGA?
4991 \begin_inset Quotes srd
4992 \end_inset
4993
4994  we expect you to have a quick look there and come back.
4995  If you read this you are on the right track.
4996 \end_layout
4997
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000  than to the solution.
5001 \end_layout
5002
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5005 \end_layout
5006
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5009  than pictures.
5010 \end_layout
5011
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5015
5016 \end_inset
5017
5018
5019 \end_layout
5020
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5023  see if it runs.
5024  Type 
5025 \family sans
5026 \series bold
5027 "sdcc -
5028 \begin_inset ERT
5029 status collapsed
5030
5031 \begin_layout Standard
5032
5033
5034 \backslash
5035 /
5036 \end_layout
5037
5038 \end_inset
5039
5040 -version"
5041 \begin_inset LatexCommand \index{version}
5042
5043 \end_inset
5044
5045
5046 \family default
5047 \series default
5048  at the prompt, and the program should run and output its version like:
5049  
5050 \newline
5051
5052 \family typewriter
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5054  (UNIX)
5055 \end_layout
5056
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059  you need to check over your installation.
5060  Make sure that the sdcc bin directory is in your executable search path
5061  defined by the PATH environment setting (
5062 \series medium
5063 see 
5064 \series default
5065 section 
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5067
5068 \end_inset
5069
5070 \InsetSpace ~
5071
5072 \series medium
5073 Install trouble-shooting for suggestions
5074 \series default
5075 ).
5076  Make sure that the sdcc program is in the bin folder, if not perhaps something
5077  did not install correctly.
5078 \newline
5079
5080 \newline
5081
5082 \series medium
5083 SDCC 
5084 \series default
5085 is commonly installed as described in section 
5086 \begin_inset Quotes sld
5087 \end_inset
5088
5089 Install and search paths
5090 \begin_inset Quotes srd
5091 \end_inset
5092
5093 .
5094 \newline
5095
5096 \newline
5097
5098 \series medium
5099 Make sure the compiler works on a very simple example.
5100  Type in the following test.c program using your favorite 
5101 \series default
5102 ASCII 
5103 \series medium
5104 editor:
5105 \end_layout
5106
5107 \begin_layout Verse
5108
5109 \family typewriter
5110 char test;
5111 \newline
5112
5113 \newline
5114 void main(void) {
5115 \newline
5116 \InsetSpace ~
5117 \InsetSpace ~
5118 \InsetSpace ~
5119 \InsetSpace ~
5120 test=0;
5121 \newline
5122 }
5123 \end_layout
5124
5125 \begin_layout Standard
5126
5127 \series medium
5128 Compile this using the following command: 
5129 \family sans
5130 \series bold
5131 "sdcc -c test.c".
5132
5133 \family default
5134 \series default
5135  
5136 \series medium
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138  Congratulations, you've just compiled your first program with SDCC.
5139  We used the -c option to tell SDCC not to link the generated code, just
5140  to keep things simple for this step.
5141 \series default
5142
5143 \newline
5144
5145 \newline
5146
5147 \series medium
5148 The next step is to try it with the linker.
5149  Type in 
5150 \family sans
5151 \series bold
5152 "sdcc test.c
5153 \family default
5154 \series default
5155 "
5156 \series medium
5157 .
5158  If all goes well the compiler will link with the libraries and produce
5159  a test.ihx output file.
5160  If this step fails
5161 \series default
5162  
5163 \series medium
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5165  likely that 
5166 \series default
5167 SDCC
5168 \series medium
5169  cannot find the 
5170 \series default
5171 /
5172 \series medium
5173 usr/local/share/sdcc/lib directory
5174 \series default
5175  
5176 \series medium
5177 (see 
5178 \series default
5179 section 
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5181
5182 \end_inset
5183
5184 \InsetSpace ~
5185
5186 \series medium
5187 Install trouble-shooting for suggestions).
5188 \series default
5189
5190 \newline
5191
5192 \newline
5193
5194 \series medium
5195 The final test is to ensure 
5196 \series default
5197 SDCC
5198 \series medium
5199  can use the 
5200 \series default
5201 standard
5202 \series medium
5203  header files and libraries.
5204  Edit test.c and change it to the following:
5205 \end_layout
5206
5207 \begin_layout Verse
5208
5209 \family typewriter
5210 #include <string.h>
5211 \newline
5212
5213 \newline
5214 char str1[10];
5215 \newline
5216
5217 \newline
5218 void main(void) {
5219 \newline
5220 \InsetSpace ~
5221 \InsetSpace ~
5222 strcpy(str1, "testing");
5223 \newline
5224 }
5225 \end_layout
5226
5227 \begin_layout Standard
5228
5229 \series medium
5230 Compile this by typing 
5231 \family sans
5232 \series bold
5233 "sdcc test.c"
5234 \family default
5235 \series medium
5236 .
5237  This should generate a test.ihx output file, and it should give no warnings
5238  such as not finding the string.h file.
5239  If it cannot find the string.h file, then the problem is that 
5240 \series default
5241 SDCC
5242 \series medium
5243  cannot find the /usr/local/share/sdcc/include directory
5244 \series default
5245  
5246 \series medium
5247 (see the 
5248 \series default
5249 section 
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5251
5252 \end_inset
5253
5254 \InsetSpace ~
5255
5256 \series medium
5257 Install trouble-shooting section for suggestions).
5258
5259 \series default
5260  Use option 
5261 \series bold
5262 -
5263 \begin_inset ERT
5264 status collapsed
5265
5266 \begin_layout Standard
5267
5268
5269 \backslash
5270 /
5271 \end_layout
5272
5273 \end_inset
5274
5275 -print-search-dirs
5276 \series default
5277
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5279
5280 \end_inset
5281
5282  to find exactly where SDCC is looking for the include and lib files.
5283 \end_layout
5284
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5288
5289 \end_inset
5290
5291
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5293
5294 \end_inset
5295
5296
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5301 \end_layout
5302
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305  again in an empty directory.
5306  Configure it like:
5307 \newline
5308
5309 \newline
5310
5311 \family sans
5312 \series bold
5313 ./configure 2>&1 | tee configure.log
5314 \family default
5315 \series default
5316
5317 \newline
5318
5319 \newline
5320 and build it like:
5321 \newline
5322
5323 \newline
5324
5325 \family sans
5326 \series bold
5327 make 2>&1 | tee make.log
5328 \family default
5329 \series default
5330
5331 \newline
5332
5333 \newline
5334 If anything goes wrong, you can review the log files to locate the problem.
5335  Or a relevant part of this can be attached to an email that could be helpful
5336  when requesting help from the mailing list.
5337 \end_layout
5338
5339 \begin_layout Subsection
5340 What the 
5341 \begin_inset Quotes sld
5342 \end_inset
5343
5344 ./configure
5345 \begin_inset Quotes srd
5346 \end_inset
5347
5348  does
5349 \end_layout
5350
5351 \begin_layout Standard
5352 The 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 ./configure
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360  command is a script that analyzes your system and performs some configuration
5361  to ensure the source package compiles on your system.
5362  It will take a few minutes to run, and will compile a few tests to determine
5363  what compiler features are installed.
5364 \end_layout
5365
5366 \begin_layout Subsection
5367 What the 
5368 \begin_inset Quotes sld
5369 \end_inset
5370
5371 make
5372 \begin_inset Quotes srd
5373 \end_inset
5374
5375  does
5376 \end_layout
5377
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380  packages into the final installed binary executables.
5381 \end_layout
5382
5383 \begin_layout Subsection
5384 What the 
5385 \begin_inset Quotes sld
5386 \end_inset
5387
5388 make install
5389 \begin_inset Quotes erd
5390 \end_inset
5391
5392  command does.
5393 \end_layout
5394
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397  files into the appropriate directories.
5398  See sections 
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5400
5401 \end_inset
5402
5403 ,\InsetSpace ~
5404
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5406
5407 \end_inset
5408
5409 \InsetSpace ~
5410 about install and search paths.
5411 \newline
5412 On most systems you will need super-user privilege
5413 s to do this.
5414 \end_layout
5415
5416 \begin_layout Section
5417 Components of SDCC
5418 \end_layout
5419
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422  These include linkers, assemblers, simulators and other components.
5423  Here is a summary of some of the components.
5424  Note that the included simulator and assembler have separate documentation
5425  which you can find in the source package in their respective directories.
5426  As SDCC grows to include support for other processors, other packages from
5427  various developers are included and may have their own sets of documentation.
5428 \newline
5429
5430 \newline
5431 You
5432  might want to look at the files which are installed in <installdir>.
5433  At the time of this writing, we find the following programs for gcc-builds:
5434 \newline
5435
5436  
5437 \newline
5438 In <installdir>/bin:
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 as-z80
5455 \series bold
5456
5457 \series default
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5463 \end_layout
5464
5465 \begin_layout Itemize
5466 link-z80
5467 \series bold
5468
5469 \series default
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5475 \end_layout
5476
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5483 \end_layout
5484
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 the include files
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5499  relocatables.
5500 \end_layout
5501
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 the documentation
5508 \end_layout
5509
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512  executables to support processors like AVR, PIC, etc.
5513 \end_layout
5514
5515 \begin_layout Subsection
5516 sdcc - The Compiler
5517 \end_layout
5518
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521  the assembler and linkage editor.
5522 \end_layout
5523
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5526 \end_layout
5527
5528 \begin_layout Standard
5529 The preprocessor
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5531
5532 \end_inset
5533
5534  is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5536
5537 \end_inset
5538
5539  preprocessor 
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5541
5542 \end_inset
5543
5544 .
5545  The C preprocessor is used to pull in #include sources, process #ifdef
5546  statements, #defines and so on.
5547 \end_layout
5548
5549 \begin_layout Subsection
5550 as
5551 \emph on
5552 xxxx
5553 \emph default
5554 , aslink, link-
5555 \emph on
5556 xxx
5557 \emph default
5558  - The Assemblers and Linkage Editors
5559 \end_layout
5560
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5563  Baldwin.
5564  John Hartman created the version for 8051, and I (Sandeep) have made some
5565  enhancements and bug fixes for it to work properly with SDCC.
5566 \end_layout
5567
5568 \begin_layout Subsection
5569 s51 - The Simulator
5570 \end_layout
5571
5572 \begin_layout Standard
5573 S51
5574 \begin_inset LatexCommand \index{s51}
5575
5576 \end_inset
5577
5578  is a free open source simulator developed by Daniel Drotos.
5579  The simulator is built as part of the build process.
5580  For more information visit Daniel's web site at: 
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5582
5583 \end_inset
5584
5585 .
5586  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5587  XA51 family.
5588 \end_layout
5589
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5592 \end_layout
5593
5594 \begin_layout Standard
5595 SDCDB
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5597
5598 \end_inset
5599
5600  is the companion source level debugger.
5601  More about SDCDB in section 
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5603
5604 \end_inset
5605
5606 .
5607  The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5609
5610 \end_inset
5611
5612 , but can be easily changed to use other simulators.
5613 \end_layout
5614
5615 \begin_layout Chapter
5616 Using SDCC
5617 \end_layout
5618
5619 \begin_layout Section
5620 Compiling
5621 \end_layout
5622
5623 \begin_layout Subsection
5624 Single Source File Projects
5625 \end_layout
5626
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629  Compile your programs with the following command 
5630 \family sans
5631 \series bold
5632 "sdcc sourcefile.c".
5633
5634 \family default
5635 \series default
5636  This will compile, assemble and link your source file.
5637  Output files are as follows:
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.asm
5642 \begin_inset LatexCommand \index{<file>.asm}
5643
5644 \end_inset
5645
5646  - Assembler source
5647 \begin_inset LatexCommand \index{Assembler source}
5648
5649 \end_inset
5650
5651  file created by the compiler
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.lst
5656 \begin_inset LatexCommand \index{<file>.lst}
5657
5658 \end_inset
5659
5660  - Assembler listing
5661 \begin_inset LatexCommand \index{Assembler listing}
5662
5663 \end_inset
5664
5665  file created by the Assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rst
5670 \begin_inset LatexCommand \index{<file>.rst}
5671
5672 \end_inset
5673
5674  - Assembler listing
5675 \begin_inset LatexCommand \index{Assembler listing}
5676
5677 \end_inset
5678
5679  file updated with linkedit information, created by linkage editor
5680 \end_layout
5681
5682 \begin_layout Itemize
5683 sourcefile.sym
5684 \begin_inset LatexCommand \index{<file>.sym}
5685
5686 \end_inset
5687
5688  - symbol listing
5689 \begin_inset LatexCommand \index{Symbol listing}
5690
5691 \end_inset
5692
5693  for the sourcefile, created by the assembler
5694 \end_layout
5695
5696 \begin_layout Itemize
5697 sourcefile.rel
5698 \begin_inset LatexCommand \index{<file>.rel}
5699
5700 \end_inset
5701
5702  or sourcefile.o
5703 \begin_inset LatexCommand \index{<file>.o}
5704
5705 \end_inset
5706
5707  - Object file
5708 \begin_inset LatexCommand \index{Object file}
5709
5710 \end_inset
5711
5712  created by the assembler, input to Linkage editor
5713 \end_layout
5714
5715 \begin_layout Itemize
5716 sourcefile.map
5717 \begin_inset LatexCommand \index{<file>.map}
5718
5719 \end_inset
5720
5721  - The memory map
5722 \begin_inset LatexCommand \index{Memory map}
5723
5724 \end_inset
5725
5726  for the load module, created by the Linker
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 sourcefile.mem
5731 \begin_inset LatexCommand \index{<file>.mem}
5732
5733 \end_inset
5734
5735  - A file with a summary of the memory usage
5736 \end_layout
5737
5738 \begin_layout Itemize
5739 sourcefile.ihx
5740 \begin_inset LatexCommand \index{<file>.ihx}
5741
5742 \end_inset
5743
5744  - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5746
5747 \end_inset
5748
5749  (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5751
5752 \end_inset
5753
5754  with -
5755 \begin_inset ERT
5756 status collapsed
5757
5758 \begin_layout Standard
5759
5760
5761 \backslash
5762 /
5763 \end_layout
5764
5765 \end_inset
5766
5767 -out-fmt-s19
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5769
5770 \end_inset
5771
5772 .
5773  If you need another format you might want to use 
5774 \family sans
5775 \shape italic
5776 objdump
5777 \family default
5778 \shape default
5779
5780 \begin_inset LatexCommand \index{objdump (tool)}
5781
5782 \end_inset
5783
5784  or
5785 \family sans
5786 \shape italic
5787  srecord
5788 \family default
5789 \shape default
5790
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5792
5793 \end_inset
5794
5795
5796 \begin_inset Note Note
5797 status collapsed
5798
5799 \begin_layout Standard
5800 hyperlinks needed
5801 \end_layout
5802
5803 \end_inset
5804
5805  - see also section 
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5807
5808 \end_inset
5809
5810 ).
5811  Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.adb
5821 \begin_inset LatexCommand \index{<file>.adb}
5822
5823 \end_inset
5824
5825  - An intermediate file containing debug information needed to create the
5826  .cdb file (with -
5827 \begin_inset ERT
5828 status collapsed
5829
5830 \begin_layout Standard
5831
5832
5833 \backslash
5834 /
5835 \end_layout
5836
5837 \end_inset
5838
5839 -debug
5840 \begin_inset LatexCommand \index{-\/-debug}
5841
5842 \end_inset
5843
5844
5845 \end_layout
5846
5847 \begin_layout Itemize
5848 sourcefile.cdb
5849 \begin_inset LatexCommand \index{<file>.cdb}
5850
5851 \end_inset
5852
5853  - An optional file (with -
5854 \begin_inset ERT
5855 status collapsed
5856
5857 \begin_layout Standard
5858
5859
5860 \backslash
5861 /
5862 \end_layout
5863
5864 \end_inset
5865
5866 -debug) containing debug information.
5867  The format is documented in cdbfileformat.pdf
5868 \end_layout
5869
5870 \begin_layout Itemize
5871 sourcefile.
5872  - (no extension)
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5874
5875 \end_inset
5876
5877  An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5879
5880 \end_inset
5881
5882  
5883 \begin_inset LatexCommand \label{OMF file}
5884
5885 \end_inset
5886
5887 file containing debug information (generated with option -
5888 \begin_inset ERT
5889 status collapsed
5890
5891 \begin_layout Standard
5892
5893
5894 \backslash
5895 /
5896 \end_layout
5897
5898 \end_inset
5899
5900 -debug).
5901  The (Intel)
5902 \emph on
5903  a
5904 \emph default
5905 bsolute 
5906 \emph on
5907 o
5908 \emph default
5909 bject 
5910 \emph on
5911 m
5912 \emph default
5913 odule 
5914 \emph on
5915 f
5916 \emph default
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5918  tools (debuggers
5919 \begin_inset LatexCommand \index{Debugger}
5920
5921 \end_inset
5922
5923 , simulators, emulators).
5924 \end_layout
5925
5926 \begin_layout Itemize
5927 sourcefile.dump*
5928 \begin_inset LatexCommand \index{<file>.dump*}
5929
5930 \end_inset
5931
5932  - Dump file to debug the compiler it self (generated with option -
5933 \begin_inset ERT
5934 status collapsed
5935
5936 \begin_layout Standard
5937
5938
5939 \backslash
5940 /
5941 \end_layout
5942
5943 \end_inset
5944
5945 -dumpall) (see section 
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5947
5948 \end_inset
5949
5950 \InsetSpace ~
5951  and section 
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5953
5954 \end_inset
5955
5956 \InsetSpace ~
5957
5958 \begin_inset Quotes sld
5959 \end_inset
5960
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5963 \end_inset
5964
5965 ).
5966 \end_layout
5967
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5971
5972 \end_inset
5973
5974  file
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5976
5977 \end_inset
5978
5979
5980 \end_layout
5981
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5985
5986 \end_inset
5987
5988  which is generated by SDCC might include lines of varying length and the
5989  addresses within the file are not guaranteed to be strictly ascending.
5990  If your toolchain or a bootloader does not like this you can use the tool
5991  
5992 \family typewriter
5993 packihx
5994 \family default
5995
5996 \begin_inset LatexCommand \index{packihx (tool)}
5997
5998 \end_inset
5999
6000  which is part of the SDCC distribution: 
6001 \newline
6002
6003 \newline
6004
6005 \family sans
6006 \series bold
6007  packihx sourcefile.ihx >sourcefile.hex
6008 \family default
6009 \series default
6010
6011 \newline
6012
6013 \newline
6014 The separately available
6015 \emph on
6016  srecord
6017 \emph default
6018
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6020
6021 \end_inset
6022
6023  package additionally allows to set undefined locations to a predefined
6024  value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6026
6027 \end_inset
6028
6029  of various flavours (crc, add, xor) and to perform other manipulations
6030  (convert, split, crop, offset, ...).
6031  
6032 \newline
6033
6034 \newline
6035
6036 \family sans
6037 \series bold
6038 srec_cat\InsetSpace ~
6039 \InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6041 \InsetSpace ~
6042 -o sourcefile.hex -intel
6043 \newline
6044
6045 \newline
6046
6047 \family default
6048 \series default
6049 An example for a more complex command line
6050 \begin_inset Foot
6051 status open
6052
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6056
6057 \end_inset
6058
6059  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6060  block is zero.
6061  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062  will be interpreted as an 
6063 \family typewriter
6064 lcall
6065 \family default
6066  to address 
6067 \family typewriter
6068 0x1212
6069 \family default
6070  (where an emergency routine could sit).
6071 \end_layout
6072
6073 \end_inset
6074
6075  could look like:
6076 \newline
6077
6078 \newline
6079
6080 \family sans
6081 \series bold
6082 \size footnotesize
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6085 \InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6089 \InsetSpace ~
6090 -o sourcefile.hex -intel
6091 \size default
6092
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 The srecord package is available at 
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6101
6102 \end_inset
6103
6104  .
6105 \end_layout
6106
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6109 \end_layout
6110
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113  Let us for example assume that you have a project containing the following
6114  files:
6115 \newline
6116
6117 \newline
6118 foo1.c (contains some functions)
6119 \newline
6120 foo2.c (contains some more functions)
6121 \newline
6122 foomai
6123 n.c (contains more functions and the function main)
6124 \newline
6125
6126 \size footnotesize
6127
6128 \newline
6129
6130 \size default
6131 The first two files will need to be compiled separately with the commands:
6132 \size footnotesize
6133  
6134 \size default
6135
6136 \newline
6137
6138 \newline
6139
6140 \family sans
6141 \series bold
6142 sdcc\InsetSpace ~
6143 -c\InsetSpace ~
6144 foo1.c
6145 \family default
6146 \series default
6147 \size footnotesize
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 \size default
6154 sdcc\InsetSpace ~
6155 -c\InsetSpace ~
6156 foo2.c
6157 \family default
6158 \series default
6159
6160 \newline
6161
6162 \newline
6163 Then compile the source file containing the 
6164 \emph on
6165 main()
6166 \emph default
6167  function and link
6168 \begin_inset LatexCommand \index{Linker}
6169
6170 \end_inset
6171
6172  the files together with the following command: 
6173 \newline
6174
6175 \newline
6176
6177 \family sans
6178 \series bold
6179 sdcc\InsetSpace ~
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6182 foo2.rel
6183 \family default
6184 \series default
6185
6186 \begin_inset LatexCommand \index{<file>.rel}
6187
6188 \end_inset
6189
6190
6191 \newline
6192
6193 \newline
6194 Alternatively, 
6195 \emph on
6196 foomain.c 
6197 \emph default
6198 can be separately compiled as well: 
6199 \family sans
6200 \series bold
6201
6202 \newline
6203
6204 \newline
6205 sdcc\InsetSpace ~
6206 -c\InsetSpace ~
6207 foomain.c
6208 \newline
6209 sdcc foomain.rel foo1.rel foo2.rel
6210 \newline
6211
6212 \newline
6213
6214 \family default
6215 \series default
6216 The file containing the 
6217 \emph on
6218 main()
6219 \emph default
6220  function
6221 \emph on
6222  
6223 \emph default
6224 \noun on
6225 must
6226 \noun default
6227  be the 
6228 \noun on
6229 first
6230 \noun default
6231  file specified in the command line, since the linkage editor processes
6232  file in the order they are presented to it.
6233  The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6235
6236 \end_inset
6237
6238 .
6239  You can view this file to troubleshoot linking problems such as those arising
6240  from missing libraries.
6241 \end_layout
6242
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6246
6247 \end_inset
6248
6249
6250 \end_layout
6251
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6255  for how to create a 
6256 \emph on
6257 .lib
6258 \begin_inset LatexCommand \index{<file>.lib}
6259
6260 \end_inset
6261
6262
6263 \emph default
6264  library file.
6265  Libraries created in this manner can be included in the command line.
6266  Make sure you include the -L <library-path> option to tell the linker where
6267  to look for these files if they are not in the current directory.
6268  Here is an example, assuming you have the source file 
6269 \emph on
6270 foomain.c
6271 \emph default
6272  and a library
6273 \emph on
6274  foolib.lib
6275 \emph default
6276  in the directory 
6277 \emph on
6278 mylib
6279 \emph default
6280  (if that is not the same as your current project):
6281 \newline
6282
6283 \newline
6284
6285 \family sans
6286 \series bold
6287 sdcc foomain.c foolib.lib -L mylib
6288 \newline
6289
6290 \newline
6291
6292 \family default
6293 \series default
6294 Note here that
6295 \emph on
6296  mylib
6297 \emph default
6298  must be an absolute path name.
6299 \newline
6300
6301 \newline
6302 The most efficient way to use libraries is
6303  to keep separate modules in separate source files.
6304  The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6306
6307 \end_inset
6308
6309  files.
6310  For an example see the standard library file 
6311 \emph on
6312 libsdcc.lib
6313 \emph default
6314  in the directory <installdir>/share/lib/small.
6315 \end_layout
6316
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6320
6321 \end_inset
6322
6323
6324 \end_layout
6325
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328  file as described in the preceding section, sdcclib can be used to embed
6329  all the modules belonging to such library in the library file itself.
6330  This results in a larger library file, but it greatly reduces the number
6331  of disk files accessed by the linker.
6332   Additionally, the packed library file contains an index of all include
6333  modules and symbols that significantly speeds up the linking process.
6334  To display a list of options supported by sdcclib type:
6335 \newline
6336
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family sans
6342 \series bold
6343 sdcclib -?
6344 \begin_inset LatexCommand \index{sdcclib}
6345
6346 \end_inset
6347
6348
6349 \newline
6350
6351 \newline
6352
6353 \family default
6354 \series default
6355 To create a new library file, start by compiling all the required modules.
6356  For example:
6357 \newline
6358
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _divsint.c
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family sans
6371 \series bold
6372 sdcc -c _divuint.c
6373 \end_layout
6374
6375 \begin_layout Standard
6376
6377 \family sans
6378 \series bold
6379 sdcc -c _modsint.c
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family sans
6385 \series bold
6386 sdcc -c _moduint.c
6387 \end_layout
6388
6389 \begin_layout Standard
6390
6391 \family sans
6392 \series bold
6393 sdcc -c _mulint.c
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6400  and _mulint.rel.
6401  The next step is to add the .rel files to the library file:
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _divsint.rel
6411 \family default
6412
6413 \begin_inset LatexCommand \index{sdcclib}
6414
6415 \end_inset
6416
6417
6418 \end_layout
6419
6420 \begin_layout Standard
6421
6422 \family sans
6423 \series bold
6424 sdcclib libint.lib _divuint.rel
6425 \end_layout
6426
6427 \begin_layout Standard
6428
6429 \family sans
6430 \series bold
6431 sdcclib libint.lib _modsint.rel
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _moduint.rel
6439 \end_layout
6440
6441 \begin_layout Standard
6442
6443 \family sans
6444 \series bold
6445 sdcclib libint.lib _mulint.rel
6446 \family default
6447 \series default
6448
6449 \newline
6450
6451 \end_layout
6452
6453 \begin_layout Standard
6454 Or, if you preffer:
6455 \family sans
6456 \series bold
6457
6458 \newline
6459
6460 \end_layout
6461
6462 \begin_layout Standard
6463
6464 \family sans
6465 \series bold
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6467 \family default
6468 \series default
6469
6470 \newline
6471
6472 \end_layout
6473
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476  If a list of .rel files is available, you can tell sdcclib to add those
6477  files to a library.
6478  For example, if the file 'myliblist.txt' contains
6479 \family sans
6480 \series bold
6481
6482 \newline
6483
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _divsint.rel
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family sans
6496 \series bold
6497 _divuint.rel
6498 \end_layout
6499
6500 \begin_layout Standard
6501
6502 \family sans
6503 \series bold
6504 _modsint.rel
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 _moduint.rel
6512 \end_layout
6513
6514 \begin_layout Standard
6515
6516 \family sans
6517 \series bold
6518 _mulint.rel
6519 \family default
6520 \series default
6521
6522 \newline
6523
6524 \end_layout
6525
6526 \begin_layout Standard
6527 Use
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \end_layout
6534
6535 \begin_layout Standard
6536
6537 \family sans
6538 \series bold
6539 sdcclib -l libint.lib myliblist.txt
6540 \family default
6541 \series default
6542
6543 \newline
6544
6545 \end_layout
6546
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549  them to the library.
6550  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6551  For example:
6552 \family sans
6553 \series bold
6554
6555 \newline
6556
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family sans
6562 \series bold
6563 set SDCCLIB_CC=sdcc -c
6564 \end_layout
6565
6566 \begin_layout Standard
6567
6568 \family sans
6569 \series bold
6570 sdcclib -l libint.lib myliblist.txt
6571 \family default
6572 \series default
6573
6574 \newline
6575
6576 \end_layout
6577
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580  and -m are available.
6581  For example:
6582 \newline
6583
6584 \newline
6585
6586 \family sans
6587 \series bold
6588 sdcclib -s libint.lib
6589 \family default
6590
6591 \begin_inset LatexCommand \index{sdcclib}
6592
6593 \end_inset
6594
6595
6596 \newline
6597
6598 \family typewriter
6599 \series default
6600 _divsint.rel:
6601 \end_layout
6602
6603 \begin_layout Standard
6604
6605 \family typewriter
6606 __divsint_a_1_1
6607 \end_layout
6608
6609 \begin_layout Standard
6610
6611 \family typewriter
6612 __divsint_PARM_2
6613 \end_layout
6614
6615 \begin_layout Standard
6616
6617 \family typewriter
6618 __divsint
6619 \newline
6620 _divuint.rel:
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divuint_a_1_1
6627 \end_layout
6628
6629 \begin_layout Standard
6630
6631 \family typewriter
6632 __divuint_PARM_2
6633 \end_layout
6634
6635 \begin_layout Standard
6636
6637 \family typewriter
6638 __divuint_reste_1_1
6639 \end_layout
6640
6641 \begin_layout Standard
6642
6643 \family typewriter
6644 __divuint_count_1_1
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __divuint
6651 \newline
6652 _modsint.rel:
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __modsint_a_1_1
6659 \end_layout
6660
6661 \begin_layout Standard
6662
6663 \family typewriter
6664 __modsint_PARM_2
6665 \end_layout
6666
6667 \begin_layout Standard
6668
6669 \family typewriter
6670 __modsint
6671 \newline
6672 _moduint.rel:
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __moduint_a_1_1
6679 \end_layout
6680
6681 \begin_layout Standard
6682
6683 \family typewriter
6684 __moduint_PARM_2
6685 \end_layout
6686
6687 \begin_layout Standard
6688
6689 \family typewriter
6690 __moduint_count_1_1
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family typewriter
6696 __moduint
6697 \newline
6698 _mulint.rel:
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __mulint_PARM_2
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family typewriter
6710 __mulint
6711 \family default
6712 \series bold
6713
6714 \newline
6715
6716 \end_layout
6717
6718 \begin_layout Standard
6719 If the source files are compiled using -
6720 \begin_inset ERT
6721 status collapsed
6722
6723 \begin_layout Standard
6724
6725
6726 \backslash
6727 /
6728 \end_layout
6729
6730 \end_inset
6731
6732 -debug
6733 \begin_inset LatexCommand \index{-\/-debug}
6734
6735 \end_inset
6736
6737 , the corresponding debug information file .adb will be include in the library
6738  file as well.
6739  The library files created with sdcclib are plain text files, so they can
6740  be viewed with a text editor.
6741  It is not recomended to modify a library file created with sdcclib using
6742  a text editor, as there are file indexes numbers located accross the file
6743  used by the linker to quickly locate the required module to link.
6744  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745  it can be safely deleted, since all the information required for linking
6746  is embedded in the library file itself.
6747  Library files created using sdcclib are used as described in the preceding
6748  sections.
6749 \begin_inset VSpace bigskip
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6758
6759 \end_inset
6760
6761
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6763
6764 \end_inset
6765
6766
6767 \end_layout
6768
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6772
6773 \end_inset
6774
6775
6776 \begin_inset LatexCommand \index{Processor selection options}
6777
6778 \end_inset
6779
6780
6781 \end_layout
6782
6783 \begin_layout List
6784 \labelwidthstring 00.00.0000
6785
6786 \series bold
6787 -mmcs51
6788 \begin_inset LatexCommand \index{-mmcs51}
6789
6790 \end_inset
6791
6792
6793 \series default
6794  Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6796
6797 \end_inset
6798
6799  family of processors.
6800  This is the default processor target.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -mds390
6808 \begin_inset LatexCommand \index{-mds390}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6816
6817 \end_inset
6818
6819  processor.
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mds400
6827 \begin_inset LatexCommand \index{-mds400}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6835
6836 \end_inset
6837
6838  processor.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -mhc08
6846 \begin_inset LatexCommand \index{-mhc08}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6854
6855 \end_inset
6856
6857  family of processors.
6858 \end_layout
6859
6860 \begin_layout List
6861 \labelwidthstring 00.00.0000
6862
6863 \series bold
6864 -mz80
6865 \begin_inset LatexCommand \index{-mz80}
6866
6867 \end_inset
6868
6869
6870 \series default
6871  Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6873
6874 \end_inset
6875
6876  family of processors.
6877 \end_layout
6878
6879 \begin_layout List
6880 \labelwidthstring 00.00.0000
6881
6882 \series bold
6883 -mgbz80
6884 \begin_inset LatexCommand \index{-mgbz80}
6885
6886 \end_inset
6887
6888
6889 \series default
6890  Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6892
6893 \end_inset
6894
6895  processor (Not actively maintained).
6896 \end_layout
6897
6898 \begin_layout List
6899 \labelwidthstring 00.00.0000
6900
6901 \series bold
6902 -mavr
6903 \begin_inset LatexCommand \index{-mavr}
6904
6905 \end_inset
6906
6907
6908 \series default
6909  Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6911
6912 \end_inset
6913
6914  processor (Not maintained, not complete).
6915  AVR users should probably have a look at winavr 
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6917
6918 \end_inset
6919
6920  or 
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6922
6923 \end_inset
6924
6925 , which is based on AVR-port of the gcc compiler.
6926 \end_layout
6927
6928 \begin_layout Standard
6929 \begin_inset Note Note
6930 status collapsed
6931
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934  Open source is also about avoiding unnecessary work .
6935  But I didn't find the 'official' link.
6936 \end_layout
6937
6938 \end_inset
6939
6940
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -mpic14
6948 \begin_inset LatexCommand \index{-mpic14}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6956
6957 \end_inset
6958
6959 -bit processors (p16f84 and variants.
6960  In development, not complete).
6961 \end_layout
6962
6963 \begin_layout Standard
6964 \begin_inset Note Note
6965 status collapsed
6966
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6969 \end_layout
6970
6971 \end_inset
6972
6973
6974 \end_layout
6975
6976 \begin_layout List
6977 \labelwidthstring 00.00.0000
6978
6979 \series bold
6980 -mpic16
6981 \begin_inset LatexCommand \index{-mpic16}
6982
6983 \end_inset
6984
6985
6986 \series default
6987  Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6989
6990 \end_inset
6991
6992 -bit processors (p18f452 and variants.
6993  In development, not complete).
6994 \end_layout
6995
6996 \begin_layout List
6997 \labelwidthstring 00.00.0000
6998
6999 \series bold
7000 -mtlcs900h
7001 \series default
7002  Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7004
7005 \end_inset
7006
7007  processor (Not maintained, not complete).
7008 \end_layout
7009
7010 \begin_layout List
7011 \labelwidthstring 00.00.0000
7012
7013 \series bold
7014 -mxa51
7015 \begin_inset LatexCommand \index{-mxa51}
7016
7017 \end_inset
7018
7019
7020 \series default
7021  Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7023
7024 \end_inset
7025
7026  processor (Not maintained, not complete).
7027 \end_layout
7028
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7031 \end_inset
7032
7033
7034 \end_layout
7035
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7039
7040 \end_inset
7041
7042
7043 \begin_inset LatexCommand \index{Preprocessor options}
7044
7045 \end_inset
7046
7047
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7049
7050 \end_inset
7051
7052
7053 \end_layout
7054
7055 \begin_layout List
7056 \labelwidthstring 00.00.0000
7057
7058 \series bold
7059 -I<path>
7060 \begin_inset LatexCommand \index{-I<path>}
7061
7062 \end_inset
7063
7064
7065 \series default
7066  The additional location where the preprocessor will look for <..h> or 
7067 \begin_inset Quotes eld
7068 \end_inset
7069
7070 ..h
7071 \begin_inset Quotes erd
7072 \end_inset
7073
7074  files.
7075 \end_layout
7076
7077 \begin_layout List
7078 \labelwidthstring 00.00.0000
7079
7080 \series bold
7081 -D<macro[=value]>
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7083
7084 \end_inset
7085
7086
7087 \series default
7088  Command line definition of macros.
7089  Passed to the preprocessor.
7090 \end_layout
7091
7092 \begin_layout List
7093 \labelwidthstring 00.00.0000
7094
7095 \series bold
7096 -M
7097 \begin_inset LatexCommand \index{-M}
7098
7099 \end_inset
7100
7101
7102 \series default
7103  Tell the preprocessor to output a rule suitable for make describing the
7104  dependencies of each object file.
7105  For each source file, the preprocessor outputs one make-rule whose target
7106  is the object file name for that source file and whose dependencies are
7107  all the files `#include'd in it.
7108  This rule may be a single line or may be continued with `
7109 \backslash
7110 '-newline if it is long.
7111  The list of rules is printed on standard output instead of the preprocessed
7112  C program.
7113  `-M' implies `-E
7114 \begin_inset LatexCommand \index{-E}
7115
7116 \end_inset
7117
7118 '.
7119 \end_layout
7120
7121 \begin_layout List
7122 \labelwidthstring 00.00.0000
7123
7124 \series bold
7125 -C
7126 \begin_inset LatexCommand \index{-C}
7127
7128 \end_inset
7129
7130
7131 \series default
7132  Tell the preprocessor not to discard comments.
7133  Used with the `-E' option.
7134 \end_layout
7135
7136 \begin_layout List
7137 \labelwidthstring 00.00.0000
7138
7139 \series bold
7140 -MM
7141 \begin_inset LatexCommand \index{-MM}
7142
7143 \end_inset
7144
7145
7146 \size large
7147 \bar under
7148  
7149 \series default
7150 \size default
7151 \bar default
7152 Like `-M' but the output mentions only the user header files included with
7153  `#include 
7154 \begin_inset Quotes eld
7155 \end_inset
7156
7157 file"'.
7158  System header files included with `#include <file>' are omitted.
7159 \end_layout
7160
7161 \begin_layout List
7162 \labelwidthstring 00.00.0000
7163
7164 \series bold
7165 -Aquestion(answer)
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7167
7168 \end_inset
7169
7170
7171 \series default
7172  Assert the answer answer for question, in case it is tested with a preprocessor
7173  conditional such as `#if #question(answer)'.
7174  `-A-' disables the standard assertions that normally describe the target
7175  machine.
7176 \end_layout
7177
7178 \begin_layout List
7179 \labelwidthstring 00.00.0000
7180
7181 \series bold
7182 -Umacro
7183 \begin_inset LatexCommand \index{-Umacro}
7184
7185 \end_inset
7186
7187
7188 \series default
7189  Undefine macro macro.
7190  `-U' options are evaluated after all `-D' options, but before any `-include'
7191  and `-imacros' options.
7192 \end_layout
7193
7194 \begin_layout List
7195 \labelwidthstring 00.00.0000
7196
7197 \series bold
7198 -dM
7199 \begin_inset LatexCommand \index{-dM}
7200
7201 \end_inset
7202
7203
7204 \series default
7205  Tell the preprocessor to output only a list of the macro definitions that
7206  are in effect at the end of preprocessing.
7207  Used with the `-E' option.
7208 \end_layout
7209
7210 \begin_layout List
7211 \labelwidthstring 00.00.0000
7212
7213 \series bold
7214 -dD
7215 \begin_inset LatexCommand \index{-dD}
7216
7217 \end_inset
7218
7219
7220 \series default
7221  Tell the preprocessor to pass all macro definitions into the output, in
7222  their proper sequence in the rest of the output.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -dN
7230 \begin_inset LatexCommand \index{-dN}
7231
7232 \end_inset
7233
7234
7235 \size large
7236 \bar under
7237  
7238 \series default
7239 \size default
7240 \bar default
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242  Only `#define name' is included in the output.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7251
7252 \end_inset
7253
7254
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7256
7257 \end_inset
7258
7259
7260 \size large
7261 \bar under
7262
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7264
7265 \end_inset
7266
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272  and the macro LO_B(3) gets expanded.
7273  See also #pragma pedantic_parse_number 
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7275
7276 \end_inset
7277
7278  in section
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7280
7281 \end_inset
7282
7283  
7284 \emph on
7285 Note: this functionality is not in conformance with C99 standard!
7286 \end_layout
7287
7288 \begin_layout List
7289 \labelwidthstring 00.00.0000
7290
7291 \series bold
7292 -Wp\InsetSpace ~
7293 preprocessorOption[,preprocessorOption]
7294 \series default
7295
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7297
7298 \end_inset
7299
7300 ...
7301  Pass the preprocessorOption to the preprocessor 
7302 \family typewriter
7303 sdcpp
7304 \family default
7305
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7307
7308 \end_inset
7309
7310 .
7311  SDCC uses an adapted version of the preprocessor 
7312 \emph on
7313 cpp
7314 \emph default
7315  of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7317
7318 \end_inset
7319
7320  (
7321 \emph on
7322 gcc
7323 \emph default
7324  
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7326
7327 \end_inset
7328
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7330 4.1.1\InsetSpace ~
7331 CPP\InsetSpace ~
7332 Manual
7333  at 
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7335
7336 \end_inset
7337
7338 .
7339 \end_layout
7340
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7343 \end_inset
7344
7345
7346 \end_layout
7347
7348 \begin_layout Subsection
7349 Linker Options
7350 \begin_inset LatexCommand \index{Options linker}
7351
7352 \end_inset
7353
7354
7355 \begin_inset LatexCommand \index{Linker options}
7356
7357 \end_inset
7358
7359
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -L\InsetSpace ~
7367 -
7368 \series default
7369
7370 \begin_inset ERT
7371 status collapsed
7372
7373 \begin_layout Standard
7374
7375
7376 \backslash
7377 /
7378 \end_layout
7379
7380 \end_inset
7381
7382
7383 \series bold
7384 -lib-path
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7386
7387 \end_inset
7388
7389
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7391
7392 \end_inset
7393
7394
7395 \series default
7396 \InsetSpace ~
7397 <absolute path to additional libraries> This option is passed to the linkage
7398  editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7400
7401 \end_inset
7402
7403  search path.
7404  The path name must be absolute.
7405  Additional library files may be specified in the command line.
7406  See section Compiling programs for more details.
7407 \end_layout
7408
7409 \begin_layout List
7410 \labelwidthstring 00.00.0000
7411
7412 \series bold
7413 -
7414 \begin_inset ERT
7415 status collapsed
7416
7417 \begin_layout Standard
7418
7419
7420 \backslash
7421 /
7422 \end_layout
7423
7424 \end_inset
7425
7426 -xram-loc
7427 \series default
7428
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7430
7431 \end_inset
7432
7433 \InsetSpace ~
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7436
7437 \end_inset
7438
7439 , default value is 0.
7440  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7441 \begin_inset ERT
7442 status collapsed
7443
7444 \begin_layout Standard
7445
7446
7447 \backslash
7448 /
7449 \end_layout
7450
7451 \end_inset
7452
7453 -xram-loc 0x8000 or -
7454 \begin_inset ERT
7455 status collapsed
7456
7457 \begin_layout Standard
7458
7459
7460 \backslash
7461 /
7462 \end_layout
7463
7464 \end_inset
7465
7466 -xram-loc 32768.
7467 \end_layout
7468
7469 \begin_layout List
7470 \labelwidthstring 00.00.0000
7471
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -code-loc
7487 \series default
7488
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7490
7491 \end_inset
7492
7493 \InsetSpace ~
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7496
7497 \end_inset
7498
7499  segment, default value 0.
7500  Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7502
7503 \end_inset
7504
7505  is also relocated to the given address.
7506  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7507 \begin_inset ERT
7508 status collapsed
7509
7510 \begin_layout Standard
7511
7512
7513 \backslash
7514 /
7515 \end_layout
7516
7517 \end_inset
7518
7519 -code-loc 0x8000 or -
7520 \begin_inset ERT
7521 status collapsed
7522
7523 \begin_layout Standard
7524
7525
7526 \backslash
7527 /
7528 \end_layout
7529
7530 \end_inset
7531
7532 -code-loc 32768.
7533 \end_layout
7534
7535 \begin_layout List
7536 \labelwidthstring 00.00.0000
7537
7538 \series bold
7539 -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc
7553 \series default
7554
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7556
7557 \end_inset
7558
7559 \InsetSpace ~
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7562
7563 \end_inset
7564
7565  is placed after the data segment.
7566  Using this option the stack can be placed anywhere in the internal memory
7567  space of the 8051.
7568  The value entered can be in Hexadecimal or Decimal format, e.g.
7569  -
7570 \begin_inset ERT
7571 status collapsed
7572
7573 \begin_layout Standard
7574
7575
7576 \backslash
7577 /
7578 \end_layout
7579
7580 \end_inset
7581
7582 -stack-loc 0x20 or -
7583 \begin_inset ERT
7584 status collapsed
7585
7586 \begin_layout Standard
7587
7588
7589 \backslash
7590 /
7591 \end_layout
7592
7593 \end_inset
7594
7595 -stack-loc 32.
7596  Since the sp register is incremented before a push or call, the initial
7597  sp will be set to one byte prior the provided value.
7598  The provided value should not overlap any other memory areas such as used
7599  register banks or the data segment and with enough space for the current
7600  application.
7601  The 
7602 \series bold
7603 -
7604 \begin_inset ERT
7605 status collapsed
7606
7607 \begin_layout Standard
7608
7609
7610 \backslash
7611 /
7612 \end_layout
7613
7614 \end_inset
7615
7616 -pack-iram
7617 \series default
7618 \InsetSpace ~
7619
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7621
7622 \end_inset
7623
7624  option (which is now a default setting) will override this setting, so
7625  you should also specify the 
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 -no-pack-iram
7641 \series default
7642 \InsetSpace ~
7643
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7645
7646 \end_inset
7647
7648  option if you need to manually place the stack.
7649 \end_layout
7650
7651 \begin_layout List
7652 \labelwidthstring 00.00.0000
7653
7654 \series bold
7655 -
7656 \begin_inset ERT
7657 status collapsed
7658
7659 \begin_layout Standard
7660
7661
7662 \backslash
7663 /
7664 \end_layout
7665
7666 \end_inset
7667
7668 -xstack-loc
7669 \series default
7670
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7672
7673 \end_inset
7674
7675 \InsetSpace ~
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7678
7679 \end_inset
7680
7681  is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7683
7684 \end_inset
7685
7686  segment.
7687  Using this option the xstack can be placed anywhere in the external memory
7688  space of the 8051.
7689  The value entered can be in Hexadecimal or Decimal format, e.g.
7690  -
7691 \begin_inset ERT
7692 status collapsed
7693
7694 \begin_layout Standard
7695
7696
7697 \backslash
7698 /
7699 \end_layout
7700
7701 \end_inset
7702
7703 -xstack-loc 0x8000 or -
7704 \begin_inset ERT
7705 status collapsed
7706
7707 \begin_layout Standard
7708
7709
7710 \backslash
7711 /
7712 \end_layout
7713
7714 \end_inset
7715
7716 -stack-loc 32768.
7717  The provided value should not overlap any other memory areas such as the
7718  pdata or xdata segment and with enough space for the current application.
7719 \end_layout
7720
7721 \begin_layout List
7722 \labelwidthstring 00.00.0000
7723
7724 \series bold
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
7739 \series default
7740
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7742
7743 \end_inset
7744
7745 \InsetSpace ~
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7748
7749 \end_inset
7750
7751  segment.
7752  The value entered can be in Hexadecimal or Decimal format, eg.
7753  -
7754 \begin_inset ERT
7755 status collapsed
7756
7757 \begin_layout Standard
7758
7759
7760 \backslash
7761 /
7762 \end_layout
7763
7764 \end_inset
7765
7766 -data-loc 0x20 or -
7767 \begin_inset ERT
7768 status collapsed
7769
7770 \begin_layout Standard
7771
7772
7773 \backslash
7774 /
7775 \end_layout
7776
7777 \end_inset
7778
7779 -data-loc 32.
7780  (By default, the start location of the internal ram data segment  is set
7781  as low as possible in memory, taking into account the used register banks
7782  and the bit segment at address 0x20.
7783  For example if register banks 0 and 1 are used without bit variables, the
7784  data segment will be set, if -
7785 \begin_inset ERT
7786 status collapsed
7787
7788 \begin_layout Standard
7789
7790
7791 \backslash
7792 /
7793 \end_layout
7794
7795 \end_inset
7796
7797 -data-loc is not used, to location 0x10.)
7798 \end_layout
7799
7800 \begin_layout List
7801 \labelwidthstring 00.00.0000
7802
7803 \series bold
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
7818 \series default
7819
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7821
7822 \end_inset
7823
7824 \InsetSpace ~
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7827
7828 \end_inset
7829
7830  of the 8051, default value is 0x80.
7831  The value entered can be in Hexadecimal or Decimal format, eg.
7832  -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -idata-loc 0x88 or -
7846 \begin_inset ERT
7847 status collapsed
7848
7849 \begin_layout Standard
7850
7851
7852 \backslash
7853 /
7854 \end_layout
7855
7856 \end_inset
7857
7858 -idata-loc 136.
7859 \end_layout
7860
7861 \begin_layout List
7862 \labelwidthstring 00.00.0000
7863
7864 \series bold
7865 -
7866 \begin_inset ERT
7867 status collapsed
7868
7869 \begin_layout Standard
7870
7871
7872 \backslash
7873 /
7874 \end_layout
7875
7876 \end_inset
7877
7878 -bit-loc
7879 \series default
7880 \InsetSpace ~
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7883
7884 \end_inset
7885
7886  addressable internal ram of the 8051.
7887  This is 
7888 \emph on
7889 not
7890 \emph default
7891  implemented yet.
7892  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7893 -bBSEG=<Value>.
7894 \end_layout
7895
7896 \begin_layout List
7897 \labelwidthstring 00.00.0000
7898
7899 \series bold
7900 -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -out-fmt-ihx
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7915
7916 \end_inset
7917
7918
7919 \bar under
7920  
7921 \series default
7922 \bar default
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7925
7926 \end_inset
7927
7928  This is the default option.
7929  The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7931
7932 \end_inset
7933
7934 .
7935 \end_layout
7936
7937 \begin_layout List
7938 \labelwidthstring 00.00.0000
7939
7940 \series bold
7941 -
7942 \begin_inset ERT
7943 status collapsed
7944
7945 \begin_layout Standard
7946
7947
7948 \backslash
7949 /
7950 \end_layout
7951
7952 \end_inset
7953
7954 -out-fmt-s19
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7956
7957 \end_inset
7958
7959
7960 \bar under
7961  
7962 \series default
7963 \bar default
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7966
7967 \end_inset
7968
7969 .
7970  The format itself is documented in the documentation of srecord.
7971 \end_layout
7972
7973 \begin_layout List
7974 \labelwidthstring 00.00.0000
7975
7976 \series bold
7977 -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -out-fmt-elf
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7992
7993 \end_inset
7994
7995
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7997
7998 \end_inset
7999
8000
8001 \bar under
8002  
8003 \series default
8004 \bar default
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8007
8008 \end_inset
8009
8010 .
8011  (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8013
8014 \end_inset
8015
8016  processors)
8017 \end_layout
8018
8019 \begin_layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -Wl\InsetSpace ~
8024 linkOption[,linkOption]
8025 \series default
8026
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8028
8029 \end_inset
8030
8031 \begin_inset LatexCommand \label{lyx:-Wl option}
8032
8033 \end_inset
8034
8035 ...
8036  Pass the linkOption to the linker.
8037  If a bootloader is used an option like 
8038 \begin_inset Quotes sld
8039 \end_inset
8040
8041 -Wl\InsetSpace ~
8042 -bCSEG=0x1000
8043 \begin_inset Quotes srd
8044 \end_inset
8045
8046  would be typical to set the start of the code segment.
8047  Either use the double quotes around this option or use no space (e.g.
8048  -Wl-bCSEG=0x1000).
8049  See also #pragma constseg and #pragma codeseg in section 
8050 \begin_inset LatexCommand \ref{sec:Pragmas}
8051
8052 \end_inset
8053
8054  .
8055  File sdcc/as/doc/asxhtm.html has more on linker options.
8056 \end_layout
8057
8058 \begin_layout Standard
8059 \begin_inset VSpace bigskip
8060 \end_inset
8061
8062
8063 \end_layout
8064
8065 \begin_layout Subsection
8066 MCS51 Options
8067 \begin_inset LatexCommand \index{Options MCS51}
8068
8069 \end_inset
8070
8071
8072 \begin_inset LatexCommand \index{MCS51 options}
8073
8074 \end_inset
8075
8076
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-small
8097 \begin_inset LatexCommand \index{-\/-model-small}
8098
8099 \end_inset
8100
8101
8102 \series default
8103 \size large
8104 \emph on
8105  
8106 \size default
8107 \emph default
8108 Generate code for Small Model programs, see section Memory Models for more
8109  details.
8110  This is the default model.
8111 \end_layout
8112
8113 \begin_layout List
8114 \labelwidthstring 00.00.0000
8115
8116 \series bold
8117 -
8118 \begin_inset ERT
8119 status collapsed
8120
8121 \begin_layout Standard
8122
8123
8124 \backslash
8125 /
8126 \end_layout
8127
8128 \end_inset
8129
8130 -model-medium
8131 \begin_inset LatexCommand \index{-\/-model-medium}
8132
8133 \end_inset
8134
8135
8136 \series default
8137  Generate code for Medium model programs, see section Memory Models for
8138  more details.
8139  If this option is used all source files in the project have to be compiled
8140  with this option.
8141  It must also be used when invoking the linker.
8142 \end_layout
8143
8144 \begin_layout List
8145 \labelwidthstring 00.00.0000
8146
8147 \series bold
8148 -
8149 \begin_inset ERT
8150 status collapsed
8151
8152 \begin_layout Standard
8153
8154
8155 \backslash
8156 /
8157 \end_layout
8158
8159 \end_inset
8160
8161 -model-large
8162 \begin_inset LatexCommand \index{-\/-model-large}
8163
8164 \end_inset
8165
8166
8167 \series default
8168  Generate code for Large model programs, see section Memory Models for more
8169  details.
8170  If this option is used all source files in the project have to be compiled
8171  with this option.
8172  It must also be used when invoking the linker.
8173 \end_layout
8174
8175 \begin_layout List
8176 \labelwidthstring 00.00.0000
8177
8178 \series bold
8179 -
8180 \begin_inset ERT
8181 status collapsed
8182
8183 \begin_layout Standard
8184
8185
8186 \backslash
8187 /
8188 \end_layout
8189
8190 \end_inset
8191
8192 -xstack
8193 \begin_inset LatexCommand \index{-\/-xstack}
8194
8195 \end_inset
8196
8197
8198 \series default
8199  Uses a pseudo stack in the pdata
8200 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8201
8202 \end_inset
8203
8204  area (usually the first 256 bytes in the external ram) for allocating variables
8205  and passing parameters.
8206  See section 
8207 \begin_inset LatexCommand \ref{sub:External-Stack}
8208
8209 \end_inset
8210
8211 \InsetSpace ~
8212  External Stack for more details.
8213 \end_layout
8214
8215 \begin_layout List
8216 \labelwidthstring 00.00.0000
8217
8218 \series bold
8219 -
8220 \begin_inset ERT
8221 status collapsed
8222
8223 \begin_layout Standard
8224
8225
8226 \backslash
8227 /
8228 \end_layout
8229
8230 \end_inset
8231
8232 -iram-size
8233 \series default
8234 \InsetSpace ~
8235 <Value>
8236 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8237
8238 \end_inset
8239
8240  Causes the linker to check if the internal ram usage is within limits of
8241  the given value.
8242 \end_layout
8243
8244 \begin_layout List
8245 \labelwidthstring 00.00.0000
8246
8247 \series bold
8248 -
8249 \begin_inset ERT
8250 status collapsed
8251
8252 \begin_layout Standard
8253
8254
8255 \backslash
8256 /
8257 \end_layout
8258
8259 \end_inset
8260
8261 -xram-size
8262 \series default
8263 \InsetSpace ~
8264 <Value>
8265 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8266
8267 \end_inset
8268
8269  Causes the linker to check if the external ram usage is within limits of
8270  the given value.
8271 \end_layout
8272
8273 \begin_layout List
8274 \labelwidthstring 00.00.0000
8275
8276 \series bold
8277 -
8278 \begin_inset ERT
8279 status collapsed
8280
8281 \begin_layout Standard
8282
8283
8284 \backslash
8285 /
8286 \end_layout
8287
8288 \end_inset
8289
8290 -code-size
8291 \series default
8292 \InsetSpace ~
8293 <Value>
8294 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8295
8296 \end_inset
8297
8298  Causes the linker to check if the code memory usage is within limits of
8299  the given value.
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -stack-size
8320 \series default
8321 \InsetSpace ~
8322 <Value>
8323 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8324
8325 \end_inset
8326
8327  Causes the linker to check if there is at minimum <Value> bytes for stack.
8328 \end_layout
8329
8330 \begin_layout List
8331 \labelwidthstring 00.00.0000
8332
8333 \series bold
8334 -
8335 \begin_inset ERT
8336 status collapsed
8337
8338 \begin_layout Standard
8339
8340
8341 \backslash
8342 /
8343 \end_layout
8344
8345 \end_inset
8346
8347 -pack-iram
8348 \series default
8349 \InsetSpace ~
8350
8351 \begin_inset LatexCommand \index{-\/-pack-iram}
8352
8353 \end_inset
8354
8355  Causes the linker to use unused register banks for data variables and pack
8356  data, idata and stack together.
8357  This is the default now.
8358 \end_layout
8359
8360 \begin_layout List
8361 \labelwidthstring 00.00.0000
8362
8363 \series bold
8364 -
8365 \begin_inset ERT
8366 status collapsed
8367
8368 \begin_layout Standard
8369
8370
8371 \backslash
8372 /
8373 \end_layout
8374
8375 \end_inset
8376
8377 -no-pack-iram
8378 \series default
8379 \InsetSpace ~
8380
8381 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8382
8383 \end_inset
8384
8385  Causes the linker to use old style for allocating memory areas.
8386 \end_layout
8387
8388 \begin_layout List
8389 \labelwidthstring 00.00.0000
8390
8391 \series bold
8392 -
8393 \begin_inset ERT
8394 status collapsed
8395
8396 \begin_layout Standard
8397
8398
8399 \backslash
8400 /
8401 \end_layout
8402
8403 \end_inset
8404
8405 -acall-ajmp
8406 \series default
8407 \InsetSpace ~
8408
8409 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8410
8411 \end_inset
8412
8413  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8414  acall/ajmp.
8415  Only use this option if your code is in the same 2k block of memory.
8416  You may need to use this option for some 8051 derivatives which lack the
8417  lcall/ljmp instructions..
8418 \end_layout
8419
8420 \begin_layout Standard
8421 \begin_inset VSpace bigskip
8422 \end_inset
8423
8424
8425 \end_layout
8426
8427 \begin_layout Subsection
8428 DS390 / DS400 Options
8429 \begin_inset LatexCommand \index{Options DS390}
8430
8431 \end_inset
8432
8433
8434 \begin_inset LatexCommand \index{DS390}
8435
8436 \end_inset
8437
8438
8439 \end_layout
8440
8441 \begin_layout List
8442 \labelwidthstring 00.00.0000
8443
8444 \series bold
8445 -
8446 \begin_inset ERT
8447 status collapsed
8448
8449 \begin_layout Standard
8450
8451
8452 \backslash
8453 /
8454 \end_layout
8455
8456 \end_inset
8457
8458 -model-flat24
8459 \series default
8460
8461 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8462
8463 \end_inset
8464
8465
8466 \size large
8467 \emph on
8468  
8469 \size default
8470 \emph default
8471 Generate 24-bit flat mode code.
8472  This is the one and only that the ds390 code generator supports right now
8473  and is default when using 
8474 \emph on
8475 -mds390
8476 \emph default
8477 .
8478  See section Memory Models for more details.
8479 \end_layout
8480
8481 \begin_layout List
8482 \labelwidthstring 00.00.0000
8483
8484 \series bold
8485 -
8486 \begin_inset ERT
8487 status collapsed
8488
8489 \begin_layout Standard
8490
8491
8492 \backslash
8493 /
8494 \end_layout
8495
8496 \end_inset
8497
8498 -protect-sp-update
8499 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8500
8501 \end_inset
8502
8503
8504 \series default
8505  disable interrupts during ESP:SP updates.
8506 \end_layout
8507
8508 \begin_layout List
8509 \labelwidthstring 00.00.0000
8510
8511 \series bold
8512 -
8513 \begin_inset ERT
8514 status collapsed
8515
8516 \begin_layout Standard
8517
8518
8519 \backslash
8520 /
8521 \end_layout
8522
8523 \end_inset
8524
8525 -stack-10bit
8526 \series default
8527
8528 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8529
8530 \end_inset
8531
8532  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8533  This is the one and only that the ds390 code generator supports right now
8534  and is default when using 
8535 \emph on
8536 -mds390
8537 \emph default
8538 .
8539  In this mode, the stack is located in the lower 1K of the internal RAM,
8540  which is mapped to 0x400000.
8541  Note that the support is incomplete, since it still uses a single byte
8542  as the stack pointer.
8543  This means that only the lower 256 bytes of the potential 1K stack space
8544  will actually be used.
8545  However, this does allow you to reclaim the precious 256 bytes of low RAM
8546  for use for the DATA and IDATA segments.
8547  The compiler will not generate any code to put the processor into 10 bit
8548  stack mode.
8549  It is important to ensure that the processor is in this mode before calling
8550  any re-entrant functions compiled with this option.
8551  In principle, this should work with the 
8552 \emph on
8553 -
8554 \begin_inset ERT
8555 status collapsed
8556
8557 \begin_layout Standard
8558
8559
8560 \backslash
8561 /
8562 \end_layout
8563
8564 \end_inset
8565
8566 -stack-auto
8567 \begin_inset LatexCommand \index{-\/-stack-auto}
8568
8569 \end_inset
8570
8571
8572 \emph default
8573  option, but that has not been tested.
8574  It is incompatible with the 
8575 \emph on
8576 -
8577 \begin_inset ERT
8578 status collapsed
8579
8580 \begin_layout Standard
8581
8582
8583 \backslash
8584 /
8585 \end_layout
8586
8587 \end_inset
8588
8589 -xstack
8590 \begin_inset LatexCommand \index{-\/-xstack}
8591
8592 \end_inset
8593
8594
8595 \emph default
8596  option.
8597  It also only makes sense if the processor is in 24 bit contiguous addressing
8598  mode (see the 
8599 \emph on
8600 -
8601 \begin_inset ERT
8602 status collapsed
8603
8604 \begin_layout Standard
8605
8606
8607 \backslash
8608 /
8609 \end_layout
8610
8611 \end_inset
8612
8613 -model-flat24 option
8614 \emph default
8615 ).
8616 \series bold
8617
8618 \begin_inset Note Note
8619 status collapsed
8620
8621 \begin_layout List
8622 \labelwidthstring 00.00.0000
8623
8624 \series bold
8625 -
8626 \begin_inset ERT
8627 status open
8628
8629 \begin_layout Standard
8630
8631
8632 \backslash
8633 /
8634 \end_layout
8635
8636 \end_inset
8637
8638 -stack-8-bit - switches off the 10-bit mode
8639 \end_layout
8640
8641 \end_inset
8642
8643
8644 \end_layout
8645
8646 \begin_layout List
8647 \labelwidthstring 00.00.0000
8648
8649 \series bold
8650 -
8651 \begin_inset ERT
8652 status collapsed
8653
8654 \begin_layout Standard
8655
8656
8657 \backslash
8658 /
8659 \end_layout
8660
8661 \end_inset
8662
8663 -stack-probe
8664 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8665
8666 \end_inset
8667
8668
8669 \series default
8670  insert call to function __stack_probe at each function prologue.
8671 \end_layout
8672
8673 \begin_layout List
8674 \labelwidthstring 00.00.0000
8675
8676 \series bold
8677 -
8678 \begin_inset ERT
8679 status open
8680
8681 \begin_layout Standard
8682
8683
8684 \backslash
8685 /
8686 \end_layout
8687
8688 \end_inset
8689
8690 -tini-libid
8691 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8692
8693 \end_inset
8694
8695
8696 \series default
8697  <nnnn> LibraryID used in -mTININative.
8698  
8699 \end_layout
8700
8701 \begin_layout List
8702 \labelwidthstring 00.00.0000
8703
8704 \series bold
8705 -
8706 \begin_inset ERT
8707 status collapsed
8708
8709 \begin_layout Standard
8710
8711
8712 \backslash
8713 /
8714 \end_layout
8715
8716 \end_inset
8717
8718 -use-accelerator
8719 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8720
8721 \end_inset
8722
8723
8724 \series default
8725  generate code for DS390 Arithmetic Accelerator.
8726  
8727 \end_layout
8728
8729 \begin_layout Standard
8730 \begin_inset VSpace bigskip
8731 \end_inset
8732
8733
8734 \end_layout
8735
8736 \begin_layout Subsection
8737 Z80 Options
8738 \begin_inset LatexCommand \index{Options Z80}
8739
8740 \end_inset
8741
8742
8743 \begin_inset LatexCommand \index{Z80}
8744
8745 \end_inset
8746
8747
8748 \end_layout
8749
8750 \begin_layout List
8751 \labelwidthstring 00.00.0000
8752
8753 \series bold
8754 -
8755 \begin_inset ERT
8756 status collapsed
8757
8758 \begin_layout Standard
8759
8760
8761 \backslash
8762 /
8763 \end_layout
8764
8765 \end_inset
8766
8767 -callee-saves-bc
8768 \series default
8769
8770 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8771
8772 \end_inset
8773
8774
8775 \size large
8776 \emph on
8777  
8778 \size default
8779 \emph default
8780 Force a called function to always save BC.
8781 \end_layout
8782
8783 \begin_layout List
8784 \labelwidthstring 00.00.0000
8785
8786 \series bold
8787 -
8788 \begin_inset ERT
8789 status collapsed
8790
8791 \begin_layout Standard
8792
8793
8794 \backslash
8795 /
8796 \end_layout
8797
8798 \end_inset
8799
8800 -no-std-crt0
8801 \series default
8802
8803 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8804
8805 \end_inset
8806
8807  When linking, skip the standard crt0.o object file.
8808  You must provide your own crt0.o for your system when linking.
8809 \end_layout
8810
8811 \begin_layout List
8812 \labelwidthstring 00.00.0000
8813
8814 \series bold
8815 -
8816 \begin_inset ERT
8817 status collapsed
8818
8819 \begin_layout Standard
8820
8821
8822 \backslash
8823 /
8824 \end_layout
8825
8826 \end_inset
8827
8828 -portmode=
8829 \series default
8830 <Value>
8831 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8832
8833 \end_inset
8834
8835  Determinate PORT I/O mode (<Value> is z80 or z180).
8836 \end_layout
8837
8838 \begin_layout List
8839 \labelwidthstring 00.00.0000
8840
8841 \series bold
8842 -
8843 \begin_inset ERT
8844 status collapsed
8845
8846 \begin_layout Standard
8847
8848
8849 \backslash
8850 /
8851 \end_layout
8852
8853 \end_inset
8854
8855 -asm=
8856 \series default
8857 <Value>
8858 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8859
8860 \end_inset
8861
8862  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8863 \end_layout
8864
8865 \begin_layout List
8866 \labelwidthstring 00.00.0000
8867
8868 \series bold
8869 -
8870 \begin_inset ERT
8871 status collapsed
8872
8873 \begin_layout Standard
8874
8875
8876 \backslash
8877 /
8878 \end_layout
8879
8880 \end_inset
8881
8882 -codeseg
8883 \series default
8884 \InsetSpace ~
8885 <Value>
8886 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8887
8888 \end_inset
8889
8890  Use <Value> for the code segment name.
8891 \end_layout
8892
8893 \begin_layout List
8894 \labelwidthstring 00.00.0000
8895
8896 \series bold
8897 -
8898 \begin_inset ERT
8899 status collapsed
8900
8901 \begin_layout Standard
8902
8903
8904 \backslash
8905 /
8906 \end_layout
8907
8908 \end_inset
8909
8910 -constseg
8911 \series default
8912 \InsetSpace ~
8913 <Value>
8914 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8915
8916 \end_inset
8917
8918  Use <Value> for the const segment name.
8919 \end_layout
8920
8921 \begin_layout List
8922 \labelwidthstring 00.00.0000
8923 \begin_inset VSpace bigskip
8924 \end_inset
8925
8926
8927 \end_layout
8928
8929 \begin_layout Subsection
8930 GBZ80 Options
8931 \begin_inset LatexCommand \index{Options GBZ80}
8932
8933 \end_inset
8934
8935
8936 \begin_inset LatexCommand \index{GBZ80}
8937
8938 \end_inset
8939
8940
8941 \end_layout
8942
8943 \begin_layout List
8944 \labelwidthstring 00.00.0000
8945
8946 \series bold
8947 -
8948 \begin_inset ERT
8949 status collapsed
8950
8951 \begin_layout Standard
8952
8953
8954 \backslash
8955 /
8956 \end_layout
8957
8958 \end_inset
8959
8960 -callee-saves-bc
8961 \series default
8962
8963 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8964
8965 \end_inset
8966
8967
8968 \size large
8969 \emph on
8970  
8971 \size default
8972 \emph default
8973 Force a called function to always save BC.
8974 \end_layout
8975
8976 \begin_layout List
8977 \labelwidthstring 00.00.0000
8978
8979 \series bold
8980 -
8981 \begin_inset ERT
8982 status collapsed
8983
8984 \begin_layout Standard
8985
8986
8987 \backslash
8988 /
8989 \end_layout
8990
8991 \end_inset
8992
8993 -no-std-crt0
8994 \series default
8995
8996 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8997
8998 \end_inset
8999
9000  When linking, skip the standard crt0.o object file.
9001  You must provide your own crt0.o for your system when linking.
9002 \end_layout
9003
9004 \begin_layout List
9005 \labelwidthstring 00.00.0000
9006
9007 \series bold
9008 -bo
9009 \series default
9010 \InsetSpace ~
9011 <Num>
9012 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9013
9014 \end_inset
9015
9016  Use code bank <Num>.
9017 \end_layout
9018
9019 \begin_layout List
9020 \labelwidthstring 00.00.0000
9021
9022 \series bold
9023 -ba
9024 \series default
9025 \InsetSpace ~
9026 <Num>
9027 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9028
9029 \end_inset
9030
9031  Use data bank <Num>.
9032 \end_layout
9033
9034 \begin_layout List
9035 \labelwidthstring 00.00.0000
9036
9037 \series bold
9038 -
9039 \begin_inset ERT
9040 status collapsed
9041
9042 \begin_layout Standard
9043
9044
9045 \backslash
9046 /
9047 \end_layout
9048
9049 \end_inset
9050
9051 -codeseg
9052 \series default
9053 \InsetSpace ~
9054 <Value>
9055 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9056
9057 \end_inset
9058
9059  Use <Value> for the code segment name.
9060 \end_layout
9061
9062 \begin_layout List
9063 \labelwidthstring 00.00.0000
9064
9065 \series bold
9066 -
9067 \begin_inset ERT
9068 status collapsed
9069
9070 \begin_layout Standard
9071
9072
9073 \backslash
9074 /
9075 \end_layout
9076
9077 \end_inset
9078
9079 -constseg
9080 \series default
9081 \InsetSpace ~
9082 <Value>
9083 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9084
9085 \end_inset
9086
9087  Use <Value> for the const segment name.
9088 \end_layout
9089
9090 \begin_layout Standard
9091 \begin_inset VSpace bigskip
9092 \end_inset
9093
9094
9095 \end_layout
9096
9097 \begin_layout Subsection
9098 Optimization Options
9099 \begin_inset LatexCommand \index{Options optimization}
9100
9101 \end_inset
9102
9103
9104 \begin_inset LatexCommand \index{Optimization options}
9105
9106 \end_inset
9107
9108
9109 \end_layout
9110
9111 \begin_layout List
9112 \labelwidthstring 00.00.0000
9113
9114 \series bold
9115 -
9116 \begin_inset ERT
9117 status collapsed
9118
9119 \begin_layout Standard
9120
9121
9122 \backslash
9123 /
9124 \end_layout
9125
9126 \end_inset
9127
9128 -nogcse
9129 \begin_inset LatexCommand \index{-\/-nogcse}
9130
9131 \end_inset
9132
9133
9134 \series default
9135  Will not do global subexpression elimination, this option may be used when
9136  the compiler creates undesirably large stack/data spaces to store compiler
9137  temporaries (
9138 \emph on
9139 s
9140 \emph default
9141 pill 
9142 \emph on
9143 loc
9144 \emph default
9145 ations, sloc
9146 \begin_inset LatexCommand \index{sloc (spill location)}
9147
9148 \end_inset
9149
9150 ).
9151  A warning message will be generated when this happens and the compiler
9152  will indicate the number of extra bytes it allocated.
9153  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9154 nogcse
9155 \begin_inset LatexCommand \index{\#pragma nogcse}
9156
9157 \end_inset
9158
9159  can be used to turn off global subexpression elimination
9160 \begin_inset LatexCommand \index{Subexpression elimination}
9161
9162 \end_inset
9163
9164  for a given function only.
9165 \end_layout
9166
9167 \begin_layout List
9168 \labelwidthstring 00.00.0000
9169
9170 \series bold
9171 -
9172 \begin_inset ERT
9173 status collapsed
9174
9175 \begin_layout Standard
9176
9177
9178 \backslash
9179 /
9180 \end_layout
9181
9182 \end_inset
9183
9184 -noinvariant
9185 \begin_inset LatexCommand \index{-\/-noinvariant}
9186
9187 \end_inset
9188
9189
9190 \series default
9191  Will not do loop invariant optimizations, this may be turned off for reasons
9192  explained for the previous option.
9193  For more details of loop optimizations performed see Loop Invariants in
9194  section 
9195 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9196
9197 \end_inset
9198
9199 .
9200  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9201 noinvariant
9202 \begin_inset LatexCommand \index{\#pragma noinvariant}
9203
9204 \end_inset
9205
9206  can be used to turn off invariant optimizations for a given function only.
9207 \end_layout
9208
9209 \begin_layout List
9210 \labelwidthstring 00.00.0000
9211
9212 \series bold
9213 -
9214 \begin_inset ERT
9215 status collapsed
9216
9217 \begin_layout Standard
9218
9219
9220 \backslash
9221 /
9222 \end_layout
9223
9224 \end_inset
9225
9226 -noinduction
9227 \begin_inset LatexCommand \index{-\/-noinduction}
9228
9229 \end_inset
9230
9231
9232 \series default
9233  Will not do loop induction optimizations, see section strength reduction
9234  for more details.
9235  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9236 noinduction
9237 \begin_inset LatexCommand \index{\#pragma noinduction}
9238
9239 \end_inset
9240
9241  can be used to turn off induction optimizations for a given function only.
9242 \end_layout
9243
9244 \begin_layout List
9245 \labelwidthstring 00.00.0000
9246
9247 \series bold
9248 -
9249 \begin_inset ERT
9250 status collapsed
9251
9252 \begin_layout Standard
9253
9254
9255 \backslash
9256 /
9257 \end_layout
9258
9259 \end_inset
9260
9261 -nojtbound
9262 \begin_inset LatexCommand \index{-\/-nojtbound}
9263
9264 \end_inset
9265
9266
9267 \size large
9268 \bar under
9269  
9270 \series default
9271 \size default
9272 \bar default
9273  Will not generate boundary condition check when switch statements
9274 \begin_inset LatexCommand \index{switch statement}
9275
9276 \end_inset
9277
9278  are implemented using jump-tables.
9279  See section 
9280 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9281
9282 \end_inset
9283
9284 \InsetSpace ~
9285 Switch Statements for more details.
9286  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9287 nojtbound
9288 \begin_inset LatexCommand \index{\#pragma nojtbound}
9289
9290 \end_inset
9291
9292  can be used to turn off boundary checking for jump tables for a given function
9293  only.
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 -noloopreverse
9314 \begin_inset LatexCommand \index{-\/-noloopreverse}
9315
9316 \end_inset
9317
9318
9319 \series default
9320 \size large
9321  
9322 \size default
9323 Will not do loop reversal 
9324 \begin_inset LatexCommand \index{Loop reversing}
9325
9326 \end_inset
9327
9328 optimization.
9329 \end_layout
9330
9331 \begin_layout List
9332 \labelwidthstring 00.00.0000
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 -
9347 \series bold
9348 nolabelopt
9349 \series default
9350  
9351 \begin_inset LatexCommand \index{-\/-nolabelopt }
9352
9353 \end_inset
9354
9355 Will not optimize labels (makes the dumpfiles more readable).
9356 \end_layout
9357
9358 \begin_layout List
9359 \labelwidthstring 00.00.0000
9360
9361 \series bold
9362 -
9363 \begin_inset ERT
9364 status collapsed
9365
9366 \begin_layout Standard
9367
9368
9369 \backslash
9370 /
9371 \end_layout
9372
9373 \end_inset
9374
9375 -no-xinit-opt
9376 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9377
9378 \end_inset
9379
9380
9381 \series default
9382  Will not memcpy initialized data from code space into xdata space.
9383  This saves a few bytes in code space if you don't have initialized data
9384 \begin_inset LatexCommand \index{Variable initialization}
9385
9386 \end_inset
9387
9388 .
9389 \end_layout
9390
9391 \begin_layout List
9392 \labelwidthstring 00.00.0000
9393
9394 \series bold
9395 -
9396 \begin_inset ERT
9397 status collapsed
9398
9399 \begin_layout Standard
9400
9401
9402 \backslash
9403 /
9404 \end_layout
9405
9406 \end_inset
9407
9408 -nooverlay
9409 \begin_inset LatexCommand \index{-\/-nooverlay}
9410
9411 \end_inset
9412
9413
9414 \series default
9415   The compiler will not overlay parameters and local variables of any function,
9416  see section Parameters and local variables for more details.
9417 \end_layout
9418
9419 \begin_layout List
9420 \labelwidthstring 00.00.0000
9421
9422 \series bold
9423 -
9424 \begin_inset ERT
9425 status collapsed
9426
9427 \begin_layout Standard
9428
9429
9430 \backslash
9431 /
9432 \end_layout
9433
9434 \end_inset
9435
9436 -no-peep
9437 \begin_inset LatexCommand \index{-\/-no-peep}
9438
9439 \end_inset
9440
9441
9442 \series default
9443  Disable peep-hole optimization with built-in rules.
9444 \end_layout
9445
9446 \begin_layout List
9447 \labelwidthstring 00.00.0000
9448
9449 \series bold
9450 -
9451 \begin_inset ERT
9452 status collapsed
9453
9454 \begin_layout Standard
9455
9456
9457 \backslash
9458 /
9459 \end_layout
9460
9461 \end_inset
9462
9463 -peep-file
9464 \series default
9465
9466 \begin_inset LatexCommand \index{-\/-peep-file}
9467
9468 \end_inset
9469
9470 \InsetSpace ~
9471 <filename> This option can be used to use additional rules to be used by
9472  the peep hole optimizer.
9473  See section 
9474 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9475
9476 \end_inset
9477
9478 \InsetSpace ~
9479 Peep Hole optimizations for details on how to write these rules.
9480 \end_layout
9481
9482 \begin_layout List
9483 \labelwidthstring 00.00.0000
9484
9485 \series bold
9486 -
9487 \begin_inset ERT
9488 status collapsed
9489
9490 \begin_layout Standard
9491
9492
9493 \backslash
9494 /
9495 \end_layout
9496
9497 \end_inset
9498
9499 -peep-asm
9500 \begin_inset LatexCommand \index{-\/-peep-asm}
9501
9502 \end_inset
9503
9504
9505 \series default
9506  Pass the inline assembler code through the peep hole optimizer.
9507  This can cause unexpected changes to inline assembler code, please go through
9508  the peephole optimizer
9509 \begin_inset LatexCommand \index{Peephole optimizer}
9510
9511 \end_inset
9512
9513  rules defined in the source file tree '<target>/peeph.def' before using
9514  this option.
9515 \end_layout
9516
9517 \begin_layout List
9518 \labelwidthstring 00.00.0000
9519
9520 \series bold
9521 -
9522 \begin_inset ERT
9523 status collapsed
9524
9525 \begin_layout Standard
9526
9527
9528 \backslash
9529 /
9530 \end_layout
9531
9532 \end_inset
9533
9534 -opt-code-speed
9535 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9536
9537 \end_inset
9538
9539
9540 \series default
9541  The compiler will optimize code generation towards fast code, possibly
9542  at the expense of code size.
9543 \end_layout
9544
9545 \begin_layout List
9546 \labelwidthstring 00.00.0000
9547
9548 \series bold
9549 -
9550 \begin_inset ERT
9551 status collapsed
9552
9553 \begin_layout Standard
9554
9555
9556 \backslash
9557 /
9558 \end_layout
9559
9560 \end_inset
9561
9562 -opt-code-size
9563 \begin_inset LatexCommand \index{-\/-opt-code-size}
9564
9565 \end_inset
9566
9567
9568 \series default
9569  The compiler will optimize code generation towards compact code, possibly
9570  at the expense of code speed.
9571 \end_layout
9572
9573 \begin_layout Standard
9574 \begin_inset VSpace bigskip
9575 \end_inset
9576
9577
9578 \end_layout
9579
9580 \begin_layout Subsection
9581 Other Options
9582 \begin_inset LatexCommand \index{Options other}
9583
9584 \end_inset
9585
9586
9587 \end_layout
9588
9589 \begin_layout List
9590 \labelwidthstring 00.00.0000
9591
9592 \series bold
9593 -c\InsetSpace ~
9594 -
9595 \begin_inset ERT
9596 status collapsed
9597
9598 \begin_layout Standard
9599
9600
9601 \backslash
9602 /
9603 \end_layout
9604
9605 \end_inset
9606
9607 -compile-only
9608 \begin_inset LatexCommand \index{-\/-compile-only}
9609
9610 \end_inset
9611
9612
9613 \begin_inset LatexCommand \index{-c -\/-compile-only}
9614
9615 \end_inset
9616
9617
9618 \series default
9619  will compile and assemble the source, but will not call the linkage editor.
9620 \end_layout
9621
9622 \begin_layout List
9623 \labelwidthstring 00.00.0000
9624
9625 \series bold
9626 -
9627 \series default
9628
9629 \begin_inset ERT
9630 status collapsed
9631
9632 \begin_layout Standard
9633
9634
9635 \backslash
9636 /
9637 \end_layout
9638
9639 \end_inset
9640
9641
9642 \series bold
9643 -c1mode
9644 \begin_inset LatexCommand \index{-\/-c1mode}
9645
9646 \end_inset
9647
9648
9649 \series default
9650  reads the preprocessed source from standard input and compiles it.
9651  The file name for the assembler output must be specified using the -o option.
9652 \end_layout
9653
9654 \begin_layout List
9655 \labelwidthstring 00.00.0000
9656
9657 \series bold
9658 -E
9659 \begin_inset LatexCommand \index{-E}
9660
9661 \end_inset
9662
9663
9664 \series default
9665  Run only the C preprocessor.
9666  Preprocess all the C source files specified and output the results to standard
9667  output.
9668 \end_layout
9669
9670 \begin_layout List
9671 \labelwidthstring 00.00.0000
9672
9673 \series bold
9674 -o\InsetSpace ~
9675 <path/file>
9676 \begin_inset LatexCommand \index{-o <path/file>}
9677
9678 \end_inset
9679
9680  
9681 \series default
9682 The output path where everything will be placed or the file name used for
9683  all generated output files.
9684  If the parameter is a path, it must have a trailing slash (or backslash
9685  for the Windows binaries) to be recognized as a path.
9686
9687 \emph on
9688  
9689 \emph default
9690 Note for Windows users: if the path contains spaces, it should be surrounded
9691  by quotes.
9692  The trailing backslash should be doubled in order to prevent escaping the
9693  final quote, for example: 
9694 \emph on
9695 -o 
9696 \begin_inset Quotes sld
9697 \end_inset
9698
9699 F:
9700 \backslash
9701 Projects
9702 \backslash
9703 test3
9704 \backslash
9705 output 1
9706 \backslash
9707
9708 \backslash
9709
9710 \begin_inset Quotes srd
9711 \end_inset
9712
9713
9714 \emph default
9715  or put after the final quote, for example: 
9716 \emph on
9717 -o 
9718 \begin_inset Quotes sld
9719 \end_inset
9720
9721 F:
9722 \backslash
9723 Projects
9724 \backslash
9725 test3
9726 \backslash
9727 output 1
9728 \begin_inset Quotes srd
9729 \end_inset
9730
9731
9732 \backslash
9733
9734 \emph default
9735 .
9736  The path using slashes for directory delimiters can be used too, for example:
9737  
9738 \emph on
9739 -o 
9740 \begin_inset Quotes sld
9741 \end_inset
9742
9743 F:/Projects/test3/output 1/
9744 \begin_inset Quotes srd
9745 \end_inset
9746
9747
9748 \emph default
9749 .
9750 \end_layout
9751
9752 \begin_layout List
9753 \labelwidthstring 00.00.0000
9754
9755 \series bold
9756 -
9757 \begin_inset ERT
9758 status collapsed
9759
9760 \begin_layout Standard
9761
9762
9763 \backslash
9764 /
9765 \end_layout
9766
9767 \end_inset
9768
9769 -stack-auto
9770 \begin_inset LatexCommand \index{-\/-stack-auto}
9771
9772 \end_inset
9773
9774
9775 \series default
9776 \size large
9777 \emph on
9778  
9779 \size default
9780 \emph default
9781 All functions in the source file will be compiled as 
9782 \emph on
9783 reentrant
9784 \emph default
9785
9786 \begin_inset LatexCommand \index{reentrant}
9787
9788 \end_inset
9789
9790 , i.e.
9791  the parameters and local variables will be allocated on the stack
9792 \begin_inset LatexCommand \index{stack}
9793
9794 \end_inset
9795
9796 .
9797  See section 
9798 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9799
9800 \end_inset
9801
9802  Parameters and Local Variables for more details.
9803  If this option is used all source files in the project should be compiled
9804  with this option.
9805  It automatically implies -
9806 \series bold
9807
9808 \begin_inset ERT
9809 status open
9810
9811 \begin_layout Standard
9812
9813
9814 \backslash
9815 /
9816 \end_layout
9817
9818 \end_inset
9819
9820
9821 \series default
9822 -int-long-reent and -
9823 \series bold
9824
9825 \begin_inset ERT
9826 status open
9827
9828 \begin_layout Standard
9829
9830
9831 \backslash
9832 /
9833 \end_layout
9834
9835 \end_inset
9836
9837
9838 \series default
9839 -float-reent.
9840  
9841 \end_layout
9842
9843 \begin_layout List
9844 \labelwidthstring 00.00.0000
9845
9846 \series bold
9847 -
9848 \begin_inset ERT
9849 status collapsed
9850
9851 \begin_layout Standard
9852
9853
9854 \backslash
9855 /
9856 \end_layout
9857
9858 \end_inset
9859
9860 -callee-saves
9861 \begin_inset LatexCommand \index{-\/-callee-saves}
9862
9863 \end_inset
9864
9865  
9866 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9867
9868 \end_inset
9869
9870 function1[,function2][,function3]....
9871
9872 \series default
9873  The compiler by default uses a caller saves convention for register saving
9874  across function calls, however this can cause unnecessary register pushing
9875  and popping when calling small functions from larger functions.
9876  This option can be used to switch the register saving convention for the
9877  function names specified.
9878  The compiler will not save registers when calling these functions, no extra
9879  code will be generated at the entry and exit (function prologue
9880 \series bold
9881
9882 \begin_inset LatexCommand \index{function prologue}
9883
9884 \end_inset
9885
9886
9887 \series default
9888  and epilogue
9889 \series bold
9890
9891 \begin_inset LatexCommand \index{function epilogue}
9892
9893 \end_inset
9894
9895
9896 \series default
9897 ) for these functions to save and restore the registers used by these functions,
9898  this can SUBSTANTIALLY reduce code and improve run time performance of
9899  the generated code.
9900  In the future the compiler (with inter procedural analysis) will be able
9901  to determine the appropriate scheme to use for each function call.
9902  DO NOT use this option for built-in functions such as _mulint..., if this
9903  option is used for a library function the appropriate library function
9904  needs to be recompiled with the same option.
9905  If the project consists of multiple source files then all the source file
9906  should be compiled with the same -
9907 \begin_inset ERT
9908 status collapsed
9909
9910 \begin_layout Standard
9911
9912
9913 \backslash
9914 /
9915 \end_layout
9916
9917 \end_inset
9918
9919 -callee-saves option string.
9920  Also see #pragma\InsetSpace ~
9921 callee_saves 
9922 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9923
9924 \end_inset
9925
9926  
9927 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9928
9929 \end_inset
9930
9931 .
9932 \end_layout
9933
9934 \begin_layout List
9935 \labelwidthstring 00.00.0000
9936
9937 \series bold
9938 -
9939 \begin_inset ERT
9940 status collapsed
9941
9942 \begin_layout Standard
9943
9944
9945 \backslash
9946 /
9947 \end_layout
9948
9949 \end_inset
9950
9951 -all-callee-saves
9952 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9953
9954 \end_inset
9955
9956  
9957 \series default
9958 Function of
9959 \series bold
9960  
9961 \series default
9962 -
9963 \begin_inset ERT
9964 status collapsed
9965
9966 \begin_layout Standard
9967
9968
9969 \backslash
9970 /
9971 \end_layout
9972
9973 \end_inset
9974
9975 -callee-saves will be applied to all functions by default.
9976 \end_layout
9977
9978 \begin_layout List
9979 \labelwidthstring 00.00.0000
9980
9981 \series bold
9982 -
9983 \begin_inset ERT
9984 status collapsed
9985
9986 \begin_layout Standard
9987
9988
9989 \backslash
9990 /
9991 \end_layout
9992
9993 \end_inset
9994
9995 -debug
9996 \begin_inset LatexCommand \index{-\/-debug}
9997
9998 \end_inset
9999
10000
10001 \bar under
10002  
10003 \series default
10004 \bar default
10005 When this option is used the compiler will generate debug information.
10006  The debug information collected in a file with .cdb extension can be used
10007  with the SDCDB.
10008  For more information see documentation for SDCDB.
10009  Another file with no extension contains debug information in AOMF or AOMF51
10010 \begin_inset LatexCommand \index{AOMF, AOMF51}
10011
10012 \end_inset
10013
10014  format which is commonly used by third party tools.
10015 \end_layout
10016
10017 \begin_layout List
10018 \labelwidthstring 00.00.0000
10019
10020 \series bold
10021 -S
10022 \begin_inset LatexCommand \index{-S}
10023
10024 \end_inset
10025
10026
10027 \size large
10028 \bar under
10029  
10030 \series default
10031 \size default
10032 \bar default
10033 Stop after the stage of compilation proper; do not assemble.
10034  The output is an assembler code file for the input file specified.
10035 \end_layout
10036
10037 \begin_layout List
10038 \labelwidthstring 00.00.0000
10039
10040 \series bold
10041 -
10042 \begin_inset ERT
10043 status collapsed
10044
10045 \begin_layout Standard
10046
10047
10048 \backslash
10049 /
10050 \end_layout
10051
10052 \end_inset
10053
10054 -int-long-reent
10055 \begin_inset LatexCommand \index{-\/-int-long-reent}
10056
10057 \end_inset
10058
10059
10060 \series default
10061  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10062  Note by default these libraries are compiled as non-reentrant.
10063  See section Installation for more details.
10064 \end_layout
10065
10066 \begin_layout List
10067 \labelwidthstring 00.00.0000
10068
10069 \series bold
10070 -
10071 \begin_inset ERT
10072 status collapsed
10073
10074 \begin_layout Standard
10075
10076
10077 \backslash
10078 /
10079 \end_layout
10080
10081 \end_inset
10082
10083 -cyclomatic
10084 \begin_inset LatexCommand \index{-\/-cyclomatic}
10085
10086 \end_inset
10087
10088
10089 \bar under
10090  
10091 \series default
10092 \bar default
10093 This option will cause the compiler to generate an information message for
10094  each function in the source file.
10095  The message contains some 
10096 \emph on
10097 important
10098 \emph default
10099  information about the function.
10100  The number of edges and nodes the compiler detected in the control flow
10101  graph of the function, and most importantly the 
10102 \emph on
10103 cyclomatic complexity
10104 \begin_inset LatexCommand \index{Cyclomatic complexity}
10105
10106 \end_inset
10107
10108
10109 \emph default
10110  see section on Cyclomatic Complexity for more details.
10111 \end_layout
10112
10113 \begin_layout List
10114 \labelwidthstring 00.00.0000
10115
10116 \series bold
10117 -
10118 \begin_inset ERT
10119 status collapsed
10120
10121 \begin_layout Standard
10122
10123
10124 \backslash
10125 /
10126 \end_layout
10127
10128 \end_inset
10129
10130 -float-reent
10131 \begin_inset LatexCommand \index{-\/-float-reent}
10132
10133 \end_inset
10134
10135
10136 \series default
10137  Floating point library is compiled as reentrant
10138 \begin_inset LatexCommand \index{reentrant}
10139
10140 \end_inset
10141
10142 .
10143  See section Installation for more details.
10144 \end_layout
10145
10146 \begin_layout List
10147 \labelwidthstring 00.00.0000
10148
10149 \series bold
10150 -
10151 \begin_inset ERT
10152 status collapsed
10153
10154 \begin_layout Standard
10155
10156
10157 \backslash
10158 /
10159 \end_layout
10160
10161 \end_inset
10162
10163 -funsigned-char
10164 \begin_inset LatexCommand \index{-\/-funsigned-char}
10165
10166 \end_inset
10167
10168
10169 \series default
10170  The default signedness for every type is
10171 \family typewriter
10172  signed
10173 \family default
10174 .
10175  In some embedded environments the default signedness of
10176 \family typewriter
10177  char
10178 \family default
10179  is
10180 \family typewriter
10181  unsigned
10182 \family default
10183 .
10184  To set the signess for characters to unsigned, use the option -
10185 \series bold
10186
10187 \begin_inset ERT
10188 status open
10189
10190 \begin_layout Standard
10191
10192
10193 \backslash
10194 /
10195 \end_layout
10196
10197 \end_inset
10198
10199
10200 \series default
10201 -funsigned-char.
10202  If this option is set and no signedness keyword (unsigned/signed) is given,
10203  a char will be signed.
10204  All other types are unaffected.
10205 \end_layout
10206
10207 \begin_layout List
10208 \labelwidthstring 00.00.0000
10209
10210 \series bold
10211 -
10212 \begin_inset ERT
10213 status collapsed
10214
10215 \begin_layout Standard
10216
10217
10218 \backslash
10219 /
10220 \end_layout
10221
10222 \end_inset
10223
10224 -main-return
10225 \begin_inset LatexCommand \index{-\/-main-return}
10226
10227 \end_inset
10228
10229
10230 \series default
10231  This option can be used if the code generated is called by a monitor program
10232  or if the main routine includes an endless loop.
10233  This option results in slightly smaller code and saves two bytes of stack
10234  space.
10235  The return from the 'main'
10236 \begin_inset LatexCommand \index{main return}
10237
10238 \end_inset
10239
10240  function will return to the function calling main.
10241  The default setting is to lock up i.e.
10242  generate a '
10243 \family typewriter
10244 sjmp .
10245 \family default
10246 '.
10247 \end_layout
10248
10249 \begin_layout List
10250 \labelwidthstring 00.00.0000
10251
10252 \series bold
10253 -
10254 \begin_inset ERT
10255 status collapsed
10256
10257 \begin_layout Standard
10258
10259
10260 \backslash
10261 /
10262 \end_layout
10263
10264 \end_inset
10265
10266 -nostdinc
10267 \begin_inset LatexCommand \index{-\/-nostdinc}
10268
10269 \end_inset
10270
10271
10272 \series default
10273  This will prevent the compiler from passing on the default include path
10274  to the preprocessor.
10275 \end_layout
10276
10277 \begin_layout List
10278 \labelwidthstring 00.00.0000
10279
10280 \series bold
10281 -
10282 \begin_inset ERT
10283 status collapsed
10284
10285 \begin_layout Standard
10286
10287
10288 \backslash
10289 /
10290 \end_layout
10291
10292 \end_inset
10293
10294 -nostdlib
10295 \begin_inset LatexCommand \index{-\/-nostdlib}
10296
10297 \end_inset
10298
10299
10300 \series default
10301  This will prevent the compiler from passing on the default library
10302 \begin_inset LatexCommand \index{Libraries}
10303
10304 \end_inset
10305
10306  path to the linker.
10307 \end_layout
10308
10309 \begin_layout List
10310 \labelwidthstring 00.00.0000
10311
10312 \series bold
10313 -
10314 \begin_inset ERT
10315 status collapsed
10316
10317 \begin_layout Standard
10318
10319
10320 \backslash
10321 /
10322 \end_layout
10323
10324 \end_inset
10325
10326 -verbose
10327 \begin_inset LatexCommand \index{-\/-verbose}
10328
10329 \end_inset
10330
10331
10332 \series default
10333  Shows the various actions the compiler is performing.
10334 \end_layout
10335
10336 \begin_layout List
10337 \labelwidthstring 00.00.0000
10338
10339 \series bold
10340 -V
10341 \begin_inset LatexCommand \index{-V}
10342
10343 \end_inset
10344
10345
10346 \series default
10347  Shows the actual commands the compiler is executing.
10348 \end_layout
10349
10350 \begin_layout List
10351 \labelwidthstring 00.00.0000
10352
10353 \series bold
10354 -
10355 \begin_inset ERT
10356 status collapsed
10357
10358 \begin_layout Standard
10359
10360
10361 \backslash
10362 /
10363 \end_layout
10364
10365 \end_inset
10366
10367 -no-c-code-in-asm
10368 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10369
10370 \end_inset
10371
10372
10373 \series default
10374  Hides your ugly and inefficient c-code from the asm file, so you can always
10375  blame the compiler :)
10376 \end_layout
10377
10378 \begin_layout List
10379 \labelwidthstring 00.00.0000
10380
10381 \series bold
10382 -
10383 \begin_inset ERT
10384 status collapsed
10385
10386 \begin_layout Standard
10387
10388
10389 \backslash
10390 /
10391 \end_layout
10392
10393 \end_inset
10394
10395 -fverbose-asm
10396 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10397
10398 \end_inset
10399
10400
10401 \series default
10402  Include code generator and peep-hole comments in the generated asm files.
10403 \end_layout
10404
10405 \begin_layout List
10406 \labelwidthstring 00.00.0000
10407
10408 \series bold
10409 -
10410 \begin_inset ERT
10411 status collapsed
10412
10413 \begin_layout Standard
10414
10415
10416 \backslash
10417 /
10418 \end_layout
10419
10420 \end_inset
10421
10422 -no-peep-comments
10423 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10424
10425 \end_inset
10426
10427
10428 \series default
10429  Don't include peep-hole comments in the generated asm files even if -
10430 \series bold
10431
10432 \begin_inset ERT
10433 status open
10434
10435 \begin_layout Standard
10436
10437
10438 \backslash
10439 /
10440 \end_layout
10441
10442 \end_inset
10443
10444
10445 \series default
10446 -fverbose-asm option is specified.
10447 \end_layout
10448
10449 \begin_layout List
10450 \labelwidthstring 00.00.0000
10451
10452 \series bold
10453 -
10454 \begin_inset ERT
10455 status collapsed
10456
10457 \begin_layout Standard
10458
10459
10460 \backslash
10461 /
10462 \end_layout
10463
10464 \end_inset
10465
10466 -i-code-in-asm
10467 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10468
10469 \end_inset
10470
10471
10472 \series default
10473  Include i-codes in the asm file.
10474  Sounds like noise but is most helpful for debugging the compiler itself.
10475 \end_layout
10476
10477 \begin_layout List
10478 \labelwidthstring 00.00.0000
10479
10480 \series bold
10481 -
10482 \begin_inset ERT
10483 status collapsed
10484
10485 \begin_layout Standard
10486
10487
10488 \backslash
10489 /
10490 \end_layout
10491
10492 \end_inset
10493
10494 -less-pedantic
10495 \begin_inset LatexCommand \index{pedantic}
10496
10497 \end_inset
10498
10499
10500 \begin_inset LatexCommand \index{-\/-less-pedantic}
10501
10502 \end_inset
10503
10504
10505 \series default
10506
10507 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10508
10509 \end_inset
10510
10511  Disable some of the more pedantic warnings
10512 \begin_inset LatexCommand \index{Warnings}
10513
10514 \end_inset
10515
10516 .
10517  For more details, see the less_pedantic pragma 
10518 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10519
10520 \end_inset
10521
10522 .
10523 \end_layout
10524
10525 \begin_layout List
10526 \labelwidthstring 00.00.0000
10527
10528 \series bold
10529 -
10530 \begin_inset ERT
10531 status collapsed
10532
10533 \begin_layout Standard
10534
10535
10536 \backslash
10537 /
10538 \end_layout
10539
10540 \end_inset
10541
10542 -disable-warning\InsetSpace ~
10543 <nnnn>
10544 \begin_inset LatexCommand \index{-\/-disable-warning}
10545
10546 \end_inset
10547
10548
10549 \series default
10550  Disable specific warning with number <nnnn>.
10551 \end_layout
10552
10553 \begin_layout List
10554 \labelwidthstring 00.00.0000
10555
10556 \series bold
10557 -
10558 \begin_inset ERT
10559 status collapsed
10560
10561 \begin_layout Standard
10562
10563
10564 \backslash
10565 /
10566 \end_layout
10567
10568 \end_inset
10569
10570 -Werror
10571 \begin_inset LatexCommand \index{-\/-Werror}
10572
10573 \end_inset
10574
10575
10576 \series default
10577  Treat all warnings as errors.
10578 \end_layout
10579
10580 \begin_layout List
10581 \labelwidthstring 00.00.0000
10582
10583 \series bold
10584 -
10585 \begin_inset ERT
10586 status collapsed
10587
10588 \begin_layout Standard
10589
10590
10591 \backslash
10592 /
10593 \end_layout
10594
10595 \end_inset
10596
10597 -print-search-dirs
10598 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10599
10600 \end_inset
10601
10602
10603 \series default
10604  Display the directories in the compiler's search path
10605 \end_layout
10606
10607 \begin_layout List
10608 \labelwidthstring 00.00.0000
10609
10610 \series bold
10611 -
10612 \begin_inset ERT
10613 status collapsed
10614
10615 \begin_layout Standard
10616
10617
10618 \backslash
10619 /
10620 \end_layout
10621
10622 \end_inset
10623
10624 -vc
10625 \begin_inset LatexCommand \index{-\/-vc}
10626
10627 \end_inset
10628
10629
10630 \series default
10631  Display errors and warnings using MSVC style, so you can use SDCC with
10632  the visual studio IDE
10633 \begin_inset LatexCommand \index{IDE}
10634
10635 \end_inset
10636
10637 .
10638  With SDCC both offering a GCC-like (the default) and a MSVC-like
10639 \begin_inset LatexCommand \index{MSVC output style}
10640
10641 \end_inset
10642
10643  output style, integration into most programming editors should be straightforwa
10644 rd.
10645 \end_layout
10646
10647 \begin_layout List
10648 \labelwidthstring 00.00.0000
10649
10650 \series bold
10651 -
10652 \begin_inset ERT
10653 status collapsed
10654
10655 \begin_layout Standard
10656
10657
10658 \backslash
10659 /
10660 \end_layout
10661
10662 \end_inset
10663
10664 -use-stdout
10665 \begin_inset LatexCommand \index{-\/-use-stdout}
10666
10667 \end_inset
10668
10669
10670 \series default
10671  Send errors and warnings to stdout instead of stderr.
10672 \end_layout
10673
10674 \begin_layout List
10675 \labelwidthstring 00.00.0000
10676
10677 \series bold
10678 -Wa\InsetSpace ~
10679 asmOption[,asmOption]
10680 \series default
10681
10682 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10683
10684 \end_inset
10685
10686 ...
10687  Pass the asmOption to the assembler
10688 \begin_inset LatexCommand \index{Options assembler}
10689
10690 \end_inset
10691
10692
10693 \begin_inset LatexCommand \index{Assembler options}
10694
10695 \end_inset
10696
10697 .
10698  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10699 \end_layout
10700
10701 \begin_layout List
10702 \labelwidthstring 00.00.0000
10703
10704 \series bold
10705 -
10706 \begin_inset ERT
10707 status collapsed
10708
10709 \begin_layout Standard
10710
10711
10712 \backslash
10713 /
10714 \end_layout
10715
10716 \end_inset
10717
10718 -std-sdcc89
10719 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10720
10721 \end_inset
10722
10723
10724 \series default
10725  Generally follow the C89 standard, but allow SDCC features that conflict
10726  with the standard (default).
10727 \end_layout
10728
10729 \begin_layout List
10730 \labelwidthstring 00.00.0000
10731
10732 \series bold
10733 -
10734 \begin_inset ERT
10735 status collapsed
10736
10737 \begin_layout Standard
10738
10739
10740 \backslash
10741 /
10742 \end_layout
10743
10744 \end_inset
10745
10746 -std-c89
10747 \begin_inset LatexCommand \index{-\/-std-c89}
10748
10749 \end_inset
10750
10751
10752 \series default
10753  Follow the C89 standard and disable SDCC features that conflict with the
10754  standard.
10755 \end_layout
10756
10757 \begin_layout List
10758 \labelwidthstring 00.00.0000
10759
10760 \series bold
10761 -
10762 \begin_inset ERT
10763 status collapsed
10764
10765 \begin_layout Standard
10766
10767
10768 \backslash
10769 /
10770 \end_layout
10771
10772 \end_inset
10773
10774 -std-sdcc99
10775 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10776
10777 \end_inset
10778
10779
10780 \series default
10781  Generally follow the C99 standard, but allow SDCC features that conflict
10782  with the standard (incomplete support).
10783 \end_layout
10784
10785 \begin_layout List
10786 \labelwidthstring 00.00.0000
10787
10788 \series bold
10789 -
10790 \begin_inset ERT
10791 status collapsed
10792
10793 \begin_layout Standard
10794
10795
10796 \backslash
10797 /
10798 \end_layout
10799
10800 \end_inset
10801
10802 -std-c99
10803 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10804
10805 \end_inset
10806
10807
10808 \series default
10809  Follow the C99 standard and disable SDCC features that conflict with the
10810  standard (incomplete support).
10811 \end_layout
10812
10813 \begin_layout List
10814 \labelwidthstring 00.00.0000
10815
10816 \series bold
10817 -
10818 \begin_inset ERT
10819 status collapsed
10820
10821 \begin_layout Standard
10822
10823
10824 \backslash
10825 /
10826 \end_layout
10827
10828 \end_inset
10829
10830 -codeseg
10831 \series default
10832
10833 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10834
10835 \end_inset
10836
10837 \begin_inset LatexCommand \label{lyx:-codeseg}
10838
10839 \end_inset
10840
10841 \InsetSpace ~
10842 <Name> The name to be used for the code
10843 \begin_inset LatexCommand \index{code}
10844
10845 \end_inset
10846
10847  segment, default CSEG.
10848  This is useful if you need to tell the compiler to put the code in a special
10849  segment so you can later on tell the linker to put this segment in a special
10850  place in memory.
10851  Can be used for instance when using bank switching to put the code in a
10852  bank.
10853 \end_layout
10854
10855 \begin_layout List
10856 \labelwidthstring 00.00.0000
10857
10858 \series bold
10859 -
10860 \begin_inset ERT
10861 status collapsed
10862
10863 \begin_layout Standard
10864
10865
10866 \backslash
10867 /
10868 \end_layout
10869
10870 \end_inset
10871
10872 -constseg
10873 \series default
10874
10875 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10876
10877 \end_inset
10878
10879 \InsetSpace ~
10880 <Name> The name to be used for the const
10881 \begin_inset LatexCommand \index{const}
10882
10883 \end_inset
10884
10885  segment, default CONST.
10886  This is useful if you need to tell the compiler to put the const data in
10887  a special segment so you can later on tell the linker to put this segment
10888  in a special place in memory.
10889  Can be used for instance when using bank switching to put the const data
10890  in a bank.
10891 \end_layout
10892
10893 \begin_layout List
10894 \labelwidthstring 00.00.0000
10895
10896 \series bold
10897 -
10898 \begin_inset ERT
10899 status collapsed
10900
10901 \begin_layout Standard
10902
10903
10904 \backslash
10905 /
10906 \end_layout
10907
10908 \end_inset
10909
10910 -fdollars-in-identifiers
10911 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10912
10913 \end_inset
10914
10915
10916 \series default
10917  Permit '$' as an identifier character.
10918 \end_layout
10919
10920 \begin_layout List
10921 \labelwidthstring 00.00.0000
10922
10923 \series bold
10924 -
10925 \begin_inset ERT
10926 status collapsed
10927
10928 \begin_layout Standard
10929
10930
10931 \backslash
10932 /
10933 \end_layout
10934
10935 \end_inset
10936
10937 -more-pedantic
10938 \series default
10939
10940 \begin_inset LatexCommand \index{-\/-more-pedantic}
10941
10942 \end_inset
10943
10944
10945 \begin_inset LatexCommand \index{pedantic}
10946
10947 \end_inset
10948
10949  Actually this is 
10950 \series bold
10951 \emph on
10952 not
10953 \series default
10954 \emph default
10955  a SDCC compiler option but if you want 
10956 \emph on
10957 more
10958 \emph default
10959  warnings you can use a separate tool dedicated to syntax checking like
10960  splint
10961 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10962
10963 \end_inset
10964
10965
10966 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10967
10968 \end_inset
10969
10970  
10971 \begin_inset LatexCommand \url{http://www.splint.org}
10972
10973 \end_inset
10974
10975 .
10976  To make your source files parseable by splint you will have to include
10977  
10978 \family sans
10979 lint.h
10980 \family default
10981
10982 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10983
10984 \end_inset
10985
10986  in your source file and add brackets around extended keywords (like 
10987 \family sans
10988
10989 \begin_inset Quotes sld
10990 \end_inset
10991
10992 __at\InsetSpace ~
10993
10994 \series bold
10995 (
10996 \series default
10997 0xab
10998 \series bold
10999 )
11000 \series default
11001
11002 \begin_inset Quotes srd
11003 \end_inset
11004
11005
11006 \family default
11007  and 
11008 \family sans
11009
11010 \begin_inset Quotes sld
11011 \end_inset
11012
11013 __interrupt\InsetSpace ~
11014 (2)
11015 \begin_inset Quotes srd
11016 \end_inset
11017
11018
11019 \family default
11020 ).
11021  
11022 \newline
11023 Splint has an excellent on line manual at 
11024 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11025
11026 \end_inset
11027
11028  and it's capabilities go beyond pure syntax checking.
11029  You'll need to tell splint the location of SDCC's include files so a typical
11030  command line could look like this: 
11031 \newline
11032
11033 \family sans
11034 splint\InsetSpace ~
11035 -I\InsetSpace ~
11036 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11037 \InsetSpace ~
11038 myprogram.c
11039 \end_layout
11040
11041 \begin_layout List
11042 \labelwidthstring 00.00.0000
11043
11044 \series bold
11045 -
11046 \begin_inset ERT
11047 status collapsed
11048
11049 \begin_layout Standard
11050
11051
11052 \backslash
11053 /
11054 \end_layout
11055
11056 \end_inset
11057
11058 -short-is-8bits
11059 \series default
11060
11061 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11062
11063 \end_inset
11064
11065
11066 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11067
11068 \end_inset
11069
11070  Treat short as 8-bit (for backward compatibility with older versions of
11071  compiler - see section 
11072 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11073
11074 \end_inset
11075
11076 )
11077 \end_layout
11078
11079 \begin_layout Standard
11080 \begin_inset VSpace bigskip
11081 \end_inset
11082
11083
11084 \end_layout
11085
11086 \begin_layout Subsection
11087 Intermediate Dump Options
11088 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11089
11090 \end_inset
11091
11092
11093 \begin_inset LatexCommand \index{Options intermediate dump}
11094
11095 \end_inset
11096
11097
11098 \begin_inset LatexCommand \index{Intermediate dump options}
11099
11100 \end_inset
11101
11102
11103 \end_layout
11104
11105 \begin_layout Standard
11106 The following options are provided for the purpose of retargetting and debugging
11107  the compiler.
11108  They provide a means to dump the intermediate code (iCode
11109 \begin_inset LatexCommand \index{iCode}
11110
11111 \end_inset
11112
11113 ) generated by the compiler in human readable form at various stages of
11114  the compilation process.
11115  More on iCodes see chapter 
11116 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11117
11118 \end_inset
11119
11120  
11121 \begin_inset Quotes srd
11122 \end_inset
11123
11124 The anatomy of the compiler
11125 \begin_inset Quotes srd
11126 \end_inset
11127
11128 .
11129 \end_layout
11130
11131 \begin_layout List
11132 \labelwidthstring 00.00.0000
11133
11134 \series bold
11135 -
11136 \begin_inset ERT
11137 status collapsed
11138
11139 \begin_layout Standard
11140
11141
11142 \backslash
11143 /
11144 \end_layout
11145
11146 \end_inset
11147
11148 -dumpraw
11149 \begin_inset LatexCommand \index{-\/-dumpraw}
11150
11151 \end_inset
11152
11153
11154 \series default
11155  This option will cause the compiler to dump the intermediate code into
11156  a file of named 
11157 \emph on
11158 <source filename>.dumpraw
11159 \emph default
11160  just after the intermediate code has been generated for a function, i.e.
11161  before any optimizations are done.
11162  The basic blocks
11163 \begin_inset LatexCommand \index{Basic blocks}
11164
11165 \end_inset
11166
11167  at this stage ordered in the depth first number, so they may not be in
11168  sequence of execution.
11169 \end_layout
11170
11171 \begin_layout List
11172 \labelwidthstring 00.00.0000
11173
11174 \series bold
11175 -
11176 \begin_inset ERT
11177 status collapsed
11178
11179 \begin_layout Standard
11180
11181
11182 \backslash
11183 /
11184 \end_layout
11185
11186 \end_inset
11187
11188 -dumpgcse
11189 \begin_inset LatexCommand \index{-\/-dumpgcse}
11190
11191 \end_inset
11192
11193
11194 \series default
11195  Will create a dump of iCodes, after global subexpression elimination
11196 \begin_inset LatexCommand \index{Global subexpression elimination}
11197
11198 \end_inset
11199
11200 , into a file named 
11201 \emph on
11202 <source filename>.dumpgcse.
11203 \end_layout
11204
11205 \begin_layout List
11206 \labelwidthstring 00.00.0000
11207
11208 \series bold
11209 -
11210 \begin_inset ERT
11211 status collapsed
11212
11213 \begin_layout Standard
11214
11215
11216 \backslash
11217 /
11218 \end_layout
11219
11220 \end_inset
11221
11222 -dumpdeadcode
11223 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11224
11225 \end_inset
11226
11227
11228 \series default
11229  Will create a dump of iCodes, after deadcode elimination
11230 \begin_inset LatexCommand \index{Dead-code elimination}
11231
11232 \end_inset
11233
11234 , into a file named 
11235 \emph on
11236 <source filename>.dumpdeadcode.
11237 \end_layout
11238
11239 \begin_layout List
11240 \labelwidthstring 00.00.0000
11241
11242 \series bold
11243 -
11244 \begin_inset ERT
11245 status collapsed
11246
11247 \begin_layout Standard
11248
11249
11250 \backslash
11251 /
11252 \end_layout
11253
11254 \end_inset
11255
11256 -dumploop
11257 \begin_inset LatexCommand \index{-\/-dumploop}
11258
11259 \end_inset
11260
11261
11262 \series default
11263 \size large
11264  
11265 \size default
11266 Will create a dump of iCodes, after loop optimizations
11267 \begin_inset LatexCommand \index{Loop optimization}
11268
11269 \end_inset
11270
11271 , into a file named 
11272 \emph on
11273 <source filename>.dumploop.
11274 \end_layout
11275
11276 \begin_layout List
11277 \labelwidthstring 00.00.0000
11278
11279 \series bold
11280 -
11281 \begin_inset ERT
11282 status collapsed
11283
11284 \begin_layout Standard
11285
11286
11287 \backslash
11288 /
11289 \end_layout
11290
11291 \end_inset
11292
11293 -dumprange
11294 \begin_inset LatexCommand \index{-\/-dumprange}
11295
11296 \end_inset
11297
11298
11299 \series default
11300 \size large
11301  
11302 \size default
11303 Will create a dump of iCodes, after live range analysis
11304 \begin_inset LatexCommand \index{Live range analysis}
11305
11306 \end_inset
11307
11308 , into a file named 
11309 \emph on
11310 <source filename>.dumprange.
11311 \end_layout
11312
11313 \begin_layout List
11314 \labelwidthstring 00.00.0000
11315
11316 \series bold
11317 -
11318 \begin_inset ERT
11319 status collapsed
11320
11321 \begin_layout Standard
11322
11323
11324 \backslash
11325 /
11326 \end_layout
11327
11328 \end_inset
11329
11330 -dumlrange
11331 \begin_inset LatexCommand \index{-\/-dumlrange}
11332
11333 \end_inset
11334
11335
11336 \series default
11337  Will dump the life ranges
11338 \begin_inset LatexCommand \index{Live range analysis}
11339
11340 \end_inset
11341
11342  for all symbols.
11343 \end_layout
11344
11345 \begin_layout List
11346 \labelwidthstring 00.00.0000
11347
11348 \series bold
11349 -
11350 \begin_inset ERT
11351 status collapsed
11352
11353 \begin_layout Standard
11354
11355
11356 \backslash
11357 /
11358 \end_layout
11359
11360 \end_inset
11361
11362 -dumpregassign
11363 \begin_inset LatexCommand \index{-\/-dumpregassign}
11364
11365 \end_inset
11366
11367
11368 \bar under
11369  
11370 \series default
11371 \bar default
11372 Will create a dump of iCodes, after register assignment
11373 \begin_inset LatexCommand \index{Register assignment}
11374
11375 \end_inset
11376
11377 , into a file named 
11378 \emph on
11379 <source filename>.dumprassgn.
11380 \end_layout
11381
11382 \begin_layout List
11383 \labelwidthstring 00.00.0000
11384
11385 \series bold
11386 -
11387 \begin_inset ERT
11388 status collapsed
11389
11390 \begin_layout Standard
11391
11392
11393 \backslash
11394 /
11395 \end_layout
11396
11397 \end_inset
11398
11399 -dumplrange
11400 \begin_inset LatexCommand \index{-\/-dumplrange}
11401
11402 \end_inset
11403
11404
11405 \series default
11406  Will create a dump of the live ranges of iTemp's
11407 \end_layout
11408
11409 \begin_layout List
11410 \labelwidthstring 00.00.0000
11411
11412 \series bold
11413 -
11414 \begin_inset ERT
11415 status collapsed
11416
11417 \begin_layout Standard
11418
11419
11420 \backslash
11421 /
11422 \end_layout
11423
11424 \end_inset
11425
11426 -dumpall
11427 \begin_inset LatexCommand \index{-\/-dumpall}
11428
11429 \end_inset
11430
11431
11432 \size large
11433 \bar under
11434  
11435 \series default
11436 \size default
11437 \bar default
11438 Will cause all the above mentioned dumps to be created.
11439 \end_layout
11440
11441 \begin_layout Standard
11442 \begin_inset VSpace bigskip
11443 \end_inset
11444
11445
11446 \end_layout
11447
11448 \begin_layout Subsection
11449 Redirecting output on Windows Shells
11450 \end_layout
11451
11452 \begin_layout Standard
11453 By default SDCC writes its error messages to 
11454 \begin_inset Quotes sld
11455 \end_inset
11456
11457 standard error
11458 \begin_inset Quotes srd
11459 \end_inset
11460
11461 .
11462  To force all messages to 
11463 \begin_inset Quotes sld
11464 \end_inset
11465
11466 standard output
11467 \begin_inset Quotes srd
11468 \end_inset
11469
11470  use 
11471 \series bold
11472 -
11473 \series default
11474 \emph on
11475
11476 \begin_inset ERT
11477 status collapsed
11478
11479 \begin_layout Standard
11480
11481
11482 \backslash
11483 /
11484 \end_layout
11485
11486 \end_inset
11487
11488
11489 \series bold
11490 \emph default
11491 -
11492 \series default
11493 use-stdout
11494 \begin_inset LatexCommand \index{-\/-use-stdout}
11495
11496 \end_inset
11497
11498 .
11499  Additionally, if you happen to have visual studio installed in your windows
11500  machine, you can use it to compile your sources using a custom build and
11501  the SDCC -
11502 \emph on
11503
11504 \begin_inset ERT
11505 status collapsed
11506
11507 \begin_layout Standard
11508
11509
11510 \backslash
11511 /
11512 \end_layout
11513
11514 \end_inset
11515
11516
11517 \emph default
11518 -vc
11519 \begin_inset LatexCommand \index{-\/-vc}
11520
11521 \end_inset
11522
11523  option.
11524  Something like this should work:
11525 \newline
11526
11527 \newline
11528
11529 \series bold
11530 c:
11531 \backslash
11532 sdcc
11533 \backslash
11534 bin
11535 \backslash
11536 sdcc.exe -
11537 \series default
11538 \emph on
11539
11540 \begin_inset ERT
11541 status collapsed
11542
11543 \begin_layout Standard
11544
11545
11546 \backslash
11547 /
11548 \end_layout
11549
11550 \end_inset
11551
11552
11553 \series bold
11554 \emph default
11555 -vc -
11556 \series default
11557 \emph on
11558
11559 \begin_inset ERT
11560 status collapsed
11561
11562 \begin_layout Standard
11563
11564
11565 \backslash
11566 /
11567 \end_layout
11568
11569 \end_inset
11570
11571
11572 \series bold
11573 \emph default
11574 -model-large -c $(InputPath)
11575 \series default
11576
11577 \begin_inset VSpace bigskip
11578 \end_inset
11579
11580
11581 \end_layout
11582
11583 \begin_layout Section
11584 Environment variables
11585 \begin_inset LatexCommand \index{Environment variables}
11586
11587 \end_inset
11588
11589
11590 \end_layout
11591
11592 \begin_layout Standard
11593 SDCC recognizes the following environment variables:
11594 \end_layout
11595
11596 \begin_layout List
11597 \labelwidthstring 00.00.0000
11598
11599 \series bold
11600 SDCC_LEAVE_SIGNALS
11601 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11602
11603 \end_inset
11604
11605
11606 \series default
11607  SDCC installs a signal handler
11608 \begin_inset LatexCommand \index{signal handler}
11609
11610 \end_inset
11611
11612  to be able to delete temporary files after an user break (^C) or an exception.
11613  If this environment variable is set, SDCC won't install the signal handler
11614  in order to be able to debug SDCC.
11615 \end_layout
11616
11617 \begin_layout List
11618 \labelwidthstring 00.00.0000
11619
11620 \series bold
11621 TMP,\InsetSpace ~
11622 TEMP,\InsetSpace ~
11623 TMPDIR
11624 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11625
11626 \end_inset
11627
11628
11629 \series default
11630  Path, where temporary files will be created.
11631  The order of the variables is the search order.
11632  In a standard *nix environment these variables are not set, and there's
11633  no need to set them.
11634  On Windows it's recommended to set one of them.
11635 \end_layout
11636
11637 \begin_layout List
11638 \labelwidthstring 00.00.0000
11639
11640 \series bold
11641 SDCC_HOME
11642 \begin_inset LatexCommand \index{SDCC\_HOME}
11643
11644 \end_inset
11645
11646
11647 \series default
11648  Path, see section 
11649 \begin_inset LatexCommand \ref{sub:Install-paths}
11650
11651 \end_inset
11652
11653 \InsetSpace ~
11654
11655 \begin_inset Quotes sld
11656 \end_inset
11657
11658  Install Paths
11659 \begin_inset Quotes srd
11660 \end_inset
11661
11662 .
11663 \end_layout
11664
11665 \begin_layout List
11666 \labelwidthstring 00.00.0000
11667
11668 \series bold
11669 SDCC_INCLUDE
11670 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11671
11672 \end_inset
11673
11674
11675 \series default
11676  Path, see section 
11677 \begin_inset LatexCommand \ref{sub:Search-Paths}
11678
11679 \end_inset
11680
11681 \InsetSpace ~
11682
11683 \begin_inset Quotes sld
11684 \end_inset
11685
11686 Search Paths
11687 \begin_inset Quotes srd
11688 \end_inset
11689
11690 .
11691 \end_layout
11692
11693 \begin_layout List
11694 \labelwidthstring 00.00.0000
11695
11696 \series bold
11697 SDCC_LIB
11698 \begin_inset LatexCommand \index{SDCC\_LIB}
11699
11700 \end_inset
11701
11702
11703 \series default
11704  Path, see section 
11705 \begin_inset LatexCommand \ref{sub:Search-Paths}
11706
11707 \end_inset
11708
11709 \InsetSpace ~
11710
11711 \begin_inset Quotes sld
11712 \end_inset
11713
11714 Search Paths
11715 \begin_inset Quotes srd
11716 \end_inset
11717
11718 ..
11719 \end_layout
11720
11721 \begin_layout Standard
11722 There are some more environment variables recognized by SDCC, but these
11723  are solely used for debugging purposes.
11724  They can change or disappear very quickly, and will never be documented.
11725 \begin_inset VSpace bigskip
11726 \end_inset
11727
11728
11729 \end_layout
11730
11731 \begin_layout Section
11732 Storage Class Language Extensions
11733 \end_layout
11734
11735 \begin_layout Subsection
11736 MCS51/DS390 Storage Class
11737 \begin_inset LatexCommand \index{Storage class}
11738
11739 \end_inset
11740
11741  Language Extensions
11742 \end_layout
11743
11744 \begin_layout Standard
11745 In addition to the ANSI storage classes SDCC allows the following MCS51
11746  specific storage classes:
11747 \end_layout
11748
11749 \begin_layout Subsubsection
11750 data
11751 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11752
11753 \end_inset
11754
11755
11756 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11757
11758 \end_inset
11759
11760  / near
11761 \begin_inset LatexCommand \index{near (storage class)}
11762
11763 \end_inset
11764
11765
11766 \begin_inset LatexCommand \index{\_\_near (storage class)}
11767
11768 \end_inset
11769
11770
11771 \end_layout
11772
11773 \begin_layout Standard
11774 This is the 
11775 \series bold
11776 default
11777 \series default
11778  storage class for the Small Memory model (
11779 \emph on
11780 data
11781 \emph default
11782  and 
11783 \emph on
11784 near
11785 \emph default
11786  or the more ANSI-C compliant forms 
11787 \emph on
11788 __data
11789 \emph default
11790  and 
11791 \emph on
11792 __near
11793 \emph default
11794  can be used synonymously).
11795  Variables declared with this storage class will be allocated in the directly
11796  addressable portion of the internal RAM of a 8051, e.g.:
11797 \end_layout
11798
11799 \begin_layout Verse
11800
11801 \family typewriter
11802 __data unsigned char test_data;
11803 \end_layout
11804
11805 \begin_layout Standard
11806 Writing 0x01 to this variable generates the assembly code:
11807 \end_layout
11808
11809 \begin_layout Verse
11810
11811 \family typewriter
11812 75*00 01\InsetSpace ~
11813 \InsetSpace ~
11814 \InsetSpace ~
11815 mov\InsetSpace ~
11816 \InsetSpace ~
11817 _test_data,#0x01
11818 \end_layout
11819
11820 \begin_layout Subsubsection
11821 xdata
11822 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11823
11824 \end_inset
11825
11826
11827 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11828
11829 \end_inset
11830
11831  / far
11832 \begin_inset LatexCommand \index{far (storage class)}
11833
11834 \end_inset
11835
11836
11837 \begin_inset LatexCommand \index{\_\_far (storage class)}
11838
11839 \end_inset
11840
11841
11842 \end_layout
11843
11844 \begin_layout Standard
11845 Variables declared with this storage class will be placed in the external
11846  RAM.
11847  This is the 
11848 \series bold
11849 default
11850 \series default
11851  storage class for the Large Memory model, e.g.:
11852 \end_layout
11853
11854 \begin_layout Verse
11855
11856 \family typewriter
11857 __xdata unsigned char test_xdata;
11858 \end_layout
11859
11860 \begin_layout Standard
11861 Writing 0x01 to this variable generates the assembly code:
11862 \end_layout
11863
11864 \begin_layout Verse
11865
11866 \family typewriter
11867 90s00r00\InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 mov\InsetSpace ~
11871 \InsetSpace ~
11872 dptr,#_test_xdata 
11873 \newline
11874 74\InsetSpace ~
11875 01\InsetSpace ~
11876 \InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 mov\InsetSpace ~
11882 \InsetSpace ~
11883 a,#0x01 
11884 \newline
11885 F0\InsetSpace ~
11886 \InsetSpace ~
11887 \InsetSpace ~
11888 \InsetSpace ~
11889 \InsetSpace ~
11890 \InsetSpace ~
11891 \InsetSpace ~
11892 \InsetSpace ~
11893 \InsetSpace ~
11894 movx\InsetSpace ~
11895 @dptr,a 
11896 \end_layout
11897
11898 \begin_layout Subsubsection
11899 idata
11900 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11901
11902 \end_inset
11903
11904
11905 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11906
11907 \end_inset
11908
11909
11910 \end_layout
11911
11912 \begin_layout Standard
11913 Variables declared with this storage class will be allocated into the indirectly
11914  addressable portion of the internal ram of a 8051, e.g.:
11915 \end_layout
11916
11917 \begin_layout Verse
11918
11919 \family typewriter
11920 __idata unsigned char test_idata;
11921 \end_layout
11922
11923 \begin_layout Standard
11924 Writing 0x01 to this variable generates the assembly code:
11925 \end_layout
11926
11927 \begin_layout Verse
11928
11929 \family typewriter
11930 78r00\InsetSpace ~
11931 \InsetSpace ~
11932 \InsetSpace ~
11933 \InsetSpace ~
11934 \InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 mov\InsetSpace ~
11938 \InsetSpace ~
11939 r0,#_test_idata
11940 \newline
11941 76\InsetSpace ~
11942 01\InsetSpace ~
11943 \InsetSpace ~
11944 \InsetSpace ~
11945 \InsetSpace ~
11946 \InsetSpace ~
11947 \InsetSpace ~
11948 \InsetSpace ~
11949 mov\InsetSpace ~
11950 \InsetSpace ~
11951 @r0,#0x01
11952 \end_layout
11953
11954 \begin_layout Standard
11955 Please note, the first 128 byte of idata physically access the same RAM
11956  as the data memory.
11957  The original 8051 had 128 byte idata memory, nowadays most devices have
11958  256 byte idata memory.
11959  The stack
11960 \begin_inset LatexCommand \index{stack}
11961
11962 \end_inset
11963
11964  is located in idata memory.
11965 \end_layout
11966
11967 \begin_layout Subsubsection
11968 pdata
11969 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11970
11971 \end_inset
11972
11973
11974 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11975
11976 \end_inset
11977
11978
11979 \end_layout
11980
11981 \begin_layout Standard
11982 Paged xdata access is just as straightforward as using the other addressing
11983  modes of a 8051.
11984  It is typically located at the start of xdata and has a maximum size of
11985  256 bytes.
11986  The following example writes 0x01 to the pdata variable.
11987  Please note, pdata access physically accesses xdata memory.
11988  The high byte of the address is determined by port P2 
11989 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11990
11991 \end_inset
11992
11993 (or in case of some 8051 variants by a separate Special Function Register,
11994  see section 
11995 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11996
11997 \end_inset
11998
11999 ).
12000  This is the 
12001 \series bold
12002 default
12003 \series default
12004  storage class for the Medium Memory model, e.g.:
12005 \end_layout
12006
12007 \begin_layout Verse
12008
12009 \family typewriter
12010 __pdata unsigned char test_pdata;
12011 \end_layout
12012
12013 \begin_layout Standard
12014 Writing 0x01 to this variable generates the assembly code:
12015 \end_layout
12016
12017 \begin_layout Verse
12018
12019 \family typewriter
12020 78r00\InsetSpace ~
12021 \InsetSpace ~
12022 \InsetSpace ~
12023 \InsetSpace ~
12024 \InsetSpace ~
12025 \InsetSpace ~
12026 mov r0,#_test_pdata
12027 \newline
12028 74 01\InsetSpace ~
12029 \InsetSpace ~
12030 \InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 mov a,#0x01 
12035 \newline
12036 F2\InsetSpace ~
12037 \InsetSpace ~
12038 \InsetSpace ~
12039 \InsetSpace ~
12040 \InsetSpace ~
12041 \InsetSpace ~
12042 \InsetSpace ~
12043 \InsetSpace ~
12044 \InsetSpace ~
12045 movx @r0,a
12046 \end_layout
12047
12048 \begin_layout Standard
12049 If the -
12050 \begin_inset ERT
12051 status collapsed
12052
12053 \begin_layout Standard
12054
12055
12056 \backslash
12057 /
12058 \end_layout
12059
12060 \end_inset
12061
12062 -xstack
12063 \begin_inset LatexCommand \index{-\/-xstack}
12064
12065 \end_inset
12066
12067  option is used the pdata memory area is followed by the xstack memory area
12068  and the sum of their sizes is limited to 256 bytes.
12069 \end_layout
12070
12071 \begin_layout Subsubsection
12072 code
12073 \begin_inset LatexCommand \index{code}
12074
12075 \end_inset
12076
12077
12078 \begin_inset LatexCommand \index{\_\_code}
12079
12080 \end_inset
12081
12082
12083 \end_layout
12084
12085 \begin_layout Standard
12086 'Variables' declared with this storage class will be placed in the code
12087  memory:
12088 \end_layout
12089
12090 \begin_layout Verse
12091
12092 \family typewriter
12093 __code unsigned char test_code;
12094 \end_layout
12095
12096 \begin_layout Standard
12097 Read access to this variable generates the assembly code:
12098 \end_layout
12099
12100 \begin_layout Verse
12101
12102 \family typewriter
12103 90s00r6F\InsetSpace ~
12104 \InsetSpace ~
12105 \InsetSpace ~
12106 mov dptr,#_test_code
12107 \newline
12108 E4\InsetSpace ~
12109 \InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 clr a
12118 \newline
12119 93\InsetSpace ~
12120 \InsetSpace ~
12121 \InsetSpace ~
12122 \InsetSpace ~
12123 \InsetSpace ~
12124 \InsetSpace ~
12125 \InsetSpace ~
12126 \InsetSpace ~
12127 \InsetSpace ~
12128 movc a,@a+dptr 
12129 \end_layout
12130
12131 \begin_layout Standard
12132
12133 \family typewriter
12134 char
12135 \family default
12136  indexed arrays of characters in code memory can be accessed efficiently:
12137 \end_layout
12138
12139 \begin_layout Verse
12140
12141 \family typewriter
12142 __code char test_array[] = {'c','h','e','a','p'}; 
12143 \end_layout
12144
12145 \begin_layout Standard
12146 Read access to this array using an 8-bit unsigned index generates the assembly
12147  code:
12148 \end_layout
12149
12150 \begin_layout Verse
12151
12152 \family typewriter
12153 E5*00\InsetSpace ~
12154 \InsetSpace ~
12155 \InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 \InsetSpace ~
12159 mov a,_index 
12160 \end_layout
12161
12162 \begin_layout Verse
12163
12164 \family typewriter
12165 90s00r41\InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 mov dptr,#_test_array
12169 \end_layout
12170
12171 \begin_layout Verse
12172
12173 \family typewriter
12174 93\InsetSpace ~
12175 \InsetSpace ~
12176 \InsetSpace ~
12177 \InsetSpace ~
12178 \InsetSpace ~
12179 \InsetSpace ~
12180 \InsetSpace ~
12181 \InsetSpace ~
12182 \InsetSpace ~
12183 movc a,@a+dptr 
12184 \end_layout
12185
12186 \begin_layout Subsubsection
12187 bit
12188 \begin_inset LatexCommand \index{bit}
12189
12190 \end_inset
12191
12192
12193 \begin_inset LatexCommand \index{\_\_bit}
12194
12195 \end_inset
12196
12197
12198 \end_layout
12199
12200 \begin_layout Standard
12201 This is a data-type and a storage class specifier.
12202  When a variable is declared as a bit, it is allocated into the bit addressable
12203  memory of 8051, e.g.:
12204 \end_layout
12205
12206 \begin_layout Verse
12207
12208 \family typewriter
12209 __bit test_bit;
12210 \end_layout
12211
12212 \begin_layout Standard
12213 Writing 1 to this variable generates the assembly code:
12214 \end_layout
12215
12216 \begin_layout Verse
12217
12218 \family typewriter
12219 D2*00\InsetSpace ~
12220 \InsetSpace ~
12221 \InsetSpace ~
12222 \InsetSpace ~
12223 \InsetSpace ~
12224 \InsetSpace ~
12225 \InsetSpace ~
12226 setb\InsetSpace ~
12227 _test_bit
12228 \end_layout
12229
12230 \begin_layout Standard
12231 The bit addressable memory consists of 128 bits which are located from 0x20
12232  to 0x2f in data memory.
12233  
12234 \newline
12235 Apart from this 8051 specific storage class most architectures support
12236  ANSI-C bitfields
12237 \begin_inset LatexCommand \index{bitfields}
12238
12239 \end_inset
12240
12241
12242 \begin_inset Foot
12243 status open
12244
12245 \begin_layout Standard
12246 Not really meant as examples, but nevertheless showing what bitfields are
12247  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12248 \end_layout
12249
12250 \end_inset
12251
12252 .
12253  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12254  signed modifier are implemented as unsigned.
12255 \end_layout
12256
12257 \begin_layout Subsubsection
12258 sfr
12259 \begin_inset LatexCommand \index{sfr}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_sfr}
12265
12266 \end_inset
12267
12268  / sfr16
12269 \begin_inset LatexCommand \index{sfr16}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr16}
12275
12276 \end_inset
12277
12278  / sfr32
12279 \begin_inset LatexCommand \index{sfr32}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{\_\_sfr32}
12285
12286 \end_inset
12287
12288  / sbit
12289 \begin_inset LatexCommand \index{\_\_sbit}
12290
12291 \end_inset
12292
12293
12294 \begin_inset LatexCommand \index{sbit}
12295
12296 \end_inset
12297
12298
12299 \end_layout
12300
12301 \begin_layout Standard
12302 Like the bit keyword, 
12303 \emph on
12304 sfr / sfr16 / sfr32 / sbit 
12305 \emph default
12306 signify both a data-type and storage class, they are used to describe the
12307  
12308 \emph on
12309 s
12310 \emph default
12311 pecial 
12312 \emph on
12313 f
12314 \emph default
12315 unction 
12316 \emph on
12317 r
12318 \emph default
12319 egisters and 
12320 \emph on
12321 s
12322 \emph default
12323 pecial 
12324 \emph on
12325 bit
12326 \emph default
12327  variables of a 8051, eg:
12328 \end_layout
12329
12330 \begin_layout Verse
12331
12332 \family typewriter
12333 __sfr __at
12334 \begin_inset LatexCommand \index{at}
12335
12336 \end_inset
12337
12338
12339 \begin_inset LatexCommand \index{\_\_at}
12340
12341 \end_inset
12342
12343  (0x80) P0;\InsetSpace ~
12344  /* special function register P0 at location 0x80 */
12345 \newline
12346
12347 \newline
12348 /* 16 bit
12349  special function register combination for timer 0
12350 \newline
12351 \InsetSpace ~
12352 \InsetSpace ~
12353  with the high byte at
12354  location 0x8C and the low byte at location 0x8A */
12355 \newline
12356 __sfr16 __at (0x8C8A)
12357  TMR0;
12358 \newline
12359
12360 \newline
12361 __sbit __at
12362 \begin_inset LatexCommand \index{at}
12363
12364 \end_inset
12365
12366
12367 \begin_inset LatexCommand \index{\_\_at}
12368
12369 \end_inset
12370
12371  (0xd7) CY;\InsetSpace ~
12372  /* CY (Carry Flag
12373 \begin_inset LatexCommand \index{Flags}
12374
12375 \end_inset
12376
12377
12378 \begin_inset LatexCommand \index{Carry flag}
12379
12380 \end_inset
12381
12382 ) */
12383 \end_layout
12384
12385 \begin_layout Standard
12386 Special function registers which are located on an address dividable by
12387  8 are bit-addressable, an
12388 \emph on
12389  sbit
12390 \emph default
12391  addresses a specific bit within these sfr.
12392 \newline
12393 16 Bit and 32 bit special function
12394  register combinations which require a certain access order are better not
12395  declared using 
12396 \emph on
12397 sfr16
12398 \emph default
12399  or 
12400 \emph on
12401 sfr32.
12402
12403 \emph default
12404  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12405  this is not guaranteed.
12406 \newline
12407
12408 \end_layout
12409
12410 \begin_layout Standard
12411 Please note, if you use a header file which was written for another compiler
12412  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12413  likely be 
12414 \emph on
12415 not 
12416 \emph default
12417 compatible.
12418  Specifically the syntax 
12419 \family typewriter
12420 \InsetSpace ~
12421 sfr P0 = 0x80;\InsetSpace ~
12422
12423 \family default
12424  is compiled 
12425 \emph on
12426 without warning
12427 \emph default
12428  by SDCC to an assignment of 0x80 to a variable called P0 
12429 \family typewriter
12430
12431 \begin_inset Marginal
12432 status collapsed
12433
12434 \begin_layout Standard
12435
12436 \series bold
12437 \InsetSpace ~
12438 !
12439 \end_layout
12440
12441 \end_inset
12442
12443 .
12444  
12445 \family default
12446 Nevertheless it is possible to write header files
12447 \begin_inset LatexCommand \index{Header files}
12448
12449 \end_inset
12450
12451
12452 \begin_inset LatexCommand \index{Include files}
12453
12454 \end_inset
12455
12456  which can be shared among different compilers (see section 
12457 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12458
12459 \end_inset
12460
12461 ).
12462  
12463 \end_layout
12464
12465 \begin_layout Subsubsection
12466 Pointers
12467 \begin_inset LatexCommand \index{Pointer}
12468
12469 \end_inset
12470
12471  to MCS51/DS390 specific memory spaces
12472 \end_layout
12473
12474 \begin_layout Standard
12475 SDCC allows (via language extensions) pointers to explicitly point to any
12476  of the memory spaces
12477 \begin_inset LatexCommand \index{Memory model}
12478
12479 \end_inset
12480
12481  of the 8051.
12482  In addition to the explicit pointers, the compiler uses (by default) generic
12483  pointers which can be used to point to any of the memory spaces.
12484 \newline
12485
12486 \newline
12487 Pointer
12488  declaration examples:
12489 \end_layout
12490
12491 \begin_layout Verse
12492
12493 \family typewriter
12494 /* pointer physically in internal ram pointing to object in external ram
12495  */ 
12496 \newline
12497 __xdata unsigned char * __data p;
12498 \newline
12499
12500 \newline
12501 /* pointer physically in external ram
12502  pointing to object in internal ram */ 
12503 \newline
12504 __data unsigned char * __xdata p;
12505 \newline
12506
12507 \newline
12508 /*
12509  pointer physically in code rom pointing to data in xdata space */ 
12510 \newline
12511 __xdata
12512  unsigned char * __code p;
12513 \newline
12514
12515 \newline
12516 /* pointer physically in code space pointing to
12517  data in code space */ 
12518 \newline
12519 __code unsigned char * __code p;
12520 \newline
12521
12522 \newline
12523 /* generic pointer
12524  physically located in xdata space */
12525 \newline
12526 unsigned char * __xdata p;
12527 \newline
12528
12529 \newline
12530 /* generic
12531  pointer physically located in default memory space */
12532 \newline
12533 unsigned char * p;
12534 \newline
12535
12536 \newline
12537 /*
12538  the following is a function pointer
12539 \begin_inset LatexCommand \index{function pointer}
12540
12541 \end_inset
12542
12543  physically located in data space */
12544 \newline
12545 char (* __data fp)(void);
12546 \end_layout
12547
12548 \begin_layout Standard
12549 Well you get the idea.
12550  
12551 \newline
12552
12553 \newline
12554 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12555 \emph on
12556 generic
12557 \emph default
12558  pointers.
12559  
12560 \size small
12561
12562 \newline
12563
12564 \newline
12565
12566 \size default
12567 The highest order byte of the 
12568 \emph on
12569 generic
12570 \emph default
12571  pointers contains the data space information.
12572  Assembler support routines are called whenever data is stored or retrieved
12573  using 
12574 \emph on
12575 generic
12576 \emph default
12577  pointers.
12578  These are useful for developing reusable library
12579 \begin_inset LatexCommand \index{Libraries}
12580
12581 \end_inset
12582
12583  routines.
12584  Explicitly specifying the pointer
12585 \begin_inset LatexCommand \index{pointer}
12586
12587 \end_inset
12588
12589  type will generate the most efficient code.
12590 \end_layout
12591
12592 \begin_layout Subsubsection
12593 Notes on MCS51 memory
12594 \begin_inset LatexCommand \index{MCS51 memory}
12595
12596 \end_inset
12597
12598  layout
12599 \end_layout
12600
12601 \begin_layout Standard
12602 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12603  RAM memory which is structured as follows:
12604 \newline
12605
12606 \newline
12607 - Bytes 00-1F - 32 bytes to hold
12608  up to 4 banks of the registers R0 to R7, 
12609 \newline
12610 - Bytes 20-2F - 16 bytes to hold
12611  128 bit
12612 \begin_inset LatexCommand \index{bit}
12613
12614 \end_inset
12615
12616  variables and, 
12617 \newline
12618 - Bytes 30-7F - 80 bytes for general purpose use.
12619 \newline
12620
12621 \end_layout
12622
12623 \begin_layout Standard
12624 Additionally some members of the MCS51 family may have up to 128 bytes of
12625  additional, indirectly addressable, internal RAM memory (
12626 \emph on
12627 idata
12628 \emph default
12629
12630 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12631
12632 \end_inset
12633
12634
12635 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12636
12637 \end_inset
12638
12639 ).
12640  Furthermore, some chips may have some built in external memory (
12641 \emph on
12642 xdata
12643 \emph default
12644
12645 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12646
12647 \end_inset
12648
12649
12650 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12651
12652 \end_inset
12653
12654 ) which should not be confused with the internal, directly addressable RAM
12655  memory (
12656 \emph on
12657 data
12658 \emph default
12659
12660 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12661
12662 \end_inset
12663
12664
12665 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12666
12667 \end_inset
12668
12669 ).
12670  Sometimes this built in 
12671 \emph on
12672 xdata
12673 \emph default
12674  memory has to be activated before using it (you can probably find this
12675  information on the datasheet of the microcontroller your are using, see
12676  also section 
12677 \begin_inset LatexCommand \ref{sub:Startup-Code}
12678
12679 \end_inset
12680
12681 \InsetSpace ~
12682 Startup-Code).
12683 \end_layout
12684
12685 \begin_layout Standard
12686 Normally SDCC will only use the first bank
12687 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12688
12689 \end_inset
12690
12691  of registers (register bank 0), but it is possible to specify that other
12692  banks of registers (keyword 
12693 \emph on
12694 using
12695 \emph default
12696  
12697 \emph on
12698
12699 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12700
12701 \end_inset
12702
12703
12704 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12705
12706 \end_inset
12707
12708
12709 \emph default
12710 ) should be used for example in interrupt
12711 \begin_inset LatexCommand \index{interrupt}
12712
12713 \end_inset
12714
12715
12716 \begin_inset LatexCommand \index{\_\_interrupt}
12717
12718 \end_inset
12719
12720  routines.
12721  By default, the compiler will place the stack after the last byte of allocated
12722  memory for variables.
12723  For example, if the first 2 banks of registers are used, and only four
12724  bytes are used for 
12725 \emph on
12726 data
12727 \emph default
12728  variables, it will position the base of the internal stack at address 20
12729  (0x14).
12730  This implies that as the stack
12731 \begin_inset LatexCommand \index{stack}
12732
12733 \end_inset
12734
12735  grows, it will use up the remaining register banks, and the 16 bytes used
12736  by the 128 bit variables, and 80 bytes for general purpose use.
12737  If any bit variables are used, the data variables will be placed in unused
12738  register banks and after the byte holding the last bit variable.
12739  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12740  (two bytes used), 
12741 \emph on
12742 data
12743 \emph default
12744  variables will be placed starting from address 0x10 to 0x20 and continue
12745  at address 0x22.
12746  You can also use -
12747 \begin_inset ERT
12748 status collapsed
12749
12750 \begin_layout Standard
12751
12752
12753 \backslash
12754 /
12755 \end_layout
12756
12757 \end_inset
12758
12759 -data-loc
12760 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12761
12762 \end_inset
12763
12764  to specify the start address of the 
12765 \emph on
12766 data
12767 \emph default
12768  and -
12769 \begin_inset ERT
12770 status collapsed
12771
12772 \begin_layout Standard
12773
12774
12775 \backslash
12776 /
12777 \end_layout
12778
12779 \end_inset
12780
12781 -iram-size
12782 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12783
12784 \end_inset
12785
12786  to specify the size of the total internal RAM (
12787 \emph on
12788 data
12789 \emph default
12790 +
12791 \emph on
12792 idata
12793 \emph default
12794 ).
12795  
12796 \newline
12797
12798 \end_layout
12799
12800 \begin_layout Standard
12801 By default the 8051 linker will place the stack after the last byte of (i)data
12802  variables.
12803  Option -
12804 \begin_inset ERT
12805 status collapsed
12806
12807 \begin_layout Standard
12808
12809
12810 \backslash
12811 /
12812 \end_layout
12813
12814 \end_inset
12815
12816 -stack-loc
12817 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12818
12819 \end_inset
12820
12821  allows you to specify the start of the stack, i.e.
12822  you could start it after any data in the general purpose area.
12823  If your microcontroller has additional indirectly addressable internal
12824  RAM (
12825 \emph on
12826 idata
12827 \emph default
12828 ) you can place the stack on it.
12829  You may also need to use -
12830 \begin_inset ERT
12831 status collapsed
12832
12833 \begin_layout Standard
12834
12835
12836 \backslash
12837 /
12838 \end_layout
12839
12840 \end_inset
12841
12842 -xdata-loc
12843 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12844
12845 \end_inset
12846
12847  to set the start address of the external RAM (
12848 \emph on
12849 xdata
12850 \emph default
12851 ) and -
12852 \begin_inset ERT
12853 status collapsed
12854
12855 \begin_layout Standard
12856
12857
12858 \backslash
12859 /
12860 \end_layout
12861
12862 \end_inset
12863
12864 -xram-size
12865 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12866
12867 \end_inset
12868
12869  to specify its size.
12870  Same goes for the code memory, using -
12871 \begin_inset ERT
12872 status collapsed
12873
12874 \begin_layout Standard
12875
12876
12877 \backslash
12878 /
12879 \end_layout
12880
12881 \end_inset
12882
12883 -code-loc
12884 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12885
12886 \end_inset
12887
12888  and -
12889 \begin_inset ERT
12890 status collapsed
12891
12892 \begin_layout Standard
12893
12894
12895 \backslash
12896 /
12897 \end_layout
12898
12899 \end_inset
12900
12901 -code-size
12902 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12903
12904 \end_inset
12905
12906 .
12907  If in doubt, don't specify any options and see if the resulting memory
12908  layout is appropriate, then you can adjust it.
12909 \end_layout
12910
12911 \begin_layout Standard
12912 The linker generates two files with memory allocation information.
12913  The first, with extension .map
12914 \begin_inset LatexCommand \index{<file>.map}
12915
12916 \end_inset
12917
12918  shows all the variables and segments.
12919  The second with extension .mem
12920 \begin_inset LatexCommand \index{<file>.mem}
12921
12922 \end_inset
12923
12924  shows the final memory layout.
12925  The linker will complain either if memory segments overlap, there is not
12926  enough memory, or there is not enough space for stack.
12927  If you get any linking warnings and/or errors related to stack or segments
12928  allocation, take a look at either the .map or .mem files to find out what
12929  the problem is.
12930  The .mem file may even suggest a solution to the problem.
12931 \begin_inset VSpace bigskip
12932 \end_inset
12933
12934
12935 \end_layout
12936
12937 \begin_layout Subsection
12938 Z80/Z180 Storage Class
12939 \begin_inset LatexCommand \index{Z80!Storage class}
12940
12941 \end_inset
12942
12943  Language Extensions
12944 \end_layout
12945
12946 \begin_layout Subsubsection
12947 sfr
12948 \begin_inset LatexCommand \index{sfr}
12949
12950 \end_inset
12951
12952
12953 \begin_inset LatexCommand \index{\_\_sfr}
12954
12955 \end_inset
12956
12957  (in/out to 8-bit addresses)
12958 \end_layout
12959
12960 \begin_layout Standard
12961 The Z80
12962 \begin_inset LatexCommand \index{Z80}
12963
12964 \end_inset
12965
12966  family has separate address spaces for memory and 
12967 \emph on
12968 i
12969 \emph default
12970 nput/
12971 \emph on
12972 o
12973 \emph default
12974 utput memory.
12975  I/O memory
12976 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12977
12978 \end_inset
12979
12980
12981 \begin_inset LatexCommand \index{Z80!I/O memory}
12982
12983 \end_inset
12984
12985
12986 \begin_inset LatexCommand \index{Z180!I/O memory}
12987
12988 \end_inset
12989
12990  is accessed with special instructions, e.g.:
12991 \end_layout
12992
12993 \begin_layout Verse
12994
12995 \family typewriter
12996 sfr at 0x78 IoPort;\InsetSpace ~
12997 \InsetSpace ~
12998 /* define a var in I/O space at 78h called IoPort */
12999  
13000 \end_layout
13001
13002 \begin_layout Standard
13003 Writing 0x01 to this variable generates the assembly code:
13004 \end_layout
13005
13006 \begin_layout Verse
13007
13008 \family typewriter
13009 3E 01\InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 ld a,#0x01
13016 \newline
13017 D3 78\InsetSpace ~
13018 \InsetSpace ~
13019 \InsetSpace ~
13020 \InsetSpace ~
13021 \InsetSpace ~
13022 \InsetSpace ~
13023 out (_IoPort),a 
13024 \end_layout
13025
13026 \begin_layout Subsubsection
13027 banked sfr
13028 \begin_inset LatexCommand \index{sfr}
13029
13030 \end_inset
13031
13032
13033 \begin_inset LatexCommand \index{\_\_sfr}
13034
13035 \end_inset
13036
13037  (in/out to 16-bit addresses)
13038 \end_layout
13039
13040 \begin_layout Standard
13041 The keyword 
13042 \emph on
13043 banked
13044 \emph default
13045  is used to support 16 bit addresses in I/O memory e.g.:
13046 \end_layout
13047
13048 \begin_layout Verse
13049
13050 \family typewriter
13051 sfr banked at
13052 \begin_inset LatexCommand \index{at}
13053
13054 \end_inset
13055
13056
13057 \begin_inset LatexCommand \index{\_\_at}
13058
13059 \end_inset
13060
13061  0x123 IoPort; 
13062 \end_layout
13063
13064 \begin_layout Standard
13065 Writing 0x01 to this variable generates the assembly code:
13066 \end_layout
13067
13068 \begin_layout Verse
13069
13070 \family typewriter
13071 01 23 01\InsetSpace ~
13072 \InsetSpace ~
13073 \InsetSpace ~
13074 ld bc,#_IoPort
13075 \newline
13076 3E 01\InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 \InsetSpace ~
13081 \InsetSpace ~
13082 ld a,#0x01 
13083 \newline
13084 ED 79\InsetSpace ~
13085 \InsetSpace ~
13086 \InsetSpace ~
13087 \InsetSpace ~
13088 \InsetSpace ~
13089 \InsetSpace ~
13090 out (c),a 
13091 \end_layout
13092
13093 \begin_layout Subsubsection
13094 sfr
13095 \begin_inset LatexCommand \index{sfr}
13096
13097 \end_inset
13098
13099
13100 \begin_inset LatexCommand \index{\_\_sfr}
13101
13102 \end_inset
13103
13104  (in0/out0 to 8 bit addresses on Z180
13105 \begin_inset LatexCommand \index{Z180}
13106
13107 \end_inset
13108
13109 /HD64180
13110 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13111
13112 \end_inset
13113
13114 )
13115 \end_layout
13116
13117 \begin_layout Standard
13118 The compiler option -
13119 \begin_inset ERT
13120 status collapsed
13121
13122 \begin_layout Standard
13123
13124
13125 \backslash
13126 /
13127 \end_layout
13128
13129 \end_inset
13130
13131 -portmode
13132 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13133
13134 \end_inset
13135
13136 =180 (80) and a compiler #pragma\InsetSpace ~
13137 portmode
13138 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13139
13140 \end_inset
13141
13142  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13143 ns 
13144 \family typewriter
13145 in0/out0
13146 \family default
13147  instead of 
13148 \family typewriter
13149 in/out
13150 \family default
13151 .
13152  If you include the file z180.h this will be set automatically.
13153 \begin_inset VSpace bigskip
13154 \end_inset
13155
13156
13157 \end_layout
13158
13159 \begin_layout Subsection
13160 HC08 Storage Class
13161 \begin_inset LatexCommand \index{HC08!Storage class}
13162
13163 \end_inset
13164
13165  Language Extensions
13166 \end_layout
13167
13168 \begin_layout Subsubsection
13169 data
13170 \begin_inset LatexCommand \index{data (hc08 storage class)}
13171
13172 \end_inset
13173
13174
13175 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13176
13177 \end_inset
13178
13179  
13180 \end_layout
13181
13182 \begin_layout Standard
13183 The data storage class declares a variable that resides in the first 256
13184  bytes of memory (the direct page).
13185  The HC08
13186 \begin_inset LatexCommand \index{HC08}
13187
13188 \end_inset
13189
13190  is most efficient at accessing variables (especially pointers) stored here.
13191 \end_layout
13192
13193 \begin_layout Subsubsection
13194 xdata
13195 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13196
13197 \end_inset
13198
13199
13200 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13201
13202 \end_inset
13203
13204  
13205 \end_layout
13206
13207 \begin_layout Standard
13208 The xdata storage class declares a variable that can reside anywhere in
13209  memory.
13210  This is the default if no storage class is specified.
13211  
13212 \begin_inset VSpace bigskip
13213 \end_inset
13214
13215
13216 \end_layout
13217
13218 \begin_layout Section
13219 Absolute Addressing
13220 \begin_inset LatexCommand \index{Absolute addressing}
13221
13222 \end_inset
13223
13224
13225 \end_layout
13226
13227 \begin_layout Standard
13228 Data items can be assigned an absolute address with the 
13229 \emph on
13230 at
13231 \begin_inset LatexCommand \index{at}
13232
13233 \end_inset
13234
13235
13236 \begin_inset LatexCommand \index{\_\_at}
13237
13238 \end_inset
13239
13240  <address>
13241 \emph default
13242  keyword, in addition to a storage class, e.g.:
13243 \end_layout
13244
13245 \begin_layout Verse
13246
13247 \family typewriter
13248 xdata
13249 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13250
13251 \end_inset
13252
13253
13254 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13255
13256 \end_inset
13257
13258  at
13259 \begin_inset LatexCommand \index{at}
13260
13261 \end_inset
13262
13263
13264 \begin_inset LatexCommand \index{\_\_at}
13265
13266 \end_inset
13267
13268  0x7ffe unsigned int chksum;
13269 \end_layout
13270
13271 \begin_layout Standard
13272 or, better conforming to ISO/IEC 9899 C:
13273 \end_layout
13274
13275 \begin_layout Verse
13276
13277 \family typewriter
13278 __xdata __at (0x7ffe) unsigned int chksum;
13279 \end_layout
13280
13281 \begin_layout Standard
13282 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13283  of the external ram.
13284  The compiler does 
13285 \emph on
13286 not
13287 \emph default
13288  reserve any space for variables declared in this way
13289 \begin_inset Marginal
13290 status collapsed
13291
13292 \begin_layout Standard
13293
13294 \series bold
13295 \InsetSpace ~
13296 !
13297 \end_layout
13298
13299 \end_inset
13300
13301  (they are implemented with an equate in the assembler).
13302  Thus it is left to the programmer to make sure there are no overlaps with
13303  other variables that are declared without the absolute address.
13304  The assembler listing file (.lst
13305 \begin_inset LatexCommand \index{<file>.lst}
13306
13307 \end_inset
13308
13309 ) and the linker output files (.rst
13310 \begin_inset LatexCommand \index{<file>.rst}
13311
13312 \end_inset
13313
13314 ) and (.map
13315 \begin_inset LatexCommand \index{<file>.map}
13316
13317 \end_inset
13318
13319 ) are good places to look for such overlaps.
13320 \end_layout
13321
13322 \begin_layout Standard
13323 If however you provide an initializer
13324 \begin_inset LatexCommand \index{Variable initialization}
13325
13326 \end_inset
13327
13328  actual memory allocation will take place and overlaps will be detected
13329  by the linker.
13330  E.g.:
13331 \end_layout
13332
13333 \begin_layout Verse
13334
13335 \family typewriter
13336 __code __at (0x7ff0) char Id[5] = 
13337 \begin_inset Quotes sld
13338 \end_inset
13339
13340 SDCC
13341 \begin_inset Quotes srd
13342 \end_inset
13343
13344 ;
13345 \end_layout
13346
13347 \begin_layout Standard
13348 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13349  in code memory.
13350 \end_layout
13351
13352 \begin_layout Standard
13353 In case of memory mapped I/O devices the keyword 
13354 \emph on
13355 volatile
13356 \emph default
13357  has to be used to tell the compiler that accesses might not be removed:
13358 \end_layout
13359
13360 \begin_layout Verse
13361
13362 \family typewriter
13363 volatile
13364 \begin_inset LatexCommand \index{volatile}
13365
13366 \end_inset
13367
13368  __xdata
13369 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13370
13371 \end_inset
13372
13373  __at
13374 \begin_inset LatexCommand \index{at}
13375
13376 \end_inset
13377
13378  (0x8000) unsigned char PORTA_8255;
13379 \end_layout
13380
13381 \begin_layout Standard
13382 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13383 r) array
13384 \family typewriter
13385 \size footnotesize
13386
13387 \begin_inset LatexCommand \index{Aligned array}
13388
13389 \end_inset
13390
13391
13392 \family default
13393 \size default
13394  starts at a block (256 byte) boundary
13395 \begin_inset LatexCommand \index{block boundary}
13396
13397 \end_inset
13398
13399  (section 
13400 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13401
13402 \end_inset
13403
13404  has an example).
13405 \newline
13406 Absolute addresses can be specified for variables in all
13407  storage classes, e.g.:
13408 \end_layout
13409
13410 \begin_layout Verse
13411
13412 \family typewriter
13413 __bit
13414 \begin_inset LatexCommand \index{bit}
13415
13416 \end_inset
13417
13418  __at
13419 \begin_inset LatexCommand \index{at}
13420
13421 \end_inset
13422
13423  (0x02) bvar;
13424 \end_layout
13425
13426 \begin_layout Standard
13427 The above example will allocate the variable at offset 0x02 in the bit-addressab
13428 le space.
13429  There is no real advantage to assigning absolute addresses to variables
13430  in this manner, unless you want strict control over all the variables allocated.
13431  One possible use would be to write hardware portable code.
13432  For example, if you have a routine that uses one or more of the microcontroller
13433  I/O pins, and such pins are different for two different hardwares, you
13434  can declare the I/O pins in your routine using:
13435 \end_layout
13436
13437 \begin_layout Verse
13438
13439 \family typewriter
13440 extern volatile
13441 \begin_inset LatexCommand \index{volatile}
13442
13443 \end_inset
13444
13445  __bit MOSI;\InsetSpace ~
13446 \InsetSpace ~
13447 \InsetSpace ~
13448 \InsetSpace ~
13449 /* master out, slave in */
13450 \newline
13451 extern volatile __bit MISO;\InsetSpace ~
13452 \InsetSpace ~
13453 \InsetSpace ~
13454 \InsetSpace ~
13455 /* master
13456  in, slave out */
13457 \newline
13458 extern volatile __bit MCLK;\InsetSpace ~
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 /* master clock */
13463 \newline
13464
13465 \newline
13466 /* Input and
13467  Output of a byte on a 3-wire serial bus.
13468 \newline
13469 \InsetSpace ~
13470 \InsetSpace ~
13471 \InsetSpace ~
13472 If needed adapt polarity of clock,
13473  polarity of data and bit order
13474 \newline
13475 \InsetSpace ~
13476 */
13477 \newline
13478 unsigned char spi_io(unsigned char out_byte)
13479  
13480 \newline
13481
13482 \newline
13483 \InsetSpace ~
13484 \InsetSpace ~
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 unsigned char i=8;
13488 \newline
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 do { 
13494 \newline
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 MOSI = out_byte & 0x80; 
13504 \newline
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 out_byte <<= 1;
13514 \newline
13515 \InsetSpace ~
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 MCLK =
13524  1; 
13525 \newline
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 \InsetSpace ~
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 \InsetSpace ~
13533 \InsetSpace ~
13534 /* _asm nop _endasm; */\InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 \InsetSpace ~
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 /* for slow peripherals */
13543 \newline
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 if(MISO) 
13553 \newline
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 \InsetSpace ~
13557 \InsetSpace ~
13558 \InsetSpace ~
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 out_byte +=
13567  1; 
13568 \newline
13569 \InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 \InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 MCLK = 0; 
13578 \newline
13579 \InsetSpace ~
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 } while(--i);
13584 \newline
13585 \InsetSpace ~
13586 \InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 return out_byte; 
13590 \newline
13591 }
13592 \end_layout
13593
13594 \begin_layout Standard
13595 Then, someplace in the code for the first hardware you would use
13596 \end_layout
13597
13598 \begin_layout Verse
13599
13600 \family typewriter
13601 __bit __at
13602 \begin_inset LatexCommand \index{at}
13603
13604 \end_inset
13605
13606
13607 \begin_inset LatexCommand \index{\_\_at}
13608
13609 \end_inset
13610
13611  (0x80) MOSI;\InsetSpace ~
13612 \InsetSpace ~
13613 \InsetSpace ~
13614 \InsetSpace ~
13615 /* I/O port 0, bit 0 */
13616 \newline
13617 __bit __at (0x81) MISO;\InsetSpace ~
13618 \InsetSpace ~
13619 \InsetSpace ~
13620 \InsetSpace ~
13621 /* I/O port 0,
13622  bit 1 */
13623 \newline
13624 __bit __at (0x82) MCLK;\InsetSpace ~
13625 \InsetSpace ~
13626 \InsetSpace ~
13627 \InsetSpace ~
13628 /* I/O port 0, bit 2 */
13629 \end_layout
13630
13631 \begin_layout Standard
13632 Similarly, for the second hardware you would use
13633 \end_layout
13634
13635 \begin_layout Verse
13636
13637 \family typewriter
13638 __bit __at (0x83) MOSI;\InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 /* I/O port 0, bit 3 */
13643 \newline
13644 __bit __at (0x91) MISO;\InsetSpace ~
13645 \InsetSpace ~
13646 \InsetSpace ~
13647 \InsetSpace ~
13648 /*
13649  I/O port 1, bit 1 */
13650 \newline
13651 __bit
13652 \begin_inset LatexCommand \index{bit}
13653
13654 \end_inset
13655
13656  __at (0x92) MCLK;\InsetSpace ~
13657 \InsetSpace ~
13658 \InsetSpace ~
13659 \InsetSpace ~
13660 /* I/O port 1, bit 2 */
13661 \end_layout
13662
13663 \begin_layout Standard
13664 and you can use the same hardware dependent routine without changes, as
13665  for example in a library.
13666  This is somehow similar to sbit, but only one absolute address has to be
13667  specified in the whole project.
13668 \begin_inset VSpace bigskip
13669 \end_inset
13670
13671
13672 \end_layout
13673
13674 \begin_layout Section
13675 Parameters
13676 \begin_inset LatexCommand \index{Parameters}
13677
13678 \end_inset
13679
13680
13681 \begin_inset LatexCommand \index{function parameter}
13682
13683 \end_inset
13684
13685  & Local Variables
13686 \begin_inset LatexCommand \index{local variables}
13687
13688 \end_inset
13689
13690
13691 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13692
13693 \end_inset
13694
13695
13696 \end_layout
13697
13698 \begin_layout Standard
13699 Automatic (local) variables and parameters to functions can either be placed
13700  on the stack or in data-space.
13701  The default action of the compiler is to place these variables in the internal
13702  RAM (for small model) or external RAM (for medium or large model).
13703  This in fact makes them similar to 
13704 \emph on
13705 static
13706 \begin_inset LatexCommand \index{static}
13707
13708 \end_inset
13709
13710
13711 \emph default
13712  so by default functions are non-reentrant
13713 \begin_inset LatexCommand \index{reentrant}
13714
13715 \end_inset
13716
13717 .
13718  
13719 \newline
13720
13721 \newline
13722 They can be placed on the stack
13723 \begin_inset LatexCommand \index{stack}
13724
13725 \end_inset
13726
13727  by using 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 \begin_inset LatexCommand \index{-\/-stack-auto}
13744
13745 \end_inset
13746
13747
13748 \emph default
13749  option, by using 
13750 \emph on
13751 #pragma\InsetSpace ~
13752 stackauto
13753 \emph default
13754
13755 \begin_inset LatexCommand \index{\#pragma stackauto}
13756
13757 \end_inset
13758
13759  or by using the 
13760 \emph on
13761 reentrant
13762 \begin_inset LatexCommand \index{reentrant}
13763
13764 \end_inset
13765
13766
13767 \emph default
13768  keyword in the function declaration, e.g.:
13769 \end_layout
13770
13771 \begin_layout Verse
13772
13773 \family typewriter
13774 unsigned char foo(char i) __reentrant 
13775 \newline
13776
13777 \newline
13778 \InsetSpace ~
13779 \InsetSpace ~
13780 \InsetSpace ~
13781 \InsetSpace ~
13782 ...
13783  
13784 \newline
13785 }
13786 \end_layout
13787
13788 \begin_layout Standard
13789 Since stack space on 8051 is limited, the 
13790 \emph on
13791 reentrant 
13792 \emph default
13793 keyword or the
13794 \emph on
13795  -
13796 \begin_inset ERT
13797 status collapsed
13798
13799 \begin_layout Standard
13800
13801
13802 \backslash
13803 /
13804 \end_layout
13805
13806 \end_inset
13807
13808 -stack-auto
13809 \emph default
13810  option should be used sparingly.
13811  Note that the reentrant keyword just means that the parameters & local
13812  variables will be allocated to the stack, it 
13813 \emph on
13814 does not
13815 \emph default
13816  mean that the function is register bank
13817 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13818
13819 \end_inset
13820
13821  independent.
13822 \newline
13823
13824 \newline
13825 Local variables
13826 \begin_inset LatexCommand \index{local variables}
13827
13828 \end_inset
13829
13830  can be assigned storage classes and absolute
13831 \begin_inset LatexCommand \index{Absolute addressing}
13832
13833 \end_inset
13834
13835  addresses, e.g.: 
13836 \end_layout
13837
13838 \begin_layout Verse
13839
13840 \family typewriter
13841 unsigned char foo() 
13842 \newline
13843 {
13844 \newline
13845 \InsetSpace ~
13846 \InsetSpace ~
13847 \InsetSpace ~
13848 \InsetSpace ~
13849 __xdata unsigned char i;
13850 \newline
13851 \InsetSpace ~
13852 \InsetSpace ~
13853 \InsetSpace ~
13854 \InsetSpace ~
13855 __bit bvar;
13856 \newline
13857 \InsetSpace ~
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 __data __at
13862 \begin_inset LatexCommand \index{at}
13863
13864 \end_inset
13865
13866  (0x31) unsigned char j;
13867 \newline
13868 \InsetSpace ~
13869 \InsetSpace ~
13870 \InsetSpace ~
13871 \InsetSpace ~
13872 ...
13873  
13874 \newline
13875 }
13876 \end_layout
13877
13878 \begin_layout Standard
13879 In the above example the variable 
13880 \emph on
13881 i
13882 \emph default
13883  will be allocated in the external ram, 
13884 \emph on
13885 bvar
13886 \emph default
13887  in bit addressable space and
13888 \emph on
13889  j
13890 \emph default
13891  in internal ram.
13892  When compiled with 
13893 \emph on
13894 -
13895 \begin_inset ERT
13896 status collapsed
13897
13898 \begin_layout Standard
13899
13900
13901 \backslash
13902 /
13903 \end_layout
13904
13905 \end_inset
13906
13907 -stack-auto
13908 \emph default
13909  or when a function is declared as 
13910 \emph on
13911 reentrant
13912 \emph default
13913  this should only be done for static variables.
13914 \end_layout
13915
13916 \begin_layout Standard
13917 Parameters
13918 \begin_inset LatexCommand \index{function parameter}
13919
13920 \end_inset
13921
13922  however are not allowed any storage class
13923 \begin_inset LatexCommand \index{Storage class}
13924
13925 \end_inset
13926
13927 , (storage classes for parameters will be ignored), their allocation is
13928  governed by the memory model in use, and the reentrancy options.
13929 \end_layout
13930
13931 \begin_layout Standard
13932 It is however allowed to use bit parameters in reentrant functions and also
13933  non-static local bit variables are supported.
13934  Efficient use is limited to 8 semi-bitregisters in bit space.
13935  They are pushed and popped to stack
13936 \begin_inset LatexCommand \index{stack}
13937
13938 \end_inset
13939
13940  as a single byte just like the normal registers.
13941 \end_layout
13942
13943 \begin_layout Section
13944 Overlaying
13945 \begin_inset LatexCommand \label{sub:Overlaying}
13946
13947 \end_inset
13948
13949
13950 \begin_inset LatexCommand \index{Overlaying}
13951
13952 \end_inset
13953
13954
13955 \end_layout
13956
13957 \begin_layout Standard
13958 For non-reentrant
13959 \begin_inset LatexCommand \index{reentrant}
13960
13961 \end_inset
13962
13963  functions SDCC will try to reduce internal ram space usage by overlaying
13964  parameters and local variables of a function (if possible).
13965  Parameters and local variables
13966 \begin_inset LatexCommand \index{local variables}
13967
13968 \end_inset
13969
13970  of a function will be allocated to an overlayable segment if the function
13971  has 
13972 \emph on
13973 no other function calls and the function is non-reentrant and the memory
13974  model
13975 \begin_inset LatexCommand \index{Memory model}
13976
13977 \end_inset
13978
13979  is small.
13980
13981 \emph default
13982  If an explicit storage class
13983 \begin_inset LatexCommand \index{Storage class}
13984
13985 \end_inset
13986
13987  is specified for a local variable, it will NOT be overlayed.
13988 \end_layout
13989
13990 \begin_layout Standard
13991 Note that the compiler (not the linkage editor) makes the decision for overlayin
13992 g the data items.
13993  Functions that are called from an interrupt service routine
13994 \begin_inset Marginal
13995 status collapsed
13996
13997 \begin_layout Standard
13998
13999 \series bold
14000 !
14001 \end_layout
14002
14003 \end_inset
14004
14005  should be preceded by a #pragma\InsetSpace ~
14006 nooverlay
14007 \begin_inset LatexCommand \index{\#pragma nooverlay}
14008
14009 \end_inset
14010
14011  if they are not reentrant.
14012 \end_layout
14013
14014 \begin_layout Standard
14015 Also note that the compiler does not do any processing of inline assembler
14016  code, so the compiler might incorrectly assign local variables and parameters
14017  of a function into the overlay segment if the inline assembler code calls
14018  other c-functions that might use the overlay.
14019  In that case the #pragma\InsetSpace ~
14020 nooverlay should be used.
14021 \end_layout
14022
14023 \begin_layout Standard
14024 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14025 tion
14026 \begin_inset LatexCommand \index{Multiplication}
14027
14028 \end_inset
14029
14030  or division
14031 \begin_inset LatexCommand \index{Division}
14032
14033 \end_inset
14034
14035  will NOT be overlayed since these are implemented using external functions,
14036  e.g.:
14037 \end_layout
14038
14039 \begin_layout Verse
14040
14041 \family typewriter
14042 #pragma save 
14043 \newline
14044 #pragma nooverlay
14045 \begin_inset LatexCommand \index{\#pragma nooverlay}
14046
14047 \end_inset
14048
14049  
14050 \newline
14051 void set_error(unsigned char errcd) 
14052 \newline
14053 {
14054 \newline
14055 \InsetSpace ~
14056 \InsetSpace ~
14057 \InsetSpace ~
14058 \InsetSpace ~
14059 P3 = errcd;
14060 \newline
14061
14062 \newline
14063 #pragma restore 
14064 \newline
14065
14066 \newline
14067 void
14068  some_isr () __interrupt
14069 \begin_inset LatexCommand \index{interrupt}
14070
14071 \end_inset
14072
14073  (2)
14074 \newline
14075 {
14076 \newline
14077 \InsetSpace ~
14078 \InsetSpace ~
14079 \InsetSpace ~
14080 \InsetSpace ~
14081 ...
14082 \newline
14083 \InsetSpace ~
14084 \InsetSpace ~
14085 \InsetSpace ~
14086 \InsetSpace ~
14087 set_error(10);
14088 \newline
14089 \InsetSpace ~
14090 \InsetSpace ~
14091 \InsetSpace ~
14092 \InsetSpace ~
14093 ...
14094  
14095 \newline
14096 }
14097 \end_layout
14098
14099 \begin_layout Standard
14100 In the above example the parameter 
14101 \emph on
14102 errcd
14103 \emph default
14104  for the function 
14105 \emph on
14106 set_error
14107 \emph default
14108  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14109 nooverlay was
14110  not present, this could cause unpredictable runtime behavior when called
14111  from an interrupt service routine.
14112  The #pragma\InsetSpace ~
14113 nooverlay ensures that the parameters and local variables for
14114  the function are NOT overlayed.
14115 \begin_inset VSpace bigskip
14116 \end_inset
14117
14118
14119 \end_layout
14120
14121 \begin_layout Section
14122 Interrupt Service Routines
14123 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14124
14125 \end_inset
14126
14127
14128 \end_layout
14129
14130 \begin_layout Subsection
14131 General Information
14132 \end_layout
14133
14134 \begin_layout Standard
14135 SDCC allows 
14136 \emph on
14137 i
14138 \emph default
14139 nterrupt 
14140 \emph on
14141 s
14142 \emph default
14143 ervice 
14144 \emph on
14145 r
14146 \emph default
14147 outines to be coded in C, with some extended keywords.
14148 \end_layout
14149
14150 \begin_layout Verse
14151
14152 \family typewriter
14153 void timer_isr (void) __interrupt (1) __using (1) 
14154 \newline
14155
14156 \newline
14157 \InsetSpace ~
14158 \InsetSpace ~
14159 \InsetSpace ~
14160 \InsetSpace ~
14161 ...
14162  
14163 \newline
14164 }
14165 \end_layout
14166
14167 \begin_layout Standard
14168 The optional number following the 
14169 \emph on
14170 interrupt
14171 \begin_inset LatexCommand \index{interrupt}
14172
14173 \end_inset
14174
14175
14176 \begin_inset LatexCommand \index{\_\_interrupt}
14177
14178 \end_inset
14179
14180
14181 \emph default
14182  keyword is the interrupt number this routine will service.
14183  When present, the compiler will insert a call to this routine in the interrupt
14184  vector table
14185 \begin_inset LatexCommand \index{interrupt vector table}
14186
14187 \end_inset
14188
14189  for the interrupt number specified.
14190  If you have multiple source files in your project, interrupt service routines
14191  can be present in any of them, but a prototype of the isr MUST be present
14192  or included in the file that contains the function 
14193 \emph on
14194 main
14195 \emph default
14196 .
14197  The optional (8051 specific) keyword 
14198 \emph on
14199 using
14200 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14201
14202 \end_inset
14203
14204
14205 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14206
14207 \end_inset
14208
14209
14210 \emph default
14211  can be used to tell the compiler to use the specified register bank when
14212  generating code for this function.
14213  
14214 \newline
14215 Interrupt service routines open the door for some very interesting bugs:
14216 \end_layout
14217
14218 \begin_layout Subsubsection
14219 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14220
14221 \end_inset
14222
14223 Common interrupt pitfall: variable not declared 
14224 \emph on
14225 volatile
14226 \end_layout
14227
14228 \begin_layout Standard
14229 If an interrupt service routine changes variables which are accessed by
14230  other functions these variables have to be declared 
14231 \emph on
14232 volatile
14233 \emph default
14234
14235 \begin_inset LatexCommand \index{volatile}
14236
14237 \end_inset
14238
14239 .
14240  See 
14241 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14242
14243 \end_inset
14244
14245  .
14246 \end_layout
14247
14248 \begin_layout Subsubsection
14249 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14250
14251 \end_inset
14252
14253 Common interrupt pitfall: 
14254 \emph on
14255 non-atomic access
14256 \end_layout
14257
14258 \begin_layout Standard
14259 If the access to these variables is not 
14260 \emph on
14261 atomic
14262 \begin_inset LatexCommand \index{atomic}
14263
14264 \end_inset
14265
14266
14267 \emph default
14268  (i.e.
14269  the processor needs more than one instruction for the access and could
14270  be interrupted while accessing the variable) the interrupt must be disabled
14271  during the access to avoid inconsistent data.
14272  
14273 \newline
14274 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14275  and should be protected by disabling interrupts.
14276  You're not automatically on the safe side if you use 8 bit variables though.
14277  We need an example here: f.e.
14278  on the 8051 the harmless looking 
14279 \begin_inset Quotes srd
14280 \end_inset
14281
14282
14283 \family typewriter
14284 flags\InsetSpace ~
14285 |=\InsetSpace ~
14286 0x80;
14287 \family default
14288
14289 \begin_inset Quotes sld
14290 \end_inset
14291
14292  is not atomic if 
14293 \family typewriter
14294 flags
14295 \family default
14296  resides in xdata.
14297  Setting 
14298 \begin_inset Quotes srd
14299 \end_inset
14300
14301
14302 \family typewriter
14303 flags\InsetSpace ~
14304 |=\InsetSpace ~
14305 0x40;
14306 \family default
14307
14308 \begin_inset Quotes sld
14309 \end_inset
14310
14311  from within an interrupt routine might get lost if the interrupt occurs
14312  at the wrong time.
14313  
14314 \begin_inset Quotes sld
14315 \end_inset
14316
14317
14318 \family typewriter
14319 counter\InsetSpace ~
14320 +=\InsetSpace ~
14321 8;
14322 \family default
14323
14324 \begin_inset Quotes srd
14325 \end_inset
14326
14327  is not atomic on the 8051 even if 
14328 \family typewriter
14329 counter
14330 \family default
14331  is located in data memory.
14332 \newline
14333 Bugs like these are hard to reproduce and can
14334  cause a lot of trouble.
14335  
14336 \end_layout
14337
14338 \begin_layout Subsubsection
14339 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14340
14341 \end_inset
14342
14343 Common interrupt pitfall: 
14344 \emph on
14345 stack overflow
14346 \end_layout
14347
14348 \begin_layout Standard
14349 The return address and the registers used in the interrupt service routine
14350  are saved on the stack
14351 \begin_inset LatexCommand \index{stack}
14352
14353 \end_inset
14354
14355  so there must be sufficient stack space.
14356  If there isn't variables or registers (or even the return address itself)
14357  will be corrupted.
14358  This 
14359 \emph on
14360 stack overflow
14361 \emph default
14362
14363 \begin_inset LatexCommand \index{stack overflow}
14364
14365 \end_inset
14366
14367  is most likely to happen if the interrupt occurs during the 
14368 \begin_inset Quotes sld
14369 \end_inset
14370
14371 deepest
14372 \begin_inset Quotes srd
14373 \end_inset
14374
14375  subroutine when the stack is already in use for f.e.
14376  many return addresses.
14377 \end_layout
14378
14379 \begin_layout Subsubsection
14380 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14381
14382 \end_inset
14383
14384 Common interrupt pitfall: 
14385 \emph on
14386 use of non-reentrant functions
14387 \end_layout
14388
14389 \begin_layout Standard
14390 A special note here, int (16 bit) and long (32 bit) integer division
14391 \begin_inset LatexCommand \index{Division}
14392
14393 \end_inset
14394
14395 , multiplication
14396 \begin_inset LatexCommand \index{Multiplication}
14397
14398 \end_inset
14399
14400  & modulus
14401 \begin_inset LatexCommand \index{Modulus}
14402
14403 \end_inset
14404
14405  and floating-point
14406 \begin_inset LatexCommand \index{Floating point support}
14407
14408 \end_inset
14409
14410  operations are implemented using external support routines.
14411  If an interrupt service routine needs to do any of these operations then
14412  the support routines (as mentioned in a following section) will have to
14413  be recompiled using the
14414 \emph on
14415  -
14416 \begin_inset ERT
14417 status collapsed
14418
14419 \begin_layout Standard
14420
14421
14422 \backslash
14423 /
14424 \end_layout
14425
14426 \end_inset
14427
14428 -stack-auto
14429 \begin_inset LatexCommand \index{-\/-stack-auto}
14430
14431 \end_inset
14432
14433
14434 \emph default
14435  option and the source file will need to be compiled using the 
14436 \emph on
14437 -
14438 \begin_inset ERT
14439 status collapsed
14440
14441 \begin_layout Standard
14442
14443
14444 \backslash
14445 /
14446 \end_layout
14447
14448 \end_inset
14449
14450 -int-long-reent
14451 \emph default
14452
14453 \begin_inset LatexCommand \index{-\/-int-long-reent}
14454
14455 \end_inset
14456
14457  compiler option.
14458  
14459 \newline
14460 Note, the type promotion
14461 \begin_inset LatexCommand \index{type promotion}
14462
14463 \end_inset
14464
14465  required by ANSI C can cause 16 bit routines to be used
14466 \begin_inset Marginal
14467 status collapsed
14468
14469 \begin_layout Standard
14470
14471 \series bold
14472 \InsetSpace ~
14473 !
14474 \end_layout
14475
14476 \end_inset
14477
14478  without the programmer being aware of it.
14479  See f.e.
14480  the cast 
14481 \family typewriter
14482 (unsigned char)(tail-1)
14483 \family default
14484  within the if clause in section 
14485 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14486
14487 \end_inset
14488
14489 .
14490 \end_layout
14491
14492 \begin_layout Standard
14493 Calling other functions from an interrupt service routine is not recommended,
14494  avoid it if possible.
14495  Note that when some function is called from an interrupt service routine
14496  it should be preceded by a #pragma\InsetSpace ~
14497 nooverlay
14498 \begin_inset LatexCommand \index{\#pragma nooverlay}
14499
14500 \end_inset
14501
14502  if it is not reentrant.
14503  Furthermore nonreentrant functions should not be called from the main program
14504  while the interrupt service routine might be active.
14505  They also must not be called from low priority interrupt service routines
14506  while a high priority interrupt service routine might be active.
14507  You could use semaphores or make the function
14508 \emph on
14509  critical
14510 \emph default
14511  if all parameters are passed in registers.
14512 \newline
14513  Also see section 
14514 \begin_inset LatexCommand \ref{sub:Overlaying}
14515
14516 \end_inset
14517
14518 \InsetSpace ~
14519 about Overlaying and section 
14520 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14521
14522 \end_inset
14523
14524 \InsetSpace ~
14525 about Functions using private register banks.
14526 \begin_inset VSpace bigskip
14527 \end_inset
14528
14529
14530 \end_layout
14531
14532 \begin_layout Subsection
14533 MCS51/DS390 Interrupt Service Routines
14534 \end_layout
14535
14536 \begin_layout Standard
14537 Interrupt
14538 \begin_inset LatexCommand \index{interrupt}
14539
14540 \end_inset
14541
14542  numbers and the corresponding address & descriptions for the Standard 8051/8052
14543  are listed below.
14544  SDCC will automatically adjust the 
14545 \begin_inset LatexCommand \index{interrupt vector table}
14546
14547 \end_inset
14548
14549  to the maximum interrupt number specified.
14550 \newline
14551
14552 \end_layout
14553
14554 \begin_layout Standard
14555 \align center
14556 \begin_inset Tabular
14557 <lyxtabular version="3" rows="9" columns="3">
14558 <features>
14559 <column alignment="center" valignment="top" leftline="true" width="0in">
14560 <column alignment="left" valignment="top" leftline="true" width="0in">
14561 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14562 <row topline="true" bottomline="true">
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14564 \begin_inset Text
14565
14566 \begin_layout Standard
14567 Interrupt #
14568 \end_layout
14569
14570 \end_inset
14571 </cell>
14572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14573 \begin_inset Text
14574
14575 \begin_layout Standard
14576 Description
14577 \end_layout
14578
14579 \end_inset
14580 </cell>
14581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14582 \begin_inset Text
14583
14584 \begin_layout Standard
14585 Vector Address
14586 \end_layout
14587
14588 \end_inset
14589 </cell>
14590 </row>
14591 <row topline="true">
14592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14593 \begin_inset Text
14594
14595 \begin_layout Standard
14596 0
14597 \end_layout
14598
14599 \end_inset
14600 </cell>
14601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14602 \begin_inset Text
14603
14604 \begin_layout Standard
14605 External 0
14606 \end_layout
14607
14608 \end_inset
14609 </cell>
14610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14611 \begin_inset Text
14612
14613 \begin_layout Standard
14614 0x0003
14615 \end_layout
14616
14617 \end_inset
14618 </cell>
14619 </row>
14620 <row topline="true">
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14622 \begin_inset Text
14623
14624 \begin_layout Standard
14625 1
14626 \end_layout
14627
14628 \end_inset
14629 </cell>
14630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14631 \begin_inset Text
14632
14633 \begin_layout Standard
14634 Timer 0
14635 \end_layout
14636
14637 \end_inset
14638 </cell>
14639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14640 \begin_inset Text
14641
14642 \begin_layout Standard
14643 0x000b
14644 \end_layout
14645
14646 \end_inset
14647 </cell>
14648 </row>
14649 <row topline="true">
14650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14651 \begin_inset Text
14652
14653 \begin_layout Standard
14654 2
14655 \end_layout
14656
14657 \end_inset
14658 </cell>
14659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14660 \begin_inset Text
14661
14662 \begin_layout Standard
14663 External 1
14664 \end_layout
14665
14666 \end_inset
14667 </cell>
14668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14669 \begin_inset Text
14670
14671 \begin_layout Standard
14672 0x0013
14673 \end_layout
14674
14675 \end_inset
14676 </cell>
14677 </row>
14678 <row topline="true">
14679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14680 \begin_inset Text
14681
14682 \begin_layout Standard
14683 3
14684 \end_layout
14685
14686 \end_inset
14687 </cell>
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14689 \begin_inset Text
14690
14691 \begin_layout Standard
14692 Timer 1
14693 \end_layout
14694
14695 \end_inset
14696 </cell>
14697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14698 \begin_inset Text
14699
14700 \begin_layout Standard
14701 0x001b
14702 \end_layout
14703
14704 \end_inset
14705 </cell>
14706 </row>
14707 <row topline="true">
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14709 \begin_inset Text
14710
14711 \begin_layout Standard
14712 4
14713 \end_layout
14714
14715 \end_inset
14716 </cell>
14717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14718 \begin_inset Text
14719
14720 \begin_layout Standard
14721 Serial
14722 \end_layout
14723
14724 \end_inset
14725 </cell>
14726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14727 \begin_inset Text
14728
14729 \begin_layout Standard
14730 0x0023
14731 \end_layout
14732
14733 \end_inset
14734 </cell>
14735 </row>
14736 <row topline="true">
14737 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14738 \begin_inset Text
14739
14740 \begin_layout Standard
14741 5
14742 \end_layout
14743
14744 \end_inset
14745 </cell>
14746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14747 \begin_inset Text
14748
14749 \begin_layout Standard
14750 Timer 2 (8052)
14751 \end_layout
14752
14753 \end_inset
14754 </cell>
14755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14756 \begin_inset Text
14757
14758 \begin_layout Standard
14759 0x002b
14760 \end_layout
14761
14762 \end_inset
14763 </cell>
14764 </row>
14765 <row topline="true">
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14767 \begin_inset Text
14768
14769 \begin_layout Standard
14770 ...
14771 \end_layout
14772
14773 \end_inset
14774 </cell>
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14776 \begin_inset Text
14777
14778 \begin_layout Standard
14779
14780 \end_layout
14781
14782 \end_inset
14783 </cell>
14784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14785 \begin_inset Text
14786
14787 \begin_layout Standard
14788 ...
14789 \end_layout
14790
14791 \end_inset
14792 </cell>
14793 </row>
14794 <row topline="true" bottomline="true">
14795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14796 \begin_inset Text
14797
14798 \begin_layout Standard
14799 n
14800 \end_layout
14801
14802 \end_inset
14803 </cell>
14804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14805 \begin_inset Text
14806
14807 \begin_layout Standard
14808
14809 \end_layout
14810
14811 \end_inset
14812 </cell>
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14814 \begin_inset Text
14815
14816 \begin_layout Standard
14817 0x0003 + 8*n
14818 \end_layout
14819
14820 \end_inset
14821 </cell>
14822 </row>
14823 </lyxtabular>
14824
14825 \end_inset
14826
14827
14828 \newline
14829
14830 \end_layout
14831
14832 \begin_layout Standard
14833 If the interrupt service routine is defined without 
14834 \emph on
14835 using
14836 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14837
14838 \end_inset
14839
14840
14841 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14842
14843 \end_inset
14844
14845
14846 \emph default
14847  a register bank or with register bank 0 (
14848 \emph on
14849 using
14850 \emph default
14851  0), the compiler will save the registers used by itself on the stack upon
14852  entry and restore them at exit, however if such an interrupt service routine
14853  calls another function then the entire register bank will be saved on the
14854  stack.
14855  This scheme may be advantageous for small interrupt service routines which
14856  have low register usage.
14857 \end_layout
14858
14859 \begin_layout Standard
14860 If the interrupt service routine is defined to be using a specific register
14861  bank then only 
14862 \emph on
14863 a, b, dptr
14864 \emph default
14865  & psw are saved and restored, if such an interrupt service routine calls
14866  another function (using another register bank) then the entire register
14867  bank of the called function will be saved on the stack
14868 \begin_inset LatexCommand \index{stack}
14869
14870 \end_inset
14871
14872 .
14873  This scheme is recommended for larger interrupt service routines.
14874 \begin_inset VSpace bigskip
14875 \end_inset
14876
14877
14878 \end_layout
14879
14880 \begin_layout Subsection
14881 HC08
14882 \begin_inset LatexCommand \index{HC08}
14883
14884 \end_inset
14885
14886  Interrupt Service Routines
14887 \end_layout
14888
14889 \begin_layout Standard
14890 Since the number of interrupts
14891 \begin_inset LatexCommand \index{HC08!interrupt}
14892
14893 \end_inset
14894
14895  available is chip specific and the interrupt vector table always ends at
14896  the last byte of memory, the interrupt numbers corresponds to the interrupt
14897  vectors in reverse order of address.
14898  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14899  2 will use the interrupt vector at 0xfffa, and so on.
14900  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14901  this way; instead see section 
14902 \begin_inset LatexCommand \ref{sub:Startup-Code}
14903
14904 \end_inset
14905
14906  for details on customizing startup.
14907 \begin_inset VSpace bigskip
14908 \end_inset
14909
14910
14911 \end_layout
14912
14913 \begin_layout Subsection
14914 Z80 Interrupt Service Routines
14915 \end_layout
14916
14917 \begin_layout Standard
14918 The Z80
14919 \begin_inset LatexCommand \index{Z80}
14920
14921 \end_inset
14922
14923  uses several different methods for determining the correct interrupt
14924 \begin_inset LatexCommand \index{Z80!interrupt}
14925
14926 \end_inset
14927
14928  vector depending on the hardware implementation.
14929  Therefore, SDCC ignores the optional interrupt number and does not attempt
14930  to generate an interrupt vector table.
14931 \end_layout
14932
14933 \begin_layout Standard
14934 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14935  instruction to return from the interrupt.
14936  To write an interrupt handler for the non-maskable interrupt, which needs
14937  a RETN instruction instead, add the 
14938 \emph on
14939 critical
14940 \emph default
14941  keyword:
14942 \end_layout
14943
14944 \begin_layout Verse
14945
14946 \family typewriter
14947 void nmi_isr (void) critical interrupt
14948 \newline
14949
14950 \newline
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 ...
14956  
14957 \newline
14958 }
14959 \end_layout
14960
14961 \begin_layout Standard
14962 However if you need to create a non-interruptable interrupt service routine
14963  you would also require the 
14964 \emph on
14965 critical
14966 \emph default
14967  keyword.
14968  To distinguish between this and an nmi_isr you must provide an interrupt
14969  number.
14970 \begin_inset VSpace bigskip
14971 \end_inset
14972
14973
14974 \end_layout
14975
14976 \begin_layout Section
14977 Enabling and Disabling Interrupts
14978 \end_layout
14979
14980 \begin_layout Subsection
14981 Critical Functions and Critical Statements
14982 \end_layout
14983
14984 \begin_layout Standard
14985 A special keyword may be associated with a block or a function declaring
14986  it as 
14987 \emph on
14988 critical
14989 \emph default
14990 .
14991  SDCC will generate code to disable all interrupts
14992 \begin_inset LatexCommand \index{interrupt}
14993
14994 \end_inset
14995
14996  upon entry to a critical function and restore the interrupt enable to the
14997  previous state before returning.
14998  Nesting critical functions will need one additional byte on the stack
14999 \begin_inset LatexCommand \index{stack}
15000
15001 \end_inset
15002
15003  for each call.
15004 \end_layout
15005
15006 \begin_layout Verse
15007
15008 \family typewriter
15009 int foo () __critical
15010 \begin_inset LatexCommand \index{critical}
15011
15012 \end_inset
15013
15014
15015 \begin_inset LatexCommand \index{\_\_critical}
15016
15017 \end_inset
15018
15019  
15020 \newline
15021
15022 \newline
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 ...
15028  
15029 \newline
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 ...
15035  
15036 \newline
15037 }
15038 \end_layout
15039
15040 \begin_layout Standard
15041 The critical attribute maybe used with other attributes like 
15042 \emph on
15043 reentrant.
15044 \emph default
15045
15046 \newline
15047 The keyword 
15048 \emph on
15049 critical
15050 \emph default
15051  may also be used to disable interrupts more locally:
15052 \end_layout
15053
15054 \begin_layout Verse
15055
15056 \family typewriter
15057 __critical{ i++; }
15058 \end_layout
15059
15060 \begin_layout Standard
15061 More than one statement could have been included in the block.
15062 \end_layout
15063
15064 \begin_layout Subsection
15065 Enabling and Disabling Interrupts directly
15066 \end_layout
15067
15068 \begin_layout Standard
15069 Interrupts
15070 \begin_inset LatexCommand \index{interrupt}
15071
15072 \end_inset
15073
15074  can also be disabled and enabled directly (8051):
15075 \end_layout
15076
15077 \begin_layout Verse
15078
15079 \family typewriter
15080 EA = 0;\InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 or:\InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 EA_SAVE = EA;
15104 \end_layout
15105
15106 \begin_layout Verse
15107
15108 \family typewriter
15109 ...\InsetSpace ~
15110 \InsetSpace ~
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 EA = 0;
15140 \end_layout
15141
15142 \begin_layout Verse
15143
15144 \family typewriter
15145 EA = 1;\InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 ...
15172 \end_layout
15173
15174 \begin_layout Verse
15175
15176 \family typewriter
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 EA = EA_SAVE;
15211 \end_layout
15212
15213 \begin_layout Standard
15214 On other architectures which have seperate opcodes for enabling and disabling
15215  interrupts you might want to make use of defines with inline assembly
15216 \begin_inset LatexCommand \index{Assembler routines}
15217
15218 \end_inset
15219
15220  (HC08
15221 \begin_inset LatexCommand \index{HC08!interrupt}
15222
15223 \end_inset
15224
15225 ):
15226 \end_layout
15227
15228 \begin_layout Verse
15229
15230 \family typewriter
15231 #define CLI _asm
15232 \begin_inset LatexCommand \index{\_asm}
15233
15234 \end_inset
15235
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 cli\InsetSpace ~
15239 \InsetSpace ~
15240 _endasm
15241 \begin_inset LatexCommand \index{\_endasm}
15242
15243 \end_inset
15244
15245
15246 \end_layout
15247
15248 \begin_layout Verse
15249
15250 \family typewriter
15251 #define SEI _asm\InsetSpace ~
15252 \InsetSpace ~
15253 sei\InsetSpace ~
15254 \InsetSpace ~
15255 _endasm; 
15256 \end_layout
15257
15258 \begin_layout Verse
15259
15260 \family typewriter
15261 ...
15262 \end_layout
15263
15264 \begin_layout Standard
15265 Note: it is sometimes sufficient to disable only a specific interrupt source
15266  like f.e.
15267  a timer or serial interrupt by manipulating an 
15268 \emph on
15269 interrupt mask
15270 \begin_inset LatexCommand \index{interrupt mask}
15271
15272 \end_inset
15273
15274
15275 \emph default
15276  register.
15277  
15278 \end_layout
15279
15280 \begin_layout Standard
15281 Usually the time during which interrupts are disabled should be kept as
15282  short as possible.
15283  This minimizes both 
15284 \emph on
15285 interrupt latency
15286 \emph default
15287
15288 \begin_inset LatexCommand \index{interrupt latency}
15289
15290 \end_inset
15291
15292  (the time between the occurrence of the interrupt and the execution of
15293  the first code in the interrupt routine) and 
15294 \emph on
15295 interrupt jitter
15296 \emph default
15297
15298 \begin_inset LatexCommand \index{interrupt jitter}
15299
15300 \end_inset
15301
15302  (the difference between the shortest and the longest interrupt latency).
15303  These really are something different, f.e.
15304  a serial interrupt has to be served before its buffer overruns so it cares
15305  for the maximum interrupt latency, whereas it does not care about jitter.
15306  On a loudspeaker driven via a digital to analog converter which is fed
15307  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15308  a much smaller jitter will be very audible.
15309 \end_layout
15310
15311 \begin_layout Standard
15312 You can reenable interrupts within an interrupt routine and on some architecture
15313 s you can make use of two (or more) levels of 
15314 \emph on
15315 interrupt priorities
15316 \emph default
15317
15318 \begin_inset LatexCommand \index{interrupt priority}
15319
15320 \end_inset
15321
15322 .
15323  On some architectures which don't support interrupt priorities these can
15324  be implemented by manipulating the interrupt mask and reenabling interrupts
15325  within the interrupt routine.
15326  Check there is sufficient space on the stack
15327 \begin_inset LatexCommand \index{stack}
15328
15329 \end_inset
15330
15331  and don't add complexity unless you have to.
15332  
15333 \end_layout
15334
15335 \begin_layout Subsection
15336 Semaphore
15337 \begin_inset LatexCommand \index{semaphore}
15338
15339 \end_inset
15340
15341  locking (mcs51/ds390)
15342 \end_layout
15343
15344 \begin_layout Standard
15345 Some architectures (mcs51/ds390) have an atomic
15346 \begin_inset LatexCommand \index{atomic}
15347
15348 \end_inset
15349
15350  bit test and
15351 \emph on
15352  
15353 \emph default
15354 clear
15355 \emph on
15356  
15357 \emph default
15358 instruction.
15359  These type of instructions are typically used in preemptive multitasking
15360  systems, where a routine f.e.
15361  claims the use of a data structure ('acquires a lock
15362 \begin_inset LatexCommand \index{lock}
15363
15364 \end_inset
15365
15366  on it'), makes some modifications and then releases the lock when the data
15367  structure is consistent again.
15368  The instruction may also be used if interrupt and non-interrupt code have
15369  to compete for a resource.
15370  With the atomic bit test and clear instruction interrupts
15371 \begin_inset LatexCommand \index{interrupt}
15372
15373 \end_inset
15374
15375  don't have to be disabled for the locking operation.
15376  
15377 \end_layout
15378
15379 \begin_layout Standard
15380 SDCC generates this instruction if the source follows this pattern:
15381 \end_layout
15382
15383 \begin_layout Verse
15384
15385 \family typewriter
15386 volatile
15387 \begin_inset LatexCommand \index{volatile}
15388
15389 \end_inset
15390
15391  bit resource_is_free; 
15392 \newline
15393
15394 \newline
15395 if (resource_is_free) 
15396 \newline
15397 \InsetSpace ~
15398 \InsetSpace ~
15399
15400 \newline
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 \InsetSpace ~
15405 resource_is_free=0; 
15406 \newline
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 ...
15412  
15413 \newline
15414 \InsetSpace ~
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 resource_is_free=1;
15419 \newline
15420 \InsetSpace ~
15421 \InsetSpace ~
15422
15423 \end_layout
15424
15425 \begin_layout Standard
15426 Note, mcs51 and ds390 support only an atomic
15427 \begin_inset LatexCommand \index{atomic}
15428
15429 \end_inset
15430
15431  bit test and 
15432 \emph on
15433 clear
15434 \emph default
15435  instruction (as opposed to atomic bit test and 
15436 \emph on
15437 set).
15438 \end_layout
15439
15440 \begin_layout Section
15441 Functions using private register banks
15442 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15443
15444 \end_inset
15445
15446  (mcs51/ds390)
15447 \end_layout
15448
15449 \begin_layout Standard
15450 Some architectures have support for quickly changing register sets.
15451  SDCC supports this feature with the 
15452 \emph on
15453 using
15454 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15455
15456 \end_inset
15457
15458
15459 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15460
15461 \end_inset
15462
15463
15464 \emph default
15465  attribute (which tells the compiler to use a register bank
15466 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15467
15468 \end_inset
15469
15470  other than the default bank zero).
15471  It should only be applied to 
15472 \emph on
15473 interrupt
15474 \begin_inset LatexCommand \index{interrupt}
15475
15476 \end_inset
15477
15478
15479 \emph default
15480  functions (see footnote below).
15481  This will in most circumstances make the generated ISR code more efficient
15482  since it will not have to save registers on the stack.
15483 \end_layout
15484
15485 \begin_layout Standard
15486 The 
15487 \emph on
15488 using
15489 \emph default
15490  attribute will have no effect on the generated code for a 
15491 \emph on
15492 non-interrupt
15493 \emph default
15494  function (but may occasionally be useful anyway
15495 \begin_inset Foot
15496 status open
15497
15498 \begin_layout Standard
15499 possible exception: if a function is called ONLY from 'interrupt' functions
15500  using a particular bank, it can be declared with the same 'using' attribute
15501  as the calling 'interrupt' functions.
15502  For instance, if you have several ISRs using bank one, and all of them
15503  call memcpy(), it might make sense to create a specialized version of memcpy()
15504  'using 1', since this would prevent the ISR from having to save bank zero
15505  to the stack on entry and switch to bank zero before calling the function
15506 \end_layout
15507
15508 \end_inset
15509
15510 ).
15511 \newline
15512
15513 \emph on
15514 (pending: Note, nowadays the 
15515 \emph default
15516 using
15517 \emph on
15518  attribute has an effect on
15519 \emph default
15520  
15521 \emph on
15522 the generated code for a 
15523 \emph default
15524 non-interrupt
15525 \emph on
15526  function
15527 \emph default
15528 .
15529 \emph on
15530 )
15531 \end_layout
15532
15533 \begin_layout Standard
15534 An 
15535 \emph on
15536 interrupt
15537 \emph default
15538  function using a non-zero bank will assume that it can trash that register
15539  bank, and will not save it.
15540  Since high-priority interrupts
15541 \begin_inset LatexCommand \index{interrupts}
15542
15543 \end_inset
15544
15545
15546 \begin_inset LatexCommand \index{interrupt priority}
15547
15548 \end_inset
15549
15550  can interrupt low-priority ones on the 8051 and friends, this means that
15551  if a high-priority ISR 
15552 \emph on
15553 using
15554 \emph default
15555  a particular bank occurs while processing a low-priority ISR 
15556 \emph on
15557 using
15558 \emph default
15559  the same bank, terrible and bad things can happen.
15560  To prevent this, no single register bank should be 
15561 \emph on
15562 used
15563 \emph default
15564  by both a high priority and a low priority ISR.
15565  This is probably most easily done by having all high priority ISRs use
15566  one bank and all low priority ISRs use another.
15567  If you have an ISR which can change priority at runtime, you're on your
15568  own: I suggest using the default bank zero and taking the small performance
15569  hit.
15570 \end_layout
15571
15572 \begin_layout Standard
15573 It is most efficient if your ISR calls no other functions.
15574  If your ISR must call other functions, it is most efficient if those functions
15575  use the same bank as the ISR (see note 1 below); the next best is if the
15576  called functions use bank zero.
15577  It is very inefficient to call a function using a different, non-zero bank
15578  from an ISR.
15579  
15580 \begin_inset VSpace bigskip
15581 \end_inset
15582
15583
15584 \end_layout
15585
15586 \begin_layout Section
15587 Startup Code
15588 \begin_inset LatexCommand \label{sub:Startup-Code}
15589
15590 \end_inset
15591
15592
15593 \begin_inset LatexCommand \index{Startup code}
15594
15595 \end_inset
15596
15597
15598 \end_layout
15599
15600 \begin_layout Subsection
15601 MCS51/DS390 Startup Code
15602 \end_layout
15603
15604 \begin_layout Standard
15605 The compiler triggers the linker to link certain initialization modules
15606  from the runtime library
15607 \begin_inset LatexCommand \index{Runtime library}
15608
15609 \end_inset
15610
15611  called crt<something>.
15612  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15613  GSINIT5) is not linked unless the -
15614 \series bold
15615
15616 \begin_inset ERT
15617 status open
15618
15619 \begin_layout Standard
15620
15621
15622 \backslash
15623 /
15624 \end_layout
15625
15626 \end_inset
15627
15628
15629 \series default
15630 -xstack option is used.
15631  These modules are highly entangled by the use of special segments/areas,
15632  but a common layout is shown below:
15633 \end_layout
15634
15635 \begin_layout Verse
15636
15637 \family typewriter
15638 \series bold
15639 \size footnotesize
15640 (main.asm)
15641 \end_layout
15642
15643 \begin_layout Verse
15644
15645 \family typewriter
15646 \size footnotesize
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 .area HOME (CODE)
15656 \newline
15657 __interrupt_vect:
15658 \newline
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 \InsetSpace ~
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 ljmp __sdcc_gsinit_startup
15668 \end_layout
15669
15670 \begin_layout Verse
15671
15672 \family typewriter
15673 \series bold
15674 \size footnotesize
15675 (crtstart.asm)
15676 \end_layout
15677
15678 \begin_layout Verse
15679
15680 \family typewriter
15681 \size footnotesize
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 .area GSINIT0 (CODE)
15691 \newline
15692 __sdcc_gsinit_startup::
15693 \newline
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 mov sp,#__start__stack - 1
15703 \end_layout
15704
15705 \begin_layout Verse
15706
15707 \family typewriter
15708 \series bold
15709 \size footnotesize
15710 (crtxstack.asm)
15711 \end_layout
15712
15713 \begin_layout Verse
15714
15715 \family typewriter
15716 \size footnotesize
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 .area GSINIT1 (CODE)
15726 \newline
15727 __sdcc_init_xstack::
15728 \newline
15729 ; Need to initialize in GSINIT1 in
15730  case the user's __sdcc_external_startup uses the xstack.
15731 \newline
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 mov __XPAGE,#(__start__x
15741 stack >> 8)
15742 \newline
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 mov _spx,#__start__xstack
15752 \end_layout
15753
15754 \begin_layout Verse
15755
15756 \family typewriter
15757 \series bold
15758 \size footnotesize
15759 (crtstart.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 GSINIT2 (CODE)
15775 \newline
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 lcall __sdcc_external_startup
15785 \newline
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 mov a,dpl
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 jz __sdcc_init_data
15805 \newline
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 ljmp
15815  __sdcc_program_startup
15816 \newline
15817 __sdcc_init_data:
15818 \end_layout
15819
15820 \begin_layout Verse
15821
15822 \family typewriter
15823 \series bold
15824 \size footnotesize
15825 (crtxinit.asm)
15826 \end_layout
15827
15828 \begin_layout Verse
15829
15830 \family typewriter
15831 \size footnotesize
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 .area GSINIT3 (CODE)
15841 \newline
15842 __mcs51_genXINIT::
15843 \newline
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 mov r1,#l_XINIT
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 mov a,r1
15863 \newline
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 orl a,#(l_XINIT
15873  >> 8)
15874 \newline
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 jz 00003$
15884 \newline
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 mov r2,#((l_XINIT+255) >> 8)
15894 \newline
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 mov dptr,#s_XINIT
15904 \newline
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov r0,#s_XISEG
15914 \newline
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 mov
15924  __XPAGE,#(s_XISEG >> 8)
15925 \newline
15926 00001$:\InsetSpace ~
15927 clr a
15928 \newline
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 movc a,@a+dptr
15938 \newline
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 movx @r0,a
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 inc dptr
15958 \newline
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 inc
15968  r0
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 cjne r0,#0,00002$
15979 \newline
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 inc __XPAGE
15989 \newline
15990 00002$:\InsetSpace ~
15991 djnz r1,00001$
15992 \newline
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 djnz r2,00001$
16002 \newline
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 mov __XPAGE,#0
16012 xFF
16013 \newline
16014 00003$:
16015 \end_layout
16016
16017 \begin_layout Verse
16018
16019 \family typewriter
16020 \series bold
16021 \size footnotesize
16022 (crtclear.asm)
16023 \end_layout
16024
16025 \begin_layout Verse
16026
16027 \family typewriter
16028 \size footnotesize
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 .area GSINIT4 (CODE)
16038 \newline
16039 __mcs51_genRAMCLEAR::
16040 \newline
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 clr a
16050 \newline
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 mov r0,#(l_IRAM-1)
16060 \newline
16061 00004$:\InsetSpace ~
16062 mov
16063  @r0,a
16064 \newline
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 \InsetSpace ~
16073 djnz r0,00004$
16074 \newline
16075 ; _mcs51_genRAMCLEAR() end
16076 \end_layout
16077
16078 \begin_layout Verse
16079
16080 \family typewriter
16081 \series bold
16082 \size footnotesize
16083 (crtxclear.asm)
16084 \end_layout
16085
16086 \begin_layout Verse
16087
16088 \family typewriter
16089 \size footnotesize
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 .area GSINIT4 (CODE)
16099 \newline
16100 __mcs51_genXRAMCLEAR::
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 mov r0,#l_PSEG
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 mov a,r0
16121 \newline
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 orl a,#(l_PSEG
16131  >> 8)
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 jz 00006$
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov r1,#s_PSEG
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 mov __XPAGE,#(s_PSEG >> 8)
16162 \newline
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 clr a
16172 \newline
16173 00005$:\InsetSpace ~
16174 movx
16175  @r1,a
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 inc r1
16186 \newline
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 djnz r0,00005$
16196 \newline
16197 00006$:
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 mov r0,#l_XSEG
16208 \newline
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 mov a,r0
16218 \newline
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 orl a,#(l_XSEG >>
16228  8)
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 jz 00008$
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 mov r1,#((l_XSEG + 255) >> 8)
16249 \newline
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 mov dptr,#s_XSEG
16259 \newline
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 clr a
16269 \newline
16270 00007$:\InsetSpace ~
16271 movx
16272  @dptr,a
16273 \newline
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 inc dptr
16283 \newline
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 djnz r0,00007$
16293 \newline
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 djnz r1,00007$
16303 \newline
16304 00008$:
16305 \end_layout
16306
16307 \begin_layout Verse
16308
16309 \family typewriter
16310 \series bold
16311 \size footnotesize
16312 (crtxstack.asm)
16313 \end_layout
16314
16315 \begin_layout Verse
16316
16317 \family typewriter
16318 \size footnotesize
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 .area GSINIT5 (CODE)
16328 \newline
16329 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16330  modifies __XPAGE
16331 \newline
16332 ; and __mcs51_genRAMCLEAR modifies _spx.
16333 \newline
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 mov __XPAGE,#(__start__x
16343 stack >> 8)
16344 \newline
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 \InsetSpace ~
16352 \InsetSpace ~
16353 mov _spx,#__start__xstack
16354 \end_layout
16355
16356 \begin_layout Verse
16357
16358 \family typewriter
16359 \series bold
16360 \size footnotesize
16361 (application modules)
16362 \end_layout
16363
16364 \begin_layout Verse
16365
16366 \family typewriter
16367 \size footnotesize
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 .area GSINIT (CODE)
16377 \end_layout
16378
16379 \begin_layout Verse
16380
16381 \family typewriter
16382 \series bold
16383 \size footnotesize
16384 (main.asm)
16385 \end_layout
16386
16387 \begin_layout Verse
16388
16389 \family typewriter
16390 \size footnotesize
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 .area GSFINAL (CODE)
16400 \newline
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 ljmp __sdcc_program_startup
16410 \newline
16411 ;---------------------------------
16412 -----------------------
16413 \newline
16414 ; Home
16415 \newline
16416 ;--------------------------------------------------
16417 ------
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 .area HOME (CODE)
16428 \newline
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 .area CSEG (CODE)
16438 \newline
16439 __sdcc_program_startup:
16440 \newline
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 lcall _main
16450 \newline
16451 ;
16452  return from main will lock up
16453 \newline
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 sjmp .
16463 \end_layout
16464
16465 \begin_layout Standard
16466 One of these modules (crtstart.asm) contains a call to the C routine 
16467 \emph on
16468 _sdcc_external_startup()
16469 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16470
16471 \end_inset
16472
16473
16474 \series bold
16475 \emph default
16476  
16477 \series default
16478 at the start of the CODE area.
16479  This routine is also in the runtime library
16480 \begin_inset LatexCommand \index{Runtime library}
16481
16482 \end_inset
16483
16484  and returns 0 by default.
16485  If this routine returns a non-zero value, the static & global variable
16486  initialization will be skipped and the function main will be invoked.
16487  Otherwise static & global variables will be initialized before the function
16488  main is invoked.
16489  You could add an 
16490 \emph on
16491 _sdcc_external_startup()
16492 \emph default
16493  routine to your program to override the default if you need to setup hardware
16494  or perform some other critical operation prior to static & global variable
16495  initialization
16496 \begin_inset LatexCommand \index{Variable initialization}
16497
16498 \end_inset
16499
16500 .
16501  On some mcs51 variants xdata
16502 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16503
16504 \end_inset
16505
16506  memory has to be explicitly enabled before it can be accessed or if the
16507  watchdog
16508 \begin_inset LatexCommand \index{watchdog}
16509
16510 \end_inset
16511
16512  needs to be disabled, this is the place to do it.
16513  The startup code clears all internal data memory, 256 bytes by default,
16514  but from 0 to n-1 if 
16515 \emph on
16516 -
16517 \begin_inset ERT
16518 status collapsed
16519
16520 \begin_layout Standard
16521
16522
16523 \backslash
16524 /
16525 \end_layout
16526
16527 \end_inset
16528
16529 -iram-size
16530 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16531
16532 \end_inset
16533
16534 n
16535 \emph default
16536  is used.
16537  (recommended for Chipcon CC1010).
16538 \end_layout
16539
16540 \begin_layout Standard
16541 See also the compiler options 
16542 \emph on
16543 -
16544 \begin_inset ERT
16545 status collapsed
16546
16547 \begin_layout Standard
16548
16549
16550 \backslash
16551 /
16552 \end_layout
16553
16554 \end_inset
16555
16556 -no-xinit
16557 \emph default
16558 -
16559 \emph on
16560 opt
16561 \emph default
16562
16563 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16564
16565 \end_inset
16566
16567
16568 \emph on
16569 -
16570 \begin_inset ERT
16571 status collapsed
16572
16573 \begin_layout Standard
16574
16575
16576 \backslash
16577 /
16578 \end_layout
16579
16580 \end_inset
16581
16582 -main-return
16583 \emph default
16584
16585 \begin_inset LatexCommand \index{-\/-main-return}
16586
16587 \end_inset
16588
16589  and section 
16590 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16591
16592 \end_inset
16593
16594  about MCS51-variants.
16595 \newline
16596
16597 \end_layout
16598
16599 \begin_layout Standard
16600 While these initialization modules are meant as generic startup code there
16601  might be the need for customization.
16602  Let's assume the return value of 
16603 \emph on
16604 _sdcc_external_startup()
16605 \emph default
16606  in 
16607 \emph on
16608 crtstart.asm
16609 \emph default
16610  should not be checked (or 
16611 \emph on
16612 _sdcc_external_startup()
16613 \emph default
16614  should not be called at all).
16615  The recommended way would be to copy 
16616 \emph on
16617 crtstart.asm
16618 \emph default
16619  (f.e.
16620  from 
16621 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16622
16623 \end_inset
16624
16625 ) into the source directory, adapt it there, then assemble it with 
16626 \emph on
16627 asx8051 -plosgff
16628 \begin_inset Foot
16629 status open
16630
16631 \begin_layout Standard
16632 \begin_inset Quotes sld
16633 \end_inset
16634
16635 -plosgff
16636 \begin_inset Quotes srd
16637 \end_inset
16638
16639  are the assembler options used in 
16640 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16641
16642 \end_inset
16643
16644
16645 \end_layout
16646
16647 \end_inset
16648
16649  crtstart.asm
16650 \emph default
16651  and when linking your project explicitely specify 
16652 \emph on
16653 crtstart.rel
16654 \emph default
16655 .
16656  As a bonus a listing of the relocated object file 
16657 \emph on
16658 crtstart.rst
16659 \emph default
16660  is generated.
16661 \end_layout
16662
16663 \begin_layout Standard
16664 \begin_inset VSpace bigskip
16665 \end_inset
16666
16667
16668 \end_layout
16669
16670 \begin_layout Subsection
16671 HC08 Startup Code
16672 \end_layout
16673
16674 \begin_layout Standard
16675 The HC08
16676 \begin_inset LatexCommand \index{HC08}
16677
16678 \end_inset
16679
16680  startup code follows the same scheme as the MCS51 startup code.
16681 \begin_inset VSpace bigskip
16682 \end_inset
16683
16684
16685 \end_layout
16686
16687 \begin_layout Subsection
16688 Z80 Startup Code
16689 \end_layout
16690
16691 \begin_layout Standard
16692 On the Z80
16693 \begin_inset LatexCommand \index{Z80}
16694
16695 \end_inset
16696
16697  the startup code is inserted by linking with crt0.o which is generated from
16698  sdcc/device/lib/z80/crt0.s.
16699  If you need a different startup code you can use the compiler option 
16700 \emph on
16701 -
16702 \series bold
16703 \emph default
16704
16705 \begin_inset ERT
16706 status collapsed
16707
16708 \begin_layout Standard
16709
16710
16711 \backslash
16712 /
16713 \end_layout
16714
16715 \end_inset
16716
16717
16718 \series default
16719 \emph on
16720 -no-std-crt0
16721 \emph default
16722
16723 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16724
16725 \end_inset
16726
16727  and provide your own crt0.o.
16728  
16729 \begin_inset VSpace bigskip
16730 \end_inset
16731
16732
16733 \end_layout
16734
16735 \begin_layout Section
16736 Inline Assembler Code
16737 \begin_inset LatexCommand \index{Assembler routines}
16738
16739 \end_inset
16740
16741
16742 \end_layout
16743
16744 \begin_layout Subsection
16745 A Step by Step Introduction
16746 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16747
16748 \end_inset
16749
16750
16751 \end_layout
16752
16753 \begin_layout Standard
16754 Starting from a small snippet of c-code this example shows for the MCS51
16755  how to use inline assembly, access variables, a function parameter and
16756  an array in xdata memory.
16757  The example uses an MCS51 here but is easily adapted for other architectures.
16758  This is a buffer routine which should be optimized:
16759 \end_layout
16760
16761 \begin_layout Verse
16762
16763 \family typewriter
16764 \size footnotesize
16765 unsigned char __far
16766 \begin_inset LatexCommand \index{far (storage class)}
16767
16768 \end_inset
16769
16770
16771 \begin_inset LatexCommand \index{\_\_far (storage class)}
16772
16773 \end_inset
16774
16775  __at
16776 \begin_inset LatexCommand \index{at}
16777
16778 \end_inset
16779
16780
16781 \begin_inset LatexCommand \index{\_\_at}
16782
16783 \end_inset
16784
16785 (0x7f00) buf[0x100];
16786 \begin_inset LatexCommand \index{Aligned array}
16787
16788 \end_inset
16789
16790
16791 \newline
16792 unsigned char head, tail;\InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 \InsetSpace ~
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 /* if interrupts
16810 \begin_inset LatexCommand \index{interrupt}
16811
16812 \end_inset
16813
16814  are involved see
16815 \newline
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 section 
16862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16863
16864 \end_inset
16865
16866  about
16867 \series bold
16868  volatile
16869 \series default
16870  */
16871 \newline
16872
16873 \newline
16874 void to_buffer( unsigned char c ) 
16875 \newline
16876 {
16877 \newline
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 if( head != (unsigned char)(tail-1)
16883  )\InsetSpace ~
16884 /* cast 
16885 \series bold
16886 needed
16887 \series default
16888  to avoid promotion
16889 \begin_inset LatexCommand \index{promotion to signed int}
16890
16891 \end_inset
16892
16893
16894 \begin_inset LatexCommand \index{type promotion}
16895
16896 \end_inset
16897
16898  to integer */
16899 \begin_inset Marginal
16900 status collapsed
16901
16902 \begin_layout Standard
16903
16904 \series bold
16905 \InsetSpace ~
16906 !
16907 \end_layout
16908
16909 \end_inset
16910
16911
16912 \newline
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 buf[ head++ ] = c;\InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 /* access to a 256 byte aligned array */
16938 \newline
16939
16940 \end_layout
16941
16942 \begin_layout Standard
16943 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16944  then a corresponding buffer.asm file is generated.
16945  We define a new function 
16946 \family typewriter
16947 to_buffer_asm()
16948 \family default
16949  in file buffer.c in which we cut and paste the generated code, removing
16950  unwanted comments and some ':'.
16951  Then add 
16952 \begin_inset Quotes sld
16953 \end_inset
16954
16955
16956 \series bold
16957 _asm
16958 \series default
16959
16960 \begin_inset Quotes srd
16961 \end_inset
16962
16963  and 
16964 \begin_inset Quotes sld
16965 \end_inset
16966
16967
16968 \series bold
16969 _endasm;
16970 \series default
16971
16972 \begin_inset Quotes srd
16973 \end_inset
16974
16975
16976 \begin_inset Foot
16977 status open
16978
16979 \begin_layout Standard
16980 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16981  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16982  has to be used.
16983  The latter is also used in the library functions.
16984 \end_layout
16985
16986 \end_inset
16987
16988  to the beginning and the end of the function body:
16989 \end_layout
16990
16991 \begin_layout Verse
16992
16993 \family typewriter
16994 \size footnotesize
16995 /* With a cut and paste from the .asm file, we have something to start with.
16996 \newline
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 The
17001  function is not yet OK! (registers aren't saved) */ 
17002 \newline
17003 void to_buffer_asm(
17004  unsigned char c ) 
17005 \newline
17006
17007 \newline
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 _asm
17013 \begin_inset LatexCommand \index{\_asm}
17014
17015 \end_inset
17016
17017
17018 \begin_inset LatexCommand \index{\_\_asm}
17019
17020 \end_inset
17021
17022
17023 \newline
17024 \InsetSpace ~
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 mov\InsetSpace ~
17029 \InsetSpace ~
17030 r2,dpl 
17031 \newline
17032 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17033 /* cast 
17034 \series bold
17035 needed
17036 \series default
17037  to avoid promotion
17038 \begin_inset LatexCommand \index{promotion to signed int}
17039
17040 \end_inset
17041
17042
17043 \begin_inset LatexCommand \index{type promotion}
17044
17045 \end_inset
17046
17047  to integer */
17048 \newline
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 mov\InsetSpace ~
17054 \InsetSpace ~
17055 a,_tail 
17056 \newline
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 dec\InsetSpace ~
17062 \InsetSpace ~
17063
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 mov\InsetSpace ~
17070 \InsetSpace ~
17071 r3,a 
17072 \newline
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 mov\InsetSpace ~
17078 \InsetSpace ~
17079 a,_head 
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 cjne a,ar3,00106$ 
17086 \newline
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 ret
17092 \newline
17093 00106$:
17094  
17095 \newline
17096 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17097 \begin_inset LatexCommand \index{Aligned array}
17098
17099 \end_inset
17100
17101
17102 \newline
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 mov\InsetSpace ~
17108 \InsetSpace ~
17109 r3,_head 
17110 \newline
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 inc\InsetSpace ~
17116 \InsetSpace ~
17117 _head 
17118 \newline
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 mov\InsetSpace ~
17124 \InsetSpace ~
17125 dpl,r3 
17126 \newline
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 mov\InsetSpace ~
17132 \InsetSpace ~
17133 dph,#(_buf >> 8) 
17134 \newline
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 mov\InsetSpace ~
17140 \InsetSpace ~
17141 a,r2 
17142 \newline
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 movx @dptr,a
17148  
17149 \newline
17150 00103$: 
17151 \newline
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 ret
17157 \newline
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 _endasm
17163 \begin_inset LatexCommand \index{\_endasm}
17164
17165 \end_inset
17166
17167
17168 \begin_inset LatexCommand \index{\_\_endasm}
17169
17170 \end_inset
17171
17172 ;
17173 \newline
17174
17175 \end_layout
17176
17177 \begin_layout Standard
17178 The new file buffer.c should compile with only one warning about the unreferenced
17179  function argument 'c'.
17180  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17181  (1) and finally have:
17182 \end_layout
17183
17184 \begin_layout Verse
17185
17186 \family typewriter
17187 \size footnotesize
17188 unsigned char __far __at(0x7f00) buf[0x100];
17189 \newline
17190 unsigned char head, tail;
17191 \newline
17192 #define
17193  USE_ASSEMBLY (1)
17194 \newline
17195
17196 \newline
17197 #if !USE_ASSEMBLY
17198 \newline
17199
17200 \newline
17201 void to_buffer( unsigned char c )
17202 \newline
17203 {
17204 \newline
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 if(
17210  head != (unsigned char)(tail-1) )
17211 \newline
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 buf[ head++ ] = c;
17221 \newline
17222 }
17223 \newline
17224
17225 \newline
17226 #else
17227 \newline
17228
17229 \newline
17230 void to_buffer(
17231  unsigned char c )
17232 \newline
17233 {
17234 \newline
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 c; // to avoid warning: unreferenced function argument
17240 \newline
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 _asm
17246 \begin_inset LatexCommand \index{\_asm}
17247
17248 \end_inset
17249
17250
17251 \begin_inset LatexCommand \index{\_\_asm}
17252
17253 \end_inset
17254
17255
17256 \newline
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 ; save used registers here.
17266  
17267 \newline
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 ; If we were still using r2,r3 we would have to push them here.
17277  
17278 \newline
17279 ; if( head != (unsigned char)(tail-1) )
17280 \newline
17281 \InsetSpace ~
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 mov\InsetSpace ~
17290  a,_tail
17291 \newline
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 dec\InsetSpace ~
17301  a
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 xrl\InsetSpace ~
17312  a,_head
17313 \newline
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 ; we
17323  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17324 \newline
17325 \InsetSpace ~
17326 \InsetSpace ~
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 jz\InsetSpace ~
17334 \InsetSpace ~
17335  t_b_end$
17336 \newline
17337 \InsetSpace ~
17338 \InsetSpace ~
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 ;
17346 \newline
17347 ;
17348  buf[ head++ ] = c;
17349 \newline
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 \InsetSpace ~
17357 \InsetSpace ~
17358 mov\InsetSpace ~
17359  a,dpl \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 ; dpl holds lower byte of function argument
17367 \newline
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 \InsetSpace ~
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 mov\InsetSpace ~
17377
17378  dpl,_head \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 ; buf is 0x100 byte aligned so head can be used directly
17382 \newline
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 mov\InsetSpace ~
17392  dph,#(_bu
17393 f>>8)
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 movx @dptr,a
17404 \newline
17405 \InsetSpace ~
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 inc \InsetSpace ~
17414 _head
17415 \newline
17416 \InsetSpace ~
17417 \InsetSpace ~
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 ; we could do an ANL _head,#0x0f here to use a
17425  smaller buffer (see above)
17426 \newline
17427 t_b_end$:
17428 \newline
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 \InsetSpace ~
17435 \InsetSpace ~
17436 \InsetSpace ~
17437 ; restore used registers here 
17438 \newline
17439 \InsetSpace ~
17440 \InsetSpace ~
17441 \InsetSpace ~
17442 \InsetSpace ~
17443 _endasm
17444 \begin_inset LatexCommand \index{\_endasm}
17445
17446 \end_inset
17447
17448
17449 \begin_inset LatexCommand \index{\_\_endasm}
17450
17451 \end_inset
17452
17453 ;
17454 \newline
17455 }
17456 \newline
17457 #endif
17458 \end_layout
17459
17460 \begin_layout Standard
17461 The inline assembler code can contain any valid code understood by the assembler
17462 , this includes any assembler directives and comment lines.
17463  The assembler does not like some characters like ':' or ''' in comments.
17464  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17465 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17466
17467 \end_inset
17468
17469
17470 \begin_inset LatexCommand \index{Assembler documentation}
17471
17472 \end_inset
17473
17474  or online at 
17475 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17476
17477 \end_inset
17478
17479 \InsetSpace ~
17480 .
17481 \end_layout
17482
17483 \begin_layout Standard
17484 The compiler does not do any validation of the code within the 
17485 \family typewriter
17486 _asm
17487 \begin_inset LatexCommand \index{\_asm}
17488
17489 \end_inset
17490
17491
17492 \begin_inset LatexCommand \index{\_\_asm}
17493
17494 \end_inset
17495
17496  ...
17497  _endasm
17498 \size footnotesize
17499
17500 \begin_inset LatexCommand \index{\_endasm}
17501
17502 \end_inset
17503
17504
17505 \begin_inset LatexCommand \index{\_\_endasm}
17506
17507 \end_inset
17508
17509
17510 \size default
17511 ;
17512 \family default
17513  keyword pair.
17514  Specifically it will not know which registers are used and thus register
17515  pushing/popping
17516 \begin_inset LatexCommand \index{push/pop}
17517
17518 \end_inset
17519
17520  has to be done manually.
17521  
17522 \end_layout
17523
17524 \begin_layout Standard
17525 It is recommended that each assembly instruction (including labels) be placed
17526  in a separate line (as the example shows).
17527  When the -
17528 \begin_inset ERT
17529 status collapsed
17530
17531 \begin_layout Standard
17532
17533
17534 \backslash
17535 /
17536 \end_layout
17537
17538 \end_inset
17539
17540 -
17541 \emph on
17542 peep-asm
17543 \begin_inset LatexCommand \index{-\/-peep-asm}
17544
17545 \end_inset
17546
17547
17548 \emph default
17549  command line option is used, the inline assembler code will be passed through
17550  the peephole optimizer
17551 \begin_inset LatexCommand \index{Peephole optimizer}
17552
17553 \end_inset
17554
17555 .
17556  There are only a few (if any) cases where this option makes sense, it might
17557  cause some unexpected changes in the inline assembler code.
17558  Please go through the peephole optimizer rules defined in file 
17559 \emph on
17560 SDCCpeeph.def
17561 \emph default
17562  before using this option.
17563 \end_layout
17564
17565 \begin_layout Subsection
17566 Naked Functions
17567 \begin_inset LatexCommand \label{sub:Naked-Functions}
17568
17569 \end_inset
17570
17571
17572 \begin_inset LatexCommand \index{Naked functions}
17573
17574 \end_inset
17575
17576
17577 \end_layout
17578
17579 \begin_layout Standard
17580 A special keyword may be associated with a function declaring it as 
17581 \emph on
17582 _naked
17583 \begin_inset LatexCommand \index{\_naked}
17584
17585 \end_inset
17586
17587
17588 \begin_inset LatexCommand \index{\_\_naked}
17589
17590 \end_inset
17591
17592 .
17593  
17594 \emph default
17595 The 
17596 \emph on
17597 _naked
17598 \emph default
17599  function modifier attribute prevents the compiler from generating prologue
17600 \begin_inset LatexCommand \index{function prologue}
17601
17602 \end_inset
17603
17604  and epilogue
17605 \begin_inset LatexCommand \index{function epilogue}
17606
17607 \end_inset
17608
17609  code for that function.
17610  This means that the user is entirely responsible for such things as saving
17611  any registers that may need to be preserved, selecting the proper register
17612  bank, generating the 
17613 \emph on
17614 return
17615 \emph default
17616  instruction at the end, etc.
17617  Practically, this means that the contents of the function must be written
17618  in inline assembler.
17619  This is particularly useful for interrupt functions, which can have a large
17620  (and often unnecessary) prologue/epilogue.
17621  For example, compare the code generated by these two functions:
17622 \end_layout
17623
17624 \begin_layout Verse
17625
17626 \family typewriter
17627 volatile
17628 \begin_inset LatexCommand \index{volatile}
17629
17630 \end_inset
17631
17632  data unsigned char counter;
17633 \newline
17634
17635 \newline
17636 void simpleInterrupt(void) __interrupt
17637 \begin_inset LatexCommand \index{interrupt}
17638
17639 \end_inset
17640
17641
17642 \begin_inset LatexCommand \index{\_\_interrupt}
17643
17644 \end_inset
17645
17646  (1)
17647 \newline
17648 {
17649 \newline
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 \InsetSpace ~
17654 counter++;
17655 \newline
17656 }
17657 \newline
17658
17659 \newline
17660 void nakedInterrupt(void) __interrupt (2) __naked
17661 \newline
17662 {
17663 \newline
17664 \InsetSpace ~
17665 \InsetSpace ~
17666 \InsetSpace ~
17667 \InsetSpace ~
17668 _asm
17669 \begin_inset LatexCommand \index{\_asm}
17670
17671 \end_inset
17672
17673
17674 \begin_inset LatexCommand \index{\_\_asm}
17675
17676 \end_inset
17677
17678
17679 \newline
17680 \InsetSpace ~
17681 \InsetSpace ~
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 inc\InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 _counter ; does not change flags, no need to save psw
17692 \newline
17693 \InsetSpace ~
17694 \InsetSpace ~
17695 \InsetSpace ~
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 reti\InsetSpace ~
17700 \InsetSpace ~
17701 \InsetSpace ~
17702 \InsetSpace ~
17703 ; MUST explicitly
17704  include ret or reti in _naked function.
17705 \newline
17706 \InsetSpace ~
17707 \InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 _endasm
17711 \begin_inset LatexCommand \index{\_endasm}
17712
17713 \end_inset
17714
17715
17716 \begin_inset LatexCommand \index{\_\_endasm}
17717
17718 \end_inset
17719
17720 ;
17721 \newline
17722 }
17723 \end_layout
17724
17725 \begin_layout Standard
17726 For an 8051 target, the generated simpleInterrupt looks like:
17727 \end_layout
17728
17729 \begin_layout Verse
17730
17731 \family typewriter
17732 Note, this is an 
17733 \emph on
17734 outdated
17735 \emph default
17736  example, recent versions of SDCC generate
17737 \newline
17738 the 
17739 \emph on
17740 same
17741 \emph default
17742  code for simpleInterrupt() and nakedInterrupt()!
17743 \newline
17744
17745 \newline
17746 _simpleInterrupt:
17747 \newline
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 push\InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 acc
17757 \newline
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 push\InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 b
17767 \newline
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 pu
17773 sh\InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 dpl
17778 \newline
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 \InsetSpace ~
17783 push\InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 dph
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 push\InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 psw
17798 \newline
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 mov\InsetSpace ~
17804 \InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 psw,#0x00
17809 \newline
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 inc\InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 _counter
17820 \newline
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 pop\InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 psw
17831 \newline
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 pop\InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 dph
17842 \newline
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 pop\InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 dpl
17853 \newline
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 pop\InsetSpace ~
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 b
17864 \newline
17865 \InsetSpace ~
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 pop\InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 acc
17875 \newline
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 reti
17881 \end_layout
17882
17883 \begin_layout Standard
17884 whereas nakedInterrupt looks like:
17885 \end_layout
17886
17887 \begin_layout Verse
17888
17889 \family typewriter
17890 _nakedInterrupt:
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 inc\InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 _counter ; does not change flags, no need to save psw
17901 \newline
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 reti\InsetSpace ~
17907 \InsetSpace ~
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 ;
17919  MUST explicitly include ret or reti in _naked function
17920 \end_layout
17921
17922 \begin_layout Standard
17923 The related directive #pragma exclude
17924 \begin_inset LatexCommand \index{\#pragma exclude}
17925
17926 \end_inset
17927
17928  allows a more fine grained control over pushing & popping
17929 \begin_inset LatexCommand \index{push/pop}
17930
17931 \end_inset
17932
17933  the registers.
17934 \end_layout
17935
17936 \begin_layout Standard
17937 While there is nothing preventing you from writing C code inside a 
17938 \family typewriter
17939 _naked
17940 \family default
17941  function, there are many ways to shoot yourself in the foot doing this,
17942  and it is recommended that you stick to inline assembler.
17943 \end_layout
17944
17945 \begin_layout Subsection
17946 Use of Labels within Inline Assembler
17947 \end_layout
17948
17949 \begin_layout Standard
17950 SDCC allows the use of in-line assembler with a few restrictions regarding
17951  labels.
17952  All labels defined within inline assembler code have to be of the form
17953  
17954 \emph on
17955 nnnnn$
17956 \emph default
17957  where nnnnn is a number less than 100 (which implies a limit of utmost
17958  100 inline assembler labels 
17959 \emph on
17960 per function
17961 \emph default
17962 \noun on
17963 )
17964 \noun default
17965 .
17966 \begin_inset Foot
17967 status open
17968
17969 \begin_layout Standard
17970 This is a slightly more stringent rule than absolutely necessary, but stays
17971  always on the safe side.
17972  Labels in the form of nnnnn$ are local labels in the assembler, locality
17973  of which is confined within two labels of the standard form.
17974  The compiler uses the same form for labels within a function (but starting
17975  from nnnnn=00100); and places always a standard label at the beginning
17976  of a function, thus limiting the locality of labels within the scope of
17977  the function.
17978  So, if the inline assembler part would be embedded into C-code, an improperly
17979  placed non-local label in the assembler would break up the reference space
17980  for labels created by the compiler for the C-code, leading to an assembling
17981  error.
17982 \end_layout
17983
17984 \begin_layout Standard
17985 The numeric part of local labels does not need to have 5 digits (although
17986  this is the form of labels output by the compiler), any valid integer will
17987  do.
17988  Please refer to the assemblers documentation for further details.
17989 \end_layout
17990
17991 \end_inset
17992
17993  
17994 \end_layout
17995
17996 \begin_layout Verse
17997
17998 \family typewriter
17999 _asm
18000 \begin_inset LatexCommand \index{\_asm}
18001
18002 \end_inset
18003
18004
18005 \begin_inset LatexCommand \index{\_\_asm}
18006
18007 \end_inset
18008
18009  
18010 \newline
18011 \InsetSpace ~
18012 \InsetSpace ~
18013 \InsetSpace ~
18014 \InsetSpace ~
18015 mov\InsetSpace ~
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 \InsetSpace ~
18019 \InsetSpace ~
18020 b,#10 
18021 \newline
18022 00001$: 
18023 \newline
18024 \InsetSpace ~
18025 \InsetSpace ~
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 djnz\InsetSpace ~
18029 \InsetSpace ~
18030 \InsetSpace ~
18031 \InsetSpace ~
18032 b,00001$ 
18033 \newline
18034 _endasm
18035 \begin_inset LatexCommand \index{\_endasm}
18036
18037 \end_inset
18038
18039
18040 \begin_inset LatexCommand \index{\_\_endasm}
18041
18042 \end_inset
18043
18044  ;
18045 \end_layout
18046
18047 \begin_layout Standard
18048 Inline assembler code cannot reference any C-labels, however it can reference
18049  labels
18050 \begin_inset LatexCommand \index{Labels}
18051
18052 \end_inset
18053
18054  defined by the inline assembler, e.g.:
18055 \end_layout
18056
18057 \begin_layout Verse
18058
18059 \family typewriter
18060 foo() { 
18061 \newline
18062 \InsetSpace ~
18063 \InsetSpace ~
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 /* some c code */ 
18067 \newline
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 \InsetSpace ~
18071 \InsetSpace ~
18072 _asm 
18073 \newline
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 \InsetSpace ~
18079 \InsetSpace ~
18080 ; some assembler code 
18081 \newline
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 \InsetSpace ~
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 ljmp 0003$ 
18089 \newline
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 _endasm;
18095  
18096 \newline
18097 \InsetSpace ~
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 /* some more c code */ 
18102 \newline
18103 clabel:\InsetSpace ~
18104 \InsetSpace ~
18105 /* inline assembler cannot reference this
18106  label */ 
18107 \begin_inset Foot
18108 status open
18109
18110 \begin_layout Standard
18111 Here, the C-label 
18112 \family typewriter
18113 clabel
18114 \family default
18115  is translated by the compiler into a local label, so the locality of labels
18116  within the function is not broken.
18117 \end_layout
18118
18119 \end_inset
18120
18121
18122 \newline
18123 \InsetSpace ~
18124 \InsetSpace ~
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 _asm
18128 \newline
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 0003$: ;label (can be referenced by inline assembler only) 
18134 \newline
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 _endasm
18140 \begin_inset LatexCommand \index{\_endasm}
18141
18142 \end_inset
18143
18144
18145 \begin_inset LatexCommand \index{\_\_endasm}
18146
18147 \end_inset
18148
18149  ; 
18150 \newline
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 /* some more c code */
18156 \newline
18157 }
18158 \end_layout
18159
18160 \begin_layout Standard
18161 In other words inline assembly code can access labels defined in inline
18162  assembly within the scope of the function.
18163  The same goes the other way, i.e.
18164  labels defines in inline assembly can not be accessed by C statements.
18165 \end_layout
18166
18167 \begin_layout Section
18168 Interfacing with Assembler Code
18169 \begin_inset LatexCommand \index{Assembler routines}
18170
18171 \end_inset
18172
18173
18174 \end_layout
18175
18176 \begin_layout Subsection
18177 Global Registers used for Parameter Passing
18178 \begin_inset LatexCommand \index{Parameter passing}
18179
18180 \end_inset
18181
18182
18183 \end_layout
18184
18185 \begin_layout Standard
18186 The compiler always uses the global registers 
18187 \emph on
18188 DPL, DPH
18189 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18190
18191 \end_inset
18192
18193
18194 \begin_inset LatexCommand \index{DPTR}
18195
18196 \end_inset
18197
18198 , B
18199 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18200
18201 \end_inset
18202
18203  
18204 \emph default
18205 and
18206 \emph on
18207  ACC
18208 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18209
18210 \end_inset
18211
18212
18213 \emph default
18214  to pass the first (non-bit) parameter to a function, and also to pass the
18215  return value 
18216 \begin_inset LatexCommand \index{return value}
18217
18218 \end_inset
18219
18220 of function; according to the following scheme: one byte return value in
18221  
18222 \emph on
18223 DPL
18224 \emph default
18225 , two byte value in 
18226 \emph on
18227 DPL
18228 \emph default
18229  (LSB) and 
18230 \emph on
18231 DPH
18232 \emph default
18233  (MSB).
18234  three byte values (generic pointers) in 
18235 \emph on
18236 DPH
18237 \emph default
18238
18239 \emph on
18240 DPL
18241 \emph default
18242  and 
18243 \emph on
18244 B
18245 \emph default
18246 , and four byte values in 
18247 \emph on
18248 DPH
18249 \emph default
18250
18251 \emph on
18252 DPL
18253 \emph default
18254 ,
18255 \emph on
18256  B
18257 \emph default
18258  and 
18259 \emph on
18260 ACC
18261 \emph default
18262 .
18263  Generic pointers
18264 \begin_inset LatexCommand \index{generic pointer}
18265
18266 \end_inset
18267
18268  contain type of accessed memory in 
18269 \emph on
18270 B
18271 \emph default
18272
18273 \series bold
18274 0x00
18275 \series default
18276  -- xdata/far, 
18277 \series bold
18278 0x40
18279 \series default
18280  -- idata/near -- , 
18281 \series bold
18282 0x60
18283 \series default
18284  -- pdata, 
18285 \series bold
18286 0x80
18287 \series default
18288  -- code
18289 \begin_inset Note Note
18290 status collapsed
18291
18292 \begin_layout Standard
18293 This might not be the case of certain memory models (medium???)
18294 \end_layout
18295
18296 \end_inset
18297
18298 .
18299 \end_layout
18300
18301 \begin_layout Standard
18302 The second parameter onwards is either allocated on the stack (for reentrant
18303  routines or if -
18304 \begin_inset ERT
18305 status collapsed
18306
18307 \begin_layout Standard
18308
18309
18310 \backslash
18311 /
18312 \end_layout
18313
18314 \end_inset
18315
18316 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18317 \end_layout
18318
18319 \begin_layout Standard
18320 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18321  space for reentrant functions or allocated directly in bit memory otherwise.
18322 \end_layout
18323
18324 \begin_layout Standard
18325 Functions (with two or more parameters or bit parameters) that are called
18326  through function pointers
18327 \begin_inset LatexCommand \index{function pointers}
18328
18329 \end_inset
18330
18331  must therefor be reentrant so the compiler knows how to pass the parameters.
18332 \end_layout
18333
18334 \begin_layout Subsection
18335 Registers usage
18336 \end_layout
18337
18338 \begin_layout Standard
18339 Unless the called function is declared as 
18340 \family typewriter
18341 _naked
18342 \family default
18343
18344 \begin_inset LatexCommand \index{naked}
18345
18346 \end_inset
18347
18348 , or the -
18349 \begin_inset ERT
18350 status collapsed
18351
18352 \begin_layout Standard
18353
18354
18355 \backslash
18356 /
18357 \end_layout
18358
18359 \end_inset
18360
18361 -callee-saves
18362 \begin_inset LatexCommand \index{-\/-callee-saves}
18363
18364 \end_inset
18365
18366 /-
18367 \begin_inset ERT
18368 status collapsed
18369
18370 \begin_layout Standard
18371
18372
18373 \backslash
18374 /
18375 \end_layout
18376
18377 \end_inset
18378
18379 -all-callee-saves command line option or the corresponding callee_saves
18380  pragma are used, the caller will save the registers (
18381 \emph on
18382 R0-R7
18383 \emph default
18384 ) around the call, so the called function can destroy they content freely.
18385 \end_layout
18386
18387 \begin_layout Standard
18388 If the called function is not declared as 
18389 \family typewriter
18390 _naked
18391 \family default
18392 , the caller will swap register banks around the call, if caller and callee
18393  use different register banks (having them defined by the 
18394 \family typewriter
18395 _using
18396 \family default
18397  modifier).
18398  
18399 \end_layout
18400
18401 \begin_layout Standard
18402 The called function can also use 
18403 \emph on
18404 DPL
18405 \emph default
18406
18407 \emph on
18408 DPH
18409 \emph default
18410
18411 \emph on
18412 B
18413 \emph default
18414  and 
18415 \emph on
18416 ACC
18417 \emph default
18418  observing that they are used for parameter/return value passing.
18419 \end_layout
18420
18421 \begin_layout Subsection
18422 Assembler Routine (non-reentrant)
18423 \end_layout
18424
18425 \begin_layout Standard
18426 In the following example
18427 \begin_inset LatexCommand \index{reentrant}
18428
18429 \end_inset
18430
18431
18432 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18433
18434 \end_inset
18435
18436  the function c_func calls an assembler routine asm_func, which takes two
18437  parameters
18438 \begin_inset LatexCommand \index{function parameter}
18439
18440 \end_inset
18441
18442 .
18443 \end_layout
18444
18445 \begin_layout Verse
18446
18447 \family typewriter
18448 extern int asm_func(unsigned char, unsigned char);
18449 \newline
18450
18451 \newline
18452 int c_func (unsigned char
18453  i, unsigned char j)
18454 \newline
18455 {
18456 \newline
18457 \InsetSpace ~
18458 \InsetSpace ~
18459 \InsetSpace ~
18460 \InsetSpace ~
18461 return asm_func(i,j);
18462 \newline
18463 }
18464 \newline
18465
18466 \newline
18467 int main()
18468 \newline
18469 {
18470 \newline
18471 \InsetSpace ~
18472 \InsetSpace ~
18473 \InsetSpace ~
18474 \InsetSpace ~
18475 return c_func(10,9);
18476 \newline
18477 }
18478 \end_layout
18479
18480 \begin_layout Standard
18481 The corresponding assembler function is:
18482 \end_layout
18483
18484 \begin_layout Verse
18485
18486 \family typewriter
18487 .globl _asm_func_PARM_2 
18488 \newline
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 \InsetSpace ~
18497 .globl _asm_func 
18498 \newline
18499 \InsetSpace ~
18500 \InsetSpace ~
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 .area OSEG 
18508 \newline
18509 _asm_func_PARM_2:
18510 \newline
18511 \InsetSpace ~
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 .ds   
18520  1 
18521 \newline
18522 \InsetSpace ~
18523 \InsetSpace ~
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 .area CSEG 
18531 \newline
18532 _asm_func: 
18533 \newline
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 mov\InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 a,dpl 
18547 \newline
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 add\InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 a,_asm_func_PARM_2 
18561 \newline
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 \InsetSpace ~
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 mov\InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 dpl,a 
18575 \newline
18576 \InsetSpace ~
18577 \InsetSpace ~
18578 \InsetSpace ~
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 \InsetSpace ~
18582 \InsetSpace ~
18583 \InsetSpace ~
18584 mov\InsetSpace ~
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 dph
18589 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18590
18591 \end_inset
18592
18593 ,#0x00 
18594 \newline
18595 \InsetSpace ~
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 \InsetSpace ~
18600 \InsetSpace ~
18601 \InsetSpace ~
18602 \InsetSpace ~
18603 ret
18604 \end_layout
18605
18606 \begin_layout Standard
18607 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18608  the parameter number starting from 1, and counting from the left.
18609  The first parameter is passed in 
18610 \emph on
18611 DPH
18612 \emph default
18613
18614 \emph on
18615 DPL
18616 \emph default
18617
18618 \emph on
18619 B
18620 \emph default
18621  and 
18622 \emph on
18623 ACC
18624 \emph default
18625  according to the description above.
18626  The variable name for the second parameter will be _<function_name>_PARM_2.
18627 \newline
18628
18629 \newline
18630 Assem
18631 ble the assembler routine with the following command:
18632 \newline
18633
18634 \newline
18635
18636 \family sans
18637 \series bold
18638 asx8051 -losg asmfunc.asm
18639 \newline
18640
18641 \newline
18642
18643 \family default
18644 \series default
18645 Then compile and link the assembler routine to the C source file with the
18646  following command:
18647 \newline
18648
18649 \newline
18650
18651 \family sans
18652 \series bold
18653 sdcc cfunc.c asmfunc.rel
18654 \end_layout
18655
18656 \begin_layout Subsection
18657 Assembler Routine (reentrant)
18658 \end_layout
18659
18660 \begin_layout Standard
18661 In this case
18662 \begin_inset LatexCommand \index{reentrant}
18663
18664 \end_inset
18665
18666
18667 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18668
18669 \end_inset
18670
18671  the second parameter
18672 \begin_inset LatexCommand \index{function parameter}
18673
18674 \end_inset
18675
18676  onwards will be passed on the stack, the parameters are pushed from right
18677  to left i.e.
18678  before the call the second leftmost parameter will be on the top of the
18679  stack (the leftmost parameter is passed in registers).
18680  Here is an example:
18681 \end_layout
18682
18683 \begin_layout Verse
18684
18685 \family typewriter
18686 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18687 \newline
18688
18689 \newline
18690 int
18691  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18692 \newline
18693 {
18694  
18695 \newline
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 return asm_func(i,j,k); 
18701 \newline
18702
18703 \newline
18704
18705 \newline
18706 int main() 
18707 \newline
18708
18709 \newline
18710 \InsetSpace ~
18711 \InsetSpace ~
18712 \InsetSpace ~
18713 \InsetSpace ~
18714 return c_func(10,9,8); 
18715 \newline
18716 }
18717 \end_layout
18718
18719 \begin_layout Standard
18720 The corresponding (unoptimized) assembler routine is:
18721 \end_layout
18722
18723 \begin_layout Verse
18724
18725 \family typewriter
18726 .globl _asm_func 
18727 \newline
18728 _asm_func: 
18729 \newline
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 push\InsetSpace ~
18735 _bp 
18736 \newline
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 mov\InsetSpace ~
18742 \InsetSpace ~
18743 _bp,sp\InsetSpace ~
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 ;stack contains: _bp, return
18750  address, second parameter, third parameter
18751 \newline
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 mov\InsetSpace ~
18757 \InsetSpace ~
18758 r2,dpl
18759 \newline
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 mov\InsetSpace ~
18765 \InsetSpace ~
18766 a,_bp
18767 \newline
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 \InsetSpace ~
18771 \InsetSpace ~
18772 add\InsetSpace ~
18773 \InsetSpace ~
18774 a,#0xfd\InsetSpace ~
18775 \InsetSpace ~
18776 \InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 ;calculate
18780  pointer to the second parameter
18781 \newline
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 mov\InsetSpace ~
18787 \InsetSpace ~
18788 r0,a 
18789 \newline
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 \InsetSpace ~
18793 \InsetSpace ~
18794 mov\InsetSpace ~
18795 \InsetSpace ~
18796 a,_bp 
18797 \newline
18798 \InsetSpace ~
18799 \InsetSpace ~
18800 \InsetSpace ~
18801 \InsetSpace ~
18802 add\InsetSpace ~
18803 \InsetSpace ~
18804 a,#0xfc\InsetSpace ~
18805 \InsetSpace ~
18806 \InsetSpace ~
18807 \InsetSpace ~
18808 \InsetSpace ~
18809 ;calculate pointer
18810  to the rightmost parameter
18811 \newline
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 \InsetSpace ~
18815 \InsetSpace ~
18816 mov\InsetSpace ~
18817 \InsetSpace ~
18818 r1,a 
18819 \newline
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 \InsetSpace ~
18823 \InsetSpace ~
18824 mov\InsetSpace ~
18825 \InsetSpace ~
18826 a,@r0
18827 \newline
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 \InsetSpace ~
18831 \InsetSpace ~
18832 add\InsetSpace ~
18833 \InsetSpace ~
18834 a,@r1
18835 \newline
18836 \InsetSpace ~
18837 \InsetSpace ~
18838 \InsetSpace ~
18839 \InsetSpace ~
18840 add\InsetSpace ~
18841 \InsetSpace ~
18842 a,r2\InsetSpace ~
18843 \InsetSpace ~
18844 \InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 \InsetSpace ~
18848 \InsetSpace ~
18849 \InsetSpace ~
18850 ;calculate the
18851  result (= sum of all three parameters)
18852 \newline
18853 \InsetSpace ~
18854 \InsetSpace ~
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 mov\InsetSpace ~
18858 \InsetSpace ~
18859 dpl,a\InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 \InsetSpace ~
18864 \InsetSpace ~
18865 \InsetSpace ~
18866 ;return value goes into dptr
18867  (cast into int)
18868 \newline
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 \InsetSpace ~
18872 \InsetSpace ~
18873 mov\InsetSpace ~
18874 \InsetSpace ~
18875 dph,#0x00 
18876 \newline
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 \InsetSpace ~
18880 \InsetSpace ~
18881 mov\InsetSpace ~
18882 \InsetSpace ~
18883 sp,_bp 
18884 \newline
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 \InsetSpace ~
18889 pop\InsetSpace ~
18890 \InsetSpace ~
18891 _bp 
18892 \newline
18893 \InsetSpace ~
18894 \InsetSpace ~
18895 \InsetSpace ~
18896 \InsetSpace ~
18897 ret
18898 \end_layout
18899
18900 \begin_layout Standard
18901 The compiling and linking procedure remains the same, however note the extra
18902  entry & exit linkage required for the assembler code, _bp is the stack
18903  frame pointer and is used to compute the offset into the stack for parameters
18904  and local variables.
18905 \begin_inset VSpace bigskip
18906 \end_inset
18907
18908
18909 \end_layout
18910
18911 \begin_layout Section
18912 int (16 bit)
18913 \begin_inset LatexCommand \index{int (16 bit)}
18914
18915 \end_inset
18916
18917  and long (32 bit)
18918 \begin_inset LatexCommand \index{long (32 bit)}
18919
18920 \end_inset
18921
18922  Support
18923 \end_layout
18924
18925 \begin_layout Standard
18926 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18927  multiplication and modulus operations are implemented by support routines.
18928  These support routines are all developed in ANSI-C to facilitate porting
18929  to other MCUs, although some model specific assembler optimizations are
18930  used.
18931  The following files contain the described routines, all of them can be
18932  found in <installdir>/share/sdcc/lib.
18933 \newline
18934
18935 \end_layout
18936
18937 \begin_layout Standard
18938 \align center
18939 \begin_inset Tabular
18940 <lyxtabular version="3" rows="11" columns="2">
18941 <features>
18942 <column alignment="left" valignment="top" leftline="true" width="0">
18943 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18944 <row topline="true" bottomline="true">
18945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18946 \begin_inset Text
18947
18948 \begin_layout Standard
18949
18950 \series bold
18951 Function
18952 \end_layout
18953
18954 \end_inset
18955 </cell>
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18957 \begin_inset Text
18958
18959 \begin_layout Standard
18960
18961 \series bold
18962 Description
18963 \end_layout
18964
18965 \end_inset
18966 </cell>
18967 </row>
18968 <row topline="true">
18969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18970 \begin_inset Text
18971
18972 \begin_layout Standard
18973 _mulint.c 
18974 \end_layout
18975
18976 \end_inset
18977 </cell>
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18979 \begin_inset Text
18980
18981 \begin_layout Standard
18982 16 bit multiplication
18983 \end_layout
18984
18985 \end_inset
18986 </cell>
18987 </row>
18988 <row topline="true">
18989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18990 \begin_inset Text
18991
18992 \begin_layout Standard
18993 _divsint.c 
18994 \end_layout
18995
18996 \end_inset
18997 </cell>
18998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18999 \begin_inset Text
19000
19001 \begin_layout Standard
19002  signed 16 bit division (calls _divuint)
19003 \end_layout
19004
19005 \end_inset
19006 </cell>
19007 </row>
19008 <row topline="true">
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19010 \begin_inset Text
19011
19012 \begin_layout Standard
19013 _divuint.c 
19014 \end_layout
19015
19016 \end_inset
19017 </cell>
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19019 \begin_inset Text
19020
19021 \begin_layout Standard
19022  unsigned 16 bit division
19023 \end_layout
19024
19025 \end_inset
19026 </cell>
19027 </row>
19028 <row topline="true">
19029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19030 \begin_inset Text
19031
19032 \begin_layout Standard
19033 _modsint.c
19034 \end_layout
19035
19036 \end_inset
19037 </cell>
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19039 \begin_inset Text
19040
19041 \begin_layout Standard
19042 signed 16 bit modulus (calls _moduint)
19043 \end_layout
19044
19045 \end_inset
19046 </cell>
19047 </row>
19048 <row topline="true">
19049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19050 \begin_inset Text
19051
19052 \begin_layout Standard
19053 _moduint.c
19054 \end_layout
19055
19056 \end_inset
19057 </cell>
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19059 \begin_inset Text
19060
19061 \begin_layout Standard
19062 unsigned 16 bit modulus
19063 \end_layout
19064
19065 \end_inset
19066 </cell>
19067 </row>
19068 <row topline="true">
19069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19070 \begin_inset Text
19071
19072 \begin_layout Standard
19073 _mullong.c
19074 \end_layout
19075
19076 \end_inset
19077 </cell>
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19079 \begin_inset Text
19080
19081 \begin_layout Standard
19082 32 bit multiplication
19083 \end_layout
19084
19085 \end_inset
19086 </cell>
19087 </row>
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \begin_layout Standard
19093 _divslong.c 
19094 \end_layout
19095
19096 \end_inset
19097 </cell>
19098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19099 \begin_inset Text
19100
19101 \begin_layout Standard
19102  signed 32 division (calls _divulong)
19103 \end_layout
19104
19105 \end_inset
19106 </cell>
19107 </row>
19108 <row topline="true">
19109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19110 \begin_inset Text
19111
19112 \begin_layout Standard
19113 _divulong.c 
19114 \end_layout
19115
19116 \end_inset
19117 </cell>
19118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19119 \begin_inset Text
19120
19121 \begin_layout Standard
19122 unsigned 32 division
19123 \end_layout
19124
19125 \end_inset
19126 </cell>
19127 </row>
19128 <row topline="true">
19129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19130 \begin_inset Text
19131
19132 \begin_layout Standard
19133 _modslong.c
19134 \end_layout
19135
19136 \end_inset
19137 </cell>
19138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19139 \begin_inset Text
19140
19141 \begin_layout Standard
19142  signed 32 bit modulus (calls _modulong)
19143 \end_layout
19144
19145 \end_inset
19146 </cell>
19147 </row>
19148 <row topline="true" bottomline="true">
19149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19150 \begin_inset Text
19151
19152 \begin_layout Standard
19153 _modulong.c
19154 \end_layout
19155
19156 \end_inset
19157 </cell>
19158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19159 \begin_inset Text
19160
19161 \begin_layout Standard
19162 unsigned 32 bit modulus
19163 \end_layout
19164
19165 \end_inset
19166 </cell>
19167 </row>
19168 </lyxtabular>
19169
19170 \end_inset
19171
19172
19173 \newline
19174
19175 \end_layout
19176
19177 \begin_layout Standard
19178 Since they are compiled as 
19179 \emph on
19180 non-reentrant
19181 \emph default
19182
19183 \begin_inset LatexCommand \index{reentrant}
19184
19185 \end_inset
19186
19187 , interrupt
19188 \begin_inset LatexCommand \index{interrupt}
19189
19190 \end_inset
19191
19192  service routines should not do any of the above operations.
19193  If this is unavoidable then the above routines will need to be compiled
19194  with the 
19195 \emph on
19196 -
19197 \begin_inset ERT
19198 status collapsed
19199
19200 \begin_layout Standard
19201
19202
19203 \backslash
19204 /
19205 \end_layout
19206
19207 \end_inset
19208
19209 -stack-auto
19210 \begin_inset LatexCommand \index{-\/-stack-auto}
19211
19212 \end_inset
19213
19214
19215 \emph default
19216  option, after which the source program will have to be compiled with 
19217 \emph on
19218 -
19219 \begin_inset ERT
19220 status collapsed
19221
19222 \begin_layout Standard
19223
19224
19225 \backslash
19226 /
19227 \end_layout
19228
19229 \end_inset
19230
19231 -int-long-reent
19232 \begin_inset LatexCommand \index{-\/-int-long-reent}
19233
19234 \end_inset
19235
19236
19237 \emph default
19238  option.
19239  Notice that you don't have to call these routines directly.
19240  The compiler will use them automatically every time an integer operation
19241  is required.
19242 \end_layout
19243
19244 \begin_layout Section
19245 Floating Point Support
19246 \begin_inset LatexCommand \index{Floating point support}
19247
19248 \end_inset
19249
19250
19251 \end_layout
19252
19253 \begin_layout Standard
19254 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19255  The floating point support routines are derived from gcc's floatlib.c and
19256  consist of the following routines:
19257 \newline
19258
19259 \end_layout
19260
19261 \begin_layout Standard
19262 \align center
19263
19264 \size footnotesize
19265 \begin_inset Tabular
19266 <lyxtabular version="3" rows="17" columns="2">
19267 <features>
19268 <column alignment="left" valignment="top" leftline="true" width="0">
19269 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19270 <row topline="true" bottomline="true">
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19272 \begin_inset Text
19273
19274 \begin_layout Standard
19275
19276 \family roman
19277 \series medium
19278 \shape up
19279 \size normal
19280 \emph off
19281 \bar no
19282 \noun off
19283 \color none
19284 Function 
19285 \end_layout
19286
19287 \end_inset
19288 </cell>
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19290 \begin_inset Text
19291
19292 \begin_layout Standard
19293 Description
19294 \end_layout
19295
19296 \end_inset
19297 </cell>
19298 </row>
19299 <row topline="true">
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19301 \begin_inset Text
19302
19303 \begin_layout Standard
19304
19305 \family roman
19306 \series medium
19307 \shape up
19308 \size normal
19309 \emph off
19310 \bar no
19311 \noun off
19312 \color none
19313 _fsadd.c
19314 \end_layout
19315
19316 \end_inset
19317 </cell>
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \begin_layout Standard
19322
19323 \family roman
19324 \series medium
19325 \shape up
19326 \size normal
19327 \emph off
19328 \bar no
19329 \noun off
19330 \color none
19331 add floating point numbers
19332 \end_layout
19333
19334 \end_inset
19335 </cell>
19336 </row>
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_inset Text
19340
19341 \begin_layout Standard
19342
19343 \family roman
19344 \series medium
19345 \shape up
19346 \size normal
19347 \emph off
19348 \bar no
19349 \noun off
19350 \color none
19351 _fssub.c 
19352 \end_layout
19353
19354 \end_inset
19355 </cell>
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19357 \begin_inset Text
19358
19359 \begin_layout Standard
19360
19361 \family roman
19362 \series medium
19363 \shape up
19364 \size normal
19365 \emph off
19366 \bar no
19367 \noun off
19368 \color none
19369 subtract floating point numbers 
19370 \end_layout
19371
19372 \end_inset
19373 </cell>
19374 </row>
19375 <row topline="true">
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19377 \begin_inset Text
19378
19379 \begin_layout Standard
19380
19381 \family roman
19382 \series medium
19383 \shape up
19384 \size normal
19385 \emph off
19386 \bar no
19387 \noun off
19388 \color none
19389 _fsdiv.c 
19390 \end_layout
19391
19392 \end_inset
19393 </cell>
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19395 \begin_inset Text
19396
19397 \begin_layout Standard
19398
19399 \family roman
19400 \series medium
19401 \shape up
19402 \size normal
19403 \emph off
19404 \bar no
19405 \noun off
19406 \color none
19407 divide floating point numbers 
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 </row>
19413 <row topline="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_inset Text
19416
19417 \begin_layout Standard
19418
19419 \family roman
19420 \series medium
19421 \shape up
19422 \size normal
19423 \emph off
19424 \bar no
19425 \noun off
19426 \color none
19427 _fsmul.c 
19428 \end_layout
19429
19430 \end_inset
19431 </cell>
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19433 \begin_inset Text
19434
19435 \begin_layout Standard
19436
19437 \family roman
19438 \series medium
19439 \shape up
19440 \size normal
19441 \emph off
19442 \bar no
19443 \noun off
19444 \color none
19445 multiply floating point numbers 
19446 \end_layout
19447
19448 \end_inset
19449 </cell>
19450 </row>
19451 <row topline="true">
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456
19457 \family roman
19458 \series medium
19459 \shape up
19460 \size normal
19461 \emph off
19462 \bar no
19463 \noun off
19464 \color none
19465 _fs2uchar.c
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474
19475 \family roman
19476 \series medium
19477 \shape up
19478 \size normal
19479 \emph off
19480 \bar no
19481 \noun off
19482 \color none
19483 convert floating point to unsigned char
19484 \end_layout
19485
19486 \end_inset
19487 </cell>
19488 </row>
19489 <row topline="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19491 \begin_inset Text
19492
19493 \begin_layout Standard
19494
19495 \family roman
19496 \series medium
19497 \shape up
19498 \size normal
19499 \emph off
19500 \bar no
19501 \noun off
19502 \color none
19503 _fs2char.c
19504 \end_layout
19505
19506 \end_inset
19507 </cell>
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19509 \begin_inset Text
19510
19511 \begin_layout Standard
19512
19513 \family roman
19514 \series medium
19515 \shape up
19516 \size normal
19517 \emph off
19518 \bar no
19519 \noun off
19520 \color none
19521 convert floating point to signed char
19522 \end_layout
19523
19524 \end_inset
19525 </cell>
19526 </row>
19527 <row topline="true">
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19529 \begin_inset Text
19530
19531 \begin_layout Standard
19532
19533 \family roman
19534 \series medium
19535 \shape up
19536 \size normal
19537 \emph off
19538 \bar no
19539 \noun off
19540 \color none
19541 _fs2uint.c
19542 \end_layout
19543
19544 \end_inset
19545 </cell>
19546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19547 \begin_inset Text
19548
19549 \begin_layout Standard
19550
19551 \family roman
19552 \series medium
19553 \shape up
19554 \size normal
19555 \emph off
19556 \bar no
19557 \noun off
19558 \color none
19559 convert floating point to unsigned int
19560 \end_layout
19561
19562 \end_inset
19563 </cell>
19564 </row>
19565 <row topline="true">
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19567 \begin_inset Text
19568
19569 \begin_layout Standard
19570
19571 \family roman
19572 \series medium
19573 \shape up
19574 \size normal
19575 \emph off
19576 \bar no
19577 \noun off
19578 \color none
19579 _fs2int.c
19580 \end_layout
19581
19582 \end_inset
19583 </cell>
19584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 convert floating point to signed int
19598 \end_layout
19599
19600 \end_inset
19601 </cell>
19602 </row>
19603 <row topline="true">
19604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19605 \begin_inset Text
19606
19607 \begin_layout Standard
19608
19609 \family roman
19610 \series medium
19611 \shape up
19612 \size normal
19613 \emph off
19614 \bar no
19615 \noun off
19616 \color none
19617 _fs2ulong.
19618 \family default
19619 \series default
19620 \shape default
19621 \size default
19622 \emph default
19623 \bar default
19624 \noun default
19625 c
19626 \end_layout
19627
19628 \end_inset
19629 </cell>
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19631 \begin_inset Text
19632
19633 \begin_layout Standard
19634
19635 \family roman
19636 \series medium
19637 \shape up
19638 \size normal
19639 \emph off
19640 \bar no
19641 \noun off
19642 \color none
19643 convert floating point to unsigned long
19644 \end_layout
19645
19646 \end_inset
19647 </cell>
19648 </row>
19649 <row topline="true">
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19651 \begin_inset Text
19652
19653 \begin_layout Standard
19654
19655 \family roman
19656 \series medium
19657 \shape up
19658 \size normal
19659 \emph off
19660 \bar no
19661 \noun off
19662 \color none
19663 _fs2long.c
19664 \end_layout
19665
19666 \end_inset
19667 </cell>
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19669 \begin_inset Text
19670
19671 \begin_layout Standard
19672
19673 \family roman
19674 \series medium
19675 \shape up
19676 \size normal
19677 \emph off
19678 \bar no
19679 \noun off
19680 \color none
19681 convert floating point to signed long
19682 \end_layout
19683
19684 \end_inset
19685 </cell>
19686 </row>
19687 <row topline="true">
19688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19689 \begin_inset Text
19690
19691 \begin_layout Standard
19692
19693 \family roman
19694 \series medium
19695 \shape up
19696 \size normal
19697 \emph off
19698 \bar no
19699 \noun off
19700 \color none
19701 _uchar2fs.c
19702 \end_layout
19703
19704 \end_inset
19705 </cell>
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19707 \begin_inset Text
19708
19709 \begin_layout Standard
19710
19711 \family roman
19712 \series medium
19713 \shape up
19714 \size normal
19715 \emph off
19716 \bar no
19717 \noun off
19718 \color none
19719 convert unsigned char to floating point
19720 \end_layout
19721
19722 \end_inset
19723 </cell>
19724 </row>
19725 <row topline="true">
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19727 \begin_inset Text
19728
19729 \begin_layout Standard
19730
19731 \family roman
19732 \series medium
19733 \shape up
19734 \size normal
19735 \emph off
19736 \bar no
19737 \noun off
19738 \color none
19739 _char2fs.c
19740 \end_layout
19741
19742 \end_inset
19743 </cell>
19744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19745 \begin_inset Text
19746
19747 \begin_layout Standard
19748
19749 \family roman
19750 \series medium
19751 \shape up
19752 \size normal
19753 \emph off
19754 \bar no
19755 \noun off
19756 \color none
19757 convert char to floating point number
19758 \end_layout
19759
19760 \end_inset
19761 </cell>
19762 </row>
19763 <row topline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19765 \begin_inset Text
19766
19767 \begin_layout Standard
19768
19769 \family roman
19770 \series medium
19771 \shape up
19772 \size normal
19773 \emph off
19774 \bar no
19775 \noun off
19776 \color none
19777 _uint2fs.c
19778 \end_layout
19779
19780 \end_inset
19781 </cell>
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19783 \begin_inset Text
19784
19785 \begin_layout Standard
19786
19787 \family roman
19788 \series medium
19789 \shape up
19790 \size normal
19791 \emph off
19792 \bar no
19793 \noun off
19794 \color none
19795 convert unsigned int to floating point
19796 \end_layout
19797
19798 \end_inset
19799 </cell>
19800 </row>
19801 <row topline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806
19807 \family roman
19808 \series medium
19809 \shape up
19810 \size normal
19811 \emph off
19812 \bar no
19813 \noun off
19814 \color none
19815 _int2fs.c
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824
19825 \family roman
19826 \series medium
19827 \shape up
19828 \size normal
19829 \emph off
19830 \bar no
19831 \noun off
19832 \color none
19833 convert int to floating point numbers
19834 \end_layout
19835
19836 \end_inset
19837 </cell>
19838 </row>
19839 <row topline="true">
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19841 \begin_inset Text
19842
19843 \begin_layout Standard
19844
19845 \family roman
19846 \series medium
19847 \shape up
19848 \size normal
19849 \emph off
19850 \bar no
19851 \noun off
19852 \color none
19853 _ulong2fs.c
19854 \end_layout
19855
19856 \end_inset
19857 </cell>
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19859 \begin_inset Text
19860
19861 \begin_layout Standard
19862
19863 \family roman
19864 \series medium
19865 \shape up
19866 \size normal
19867 \emph off
19868 \bar no
19869 \noun off
19870 \color none
19871 convert unsigned long to floating point number
19872 \end_layout
19873
19874 \end_inset
19875 </cell>
19876 </row>
19877 <row topline="true" bottomline="true">
19878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19879 \begin_inset Text
19880
19881 \begin_layout Standard
19882
19883 \family roman
19884 \series medium
19885 \shape up
19886 \size normal
19887 \emph off
19888 \bar no
19889 \noun off
19890 \color none
19891 _long2fs.c
19892 \end_layout
19893
19894 \end_inset
19895 </cell>
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \begin_layout Standard
19900
19901 \family roman
19902 \series medium
19903 \shape up
19904 \size normal
19905 \emph off
19906 \bar no
19907 \noun off
19908 \color none
19909 convert long to floating point number
19910 \end_layout
19911
19912 \end_inset
19913 </cell>
19914 </row>
19915 </lyxtabular>
19916
19917 \end_inset
19918
19919
19920 \newline
19921
19922 \end_layout
19923
19924 \begin_layout Standard
19925 These support routines are developed in ANSI-C so there is room for space
19926  and speed improvement
19927 \begin_inset Foot
19928 status open
19929
19930 \begin_layout Standard
19931 These floating point routines (
19932 \emph on
19933 not
19934 \emph default
19935  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19936  
19937 \end_layout
19938
19939 \end_inset
19940
19941 .
19942  Note if all these routines are used simultaneously the data space might
19943  overflow.
19944  For serious floating point usage the large model might be needed.
19945  Also notice that you don't have to call this routines directly.
19946  The compiler will use them automatically every time a floating point operation
19947  is required.
19948 \begin_inset VSpace bigskip
19949 \end_inset
19950
19951
19952 \end_layout
19953
19954 \begin_layout Section
19955 Library Routines
19956 \begin_inset LatexCommand \index{Libraries}
19957
19958 \end_inset
19959
19960
19961 \end_layout
19962
19963 \begin_layout Standard
19964
19965 \emph on
19966 <pending: this is messy and incomplete - a little more information is in
19967  sdcc/doc/libdoc.txt
19968 \emph default
19969  >
19970 \end_layout
19971
19972 \begin_layout Subsection
19973 Compiler support routines (_gptrget, _mulint etc.)
19974 \end_layout
19975
19976 \begin_layout Subsection
19977 Stdclib functions (puts, printf, strcat etc.)
19978 \end_layout
19979
19980 \begin_layout Subsubsection
19981 <stdio.h>
19982 \end_layout
19983
19984 \begin_layout Paragraph
19985 getchar(), putchar()
19986 \end_layout
19987
19988 \begin_layout Standard
19989 \begin_inset LatexCommand \index{<stdio.h>}
19990
19991 \end_inset
19992
19993 As usual on embedded systems you have to provide your own 
19994 \family typewriter
19995 getchar()
19996 \begin_inset LatexCommand \index{getchar()}
19997
19998 \end_inset
19999
20000  
20001 \family default
20002 and 
20003 \family typewriter
20004 putchar()
20005 \begin_inset LatexCommand \index{putchar()}
20006
20007 \end_inset
20008
20009
20010 \family default
20011  routines.
20012  SDCC does not know whether the system connects to a serial line with or
20013  without handshake, LCD, keyboard or other device.
20014  And whether a 
20015 \family typewriter
20016 lf
20017 \family default
20018  to 
20019 \family typewriter
20020 crlf
20021 \family default
20022  conversion within 
20023 \family typewriter
20024 putchar()
20025 \family default
20026  is intended.
20027  You'll find examples for serial routines f.e.
20028  in sdcc/device/lib.
20029  For the mcs51 this minimalistic polling 
20030 \family typewriter
20031 putchar()
20032 \family default
20033  routine might be a start:
20034 \end_layout
20035
20036 \begin_layout Verse
20037
20038 \family typewriter
20039 void putchar (char c) { 
20040 \newline
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 while (!TI)\InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048  /* assumes UART is initialized */
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 \InsetSpace ~
20055 \InsetSpace ~
20056 \InsetSpace ~
20057 \InsetSpace ~
20058 ;
20059 \newline
20060 \InsetSpace ~
20061 \InsetSpace ~
20062 \InsetSpace ~
20063 \InsetSpace ~
20064 TI
20065  = 0;
20066 \newline
20067 \InsetSpace ~
20068 \InsetSpace ~
20069 \InsetSpace ~
20070 \InsetSpace ~
20071 SBUF = c;
20072 \newline
20073 }
20074 \end_layout
20075
20076 \begin_layout Paragraph
20077 printf()
20078 \end_layout
20079
20080 \begin_layout Standard
20081 The default
20082 \family typewriter
20083  printf()
20084 \begin_inset LatexCommand \index{printf()}
20085
20086 \end_inset
20087
20088
20089 \family default
20090  implementation in
20091 \family typewriter
20092  printf_large.c
20093 \family default
20094  does not support float (except on ds390).
20095  To enable this recompile it with the option 
20096 \emph on
20097 -
20098 \begin_inset ERT
20099 status collapsed
20100
20101 \begin_layout Standard
20102
20103
20104 \backslash
20105 /
20106 \end_layout
20107
20108 \end_inset
20109
20110 DUSE_FLOATS=1
20111 \begin_inset LatexCommand \index{USE\_FLOATS}
20112
20113 \end_inset
20114
20115
20116 \emph default
20117  on the command line.
20118  Use
20119 \emph on
20120  -
20121 \begin_inset ERT
20122 status collapsed
20123
20124 \begin_layout Standard
20125
20126
20127 \backslash
20128 /
20129 \end_layout
20130
20131 \end_inset
20132
20133 -model-large
20134 \begin_inset LatexCommand \index{-\/-model-large}
20135
20136 \end_inset
20137
20138
20139 \emph default
20140  for the mcs51 port, since this uses a lot of memory.
20141 \end_layout
20142
20143 \begin_layout Standard
20144 If you're short on code memory you might want to use 
20145 \family typewriter
20146 printf_small()
20147 \begin_inset LatexCommand \index{printf\_small()}
20148
20149 \end_inset
20150
20151
20152 \family default
20153  
20154 \emph on
20155 instead
20156 \emph default
20157  of
20158 \family typewriter
20159  printf().
20160
20161 \family default
20162  For the mcs51 there additionally are assembly versions 
20163 \family typewriter
20164 printf_tiny()
20165 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20166
20167 \end_inset
20168
20169
20170 \family default
20171  (subset of printf using less than 270 bytes) and 
20172 \family typewriter
20173 printf_fast()
20174 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20175
20176 \end_inset
20177
20178  
20179 \family default
20180 and
20181 \family typewriter
20182  printf_fast_f()
20183 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20184
20185 \end_inset
20186
20187
20188 \family default
20189  (floating-point aware version of printf_fast) which should fit the requirements
20190  of many embedded systems (printf_fast() can be customized by unsetting
20191  #defines to 
20192 \emph on
20193 not
20194 \emph default
20195  support long variables and field widths).
20196  Be sure to use only one of these printf options within a project.
20197 \newline
20198
20199 \end_layout
20200
20201 \begin_layout Standard
20202 Feature matrix of different 
20203 \emph on
20204 printf
20205 \emph default
20206  options on mcs51.
20207 \end_layout
20208
20209 \begin_layout Standard
20210 \begin_inset Tabular
20211 <lyxtabular version="3" rows="14" columns="7">
20212 <features islongtable="true">
20213 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20214 <column alignment="center" valignment="top" leftline="true" width="0">
20215 <column alignment="center" valignment="top" leftline="true" width="12col%">
20216 <column alignment="center" valignment="top" leftline="true" width="10col%">
20217 <column alignment="center" valignment="top" leftline="true" width="0">
20218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20219 <column alignment="center" valignment="top" rightline="true" width="0">
20220 <row topline="true" bottomline="true" endhead="true">
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20222 \begin_inset Text
20223
20224 \begin_layout Standard
20225
20226 \series bold
20227 \size large
20228 mcs51
20229 \end_layout
20230
20231 \end_inset
20232 </cell>
20233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20234 \begin_inset Text
20235
20236 \begin_layout Standard
20237 printf
20238 \begin_inset LatexCommand \index{printf}
20239
20240 \end_inset
20241
20242
20243 \end_layout
20244
20245 \end_inset
20246 </cell>
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20248 \begin_inset Text
20249
20250 \begin_layout Standard
20251 printf 
20252 \size scriptsize
20253 USE_FLOATS=1
20254 \end_layout
20255
20256 \end_inset
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 printf_small
20263 \end_layout
20264
20265 \end_inset
20266 </cell>
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20268 \begin_inset Text
20269
20270 \begin_layout Standard
20271 printf_fast
20272 \end_layout
20273
20274 \end_inset
20275 </cell>
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20277 \begin_inset Text
20278
20279 \begin_layout Standard
20280 printf_fast_f
20281 \end_layout
20282
20283 \end_inset
20284 </cell>
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20286 \begin_inset Text
20287
20288 \begin_layout Standard
20289 printf_tiny
20290 \end_layout
20291
20292 \end_inset
20293 </cell>
20294 </row>
20295 <row topline="true" endhead="true">
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20297 \begin_inset Text
20298
20299 \begin_layout Standard
20300 filename
20301 \end_layout
20302
20303 \end_inset
20304 </cell>
20305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20306 \begin_inset Text
20307
20308 \begin_layout Standard
20309
20310 \size scriptsize
20311 printf_large.c
20312 \end_layout
20313
20314 \end_inset
20315 </cell>
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20317 \begin_inset Text
20318
20319 \begin_layout Standard
20320
20321 \size scriptsize
20322 printf_large.c
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
20332 \size scriptsize
20333 printfl.c
20334 \end_layout
20335
20336 \end_inset
20337 </cell>
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 \begin_inset Text
20340
20341 \begin_layout Standard
20342
20343 \size scriptsize
20344 printf_fast.c
20345 \end_layout
20346
20347 \end_inset
20348 </cell>
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \begin_layout Standard
20353
20354 \size scriptsize
20355 printf_fast_f.c
20356 \end_layout
20357
20358 \end_inset
20359 </cell>
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20361 \begin_inset Text
20362
20363 \begin_layout Standard
20364
20365 \size scriptsize
20366 printf_tiny.c
20367 \end_layout
20368
20369 \end_inset
20370 </cell>
20371 </row>
20372 <row topline="true" endhead="true">
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377 \begin_inset Quotes sld
20378 \end_inset
20379
20380 Hello World
20381 \begin_inset Quotes srd
20382 \end_inset
20383
20384  size
20385 \end_layout
20386
20387 \begin_layout Standard
20388 small / large
20389 \end_layout
20390
20391 \end_inset
20392 </cell>
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_inset Text
20395
20396 \begin_layout Standard
20397 1.7k / 2.4k
20398 \end_layout
20399
20400 \end_inset
20401 </cell>
20402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_inset Text
20404
20405 \begin_layout Standard
20406 4.3k / 5.6k
20407 \end_layout
20408
20409 \end_inset
20410 </cell>
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \begin_layout Standard
20415 1.2k / 1.8k
20416 \end_layout
20417
20418 \end_inset
20419 </cell>
20420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20421 \begin_inset Text
20422
20423 \begin_layout Standard
20424 1.3k / 1.3k
20425 \end_layout
20426
20427 \end_inset
20428 </cell>
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20430 \begin_inset Text
20431
20432 \begin_layout Standard
20433 1.9k / 1.9k
20434 \end_layout
20435
20436 \end_inset
20437 </cell>
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20439 \begin_inset Text
20440
20441 \begin_layout Standard
20442 0.44k / 0.44k
20443 \end_layout
20444
20445 \end_inset
20446 </cell>
20447 </row>
20448 <row topline="true" endhead="true">
20449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20450 \begin_inset Text
20451
20452 \begin_layout Standard
20453 code size
20454 \end_layout
20455
20456 \begin_layout Standard
20457 small / large
20458 \end_layout
20459
20460 \end_inset
20461 </cell>
20462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20463 \begin_inset Text
20464
20465 \begin_layout Standard
20466 1.4k / 2.0k
20467 \end_layout
20468
20469 \end_inset
20470 </cell>
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20472 \begin_inset Text
20473
20474 \begin_layout Standard
20475 2.8k / 3.7k
20476 \end_layout
20477
20478 \end_inset
20479 </cell>
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 \begin_inset Text
20482
20483 \begin_layout Standard
20484 0.45k / 0.47k (+ _ltoa)
20485 \end_layout
20486
20487 \end_inset
20488 </cell>
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 1.2k / 1.2k
20494 \end_layout
20495
20496 \end_inset
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \begin_layout Standard
20502 1.6k / 1.6k
20503 \end_layout
20504
20505 \end_inset
20506 </cell>
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \begin_layout Standard
20511 0.26k / 0.26k
20512 \end_layout
20513
20514 \end_inset
20515 </cell>
20516 </row>
20517 <row topline="true">
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20519 \begin_inset Text
20520
20521 \begin_layout Standard
20522 formats
20523 \end_layout
20524
20525 \end_inset
20526 </cell>
20527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20528 \begin_inset Text
20529
20530 \begin_layout Standard
20531 cdi
20532 \emph on
20533 o
20534 \emph default
20535 psux
20536 \end_layout
20537
20538 \end_inset
20539 </cell>
20540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20541 \begin_inset Text
20542
20543 \begin_layout Standard
20544
20545 \family roman
20546 \series medium
20547 \shape up
20548 \size normal
20549 \emph off
20550 \bar no
20551 \noun off
20552 \color none
20553 cd
20554 \family default
20555 \series default
20556 \shape default
20557 \size default
20558 \emph default
20559 \bar default
20560 \noun default
20561 f
20562 \family roman
20563 \series medium
20564 \shape up
20565 \size normal
20566 \emph off
20567 \bar no
20568 \noun off
20569 i
20570 \family default
20571 \series default
20572 \shape default
20573 \size default
20574 \emph on
20575 \bar default
20576 \noun default
20577 o
20578 \family roman
20579 \series medium
20580 \shape up
20581 \size normal
20582 \emph off
20583 \bar no
20584 \noun off
20585 psux
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \begin_layout Standard
20594 c
20595 \family roman
20596 \series medium
20597 \shape up
20598 \size normal
20599 \emph off
20600 \bar no
20601 \noun off
20602 \color none
20603 d
20604 \family default
20605 \series default
20606 \shape default
20607 \size default
20608 \emph on
20609 \bar default
20610 \noun default
20611 o
20612 \family roman
20613 \series medium
20614 \shape up
20615 \size normal
20616 \emph off
20617 \bar no
20618 \noun off
20619 s
20620 \family default
20621 \series default
20622 \shape default
20623 \size default
20624 \emph default
20625 \bar default
20626 \noun default
20627 x
20628 \end_layout
20629
20630 \end_inset
20631 </cell>
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_inset Text
20634
20635 \begin_layout Standard
20636 cdsux
20637 \end_layout
20638
20639 \end_inset
20640 </cell>
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20642 \begin_inset Text
20643
20644 \begin_layout Standard
20645 cdfsux
20646 \end_layout
20647
20648 \end_inset
20649 </cell>
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20651 \begin_inset Text
20652
20653 \begin_layout Standard
20654 cdsux
20655 \end_layout
20656
20657 \end_inset
20658 </cell>
20659 </row>
20660 <row topline="true">
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20662 \begin_inset Text
20663
20664 \begin_layout Standard
20665 long (32 bit) support
20666 \end_layout
20667
20668 \end_inset
20669 </cell>
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_inset Text
20672
20673 \begin_layout Standard
20674 x
20675 \end_layout
20676
20677 \end_inset
20678 </cell>
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20680 \begin_inset Text
20681
20682 \begin_layout Standard
20683 x
20684 \end_layout
20685
20686 \end_inset
20687 </cell>
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20689 \begin_inset Text
20690
20691 \begin_layout Standard
20692 x
20693 \end_layout
20694
20695 \end_inset
20696 </cell>
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \begin_layout Standard
20701 x
20702 \end_layout
20703
20704 \end_inset
20705 </cell>
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \begin_layout Standard
20710
20711 \family roman
20712 \series medium
20713 \shape up
20714 \size normal
20715 \emph off
20716 \bar no
20717 \noun off
20718 \color none
20719 x
20720 \end_layout
20721
20722 \end_inset
20723 </cell>
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20725 \begin_inset Text
20726
20727 \begin_layout Standard
20728 -
20729 \end_layout
20730
20731 \end_inset
20732 </cell>
20733 </row>
20734 <row topline="true">
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 \begin_inset Text
20737
20738 \begin_layout Standard
20739 byte arguments on stack
20740 \end_layout
20741
20742 \end_inset
20743 </cell>
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \begin_layout Standard
20748 b
20749 \end_layout
20750
20751 \end_inset
20752 </cell>
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20754 \begin_inset Text
20755
20756 \begin_layout Standard
20757 b
20758 \end_layout
20759
20760 \end_inset
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766 -
20767 \end_layout
20768
20769 \end_inset
20770 </cell>
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20772 \begin_inset Text
20773
20774 \begin_layout Standard
20775 -
20776 \end_layout
20777
20778 \end_inset
20779 </cell>
20780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20781 \begin_inset Text
20782
20783 \begin_layout Standard
20784 -
20785 \end_layout
20786
20787 \end_inset
20788 </cell>
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20790 \begin_inset Text
20791
20792 \begin_layout Standard
20793 -
20794 \end_layout
20795
20796 \end_inset
20797 </cell>
20798 </row>
20799 <row topline="true">
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20801 \begin_inset Text
20802
20803 \begin_layout Standard
20804 float format
20805 \begin_inset LatexCommand \index{Floating point support}
20806
20807 \end_inset
20808
20809
20810 \end_layout
20811
20812 \end_inset
20813 </cell>
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20815 \begin_inset Text
20816
20817 \begin_layout Standard
20818 -
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 %f
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" rightline="true" usebox="none">
20851 \begin_inset Text
20852
20853 \begin_layout Standard
20854 %f
20855 \begin_inset Foot
20856 status collapsed
20857
20858 \begin_layout Standard
20859 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20860 \end_layout
20861
20862 \end_inset
20863
20864
20865 \end_layout
20866
20867 \end_inset
20868 </cell>
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20870 \begin_inset Text
20871
20872 \begin_layout Standard
20873 -
20874 \end_layout
20875
20876 \end_inset
20877 </cell>
20878 </row>
20879 <row topline="true">
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 \begin_inset Text
20882
20883 \begin_layout Standard
20884 float formats %e %g
20885 \end_layout
20886
20887 \end_inset
20888 </cell>
20889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20890 \begin_inset Text
20891
20892 \begin_layout Standard
20893 -
20894 \end_layout
20895
20896 \end_inset
20897 </cell>
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \begin_layout Standard
20902 -
20903 \end_layout
20904
20905 \end_inset
20906 </cell>
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20908 \begin_inset Text
20909
20910 \begin_layout Standard
20911 -
20912 \end_layout
20913
20914 \end_inset
20915 </cell>
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \begin_layout Standard
20920 -
20921 \end_layout
20922
20923 \end_inset
20924 </cell>
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20926 \begin_inset Text
20927
20928 \begin_layout Standard
20929 -
20930 \end_layout
20931
20932 \end_inset
20933 </cell>
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20935 \begin_inset Text
20936
20937 \begin_layout Standard
20938 -
20939 \end_layout
20940
20941 \end_inset
20942 </cell>
20943 </row>
20944 <row topline="true" bottomline="true">
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_inset Text
20947
20948 \begin_layout Standard
20949 field width
20950 \end_layout
20951
20952 \end_inset
20953 </cell>
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20955 \begin_inset Text
20956
20957 \begin_layout Standard
20958 x
20959 \end_layout
20960
20961 \end_inset
20962 </cell>
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20964 \begin_inset Text
20965
20966 \begin_layout Standard
20967 x
20968 \end_layout
20969
20970 \end_inset
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \begin_layout Standard
20976 -
20977 \end_layout
20978
20979 \end_inset
20980 </cell>
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 \begin_inset Text
20983
20984 \begin_layout Standard
20985 x
20986 \end_layout
20987
20988 \end_inset
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \begin_layout Standard
20994 x
20995 \end_layout
20996
20997 \end_inset
20998 </cell>
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21000 \begin_inset Text
21001
21002 \begin_layout Standard
21003 -
21004 \end_layout
21005
21006 \end_inset
21007 </cell>
21008 </row>
21009 <row bottomline="true">
21010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21011 \begin_inset Text
21012
21013 \begin_layout Standard
21014 string speed
21015 \begin_inset Foot
21016 status collapsed
21017
21018 \begin_layout Standard
21019 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21020 \backslash
21021 r', '
21022 \backslash
21023 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21024 \end_layout
21025
21026 \end_inset
21027
21028 ,
21029 \end_layout
21030
21031 \begin_layout Standard
21032 small / large
21033 \end_layout
21034
21035 \end_inset
21036 </cell>
21037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_inset Text
21039
21040 \begin_layout Standard
21041 1.52 / 2.59 ms
21042 \end_layout
21043
21044 \end_inset
21045 </cell>
21046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21047 \begin_inset Text
21048
21049 \begin_layout Standard
21050 1.53 / 2.62 ms
21051 \end_layout
21052
21053 \end_inset
21054 </cell>
21055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21056 \begin_inset Text
21057
21058 \begin_layout Standard
21059 0.92 / 0.93 ms
21060 \end_layout
21061
21062 \end_inset
21063 </cell>
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21065 \begin_inset Text
21066
21067 \begin_layout Standard
21068 0.45 / 0.45 ms
21069 \end_layout
21070
21071 \end_inset
21072 </cell>
21073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21074 \begin_inset Text
21075
21076 \begin_layout Standard
21077 0.46 / 0.46 ms
21078 \end_layout
21079
21080 \end_inset
21081 </cell>
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21083 \begin_inset Text
21084
21085 \begin_layout Standard
21086 0.45 / 0.45 ms
21087 \end_layout
21088
21089 \end_inset
21090 </cell>
21091 </row>
21092 <row bottomline="true">
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \begin_layout Standard
21097 int speed
21098 \begin_inset Foot
21099 status collapsed
21100
21101 \begin_layout Standard
21102 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21103  putchar()
21104 \end_layout
21105
21106 \end_inset
21107
21108 ,
21109 \end_layout
21110
21111 \begin_layout Standard
21112 small / large
21113 \end_layout
21114
21115 \end_inset
21116 </cell>
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_inset Text
21119
21120 \begin_layout Standard
21121 3.01 / 3.61 ms
21122 \end_layout
21123
21124 \end_inset
21125 </cell>
21126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21127 \begin_inset Text
21128
21129 \begin_layout Standard
21130 3.01 / 3.61 ms
21131 \end_layout
21132
21133 \end_inset
21134 </cell>
21135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21136 \begin_inset Text
21137
21138 \begin_layout Standard
21139 3.51 / 18.13 ms
21140 \end_layout
21141
21142 \end_inset
21143 </cell>
21144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21145 \begin_inset Text
21146
21147 \begin_layout Standard
21148 0.22 / 0.22 ms
21149 \end_layout
21150
21151 \end_inset
21152 </cell>
21153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21154 \begin_inset Text
21155
21156 \begin_layout Standard
21157 0.23 / 0.23 ms
21158 \end_layout
21159
21160 \end_inset
21161 </cell>
21162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21163 \begin_inset Text
21164
21165 \begin_layout Standard
21166 0.25 / 0.25 ms
21167 \begin_inset Foot
21168 status collapsed
21169
21170 \begin_layout Standard
21171 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21172 \end_layout
21173
21174 \end_inset
21175
21176
21177 \end_layout
21178
21179 \end_inset
21180 </cell>
21181 </row>
21182 <row bottomline="true">
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \begin_layout Standard
21187 long speed
21188 \begin_inset Foot
21189 status collapsed
21190
21191 \begin_layout Standard
21192 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21193  empty putchar()
21194 \end_layout
21195
21196 \end_inset
21197
21198 ,
21199 \end_layout
21200
21201 \begin_layout Standard
21202 small / large
21203 \end_layout
21204
21205 \end_inset
21206 </cell>
21207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21208 \begin_inset Text
21209
21210 \begin_layout Standard
21211 5.37 / 6.31 ms
21212 \end_layout
21213
21214 \end_inset
21215 </cell>
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21217 \begin_inset Text
21218
21219 \begin_layout Standard
21220 5.37 / 6.31 ms
21221 \end_layout
21222
21223 \end_inset
21224 </cell>
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21226 \begin_inset Text
21227
21228 \begin_layout Standard
21229 8.71 / 40.65 ms
21230 \end_layout
21231
21232 \end_inset
21233 </cell>
21234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21235 \begin_inset Text
21236
21237 \begin_layout Standard
21238 0.40 / 0.40 ms
21239 \end_layout
21240
21241 \end_inset
21242 </cell>
21243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21244 \begin_inset Text
21245
21246 \begin_layout Standard
21247 0.40 / 0.40 ms
21248 \end_layout
21249
21250 \end_inset
21251 </cell>
21252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21253 \begin_inset Text
21254
21255 \begin_layout Standard
21256 -
21257 \end_layout
21258
21259 \end_inset
21260 </cell>
21261 </row>
21262 <row bottomline="true">
21263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 \begin_inset Text
21265
21266 \begin_layout Standard
21267 float speed
21268 \begin_inset Foot
21269 status collapsed
21270
21271 \begin_layout Standard
21272 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21273  empty putchar()
21274 \end_layout
21275
21276 \end_inset
21277
21278 ,
21279 \end_layout
21280
21281 \begin_layout Standard
21282 small / large
21283 \end_layout
21284
21285 \end_inset
21286 </cell>
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21288 \begin_inset Text
21289
21290 \begin_layout Standard
21291 -
21292 \end_layout
21293
21294 \end_inset
21295 </cell>
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \begin_layout Standard
21300 7.49 / 22.47 ms
21301 \end_layout
21302
21303 \end_inset
21304 </cell>
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21306 \begin_inset Text
21307
21308 \begin_layout Standard
21309 -
21310 \end_layout
21311
21312 \end_inset
21313 </cell>
21314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21315 \begin_inset Text
21316
21317 \begin_layout Standard
21318 -
21319 \end_layout
21320
21321 \end_inset
21322 </cell>
21323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21324 \begin_inset Text
21325
21326 \begin_layout Standard
21327 1.04 / 1.04 ms
21328 \end_layout
21329
21330 \end_inset
21331 </cell>
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21333 \begin_inset Text
21334
21335 \begin_layout Standard
21336 -
21337 \end_layout
21338
21339 \end_inset
21340 </cell>
21341 </row>
21342 </lyxtabular>
21343
21344 \end_inset
21345
21346
21347 \end_layout
21348
21349 \begin_layout Subsubsection
21350 <malloc.h>
21351 \begin_inset LatexCommand \index{malloc.h}
21352
21353 \end_inset
21354
21355
21356 \end_layout
21357
21358 \begin_layout Standard
21359 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21360  using dynamic memory allocation
21361 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21362
21363 \end_inset
21364
21365  and a default heap
21366 \begin_inset LatexCommand \index{heap (malloc)}
21367
21368 \end_inset
21369
21370  space of 1024 bytes is provided for malloc to allocate memory from.
21371  If you need a different heap size you need to recompile _heap.c with the
21372  required size defined in HEAP_SIZE.
21373  It is recommended to make a copy of this file into your project directory
21374  and compile it there with:
21375 \end_layout
21376
21377 \begin_layout Verse
21378
21379 \family typewriter
21380 sdcc -c _heap.c -D HEAD_SIZE=2048
21381 \end_layout
21382
21383 \begin_layout Standard
21384 And then link it with:
21385 \end_layout
21386
21387 \begin_layout Verse
21388
21389 \family typewriter
21390 sdcc main.rel _heap.rel
21391 \end_layout
21392
21393 \begin_layout Subsection
21394 Math functions (sinf, powf, sqrtf etc.)
21395 \end_layout
21396
21397 \begin_layout Subsubsection
21398 <math.h>
21399 \end_layout
21400
21401 \begin_layout Standard
21402 See definitions in file <math.h>.
21403 \end_layout
21404
21405 \begin_layout Subsection
21406 Other libraries
21407 \end_layout
21408
21409 \begin_layout Standard
21410 Libraries
21411 \begin_inset LatexCommand \index{Libraries}
21412
21413 \end_inset
21414
21415  included in SDCC should have a license at least as liberal as the GNU Lesser
21416  General Public License
21417 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21418
21419 \end_inset
21420
21421  
21422 \emph on
21423 LGPL
21424 \emph default
21425 .
21426 \end_layout
21427
21428 \begin_layout Standard
21429 \begin_inset Note Note
21430 status collapsed
21431
21432 \begin_layout Standard
21433 license statements for the libraries are missing.
21434  sdcc/device/lib/ser_ir.c
21435 \end_layout
21436
21437 \begin_layout Standard
21438 or _decdptr f.e.
21439  come with a GPL (as opposed to LGPL) License - this will not be liberal
21440  enough for many embedded programmers.
21441 \end_layout
21442
21443 \end_inset
21444
21445
21446 \end_layout
21447
21448 \begin_layout Standard
21449 If you have ported some library or want to share experience about some code
21450  which f.e.
21451  falls into any of these categories Busses (I
21452 \begin_inset Formula $^{\textrm{2}}$
21453 \end_inset
21454
21455 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21456  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21457  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21458 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21459
21460 \end_inset
21461
21462 \InsetSpace ~
21463 would certainly like to hear about it.
21464 \end_layout
21465
21466 \begin_layout Standard
21467 Programmers coding for embedded systems are not especially famous for being
21468  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21469 e these references are very valuable.
21470  Let's help to create a climate where information is shared.
21471 \begin_inset VSpace bigskip
21472 \end_inset
21473
21474
21475 \end_layout
21476
21477 \begin_layout Section
21478 Memory Models
21479 \end_layout
21480
21481 \begin_layout Subsection
21482 MCS51 Memory Models
21483 \begin_inset LatexCommand \index{Memory model}
21484
21485 \end_inset
21486
21487
21488 \begin_inset LatexCommand \index{MCS51 memory model}
21489
21490 \end_inset
21491
21492
21493 \end_layout
21494
21495 \begin_layout Subsubsection
21496 Small, Medium and Large
21497 \end_layout
21498
21499 \begin_layout Standard
21500 SDCC allows three memory models for MCS51 code, 
21501 \shape slanted
21502 small, medium
21503 \shape default
21504  and 
21505 \shape slanted
21506 large
21507 \shape default
21508 .
21509  Modules compiled with different memory models should 
21510 \emph on
21511 never
21512 \emph default
21513  be combined together or the results would be unpredictable.
21514  The library routines supplied with the compiler are compiled as small,
21515  medium and large.
21516  The compiled library modules are contained in separate directories as small,
21517  medium and large so that you can link to the appropriate set.
21518 \end_layout
21519
21520 \begin_layout Standard
21521 When the medium or large model is used all variables declared without a
21522  storage class will be allocated into the external ram, this includes all
21523  parameters and local variables (for non-reentrant
21524 \begin_inset LatexCommand \index{reentrant}
21525
21526 \end_inset
21527
21528  functions).
21529  When the small model is used variables without storage class are allocated
21530  in the internal ram.
21531 \end_layout
21532
21533 \begin_layout Standard
21534 Judicious usage of the processor specific storage classes
21535 \begin_inset LatexCommand \index{Storage class}
21536
21537 \end_inset
21538
21539  and the 'reentrant' function type will yield much more efficient code,
21540  than using the large model.
21541  Several optimizations are disabled when the program is compiled using the
21542  large model, it is therefore recommended that the small model be used unless
21543  absolutely required.
21544 \end_layout
21545
21546 \begin_layout Subsubsection
21547 External Stack
21548 \begin_inset LatexCommand \label{sub:External-Stack}
21549
21550 \end_inset
21551
21552
21553 \begin_inset LatexCommand \index{stack}
21554
21555 \end_inset
21556
21557
21558 \begin_inset LatexCommand \index{External stack (mcs51)}
21559
21560 \end_inset
21561
21562
21563 \end_layout
21564
21565 \begin_layout Standard
21566 The external stack (-
21567 \begin_inset ERT
21568 status collapsed
21569
21570 \begin_layout Standard
21571
21572
21573 \backslash
21574 /
21575 \end_layout
21576
21577 \end_inset
21578
21579 -xstack option
21580 \begin_inset LatexCommand \index{-\/-xstack}
21581
21582 \end_inset
21583
21584 ) is located in pdata
21585 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21586
21587 \end_inset
21588
21589  memory (usually at the start of the external ram segment) and uses all
21590  unused space in pdata (max.
21591  256 bytes).
21592  When -
21593 \begin_inset ERT
21594 status collapsed
21595
21596 \begin_layout Standard
21597
21598
21599 \backslash
21600 /
21601 \end_layout
21602
21603 \end_inset
21604
21605 -xstack option is used to compile the program, the parameters and local
21606  variables
21607 \begin_inset LatexCommand \index{local variables}
21608
21609 \end_inset
21610
21611  of all reentrant functions are allocated in this area.
21612  This option is provided for programs with large stack space requirements.
21613  When used with the -
21614 \begin_inset ERT
21615 status collapsed
21616
21617 \begin_layout Standard
21618
21619
21620 \backslash
21621 /
21622 \end_layout
21623
21624 \end_inset
21625
21626 -stack-auto
21627 \begin_inset LatexCommand \index{-\/-stack-auto}
21628
21629 \end_inset
21630
21631  option, all parameters and local variables are allocated on the external
21632  stack (note: support libraries will need to be recompiled with the same
21633  options.
21634  There is a predefined target in the library makefile).
21635 \end_layout
21636
21637 \begin_layout Standard
21638 The compiler outputs the higher order address byte of the external ram segment
21639  into port P2
21640 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21641
21642 \end_inset
21643
21644  (see also section 
21645 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21646
21647 \end_inset
21648
21649 ), therefore when using the External Stack option, this port 
21650 \emph on
21651 may not
21652 \emph default
21653  be used by the application program.
21654 \end_layout
21655
21656 \begin_layout Subsection
21657 DS390 Memory Model
21658 \begin_inset LatexCommand \index{Memory model}
21659
21660 \end_inset
21661
21662
21663 \begin_inset LatexCommand \index{DS390 memory model}
21664
21665 \end_inset
21666
21667
21668 \end_layout
21669
21670 \begin_layout Standard
21671 The only model supported is Flat 24
21672 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21673
21674 \end_inset
21675
21676 .
21677  This generates code for the 24 bit contiguous addressing mode of the Dallas
21678  DS80C390 part.
21679  In this mode, up to four meg of external RAM or code space can be directly
21680  addressed.
21681  See the data sheets at www.dalsemi.com for further information on this part.
21682 \newline
21683
21684 \newline
21685 Note
21686  that the compiler does not generate any code to place the processor into
21687  24 bitmode (although 
21688 \emph on
21689 tinibios
21690 \emph default
21691  in the ds390 libraries will do that for you).
21692  If you don't use 
21693 \emph on
21694 tinibios
21695 \emph default
21696
21697 \begin_inset LatexCommand \index{Tinibios (DS390)}
21698
21699 \end_inset
21700
21701 , the boot loader or similar code must ensure that the processor is in 24
21702  bit contiguous addressing mode before calling the SDCC startup code.
21703 \newline
21704
21705 \newline
21706 Like
21707  the 
21708 \emph on
21709 -
21710 \begin_inset ERT
21711 status collapsed
21712
21713 \begin_layout Standard
21714
21715
21716 \backslash
21717 /
21718 \end_layout
21719
21720 \end_inset
21721
21722 -model-large
21723 \emph default
21724  option, variables will by default be placed into the XDATA segment.
21725  
21726 \newline
21727
21728 \newline
21729 Segments may be placed anywhere in the 4 meg address space using the usual
21730  -
21731 \begin_inset ERT
21732 status collapsed
21733
21734 \begin_layout Standard
21735
21736
21737 \backslash
21738 /
21739 \end_layout
21740
21741 \end_inset
21742
21743 -*-loc options.
21744  Note that if any segments are located above 64K, the -r flag must be passed
21745  to the linker to generate the proper segment relocations, and the Intel
21746  HEX output format must be used.
21747  The -r flag can be passed to the linker by using the option 
21748 \emph on
21749 -Wl-r
21750 \emph default
21751  on the SDCC command line.
21752  However, currently the linker can not handle code segments > 64k.
21753 \end_layout
21754
21755 \begin_layout Section
21756 Pragmas
21757 \begin_inset LatexCommand \label{sec:Pragmas}
21758
21759 \end_inset
21760
21761
21762 \begin_inset LatexCommand \index{Pragmas}
21763
21764 \end_inset
21765
21766
21767 \end_layout
21768
21769 \begin_layout Standard
21770 Pragmas are used to turn on and/or off certain compiler options.
21771  Some of them are closely related to corresponding command-line options
21772  (see section 
21773 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21774
21775 \end_inset
21776
21777 ).
21778 \newline
21779 Pragmas should be placed before and/or after a function, placing pragmas
21780  inside a function body could have unpredictable results.
21781 \newline
21782
21783 \newline
21784 SDCC supports the
21785  following #pragma directives:
21786 \end_layout
21787
21788 \begin_layout Itemize
21789
21790 \series bold
21791 save
21792 \series default
21793
21794 \begin_inset LatexCommand \index{\#pragma save}
21795
21796 \end_inset
21797
21798  - this will save most current options to the save/restore stack.
21799  See #pragma\InsetSpace ~
21800 restore.
21801 \end_layout
21802
21803 \begin_layout Itemize
21804
21805 \series bold
21806 restore
21807 \series default
21808
21809 \begin_inset LatexCommand \index{\#pragma restore}
21810
21811 \end_inset
21812
21813  - will restore saved options from the last save.
21814  saves & restores can be nested.
21815  SDCC uses a save/restore stack: save pushes current options to the stack,
21816  restore pulls current options from the stack.
21817  See #pragma\InsetSpace ~
21818 save.
21819 \newline
21820
21821 \end_layout
21822
21823 \begin_layout Itemize
21824
21825 \series bold
21826 callee_saves
21827 \series default
21828
21829 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21830
21831 \end_inset
21832
21833
21834 \begin_inset LatexCommand \index{function prologue}
21835
21836 \end_inset
21837
21838  function1[,function2[,function3...]] 
21839 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21840
21841 \end_inset
21842
21843 - The compiler by default uses a caller saves convention for register saving
21844  across function calls, however this can cause unnecessary register pushing
21845  and popping
21846 \begin_inset LatexCommand \index{push/pop}
21847
21848 \end_inset
21849
21850  when calling small functions from larger functions.
21851  This option can be used to switch off the register saving convention for
21852  the function names specified.
21853  The compiler will not save registers when calling these functions, extra
21854  code need to be manually inserted at the entry and exit for these functions
21855  to save and restore the registers used by these functions, this can SUBSTANTIAL
21856 LY reduce code and improve run time performance of the generated code.
21857  In the future the compiler (with inter procedural analysis) may be able
21858  to determine the appropriate scheme to use for each function call.
21859  If -
21860 \begin_inset ERT
21861 status collapsed
21862
21863 \begin_layout Standard
21864
21865
21866 \backslash
21867 /
21868 \end_layout
21869
21870 \end_inset
21871
21872 -callee-saves command line option is used (see page 
21873 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21874
21875 \end_inset
21876
21877 ), the function names specified in #pragma\InsetSpace ~
21878 callee_saves
21879 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21880
21881 \end_inset
21882
21883  is appended to the list of functions specified in the command line.
21884 \end_layout
21885
21886 \begin_layout Itemize
21887
21888 \series bold
21889 exclude
21890 \series default
21891
21892 \begin_inset LatexCommand \index{\#pragma exclude}
21893
21894 \end_inset
21895
21896  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21897  of pairs of push/pop
21898 \begin_inset LatexCommand \index{push/pop}
21899
21900 \end_inset
21901
21902  instructions in 
21903 \emph on
21904 I
21905 \emph default
21906 nterrupt
21907 \begin_inset LatexCommand \index{interrupt}
21908
21909 \end_inset
21910
21911  
21912 \emph on
21913 S
21914 \emph default
21915 ervice 
21916 \emph on
21917 R
21918 \emph default
21919 outines.
21920  The directive should be placed immediately before the ISR function definition
21921  and it affects ALL ISR functions following it.
21922  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21923 exclude\InsetSpace ~
21924 none
21925 \begin_inset LatexCommand \index{\#pragma exclude}
21926
21927 \end_inset
21928
21929 .
21930  See also the related keyword _naked
21931 \begin_inset LatexCommand \index{\_naked}
21932
21933 \end_inset
21934
21935
21936 \begin_inset LatexCommand \index{\_\_naked}
21937
21938 \end_inset
21939
21940 .
21941 \end_layout
21942
21943 \begin_layout Itemize
21944
21945 \series bold
21946 less_pedantic
21947 \series default
21948
21949 \begin_inset LatexCommand \index{pedantic}
21950
21951 \end_inset
21952
21953
21954 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21955
21956 \end_inset
21957
21958  
21959 \begin_inset LatexCommand \label{ite:less_pedantic}
21960
21961 \end_inset
21962
21963 - the compiler will not warn you anymore for obvious mistakes, you're on
21964  your own now ;-( .
21965  See also the command line option -
21966 \begin_inset ERT
21967 status collapsed
21968
21969 \begin_layout Standard
21970
21971
21972 \backslash
21973 /
21974 \end_layout
21975
21976 \end_inset
21977
21978 -less-pedantic 
21979 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21980
21981 \end_inset
21982
21983 .
21984  
21985 \newline
21986 More specifically, the following warnings will be disabled: 
21987 \shape italic
21988 comparison is always [true/false] due to limited range of data type
21989 \shape default
21990  (94); 
21991 \shape italic
21992 overflow in implicit constant conversion
21993 \shape default
21994  (158); [the (in)famous] 
21995 \shape italic
21996 conditional flow changed by optimizer: so said EVELYN the modified DOG
21997 \shape default
21998  (110); 
21999 \shape italic
22000 function '[function name]' must return value
22001 \shape default
22002  (59).
22003  
22004 \newline
22005 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22006  level) are disabled, too, namely: 
22007 \shape italic
22008 constant value '[
22009 \begin_inset Note Note
22010 status collapsed
22011
22012 \begin_layout Standard
22013 dunno what comes here - this warning appears to be unused altogether
22014 \end_layout
22015
22016 \end_inset
22017
22018 ]', out of range
22019 \shape default
22020  (81); 
22021 \shape italic
22022 [left/right] shifting more than size of object changed to zero
22023 \shape default
22024  (116); 
22025 \shape italic
22026 unreachable code
22027 \shape default
22028  (126); 
22029 \shape italic
22030 integer overflow in expression
22031 \shape default
22032  (165); 
22033 \shape italic
22034 unmatched #pragma save and #pragma restore
22035 \shape default
22036  (170); 
22037 \shape italic
22038 comparison of 'signed char' with 'unsigned char' requires promotion to int
22039 \shape default
22040  (185); 
22041 \shape italic
22042 ISO C90 does not support flexible array members
22043 \shape default
22044  (187); 
22045 \shape italic
22046 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22047 nam
22048 e]':\InsetSpace ~
22049 [
22050 \begin_inset Note Note
22051 status collapsed
22052
22053 \begin_layout Standard
22054 appears to be always blank - what was supposed to be here?
22055 \end_layout
22056
22057 \end_inset
22058
22059 ]
22060 \shape default
22061  (114); 
22062 \shape italic
22063 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22064  complexity [number]
22065 \shape default
22066  (121).
22067 \end_layout
22068
22069 \begin_layout Itemize
22070
22071 \series bold
22072 disable_warning
22073 \series default
22074  <nnnn>
22075 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22076
22077 \end_inset
22078
22079  - the compiler will not warn you anymore about warning number <nnnn>.
22080 \end_layout
22081
22082 \begin_layout Itemize
22083
22084 \series bold
22085 nogcse
22086 \series default
22087
22088 \begin_inset LatexCommand \index{\#pragma nogcse}
22089
22090 \end_inset
22091
22092  - will stop global common subexpression elimination.
22093 \end_layout
22094
22095 \begin_layout Itemize
22096
22097 \series bold
22098 noinduction
22099 \series default
22100
22101 \begin_inset LatexCommand \index{\#pragma noinduction}
22102
22103 \end_inset
22104
22105  - will stop loop induction optimizations.
22106 \end_layout
22107
22108 \begin_layout Itemize
22109
22110 \series bold
22111 noinvariant
22112 \series default
22113
22114 \begin_inset LatexCommand \index{\#pragma noinvariant}
22115
22116 \end_inset
22117
22118  - will not do loop invariant optimizations.
22119  For more details see Loop Invariants in section
22120 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22121
22122 \end_inset
22123
22124 .
22125 \end_layout
22126
22127 \begin_layout Itemize
22128
22129 \series bold
22130 noiv
22131 \series default
22132
22133 \begin_inset LatexCommand \index{\#pragma noiv}
22134
22135 \end_inset
22136
22137  - Do not generate interrupt
22138 \begin_inset LatexCommand \index{interrupt}
22139
22140 \end_inset
22141
22142  vector table
22143 \begin_inset LatexCommand \index{interrupt vector table}
22144
22145 \end_inset
22146
22147  entries for all ISR functions defined after the pragma.
22148  This is useful in cases where the interrupt vector table must be defined
22149  manually, or when there is a secondary, manually defined interrupt vector
22150  table (e.g.
22151  for the autovector feature of the Cypress EZ-USB FX2).
22152  More elegantly this can be achieved by obmitting the optional interrupt
22153  number after the interrupt keyword, see section 
22154 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22155
22156 \end_inset
22157
22158 \InsetSpace ~
22159 about interrupts.
22160 \end_layout
22161
22162 \begin_layout Itemize
22163
22164 \series bold
22165 nojtbound
22166 \series default
22167
22168 \begin_inset LatexCommand \index{\#pragma nojtbound}
22169
22170 \end_inset
22171
22172  - will not generate code for boundary value checking, when switch statements
22173  are turned into jump-tables (dangerous).
22174  For more details see section 
22175 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22176
22177 \end_inset
22178
22179 .
22180 \end_layout
22181
22182 \begin_layout Itemize
22183
22184 \series bold
22185 noloopreverse
22186 \series default
22187
22188 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22189
22190 \end_inset
22191
22192  - Will not do loop reversal optimization
22193 \end_layout
22194
22195 \begin_layout Itemize
22196
22197 \series bold
22198 nooverlay
22199 \series default
22200
22201 \begin_inset LatexCommand \index{\#pragma nooverlay}
22202
22203 \end_inset
22204
22205  - the compiler will not overlay the parameters and local variables of a
22206  function.
22207 \end_layout
22208
22209 \begin_layout Itemize
22210
22211 \series bold
22212 stackauto
22213 \series default
22214
22215 \begin_inset LatexCommand \index{\#pragma stackauto}
22216
22217 \end_inset
22218
22219 - See option -
22220 \begin_inset ERT
22221 status collapsed
22222
22223 \begin_layout Standard
22224
22225
22226 \backslash
22227 /
22228 \end_layout
22229
22230 \end_inset
22231
22232 -stack-auto
22233 \begin_inset LatexCommand \index{-\/-stack-auto}
22234
22235 \end_inset
22236
22237  and section 
22238 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22239
22240 \end_inset
22241
22242  Parameters and Local Variables.
22243 \end_layout
22244
22245 \begin_layout Itemize
22246
22247 \series bold
22248 opt_code_speed
22249 \series default
22250  
22251 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22252
22253 \end_inset
22254
22255 - The compiler will optimize code generation towards fast code, possibly
22256  at the expense of code size.
22257  Currently this has little effect.
22258 \end_layout
22259
22260 \begin_layout Itemize
22261
22262 \series bold
22263 opt_code_size
22264 \series default
22265  
22266 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22267
22268 \end_inset
22269
22270 - The compiler will optimize code generation towards compact code, possibly
22271  at the expense of code speed.
22272  Currently this has little effect.
22273 \end_layout
22274
22275 \begin_layout Itemize
22276
22277 \series bold
22278 opt_code_balanced
22279 \series default
22280  
22281 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22282
22283 \end_inset
22284
22285 - The compiler will attempt to generate code that is both compact and fast,
22286  as long as meeting one goal is not a detriment to the other (this is the
22287  default).
22288  
22289 \end_layout
22290
22291 \begin_layout Itemize
22292
22293 \series bold
22294 std_sdcc89
22295 \series default
22296  
22297 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22298
22299 \end_inset
22300
22301 - Generally follow the C89 standard, but allow SDCC features that conflict
22302  with the standard (default).
22303 \end_layout
22304
22305 \begin_layout Itemize
22306
22307 \series bold
22308 std_c89
22309 \series default
22310  
22311 \begin_inset LatexCommand \index{\#pragma std\_c89}
22312
22313 \end_inset
22314
22315 - Follow the C89 standard and disable SDCC features that conflict with the
22316  standard.
22317 \end_layout
22318
22319 \begin_layout Itemize
22320
22321 \series bold
22322 std_sdcc99
22323 \series default
22324  
22325 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22326
22327 \end_inset
22328
22329 - Generally follow the C99 standard, but allow SDCC features that conflict
22330  with the standard (incomplete support).
22331 \end_layout
22332
22333 \begin_layout Itemize
22334
22335 \series bold
22336 std_c99
22337 \series default
22338  
22339 \begin_inset LatexCommand \index{\#pragma std\_c99}
22340
22341 \end_inset
22342
22343 - Follow the C99 standard and disable SDCC features that conflict with the
22344  standard (incomplete support).
22345 \end_layout
22346
22347 \begin_layout Itemize
22348
22349 \series bold
22350 codeseg
22351 \series default
22352  <name>
22353 \begin_inset LatexCommand \index{\#pragma codeseg}
22354
22355 \end_inset
22356
22357 - Use this name (max.
22358  8 characters) for the code segment.
22359  See option -
22360 \begin_inset ERT
22361 status collapsed
22362
22363 \begin_layout Standard
22364
22365
22366 \backslash
22367 /
22368 \end_layout
22369
22370 \end_inset
22371
22372 -codeseg.
22373 \end_layout
22374
22375 \begin_layout Itemize
22376
22377 \series bold
22378 constseg
22379 \series default
22380  <name>
22381 \begin_inset LatexCommand \index{\#pragma constseg}
22382
22383 \end_inset
22384
22385 - Use this name (max.
22386  8 characters) for the const segment.
22387  See option -
22388 \begin_inset ERT
22389 status collapsed
22390
22391 \begin_layout Standard
22392
22393
22394 \backslash
22395 /
22396 \end_layout
22397
22398 \end_inset
22399
22400 -constseg.
22401 \end_layout
22402
22403 \begin_layout Standard
22404 The preprocessor SDCPP
22405 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22406
22407 \end_inset
22408
22409  supports the following #pragma directives:
22410 \end_layout
22411
22412 \begin_layout Itemize
22413
22414 \series bold
22415 pedantic_parse_number
22416 \series default
22417
22418 \begin_inset LatexCommand \index{pedantic}
22419
22420 \end_inset
22421
22422
22423 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22424
22425 \end_inset
22426
22427  (+ | -) 
22428 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22429
22430 \end_inset
22431
22432 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22433  properly and the macro LO_B(3) gets expanded.
22434  Default is off.
22435  See also the -
22436 \begin_inset ERT
22437 status collapsed
22438
22439 \begin_layout Standard
22440
22441
22442 \backslash
22443 /
22444 \end_layout
22445
22446 \end_inset
22447
22448 -pedantic-parse-number command line option 
22449 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22450
22451 \end_inset
22452
22453 .
22454  
22455 \newline
22456 Below is an example on how to use this pragma.
22457
22458 \emph on
22459  Note: this functionality is not in conformance with standard!
22460 \end_layout
22461
22462 \begin_layout Verse
22463
22464 \family typewriter
22465 #pragma pedantic_parse_number +
22466 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22467
22468 \end_inset
22469
22470
22471 \newline
22472
22473 \newline
22474 #define LO_B(x) ((x) & 0xff)
22475 \newline
22476
22477 \newline
22478 unsigned char foo(void)
22479 \newline
22480 {
22481 \newline
22482 \InsetSpace ~
22483 \InsetSpace ~
22484 \InsetSpace ~
22485 unsigned char c=0xfe-LO_B(3)
22486 ;
22487 \newline
22488
22489 \newline
22490 \InsetSpace ~
22491 \InsetSpace ~
22492 \InsetSpace ~
22493 return c;
22494 \newline
22495 }
22496 \newline
22497
22498 \end_layout
22499
22500 \begin_layout Itemize
22501
22502 \series bold
22503 preproc_asm
22504 \series default
22505
22506 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22507
22508 \end_inset
22509
22510  (+ | -) - switch _asm _endasm block preprocessing on / off.
22511  Default is on.
22512  You use this prama to define multilines of assembly code.
22513  This will prevent the preprocessor from changing the formating required
22514  by assembly code.
22515  Below is an example on how to use this pragma.
22516 \end_layout
22517
22518 \begin_layout Verse
22519
22520 \family typewriter
22521 #pragma preproc_asm -
22522 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22523
22524 \end_inset
22525
22526
22527 \newline
22528 #define MYDELAY _asm
22529 \newline
22530 \InsetSpace ~
22531 \InsetSpace ~
22532 \InsetSpace ~
22533 nop ;my assembly comment...
22534 \newline
22535 \InsetSpace ~
22536 \InsetSpace ~
22537 \InsetSpace ~
22538 nop
22539 \newline
22540 \InsetSpace ~
22541 \InsetSpace ~
22542 \InsetSpace ~
22543 nop
22544 \newline
22545 _endasm
22546 \newline
22547 #pragma preproc_asm
22548  +
22549 \newline
22550
22551 \newline
22552 void foo (void) 
22553 \newline
22554
22555 \newline
22556 \InsetSpace ~
22557 \InsetSpace ~
22558 \InsetSpace ~
22559  ...
22560  
22561 \newline
22562 \InsetSpace ~
22563 \InsetSpace ~
22564 \InsetSpace ~
22565  MYDELAY;
22566 \newline
22567 \InsetSpace ~
22568 \InsetSpace ~
22569 \InsetSpace ~
22570  ...
22571  
22572 \newline
22573
22574 \newline
22575
22576 \end_layout
22577
22578 \begin_layout Itemize
22579
22580 \series bold
22581 sdcc_hash
22582 \series default
22583
22584 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22585
22586 \end_inset
22587
22588  (+ | -) - Allow "naked" hash in macro definition, for example:
22589 \newline
22590
22591 \family typewriter
22592 #define DIR_LO(x) #(x & 0xff)
22593 \family default
22594
22595 \newline
22596 Default is off.
22597  Below is an example on how to use this pragma.
22598 \end_layout
22599
22600 \begin_layout Verse
22601
22602 \family typewriter
22603 #pragma preproc_asm +
22604 \newline
22605 #pragma sdcc_hash +
22606 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22607
22608 \end_inset
22609
22610
22611 \newline
22612
22613 \newline
22614 #define ROMCALL(x) 
22615 \backslash
22616
22617 \newline
22618 \InsetSpace ~
22619 \InsetSpace ~
22620 \InsetSpace ~
22621 mov R6_B3, #(x & 0xff) 
22622 \backslash
22623
22624 \newline
22625 \InsetSpace ~
22626 \InsetSpace ~
22627 \InsetSpace ~
22628 mov R7_B3, #((x >> 8) & 0xff) 
22629 \backslash
22630
22631 \newline
22632 \InsetSpace ~
22633 \InsetSpace ~
22634 \InsetSpace ~
22635 lcall __romcall
22636 \newline
22637
22638 \newline
22639 ...
22640 \newline
22641 _asm
22642 \newline
22643 ROMCALL(72)
22644 \newline
22645 _endasm;
22646 \newline
22647 ...
22648 \newline
22649
22650 \end_layout
22651
22652 \begin_layout Standard
22653 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22654 ons which might cause the compiler to generate extra stack and/or data space
22655  to store compiler generated temporary variables.
22656  This usually happens in large functions.
22657  Pragma directives should be used as shown in the following example, they
22658  are used to control options and optimizations for a given function.
22659  
22660 \end_layout
22661
22662 \begin_layout Verse
22663
22664 \family typewriter
22665 #pragma save
22666 \begin_inset LatexCommand \index{\#pragma save}
22667
22668 \end_inset
22669
22670  \InsetSpace ~
22671 \InsetSpace ~
22672 \InsetSpace ~
22673 \InsetSpace ~
22674 \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 /* save the current settings */ 
22678 \newline
22679 #pragma nogcse
22680 \begin_inset LatexCommand \index{\#pragma nogcse}
22681
22682 \end_inset
22683
22684  \InsetSpace ~
22685 \InsetSpace ~
22686 \InsetSpace ~
22687 \InsetSpace ~
22688 \InsetSpace ~
22689 /* turnoff global subexpression elimination */ 
22690 \newline
22691 #pragma noinduction
22692 \begin_inset LatexCommand \index{\#pragma noinduction}
22693
22694 \end_inset
22695
22696  /* turn off induction optimizations */ 
22697 \newline
22698 int foo () 
22699 \newline
22700
22701 \newline
22702 \InsetSpace ~
22703  \InsetSpace ~
22704  ...
22705  
22706 \newline
22707 \InsetSpace ~
22708  \InsetSpace ~
22709  /* large code */ 
22710 \newline
22711 \InsetSpace ~
22712  \InsetSpace ~
22713  ...
22714  
22715 \newline
22716
22717 \newline
22718 #pragma restore
22719 \begin_inset LatexCommand \index{\#pragma restore}
22720
22721 \end_inset
22722
22723  /* turn the optimizations back on */
22724 \end_layout
22725
22726 \begin_layout Standard
22727 The compiler will generate a warning message when extra space is allocated.
22728  It is strongly recommended that the save and restore pragmas be used when
22729  changing options for a function.
22730 \newline
22731
22732 \newline
22733
22734 \newline
22735
22736 \end_layout
22737
22738 \begin_layout Section
22739 Defines Created by the Compiler
22740 \end_layout
22741
22742 \begin_layout Standard
22743 The compiler creates the following #defines
22744 \begin_inset LatexCommand \index{\#defines}
22745
22746 \end_inset
22747
22748
22749 \begin_inset LatexCommand \index{Defines created by the compiler}
22750
22751 \end_inset
22752
22753 :
22754 \newline
22755
22756 \end_layout
22757
22758 \begin_layout Standard
22759 \begin_inset Tabular
22760 <lyxtabular version="3" rows="15" columns="2">
22761 <features>
22762 <column alignment="left" valignment="top" leftline="true" width="3in">
22763 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22764 <row topline="true" bottomline="true">
22765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22766 \begin_inset Text
22767
22768 \begin_layout Standard
22769
22770 \series bold
22771 #define
22772 \end_layout
22773
22774 \end_inset
22775 </cell>
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_inset Text
22778
22779 \begin_layout Standard
22780
22781 \series bold
22782 Description
22783 \end_layout
22784
22785 \end_inset
22786 </cell>
22787 </row>
22788 <row topline="true">
22789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22790 \begin_inset Text
22791
22792 \begin_layout Standard
22793 SDCC
22794 \begin_inset LatexCommand \index{SDCC}
22795
22796 \end_inset
22797
22798  
22799 \end_layout
22800
22801 \end_inset
22802 </cell>
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22804 \begin_inset Text
22805
22806 \begin_layout Standard
22807 Always defined.
22808  Since version 2.5.6 the version number as an int (ex.
22809  256)
22810 \end_layout
22811
22812 \end_inset
22813 </cell>
22814 </row>
22815 <row topline="true">
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22817 \begin_inset Text
22818
22819 \begin_layout Standard
22820 SDCC_mcs51
22821 \begin_inset LatexCommand \index{SDCC\_mcs51}
22822
22823 \end_inset
22824
22825  or SDCC_ds390
22826 \begin_inset LatexCommand \index{SDCC\_ds390}
22827
22828 \end_inset
22829
22830  or SDCC_z80
22831 \begin_inset LatexCommand \index{SDCC\_z80}
22832
22833 \end_inset
22834
22835 , etc.
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 depending on the model used (e.g.: -mds390)
22845 \end_layout
22846
22847 \end_inset
22848 </cell>
22849 </row>
22850 <row topline="true">
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22852 \begin_inset Text
22853
22854 \begin_layout Standard
22855 __mcs51
22856 \begin_inset LatexCommand \index{\_\_mcs51}
22857
22858 \end_inset
22859
22860 , __ds390
22861 \begin_inset LatexCommand \index{\_\_ds390}
22862
22863 \end_inset
22864
22865 , __hc08
22866 \begin_inset LatexCommand \index{\_\_hc08}
22867
22868 \end_inset
22869
22870 , __z80
22871 \begin_inset LatexCommand \index{\_\_z80}
22872
22873 \end_inset
22874
22875 , etc
22876 \end_layout
22877
22878 \end_inset
22879 </cell>
22880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22881 \begin_inset Text
22882
22883 \begin_layout Standard
22884 depending on the model used (e.g.
22885  -mz80)
22886 \end_layout
22887
22888 \end_inset
22889 </cell>
22890 </row>
22891 <row topline="true">
22892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22893 \begin_inset Text
22894
22895 \begin_layout Standard
22896 SDCC_STACK_AUTO
22897 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22898
22899 \end_inset
22900
22901
22902 \end_layout
22903
22904 \end_inset
22905 </cell>
22906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22907 \begin_inset Text
22908
22909 \begin_layout Standard
22910 when 
22911 \emph on
22912 -
22913 \begin_inset ERT
22914 status collapsed
22915
22916 \begin_layout Standard
22917
22918
22919 \backslash
22920 /
22921 \end_layout
22922
22923 \end_inset
22924
22925 -stack-auto
22926 \emph default
22927  option is used
22928 \end_layout
22929
22930 \end_inset
22931 </cell>
22932 </row>
22933 <row topline="true">
22934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22935 \begin_inset Text
22936
22937 \begin_layout Standard
22938 SDCC_MODEL_SMALL
22939 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22940
22941 \end_inset
22942
22943
22944 \end_layout
22945
22946 \end_inset
22947 </cell>
22948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22949 \begin_inset Text
22950
22951 \begin_layout Standard
22952 when 
22953 \emph on
22954 -
22955 \begin_inset ERT
22956 status collapsed
22957
22958 \begin_layout Standard
22959
22960
22961 \backslash
22962 /
22963 \end_layout
22964
22965 \end_inset
22966
22967 -model-small
22968 \emph default
22969  is used
22970 \end_layout
22971
22972 \end_inset
22973 </cell>
22974 </row>
22975 <row topline="true">
22976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22977 \begin_inset Text
22978
22979 \begin_layout Standard
22980 SDCC_MODEL_MEDIUM
22981 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22982
22983 \end_inset
22984
22985
22986 \end_layout
22987
22988 \end_inset
22989 </cell>
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \begin_layout Standard
22994 when 
22995 \emph on
22996 -
22997 \begin_inset ERT
22998 status collapsed
22999
23000 \begin_layout Standard
23001
23002
23003 \backslash
23004 /
23005 \end_layout
23006
23007 \end_inset
23008
23009 -model-medium
23010 \emph default
23011  is used
23012 \end_layout
23013
23014 \end_inset
23015 </cell>
23016 </row>
23017 <row topline="true">
23018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23019 \begin_inset Text
23020
23021 \begin_layout Standard
23022 SDCC_MODEL_LARGE
23023 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23024
23025 \end_inset
23026
23027
23028 \end_layout
23029
23030 \end_inset
23031 </cell>
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23033 \begin_inset Text
23034
23035 \begin_layout Standard
23036 when 
23037 \emph on
23038 -
23039 \begin_inset ERT
23040 status collapsed
23041
23042 \begin_layout Standard
23043
23044
23045 \backslash
23046 /
23047 \end_layout
23048
23049 \end_inset
23050
23051 -model-large
23052 \emph default
23053  is used
23054 \end_layout
23055
23056 \end_inset
23057 </cell>
23058 </row>
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23061 \begin_inset Text
23062
23063 \begin_layout Standard
23064 SDCC_USE_XSTACK
23065 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23066
23067 \end_inset
23068
23069
23070 \end_layout
23071
23072 \end_inset
23073 </cell>
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_inset Text
23076
23077 \begin_layout Standard
23078 when 
23079 \emph on
23080 -
23081 \begin_inset ERT
23082 status collapsed
23083
23084 \begin_layout Standard
23085
23086
23087 \backslash
23088 /
23089 \end_layout
23090
23091 \end_inset
23092
23093 -xstack
23094 \emph default
23095  option is used
23096 \end_layout
23097
23098 \end_inset
23099 </cell>
23100 </row>
23101 <row topline="true">
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23103 \begin_inset Text
23104
23105 \begin_layout Standard
23106 SDCC_STACK_TENBIT
23107 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23108
23109 \end_inset
23110
23111  
23112 \end_layout
23113
23114 \end_inset
23115 </cell>
23116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23117 \begin_inset Text
23118
23119 \begin_layout Standard
23120 when 
23121 \emph on
23122 -mds390
23123 \emph default
23124  is used
23125 \end_layout
23126
23127 \end_inset
23128 </cell>
23129 </row>
23130 <row topline="true">
23131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23132 \begin_inset Text
23133
23134 \begin_layout Standard
23135 SDCC_MODEL_FLAT24
23136 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23137
23138 \end_inset
23139
23140
23141 \end_layout
23142
23143 \end_inset
23144 </cell>
23145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23146 \begin_inset Text
23147
23148 \begin_layout Standard
23149 when 
23150 \emph on
23151 -mds390
23152 \emph default
23153  is used
23154 \end_layout
23155
23156 \end_inset
23157 </cell>
23158 </row>
23159 <row topline="true">
23160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23161 \begin_inset Text
23162
23163 \begin_layout Standard
23164 SDCC_REVISION
23165 \begin_inset LatexCommand \index{SDCC\_REVISION}
23166
23167 \end_inset
23168
23169
23170 \end_layout
23171
23172 \end_inset
23173 </cell>
23174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23175 \begin_inset Text
23176
23177 \begin_layout Standard
23178 Always defined.
23179  SDCC svn revision number
23180 \end_layout
23181
23182 \end_inset
23183 </cell>
23184 </row>
23185 <row topline="true">
23186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23187 \begin_inset Text
23188
23189 \begin_layout Standard
23190 SDCC_PARMS_IN_BANK1
23191 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23192
23193 \end_inset
23194
23195
23196 \end_layout
23197
23198 \end_inset
23199 </cell>
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23201 \begin_inset Text
23202
23203 \begin_layout Standard
23204 when 
23205 \emph on
23206 -
23207 \begin_inset ERT
23208 status collapsed
23209
23210 \begin_layout Standard
23211
23212
23213 \backslash
23214 /
23215 \end_layout
23216
23217 \end_inset
23218
23219 -parms-in-bank1
23220 \emph default
23221  is used
23222 \end_layout
23223
23224 \end_inset
23225 </cell>
23226 </row>
23227 <row topline="true">
23228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23229 \begin_inset Text
23230
23231 \begin_layout Standard
23232 SDCC_FLOAT_REENT
23233 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23234
23235 \end_inset
23236
23237
23238 \end_layout
23239
23240 \end_inset
23241 </cell>
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23243 \begin_inset Text
23244
23245 \begin_layout Standard
23246 when 
23247 \emph on
23248 -
23249 \begin_inset ERT
23250 status collapsed
23251
23252 \begin_layout Standard
23253
23254
23255 \backslash
23256 /
23257 \end_layout
23258
23259 \end_inset
23260
23261 -float-reent
23262 \emph default
23263  is used
23264 \end_layout
23265
23266 \end_inset
23267 </cell>
23268 </row>
23269 <row topline="true" bottomline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23271 \begin_inset Text
23272
23273 \begin_layout Standard
23274 SDCC_INT_LONG_REENT
23275 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23276
23277 \end_inset
23278
23279
23280 \end_layout
23281
23282 \end_inset
23283 </cell>
23284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23285 \begin_inset Text
23286
23287 \begin_layout Standard
23288 when 
23289 \emph on
23290 -
23291 \begin_inset ERT
23292 status collapsed
23293
23294 \begin_layout Standard
23295
23296
23297 \backslash
23298 /
23299 \end_layout
23300
23301 \end_inset
23302
23303 -int-long-reent
23304 \emph default
23305  is used
23306 \end_layout
23307
23308 \end_inset
23309 </cell>
23310 </row>
23311 </lyxtabular>
23312
23313 \end_inset
23314
23315
23316 \end_layout
23317
23318 \begin_layout Chapter
23319 Notes on supported Processors
23320 \end_layout
23321
23322 \begin_layout Section
23323 MCS51 variants
23324 \begin_inset LatexCommand \label{sub:MCS51-variants}
23325
23326 \end_inset
23327
23328
23329 \begin_inset LatexCommand \index{MCS51 variants}
23330
23331 \end_inset
23332
23333
23334 \end_layout
23335
23336 \begin_layout Standard
23337 MCS51 processors are available from many vendors and come in many different
23338  flavours.
23339  While they might differ considerably in respect to Special Function Registers
23340  the core MCS51 is usually not modified or is kept compatible.
23341  
23342 \end_layout
23343
23344 \begin_layout Subsection
23345 pdata access by SFR 
23346 \end_layout
23347
23348 \begin_layout Standard
23349 With the upcome of devices with internal xdata and flash memory devices
23350  using port P2
23351 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23352
23353 \end_inset
23354
23355  as dedicated I/O port is becoming more popular.
23356  Switching the high byte for pdata
23357 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23358
23359 \end_inset
23360
23361  access which was formerly done by port P2 is then achieved by a Special
23362  Function Register
23363 \begin_inset LatexCommand \index{sfr}
23364
23365 \end_inset
23366
23367 .
23368  In well-established MCS51 tradition the address of this 
23369 \emph on
23370 sfr
23371 \emph default
23372  is where the chip designers decided to put it.
23373  Needless to say that they didn't agree on a common name either.
23374  So that the startup code can correctly initialize xdata variables, you
23375  should define an sfr with the name _XPAGE
23376 \family typewriter
23377
23378 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23379
23380 \end_inset
23381
23382
23383 \family default
23384  at the appropriate location if the default, port P2, is not used for this.
23385  Some examples are:
23386 \end_layout
23387
23388 \begin_layout Verse
23389
23390 \family typewriter
23391 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23392  MPAGE */
23393 \end_layout
23394
23395 \begin_layout Verse
23396
23397 \family typewriter
23398 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23399  a.k.a.
23400  MPAGE */
23401 \end_layout
23402
23403 \begin_layout Verse
23404
23405 \family typewriter
23406 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23407  XPAGE */
23408 \end_layout
23409
23410 \begin_layout Verse
23411
23412 \family typewriter
23413 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23414  EMI0CN */
23415 \end_layout
23416
23417 \begin_layout Verse
23418
23419 \family typewriter
23420 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23421  EMI0CN */
23422 \end_layout
23423
23424 \begin_layout Standard
23425 For more exotic implementations further customizations may be needed.
23426  See section 
23427 \begin_inset LatexCommand \ref{sub:Startup-Code}
23428
23429 \end_inset
23430
23431  for other possibilities.
23432 \end_layout
23433
23434 \begin_layout Subsection
23435 Other Features available by SFR
23436 \end_layout
23437
23438 \begin_layout Standard
23439 Some MCS51 variants offer features like Double DPTR
23440 \begin_inset LatexCommand \index{DPTR}
23441
23442 \end_inset
23443
23444 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23445  These are currently not used for the MCS51 port.
23446  If you absolutely need them you can fall back to inline assembly or submit
23447  a patch to SDCC.
23448 \end_layout
23449
23450 \begin_layout Subsection
23451 Bankswitching
23452 \end_layout
23453
23454 \begin_layout Standard
23455 Bankswitching
23456 \begin_inset LatexCommand \index{Bankswitching}
23457
23458 \end_inset
23459
23460  (a.k.a.
23461  code banking
23462 \begin_inset LatexCommand \index{code banking}
23463
23464 \end_inset
23465
23466 ) is a technique to increase the code space above the 64k limit of the 8051.
23467 \end_layout
23468
23469 \begin_layout Subsubsection
23470 Hardware
23471 \end_layout
23472
23473 \begin_layout Standard
23474 \begin_inset Tabular
23475 <lyxtabular version="3" rows="3" columns="4">
23476 <features>
23477 <column alignment="center" valignment="top" width="0">
23478 <column alignment="center" valignment="top" leftline="true" width="0">
23479 <column alignment="center" valignment="top" leftline="true" width="0">
23480 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23481 <row topline="true" bottomline="true">
23482 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23483 \begin_inset Text
23484
23485 \begin_layout Standard
23486 8000-FFFF
23487 \end_layout
23488
23489 \end_inset
23490 </cell>
23491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23492 \begin_inset Text
23493
23494 \begin_layout Standard
23495 bank1
23496 \end_layout
23497
23498 \end_inset
23499 </cell>
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23501 \begin_inset Text
23502
23503 \begin_layout Standard
23504 bank2
23505 \end_layout
23506
23507 \end_inset
23508 </cell>
23509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23510 \begin_inset Text
23511
23512 \begin_layout Standard
23513 bank3
23514 \end_layout
23515
23516 \end_inset
23517 </cell>
23518 </row>
23519 <row topline="true" bottomline="true">
23520 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23521 \begin_inset Text
23522
23523 \begin_layout Standard
23524 0000-7FFF
23525 \end_layout
23526
23527 \end_inset
23528 </cell>
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23530 \begin_inset Text
23531
23532 \begin_layout Standard
23533 common
23534 \end_layout
23535
23536 \end_inset
23537 </cell>
23538 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23539 \begin_inset Text
23540
23541 \begin_layout Standard
23542
23543 \end_layout
23544
23545 \end_inset
23546 </cell>
23547 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23548 \begin_inset Text
23549
23550 \begin_layout Standard
23551
23552 \end_layout
23553
23554 \end_inset
23555 </cell>
23556 </row>
23557 <row>
23558 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23559 \begin_inset Text
23560
23561 \begin_layout Standard
23562 SiLabs C8051F120 example
23563 \end_layout
23564
23565 \end_inset
23566 </cell>
23567 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23568 \begin_inset Text
23569
23570 \begin_layout Standard
23571
23572 \end_layout
23573
23574 \end_inset
23575 </cell>
23576 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23577 \begin_inset Text
23578
23579 \begin_layout Standard
23580
23581 \end_layout
23582
23583 \end_inset
23584 </cell>
23585 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23586 \begin_inset Text
23587
23588 \begin_layout Standard
23589
23590 \end_layout
23591
23592 \end_inset
23593 </cell>
23594 </row>
23595 </lyxtabular>
23596
23597 \end_inset
23598
23599
23600 \newline
23601
23602 \newline
23603 Usually the hardware uses some sfr (an output port or an internal sfr) to
23604  select a bank and put it in the banked area of the memory map.
23605  The selected bank usually becomes active immediately upon assignment to
23606  this sfr and when running inside a bank it will switch out this code it
23607  is currently running.
23608  Therefor you cannot jump or call directly from one bank to another and
23609  need to use a so-called trampoline in the common area.
23610  For SDCC an example trampoline is in crtbank.asm and you may need to change
23611  it to your 8051 derivative or schematic.
23612  The presented code is written for the C8051F120.
23613 \newline
23614
23615 \newline
23616 When calling a banked function
23617  SDCC will put the LSB of the functions address in register R0, the MSB
23618  in R1 and the bank in R2 and then call this trampoline 
23619 \emph on
23620 __sdcc_banked_call
23621 \emph default
23622 .
23623  The current selected bank is saved on the stack, the new bank is selected
23624  and an indirect jump is made.
23625  When the banked function returns it jumps to 
23626 \emph on
23627 __sdcc_banked_ret
23628 \emph default
23629  which restores the previous bank and returns to the caller.
23630 \end_layout
23631
23632 \begin_layout Subsubsection
23633 Software
23634 \end_layout
23635
23636 \begin_layout Standard
23637 When writing banked software using SDCC you need to use some special keywords
23638  and options.
23639  You also need to take over a bit of work from the linker.
23640 \newline
23641
23642 \newline
23643 To create a function
23644  that can be called from another bank it requires the keyword 
23645 \emph on
23646 banked
23647 \emph default
23648
23649 \begin_inset LatexCommand \index{banked}
23650
23651 \end_inset
23652
23653 .
23654  The caller must see this in the prototype of the callee and the callee
23655  needs it for a proper return.
23656  Called functions within the same bank as the caller do not need the 
23657 \emph on
23658 banked
23659 \emph default
23660  keyword nor do functions in the common area.
23661  Beware: SDCC does not know or check if functions are in the same bank.
23662  This is your responsibility!
23663 \newline
23664
23665 \newline
23666 Normally all functions you write end up in
23667  the segment CSEG.
23668  If you want a function explicitly to reside in the common area put it in
23669  segment HOME.
23670  This applies for instance to interrupt service routines as they should
23671  not be banked.
23672 \end_layout
23673
23674 \begin_layout Standard
23675 Functions that need to be in a switched bank must be put in a named segment.
23676  The name can be mostly anything upto eight characters (e.g.
23677  BANK1).
23678  To do this you either use -
23679 \begin_inset ERT
23680 status collapsed
23681
23682 \begin_layout Standard
23683
23684
23685 \backslash
23686 /
23687 \end_layout
23688
23689 \end_inset
23690
23691 -codeseg BANK1 (See 
23692 \begin_inset LatexCommand \ref{lyx:-codeseg}
23693
23694 \end_inset
23695
23696 ) on the command line when compiling or #pragma codeseg BANK1 (See 
23697 \begin_inset LatexCommand \ref{sec:Pragmas}
23698
23699 \end_inset
23700
23701 ) at the top of the C source file.
23702  The segment name always applies to the whole source file and generated
23703  object so functions for different banks need to be defined in different
23704  source files.
23705 \newline
23706
23707 \newline
23708 When linking your objects you need to tell the linker where
23709  to put your segments.
23710  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23711 00 (See 
23712 \begin_inset LatexCommand \ref{lyx:-Wl option}
23713
23714 \end_inset
23715
23716 ).
23717  This sets the virtual start address of this segment.
23718  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23719  The linker will not check for overflows, again this is your responsibility.
23720 \end_layout
23721
23722 \begin_layout Standard
23723 \begin_inset VSpace bigskip
23724 \end_inset
23725
23726
23727 \end_layout
23728
23729 \begin_layout Section
23730 DS400 port
23731 \end_layout
23732
23733 \begin_layout Standard
23734 The DS80C400
23735 \begin_inset LatexCommand \index{DS80C400}
23736
23737 \end_inset
23738
23739
23740 \begin_inset LatexCommand \index{DS400}
23741
23742 \end_inset
23743
23744  microcontroller has a rich set of peripherals.
23745  In its built-in ROM library it includes functions to access some of the
23746  features, among them is a TCP stack with IP4 and IP6 support.
23747  Library headers (currently in beta status) and other files are provided
23748  at 
23749 \size footnotesize
23750
23751 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23752
23753 \end_inset
23754
23755 .
23756  
23757 \begin_inset VSpace bigskip
23758 \end_inset
23759
23760
23761 \end_layout
23762
23763 \begin_layout Section
23764 The Z80 and gbz80 port
23765 \end_layout
23766
23767 \begin_layout Standard
23768 SDCC can target both the Zilog Z80
23769 \begin_inset LatexCommand \index{Z80}
23770
23771 \end_inset
23772
23773  and the Nintendo Gameboy's Z80-like gbz80
23774 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23775
23776 \end_inset
23777
23778 .
23779  The Z80 port is passed through the same 
23780 \emph on
23781 regressions tests
23782 \begin_inset LatexCommand \index{Regression test}
23783
23784 \end_inset
23785
23786
23787 \emph default
23788  (see section 
23789 \begin_inset LatexCommand \ref{sec:Quality-control}
23790
23791 \end_inset
23792
23793 ) as the MCS51 and DS390 ports, so floating point support, support for long
23794  variables and bitfield support is fine.
23795  See mailing lists and forums about interrupt routines.
23796 \end_layout
23797
23798 \begin_layout Standard
23799 As always, the code is the authoritative reference - see z80/ralloc.c and
23800  z80/gen.c.
23801  The stack
23802 \begin_inset LatexCommand \index{Z80!stack}
23803
23804 \end_inset
23805
23806  frame is similar to that generated by the IAR Z80 compiler.
23807  IX is used as the base pointer, HL and IY are used as a temporary registers,
23808  and BC and DE are available for holding variables.
23809  Return values
23810 \begin_inset LatexCommand \index{Z80!return value}
23811
23812 \end_inset
23813
23814  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23815  bytes).
23816  The gbz80 port use the same set of registers for the return values, but
23817  in a different order of significance: E (one byte), DE (two bytes), or
23818  HLDE (four bytes).
23819 \begin_inset VSpace bigskip
23820 \end_inset
23821
23822
23823 \end_layout
23824
23825 \begin_layout Section
23826 The HC08 port
23827 \end_layout
23828
23829 \begin_layout Standard
23830 The port to the Freescale/Motorola HC08
23831 \begin_inset LatexCommand \index{HC08}
23832
23833 \end_inset
23834
23835  family has been added in October 2003, and is still undergoing some basic
23836  development.
23837  The code generator is complete, but the register allocation is still quite
23838  unoptimized.
23839  Some of the SDCC's standard C library functions have embedded non-HC08
23840  inline assembly and so are not yet usable.
23841 \end_layout
23842
23843 \begin_layout Standard
23844 The HC08 port passes the regression test suite (see section 
23845 \begin_inset LatexCommand \ref{sec:Quality-control}
23846
23847 \end_inset
23848
23849 ).
23850 \begin_inset VSpace bigskip
23851 \end_inset
23852
23853
23854 \end_layout
23855
23856 \begin_layout Section
23857 The PIC14
23858 \begin_inset LatexCommand \index{PIC14}
23859
23860 \end_inset
23861
23862  port
23863 \end_layout
23864
23865 \begin_layout Standard
23866 The PIC14 port adds support for Microchip
23867 \begin_inset LatexCommand \index{Microchip}
23868
23869 \end_inset
23870
23871
23872 \begin_inset Formula $^{\text{TM}}$
23873 \end_inset
23874
23875  PIC
23876 \begin_inset LatexCommand \index{PIC14}
23877
23878 \end_inset
23879
23880
23881 \begin_inset Formula $^{\text{TM}}$
23882 \end_inset
23883
23884  MCUs with 14 bit wide instructions.
23885  This port is not yet mature and still lacks many features.
23886  However, it can work for simple code.
23887 \end_layout
23888
23889 \begin_layout Standard
23890 Currently supported devices include:
23891 \end_layout
23892
23893 \begin_layout Standard
23894 12F: 629, 635, 675, 683
23895 \end_layout
23896
23897 \begin_layout Standard
23898 16C: 432, 433
23899 \end_layout
23900
23901 \begin_layout Standard
23902 16C: 554, 557, 558
23903 \end_layout
23904
23905 \begin_layout Standard
23906 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23907 \end_layout
23908
23909 \begin_layout Standard
23910 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23911  781, 782
23912 \end_layout
23913
23914 \begin_layout Standard
23915 16C: 925, 926
23916 \end_layout
23917
23918 \begin_layout Standard
23919 16CR: 620a, 73, 74, 76, 77
23920 \end_layout
23921
23922 \begin_layout Standard
23923 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23924  687, 688, 689, 690
23925 \end_layout
23926
23927 \begin_layout Standard
23928 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23929 \end_layout
23930
23931 \begin_layout Standard
23932 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23933  877, 877a, 88, 886, 887
23934 \end_layout
23935
23936 \begin_layout Standard
23937 16F: 913, 914, 916, 917, 946
23938 \end_layout
23939
23940 \begin_layout Standard
23941 26HV: 626, 785
23942 \end_layout
23943
23944 \begin_layout Standard
23945 An up-to-date list of currently supported devices can be obtained via 
23946 \family typewriter
23947 sdcc -mpic14 -phelp foo.c
23948 \family default
23949  (foo.c must exist...).
23950 \end_layout
23951
23952 \begin_layout Subsection
23953 PIC Code Pages
23954 \begin_inset LatexCommand \index{code page (pic14)}
23955
23956 \end_inset
23957
23958  and Memory Banks
23959 \begin_inset LatexCommand \index{Memory bank (pic14)}
23960
23961 \end_inset
23962
23963
23964 \end_layout
23965
23966 \begin_layout Standard
23967 The linker organizes allocation for the code page and RAM banks.
23968  It does not have intimate knowledge of the code flow.
23969  It will put all the code section of a single .asm file into a single code
23970  page.
23971  In order to make use of multiple code pages, separate asm files must be
23972  used.
23973  The compiler assigns all 
23974 \emph on
23975 static
23976 \emph default
23977  functions of a single .c file into the same code page.
23978 \newline
23979
23980 \newline
23981 To get the best results,
23982  follow these guidelines:
23983 \end_layout
23984
23985 \begin_layout Enumerate
23986 Make local functions static, as non static functions require code page selection
23987  overhead.
23988 \newline
23989 Due to the way sdcc handles functions, place called functions prior
23990  to calling functions in the file wherever possible: Otherwise sdcc will
23991  insert unneccessary pagesel directives around the call, believing that
23992  the called function is externally defined.
23993 \end_layout
23994
23995 \begin_layout Enumerate
23996 For devices that have multiple code pages it is more efficient to use the
23997  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23998  but only 2 files for the 16F874.
23999  This way the linker can put the code for each file into different code
24000  pages and there will be less page selection overhead.
24001 \end_layout
24002
24003 \begin_layout Enumerate
24004 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24005  instruction set), use `unsigned char' wherever possible instead of `int'.
24006 \end_layout
24007
24008 \begin_layout Subsection
24009 Adding New Devices to the Port 
24010 \end_layout
24011
24012 \begin_layout Standard
24013 Adding support for a new 14
24014 \begin_inset ERT
24015 status open
24016
24017 \begin_layout Standard
24018
24019
24020 \backslash
24021 ,
24022 \end_layout
24023
24024 \end_inset
24025
24026 bit PIC MCU requires the following steps:
24027 \end_layout
24028
24029 \begin_layout Enumerate
24030 Create a new device description.
24031 \newline
24032 Each device is described in two files: pic16f*.h
24033  and pic16f*.c.
24034  These files primarily define SFRs, structs to access their bits, and symbolic
24035  configuration options.
24036  Both files can be generated from gputils' .inc files using the perl script
24037  
24038 \family typewriter
24039 support/scripts/inc2h.pl
24040 \family default
24041 .
24042  This file also contains further instructions on how to proceed.
24043 \end_layout
24044
24045 \begin_layout Enumerate
24046 Copy the .h file into SDCC's include path and either add the .c file to your
24047  project or copy it to 
24048 \family typewriter
24049 device/lib/pic/libdev
24050 \family default
24051 .
24052  Afterwards, rebuild and install the libraries.
24053 \end_layout
24054
24055 \begin_layout Enumerate
24056 Edit pic14devices.txt in SDCC's include path (
24057 \family typewriter
24058 device/include/pic/
24059 \family default
24060  in the source tree or 
24061 \family typewriter
24062 /usr/local/share/sdcc/include/pic
24063 \family default
24064  after installation).
24065 \newline
24066 You need to add a device specification here to make
24067  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24068  the compiler.
24069  Probably you can copy and modify an existing entry.
24070  The file format is documented at the top of the file.
24071 \end_layout
24072
24073 \begin_layout Subsection
24074 Interrupt Code
24075 \end_layout
24076
24077 \begin_layout Standard
24078 For the interrupt function, use the keyword `__interrupt'
24079 \begin_inset LatexCommand \index{PIC14!interrupt}
24080
24081 \end_inset
24082
24083  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24084  there to avoid a syntax error - it ought to be fixed).
24085  E.g.:
24086 \end_layout
24087
24088 \begin_layout Verse
24089
24090 \family typewriter
24091 void Intr(void) __interrupt 0
24092 \newline
24093 {
24094 \newline
24095 \InsetSpace ~
24096 \InsetSpace ~
24097 T0IF = 0; /* Clear timer interrupt */
24098 \newline
24099 }
24100 \end_layout
24101
24102 \begin_layout Subsection
24103 Linking and Assembling
24104 \end_layout
24105
24106 \begin_layout Standard
24107 For assembling you can use either GPUTILS'
24108 \begin_inset LatexCommand \index{gputils (pic tools)}
24109
24110 \end_inset
24111
24112  gpasm.exe or MPLAB's mpasmwin.exe.
24113  GPUTILS are available from 
24114 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24115
24116 \end_inset
24117
24118 .
24119  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24120  If you use MPLAB and an interrupt function then the linker script file
24121  vectors section will need to be enlarged to link with mplink.
24122 \newline
24123
24124 \newline
24125 Here is a 
24126 \family typewriter
24127 Makefile
24128 \family default
24129  using GPUTILS:
24130 \end_layout
24131
24132 \begin_layout Verse
24133
24134 \family typewriter
24135 .c.o:
24136 \newline
24137 \InsetSpace ~
24138 \InsetSpace ~
24139 \InsetSpace ~
24140 \InsetSpace ~
24141 \InsetSpace ~
24142 \InsetSpace ~
24143 \InsetSpace ~
24144 \InsetSpace ~
24145 sdcc -V -mpic14 -p16f877 -c $< 
24146 \newline
24147
24148 \newline
24149 $(PRJ).hex: $(OBJS) 
24150 \newline
24151 \InsetSpace ~
24152 \InsetSpace ~
24153 \InsetSpace ~
24154 \InsetSpace ~
24155 \InsetSpace ~
24156 \InsetSpace ~
24157 \InsetSpace ~
24158 \InsetSpace ~
24159 gplink -m -s $(PRJ).lkr
24160  -o $(PRJ).hex $(OBJS) libsdcc.lib
24161 \end_layout
24162
24163 \begin_layout Standard
24164 Here is a 
24165 \family typewriter
24166 Makefile
24167 \family default
24168  using MPLAB:
24169 \end_layout
24170
24171 \begin_layout Verse
24172
24173 \family typewriter
24174 .c.o: 
24175 \newline
24176 \InsetSpace ~
24177 \InsetSpace ~
24178 \InsetSpace ~
24179 \InsetSpace ~
24180 \InsetSpace ~
24181 \InsetSpace ~
24182 \InsetSpace ~
24183 \InsetSpace ~
24184 sdcc -S -V -mpic14 -p16f877 $< 
24185 \newline
24186 \InsetSpace ~
24187 \InsetSpace ~
24188 \InsetSpace ~
24189 \InsetSpace ~
24190 \InsetSpace ~
24191 \InsetSpace ~
24192 \InsetSpace ~
24193 \InsetSpace ~
24194 mpasmwin /q /o $*.asm
24195 \newline
24196
24197 \newline
24198 $(PRJ).hex: $(OBJS)
24199  
24200 \newline
24201 \InsetSpace ~
24202 \InsetSpace ~
24203 \InsetSpace ~
24204 \InsetSpace ~
24205 \InsetSpace ~
24206 \InsetSpace ~
24207 \InsetSpace ~
24208 \InsetSpace ~
24209 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24210 \end_layout
24211
24212 \begin_layout Standard
24213 Please note that indentations within a
24214 \family typewriter
24215  Makefile
24216 \family default
24217  have to be done with a tabulator character.
24218 \end_layout
24219
24220 \begin_layout Subsection
24221 Command-Line Options
24222 \end_layout
24223
24224 \begin_layout Standard
24225 Besides the switches common to all SDCC backends, the PIC14 port accepts
24226  the following options (for an updated list see sdcc -
24227 \begin_inset ERT
24228 status collapsed
24229
24230 \begin_layout Standard
24231
24232
24233 \backslash
24234 /
24235 \end_layout
24236
24237 \end_inset
24238
24239 -help):
24240 \end_layout
24241
24242 \begin_layout Description
24243 -
24244 \begin_inset ERT
24245 status collapsed
24246
24247 \begin_layout Standard
24248
24249
24250 \backslash
24251 /
24252 \end_layout
24253
24254 \end_inset
24255
24256 -debug-xtra
24257 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24258
24259 \end_inset
24260
24261  emit debug info in assembly output
24262 \end_layout
24263
24264 \begin_layout Description
24265 -
24266 \begin_inset ERT
24267 status collapsed
24268
24269 \begin_layout Standard
24270
24271
24272 \backslash
24273 /
24274 \end_layout
24275
24276 \end_inset
24277
24278 -no-pcode-opt
24279 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24280
24281 \end_inset
24282
24283  disable (slightly faulty) optimization on pCode
24284 \end_layout
24285
24286 \begin_layout Description
24287 -
24288 \begin_inset ERT
24289 status collapsed
24290
24291 \begin_layout Standard
24292
24293
24294 \backslash
24295 /
24296 \end_layout
24297
24298 \end_inset
24299
24300 -stack-loc
24301 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24302
24303 \end_inset
24304
24305  sets the lowest address of the argument passing stack (defaults to a suitably
24306  large shared databank to reduce BANKSEL overhead)
24307 \end_layout
24308
24309 \begin_layout Description
24310 -
24311 \begin_inset ERT
24312 status collapsed
24313
24314 \begin_layout Standard
24315
24316
24317 \backslash
24318 /
24319 \end_layout
24320
24321 \end_inset
24322
24323 -stack-size
24324 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24325
24326 \end_inset
24327
24328  sets the size if the argument passing stack (default: 16, minimum: 4)
24329 \end_layout
24330
24331 \begin_layout Subsection
24332 Environment Variables
24333 \end_layout
24334
24335 \begin_layout Standard
24336 The PIC14 port recognizes the following environment variables:
24337 \end_layout
24338
24339 \begin_layout Description
24340 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24341  register (the ones called r0xNNNN) in a section of its own.
24342  By default (if this variable is unset), sdcc tries to cluster registers
24343  in sections in order to reduce the BANKSEL overhead when accessing them.
24344 \end_layout
24345
24346 \begin_layout Subsection
24347 The Library
24348 \end_layout
24349
24350 \begin_layout Standard
24351 The PIC14 library currently only contains support routines required by the
24352  compiler to implement multiplication, division, and floating point support.
24353  No libc-like replacement is available at the moment, though many of the
24354  common sdcc library sources (in 
24355 \family typewriter
24356 device/lib
24357 \family default
24358 ) should also compile with the PIC14 port.
24359 \end_layout
24360
24361 \begin_layout Subsubsection
24362 error: missing definition for symbol ``__gptrget1''
24363 \end_layout
24364
24365 \begin_layout Standard
24366 The PIC14 port uses library routines to provide more complex operations
24367  like multiplication, division/modulus and (generic) pointer dereferencing.
24368  In order to add these routines to your project, you must link with PIC14's
24369  
24370 \family typewriter
24371 libsdcc.lib
24372 \family default
24373 .
24374  For single source file projects this is done automatically, more complex
24375  projects must add 
24376 \family typewriter
24377 libsdcc.lib
24378 \family default
24379  to the linker's arguments.
24380  Make sure you also add an include path for the library (using the -I switch
24381  to the linker)!
24382 \end_layout
24383
24384 \begin_layout Subsubsection
24385 Processor mismatch in file ``XXX''.
24386 \end_layout
24387
24388 \begin_layout Standard
24389 This warning can usually be ignored due to the very good compatibility amongst
24390  14
24391 \begin_inset ERT
24392 status open
24393
24394 \begin_layout Standard
24395
24396
24397 \backslash
24398 ,
24399 \end_layout
24400
24401 \end_inset
24402
24403 bit PIC
24404 \begin_inset LatexCommand \index{PIC14}
24405
24406 \end_inset
24407
24408  devices.
24409 \end_layout
24410
24411 \begin_layout Standard
24412 You might also consider recompiling the library for your specific device
24413  by changing the ARCH=p16f877 (default target) entry in 
24414 \family typewriter
24415 device/lib/pic/Makefile.in
24416 \family default
24417  and 
24418 \family typewriter
24419 device/lib/pic/Makefile
24420 \family default
24421  to reflect your device.
24422  This might even improve performance for smaller devices as unneccesary
24423  BANKSELs might be removed.
24424 \end_layout
24425
24426 \begin_layout Subsection
24427 Known Bugs
24428 \end_layout
24429
24430 \begin_layout Subsubsection
24431 Function arguments
24432 \end_layout
24433
24434 \begin_layout Standard
24435 Functions with variable argument lists (like printf) are not yet supported.
24436  Similarly, taking the address of the first argument passed into a function
24437  does not work: It is currently passed in WREG and has no address...
24438 \end_layout
24439
24440 \begin_layout Subsubsection
24441 Regression tests fail
24442 \end_layout
24443
24444 \begin_layout Standard
24445 Though the small subset of regression tests in src/regression passes, SDCC
24446  regression test suite does not, indicating that there are still major bugs
24447  in the port.
24448  However, many smaller projects have successfully used SDCC in the past...
24449 \end_layout
24450
24451 \begin_layout Standard
24452
24453 \size footnotesize
24454
24455 \newpage
24456
24457 \end_layout
24458
24459 \begin_layout Section
24460 The PIC16
24461 \begin_inset LatexCommand \index{PIC16}
24462
24463 \end_inset
24464
24465  port
24466 \end_layout
24467
24468 \begin_layout Standard
24469 The PIC16 port adds support for Microchip
24470 \begin_inset LatexCommand \index{Microchip}
24471
24472 \end_inset
24473
24474
24475 \begin_inset Formula $^{\text{TM}}$
24476 \end_inset
24477
24478  PIC
24479 \begin_inset LatexCommand \index{PIC}
24480
24481 \end_inset
24482
24483
24484 \begin_inset Formula $^{\text{TM}}$
24485 \end_inset
24486
24487  MCUs with 16 bit wide instructions.
24488  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24489 ; devices supported by the port include:
24490 \end_layout
24491
24492 \begin_layout Standard
24493 18F: 242, 248, 252, 258, 442, 448, 452, 458
24494 \end_layout
24495
24496 \begin_layout Standard
24497 18F: 1220, 1320
24498 \end_layout
24499
24500 \begin_layout Standard
24501 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24502  2620
24503 \end_layout
24504
24505 \begin_layout Standard
24506 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24507  45j10, 4620
24508 \end_layout
24509
24510 \begin_layout Standard
24511 18F: 6520, 6620, 6680, 6720
24512 \end_layout
24513
24514 \begin_layout Standard
24515 18F: 8520, 8620, 8680, 8720
24516 \end_layout
24517
24518 \begin_layout Subsection
24519 Global Options
24520 \end_layout
24521
24522 \begin_layout Standard
24523 PIC16 port supports the standard command line arguments as supposed, with
24524  the exception of certain cases that will be mentioned in the following
24525  list:
24526 \end_layout
24527
24528 \begin_layout Description
24529 -
24530 \begin_inset ERT
24531 status collapsed
24532
24533 \begin_layout Standard
24534
24535
24536 \backslash
24537 /
24538 \end_layout
24539
24540 \end_inset
24541
24542 -callee-saves
24543 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24544
24545 \end_inset
24546
24547  See -
24548 \begin_inset ERT
24549 status collapsed
24550
24551 \begin_layout Standard
24552
24553
24554 \backslash
24555 /
24556 \end_layout
24557
24558 \end_inset
24559
24560 -all-callee-saves
24561 \end_layout
24562
24563 \begin_layout Description
24564 -
24565 \begin_inset ERT
24566 status collapsed
24567
24568 \begin_layout Standard
24569
24570
24571 \backslash
24572 /
24573 \end_layout
24574
24575 \end_inset
24576
24577 -fommit-frame-pointer
24578 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24579
24580 \end_inset
24581
24582  Frame pointer will be omitted when the function uses no local variables.
24583 \end_layout
24584
24585 \begin_layout Subsection
24586 Port Specific Options
24587 \begin_inset LatexCommand \index{Options PIC16}
24588
24589 \end_inset
24590
24591
24592 \end_layout
24593
24594 \begin_layout Standard
24595 The port specific options appear after the global options in the sdcc -
24596 \begin_inset ERT
24597 status collapsed
24598
24599 \begin_layout Standard
24600
24601
24602 \backslash
24603 /
24604 \end_layout
24605
24606 \end_inset
24607
24608 -help output.
24609 \end_layout
24610
24611 \begin_layout Subsubsection
24612 Code Generation Options
24613 \end_layout
24614
24615 \begin_layout Standard
24616 These options influence the generated assembler code.
24617 \end_layout
24618
24619 \begin_layout Description
24620 -
24621 \begin_inset ERT
24622 status collapsed
24623
24624 \begin_layout Standard
24625
24626
24627 \backslash
24628 /
24629 \end_layout
24630
24631 \end_inset
24632
24633 -pstack-model=[model] Used in conjuction with the command above.
24634  Defines the stack model to be used, valid stack models are:
24635 \end_layout
24636
24637 \begin_deeper
24638 \begin_layout List
24639 \labelwidthstring 00.00.0000
24640
24641 \emph on
24642 small
24643 \emph default
24644  Selects small stack model.
24645  8 bit stack and frame pointers.
24646  Supports 256 bytes stack size.
24647 \end_layout
24648
24649 \begin_layout List
24650 \labelwidthstring 00.00.0000
24651
24652 \emph on
24653 large
24654 \emph default
24655  Selects large stack model.
24656  16 bit stack and frame pointers.
24657  Supports 65536 bytes stack size.
24658 \end_layout
24659
24660 \end_deeper
24661 \begin_layout Description
24662 -
24663 \begin_inset ERT
24664 status collapsed
24665
24666 \begin_layout Standard
24667
24668
24669 \backslash
24670 /
24671 \end_layout
24672
24673 \end_inset
24674
24675 -pno-banksel Do not generate BANKSEL assembler directives.
24676 \end_layout
24677
24678 \begin_layout Description
24679 -
24680 \begin_inset ERT
24681 status collapsed
24682
24683 \begin_layout Standard
24684
24685
24686 \backslash
24687 /
24688 \end_layout
24689
24690 \end_inset
24691
24692 -extended Enable extended instruction set/literal offset addressing mode.
24693  Use with care!
24694 \end_layout
24695
24696 \begin_layout Subsubsection
24697 Optimization Options
24698 \end_layout
24699
24700 \begin_layout Description
24701 -
24702 \begin_inset ERT
24703 status collapsed
24704
24705 \begin_layout Standard
24706
24707
24708 \backslash
24709 /
24710 \end_layout
24711
24712 \end_inset
24713
24714 -obanksel=n Set optimization level for inserting BANKSELs.
24715 \newline
24716
24717 \end_layout
24718
24719 \begin_deeper
24720 \begin_layout List
24721 \labelwidthstring 00.00.0000
24722 0 no optimization
24723 \end_layout
24724
24725 \begin_layout List
24726 \labelwidthstring 00.00.0000
24727 1 checks previous used register and if it is the same then does not emit
24728  BANKSEL, accounts only for labels.
24729 \end_layout
24730
24731 \begin_layout List
24732 \labelwidthstring 00.00.0000
24733 2 tries to check the location of (even different) symbols and removes BANKSELs
24734  if they are in the same bank.
24735  
24736 \newline
24737
24738 \emph on
24739 Important: There might be problems if the linker script has data sections
24740  across bank borders!
24741 \end_layout
24742
24743 \end_deeper
24744 \begin_layout Description
24745 -
24746 \begin_inset ERT
24747 status collapsed
24748
24749 \begin_layout Standard
24750
24751
24752 \backslash
24753 /
24754 \end_layout
24755
24756 \end_inset
24757
24758 -denable-peeps Force the usage of peepholes.
24759  Use with care.
24760 \end_layout
24761
24762 \begin_layout Description
24763 -
24764 \begin_inset ERT
24765 status collapsed
24766
24767 \begin_layout Standard
24768
24769
24770 \backslash
24771 /
24772 \end_layout
24773
24774 \end_inset
24775
24776 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24777 \end_layout
24778
24779 \begin_layout Description
24780 -
24781 \begin_inset ERT
24782 status collapsed
24783
24784 \begin_layout Standard
24785
24786
24787 \backslash
24788 /
24789 \end_layout
24790
24791 \end_inset
24792
24793 -optimize-cmp Try to optimize some compares.
24794 \end_layout
24795
24796 \begin_layout Description
24797 -
24798 \begin_inset ERT
24799 status collapsed
24800
24801 \begin_layout Standard
24802
24803
24804 \backslash
24805 /
24806 \end_layout
24807
24808 \end_inset
24809
24810 -optimize-df Analyze the dataflow of the generated code and improve it.
24811 \end_layout
24812
24813 \begin_layout Subsubsection
24814 Assembling Options
24815 \end_layout
24816
24817 \begin_layout Description
24818 -
24819 \begin_inset ERT
24820 status collapsed
24821
24822 \begin_layout Standard
24823
24824
24825 \backslash
24826 /
24827 \end_layout
24828
24829 \end_inset
24830
24831 -asm= Sets the full path and name of an external assembler to call.
24832 \end_layout
24833
24834 \begin_layout Description
24835 -
24836 \begin_inset ERT
24837 status collapsed
24838
24839 \begin_layout Standard
24840
24841
24842 \backslash
24843 /
24844 \end_layout
24845
24846 \end_inset
24847
24848 -mplab-comp MPLAB
24849 \begin_inset LatexCommand \index{PIC16!MPLAB}
24850
24851 \end_inset
24852
24853  compatibility option.
24854  Currently only suppresses special gpasm directives.
24855 \end_layout
24856
24857 \begin_layout Subsubsection
24858 Linking Options
24859 \end_layout
24860
24861 \begin_layout Description
24862 -
24863 \begin_inset ERT
24864 status collapsed
24865
24866 \begin_layout Standard
24867
24868
24869 \backslash
24870 /
24871 \end_layout
24872
24873 \end_inset
24874
24875 -link= Sets the full path and name of an external linker to call.
24876 \end_layout
24877
24878 \begin_layout Description
24879 -
24880 \begin_inset ERT
24881 status collapsed
24882
24883 \begin_layout Standard
24884
24885
24886 \backslash
24887 /
24888 \end_layout
24889
24890 \end_inset
24891
24892 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24893  unitialized data variables with [kword].
24894  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24895 \end_layout
24896
24897 \begin_layout Description
24898 -
24899 \begin_inset ERT
24900 status collapsed
24901
24902 \begin_layout Standard
24903
24904
24905 \backslash
24906 /
24907 \end_layout
24908
24909 \end_inset
24910
24911 -ivt-loc=n Place the interrupt vector table at address 
24912 \emph on
24913 n
24914 \emph default
24915 .
24916  Useful for bootloaders.
24917 \end_layout
24918
24919 \begin_layout Description
24920 -
24921 \begin_inset ERT
24922 status collapsed
24923
24924 \begin_layout Standard
24925
24926
24927 \backslash
24928 /
24929 \end_layout
24930
24931 \end_inset
24932
24933 -nodefaultlibs Do not link default libraries when linking.
24934 \end_layout
24935
24936 \begin_layout Description
24937 -
24938 \begin_inset ERT
24939 status collapsed
24940
24941 \begin_layout Standard
24942
24943
24944 \backslash
24945 /
24946 \end_layout
24947
24948 \end_inset
24949
24950 -use-crt= Use a custom run-time module instead of the defaults.
24951 \end_layout
24952
24953 \begin_layout Description
24954 -
24955 \begin_inset ERT
24956 status collapsed
24957
24958 \begin_layout Standard
24959
24960
24961 \backslash
24962 /
24963 \end_layout
24964
24965 \end_inset
24966
24967 -no-crt Don't link the default run-time modules
24968 \end_layout
24969
24970 \begin_layout Subsubsection
24971 Debugging Options
24972 \end_layout
24973
24974 \begin_layout Standard
24975 Debugging options enable extra debugging information in the output files.
24976 \end_layout
24977
24978 \begin_layout Description
24979 -
24980 \begin_inset ERT
24981 status collapsed
24982
24983 \begin_layout Standard
24984
24985
24986 \backslash
24987 /
24988 \end_layout
24989
24990 \end_inset
24991
24992 -debug-xtra Similar to -
24993 \begin_inset ERT
24994 status collapsed
24995
24996 \begin_layout Standard
24997
24998
24999 \backslash
25000 /
25001 \end_layout
25002
25003 \end_inset
25004
25005 -debug
25006 \begin_inset LatexCommand \index{-\/-debug}
25007
25008 \end_inset
25009
25010 , but dumps more information.
25011 \end_layout
25012
25013 \begin_layout Description
25014 -
25015 \begin_inset ERT
25016 status collapsed
25017
25018 \begin_layout Standard
25019
25020
25021 \backslash
25022 /
25023 \end_layout
25024
25025 \end_inset
25026
25027 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25028  information.
25029  <source> is the name of the file being compiled.
25030 \end_layout
25031
25032 \begin_layout Description
25033 -
25034 \begin_inset ERT
25035 status collapsed
25036
25037 \begin_layout Standard
25038
25039
25040 \backslash
25041 /
25042 \end_layout
25043
25044 \end_inset
25045
25046 -pcode-verbose Enable pcode debugging information in translation.
25047 \end_layout
25048
25049 \begin_layout Description
25050 -
25051 \begin_inset ERT
25052 status collapsed
25053
25054 \begin_layout Standard
25055
25056
25057 \backslash
25058 /
25059 \end_layout
25060
25061 \end_inset
25062
25063 -calltree Dump call tree in .calltree file.
25064 \end_layout
25065
25066 \begin_layout Description
25067 -
25068 \begin_inset ERT
25069 status collapsed
25070
25071 \begin_layout Standard
25072
25073
25074 \backslash
25075 /
25076 \end_layout
25077
25078 \end_inset
25079
25080 -gstack Trace push/pops for stack pointer overflow.
25081 \end_layout
25082
25083 \begin_layout Subsection
25084 Enviroment Variables
25085 \end_layout
25086
25087 \begin_layout Standard
25088 There is a number of enviromental variables that can be used when running
25089  SDCC to enable certain optimizations or force a specific program behaviour.
25090  these variables are primarily for debugging purposes so they can be enabled/dis
25091 abled at will.
25092 \end_layout
25093
25094 \begin_layout Standard
25095 Currently there is only two such variables available:
25096 \end_layout
25097
25098 \begin_layout Description
25099 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25100  bitfields is optimized by directly loading FSR0 with the address of the
25101  bitfield structure.
25102  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25103  then load FSR0.
25104  This step saves data ram and code space for functions that make heavy use
25105  of bitfields.
25106  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25107  option).
25108  
25109 \end_layout
25110
25111 \begin_layout Description
25112 NO_REG_OPT Do not perform pCode registers optimization.
25113  This should be used for debugging purposes.
25114  If bugs in the pcode optimizer are found, users can benefit from temporarily
25115  disabling the optimizer until the bug is fixed.
25116 \end_layout
25117
25118 \begin_layout Subsection
25119 Preprocessor Macros
25120 \end_layout
25121
25122 \begin_layout Standard
25123 PIC16
25124 \begin_inset LatexCommand \index{PIC16}
25125
25126 \end_inset
25127
25128  port defines the following preprocessor macros while translating a source.
25129 \end_layout
25130
25131 \begin_layout Standard
25132 \align center
25133 \begin_inset Tabular
25134 <lyxtabular version="3" rows="6" columns="2">
25135 <features>
25136 <column alignment="center" valignment="top" leftline="true" width="0">
25137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25138 <row topline="true" bottomline="true">
25139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25140 \begin_inset Text
25141
25142 \begin_layout Standard
25143 Macro
25144 \end_layout
25145
25146 \end_inset
25147 </cell>
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25149 \begin_inset Text
25150
25151 \begin_layout Standard
25152 Description
25153 \end_layout
25154
25155 \end_inset
25156 </cell>
25157 </row>
25158 <row topline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25160 \begin_inset Text
25161
25162 \begin_layout Standard
25163 SDCC_pic16
25164 \end_layout
25165
25166 \end_inset
25167 </cell>
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25169 \begin_inset Text
25170
25171 \begin_layout Standard
25172 Port identification
25173 \end_layout
25174
25175 \end_inset
25176 </cell>
25177 </row>
25178 <row topline="true">
25179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25180 \begin_inset Text
25181
25182 \begin_layout Standard
25183 _
25184 \begin_inset ERT
25185 status collapsed
25186
25187 \begin_layout Standard
25188
25189
25190 \backslash
25191 /
25192 \end_layout
25193
25194 \end_inset
25195
25196 _pic16
25197 \end_layout
25198
25199 \end_inset
25200 </cell>
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25202 \begin_inset Text
25203
25204 \begin_layout Standard
25205 Port identification (same as above)
25206 \end_layout
25207
25208 \end_inset
25209 </cell>
25210 </row>
25211 <row topline="true">
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25213 \begin_inset Text
25214
25215 \begin_layout Standard
25216 pic18fxxxx
25217 \end_layout
25218
25219 \end_inset
25220 </cell>
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25222 \begin_inset Text
25223
25224 \begin_layout Standard
25225 MCU Identification.
25226  
25227 \emph on
25228 xxxx
25229 \emph default
25230  is the microcontrol identification number, i.e.
25231  452, 6620, etc
25232 \end_layout
25233
25234 \end_inset
25235 </cell>
25236 </row>
25237 <row topline="true">
25238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25239 \begin_inset Text
25240
25241 \begin_layout Standard
25242 _
25243 \begin_inset ERT
25244 status collapsed
25245
25246 \begin_layout Standard
25247
25248
25249 \backslash
25250 /
25251 \end_layout
25252
25253 \end_inset
25254
25255 _18Fxxxx
25256 \end_layout
25257
25258 \end_inset
25259 </cell>
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25261 \begin_inset Text
25262
25263 \begin_layout Standard
25264 MCU Identification (same as above)
25265 \end_layout
25266
25267 \end_inset
25268 </cell>
25269 </row>
25270 <row topline="true" bottomline="true">
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25272 \begin_inset Text
25273
25274 \begin_layout Standard
25275 STACK_MODEL_nnn
25276 \end_layout
25277
25278 \end_inset
25279 </cell>
25280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25281 \begin_inset Text
25282
25283 \begin_layout Standard
25284 nnn = SMALL or LARGE respectively according to the stack model used
25285 \end_layout
25286
25287 \end_inset
25288 </cell>
25289 </row>
25290 </lyxtabular>
25291
25292 \end_inset
25293
25294
25295 \end_layout
25296
25297 \begin_layout Standard
25298 In addition the following macros are defined when calling assembler:
25299 \end_layout
25300
25301 \begin_layout Standard
25302 \align center
25303 \begin_inset Tabular
25304 <lyxtabular version="3" rows="4" columns="2">
25305 <features>
25306 <column alignment="center" valignment="top" leftline="true" width="0">
25307 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25308 <row topline="true" bottomline="true">
25309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25310 \begin_inset Text
25311
25312 \begin_layout Standard
25313 Macro
25314 \end_layout
25315
25316 \end_inset
25317 </cell>
25318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25319 \begin_inset Text
25320
25321 \begin_layout Standard
25322 Description
25323 \end_layout
25324
25325 \end_inset
25326 </cell>
25327 </row>
25328 <row topline="true">
25329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25330 \begin_inset Text
25331
25332 \begin_layout Standard
25333 __18Fxxxx
25334 \end_layout
25335
25336 \end_inset
25337 </cell>
25338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25339 \begin_inset Text
25340
25341 \begin_layout Standard
25342 MCU Identification.
25343  
25344 \emph on
25345 xxxx
25346 \emph default
25347  is the microcontrol identification number, i.e.
25348  452, 6620, etc
25349 \end_layout
25350
25351 \end_inset
25352 </cell>
25353 </row>
25354 <row topline="true">
25355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25356 \begin_inset Text
25357
25358 \begin_layout Standard
25359 SDCC_MODEL_nnn
25360 \end_layout
25361
25362 \end_inset
25363 </cell>
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25365 \begin_inset Text
25366
25367 \begin_layout Standard
25368 nnn = SMALL or LARGE respectively according to the memory model used for
25369  SDCC
25370 \end_layout
25371
25372 \end_inset
25373 </cell>
25374 </row>
25375 <row topline="true" bottomline="true">
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25377 \begin_inset Text
25378
25379 \begin_layout Standard
25380 STACK_MODEL_nnn
25381 \end_layout
25382
25383 \end_inset
25384 </cell>
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25386 \begin_inset Text
25387
25388 \begin_layout Standard
25389 nnn = SMALL or LARGE respectively according to the stack model used
25390 \end_layout
25391
25392 \end_inset
25393 </cell>
25394 </row>
25395 </lyxtabular>
25396
25397 \end_inset
25398
25399
25400 \end_layout
25401
25402 \begin_layout Subsection
25403 Directories
25404 \end_layout
25405
25406 \begin_layout Standard
25407 PIC16
25408 \begin_inset LatexCommand \index{PIC16}
25409
25410 \end_inset
25411
25412  port uses the following directories for searching header files and libraries.
25413 \end_layout
25414
25415 \begin_layout Standard
25416 \align center
25417 \begin_inset Tabular
25418 <lyxtabular version="3" rows="3" columns="4">
25419 <features>
25420 <column alignment="center" valignment="top" leftline="true" width="0">
25421 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25422 <column alignment="center" valignment="top" width="0">
25423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25424 <row topline="true" bottomline="true">
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25426 \begin_inset Text
25427
25428 \begin_layout Standard
25429 Directory
25430 \end_layout
25431
25432 \end_inset
25433 </cell>
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25435 \begin_inset Text
25436
25437 \begin_layout Standard
25438 Description
25439 \end_layout
25440
25441 \end_inset
25442 </cell>
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25444 \begin_inset Text
25445
25446 \begin_layout Standard
25447 Target
25448 \end_layout
25449
25450 \end_inset
25451 </cell>
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25453 \begin_inset Text
25454
25455 \begin_layout Standard
25456 Command prefix
25457 \end_layout
25458
25459 \end_inset
25460 </cell>
25461 </row>
25462 <row topline="true">
25463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25464 \begin_inset Text
25465
25466 \begin_layout Standard
25467 PREFIX/sdcc/include/pic16
25468 \end_layout
25469
25470 \end_inset
25471 </cell>
25472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25473 \begin_inset Text
25474
25475 \begin_layout Standard
25476 PIC16 specific headers
25477 \end_layout
25478
25479 \end_inset
25480 </cell>
25481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25482 \begin_inset Text
25483
25484 \begin_layout Standard
25485 Compiler
25486 \end_layout
25487
25488 \end_inset
25489 </cell>
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25491 \begin_inset Text
25492
25493 \begin_layout Standard
25494 -I
25495 \end_layout
25496
25497 \end_inset
25498 </cell>
25499 </row>
25500 <row topline="true" bottomline="true">
25501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25502 \begin_inset Text
25503
25504 \begin_layout Standard
25505 PREFIX/sdcc/lib/pic16
25506 \end_layout
25507
25508 \end_inset
25509 </cell>
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25511 \begin_inset Text
25512
25513 \begin_layout Standard
25514 PIC16 specific libraries
25515 \end_layout
25516
25517 \end_inset
25518 </cell>
25519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25520 \begin_inset Text
25521
25522 \begin_layout Standard
25523 Linker
25524 \end_layout
25525
25526 \end_inset
25527 </cell>
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25529 \begin_inset Text
25530
25531 \begin_layout Standard
25532 -L
25533 \end_layout
25534
25535 \end_inset
25536 </cell>
25537 </row>
25538 </lyxtabular>
25539
25540 \end_inset
25541
25542
25543 \end_layout
25544
25545 \begin_layout Subsection
25546 Pragmas
25547 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25548
25549 \end_inset
25550
25551
25552 \end_layout
25553
25554 \begin_layout Standard
25555 The PIC16
25556 \begin_inset LatexCommand \index{PIC16}
25557
25558 \end_inset
25559
25560  port currently supports the following pragmas:
25561 \end_layout
25562
25563 \begin_layout Description
25564 stack
25565 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25566
25567 \end_inset
25568
25569  This forces the code generator to initialize the stack & frame pointers
25570  at a specific address.
25571  This is an ad hoc solution for cases where no STACK directive is available
25572  in the linker script or gplink is not instructed to create a stack section.
25573 \newline
25574 The
25575  stack pragma should be used only once in a project.
25576  Multiple pragmas may result in indeterminate behaviour of the program.
25577 \begin_inset Foot
25578 status open
25579
25580 \begin_layout Standard
25581 The old format (ie.
25582  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25583  cross page boundaries (or even exceed the available data RAM) and crash
25584  the program.
25585  Make sure that stack does not cross page boundaries when using the SMALL
25586  stack model.
25587 \end_layout
25588
25589 \end_inset
25590
25591
25592 \newline
25593 The format is as follows:
25594 \newline
25595
25596 \end_layout
25597
25598 \begin_layout LyX-Code
25599 #pragma stack bottom_address [stack_size]
25600 \newline
25601
25602 \end_layout
25603
25604 \begin_layout Standard
25605
25606 \emph on
25607 bottom_address
25608 \emph default
25609  is the lower bound of the stack section.
25610  The stack pointer initially will point at address (bottom_address+stack_size-1).
25611 \end_layout
25612
25613 \begin_layout LyX-Code
25614 Example:
25615 \end_layout
25616
25617 \begin_layout LyX-Code
25618
25619 \end_layout
25620
25621 \begin_layout LyX-Code
25622 /* initializes stack of 100 bytes at RAM address 0x200 */
25623 \end_layout
25624
25625 \begin_layout LyX-Code
25626 #pragma stack 0x200 100
25627 \end_layout
25628
25629 \begin_layout Standard
25630 If the stack_size field is omitted then a stack is created with the default
25631  size of 64.
25632  This size might be enough for most programs, but its not enough for operations
25633  with deep function nesting or excessive stack usage.
25634 \end_layout
25635
25636 \begin_layout Description
25637 code
25638 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25639
25640 \end_inset
25641
25642  Force a function to a static FLASH address.
25643 \end_layout
25644
25645 \begin_layout LyX-Code
25646 Example:
25647 \end_layout
25648
25649 \begin_layout LyX-Code
25650
25651 \end_layout
25652
25653 \begin_layout LyX-Code
25654 /* place function test_func at 0x4000 */
25655 \end_layout
25656
25657 \begin_layout LyX-Code
25658 #pragma code test_func 0x4000
25659 \end_layout
25660
25661 \begin_layout LyX-Code
25662
25663 \end_layout
25664
25665 \begin_layout Description
25666 library instructs the linker to use a library module.
25667 \newline
25668 Usage:
25669 \end_layout
25670
25671 \begin_layout LyX-Code
25672 #pragma library module_name
25673 \end_layout
25674
25675 \begin_layout Standard
25676
25677 \emph on
25678 module_name
25679 \emph default
25680  can be any library or object file (including its path).
25681  Note that there are four reserved keywords which have special meaning.
25682  These are:
25683 \end_layout
25684
25685 \begin_layout Standard
25686 \align center
25687 \begin_inset Tabular
25688 <lyxtabular version="3" rows="6" columns="3">
25689 <features>
25690 <column alignment="center" valignment="top" leftline="true" width="0">
25691 <column alignment="block" valignment="top" leftline="true" width="20page%">
25692 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25693 <row topline="true" bottomline="true">
25694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25695 \begin_inset Text
25696
25697 \begin_layout Standard
25698 Keyword
25699 \end_layout
25700
25701 \end_inset
25702 </cell>
25703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25704 \begin_inset Text
25705
25706 \begin_layout Standard
25707 Description
25708 \end_layout
25709
25710 \end_inset
25711 </cell>
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25713 \begin_inset Text
25714
25715 \begin_layout Standard
25716 Module to link
25717 \end_layout
25718
25719 \end_inset
25720 </cell>
25721 </row>
25722 <row topline="true">
25723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25724 \begin_inset Text
25725
25726 \begin_layout Standard
25727
25728 \series bold
25729 ignore
25730 \end_layout
25731
25732 \end_inset
25733 </cell>
25734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25735 \begin_inset Text
25736
25737 \begin_layout Standard
25738 ignore all library pragmas
25739 \end_layout
25740
25741 \end_inset
25742 </cell>
25743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25744 \begin_inset Text
25745
25746 \begin_layout Standard
25747
25748 \emph on
25749 (none)
25750 \end_layout
25751
25752 \end_inset
25753 </cell>
25754 </row>
25755 <row topline="true">
25756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25757 \begin_inset Text
25758
25759 \begin_layout Standard
25760
25761 \series bold
25762 c
25763 \end_layout
25764
25765 \end_inset
25766 </cell>
25767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25768 \begin_inset Text
25769
25770 \begin_layout Standard
25771 link the C library
25772 \end_layout
25773
25774 \end_inset
25775 </cell>
25776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25777 \begin_inset Text
25778
25779 \begin_layout Standard
25780
25781 \emph on
25782 libc18f
25783 \emph default
25784 .lib
25785 \end_layout
25786
25787 \end_inset
25788 </cell>
25789 </row>
25790 <row topline="true">
25791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25792 \begin_inset Text
25793
25794 \begin_layout Standard
25795
25796 \series bold
25797 math
25798 \end_layout
25799
25800 \end_inset
25801 </cell>
25802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25803 \begin_inset Text
25804
25805 \begin_layout Standard
25806 link the Math libarary
25807 \end_layout
25808
25809 \end_inset
25810 </cell>
25811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25812 \begin_inset Text
25813
25814 \begin_layout Standard
25815
25816 \emph on
25817 libm18f
25818 \emph default
25819 .lib
25820 \end_layout
25821
25822 \end_inset
25823 </cell>
25824 </row>
25825 <row topline="true">
25826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25827 \begin_inset Text
25828
25829 \begin_layout Standard
25830
25831 \series bold
25832 io
25833 \end_layout
25834
25835 \end_inset
25836 </cell>
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25838 \begin_inset Text
25839
25840 \begin_layout Standard
25841 link the I/O library
25842 \end_layout
25843
25844 \end_inset
25845 </cell>
25846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25847 \begin_inset Text
25848
25849 \begin_layout Standard
25850
25851 \emph on
25852 libio18f*
25853 \emph default
25854 .lib
25855 \end_layout
25856
25857 \end_inset
25858 </cell>
25859 </row>
25860 <row topline="true" bottomline="true">
25861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25862 \begin_inset Text
25863
25864 \begin_layout Standard
25865
25866 \series bold
25867 debug
25868 \end_layout
25869
25870 \end_inset
25871 </cell>
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25873 \begin_inset Text
25874
25875 \begin_layout Standard
25876 link the debug library
25877 \end_layout
25878
25879 \end_inset
25880 </cell>
25881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25882 \begin_inset Text
25883
25884 \begin_layout Standard
25885
25886 \emph on
25887 libdebug
25888 \emph default
25889 .lib
25890 \end_layout
25891
25892 \end_inset
25893 </cell>
25894 </row>
25895 </lyxtabular>
25896
25897 \end_inset
25898
25899
25900 \newline
25901 * is the device number, i.e.
25902  452 for PIC18F452 MCU.
25903 \end_layout
25904
25905 \begin_layout Standard
25906 This feature allows for linking with specific libraries withoug having to
25907  explicit name them in the command line.
25908  Note that the 
25909 \noun on
25910 ignore
25911 \noun default
25912  keyword will reject all modules specified by the library pragma.
25913 \end_layout
25914
25915 \begin_layout Description
25916 udata The pragma udata instructs the compiler to emit code so that linker
25917  will place a variable at a specific memory bank.
25918 \end_layout
25919
25920 \begin_layout LyX-Code
25921 Example:
25922 \end_layout
25923
25924 \begin_layout LyX-Code
25925
25926 \end_layout
25927
25928 \begin_layout LyX-Code
25929 /* places variable foo at bank2 */
25930 \end_layout
25931
25932 \begin_layout LyX-Code
25933 #pragma udata bank2 foo
25934 \end_layout
25935
25936 \begin_layout LyX-Code
25937 char foo;
25938 \end_layout
25939
25940 \begin_layout Standard
25941 In order for this pragma to work extra SECTION directives should be added
25942  in the .lkr script.
25943  In the following example a sample .lkr file is shown:
25944 \end_layout
25945
25946 \begin_layout LyX-Code
25947
25948 \end_layout
25949
25950 \begin_layout LyX-Code
25951 // Sample linker script for the PIC18F452 processor
25952 \end_layout
25953
25954 \begin_layout LyX-Code
25955 LIBPATH .
25956 \end_layout
25957
25958 \begin_layout LyX-Code
25959 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25960 \end_layout
25961
25962 \begin_layout LyX-Code
25963 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25964 \end_layout
25965
25966 \begin_layout LyX-Code
25967 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25968 \end_layout
25969
25970 \begin_layout LyX-Code
25971 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25972 \end_layout
25973
25974 \begin_layout LyX-Code
25975 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25976 \end_layout
25977
25978 \begin_layout LyX-Code
25979 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25980 \end_layout
25981
25982 \begin_layout LyX-Code
25983 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25984 \end_layout
25985
25986 \begin_layout LyX-Code
25987
25988 \end_layout
25989
25990 \begin_layout LyX-Code
25991 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25992 \end_layout
25993
25994 \begin_layout LyX-Code
25995 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25996 \end_layout
25997
25998 \begin_layout LyX-Code
25999 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
26000 \end_layout
26001
26002 \begin_layout LyX-Code
26003 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
26004 \end_layout
26005
26006 \begin_layout LyX-Code
26007 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
26008 \end_layout
26009
26010 \begin_layout LyX-Code
26011 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
26012 \end_layout
26013
26014 \begin_layout LyX-Code
26015 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
26016 \end_layout
26017
26018 \begin_layout LyX-Code
26019
26020 \end_layout
26021
26022 \begin_layout LyX-Code
26023 SECTION    NAME=CONFIG     ROM=config
26024 \end_layout
26025
26026 \begin_layout LyX-Code
26027
26028 \end_layout
26029
26030 \begin_layout LyX-Code
26031 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
26032 \end_layout
26033
26034 \begin_layout LyX-Code
26035 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
26036 \end_layout
26037
26038 \begin_layout LyX-Code
26039 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
26040 \end_layout
26041
26042 \begin_layout LyX-Code
26043 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
26044 \end_layout
26045
26046 \begin_layout LyX-Code
26047 SECTION    NAME=bank4      RAM=gpr4
26048 \end_layout
26049
26050 \begin_layout LyX-Code
26051 SECTION    NAME=bank5      RAM=gpr5
26052 \end_layout
26053
26054 \begin_layout Standard
26055 The linker will recognise the section name set in the pragma statement and
26056  will position the variable at the memory bank set with the RAM field at
26057  the SECTION line in the linker script file.
26058 \end_layout
26059
26060 \begin_layout Subsection
26061 Header Files
26062 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26063
26064 \end_inset
26065
26066
26067 \end_layout
26068
26069 \begin_layout Standard
26070 There is one main header file
26071 \begin_inset LatexCommand \index{PIC16!Header files}
26072
26073 \end_inset
26074
26075  that can be included to the source files using the pic16
26076 \begin_inset LatexCommand \index{PIC16}
26077
26078 \end_inset
26079
26080  port.
26081  That file is the 
26082 \series bold
26083 pic18fregs.h
26084 \series default
26085 .
26086  This header file contains the definitions for the processor special registers,
26087  so it is necessary if the source accesses them.
26088  It can be included by adding the following line in the beginning of the
26089  file:
26090 \end_layout
26091
26092 \begin_layout LyX-Code
26093 #include <pic18fregs.h>
26094 \end_layout
26095
26096 \begin_layout Standard
26097 The specific microcontroller is selected within the pic18fregs.h automatically,
26098  so the same source can be used with a variety of devices.
26099 \end_layout
26100
26101 \begin_layout Subsection
26102 Libraries
26103 \end_layout
26104
26105 \begin_layout Standard
26106 The libraries
26107 \begin_inset LatexCommand \index{PIC16!Libraries}
26108
26109 \end_inset
26110
26111  that PIC16
26112 \begin_inset LatexCommand \index{PIC16}
26113
26114 \end_inset
26115
26116  port depends on are the microcontroller device libraries which contain
26117  the symbol definitions for the microcontroller special function registers.
26118  These libraries have the format pic18fxxxx.lib, where 
26119 \emph on
26120 xxxx
26121 \emph default
26122  is the microcontroller identification number.
26123  The specific library is selected automatically by the compiler at link
26124  stage according to the selected device.
26125 \end_layout
26126
26127 \begin_layout Standard
26128 Libraries are created with gplib which is part of the gputils package 
26129 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26130
26131 \end_inset
26132
26133 .
26134 \end_layout
26135
26136 \begin_layout Subsubsection*
26137 Building the libraries
26138 \end_layout
26139
26140 \begin_layout Standard
26141 Before using SDCC/pic16 there are some libraries that need to be compiled.
26142  This process is not done automatically by SDCC since not all users use
26143  SDCC for pic16 projects.
26144  So each user should compile the libraries separately.
26145 \end_layout
26146
26147 \begin_layout Standard
26148 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26149 \end_layout
26150
26151 \begin_layout LyX-Code
26152 cd device/lib/pic16
26153 \end_layout
26154
26155 \begin_layout LyX-Code
26156 ./configure
26157 \end_layout
26158
26159 \begin_layout LyX-Code
26160 make
26161 \end_layout
26162
26163 \begin_layout LyX-Code
26164 cd ..
26165 \end_layout
26166
26167 \begin_layout LyX-Code
26168 make model-pic16
26169 \end_layout
26170
26171 \begin_layout LyX-Code
26172 su -c 'make install'     # install the libraries, you need the root password
26173 \end_layout
26174
26175 \begin_layout Standard
26176 If you need to install the headers too, do:
26177 \end_layout
26178
26179 \begin_layout LyX-Code
26180 cd device/include
26181 \end_layout
26182
26183 \begin_layout LyX-Code
26184 su -c 'make install'     # install the headers, you need the root password
26185 \end_layout
26186
26187 \begin_layout Standard
26188 There exist a special target to build the I/O libraries.
26189  This target is not automatically build because it will build the I/O library
26190  for 
26191 \emph on
26192 every
26193 \emph default
26194  supported device.
26195  This way building will take quite a lot of time.
26196  Users are advised to edit the 
26197 \series bold
26198 device/lib/pic16/pics.build
26199 \series default
26200  file and then execute:
26201 \end_layout
26202
26203 \begin_layout LyX-Code
26204 make lib-io
26205 \end_layout
26206
26207 \begin_layout Subsection
26208 Adding New Devices to the Port
26209 \end_layout
26210
26211 \begin_layout Standard
26212 Adding support for a new 16
26213 \begin_inset ERT
26214 status open
26215
26216 \begin_layout Standard
26217
26218
26219 \backslash
26220 ,
26221 \end_layout
26222
26223 \end_inset
26224
26225 bit PIC MCU requires the following steps:
26226 \end_layout
26227
26228 \begin_layout Enumerate
26229 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26230 \newline
26231
26232 \family typewriter
26233 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26234 inc
26235 \end_layout
26236
26237 \begin_layout Enumerate
26238
26239 \family typewriter
26240 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26241 \end_layout
26242
26243 \begin_layout Enumerate
26244
26245 \family typewriter
26246 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26247 \end_layout
26248
26249 \begin_layout Enumerate
26250 Add DEVICE to 
26251 \family typewriter
26252 /path/to/sdcc/device/lib/pic16/pics.all
26253 \family default
26254  (and 
26255 \family typewriter
26256 .build
26257 \family default
26258 ).
26259 \newline
26260 Note: No 18f prefix here!
26261 \end_layout
26262
26263 \begin_layout Enumerate
26264 Adjust 
26265 \family typewriter
26266 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26267 \family default
26268
26269 \newline
26270 Add your DEVICE if it does not compile in 
26271 \family typewriter
26272 adc
26273 \family default
26274
26275 \family typewriter
26276 i2c
26277 \family default
26278 , or 
26279 \family typewriter
26280 usart
26281 \family default
26282 .
26283 \end_layout
26284
26285 \begin_layout Enumerate
26286 Edit 
26287 \family typewriter
26288 /path/to/sdcc/device/include/pic16/pic18fregs.h
26289 \family default
26290 .
26291  The file format is self-explanatory, just add
26292 \newline
26293
26294 \family typewriter
26295 #elif defined(picDEVICE)
26296 \newline
26297 # include <picDEVICE.h>
26298 \family default
26299
26300 \newline
26301 at the right place (keep it sorted).
26302 \end_layout
26303
26304 \begin_layout Enumerate
26305 Edit 
26306 \family typewriter
26307 /path/to/sdcc/src/pic16/devices.inc
26308 \family default
26309 .
26310  Copy and modify an existing entry and insert it at the correct place (keep
26311  the file sorted).
26312  The file is hardly documented, look at the entries for the 18f2221...
26313 \end_layout
26314
26315 \begin_layout Enumerate
26316 Recompile SDCC, including the pic16 libraries.
26317 \end_layout
26318
26319 \begin_layout Subsection
26320 Memory Models
26321 \end_layout
26322
26323 \begin_layout Standard
26324 The following memory models are supported by the PIC16 port:
26325 \end_layout
26326
26327 \begin_layout Itemize
26328 small model
26329 \end_layout
26330
26331 \begin_layout Itemize
26332 large model
26333 \end_layout
26334
26335 \begin_layout Standard
26336 Memory model affects the default size of pointers within the source.
26337  The sizes are shown in the next table:
26338 \end_layout
26339
26340 \begin_layout Standard
26341 \align center
26342 \begin_inset Tabular
26343 <lyxtabular version="3" rows="3" columns="3">
26344 <features>
26345 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26346 <column alignment="center" valignment="top" leftline="true" width="0">
26347 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26348 <row topline="true" bottomline="true">
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26350 \begin_inset Text
26351
26352 \begin_layout Standard
26353 Pointer sizes according to memory model
26354 \end_layout
26355
26356 \end_inset
26357 </cell>
26358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26359 \begin_inset Text
26360
26361 \begin_layout Standard
26362 small model
26363 \end_layout
26364
26365 \end_inset
26366 </cell>
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26368 \begin_inset Text
26369
26370 \begin_layout Standard
26371 large model
26372 \end_layout
26373
26374 \end_inset
26375 </cell>
26376 </row>
26377 <row topline="true" bottomline="true">
26378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26379 \begin_inset Text
26380
26381 \begin_layout Standard
26382 code pointers
26383 \end_layout
26384
26385 \end_inset
26386 </cell>
26387 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26388 \begin_inset Text
26389
26390 \begin_layout Standard
26391 16-bits
26392 \end_layout
26393
26394 \end_inset
26395 </cell>
26396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26397 \begin_inset Text
26398
26399 \begin_layout Standard
26400 24-bits
26401 \end_layout
26402
26403 \end_inset
26404 </cell>
26405 </row>
26406 <row topline="true" bottomline="true">
26407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26408 \begin_inset Text
26409
26410 \begin_layout Standard
26411 data pointers
26412 \end_layout
26413
26414 \end_inset
26415 </cell>
26416 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26417 \begin_inset Text
26418
26419 \begin_layout Standard
26420 16-bits
26421 \end_layout
26422
26423 \end_inset
26424 </cell>
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26426 \begin_inset Text
26427
26428 \begin_layout Standard
26429 16-bits
26430 \end_layout
26431
26432 \end_inset
26433 </cell>
26434 </row>
26435 </lyxtabular>
26436
26437 \end_inset
26438
26439
26440 \end_layout
26441
26442 \begin_layout Standard
26443 It is advisable that all sources within a project are compiled with the
26444  same memory model.
26445  If one wants to override the default memory model, this can be done by
26446  declaring a pointer as 
26447 \series bold
26448 far
26449 \series default
26450  or 
26451 \series bold
26452 near
26453 \series default
26454 .
26455  Far selects large memory model's pointers, while near selects small memory
26456  model's pointers.
26457 \end_layout
26458
26459 \begin_layout Standard
26460 The standard device libraries (see 
26461 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26462
26463 \end_inset
26464
26465 ) contain no reference to pointers, so they can be used with both memory
26466  models.
26467 \end_layout
26468
26469 \begin_layout Subsection
26470 Stack
26471 \end_layout
26472
26473 \begin_layout Standard
26474 The stack
26475 \begin_inset LatexCommand \index{PIC16!stack}
26476
26477 \end_inset
26478
26479  implementation for the PIC16 port uses two indirect registers, FSR1 and
26480  FSR2.
26481 \end_layout
26482
26483 \begin_layout Description
26484 FSR1 is assigned as stack pointer
26485 \end_layout
26486
26487 \begin_layout Description
26488 FSR2 is assigned as frame pointer
26489 \end_layout
26490
26491 \begin_layout Standard
26492 The following stack models are supported by the PIC16 port
26493 \end_layout
26494
26495 \begin_layout Itemize
26496
26497 \noun on
26498 small
26499 \noun default
26500  model
26501 \end_layout
26502
26503 \begin_layout Itemize
26504
26505 \noun on
26506 large
26507 \noun default
26508  model
26509 \end_layout
26510
26511 \begin_layout Standard
26512
26513 \noun on
26514 Small
26515 \noun default
26516  model means that only the FSRxL byte is used to access stack and frame,
26517  while 
26518 \emph on
26519 \noun on
26520 large
26521 \emph default
26522 \noun default
26523  uses both FSRxL and FSRxH registers.
26524  The following table shows the stack/frame pointers sizes according to stack
26525  model and the maximum space they can address:
26526 \end_layout
26527
26528 \begin_layout Standard
26529 \align center
26530 \begin_inset Tabular
26531 <lyxtabular version="3" rows="3" columns="3">
26532 <features>
26533 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26534 <column alignment="center" valignment="top" leftline="true" width="0">
26535 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26536 <row topline="true" bottomline="true">
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26538 \begin_inset Text
26539
26540 \begin_layout Standard
26541 Stack & Frame pointer sizes according to stack model
26542 \end_layout
26543
26544 \end_inset
26545 </cell>
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26547 \begin_inset Text
26548
26549 \begin_layout Standard
26550 small
26551 \end_layout
26552
26553 \end_inset
26554 </cell>
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26556 \begin_inset Text
26557
26558 \begin_layout Standard
26559 large
26560 \end_layout
26561
26562 \end_inset
26563 </cell>
26564 </row>
26565 <row topline="true">
26566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26567 \begin_inset Text
26568
26569 \begin_layout Standard
26570 Stack pointer FSR1
26571 \end_layout
26572
26573 \end_inset
26574 </cell>
26575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26576 \begin_inset Text
26577
26578 \begin_layout Standard
26579 8-bits
26580 \end_layout
26581
26582 \end_inset
26583 </cell>
26584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26585 \begin_inset Text
26586
26587 \begin_layout Standard
26588 16-bits
26589 \end_layout
26590
26591 \end_inset
26592 </cell>
26593 </row>
26594 <row topline="true" bottomline="true">
26595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26596 \begin_inset Text
26597
26598 \begin_layout Standard
26599 Frame pointer FSR2
26600 \end_layout
26601
26602 \end_inset
26603 </cell>
26604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26605 \begin_inset Text
26606
26607 \begin_layout Standard
26608 8-bits
26609 \end_layout
26610
26611 \end_inset
26612 </cell>
26613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26614 \begin_inset Text
26615
26616 \begin_layout Standard
26617 16-bits
26618 \end_layout
26619
26620 \end_inset
26621 </cell>
26622 </row>
26623 </lyxtabular>
26624
26625 \end_inset
26626
26627
26628 \end_layout
26629
26630 \begin_layout Standard
26631
26632 \noun on
26633 Large 
26634 \noun default
26635 stack model is currently not working properly throughout the code generator.
26636  So its use is not advised.
26637  Also there are some other points that need special care:
26638 \newline
26639
26640 \end_layout
26641
26642 \begin_layout Enumerate
26643 Do not create stack sections with size more than one physical bank (that
26644  is 256 bytes)
26645 \end_layout
26646
26647 \begin_layout Enumerate
26648 Stack sections should no cross physical bank limits (i.e.
26649  #pragma stack 0x50 0x100)
26650 \end_layout
26651
26652 \begin_layout Standard
26653 These limitations are caused by the fact that only FSRxL is modified when
26654  using SMALL stack model, so no more than 256 bytes of stack can be used.
26655  This problem will disappear after LARGE model is fully implemented.
26656 \end_layout
26657
26658 \begin_layout Subsection
26659 Functions
26660 \end_layout
26661
26662 \begin_layout Standard
26663 In addition to the standard SDCC function keywords, PIC16
26664 \begin_inset LatexCommand \index{PIC16}
26665
26666 \end_inset
26667
26668  port makes available two more:
26669 \end_layout
26670
26671 \begin_layout Description
26672 wparam
26673 \begin_inset LatexCommand \index{PIC16!wparam}
26674
26675 \end_inset
26676
26677  Use the WREG to pass one byte of the first function argument.
26678  This improves speed but you may not use this for functions with arguments
26679  that are called via function pointers, otherwise the first byte of the
26680  first parameter will get lost.
26681  Usage:
26682 \end_layout
26683
26684 \begin_layout LyX-Code
26685 void func_wparam(int a) wparam
26686 \end_layout
26687
26688 \begin_layout LyX-Code
26689 {
26690 \end_layout
26691
26692 \begin_layout LyX-Code
26693     /* WREG hold the lower part of a */
26694 \end_layout
26695
26696 \begin_layout LyX-Code
26697     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26698  */
26699 \end_layout
26700
26701 \begin_layout LyX-Code
26702 ...
26703 \end_layout
26704
26705 \begin_layout LyX-Code
26706 }
26707 \end_layout
26708
26709 \begin_layout Description
26710 shadowregs
26711 \begin_inset LatexCommand \index{PIC16!shadowregs}
26712
26713 \end_inset
26714
26715  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26716  hardware shadow registers which hold the values of WREG, STATUS and BSR
26717  registers.
26718  This can be done by adding the keyword 
26719 \emph on
26720 shadowregs
26721 \emph default
26722  before the 
26723 \emph on
26724 interrupt
26725 \emph default
26726  keyword in the function's header.
26727 \end_layout
26728
26729 \begin_layout LyX-Code
26730 void isr_shadow(void) shadowregs interrupt 1
26731 \end_layout
26732
26733 \begin_layout LyX-Code
26734 {
26735 \end_layout
26736
26737 \begin_layout LyX-Code
26738 ...
26739 \end_layout
26740
26741 \begin_layout LyX-Code
26742 }
26743 \end_layout
26744
26745 \begin_layout Standard
26746
26747 \emph on
26748 shadowregs
26749 \emph default
26750  instructs the code generator not to store/restore WREG, STATUS, BSR when
26751  entering/exiting the ISR.
26752 \end_layout
26753
26754 \begin_layout Subsection
26755 Function return values
26756 \end_layout
26757
26758 \begin_layout Standard
26759 Return values from functions are placed to the appropriate registers following
26760  a modified Microchip policy optimized for SDCC.
26761  The following table shows these registers:
26762 \end_layout
26763
26764 \begin_layout Standard
26765 \align center
26766 \begin_inset Tabular
26767 <lyxtabular version="3" rows="6" columns="2">
26768 <features>
26769 <column alignment="center" valignment="top" leftline="true" width="0">
26770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26771 <row topline="true" bottomline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26773 \begin_inset Text
26774
26775 \begin_layout Standard
26776 size
26777 \end_layout
26778
26779 \end_inset
26780 </cell>
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26782 \begin_inset Text
26783
26784 \begin_layout Standard
26785 destination register
26786 \end_layout
26787
26788 \end_inset
26789 </cell>
26790 </row>
26791 <row topline="true">
26792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26793 \begin_inset Text
26794
26795 \begin_layout Standard
26796 8 bits
26797 \end_layout
26798
26799 \end_inset
26800 </cell>
26801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26802 \begin_inset Text
26803
26804 \begin_layout Standard
26805 WREG
26806 \end_layout
26807
26808 \end_inset
26809 </cell>
26810 </row>
26811 <row topline="true">
26812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26813 \begin_inset Text
26814
26815 \begin_layout Standard
26816 16 bits
26817 \end_layout
26818
26819 \end_inset
26820 </cell>
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26822 \begin_inset Text
26823
26824 \begin_layout Standard
26825 PRODL:WREG
26826 \end_layout
26827
26828 \end_inset
26829 </cell>
26830 </row>
26831 <row topline="true">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26833 \begin_inset Text
26834
26835 \begin_layout Standard
26836 24 bits
26837 \end_layout
26838
26839 \end_inset
26840 </cell>
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26842 \begin_inset Text
26843
26844 \begin_layout Standard
26845 PRODH:PRODL:WREG
26846 \end_layout
26847
26848 \end_inset
26849 </cell>
26850 </row>
26851 <row topline="true">
26852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26853 \begin_inset Text
26854
26855 \begin_layout Standard
26856 32 bits
26857 \end_layout
26858
26859 \end_inset
26860 </cell>
26861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26862 \begin_inset Text
26863
26864 \begin_layout Standard
26865 FSR0L:PRODH:PRODL:WREG
26866 \end_layout
26867
26868 \end_inset
26869 </cell>
26870 </row>
26871 <row topline="true" bottomline="true">
26872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26873 \begin_inset Text
26874
26875 \begin_layout Standard
26876 >32 bits
26877 \end_layout
26878
26879 \end_inset
26880 </cell>
26881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26882 \begin_inset Text
26883
26884 \begin_layout Standard
26885 on stack, FSR0 points to the beginning
26886 \end_layout
26887
26888 \end_inset
26889 </cell>
26890 </row>
26891 </lyxtabular>
26892
26893 \end_inset
26894
26895
26896 \end_layout
26897
26898 \begin_layout Subsection
26899 Interrupts
26900 \end_layout
26901
26902 \begin_layout Standard
26903 An interrupt
26904 \begin_inset LatexCommand \index{PIC16!interrupt}
26905
26906 \end_inset
26907
26908  service routine (ISR) is declared using the 
26909 \emph on
26910 interrupt
26911 \emph default
26912  keyword.
26913 \end_layout
26914
26915 \begin_layout LyX-Code
26916 void isr(void) interrupt 
26917 \emph on
26918 n
26919 \end_layout
26920
26921 \begin_layout LyX-Code
26922 {
26923 \end_layout
26924
26925 \begin_layout LyX-Code
26926 ...
26927 \end_layout
26928
26929 \begin_layout LyX-Code
26930 }
26931 \end_layout
26932
26933 \begin_layout Standard
26934
26935 \emph on
26936 n
26937 \emph default
26938  is the interrupt number, which for PIC18F devices can be:
26939 \end_layout
26940
26941 \begin_layout Standard
26942 \align center
26943 \begin_inset Tabular
26944 <lyxtabular version="3" rows="4" columns="3">
26945 <features>
26946 <column alignment="center" valignment="top" leftline="true" width="0">
26947 <column alignment="center" valignment="top" leftline="true" width="0">
26948 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26949 <row topline="true" bottomline="true">
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26951 \begin_inset Text
26952
26953 \begin_layout Standard
26954
26955 \emph on
26956 n
26957 \end_layout
26958
26959 \end_inset
26960 </cell>
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26962 \begin_inset Text
26963
26964 \begin_layout Standard
26965 Interrupt Vector
26966 \end_layout
26967
26968 \end_inset
26969 </cell>
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26971 \begin_inset Text
26972
26973 \begin_layout Standard
26974 Interrupt Vector Address
26975 \end_layout
26976
26977 \end_inset
26978 </cell>
26979 </row>
26980 <row topline="true">
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26982 \begin_inset Text
26983
26984 \begin_layout Standard
26985 0
26986 \end_layout
26987
26988 \end_inset
26989 </cell>
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994 RESET vector
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \begin_layout Standard
27003 0x000000
27004 \end_layout
27005
27006 \end_inset
27007 </cell>
27008 </row>
27009 <row topline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014
27015 \family roman
27016 \series medium
27017 \shape up
27018 \size normal
27019 \emph off
27020 \bar no
27021 \noun off
27022 \color none
27023 1
27024 \end_layout
27025
27026 \end_inset
27027 </cell>
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032
27033 \family roman
27034 \series medium
27035 \shape up
27036 \size normal
27037 \emph off
27038 \bar no
27039 \noun off
27040 \color none
27041 HIGH priority interrupts
27042 \end_layout
27043
27044 \end_inset
27045 </cell>
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27047 \begin_inset Text
27048
27049 \begin_layout Standard
27050 0x000008
27051 \end_layout
27052
27053 \end_inset
27054 </cell>
27055 </row>
27056 <row topline="true" bottomline="true">
27057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27058 \begin_inset Text
27059
27060 \begin_layout Standard
27061 2
27062 \end_layout
27063
27064 \end_inset
27065 </cell>
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27067 \begin_inset Text
27068
27069 \begin_layout Standard
27070 LOW priority interrupts
27071 \end_layout
27072
27073 \end_inset
27074 </cell>
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27076 \begin_inset Text
27077
27078 \begin_layout Standard
27079 0x000018
27080 \end_layout
27081
27082 \end_inset
27083 </cell>
27084 </row>
27085 </lyxtabular>
27086
27087 \end_inset
27088
27089
27090 \end_layout
27091
27092 \begin_layout Standard
27093 When generating assembly code for ISR the code generator places a 
27094 \noun on
27095 goto 
27096 \noun default
27097 instruction at the 
27098 \emph on
27099 Interrupt Vector Address
27100 \emph default
27101  which points at the genetated ISR.
27102  This single GOTO instruction is part of an automatically generated 
27103 \emph on
27104 interrupt entry point
27105 \emph default
27106  function.
27107  The actuall ISR code is placed as normally would in the code space.
27108  Upon interrupt request, the GOTO instruction is executed which jumps to
27109  the ISR code.
27110  When declaring interrupt functions as _naked this GOTO instruction is 
27111 \series bold
27112 not
27113 \series default
27114  generated.
27115  The whole interrupt functions is therefore placed at the Interrupt Vector
27116  Address of the specific interrupt.
27117  This is not a problem for the LOW priority interrupts, but it is a problem
27118  for the RESET and the HIGH priority interrupts because code may be written
27119  at the next interrupt's vector address and cause undeterminate program
27120  behaviour if that interrupt is raised.
27121 \begin_inset Foot
27122 status open
27123
27124 \begin_layout Standard
27125 This is not a problem when
27126 \end_layout
27127
27128 \begin_layout Enumerate
27129 this is a HIGH interrupt ISR and LOW interrupts are 
27130 \emph on
27131 disabled
27132 \emph default
27133  or not used.
27134 \end_layout
27135
27136 \begin_layout Enumerate
27137 when the ISR is small enough not to reach the next interrupt's vector address.
27138 \end_layout
27139
27140 \end_inset
27141
27142
27143 \end_layout
27144
27145 \begin_layout Standard
27146
27147 \emph on
27148 n
27149 \emph default
27150  may be omitted.
27151  This way a function is generated similar to an ISR, but it is not assigned
27152  to any interrupt.
27153 \end_layout
27154
27155 \begin_layout Standard
27156 When entering an interrupt, currently the PIC16
27157 \begin_inset LatexCommand \index{PIC16}
27158
27159 \end_inset
27160
27161  port automatically saves the following registers:
27162 \end_layout
27163
27164 \begin_layout Itemize
27165 WREG
27166 \end_layout
27167
27168 \begin_layout Itemize
27169 STATUS
27170 \end_layout
27171
27172 \begin_layout Itemize
27173 BSR
27174 \end_layout
27175
27176 \begin_layout Itemize
27177 PROD (PRODL and PRODH)
27178 \end_layout
27179
27180 \begin_layout Itemize
27181 FSR0 (FSR0L and FSR0H)
27182 \end_layout
27183
27184 \begin_layout Standard
27185 These registers are restored upon return from the interrupt routine.
27186 \begin_inset Foot
27187 status open
27188
27189 \begin_layout Standard
27190 NOTE that when the _naked attribute is specified for an interrupt routine,
27191  then NO registers are stored or restored.
27192 \end_layout
27193
27194 \end_inset
27195
27196
27197 \end_layout
27198
27199 \begin_layout Subsection
27200 Generic Pointers
27201 \end_layout
27202
27203 \begin_layout Standard
27204 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27205  There are 3 types of generic pointers currently implemented data, code
27206  and eeprom pointers.
27207  They are differentiated by the value of the 7th and 6th bits of the upper
27208  byte:
27209 \end_layout
27210
27211 \begin_layout Standard
27212 \align center
27213 \begin_inset Tabular
27214 <lyxtabular version="3" rows="5" columns="5">
27215 <features>
27216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27217 <column alignment="center" valignment="top" width="0">
27218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27219 <column alignment="center" valignment="top" width="0">
27220 <column alignment="left" valignment="top" rightline="true" width="0">
27221 <row topline="true" bottomline="true">
27222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27223 \begin_inset Text
27224
27225 \begin_layout Standard
27226 pointer type
27227 \end_layout
27228
27229 \end_inset
27230 </cell>
27231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27232 \begin_inset Text
27233
27234 \begin_layout Standard
27235 7th bit
27236 \end_layout
27237
27238 \end_inset
27239 </cell>
27240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27241 \begin_inset Text
27242
27243 \begin_layout Standard
27244 6th bit
27245 \end_layout
27246
27247 \end_inset
27248 </cell>
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27250 \begin_inset Text
27251
27252 \begin_layout Standard
27253 rest of the pointer
27254 \end_layout
27255
27256 \end_inset
27257 </cell>
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27259 \begin_inset Text
27260
27261 \begin_layout Standard
27262 description
27263 \end_layout
27264
27265 \end_inset
27266 </cell>
27267 </row>
27268 <row topline="true" bottomline="true">
27269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27270 \begin_inset Text
27271
27272 \begin_layout Standard
27273 data 
27274 \end_layout
27275
27276 \end_inset
27277 </cell>
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27279 \begin_inset Text
27280
27281 \begin_layout Standard
27282 1
27283 \end_layout
27284
27285 \end_inset
27286 </cell>
27287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27288 \begin_inset Text
27289
27290 \begin_layout Standard
27291 0
27292 \end_layout
27293
27294 \end_inset
27295 </cell>
27296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27297 \begin_inset Text
27298
27299 \begin_layout Standard
27300
27301 \family typewriter
27302 \shape slanted
27303 \emph on
27304 uuuuuu uuuuxxxx xxxxxxxx
27305 \end_layout
27306
27307 \end_inset
27308 </cell>
27309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27310 \begin_inset Text
27311
27312 \begin_layout Standard
27313 a 12-bit data pointer in data RAM memory
27314 \end_layout
27315
27316 \end_inset
27317 </cell>
27318 </row>
27319 <row bottomline="true">
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27321 \begin_inset Text
27322
27323 \begin_layout Standard
27324 code
27325 \end_layout
27326
27327 \end_inset
27328 </cell>
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27330 \begin_inset Text
27331
27332 \begin_layout Standard
27333 0
27334 \end_layout
27335
27336 \end_inset
27337 </cell>
27338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27339 \begin_inset Text
27340
27341 \begin_layout Standard
27342 0
27343 \end_layout
27344
27345 \end_inset
27346 </cell>
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27348 \begin_inset Text
27349
27350 \begin_layout Standard
27351
27352 \family typewriter
27353 \shape slanted
27354 \emph on
27355 uxxxxx xxxxxxxx xxxxxxxx
27356 \end_layout
27357
27358 \end_inset
27359 </cell>
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27361 \begin_inset Text
27362
27363 \begin_layout Standard
27364 a 21-bit code pointer in FLASH memory
27365 \end_layout
27366
27367 \end_inset
27368 </cell>
27369 </row>
27370 <row bottomline="true">
27371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27372 \begin_inset Text
27373
27374 \begin_layout Standard
27375 eeprom
27376 \end_layout
27377
27378 \end_inset
27379 </cell>
27380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27381 \begin_inset Text
27382
27383 \begin_layout Standard
27384 0
27385 \end_layout
27386
27387 \end_inset
27388 </cell>
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27390 \begin_inset Text
27391
27392 \begin_layout Standard
27393 1
27394 \end_layout
27395
27396 \end_inset
27397 </cell>
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27399 \begin_inset Text
27400
27401 \begin_layout Standard
27402
27403 \family typewriter
27404 \shape slanted
27405 \emph on
27406 uuuuuu uuuuuuxx xxxxxxxx
27407 \end_layout
27408
27409 \end_inset
27410 </cell>
27411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27412 \begin_inset Text
27413
27414 \begin_layout Standard
27415 a 10-bit eeprom pointer in EEPROM memory
27416 \end_layout
27417
27418 \end_inset
27419 </cell>
27420 </row>
27421 <row bottomline="true">
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27423 \begin_inset Text
27424
27425 \begin_layout Standard
27426 (unimplemented)
27427 \end_layout
27428
27429 \end_inset
27430 </cell>
27431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27432 \begin_inset Text
27433
27434 \begin_layout Standard
27435 1
27436 \end_layout
27437
27438 \end_inset
27439 </cell>
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27441 \begin_inset Text
27442
27443 \begin_layout Standard
27444 1
27445 \end_layout
27446
27447 \end_inset
27448 </cell>
27449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27450 \begin_inset Text
27451
27452 \begin_layout Standard
27453
27454 \family typewriter
27455 \shape slanted
27456 \emph on
27457 xxxxxx xxxxxxxx xxxxxxxx
27458 \end_layout
27459
27460 \end_inset
27461 </cell>
27462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27463 \begin_inset Text
27464
27465 \begin_layout Standard
27466 unimplemented pointer type
27467 \end_layout
27468
27469 \end_inset
27470 </cell>
27471 </row>
27472 </lyxtabular>
27473
27474 \end_inset
27475
27476
27477 \end_layout
27478
27479 \begin_layout Standard
27480 Generic pointer are read and written with a set of library functions which
27481  read/write 1, 2, 3, 4 bytes.
27482 \end_layout
27483
27484 \begin_layout Subsection
27485 PIC16 C Libraries
27486 \end_layout
27487
27488 \begin_layout Subsubsection
27489 Standard I/O Streams
27490 \end_layout
27491
27492 \begin_layout Standard
27493 In the 
27494 \emph on
27495 stdio.h
27496 \emph default
27497  the type FILE is defined as:
27498 \end_layout
27499
27500 \begin_layout LyX-Code
27501 typedef char * FILE;
27502 \end_layout
27503
27504 \begin_layout Standard
27505 This type is the stream type implemented I/O in the PIC18F devices.
27506  Also the standard input and output streams are declared in stdio.h:
27507 \end_layout
27508
27509 \begin_layout LyX-Code
27510 extern FILE * stdin;
27511 \end_layout
27512
27513 \begin_layout LyX-Code
27514 extern FILE * stdout;
27515 \end_layout
27516
27517 \begin_layout Standard
27518 The FILE type is actually a generic pointer which defines one more type
27519  of generic pointers, the 
27520 \emph on
27521 stream 
27522 \emph default
27523 pointer.
27524  This new type has the format:
27525 \end_layout
27526
27527 \begin_layout Standard
27528 \align center
27529 \begin_inset Tabular
27530 <lyxtabular version="3" rows="2" columns="7">
27531 <features>
27532 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27533 <column alignment="center" valignment="top" width="0">
27534 <column alignment="center" valignment="top" leftline="true" width="0">
27535 <column alignment="center" valignment="top" leftline="true" width="0">
27536 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27537 <column alignment="center" valignment="top" width="0">
27538 <column alignment="left" valignment="top" rightline="true" width="0">
27539 <row topline="true" bottomline="true">
27540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27541 \begin_inset Text
27542
27543 \begin_layout Standard
27544 pointer type
27545 \end_layout
27546
27547 \end_inset
27548 </cell>
27549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27550 \begin_inset Text
27551
27552 \begin_layout Standard
27553 <7:6>
27554 \end_layout
27555
27556 \end_inset
27557 </cell>
27558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27559 \begin_inset Text
27560
27561 \begin_layout Standard
27562 <5>
27563 \end_layout
27564
27565 \end_inset
27566 </cell>
27567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27568 \begin_inset Text
27569
27570 \begin_layout Standard
27571 <4>
27572 \end_layout
27573
27574 \end_inset
27575 </cell>
27576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27577 \begin_inset Text
27578
27579 \begin_layout Standard
27580 <3:0>
27581 \end_layout
27582
27583 \end_inset
27584 </cell>
27585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27586 \begin_inset Text
27587
27588 \begin_layout Standard
27589 rest of the pointer
27590 \end_layout
27591
27592 \end_inset
27593 </cell>
27594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27595 \begin_inset Text
27596
27597 \begin_layout Standard
27598 descrption
27599 \end_layout
27600
27601 \end_inset
27602 </cell>
27603 </row>
27604 <row topline="true" bottomline="true">
27605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27606 \begin_inset Text
27607
27608 \begin_layout Standard
27609 stream
27610 \end_layout
27611
27612 \end_inset
27613 </cell>
27614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27615 \begin_inset Text
27616
27617 \begin_layout Standard
27618 00
27619 \end_layout
27620
27621 \end_inset
27622 </cell>
27623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27624 \begin_inset Text
27625
27626 \begin_layout Standard
27627 1
27628 \end_layout
27629
27630 \end_inset
27631 </cell>
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27633 \begin_inset Text
27634
27635 \begin_layout Standard
27636 0
27637 \end_layout
27638
27639 \end_inset
27640 </cell>
27641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27642 \begin_inset Text
27643
27644 \begin_layout Standard
27645 nnnn
27646 \end_layout
27647
27648 \end_inset
27649 </cell>
27650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27651 \begin_inset Text
27652
27653 \begin_layout Standard
27654
27655 \family typewriter
27656 \shape slanted
27657 \emph on
27658 uuuuuuuu uuuuuuuu
27659 \end_layout
27660
27661 \end_inset
27662 </cell>
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27664 \begin_inset Text
27665
27666 \begin_layout Standard
27667 upper byte high nubble is 0x2n, the rest are zeroes
27668 \end_layout
27669
27670 \end_inset
27671 </cell>
27672 </row>
27673 </lyxtabular>
27674
27675 \end_inset
27676
27677
27678 \end_layout
27679
27680 \begin_layout Standard
27681 Currently implemented there are 3 types of streams defined:
27682 \end_layout
27683
27684 \begin_layout Standard
27685 \align center
27686 \begin_inset Tabular
27687 <lyxtabular version="3" rows="4" columns="4">
27688 <features>
27689 <column alignment="center" valignment="top" leftline="true" width="0">
27690 <column alignment="center" valignment="top" leftline="true" width="0">
27691 <column alignment="center" valignment="top" leftline="true" width="0">
27692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27693 <row topline="true" bottomline="true">
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27695 \begin_inset Text
27696
27697 \begin_layout Standard
27698 stream type
27699 \end_layout
27700
27701 \end_inset
27702 </cell>
27703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27704 \begin_inset Text
27705
27706 \begin_layout Standard
27707 value
27708 \end_layout
27709
27710 \end_inset
27711 </cell>
27712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27713 \begin_inset Text
27714
27715 \begin_layout Standard
27716 module
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 </row>
27731 <row topline="true">
27732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27733 \begin_inset Text
27734
27735 \begin_layout Standard
27736 STREAM_USART
27737 \end_layout
27738
27739 \end_inset
27740 </cell>
27741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27742 \begin_inset Text
27743
27744 \begin_layout Standard
27745
27746 \family typewriter
27747 0x200000UL
27748 \end_layout
27749
27750 \end_inset
27751 </cell>
27752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27753 \begin_inset Text
27754
27755 \begin_layout Standard
27756 USART
27757 \end_layout
27758
27759 \end_inset
27760 </cell>
27761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27762 \begin_inset Text
27763
27764 \begin_layout Standard
27765 Writes/Reads characters via the USART peripheral
27766 \end_layout
27767
27768 \end_inset
27769 </cell>
27770 </row>
27771 <row topline="true">
27772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27773 \begin_inset Text
27774
27775 \begin_layout Standard
27776 STREAM_MSSP
27777 \end_layout
27778
27779 \end_inset
27780 </cell>
27781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27782 \begin_inset Text
27783
27784 \begin_layout Standard
27785
27786 \family typewriter
27787 0x210000UL
27788 \end_layout
27789
27790 \end_inset
27791 </cell>
27792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27793 \begin_inset Text
27794
27795 \begin_layout Standard
27796 MSSP
27797 \end_layout
27798
27799 \end_inset
27800 </cell>
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27802 \begin_inset Text
27803
27804 \begin_layout Standard
27805 Writes/Reads characters via the MSSP peripheral
27806 \end_layout
27807
27808 \end_inset
27809 </cell>
27810 </row>
27811 <row topline="true" bottomline="true">
27812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27813 \begin_inset Text
27814
27815 \begin_layout Standard
27816 STREAM_USER
27817 \end_layout
27818
27819 \end_inset
27820 </cell>
27821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27822 \begin_inset Text
27823
27824 \begin_layout Standard
27825
27826 \family typewriter
27827 0x2f0000UL
27828 \end_layout
27829
27830 \end_inset
27831 </cell>
27832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27833 \begin_inset Text
27834
27835 \begin_layout Standard
27836 (none)
27837 \end_layout
27838
27839 \end_inset
27840 </cell>
27841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27842 \begin_inset Text
27843
27844 \begin_layout Standard
27845 Writes/Reads characters via used defined functions
27846 \end_layout
27847
27848 \end_inset
27849 </cell>
27850 </row>
27851 </lyxtabular>
27852
27853 \end_inset
27854
27855
27856 \end_layout
27857
27858 \begin_layout Standard
27859 The stream identifiers are declared as macros in the stdio.h header.
27860 \end_layout
27861
27862 \begin_layout Standard
27863 In the libc library there exist the functions that are used to write to
27864  each of the above streams.
27865  These are
27866 \end_layout
27867
27868 \begin_layout Description
27869 _
27870 \begin_inset ERT
27871 status collapsed
27872
27873 \begin_layout Standard
27874
27875
27876 \backslash
27877 /
27878 \end_layout
27879
27880 \end_inset
27881
27882 _stream_usart_putchar writes a character at the USART stream
27883 \end_layout
27884
27885 \begin_layout Description
27886 _
27887 \begin_inset ERT
27888 status collapsed
27889
27890 \begin_layout Standard
27891
27892
27893 \backslash
27894 /
27895 \end_layout
27896
27897 \end_inset
27898
27899 _stream_mssp_putchar writes a character at the MSSP stream
27900 \end_layout
27901
27902 \begin_layout Description
27903 putchar dummy function.
27904  This writes a character to a user specified manner.
27905 \end_layout
27906
27907 \begin_layout Standard
27908 In order to increase performance 
27909 \emph on
27910 putchar 
27911 \emph default
27912 is declared in stdio.h as having its parameter in WREG (it has the wparam
27913  keyword).
27914  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27915  in a user-friendly way.
27916  
27917 \emph on
27918 arg
27919 \emph default
27920  is the name of the variable that holds the character to print.
27921  An example follows:
27922 \end_layout
27923
27924 \begin_layout LyX-Code
27925 #include <pic18fregs.h>
27926 \newline
27927 #include <stdio.h>
27928 \newline
27929
27930 \newline
27931 PUTCHAR( c )
27932 \end_layout
27933
27934 \begin_layout LyX-Code
27935 {
27936 \end_layout
27937
27938 \begin_layout LyX-Code
27939     PORTA = c;    /* dump character c to PORTA */
27940 \end_layout
27941
27942 \begin_layout LyX-Code
27943
27944 \newline
27945
27946 \newline
27947 void main(void)
27948 \end_layout
27949
27950 \begin_layout LyX-Code
27951 {
27952 \end_layout
27953
27954 \begin_layout LyX-Code
27955     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27956 \end_layout
27957
27958 \begin_layout LyX-Code
27959                               * by default to STREAM_USER */
27960 \end_layout
27961
27962 \begin_layout LyX-Code
27963     printf (
27964 \begin_inset Quotes sld
27965 \end_inset
27966
27967 This is a printf test
27968 \backslash
27969 n
27970 \begin_inset Quotes srd
27971 \end_inset
27972
27973 );
27974 \end_layout
27975
27976 \begin_layout LyX-Code
27977 }
27978 \end_layout
27979
27980 \begin_layout LyX-Code
27981
27982 \end_layout
27983
27984 \begin_layout Subsubsection
27985 Printing functions
27986 \end_layout
27987
27988 \begin_layout Standard
27989 PIC16 contains an implementation of the printf-family of functions.
27990  There exist the following functions:
27991 \end_layout
27992
27993 \begin_layout LyX-Code
27994 extern unsigned int sprintf(char *buf, char *fmt, ...);
27995 \end_layout
27996
27997 \begin_layout LyX-Code
27998 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27999 \end_layout
28000
28001 \begin_layout LyX-Code
28002
28003 \end_layout
28004
28005 \begin_layout LyX-Code
28006 extern unsigned int printf(char *fmt, ...);
28007 \end_layout
28008
28009 \begin_layout LyX-Code
28010 extern unsigned int vprintf(char *fmt, va_lista ap);
28011 \end_layout
28012
28013 \begin_layout LyX-Code
28014
28015 \end_layout
28016
28017 \begin_layout LyX-Code
28018 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28019 \end_layout
28020
28021 \begin_layout LyX-Code
28022 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28023 \end_layout
28024
28025 \begin_layout Standard
28026 For sprintf and vsprintf 
28027 \emph on
28028 buf 
28029 \emph default
28030 should normally be a data pointer where the resulting string will be placed.
28031  No range checking is done so the user should allocate the necessery buffer.
28032  For fprintf and vfprintf 
28033 \emph on
28034 fp
28035 \emph default
28036  should be a stream pointer (i.e.
28037  stdout, STREAM_MSSP, etc...).
28038 \end_layout
28039
28040 \begin_layout Subsubsection
28041 Signals
28042 \end_layout
28043
28044 \begin_layout Standard
28045 The PIC18F family of microcontrollers supports a number of interrupt sources.
28046  A list of these interrupts is shown in the following table:
28047 \end_layout
28048
28049 \begin_layout Standard
28050 \align center
28051 \begin_inset Tabular
28052 <lyxtabular version="3" rows="11" columns="4">
28053 <features>
28054 <column alignment="left" valignment="top" leftline="true" width="0">
28055 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28056 <column alignment="left" valignment="top" leftline="true" width="0">
28057 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28058 <row topline="true" bottomline="true">
28059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28060 \begin_inset Text
28061
28062 \begin_layout Standard
28063 signal name
28064 \end_layout
28065
28066 \end_inset
28067 </cell>
28068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28069 \begin_inset Text
28070
28071 \begin_layout Standard
28072 description
28073 \end_layout
28074
28075 \end_inset
28076 </cell>
28077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28078 \begin_inset Text
28079
28080 \begin_layout Standard
28081 signal name
28082 \end_layout
28083
28084 \end_inset
28085 </cell>
28086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28087 \begin_inset Text
28088
28089 \begin_layout Standard
28090 descritpion
28091 \end_layout
28092
28093 \end_inset
28094 </cell>
28095 </row>
28096 <row topline="true">
28097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28098 \begin_inset Text
28099
28100 \begin_layout Standard
28101 SIG_RB
28102 \end_layout
28103
28104 \end_inset
28105 </cell>
28106 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28107 \begin_inset Text
28108
28109 \begin_layout Standard
28110 PORTB change interrupt
28111 \end_layout
28112
28113 \end_inset
28114 </cell>
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28116 \begin_inset Text
28117
28118 \begin_layout Standard
28119 SIG_EE
28120 \end_layout
28121
28122 \end_inset
28123 </cell>
28124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28125 \begin_inset Text
28126
28127 \begin_layout Standard
28128 EEPROM/FLASH write complete interrupt
28129 \end_layout
28130
28131 \end_inset
28132 </cell>
28133 </row>
28134 <row topline="true">
28135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28136 \begin_inset Text
28137
28138 \begin_layout Standard
28139 SIG_INT0
28140 \end_layout
28141
28142 \end_inset
28143 </cell>
28144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28145 \begin_inset Text
28146
28147 \begin_layout Standard
28148 INT0 external interrupt
28149 \end_layout
28150
28151 \end_inset
28152 </cell>
28153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28154 \begin_inset Text
28155
28156 \begin_layout Standard
28157 SIG_BCOL
28158 \end_layout
28159
28160 \end_inset
28161 </cell>
28162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28163 \begin_inset Text
28164
28165 \begin_layout Standard
28166 Bus collision interrupt
28167 \end_layout
28168
28169 \end_inset
28170 </cell>
28171 </row>
28172 <row topline="true">
28173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28174 \begin_inset Text
28175
28176 \begin_layout Standard
28177 SIG_INT1
28178 \end_layout
28179
28180 \end_inset
28181 </cell>
28182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28183 \begin_inset Text
28184
28185 \begin_layout Standard
28186 INT1 external interrupt
28187 \end_layout
28188
28189 \end_inset
28190 </cell>
28191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28192 \begin_inset Text
28193
28194 \begin_layout Standard
28195 SIG_LVD
28196 \end_layout
28197
28198 \end_inset
28199 </cell>
28200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28201 \begin_inset Text
28202
28203 \begin_layout Standard
28204 Low voltage detect interrupt
28205 \end_layout
28206
28207 \end_inset
28208 </cell>
28209 </row>
28210 <row topline="true">
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28212 \begin_inset Text
28213
28214 \begin_layout Standard
28215 SIG_INT2
28216 \end_layout
28217
28218 \end_inset
28219 </cell>
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_inset Text
28222
28223 \begin_layout Standard
28224 INT2 external interrupt
28225 \end_layout
28226
28227 \end_inset
28228 </cell>
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28230 \begin_inset Text
28231
28232 \begin_layout Standard
28233 SIG_PSP
28234 \end_layout
28235
28236 \end_inset
28237 </cell>
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28239 \begin_inset Text
28240
28241 \begin_layout Standard
28242 Parallel slave port interrupt
28243 \end_layout
28244
28245 \end_inset
28246 </cell>
28247 </row>
28248 <row topline="true">
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28250 \begin_inset Text
28251
28252 \begin_layout Standard
28253 SIG_CCP1
28254 \end_layout
28255
28256 \end_inset
28257 </cell>
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28259 \begin_inset Text
28260
28261 \begin_layout Standard
28262 CCP1 module interrupt
28263 \end_layout
28264
28265 \end_inset
28266 </cell>
28267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28268 \begin_inset Text
28269
28270 \begin_layout Standard
28271 SIG_AD
28272 \end_layout
28273
28274 \end_inset
28275 </cell>
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28277 \begin_inset Text
28278
28279 \begin_layout Standard
28280 AD convertion complete interrupt
28281 \end_layout
28282
28283 \end_inset
28284 </cell>
28285 </row>
28286 <row topline="true">
28287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28288 \begin_inset Text
28289
28290 \begin_layout Standard
28291 SIG_CCP2
28292 \end_layout
28293
28294 \end_inset
28295 </cell>
28296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28297 \begin_inset Text
28298
28299 \begin_layout Standard
28300 CCP2 module interrupt
28301 \end_layout
28302
28303 \end_inset
28304 </cell>
28305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28306 \begin_inset Text
28307
28308 \begin_layout Standard
28309 SIG_RC
28310 \end_layout
28311
28312 \end_inset
28313 </cell>
28314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28315 \begin_inset Text
28316
28317 \begin_layout Standard
28318 USART receive interrupt
28319 \end_layout
28320
28321 \end_inset
28322 </cell>
28323 </row>
28324 <row topline="true">
28325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28326 \begin_inset Text
28327
28328 \begin_layout Standard
28329 SIG_TMR0
28330 \end_layout
28331
28332 \end_inset
28333 </cell>
28334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28335 \begin_inset Text
28336
28337 \begin_layout Standard
28338 TMR0 overflow interrupt
28339 \end_layout
28340
28341 \end_inset
28342 </cell>
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28344 \begin_inset Text
28345
28346 \begin_layout Standard
28347 SIG_TX
28348 \end_layout
28349
28350 \end_inset
28351 </cell>
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28353 \begin_inset Text
28354
28355 \begin_layout Standard
28356 USART transmit interrupt
28357 \end_layout
28358
28359 \end_inset
28360 </cell>
28361 </row>
28362 <row topline="true">
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28364 \begin_inset Text
28365
28366 \begin_layout Standard
28367 SIG_TMR1
28368 \end_layout
28369
28370 \end_inset
28371 </cell>
28372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28373 \begin_inset Text
28374
28375 \begin_layout Standard
28376 TMR1 overflow interrupt
28377 \end_layout
28378
28379 \end_inset
28380 </cell>
28381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28382 \begin_inset Text
28383
28384 \begin_layout Standard
28385 SIG_MSSP
28386 \end_layout
28387
28388 \end_inset
28389 </cell>
28390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28391 \begin_inset Text
28392
28393 \begin_layout Standard
28394 SSP receive/transmit interrupt
28395 \end_layout
28396
28397 \end_inset
28398 </cell>
28399 </row>
28400 <row topline="true">
28401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28402 \begin_inset Text
28403
28404 \begin_layout Standard
28405 SIG_TMR2
28406 \end_layout
28407
28408 \end_inset
28409 </cell>
28410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28411 \begin_inset Text
28412
28413 \begin_layout Standard
28414 TMR2 matches PR2 interrupt
28415 \end_layout
28416
28417 \end_inset
28418 </cell>
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28420 \begin_inset Text
28421
28422 \begin_layout Standard
28423
28424 \end_layout
28425
28426 \end_inset
28427 </cell>
28428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28429 \begin_inset Text
28430
28431 \begin_layout Standard
28432
28433 \end_layout
28434
28435 \end_inset
28436 </cell>
28437 </row>
28438 <row topline="true" bottomline="true">
28439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28440 \begin_inset Text
28441
28442 \begin_layout Standard
28443 SIG_TMR3
28444 \end_layout
28445
28446 \end_inset
28447 </cell>
28448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28449 \begin_inset Text
28450
28451 \begin_layout Standard
28452 TMR3 overflow interrupt
28453 \end_layout
28454
28455 \end_inset
28456 </cell>
28457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28458 \begin_inset Text
28459
28460 \begin_layout Standard
28461
28462 \end_layout
28463
28464 \end_inset
28465 </cell>
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28467 \begin_inset Text
28468
28469 \begin_layout Standard
28470
28471 \end_layout
28472
28473 \end_inset
28474 </cell>
28475 </row>
28476 </lyxtabular>
28477
28478 \end_inset
28479
28480
28481 \end_layout
28482
28483 \begin_layout Standard
28484 The prototypes for these names are defined in the header file 
28485 \emph on
28486 signal.h
28487 \emph default
28488  .
28489 \end_layout
28490
28491 \begin_layout Standard
28492 In order to simplify signal handling, a number of macros is provided:
28493 \end_layout
28494
28495 \begin_layout List
28496 \labelwidthstring 00.00.0000
28497 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28498  high priority interrupts.
28499  
28500 \emph on
28501 name
28502 \emph default
28503  is the function name to use.
28504 \end_layout
28505
28506 \begin_layout List
28507 \labelwidthstring 00.00.0000
28508 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28509  low priority interrupt.
28510  
28511 \emph on
28512 name
28513 \emph default
28514  is the function name to use.
28515 \end_layout
28516
28517 \begin_layout List
28518 \labelwidthstring 00.00.0000
28519 DEF_HANDLER(sig,handler) define a handler for signal 
28520 \emph on
28521 sig.
28522 \end_layout
28523
28524 \begin_layout List
28525 \labelwidthstring 00.00.0000
28526 END_DEF end the declaration of the dispatch table.
28527 \end_layout
28528
28529 \begin_layout Standard
28530 Additionally there are two more macros to simplify the declaration of the
28531  signal handler:
28532 \end_layout
28533
28534 \begin_layout List
28535 \labelwidthstring 00.00.0000
28536
28537 \series medium
28538 SIGHANDLER(handler) 
28539 \series default
28540 this declares the function prototype for the 
28541 \emph on
28542 handler
28543 \emph default
28544  function.
28545 \end_layout
28546
28547 \begin_layout List
28548 \labelwidthstring 00.00.0000
28549 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28550 \end_layout
28551
28552 \begin_layout Standard
28553 An example of using the macros above is shown below:
28554 \end_layout
28555
28556 \begin_layout LyX-Code
28557 #include <pic18fregs.h>
28558 \end_layout
28559
28560 \begin_layout LyX-Code
28561 #include <signal.h>
28562 \newline
28563
28564 \newline
28565 DEF_INTHIGH(high_int)
28566 \end_layout
28567
28568 \begin_layout LyX-Code
28569 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28570 \end_layout
28571
28572 \begin_layout LyX-Code
28573 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28574 \end_layout
28575
28576 \begin_layout LyX-Code
28577 END_DEF
28578 \newline
28579
28580 \newline
28581 SIGHANDLER(_tmr0_handler)
28582 \end_layout
28583
28584 \begin_layout LyX-Code
28585 {
28586 \end_layout
28587
28588 \begin_layout LyX-Code
28589   /* action to be taken when timer 0 overflows */
28590 \end_layout
28591
28592 \begin_layout LyX-Code
28593 }
28594 \newline
28595
28596 \newline
28597 SIGHANDLERNAKED(_bcol_handler)
28598 \end_layout
28599
28600 \begin_layout LyX-Code
28601 {
28602 \end_layout
28603
28604 \begin_layout LyX-Code
28605   _asm
28606 \end_layout
28607
28608 \begin_layout LyX-Code
28609     /* action to be taken when bus collision occurs */
28610 \end_layout
28611
28612 \begin_layout LyX-Code
28613     retfie
28614 \end_layout
28615
28616 \begin_layout LyX-Code
28617  _endasm;
28618 \end_layout
28619
28620 \begin_layout LyX-Code
28621 }
28622 \end_layout
28623
28624 \begin_layout Standard
28625
28626 \series bold
28627 NOTES:
28628 \series default
28629  Special care should be taken when using the above scheme:
28630 \end_layout
28631
28632 \begin_layout Itemize
28633 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28634 \end_layout
28635
28636 \begin_layout Itemize
28637 when declaring SIGHANDLERNAKED handler never forget to use 
28638 \emph on
28639 retfie
28640 \emph default
28641  for proper returning.
28642 \end_layout
28643
28644 \begin_layout Subsection
28645 PIC16 Port -- Tips
28646 \end_layout
28647
28648 \begin_layout Standard
28649 Here you can find some general tips for compiling programs with SDCC/pic16.
28650 \end_layout
28651
28652 \begin_layout Subsubsection
28653 Stack size
28654 \end_layout
28655
28656 \begin_layout Standard
28657 The default stack
28658 \begin_inset LatexCommand \index{PIC16!stack}
28659
28660 \end_inset
28661
28662  size (that is 64 bytes) probably is enough for many programs.
28663  One must take care that when there are many levels of function nesting,
28664  or there is excessive usage of stack, its size should be extended.
28665  An example of such a case is the printf/sprintf family of functions.
28666  If you encounter problems like not being able to print integers, then you
28667  need to set the stack size around the maximum (256 for small stack model).
28668  The following diagram shows what happens when calling printf to print an
28669  integer:
28670 \end_layout
28671
28672 \begin_layout LyX-Code
28673 printf () --> ltoa () --> ultoa () --> divschar ()
28674 \end_layout
28675
28676 \begin_layout Standard
28677 It is should be understood that stack is easily consumed when calling complicate
28678 d functions.
28679  Using command line arguments like -
28680 \begin_inset ERT
28681 status collapsed
28682
28683 \begin_layout Standard
28684
28685
28686 \backslash
28687 /
28688 \end_layout
28689
28690 \end_inset
28691
28692 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28693  stack frames.
28694  Other ways to reduce stack usage may exist.
28695 \end_layout
28696
28697 \begin_layout Subsection
28698 Known Bugs
28699 \end_layout
28700
28701 \begin_layout Standard
28702 The PIC16 Port currently does not pass SDCC's regression test
28703 \begin_inset LatexCommand \index{Regression test (PIC16)}
28704
28705 \end_inset
28706
28707  suite (see section 
28708 \begin_inset LatexCommand \ref{sec:Quality-control}
28709
28710 \end_inset
28711
28712 ) and thus the snapshot build regression tests for the PIC16 target are
28713  currently disabled for all hosts
28714 \emph on
28715 .
28716 \end_layout
28717
28718 \begin_layout Chapter
28719 Debugging
28720 \end_layout
28721
28722 \begin_layout Standard
28723 There are several approaches to debugging your code.
28724  This chapter is meant to show your options and to give detail on some of
28725  them:
28726 \newline
28727
28728 \newline
28729 When writing your code:
28730 \end_layout
28731
28732 \begin_layout Itemize
28733 write your code with debugging in mind (avoid duplicating code, put conceptually
28734  similar variables into structs, use structured code, have strategic points
28735  within your code where all variables are consistent, ...)
28736 \end_layout
28737
28738 \begin_layout Itemize
28739 run a syntax-checking tool like splint
28740 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28741
28742 \end_inset
28743
28744
28745 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28746
28747 \end_inset
28748
28749  (see -
28750 \begin_inset ERT
28751 status collapsed
28752
28753 \begin_layout Standard
28754
28755
28756 \backslash
28757 /
28758 \end_layout
28759
28760 \end_inset
28761
28762 -more-pedantic 
28763 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28764
28765 \end_inset
28766
28767 ) over the code.
28768 \end_layout
28769
28770 \begin_layout Itemize
28771 for the high level code use a C-compiler (like f.e.
28772  GCC) to compile run and debug the code on your host.
28773  See (see -
28774 \begin_inset ERT
28775 status collapsed
28776
28777 \begin_layout Standard
28778
28779
28780 \backslash
28781 /
28782 \end_layout
28783
28784 \end_inset
28785
28786 -more-pedantic 
28787 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28788
28789 \end_inset
28790
28791 ) on how to handle syntax extensions like __xdata, __at(), ...
28792  
28793 \end_layout
28794
28795 \begin_layout Itemize
28796 use another C-compiler to compile code for your target.
28797  Always an option but not recommended:) And not very likely to help you.
28798  If you seriously consider walking this path you should at least occasionally
28799  check portability of your code.
28800  Most commercial compiler vendors will offer an evaluation version so you
28801  can test compile your code or snippets of your code.
28802 \end_layout
28803
28804 \begin_layout Standard
28805 Debugging on a simulator:
28806 \end_layout
28807
28808 \begin_layout Itemize
28809 there is a separate section about SDCDB (section 
28810 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28811
28812 \end_inset
28813
28814 ) below.
28815 \end_layout
28816
28817 \begin_layout Itemize
28818 or (8051 specific) use a freeware/commercial simulator which interfaces
28819  to the AOMF
28820 \begin_inset LatexCommand \index{AOMF, AOMF51}
28821
28822 \end_inset
28823
28824  file (see 
28825 \begin_inset LatexCommand \ref{OMF file}
28826
28827 \end_inset
28828
28829 ) optionally generated by SDCC.
28830 \end_layout
28831
28832 \begin_layout Standard
28833 Debugging On-target: 
28834 \end_layout
28835
28836 \begin_layout Itemize
28837 use a MCU port pin to serially output debug data to the RS232 port of your
28838  host.
28839  You'll probably want some level shifting device typically involving a MAX232
28840  or similar IC.
28841  If the hardware serial port of the MCU is not available search for 'Software
28842  UART' in your favourite search machine.
28843 \end_layout
28844
28845 \begin_layout Itemize
28846 use an on-target monitor.
28847  In this context a monitor is a small program which usually accepts commands
28848  via a serial line and allows to set program counter, to single step through
28849  a program and read/write memory locations.
28850  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28851  
28852 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28853
28854 \end_inset
28855
28856 ).
28857 \end_layout
28858
28859 \begin_layout Itemize
28860 toggle MCU port pins at strategic points within your code and use an oscilloscop
28861 e.
28862  A 
28863 \emph on
28864 digital oscilloscope
28865 \emph default
28866
28867 \begin_inset LatexCommand \index{Oscilloscope}
28868
28869 \end_inset
28870
28871  with deep trace memory is really helpful especially if you have to debug
28872  a realtime application.
28873  If you need to monitor more pins than your oscilloscope provides you can
28874  sometimes get away with a small R-2R network.
28875  On a single channel oscilloscope you could f.e.
28876  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28877 k
28878 \begin_inset Formula $\Omega$
28879 \end_inset
28880
28881  resistor and the other one by a 5\InsetSpace ~
28882 k
28883 \begin_inset Formula $\Omega$
28884 \end_inset
28885
28886  resistor to the oscilloscope probe (check output drive capability of the
28887  pins you want to monitor).
28888  If you need to monitor many more pins a 
28889 \emph on
28890 logic analyzer
28891 \emph default
28892  will be handy.
28893 \end_layout
28894
28895 \begin_layout Itemize
28896 use an ICE (
28897 \emph on
28898 i
28899 \emph default
28900
28901 \emph on
28902 c
28903 \emph default
28904 ircuit 
28905 \emph on
28906 e
28907 \emph default
28908 mulator
28909 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28910
28911 \end_inset
28912
28913 ).
28914  Usually very expensive.
28915  And very nice to have too.
28916  And usually locks you (for years...) to the devices the ICE can emulate.
28917  
28918 \end_layout
28919
28920 \begin_layout Itemize
28921 use a remote debugger.
28922  In most 8-bit systems the symbol information is not available on the target,
28923  and a complete debugger is too bulky for the target system.
28924  Therefore usually a debugger on the host system connects to an on-target
28925  debugging stub which accepts only primitive commands.
28926  
28927 \newline
28928 Terms to enter into your favourite search engine could be 'remote debugging',
28929  'gdb stub' or 'inferior debugger'.
28930  (is there one?)
28931 \end_layout
28932
28933 \begin_layout Itemize
28934 use an on target hardware debugger.
28935  Some of the more modern MCUs include hardware support for setting break
28936  points and monitoring/changing variables by using dedicated hardware pins.
28937  This facility doesn't require additional code to run on the target and
28938  
28939 \emph on
28940 usually
28941 \emph default
28942  doesn't affect runtime behaviour until a breakpoint is hit.
28943  For the mcs51 most hardware debuggers use the AOMF
28944 \begin_inset LatexCommand \index{AOMF, AOMF51}
28945
28946 \end_inset
28947
28948  file (see 
28949 \begin_inset LatexCommand \ref{OMF file}
28950
28951 \end_inset
28952
28953 ) as input file.
28954  
28955 \end_layout
28956
28957 \begin_layout Standard
28958 Last not least:
28959 \end_layout
28960
28961 \begin_layout Itemize
28962 if you are not familiar with any of the following terms you're likely to
28963  run into problems rather sooner than later: 
28964 \emph on
28965 volatile
28966 \emph default
28967
28968 \emph on
28969 atomic
28970 \emph default
28971
28972 \emph on
28973 memory map
28974 \emph default
28975
28976 \emph on
28977 overlay
28978 \emph default
28979 .
28980  As an embedded programmer you 
28981 \emph on
28982 have
28983 \emph default
28984  to know them so why not look them up 
28985 \emph on
28986 before
28987 \emph default
28988  you have problems?)
28989 \end_layout
28990
28991 \begin_layout Itemize
28992 tell someone else about your problem (actually this is a surprisingly effective
28993  means to hunt down the bug even if the listener is not familiar with your
28994  environment).
28995  As 'failure to communicate' is probably one of the job-induced deformations
28996  of an embedded programmer this is highly encouraged.
28997 \end_layout
28998
28999 \begin_layout Section
29000 Debugging with SDCDB
29001 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29002
29003 \end_inset
29004
29005
29006 \begin_inset LatexCommand \index{SDCDB (debugger)}
29007
29008 \end_inset
29009
29010  
29011 \end_layout
29012
29013 \begin_layout Standard
29014 SDCC is distributed with a source level debugger
29015 \begin_inset LatexCommand \index{Debugger}
29016
29017 \end_inset
29018
29019 .
29020  The debugger uses a command line interface, the command repertoire of the
29021  debugger has been kept as close to gdb
29022 \begin_inset LatexCommand \index{gdb}
29023
29024 \end_inset
29025
29026  (the GNU debugger) as possible.
29027  The configuration and build process is part of the standard compiler installati
29028 on, which also builds and installs the debugger in the target directory
29029  specified during configuration.
29030  The debugger allows you debug BOTH at the C source and at the ASM source
29031  level.
29032 \end_layout
29033
29034 \begin_layout Subsection
29035 Compiling for Debugging
29036 \end_layout
29037
29038 \begin_layout Standard
29039 The -
29040 \begin_inset ERT
29041 status collapsed
29042
29043 \begin_layout Standard
29044
29045
29046 \backslash
29047 /
29048 \end_layout
29049
29050 \end_inset
29051
29052 -debug
29053 \begin_inset LatexCommand \index{-\/-debug}
29054
29055 \end_inset
29056
29057  option must be specified for all files for which debug information is to
29058  be generated.
29059  The compiler generates a .adb file for each of these files.
29060  The linker creates the .cdb
29061 \begin_inset LatexCommand \index{<file>.cdb}
29062
29063 \end_inset
29064
29065  file from the .adb
29066 \begin_inset LatexCommand \index{<file>.adb}
29067
29068 \end_inset
29069
29070  files and the address information.
29071  This .cdb is used by the debugger.
29072 \end_layout
29073
29074 \begin_layout Subsection
29075 How the Debugger Works
29076 \end_layout
29077
29078 \begin_layout Standard
29079 When the -
29080 \begin_inset ERT
29081 status collapsed
29082
29083 \begin_layout Standard
29084
29085
29086 \backslash
29087 /
29088 \end_layout
29089
29090 \end_inset
29091
29092 -debug option is specified the compiler generates extra symbol information
29093  some of which are put into the assembler source and some are put into the
29094  .adb file.
29095  Then the linker creates the .cdb file from the individual .adb files with
29096  the address information for the symbols.
29097  The debugger reads the symbolic information generated by the compiler &
29098  the address information generated by the linker.
29099  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29100  execution is controlled by the debugger.
29101  When a command is issued for the debugger, it translates it into appropriate
29102  commands for the simulator.
29103  (Currently SDCDM only connects to the simulator but 
29104 \emph on
29105 newcdb
29106 \emph default
29107  at 
29108 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29109
29110 \end_inset
29111
29112  is an effort to connect directly to the hardware.) 
29113 \end_layout
29114
29115 \begin_layout Subsection
29116 Starting the Debugger SDCDB
29117 \end_layout
29118
29119 \begin_layout Standard
29120 The debugger can be started using the following command line.
29121  (Assume the file you are debugging has the file name foo).
29122 \newline
29123
29124 \newline
29125
29126 \family sans
29127 \series bold
29128 sdcdb foo
29129 \newline
29130
29131 \family default
29132 \series default
29133
29134 \newline
29135 The debugger will look for the following files.
29136 \end_layout
29137
29138 \begin_layout Itemize
29139 foo.c - the source file.
29140 \end_layout
29141
29142 \begin_layout Itemize
29143 foo.cdb - the debugger symbol information file.
29144 \end_layout
29145
29146 \begin_layout Itemize
29147 foo.ihx - the Intel hex format
29148 \begin_inset LatexCommand \index{Intel hex format}
29149
29150 \end_inset
29151
29152  object file.
29153 \end_layout
29154
29155 \begin_layout Subsection
29156 SDCDB Command Line Options
29157 \end_layout
29158
29159 \begin_layout Itemize
29160 -
29161 \begin_inset ERT
29162 status collapsed
29163
29164 \begin_layout Standard
29165
29166
29167 \backslash
29168 /
29169 \end_layout
29170
29171 \end_inset
29172
29173 -directory=<source file directory> this option can used to specify the directory
29174  search list.
29175  The debugger will look into the directory list specified for source, cdb
29176  & ihx files.
29177  The items in the directory list must be separated by ':', e.g.
29178  if the source files can be in the directories /home/src1 and /home/src2,
29179  the -
29180 \begin_inset ERT
29181 status collapsed
29182
29183 \begin_layout Standard
29184
29185
29186 \backslash
29187 /
29188 \end_layout
29189
29190 \end_inset
29191
29192 -directory option should be -
29193 \begin_inset ERT
29194 status collapsed
29195
29196 \begin_layout Standard
29197
29198
29199 \backslash
29200 /
29201 \end_layout
29202
29203 \end_inset
29204
29205 -directory=/home/src1:/home/src2.
29206  Note there can be no spaces in the option.
29207  
29208 \end_layout
29209
29210 \begin_layout Itemize
29211 -cd <directory> - change to the <directory>.
29212 \end_layout
29213
29214 \begin_layout Itemize
29215 -fullname - used by GUI front ends.
29216 \end_layout
29217
29218 \begin_layout Itemize
29219 -cpu <cpu-type> - this argument is passed to the simulator please see the
29220  simulator docs for details.
29221 \end_layout
29222
29223 \begin_layout Itemize
29224 -X <Clock frequency > this options is passed to the simulator please see
29225  the simulator docs for details.
29226 \end_layout
29227
29228 \begin_layout Itemize
29229 -s <serial port file> passed to simulator see the simulator docs for details.
29230 \end_layout
29231
29232 \begin_layout Itemize
29233 -S <serial in,out> passed to simulator see the simulator docs for details.
29234 \end_layout
29235
29236 \begin_layout Itemize
29237 -k <port number> passed to simulator see the simulator docs for details.
29238 \end_layout
29239
29240 \begin_layout Subsection
29241 SDCDB Debugger Commands
29242 \end_layout
29243
29244 \begin_layout Standard
29245 As mentioned earlier the command interface for the debugger has been deliberatel
29246 y kept as close the GNU debugger gdb, as possible.
29247  This will help the integration with existing graphical user interfaces
29248  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29249  If you use a graphical user interface for the debugger you can skip this
29250  section.
29251 \end_layout
29252
29253 \begin_layout Subsubsection*
29254 break [line | file:line | function | file:function]
29255 \end_layout
29256
29257 \begin_layout Standard
29258 Set breakpoint at specified line or function:
29259 \newline
29260
29261 \newline
29262
29263 \family sans
29264 \series bold
29265 sdcdb>break 100 
29266 \newline
29267 sdcdb>break foo.c:100
29268 \newline
29269 sdcdb>break funcfoo
29270 \newline
29271 sdcdb>break foo.c:funcfoo
29272 \end_layout
29273
29274 \begin_layout Subsubsection*
29275 clear [line | file:line | function | file:function ]
29276 \end_layout
29277
29278 \begin_layout Standard
29279 Clear breakpoint at specified line or function:
29280 \newline
29281
29282 \newline
29283
29284 \family sans
29285 \series bold
29286 sdcdb>clear 100
29287 \newline
29288 sdcdb>clear foo.c:100
29289 \newline
29290 sdcdb>clear funcfoo
29291 \newline
29292 sdcdb>clear foo.c:funcfoo
29293 \end_layout
29294
29295 \begin_layout Subsubsection*
29296 continue
29297 \end_layout
29298
29299 \begin_layout Standard
29300 Continue program being debugged, after breakpoint.
29301 \end_layout
29302
29303 \begin_layout Subsubsection*
29304 finish
29305 \end_layout
29306
29307 \begin_layout Standard
29308 Execute till the end of the current function.
29309 \end_layout
29310
29311 \begin_layout Subsubsection*
29312 delete [n]
29313 \end_layout
29314
29315 \begin_layout Standard
29316 Delete breakpoint number 'n'.
29317  If used without any option clear ALL user defined break points.
29318 \end_layout
29319
29320 \begin_layout Subsubsection*
29321 info [break | stack | frame | registers ]
29322 \end_layout
29323
29324 \begin_layout Itemize
29325 info break - list all breakpoints
29326 \end_layout
29327
29328 \begin_layout Itemize
29329 info stack - show the function call stack.
29330 \end_layout
29331
29332 \begin_layout Itemize
29333 info frame - show information about the current execution frame.
29334 \end_layout
29335
29336 \begin_layout Itemize
29337 info registers - show content of all registers.
29338 \end_layout
29339
29340 \begin_layout Subsubsection*
29341 step
29342 \end_layout
29343
29344 \begin_layout Standard
29345 Step program until it reaches a different source line.
29346  Note: pressing <return> repeats the last command.
29347 \end_layout
29348
29349 \begin_layout Subsubsection*
29350 next
29351 \end_layout
29352
29353 \begin_layout Standard
29354 Step program, proceeding through subroutine calls.
29355 \end_layout
29356
29357 \begin_layout Subsubsection*
29358 run
29359 \end_layout
29360
29361 \begin_layout Standard
29362 Start debugged program.
29363 \end_layout
29364
29365 \begin_layout Subsubsection*
29366 ptype variable 
29367 \end_layout
29368
29369 \begin_layout Standard
29370 Print type information of the variable.
29371 \end_layout
29372
29373 \begin_layout Subsubsection*
29374 print variable
29375 \end_layout
29376
29377 \begin_layout Standard
29378 print value of variable.
29379 \end_layout
29380
29381 \begin_layout Subsubsection*
29382 file filename
29383 \end_layout
29384
29385 \begin_layout Standard
29386 load the given file name.
29387  Note this is an alternate method of loading file for debugging.
29388 \end_layout
29389
29390 \begin_layout Subsubsection*
29391 frame
29392 \end_layout
29393
29394 \begin_layout Standard
29395 print information about current frame.
29396 \end_layout
29397
29398 \begin_layout Subsubsection*
29399 set srcmode
29400 \end_layout
29401
29402 \begin_layout Standard
29403 Toggle between C source & assembly source.
29404 \end_layout
29405
29406 \begin_layout Subsubsection*
29407 ! simulator command
29408 \end_layout
29409
29410 \begin_layout Standard
29411 Send the string following '!' to the simulator, the simulator response is
29412  displayed.
29413  Note the debugger does not interpret the command being sent to the simulator,
29414  so if a command like 'go' is sent the debugger can loose its execution
29415  context and may display incorrect values.
29416 \end_layout
29417
29418 \begin_layout Subsubsection*
29419 quit
29420 \end_layout
29421
29422 \begin_layout Standard
29423 "Watch me now.
29424  Iam going Down.
29425  My name is Bobby Brown"
29426 \end_layout
29427
29428 \begin_layout Subsection
29429 Interfacing SDCDB with DDD
29430 \end_layout
29431
29432 \begin_layout Standard
29433 \begin_inset Note Note
29434 status collapsed
29435
29436 \begin_layout Standard
29437 The screenshot was converted from png to eps with: 
29438 \begin_inset Quotes sld
29439 \end_inset
29440
29441 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29442 \begin_inset Quotes srd
29443 \end_inset
29444
29445  which produces a pretty compact eps file which is free from compression
29446  artifacts.
29447 \end_layout
29448
29449 \begin_layout Standard
29450 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29451  as this broke the build system on Sourceforge (pdf-file was broken.
29452  pdflatex does not accept eps files).
29453 \end_layout
29454
29455 \end_inset
29456
29457
29458 \end_layout
29459
29460 \begin_layout Standard
29461 The 
29462 \emph on
29463 p
29464 \emph default
29465 ortable 
29466 \emph on
29467 n
29468 \emph default
29469 etwork 
29470 \emph on
29471 g
29472 \emph default
29473 raphics File 
29474 \size footnotesize
29475
29476 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29477
29478 \end_inset
29479
29480
29481 \size default
29482  shows a screenshot of a debugging session with DDD
29483 \begin_inset LatexCommand \index{DDD (debugger)}
29484
29485 \end_inset
29486
29487  (Unix only) on a simulated 8032.
29488  The debugging session might not run as smoothly as the screenshot suggests.
29489  The debugger allows setting of breakpoints, displaying and changing variables,
29490  single stepping through C and assembler code.
29491  
29492 \newline
29493 The source was compiled with 
29494 \family sans
29495 \series bold
29496
29497 \newline
29498
29499 \newline
29500 sdcc -
29501 \family default
29502 \series default
29503
29504 \begin_inset ERT
29505 status collapsed
29506
29507 \begin_layout Standard
29508
29509
29510 \backslash
29511 /
29512 \end_layout
29513
29514 \end_inset
29515
29516
29517 \family sans
29518 \series bold
29519 -debug ddd_example.c
29520 \family default
29521 \series default
29522  
29523 \family sans
29524 \series bold
29525
29526 \newline
29527
29528 \family default
29529 \series default
29530
29531 \newline
29532 and DDD was invoked with 
29533 \family sans
29534 \series bold
29535
29536 \newline
29537
29538 \newline
29539 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29540 \end_layout
29541
29542 \begin_layout Standard
29543 \begin_inset Note Note
29544 status open
29545
29546 \begin_layout Standard
29547 Check that the double quotes or an apostroph within the command line survive
29548  the LyX tool chain.
29549  Previously the apostrophs got slanted in the PDF output so a cut and paste
29550  did not work.
29551 \end_layout
29552
29553 \end_inset
29554
29555
29556 \end_layout
29557
29558 \begin_layout Subsection
29559 Interfacing SDCDB with XEmacs
29560 \begin_inset LatexCommand \index{XEmacs}
29561
29562 \end_inset
29563
29564
29565 \begin_inset LatexCommand \index{Emacs}
29566
29567 \end_inset
29568
29569
29570 \end_layout
29571
29572 \begin_layout Standard
29573 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29574  sdcdb.el and sdcdbsrc.el.
29575  These two files can be found in the $(prefix)/bin directory after the installat
29576 ion is complete.
29577  These files need to be loaded into XEmacs for the interface to work.
29578  This can be done at XEmacs startup time by inserting the following into
29579  your '.xemacs' file (which can be found in your HOME directory): 
29580 \newline
29581
29582 \newline
29583
29584 \family typewriter
29585 (load-file sdcdbsrc.el) 
29586 \family default
29587
29588 \newline
29589
29590 \newline
29591 .xemacs is a lisp file so the () around the command is REQUIRED.
29592  The files can also be loaded dynamically while XEmacs is running, set the
29593  environment variable 'EMACSLOADPATH' to the installation bin directory
29594  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29595  To start the interface enter the following command: 
29596 \newline
29597
29598 \newline
29599
29600 \family sans
29601 \series bold
29602 ESC-x sdcdbsrc
29603 \family default
29604 \series default
29605
29606 \newline
29607
29608 \newline
29609 You will prompted to enter the file name to be debugged.
29610  
29611 \newline
29612
29613 \newline
29614 The command line options that are passed to the simulator directly are
29615  bound to default values in the file sdcdbsrc.el.
29616  The variables are listed below, these values maybe changed as required.
29617 \end_layout
29618
29619 \begin_layout Itemize
29620 sdcdbsrc-cpu-type '51
29621 \end_layout
29622
29623 \begin_layout Itemize
29624 sdcdbsrc-frequency '11059200
29625 \end_layout
29626
29627 \begin_layout Itemize
29628 sdcdbsrc-serial nil
29629 \end_layout
29630
29631 \begin_layout Standard
29632 The following is a list of key mapping for the debugger interface.
29633 \end_layout
29634
29635 \begin_layout Standard
29636 \InsetSpace ~
29637
29638 \family typewriter
29639
29640 \newline
29641 ;;\InsetSpace ~
29642 Current Listing :: 
29643 \newline
29644 ;;key\InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 \InsetSpace ~
29658 binding\InsetSpace ~
29659 \InsetSpace ~
29660 \InsetSpace ~
29661 \InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 \InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 Comment 
29681 \newline
29682 ;;---\InsetSpace ~
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 -------
29719 \newline
29720 ;; 
29721 \newline
29722 ;;\InsetSpace ~
29723 n\InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 \InsetSpace ~
29732 \InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 sdcdb-next-fro
29739 m-src\InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 SDCDB next command 
29750 \newline
29751 ;;\InsetSpace ~
29752 b\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 sdcdb-back-from-src\InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 SDCDB back command 
29778 \newline
29779 ;;\InsetSpace ~
29780 c\InsetSpace ~
29781 \InsetSpace ~
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 sdcdb-cont-f
29796 rom-src\InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 SDCDB continue command
29807 \newline
29808 ;;\InsetSpace ~
29809 s\InsetSpace ~
29810 \InsetSpace ~
29811 \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 sdcdb-step-from-src\InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 SDCDB step command 
29835 \newline
29836 ;;\InsetSpace ~
29837 ?\InsetSpace ~
29838 \InsetSpace ~
29839 \InsetSpace ~
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 sdcdb-w
29853 hatis-c-sexp\InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 SDCDB ptypecommand for data at 
29864 \newline
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 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \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 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 buffer point 
29913 \newline
29914 ;;\InsetSpace ~
29915 x\InsetSpace ~
29916 \InsetSpace ~
29917 \InsetSpace ~
29918 \InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 sdcdbsrc-delete\InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 SDCD
29945 B Delete all breakpoints if no arg 
29946 \newline
29947 ;;\InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 \InsetSpace ~
29975 \InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 \InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 given or delete arg (C-u arg x) 
29995 \newline
29996 ;;\InsetSpace ~
29997 m\InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 sdcdbsrc
30013 -frame\InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 SDCDB Display current frame if no arg, 
30029 \newline
30030 ;;\InsetSpace ~
30031 \InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \InsetSpace ~
30040 \InsetSpace ~
30041 \InsetSpace ~
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046 \InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 \InsetSpace ~
30055 \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 \InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 given or display frame arg
30078  
30079 \newline
30080 ;;\InsetSpace ~
30081 \InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 \InsetSpace ~
30093 \InsetSpace ~
30094 \InsetSpace ~
30095 \InsetSpace ~
30096 \InsetSpace ~
30097 \InsetSpace ~
30098 \InsetSpace ~
30099 \InsetSpace ~
30100 \InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104 \InsetSpace ~
30105 \InsetSpace ~
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109 \InsetSpace ~
30110 \InsetSpace ~
30111 \InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 \InsetSpace ~
30123 \InsetSpace ~
30124 \InsetSpace ~
30125 \InsetSpace ~
30126 \InsetSpace ~
30127 buffer point 
30128 \newline
30129 ;;\InsetSpace ~
30130 !\InsetSpace ~
30131 \InsetSpace ~
30132 \InsetSpace ~
30133 \InsetSpace ~
30134 \InsetSpace ~
30135 \InsetSpace ~
30136 \InsetSpace ~
30137 \InsetSpace ~
30138 \InsetSpace ~
30139 \InsetSpace ~
30140 \InsetSpace ~
30141 \InsetSpace ~
30142 \InsetSpace ~
30143 \InsetSpace ~
30144 \InsetSpace ~
30145 sdcdbsrc-goto-sdcdb\InsetSpace ~
30146 \InsetSpace ~
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150 \InsetSpace ~
30151 \InsetSpace ~
30152 \InsetSpace ~
30153 \InsetSpace ~
30154 \InsetSpace ~
30155 Goto the SDCDB output buffer 
30156 \newline
30157 ;;\InsetSpace ~
30158 p\InsetSpace ~
30159 \InsetSpace ~
30160 \InsetSpace ~
30161 \InsetSpace ~
30162 \InsetSpace ~
30163 \InsetSpace ~
30164 \InsetSpace ~
30165 \InsetSpace ~
30166 \InsetSpace ~
30167 \InsetSpace ~
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 \InsetSpace ~
30171 \InsetSpace ~
30172 \InsetSpace ~
30173 sdcdb-prin
30174 t-c-sexp\InsetSpace ~
30175 \InsetSpace ~
30176 \InsetSpace ~
30177 \InsetSpace ~
30178 \InsetSpace ~
30179 \InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 SDCDB print command for data at 
30186 \newline
30187 ;;\InsetSpace ~
30188 \InsetSpace ~
30189 \InsetSpace ~
30190 \InsetSpace ~
30191 \InsetSpace ~
30192 \InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 \InsetSpace ~
30199 \InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203 \InsetSpace ~
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 \InsetSpace ~
30208 \InsetSpace ~
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 \InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 \InsetSpace ~
30218 \InsetSpace ~
30219 \InsetSpace ~
30220 \InsetSpace ~
30221 \InsetSpace ~
30222 \InsetSpace ~
30223 \InsetSpace ~
30224 \InsetSpace ~
30225 \InsetSpace ~
30226 \InsetSpace ~
30227 \InsetSpace ~
30228 \InsetSpace ~
30229 \InsetSpace ~
30230 \InsetSpace ~
30231 \InsetSpace ~
30232 \InsetSpace ~
30233 \InsetSpace ~
30234 buffer point 
30235 \newline
30236 ;;\InsetSpace ~
30237 g\InsetSpace ~
30238 \InsetSpace ~
30239 \InsetSpace ~
30240 \InsetSpace ~
30241 \InsetSpace ~
30242 \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 sdcdbsrc-goto-sdcdb\InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256 \InsetSpace ~
30257 \InsetSpace ~
30258 \InsetSpace ~
30259 \InsetSpace ~
30260 \InsetSpace ~
30261 \InsetSpace ~
30262 Got
30263 o the SDCDB output buffer 
30264 \newline
30265 ;;\InsetSpace ~
30266 t\InsetSpace ~
30267 \InsetSpace ~
30268 \InsetSpace ~
30269 \InsetSpace ~
30270 \InsetSpace ~
30271 \InsetSpace ~
30272 \InsetSpace ~
30273 \InsetSpace ~
30274 \InsetSpace ~
30275 \InsetSpace ~
30276 \InsetSpace ~
30277 \InsetSpace ~
30278 \InsetSpace ~
30279 \InsetSpace ~
30280 \InsetSpace ~
30281 sdcdbsrc-mode\InsetSpace ~
30282 \InsetSpace ~
30283 \InsetSpace ~
30284 \InsetSpace ~
30285 \InsetSpace ~
30286 \InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 \InsetSpace ~
30293 \InsetSpace ~
30294 \InsetSpace ~
30295 \InsetSpace ~
30296 \InsetSpace ~
30297 Toggles Sdcdbsrc mode (turns it
30298  off) 
30299 \newline
30300 ;; 
30301 \newline
30302 ;;\InsetSpace ~
30303 C-c\InsetSpace ~
30304 C-f\InsetSpace ~
30305 \InsetSpace ~
30306 \InsetSpace ~
30307 \InsetSpace ~
30308 \InsetSpace ~
30309 \InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 \InsetSpace ~
30313 sdcdb-finish-from-src\InsetSpace ~
30314 \InsetSpace ~
30315 \InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 SDCDB finish command 
30322 \newline
30323 ;; 
30324 \newline
30325 ;;\InsetSpace ~
30326 C-x\InsetSpace ~
30327 SPC\InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 \InsetSpace ~
30332 \InsetSpace ~
30333 \InsetSpace ~
30334 \InsetSpace ~
30335 \InsetSpace ~
30336 sdcdb-brea
30337 k\InsetSpace ~
30338 \InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 \InsetSpace ~
30344 \InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 \InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 \InsetSpace ~
30351 \InsetSpace ~
30352 \InsetSpace ~
30353 \InsetSpace ~
30354 \InsetSpace ~
30355 Set break for line with point 
30356 \newline
30357 ;;\InsetSpace ~
30358 ESC\InsetSpace ~
30359 t\InsetSpace ~
30360 \InsetSpace ~
30361 \InsetSpace ~
30362 \InsetSpace ~
30363 \InsetSpace ~
30364 \InsetSpace ~
30365 \InsetSpace ~
30366 \InsetSpace ~
30367 \InsetSpace ~
30368 \InsetSpace ~
30369 \InsetSpace ~
30370 sdcdbsrc-mode\InsetSpace ~
30371 \InsetSpace ~
30372 \InsetSpace ~
30373 \InsetSpace ~
30374 \InsetSpace ~
30375 \InsetSpace ~
30376 \InsetSpace ~
30377 \InsetSpace ~
30378 \InsetSpace ~
30379 \InsetSpace ~
30380 \InsetSpace ~
30381 \InsetSpace ~
30382 \InsetSpace ~
30383 \InsetSpace ~
30384 \InsetSpace ~
30385 \InsetSpace ~
30386 Toggle Sdcdbsrc mode 
30387 \newline
30388 ;;\InsetSpace ~
30389 ESC\InsetSpace ~
30390 m\InsetSpace ~
30391 \InsetSpace ~
30392 \InsetSpace ~
30393 \InsetSpace ~
30394 \InsetSpace ~
30395 \InsetSpace ~
30396 \InsetSpace ~
30397 \InsetSpace ~
30398 \InsetSpace ~
30399 \InsetSpace ~
30400 \InsetSpace ~
30401 sdc
30402 dbsrc-srcmode\InsetSpace ~
30403 \InsetSpace ~
30404 \InsetSpace ~
30405 \InsetSpace ~
30406 \InsetSpace ~
30407 \InsetSpace ~
30408 \InsetSpace ~
30409 \InsetSpace ~
30410 \InsetSpace ~
30411 \InsetSpace ~
30412 \InsetSpace ~
30413 \InsetSpace ~
30414 \InsetSpace ~
30415 Toggle list mode 
30416 \newline
30417 ;; 
30418 \newline
30419
30420 \family default
30421
30422 \newpage
30423
30424 \end_layout
30425
30426 \begin_layout Chapter
30427 TIPS
30428 \end_layout
30429
30430 \begin_layout Standard
30431 Here are a few guidelines that will help the compiler generate more efficient
30432  code, some of the tips are specific to this compiler others are generally
30433  good programming practice.
30434 \end_layout
30435
30436 \begin_layout Itemize
30437 Use the smallest data type to represent your data-value.
30438  If it is known in advance that the value is going to be less than 256 then
30439  use an 'unsigned char' instead of a 'short' or 'int'.
30440  Please note, that ANSI C requires both signed and unsigned chars to be
30441  promoted to 'signed int'
30442 \begin_inset LatexCommand \index{promotion to signed int}
30443
30444 \end_inset
30445
30446
30447 \begin_inset Marginal
30448 status collapsed
30449
30450 \begin_layout Standard
30451
30452 \series bold
30453 \InsetSpace ~
30454 !
30455 \end_layout
30456
30457 \end_inset
30458
30459  before doing any operation.
30460  This promotion
30461 \begin_inset LatexCommand \index{type promotion}
30462
30463 \end_inset
30464
30465
30466 \begin_inset LatexCommand \label{type promotion}
30467
30468 \end_inset
30469
30470  can be omitted, if the result is the same.
30471  The effect of the promotion rules together with the sign-extension is often
30472  surprising:
30473 \end_layout
30474
30475 \begin_deeper
30476 \begin_layout Verse
30477
30478 \family typewriter
30479 unsigned char uc = 0xfe;
30480 \newline
30481 if (uc * uc < 0) /* this is true! */
30482 \newline
30483 {
30484 \newline
30485 \InsetSpace ~
30486 \InsetSpace ~
30487 \InsetSpace ~
30488 \InsetSpace ~
30489 ....
30490 \newline
30491 }
30492 \end_layout
30493
30494 \begin_layout Standard
30495
30496 \family typewriter
30497 uc * uc
30498 \family default
30499  is evaluated as 
30500 \family typewriter
30501 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30502 \family default
30503 .
30504  
30505 \newline
30506 Another one:
30507 \end_layout
30508
30509 \begin_layout Verse
30510
30511 \family typewriter
30512 (unsigned char) -12 / (signed char) -3 = ...
30513 \end_layout
30514
30515 \begin_layout Standard
30516 No, the result is not 4:
30517 \end_layout
30518
30519 \begin_layout Verse
30520
30521 \family typewriter
30522 (int) (unsigned char) -12 / (int) (signed char) -3 =
30523 \newline
30524 (int) (unsigned char)
30525  0xf4 / (int) (signed char) 0xfd =
30526 \newline
30527 (int) 0x00f4 / (int) 0xfffd =
30528 \newline
30529 (int) 0x00f4
30530  / (int) 0xfffd =
30531 \newline
30532 (int) 244 / (int) -3 =
30533 \newline
30534 (int) -81 = (int) 0xffaf;
30535 \end_layout
30536
30537 \begin_layout Standard
30538 Don't complain, that gcc gives you a different result.
30539  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30540  Therefore the results are different.
30541 \newline
30542 From 
30543 \begin_inset Quotes sld
30544 \end_inset
30545
30546 comp.lang.c FAQ
30547 \begin_inset Quotes srd
30548 \end_inset
30549
30550 :
30551 \end_layout
30552
30553 \begin_layout Quote
30554
30555 \emph on
30556 If well-defined overflow characteristics are important and negative values
30557  are not, or if you want to steer clear of sign-extension problems when
30558  manipulating bits or bytes, use one of the corresponding unsigned types.
30559  (Beware when mixing signed and unsigned values in expressions, though.)
30560 \newline
30561 Although
30562  character types (especially unsigned char) can be used as "tiny" integers,
30563  doing so is sometimes more trouble than it's worth, due to unpredictable
30564  sign extension and increased code size.
30565 \end_layout
30566
30567 \end_deeper
30568 \begin_layout Itemize
30569 Use unsigned when it is known in advance that the value is not going to
30570  be negative.
30571  This helps especially if you are doing division or multiplication, bit-shifting
30572  or are using an array index.
30573 \end_layout
30574
30575 \begin_layout Itemize
30576 NEVER jump into a LOOP.
30577 \end_layout
30578
30579 \begin_layout Itemize
30580 Declare the variables to be local
30581 \begin_inset LatexCommand \index{local variables}
30582
30583 \end_inset
30584
30585  whenever possible, especially loop control variables (induction).
30586 \end_layout
30587
30588 \begin_layout Itemize
30589 Have a look at the assembly listing to get a 
30590 \begin_inset Quotes sld
30591 \end_inset
30592
30593 feeling
30594 \begin_inset Quotes srd
30595 \end_inset
30596
30597  for the code generation.
30598 \end_layout
30599
30600 \begin_layout Section
30601 Porting code from or to other compilers
30602 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30603
30604 \end_inset
30605
30606
30607 \end_layout
30608
30609 \begin_layout Itemize
30610 check whether endianness of the compilers differs and adapt where needed.
30611 \end_layout
30612
30613 \begin_layout Itemize
30614 check the device specific header files
30615 \begin_inset LatexCommand \index{Header files}
30616
30617 \end_inset
30618
30619
30620 \begin_inset LatexCommand \index{Include files}
30621
30622 \end_inset
30623
30624  for compiler specific syntax.
30625  Eventually include the file <compiler.h
30626 \begin_inset LatexCommand \index{compiler.h (include file)}
30627
30628 \end_inset
30629
30630
30631 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30632
30633 \end_inset
30634
30635  to allow using common header files.
30636  (see f.e.
30637  cc2510fx.h 
30638 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30639
30640 \end_inset
30641
30642 ).
30643 \end_layout
30644
30645 \begin_layout Itemize
30646 check whether the startup code contains the correct initialization (watchdog,
30647  peripherals).
30648 \end_layout
30649
30650 \begin_layout Itemize
30651 check whether the sizes of short, int, long match.
30652 \end_layout
30653
30654 \begin_layout Itemize
30655 check if some 16 or 32 bit hardware registers require a specific addressing
30656  order (least significant or most significant byte first) and adapt if needed
30657  (
30658 \emph on
30659 first
30660 \emph default
30661  and 
30662 \emph on
30663 last
30664 \emph default
30665  relate to time and not to lower/upper memory location here, so this is
30666  
30667 \emph on
30668 not
30669 \emph default
30670  the same as endianness).
30671 \end_layout
30672
30673 \begin_layout Itemize
30674 check whether the keyword 
30675 \emph on
30676 volatile
30677 \emph default
30678  is used where needed.
30679  The compilers might differ in their optimization characteristics (as different
30680  versions of the same compiler might also use more clever optimizations
30681  this is good idea anyway).
30682  See section 
30683 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30684
30685 \end_inset
30686
30687 .
30688 \end_layout
30689
30690 \begin_layout Itemize
30691 check that the compilers are not told to supress warnings.
30692 \end_layout
30693
30694 \begin_layout Itemize
30695 check and convert compiler specific extensions (interrupts, memory areas,
30696  pragmas etc.).
30697 \end_layout
30698
30699 \begin_layout Itemize
30700 check for differences in type promotion.
30701  Especially check for math operations on 
30702 \family typewriter
30703 char
30704 \family default
30705  or 
30706 \family typewriter
30707 unsigned char
30708 \family default
30709  variables.
30710  For the sake of C99 compatibility SDCC will probably promote these to 
30711 \family typewriter
30712 int
30713 \family default
30714  more often than other compilers.
30715  Eventually insert explicit casts to 
30716 \family typewriter
30717 (char) 
30718 \family default
30719 or
30720 \family typewriter
30721  (unsigned char)
30722 \family default
30723 .
30724  Also check that the ~\InsetSpace ~
30725 operator
30726 \begin_inset LatexCommand \index{\~\/ Operator}
30727
30728 \end_inset
30729
30730  is not used on 
30731 \family typewriter
30732 bit
30733 \begin_inset LatexCommand \index{bit}
30734
30735 \end_inset
30736
30737
30738 \family default
30739  variables, use the !\InsetSpace ~
30740 operator instead.
30741  See sections 
30742 \begin_inset LatexCommand \ref{type promotion}
30743
30744 \end_inset
30745
30746  and 
30747 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30748
30749 \end_inset
30750
30751 .
30752 \end_layout
30753
30754 \begin_layout Itemize
30755 check the assembly code generated for interrupt routines (f.e.
30756  for calls to possibly non-reentrant library functions).
30757 \end_layout
30758
30759 \begin_layout Itemize
30760 check whether timing loops result in proper timing (or preferably consider
30761  a rewrite of the code with timer based delays instead).
30762 \end_layout
30763
30764 \begin_layout Itemize
30765 check for differences in printf parameters (some compilers push (va_arg
30766 \begin_inset LatexCommand \index{vararg, va\_arg}
30767
30768 \end_inset
30769
30770 ) char variables as 
30771 \family typewriter
30772 int
30773 \family default
30774  others push them as 
30775 \family typewriter
30776 char
30777 \family default
30778 .
30779  See section 
30780 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30781
30782 \end_inset
30783
30784 ).
30785 \end_layout
30786
30787 \begin_layout Itemize
30788 check the resulting memory map
30789 \begin_inset LatexCommand \index{Memory map}
30790
30791 \end_inset
30792
30793 .
30794  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30795 ly idata, pdata, xdata).
30796  Eventually check if unexpected library functions are included.
30797 \end_layout
30798
30799 \begin_layout Section
30800 Tools
30801 \begin_inset LatexCommand \index{Tools}
30802
30803 \end_inset
30804
30805  included in the distribution
30806 \end_layout
30807
30808 \begin_layout Standard
30809 \align left
30810 \begin_inset Tabular
30811 <lyxtabular version="3" rows="12" columns="3">
30812 <features>
30813 <column alignment="left" valignment="top" leftline="true" width="0pt">
30814 <column alignment="left" valignment="top" leftline="true" width="0pt">
30815 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30816 <row topline="true" bottomline="true">
30817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30818 \begin_inset Text
30819
30820 \begin_layout Standard
30821
30822 \series bold
30823 Name
30824 \end_layout
30825
30826 \end_inset
30827 </cell>
30828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30829 \begin_inset Text
30830
30831 \begin_layout Standard
30832
30833 \series bold
30834 Purpose
30835 \end_layout
30836
30837 \end_inset
30838 </cell>
30839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30840 \begin_inset Text
30841
30842 \begin_layout Standard
30843
30844 \series bold
30845 Directory
30846 \end_layout
30847
30848 \end_inset
30849 </cell>
30850 </row>
30851 <row topline="true">
30852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30853 \begin_inset Text
30854
30855 \begin_layout Standard
30856 uCsim
30857 \begin_inset LatexCommand \index{uCsim}
30858
30859 \end_inset
30860
30861
30862 \end_layout
30863
30864 \end_inset
30865 </cell>
30866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30867 \begin_inset Text
30868
30869 \begin_layout Standard
30870 Simulator for various architectures
30871 \end_layout
30872
30873 \end_inset
30874 </cell>
30875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30876 \begin_inset Text
30877
30878 \begin_layout Standard
30879 sdcc/sim/ucsim
30880 \end_layout
30881
30882 \end_inset
30883 </cell>
30884 </row>
30885 <row topline="true">
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30887 \begin_inset Text
30888
30889 \begin_layout Standard
30890 keil2sdcc.pl
30891 \end_layout
30892
30893 \end_inset
30894 </cell>
30895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30896 \begin_inset Text
30897
30898 \begin_layout Standard
30899 header file
30900 \begin_inset LatexCommand \index{Header files}
30901
30902 \end_inset
30903
30904
30905 \begin_inset LatexCommand \index{Include files}
30906
30907 \end_inset
30908
30909  conversion
30910 \end_layout
30911
30912 \end_inset
30913 </cell>
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30915 \begin_inset Text
30916
30917 \begin_layout Standard
30918 sdcc/support/scripts
30919 \end_layout
30920
30921 \end_inset
30922 </cell>
30923 </row>
30924 <row topline="true">
30925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30926 \begin_inset Text
30927
30928 \begin_layout Standard
30929 mh2h.c
30930 \end_layout
30931
30932 \end_inset
30933 </cell>
30934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30935 \begin_inset Text
30936
30937 \begin_layout Standard
30938 header file conversion
30939 \end_layout
30940
30941 \end_inset
30942 </cell>
30943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30944 \begin_inset Text
30945
30946 \begin_layout Standard
30947 sdcc/support/scripts
30948 \end_layout
30949
30950 \end_inset
30951 </cell>
30952 </row>
30953 <row topline="true">
30954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30955 \begin_inset Text
30956
30957 \begin_layout Standard
30958 as-gbz80
30959 \end_layout
30960
30961 \end_inset
30962 </cell>
30963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30964 \begin_inset Text
30965
30966 \begin_layout Standard
30967 Assembler
30968 \end_layout
30969
30970 \end_inset
30971 </cell>
30972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30973 \begin_inset Text
30974
30975 \begin_layout Standard
30976
30977 \family roman
30978 \series medium
30979 \shape up
30980 \size normal
30981 \emph off
30982 \bar no
30983 \noun off
30984 \color none
30985 sdcc/bin
30986 \end_layout
30987
30988 \end_inset
30989 </cell>
30990 </row>
30991 <row topline="true">
30992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30993 \begin_inset Text
30994
30995 \begin_layout Standard
30996 as-z80
30997 \end_layout
30998
30999 \end_inset
31000 </cell>
31001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31002 \begin_inset Text
31003
31004 \begin_layout Standard
31005 Assembler
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
31015 \family roman
31016 \series medium
31017 \shape up
31018 \size normal
31019 \emph off
31020 \bar no
31021 \noun off
31022 \color none
31023 sdcc/bin
31024 \end_layout
31025
31026 \end_inset
31027 </cell>
31028 </row>
31029 <row topline="true">
31030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31031 \begin_inset Text
31032
31033 \begin_layout Standard
31034 asx8051
31035 \end_layout
31036
31037 \end_inset
31038 </cell>
31039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31040 \begin_inset Text
31041
31042 \begin_layout Standard
31043 Assembler
31044 \end_layout
31045
31046 \end_inset
31047 </cell>
31048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31049 \begin_inset Text
31050
31051 \begin_layout Standard
31052
31053 \family roman
31054 \series medium
31055 \shape up
31056 \size normal
31057 \emph off
31058 \bar no
31059 \noun off
31060 \color none
31061 sdcc/bin
31062 \end_layout
31063
31064 \end_inset
31065 </cell>
31066 </row>
31067 <row topline="true">
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31069 \begin_inset Text
31070
31071 \begin_layout Standard
31072 SDCDB
31073 \end_layout
31074
31075 \end_inset
31076 </cell>
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31078 \begin_inset Text
31079
31080 \begin_layout Standard
31081 Simulator
31082 \end_layout
31083
31084 \end_inset
31085 </cell>
31086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31087 \begin_inset Text
31088
31089 \begin_layout Standard
31090
31091 \family roman
31092 \series medium
31093 \shape up
31094 \size normal
31095 \emph off
31096 \bar no
31097 \noun off
31098 \color none
31099 sdcc/bin
31100 \end_layout
31101
31102 \end_inset
31103 </cell>
31104 </row>
31105 <row topline="true">
31106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31107 \begin_inset Text
31108
31109 \begin_layout Standard
31110 aslink
31111 \end_layout
31112
31113 \end_inset
31114 </cell>
31115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31116 \begin_inset Text
31117
31118 \begin_layout Standard
31119 Linker
31120 \end_layout
31121
31122 \end_inset
31123 </cell>
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31125 \begin_inset Text
31126
31127 \begin_layout Standard
31128
31129 \family roman
31130 \series medium
31131 \shape up
31132 \size normal
31133 \emph off
31134 \bar no
31135 \noun off
31136 \color none
31137 sdcc/bin
31138 \end_layout
31139
31140 \end_inset
31141 </cell>
31142 </row>
31143 <row topline="true">
31144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31145 \begin_inset Text
31146
31147 \begin_layout Standard
31148 link-z80
31149 \end_layout
31150
31151 \end_inset
31152 </cell>
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31154 \begin_inset Text
31155
31156 \begin_layout Standard
31157 Linker
31158 \end_layout
31159
31160 \end_inset
31161 </cell>
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31163 \begin_inset Text
31164
31165 \begin_layout Standard
31166
31167 \family roman
31168 \series medium
31169 \shape up
31170 \size normal
31171 \emph off
31172 \bar no
31173 \noun off
31174 \color none
31175 sdcc/bin
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 </row>
31181 <row topline="true">
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 \begin_inset Text
31184
31185 \begin_layout Standard
31186 link-gbz80
31187 \end_layout
31188
31189 \end_inset
31190 </cell>
31191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31192 \begin_inset Text
31193
31194 \begin_layout Standard
31195 Linker
31196 \end_layout
31197
31198 \end_inset
31199 </cell>
31200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31201 \begin_inset Text
31202
31203 \begin_layout Standard
31204
31205 \family roman
31206 \series medium
31207 \shape up
31208 \size normal
31209 \emph off
31210 \bar no
31211 \noun off
31212 \color none
31213 sdcc/bin
31214 \end_layout
31215
31216 \end_inset
31217 </cell>
31218 </row>
31219 <row topline="true" bottomline="true">
31220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31221 \begin_inset Text
31222
31223 \begin_layout Standard
31224 packihx
31225 \end_layout
31226
31227 \end_inset
31228 </cell>
31229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31230 \begin_inset Text
31231
31232 \begin_layout Standard
31233 Intel Hex packer 
31234 \begin_inset LatexCommand \index{packihx (tool)}
31235
31236 \end_inset
31237
31238
31239 \end_layout
31240
31241 \end_inset
31242 </cell>
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31244 \begin_inset Text
31245
31246 \begin_layout Standard
31247
31248 \family roman
31249 \series medium
31250 \shape up
31251 \size normal
31252 \emph off
31253 \bar no
31254 \noun off
31255 \color none
31256 sdcc/bin
31257 \end_layout
31258
31259 \end_inset
31260 </cell>
31261 </row>
31262 </lyxtabular>
31263
31264 \end_inset
31265
31266
31267 \newline
31268
31269 \end_layout
31270
31271 \begin_layout Section
31272 Documentation
31273 \begin_inset LatexCommand \index{Documentation}
31274
31275 \end_inset
31276
31277  included in the distribution
31278 \end_layout
31279
31280 \begin_layout Standard
31281 \align left
31282 \begin_inset Tabular
31283 <lyxtabular version="3" rows="10" columns="2">
31284 <features>
31285 <column alignment="block" valignment="top" leftline="true" width="40col%">
31286 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31287 <row topline="true" bottomline="true" endhead="true">
31288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31289 \begin_inset Text
31290
31291 \begin_layout Standard
31292
31293 \series bold
31294 Subject / Title
31295 \end_layout
31296
31297 \end_inset
31298 </cell>
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \begin_layout Standard
31303
31304 \series bold
31305 Filename / Where to get
31306 \end_layout
31307
31308 \end_inset
31309 </cell>
31310 </row>
31311 <row topline="true">
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31313 \begin_inset Text
31314
31315 \begin_layout Standard
31316 SDCC Compiler User Guide
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 You're reading it right now
31326 \emph on
31327  \InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330
31331 \hfill
31332 online at:
31333 \emph default
31334
31335 \newline
31336
31337 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31338
31339 \end_inset
31340
31341
31342 \end_layout
31343
31344 \end_inset
31345 </cell>
31346 </row>
31347 <row topline="true">
31348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31349 \begin_inset Text
31350
31351 \begin_layout Standard
31352 Changelog of SDCC
31353 \end_layout
31354
31355 \end_inset
31356 </cell>
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31358 \begin_inset Text
31359
31360 \begin_layout Standard
31361 sdcc/Changelog
31362 \emph on
31363  \InsetSpace ~
31364 \InsetSpace ~
31365 \InsetSpace ~
31366
31367 \hfill
31368 online at:
31369 \emph default
31370
31371 \newline
31372
31373 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31374
31375 \end_inset
31376
31377
31378 \end_layout
31379
31380 \end_inset
31381 </cell>
31382 </row>
31383 <row topline="true">
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31385 \begin_inset Text
31386
31387 \begin_layout Standard
31388 ASXXXX
31389 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31390
31391 \end_inset
31392
31393
31394 \begin_inset LatexCommand \index{Assembler documentation}
31395
31396 \end_inset
31397
31398  Assemblers and
31399 \newline
31400 ASLINK
31401 \begin_inset LatexCommand \index{aslink}
31402
31403 \end_inset
31404
31405
31406 \begin_inset LatexCommand \index{Linker documentation}
31407
31408 \end_inset
31409
31410  Relocating Linker
31411 \end_layout
31412
31413 \end_inset
31414 </cell>
31415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31416 \begin_inset Text
31417
31418 \begin_layout Standard
31419 sdcc/as/doc/asxhtm.html 
31420 \emph on
31421 \InsetSpace ~
31422 \InsetSpace ~
31423 \InsetSpace ~
31424
31425 \hfill
31426 online at:
31427 \emph default
31428
31429 \newline
31430
31431 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31432
31433 \end_inset
31434
31435
31436 \end_layout
31437
31438 \end_inset
31439 </cell>
31440 </row>
31441 <row topline="true">
31442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31443 \begin_inset Text
31444
31445 \begin_layout Standard
31446 SDCC regression test
31447 \begin_inset LatexCommand \index{Regression test}
31448
31449 \end_inset
31450
31451
31452 \end_layout
31453
31454 \end_inset
31455 </cell>
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31457 \begin_inset Text
31458
31459 \begin_layout Standard
31460 sdcc/doc/test_suite_spec.pdf 
31461 \emph on
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465
31466 \hfill
31467 online at:
31468 \emph default
31469
31470 \newline
31471
31472 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31473
31474 \end_inset
31475
31476
31477 \end_layout
31478
31479 \end_inset
31480 </cell>
31481 </row>
31482 <row topline="true">
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31484 \begin_inset Text
31485
31486 \begin_layout Standard
31487 Various notes
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 sdcc/doc/* 
31497 \emph on
31498 \InsetSpace ~
31499 \InsetSpace ~
31500 \InsetSpace ~
31501
31502 \hfill
31503 online at:
31504 \emph default
31505
31506 \newline
31507
31508 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31509
31510 \end_inset
31511
31512
31513 \end_layout
31514
31515 \end_inset
31516 </cell>
31517 </row>
31518 <row topline="true">
31519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31520 \begin_inset Text
31521
31522 \begin_layout Standard
31523 Notes on debugging with SDCDB
31524 \begin_inset LatexCommand \index{SDCDB (debugger)}
31525
31526 \end_inset
31527
31528
31529 \end_layout
31530
31531 \end_inset
31532 </cell>
31533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31534 \begin_inset Text
31535
31536 \begin_layout Standard
31537 sdcc/debugger/README 
31538 \emph on
31539 \InsetSpace ~
31540 \InsetSpace ~
31541 \InsetSpace ~
31542
31543 \hfill
31544 online at
31545 \emph default
31546 :
31547 \newline
31548
31549 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31550
31551 \end_inset
31552
31553
31554 \end_layout
31555
31556 \end_inset
31557 </cell>
31558 </row>
31559 <row topline="true">
31560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31561 \begin_inset Text
31562
31563 \begin_layout Standard
31564 uCsim
31565 \begin_inset LatexCommand \index{uCsim}
31566
31567 \end_inset
31568
31569  Software simulator for microcontrollers
31570 \end_layout
31571
31572 \end_inset
31573 </cell>
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31575 \begin_inset Text
31576
31577 \begin_layout Standard
31578
31579 \family roman
31580 \series medium
31581 \shape up
31582 \size normal
31583 \emph off
31584 \bar no
31585 \noun off
31586 \color none
31587 sdcc/sim/ucsim/doc
31588 \family default
31589 \series default
31590 \shape default
31591 \size default
31592 \emph default
31593 \bar default
31594 \noun default
31595 /index.html 
31596 \emph on
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 \InsetSpace ~
31600
31601 \hfill
31602 online at:
31603 \emph default
31604
31605 \newline
31606
31607 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31608
31609 \end_inset
31610
31611
31612 \end_layout
31613
31614 \end_inset
31615 </cell>
31616 </row>
31617 <row topline="true">
31618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31619 \begin_inset Text
31620
31621 \begin_layout Standard
31622 Temporary notes on the pic16
31623 \begin_inset LatexCommand \index{PIC16}
31624
31625 \end_inset
31626
31627  port
31628 \end_layout
31629
31630 \end_inset
31631 </cell>
31632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31633 \begin_inset Text
31634
31635 \begin_layout Standard
31636 sdcc/src/pic16/NOTES 
31637 \emph on
31638 \InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641
31642 \hfill
31643 online at:
31644 \newline
31645
31646 \emph default
31647
31648 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31649
31650 \end_inset
31651
31652
31653 \end_layout
31654
31655 \end_inset
31656 </cell>
31657 </row>
31658 <row topline="true" bottomline="true">
31659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31660 \begin_inset Text
31661
31662 \begin_layout Standard
31663 SDCC internal documentation (debugging file format)
31664 \end_layout
31665
31666 \end_inset
31667 </cell>
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31669 \begin_inset Text
31670
31671 \begin_layout Standard
31672 sdcc/doc/
31673 \family roman
31674 \series medium
31675 \shape up
31676 \size normal
31677 \emph off
31678 \bar no
31679 \noun off
31680 \color none
31681 cdbfileformat.pd
31682 \family default
31683 \series default
31684 \shape default
31685 \size default
31686 \emph default
31687 \bar default
31688 \noun default
31689 f
31690 \emph on
31691  \InsetSpace ~
31692 \InsetSpace ~
31693 \InsetSpace ~
31694
31695 \hfill
31696 online at:
31697 \emph default
31698
31699 \newline
31700
31701 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31702
31703 \end_inset
31704
31705
31706 \end_layout
31707
31708 \end_inset
31709 </cell>
31710 </row>
31711 </lyxtabular>
31712
31713 \end_inset
31714
31715
31716 \newline
31717
31718 \end_layout
31719
31720 \begin_layout Section
31721 Related open source tools
31722 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31723
31724 \end_inset
31725
31726
31727 \begin_inset LatexCommand \index{Related tools}
31728
31729 \end_inset
31730
31731
31732 \end_layout
31733
31734 \begin_layout Standard
31735 \align left
31736 \begin_inset Tabular
31737 <lyxtabular version="3" rows="16" columns="3">
31738 <features>
31739 <column alignment="left" valignment="top" leftline="true" width="0pt">
31740 <column alignment="block" valignment="top" leftline="true" width="30line%">
31741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31742 <row topline="true" bottomline="true">
31743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31744 \begin_inset Text
31745
31746 \begin_layout Standard
31747
31748 \series bold
31749 Name
31750 \end_layout
31751
31752 \end_inset
31753 </cell>
31754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31755 \begin_inset Text
31756
31757 \begin_layout Standard
31758
31759 \series bold
31760 Purpose
31761 \end_layout
31762
31763 \end_inset
31764 </cell>
31765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31766 \begin_inset Text
31767
31768 \begin_layout Standard
31769
31770 \series bold
31771 Where to get
31772 \end_layout
31773
31774 \end_inset
31775 </cell>
31776 </row>
31777 <row topline="true">
31778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31779 \begin_inset Text
31780
31781 \begin_layout Standard
31782 gpsim
31783 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31784
31785 \end_inset
31786
31787
31788 \end_layout
31789
31790 \end_inset
31791 </cell>
31792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31793 \begin_inset Text
31794
31795 \begin_layout Standard
31796 PIC simulator
31797 \end_layout
31798
31799 \end_inset
31800 </cell>
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31802 \begin_inset Text
31803
31804 \begin_layout Standard
31805 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31806
31807 \end_inset
31808
31809
31810 \end_layout
31811
31812 \end_inset
31813 </cell>
31814 </row>
31815 <row topline="true">
31816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31817 \begin_inset Text
31818
31819 \begin_layout Standard
31820 gputils
31821 \begin_inset LatexCommand \index{gputils (pic tools)}
31822
31823 \end_inset
31824
31825
31826 \end_layout
31827
31828 \end_inset
31829 </cell>
31830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31831 \begin_inset Text
31832
31833 \begin_layout Standard
31834 GNU PIC utilities
31835 \end_layout
31836
31837 \end_inset
31838 </cell>
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31840 \begin_inset Text
31841
31842 \begin_layout Standard
31843 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31844
31845 \end_inset
31846
31847
31848 \end_layout
31849
31850 \end_inset
31851 </cell>
31852 </row>
31853 <row topline="true">
31854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31855 \begin_inset Text
31856
31857 \begin_layout Standard
31858 flP5
31859 \end_layout
31860
31861 \end_inset
31862 </cell>
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31864 \begin_inset Text
31865
31866 \begin_layout Standard
31867 PIC programmer
31868 \end_layout
31869
31870 \end_inset
31871 </cell>
31872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31873 \begin_inset Text
31874
31875 \begin_layout Standard
31876 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31877
31878 \end_inset
31879
31880
31881 \end_layout
31882
31883 \end_inset
31884 </cell>
31885 </row>
31886 <row topline="true">
31887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31888 \begin_inset Text
31889
31890 \begin_layout Standard
31891 ec2drv/newcdb
31892 \end_layout
31893
31894 \end_inset
31895 </cell>
31896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31897 \begin_inset Text
31898
31899 \begin_layout Standard
31900 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31901  (Unix only)
31902 \end_layout
31903
31904 \end_inset
31905 </cell>
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31907 \begin_inset Text
31908
31909 \begin_layout Standard
31910 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31911
31912 \end_inset
31913
31914
31915 \end_layout
31916
31917 \end_inset
31918 </cell>
31919 </row>
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31922 \begin_inset Text
31923
31924 \begin_layout Standard
31925 indent
31926 \begin_inset LatexCommand \index{indent (source formatting tool)}
31927
31928 \end_inset
31929
31930
31931 \end_layout
31932
31933 \end_inset
31934 </cell>
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31936 \begin_inset Text
31937
31938 \begin_layout Standard
31939 Formats C source - Master of the white spaces
31940 \end_layout
31941
31942 \end_inset
31943 </cell>
31944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31945 \begin_inset Text
31946
31947 \begin_layout Standard
31948 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31949
31950 \end_inset
31951
31952
31953 \end_layout
31954
31955 \end_inset
31956 </cell>
31957 </row>
31958 <row topline="true">
31959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31960 \begin_inset Text
31961
31962 \begin_layout Standard
31963 srecord
31964 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31965
31966 \end_inset
31967
31968
31969 \end_layout
31970
31971 \end_inset
31972 </cell>
31973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31974 \begin_inset Text
31975
31976 \begin_layout Standard
31977 Object file conversion, checksumming, ...
31978 \end_layout
31979
31980 \end_inset
31981 </cell>
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31983 \begin_inset Text
31984
31985 \begin_layout Standard
31986 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31987
31988 \end_inset
31989
31990
31991 \end_layout
31992
31993 \end_inset
31994 </cell>
31995 </row>
31996 <row topline="true">
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31998 \begin_inset Text
31999
32000 \begin_layout Standard
32001 objdump
32002 \begin_inset LatexCommand \index{objdump (tool)}
32003
32004 \end_inset
32005
32006
32007 \end_layout
32008
32009 \end_inset
32010 </cell>
32011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32012 \begin_inset Text
32013
32014 \begin_layout Standard
32015 Object file conversion, ...
32016 \end_layout
32017
32018 \end_inset
32019 </cell>
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32021 \begin_inset Text
32022
32023 \begin_layout Standard
32024 Part of binutils (should be there anyway)
32025 \end_layout
32026
32027 \end_inset
32028 </cell>
32029 </row>
32030 <row topline="true">
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32032 \begin_inset Text
32033
32034 \begin_layout Standard
32035 cmon51
32036 \end_layout
32037
32038 \end_inset
32039 </cell>
32040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32041 \begin_inset Text
32042
32043 \begin_layout Standard
32044 8051 monitor (hex up-/download, single step, disassemble)
32045 \end_layout
32046
32047 \end_inset
32048 </cell>
32049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32050 \begin_inset Text
32051
32052 \begin_layout Standard
32053 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32054
32055 \end_inset
32056
32057
32058 \end_layout
32059
32060 \end_inset
32061 </cell>
32062 </row>
32063 <row topline="true">
32064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32065 \begin_inset Text
32066
32067 \begin_layout Standard
32068 doxygen
32069 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32070
32071 \end_inset
32072
32073
32074 \end_layout
32075
32076 \end_inset
32077 </cell>
32078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32079 \begin_inset Text
32080
32081 \begin_layout Standard
32082 Source code documentation system
32083 \end_layout
32084
32085 \end_inset
32086 </cell>
32087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32088 \begin_inset Text
32089
32090 \begin_layout Standard
32091 \begin_inset LatexCommand \url{http://www.doxygen.org}
32092
32093 \end_inset
32094
32095
32096 \end_layout
32097
32098 \end_inset
32099 </cell>
32100 </row>
32101 <row topline="true">
32102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32103 \begin_inset Text
32104
32105 \begin_layout Standard
32106 kdevelop
32107 \end_layout
32108
32109 \end_inset
32110 </cell>
32111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32112 \begin_inset Text
32113
32114 \begin_layout Standard
32115 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32116 \end_layout
32117
32118 \end_inset
32119 </cell>
32120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32121 \begin_inset Text
32122
32123 \begin_layout Standard
32124 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32125
32126 \end_inset
32127
32128
32129 \end_layout
32130
32131 \end_inset
32132 </cell>
32133 </row>
32134 <row topline="true">
32135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32136 \begin_inset Text
32137
32138 \begin_layout Standard
32139 paulmon
32140 \end_layout
32141
32142 \end_inset
32143 </cell>
32144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32145 \begin_inset Text
32146
32147 \begin_layout Standard
32148 8051 monitor (hex up-/download, single step, disassemble)
32149 \end_layout
32150
32151 \end_inset
32152 </cell>
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32154 \begin_inset Text
32155
32156 \begin_layout Standard
32157 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32158
32159 \end_inset
32160
32161
32162 \end_layout
32163
32164 \end_inset
32165 </cell>
32166 </row>
32167 <row topline="true">
32168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32169 \begin_inset Text
32170
32171 \begin_layout Standard
32172 splint
32173 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32174
32175 \end_inset
32176
32177
32178 \end_layout
32179
32180 \end_inset
32181 </cell>
32182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32183 \begin_inset Text
32184
32185 \begin_layout Standard
32186 Statically checks c sources (see 
32187 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32188
32189 \end_inset
32190
32191 )
32192 \end_layout
32193
32194 \end_inset
32195 </cell>
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32197 \begin_inset Text
32198
32199 \begin_layout Standard
32200 \begin_inset LatexCommand \url{http://www.splint.org}
32201
32202 \end_inset
32203
32204
32205 \end_layout
32206
32207 \end_inset
32208 </cell>
32209 </row>
32210 <row topline="true" bottomline="true">
32211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32212 \begin_inset Text
32213
32214 \begin_layout Standard
32215 ddd
32216 \begin_inset LatexCommand \index{DDD (debugger)}
32217
32218 \end_inset
32219
32220
32221 \end_layout
32222
32223 \end_inset
32224 </cell>
32225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32226 \begin_inset Text
32227
32228 \begin_layout Standard
32229 Debugger, serves nicely as GUI to SDCDB
32230 \begin_inset LatexCommand \index{SDCDB (debugger)}
32231
32232 \end_inset
32233
32234  (Unix only)
32235 \end_layout
32236
32237 \end_inset
32238 </cell>
32239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32240 \begin_inset Text
32241
32242 \begin_layout Standard
32243 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32244
32245 \end_inset
32246
32247
32248 \end_layout
32249
32250 \end_inset
32251 </cell>
32252 </row>
32253 <row bottomline="true">
32254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32255 \begin_inset Text
32256
32257 \begin_layout Standard
32258 d52
32259 \begin_inset LatexCommand \index{d52}
32260
32261 \end_inset
32262
32263
32264 \begin_inset LatexCommand \index{d52 (disassembler)}
32265
32266 \end_inset
32267
32268
32269 \end_layout
32270
32271 \end_inset
32272 </cell>
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32274 \begin_inset Text
32275
32276 \begin_layout Standard
32277 Disassembler, can count instruction cycles
32278 \begin_inset LatexCommand \index{instruction cycles (count)}
32279
32280 \end_inset
32281
32282 , use with options -pnd
32283 \end_layout
32284
32285 \end_inset
32286 </cell>
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32288 \begin_inset Text
32289
32290 \begin_layout Standard
32291 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32292
32293 \end_inset
32294
32295
32296 \end_layout
32297
32298 \end_inset
32299 </cell>
32300 </row>
32301 <row bottomline="true">
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32303 \begin_inset Text
32304
32305 \begin_layout Standard
32306 cmake
32307 \begin_inset LatexCommand \index{cmake}
32308
32309 \end_inset
32310
32311
32312 \end_layout
32313
32314 \end_inset
32315 </cell>
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32317 \begin_inset Text
32318
32319 \begin_layout Standard
32320 Cross platform build system, generates Makefiles
32321 \begin_inset LatexCommand \index{Makefile}
32322
32323 \end_inset
32324
32325  and project workspaces
32326 \begin_inset LatexCommand \index{project workspace}
32327
32328 \end_inset
32329
32330
32331 \end_layout
32332
32333 \end_inset
32334 </cell>
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32336 \begin_inset Text
32337
32338 \begin_layout Standard
32339 \begin_inset LatexCommand \url{http://www.cmake.org}
32340
32341 \end_inset
32342
32343  \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 and a dedicated wiki entry: 
32348 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32349
32350 \end_inset
32351
32352
32353 \end_layout
32354
32355 \end_inset
32356 </cell>
32357 </row>
32358 </lyxtabular>
32359
32360 \end_inset
32361
32362
32363 \newline
32364
32365 \end_layout
32366
32367 \begin_layout Section
32368 Related documentation / recommended reading
32369 \end_layout
32370
32371 \begin_layout Standard
32372 \align left
32373 \begin_inset Tabular
32374 <lyxtabular version="3" rows="7" columns="3">
32375 <features>
32376 <column alignment="left" valignment="top" leftline="true" width="0pt">
32377 <column alignment="left" valignment="top" leftline="true" width="0">
32378 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32379 <row topline="true" bottomline="true">
32380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32381 \begin_inset Text
32382
32383 \begin_layout Standard
32384
32385 \series bold
32386 Name
32387 \end_layout
32388
32389 \end_inset
32390 </cell>
32391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32392 \begin_inset Text
32393
32394 \begin_layout Standard
32395
32396 \series bold
32397 Subject / Title
32398 \end_layout
32399
32400 \end_inset
32401 </cell>
32402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32403 \begin_inset Text
32404
32405 \begin_layout Standard
32406
32407 \series bold
32408 Where to get
32409 \end_layout
32410
32411 \end_inset
32412 </cell>
32413 </row>
32414 <row topline="true">
32415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32416 \begin_inset Text
32417
32418 \begin_layout Standard
32419
32420 \family roman
32421 \series medium
32422 \shape up
32423 \size normal
32424 \emph off
32425 \bar no
32426 \noun off
32427 \color none
32428 c-refcard.pdf
32429 \end_layout
32430
32431 \end_inset
32432 </cell>
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_inset Text
32435
32436 \begin_layout Standard
32437 C Reference Card
32438 \begin_inset LatexCommand \index{C Reference card}
32439
32440 \end_inset
32441
32442 , 2 pages
32443 \end_layout
32444
32445 \end_inset
32446 </cell>
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32448 \begin_inset Text
32449
32450 \begin_layout Standard
32451 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32452
32453 \end_inset
32454
32455
32456 \end_layout
32457
32458 \end_inset
32459 </cell>
32460 </row>
32461 <row topline="true">
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32463 \begin_inset Text
32464
32465 \begin_layout Standard
32466 c-faq
32467 \end_layout
32468
32469 \end_inset
32470 </cell>
32471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32472 \begin_inset Text
32473
32474 \begin_layout Standard
32475 C-FAQ
32476 \begin_inset LatexCommand \index{C FAQ}
32477
32478 \end_inset
32479
32480
32481 \end_layout
32482
32483 \end_inset
32484 </cell>
32485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32486 \begin_inset Text
32487
32488 \begin_layout Standard
32489 \begin_inset LatexCommand \url{http://www.c-faq.com}
32490
32491 \end_inset
32492
32493
32494 \end_layout
32495
32496 \end_inset
32497 </cell>
32498 </row>
32499 <row topline="true">
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32501 \begin_inset Text
32502
32503 \begin_layout Standard
32504 ISO/IEC 9899:TC2
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 \begin_inset Quotes sld
32514 \end_inset
32515
32516 C-Standard
32517 \begin_inset Quotes srd
32518 \end_inset
32519
32520
32521 \end_layout
32522
32523 \end_inset
32524 </cell>
32525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32526 \begin_inset Text
32527
32528 \begin_layout Standard
32529
32530 \size footnotesize
32531 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32532
32533 \end_inset
32534
32535
32536 \end_layout
32537
32538 \end_inset
32539 </cell>
32540 </row>
32541 <row topline="true">
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32543 \begin_inset Text
32544
32545 \begin_layout Standard
32546 ISO/IEC DTR 18037
32547 \end_layout
32548
32549 \end_inset
32550 </cell>
32551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32552 \begin_inset Text
32553
32554 \begin_layout Standard
32555 \begin_inset Quotes sld
32556 \end_inset
32557
32558 Extensions for Embedded C
32559 \begin_inset Quotes srd
32560 \end_inset
32561
32562
32563 \end_layout
32564
32565 \end_inset
32566 </cell>
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32568 \begin_inset Text
32569
32570 \begin_layout Standard
32571
32572 \size footnotesize
32573 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32574
32575 \end_inset
32576
32577
32578 \end_layout
32579
32580 \end_inset
32581 </cell>
32582 </row>
32583 <row topline="true">
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32585 \begin_inset Text
32586
32587 \begin_layout Standard
32588
32589 \end_layout
32590
32591 \end_inset
32592 </cell>
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32594 \begin_inset Text
32595
32596 \begin_layout Standard
32597 Latest datasheet of target CPU
32598 \end_layout
32599
32600 \end_inset
32601 </cell>
32602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32603 \begin_inset Text
32604
32605 \begin_layout Standard
32606 vendor
32607 \end_layout
32608
32609 \end_inset
32610 </cell>
32611 </row>
32612 <row topline="true" bottomline="true">
32613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32614 \begin_inset Text
32615
32616 \begin_layout Standard
32617
32618 \end_layout
32619
32620 \end_inset
32621 </cell>
32622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32623 \begin_inset Text
32624
32625 \begin_layout Standard
32626 Revision history of datasheet
32627 \end_layout
32628
32629 \end_inset
32630 </cell>
32631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32632 \begin_inset Text
32633
32634 \begin_layout Standard
32635 vendor
32636 \end_layout
32637
32638 \end_inset
32639 </cell>
32640 </row>
32641 </lyxtabular>
32642
32643 \end_inset
32644
32645
32646 \newline
32647
32648 \end_layout
32649
32650 \begin_layout Section
32651 Application notes specifically for SDCC
32652 \end_layout
32653
32654 \begin_layout Standard
32655 SDCC makes no claims about the completeness of this list and about up-to-datenes
32656 s or correctness of the application notes
32657 \begin_inset LatexCommand \index{Application notes}
32658
32659 \end_inset
32660
32661 .
32662 \end_layout
32663
32664 \begin_layout Standard
32665 \align left
32666
32667 \size footnotesize
32668 \begin_inset Tabular
32669 <lyxtabular version="3" rows="7" columns="3">
32670 <features>
32671 <column alignment="block" valignment="top" leftline="true" width="17col%">
32672 <column alignment="block" valignment="top" leftline="true" width="27col%">
32673 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32674 <row topline="true" bottomline="true">
32675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32676 \begin_inset Text
32677
32678 \begin_layout Standard
32679
32680 \series bold
32681 \size footnotesize
32682 Vendor
32683 \end_layout
32684
32685 \end_inset
32686 </cell>
32687 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32688 \begin_inset Text
32689
32690 \begin_layout Standard
32691
32692 \series bold
32693 \size footnotesize
32694 Subject / Title
32695 \end_layout
32696
32697 \end_inset
32698 </cell>
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32700 \begin_inset Text
32701
32702 \begin_layout Standard
32703
32704 \series bold
32705 \size footnotesize
32706 Where to get
32707 \end_layout
32708
32709 \end_inset
32710 </cell>
32711 </row>
32712 <row topline="true">
32713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32714 \begin_inset Text
32715
32716 \begin_layout Standard
32717
32718 \size footnotesize
32719 Maxim / Dallas
32720 \end_layout
32721
32722 \end_inset
32723 </cell>
32724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32725 \begin_inset Text
32726
32727 \begin_layout Standard
32728
32729 \size footnotesize
32730 Using the SDCC Compiler for the DS80C400
32731 \begin_inset LatexCommand \index{DS80C400}
32732
32733 \end_inset
32734
32735
32736 \end_layout
32737
32738 \end_inset
32739 </cell>
32740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32741 \begin_inset Text
32742
32743 \begin_layout Standard
32744
32745 \size footnotesize
32746 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32747
32748 \end_inset
32749
32750
32751 \end_layout
32752
32753 \end_inset
32754 </cell>
32755 </row>
32756 <row topline="true">
32757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32758 \begin_inset Text
32759
32760 \begin_layout Standard
32761
32762 \size footnotesize
32763 Maxim / Dallas
32764 \end_layout
32765
32766 \end_inset
32767 </cell>
32768 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32769 \begin_inset Text
32770
32771 \begin_layout Standard
32772
32773 \size footnotesize
32774 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32775 \begin_inset LatexCommand \index{DS89C4x0}
32776
32777 \end_inset
32778
32779  Family of Microcontrollers
32780 \end_layout
32781
32782 \end_inset
32783 </cell>
32784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32785 \begin_inset Text
32786
32787 \begin_layout Standard
32788
32789 \size footnotesize
32790 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32791
32792 \end_inset
32793
32794
32795 \end_layout
32796
32797 \end_inset
32798 </cell>
32799 </row>
32800 <row topline="true">
32801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32802 \begin_inset Text
32803
32804 \begin_layout Standard
32805
32806 \size footnotesize
32807 Silicon Laboratories / Cygnal
32808 \end_layout
32809
32810 \end_inset
32811 </cell>
32812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32813 \begin_inset Text
32814
32815 \begin_layout Standard
32816
32817 \size footnotesize
32818 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32819 \begin_inset LatexCommand \index{IDE}
32820
32821 \end_inset
32822
32823
32824 \end_layout
32825
32826 \end_inset
32827 </cell>
32828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32829 \begin_inset Text
32830
32831 \begin_layout Standard
32832
32833 \size footnotesize
32834 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32835
32836 \end_inset
32837
32838
32839 \end_layout
32840
32841 \end_inset
32842 </cell>
32843 </row>
32844 <row topline="true">
32845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32846 \begin_inset Text
32847
32848 \begin_layout Standard
32849
32850 \size footnotesize
32851 Ramtron / Goal Semiconductor
32852 \end_layout
32853
32854 \end_inset
32855 </cell>
32856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32857 \begin_inset Text
32858
32859 \begin_layout Standard
32860
32861 \size footnotesize
32862 Interfacing SDCC to Syn and Textpad
32863 \end_layout
32864
32865 \end_inset
32866 </cell>
32867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32868 \begin_inset Text
32869
32870 \begin_layout Standard
32871
32872 \size footnotesize
32873 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32874
32875 \end_inset
32876
32877
32878 \end_layout
32879
32880 \end_inset
32881 </cell>
32882 </row>
32883 <row topline="true">
32884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32885 \begin_inset Text
32886
32887 \begin_layout Standard
32888
32889 \size footnotesize
32890 Ramtron / Goal Semiconductor
32891 \end_layout
32892
32893 \end_inset
32894 </cell>
32895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32896 \begin_inset Text
32897
32898 \begin_layout Standard
32899
32900 \size footnotesize
32901 Installing and Configuring SDCC and Crimson Editor 
32902 \end_layout
32903
32904 \end_inset
32905 </cell>
32906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32907 \begin_inset Text
32908
32909 \begin_layout Standard
32910
32911 \size footnotesize
32912 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32913
32914 \end_inset
32915
32916
32917 \end_layout
32918
32919 \end_inset
32920 </cell>
32921 </row>
32922 <row topline="true" bottomline="true">
32923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32924 \begin_inset Text
32925
32926 \begin_layout Standard
32927
32928 \size footnotesize
32929 Texas Instruments
32930 \end_layout
32931
32932 \end_inset
32933 </cell>
32934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32935 \begin_inset Text
32936
32937 \begin_layout Standard
32938
32939 \size footnotesize
32940 MSC12xx Programming with SDCC
32941 \end_layout
32942
32943 \end_inset
32944 </cell>
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32946 \begin_inset Text
32947
32948 \begin_layout Standard
32949
32950 \size footnotesize
32951 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32952
32953 \end_inset
32954
32955
32956 \end_layout
32957
32958 \end_inset
32959 </cell>
32960 </row>
32961 </lyxtabular>
32962
32963 \end_inset
32964
32965
32966 \end_layout
32967
32968 \begin_layout Section
32969 Some Questions
32970 \end_layout
32971
32972 \begin_layout Standard
32973 Some questions answered, some pointers given - it might be time to in turn
32974  ask 
32975 \emph on
32976 you
32977 \emph default
32978  some questions: 
32979 \end_layout
32980
32981 \begin_layout Itemize
32982 can you solve your project with the selected microcontroller? Would you
32983  find out early or rather late that your target is too small/slow/whatever?
32984  Can you switch to a slightly better device if it doesn't fit?
32985 \end_layout
32986
32987 \begin_layout Itemize
32988 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32989  and/or another programming language be more adequate? Would an operating
32990  system on the target device help?
32991 \end_layout
32992
32993 \begin_layout Itemize
32994 if you solved the problem, will the marketing department be happy?
32995 \end_layout
32996
32997 \begin_layout Itemize
32998 if the marketing department is happy, will customers be happy?
32999 \end_layout
33000
33001 \begin_layout Itemize
33002 if you're the project manager, marketing department and maybe even the customer
33003  in one person, have you tried to see the project from the outside?
33004 \end_layout
33005
33006 \begin_layout Itemize
33007 is the project done if you think it is done? Or is just that other interface/pro
33008 tocol/feature/configuration/option missing? How about website, manual(s),
33009  internationali(z|s)ation, packaging, labels, 2nd source for components,
33010  electromagnetic compatability/interference, documentation for production,
33011  production test software, update mechanism, patent issues?
33012 \end_layout
33013
33014 \begin_layout Itemize
33015 is your project adequately positioned in that magic triangle: fame, fortune,
33016  fun?
33017 \end_layout
33018
33019 \begin_layout Standard
33020 Maybe not all answers to these questions are known and some answers may
33021  even be 
33022 \emph on
33023 no
33024 \emph default
33025 , nevertheless knowing these questions may help you to avoid burnout
33026 \begin_inset Foot
33027 status open
33028
33029 \begin_layout Standard
33030 burnout is bad for electronic devices, programmers and motorcycle tyres
33031 \end_layout
33032
33033 \end_inset
33034
33035 .
33036  Chances are you didn't want to hear some of them...
33037 \end_layout
33038
33039 \begin_layout Chapter
33040 Support
33041 \begin_inset LatexCommand \index{Support}
33042
33043 \end_inset
33044
33045
33046 \end_layout
33047
33048 \begin_layout Standard
33049 SDCC has grown to be a large project.
33050  The compiler alone (without the preprocessor, assembler and linker) is
33051  well over 150,000 lines of code (blank stripped).
33052  The open source nature of this project is a key to its continued growth
33053  and support.
33054  You gain the benefit and support of many active software developers and
33055  end users.
33056  Is SDCC perfect? No, that's why we need your help.
33057  The developers take pride in fixing reported bugs.
33058  You can help by reporting the bugs and helping other SDCC users.
33059  There are lots of ways to contribute, and we encourage you to take part
33060  in making SDCC a great software package.
33061  
33062 \end_layout
33063
33064 \begin_layout Standard
33065 The SDCC project is hosted on the SDCC sourceforge site at 
33066 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33067
33068 \end_inset
33069
33070 .
33071  You'll find the complete set of mailing lists
33072 \begin_inset LatexCommand \index{Mailing list(s)}
33073
33074 \end_inset
33075
33076 , forums, bug reporting system, patch submission
33077 \begin_inset LatexCommand \index{Patch submission}
33078
33079 \end_inset
33080
33081  system, download
33082 \begin_inset LatexCommand \index{download}
33083
33084 \end_inset
33085
33086  area and Subversion code repository
33087 \begin_inset LatexCommand \index{Subversion code repository}
33088
33089 \end_inset
33090
33091  there.
33092 \end_layout
33093
33094 \begin_layout Section
33095 Reporting Bugs
33096 \begin_inset LatexCommand \index{Bug reporting}
33097
33098 \end_inset
33099
33100
33101 \begin_inset LatexCommand \index{Reporting bugs}
33102
33103 \end_inset
33104
33105
33106 \end_layout
33107
33108 \begin_layout Standard
33109 The recommended way of reporting bugs is using the infrastructure of the
33110  sourceforge site.
33111  You can follow the status of bug reports there and have an overview about
33112  the known bugs.
33113 \end_layout
33114
33115 \begin_layout Standard
33116 Bug reports are automatically forwarded to the developer mailing list and
33117  will be fixed ASAP.
33118  When reporting a bug, it is very useful to include a small test program
33119  (the smaller the better) which reproduces the problem.
33120  If you can isolate the problem by looking at the generated assembly code,
33121  this can be very helpful.
33122  Compiling your program with the -
33123 \begin_inset ERT
33124 status collapsed
33125
33126 \begin_layout Standard
33127
33128
33129 \backslash
33130 /
33131 \end_layout
33132
33133 \end_inset
33134
33135 -dumpall
33136 \begin_inset LatexCommand \index{-\/-dumpall}
33137
33138 \end_inset
33139
33140  option can sometimes be useful in locating optimization problems.
33141  When reporting a bug please make sure you:
33142 \end_layout
33143
33144 \begin_layout Enumerate
33145 Attach the code you are compiling with SDCC.
33146  
33147 \end_layout
33148
33149 \begin_layout Enumerate
33150 Specify the exact command you use to run SDCC, or attach your Makefile.
33151  
33152 \end_layout
33153
33154 \begin_layout Enumerate
33155 Specify the SDCC version (type "
33156 \family sans
33157 \series bold
33158 sdcc -v
33159 \family default
33160 \series default
33161 "), your platform, and operating system.
33162  
33163 \end_layout
33164
33165 \begin_layout Enumerate
33166 Provide an exact copy of any error message or incorrect output.
33167  
33168 \end_layout
33169
33170 \begin_layout Enumerate
33171 Put something meaningful in the subject of your message.
33172 \end_layout
33173
33174 \begin_layout Standard
33175 Please attempt to include these 5 important parts, as applicable, in all
33176  requests for support or when reporting any problems or bugs with SDCC.
33177  Though this will make your message lengthy, it will greatly improve your
33178  chance that SDCC users and developers will be able to help you.
33179  Some SDCC developers are frustrated by bug reports without code provided
33180  that they can use to reproduce and ultimately fix the problem, so please
33181  be sure to provide sample code if you are reporting a bug! 
33182 \end_layout
33183
33184 \begin_layout Standard
33185 Please have a short check that you are using a recent version of SDCC and
33186  the bug is not yet known.
33187  This is the link for reporting bugs: 
33188 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33189
33190 \end_inset
33191
33192 .
33193  With SDCC on average having more than 200 downloads
33194 \begin_inset LatexCommand \index{download}
33195
33196 \end_inset
33197
33198  on sourceforge per day
33199 \begin_inset Foot
33200 status open
33201
33202 \begin_layout Standard
33203 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33204  between 2002 and 2005.
33205  This does not include other methods of distribution.
33206 \end_layout
33207
33208 \end_inset
33209
33210  there must be some users.
33211  So it's not exactly easy to find a new bug.
33212  If you find one we need it: 
33213 \emph on
33214 reporting bugs is good
33215 \emph default
33216 .
33217 \end_layout
33218
33219 \begin_layout Section
33220 Requesting Features
33221 \begin_inset LatexCommand \label{sub:Requesting-Features}
33222
33223 \end_inset
33224
33225
33226 \begin_inset LatexCommand \index{Feature request}
33227
33228 \end_inset
33229
33230
33231 \begin_inset LatexCommand \index{Requesting features}
33232
33233 \end_inset
33234
33235
33236 \end_layout
33237
33238 \begin_layout Standard
33239 Like bug reports feature requests are forwarded to the developer mailing
33240  list.
33241  This is the link for requesting features: 
33242 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33243
33244 \end_inset
33245
33246 .
33247 \end_layout
33248
33249 \begin_layout Section
33250 Submitting patches
33251 \end_layout
33252
33253 \begin_layout Standard
33254 Like bug reports contributed patches are forwarded to the developer mailing
33255  list.
33256  This is the link for submitting patches
33257 \begin_inset LatexCommand \index{Patch submission}
33258
33259 \end_inset
33260
33261
33262 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33263
33264 \end_inset
33265
33266 .
33267 \end_layout
33268
33269 \begin_layout Standard
33270 You need to specify some parameters to the 
33271 \family typewriter
33272 diff
33273 \family default
33274  command for the patches to be useful.
33275  If you modified more than one file a patch created f.e.
33276  with 
33277 \family sans
33278 \series bold
33279
33280 \begin_inset Quotes sld
33281 \end_inset
33282
33283 diff -Naur unmodified_directory modified_directory >my_changes.patch
33284 \begin_inset Quotes srd
33285 \end_inset
33286
33287
33288 \family default
33289 \series default
33290  will be fine, otherwise 
33291 \family sans
33292 \series bold
33293
33294 \begin_inset Quotes sld
33295 \end_inset
33296
33297 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33298 \begin_inset Quotes srd
33299 \end_inset
33300
33301
33302 \series default
33303  
33304 \family default
33305 will do.
33306 \end_layout
33307
33308 \begin_layout Section
33309 Getting Help
33310 \end_layout
33311
33312 \begin_layout Standard
33313 These links should take you directly to the 
33314 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33315
33316 \end_inset
33317
33318
33319 \begin_inset Foot
33320 status open
33321
33322 \begin_layout Standard
33323 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33324  automated messages (mid 2003)
33325 \end_layout
33326
33327 \end_inset
33328
33329  and the 
33330 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33331
33332 \end_inset
33333
33334 , lists
33335 \begin_inset LatexCommand \index{Mailing list(s)}
33336
33337 \end_inset
33338
33339  and forums are archived and searchable so if you are lucky someone already
33340  had a similar problem.
33341  While mails to the lists themselves are delivered promptly their web front
33342  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33343  if you're seriously using SDCC please consider subscribing to the lists.
33344 \end_layout
33345
33346 \begin_layout Section
33347 ChangeLog
33348 \end_layout
33349
33350 \begin_layout Standard
33351 You can follow the status of the Subversion version
33352 \begin_inset LatexCommand \index{version}
33353
33354 \end_inset
33355
33356  of SDCC by watching the Changelog
33357 \begin_inset LatexCommand \index{Changelog}
33358
33359 \end_inset
33360
33361  in the Subversion repository
33362 \size footnotesize
33363  
33364 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33365
33366 \end_inset
33367
33368 .
33369 \end_layout
33370
33371 \begin_layout Section
33372 Subversion Source Code Repository
33373 \end_layout
33374
33375 \begin_layout Standard
33376 The output of 
33377 \family sans
33378 \series bold
33379 sdcc -
33380 \family default
33381
33382 \begin_inset ERT
33383 status open
33384
33385 \begin_layout Standard
33386
33387
33388 \backslash
33389 /
33390 \end_layout
33391
33392 \end_inset
33393
33394
33395 \family sans
33396 -version
33397 \family default
33398 \series default
33399  or the filenames of the snapshot versions of SDCC include date and its
33400  Subversion
33401 \begin_inset LatexCommand \index{Subversion code repository}
33402
33403 \end_inset
33404
33405  number.
33406  Subversion allows to download the source of recent or previous versions
33407  
33408 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33409
33410 \end_inset
33411
33412  (by number or by date).
33413  An on-line source code browser and detailled instructions are also available
33414  there.
33415  SDCC versions starting from 1999 up to now are available (currently the
33416  versions prior to the conversion from cvs
33417 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33418
33419 \end_inset
33420
33421  to Subversion (April 2006) are either by accessible by Subversion or by
33422  cvs).
33423 \end_layout
33424
33425 \begin_layout Section
33426 Release policy
33427 \begin_inset LatexCommand \index{Release policy}
33428
33429 \end_inset
33430
33431
33432 \end_layout
33433
33434 \begin_layout Standard
33435 Historically there often were long delays between official releases and
33436  the sourceforge download area tends to get not updated at all.
33437  Excuses in the past might have referred to problems with live range analysis,
33438  but as this was fixed a while ago, the current problem is that another
33439  excuse has to be found.
33440  Kidding aside, we have to get better there! On the other hand there are
33441  daily snapshots available at 
33442 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33443
33444 \end_inset
33445
33446 , and you can always build the very last version (hopefully with many bugs
33447  fixed, and features added) from the source code available at 
33448 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33449
33450 \end_inset
33451
33452 .
33453  The SDCC Wiki
33454 \begin_inset LatexCommand \index{wiki}
33455
33456 \end_inset
33457
33458
33459 \begin_inset LatexCommand \index{SDCC Wiki}
33460
33461 \end_inset
33462
33463  at 
33464 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33465
33466 \end_inset
33467
33468  also holds some information about past and future releases.
33469 \end_layout
33470
33471 \begin_layout Section
33472 Examples
33473 \begin_inset LatexCommand \index{Examples}
33474
33475 \end_inset
33476
33477
33478 \end_layout
33479
33480 \begin_layout Standard
33481 You'll find some small examples in the directory 
33482 \emph on
33483 sdcc/device/examples/.
33484  
33485 \emph default
33486 More examples and libraries are available at
33487 \emph on
33488  The SDCC Open Knowledge Resource 
33489 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33490
33491 \end_inset
33492
33493  
33494 \emph default
33495 web site or at 
33496 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33497
33498 \end_inset
33499
33500 .
33501 \end_layout
33502
33503 \begin_layout Standard
33504 \begin_inset Note Note
33505 status collapsed
33506
33507 \begin_layout Standard
33508 I did insert a reference to Paul's web site here although it seems rather
33509  dedicated to a specific 8032 board (I think it's okay because it f.e.
33510  shows LCD/Harddisc interface and has a free 8051 monitor.
33511  Independent 8032 board vendors face hard competition of heavily subsidized
33512  development boards anyway).
33513 \end_layout
33514
33515 \begin_layout Standard
33516 Maybe we should include some links to real world applications.
33517  Preferably pointer to pointers (one for each architecture) so this stays
33518  manageable here?
33519 \end_layout
33520
33521 \end_inset
33522
33523
33524 \end_layout
33525
33526 \begin_layout Section
33527 Quality control
33528 \begin_inset LatexCommand \label{sec:Quality-control}
33529
33530 \end_inset
33531
33532
33533 \begin_inset LatexCommand \index{Quality control}
33534
33535 \end_inset
33536
33537
33538 \end_layout
33539
33540 \begin_layout Standard
33541 The compiler is passed through snaphot build compile and build checks.
33542  The so called 
33543 \shape italic
33544 regression tests
33545 \shape default
33546
33547 \begin_inset LatexCommand \index{Regression test}
33548
33549 \end_inset
33550
33551  check that SDCC itself compiles flawlessly on several host platforms (i386,
33552  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33553  and checks the quality of the code generated by SDCC by running the code
33554  for several target platforms through simulators.
33555  The regression test suite comprises more than 100 files which expand to
33556  more than 500 test cases which include more than 4500 tests.
33557  The results of these tests are published daily on SDCC's snapshot page
33558  (click on the red or green symbols on the right side of 
33559 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33560
33561 \end_inset
33562
33563 ).
33564 \end_layout
33565
33566 \begin_layout Standard
33567 There is a separate document 
33568 \shape italic
33569 test_suite.pdf 
33570 \begin_inset LatexCommand \index{Test suite}
33571
33572 \end_inset
33573
33574
33575 \shape default
33576  
33577 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33578
33579 \end_inset
33580
33581  about the regression test suite.
33582 \end_layout
33583
33584 \begin_layout Standard
33585 You'll find the test code in the directory 
33586 \shape italic
33587 sdcc/support/regression
33588 \shape default
33589 .
33590  You can run these tests manually by running 
33591 \family sans
33592 make
33593 \family default
33594  in this directory (or f.e.
33595  
33596 \family sans
33597 \series bold
33598
33599 \begin_inset Quotes sld
33600 \end_inset
33601
33602 make test-mcs51
33603 \begin_inset Quotes srd
33604 \end_inset
33605
33606
33607 \family default
33608 \series default
33609  if you don't want to run the complete tests).
33610  The test code might also be interesting if you want to look for examples
33611 \begin_inset LatexCommand \index{Examples}
33612
33613 \end_inset
33614
33615  checking corner cases of SDCC or if you plan to submit patches
33616 \begin_inset LatexCommand \index{Patch submission}
33617
33618 \end_inset
33619
33620 .
33621 \end_layout
33622
33623 \begin_layout Standard
33624 The PIC14 port uses a different set of regression tests 
33625 \begin_inset LatexCommand \index{Regression test (PIC14)}
33626
33627 \end_inset
33628
33629 , you'll find them in the directory 
33630 \shape italic
33631 sdcc/src/regression
33632 \shape default
33633 .
33634 \end_layout
33635
33636 \begin_layout Section
33637 Use of SDCC in Education
33638 \end_layout
33639
33640 \begin_layout Standard
33641 In short: 
33642 \emph on
33643 highly
33644 \emph default
33645  encouraged
33646 \begin_inset Foot
33647 status open
33648
33649 \begin_layout Standard
33650 the phrase "use in education" might evoke the association "
33651 \emph on
33652 only
33653 \emph default
33654  fit for use in education".
33655  This connotation is not intended but nevertheless risked as the licensing
33656  of SDCC makes it difficult to offer educational discounts
33657 \end_layout
33658
33659 \end_inset
33660
33661 .
33662  If your rationales are to:
33663 \end_layout
33664
33665 \begin_layout Enumerate
33666 give students a chance to understand the 
33667 \emph on
33668 complete
33669 \emph default
33670  steps of code generation
33671 \end_layout
33672
33673 \begin_layout Enumerate
33674 have a curriculum that can be extended for years.
33675  Then you could use an fpga board as target and your curriculum will seamlessly
33676  extend from logic synthesis (
33677 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33678
33679 \end_inset
33680
33681
33682 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33683
33684 \end_inset
33685
33686 ), over assembly programming, to C to FPGA compilers (
33687 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33688
33689 \end_inset
33690
33691 ) and to C.
33692 \end_layout
33693
33694 \begin_layout Enumerate
33695 be able to insert excursions about skills like using a revision control
33696  system, submitting/applying patches, using a type-setting (as opposed to
33697  word-processing) engine LyX/LaTeX, using 
33698 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33699
33700 \end_inset
33701
33702 , following some 
33703 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33704
33705 \end_inset
33706
33707 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33708  Source Software, CPU simulation, compiler regression tests
33709 \begin_inset LatexCommand \index{Regression test}
33710
33711 \end_inset
33712
33713 .
33714  
33715 \newline
33716 And if there should be a shortage of ideas then you can always point students
33717  to the ever-growing feature request list 
33718 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33719
33720 \end_inset
33721
33722 .
33723 \end_layout
33724
33725 \begin_layout Enumerate
33726 not tie students to a specific host platform and instead allow them to use
33727  a host platform of 
33728 \emph on
33729 their
33730 \emph default
33731  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33732  and eventually 
33733 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33734
33735 \end_inset
33736
33737 )
33738 \end_layout
33739
33740 \begin_layout Enumerate
33741 not encourage students to use illegal copies of educational software
33742 \end_layout
33743
33744 \begin_layout Enumerate
33745 be immune to licensing/availability/price changes of the chosen tool chain
33746 \end_layout
33747
33748 \begin_layout Enumerate
33749 be able to change to a new target platform without having to adopt a new
33750  tool chain
33751 \end_layout
33752
33753 \begin_layout Enumerate
33754 have complete control over and insight into the tool chain
33755 \end_layout
33756
33757 \begin_layout Enumerate
33758 make your students aware about the pros and cons of open source software
33759  development
33760 \end_layout
33761
33762 \begin_layout Enumerate
33763 give back to the public as you are probably at least partially publically
33764  funded
33765 \end_layout
33766
33767 \begin_layout Enumerate
33768 give students a chance to publically prove their skills and to possibly
33769  see a world wide impact
33770 \end_layout
33771
33772 \begin_layout Standard
33773 then SDCC is probably among the first choices.
33774  Well, probably SDCC might be the only choice.
33775 \newpage
33776
33777 \end_layout
33778
33779 \begin_layout Chapter
33780 SDCC Technical Data
33781 \end_layout
33782
33783 \begin_layout Section
33784 Optimizations
33785 \begin_inset LatexCommand \index{Optimizations}
33786
33787 \end_inset
33788
33789
33790 \end_layout
33791
33792 \begin_layout Standard
33793 SDCC performs a host of standard optimizations in addition to some MCU specific
33794  optimizations.
33795  
33796 \end_layout
33797
33798 \begin_layout Subsection
33799 Sub-expression Elimination
33800 \begin_inset LatexCommand \index{Subexpression elimination}
33801
33802 \end_inset
33803
33804
33805 \end_layout
33806
33807 \begin_layout Standard
33808 The compiler does local and 
33809 \emph on
33810 g
33811 \emph default
33812 lobal 
33813 \emph on
33814 c
33815 \emph default
33816 ommon 
33817 \emph on
33818 s
33819 \emph default
33820 ubexpression 
33821 \emph on
33822 e
33823 \emph default
33824 limination, e.g.: 
33825 \end_layout
33826
33827 \begin_layout Verse
33828
33829 \family typewriter
33830 i = x + y + 1; 
33831 \newline
33832 j = x + y;
33833 \end_layout
33834
33835 \begin_layout Standard
33836 will be translated to
33837 \end_layout
33838
33839 \begin_layout Verse
33840
33841 \family typewriter
33842 iTemp = x + y; 
33843 \newline
33844 i = iTemp + 1; 
33845 \newline
33846 j = iTemp;
33847 \end_layout
33848
33849 \begin_layout Standard
33850 Some subexpressions are not as obvious as the above example, e.g.:
33851 \end_layout
33852
33853 \begin_layout Verse
33854
33855 \family typewriter
33856 a->b[i].c = 10; 
33857 \newline
33858 a->b[i].d = 11;
33859 \end_layout
33860
33861 \begin_layout Standard
33862 In this case the address arithmetic a->b[i] will be computed only once;
33863  the equivalent code in C would be.
33864 \end_layout
33865
33866 \begin_layout Verse
33867
33868 \family typewriter
33869 iTemp = a->b[i]; 
33870 \newline
33871 iTemp.c = 10; 
33872 \newline
33873 iTemp.d = 11;
33874 \end_layout
33875
33876 \begin_layout Standard
33877 The compiler will try to keep these temporary variables in registers.
33878 \end_layout
33879
33880 \begin_layout Subsection
33881 Dead-Code Elimination
33882 \begin_inset LatexCommand \index{Dead-code elimination}
33883
33884 \end_inset
33885
33886
33887 \end_layout
33888
33889 \begin_layout Verse
33890
33891 \family typewriter
33892 int global;
33893 \newline
33894
33895 \newline
33896 void f () { 
33897 \newline
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 int i; 
33901 \newline
33902 \InsetSpace ~
33903 \InsetSpace ~
33904 i = 1; \InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 /* dead store */ 
33910 \newline
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 global = 1;\InsetSpace ~
33914 /* dead
33915  store */ 
33916 \newline
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 global = 2; 
33920 \newline
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 return; 
33924 \newline
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 global = 3;\InsetSpace ~
33928 /* unreachable */ 
33929 \newline
33930 }
33931 \end_layout
33932
33933 \begin_layout Standard
33934 will be changed to
33935 \end_layout
33936
33937 \begin_layout Verse
33938
33939 \family typewriter
33940 int global;
33941 \newline
33942
33943 \newline
33944 void f () {
33945 \newline
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 global = 2; 
33949 \newline
33950 }
33951 \end_layout
33952
33953 \begin_layout Subsection
33954 Copy-Propagation
33955 \begin_inset LatexCommand \index{Copy propagation}
33956
33957 \end_inset
33958
33959
33960 \end_layout
33961
33962 \begin_layout Verse
33963
33964 \family typewriter
33965 int f() { 
33966 \newline
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 int i, j; 
33970 \newline
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 i = 10; 
33974 \newline
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 j = i; 
33978 \newline
33979 \InsetSpace ~
33980 \InsetSpace ~
33981 return j; 
33982 \newline
33983 }
33984 \end_layout
33985
33986 \begin_layout Standard
33987 will be changed to 
33988 \end_layout
33989
33990 \begin_layout Verse
33991
33992 \family typewriter
33993 int f() { 
33994 \newline
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 int i, j; 
33998 \newline
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 i = 10; 
34002 \newline
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 j = 10; 
34006 \newline
34007 \InsetSpace ~
34008 \InsetSpace ~
34009 return 10; 
34010 \newline
34011 }
34012 \end_layout
34013
34014 \begin_layout Standard
34015 Note: the dead stores created by this copy propagation will be eliminated
34016  by dead-code elimination.
34017 \end_layout
34018
34019 \begin_layout Subsection
34020 Loop Optimizations
34021 \begin_inset LatexCommand \index{Loop optimization}
34022
34023 \end_inset
34024
34025
34026 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34027
34028 \end_inset
34029
34030
34031 \end_layout
34032
34033 \begin_layout Standard
34034 Two types of loop optimizations are done by SDCC 
34035 \emph on
34036 loop invariant
34037 \emph default
34038  lifting and
34039 \emph on
34040  strength reduction
34041 \emph default
34042  of loop induction variables.
34043  In addition to the strength reduction the optimizer marks the induction
34044  variables and the register allocator tries to keep the induction variables
34045  in registers for the duration of the loop.
34046  Because of this preference of the register allocator
34047 \begin_inset LatexCommand \index{Register allocation}
34048
34049 \end_inset
34050
34051 , loop induction optimization causes an increase in register pressure, which
34052  may cause unwanted spilling of other temporary variables into the stack
34053 \begin_inset LatexCommand \index{stack}
34054
34055 \end_inset
34056
34057  / data space.
34058  The compiler will generate a warning message when it is forced to allocate
34059  extra space either on the stack or data space.
34060  If this extra space allocation is undesirable then induction optimization
34061  can be eliminated either for the entire source file (with -
34062 \begin_inset ERT
34063 status collapsed
34064
34065 \begin_layout Standard
34066
34067
34068 \backslash
34069 /
34070 \end_layout
34071
34072 \end_inset
34073
34074 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34075 noinduction
34076 \begin_inset LatexCommand \index{\#pragma noinduction}
34077
34078 \end_inset
34079
34080 .
34081 \newline
34082
34083 \newline
34084 Loop Invariant:
34085 \end_layout
34086
34087 \begin_layout Verse
34088
34089 \family typewriter
34090 for (i = 0 ; i < 100 ; i ++) 
34091 \newline
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 f += k + l;
34097 \end_layout
34098
34099 \begin_layout Standard
34100 changed to
34101 \end_layout
34102
34103 \begin_layout Verse
34104
34105 \family typewriter
34106 itemp = k + l; 
34107 \newline
34108 for (i = 0; i < 100; i++) 
34109 \newline
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 f += itemp;
34115 \end_layout
34116
34117 \begin_layout Standard
34118 As mentioned previously some loop invariants are not as apparent, all static
34119  address computations are also moved out of the loop.
34120 \newline
34121
34122 \newline
34123 Strength Reduction
34124 \begin_inset LatexCommand \index{Strength reduction}
34125
34126 \end_inset
34127
34128 , this optimization substitutes an expression by a cheaper expression:
34129 \end_layout
34130
34131 \begin_layout Verse
34132
34133 \family typewriter
34134 for (i=0;i < 100; i++)
34135 \newline
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 ar[i*5] = i*3;
34141 \end_layout
34142
34143 \begin_layout Standard
34144 changed to
34145 \end_layout
34146
34147 \begin_layout Verse
34148
34149 \family typewriter
34150 itemp1 = 0; 
34151 \newline
34152 itemp2 = 0; 
34153 \newline
34154 for (i=0;i< 100;i++) { 
34155 \newline
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 ar[itemp1] = itemp2; 
34161 \newline
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 itemp1
34167  += 5; 
34168 \newline
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 itemp2 += 3; 
34174 \newline
34175 }
34176 \end_layout
34177
34178 \begin_layout Standard
34179 The more expensive multiplication
34180 \begin_inset LatexCommand \index{Multiplication}
34181
34182 \end_inset
34183
34184  is changed to a less expensive addition.
34185 \end_layout
34186
34187 \begin_layout Subsection
34188 Loop Reversing
34189 \begin_inset LatexCommand \index{Loop reversing}
34190
34191 \end_inset
34192
34193
34194 \end_layout
34195
34196 \begin_layout Standard
34197 This optimization is done to reduce the overhead of checking loop boundaries
34198  for every iteration.
34199  Some simple loops can be reversed and implemented using a 
34200 \begin_inset Quotes eld
34201 \end_inset
34202
34203 decrement and jump if not zero
34204 \begin_inset Quotes erd
34205 \end_inset
34206
34207  instruction.
34208  SDCC checks for the following criterion to determine if a loop is reversible
34209  (note: more sophisticated compilers use data-dependency analysis to make
34210  this determination, SDCC uses a more simple minded analysis).
34211 \end_layout
34212
34213 \begin_layout Itemize
34214 The 'for' loop is of the form 
34215 \newline
34216
34217 \newline
34218
34219 \family typewriter
34220 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34221  += 1])
34222 \newline
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 <for body>
34228 \end_layout
34229
34230 \begin_layout Itemize
34231 The <for body> does not contain 
34232 \begin_inset Quotes eld
34233 \end_inset
34234
34235 continue
34236 \begin_inset Quotes erd
34237 \end_inset
34238
34239  or 'break
34240 \begin_inset Quotes erd
34241 \end_inset
34242
34243 .
34244 \end_layout
34245
34246 \begin_layout Itemize
34247 All goto's are contained within the loop.
34248 \end_layout
34249
34250 \begin_layout Itemize
34251 No function calls within the loop.
34252 \end_layout
34253
34254 \begin_layout Itemize
34255 The loop control variable <sym> is not assigned any value within the loop
34256 \end_layout
34257
34258 \begin_layout Itemize
34259 The loop control variable does NOT participate in any arithmetic operation
34260  within the loop.
34261 \end_layout
34262
34263 \begin_layout Itemize
34264 There are NO switch statements in the loop.
34265 \end_layout
34266
34267 \begin_layout Subsection
34268 Algebraic Simplifications
34269 \end_layout
34270
34271 \begin_layout Standard
34272 SDCC does numerous algebraic simplifications, the following is a small sub-set
34273  of these optimizations.
34274 \end_layout
34275
34276 \begin_layout Verse
34277
34278 \family typewriter
34279 i = j + 0;\InsetSpace ~
34280 \InsetSpace ~
34281 \InsetSpace ~
34282 \InsetSpace ~
34283  /* changed to: */\InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287  i = j; 
34288 \newline
34289 i /= 2;\InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296  /* changed to: */\InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 \InsetSpace ~
34300  i >>= 1; 
34301 \newline
34302 i
34303  = j - j;\InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307  /* changed to: */\InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311  i = 0; 
34312 \newline
34313 i = j / 1;\InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317  /* changed to: */\InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321  i = j;
34322 \end_layout
34323
34324 \begin_layout Standard
34325 Note the subexpressions
34326 \begin_inset LatexCommand \index{Subexpression}
34327
34328 \end_inset
34329
34330  given above are generally introduced by macro expansions or as a result
34331  of copy/constant propagation.
34332 \end_layout
34333
34334 \begin_layout Subsection
34335 'switch' Statements
34336 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34337
34338 \end_inset
34339
34340
34341 \begin_inset LatexCommand \index{switch statement}
34342
34343 \end_inset
34344
34345
34346 \end_layout
34347
34348 \begin_layout Standard
34349 SDCC can optimize switch statements to jump tables
34350 \begin_inset LatexCommand \index{jump tables}
34351
34352 \end_inset
34353
34354 .
34355  It makes the decision based on an estimate of the generated code size.
34356  SDCC is quite liberal in the requirements for jump table generation: 
34357 \end_layout
34358
34359 \begin_layout Itemize
34360 The labels need not be in order, and the starting number need not be one
34361  or zero, the case labels are in numerical sequence or not too many case
34362  labels are missing.
34363 \end_layout
34364
34365 \begin_deeper
34366 \begin_layout Verse
34367
34368 \family typewriter
34369 switch(i) {\InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 switch (i) { 
34396 \newline
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 case 4: ...\InsetSpace ~
34401 \InsetSpace ~
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 case 0: ...
34427  
34428 \newline
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 case 5: ...\InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 case 1: ...
34459  
34460 \newline
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 case 3: ...\InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490
34491 \newline
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 case 6: ...\InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 case 3: ...
34522  
34523 \newline
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 case 7: ...\InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 case 4: ...
34554  
34555 \newline
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 case 8: ...\InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 case 5: ...
34586  
34587 \newline
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 case 9: ...\InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 case 6: ...
34618  
34619 \newline
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 case 10: ...\InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 case 7: ...
34649  
34650 \newline
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 case 11: ...\InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 case 8: ...
34680  
34681 \newline
34682 }\InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 }
34719 \end_layout
34720
34721 \begin_layout Standard
34722 Both the above switch statements will be implemented using a jump-table.
34723  The example to the right side is slightly more efficient as the check for
34724  the lower boundary of the jump-table is not needed.
34725 \end_layout
34726
34727 \end_deeper
34728 \begin_layout Itemize
34729 The number of case labels is not larger than supported by the target architectur
34730 e.
34731 \end_layout
34732
34733 \begin_layout Itemize
34734 If the case labels are not in numerical sequence ('gaps' between cases)
34735  SDCC checks whether a jump table with additionally inserted dummy cases
34736  is still attractive.
34737  
34738 \end_layout
34739
34740 \begin_layout Itemize
34741 If the starting number is not zero and a check for the lower boundary of
34742  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34743  ...
34744  .
34745 \end_layout
34746
34747 \begin_layout Standard
34748 Switch statements which have large gaps in the numeric sequence or those
34749  that have too many case labels can be split into more than one switch statement
34750  for efficient code generation, e.g.:
34751 \end_layout
34752
34753 \begin_layout Verse
34754
34755 \family typewriter
34756 switch (i) { 
34757 \newline
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 case 1: ...
34761  
34762 \newline
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 case 2: ...
34766  
34767 \newline
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 case 3: ...
34771  
34772 \newline
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 case 4: ...
34776  
34777 \newline
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 case 5: ...
34781  
34782 \newline
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 case 6: ...
34786  
34787 \newline
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 case 7: ...
34791  
34792 \newline
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 case 101: ...
34796  
34797 \newline
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 case 102: ...
34801  
34802 \newline
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 case 103: ...
34806  
34807 \newline
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 case 104: ...
34811  
34812 \newline
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 case 105: ...
34816  
34817 \newline
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 case 106: ...
34821  
34822 \newline
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 case 107: ...
34826  
34827 \newline
34828 }
34829 \end_layout
34830
34831 \begin_layout Standard
34832 If the above switch statement is broken down into two switch statements
34833 \end_layout
34834
34835 \begin_layout Verse
34836
34837 \family typewriter
34838 switch (i) { 
34839 \newline
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 case 1: ...
34843  
34844 \newline
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 case 2: ...
34848  
34849 \newline
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 case 3: ...
34853  
34854 \newline
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 case 4: ...
34858  
34859 \newline
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 case 5: ...
34863  
34864 \newline
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 case 6: ...
34868  
34869 \newline
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 case 7: ...
34873  
34874 \newline
34875 }
34876 \end_layout
34877
34878 \begin_layout Standard
34879 and
34880 \end_layout
34881
34882 \begin_layout Verse
34883
34884 \family typewriter
34885 switch (i) { 
34886 \newline
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 case 101: ...
34890  
34891 \newline
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 case 102: ...
34895  
34896 \newline
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 case 103: ...
34900  
34901 \newline
34902 \InsetSpace ~
34903 \InsetSpace ~
34904 case 104: ...
34905  
34906 \newline
34907 \InsetSpace ~
34908 \InsetSpace ~
34909 case 105: ...
34910  
34911 \newline
34912 \InsetSpace ~
34913 \InsetSpace ~
34914 case 106: ...
34915  
34916 \newline
34917 \InsetSpace ~
34918 \InsetSpace ~
34919 case 107: ...
34920  
34921 \newline
34922 }
34923 \end_layout
34924
34925 \begin_layout Standard
34926 then both the switch statements will be implemented using jump-tables whereas
34927  the unmodified switch statement will not be.
34928 \end_layout
34929
34930 \begin_layout Standard
34931 \begin_inset Note Note
34932 status collapsed
34933
34934 \begin_layout Standard
34935 There might be reasons which SDCC cannot know about to either favour or
34936  not favour jump tables.
34937  If the target system has to be as quick for the last switch case as for
34938  the first (pro jump table), or if the switch argument is known to be zero
34939  in the majority of the cases (contra jump table).
34940 \end_layout
34941
34942 \end_inset
34943
34944
34945 \end_layout
34946
34947 \begin_layout Standard
34948 The pragma nojtbound
34949 \begin_inset LatexCommand \index{\#pragma nojtbound}
34950
34951 \end_inset
34952
34953  can be used to turn off checking the 
34954 \emph on
34955 j
34956 \emph default
34957 ump 
34958 \emph on
34959 t
34960 \emph default
34961 able 
34962 \emph on
34963 bound
34964 \emph default
34965 aries.
34966  It has no effect if a default label is supplied.
34967  Use of this pragma is dangerous: if the switch
34968 \begin_inset LatexCommand \index{switch statement}
34969
34970 \end_inset
34971
34972  argument is not matched by a case statement the processor will happily
34973  jump into Nirvana.
34974 \end_layout
34975
34976 \begin_layout Subsection
34977 Bit-shifting Operations
34978 \begin_inset LatexCommand \index{Bit shifting}
34979
34980 \end_inset
34981
34982 .
34983 \end_layout
34984
34985 \begin_layout Standard
34986 Bit shifting is one of the most frequently used operation in embedded programmin
34987 g.
34988  SDCC tries to implement bit-shift operations in the most efficient way
34989  possible, e.g.:
34990 \end_layout
34991
34992 \begin_layout Verse
34993
34994 \family typewriter
34995 unsigned char i;
34996 \newline
34997 ...
34998  
34999 \newline
35000 i >>= 4; 
35001 \newline
35002 ...
35003 \end_layout
35004
35005 \begin_layout Standard
35006 generates the following code:
35007 \end_layout
35008
35009 \begin_layout Verse
35010
35011 \family typewriter
35012 mov\InsetSpace ~
35013  a,_i 
35014 \newline
35015 swap a 
35016 \newline
35017 anl\InsetSpace ~
35018  a,#0x0f 
35019 \newline
35020 mov\InsetSpace ~
35021  _i,a
35022 \end_layout
35023
35024 \begin_layout Standard
35025 In general SDCC will never setup a loop if the shift count is known.
35026  Another example:
35027 \end_layout
35028
35029 \begin_layout Verse
35030
35031 \family typewriter
35032 unsigned int i; 
35033 \newline
35034 ...
35035  
35036 \newline
35037 i >>= 9; 
35038 \newline
35039 ...
35040 \end_layout
35041
35042 \begin_layout Standard
35043 will generate:
35044 \end_layout
35045
35046 \begin_layout Verse
35047
35048 \family typewriter
35049 mov\InsetSpace ~
35050 \InsetSpace ~
35051 a,(_i + 1) 
35052 \newline
35053 mov\InsetSpace ~
35054 \InsetSpace ~
35055 (_i + 1),#0x00 
35056 \newline
35057 clr\InsetSpace ~
35058 \InsetSpace ~
35059
35060 \newline
35061 rrc\InsetSpace ~
35062 \InsetSpace ~
35063
35064 \newline
35065 mov\InsetSpace ~
35066 \InsetSpace ~
35067 _i,a
35068 \end_layout
35069
35070 \begin_layout Subsection
35071 Bit-rotation
35072 \begin_inset LatexCommand \index{Bit rotation}
35073
35074 \end_inset
35075
35076
35077 \end_layout
35078
35079 \begin_layout Standard
35080 A special case of the bit-shift operation is bit rotation
35081 \begin_inset LatexCommand \index{rotating bits}
35082
35083 \end_inset
35084
35085 , SDCC recognizes the following expression to be a left bit-rotation:
35086 \end_layout
35087
35088 \begin_layout Verse
35089
35090 \family typewriter
35091 \series bold
35092 unsigned
35093 \series default
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 char i;\InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100 \InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 /* unsigned is needed for rotation */ 
35108 \newline
35109 ...
35110  
35111 \newline
35112 i = ((i << 1) | (i >> 7)); 
35113 \family default
35114
35115 \newline
35116
35117 \family typewriter
35118 ...
35119 \end_layout
35120
35121 \begin_layout Standard
35122 will generate the following code:
35123 \end_layout
35124
35125 \begin_layout Verse
35126
35127 \family typewriter
35128 mov\InsetSpace ~
35129 \InsetSpace ~
35130 a,_i 
35131 \newline
35132 rl\InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135
35136 \newline
35137 mov\InsetSpace ~
35138 \InsetSpace ~
35139 _i,a
35140 \end_layout
35141
35142 \begin_layout Standard
35143 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35144 ns of this case will also be recognized as bit-rotation, i.e.: 
35145 \end_layout
35146
35147 \begin_layout Verse
35148
35149 \family typewriter
35150 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35151 \end_layout
35152
35153 \begin_layout Subsection
35154 Nibble and Byte Swapping
35155 \end_layout
35156
35157 \begin_layout Standard
35158 Other special cases of the bit-shift operations are nibble or byte swapping
35159 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35160
35161 \end_inset
35162
35163 , SDCC recognizes the following expressions:
35164 \end_layout
35165
35166 \begin_layout Verse
35167
35168 \family typewriter
35169 \series bold
35170 unsigned
35171 \series default
35172 \InsetSpace ~
35173 \InsetSpace ~
35174 char i; 
35175 \newline
35176
35177 \series bold
35178 unsigned
35179 \series default
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 int j; 
35183 \newline
35184 ...
35185  
35186 \newline
35187 i = ((i << 4) | (i >> 4)); 
35188 \family default
35189
35190 \newline
35191
35192 \family typewriter
35193 j = ((j << 8) | (j >> 8)); 
35194 \end_layout
35195
35196 \begin_layout Standard
35197 and generates a swap instruction for the nibble swapping
35198 \begin_inset LatexCommand \index{Nibble swapping}
35199
35200 \end_inset
35201
35202  or move instructions for the byte swapping
35203 \begin_inset LatexCommand \index{Byte swapping}
35204
35205 \end_inset
35206
35207 .
35208  The 
35209 \begin_inset Quotes sld
35210 \end_inset
35211
35212 j
35213 \begin_inset Quotes srd
35214 \end_inset
35215
35216  example can be used to convert from little to big-endian or vice versa.
35217  If you want to change the endianness of a 
35218 \emph on
35219 signed
35220 \emph default
35221  integer you have to cast to 
35222 \family typewriter
35223 (unsigned int)
35224 \family default
35225  first.
35226 \end_layout
35227
35228 \begin_layout Standard
35229 Note that SDCC stores numbers in little-endian
35230 \begin_inset Foot
35231 status open
35232
35233 \begin_layout Standard
35234 Usually 8-bit processors don't care much about endianness.
35235  This is not the case for the standard 8051 which only has an instruction
35236  to increment its 
35237 \emph on
35238 dptr
35239 \emph default
35240
35241 \begin_inset LatexCommand \index{DPTR}
35242
35243 \end_inset
35244
35245 -datapointer
35246 \emph on
35247  
35248 \emph default
35249 so little-endian is the more efficient byte order.
35250 \end_layout
35251
35252 \end_inset
35253
35254
35255 \begin_inset LatexCommand \index{little-endian}
35256
35257 \end_inset
35258
35259
35260 \begin_inset LatexCommand \index{Endianness}
35261
35262 \end_inset
35263
35264  format (i.e.
35265  lowest order first).
35266 \end_layout
35267
35268 \begin_layout Subsection
35269 Highest Order Bit
35270 \begin_inset LatexCommand \index{Highest Order Bit}
35271
35272 \end_inset
35273
35274  / Any Order Bit
35275 \begin_inset LatexCommand \index{Any Order Bit}
35276
35277 \end_inset
35278
35279
35280 \end_layout
35281
35282 \begin_layout Standard
35283 It is frequently required to obtain the highest order bit of an integral
35284  type (long, int, short or char types).
35285  Also obtaining any other order bit is not uncommon.
35286  SDCC recognizes the following expressions to yield the highest order bit
35287  and generates optimized code for it, e.g.:
35288 \end_layout
35289
35290 \begin_layout Verse
35291
35292 \family typewriter
35293 unsigned int gint; 
35294 \newline
35295
35296 \newline
35297 foo () { 
35298 \newline
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 unsigned char hob1, aob1; 
35302 \newline
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 bit hob2, hob3, aob2,
35306  aob3; 
35307 \newline
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 ...
35311  
35312 \newline
35313 \InsetSpace ~
35314 \InsetSpace ~
35315 hob1 = (gint >> 15) & 1; 
35316 \newline
35317 \InsetSpace ~
35318 \InsetSpace ~
35319 hob2 = (gint >> 15) & 1; 
35320 \newline
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 hob3 = gint & 0x8000;
35324  
35325 \newline
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 aob1 = (gint >> 9) & 1; 
35329 \newline
35330 \InsetSpace ~
35331 \InsetSpace ~
35332 aob2 = (gint >> 8) & 1; 
35333 \newline
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 aob3 = gint & 0x0800; 
35337 \newline
35338 \InsetSpace ~
35339 \InsetSpace ~
35340 ..
35341  
35342 \newline
35343 }
35344 \end_layout
35345
35346 \begin_layout Standard
35347 will generate the following code:
35348 \end_layout
35349
35350 \begin_layout Verse
35351
35352 \family typewriter
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378  61 ;\InsetSpace ~
35379  hob.c 7 
35380 \newline
35381 000A E5*01\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  62\InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 \InsetSpace ~
35404  mov\InsetSpace ~
35405 \InsetSpace ~
35406  a,(_gint + 1) 
35407 \newline
35408 000C 23\InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426  63\InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434  rl\InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437  a 
35438 \newline
35439 000D 54 01\InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454
35455  64\InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463  anl\InsetSpace ~
35464 \InsetSpace ~
35465  a,#0x01 
35466 \newline
35467 000F F5*02\InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482  65\InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 \InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490  mov\InsetSpace ~
35491 \InsetSpace ~
35492  _foo_hob1_1_1,a 
35493 \newline
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 \InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519  66 ;\InsetSpace ~
35520  hob.c 8 
35521 \newline
35522 0011 E5*01\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
35538  67\InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545 \InsetSpace ~
35546  mov\InsetSpace ~
35547 \InsetSpace ~
35548  a,(_gint + 1) 
35549 \newline
35550 0013 33\InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568  68\InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 \InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576  rlc\InsetSpace ~
35577 \InsetSpace ~
35578  a 
35579 \newline
35580 0014 92*00\InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595  69\InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603  mov\InsetSpace ~
35604 \InsetSpace ~
35605  _foo_hob2_1_1,c
35606  
35607 \newline
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 \InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633  66 ;\InsetSpace ~
35634  hob.c 9 
35635 \newline
35636 0016 E5*01\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  67\InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 \InsetSpace ~
35656 \InsetSpace ~
35657 \InsetSpace ~
35658 \InsetSpace ~
35659  mov\InsetSpace ~
35660 \InsetSpace ~
35661  a,(_gint + 1) 
35662 \newline
35663 0018 33\InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681  68\InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685 \InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689  rlc\InsetSpace ~
35690 \InsetSpace ~
35691  a 
35692 \newline
35693 0019 92*01\InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708
35709  69\InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717  mov\InsetSpace ~
35718 \InsetSpace ~
35719  _foo_hob3_1_1,c 
35720 \newline
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746  70 ;\InsetSpace ~
35747  hob.c 10 
35748 \newline
35749 001B E5*01\InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764  71\InsetSpace ~
35765 \InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772  mov\InsetSpace ~
35773 \InsetSpace ~
35774  a,(_gint + 1) 
35775 \newline
35776 001D
35777  03\InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795  72\InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 \InsetSpace ~
35800 \InsetSpace ~
35801 \InsetSpace ~
35802 \InsetSpace ~
35803  rr\InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806  a 
35807 \newline
35808 001E 54 01\InsetSpace ~
35809 \InsetSpace ~
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 \InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823  73\InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830 \InsetSpace ~
35831  anl\InsetSpace ~
35832 \InsetSpace ~
35833  a,#0x01 
35834 \newline
35835 0020 F5*03\InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850  74\InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858  mov\InsetSpace ~
35859 \InsetSpace ~
35860  _foo_aob1_1_1,a
35861  
35862 \newline
35863 \InsetSpace ~
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888  75 ;\InsetSpace ~
35889  hob.c 11 
35890 \newline
35891 0022 E5*01\InsetSpace ~
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  76\InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914  mov\InsetSpace ~
35915 \InsetSpace ~
35916  a,(_gint + 1) 
35917 \newline
35918 0024 13\InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936  77\InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944  rrc\InsetSpace ~
35945 \InsetSpace ~
35946  a 
35947 \newline
35948 0025 92*02\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
35964  78\InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972  mov\InsetSpace ~
35973 \InsetSpace ~
35974  _foo_aob2_1_1,c 
35975 \newline
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001  79 ;\InsetSpace ~
36002  hob.c 12 
36003 \newline
36004 0027 E5*01\InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019  80\InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027  mov\InsetSpace ~
36028 \InsetSpace ~
36029  a,(_gint + 1) 
36030 \newline
36031 0029
36032  A2 E3\InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047  81\InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055  mov\InsetSpace ~
36056 \InsetSpace ~
36057  c,acc[3] 
36058 \newline
36059 002B 92*03\InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074  82\InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082  mov\InsetSpace ~
36083 \InsetSpace ~
36084  _foo_aob3_1_1,c 
36085 \end_layout
36086
36087 \begin_layout Standard
36088 Other variations of these cases however will 
36089 \emph on
36090 not
36091 \emph default
36092  be recognized.
36093  They are standard C expressions, so I heartily recommend these be the only
36094  way to get the highest order bit, (it is portable).
36095  Of course it will be recognized even if it is embedded in other expressions,
36096  e.g.:
36097 \end_layout
36098
36099 \begin_layout Verse
36100
36101 \family typewriter
36102 xyz = gint + ((gint >> 15) & 1);
36103 \end_layout
36104
36105 \begin_layout Standard
36106 will still be recognized.
36107 \end_layout
36108
36109 \begin_layout Subsection
36110 Higher Order Byte
36111 \begin_inset LatexCommand \index{Higher Order Byte}
36112
36113 \end_inset
36114
36115  / Higher Order Word
36116 \begin_inset LatexCommand \index{Higher Order Word}
36117
36118 \end_inset
36119
36120
36121 \end_layout
36122
36123 \begin_layout Standard
36124 It is also frequently required to obtain a higher order byte or word of
36125  a larger integral type (long, int or short types).
36126  SDCC recognizes the following expressions to yield the higher order byte
36127  or word and generates optimized code for it, e.g.:
36128 \end_layout
36129
36130 \begin_layout Verse
36131
36132 \family typewriter
36133 unsigned int gint; 
36134 \newline
36135 unsigned long int glong; 
36136 \newline
36137
36138 \newline
36139 foo () { 
36140 \newline
36141 \InsetSpace ~
36142 \InsetSpace ~
36143 unsigned char hob1,
36144  hob2; 
36145 \newline
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 unsigned int how1, how2; 
36149 \newline
36150 \InsetSpace ~
36151 \InsetSpace ~
36152 ...
36153  
36154 \newline
36155 \InsetSpace ~
36156 \InsetSpace ~
36157 hob1 = (gint >> 8) & 0xFF; 
36158 \newline
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 hob2 = glong >> 24; 
36162 \newline
36163 \InsetSpace ~
36164 \InsetSpace ~
36165 how1 = (glong >> 16) & 0xFFFF;
36166  
36167 \newline
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 how2 = glong >> 8; 
36171 \newline
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 ..
36175  
36176 \newline
36177 }
36178 \end_layout
36179
36180 \begin_layout Standard
36181 will generate the following code:
36182 \end_layout
36183
36184 \begin_layout Verse
36185
36186 \family typewriter
36187 \InsetSpace ~
36188 \InsetSpace ~
36189 \InsetSpace ~
36190 \InsetSpace ~
36191 \InsetSpace ~
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 \InsetSpace ~
36195 \InsetSpace ~
36196 \InsetSpace ~
36197 \InsetSpace ~
36198 \InsetSpace ~
36199 \InsetSpace ~
36200 \InsetSpace ~
36201 \InsetSpace ~
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 \InsetSpace ~
36205 \InsetSpace ~
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 \InsetSpace ~
36211 \InsetSpace ~
36212  91 ;\InsetSpace ~
36213  hob.c 15 
36214 \newline
36215 0037 85*01*06\InsetSpace ~
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225 \InsetSpace ~
36226 \InsetSpace ~
36227  92\InsetSpace ~
36228 \InsetSpace ~
36229 \InsetSpace ~
36230 \InsetSpace ~
36231 \InsetSpace ~
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 \InsetSpace ~
36235  mov\InsetSpace ~
36236 \InsetSpace ~
36237  _foo_hob1_1_1,(_gint + 1) 
36238 \newline
36239 \InsetSpace ~
36240 \InsetSpace ~
36241 \InsetSpace ~
36242 \InsetSpace ~
36243 \InsetSpace ~
36244 \InsetSpace ~
36245 \InsetSpace ~
36246 \InsetSpace ~
36247 \InsetSpace ~
36248 \InsetSpace ~
36249 \InsetSpace ~
36250 \InsetSpace ~
36251 \InsetSpace ~
36252 \InsetSpace ~
36253 \InsetSpace ~
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264  93 ;\InsetSpace ~
36265  hob.c
36266  16 
36267 \newline
36268 003A 85*05*07\InsetSpace ~
36269 \InsetSpace ~
36270 \InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 \InsetSpace ~
36280  94\InsetSpace ~
36281 \InsetSpace ~
36282 \InsetSpace ~
36283 \InsetSpace ~
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288  mov\InsetSpace ~
36289 \InsetSpace ~
36290  _foo_hob2_1_1,(_glong + 3) 
36291 \newline
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 \InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 \InsetSpace ~
36299 \InsetSpace ~
36300 \InsetSpace ~
36301 \InsetSpace ~
36302 \InsetSpace ~
36303 \InsetSpace ~
36304 \InsetSpace ~
36305 \InsetSpace ~
36306 \InsetSpace ~
36307 \InsetSpace ~
36308 \InsetSpace ~
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 \InsetSpace ~
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317  95 ;\InsetSpace ~
36318  hob.c 17 
36319 \newline
36320 003D 85*04*08\InsetSpace ~
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 \InsetSpace ~
36324 \InsetSpace ~
36325 \InsetSpace ~
36326 \InsetSpace ~
36327 \InsetSpace ~
36328 \InsetSpace ~
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 \InsetSpace ~
36332
36333  96\InsetSpace ~
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 \InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341  mov\InsetSpace ~
36342 \InsetSpace ~
36343  _foo_how1_1_1,(_glong + 2) 
36344 \newline
36345 0040 85*05*09\InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348 \InsetSpace ~
36349 \InsetSpace ~
36350 \InsetSpace ~
36351 \InsetSpace ~
36352 \InsetSpace ~
36353 \InsetSpace ~
36354 \InsetSpace ~
36355 \InsetSpace ~
36356 \InsetSpace ~
36357  97\InsetSpace ~
36358 \InsetSpace ~
36359 \InsetSpace ~
36360 \InsetSpace ~
36361 \InsetSpace ~
36362 \InsetSpace ~
36363 \InsetSpace ~
36364 \InsetSpace ~
36365  mov\InsetSpace ~
36366 \InsetSpace ~
36367  (_foo_how1_1_1 +
36368  1),(_glong + 3) 
36369 \newline
36370 0043 85*03*0A\InsetSpace ~
36371 \InsetSpace ~
36372 \InsetSpace ~
36373 \InsetSpace ~
36374 \InsetSpace ~
36375 \InsetSpace ~
36376 \InsetSpace ~
36377 \InsetSpace ~
36378 \InsetSpace ~
36379 \InsetSpace ~
36380 \InsetSpace ~
36381 \InsetSpace ~
36382  98\InsetSpace ~
36383 \InsetSpace ~
36384 \InsetSpace ~
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 \InsetSpace ~
36389 \InsetSpace ~
36390  mov\InsetSpace ~
36391 \InsetSpace ~
36392  _foo_how2_1_1,(_glong + 1) 
36393 \newline
36394 0046 85*04*0B\InsetSpace ~
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 \InsetSpace ~
36398 \InsetSpace ~
36399 \InsetSpace ~
36400 \InsetSpace ~
36401 \InsetSpace ~
36402 \InsetSpace ~
36403 \InsetSpace ~
36404 \InsetSpace ~
36405 \InsetSpace ~
36406
36407  99\InsetSpace ~
36408 \InsetSpace ~
36409 \InsetSpace ~
36410 \InsetSpace ~
36411 \InsetSpace ~
36412 \InsetSpace ~
36413 \InsetSpace ~
36414 \InsetSpace ~
36415  mov\InsetSpace ~
36416 \InsetSpace ~
36417  (_foo_how2_1_1 + 1),(_glong + 2) 
36418 \end_layout
36419
36420 \begin_layout Standard
36421 Again, variations of these cases may 
36422 \emph on
36423 not
36424 \emph default
36425  be recognized.
36426  They are standard C expressions, so I heartily recommend these be the only
36427  way to get the higher order byte/word, (it is portable).
36428  Of course it will be recognized even if it is embedded in other expressions,
36429  e.g.:
36430 \end_layout
36431
36432 \begin_layout Verse
36433
36434 \family typewriter
36435 xyz = gint + ((gint >> 8) & 0xFF);
36436 \end_layout
36437
36438 \begin_layout Standard
36439 will still be recognized.
36440 \end_layout
36441
36442 \begin_layout Subsection
36443 Peephole Optimizer
36444 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36445
36446 \end_inset
36447
36448
36449 \begin_inset LatexCommand \index{Peephole optimizer}
36450
36451 \end_inset
36452
36453
36454 \end_layout
36455
36456 \begin_layout Standard
36457 The compiler uses a rule based, pattern matching and re-writing mechanism
36458  for peep-hole optimization.
36459  It is inspired by 
36460 \emph on
36461 copt
36462 \emph default
36463  a peep-hole optimizer by Christopher W.
36464  Fraser (cwfraser\InsetSpace ~
36465 @\InsetSpace ~
36466 microsoft.com).
36467  A default set of rules are compiled into the compiler, additional rules
36468  may be added with the 
36469 \emph on
36470 -
36471 \begin_inset ERT
36472 status collapsed
36473
36474 \begin_layout Standard
36475
36476
36477 \backslash
36478 /
36479 \end_layout
36480
36481 \end_inset
36482
36483 -peep-file
36484 \begin_inset LatexCommand \index{-\/-peep-file}
36485
36486 \end_inset
36487
36488  <filename>
36489 \emph default
36490  option.
36491  The rule language is best illustrated with examples.
36492 \end_layout
36493
36494 \begin_layout Verse
36495
36496 \family typewriter
36497 replace { 
36498 \newline
36499 \InsetSpace ~
36500 \InsetSpace ~
36501 mov %1,a 
36502 \newline
36503 \InsetSpace ~
36504 \InsetSpace ~
36505 mov a,%1
36506 \newline
36507 } by {
36508 \newline
36509 \InsetSpace ~
36510 \InsetSpace ~
36511 mov %1,a
36512 \newline
36513 }
36514 \end_layout
36515
36516 \begin_layout Standard
36517 The above rule will change the following assembly
36518 \begin_inset LatexCommand \index{Assembler routines}
36519
36520 \end_inset
36521
36522  sequence:
36523 \end_layout
36524
36525 \begin_layout Verse
36526
36527 \family typewriter
36528 mov r1,a 
36529 \newline
36530 mov a,r1
36531 \end_layout
36532
36533 \begin_layout Standard
36534 to
36535 \end_layout
36536
36537 \begin_layout Verse
36538
36539 \family typewriter
36540 mov r1,a
36541 \end_layout
36542
36543 \begin_layout Standard
36544 Note: All occurrences of a 
36545 \emph on
36546 %n
36547 \emph default
36548  (pattern variable) must denote the same string.
36549  With the above rule, the assembly sequence:
36550 \end_layout
36551
36552 \begin_layout Verse
36553
36554 \family typewriter
36555 mov r1,a 
36556 \newline
36557 mov a,r2
36558 \end_layout
36559
36560 \begin_layout Standard
36561 will remain unmodified.
36562 \newline
36563
36564 \newline
36565 Other special case optimizations may be added by the
36566  user (via 
36567 \emph on
36568 -
36569 \begin_inset ERT
36570 status collapsed
36571
36572 \begin_layout Standard
36573
36574
36575 \backslash
36576 /
36577 \end_layout
36578
36579 \end_inset
36580
36581 -peep-file option
36582 \emph default
36583 ).
36584  E.g.
36585  some variants of the 8051 MCU
36586 \begin_inset LatexCommand \index{MCS51 variants}
36587
36588 \end_inset
36589
36590  allow only 
36591 \family typewriter
36592 ajmp
36593 \family default
36594  and 
36595 \family typewriter
36596 acall
36597 \family default
36598 .
36599  The following two rules will change all 
36600 \family typewriter
36601 ljmp
36602 \family default
36603  and 
36604 \family typewriter
36605 lcall
36606 \family default
36607  to 
36608 \family typewriter
36609 ajmp
36610 \family default
36611  and 
36612 \family typewriter
36613 acall
36614 \end_layout
36615
36616 \begin_layout Verse
36617
36618 \family typewriter
36619 replace { lcall %1 } by { acall %1 } 
36620 \newline
36621 replace { ljmp %1 } by { ajmp %1 }
36622 \end_layout
36623
36624 \begin_layout Standard
36625 (NOTE: from version 2.7.3 on, you can use option -
36626 \emph on
36627
36628 \begin_inset ERT
36629 status collapsed
36630
36631 \begin_layout Standard
36632
36633
36634 \backslash
36635 /
36636 \end_layout
36637
36638 \end_inset
36639
36640
36641 \emph default
36642 -acall-ajmp
36643 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36644
36645 \end_inset
36646
36647 , which also takes care of aligning the interrupt vectors properly.)
36648 \newline
36649
36650 \end_layout
36651
36652 \begin_layout Standard
36653 The 
36654 \emph on
36655 inline-assembler code
36656 \emph default
36657  is also passed through the peep hole optimizer, thus the peephole optimizer
36658  can also be used as an assembly level macro expander.
36659  The rules themselves are MCU dependent whereas the rule language infra-structur
36660 e is MCU independent.
36661  Peephole optimization rules for other MCU can be easily programmed using
36662  the rule language.
36663 \newline
36664
36665 \newline
36666 The syntax for a rule is as follows:
36667 \end_layout
36668
36669 \begin_layout Verse
36670
36671 \family typewriter
36672 rule := replace [ restart ] '{' <assembly sequence> '
36673 \backslash
36674 n' 
36675 \newline
36676 \InsetSpace ~
36677  \InsetSpace ~
36678  \InsetSpace ~
36679  \InsetSpace ~
36680  \InsetSpace ~
36681  \InsetSpace ~
36682  \InsetSpace ~
36683  \InsetSpace ~
36684  \InsetSpace ~
36685  \InsetSpace ~
36686  \InsetSpace ~
36687  \InsetSpace ~
36688  \InsetSpace ~
36689  \InsetSpace ~
36690  '}' by '{' '
36691 \backslash
36692 n' 
36693 \newline
36694 \InsetSpace ~
36695  \InsetSpace ~
36696  \InsetSpace ~
36697  \InsetSpace ~
36698  \InsetSpace ~
36699  \InsetSpace ~
36700  \InsetSpace ~
36701  \InsetSpace ~
36702  \InsetSpace ~
36703  \InsetSpace ~
36704  \InsetSpace ~
36705  \InsetSpace ~
36706  \InsetSpace ~
36707  \InsetSpace ~
36708  \InsetSpace ~
36709  \InsetSpace ~
36710  <assembly sequence> '
36711 \backslash
36712 n' 
36713 \newline
36714 \InsetSpace ~
36715  \InsetSpace ~
36716  \InsetSpace ~
36717  \InsetSpace ~
36718  \InsetSpace ~
36719  \InsetSpace ~
36720  \InsetSpace ~
36721  \InsetSpace ~
36722  \InsetSpace ~
36723  \InsetSpace ~
36724  \InsetSpace ~
36725  \InsetSpace ~
36726  \InsetSpace ~
36727  \InsetSpace ~
36728  '}' [if <functionName> ] '
36729 \backslash
36730 n' 
36731 \end_layout
36732
36733 \begin_layout Standard
36734 <assembly sequence> := assembly instruction (each instruction including
36735  labels must be on a separate line).
36736 \newline
36737
36738 \newline
36739 The optimizer will apply to the rules
36740  one by one from the top in the sequence of their appearance, it will terminate
36741  when all rules are exhausted.
36742  If the 'restart' option is specified, then the optimizer will start matching
36743  the rules again from the top, this option for a rule is expensive (performance)
36744 , it is intended to be used in situations where a transformation will trigger
36745  the same rule again.
36746  An example of this (not a good one, it has side effects) is the following
36747  rule:
36748 \end_layout
36749
36750 \begin_layout Verse
36751
36752 \family typewriter
36753 replace restart { 
36754 \newline
36755 \InsetSpace ~
36756 \InsetSpace ~
36757 pop %1 
36758 \newline
36759 \InsetSpace ~
36760 \InsetSpace ~
36761 push %1 } by { 
36762 \newline
36763 \InsetSpace ~
36764 \InsetSpace ~
36765 ; nop 
36766 \newline
36767 }
36768 \end_layout
36769
36770 \begin_layout Standard
36771 Note that the replace pattern cannot be a blank, but can be a comment line.
36772  Without the 'restart' option only the innermost 'pop' 'push' pair would
36773  be eliminated, i.e.:
36774 \end_layout
36775
36776 \begin_layout Verse
36777
36778 \family typewriter
36779 pop ar1 
36780 \newline
36781 pop ar2 
36782 \newline
36783 push ar2 
36784 \newline
36785 push ar1
36786 \end_layout
36787
36788 \begin_layout Standard
36789 would result in:
36790 \end_layout
36791
36792 \begin_layout Verse
36793
36794 \family typewriter
36795 pop ar1 
36796 \newline
36797 ; nop 
36798 \newline
36799 push ar1
36800 \end_layout
36801
36802 \begin_layout Standard
36803
36804 \emph on
36805 with
36806 \emph default
36807  the restart option the rule will be applied again to the resulting code
36808  and then all the pop-push pairs will be eliminated to yield:
36809 \end_layout
36810
36811 \begin_layout Verse
36812
36813 \family typewriter
36814 ; nop 
36815 \newline
36816 ; nop
36817 \end_layout
36818
36819 \begin_layout Standard
36820 A conditional function can be attached to a rule.
36821  Attaching rules are somewhat more involved, let me illustrate this with
36822  an example.
36823 \end_layout
36824
36825 \begin_layout Verse
36826
36827 \family typewriter
36828 replace { 
36829 \newline
36830 \InsetSpace ~
36831  \InsetSpace ~
36832  \InsetSpace ~
36833 ljmp %5 
36834 \newline
36835 %2:
36836 \newline
36837 } by { 
36838 \newline
36839 \InsetSpace ~
36840  \InsetSpace ~
36841  \InsetSpace ~
36842 sjmp %5 
36843 \newline
36844 %2:
36845 \newline
36846 } if labelInRange
36847 \end_layout
36848
36849 \begin_layout Standard
36850 The optimizer does a look-up of a function name table defined in function
36851  
36852 \emph on
36853 callFuncByName
36854 \emph default
36855  in the source file SDCCpeeph.c, with the name 
36856 \emph on
36857 labelInRange
36858 \emph default
36859 .
36860  If it finds a corresponding entry the function is called.
36861  Note there can be no parameters specified for these functions, in this
36862  case the use of 
36863 \emph on
36864 %5
36865 \emph default
36866  is crucial, since the function 
36867 \emph on
36868 labelInRange
36869 \emph default
36870  expects to find the label in that particular variable (the hash table containin
36871 g the variable bindings is passed as a parameter).
36872  If you want to code more such functions, take a close look at the function
36873  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36874  Currently implemented are 
36875 \emph on
36876 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36877  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36878 \emph default
36879 and
36880 \emph on
36881  notVolatile
36882 \emph default
36883 .
36884 \end_layout
36885
36886 \begin_layout Standard
36887 I know this whole thing is a little kludgey, but maybe some day we will
36888  have some better means.
36889  If you are looking at this file, you will see the default rules that are
36890  compiled into the compiler, you can add your own rules in the default set
36891  there if you get tired of specifying the -
36892 \begin_inset ERT
36893 status collapsed
36894
36895 \begin_layout Standard
36896
36897
36898 \backslash
36899 /
36900 \end_layout
36901
36902 \end_inset
36903
36904 -peep-file option.
36905 \end_layout
36906
36907 \begin_layout Section
36908 ANSI-Compliance
36909 \begin_inset LatexCommand \index{ANSI-compliance}
36910
36911 \end_inset
36912
36913
36914 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36915
36916 \end_inset
36917
36918
36919 \end_layout
36920
36921 \begin_layout Standard
36922 The latest publically available version of the standard 
36923 \emph on
36924 ISO/IEC 9899 - Programming languages - C
36925 \emph default
36926  should be available at: 
36927 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36928
36929 \end_inset
36930
36931 .
36932 \newline
36933
36934 \end_layout
36935
36936 \begin_layout Standard
36937 Deviations from the compliance:
36938 \end_layout
36939
36940 \begin_layout Itemize
36941 functions are not reentrant
36942 \begin_inset LatexCommand \index{reentrant}
36943
36944 \end_inset
36945
36946  unless explicitly declared as such or the 
36947 \series bold
36948 -
36949 \begin_inset ERT
36950 status collapsed
36951
36952 \begin_layout Standard
36953
36954
36955 \backslash
36956 /
36957 \end_layout
36958
36959 \end_inset
36960
36961 -stack-auto
36962 \begin_inset LatexCommand \index{-\/-stack-auto}
36963
36964 \end_inset
36965
36966
36967 \series default
36968  command line option is specified.
36969 \end_layout
36970
36971 \begin_layout Itemize
36972 structures
36973 \begin_inset LatexCommand \index{struct}
36974
36975 \end_inset
36976
36977  and unions
36978 \begin_inset LatexCommand \index{union}
36979
36980 \end_inset
36981
36982  cannot be assigned values directly, cannot be passed as function parameters
36983  or assigned to each other and cannot be a return value
36984 \begin_inset LatexCommand \index{return value}
36985
36986 \end_inset
36987
36988  from a function, e.g.:
36989 \end_layout
36990
36991 \begin_deeper
36992 \begin_layout Verse
36993
36994 \family typewriter
36995 struct s { ...
36996  }; 
36997 \newline
36998 struct s s1, s2; 
36999 \newline
37000 foo() 
37001 \newline
37002
37003 \newline
37004 \InsetSpace ~
37005 \InsetSpace ~
37006 \InsetSpace ~
37007 \InsetSpace ~
37008 ...
37009  
37010 \newline
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
37016 \newline
37017 \InsetSpace ~
37018 \InsetSpace ~
37019 \InsetSpace ~
37020 \InsetSpace ~
37021 ...
37022  
37023 \newline
37024 }
37025 \newline
37026
37027 \series bold
37028 struct
37029 \series default
37030  s foo1 (
37031 \series bold
37032 struct
37033 \series default
37034  s parms) /* invalid in SDCC although allowed in ANSI */
37035 \newline
37036
37037 \newline
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 struct s rets;
37043  
37044 \newline
37045 \InsetSpace ~
37046 \InsetSpace ~
37047 \InsetSpace ~
37048 \InsetSpace ~
37049 ...
37050  
37051 \newline
37052 \InsetSpace ~
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 \InsetSpace ~
37056 return rets; /* is invalid in SDCC although allowed in ANSI */ 
37057 \newline
37058 }
37059 \end_layout
37060
37061 \end_deeper
37062 \begin_layout Itemize
37063 initialization of structure arrays must be fully braced.
37064 \end_layout
37065
37066 \begin_deeper
37067 \begin_layout Verse
37068
37069 \family typewriter
37070 struct s { char x } a[] = {1, 2};\InsetSpace ~
37071 \InsetSpace ~
37072 \InsetSpace ~
37073 \InsetSpace ~
37074 \InsetSpace ~
37075 /* invalid in SDCC */
37076 \newline
37077 struct s { char x
37078  } a[] = {{1}, {2}}; /* OK */
37079 \end_layout
37080
37081 \end_deeper
37082 \begin_layout Itemize
37083 'long long
37084 \begin_inset LatexCommand \index{long long (not supported)}
37085
37086 \end_inset
37087
37088 ' (64 bit integers
37089 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37090
37091 \end_inset
37092
37093 ) not supported.
37094 \end_layout
37095
37096 \begin_layout Itemize
37097 'double
37098 \begin_inset LatexCommand \index{double (not supported)}
37099
37100 \end_inset
37101
37102 ' precision floating point 
37103 \begin_inset LatexCommand \index{Floating point support}
37104
37105 \end_inset
37106
37107 not supported.
37108 \end_layout
37109
37110 \begin_layout Itemize
37111 Old K&R style
37112 \begin_inset LatexCommand \index{K\&R style}
37113
37114 \end_inset
37115
37116  function declarations are NOT allowed.
37117 \end_layout
37118
37119 \begin_deeper
37120 \begin_layout Verse
37121
37122 \family typewriter
37123 foo(i,j) /* this old style of function declarations */ 
37124 \newline
37125 int i,j; /* is valid
37126  in ANSI but not valid in SDCC */ 
37127 \newline
37128
37129 \newline
37130 \InsetSpace ~
37131 \InsetSpace ~
37132 \InsetSpace ~
37133 \InsetSpace ~
37134 ...
37135  
37136 \newline
37137 }
37138 \end_layout
37139
37140 \end_deeper
37141 \begin_layout Itemize
37142 Most enhancements in C99 are not supported, e.g.:
37143 \end_layout
37144
37145 \begin_deeper
37146 \begin_layout Verse
37147
37148 \family typewriter
37149 for (
37150 \series bold
37151 int
37152 \series default
37153  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37154 \end_layout
37155
37156 \end_deeper
37157 \begin_layout Itemize
37158 But some have been added recently in SDCC 2.7.0.
37159  They must be considered alpha quality however.
37160 \end_layout
37161
37162 \begin_deeper
37163 \begin_layout Verse
37164
37165 \family typewriter
37166 \series bold
37167 inline
37168 \begin_inset LatexCommand \index{inline (not supported)}
37169
37170 \end_inset
37171
37172
37173 \series default
37174  int increment (int a) { return a+1; } /* inlines the increment without
37175  function call overhead */
37176 \newline
37177 int * 
37178 \series bold
37179 restrict
37180 \begin_inset LatexCommand \index{inline (not supported)}
37181
37182 \end_inset
37183
37184
37185 \series default
37186  p; /* accepted but ignored */
37187 \end_layout
37188
37189 \end_deeper
37190 \begin_layout Itemize
37191 Certain words that are valid identifiers in the standard may be reserved
37192  words in SDCC unless the 
37193 \series bold
37194 -
37195 \begin_inset ERT
37196 status collapsed
37197
37198 \begin_layout Standard
37199
37200
37201 \backslash
37202 /
37203 \end_layout
37204
37205 \end_inset
37206
37207 -std-c89
37208 \begin_inset LatexCommand \index{-\/-std-c89}
37209
37210 \end_inset
37211
37212  
37213 \series default
37214 or
37215 \series bold
37216  -
37217 \begin_inset ERT
37218 status collapsed
37219
37220 \begin_layout Standard
37221
37222
37223 \backslash
37224 /
37225 \end_layout
37226
37227 \end_inset
37228
37229 -std-c99
37230 \begin_inset LatexCommand \index{-\/-std-c99}
37231
37232 \end_inset
37233
37234
37235 \series default
37236  command line options are used.
37237  These may include (depending on the selected processor): 'at', 'banked',
37238  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37239 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37240  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37241  '_naked'.
37242  Compliant equivalents of these keywords are always available in a form
37243  that begin with two underscores
37244 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37245
37246 \end_inset
37247
37248 , f.e.
37249  '__data' instead of 'data'.
37250 \end_layout
37251
37252 \begin_layout Itemize
37253 Integer promotion of variable arguments is not performed if the argument
37254  is explicitly taypecasted unless the
37255 \series bold
37256  -
37257 \begin_inset ERT
37258 status collapsed
37259
37260 \begin_layout Standard
37261
37262
37263 \backslash
37264 /
37265 \end_layout
37266
37267 \end_inset
37268
37269 -std-c89
37270 \begin_inset LatexCommand \index{-\/-std-c89}
37271
37272 \end_inset
37273
37274  
37275 \series default
37276 or
37277 \series bold
37278  -
37279 \begin_inset ERT
37280 status collapsed
37281
37282 \begin_layout Standard
37283
37284
37285 \backslash
37286 /
37287 \end_layout
37288
37289 \end_inset
37290
37291 -std-c99
37292 \begin_inset LatexCommand \index{-\/-std-c99}
37293
37294 \end_inset
37295
37296
37297 \series default
37298  command line options are used.
37299 \end_layout
37300
37301 \begin_deeper
37302 \begin_layout Verse
37303
37304 \family typewriter
37305 void vararg_func (char *str, ...) { str; }
37306 \newline
37307
37308 \newline
37309 void main (void)
37310 \newline
37311 {
37312 \newline
37313 \InsetSpace ~
37314 \InsetSpace ~
37315 char c = 10;
37316 \newline
37317
37318 \newline
37319 \InsetSpace ~
37320 \InsetSpace ~
37321 /* argument
37322  u is promoted to int before
37323 \newline
37324 \InsetSpace ~
37325 \InsetSpace ~
37326 \InsetSpace ~
37327 * passing to function */
37328 \newline
37329 \InsetSpace ~
37330 \InsetSpace ~
37331 vararg_func ("%c", c);
37332 \newline
37333
37334 \newline
37335 \InsetSpace ~
37336 \InsetSpace ~
37337 /*
37338  argument u is not promoted to int,
37339 \newline
37340 \InsetSpace ~
37341 \InsetSpace ~
37342 \InsetSpace ~
37343 * it is passed as char to function
37344 \newline
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 \InsetSpace ~
37348 * if
37349  --std-cXX is not defined;
37350 \newline
37351 \InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 * is promoted to int before passing
37355 \newline
37356 \InsetSpace ~
37357 \InsetSpace ~
37358 \InsetSpace ~
37359 * to function
37360  if --std-cXX is defined */
37361 \newline
37362 \InsetSpace ~
37363 \InsetSpace ~
37364 vararg_func ("%bc", (char)u);
37365 \newline
37366 }
37367 \end_layout
37368
37369 \end_deeper
37370 \begin_layout Section
37371 Cyclomatic Complexity
37372 \begin_inset LatexCommand \index{Cyclomatic complexity}
37373
37374 \end_inset
37375
37376
37377 \end_layout
37378
37379 \begin_layout Standard
37380 Cyclomatic complexity of a function is defined as the number of independent
37381  paths the program can take during execution of the function.
37382  This is an important number since it defines the number test cases you
37383  have to generate to validate the function.
37384  The accepted industry standard for complexity number is 10, if the cyclomatic
37385  complexity reported by SDCC exceeds 10 you should think about simplification
37386  of the function logic.
37387  Note that the complexity level is not related to the number of lines of
37388  code in a function.
37389  Large functions can have low complexity, and small functions can have large
37390  complexity levels.
37391  
37392 \newline
37393
37394 \newline
37395 SDCC uses the following formula to compute the complexity:
37396 \newline
37397
37398 \end_layout
37399
37400 \begin_layout Standard
37401 complexity = (number of edges in control flow graph) - (number of nodes
37402  in control flow graph) + 2;
37403 \newline
37404
37405 \newline
37406 Having said that the industry standard is 10,
37407  you should be aware that in some cases it be may unavoidable to have a
37408  complexity level of less than 10.
37409  For example if you have switch statement with more than 10 case labels,
37410  each case label adds one to the complexity level.
37411  The complexity level is by no means an absolute measure of the algorithmic
37412  complexity of the function, it does however provide a good starting point
37413  for which functions you might look at for further optimization.
37414 \end_layout
37415
37416 \begin_layout Section
37417 Retargetting for other Processors
37418 \end_layout
37419
37420 \begin_layout Standard
37421 The issues for retargetting the compiler are far too numerous to be covered
37422  by this document.
37423  What follows is a brief description of each of the seven phases of the
37424  compiler and its MCU dependency.
37425 \end_layout
37426
37427 \begin_layout Itemize
37428 Parsing the source and building the annotated parse tree.
37429  This phase is largely MCU independent (except for the language extensions).
37430  Syntax & semantic checks are also done in this phase, along with some initial
37431  optimizations like back patching labels and the pattern matching optimizations
37432  like bit-rotation etc.
37433 \end_layout
37434
37435 \begin_layout Itemize
37436 The second phase involves generating an intermediate code which can be easy
37437  manipulated during the later phases.
37438  This phase is entirely MCU independent.
37439  The intermediate code generation assumes the target machine has unlimited
37440  number of registers, and designates them with the name iTemp.
37441  The compiler can be made to dump a human readable form of the code generated
37442  by using the -
37443 \begin_inset ERT
37444 status collapsed
37445
37446 \begin_layout Standard
37447
37448
37449 \backslash
37450 /
37451 \end_layout
37452
37453 \end_inset
37454
37455 -dumpraw option.
37456 \end_layout
37457
37458 \begin_layout Itemize
37459 This phase does the bulk of the standard optimizations and is also MCU independe
37460 nt.
37461  This phase can be broken down into several sub-phases:
37462 \newline
37463
37464 \newline
37465 Break down intermediate
37466  code (iCode) into basic blocks.
37467 \newline
37468 Do control flow & data flow analysis on the
37469  basic blocks.
37470 \newline
37471 Do local common subexpression elimination, then global subexpressio
37472 n elimination
37473 \newline
37474 Dead code elimination
37475 \newline
37476 Loop optimizations
37477 \newline
37478 If loop optimizations
37479  caused any changes then do 'global subexpression elimination' and 'dead
37480  code elimination' again.
37481 \end_layout
37482
37483 \begin_layout Itemize
37484 This phase determines the live-ranges; by live range I mean those iTemp
37485  variables defined by the compiler that still survive after all the optimization
37486 s.
37487  Live range analysis
37488 \begin_inset LatexCommand \index{Live range analysis}
37489
37490 \end_inset
37491
37492  is essential for register allocation, since these computation determines
37493  which of these iTemps will be assigned to registers, and for how long.
37494 \end_layout
37495
37496 \begin_layout Itemize
37497 Phase five is register allocation.
37498  There are two parts to this process.
37499 \newline
37500
37501 \newline
37502 The first part I call 'register packing'
37503  (for lack of a better term).
37504  In this case several MCU specific expression folding is done to reduce
37505  register pressure.
37506 \newline
37507
37508 \newline
37509 The second part is more MCU independent and deals with
37510  allocating registers to the remaining live ranges.
37511  A lot of MCU specific code does creep into this phase because of the limited
37512  number of index registers available in the 8051.
37513 \end_layout
37514
37515 \begin_layout Itemize
37516 The Code generation phase is (unhappily), entirely MCU dependent and very
37517  little (if any at all) of this code can be reused for other MCU.
37518  However the scheme for allocating a homogenized assembler operand for each
37519  iCode operand may be reused.
37520 \end_layout
37521
37522 \begin_layout Itemize
37523 As mentioned in the optimization section the peep-hole optimizer is rule
37524  based system, which can reprogrammed for other MCUs.
37525 \end_layout
37526
37527 \begin_layout Standard
37528 More information is available on SDCC Wiki
37529 \begin_inset LatexCommand \index{wiki}
37530
37531 \end_inset
37532
37533  (preliminary link 
37534 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37535
37536 \end_inset
37537
37538 ) and in the thread 
37539 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37540
37541 \end_inset
37542
37543  .
37544 \end_layout
37545
37546 \begin_layout Chapter
37547 Compiler internals
37548 \begin_inset LatexCommand \index{Compiler internals}
37549
37550 \end_inset
37551
37552
37553 \end_layout
37554
37555 \begin_layout Section
37556 The anatomy of the compiler
37557 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37558
37559 \end_inset
37560
37561
37562 \end_layout
37563
37564 \begin_layout Standard
37565
37566 \shape italic
37567 This is an excerpt from an article published in Circuit Cellar Magazine
37568  in 
37569 \series bold
37570 August 2000
37571 \series default
37572 .
37573  It's a little outdated (the compiler is much more efficient now and user/develo
37574 per friendly), but pretty well exposes the guts of it all.
37575 \shape default
37576
37577 \newline
37578
37579 \newline
37580 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37581  It is fairly easy to retarget for other 8-bit MCU.
37582  Here we take a look at some of the internals of the compiler.
37583  
37584 \end_layout
37585
37586 \begin_layout Paragraph*
37587 Parsing
37588 \begin_inset LatexCommand \index{Parsing}
37589
37590 \end_inset
37591
37592  
37593 \end_layout
37594
37595 \begin_layout Standard
37596 Parsing the input source file and creating an AST (Annotated Syntax Tree
37597 \begin_inset LatexCommand \index{Annotated syntax tree}
37598
37599 \end_inset
37600
37601 ).
37602  This phase also involves propagating types (annotating each node of the
37603  parse tree with type information) and semantic analysis.
37604  There are some MCU specific parsing rules.
37605  For example the storage classes, the extended storage classes are MCU specific
37606  while there may be a xdata storage class for 8051 there is no such storage
37607  class for z80 or Atmel AVR.
37608  SDCC allows MCU specific storage class extensions, i.e.
37609  xdata will be treated as a storage class specifier when parsing 8051 C
37610  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37611  C code.
37612 \end_layout
37613
37614 \begin_layout Paragraph*
37615 Generating iCode
37616 \begin_inset LatexCommand \index{iCode}
37617
37618 \end_inset
37619
37620
37621 \end_layout
37622
37623 \begin_layout Standard
37624 Intermediate code generation.
37625  In this phase the AST is broken down into three-operand form (iCode).
37626  These three operand forms are represented as doubly linked lists.
37627  ICode is the term given to the intermediate form generated by the compiler.
37628  ICode example section shows some examples of iCode generated for some simple
37629  C source functions.
37630 \end_layout
37631
37632 \begin_layout Paragraph*
37633 Optimizations
37634 \begin_inset LatexCommand \index{Optimizations}
37635
37636 \end_inset
37637
37638 .
37639 \end_layout
37640
37641 \begin_layout Standard
37642 Bulk of the target independent optimizations is performed in this phase.
37643  The optimizations include constant propagation, common sub-expression eliminati
37644 on, loop invariant code movement, strength reduction of loop induction variables
37645  and dead-code elimination.
37646 \end_layout
37647
37648 \begin_layout Paragraph*
37649 Live range analysis
37650 \begin_inset LatexCommand \index{Live range analysis}
37651
37652 \end_inset
37653
37654
37655 \end_layout
37656
37657 \begin_layout Standard
37658 During intermediate code generation phase, the compiler assumes the target
37659  machine has infinite number of registers and generates a lot of temporary
37660  variables.
37661  The live range computation determines the lifetime of each of these compiler-ge
37662 nerated temporaries.
37663  A picture speaks a thousand words.
37664  ICode example sections show the live range annotations for each of the
37665  operand.
37666  It is important to note here, each iCode is assigned a number in the order
37667  of its execution in the function.
37668  The live ranges are computed in terms of these numbers.
37669  The from number is the number of the iCode which first defines the operand
37670  and the to number signifies the iCode which uses this operand last.
37671 \end_layout
37672
37673 \begin_layout Paragraph*
37674 Register Allocation
37675 \begin_inset LatexCommand \index{Register allocation}
37676
37677 \end_inset
37678
37679
37680 \end_layout
37681
37682 \begin_layout Standard
37683 The register allocation determines the type and number of registers needed
37684  by each operand.
37685  In most MCUs only a few registers can be used for indirect addressing.
37686  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37687  address the internal ram and DPTR to indirectly address the external ram.
37688  The compiler will try to allocate the appropriate register to pointer variables
37689  if it can.
37690  ICode example section shows the operands annotated with the registers assigned
37691  to them.
37692  The compiler will try to keep operands in registers as much as possible;
37693  there are several schemes the compiler uses to do achieve this.
37694  When the compiler runs out of registers the compiler will check to see
37695  if there are any live operands which is not used or defined in the current
37696  basic block being processed, if there are any found then it will push that
37697  operand and use the registers in this block, the operand will then be popped
37698  at the end of the basic block.
37699  
37700 \end_layout
37701
37702 \begin_layout Standard
37703 There are other MCU specific considerations in this phase.
37704  Some MCUs have an accumulator; very short-lived operands could be assigned
37705  to the accumulator instead of a general-purpose register.
37706 \end_layout
37707
37708 \begin_layout Paragraph*
37709 Code generation
37710 \end_layout
37711
37712 \begin_layout Standard
37713 Figure II gives a table of iCode
37714 \begin_inset LatexCommand \index{iCode}
37715
37716 \end_inset
37717
37718  operations supported by the compiler.
37719  The code generation involves translating these operations into corresponding
37720  assembly code for the processor.
37721  This sounds overly simple but that is the essence of code generation.
37722  Some of the iCode operations are generated on a MCU specific manner for
37723  example, the z80 port does not use registers to pass parameters so the
37724  SEND and RECV iCode operations will not be generated, and it also does
37725  not support JUMPTABLES.
37726  
37727 \newline
37728
37729 \end_layout
37730
37731 \begin_layout Standard
37732
37733 \size footnotesize
37734 Figure II 
37735 \begin_inset Tabular
37736 <lyxtabular version="3" rows="39" columns="4">
37737 <features islongtable="true" headBottomDL="true">
37738 <column alignment="block" valignment="top" leftline="true" width="13col%">
37739 <column alignment="left" valignment="top" leftline="true" width="13col%">
37740 <column alignment="block" valignment="top" leftline="true" width="22col%">
37741 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37742 <row topline="true" bottomline="true" endhead="true">
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37744 \begin_inset Text
37745
37746 \begin_layout Standard
37747
37748 \series bold
37749 iCode
37750 \series default
37751
37752 \begin_inset LatexCommand \index{iCode}
37753
37754 \end_inset
37755
37756
37757 \end_layout
37758
37759 \end_inset
37760 </cell>
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_inset Text
37763
37764 \begin_layout Standard
37765
37766 \series bold
37767 Operands
37768 \end_layout
37769
37770 \end_inset
37771 </cell>
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37773 \begin_inset Text
37774
37775 \begin_layout Standard
37776
37777 \series bold
37778 Description
37779 \end_layout
37780
37781 \end_inset
37782 </cell>
37783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37784 \begin_inset Text
37785
37786 \begin_layout Standard
37787
37788 \series bold
37789 C Equivalent
37790 \end_layout
37791
37792 \end_inset
37793 </cell>
37794 </row>
37795 <row topline="true">
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37797 \begin_inset Text
37798
37799 \begin_layout Standard
37800
37801 \size footnotesize
37802 '!'
37803 \end_layout
37804
37805 \end_inset
37806 </cell>
37807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37808 \begin_inset Text
37809
37810 \begin_layout Standard
37811
37812 \size footnotesize
37813 IC_LEFT() IC_RESULT()
37814 \end_layout
37815
37816 \end_inset
37817 </cell>
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37819 \begin_inset Text
37820
37821 \begin_layout Standard
37822
37823 \size footnotesize
37824 NOT operation 
37825 \end_layout
37826
37827 \end_inset
37828 </cell>
37829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37830 \begin_inset Text
37831
37832 \begin_layout Standard
37833
37834 \size footnotesize
37835 IC_RESULT = ! IC_LEFT;
37836 \end_layout
37837
37838 \end_inset
37839 </cell>
37840 </row>
37841 <row topline="true">
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37843 \begin_inset Text
37844
37845 \begin_layout Standard
37846
37847 \size footnotesize
37848 '~'
37849 \end_layout
37850
37851 \end_inset
37852 </cell>
37853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37854 \begin_inset Text
37855
37856 \begin_layout Standard
37857
37858 \size footnotesize
37859 IC_LEFT() IC_RESULT()
37860 \end_layout
37861
37862 \end_inset
37863 </cell>
37864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37865 \begin_inset Text
37866
37867 \begin_layout Standard
37868
37869 \size footnotesize
37870 Bitwise complement of 
37871 \end_layout
37872
37873 \end_inset
37874 </cell>
37875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37876 \begin_inset Text
37877
37878 \begin_layout Standard
37879
37880 \size footnotesize
37881 IC_RESULT = ~IC_LEFT;
37882 \end_layout
37883
37884 \end_inset
37885 </cell>
37886 </row>
37887 <row topline="true">
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37889 \begin_inset Text
37890
37891 \begin_layout Standard
37892
37893 \size footnotesize
37894 RRC
37895 \end_layout
37896
37897 \end_inset
37898 </cell>
37899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37900 \begin_inset Text
37901
37902 \begin_layout Standard
37903
37904 \size footnotesize
37905 IC_LEFT() IC_RESULT()
37906 \end_layout
37907
37908 \end_inset
37909 </cell>
37910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37911 \begin_inset Text
37912
37913 \begin_layout Standard
37914
37915 \size footnotesize
37916 Rotate right with carry
37917 \end_layout
37918
37919 \end_inset
37920 </cell>
37921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37922 \begin_inset Text
37923
37924 \begin_layout Standard
37925
37926 \size footnotesize
37927 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37928 \end_layout
37929
37930 \end_inset
37931 </cell>
37932 </row>
37933 <row topline="true">
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37935 \begin_inset Text
37936
37937 \begin_layout Standard
37938
37939 \size footnotesize
37940 RLC
37941 \end_layout
37942
37943 \end_inset
37944 </cell>
37945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37946 \begin_inset Text
37947
37948 \begin_layout Standard
37949
37950 \size footnotesize
37951 IC_LEFT() IC_RESULT()
37952 \end_layout
37953
37954 \end_inset
37955 </cell>
37956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37957 \begin_inset Text
37958
37959 \begin_layout Standard
37960
37961 \size footnotesize
37962 Rotate left with carry
37963 \end_layout
37964
37965 \end_inset
37966 </cell>
37967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37968 \begin_inset Text
37969
37970 \begin_layout Standard
37971
37972 \size footnotesize
37973 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37974 \end_layout
37975
37976 \end_inset
37977 </cell>
37978 </row>
37979 <row topline="true">
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37981 \begin_inset Text
37982
37983 \begin_layout Standard
37984
37985 \size footnotesize
37986 GETHBIT
37987 \end_layout
37988
37989 \end_inset
37990 </cell>
37991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37992 \begin_inset Text
37993
37994 \begin_layout Standard
37995
37996 \size footnotesize
37997 IC_LEFT() IC_RESULT()
37998 \end_layout
37999
38000 \end_inset
38001 </cell>
38002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38003 \begin_inset Text
38004
38005 \begin_layout Standard
38006
38007 \size footnotesize
38008 Get the highest order bit of IC_LEFT
38009 \end_layout
38010
38011 \end_inset
38012 </cell>
38013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38014 \begin_inset Text
38015
38016 \begin_layout Standard
38017
38018 \size footnotesize
38019 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38020 \end_layout
38021
38022 \end_inset
38023 </cell>
38024 </row>
38025 <row topline="true">
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38027 \begin_inset Text
38028
38029 \begin_layout Standard
38030
38031 \size footnotesize
38032 UNARYMINUS
38033 \end_layout
38034
38035 \end_inset
38036 </cell>
38037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38038 \begin_inset Text
38039
38040 \begin_layout Standard
38041
38042 \size footnotesize
38043 IC_LEFT() IC_RESULT()
38044 \end_layout
38045
38046 \end_inset
38047 </cell>
38048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38049 \begin_inset Text
38050
38051 \begin_layout Standard
38052
38053 \size footnotesize
38054 Unary minus
38055 \end_layout
38056
38057 \end_inset
38058 </cell>
38059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38060 \begin_inset Text
38061
38062 \begin_layout Standard
38063
38064 \size footnotesize
38065 IC_RESULT = - IC_LEFT;
38066 \end_layout
38067
38068 \end_inset
38069 </cell>
38070 </row>
38071 <row topline="true">
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38073 \begin_inset Text
38074
38075 \begin_layout Standard
38076
38077 \size footnotesize
38078 IPUSH
38079 \end_layout
38080
38081 \end_inset
38082 </cell>
38083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38084 \begin_inset Text
38085
38086 \begin_layout Standard
38087
38088 \size footnotesize
38089 IC_LEFT()
38090 \end_layout
38091
38092 \end_inset
38093 </cell>
38094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38095 \begin_inset Text
38096
38097 \begin_layout Standard
38098
38099 \size footnotesize
38100 Push the operand into stack
38101 \end_layout
38102
38103 \end_inset
38104 </cell>
38105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38106 \begin_inset Text
38107
38108 \begin_layout Standard
38109
38110 \size footnotesize
38111 NONE
38112 \end_layout
38113
38114 \end_inset
38115 </cell>
38116 </row>
38117 <row topline="true">
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38119 \begin_inset Text
38120
38121 \begin_layout Standard
38122
38123 \size footnotesize
38124 IPOP
38125 \end_layout
38126
38127 \end_inset
38128 </cell>
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38130 \begin_inset Text
38131
38132 \begin_layout Standard
38133
38134 \size footnotesize
38135 IC_LEFT()
38136 \end_layout
38137
38138 \end_inset
38139 </cell>
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38141 \begin_inset Text
38142
38143 \begin_layout Standard
38144
38145 \size footnotesize
38146 Pop the operand from the stack 
38147 \end_layout
38148
38149 \end_inset
38150 </cell>
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38152 \begin_inset Text
38153
38154 \begin_layout Standard
38155
38156 \size footnotesize
38157 NONE
38158 \end_layout
38159
38160 \end_inset
38161 </cell>
38162 </row>
38163 <row topline="true">
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38165 \begin_inset Text
38166
38167 \begin_layout Standard
38168
38169 \size footnotesize
38170 CALL
38171 \end_layout
38172
38173 \end_inset
38174 </cell>
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38176 \begin_inset Text
38177
38178 \begin_layout Standard
38179
38180 \size footnotesize
38181 IC_LEFT() IC_RESULT()
38182 \end_layout
38183
38184 \end_inset
38185 </cell>
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38187 \begin_inset Text
38188
38189 \begin_layout Standard
38190
38191 \size footnotesize
38192 Call the function represented by IC_LEFT 
38193 \end_layout
38194
38195 \end_inset
38196 </cell>
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38198 \begin_inset Text
38199
38200 \begin_layout Standard
38201
38202 \size footnotesize
38203 IC_RESULT = IC_LEFT();
38204 \end_layout
38205
38206 \end_inset
38207 </cell>
38208 </row>
38209 <row topline="true">
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38211 \begin_inset Text
38212
38213 \begin_layout Standard
38214
38215 \size footnotesize
38216 PCALL
38217 \end_layout
38218
38219 \end_inset
38220 </cell>
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38222 \begin_inset Text
38223
38224 \begin_layout Standard
38225
38226 \size footnotesize
38227 IC_LEFT() IC_RESULT()
38228 \end_layout
38229
38230 \end_inset
38231 </cell>
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38233 \begin_inset Text
38234
38235 \begin_layout Standard
38236
38237 \size footnotesize
38238 Call via function pointer
38239 \end_layout
38240
38241 \end_inset
38242 </cell>
38243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38244 \begin_inset Text
38245
38246 \begin_layout Standard
38247
38248 \size footnotesize
38249 IC_RESULT = (*IC_LEFT)();
38250 \end_layout
38251
38252 \end_inset
38253 </cell>
38254 </row>
38255 <row topline="true">
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38257 \begin_inset Text
38258
38259 \begin_layout Standard
38260
38261 \size footnotesize
38262 RETURN
38263 \end_layout
38264
38265 \end_inset
38266 </cell>
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38268 \begin_inset Text
38269
38270 \begin_layout Standard
38271
38272 \size footnotesize
38273 IC_LEFT()
38274 \end_layout
38275
38276 \end_inset
38277 </cell>
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38279 \begin_inset Text
38280
38281 \begin_layout Standard
38282
38283 \size footnotesize
38284 Return the value in operand IC_LEFT 
38285 \end_layout
38286
38287 \end_inset
38288 </cell>
38289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38290 \begin_inset Text
38291
38292 \begin_layout Standard
38293
38294 \size footnotesize
38295 return IC_LEFT;
38296 \end_layout
38297
38298 \end_inset
38299 </cell>
38300 </row>
38301 <row topline="true">
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38303 \begin_inset Text
38304
38305 \begin_layout Standard
38306
38307 \size footnotesize
38308 LABEL
38309 \end_layout
38310
38311 \end_inset
38312 </cell>
38313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38314 \begin_inset Text
38315
38316 \begin_layout Standard
38317
38318 \size footnotesize
38319 IC_LABEL() 
38320 \end_layout
38321
38322 \end_inset
38323 </cell>
38324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38325 \begin_inset Text
38326
38327 \begin_layout Standard
38328
38329 \size footnotesize
38330 Label
38331 \end_layout
38332
38333 \end_inset
38334 </cell>
38335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38336 \begin_inset Text
38337
38338 \begin_layout Standard
38339
38340 \size footnotesize
38341 IC_LABEL:
38342 \end_layout
38343
38344 \end_inset
38345 </cell>
38346 </row>
38347 <row topline="true">
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38349 \begin_inset Text
38350
38351 \begin_layout Standard
38352
38353 \size footnotesize
38354 GOTO
38355 \end_layout
38356
38357 \end_inset
38358 </cell>
38359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38360 \begin_inset Text
38361
38362 \begin_layout Standard
38363
38364 \size footnotesize
38365 IC_LABEL() 
38366 \end_layout
38367
38368 \end_inset
38369 </cell>
38370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38371 \begin_inset Text
38372
38373 \begin_layout Standard
38374
38375 \size footnotesize
38376 Goto label
38377 \end_layout
38378
38379 \end_inset
38380 </cell>
38381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38382 \begin_inset Text
38383
38384 \begin_layout Standard
38385
38386 \size footnotesize
38387 goto IC_LABEL();
38388 \end_layout
38389
38390 \end_inset
38391 </cell>
38392 </row>
38393 <row topline="true">
38394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38395 \begin_inset Text
38396
38397 \begin_layout Standard
38398
38399 \size footnotesize
38400 '+'
38401 \end_layout
38402
38403 \end_inset
38404 </cell>
38405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38406 \begin_inset Text
38407
38408 \begin_layout Standard
38409
38410 \size footnotesize
38411 IC_LEFT() IC_RIGHT() IC_RESULT()
38412 \end_layout
38413
38414 \end_inset
38415 </cell>
38416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38417 \begin_inset Text
38418
38419 \begin_layout Standard
38420
38421 \size footnotesize
38422 Addition
38423 \end_layout
38424
38425 \end_inset
38426 </cell>
38427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38428 \begin_inset Text
38429
38430 \begin_layout Standard
38431
38432 \size footnotesize
38433 IC_RESULT = IC_LEFT + IC_RIGHT
38434 \end_layout
38435
38436 \end_inset
38437 </cell>
38438 </row>
38439 <row topline="true">
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38441 \begin_inset Text
38442
38443 \begin_layout Standard
38444
38445 \size footnotesize
38446 '-'
38447 \end_layout
38448
38449 \end_inset
38450 </cell>
38451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38452 \begin_inset Text
38453
38454 \begin_layout Standard
38455
38456 \size footnotesize
38457 IC_LEFT() IC_RIGHT() IC_RESULT()
38458 \end_layout
38459
38460 \end_inset
38461 </cell>
38462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38463 \begin_inset Text
38464
38465 \begin_layout Standard
38466
38467 \size footnotesize
38468 Subtraction
38469 \end_layout
38470
38471 \end_inset
38472 </cell>
38473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38474 \begin_inset Text
38475
38476 \begin_layout Standard
38477
38478 \size footnotesize
38479 IC_RESULT = IC_LEFT - IC_RIGHT 
38480 \end_layout
38481
38482 \end_inset
38483 </cell>
38484 </row>
38485 <row topline="true">
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38487 \begin_inset Text
38488
38489 \begin_layout Standard
38490
38491 \size footnotesize
38492 '*'
38493 \end_layout
38494
38495 \end_inset
38496 </cell>
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38498 \begin_inset Text
38499
38500 \begin_layout Standard
38501
38502 \size footnotesize
38503 IC_LEFT() IC_RIGHT() IC_RESULT()
38504 \end_layout
38505
38506 \end_inset
38507 </cell>
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38509 \begin_inset Text
38510
38511 \begin_layout Standard
38512
38513 \size footnotesize
38514 Multiplication 
38515 \end_layout
38516
38517 \end_inset
38518 </cell>
38519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38520 \begin_inset Text
38521
38522 \begin_layout Standard
38523
38524 \size footnotesize
38525 IC_RESULT = IC_LEFT * IC_RIGHT;
38526 \end_layout
38527
38528 \end_inset
38529 </cell>
38530 </row>
38531 <row topline="true">
38532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38533 \begin_inset Text
38534
38535 \begin_layout Standard
38536
38537 \size footnotesize
38538 '/'
38539 \end_layout
38540
38541 \end_inset
38542 </cell>
38543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38544 \begin_inset Text
38545
38546 \begin_layout Standard
38547
38548 \size footnotesize
38549 IC_LEFT() IC_RIGHT() IC_RESULT()
38550 \end_layout
38551
38552 \end_inset
38553 </cell>
38554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38555 \begin_inset Text
38556
38557 \begin_layout Standard
38558
38559 \size footnotesize
38560 Division
38561 \end_layout
38562
38563 \end_inset
38564 </cell>
38565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38566 \begin_inset Text
38567
38568 \begin_layout Standard
38569
38570 \size footnotesize
38571 IC_RESULT = IC_LEFT / IC_RIGHT;
38572 \end_layout
38573
38574 \end_inset
38575 </cell>
38576 </row>
38577 <row topline="true">
38578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38579 \begin_inset Text
38580
38581 \begin_layout Standard
38582
38583 \size footnotesize
38584 '%'
38585 \end_layout
38586
38587 \end_inset
38588 </cell>
38589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38590 \begin_inset Text
38591
38592 \begin_layout Standard
38593
38594 \size footnotesize
38595 IC_LEFT() IC_RIGHT() IC_RESULT()
38596 \end_layout
38597
38598 \end_inset
38599 </cell>
38600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38601 \begin_inset Text
38602
38603 \begin_layout Standard
38604
38605 \size footnotesize
38606 Modulus
38607 \end_layout
38608
38609 \end_inset
38610 </cell>
38611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38612 \begin_inset Text
38613
38614 \begin_layout Standard
38615
38616 \size footnotesize
38617 IC_RESULT = IC_LEFT % IC_RIGHT;
38618 \end_layout
38619
38620 \end_inset
38621 </cell>
38622 </row>
38623 <row topline="true">
38624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38625 \begin_inset Text
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 '<'
38631 \end_layout
38632
38633 \end_inset
38634 </cell>
38635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38636 \begin_inset Text
38637
38638 \begin_layout Standard
38639
38640 \size footnotesize
38641 IC_LEFT() IC_RIGHT() IC_RESULT()
38642 \end_layout
38643
38644 \end_inset
38645 </cell>
38646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38647 \begin_inset Text
38648
38649 \begin_layout Standard
38650
38651 \size footnotesize
38652 Less than
38653 \end_layout
38654
38655 \end_inset
38656 </cell>
38657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38658 \begin_inset Text
38659
38660 \begin_layout Standard
38661
38662 \size footnotesize
38663 IC_RESULT = IC_LEFT < IC_RIGHT;
38664 \end_layout
38665
38666 \end_inset
38667 </cell>
38668 </row>
38669 <row topline="true">
38670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38671 \begin_inset Text
38672
38673 \begin_layout Standard
38674
38675 \size footnotesize
38676 '>'
38677 \end_layout
38678
38679 \end_inset
38680 </cell>
38681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38682 \begin_inset Text
38683
38684 \begin_layout Standard
38685
38686 \size footnotesize
38687 IC_LEFT() IC_RIGHT() IC_RESULT()
38688 \end_layout
38689
38690 \end_inset
38691 </cell>
38692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38693 \begin_inset Text
38694
38695 \begin_layout Standard
38696
38697 \size footnotesize
38698 Greater than 
38699 \end_layout
38700
38701 \end_inset
38702 </cell>
38703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38704 \begin_inset Text
38705
38706 \begin_layout Standard
38707
38708 \size footnotesize
38709 IC_RESULT = IC_LEFT > IC_RIGHT;
38710 \end_layout
38711
38712 \end_inset
38713 </cell>
38714 </row>
38715 <row topline="true">
38716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38717 \begin_inset Text
38718
38719 \begin_layout Standard
38720
38721 \size footnotesize
38722 EQ_OP
38723 \end_layout
38724
38725 \end_inset
38726 </cell>
38727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38728 \begin_inset Text
38729
38730 \begin_layout Standard
38731
38732 \size footnotesize
38733 IC_LEFT() IC_RIGHT() IC_RESULT()
38734 \end_layout
38735
38736 \end_inset
38737 </cell>
38738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38739 \begin_inset Text
38740
38741 \begin_layout Standard
38742
38743 \size footnotesize
38744 Equal to 
38745 \end_layout
38746
38747 \end_inset
38748 </cell>
38749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38750 \begin_inset Text
38751
38752 \begin_layout Standard
38753
38754 \size footnotesize
38755 IC_RESULT = IC_LEFT == IC_RIGHT;
38756 \end_layout
38757
38758 \end_inset
38759 </cell>
38760 </row>
38761 <row topline="true">
38762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38763 \begin_inset Text
38764
38765 \begin_layout Standard
38766
38767 \size footnotesize
38768 AND_OP
38769 \end_layout
38770
38771 \end_inset
38772 </cell>
38773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38774 \begin_inset Text
38775
38776 \begin_layout Standard
38777
38778 \size footnotesize
38779 IC_LEFT() IC_RIGHT() IC_RESULT() 
38780 \end_layout
38781
38782 \end_inset
38783 </cell>
38784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38785 \begin_inset Text
38786
38787 \begin_layout Standard
38788
38789 \size footnotesize
38790 Logical and operation
38791 \end_layout
38792
38793 \end_inset
38794 </cell>
38795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38796 \begin_inset Text
38797
38798 \begin_layout Standard
38799
38800 \size footnotesize
38801 IC_RESULT = IC_LEFT && IC_RIGHT; 
38802 \end_layout
38803
38804 \end_inset
38805 </cell>
38806 </row>
38807 <row topline="true">
38808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38809 \begin_inset Text
38810
38811 \begin_layout Standard
38812
38813 \size footnotesize
38814 OR_OP
38815 \end_layout
38816
38817 \end_inset
38818 </cell>
38819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38820 \begin_inset Text
38821
38822 \begin_layout Standard
38823
38824 \size footnotesize
38825 IC_LEFT() IC_RIGHT() IC_RESULT() 
38826 \end_layout
38827
38828 \end_inset
38829 </cell>
38830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38831 \begin_inset Text
38832
38833 \begin_layout Standard
38834
38835 \size footnotesize
38836 Logical or operation 
38837 \end_layout
38838
38839 \end_inset
38840 </cell>
38841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38842 \begin_inset Text
38843
38844 \begin_layout Standard
38845
38846 \size footnotesize
38847 IC_RESULT = IC_LEFT || IC_RIGHT; 
38848 \end_layout
38849
38850 \end_inset
38851 </cell>
38852 </row>
38853 <row topline="true">
38854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38855 \begin_inset Text
38856
38857 \begin_layout Standard
38858
38859 \size footnotesize
38860 '^'
38861 \end_layout
38862
38863 \end_inset
38864 </cell>
38865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38866 \begin_inset Text
38867
38868 \begin_layout Standard
38869
38870 \size footnotesize
38871 IC_LEFT() IC_RIGHT() IC_RESULT() 
38872 \end_layout
38873
38874 \end_inset
38875 </cell>
38876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38877 \begin_inset Text
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 Exclusive OR
38883 \end_layout
38884
38885 \end_inset
38886 </cell>
38887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38888 \begin_inset Text
38889
38890 \begin_layout Standard
38891
38892 \size footnotesize
38893 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38894 \end_layout
38895
38896 \end_inset
38897 </cell>
38898 </row>
38899 <row topline="true">
38900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38901 \begin_inset Text
38902
38903 \begin_layout Standard
38904
38905 \size footnotesize
38906 '|'
38907 \end_layout
38908
38909 \end_inset
38910 </cell>
38911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38912 \begin_inset Text
38913
38914 \begin_layout Standard
38915
38916 \size footnotesize
38917 IC_LEFT() IC_RIGHT() IC_RESULT() 
38918 \end_layout
38919
38920 \end_inset
38921 </cell>
38922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38923 \begin_inset Text
38924
38925 \begin_layout Standard
38926
38927 \size footnotesize
38928 Bitwise OR 
38929 \end_layout
38930
38931 \end_inset
38932 </cell>
38933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38934 \begin_inset Text
38935
38936 \begin_layout Standard
38937
38938 \size footnotesize
38939 IC_RESULT = IC_LEFT | IC_RIGHT;
38940 \end_layout
38941
38942 \end_inset
38943 </cell>
38944 </row>
38945 <row topline="true">
38946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38947 \begin_inset Text
38948
38949 \begin_layout Standard
38950
38951 \size footnotesize
38952 BITWISEAND
38953 \end_layout
38954
38955 \end_inset
38956 </cell>
38957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38958 \begin_inset Text
38959
38960 \begin_layout Standard
38961
38962 \size footnotesize
38963 IC_LEFT() IC_RIGHT() IC_RESULT()
38964 \end_layout
38965
38966 \end_inset
38967 </cell>
38968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38969 \begin_inset Text
38970
38971 \begin_layout Standard
38972
38973 \size footnotesize
38974 Bitwise AND 
38975 \end_layout
38976
38977 \end_inset
38978 </cell>
38979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38980 \begin_inset Text
38981
38982 \begin_layout Standard
38983
38984 \size footnotesize
38985 IC_RESULT = IC_LEFT & IC_RIGHT;
38986 \end_layout
38987
38988 \end_inset
38989 </cell>
38990 </row>
38991 <row topline="true">
38992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38993 \begin_inset Text
38994
38995 \begin_layout Standard
38996
38997 \size footnotesize
38998 LEFT_OP
38999 \end_layout
39000
39001 \end_inset
39002 </cell>
39003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39004 \begin_inset Text
39005
39006 \begin_layout Standard
39007
39008 \size footnotesize
39009 IC_LEFT() IC_RIGHT() IC_RESULT()
39010 \end_layout
39011
39012 \end_inset
39013 </cell>
39014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39015 \begin_inset Text
39016
39017 \begin_layout Standard
39018
39019 \size footnotesize
39020 Left shift 
39021 \end_layout
39022
39023 \end_inset
39024 </cell>
39025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39026 \begin_inset Text
39027
39028 \begin_layout Standard
39029
39030 \size footnotesize
39031 IC_RESULT = IC_LEFT << IC_RIGHT 
39032 \end_layout
39033
39034 \end_inset
39035 </cell>
39036 </row>
39037 <row topline="true">
39038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39039 \begin_inset Text
39040
39041 \begin_layout Standard
39042
39043 \size footnotesize
39044 RIGHT_OP
39045 \end_layout
39046
39047 \end_inset
39048 </cell>
39049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39050 \begin_inset Text
39051
39052 \begin_layout Standard
39053
39054 \size footnotesize
39055 IC_LEFT() IC_RIGHT() IC_RESULT()
39056 \end_layout
39057
39058 \end_inset
39059 </cell>
39060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39061 \begin_inset Text
39062
39063 \begin_layout Standard
39064
39065 \size footnotesize
39066 Right shift
39067 \end_layout
39068
39069 \end_inset
39070 </cell>
39071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39072 \begin_inset Text
39073
39074 \begin_layout Standard
39075
39076 \size footnotesize
39077 IC_RESULT = IC_LEFT >> IC_RIGHT 
39078 \end_layout
39079
39080 \end_inset
39081 </cell>
39082 </row>
39083 <row topline="true">
39084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39085 \begin_inset Text
39086
39087 \begin_layout Standard
39088
39089 \size footnotesize
39090 GET_VALUE_
39091 \newline
39092 AT_ ADDRESS
39093 \end_layout
39094
39095 \end_inset
39096 </cell>
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39098 \begin_inset Text
39099
39100 \begin_layout Standard
39101
39102 \size footnotesize
39103 IC_LEFT() IC_RESULT()
39104 \end_layout
39105
39106 \end_inset
39107 </cell>
39108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39109 \begin_inset Text
39110
39111 \begin_layout Standard
39112
39113 \size footnotesize
39114 Indirect fetch 
39115 \end_layout
39116
39117 \end_inset
39118 </cell>
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39120 \begin_inset Text
39121
39122 \begin_layout Standard
39123
39124 \size footnotesize
39125 IC_RESULT = (*IC_LEFT);
39126 \end_layout
39127
39128 \end_inset
39129 </cell>
39130 </row>
39131 <row topline="true">
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 POINTER_SET
39139 \end_layout
39140
39141 \end_inset
39142 </cell>
39143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39144 \begin_inset Text
39145
39146 \begin_layout Standard
39147
39148 \size footnotesize
39149 IC_RIGHT() IC_RESULT() 
39150 \end_layout
39151
39152 \end_inset
39153 </cell>
39154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39155 \begin_inset Text
39156
39157 \begin_layout Standard
39158
39159 \size footnotesize
39160 Indirect set
39161 \end_layout
39162
39163 \end_inset
39164 </cell>
39165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39166 \begin_inset Text
39167
39168 \begin_layout Standard
39169
39170 \size footnotesize
39171 (*IC_RESULT) = IC_RIGHT;
39172 \end_layout
39173
39174 \end_inset
39175 </cell>
39176 </row>
39177 <row topline="true">
39178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39179 \begin_inset Text
39180
39181 \begin_layout Standard
39182
39183 \size footnotesize
39184 '='
39185 \end_layout
39186
39187 \end_inset
39188 </cell>
39189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39190 \begin_inset Text
39191
39192 \begin_layout Standard
39193
39194 \size footnotesize
39195 IC_RIGHT() IC_RESULT()
39196 \end_layout
39197
39198 \end_inset
39199 </cell>
39200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39201 \begin_inset Text
39202
39203 \begin_layout Standard
39204
39205 \size footnotesize
39206 Assignment
39207 \end_layout
39208
39209 \end_inset
39210 </cell>
39211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39212 \begin_inset Text
39213
39214 \begin_layout Standard
39215
39216 \size footnotesize
39217 IC_RESULT = IC_RIGHT;
39218 \end_layout
39219
39220 \end_inset
39221 </cell>
39222 </row>
39223 <row topline="true">
39224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39225 \begin_inset Text
39226
39227 \begin_layout Standard
39228
39229 \size footnotesize
39230 IFX
39231 \end_layout
39232
39233 \end_inset
39234 </cell>
39235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39236 \begin_inset Text
39237
39238 \begin_layout Standard
39239
39240 \size footnotesize
39241 IC_COND IC_TRUE IC_LABEL
39242 \end_layout
39243
39244 \end_inset
39245 </cell>
39246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39247 \begin_inset Text
39248
39249 \begin_layout Standard
39250
39251 \size footnotesize
39252 Conditional jump.
39253  If true label is present then jump to true label if condition is true else
39254  jump to false label if condition is false 
39255 \end_layout
39256
39257 \end_inset
39258 </cell>
39259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39260 \begin_inset Text
39261
39262 \begin_layout Standard
39263
39264 \size footnotesize
39265 if (IC_COND) goto IC_TRUE; 
39266 \newline
39267 \InsetSpace ~
39268 \InsetSpace ~
39269 Or 
39270 \newline
39271 If (!IC_COND) goto IC_FALSE;
39272 \end_layout
39273
39274 \end_inset
39275 </cell>
39276 </row>
39277 <row topline="true">
39278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39279 \begin_inset Text
39280
39281 \begin_layout Standard
39282
39283 \size footnotesize
39284 ADDRESS_OF
39285 \end_layout
39286
39287 \end_inset
39288 </cell>
39289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39290 \begin_inset Text
39291
39292 \begin_layout Standard
39293
39294 \size footnotesize
39295 IC_LEFT() IC_RESULT()
39296 \end_layout
39297
39298 \end_inset
39299 </cell>
39300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39301 \begin_inset Text
39302
39303 \begin_layout Standard
39304
39305 \size footnotesize
39306 Address of 
39307 \end_layout
39308
39309 \end_inset
39310 </cell>
39311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39312 \begin_inset Text
39313
39314 \begin_layout Standard
39315
39316 \size footnotesize
39317 IC_RESULT = &IC_LEFT();
39318 \end_layout
39319
39320 \end_inset
39321 </cell>
39322 </row>
39323 <row topline="true">
39324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39325 \begin_inset Text
39326
39327 \begin_layout Standard
39328
39329 \size footnotesize
39330 JUMPTABLE
39331 \end_layout
39332
39333 \end_inset
39334 </cell>
39335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39336 \begin_inset Text
39337
39338 \begin_layout Standard
39339
39340 \size footnotesize
39341 IC_JTCOND IC_JTLABELS
39342 \end_layout
39343
39344 \end_inset
39345 </cell>
39346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39347 \begin_inset Text
39348
39349 \begin_layout Standard
39350
39351 \size footnotesize
39352 Jump to list of labels depending on the value of JTCOND
39353 \end_layout
39354
39355 \end_inset
39356 </cell>
39357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39358 \begin_inset Text
39359
39360 \begin_layout Standard
39361
39362 \size footnotesize
39363 Switch statement
39364 \end_layout
39365
39366 \end_inset
39367 </cell>
39368 </row>
39369 <row topline="true">
39370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39371 \begin_inset Text
39372
39373 \begin_layout Standard
39374
39375 \size footnotesize
39376 CAST
39377 \end_layout
39378
39379 \end_inset
39380 </cell>
39381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39382 \begin_inset Text
39383
39384 \begin_layout Standard
39385
39386 \size footnotesize
39387 IC_RIGHT() IC_LEFT() IC_RESULT()
39388 \end_layout
39389
39390 \end_inset
39391 </cell>
39392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39393 \begin_inset Text
39394
39395 \begin_layout Standard
39396
39397 \size footnotesize
39398 Cast types 
39399 \end_layout
39400
39401 \end_inset
39402 </cell>
39403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39404 \begin_inset Text
39405
39406 \begin_layout Standard
39407
39408 \size footnotesize
39409 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39410 \end_layout
39411
39412 \end_inset
39413 </cell>
39414 </row>
39415 <row topline="true">
39416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39417 \begin_inset Text
39418
39419 \begin_layout Standard
39420
39421 \size footnotesize
39422 SEND
39423 \end_layout
39424
39425 \end_inset
39426 </cell>
39427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39428 \begin_inset Text
39429
39430 \begin_layout Standard
39431
39432 \size footnotesize
39433 IC_LEFT()
39434 \end_layout
39435
39436 \end_inset
39437 </cell>
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39439 \begin_inset Text
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 This is used for passing parameters in registers; 
39445 \newline
39446 move IC_LEFT to the next
39447  available parameter register.
39448 \end_layout
39449
39450 \end_inset
39451 </cell>
39452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39453 \begin_inset Text
39454
39455 \begin_layout Standard
39456
39457 \size footnotesize
39458 None
39459 \end_layout
39460
39461 \end_inset
39462 </cell>
39463 </row>
39464 <row topline="true">
39465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39466 \begin_inset Text
39467
39468 \begin_layout Standard
39469
39470 \size footnotesize
39471 RECV
39472 \end_layout
39473
39474 \end_inset
39475 </cell>
39476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39477 \begin_inset Text
39478
39479 \begin_layout Standard
39480
39481 \size footnotesize
39482 IC_RESULT()
39483 \end_layout
39484
39485 \end_inset
39486 </cell>
39487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39488 \begin_inset Text
39489
39490 \begin_layout Standard
39491
39492 \size footnotesize
39493 This is used for receiving parameters passed in registers;
39494 \newline
39495 Move the values
39496  in the next parameter register to IC_RESULT 
39497 \end_layout
39498
39499 \end_inset
39500 </cell>
39501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39502 \begin_inset Text
39503
39504 \begin_layout Standard
39505
39506 \size footnotesize
39507 None
39508 \end_layout
39509
39510 \end_inset
39511 </cell>
39512 </row>
39513 <row topline="true" bottomline="true">
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_inset Text
39516
39517 \begin_layout Standard
39518
39519 \shape slanted
39520 \size footnotesize
39521 (some more have been added)
39522 \end_layout
39523
39524 \end_inset
39525 </cell>
39526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39527 \begin_inset Text
39528
39529 \begin_layout Standard
39530
39531 \end_layout
39532
39533 \end_inset
39534 </cell>
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39536 \begin_inset Text
39537
39538 \begin_layout Standard
39539
39540 \end_layout
39541
39542 \end_inset
39543 </cell>
39544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39545 \begin_inset Text
39546
39547 \begin_layout Standard
39548
39549 \shape slanted
39550 \size footnotesize
39551 see f.e.
39552  
39553 \family typewriter
39554 gen51Code()
39555 \family default
39556  in 
39557 \family typewriter
39558 src/mcs51/gen.c
39559 \end_layout
39560
39561 \end_inset
39562 </cell>
39563 </row>
39564 </lyxtabular>
39565
39566 \end_inset
39567
39568
39569 \end_layout
39570
39571 \begin_layout Standard
39572 \begin_inset Note Note
39573 status collapsed
39574
39575 \begin_layout Standard
39576 In the original article Figure II was announced to be downloadable on 
39577 \shape italic
39578 Circuit Cellar
39579 \shape default
39580 's web site.
39581  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39582 \end_layout
39583
39584 \end_inset
39585
39586
39587 \end_layout
39588
39589 \begin_layout Paragraph*
39590 ICode Example
39591 \begin_inset LatexCommand \index{iCode}
39592
39593 \end_inset
39594
39595
39596 \end_layout
39597
39598 \begin_layout Standard
39599 This section shows some details of iCode.
39600  The example C code does not do anything useful; it is used as an example
39601  to illustrate the intermediate code generated by the compiler.
39602 \end_layout
39603
39604 \begin_layout Verse
39605
39606 \family typewriter
39607 1.\InsetSpace ~
39608 xdata int * p;
39609 \newline
39610 2.\InsetSpace ~
39611 int gint;
39612 \newline
39613 3.\InsetSpace ~
39614 /* This function does nothing useful.
39615  It is used
39616 \newline
39617 4.\InsetSpace ~
39618 \InsetSpace ~
39619 \InsetSpace ~
39620 \InsetSpace ~
39621 for the purpose of explaining iCode */
39622 \newline
39623 5.\InsetSpace ~
39624 short function (data
39625  int *x)
39626 \newline
39627 6.\InsetSpace ~
39628 {
39629 \newline
39630 7.\InsetSpace ~
39631 \InsetSpace ~
39632 \InsetSpace ~
39633 short i=10; \InsetSpace ~
39634 \InsetSpace ~
39635 /* dead initialization eliminated */
39636 \newline
39637 8.\InsetSpace ~
39638 \InsetSpace ~
39639 \InsetSpace ~
39640 short sum=10;
39641  /* dead initialization eliminated */
39642 \newline
39643 9.\InsetSpace ~
39644 \InsetSpace ~
39645 \InsetSpace ~
39646 short mul;
39647 \newline
39648 10.\InsetSpace ~
39649 \InsetSpace ~
39650 int j ;
39651 \newline
39652 11.\InsetSpace ~
39653 \InsetSpace ~
39654 while (*x) *x++
39655  = *p++; 
39656 \newline
39657 12.\InsetSpace ~
39658 \InsetSpace ~
39659 \InsetSpace ~
39660 \InsetSpace ~
39661 sum = 0 ; 
39662 \newline
39663 13.\InsetSpace ~
39664 \InsetSpace ~
39665 mul = 0;
39666 \newline
39667 14.\InsetSpace ~
39668 \InsetSpace ~
39669 /* compiler detects i,j to be induction
39670  variables */
39671 \newline
39672 15.\InsetSpace ~
39673 \InsetSpace ~
39674 for (i = 0, j = 10 ; i < 10 ; i++, j
39675 \family default
39676 -
39677 \begin_inset ERT
39678 status collapsed
39679
39680 \begin_layout Standard
39681
39682
39683 \backslash
39684 /
39685 \end_layout
39686
39687 \end_inset
39688
39689 -
39690 \family typewriter
39691 ) {
39692 \newline
39693 16.\InsetSpace ~
39694 \InsetSpace ~
39695 \InsetSpace ~
39696 \InsetSpace ~
39697 sum += i;
39698 \newline
39699 17.\InsetSpace ~
39700 \InsetSpace ~
39701 \InsetSpace ~
39702 \InsetSpace ~
39703 mul += i * 3; \InsetSpace ~
39704 \InsetSpace ~
39705 /* this multiplication remains */
39706 \newline
39707 18.\InsetSpace ~
39708 \InsetSpace ~
39709 \InsetSpace ~
39710 \InsetSpace ~
39711 gint +=
39712  j * 3;\InsetSpace ~
39713 \InsetSpace ~
39714 /* this multiplication changed to addition */
39715 \newline
39716 19.\InsetSpace ~
39717 \InsetSpace ~
39718 }
39719 \newline
39720 20.\InsetSpace ~
39721 \InsetSpace ~
39722 return sum+mul;
39723 \newline
39724 21.\InsetSpace ~
39725 }
39726 \end_layout
39727
39728 \begin_layout Standard
39729 In addition to the operands each iCode contains information about the filename
39730  and line it corresponds to in the source file.
39731  The first field in the listing should be interpreted as follows:
39732 \newline
39733
39734 \shape italic
39735 \size footnotesize
39736 Filename(linenumber: iCode Execution sequence number : ICode hash table
39737  key : loop depth of the iCode).
39738 \shape default
39739 \size default
39740
39741 \newline
39742 Then follows the human readable form of the ICode operation.
39743  Each operand of this triplet form can be of three basic types a) compiler
39744  generated temporary b) user defined variable c) a constant value.
39745  Note that local variables and parameters are replaced by compiler generated
39746  temporaries.
39747  Live ranges
39748 \begin_inset LatexCommand \index{Live range analysis}
39749
39750 \end_inset
39751
39752  are computed only for temporaries (i.e.
39753  live ranges are not computed for global variables).
39754  Registers
39755 \begin_inset LatexCommand \index{Register allocation}
39756
39757 \end_inset
39758
39759  are allocated for temporaries only.
39760  Operands are formatted in the following manner:
39761 \newline
39762
39763 \shape italic
39764 \size footnotesize
39765 Operand Name [lr live-from : live-to ] { type information } [ registers
39766  allocated ].
39767 \shape default
39768 \size default
39769
39770 \newline
39771 As mentioned earlier the live ranges are computed in terms of the execution
39772  sequence number of the iCodes, for example 
39773 \newline
39774 the iTemp0 is live from (i.e.
39775  first defined in iCode with execution sequence number 3, and is last used
39776  in the iCode with sequence number 5).
39777  For induction variables such as iTemp21 the live range computation extends
39778  the lifetime from the start to the end of the loop.
39779 \newline
39780 The register allocator
39781  used the live range information to allocate registers, the same registers
39782  may be used for different temporaries if their live ranges do not overlap,
39783  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39784  ranges do not overlap.
39785  In addition the allocator also takes into consideration the type and usage
39786  of a temporary, for example itemp6 is a pointer to near space and is used
39787  as to fetch data from (i.e.
39788  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39789  Some short lived temporaries are allocated to special registers which have
39790  meaning to the code generator e.g.
39791  iTemp13 is allocated to a pseudo register CC which tells the back end that
39792  the temporary is used only for a conditional jump the code generation makes
39793  use of this information to optimize a compare and jump ICode.
39794 \newline
39795 There are several
39796  loop optimizations
39797 \begin_inset LatexCommand \index{Loop optimization}
39798
39799 \end_inset
39800
39801  performed by the compiler.
39802  It can detect induction variables iTemp21(i) and iTemp23(j).
39803  Also note the compiler does selective strength reduction
39804 \begin_inset LatexCommand \index{Strength reduction}
39805
39806 \end_inset
39807
39808 , i.e.
39809  the multiplication of an induction variable in line 18 (gint = j * 3) is
39810  changed to addition, a new temporary iTemp17 is allocated and assigned
39811  a initial value, a constant 3 is then added for each iteration of the loop.
39812  The compiler does not change the multiplication
39813 \begin_inset LatexCommand \index{Multiplication}
39814
39815 \end_inset
39816
39817  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39818 \newline
39819
39820 Note the dead code elimination
39821 \begin_inset LatexCommand \index{Dead-code elimination}
39822
39823 \end_inset
39824
39825  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39826  respectively.
39827 \newline
39828
39829 \end_layout
39830
39831 \begin_layout Standard
39832
39833 \size footnotesize
39834 Sample.c (5:1:0:0) _entry($9) :
39835 \end_layout
39836
39837 \begin_layout Standard
39838
39839 \size footnotesize
39840 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39841 \end_layout
39842
39843 \begin_layout Standard
39844
39845 \size footnotesize
39846 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39847 \end_layout
39848
39849 \begin_layout Standard
39850
39851 \size footnotesize
39852 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39853 \end_layout
39854
39855 \begin_layout Standard
39856
39857 \size footnotesize
39858 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39859  * int}[r2]
39860 \end_layout
39861
39862 \begin_layout Standard
39863
39864 \size footnotesize
39865 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39866 \end_layout
39867
39868 \begin_layout Standard
39869
39870 \size footnotesize
39871 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39872  int}[r0]]
39873 \end_layout
39874
39875 \begin_layout Standard
39876
39877 \size footnotesize
39878 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39879 \end_layout
39880
39881 \begin_layout Standard
39882
39883 \size footnotesize
39884 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39885  * int}
39886 \end_layout
39887
39888 \begin_layout Standard
39889
39890 \size footnotesize
39891 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39892  {short}
39893 \end_layout
39894
39895 \begin_layout Standard
39896
39897 \size footnotesize
39898 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39899  * int}[DPTR]]
39900 \end_layout
39901
39902 \begin_layout Standard
39903
39904 \size footnotesize
39905 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39906 }[r2 r3]
39907 \end_layout
39908
39909 \begin_layout Standard
39910
39911 \size footnotesize
39912 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39913  * int}[r0] + 0x2 {short}
39914 \end_layout
39915
39916 \begin_layout Standard
39917
39918 \size footnotesize
39919 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39920 \end_layout
39921
39922 \begin_layout Standard
39923
39924 \size footnotesize
39925 Sample.c(11:17:21:0)_whilebreak_0($3) :
39926 \end_layout
39927
39928 \begin_layout Standard
39929
39930 \size footnotesize
39931 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39932 \end_layout
39933
39934 \begin_layout Standard
39935
39936 \size footnotesize
39937 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39938 \end_layout
39939
39940 \begin_layout Standard
39941
39942 \size footnotesize
39943 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39944 \end_layout
39945
39946 \begin_layout Standard
39947
39948 \size footnotesize
39949 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39950 \end_layout
39951
39952 \begin_layout Standard
39953
39954 \size footnotesize
39955 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39956 \end_layout
39957
39958 \begin_layout Standard
39959
39960 \size footnotesize
39961 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39962 \end_layout
39963
39964 \begin_layout Standard
39965
39966 \size footnotesize
39967 Sample.c(15:24:26:1)_forcond_0($4) :
39968 \end_layout
39969
39970 \begin_layout Standard
39971
39972 \size footnotesize
39973 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39974  < 0xa {short}
39975 \end_layout
39976
39977 \begin_layout Standard
39978
39979 \size footnotesize
39980 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39981 \end_layout
39982
39983 \begin_layout Standard
39984
39985 \size footnotesize
39986 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39987  + ITemp21 [lr21:38]{short}[r4]
39988 \end_layout
39989
39990 \begin_layout Standard
39991
39992 \size footnotesize
39993 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39994  * 0x3 {short}
39995 \end_layout
39996
39997 \begin_layout Standard
39998
39999 \size footnotesize
40000 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40001  + iTemp15 [lr29:30]{short}[r1]
40002 \end_layout
40003
40004 \begin_layout Standard
40005
40006 \size footnotesize
40007 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40008  r0]- 0x3 {short}
40009 \end_layout
40010
40011 \begin_layout Standard
40012
40013 \size footnotesize
40014 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40015 int}[r7 r0]
40016 \end_layout
40017
40018 \begin_layout Standard
40019
40020 \size footnotesize
40021 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40022  + 0x1 {short}
40023 \end_layout
40024
40025 \begin_layout Standard
40026
40027 \size footnotesize
40028 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40029  r6]- 0x1 {short}
40030 \end_layout
40031
40032 \begin_layout Standard
40033
40034 \size footnotesize
40035 Sample.c(19:38:47:1) goto _forcond_0($4)
40036 \end_layout
40037
40038 \begin_layout Standard
40039
40040 \size footnotesize
40041 Sample.c(19:39:48:0)_forbreak_0($7) :
40042 \end_layout
40043
40044 \begin_layout Standard
40045
40046 \size footnotesize
40047 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40048  + ITemp11 [lr19:40]{short}[r3]
40049 \end_layout
40050
40051 \begin_layout Standard
40052
40053 \size footnotesize
40054 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40055 \end_layout
40056
40057 \begin_layout Standard
40058
40059 \size footnotesize
40060 Sample.c(20:42:51:0)_return($8) :
40061 \end_layout
40062
40063 \begin_layout Standard
40064
40065 \size footnotesize
40066 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40067 \size default
40068
40069 \newline
40070
40071 \newline
40072 Finally the code generated for this function:
40073 \newline
40074
40075 \end_layout
40076
40077 \begin_layout Standard
40078
40079 \size footnotesize
40080 .area DSEG (DATA)
40081 \end_layout
40082
40083 \begin_layout Standard
40084
40085 \size footnotesize
40086 _p::
40087 \end_layout
40088
40089 \begin_layout Standard
40090
40091 \size footnotesize
40092 \InsetSpace ~
40093 \InsetSpace ~
40094 .ds 2
40095 \end_layout
40096
40097 \begin_layout Standard
40098
40099 \size footnotesize
40100 _gint::
40101 \end_layout
40102
40103 \begin_layout Standard
40104
40105 \size footnotesize
40106 \InsetSpace ~
40107 \InsetSpace ~
40108 .ds 2
40109 \end_layout
40110
40111 \begin_layout Standard
40112
40113 \size footnotesize
40114 ; sample.c 5
40115 \end_layout
40116
40117 \begin_layout Standard
40118
40119 \size footnotesize
40120 ; ----------------------------------------------
40121 \end_layout
40122
40123 \begin_layout Standard
40124
40125 \size footnotesize
40126 ; function function
40127 \end_layout
40128
40129 \begin_layout Standard
40130
40131 \size footnotesize
40132 ; ----------------------------------------------
40133 \end_layout
40134
40135 \begin_layout Standard
40136
40137 \size footnotesize
40138 _function:
40139 \end_layout
40140
40141 \begin_layout Standard
40142
40143 \size footnotesize
40144 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40145 \end_layout
40146
40147 \begin_layout Standard
40148
40149 \size footnotesize
40150 \InsetSpace ~
40151 \InsetSpace ~
40152 mov r2,dpl
40153 \end_layout
40154
40155 \begin_layout Standard
40156
40157 \size footnotesize
40158 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40159 \end_layout
40160
40161 \begin_layout Standard
40162
40163 \size footnotesize
40164 \InsetSpace ~
40165 \InsetSpace ~
40166 mov ar0,r2
40167 \end_layout
40168
40169 \begin_layout Standard
40170
40171 \size footnotesize
40172 ;_whilecontinue_0($1) :
40173 \end_layout
40174
40175 \begin_layout Standard
40176
40177 \size footnotesize
40178 00101$:
40179 \end_layout
40180
40181 \begin_layout Standard
40182
40183 \size footnotesize
40184 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40185 \end_layout
40186
40187 \begin_layout Standard
40188
40189 \size footnotesize
40190 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40191 \end_layout
40192
40193 \begin_layout Standard
40194
40195 \size footnotesize
40196 \InsetSpace ~
40197 \InsetSpace ~
40198 mov ar2,@r0
40199 \end_layout
40200
40201 \begin_layout Standard
40202
40203 \size footnotesize
40204 \InsetSpace ~
40205 \InsetSpace ~
40206 inc r0
40207 \end_layout
40208
40209 \begin_layout Standard
40210
40211 \size footnotesize
40212 \InsetSpace ~
40213 \InsetSpace ~
40214 mov ar3,@r0
40215 \end_layout
40216
40217 \begin_layout Standard
40218
40219 \size footnotesize
40220 \InsetSpace ~
40221 \InsetSpace ~
40222 dec r0
40223 \end_layout
40224
40225 \begin_layout Standard
40226
40227 \size footnotesize
40228 \InsetSpace ~
40229 \InsetSpace ~
40230 mov a,r2
40231 \end_layout
40232
40233 \begin_layout Standard
40234
40235 \size footnotesize
40236 \InsetSpace ~
40237 \InsetSpace ~
40238 orl a,r3
40239 \end_layout
40240
40241 \begin_layout Standard
40242
40243 \size footnotesize
40244 \InsetSpace ~
40245 \InsetSpace ~
40246 jz 00103$
40247 \end_layout
40248
40249 \begin_layout Standard
40250
40251 \size footnotesize
40252 00114$:
40253 \end_layout
40254
40255 \begin_layout Standard
40256
40257 \size footnotesize
40258 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40259 \end_layout
40260
40261 \begin_layout Standard
40262
40263 \size footnotesize
40264 \InsetSpace ~
40265 \InsetSpace ~
40266 mov dpl,_p
40267 \end_layout
40268
40269 \begin_layout Standard
40270
40271 \size footnotesize
40272 \InsetSpace ~
40273 \InsetSpace ~
40274 mov dph,(_p + 1)
40275 \end_layout
40276
40277 \begin_layout Standard
40278
40279 \size footnotesize
40280 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40281 \end_layout
40282
40283 \begin_layout Standard
40284
40285 \size footnotesize
40286 \InsetSpace ~
40287 \InsetSpace ~
40288 mov a,#0x02
40289 \end_layout
40290
40291 \begin_layout Standard
40292
40293 \size footnotesize
40294 \InsetSpace ~
40295 \InsetSpace ~
40296 add a,_p
40297 \end_layout
40298
40299 \begin_layout Standard
40300
40301 \size footnotesize
40302 \InsetSpace ~
40303 \InsetSpace ~
40304 mov _p,a
40305 \end_layout
40306
40307 \begin_layout Standard
40308
40309 \size footnotesize
40310 \InsetSpace ~
40311 \InsetSpace ~
40312 clr a
40313 \end_layout
40314
40315 \begin_layout Standard
40316
40317 \size footnotesize
40318 \InsetSpace ~
40319 \InsetSpace ~
40320 addc a,(_p + 1)
40321 \end_layout
40322
40323 \begin_layout Standard
40324
40325 \size footnotesize
40326 \InsetSpace ~
40327 \InsetSpace ~
40328 mov (_p + 1),a
40329 \end_layout
40330
40331 \begin_layout Standard
40332
40333 \size footnotesize
40334 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40335 \end_layout
40336
40337 \begin_layout Standard
40338
40339 \size footnotesize
40340 \InsetSpace ~
40341 \InsetSpace ~
40342 movx a,@dptr
40343 \end_layout
40344
40345 \begin_layout Standard
40346
40347 \size footnotesize
40348 \InsetSpace ~
40349 \InsetSpace ~
40350 mov r2,a
40351 \end_layout
40352
40353 \begin_layout Standard
40354
40355 \size footnotesize
40356 \InsetSpace ~
40357 \InsetSpace ~
40358 inc dptr
40359 \end_layout
40360
40361 \begin_layout Standard
40362
40363 \size footnotesize
40364 \InsetSpace ~
40365 \InsetSpace ~
40366 movx a,@dptr
40367 \end_layout
40368
40369 \begin_layout Standard
40370
40371 \size footnotesize
40372 \InsetSpace ~
40373 \InsetSpace ~
40374 mov r3,a
40375 \end_layout
40376
40377 \begin_layout Standard
40378
40379 \size footnotesize
40380 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40381 \end_layout
40382
40383 \begin_layout Standard
40384
40385 \size footnotesize
40386 \InsetSpace ~
40387 \InsetSpace ~
40388 mov @r0,ar2
40389 \end_layout
40390
40391 \begin_layout Standard
40392
40393 \size footnotesize
40394 \InsetSpace ~
40395 \InsetSpace ~
40396 inc r0
40397 \end_layout
40398
40399 \begin_layout Standard
40400
40401 \size footnotesize
40402 \InsetSpace ~
40403 \InsetSpace ~
40404 mov @r0,ar3
40405 \end_layout
40406
40407 \begin_layout Standard
40408
40409 \size footnotesize
40410 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40411 \end_layout
40412
40413 \begin_layout Standard
40414
40415 \size footnotesize
40416 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40417 \end_layout
40418
40419 \begin_layout Standard
40420
40421 \size footnotesize
40422 ; 0x2 {short}
40423 \end_layout
40424
40425 \begin_layout Standard
40426
40427 \size footnotesize
40428 \InsetSpace ~
40429 \InsetSpace ~
40430 inc r0
40431 \end_layout
40432
40433 \begin_layout Standard
40434
40435 \size footnotesize
40436 ; goto _whilecontinue_0($1)
40437 \end_layout
40438
40439 \begin_layout Standard
40440
40441 \size footnotesize
40442 \InsetSpace ~
40443 \InsetSpace ~
40444 sjmp 00101$
40445 \end_layout
40446
40447 \begin_layout Standard
40448
40449 \size footnotesize
40450 ; _whilebreak_0($3) :
40451 \end_layout
40452
40453 \begin_layout Standard
40454
40455 \size footnotesize
40456 00103$:
40457 \end_layout
40458
40459 \begin_layout Standard
40460
40461 \size footnotesize
40462 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40463 \end_layout
40464
40465 \begin_layout Standard
40466
40467 \size footnotesize
40468 \InsetSpace ~
40469 \InsetSpace ~
40470 mov r2,#0x00
40471 \end_layout
40472
40473 \begin_layout Standard
40474
40475 \size footnotesize
40476 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40477 \end_layout
40478
40479 \begin_layout Standard
40480
40481 \size footnotesize
40482 \InsetSpace ~
40483 \InsetSpace ~
40484 mov r3,#0x00
40485 \end_layout
40486
40487 \begin_layout Standard
40488
40489 \size footnotesize
40490 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40491 \end_layout
40492
40493 \begin_layout Standard
40494
40495 \size footnotesize
40496 \InsetSpace ~
40497 \InsetSpace ~
40498 mov r4,#0x00
40499 \end_layout
40500
40501 \begin_layout Standard
40502
40503 \size footnotesize
40504 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40505 \end_layout
40506
40507 \begin_layout Standard
40508
40509 \size footnotesize
40510 \InsetSpace ~
40511 \InsetSpace ~
40512 mov r5,#0x0A
40513 \end_layout
40514
40515 \begin_layout Standard
40516
40517 \size footnotesize
40518 \InsetSpace ~
40519 \InsetSpace ~
40520 mov r6,#0x00
40521 \end_layout
40522
40523 \begin_layout Standard
40524
40525 \size footnotesize
40526 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40527 \end_layout
40528
40529 \begin_layout Standard
40530
40531 \size footnotesize
40532 \InsetSpace ~
40533 \InsetSpace ~
40534 mov r7,#0x1E
40535 \end_layout
40536
40537 \begin_layout Standard
40538
40539 \size footnotesize
40540 \InsetSpace ~
40541 \InsetSpace ~
40542 mov r0,#0x00
40543 \end_layout
40544
40545 \begin_layout Standard
40546
40547 \size footnotesize
40548 ; _forcond_0($4) :
40549 \end_layout
40550
40551 \begin_layout Standard
40552
40553 \size footnotesize
40554 00104$:
40555 \end_layout
40556
40557 \begin_layout Standard
40558
40559 \size footnotesize
40560 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40561 \end_layout
40562
40563 \begin_layout Standard
40564
40565 \size footnotesize
40566 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40567 \end_layout
40568
40569 \begin_layout Standard
40570
40571 \size footnotesize
40572 \InsetSpace ~
40573 \InsetSpace ~
40574 clr c
40575 \end_layout
40576
40577 \begin_layout Standard
40578
40579 \size footnotesize
40580 \InsetSpace ~
40581 \InsetSpace ~
40582 mov a,r4
40583 \end_layout
40584
40585 \begin_layout Standard
40586
40587 \size footnotesize
40588 \InsetSpace ~
40589 \InsetSpace ~
40590 xrl a,#0x80
40591 \end_layout
40592
40593 \begin_layout Standard
40594
40595 \size footnotesize
40596 \InsetSpace ~
40597 \InsetSpace ~
40598 subb a,#0x8a
40599 \end_layout
40600
40601 \begin_layout Standard
40602
40603 \size footnotesize
40604 \InsetSpace ~
40605 \InsetSpace ~
40606 jnc 00107$
40607 \end_layout
40608
40609 \begin_layout Standard
40610
40611 \size footnotesize
40612 00115$:
40613 \end_layout
40614
40615 \begin_layout Standard
40616
40617 \size footnotesize
40618 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40619 \end_layout
40620
40621 \begin_layout Standard
40622
40623 \size footnotesize
40624 ; iTemp21 [lr21:38]{short}[r4]
40625 \end_layout
40626
40627 \begin_layout Standard
40628
40629 \size footnotesize
40630 \InsetSpace ~
40631 \InsetSpace ~
40632 mov a,r4
40633 \end_layout
40634
40635 \begin_layout Standard
40636
40637 \size footnotesize
40638 \InsetSpace ~
40639 \InsetSpace ~
40640 add a,r2
40641 \end_layout
40642
40643 \begin_layout Standard
40644
40645 \size footnotesize
40646 \InsetSpace ~
40647 \InsetSpace ~
40648 mov r2,a
40649 \end_layout
40650
40651 \begin_layout Standard
40652
40653 \size footnotesize
40654 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40655 \end_layout
40656
40657 \begin_layout Standard
40658
40659 \size footnotesize
40660 \InsetSpace ~
40661 \InsetSpace ~
40662 mov b,#0x03
40663 \end_layout
40664
40665 \begin_layout Standard
40666
40667 \size footnotesize
40668 \InsetSpace ~
40669 \InsetSpace ~
40670 mov a,r4
40671 \end_layout
40672
40673 \begin_layout Standard
40674
40675 \size footnotesize
40676 \InsetSpace ~
40677 \InsetSpace ~
40678 mul ab
40679 \end_layout
40680
40681 \begin_layout Standard
40682
40683 \size footnotesize
40684 \InsetSpace ~
40685 \InsetSpace ~
40686 mov r1,a
40687 \end_layout
40688
40689 \begin_layout Standard
40690
40691 \size footnotesize
40692 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40693 \end_layout
40694
40695 \begin_layout Standard
40696
40697 \size footnotesize
40698 ; iTemp15 [lr29:30]{short}[r1]
40699 \end_layout
40700
40701 \begin_layout Standard
40702
40703 \size footnotesize
40704 \InsetSpace ~
40705 \InsetSpace ~
40706 add a,r3
40707 \end_layout
40708
40709 \begin_layout Standard
40710
40711 \size footnotesize
40712 \InsetSpace ~
40713 \InsetSpace ~
40714 mov r3,a
40715 \end_layout
40716
40717 \begin_layout Standard
40718
40719 \size footnotesize
40720 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40721 \end_layout
40722
40723 \begin_layout Standard
40724
40725 \size footnotesize
40726 \InsetSpace ~
40727 \InsetSpace ~
40728 mov a,r7
40729 \end_layout
40730
40731 \begin_layout Standard
40732
40733 \size footnotesize
40734 \InsetSpace ~
40735 \InsetSpace ~
40736 add a,#0xfd
40737 \end_layout
40738
40739 \begin_layout Standard
40740
40741 \size footnotesize
40742 \InsetSpace ~
40743 \InsetSpace ~
40744 mov r7,a
40745 \end_layout
40746
40747 \begin_layout Standard
40748
40749 \size footnotesize
40750 \InsetSpace ~
40751 \InsetSpace ~
40752 mov a,r0
40753 \end_layout
40754
40755 \begin_layout Standard
40756
40757 \size footnotesize
40758 \InsetSpace ~
40759 \InsetSpace ~
40760 addc a,#0xff
40761 \end_layout
40762
40763 \begin_layout Standard
40764
40765 \size footnotesize
40766 \InsetSpace ~
40767 \InsetSpace ~
40768 mov r0,a
40769 \end_layout
40770
40771 \begin_layout Standard
40772
40773 \size footnotesize
40774 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40775 \end_layout
40776
40777 \begin_layout Standard
40778
40779 \size footnotesize
40780 \InsetSpace ~
40781 \InsetSpace ~
40782 mov a,r7
40783 \end_layout
40784
40785 \begin_layout Standard
40786
40787 \size footnotesize
40788 \InsetSpace ~
40789 \InsetSpace ~
40790 add a,_gint
40791 \end_layout
40792
40793 \begin_layout Standard
40794
40795 \size footnotesize
40796 \InsetSpace ~
40797 \InsetSpace ~
40798 mov _gint,a
40799 \end_layout
40800
40801 \begin_layout Standard
40802
40803 \size footnotesize
40804 \InsetSpace ~
40805 \InsetSpace ~
40806 mov a,r0
40807 \end_layout
40808
40809 \begin_layout Standard
40810
40811 \size footnotesize
40812 \InsetSpace ~
40813 \InsetSpace ~
40814 addc a,(_gint + 1)
40815 \end_layout
40816
40817 \begin_layout Standard
40818
40819 \size footnotesize
40820 \InsetSpace ~
40821 \InsetSpace ~
40822 mov (_gint + 1),a
40823 \end_layout
40824
40825 \begin_layout Standard
40826
40827 \size footnotesize
40828 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40829 \end_layout
40830
40831 \begin_layout Standard
40832
40833 \size footnotesize
40834 \InsetSpace ~
40835 \InsetSpace ~
40836 inc r4
40837 \end_layout
40838
40839 \begin_layout Standard
40840
40841 \size footnotesize
40842 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40843 \end_layout
40844
40845 \begin_layout Standard
40846
40847 \size footnotesize
40848 \InsetSpace ~
40849 \InsetSpace ~
40850 dec r5
40851 \end_layout
40852
40853 \begin_layout Standard
40854
40855 \size footnotesize
40856 \InsetSpace ~
40857 \InsetSpace ~
40858 cjne r5,#0xff,00104$
40859 \end_layout
40860
40861 \begin_layout Standard
40862
40863 \size footnotesize
40864 \InsetSpace ~
40865 \InsetSpace ~
40866 dec r6
40867 \end_layout
40868
40869 \begin_layout Standard
40870
40871 \size footnotesize
40872 ; goto _forcond_0($4)
40873 \end_layout
40874
40875 \begin_layout Standard
40876
40877 \size footnotesize
40878 \InsetSpace ~
40879 \InsetSpace ~
40880 sjmp 00104$
40881 \end_layout
40882
40883 \begin_layout Standard
40884
40885 \size footnotesize
40886 ; _forbreak_0($7) :
40887 \end_layout
40888
40889 \begin_layout Standard
40890
40891 \size footnotesize
40892 00107$:
40893 \end_layout
40894
40895 \begin_layout Standard
40896
40897 \size footnotesize
40898 ; ret iTemp24 [lr40:41]{short}
40899 \end_layout
40900
40901 \begin_layout Standard
40902
40903 \size footnotesize
40904 \InsetSpace ~
40905 \InsetSpace ~
40906 mov a,r3
40907 \end_layout
40908
40909 \begin_layout Standard
40910
40911 \size footnotesize
40912 \InsetSpace ~
40913 \InsetSpace ~
40914 add a,r2
40915 \end_layout
40916
40917 \begin_layout Standard
40918
40919 \size footnotesize
40920 \InsetSpace ~
40921 \InsetSpace ~
40922 mov dpl,a
40923 \end_layout
40924
40925 \begin_layout Standard
40926
40927 \size footnotesize
40928 ; _return($8) :
40929 \end_layout
40930
40931 \begin_layout Standard
40932
40933 \size footnotesize
40934 00108$:
40935 \end_layout
40936
40937 \begin_layout Standard
40938
40939 \size footnotesize
40940 \InsetSpace ~
40941 \InsetSpace ~
40942 ret
40943 \newline
40944
40945 \end_layout
40946
40947 \begin_layout Section
40948 A few words about basic block successors, predecessors and dominators
40949 \end_layout
40950
40951 \begin_layout Standard
40952 Successors are basic blocks
40953 \begin_inset LatexCommand \index{Basic blocks}
40954
40955 \end_inset
40956
40957  that might execute after this basic block.
40958 \newline
40959 Predecessors are basic blocks
40960  that might execute before reaching this basic block.
40961 \newline
40962 Dominators are basic
40963  blocks that WILL execute before reaching this basic block.
40964 \newline
40965
40966 \end_layout
40967
40968 \begin_layout Standard
40969 [basic block 1]
40970 \end_layout
40971
40972 \begin_layout Standard
40973 if (something)
40974 \end_layout
40975
40976 \begin_layout Standard
40977 \InsetSpace ~
40978 \InsetSpace ~
40979 \InsetSpace ~
40980 \InsetSpace ~
40981 [basic block 2]
40982 \end_layout
40983
40984 \begin_layout Standard
40985 else
40986 \end_layout
40987
40988 \begin_layout Standard
40989 \InsetSpace ~
40990 \InsetSpace ~
40991 \InsetSpace ~
40992 \InsetSpace ~
40993 [basic block 3]
40994 \end_layout
40995
40996 \begin_layout Standard
40997 [basic block 4]
40998 \newline
40999
41000 \end_layout
41001
41002 \begin_layout Standard
41003 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41004 \end_layout
41005
41006 \begin_layout Standard
41007 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41008 \end_layout
41009
41010 \begin_layout Standard
41011 c) domVect of [BB4] = BB1 ...
41012  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41013  was executed.
41014 \end_layout
41015
41016 \begin_layout Chapter
41017 Acknowledgments
41018 \end_layout
41019
41020 \begin_layout Standard
41021 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41022
41023 \end_inset
41024
41025
41026 \newline
41027
41028 \newline
41029
41030 \emph on
41031 Thanks to all the other volunteer developers who have helped with coding,
41032  testing, web-page creation, distribution sets, etc.
41033  You know who you are :-)
41034 \emph default
41035
41036 \newline
41037
41038 \newline
41039
41040 \emph on
41041 Thanks to Sourceforge 
41042 \begin_inset LatexCommand \url{http://www.sf.net}
41043
41044 \end_inset
41045
41046  which has hosted the project since 1999 and donates significant download
41047  bandwidth.
41048 \emph default
41049
41050 \newline
41051
41052 \newline
41053
41054 \emph on
41055 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41056  cycles and bandwidth for snapshot builds.
41057 \newline
41058
41059 \end_layout
41060
41061 \begin_layout Standard
41062 This document was initially written by Sandeep Dutta
41063 \end_layout
41064
41065 \begin_layout Standard
41066 All product names mentioned herein may be trademarks
41067 \begin_inset LatexCommand \index{Trademarks}
41068
41069 \end_inset
41070
41071  of their respective companies.
41072  
41073 \end_layout
41074
41075 \begin_layout Section*
41076 Alphabetical index
41077 \end_layout
41078
41079 \begin_layout Standard
41080 To avoid confusion, the installation and building options for SDCC itself
41081  (chapter 2) are not part of the index.
41082 \end_layout
41083
41084 \begin_layout Standard
41085 \begin_inset LatexCommand \printindex{}
41086
41087 \end_inset
41088
41089
41090 \end_layout
41091
41092 \end_body
41093 \end_document