* doc/sdccman.lyx: added paragraph about bankswitching for mcs51
[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.0
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 ...
8032  Pass the linkOption to the linker.
8033  If a bootloader is used an option like 
8034 \begin_inset Quotes sld
8035 \end_inset
8036
8037 -Wl\InsetSpace ~
8038 -bCSEG=0x1000
8039 \begin_inset Quotes srd
8040 \end_inset
8041
8042  would be typical to set the start of the code segment.
8043  See also #pragma constseg and #pragma codeseg in section 
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8045
8046 \end_inset
8047
8048  .
8049  File sdcc/as/doc/asxhtm.html has more on linker options.
8050 \end_layout
8051
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8054 \end_inset
8055
8056
8057 \end_layout
8058
8059 \begin_layout Subsection
8060 MCS51 Options
8061 \begin_inset LatexCommand \index{Options MCS51}
8062
8063 \end_inset
8064
8065
8066 \begin_inset LatexCommand \index{MCS51 options}
8067
8068 \end_inset
8069
8070
8071 \end_layout
8072
8073 \begin_layout List
8074 \labelwidthstring 00.00.0000
8075
8076 \series bold
8077 -
8078 \begin_inset ERT
8079 status collapsed
8080
8081 \begin_layout Standard
8082
8083
8084 \backslash
8085 /
8086 \end_layout
8087
8088 \end_inset
8089
8090 -model-small
8091 \begin_inset LatexCommand \index{-\/-model-small}
8092
8093 \end_inset
8094
8095
8096 \series default
8097 \size large
8098 \emph on
8099  
8100 \size default
8101 \emph default
8102 Generate code for Small Model programs, see section Memory Models for more
8103  details.
8104  This is the default model.
8105 \end_layout
8106
8107 \begin_layout List
8108 \labelwidthstring 00.00.0000
8109
8110 \series bold
8111 -
8112 \begin_inset ERT
8113 status collapsed
8114
8115 \begin_layout Standard
8116
8117
8118 \backslash
8119 /
8120 \end_layout
8121
8122 \end_inset
8123
8124 -model-medium
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8126
8127 \end_inset
8128
8129
8130 \series default
8131  Generate code for Medium model programs, see section Memory Models for
8132  more details.
8133  If this option is used all source files in the project have to be compiled
8134  with this option.
8135  It must also be used when invoking the linker.
8136 \end_layout
8137
8138 \begin_layout List
8139 \labelwidthstring 00.00.0000
8140
8141 \series bold
8142 -
8143 \begin_inset ERT
8144 status collapsed
8145
8146 \begin_layout Standard
8147
8148
8149 \backslash
8150 /
8151 \end_layout
8152
8153 \end_inset
8154
8155 -model-large
8156 \begin_inset LatexCommand \index{-\/-model-large}
8157
8158 \end_inset
8159
8160
8161 \series default
8162  Generate code for Large model programs, see section Memory Models for more
8163  details.
8164  If this option is used all source files in the project have to be compiled
8165  with this option.
8166  It must also be used when invoking the linker.
8167 \end_layout
8168
8169 \begin_layout List
8170 \labelwidthstring 00.00.0000
8171
8172 \series bold
8173 -
8174 \begin_inset ERT
8175 status collapsed
8176
8177 \begin_layout Standard
8178
8179
8180 \backslash
8181 /
8182 \end_layout
8183
8184 \end_inset
8185
8186 -xstack
8187 \begin_inset LatexCommand \index{-\/-xstack}
8188
8189 \end_inset
8190
8191
8192 \series default
8193  Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8195
8196 \end_inset
8197
8198  area (usually the first 256 bytes in the external ram) for allocating variables
8199  and passing parameters.
8200  See section 
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8202
8203 \end_inset
8204
8205 \InsetSpace ~
8206  External Stack for more details.
8207 \end_layout
8208
8209 \begin_layout List
8210 \labelwidthstring 00.00.0000
8211
8212 \series bold
8213 -
8214 \begin_inset ERT
8215 status collapsed
8216
8217 \begin_layout Standard
8218
8219
8220 \backslash
8221 /
8222 \end_layout
8223
8224 \end_inset
8225
8226 -iram-size
8227 \series default
8228 \InsetSpace ~
8229 <Value>
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8231
8232 \end_inset
8233
8234  Causes the linker to check if the internal ram usage is within limits of
8235  the given value.
8236 \end_layout
8237
8238 \begin_layout List
8239 \labelwidthstring 00.00.0000
8240
8241 \series bold
8242 -
8243 \begin_inset ERT
8244 status collapsed
8245
8246 \begin_layout Standard
8247
8248
8249 \backslash
8250 /
8251 \end_layout
8252
8253 \end_inset
8254
8255 -xram-size
8256 \series default
8257 \InsetSpace ~
8258 <Value>
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8260
8261 \end_inset
8262
8263  Causes the linker to check if the external ram usage is within limits of
8264  the given value.
8265 \end_layout
8266
8267 \begin_layout List
8268 \labelwidthstring 00.00.0000
8269
8270 \series bold
8271 -
8272 \begin_inset ERT
8273 status collapsed
8274
8275 \begin_layout Standard
8276
8277
8278 \backslash
8279 /
8280 \end_layout
8281
8282 \end_inset
8283
8284 -code-size
8285 \series default
8286 \InsetSpace ~
8287 <Value>
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8289
8290 \end_inset
8291
8292  Causes the linker to check if the code memory usage is within limits of
8293  the given value.
8294 \end_layout
8295
8296 \begin_layout List
8297 \labelwidthstring 00.00.0000
8298
8299 \series bold
8300 -
8301 \begin_inset ERT
8302 status collapsed
8303
8304 \begin_layout Standard
8305
8306
8307 \backslash
8308 /
8309 \end_layout
8310
8311 \end_inset
8312
8313 -stack-size
8314 \series default
8315 \InsetSpace ~
8316 <Value>
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8318
8319 \end_inset
8320
8321  Causes the linker to check if there is at minimum <Value> bytes for stack.
8322 \end_layout
8323
8324 \begin_layout List
8325 \labelwidthstring 00.00.0000
8326
8327 \series bold
8328 -
8329 \begin_inset ERT
8330 status collapsed
8331
8332 \begin_layout Standard
8333
8334
8335 \backslash
8336 /
8337 \end_layout
8338
8339 \end_inset
8340
8341 -pack-iram
8342 \series default
8343 \InsetSpace ~
8344
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8346
8347 \end_inset
8348
8349  Causes the linker to use unused register banks for data variables and pack
8350  data, idata and stack together.
8351  This is the default now.
8352 \end_layout
8353
8354 \begin_layout List
8355 \labelwidthstring 00.00.0000
8356
8357 \series bold
8358 -
8359 \begin_inset ERT
8360 status collapsed
8361
8362 \begin_layout Standard
8363
8364
8365 \backslash
8366 /
8367 \end_layout
8368
8369 \end_inset
8370
8371 -no-pack-iram
8372 \series default
8373 \InsetSpace ~
8374
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8376
8377 \end_inset
8378
8379  Causes the linker to use old style for allocating memory areas.
8380 \end_layout
8381
8382 \begin_layout List
8383 \labelwidthstring 00.00.0000
8384
8385 \series bold
8386 -
8387 \begin_inset ERT
8388 status collapsed
8389
8390 \begin_layout Standard
8391
8392
8393 \backslash
8394 /
8395 \end_layout
8396
8397 \end_inset
8398
8399 -acall-ajmp
8400 \series default
8401 \InsetSpace ~
8402
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8404
8405 \end_inset
8406
8407  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8408  acall/ajmp.
8409  Only use this option if your code is in the same 2k block of memory.
8410  You may need to use this option for some 8051 derivatives which lack the
8411  lcall/ljmp instructions..
8412 \end_layout
8413
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8416 \end_inset
8417
8418
8419 \end_layout
8420
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8424
8425 \end_inset
8426
8427
8428 \begin_inset LatexCommand \index{DS390}
8429
8430 \end_inset
8431
8432
8433 \end_layout
8434
8435 \begin_layout List
8436 \labelwidthstring 00.00.0000
8437
8438 \series bold
8439 -
8440 \begin_inset ERT
8441 status collapsed
8442
8443 \begin_layout Standard
8444
8445
8446 \backslash
8447 /
8448 \end_layout
8449
8450 \end_inset
8451
8452 -model-flat24
8453 \series default
8454
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8456
8457 \end_inset
8458
8459
8460 \size large
8461 \emph on
8462  
8463 \size default
8464 \emph default
8465 Generate 24-bit flat mode code.
8466  This is the one and only that the ds390 code generator supports right now
8467  and is default when using 
8468 \emph on
8469 -mds390
8470 \emph default
8471 .
8472  See section Memory Models for more details.
8473 \end_layout
8474
8475 \begin_layout List
8476 \labelwidthstring 00.00.0000
8477
8478 \series bold
8479 -
8480 \begin_inset ERT
8481 status collapsed
8482
8483 \begin_layout Standard
8484
8485
8486 \backslash
8487 /
8488 \end_layout
8489
8490 \end_inset
8491
8492 -protect-sp-update
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8494
8495 \end_inset
8496
8497
8498 \series default
8499  disable interrupts during ESP:SP updates.
8500 \end_layout
8501
8502 \begin_layout List
8503 \labelwidthstring 00.00.0000
8504
8505 \series bold
8506 -
8507 \begin_inset ERT
8508 status collapsed
8509
8510 \begin_layout Standard
8511
8512
8513 \backslash
8514 /
8515 \end_layout
8516
8517 \end_inset
8518
8519 -stack-10bit
8520 \series default
8521
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8523
8524 \end_inset
8525
8526  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527  This is the one and only that the ds390 code generator supports right now
8528  and is default when using 
8529 \emph on
8530 -mds390
8531 \emph default
8532 .
8533  In this mode, the stack is located in the lower 1K of the internal RAM,
8534  which is mapped to 0x400000.
8535  Note that the support is incomplete, since it still uses a single byte
8536  as the stack pointer.
8537  This means that only the lower 256 bytes of the potential 1K stack space
8538  will actually be used.
8539  However, this does allow you to reclaim the precious 256 bytes of low RAM
8540  for use for the DATA and IDATA segments.
8541  The compiler will not generate any code to put the processor into 10 bit
8542  stack mode.
8543  It is important to ensure that the processor is in this mode before calling
8544  any re-entrant functions compiled with this option.
8545  In principle, this should work with the 
8546 \emph on
8547 -
8548 \begin_inset ERT
8549 status collapsed
8550
8551 \begin_layout Standard
8552
8553
8554 \backslash
8555 /
8556 \end_layout
8557
8558 \end_inset
8559
8560 -stack-auto
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8562
8563 \end_inset
8564
8565
8566 \emph default
8567  option, but that has not been tested.
8568  It is incompatible with the 
8569 \emph on
8570 -
8571 \begin_inset ERT
8572 status collapsed
8573
8574 \begin_layout Standard
8575
8576
8577 \backslash
8578 /
8579 \end_layout
8580
8581 \end_inset
8582
8583 -xstack
8584 \begin_inset LatexCommand \index{-\/-xstack}
8585
8586 \end_inset
8587
8588
8589 \emph default
8590  option.
8591  It also only makes sense if the processor is in 24 bit contiguous addressing
8592  mode (see the 
8593 \emph on
8594 -
8595 \begin_inset ERT
8596 status collapsed
8597
8598 \begin_layout Standard
8599
8600
8601 \backslash
8602 /
8603 \end_layout
8604
8605 \end_inset
8606
8607 -model-flat24 option
8608 \emph default
8609 ).
8610 \series bold
8611
8612 \begin_inset Note Note
8613 status collapsed
8614
8615 \begin_layout List
8616 \labelwidthstring 00.00.0000
8617
8618 \series bold
8619 -
8620 \begin_inset ERT
8621 status open
8622
8623 \begin_layout Standard
8624
8625
8626 \backslash
8627 /
8628 \end_layout
8629
8630 \end_inset
8631
8632 -stack-8-bit - switches off the 10-bit mode
8633 \end_layout
8634
8635 \end_inset
8636
8637
8638 \end_layout
8639
8640 \begin_layout List
8641 \labelwidthstring 00.00.0000
8642
8643 \series bold
8644 -
8645 \begin_inset ERT
8646 status collapsed
8647
8648 \begin_layout Standard
8649
8650
8651 \backslash
8652 /
8653 \end_layout
8654
8655 \end_inset
8656
8657 -stack-probe
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8659
8660 \end_inset
8661
8662
8663 \series default
8664  insert call to function __stack_probe at each function prologue.
8665 \end_layout
8666
8667 \begin_layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status open
8674
8675 \begin_layout Standard
8676
8677
8678 \backslash
8679 /
8680 \end_layout
8681
8682 \end_inset
8683
8684 -tini-libid
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8686
8687 \end_inset
8688
8689
8690 \series default
8691  <nnnn> LibraryID used in -mTININative.
8692  
8693 \end_layout
8694
8695 \begin_layout List
8696 \labelwidthstring 00.00.0000
8697
8698 \series bold
8699 -
8700 \begin_inset ERT
8701 status collapsed
8702
8703 \begin_layout Standard
8704
8705
8706 \backslash
8707 /
8708 \end_layout
8709
8710 \end_inset
8711
8712 -use-accelerator
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8714
8715 \end_inset
8716
8717
8718 \series default
8719  generate code for DS390 Arithmetic Accelerator.
8720  
8721 \end_layout
8722
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8725 \end_inset
8726
8727
8728 \end_layout
8729
8730 \begin_layout Subsection
8731 Z80 Options
8732 \begin_inset LatexCommand \index{Options Z80}
8733
8734 \end_inset
8735
8736
8737 \begin_inset LatexCommand \index{Z80}
8738
8739 \end_inset
8740
8741
8742 \end_layout
8743
8744 \begin_layout List
8745 \labelwidthstring 00.00.0000
8746
8747 \series bold
8748 -
8749 \begin_inset ERT
8750 status collapsed
8751
8752 \begin_layout Standard
8753
8754
8755 \backslash
8756 /
8757 \end_layout
8758
8759 \end_inset
8760
8761 -callee-saves-bc
8762 \series default
8763
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8765
8766 \end_inset
8767
8768
8769 \size large
8770 \emph on
8771  
8772 \size default
8773 \emph default
8774 Force a called function to always save BC.
8775 \end_layout
8776
8777 \begin_layout List
8778 \labelwidthstring 00.00.0000
8779
8780 \series bold
8781 -
8782 \begin_inset ERT
8783 status collapsed
8784
8785 \begin_layout Standard
8786
8787
8788 \backslash
8789 /
8790 \end_layout
8791
8792 \end_inset
8793
8794 -no-std-crt0
8795 \series default
8796
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8798
8799 \end_inset
8800
8801  When linking, skip the standard crt0.o object file.
8802  You must provide your own crt0.o for your system when linking.
8803 \end_layout
8804
8805 \begin_layout List
8806 \labelwidthstring 00.00.0000
8807
8808 \series bold
8809 -
8810 \begin_inset ERT
8811 status collapsed
8812
8813 \begin_layout Standard
8814
8815
8816 \backslash
8817 /
8818 \end_layout
8819
8820 \end_inset
8821
8822 -portmode=
8823 \series default
8824 <Value>
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8826
8827 \end_inset
8828
8829  Determinate PORT I/O mode (<Value> is z80 or z180).
8830 \end_layout
8831
8832 \begin_layout List
8833 \labelwidthstring 00.00.0000
8834
8835 \series bold
8836 -
8837 \begin_inset ERT
8838 status collapsed
8839
8840 \begin_layout Standard
8841
8842
8843 \backslash
8844 /
8845 \end_layout
8846
8847 \end_inset
8848
8849 -asm=
8850 \series default
8851 <Value>
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8853
8854 \end_inset
8855
8856  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -codeseg
8877 \series default
8878 \InsetSpace ~
8879 <Value>
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8881
8882 \end_inset
8883
8884  Use <Value> for the code segment name.
8885 \end_layout
8886
8887 \begin_layout List
8888 \labelwidthstring 00.00.0000
8889
8890 \series bold
8891 -
8892 \begin_inset ERT
8893 status collapsed
8894
8895 \begin_layout Standard
8896
8897
8898 \backslash
8899 /
8900 \end_layout
8901
8902 \end_inset
8903
8904 -constseg
8905 \series default
8906 \InsetSpace ~
8907 <Value>
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8909
8910 \end_inset
8911
8912  Use <Value> for the const segment name.
8913 \end_layout
8914
8915 \begin_layout List
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8918 \end_inset
8919
8920
8921 \end_layout
8922
8923 \begin_layout Subsection
8924 GBZ80 Options
8925 \begin_inset LatexCommand \index{Options GBZ80}
8926
8927 \end_inset
8928
8929
8930 \begin_inset LatexCommand \index{GBZ80}
8931
8932 \end_inset
8933
8934
8935 \end_layout
8936
8937 \begin_layout List
8938 \labelwidthstring 00.00.0000
8939
8940 \series bold
8941 -
8942 \begin_inset ERT
8943 status collapsed
8944
8945 \begin_layout Standard
8946
8947
8948 \backslash
8949 /
8950 \end_layout
8951
8952 \end_inset
8953
8954 -callee-saves-bc
8955 \series default
8956
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8958
8959 \end_inset
8960
8961
8962 \size large
8963 \emph on
8964  
8965 \size default
8966 \emph default
8967 Force a called function to always save BC.
8968 \end_layout
8969
8970 \begin_layout List
8971 \labelwidthstring 00.00.0000
8972
8973 \series bold
8974 -
8975 \begin_inset ERT
8976 status collapsed
8977
8978 \begin_layout Standard
8979
8980
8981 \backslash
8982 /
8983 \end_layout
8984
8985 \end_inset
8986
8987 -no-std-crt0
8988 \series default
8989
8990 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8991
8992 \end_inset
8993
8994  When linking, skip the standard crt0.o object file.
8995  You must provide your own crt0.o for your system when linking.
8996 \end_layout
8997
8998 \begin_layout List
8999 \labelwidthstring 00.00.0000
9000
9001 \series bold
9002 -bo
9003 \series default
9004 \InsetSpace ~
9005 <Num>
9006 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9007
9008 \end_inset
9009
9010  Use code bank <Num>.
9011 \end_layout
9012
9013 \begin_layout List
9014 \labelwidthstring 00.00.0000
9015
9016 \series bold
9017 -ba
9018 \series default
9019 \InsetSpace ~
9020 <Num>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9022
9023 \end_inset
9024
9025  Use data bank <Num>.
9026 \end_layout
9027
9028 \begin_layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -
9033 \begin_inset ERT
9034 status collapsed
9035
9036 \begin_layout Standard
9037
9038
9039 \backslash
9040 /
9041 \end_layout
9042
9043 \end_inset
9044
9045 -codeseg
9046 \series default
9047 \InsetSpace ~
9048 <Value>
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9050
9051 \end_inset
9052
9053  Use <Value> for the code segment name.
9054 \end_layout
9055
9056 \begin_layout List
9057 \labelwidthstring 00.00.0000
9058
9059 \series bold
9060 -
9061 \begin_inset ERT
9062 status collapsed
9063
9064 \begin_layout Standard
9065
9066
9067 \backslash
9068 /
9069 \end_layout
9070
9071 \end_inset
9072
9073 -constseg
9074 \series default
9075 \InsetSpace ~
9076 <Value>
9077 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9078
9079 \end_inset
9080
9081  Use <Value> for the const segment name.
9082 \end_layout
9083
9084 \begin_layout Standard
9085 \begin_inset VSpace bigskip
9086 \end_inset
9087
9088
9089 \end_layout
9090
9091 \begin_layout Subsection
9092 Optimization Options
9093 \begin_inset LatexCommand \index{Options optimization}
9094
9095 \end_inset
9096
9097
9098 \begin_inset LatexCommand \index{Optimization options}
9099
9100 \end_inset
9101
9102
9103 \end_layout
9104
9105 \begin_layout List
9106 \labelwidthstring 00.00.0000
9107
9108 \series bold
9109 -
9110 \begin_inset ERT
9111 status collapsed
9112
9113 \begin_layout Standard
9114
9115
9116 \backslash
9117 /
9118 \end_layout
9119
9120 \end_inset
9121
9122 -nogcse
9123 \begin_inset LatexCommand \index{-\/-nogcse}
9124
9125 \end_inset
9126
9127
9128 \series default
9129  Will not do global subexpression elimination, this option may be used when
9130  the compiler creates undesirably large stack/data spaces to store compiler
9131  temporaries (
9132 \emph on
9133 s
9134 \emph default
9135 pill 
9136 \emph on
9137 loc
9138 \emph default
9139 ations, sloc
9140 \begin_inset LatexCommand \index{sloc (spill location)}
9141
9142 \end_inset
9143
9144 ).
9145  A warning message will be generated when this happens and the compiler
9146  will indicate the number of extra bytes it allocated.
9147  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9148 nogcse
9149 \begin_inset LatexCommand \index{\#pragma nogcse}
9150
9151 \end_inset
9152
9153  can be used to turn off global subexpression elimination
9154 \begin_inset LatexCommand \index{Subexpression elimination}
9155
9156 \end_inset
9157
9158  for a given function only.
9159 \end_layout
9160
9161 \begin_layout List
9162 \labelwidthstring 00.00.0000
9163
9164 \series bold
9165 -
9166 \begin_inset ERT
9167 status collapsed
9168
9169 \begin_layout Standard
9170
9171
9172 \backslash
9173 /
9174 \end_layout
9175
9176 \end_inset
9177
9178 -noinvariant
9179 \begin_inset LatexCommand \index{-\/-noinvariant}
9180
9181 \end_inset
9182
9183
9184 \series default
9185  Will not do loop invariant optimizations, this may be turned off for reasons
9186  explained for the previous option.
9187  For more details of loop optimizations performed see Loop Invariants in
9188  section 
9189 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9190
9191 \end_inset
9192
9193 .
9194  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9195 noinvariant
9196 \begin_inset LatexCommand \index{\#pragma noinvariant}
9197
9198 \end_inset
9199
9200  can be used to turn off invariant optimizations for a given function only.
9201 \end_layout
9202
9203 \begin_layout List
9204 \labelwidthstring 00.00.0000
9205
9206 \series bold
9207 -
9208 \begin_inset ERT
9209 status collapsed
9210
9211 \begin_layout Standard
9212
9213
9214 \backslash
9215 /
9216 \end_layout
9217
9218 \end_inset
9219
9220 -noinduction
9221 \begin_inset LatexCommand \index{-\/-noinduction}
9222
9223 \end_inset
9224
9225
9226 \series default
9227  Will not do loop induction optimizations, see section strength reduction
9228  for more details.
9229  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9230 noinduction
9231 \begin_inset LatexCommand \index{\#pragma noinduction}
9232
9233 \end_inset
9234
9235  can be used to turn off induction optimizations for a given function only.
9236 \end_layout
9237
9238 \begin_layout List
9239 \labelwidthstring 00.00.0000
9240
9241 \series bold
9242 -
9243 \begin_inset ERT
9244 status collapsed
9245
9246 \begin_layout Standard
9247
9248
9249 \backslash
9250 /
9251 \end_layout
9252
9253 \end_inset
9254
9255 -nojtbound
9256 \begin_inset LatexCommand \index{-\/-nojtbound}
9257
9258 \end_inset
9259
9260
9261 \size large
9262 \bar under
9263  
9264 \series default
9265 \size default
9266 \bar default
9267  Will not generate boundary condition check when switch statements
9268 \begin_inset LatexCommand \index{switch statement}
9269
9270 \end_inset
9271
9272  are implemented using jump-tables.
9273  See section 
9274 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9275
9276 \end_inset
9277
9278 \InsetSpace ~
9279 Switch Statements for more details.
9280  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9281 nojtbound
9282 \begin_inset LatexCommand \index{\#pragma nojtbound}
9283
9284 \end_inset
9285
9286  can be used to turn off boundary checking for jump tables for a given function
9287  only.
9288 \end_layout
9289
9290 \begin_layout List
9291 \labelwidthstring 00.00.0000
9292
9293 \series bold
9294 -
9295 \begin_inset ERT
9296 status collapsed
9297
9298 \begin_layout Standard
9299
9300
9301 \backslash
9302 /
9303 \end_layout
9304
9305 \end_inset
9306
9307 -noloopreverse
9308 \begin_inset LatexCommand \index{-\/-noloopreverse}
9309
9310 \end_inset
9311
9312
9313 \series default
9314 \size large
9315  
9316 \size default
9317 Will not do loop reversal 
9318 \begin_inset LatexCommand \index{Loop reversing}
9319
9320 \end_inset
9321
9322 optimization.
9323 \end_layout
9324
9325 \begin_layout List
9326 \labelwidthstring 00.00.0000
9327 -
9328 \begin_inset ERT
9329 status collapsed
9330
9331 \begin_layout Standard
9332
9333
9334 \backslash
9335 /
9336 \end_layout
9337
9338 \end_inset
9339
9340 -
9341 \series bold
9342 nolabelopt
9343 \series default
9344  
9345 \begin_inset LatexCommand \index{-\/-nolabelopt }
9346
9347 \end_inset
9348
9349 Will not optimize labels (makes the dumpfiles more readable).
9350 \end_layout
9351
9352 \begin_layout List
9353 \labelwidthstring 00.00.0000
9354
9355 \series bold
9356 -
9357 \begin_inset ERT
9358 status collapsed
9359
9360 \begin_layout Standard
9361
9362
9363 \backslash
9364 /
9365 \end_layout
9366
9367 \end_inset
9368
9369 -no-xinit-opt
9370 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9371
9372 \end_inset
9373
9374
9375 \series default
9376  Will not memcpy initialized data from code space into xdata space.
9377  This saves a few bytes in code space if you don't have initialized data
9378 \begin_inset LatexCommand \index{Variable initialization}
9379
9380 \end_inset
9381
9382 .
9383 \end_layout
9384
9385 \begin_layout List
9386 \labelwidthstring 00.00.0000
9387
9388 \series bold
9389 -
9390 \begin_inset ERT
9391 status collapsed
9392
9393 \begin_layout Standard
9394
9395
9396 \backslash
9397 /
9398 \end_layout
9399
9400 \end_inset
9401
9402 -nooverlay
9403 \begin_inset LatexCommand \index{-\/-nooverlay}
9404
9405 \end_inset
9406
9407
9408 \series default
9409   The compiler will not overlay parameters and local variables of any function,
9410  see section Parameters and local variables for more details.
9411 \end_layout
9412
9413 \begin_layout List
9414 \labelwidthstring 00.00.0000
9415
9416 \series bold
9417 -
9418 \begin_inset ERT
9419 status collapsed
9420
9421 \begin_layout Standard
9422
9423
9424 \backslash
9425 /
9426 \end_layout
9427
9428 \end_inset
9429
9430 -no-peep
9431 \begin_inset LatexCommand \index{-\/-no-peep}
9432
9433 \end_inset
9434
9435
9436 \series default
9437  Disable peep-hole optimization with built-in rules.
9438 \end_layout
9439
9440 \begin_layout List
9441 \labelwidthstring 00.00.0000
9442
9443 \series bold
9444 -
9445 \begin_inset ERT
9446 status collapsed
9447
9448 \begin_layout Standard
9449
9450
9451 \backslash
9452 /
9453 \end_layout
9454
9455 \end_inset
9456
9457 -peep-file
9458 \series default
9459
9460 \begin_inset LatexCommand \index{-\/-peep-file}
9461
9462 \end_inset
9463
9464 \InsetSpace ~
9465 <filename> This option can be used to use additional rules to be used by
9466  the peep hole optimizer.
9467  See section 
9468 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9469
9470 \end_inset
9471
9472 \InsetSpace ~
9473 Peep Hole optimizations for details on how to write these rules.
9474 \end_layout
9475
9476 \begin_layout List
9477 \labelwidthstring 00.00.0000
9478
9479 \series bold
9480 -
9481 \begin_inset ERT
9482 status collapsed
9483
9484 \begin_layout Standard
9485
9486
9487 \backslash
9488 /
9489 \end_layout
9490
9491 \end_inset
9492
9493 -peep-asm
9494 \begin_inset LatexCommand \index{-\/-peep-asm}
9495
9496 \end_inset
9497
9498
9499 \series default
9500  Pass the inline assembler code through the peep hole optimizer.
9501  This can cause unexpected changes to inline assembler code, please go through
9502  the peephole optimizer
9503 \begin_inset LatexCommand \index{Peephole optimizer}
9504
9505 \end_inset
9506
9507  rules defined in the source file tree '<target>/peeph.def' before using
9508  this option.
9509 \end_layout
9510
9511 \begin_layout List
9512 \labelwidthstring 00.00.0000
9513
9514 \series bold
9515 -
9516 \begin_inset ERT
9517 status collapsed
9518
9519 \begin_layout Standard
9520
9521
9522 \backslash
9523 /
9524 \end_layout
9525
9526 \end_inset
9527
9528 -opt-code-speed
9529 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9530
9531 \end_inset
9532
9533
9534 \series default
9535  The compiler will optimize code generation towards fast code, possibly
9536  at the expense of code size.
9537 \end_layout
9538
9539 \begin_layout List
9540 \labelwidthstring 00.00.0000
9541
9542 \series bold
9543 -
9544 \begin_inset ERT
9545 status collapsed
9546
9547 \begin_layout Standard
9548
9549
9550 \backslash
9551 /
9552 \end_layout
9553
9554 \end_inset
9555
9556 -opt-code-size
9557 \begin_inset LatexCommand \index{-\/-opt-code-size}
9558
9559 \end_inset
9560
9561
9562 \series default
9563  The compiler will optimize code generation towards compact code, possibly
9564  at the expense of code speed.
9565 \end_layout
9566
9567 \begin_layout Standard
9568 \begin_inset VSpace bigskip
9569 \end_inset
9570
9571
9572 \end_layout
9573
9574 \begin_layout Subsection
9575 Other Options
9576 \begin_inset LatexCommand \index{Options other}
9577
9578 \end_inset
9579
9580
9581 \end_layout
9582
9583 \begin_layout List
9584 \labelwidthstring 00.00.0000
9585
9586 \series bold
9587 -c\InsetSpace ~
9588 -
9589 \begin_inset ERT
9590 status collapsed
9591
9592 \begin_layout Standard
9593
9594
9595 \backslash
9596 /
9597 \end_layout
9598
9599 \end_inset
9600
9601 -compile-only
9602 \begin_inset LatexCommand \index{-\/-compile-only}
9603
9604 \end_inset
9605
9606
9607 \begin_inset LatexCommand \index{-c -\/-compile-only}
9608
9609 \end_inset
9610
9611
9612 \series default
9613  will compile and assemble the source, but will not call the linkage editor.
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \series default
9622
9623 \begin_inset ERT
9624 status collapsed
9625
9626 \begin_layout Standard
9627
9628
9629 \backslash
9630 /
9631 \end_layout
9632
9633 \end_inset
9634
9635
9636 \series bold
9637 -c1mode
9638 \begin_inset LatexCommand \index{-\/-c1mode}
9639
9640 \end_inset
9641
9642
9643 \series default
9644  reads the preprocessed source from standard input and compiles it.
9645  The file name for the assembler output must be specified using the -o option.
9646 \end_layout
9647
9648 \begin_layout List
9649 \labelwidthstring 00.00.0000
9650
9651 \series bold
9652 -E
9653 \begin_inset LatexCommand \index{-E}
9654
9655 \end_inset
9656
9657
9658 \series default
9659  Run only the C preprocessor.
9660  Preprocess all the C source files specified and output the results to standard
9661  output.
9662 \end_layout
9663
9664 \begin_layout List
9665 \labelwidthstring 00.00.0000
9666
9667 \series bold
9668 -o\InsetSpace ~
9669 <path/file>
9670 \begin_inset LatexCommand \index{-o <path/file>}
9671
9672 \end_inset
9673
9674  
9675 \series default
9676 The output path where everything will be placed or the file name used for
9677  all generated output files.
9678  If the parameter is a path, it must have a trailing slash (or backslash
9679  for the Windows binaries) to be recognized as a path.
9680
9681 \emph on
9682  
9683 \emph default
9684 Note for Windows users: if the path contains spaces, it should be surrounded
9685  by quotes.
9686  The trailing backslash should be doubled in order to prevent escaping the
9687  final quote, for example: 
9688 \emph on
9689 -o 
9690 \begin_inset Quotes sld
9691 \end_inset
9692
9693 F:
9694 \backslash
9695 Projects
9696 \backslash
9697 test3
9698 \backslash
9699 output 1
9700 \backslash
9701
9702 \backslash
9703
9704 \begin_inset Quotes srd
9705 \end_inset
9706
9707
9708 \emph default
9709  or put after the final quote, for example: 
9710 \emph on
9711 -o 
9712 \begin_inset Quotes sld
9713 \end_inset
9714
9715 F:
9716 \backslash
9717 Projects
9718 \backslash
9719 test3
9720 \backslash
9721 output 1
9722 \begin_inset Quotes srd
9723 \end_inset
9724
9725
9726 \backslash
9727
9728 \emph default
9729 .
9730  The path using slashes for directory delimiters can be used too, for example:
9731  
9732 \emph on
9733 -o 
9734 \begin_inset Quotes sld
9735 \end_inset
9736
9737 F:/Projects/test3/output 1/
9738 \begin_inset Quotes srd
9739 \end_inset
9740
9741
9742 \emph default
9743 .
9744 \end_layout
9745
9746 \begin_layout List
9747 \labelwidthstring 00.00.0000
9748
9749 \series bold
9750 -
9751 \begin_inset ERT
9752 status collapsed
9753
9754 \begin_layout Standard
9755
9756
9757 \backslash
9758 /
9759 \end_layout
9760
9761 \end_inset
9762
9763 -stack-auto
9764 \begin_inset LatexCommand \index{-\/-stack-auto}
9765
9766 \end_inset
9767
9768
9769 \series default
9770 \size large
9771 \emph on
9772  
9773 \size default
9774 \emph default
9775 All functions in the source file will be compiled as 
9776 \emph on
9777 reentrant
9778 \emph default
9779
9780 \begin_inset LatexCommand \index{reentrant}
9781
9782 \end_inset
9783
9784 , i.e.
9785  the parameters and local variables will be allocated on the stack
9786 \begin_inset LatexCommand \index{stack}
9787
9788 \end_inset
9789
9790 .
9791  See section 
9792 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9793
9794 \end_inset
9795
9796  Parameters and Local Variables for more details.
9797  If this option is used all source files in the project should be compiled
9798  with this option.
9799  It automatically implies -
9800 \series bold
9801
9802 \begin_inset ERT
9803 status open
9804
9805 \begin_layout Standard
9806
9807
9808 \backslash
9809 /
9810 \end_layout
9811
9812 \end_inset
9813
9814
9815 \series default
9816 -int-long-reent and -
9817 \series bold
9818
9819 \begin_inset ERT
9820 status open
9821
9822 \begin_layout Standard
9823
9824
9825 \backslash
9826 /
9827 \end_layout
9828
9829 \end_inset
9830
9831
9832 \series default
9833 -float-reent.
9834  
9835 \end_layout
9836
9837 \begin_layout List
9838 \labelwidthstring 00.00.0000
9839
9840 \series bold
9841 -
9842 \begin_inset ERT
9843 status collapsed
9844
9845 \begin_layout Standard
9846
9847
9848 \backslash
9849 /
9850 \end_layout
9851
9852 \end_inset
9853
9854 -callee-saves
9855 \begin_inset LatexCommand \index{-\/-callee-saves}
9856
9857 \end_inset
9858
9859  
9860 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9861
9862 \end_inset
9863
9864 function1[,function2][,function3]....
9865
9866 \series default
9867  The compiler by default uses a caller saves convention for register saving
9868  across function calls, however this can cause unnecessary register pushing
9869  and popping when calling small functions from larger functions.
9870  This option can be used to switch the register saving convention for the
9871  function names specified.
9872  The compiler will not save registers when calling these functions, no extra
9873  code will be generated at the entry and exit (function prologue
9874 \series bold
9875
9876 \begin_inset LatexCommand \index{function prologue}
9877
9878 \end_inset
9879
9880
9881 \series default
9882  and epilogue
9883 \series bold
9884
9885 \begin_inset LatexCommand \index{function epilogue}
9886
9887 \end_inset
9888
9889
9890 \series default
9891 ) for these functions to save and restore the registers used by these functions,
9892  this can SUBSTANTIALLY reduce code and improve run time performance of
9893  the generated code.
9894  In the future the compiler (with inter procedural analysis) will be able
9895  to determine the appropriate scheme to use for each function call.
9896  DO NOT use this option for built-in functions such as _mulint..., if this
9897  option is used for a library function the appropriate library function
9898  needs to be recompiled with the same option.
9899  If the project consists of multiple source files then all the source file
9900  should be compiled with the same -
9901 \begin_inset ERT
9902 status collapsed
9903
9904 \begin_layout Standard
9905
9906
9907 \backslash
9908 /
9909 \end_layout
9910
9911 \end_inset
9912
9913 -callee-saves option string.
9914  Also see #pragma\InsetSpace ~
9915 callee_saves 
9916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9917
9918 \end_inset
9919
9920  
9921 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9922
9923 \end_inset
9924
9925 .
9926 \end_layout
9927
9928 \begin_layout List
9929 \labelwidthstring 00.00.0000
9930
9931 \series bold
9932 -
9933 \begin_inset ERT
9934 status collapsed
9935
9936 \begin_layout Standard
9937
9938
9939 \backslash
9940 /
9941 \end_layout
9942
9943 \end_inset
9944
9945 -all-callee-saves
9946 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9947
9948 \end_inset
9949
9950  
9951 \series default
9952 Function of
9953 \series bold
9954  
9955 \series default
9956 -
9957 \begin_inset ERT
9958 status collapsed
9959
9960 \begin_layout Standard
9961
9962
9963 \backslash
9964 /
9965 \end_layout
9966
9967 \end_inset
9968
9969 -callee-saves will be applied to all functions by default.
9970 \end_layout
9971
9972 \begin_layout List
9973 \labelwidthstring 00.00.0000
9974
9975 \series bold
9976 -
9977 \begin_inset ERT
9978 status collapsed
9979
9980 \begin_layout Standard
9981
9982
9983 \backslash
9984 /
9985 \end_layout
9986
9987 \end_inset
9988
9989 -debug
9990 \begin_inset LatexCommand \index{-\/-debug}
9991
9992 \end_inset
9993
9994
9995 \bar under
9996  
9997 \series default
9998 \bar default
9999 When this option is used the compiler will generate debug information.
10000  The debug information collected in a file with .cdb extension can be used
10001  with the SDCDB.
10002  For more information see documentation for SDCDB.
10003  Another file with no extension contains debug information in AOMF or AOMF51
10004 \begin_inset LatexCommand \index{AOMF, AOMF51}
10005
10006 \end_inset
10007
10008  format which is commonly used by third party tools.
10009 \end_layout
10010
10011 \begin_layout List
10012 \labelwidthstring 00.00.0000
10013
10014 \series bold
10015 -S
10016 \begin_inset LatexCommand \index{-S}
10017
10018 \end_inset
10019
10020
10021 \size large
10022 \bar under
10023  
10024 \series default
10025 \size default
10026 \bar default
10027 Stop after the stage of compilation proper; do not assemble.
10028  The output is an assembler code file for the input file specified.
10029 \end_layout
10030
10031 \begin_layout List
10032 \labelwidthstring 00.00.0000
10033
10034 \series bold
10035 -
10036 \begin_inset ERT
10037 status collapsed
10038
10039 \begin_layout Standard
10040
10041
10042 \backslash
10043 /
10044 \end_layout
10045
10046 \end_inset
10047
10048 -int-long-reent
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10050
10051 \end_inset
10052
10053
10054 \series default
10055  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10056  Note by default these libraries are compiled as non-reentrant.
10057  See section Installation for more details.
10058 \end_layout
10059
10060 \begin_layout List
10061 \labelwidthstring 00.00.0000
10062
10063 \series bold
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -cyclomatic
10078 \begin_inset LatexCommand \index{-\/-cyclomatic}
10079
10080 \end_inset
10081
10082
10083 \bar under
10084  
10085 \series default
10086 \bar default
10087 This option will cause the compiler to generate an information message for
10088  each function in the source file.
10089  The message contains some 
10090 \emph on
10091 important
10092 \emph default
10093  information about the function.
10094  The number of edges and nodes the compiler detected in the control flow
10095  graph of the function, and most importantly the 
10096 \emph on
10097 cyclomatic complexity
10098 \begin_inset LatexCommand \index{Cyclomatic complexity}
10099
10100 \end_inset
10101
10102
10103 \emph default
10104  see section on Cyclomatic Complexity for more details.
10105 \end_layout
10106
10107 \begin_layout List
10108 \labelwidthstring 00.00.0000
10109
10110 \series bold
10111 -
10112 \begin_inset ERT
10113 status collapsed
10114
10115 \begin_layout Standard
10116
10117
10118 \backslash
10119 /
10120 \end_layout
10121
10122 \end_inset
10123
10124 -float-reent
10125 \begin_inset LatexCommand \index{-\/-float-reent}
10126
10127 \end_inset
10128
10129
10130 \series default
10131  Floating point library is compiled as reentrant
10132 \begin_inset LatexCommand \index{reentrant}
10133
10134 \end_inset
10135
10136 .
10137  See section Installation for more details.
10138 \end_layout
10139
10140 \begin_layout List
10141 \labelwidthstring 00.00.0000
10142
10143 \series bold
10144 -
10145 \begin_inset ERT
10146 status collapsed
10147
10148 \begin_layout Standard
10149
10150
10151 \backslash
10152 /
10153 \end_layout
10154
10155 \end_inset
10156
10157 -funsigned-char
10158 \begin_inset LatexCommand \index{-\/-funsigned-char}
10159
10160 \end_inset
10161
10162
10163 \series default
10164  The default signedness for every type is
10165 \family typewriter
10166  signed
10167 \family default
10168 .
10169  In some embedded environments the default signedness of
10170 \family typewriter
10171  char
10172 \family default
10173  is
10174 \family typewriter
10175  unsigned
10176 \family default
10177 .
10178  To set the signess for characters to unsigned, use the option -
10179 \series bold
10180
10181 \begin_inset ERT
10182 status open
10183
10184 \begin_layout Standard
10185
10186
10187 \backslash
10188 /
10189 \end_layout
10190
10191 \end_inset
10192
10193
10194 \series default
10195 -funsigned-char.
10196  If this option is set and no signedness keyword (unsigned/signed) is given,
10197  a char will be signed.
10198  All other types are unaffected.
10199 \end_layout
10200
10201 \begin_layout List
10202 \labelwidthstring 00.00.0000
10203
10204 \series bold
10205 -
10206 \begin_inset ERT
10207 status collapsed
10208
10209 \begin_layout Standard
10210
10211
10212 \backslash
10213 /
10214 \end_layout
10215
10216 \end_inset
10217
10218 -main-return
10219 \begin_inset LatexCommand \index{-\/-main-return}
10220
10221 \end_inset
10222
10223
10224 \series default
10225  This option can be used if the code generated is called by a monitor program
10226  or if the main routine includes an endless loop.
10227  This option results in slightly smaller code and saves two bytes of stack
10228  space.
10229  The return from the 'main'
10230 \begin_inset LatexCommand \index{main return}
10231
10232 \end_inset
10233
10234  function will return to the function calling main.
10235  The default setting is to lock up i.e.
10236  generate a '
10237 \family typewriter
10238 sjmp .
10239 \family default
10240 '.
10241 \end_layout
10242
10243 \begin_layout List
10244 \labelwidthstring 00.00.0000
10245
10246 \series bold
10247 -
10248 \begin_inset ERT
10249 status collapsed
10250
10251 \begin_layout Standard
10252
10253
10254 \backslash
10255 /
10256 \end_layout
10257
10258 \end_inset
10259
10260 -nostdinc
10261 \begin_inset LatexCommand \index{-\/-nostdinc}
10262
10263 \end_inset
10264
10265
10266 \series default
10267  This will prevent the compiler from passing on the default include path
10268  to the preprocessor.
10269 \end_layout
10270
10271 \begin_layout List
10272 \labelwidthstring 00.00.0000
10273
10274 \series bold
10275 -
10276 \begin_inset ERT
10277 status collapsed
10278
10279 \begin_layout Standard
10280
10281
10282 \backslash
10283 /
10284 \end_layout
10285
10286 \end_inset
10287
10288 -nostdlib
10289 \begin_inset LatexCommand \index{-\/-nostdlib}
10290
10291 \end_inset
10292
10293
10294 \series default
10295  This will prevent the compiler from passing on the default library
10296 \begin_inset LatexCommand \index{Libraries}
10297
10298 \end_inset
10299
10300  path to the linker.
10301 \end_layout
10302
10303 \begin_layout List
10304 \labelwidthstring 00.00.0000
10305
10306 \series bold
10307 -
10308 \begin_inset ERT
10309 status collapsed
10310
10311 \begin_layout Standard
10312
10313
10314 \backslash
10315 /
10316 \end_layout
10317
10318 \end_inset
10319
10320 -verbose
10321 \begin_inset LatexCommand \index{-\/-verbose}
10322
10323 \end_inset
10324
10325
10326 \series default
10327  Shows the various actions the compiler is performing.
10328 \end_layout
10329
10330 \begin_layout List
10331 \labelwidthstring 00.00.0000
10332
10333 \series bold
10334 -V
10335 \begin_inset LatexCommand \index{-V}
10336
10337 \end_inset
10338
10339
10340 \series default
10341  Shows the actual commands the compiler is executing.
10342 \end_layout
10343
10344 \begin_layout List
10345 \labelwidthstring 00.00.0000
10346
10347 \series bold
10348 -
10349 \begin_inset ERT
10350 status collapsed
10351
10352 \begin_layout Standard
10353
10354
10355 \backslash
10356 /
10357 \end_layout
10358
10359 \end_inset
10360
10361 -no-c-code-in-asm
10362 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10363
10364 \end_inset
10365
10366
10367 \series default
10368  Hides your ugly and inefficient c-code from the asm file, so you can always
10369  blame the compiler :)
10370 \end_layout
10371
10372 \begin_layout List
10373 \labelwidthstring 00.00.0000
10374
10375 \series bold
10376 -
10377 \begin_inset ERT
10378 status collapsed
10379
10380 \begin_layout Standard
10381
10382
10383 \backslash
10384 /
10385 \end_layout
10386
10387 \end_inset
10388
10389 -fverbose-asm
10390 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10391
10392 \end_inset
10393
10394
10395 \series default
10396  Include code generator and peep-hole comments in the generated asm files.
10397 \end_layout
10398
10399 \begin_layout List
10400 \labelwidthstring 00.00.0000
10401
10402 \series bold
10403 -
10404 \begin_inset ERT
10405 status collapsed
10406
10407 \begin_layout Standard
10408
10409
10410 \backslash
10411 /
10412 \end_layout
10413
10414 \end_inset
10415
10416 -no-peep-comments
10417 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10418
10419 \end_inset
10420
10421
10422 \series default
10423  Don't include peep-hole comments in the generated asm files even if -
10424 \series bold
10425
10426 \begin_inset ERT
10427 status open
10428
10429 \begin_layout Standard
10430
10431
10432 \backslash
10433 /
10434 \end_layout
10435
10436 \end_inset
10437
10438
10439 \series default
10440 -fverbose-asm option is specified.
10441 \end_layout
10442
10443 \begin_layout List
10444 \labelwidthstring 00.00.0000
10445
10446 \series bold
10447 -
10448 \begin_inset ERT
10449 status collapsed
10450
10451 \begin_layout Standard
10452
10453
10454 \backslash
10455 /
10456 \end_layout
10457
10458 \end_inset
10459
10460 -i-code-in-asm
10461 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10462
10463 \end_inset
10464
10465
10466 \series default
10467  Include i-codes in the asm file.
10468  Sounds like noise but is most helpful for debugging the compiler itself.
10469 \end_layout
10470
10471 \begin_layout List
10472 \labelwidthstring 00.00.0000
10473
10474 \series bold
10475 -
10476 \begin_inset ERT
10477 status collapsed
10478
10479 \begin_layout Standard
10480
10481
10482 \backslash
10483 /
10484 \end_layout
10485
10486 \end_inset
10487
10488 -less-pedantic
10489 \begin_inset LatexCommand \index{pedantic}
10490
10491 \end_inset
10492
10493
10494 \begin_inset LatexCommand \index{-\/-less-pedantic}
10495
10496 \end_inset
10497
10498
10499 \series default
10500
10501 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10502
10503 \end_inset
10504
10505  Disable some of the more pedantic warnings
10506 \begin_inset LatexCommand \index{Warnings}
10507
10508 \end_inset
10509
10510 .
10511  For more details, see the less_pedantic pragma 
10512 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10513
10514 \end_inset
10515
10516 .
10517 \end_layout
10518
10519 \begin_layout List
10520 \labelwidthstring 00.00.0000
10521
10522 \series bold
10523 -
10524 \begin_inset ERT
10525 status collapsed
10526
10527 \begin_layout Standard
10528
10529
10530 \backslash
10531 /
10532 \end_layout
10533
10534 \end_inset
10535
10536 -disable-warning\InsetSpace ~
10537 <nnnn>
10538 \begin_inset LatexCommand \index{-\/-disable-warning}
10539
10540 \end_inset
10541
10542
10543 \series default
10544  Disable specific warning with number <nnnn>.
10545 \end_layout
10546
10547 \begin_layout List
10548 \labelwidthstring 00.00.0000
10549
10550 \series bold
10551 -
10552 \begin_inset ERT
10553 status collapsed
10554
10555 \begin_layout Standard
10556
10557
10558 \backslash
10559 /
10560 \end_layout
10561
10562 \end_inset
10563
10564 -Werror
10565 \begin_inset LatexCommand \index{-\/-Werror}
10566
10567 \end_inset
10568
10569
10570 \series default
10571  Treat all warnings as errors.
10572 \end_layout
10573
10574 \begin_layout List
10575 \labelwidthstring 00.00.0000
10576
10577 \series bold
10578 -
10579 \begin_inset ERT
10580 status collapsed
10581
10582 \begin_layout Standard
10583
10584
10585 \backslash
10586 /
10587 \end_layout
10588
10589 \end_inset
10590
10591 -print-search-dirs
10592 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10593
10594 \end_inset
10595
10596
10597 \series default
10598  Display the directories in the compiler's search path
10599 \end_layout
10600
10601 \begin_layout List
10602 \labelwidthstring 00.00.0000
10603
10604 \series bold
10605 -
10606 \begin_inset ERT
10607 status collapsed
10608
10609 \begin_layout Standard
10610
10611
10612 \backslash
10613 /
10614 \end_layout
10615
10616 \end_inset
10617
10618 -vc
10619 \begin_inset LatexCommand \index{-\/-vc}
10620
10621 \end_inset
10622
10623
10624 \series default
10625  Display errors and warnings using MSVC style, so you can use SDCC with
10626  the visual studio IDE
10627 \begin_inset LatexCommand \index{IDE}
10628
10629 \end_inset
10630
10631 .
10632  With SDCC both offering a GCC-like (the default) and a MSVC-like
10633 \begin_inset LatexCommand \index{MSVC output style}
10634
10635 \end_inset
10636
10637  output style, integration into most programming editors should be straightforwa
10638 rd.
10639 \end_layout
10640
10641 \begin_layout List
10642 \labelwidthstring 00.00.0000
10643
10644 \series bold
10645 -
10646 \begin_inset ERT
10647 status collapsed
10648
10649 \begin_layout Standard
10650
10651
10652 \backslash
10653 /
10654 \end_layout
10655
10656 \end_inset
10657
10658 -use-stdout
10659 \begin_inset LatexCommand \index{-\/-use-stdout}
10660
10661 \end_inset
10662
10663
10664 \series default
10665  Send errors and warnings to stdout instead of stderr.
10666 \end_layout
10667
10668 \begin_layout List
10669 \labelwidthstring 00.00.0000
10670
10671 \series bold
10672 -Wa\InsetSpace ~
10673 asmOption[,asmOption]
10674 \series default
10675
10676 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10677
10678 \end_inset
10679
10680 ...
10681  Pass the asmOption to the assembler
10682 \begin_inset LatexCommand \index{Options assembler}
10683
10684 \end_inset
10685
10686
10687 \begin_inset LatexCommand \index{Assembler options}
10688
10689 \end_inset
10690
10691 .
10692  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10693 \end_layout
10694
10695 \begin_layout List
10696 \labelwidthstring 00.00.0000
10697
10698 \series bold
10699 -
10700 \begin_inset ERT
10701 status collapsed
10702
10703 \begin_layout Standard
10704
10705
10706 \backslash
10707 /
10708 \end_layout
10709
10710 \end_inset
10711
10712 -std-sdcc89
10713 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10714
10715 \end_inset
10716
10717
10718 \series default
10719  Generally follow the C89 standard, but allow SDCC features that conflict
10720  with the standard (default).
10721 \end_layout
10722
10723 \begin_layout List
10724 \labelwidthstring 00.00.0000
10725
10726 \series bold
10727 -
10728 \begin_inset ERT
10729 status collapsed
10730
10731 \begin_layout Standard
10732
10733
10734 \backslash
10735 /
10736 \end_layout
10737
10738 \end_inset
10739
10740 -std-c89
10741 \begin_inset LatexCommand \index{-\/-std-c89}
10742
10743 \end_inset
10744
10745
10746 \series default
10747  Follow the C89 standard and disable SDCC features that conflict with the
10748  standard.
10749 \end_layout
10750
10751 \begin_layout List
10752 \labelwidthstring 00.00.0000
10753
10754 \series bold
10755 -
10756 \begin_inset ERT
10757 status collapsed
10758
10759 \begin_layout Standard
10760
10761
10762 \backslash
10763 /
10764 \end_layout
10765
10766 \end_inset
10767
10768 -std-sdcc99
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10770
10771 \end_inset
10772
10773
10774 \series default
10775  Generally follow the C99 standard, but allow SDCC features that conflict
10776  with the standard (incomplete support).
10777 \end_layout
10778
10779 \begin_layout List
10780 \labelwidthstring 00.00.0000
10781
10782 \series bold
10783 -
10784 \begin_inset ERT
10785 status collapsed
10786
10787 \begin_layout Standard
10788
10789
10790 \backslash
10791 /
10792 \end_layout
10793
10794 \end_inset
10795
10796 -std-c99
10797 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10798
10799 \end_inset
10800
10801
10802 \series default
10803  Follow the C99 standard and disable SDCC features that conflict with the
10804  standard (incomplete support).
10805 \end_layout
10806
10807 \begin_layout List
10808 \labelwidthstring 00.00.0000
10809
10810 \series bold
10811 -
10812 \begin_inset ERT
10813 status collapsed
10814
10815 \begin_layout Standard
10816
10817
10818 \backslash
10819 /
10820 \end_layout
10821
10822 \end_inset
10823
10824 -codeseg
10825 \series default
10826
10827 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10828
10829 \end_inset
10830
10831 \InsetSpace ~
10832 <Name> The name to be used for the code
10833 \begin_inset LatexCommand \index{code}
10834
10835 \end_inset
10836
10837  segment, default CSEG.
10838  This is useful if you need to tell the compiler to put the code in a special
10839  segment so you can later on tell the linker to put this segment in a special
10840  place in memory.
10841  Can be used for instance when using bank switching to put the code in a
10842  bank.
10843 \end_layout
10844
10845 \begin_layout List
10846 \labelwidthstring 00.00.0000
10847
10848 \series bold
10849 -
10850 \begin_inset ERT
10851 status collapsed
10852
10853 \begin_layout Standard
10854
10855
10856 \backslash
10857 /
10858 \end_layout
10859
10860 \end_inset
10861
10862 -constseg
10863 \series default
10864
10865 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10866
10867 \end_inset
10868
10869 \InsetSpace ~
10870 <Name> The name to be used for the const
10871 \begin_inset LatexCommand \index{const}
10872
10873 \end_inset
10874
10875  segment, default CONST.
10876  This is useful if you need to tell the compiler to put the const data in
10877  a special segment so you can later on tell the linker to put this segment
10878  in a special place in memory.
10879  Can be used for instance when using bank switching to put the const data
10880  in a bank.
10881 \end_layout
10882
10883 \begin_layout List
10884 \labelwidthstring 00.00.0000
10885
10886 \series bold
10887 -
10888 \begin_inset ERT
10889 status collapsed
10890
10891 \begin_layout Standard
10892
10893
10894 \backslash
10895 /
10896 \end_layout
10897
10898 \end_inset
10899
10900 -fdollars-in-identifiers
10901 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10902
10903 \end_inset
10904
10905
10906 \series default
10907  Permit '$' as an identifier character.
10908 \end_layout
10909
10910 \begin_layout List
10911 \labelwidthstring 00.00.0000
10912
10913 \series bold
10914 -
10915 \begin_inset ERT
10916 status collapsed
10917
10918 \begin_layout Standard
10919
10920
10921 \backslash
10922 /
10923 \end_layout
10924
10925 \end_inset
10926
10927 -more-pedantic
10928 \series default
10929
10930 \begin_inset LatexCommand \index{-\/-more-pedantic}
10931
10932 \end_inset
10933
10934
10935 \begin_inset LatexCommand \index{pedantic}
10936
10937 \end_inset
10938
10939  Actually this is 
10940 \series bold
10941 \emph on
10942 not
10943 \series default
10944 \emph default
10945  a SDCC compiler option but if you want 
10946 \emph on
10947 more
10948 \emph default
10949  warnings you can use a separate tool dedicated to syntax checking like
10950  splint
10951 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10952
10953 \end_inset
10954
10955
10956 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10957
10958 \end_inset
10959
10960  
10961 \begin_inset LatexCommand \url{http://www.splint.org}
10962
10963 \end_inset
10964
10965 .
10966  To make your source files parseable by splint you will have to include
10967  
10968 \family sans
10969 lint.h
10970 \family default
10971
10972 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10973
10974 \end_inset
10975
10976  in your source file and add brackets around extended keywords (like 
10977 \family sans
10978
10979 \begin_inset Quotes sld
10980 \end_inset
10981
10982 __at\InsetSpace ~
10983
10984 \series bold
10985 (
10986 \series default
10987 0xab
10988 \series bold
10989 )
10990 \series default
10991
10992 \begin_inset Quotes srd
10993 \end_inset
10994
10995
10996 \family default
10997  and 
10998 \family sans
10999
11000 \begin_inset Quotes sld
11001 \end_inset
11002
11003 __interrupt\InsetSpace ~
11004 (2)
11005 \begin_inset Quotes srd
11006 \end_inset
11007
11008
11009 \family default
11010 ).
11011  
11012 \newline
11013 Splint has an excellent on line manual at 
11014 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11015
11016 \end_inset
11017
11018  and it's capabilities go beyond pure syntax checking.
11019  You'll need to tell splint the location of SDCC's include files so a typical
11020  command line could look like this: 
11021 \newline
11022
11023 \family sans
11024 splint\InsetSpace ~
11025 -I\InsetSpace ~
11026 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11027 \InsetSpace ~
11028 myprogram.c
11029 \end_layout
11030
11031 \begin_layout List
11032 \labelwidthstring 00.00.0000
11033
11034 \series bold
11035 -
11036 \begin_inset ERT
11037 status collapsed
11038
11039 \begin_layout Standard
11040
11041
11042 \backslash
11043 /
11044 \end_layout
11045
11046 \end_inset
11047
11048 -short-is-8bits
11049 \series default
11050
11051 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11052
11053 \end_inset
11054
11055
11056 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11057
11058 \end_inset
11059
11060  Treat short as 8-bit (for backward compatibility with older versions of
11061  compiler - see section 
11062 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11063
11064 \end_inset
11065
11066 )
11067 \end_layout
11068
11069 \begin_layout Standard
11070 \begin_inset VSpace bigskip
11071 \end_inset
11072
11073
11074 \end_layout
11075
11076 \begin_layout Subsection
11077 Intermediate Dump Options
11078 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11079
11080 \end_inset
11081
11082
11083 \begin_inset LatexCommand \index{Options intermediate dump}
11084
11085 \end_inset
11086
11087
11088 \begin_inset LatexCommand \index{Intermediate dump options}
11089
11090 \end_inset
11091
11092
11093 \end_layout
11094
11095 \begin_layout Standard
11096 The following options are provided for the purpose of retargetting and debugging
11097  the compiler.
11098  They provide a means to dump the intermediate code (iCode
11099 \begin_inset LatexCommand \index{iCode}
11100
11101 \end_inset
11102
11103 ) generated by the compiler in human readable form at various stages of
11104  the compilation process.
11105  More on iCodes see chapter 
11106 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11107
11108 \end_inset
11109
11110  
11111 \begin_inset Quotes srd
11112 \end_inset
11113
11114 The anatomy of the compiler
11115 \begin_inset Quotes srd
11116 \end_inset
11117
11118 .
11119 \end_layout
11120
11121 \begin_layout List
11122 \labelwidthstring 00.00.0000
11123
11124 \series bold
11125 -
11126 \begin_inset ERT
11127 status collapsed
11128
11129 \begin_layout Standard
11130
11131
11132 \backslash
11133 /
11134 \end_layout
11135
11136 \end_inset
11137
11138 -dumpraw
11139 \begin_inset LatexCommand \index{-\/-dumpraw}
11140
11141 \end_inset
11142
11143
11144 \series default
11145  This option will cause the compiler to dump the intermediate code into
11146  a file of named 
11147 \emph on
11148 <source filename>.dumpraw
11149 \emph default
11150  just after the intermediate code has been generated for a function, i.e.
11151  before any optimizations are done.
11152  The basic blocks
11153 \begin_inset LatexCommand \index{Basic blocks}
11154
11155 \end_inset
11156
11157  at this stage ordered in the depth first number, so they may not be in
11158  sequence of execution.
11159 \end_layout
11160
11161 \begin_layout List
11162 \labelwidthstring 00.00.0000
11163
11164 \series bold
11165 -
11166 \begin_inset ERT
11167 status collapsed
11168
11169 \begin_layout Standard
11170
11171
11172 \backslash
11173 /
11174 \end_layout
11175
11176 \end_inset
11177
11178 -dumpgcse
11179 \begin_inset LatexCommand \index{-\/-dumpgcse}
11180
11181 \end_inset
11182
11183
11184 \series default
11185  Will create a dump of iCodes, after global subexpression elimination
11186 \begin_inset LatexCommand \index{Global subexpression elimination}
11187
11188 \end_inset
11189
11190 , into a file named 
11191 \emph on
11192 <source filename>.dumpgcse.
11193 \end_layout
11194
11195 \begin_layout List
11196 \labelwidthstring 00.00.0000
11197
11198 \series bold
11199 -
11200 \begin_inset ERT
11201 status collapsed
11202
11203 \begin_layout Standard
11204
11205
11206 \backslash
11207 /
11208 \end_layout
11209
11210 \end_inset
11211
11212 -dumpdeadcode
11213 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11214
11215 \end_inset
11216
11217
11218 \series default
11219  Will create a dump of iCodes, after deadcode elimination
11220 \begin_inset LatexCommand \index{Dead-code elimination}
11221
11222 \end_inset
11223
11224 , into a file named 
11225 \emph on
11226 <source filename>.dumpdeadcode.
11227 \end_layout
11228
11229 \begin_layout List
11230 \labelwidthstring 00.00.0000
11231
11232 \series bold
11233 -
11234 \begin_inset ERT
11235 status collapsed
11236
11237 \begin_layout Standard
11238
11239
11240 \backslash
11241 /
11242 \end_layout
11243
11244 \end_inset
11245
11246 -dumploop
11247 \begin_inset LatexCommand \index{-\/-dumploop}
11248
11249 \end_inset
11250
11251
11252 \series default
11253 \size large
11254  
11255 \size default
11256 Will create a dump of iCodes, after loop optimizations
11257 \begin_inset LatexCommand \index{Loop optimization}
11258
11259 \end_inset
11260
11261 , into a file named 
11262 \emph on
11263 <source filename>.dumploop.
11264 \end_layout
11265
11266 \begin_layout List
11267 \labelwidthstring 00.00.0000
11268
11269 \series bold
11270 -
11271 \begin_inset ERT
11272 status collapsed
11273
11274 \begin_layout Standard
11275
11276
11277 \backslash
11278 /
11279 \end_layout
11280
11281 \end_inset
11282
11283 -dumprange
11284 \begin_inset LatexCommand \index{-\/-dumprange}
11285
11286 \end_inset
11287
11288
11289 \series default
11290 \size large
11291  
11292 \size default
11293 Will create a dump of iCodes, after live range analysis
11294 \begin_inset LatexCommand \index{Live range analysis}
11295
11296 \end_inset
11297
11298 , into a file named 
11299 \emph on
11300 <source filename>.dumprange.
11301 \end_layout
11302
11303 \begin_layout List
11304 \labelwidthstring 00.00.0000
11305
11306 \series bold
11307 -
11308 \begin_inset ERT
11309 status collapsed
11310
11311 \begin_layout Standard
11312
11313
11314 \backslash
11315 /
11316 \end_layout
11317
11318 \end_inset
11319
11320 -dumlrange
11321 \begin_inset LatexCommand \index{-\/-dumlrange}
11322
11323 \end_inset
11324
11325
11326 \series default
11327  Will dump the life ranges
11328 \begin_inset LatexCommand \index{Live range analysis}
11329
11330 \end_inset
11331
11332  for all symbols.
11333 \end_layout
11334
11335 \begin_layout List
11336 \labelwidthstring 00.00.0000
11337
11338 \series bold
11339 -
11340 \begin_inset ERT
11341 status collapsed
11342
11343 \begin_layout Standard
11344
11345
11346 \backslash
11347 /
11348 \end_layout
11349
11350 \end_inset
11351
11352 -dumpregassign
11353 \begin_inset LatexCommand \index{-\/-dumpregassign}
11354
11355 \end_inset
11356
11357
11358 \bar under
11359  
11360 \series default
11361 \bar default
11362 Will create a dump of iCodes, after register assignment
11363 \begin_inset LatexCommand \index{Register assignment}
11364
11365 \end_inset
11366
11367 , into a file named 
11368 \emph on
11369 <source filename>.dumprassgn.
11370 \end_layout
11371
11372 \begin_layout List
11373 \labelwidthstring 00.00.0000
11374
11375 \series bold
11376 -
11377 \begin_inset ERT
11378 status collapsed
11379
11380 \begin_layout Standard
11381
11382
11383 \backslash
11384 /
11385 \end_layout
11386
11387 \end_inset
11388
11389 -dumplrange
11390 \begin_inset LatexCommand \index{-\/-dumplrange}
11391
11392 \end_inset
11393
11394
11395 \series default
11396  Will create a dump of the live ranges of iTemp's
11397 \end_layout
11398
11399 \begin_layout List
11400 \labelwidthstring 00.00.0000
11401
11402 \series bold
11403 -
11404 \begin_inset ERT
11405 status collapsed
11406
11407 \begin_layout Standard
11408
11409
11410 \backslash
11411 /
11412 \end_layout
11413
11414 \end_inset
11415
11416 -dumpall
11417 \begin_inset LatexCommand \index{-\/-dumpall}
11418
11419 \end_inset
11420
11421
11422 \size large
11423 \bar under
11424  
11425 \series default
11426 \size default
11427 \bar default
11428 Will cause all the above mentioned dumps to be created.
11429 \end_layout
11430
11431 \begin_layout Standard
11432 \begin_inset VSpace bigskip
11433 \end_inset
11434
11435
11436 \end_layout
11437
11438 \begin_layout Subsection
11439 Redirecting output on Windows Shells
11440 \end_layout
11441
11442 \begin_layout Standard
11443 By default SDCC writes its error messages to 
11444 \begin_inset Quotes sld
11445 \end_inset
11446
11447 standard error
11448 \begin_inset Quotes srd
11449 \end_inset
11450
11451 .
11452  To force all messages to 
11453 \begin_inset Quotes sld
11454 \end_inset
11455
11456 standard output
11457 \begin_inset Quotes srd
11458 \end_inset
11459
11460  use 
11461 \series bold
11462 -
11463 \series default
11464 \emph on
11465
11466 \begin_inset ERT
11467 status collapsed
11468
11469 \begin_layout Standard
11470
11471
11472 \backslash
11473 /
11474 \end_layout
11475
11476 \end_inset
11477
11478
11479 \series bold
11480 \emph default
11481 -
11482 \series default
11483 use-stdout
11484 \begin_inset LatexCommand \index{-\/-use-stdout}
11485
11486 \end_inset
11487
11488 .
11489  Additionally, if you happen to have visual studio installed in your windows
11490  machine, you can use it to compile your sources using a custom build and
11491  the SDCC -
11492 \emph on
11493
11494 \begin_inset ERT
11495 status collapsed
11496
11497 \begin_layout Standard
11498
11499
11500 \backslash
11501 /
11502 \end_layout
11503
11504 \end_inset
11505
11506
11507 \emph default
11508 -vc
11509 \begin_inset LatexCommand \index{-\/-vc}
11510
11511 \end_inset
11512
11513  option.
11514  Something like this should work:
11515 \newline
11516
11517 \newline
11518
11519 \series bold
11520 c:
11521 \backslash
11522 sdcc
11523 \backslash
11524 bin
11525 \backslash
11526 sdcc.exe -
11527 \series default
11528 \emph on
11529
11530 \begin_inset ERT
11531 status collapsed
11532
11533 \begin_layout Standard
11534
11535
11536 \backslash
11537 /
11538 \end_layout
11539
11540 \end_inset
11541
11542
11543 \series bold
11544 \emph default
11545 -vc -
11546 \series default
11547 \emph on
11548
11549 \begin_inset ERT
11550 status collapsed
11551
11552 \begin_layout Standard
11553
11554
11555 \backslash
11556 /
11557 \end_layout
11558
11559 \end_inset
11560
11561
11562 \series bold
11563 \emph default
11564 -model-large -c $(InputPath)
11565 \series default
11566
11567 \begin_inset VSpace bigskip
11568 \end_inset
11569
11570
11571 \end_layout
11572
11573 \begin_layout Section
11574 Environment variables
11575 \begin_inset LatexCommand \index{Environment variables}
11576
11577 \end_inset
11578
11579
11580 \end_layout
11581
11582 \begin_layout Standard
11583 SDCC recognizes the following environment variables:
11584 \end_layout
11585
11586 \begin_layout List
11587 \labelwidthstring 00.00.0000
11588
11589 \series bold
11590 SDCC_LEAVE_SIGNALS
11591 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11592
11593 \end_inset
11594
11595
11596 \series default
11597  SDCC installs a signal handler
11598 \begin_inset LatexCommand \index{signal handler}
11599
11600 \end_inset
11601
11602  to be able to delete temporary files after an user break (^C) or an exception.
11603  If this environment variable is set, SDCC won't install the signal handler
11604  in order to be able to debug SDCC.
11605 \end_layout
11606
11607 \begin_layout List
11608 \labelwidthstring 00.00.0000
11609
11610 \series bold
11611 TMP,\InsetSpace ~
11612 TEMP,\InsetSpace ~
11613 TMPDIR
11614 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11615
11616 \end_inset
11617
11618
11619 \series default
11620  Path, where temporary files will be created.
11621  The order of the variables is the search order.
11622  In a standard *nix environment these variables are not set, and there's
11623  no need to set them.
11624  On Windows it's recommended to set one of them.
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 SDCC_HOME
11632 \begin_inset LatexCommand \index{SDCC\_HOME}
11633
11634 \end_inset
11635
11636
11637 \series default
11638  Path, see section 
11639 \begin_inset LatexCommand \ref{sub:Install-paths}
11640
11641 \end_inset
11642
11643 \InsetSpace ~
11644
11645 \begin_inset Quotes sld
11646 \end_inset
11647
11648  Install Paths
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 .
11653 \end_layout
11654
11655 \begin_layout List
11656 \labelwidthstring 00.00.0000
11657
11658 \series bold
11659 SDCC_INCLUDE
11660 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11661
11662 \end_inset
11663
11664
11665 \series default
11666  Path, see section 
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11668
11669 \end_inset
11670
11671 \InsetSpace ~
11672
11673 \begin_inset Quotes sld
11674 \end_inset
11675
11676 Search Paths
11677 \begin_inset Quotes srd
11678 \end_inset
11679
11680 .
11681 \end_layout
11682
11683 \begin_layout List
11684 \labelwidthstring 00.00.0000
11685
11686 \series bold
11687 SDCC_LIB
11688 \begin_inset LatexCommand \index{SDCC\_LIB}
11689
11690 \end_inset
11691
11692
11693 \series default
11694  Path, see section 
11695 \begin_inset LatexCommand \ref{sub:Search-Paths}
11696
11697 \end_inset
11698
11699 \InsetSpace ~
11700
11701 \begin_inset Quotes sld
11702 \end_inset
11703
11704 Search Paths
11705 \begin_inset Quotes srd
11706 \end_inset
11707
11708 ..
11709 \end_layout
11710
11711 \begin_layout Standard
11712 There are some more environment variables recognized by SDCC, but these
11713  are solely used for debugging purposes.
11714  They can change or disappear very quickly, and will never be documented.
11715 \begin_inset VSpace bigskip
11716 \end_inset
11717
11718
11719 \end_layout
11720
11721 \begin_layout Section
11722 Storage Class Language Extensions
11723 \end_layout
11724
11725 \begin_layout Subsection
11726 MCS51/DS390 Storage Class
11727 \begin_inset LatexCommand \index{Storage class}
11728
11729 \end_inset
11730
11731  Language Extensions
11732 \end_layout
11733
11734 \begin_layout Standard
11735 In addition to the ANSI storage classes SDCC allows the following MCS51
11736  specific storage classes:
11737 \end_layout
11738
11739 \begin_layout Subsubsection
11740 data
11741 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11742
11743 \end_inset
11744
11745
11746 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11747
11748 \end_inset
11749
11750  / near
11751 \begin_inset LatexCommand \index{near (storage class)}
11752
11753 \end_inset
11754
11755
11756 \begin_inset LatexCommand \index{\_\_near (storage class)}
11757
11758 \end_inset
11759
11760
11761 \end_layout
11762
11763 \begin_layout Standard
11764 This is the 
11765 \series bold
11766 default
11767 \series default
11768  storage class for the Small Memory model (
11769 \emph on
11770 data
11771 \emph default
11772  and 
11773 \emph on
11774 near
11775 \emph default
11776  or the more ANSI-C compliant forms 
11777 \emph on
11778 __data
11779 \emph default
11780  and 
11781 \emph on
11782 __near
11783 \emph default
11784  can be used synonymously).
11785  Variables declared with this storage class will be allocated in the directly
11786  addressable portion of the internal RAM of a 8051, e.g.:
11787 \end_layout
11788
11789 \begin_layout Verse
11790
11791 \family typewriter
11792 __data unsigned char test_data;
11793 \end_layout
11794
11795 \begin_layout Standard
11796 Writing 0x01 to this variable generates the assembly code:
11797 \end_layout
11798
11799 \begin_layout Verse
11800
11801 \family typewriter
11802 75*00 01\InsetSpace ~
11803 \InsetSpace ~
11804 \InsetSpace ~
11805 mov\InsetSpace ~
11806 \InsetSpace ~
11807 _test_data,#0x01
11808 \end_layout
11809
11810 \begin_layout Subsubsection
11811 xdata
11812 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11813
11814 \end_inset
11815
11816
11817 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11818
11819 \end_inset
11820
11821  / far
11822 \begin_inset LatexCommand \index{far (storage class)}
11823
11824 \end_inset
11825
11826
11827 \begin_inset LatexCommand \index{\_\_far (storage class)}
11828
11829 \end_inset
11830
11831
11832 \end_layout
11833
11834 \begin_layout Standard
11835 Variables declared with this storage class will be placed in the external
11836  RAM.
11837  This is the 
11838 \series bold
11839 default
11840 \series default
11841  storage class for the Large Memory model, e.g.:
11842 \end_layout
11843
11844 \begin_layout Verse
11845
11846 \family typewriter
11847 __xdata unsigned char test_xdata;
11848 \end_layout
11849
11850 \begin_layout Standard
11851 Writing 0x01 to this variable generates the assembly code:
11852 \end_layout
11853
11854 \begin_layout Verse
11855
11856 \family typewriter
11857 90s00r00\InsetSpace ~
11858 \InsetSpace ~
11859 \InsetSpace ~
11860 mov\InsetSpace ~
11861 \InsetSpace ~
11862 dptr,#_test_xdata 
11863 \newline
11864 74\InsetSpace ~
11865 01\InsetSpace ~
11866 \InsetSpace ~
11867 \InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 \InsetSpace ~
11871 mov\InsetSpace ~
11872 \InsetSpace ~
11873 a,#0x01 
11874 \newline
11875 F0\InsetSpace ~
11876 \InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 \InsetSpace ~
11882 \InsetSpace ~
11883 \InsetSpace ~
11884 movx\InsetSpace ~
11885 @dptr,a 
11886 \end_layout
11887
11888 \begin_layout Subsubsection
11889 idata
11890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11891
11892 \end_inset
11893
11894
11895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11896
11897 \end_inset
11898
11899
11900 \end_layout
11901
11902 \begin_layout Standard
11903 Variables declared with this storage class will be allocated into the indirectly
11904  addressable portion of the internal ram of a 8051, e.g.:
11905 \end_layout
11906
11907 \begin_layout Verse
11908
11909 \family typewriter
11910 __idata unsigned char test_idata;
11911 \end_layout
11912
11913 \begin_layout Standard
11914 Writing 0x01 to this variable generates the assembly code:
11915 \end_layout
11916
11917 \begin_layout Verse
11918
11919 \family typewriter
11920 78r00\InsetSpace ~
11921 \InsetSpace ~
11922 \InsetSpace ~
11923 \InsetSpace ~
11924 \InsetSpace ~
11925 \InsetSpace ~
11926 \InsetSpace ~
11927 mov\InsetSpace ~
11928 \InsetSpace ~
11929 r0,#_test_idata
11930 \newline
11931 76\InsetSpace ~
11932 01\InsetSpace ~
11933 \InsetSpace ~
11934 \InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 mov\InsetSpace ~
11940 \InsetSpace ~
11941 @r0,#0x01
11942 \end_layout
11943
11944 \begin_layout Standard
11945 Please note, the first 128 byte of idata physically access the same RAM
11946  as the data memory.
11947  The original 8051 had 128 byte idata memory, nowadays most devices have
11948  256 byte idata memory.
11949  The stack
11950 \begin_inset LatexCommand \index{stack}
11951
11952 \end_inset
11953
11954  is located in idata memory.
11955 \end_layout
11956
11957 \begin_layout Subsubsection
11958 pdata
11959 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11960
11961 \end_inset
11962
11963
11964 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11965
11966 \end_inset
11967
11968
11969 \end_layout
11970
11971 \begin_layout Standard
11972 Paged xdata access is just as straightforward as using the other addressing
11973  modes of a 8051.
11974  It is typically located at the start of xdata and has a maximum size of
11975  256 bytes.
11976  The following example writes 0x01 to the pdata variable.
11977  Please note, pdata access physically accesses xdata memory.
11978  The high byte of the address is determined by port P2 
11979 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11980
11981 \end_inset
11982
11983 (or in case of some 8051 variants by a separate Special Function Register,
11984  see section 
11985 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11986
11987 \end_inset
11988
11989 ).
11990  This is the 
11991 \series bold
11992 default
11993 \series default
11994  storage class for the Medium Memory model, e.g.:
11995 \end_layout
11996
11997 \begin_layout Verse
11998
11999 \family typewriter
12000 __pdata unsigned char test_pdata;
12001 \end_layout
12002
12003 \begin_layout Standard
12004 Writing 0x01 to this variable generates the assembly code:
12005 \end_layout
12006
12007 \begin_layout Verse
12008
12009 \family typewriter
12010 78r00\InsetSpace ~
12011 \InsetSpace ~
12012 \InsetSpace ~
12013 \InsetSpace ~
12014 \InsetSpace ~
12015 \InsetSpace ~
12016 mov r0,#_test_pdata
12017 \newline
12018 74 01\InsetSpace ~
12019 \InsetSpace ~
12020 \InsetSpace ~
12021 \InsetSpace ~
12022 \InsetSpace ~
12023 \InsetSpace ~
12024 mov a,#0x01 
12025 \newline
12026 F2\InsetSpace ~
12027 \InsetSpace ~
12028 \InsetSpace ~
12029 \InsetSpace ~
12030 \InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 \InsetSpace ~
12035 movx @r0,a
12036 \end_layout
12037
12038 \begin_layout Standard
12039 If the -
12040 \begin_inset ERT
12041 status collapsed
12042
12043 \begin_layout Standard
12044
12045
12046 \backslash
12047 /
12048 \end_layout
12049
12050 \end_inset
12051
12052 -xstack
12053 \begin_inset LatexCommand \index{-\/-xstack}
12054
12055 \end_inset
12056
12057  option is used the pdata memory area is followed by the xstack memory area
12058  and the sum of their sizes is limited to 256 bytes.
12059 \end_layout
12060
12061 \begin_layout Subsubsection
12062 code
12063 \begin_inset LatexCommand \index{code}
12064
12065 \end_inset
12066
12067
12068 \begin_inset LatexCommand \index{\_\_code}
12069
12070 \end_inset
12071
12072
12073 \end_layout
12074
12075 \begin_layout Standard
12076 'Variables' declared with this storage class will be placed in the code
12077  memory:
12078 \end_layout
12079
12080 \begin_layout Verse
12081
12082 \family typewriter
12083 __code unsigned char test_code;
12084 \end_layout
12085
12086 \begin_layout Standard
12087 Read access to this variable generates the assembly code:
12088 \end_layout
12089
12090 \begin_layout Verse
12091
12092 \family typewriter
12093 90s00r6F\InsetSpace ~
12094 \InsetSpace ~
12095 \InsetSpace ~
12096 mov dptr,#_test_code
12097 \newline
12098 E4\InsetSpace ~
12099 \InsetSpace ~
12100 \InsetSpace ~
12101 \InsetSpace ~
12102 \InsetSpace ~
12103 \InsetSpace ~
12104 \InsetSpace ~
12105 \InsetSpace ~
12106 \InsetSpace ~
12107 clr a
12108 \newline
12109 93\InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 \InsetSpace ~
12118 movc a,@a+dptr 
12119 \end_layout
12120
12121 \begin_layout Standard
12122
12123 \family typewriter
12124 char
12125 \family default
12126  indexed arrays of characters in code memory can be accessed efficiently:
12127 \end_layout
12128
12129 \begin_layout Verse
12130
12131 \family typewriter
12132 __code char test_array[] = {'c','h','e','a','p'}; 
12133 \end_layout
12134
12135 \begin_layout Standard
12136 Read access to this array using an 8-bit unsigned index generates the assembly
12137  code:
12138 \end_layout
12139
12140 \begin_layout Verse
12141
12142 \family typewriter
12143 E5*00\InsetSpace ~
12144 \InsetSpace ~
12145 \InsetSpace ~
12146 \InsetSpace ~
12147 \InsetSpace ~
12148 \InsetSpace ~
12149 mov a,_index 
12150 \end_layout
12151
12152 \begin_layout Verse
12153
12154 \family typewriter
12155 90s00r41\InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 mov dptr,#_test_array
12159 \end_layout
12160
12161 \begin_layout Verse
12162
12163 \family typewriter
12164 93\InsetSpace ~
12165 \InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 \InsetSpace ~
12169 \InsetSpace ~
12170 \InsetSpace ~
12171 \InsetSpace ~
12172 \InsetSpace ~
12173 movc a,@a+dptr 
12174 \end_layout
12175
12176 \begin_layout Subsubsection
12177 bit
12178 \begin_inset LatexCommand \index{bit}
12179
12180 \end_inset
12181
12182
12183 \begin_inset LatexCommand \index{\_\_bit}
12184
12185 \end_inset
12186
12187
12188 \end_layout
12189
12190 \begin_layout Standard
12191 This is a data-type and a storage class specifier.
12192  When a variable is declared as a bit, it is allocated into the bit addressable
12193  memory of 8051, e.g.:
12194 \end_layout
12195
12196 \begin_layout Verse
12197
12198 \family typewriter
12199 __bit test_bit;
12200 \end_layout
12201
12202 \begin_layout Standard
12203 Writing 1 to this variable generates the assembly code:
12204 \end_layout
12205
12206 \begin_layout Verse
12207
12208 \family typewriter
12209 D2*00\InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 \InsetSpace ~
12215 \InsetSpace ~
12216 setb\InsetSpace ~
12217 _test_bit
12218 \end_layout
12219
12220 \begin_layout Standard
12221 The bit addressable memory consists of 128 bits which are located from 0x20
12222  to 0x2f in data memory.
12223  
12224 \newline
12225 Apart from this 8051 specific storage class most architectures support
12226  ANSI-C bitfields
12227 \begin_inset LatexCommand \index{bitfields}
12228
12229 \end_inset
12230
12231
12232 \begin_inset Foot
12233 status open
12234
12235 \begin_layout Standard
12236 Not really meant as examples, but nevertheless showing what bitfields are
12237  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12238 \end_layout
12239
12240 \end_inset
12241
12242 .
12243  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12244  signed modifier are implemented as unsigned.
12245 \end_layout
12246
12247 \begin_layout Subsubsection
12248 sfr
12249 \begin_inset LatexCommand \index{sfr}
12250
12251 \end_inset
12252
12253
12254 \begin_inset LatexCommand \index{\_\_sfr}
12255
12256 \end_inset
12257
12258  / sfr16
12259 \begin_inset LatexCommand \index{sfr16}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_sfr16}
12265
12266 \end_inset
12267
12268  / sfr32
12269 \begin_inset LatexCommand \index{sfr32}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr32}
12275
12276 \end_inset
12277
12278  / sbit
12279 \begin_inset LatexCommand \index{\_\_sbit}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{sbit}
12285
12286 \end_inset
12287
12288
12289 \end_layout
12290
12291 \begin_layout Standard
12292 Like the bit keyword, 
12293 \emph on
12294 sfr / sfr16 / sfr32 / sbit 
12295 \emph default
12296 signify both a data-type and storage class, they are used to describe the
12297  
12298 \emph on
12299 s
12300 \emph default
12301 pecial 
12302 \emph on
12303 f
12304 \emph default
12305 unction 
12306 \emph on
12307 r
12308 \emph default
12309 egisters and 
12310 \emph on
12311 s
12312 \emph default
12313 pecial 
12314 \emph on
12315 bit
12316 \emph default
12317  variables of a 8051, eg:
12318 \end_layout
12319
12320 \begin_layout Verse
12321
12322 \family typewriter
12323 __sfr __at
12324 \begin_inset LatexCommand \index{at}
12325
12326 \end_inset
12327
12328
12329 \begin_inset LatexCommand \index{\_\_at}
12330
12331 \end_inset
12332
12333  (0x80) P0;\InsetSpace ~
12334  /* special function register P0 at location 0x80 */
12335 \newline
12336
12337 \newline
12338 /* 16 bit
12339  special function register combination for timer 0
12340 \newline
12341 \InsetSpace ~
12342 \InsetSpace ~
12343  with the high byte at
12344  location 0x8C and the low byte at location 0x8A */
12345 \newline
12346 __sfr16 __at (0x8C8A)
12347  TMR0;
12348 \newline
12349
12350 \newline
12351 __sbit __at
12352 \begin_inset LatexCommand \index{at}
12353
12354 \end_inset
12355
12356
12357 \begin_inset LatexCommand \index{\_\_at}
12358
12359 \end_inset
12360
12361  (0xd7) CY;\InsetSpace ~
12362  /* CY (Carry Flag
12363 \begin_inset LatexCommand \index{Flags}
12364
12365 \end_inset
12366
12367
12368 \begin_inset LatexCommand \index{Carry flag}
12369
12370 \end_inset
12371
12372 ) */
12373 \end_layout
12374
12375 \begin_layout Standard
12376 Special function registers which are located on an address dividable by
12377  8 are bit-addressable, an
12378 \emph on
12379  sbit
12380 \emph default
12381  addresses a specific bit within these sfr.
12382 \newline
12383 16 Bit and 32 bit special function
12384  register combinations which require a certain access order are better not
12385  declared using 
12386 \emph on
12387 sfr16
12388 \emph default
12389  or 
12390 \emph on
12391 sfr32.
12392
12393 \emph default
12394  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12395  this is not guaranteed.
12396 \newline
12397
12398 \end_layout
12399
12400 \begin_layout Standard
12401 Please note, if you use a header file which was written for another compiler
12402  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12403  likely be 
12404 \emph on
12405 not 
12406 \emph default
12407 compatible.
12408  Specifically the syntax 
12409 \family typewriter
12410 \InsetSpace ~
12411 sfr P0 = 0x80;\InsetSpace ~
12412
12413 \family default
12414  is compiled 
12415 \emph on
12416 without warning
12417 \emph default
12418  by SDCC to an assignment of 0x80 to a variable called P0 
12419 \family typewriter
12420
12421 \begin_inset Marginal
12422 status collapsed
12423
12424 \begin_layout Standard
12425
12426 \series bold
12427 \InsetSpace ~
12428 !
12429 \end_layout
12430
12431 \end_inset
12432
12433 .
12434  
12435 \family default
12436 Nevertheless it is possible to write header files
12437 \begin_inset LatexCommand \index{Header files}
12438
12439 \end_inset
12440
12441
12442 \begin_inset LatexCommand \index{Include files}
12443
12444 \end_inset
12445
12446  which can be shared among different compilers (see section 
12447 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12448
12449 \end_inset
12450
12451 ).
12452  
12453 \end_layout
12454
12455 \begin_layout Subsubsection
12456 Pointers
12457 \begin_inset LatexCommand \index{Pointer}
12458
12459 \end_inset
12460
12461  to MCS51/DS390 specific memory spaces
12462 \end_layout
12463
12464 \begin_layout Standard
12465 SDCC allows (via language extensions) pointers to explicitly point to any
12466  of the memory spaces
12467 \begin_inset LatexCommand \index{Memory model}
12468
12469 \end_inset
12470
12471  of the 8051.
12472  In addition to the explicit pointers, the compiler uses (by default) generic
12473  pointers which can be used to point to any of the memory spaces.
12474 \newline
12475
12476 \newline
12477 Pointer
12478  declaration examples:
12479 \end_layout
12480
12481 \begin_layout Verse
12482
12483 \family typewriter
12484 /* pointer physically in internal ram pointing to object in external ram
12485  */ 
12486 \newline
12487 __xdata unsigned char * __data p;
12488 \newline
12489
12490 \newline
12491 /* pointer physically in external ram
12492  pointing to object in internal ram */ 
12493 \newline
12494 __data unsigned char * __xdata p;
12495 \newline
12496
12497 \newline
12498 /*
12499  pointer physically in code rom pointing to data in xdata space */ 
12500 \newline
12501 __xdata
12502  unsigned char * __code p;
12503 \newline
12504
12505 \newline
12506 /* pointer physically in code space pointing to
12507  data in code space */ 
12508 \newline
12509 __code unsigned char * __code p;
12510 \newline
12511
12512 \newline
12513 /* generic pointer
12514  physically located in xdata space */
12515 \newline
12516 unsigned char * __xdata p;
12517 \newline
12518
12519 \newline
12520 /* generic
12521  pointer physically located in default memory space */
12522 \newline
12523 unsigned char * p;
12524 \newline
12525
12526 \newline
12527 /*
12528  the following is a function pointer
12529 \begin_inset LatexCommand \index{function pointer}
12530
12531 \end_inset
12532
12533  physically located in data space */
12534 \newline
12535 char (* __data fp)(void);
12536 \end_layout
12537
12538 \begin_layout Standard
12539 Well you get the idea.
12540  
12541 \newline
12542
12543 \newline
12544 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12545 \emph on
12546 generic
12547 \emph default
12548  pointers.
12549  
12550 \size small
12551
12552 \newline
12553
12554 \newline
12555
12556 \size default
12557 The highest order byte of the 
12558 \emph on
12559 generic
12560 \emph default
12561  pointers contains the data space information.
12562  Assembler support routines are called whenever data is stored or retrieved
12563  using 
12564 \emph on
12565 generic
12566 \emph default
12567  pointers.
12568  These are useful for developing reusable library
12569 \begin_inset LatexCommand \index{Libraries}
12570
12571 \end_inset
12572
12573  routines.
12574  Explicitly specifying the pointer
12575 \begin_inset LatexCommand \index{pointer}
12576
12577 \end_inset
12578
12579  type will generate the most efficient code.
12580 \end_layout
12581
12582 \begin_layout Subsubsection
12583 Notes on MCS51 memory
12584 \begin_inset LatexCommand \index{MCS51 memory}
12585
12586 \end_inset
12587
12588  layout
12589 \end_layout
12590
12591 \begin_layout Standard
12592 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12593  RAM memory which is structured as follows:
12594 \newline
12595
12596 \newline
12597 - Bytes 00-1F - 32 bytes to hold
12598  up to 4 banks of the registers R0 to R7, 
12599 \newline
12600 - Bytes 20-2F - 16 bytes to hold
12601  128 bit
12602 \begin_inset LatexCommand \index{bit}
12603
12604 \end_inset
12605
12606  variables and, 
12607 \newline
12608 - Bytes 30-7F - 80 bytes for general purpose use.
12609 \newline
12610
12611 \end_layout
12612
12613 \begin_layout Standard
12614 Additionally some members of the MCS51 family may have up to 128 bytes of
12615  additional, indirectly addressable, internal RAM memory (
12616 \emph on
12617 idata
12618 \emph default
12619
12620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12621
12622 \end_inset
12623
12624
12625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12626
12627 \end_inset
12628
12629 ).
12630  Furthermore, some chips may have some built in external memory (
12631 \emph on
12632 xdata
12633 \emph default
12634
12635 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12636
12637 \end_inset
12638
12639
12640 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12641
12642 \end_inset
12643
12644 ) which should not be confused with the internal, directly addressable RAM
12645  memory (
12646 \emph on
12647 data
12648 \emph default
12649
12650 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12651
12652 \end_inset
12653
12654
12655 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12656
12657 \end_inset
12658
12659 ).
12660  Sometimes this built in 
12661 \emph on
12662 xdata
12663 \emph default
12664  memory has to be activated before using it (you can probably find this
12665  information on the datasheet of the microcontroller your are using, see
12666  also section 
12667 \begin_inset LatexCommand \ref{sub:Startup-Code}
12668
12669 \end_inset
12670
12671 \InsetSpace ~
12672 Startup-Code).
12673 \end_layout
12674
12675 \begin_layout Standard
12676 Normally SDCC will only use the first bank
12677 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12678
12679 \end_inset
12680
12681  of registers (register bank 0), but it is possible to specify that other
12682  banks of registers (keyword 
12683 \emph on
12684 using
12685 \emph default
12686  
12687 \emph on
12688
12689 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12690
12691 \end_inset
12692
12693
12694 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12695
12696 \end_inset
12697
12698
12699 \emph default
12700 ) should be used for example in interrupt
12701 \begin_inset LatexCommand \index{interrupt}
12702
12703 \end_inset
12704
12705
12706 \begin_inset LatexCommand \index{\_\_interrupt}
12707
12708 \end_inset
12709
12710  routines.
12711  By default, the compiler will place the stack after the last byte of allocated
12712  memory for variables.
12713  For example, if the first 2 banks of registers are used, and only four
12714  bytes are used for 
12715 \emph on
12716 data
12717 \emph default
12718  variables, it will position the base of the internal stack at address 20
12719  (0x14).
12720  This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12722
12723 \end_inset
12724
12725  grows, it will use up the remaining register banks, and the 16 bytes used
12726  by the 128 bit variables, and 80 bytes for general purpose use.
12727  If any bit variables are used, the data variables will be placed in unused
12728  register banks and after the byte holding the last bit variable.
12729  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12730  (two bytes used), 
12731 \emph on
12732 data
12733 \emph default
12734  variables will be placed starting from address 0x10 to 0x20 and continue
12735  at address 0x22.
12736  You can also use -
12737 \begin_inset ERT
12738 status collapsed
12739
12740 \begin_layout Standard
12741
12742
12743 \backslash
12744 /
12745 \end_layout
12746
12747 \end_inset
12748
12749 -data-loc
12750 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12751
12752 \end_inset
12753
12754  to specify the start address of the 
12755 \emph on
12756 data
12757 \emph default
12758  and -
12759 \begin_inset ERT
12760 status collapsed
12761
12762 \begin_layout Standard
12763
12764
12765 \backslash
12766 /
12767 \end_layout
12768
12769 \end_inset
12770
12771 -iram-size
12772 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12773
12774 \end_inset
12775
12776  to specify the size of the total internal RAM (
12777 \emph on
12778 data
12779 \emph default
12780 +
12781 \emph on
12782 idata
12783 \emph default
12784 ).
12785  
12786 \newline
12787
12788 \end_layout
12789
12790 \begin_layout Standard
12791 By default the 8051 linker will place the stack after the last byte of (i)data
12792  variables.
12793  Option -
12794 \begin_inset ERT
12795 status collapsed
12796
12797 \begin_layout Standard
12798
12799
12800 \backslash
12801 /
12802 \end_layout
12803
12804 \end_inset
12805
12806 -stack-loc
12807 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12808
12809 \end_inset
12810
12811  allows you to specify the start of the stack, i.e.
12812  you could start it after any data in the general purpose area.
12813  If your microcontroller has additional indirectly addressable internal
12814  RAM (
12815 \emph on
12816 idata
12817 \emph default
12818 ) you can place the stack on it.
12819  You may also need to use -
12820 \begin_inset ERT
12821 status collapsed
12822
12823 \begin_layout Standard
12824
12825
12826 \backslash
12827 /
12828 \end_layout
12829
12830 \end_inset
12831
12832 -xdata-loc
12833 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12834
12835 \end_inset
12836
12837  to set the start address of the external RAM (
12838 \emph on
12839 xdata
12840 \emph default
12841 ) and -
12842 \begin_inset ERT
12843 status collapsed
12844
12845 \begin_layout Standard
12846
12847
12848 \backslash
12849 /
12850 \end_layout
12851
12852 \end_inset
12853
12854 -xram-size
12855 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12856
12857 \end_inset
12858
12859  to specify its size.
12860  Same goes for the code memory, using -
12861 \begin_inset ERT
12862 status collapsed
12863
12864 \begin_layout Standard
12865
12866
12867 \backslash
12868 /
12869 \end_layout
12870
12871 \end_inset
12872
12873 -code-loc
12874 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12875
12876 \end_inset
12877
12878  and -
12879 \begin_inset ERT
12880 status collapsed
12881
12882 \begin_layout Standard
12883
12884
12885 \backslash
12886 /
12887 \end_layout
12888
12889 \end_inset
12890
12891 -code-size
12892 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12893
12894 \end_inset
12895
12896 .
12897  If in doubt, don't specify any options and see if the resulting memory
12898  layout is appropriate, then you can adjust it.
12899 \end_layout
12900
12901 \begin_layout Standard
12902 The linker generates two files with memory allocation information.
12903  The first, with extension .map
12904 \begin_inset LatexCommand \index{<file>.map}
12905
12906 \end_inset
12907
12908  shows all the variables and segments.
12909  The second with extension .mem
12910 \begin_inset LatexCommand \index{<file>.mem}
12911
12912 \end_inset
12913
12914  shows the final memory layout.
12915  The linker will complain either if memory segments overlap, there is not
12916  enough memory, or there is not enough space for stack.
12917  If you get any linking warnings and/or errors related to stack or segments
12918  allocation, take a look at either the .map or .mem files to find out what
12919  the problem is.
12920  The .mem file may even suggest a solution to the problem.
12921 \begin_inset VSpace bigskip
12922 \end_inset
12923
12924
12925 \end_layout
12926
12927 \begin_layout Subsection
12928 Z80/Z180 Storage Class
12929 \begin_inset LatexCommand \index{Z80!Storage class}
12930
12931 \end_inset
12932
12933  Language Extensions
12934 \end_layout
12935
12936 \begin_layout Subsubsection
12937 sfr
12938 \begin_inset LatexCommand \index{sfr}
12939
12940 \end_inset
12941
12942
12943 \begin_inset LatexCommand \index{\_\_sfr}
12944
12945 \end_inset
12946
12947  (in/out to 8-bit addresses)
12948 \end_layout
12949
12950 \begin_layout Standard
12951 The Z80
12952 \begin_inset LatexCommand \index{Z80}
12953
12954 \end_inset
12955
12956  family has separate address spaces for memory and 
12957 \emph on
12958 i
12959 \emph default
12960 nput/
12961 \emph on
12962 o
12963 \emph default
12964 utput memory.
12965  I/O memory
12966 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12967
12968 \end_inset
12969
12970
12971 \begin_inset LatexCommand \index{Z80!I/O memory}
12972
12973 \end_inset
12974
12975
12976 \begin_inset LatexCommand \index{Z180!I/O memory}
12977
12978 \end_inset
12979
12980  is accessed with special instructions, e.g.:
12981 \end_layout
12982
12983 \begin_layout Verse
12984
12985 \family typewriter
12986 sfr at 0x78 IoPort;\InsetSpace ~
12987 \InsetSpace ~
12988 /* define a var in I/O space at 78h called IoPort */
12989  
12990 \end_layout
12991
12992 \begin_layout Standard
12993 Writing 0x01 to this variable generates the assembly code:
12994 \end_layout
12995
12996 \begin_layout Verse
12997
12998 \family typewriter
12999 3E 01\InsetSpace ~
13000 \InsetSpace ~
13001 \InsetSpace ~
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 ld a,#0x01
13006 \newline
13007 D3 78\InsetSpace ~
13008 \InsetSpace ~
13009 \InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 out (_IoPort),a 
13014 \end_layout
13015
13016 \begin_layout Subsubsection
13017 banked sfr
13018 \begin_inset LatexCommand \index{sfr}
13019
13020 \end_inset
13021
13022
13023 \begin_inset LatexCommand \index{\_\_sfr}
13024
13025 \end_inset
13026
13027  (in/out to 16-bit addresses)
13028 \end_layout
13029
13030 \begin_layout Standard
13031 The keyword 
13032 \emph on
13033 banked
13034 \emph default
13035  is used to support 16 bit addresses in I/O memory e.g.:
13036 \end_layout
13037
13038 \begin_layout Verse
13039
13040 \family typewriter
13041 sfr banked at
13042 \begin_inset LatexCommand \index{at}
13043
13044 \end_inset
13045
13046
13047 \begin_inset LatexCommand \index{\_\_at}
13048
13049 \end_inset
13050
13051  0x123 IoPort; 
13052 \end_layout
13053
13054 \begin_layout Standard
13055 Writing 0x01 to this variable generates the assembly code:
13056 \end_layout
13057
13058 \begin_layout Verse
13059
13060 \family typewriter
13061 01 23 01\InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 ld bc,#_IoPort
13065 \newline
13066 3E 01\InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 \InsetSpace ~
13071 \InsetSpace ~
13072 ld a,#0x01 
13073 \newline
13074 ED 79\InsetSpace ~
13075 \InsetSpace ~
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 out (c),a 
13081 \end_layout
13082
13083 \begin_layout Subsubsection
13084 sfr
13085 \begin_inset LatexCommand \index{sfr}
13086
13087 \end_inset
13088
13089
13090 \begin_inset LatexCommand \index{\_\_sfr}
13091
13092 \end_inset
13093
13094  (in0/out0 to 8 bit addresses on Z180
13095 \begin_inset LatexCommand \index{Z180}
13096
13097 \end_inset
13098
13099 /HD64180
13100 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13101
13102 \end_inset
13103
13104 )
13105 \end_layout
13106
13107 \begin_layout Standard
13108 The compiler option -
13109 \begin_inset ERT
13110 status collapsed
13111
13112 \begin_layout Standard
13113
13114
13115 \backslash
13116 /
13117 \end_layout
13118
13119 \end_inset
13120
13121 -portmode
13122 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13123
13124 \end_inset
13125
13126 =180 (80) and a compiler #pragma\InsetSpace ~
13127 portmode
13128 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13129
13130 \end_inset
13131
13132  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13133 ns 
13134 \family typewriter
13135 in0/out0
13136 \family default
13137  instead of 
13138 \family typewriter
13139 in/out
13140 \family default
13141 .
13142  If you include the file z180.h this will be set automatically.
13143 \begin_inset VSpace bigskip
13144 \end_inset
13145
13146
13147 \end_layout
13148
13149 \begin_layout Subsection
13150 HC08 Storage Class
13151 \begin_inset LatexCommand \index{HC08!Storage class}
13152
13153 \end_inset
13154
13155  Language Extensions
13156 \end_layout
13157
13158 \begin_layout Subsubsection
13159 data
13160 \begin_inset LatexCommand \index{data (hc08 storage class)}
13161
13162 \end_inset
13163
13164
13165 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13166
13167 \end_inset
13168
13169  
13170 \end_layout
13171
13172 \begin_layout Standard
13173 The data storage class declares a variable that resides in the first 256
13174  bytes of memory (the direct page).
13175  The HC08
13176 \begin_inset LatexCommand \index{HC08}
13177
13178 \end_inset
13179
13180  is most efficient at accessing variables (especially pointers) stored here.
13181 \end_layout
13182
13183 \begin_layout Subsubsection
13184 xdata
13185 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13186
13187 \end_inset
13188
13189
13190 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13191
13192 \end_inset
13193
13194  
13195 \end_layout
13196
13197 \begin_layout Standard
13198 The xdata storage class declares a variable that can reside anywhere in
13199  memory.
13200  This is the default if no storage class is specified.
13201  
13202 \begin_inset VSpace bigskip
13203 \end_inset
13204
13205
13206 \end_layout
13207
13208 \begin_layout Section
13209 Absolute Addressing
13210 \begin_inset LatexCommand \index{Absolute addressing}
13211
13212 \end_inset
13213
13214
13215 \end_layout
13216
13217 \begin_layout Standard
13218 Data items can be assigned an absolute address with the 
13219 \emph on
13220 at
13221 \begin_inset LatexCommand \index{at}
13222
13223 \end_inset
13224
13225
13226 \begin_inset LatexCommand \index{\_\_at}
13227
13228 \end_inset
13229
13230  <address>
13231 \emph default
13232  keyword, in addition to a storage class, e.g.:
13233 \end_layout
13234
13235 \begin_layout Verse
13236
13237 \family typewriter
13238 xdata
13239 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13240
13241 \end_inset
13242
13243
13244 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13245
13246 \end_inset
13247
13248  at
13249 \begin_inset LatexCommand \index{at}
13250
13251 \end_inset
13252
13253
13254 \begin_inset LatexCommand \index{\_\_at}
13255
13256 \end_inset
13257
13258  0x7ffe unsigned int chksum;
13259 \end_layout
13260
13261 \begin_layout Standard
13262 or, better conforming to ISO/IEC 9899 C:
13263 \end_layout
13264
13265 \begin_layout Verse
13266
13267 \family typewriter
13268 __xdata __at (0x7ffe) unsigned int chksum;
13269 \end_layout
13270
13271 \begin_layout Standard
13272 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13273  of the external ram.
13274  The compiler does 
13275 \emph on
13276 not
13277 \emph default
13278  reserve any space for variables declared in this way
13279 \begin_inset Marginal
13280 status collapsed
13281
13282 \begin_layout Standard
13283
13284 \series bold
13285 \InsetSpace ~
13286 !
13287 \end_layout
13288
13289 \end_inset
13290
13291  (they are implemented with an equate in the assembler).
13292  Thus it is left to the programmer to make sure there are no overlaps with
13293  other variables that are declared without the absolute address.
13294  The assembler listing file (.lst
13295 \begin_inset LatexCommand \index{<file>.lst}
13296
13297 \end_inset
13298
13299 ) and the linker output files (.rst
13300 \begin_inset LatexCommand \index{<file>.rst}
13301
13302 \end_inset
13303
13304 ) and (.map
13305 \begin_inset LatexCommand \index{<file>.map}
13306
13307 \end_inset
13308
13309 ) are good places to look for such overlaps.
13310 \end_layout
13311
13312 \begin_layout Standard
13313 If however you provide an initializer
13314 \begin_inset LatexCommand \index{Variable initialization}
13315
13316 \end_inset
13317
13318  actual memory allocation will take place and overlaps will be detected
13319  by the linker.
13320  E.g.:
13321 \end_layout
13322
13323 \begin_layout Verse
13324
13325 \family typewriter
13326 __code __at (0x7ff0) char Id[5] = 
13327 \begin_inset Quotes sld
13328 \end_inset
13329
13330 SDCC
13331 \begin_inset Quotes srd
13332 \end_inset
13333
13334 ;
13335 \end_layout
13336
13337 \begin_layout Standard
13338 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13339  in code memory.
13340 \end_layout
13341
13342 \begin_layout Standard
13343 In case of memory mapped I/O devices the keyword 
13344 \emph on
13345 volatile
13346 \emph default
13347  has to be used to tell the compiler that accesses might not be removed:
13348 \end_layout
13349
13350 \begin_layout Verse
13351
13352 \family typewriter
13353 volatile
13354 \begin_inset LatexCommand \index{volatile}
13355
13356 \end_inset
13357
13358  __xdata
13359 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13360
13361 \end_inset
13362
13363  __at
13364 \begin_inset LatexCommand \index{at}
13365
13366 \end_inset
13367
13368  (0x8000) unsigned char PORTA_8255;
13369 \end_layout
13370
13371 \begin_layout Standard
13372 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13373 r) array
13374 \family typewriter
13375 \size footnotesize
13376
13377 \begin_inset LatexCommand \index{Aligned array}
13378
13379 \end_inset
13380
13381
13382 \family default
13383 \size default
13384  starts at a block (256 byte) boundary
13385 \begin_inset LatexCommand \index{block boundary}
13386
13387 \end_inset
13388
13389  (section 
13390 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13391
13392 \end_inset
13393
13394  has an example).
13395 \newline
13396 Absolute addresses can be specified for variables in all
13397  storage classes, e.g.:
13398 \end_layout
13399
13400 \begin_layout Verse
13401
13402 \family typewriter
13403 __bit
13404 \begin_inset LatexCommand \index{bit}
13405
13406 \end_inset
13407
13408  __at
13409 \begin_inset LatexCommand \index{at}
13410
13411 \end_inset
13412
13413  (0x02) bvar;
13414 \end_layout
13415
13416 \begin_layout Standard
13417 The above example will allocate the variable at offset 0x02 in the bit-addressab
13418 le space.
13419  There is no real advantage to assigning absolute addresses to variables
13420  in this manner, unless you want strict control over all the variables allocated.
13421  One possible use would be to write hardware portable code.
13422  For example, if you have a routine that uses one or more of the microcontroller
13423  I/O pins, and such pins are different for two different hardwares, you
13424  can declare the I/O pins in your routine using:
13425 \end_layout
13426
13427 \begin_layout Verse
13428
13429 \family typewriter
13430 extern volatile
13431 \begin_inset LatexCommand \index{volatile}
13432
13433 \end_inset
13434
13435  __bit MOSI;\InsetSpace ~
13436 \InsetSpace ~
13437 \InsetSpace ~
13438 \InsetSpace ~
13439 /* master out, slave in */
13440 \newline
13441 extern volatile __bit MISO;\InsetSpace ~
13442 \InsetSpace ~
13443 \InsetSpace ~
13444 \InsetSpace ~
13445 /* master
13446  in, slave out */
13447 \newline
13448 extern volatile __bit MCLK;\InsetSpace ~
13449 \InsetSpace ~
13450 \InsetSpace ~
13451 \InsetSpace ~
13452 /* master clock */
13453 \newline
13454
13455 \newline
13456 /* Input and
13457  Output of a byte on a 3-wire serial bus.
13458 \newline
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 If needed adapt polarity of clock,
13463  polarity of data and bit order
13464 \newline
13465 \InsetSpace ~
13466 */
13467 \newline
13468 unsigned char spi_io(unsigned char out_byte)
13469  
13470 \newline
13471
13472 \newline
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 \InsetSpace ~
13476 \InsetSpace ~
13477 unsigned char i=8;
13478 \newline
13479 \InsetSpace ~
13480 \InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 do { 
13484 \newline
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 \InsetSpace ~
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 MOSI = out_byte & 0x80; 
13494 \newline
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 out_byte <<= 1;
13504 \newline
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 MCLK =
13514  1; 
13515 \newline
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 \InsetSpace ~
13524 /* _asm nop _endasm; */\InsetSpace ~
13525 \InsetSpace ~
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 \InsetSpace ~
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 /* for slow peripherals */
13533 \newline
13534 \InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 \InsetSpace ~
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 if(MISO) 
13543 \newline
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 out_byte +=
13557  1; 
13558 \newline
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 \InsetSpace ~
13567 MCLK = 0; 
13568 \newline
13569 \InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 } while(--i);
13574 \newline
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 \InsetSpace ~
13579 return out_byte; 
13580 \newline
13581 }
13582 \end_layout
13583
13584 \begin_layout Standard
13585 Then, someplace in the code for the first hardware you would use
13586 \end_layout
13587
13588 \begin_layout Verse
13589
13590 \family typewriter
13591 __bit __at
13592 \begin_inset LatexCommand \index{at}
13593
13594 \end_inset
13595
13596
13597 \begin_inset LatexCommand \index{\_\_at}
13598
13599 \end_inset
13600
13601  (0x80) MOSI;\InsetSpace ~
13602 \InsetSpace ~
13603 \InsetSpace ~
13604 \InsetSpace ~
13605 /* I/O port 0, bit 0 */
13606 \newline
13607 __bit __at (0x81) MISO;\InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 \InsetSpace ~
13611 /* I/O port 0,
13612  bit 1 */
13613 \newline
13614 __bit __at (0x82) MCLK;\InsetSpace ~
13615 \InsetSpace ~
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 /* I/O port 0, bit 2 */
13619 \end_layout
13620
13621 \begin_layout Standard
13622 Similarly, for the second hardware you would use
13623 \end_layout
13624
13625 \begin_layout Verse
13626
13627 \family typewriter
13628 __bit __at (0x83) MOSI;\InsetSpace ~
13629 \InsetSpace ~
13630 \InsetSpace ~
13631 \InsetSpace ~
13632 /* I/O port 0, bit 3 */
13633 \newline
13634 __bit __at (0x91) MISO;\InsetSpace ~
13635 \InsetSpace ~
13636 \InsetSpace ~
13637 \InsetSpace ~
13638 /*
13639  I/O port 1, bit 1 */
13640 \newline
13641 __bit
13642 \begin_inset LatexCommand \index{bit}
13643
13644 \end_inset
13645
13646  __at (0x92) MCLK;\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 /* I/O port 1, bit 2 */
13651 \end_layout
13652
13653 \begin_layout Standard
13654 and you can use the same hardware dependent routine without changes, as
13655  for example in a library.
13656  This is somehow similar to sbit, but only one absolute address has to be
13657  specified in the whole project.
13658 \begin_inset VSpace bigskip
13659 \end_inset
13660
13661
13662 \end_layout
13663
13664 \begin_layout Section
13665 Parameters
13666 \begin_inset LatexCommand \index{Parameters}
13667
13668 \end_inset
13669
13670
13671 \begin_inset LatexCommand \index{function parameter}
13672
13673 \end_inset
13674
13675  & Local Variables
13676 \begin_inset LatexCommand \index{local variables}
13677
13678 \end_inset
13679
13680
13681 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13682
13683 \end_inset
13684
13685
13686 \end_layout
13687
13688 \begin_layout Standard
13689 Automatic (local) variables and parameters to functions can either be placed
13690  on the stack or in data-space.
13691  The default action of the compiler is to place these variables in the internal
13692  RAM (for small model) or external RAM (for medium or large model).
13693  This in fact makes them similar to 
13694 \emph on
13695 static
13696 \begin_inset LatexCommand \index{static}
13697
13698 \end_inset
13699
13700
13701 \emph default
13702  so by default functions are non-reentrant
13703 \begin_inset LatexCommand \index{reentrant}
13704
13705 \end_inset
13706
13707 .
13708  
13709 \newline
13710
13711 \newline
13712 They can be placed on the stack
13713 \begin_inset LatexCommand \index{stack}
13714
13715 \end_inset
13716
13717  by using the
13718 \emph on
13719  -
13720 \begin_inset ERT
13721 status collapsed
13722
13723 \begin_layout Standard
13724
13725
13726 \backslash
13727 /
13728 \end_layout
13729
13730 \end_inset
13731
13732 -stack-auto
13733 \begin_inset LatexCommand \index{-\/-stack-auto}
13734
13735 \end_inset
13736
13737
13738 \emph default
13739  option, by using 
13740 \emph on
13741 #pragma\InsetSpace ~
13742 stackauto
13743 \emph default
13744
13745 \begin_inset LatexCommand \index{\#pragma stackauto}
13746
13747 \end_inset
13748
13749  or by using the 
13750 \emph on
13751 reentrant
13752 \begin_inset LatexCommand \index{reentrant}
13753
13754 \end_inset
13755
13756
13757 \emph default
13758  keyword in the function declaration, e.g.:
13759 \end_layout
13760
13761 \begin_layout Verse
13762
13763 \family typewriter
13764 unsigned char foo(char i) __reentrant 
13765 \newline
13766
13767 \newline
13768 \InsetSpace ~
13769 \InsetSpace ~
13770 \InsetSpace ~
13771 \InsetSpace ~
13772 ...
13773  
13774 \newline
13775 }
13776 \end_layout
13777
13778 \begin_layout Standard
13779 Since stack space on 8051 is limited, the 
13780 \emph on
13781 reentrant 
13782 \emph default
13783 keyword or the
13784 \emph on
13785  -
13786 \begin_inset ERT
13787 status collapsed
13788
13789 \begin_layout Standard
13790
13791
13792 \backslash
13793 /
13794 \end_layout
13795
13796 \end_inset
13797
13798 -stack-auto
13799 \emph default
13800  option should be used sparingly.
13801  Note that the reentrant keyword just means that the parameters & local
13802  variables will be allocated to the stack, it 
13803 \emph on
13804 does not
13805 \emph default
13806  mean that the function is register bank
13807 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13808
13809 \end_inset
13810
13811  independent.
13812 \newline
13813
13814 \newline
13815 Local variables
13816 \begin_inset LatexCommand \index{local variables}
13817
13818 \end_inset
13819
13820  can be assigned storage classes and absolute
13821 \begin_inset LatexCommand \index{Absolute addressing}
13822
13823 \end_inset
13824
13825  addresses, e.g.: 
13826 \end_layout
13827
13828 \begin_layout Verse
13829
13830 \family typewriter
13831 unsigned char foo() 
13832 \newline
13833 {
13834 \newline
13835 \InsetSpace ~
13836 \InsetSpace ~
13837 \InsetSpace ~
13838 \InsetSpace ~
13839 __xdata unsigned char i;
13840 \newline
13841 \InsetSpace ~
13842 \InsetSpace ~
13843 \InsetSpace ~
13844 \InsetSpace ~
13845 __bit bvar;
13846 \newline
13847 \InsetSpace ~
13848 \InsetSpace ~
13849 \InsetSpace ~
13850 \InsetSpace ~
13851 __data __at
13852 \begin_inset LatexCommand \index{at}
13853
13854 \end_inset
13855
13856  (0x31) unsigned char j;
13857 \newline
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 \InsetSpace ~
13862 ...
13863  
13864 \newline
13865 }
13866 \end_layout
13867
13868 \begin_layout Standard
13869 In the above example the variable 
13870 \emph on
13871 i
13872 \emph default
13873  will be allocated in the external ram, 
13874 \emph on
13875 bvar
13876 \emph default
13877  in bit addressable space and
13878 \emph on
13879  j
13880 \emph default
13881  in internal ram.
13882  When compiled with 
13883 \emph on
13884 -
13885 \begin_inset ERT
13886 status collapsed
13887
13888 \begin_layout Standard
13889
13890
13891 \backslash
13892 /
13893 \end_layout
13894
13895 \end_inset
13896
13897 -stack-auto
13898 \emph default
13899  or when a function is declared as 
13900 \emph on
13901 reentrant
13902 \emph default
13903  this should only be done for static variables.
13904 \end_layout
13905
13906 \begin_layout Standard
13907 Parameters
13908 \begin_inset LatexCommand \index{function parameter}
13909
13910 \end_inset
13911
13912  however are not allowed any storage class
13913 \begin_inset LatexCommand \index{Storage class}
13914
13915 \end_inset
13916
13917 , (storage classes for parameters will be ignored), their allocation is
13918  governed by the memory model in use, and the reentrancy options.
13919 \end_layout
13920
13921 \begin_layout Standard
13922 It is however allowed to use bit parameters in reentrant functions and also
13923  non-static local bit variables are supported.
13924  Efficient use is limited to 8 semi-bitregisters in bit space.
13925  They are pushed and popped to stack
13926 \begin_inset LatexCommand \index{stack}
13927
13928 \end_inset
13929
13930  as a single byte just like the normal registers.
13931 \end_layout
13932
13933 \begin_layout Section
13934 Overlaying
13935 \begin_inset LatexCommand \label{sub:Overlaying}
13936
13937 \end_inset
13938
13939
13940 \begin_inset LatexCommand \index{Overlaying}
13941
13942 \end_inset
13943
13944
13945 \end_layout
13946
13947 \begin_layout Standard
13948 For non-reentrant
13949 \begin_inset LatexCommand \index{reentrant}
13950
13951 \end_inset
13952
13953  functions SDCC will try to reduce internal ram space usage by overlaying
13954  parameters and local variables of a function (if possible).
13955  Parameters and local variables
13956 \begin_inset LatexCommand \index{local variables}
13957
13958 \end_inset
13959
13960  of a function will be allocated to an overlayable segment if the function
13961  has 
13962 \emph on
13963 no other function calls and the function is non-reentrant and the memory
13964  model
13965 \begin_inset LatexCommand \index{Memory model}
13966
13967 \end_inset
13968
13969  is small.
13970
13971 \emph default
13972  If an explicit storage class
13973 \begin_inset LatexCommand \index{Storage class}
13974
13975 \end_inset
13976
13977  is specified for a local variable, it will NOT be overlayed.
13978 \end_layout
13979
13980 \begin_layout Standard
13981 Note that the compiler (not the linkage editor) makes the decision for overlayin
13982 g the data items.
13983  Functions that are called from an interrupt service routine
13984 \begin_inset Marginal
13985 status collapsed
13986
13987 \begin_layout Standard
13988
13989 \series bold
13990 !
13991 \end_layout
13992
13993 \end_inset
13994
13995  should be preceded by a #pragma\InsetSpace ~
13996 nooverlay
13997 \begin_inset LatexCommand \index{\#pragma nooverlay}
13998
13999 \end_inset
14000
14001  if they are not reentrant.
14002 \end_layout
14003
14004 \begin_layout Standard
14005 Also note that the compiler does not do any processing of inline assembler
14006  code, so the compiler might incorrectly assign local variables and parameters
14007  of a function into the overlay segment if the inline assembler code calls
14008  other c-functions that might use the overlay.
14009  In that case the #pragma\InsetSpace ~
14010 nooverlay should be used.
14011 \end_layout
14012
14013 \begin_layout Standard
14014 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14015 tion
14016 \begin_inset LatexCommand \index{Multiplication}
14017
14018 \end_inset
14019
14020  or division
14021 \begin_inset LatexCommand \index{Division}
14022
14023 \end_inset
14024
14025  will NOT be overlayed since these are implemented using external functions,
14026  e.g.:
14027 \end_layout
14028
14029 \begin_layout Verse
14030
14031 \family typewriter
14032 #pragma save 
14033 \newline
14034 #pragma nooverlay
14035 \begin_inset LatexCommand \index{\#pragma nooverlay}
14036
14037 \end_inset
14038
14039  
14040 \newline
14041 void set_error(unsigned char errcd) 
14042 \newline
14043 {
14044 \newline
14045 \InsetSpace ~
14046 \InsetSpace ~
14047 \InsetSpace ~
14048 \InsetSpace ~
14049 P3 = errcd;
14050 \newline
14051
14052 \newline
14053 #pragma restore 
14054 \newline
14055
14056 \newline
14057 void
14058  some_isr () __interrupt
14059 \begin_inset LatexCommand \index{interrupt}
14060
14061 \end_inset
14062
14063  (2)
14064 \newline
14065 {
14066 \newline
14067 \InsetSpace ~
14068 \InsetSpace ~
14069 \InsetSpace ~
14070 \InsetSpace ~
14071 ...
14072 \newline
14073 \InsetSpace ~
14074 \InsetSpace ~
14075 \InsetSpace ~
14076 \InsetSpace ~
14077 set_error(10);
14078 \newline
14079 \InsetSpace ~
14080 \InsetSpace ~
14081 \InsetSpace ~
14082 \InsetSpace ~
14083 ...
14084  
14085 \newline
14086 }
14087 \end_layout
14088
14089 \begin_layout Standard
14090 In the above example the parameter 
14091 \emph on
14092 errcd
14093 \emph default
14094  for the function 
14095 \emph on
14096 set_error
14097 \emph default
14098  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14099 nooverlay was
14100  not present, this could cause unpredictable runtime behavior when called
14101  from an interrupt service routine.
14102  The #pragma\InsetSpace ~
14103 nooverlay ensures that the parameters and local variables for
14104  the function are NOT overlayed.
14105 \begin_inset VSpace bigskip
14106 \end_inset
14107
14108
14109 \end_layout
14110
14111 \begin_layout Section
14112 Interrupt Service Routines
14113 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14114
14115 \end_inset
14116
14117
14118 \end_layout
14119
14120 \begin_layout Subsection
14121 General Information
14122 \end_layout
14123
14124 \begin_layout Standard
14125 SDCC allows 
14126 \emph on
14127 i
14128 \emph default
14129 nterrupt 
14130 \emph on
14131 s
14132 \emph default
14133 ervice 
14134 \emph on
14135 r
14136 \emph default
14137 outines to be coded in C, with some extended keywords.
14138 \end_layout
14139
14140 \begin_layout Verse
14141
14142 \family typewriter
14143 void timer_isr (void) __interrupt (1) __using (1) 
14144 \newline
14145
14146 \newline
14147 \InsetSpace ~
14148 \InsetSpace ~
14149 \InsetSpace ~
14150 \InsetSpace ~
14151 ...
14152  
14153 \newline
14154 }
14155 \end_layout
14156
14157 \begin_layout Standard
14158 The optional number following the 
14159 \emph on
14160 interrupt
14161 \begin_inset LatexCommand \index{interrupt}
14162
14163 \end_inset
14164
14165
14166 \begin_inset LatexCommand \index{\_\_interrupt}
14167
14168 \end_inset
14169
14170
14171 \emph default
14172  keyword is the interrupt number this routine will service.
14173  When present, the compiler will insert a call to this routine in the interrupt
14174  vector table
14175 \begin_inset LatexCommand \index{interrupt vector table}
14176
14177 \end_inset
14178
14179  for the interrupt number specified.
14180  If you have multiple source files in your project, interrupt service routines
14181  can be present in any of them, but a prototype of the isr MUST be present
14182  or included in the file that contains the function 
14183 \emph on
14184 main
14185 \emph default
14186 .
14187  The optional (8051 specific) keyword 
14188 \emph on
14189 using
14190 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14191
14192 \end_inset
14193
14194
14195 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14196
14197 \end_inset
14198
14199
14200 \emph default
14201  can be used to tell the compiler to use the specified register bank when
14202  generating code for this function.
14203  
14204 \newline
14205 Interrupt service routines open the door for some very interesting bugs:
14206 \end_layout
14207
14208 \begin_layout Subsubsection
14209 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14210
14211 \end_inset
14212
14213 Common interrupt pitfall: variable not declared 
14214 \emph on
14215 volatile
14216 \end_layout
14217
14218 \begin_layout Standard
14219 If an interrupt service routine changes variables which are accessed by
14220  other functions these variables have to be declared 
14221 \emph on
14222 volatile
14223 \emph default
14224
14225 \begin_inset LatexCommand \index{volatile}
14226
14227 \end_inset
14228
14229 .
14230  See 
14231 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14232
14233 \end_inset
14234
14235  .
14236 \end_layout
14237
14238 \begin_layout Subsubsection
14239 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14240
14241 \end_inset
14242
14243 Common interrupt pitfall: 
14244 \emph on
14245 non-atomic access
14246 \end_layout
14247
14248 \begin_layout Standard
14249 If the access to these variables is not 
14250 \emph on
14251 atomic
14252 \begin_inset LatexCommand \index{atomic}
14253
14254 \end_inset
14255
14256
14257 \emph default
14258  (i.e.
14259  the processor needs more than one instruction for the access and could
14260  be interrupted while accessing the variable) the interrupt must be disabled
14261  during the access to avoid inconsistent data.
14262  
14263 \newline
14264 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14265  and should be protected by disabling interrupts.
14266  You're not automatically on the safe side if you use 8 bit variables though.
14267  We need an example here: f.e.
14268  on the 8051 the harmless looking 
14269 \begin_inset Quotes srd
14270 \end_inset
14271
14272
14273 \family typewriter
14274 flags\InsetSpace ~
14275 |=\InsetSpace ~
14276 0x80;
14277 \family default
14278
14279 \begin_inset Quotes sld
14280 \end_inset
14281
14282  is not atomic if 
14283 \family typewriter
14284 flags
14285 \family default
14286  resides in xdata.
14287  Setting 
14288 \begin_inset Quotes srd
14289 \end_inset
14290
14291
14292 \family typewriter
14293 flags\InsetSpace ~
14294 |=\InsetSpace ~
14295 0x40;
14296 \family default
14297
14298 \begin_inset Quotes sld
14299 \end_inset
14300
14301  from within an interrupt routine might get lost if the interrupt occurs
14302  at the wrong time.
14303  
14304 \begin_inset Quotes sld
14305 \end_inset
14306
14307
14308 \family typewriter
14309 counter\InsetSpace ~
14310 +=\InsetSpace ~
14311 8;
14312 \family default
14313
14314 \begin_inset Quotes srd
14315 \end_inset
14316
14317  is not atomic on the 8051 even if 
14318 \family typewriter
14319 counter
14320 \family default
14321  is located in data memory.
14322 \newline
14323 Bugs like these are hard to reproduce and can
14324  cause a lot of trouble.
14325  
14326 \end_layout
14327
14328 \begin_layout Subsubsection
14329 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14330
14331 \end_inset
14332
14333 Common interrupt pitfall: 
14334 \emph on
14335 stack overflow
14336 \end_layout
14337
14338 \begin_layout Standard
14339 The return address and the registers used in the interrupt service routine
14340  are saved on the stack
14341 \begin_inset LatexCommand \index{stack}
14342
14343 \end_inset
14344
14345  so there must be sufficient stack space.
14346  If there isn't variables or registers (or even the return address itself)
14347  will be corrupted.
14348  This 
14349 \emph on
14350 stack overflow
14351 \emph default
14352
14353 \begin_inset LatexCommand \index{stack overflow}
14354
14355 \end_inset
14356
14357  is most likely to happen if the interrupt occurs during the 
14358 \begin_inset Quotes sld
14359 \end_inset
14360
14361 deepest
14362 \begin_inset Quotes srd
14363 \end_inset
14364
14365  subroutine when the stack is already in use for f.e.
14366  many return addresses.
14367 \end_layout
14368
14369 \begin_layout Subsubsection
14370 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14371
14372 \end_inset
14373
14374 Common interrupt pitfall: 
14375 \emph on
14376 use of non-reentrant functions
14377 \end_layout
14378
14379 \begin_layout Standard
14380 A special note here, int (16 bit) and long (32 bit) integer division
14381 \begin_inset LatexCommand \index{Division}
14382
14383 \end_inset
14384
14385 , multiplication
14386 \begin_inset LatexCommand \index{Multiplication}
14387
14388 \end_inset
14389
14390  & modulus
14391 \begin_inset LatexCommand \index{Modulus}
14392
14393 \end_inset
14394
14395  and floating-point
14396 \begin_inset LatexCommand \index{Floating point support}
14397
14398 \end_inset
14399
14400  operations are implemented using external support routines.
14401  If an interrupt service routine needs to do any of these operations then
14402  the support routines (as mentioned in a following section) will have to
14403  be recompiled using the
14404 \emph on
14405  -
14406 \begin_inset ERT
14407 status collapsed
14408
14409 \begin_layout Standard
14410
14411
14412 \backslash
14413 /
14414 \end_layout
14415
14416 \end_inset
14417
14418 -stack-auto
14419 \begin_inset LatexCommand \index{-\/-stack-auto}
14420
14421 \end_inset
14422
14423
14424 \emph default
14425  option and the source file will need to be compiled using the 
14426 \emph on
14427 -
14428 \begin_inset ERT
14429 status collapsed
14430
14431 \begin_layout Standard
14432
14433
14434 \backslash
14435 /
14436 \end_layout
14437
14438 \end_inset
14439
14440 -int-long-reent
14441 \emph default
14442
14443 \begin_inset LatexCommand \index{-\/-int-long-reent}
14444
14445 \end_inset
14446
14447  compiler option.
14448  
14449 \newline
14450 Note, the type promotion
14451 \begin_inset LatexCommand \index{type promotion}
14452
14453 \end_inset
14454
14455  required by ANSI C can cause 16 bit routines to be used
14456 \begin_inset Marginal
14457 status collapsed
14458
14459 \begin_layout Standard
14460
14461 \series bold
14462 \InsetSpace ~
14463 !
14464 \end_layout
14465
14466 \end_inset
14467
14468  without the programmer being aware of it.
14469  See f.e.
14470  the cast 
14471 \family typewriter
14472 (unsigned char)(tail-1)
14473 \family default
14474  within the if clause in section 
14475 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14476
14477 \end_inset
14478
14479 .
14480 \end_layout
14481
14482 \begin_layout Standard
14483 Calling other functions from an interrupt service routine is not recommended,
14484  avoid it if possible.
14485  Note that when some function is called from an interrupt service routine
14486  it should be preceded by a #pragma\InsetSpace ~
14487 nooverlay
14488 \begin_inset LatexCommand \index{\#pragma nooverlay}
14489
14490 \end_inset
14491
14492  if it is not reentrant.
14493  Furthermore nonreentrant functions should not be called from the main program
14494  while the interrupt service routine might be active.
14495  They also must not be called from low priority interrupt service routines
14496  while a high priority interrupt service routine might be active.
14497  You could use semaphores or make the function
14498 \emph on
14499  critical
14500 \emph default
14501  if all parameters are passed in registers.
14502 \newline
14503  Also see section 
14504 \begin_inset LatexCommand \ref{sub:Overlaying}
14505
14506 \end_inset
14507
14508 \InsetSpace ~
14509 about Overlaying and section 
14510 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14511
14512 \end_inset
14513
14514 \InsetSpace ~
14515 about Functions using private register banks.
14516 \begin_inset VSpace bigskip
14517 \end_inset
14518
14519
14520 \end_layout
14521
14522 \begin_layout Subsection
14523 MCS51/DS390 Interrupt Service Routines
14524 \end_layout
14525
14526 \begin_layout Standard
14527 Interrupt
14528 \begin_inset LatexCommand \index{interrupt}
14529
14530 \end_inset
14531
14532  numbers and the corresponding address & descriptions for the Standard 8051/8052
14533  are listed below.
14534  SDCC will automatically adjust the 
14535 \begin_inset LatexCommand \index{interrupt vector table}
14536
14537 \end_inset
14538
14539  to the maximum interrupt number specified.
14540 \newline
14541
14542 \end_layout
14543
14544 \begin_layout Standard
14545 \align center
14546 \begin_inset Tabular
14547 <lyxtabular version="3" rows="9" columns="3">
14548 <features>
14549 <column alignment="center" valignment="top" leftline="true" width="0in">
14550 <column alignment="left" valignment="top" leftline="true" width="0in">
14551 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14552 <row topline="true" bottomline="true">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14554 \begin_inset Text
14555
14556 \begin_layout Standard
14557 Interrupt #
14558 \end_layout
14559
14560 \end_inset
14561 </cell>
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14563 \begin_inset Text
14564
14565 \begin_layout Standard
14566 Description
14567 \end_layout
14568
14569 \end_inset
14570 </cell>
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14572 \begin_inset Text
14573
14574 \begin_layout Standard
14575 Vector Address
14576 \end_layout
14577
14578 \end_inset
14579 </cell>
14580 </row>
14581 <row topline="true">
14582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14583 \begin_inset Text
14584
14585 \begin_layout Standard
14586 0
14587 \end_layout
14588
14589 \end_inset
14590 </cell>
14591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14592 \begin_inset Text
14593
14594 \begin_layout Standard
14595 External 0
14596 \end_layout
14597
14598 \end_inset
14599 </cell>
14600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14601 \begin_inset Text
14602
14603 \begin_layout Standard
14604 0x0003
14605 \end_layout
14606
14607 \end_inset
14608 </cell>
14609 </row>
14610 <row topline="true">
14611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14612 \begin_inset Text
14613
14614 \begin_layout Standard
14615 1
14616 \end_layout
14617
14618 \end_inset
14619 </cell>
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14621 \begin_inset Text
14622
14623 \begin_layout Standard
14624 Timer 0
14625 \end_layout
14626
14627 \end_inset
14628 </cell>
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14630 \begin_inset Text
14631
14632 \begin_layout Standard
14633 0x000b
14634 \end_layout
14635
14636 \end_inset
14637 </cell>
14638 </row>
14639 <row topline="true">
14640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14641 \begin_inset Text
14642
14643 \begin_layout Standard
14644 2
14645 \end_layout
14646
14647 \end_inset
14648 </cell>
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14650 \begin_inset Text
14651
14652 \begin_layout Standard
14653 External 1
14654 \end_layout
14655
14656 \end_inset
14657 </cell>
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14659 \begin_inset Text
14660
14661 \begin_layout Standard
14662 0x0013
14663 \end_layout
14664
14665 \end_inset
14666 </cell>
14667 </row>
14668 <row topline="true">
14669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14670 \begin_inset Text
14671
14672 \begin_layout Standard
14673 3
14674 \end_layout
14675
14676 \end_inset
14677 </cell>
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14679 \begin_inset Text
14680
14681 \begin_layout Standard
14682 Timer 1
14683 \end_layout
14684
14685 \end_inset
14686 </cell>
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14688 \begin_inset Text
14689
14690 \begin_layout Standard
14691 0x001b
14692 \end_layout
14693
14694 \end_inset
14695 </cell>
14696 </row>
14697 <row topline="true">
14698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14699 \begin_inset Text
14700
14701 \begin_layout Standard
14702 4
14703 \end_layout
14704
14705 \end_inset
14706 </cell>
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14708 \begin_inset Text
14709
14710 \begin_layout Standard
14711 Serial
14712 \end_layout
14713
14714 \end_inset
14715 </cell>
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14717 \begin_inset Text
14718
14719 \begin_layout Standard
14720 0x0023
14721 \end_layout
14722
14723 \end_inset
14724 </cell>
14725 </row>
14726 <row topline="true">
14727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14728 \begin_inset Text
14729
14730 \begin_layout Standard
14731 5
14732 \end_layout
14733
14734 \end_inset
14735 </cell>
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14737 \begin_inset Text
14738
14739 \begin_layout Standard
14740 Timer 2 (8052)
14741 \end_layout
14742
14743 \end_inset
14744 </cell>
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14746 \begin_inset Text
14747
14748 \begin_layout Standard
14749 0x002b
14750 \end_layout
14751
14752 \end_inset
14753 </cell>
14754 </row>
14755 <row topline="true">
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14757 \begin_inset Text
14758
14759 \begin_layout Standard
14760 ...
14761 \end_layout
14762
14763 \end_inset
14764 </cell>
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14766 \begin_inset Text
14767
14768 \begin_layout Standard
14769
14770 \end_layout
14771
14772 \end_inset
14773 </cell>
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14775 \begin_inset Text
14776
14777 \begin_layout Standard
14778 ...
14779 \end_layout
14780
14781 \end_inset
14782 </cell>
14783 </row>
14784 <row topline="true" bottomline="true">
14785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14786 \begin_inset Text
14787
14788 \begin_layout Standard
14789 n
14790 \end_layout
14791
14792 \end_inset
14793 </cell>
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14795 \begin_inset Text
14796
14797 \begin_layout Standard
14798
14799 \end_layout
14800
14801 \end_inset
14802 </cell>
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14804 \begin_inset Text
14805
14806 \begin_layout Standard
14807 0x0003 + 8*n
14808 \end_layout
14809
14810 \end_inset
14811 </cell>
14812 </row>
14813 </lyxtabular>
14814
14815 \end_inset
14816
14817
14818 \newline
14819
14820 \end_layout
14821
14822 \begin_layout Standard
14823 If the interrupt service routine is defined without 
14824 \emph on
14825 using
14826 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14827
14828 \end_inset
14829
14830
14831 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14832
14833 \end_inset
14834
14835
14836 \emph default
14837  a register bank or with register bank 0 (
14838 \emph on
14839 using
14840 \emph default
14841  0), the compiler will save the registers used by itself on the stack upon
14842  entry and restore them at exit, however if such an interrupt service routine
14843  calls another function then the entire register bank will be saved on the
14844  stack.
14845  This scheme may be advantageous for small interrupt service routines which
14846  have low register usage.
14847 \end_layout
14848
14849 \begin_layout Standard
14850 If the interrupt service routine is defined to be using a specific register
14851  bank then only 
14852 \emph on
14853 a, b, dptr
14854 \emph default
14855  & psw are saved and restored, if such an interrupt service routine calls
14856  another function (using another register bank) then the entire register
14857  bank of the called function will be saved on the stack
14858 \begin_inset LatexCommand \index{stack}
14859
14860 \end_inset
14861
14862 .
14863  This scheme is recommended for larger interrupt service routines.
14864 \begin_inset VSpace bigskip
14865 \end_inset
14866
14867
14868 \end_layout
14869
14870 \begin_layout Subsection
14871 HC08
14872 \begin_inset LatexCommand \index{HC08}
14873
14874 \end_inset
14875
14876  Interrupt Service Routines
14877 \end_layout
14878
14879 \begin_layout Standard
14880 Since the number of interrupts
14881 \begin_inset LatexCommand \index{HC08!interrupt}
14882
14883 \end_inset
14884
14885  available is chip specific and the interrupt vector table always ends at
14886  the last byte of memory, the interrupt numbers corresponds to the interrupt
14887  vectors in reverse order of address.
14888  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14889  2 will use the interrupt vector at 0xfffa, and so on.
14890  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14891  this way; instead see section 
14892 \begin_inset LatexCommand \ref{sub:Startup-Code}
14893
14894 \end_inset
14895
14896  for details on customizing startup.
14897 \begin_inset VSpace bigskip
14898 \end_inset
14899
14900
14901 \end_layout
14902
14903 \begin_layout Subsection
14904 Z80 Interrupt Service Routines
14905 \end_layout
14906
14907 \begin_layout Standard
14908 The Z80
14909 \begin_inset LatexCommand \index{Z80}
14910
14911 \end_inset
14912
14913  uses several different methods for determining the correct interrupt
14914 \begin_inset LatexCommand \index{Z80!interrupt}
14915
14916 \end_inset
14917
14918  vector depending on the hardware implementation.
14919  Therefore, SDCC ignores the optional interrupt number and does not attempt
14920  to generate an interrupt vector table.
14921 \end_layout
14922
14923 \begin_layout Standard
14924 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14925  instruction to return from the interrupt.
14926  To write an interrupt handler for the non-maskable interrupt, which needs
14927  a RETN instruction instead, add the 
14928 \emph on
14929 critical
14930 \emph default
14931  keyword:
14932 \end_layout
14933
14934 \begin_layout Verse
14935
14936 \family typewriter
14937 void nmi_isr (void) critical interrupt
14938 \newline
14939
14940 \newline
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 ...
14946  
14947 \newline
14948 }
14949 \end_layout
14950
14951 \begin_layout Standard
14952 However if you need to create a non-interruptable interrupt service routine
14953  you would also require the 
14954 \emph on
14955 critical
14956 \emph default
14957  keyword.
14958  To distinguish between this and an nmi_isr you must provide an interrupt
14959  number.
14960 \begin_inset VSpace bigskip
14961 \end_inset
14962
14963
14964 \end_layout
14965
14966 \begin_layout Section
14967 Enabling and Disabling Interrupts
14968 \end_layout
14969
14970 \begin_layout Subsection
14971 Critical Functions and Critical Statements
14972 \end_layout
14973
14974 \begin_layout Standard
14975 A special keyword may be associated with a block or a function declaring
14976  it as 
14977 \emph on
14978 critical
14979 \emph default
14980 .
14981  SDCC will generate code to disable all interrupts
14982 \begin_inset LatexCommand \index{interrupt}
14983
14984 \end_inset
14985
14986  upon entry to a critical function and restore the interrupt enable to the
14987  previous state before returning.
14988  Nesting critical functions will need one additional byte on the stack
14989 \begin_inset LatexCommand \index{stack}
14990
14991 \end_inset
14992
14993  for each call.
14994 \end_layout
14995
14996 \begin_layout Verse
14997
14998 \family typewriter
14999 int foo () __critical
15000 \begin_inset LatexCommand \index{critical}
15001
15002 \end_inset
15003
15004
15005 \begin_inset LatexCommand \index{\_\_critical}
15006
15007 \end_inset
15008
15009  
15010 \newline
15011
15012 \newline
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 ...
15018  
15019 \newline
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 ...
15025  
15026 \newline
15027 }
15028 \end_layout
15029
15030 \begin_layout Standard
15031 The critical attribute maybe used with other attributes like 
15032 \emph on
15033 reentrant.
15034 \emph default
15035
15036 \newline
15037 The keyword 
15038 \emph on
15039 critical
15040 \emph default
15041  may also be used to disable interrupts more locally:
15042 \end_layout
15043
15044 \begin_layout Verse
15045
15046 \family typewriter
15047 __critical{ i++; }
15048 \end_layout
15049
15050 \begin_layout Standard
15051 More than one statement could have been included in the block.
15052 \end_layout
15053
15054 \begin_layout Subsection
15055 Enabling and Disabling Interrupts directly
15056 \end_layout
15057
15058 \begin_layout Standard
15059 Interrupts
15060 \begin_inset LatexCommand \index{interrupt}
15061
15062 \end_inset
15063
15064  can also be disabled and enabled directly (8051):
15065 \end_layout
15066
15067 \begin_layout Verse
15068
15069 \family typewriter
15070 EA = 0;\InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 or:\InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 EA_SAVE = EA;
15094 \end_layout
15095
15096 \begin_layout Verse
15097
15098 \family typewriter
15099 ...\InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 \InsetSpace ~
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
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 EA = 0;
15130 \end_layout
15131
15132 \begin_layout Verse
15133
15134 \family typewriter
15135 EA = 1;\InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \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 ...
15162 \end_layout
15163
15164 \begin_layout Verse
15165
15166 \family typewriter
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
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 EA = EA_SAVE;
15201 \end_layout
15202
15203 \begin_layout Standard
15204 On other architectures which have seperate opcodes for enabling and disabling
15205  interrupts you might want to make use of defines with inline assembly
15206 \begin_inset LatexCommand \index{Assembler routines}
15207
15208 \end_inset
15209
15210  (HC08
15211 \begin_inset LatexCommand \index{HC08!interrupt}
15212
15213 \end_inset
15214
15215 ):
15216 \end_layout
15217
15218 \begin_layout Verse
15219
15220 \family typewriter
15221 #define CLI _asm
15222 \begin_inset LatexCommand \index{\_asm}
15223
15224 \end_inset
15225
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 cli\InsetSpace ~
15229 \InsetSpace ~
15230 _endasm
15231 \begin_inset LatexCommand \index{\_endasm}
15232
15233 \end_inset
15234
15235
15236 \end_layout
15237
15238 \begin_layout Verse
15239
15240 \family typewriter
15241 #define SEI _asm\InsetSpace ~
15242 \InsetSpace ~
15243 sei\InsetSpace ~
15244 \InsetSpace ~
15245 _endasm; 
15246 \end_layout
15247
15248 \begin_layout Verse
15249
15250 \family typewriter
15251 ...
15252 \end_layout
15253
15254 \begin_layout Standard
15255 Note: it is sometimes sufficient to disable only a specific interrupt source
15256  like f.e.
15257  a timer or serial interrupt by manipulating an 
15258 \emph on
15259 interrupt mask
15260 \begin_inset LatexCommand \index{interrupt mask}
15261
15262 \end_inset
15263
15264
15265 \emph default
15266  register.
15267  
15268 \end_layout
15269
15270 \begin_layout Standard
15271 Usually the time during which interrupts are disabled should be kept as
15272  short as possible.
15273  This minimizes both 
15274 \emph on
15275 interrupt latency
15276 \emph default
15277
15278 \begin_inset LatexCommand \index{interrupt latency}
15279
15280 \end_inset
15281
15282  (the time between the occurrence of the interrupt and the execution of
15283  the first code in the interrupt routine) and 
15284 \emph on
15285 interrupt jitter
15286 \emph default
15287
15288 \begin_inset LatexCommand \index{interrupt jitter}
15289
15290 \end_inset
15291
15292  (the difference between the shortest and the longest interrupt latency).
15293  These really are something different, f.e.
15294  a serial interrupt has to be served before its buffer overruns so it cares
15295  for the maximum interrupt latency, whereas it does not care about jitter.
15296  On a loudspeaker driven via a digital to analog converter which is fed
15297  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15298  a much smaller jitter will be very audible.
15299 \end_layout
15300
15301 \begin_layout Standard
15302 You can reenable interrupts within an interrupt routine and on some architecture
15303 s you can make use of two (or more) levels of 
15304 \emph on
15305 interrupt priorities
15306 \emph default
15307
15308 \begin_inset LatexCommand \index{interrupt priority}
15309
15310 \end_inset
15311
15312 .
15313  On some architectures which don't support interrupt priorities these can
15314  be implemented by manipulating the interrupt mask and reenabling interrupts
15315  within the interrupt routine.
15316  Check there is sufficient space on the stack
15317 \begin_inset LatexCommand \index{stack}
15318
15319 \end_inset
15320
15321  and don't add complexity unless you have to.
15322  
15323 \end_layout
15324
15325 \begin_layout Subsection
15326 Semaphore
15327 \begin_inset LatexCommand \index{semaphore}
15328
15329 \end_inset
15330
15331  locking (mcs51/ds390)
15332 \end_layout
15333
15334 \begin_layout Standard
15335 Some architectures (mcs51/ds390) have an atomic
15336 \begin_inset LatexCommand \index{atomic}
15337
15338 \end_inset
15339
15340  bit test and
15341 \emph on
15342  
15343 \emph default
15344 clear
15345 \emph on
15346  
15347 \emph default
15348 instruction.
15349  These type of instructions are typically used in preemptive multitasking
15350  systems, where a routine f.e.
15351  claims the use of a data structure ('acquires a lock
15352 \begin_inset LatexCommand \index{lock}
15353
15354 \end_inset
15355
15356  on it'), makes some modifications and then releases the lock when the data
15357  structure is consistent again.
15358  The instruction may also be used if interrupt and non-interrupt code have
15359  to compete for a resource.
15360  With the atomic bit test and clear instruction interrupts
15361 \begin_inset LatexCommand \index{interrupt}
15362
15363 \end_inset
15364
15365  don't have to be disabled for the locking operation.
15366  
15367 \end_layout
15368
15369 \begin_layout Standard
15370 SDCC generates this instruction if the source follows this pattern:
15371 \end_layout
15372
15373 \begin_layout Verse
15374
15375 \family typewriter
15376 volatile
15377 \begin_inset LatexCommand \index{volatile}
15378
15379 \end_inset
15380
15381  bit resource_is_free; 
15382 \newline
15383
15384 \newline
15385 if (resource_is_free) 
15386 \newline
15387 \InsetSpace ~
15388 \InsetSpace ~
15389
15390 \newline
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 resource_is_free=0; 
15396 \newline
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 ...
15402  
15403 \newline
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 resource_is_free=1;
15409 \newline
15410 \InsetSpace ~
15411 \InsetSpace ~
15412
15413 \end_layout
15414
15415 \begin_layout Standard
15416 Note, mcs51 and ds390 support only an atomic
15417 \begin_inset LatexCommand \index{atomic}
15418
15419 \end_inset
15420
15421  bit test and 
15422 \emph on
15423 clear
15424 \emph default
15425  instruction (as opposed to atomic bit test and 
15426 \emph on
15427 set).
15428 \end_layout
15429
15430 \begin_layout Section
15431 Functions using private register banks
15432 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15433
15434 \end_inset
15435
15436  (mcs51/ds390)
15437 \end_layout
15438
15439 \begin_layout Standard
15440 Some architectures have support for quickly changing register sets.
15441  SDCC supports this feature with the 
15442 \emph on
15443 using
15444 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15445
15446 \end_inset
15447
15448
15449 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15450
15451 \end_inset
15452
15453
15454 \emph default
15455  attribute (which tells the compiler to use a register bank
15456 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15457
15458 \end_inset
15459
15460  other than the default bank zero).
15461  It should only be applied to 
15462 \emph on
15463 interrupt
15464 \begin_inset LatexCommand \index{interrupt}
15465
15466 \end_inset
15467
15468
15469 \emph default
15470  functions (see footnote below).
15471  This will in most circumstances make the generated ISR code more efficient
15472  since it will not have to save registers on the stack.
15473 \end_layout
15474
15475 \begin_layout Standard
15476 The 
15477 \emph on
15478 using
15479 \emph default
15480  attribute will have no effect on the generated code for a 
15481 \emph on
15482 non-interrupt
15483 \emph default
15484  function (but may occasionally be useful anyway
15485 \begin_inset Foot
15486 status open
15487
15488 \begin_layout Standard
15489 possible exception: if a function is called ONLY from 'interrupt' functions
15490  using a particular bank, it can be declared with the same 'using' attribute
15491  as the calling 'interrupt' functions.
15492  For instance, if you have several ISRs using bank one, and all of them
15493  call memcpy(), it might make sense to create a specialized version of memcpy()
15494  'using 1', since this would prevent the ISR from having to save bank zero
15495  to the stack on entry and switch to bank zero before calling the function
15496 \end_layout
15497
15498 \end_inset
15499
15500 ).
15501 \newline
15502
15503 \emph on
15504 (pending: Note, nowadays the 
15505 \emph default
15506 using
15507 \emph on
15508  attribute has an effect on
15509 \emph default
15510  
15511 \emph on
15512 the generated code for a 
15513 \emph default
15514 non-interrupt
15515 \emph on
15516  function
15517 \emph default
15518 .
15519 \emph on
15520 )
15521 \end_layout
15522
15523 \begin_layout Standard
15524 An 
15525 \emph on
15526 interrupt
15527 \emph default
15528  function using a non-zero bank will assume that it can trash that register
15529  bank, and will not save it.
15530  Since high-priority interrupts
15531 \begin_inset LatexCommand \index{interrupts}
15532
15533 \end_inset
15534
15535
15536 \begin_inset LatexCommand \index{interrupt priority}
15537
15538 \end_inset
15539
15540  can interrupt low-priority ones on the 8051 and friends, this means that
15541  if a high-priority ISR 
15542 \emph on
15543 using
15544 \emph default
15545  a particular bank occurs while processing a low-priority ISR 
15546 \emph on
15547 using
15548 \emph default
15549  the same bank, terrible and bad things can happen.
15550  To prevent this, no single register bank should be 
15551 \emph on
15552 used
15553 \emph default
15554  by both a high priority and a low priority ISR.
15555  This is probably most easily done by having all high priority ISRs use
15556  one bank and all low priority ISRs use another.
15557  If you have an ISR which can change priority at runtime, you're on your
15558  own: I suggest using the default bank zero and taking the small performance
15559  hit.
15560 \end_layout
15561
15562 \begin_layout Standard
15563 It is most efficient if your ISR calls no other functions.
15564  If your ISR must call other functions, it is most efficient if those functions
15565  use the same bank as the ISR (see note 1 below); the next best is if the
15566  called functions use bank zero.
15567  It is very inefficient to call a function using a different, non-zero bank
15568  from an ISR.
15569  
15570 \begin_inset VSpace bigskip
15571 \end_inset
15572
15573
15574 \end_layout
15575
15576 \begin_layout Section
15577 Startup Code
15578 \begin_inset LatexCommand \label{sub:Startup-Code}
15579
15580 \end_inset
15581
15582
15583 \begin_inset LatexCommand \index{Startup code}
15584
15585 \end_inset
15586
15587
15588 \end_layout
15589
15590 \begin_layout Subsection
15591 MCS51/DS390 Startup Code
15592 \end_layout
15593
15594 \begin_layout Standard
15595 The compiler triggers the linker to link certain initialization modules
15596  from the runtime library
15597 \begin_inset LatexCommand \index{Runtime library}
15598
15599 \end_inset
15600
15601  called crt<something>.
15602  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15603  GSINIT5) is not linked unless the -
15604 \series bold
15605
15606 \begin_inset ERT
15607 status open
15608
15609 \begin_layout Standard
15610
15611
15612 \backslash
15613 /
15614 \end_layout
15615
15616 \end_inset
15617
15618
15619 \series default
15620 -xstack option is used.
15621  These modules are highly entangled by the use of special segments/areas,
15622  but a common layout is shown below:
15623 \end_layout
15624
15625 \begin_layout Verse
15626
15627 \family typewriter
15628 \series bold
15629 \size footnotesize
15630 (main.asm)
15631 \end_layout
15632
15633 \begin_layout Verse
15634
15635 \family typewriter
15636 \size footnotesize
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 .area HOME (CODE)
15646 \newline
15647 __interrupt_vect:
15648 \newline
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 ljmp __sdcc_gsinit_startup
15658 \end_layout
15659
15660 \begin_layout Verse
15661
15662 \family typewriter
15663 \series bold
15664 \size footnotesize
15665 (crtstart.asm)
15666 \end_layout
15667
15668 \begin_layout Verse
15669
15670 \family typewriter
15671 \size footnotesize
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 .area GSINIT0 (CODE)
15681 \newline
15682 __sdcc_gsinit_startup::
15683 \newline
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 mov sp,#__start__stack - 1
15693 \end_layout
15694
15695 \begin_layout Verse
15696
15697 \family typewriter
15698 \series bold
15699 \size footnotesize
15700 (crtxstack.asm)
15701 \end_layout
15702
15703 \begin_layout Verse
15704
15705 \family typewriter
15706 \size footnotesize
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 .area GSINIT1 (CODE)
15716 \newline
15717 __sdcc_init_xstack::
15718 \newline
15719 ; Need to initialize in GSINIT1 in
15720  case the user's __sdcc_external_startup uses the xstack.
15721 \newline
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 mov __XPAGE,#(__start__x
15731 stack >> 8)
15732 \newline
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 mov _spx,#__start__xstack
15742 \end_layout
15743
15744 \begin_layout Verse
15745
15746 \family typewriter
15747 \series bold
15748 \size footnotesize
15749 (crtstart.asm)
15750 \end_layout
15751
15752 \begin_layout Verse
15753
15754 \family typewriter
15755 \size footnotesize
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 .area GSINIT2 (CODE)
15765 \newline
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 lcall __sdcc_external_startup
15775 \newline
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 mov a,dpl
15785 \newline
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 jz __sdcc_init_data
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 ljmp
15805  __sdcc_program_startup
15806 \newline
15807 __sdcc_init_data:
15808 \end_layout
15809
15810 \begin_layout Verse
15811
15812 \family typewriter
15813 \series bold
15814 \size footnotesize
15815 (crtxinit.asm)
15816 \end_layout
15817
15818 \begin_layout Verse
15819
15820 \family typewriter
15821 \size footnotesize
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 .area GSINIT3 (CODE)
15831 \newline
15832 __mcs51_genXINIT::
15833 \newline
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 mov r1,#l_XINIT
15843 \newline
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 mov a,r1
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 orl a,#(l_XINIT
15863  >> 8)
15864 \newline
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 jz 00003$
15874 \newline
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 mov r2,#((l_XINIT+255) >> 8)
15884 \newline
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 mov dptr,#s_XINIT
15894 \newline
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 mov r0,#s_XISEG
15904 \newline
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov
15914  __XPAGE,#(s_XISEG >> 8)
15915 \newline
15916 00001$:\InsetSpace ~
15917 clr a
15918 \newline
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 movc a,@a+dptr
15928 \newline
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 movx @r0,a
15938 \newline
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 inc dptr
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 inc
15958  r0
15959 \newline
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 cjne r0,#0,00002$
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 inc __XPAGE
15979 \newline
15980 00002$:\InsetSpace ~
15981 djnz r1,00001$
15982 \newline
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 djnz r2,00001$
15992 \newline
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 mov __XPAGE,#0
16002 xFF
16003 \newline
16004 00003$:
16005 \end_layout
16006
16007 \begin_layout Verse
16008
16009 \family typewriter
16010 \series bold
16011 \size footnotesize
16012 (crtclear.asm)
16013 \end_layout
16014
16015 \begin_layout Verse
16016
16017 \family typewriter
16018 \size footnotesize
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 .area GSINIT4 (CODE)
16028 \newline
16029 __mcs51_genRAMCLEAR::
16030 \newline
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 clr a
16040 \newline
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 mov r0,#(l_IRAM-1)
16050 \newline
16051 00004$:\InsetSpace ~
16052 mov
16053  @r0,a
16054 \newline
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 djnz r0,00004$
16064 \newline
16065 ; _mcs51_genRAMCLEAR() end
16066 \end_layout
16067
16068 \begin_layout Verse
16069
16070 \family typewriter
16071 \series bold
16072 \size footnotesize
16073 (crtxclear.asm)
16074 \end_layout
16075
16076 \begin_layout Verse
16077
16078 \family typewriter
16079 \size footnotesize
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 .area GSINIT4 (CODE)
16089 \newline
16090 __mcs51_genXRAMCLEAR::
16091 \newline
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 mov r0,#l_PSEG
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 mov a,r0
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 orl a,#(l_PSEG
16121  >> 8)
16122 \newline
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 jz 00006$
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 mov r1,#s_PSEG
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov __XPAGE,#(s_PSEG >> 8)
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 clr a
16162 \newline
16163 00005$:\InsetSpace ~
16164 movx
16165  @r1,a
16166 \newline
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 inc r1
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 djnz r0,00005$
16186 \newline
16187 00006$:
16188 \newline
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 mov r0,#l_XSEG
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 mov a,r0
16208 \newline
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 orl a,#(l_XSEG >>
16218  8)
16219 \newline
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 jz 00008$
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 mov r1,#((l_XSEG + 255) >> 8)
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 mov dptr,#s_XSEG
16249 \newline
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 clr a
16259 \newline
16260 00007$:\InsetSpace ~
16261 movx
16262  @dptr,a
16263 \newline
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 inc dptr
16273 \newline
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 djnz r0,00007$
16283 \newline
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 djnz r1,00007$
16293 \newline
16294 00008$:
16295 \end_layout
16296
16297 \begin_layout Verse
16298
16299 \family typewriter
16300 \series bold
16301 \size footnotesize
16302 (crtxstack.asm)
16303 \end_layout
16304
16305 \begin_layout Verse
16306
16307 \family typewriter
16308 \size footnotesize
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 .area GSINIT5 (CODE)
16318 \newline
16319 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16320  modifies __XPAGE
16321 \newline
16322 ; and __mcs51_genRAMCLEAR modifies _spx.
16323 \newline
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 mov __XPAGE,#(__start__x
16333 stack >> 8)
16334 \newline
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 mov _spx,#__start__xstack
16344 \end_layout
16345
16346 \begin_layout Verse
16347
16348 \family typewriter
16349 \series bold
16350 \size footnotesize
16351 (application modules)
16352 \end_layout
16353
16354 \begin_layout Verse
16355
16356 \family typewriter
16357 \size footnotesize
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 .area GSINIT (CODE)
16367 \end_layout
16368
16369 \begin_layout Verse
16370
16371 \family typewriter
16372 \series bold
16373 \size footnotesize
16374 (main.asm)
16375 \end_layout
16376
16377 \begin_layout Verse
16378
16379 \family typewriter
16380 \size footnotesize
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 .area GSFINAL (CODE)
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 ljmp __sdcc_program_startup
16400 \newline
16401 ;---------------------------------
16402 -----------------------
16403 \newline
16404 ; Home
16405 \newline
16406 ;--------------------------------------------------
16407 ------
16408 \newline
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 .area HOME (CODE)
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 .area CSEG (CODE)
16428 \newline
16429 __sdcc_program_startup:
16430 \newline
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 lcall _main
16440 \newline
16441 ;
16442  return from main will lock up
16443 \newline
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 sjmp .
16453 \end_layout
16454
16455 \begin_layout Standard
16456 One of these modules (crtstart.asm) contains a call to the C routine 
16457 \emph on
16458 _sdcc_external_startup()
16459 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16460
16461 \end_inset
16462
16463
16464 \series bold
16465 \emph default
16466  
16467 \series default
16468 at the start of the CODE area.
16469  This routine is also in the runtime library
16470 \begin_inset LatexCommand \index{Runtime library}
16471
16472 \end_inset
16473
16474  and returns 0 by default.
16475  If this routine returns a non-zero value, the static & global variable
16476  initialization will be skipped and the function main will be invoked.
16477  Otherwise static & global variables will be initialized before the function
16478  main is invoked.
16479  You could add an 
16480 \emph on
16481 _sdcc_external_startup()
16482 \emph default
16483  routine to your program to override the default if you need to setup hardware
16484  or perform some other critical operation prior to static & global variable
16485  initialization
16486 \begin_inset LatexCommand \index{Variable initialization}
16487
16488 \end_inset
16489
16490 .
16491  On some mcs51 variants xdata
16492 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16493
16494 \end_inset
16495
16496  memory has to be explicitly enabled before it can be accessed or if the
16497  watchdog
16498 \begin_inset LatexCommand \index{watchdog}
16499
16500 \end_inset
16501
16502  needs to be disabled, this is the place to do it.
16503  The startup code clears all internal data memory, 256 bytes by default,
16504  but from 0 to n-1 if 
16505 \emph on
16506 -
16507 \begin_inset ERT
16508 status collapsed
16509
16510 \begin_layout Standard
16511
16512
16513 \backslash
16514 /
16515 \end_layout
16516
16517 \end_inset
16518
16519 -iram-size
16520 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16521
16522 \end_inset
16523
16524 n
16525 \emph default
16526  is used.
16527  (recommended for Chipcon CC1010).
16528 \end_layout
16529
16530 \begin_layout Standard
16531 See also the compiler options 
16532 \emph on
16533 -
16534 \begin_inset ERT
16535 status collapsed
16536
16537 \begin_layout Standard
16538
16539
16540 \backslash
16541 /
16542 \end_layout
16543
16544 \end_inset
16545
16546 -no-xinit
16547 \emph default
16548 -
16549 \emph on
16550 opt
16551 \emph default
16552
16553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16554
16555 \end_inset
16556
16557
16558 \emph on
16559 -
16560 \begin_inset ERT
16561 status collapsed
16562
16563 \begin_layout Standard
16564
16565
16566 \backslash
16567 /
16568 \end_layout
16569
16570 \end_inset
16571
16572 -main-return
16573 \emph default
16574
16575 \begin_inset LatexCommand \index{-\/-main-return}
16576
16577 \end_inset
16578
16579  and section 
16580 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16581
16582 \end_inset
16583
16584  about MCS51-variants.
16585 \newline
16586
16587 \end_layout
16588
16589 \begin_layout Standard
16590 While these initialization modules are meant as generic startup code there
16591  might be the need for customization.
16592  Let's assume the return value of 
16593 \emph on
16594 _sdcc_external_startup()
16595 \emph default
16596  in 
16597 \emph on
16598 crtstart.asm
16599 \emph default
16600  should not be checked (or 
16601 \emph on
16602 _sdcc_external_startup()
16603 \emph default
16604  should not be called at all).
16605  The recommended way would be to copy 
16606 \emph on
16607 crtstart.asm
16608 \emph default
16609  (f.e.
16610  from 
16611 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16612
16613 \end_inset
16614
16615 ) into the source directory, adapt it there, then assemble it with 
16616 \emph on
16617 asx8051 -plosgff
16618 \begin_inset Foot
16619 status open
16620
16621 \begin_layout Standard
16622 \begin_inset Quotes sld
16623 \end_inset
16624
16625 -plosgff
16626 \begin_inset Quotes srd
16627 \end_inset
16628
16629  are the assembler options used in 
16630 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16631
16632 \end_inset
16633
16634
16635 \end_layout
16636
16637 \end_inset
16638
16639  crtstart.asm
16640 \emph default
16641  and when linking your project explicitely specify 
16642 \emph on
16643 crtstart.rel
16644 \emph default
16645 .
16646  As a bonus a listing of the relocated object file 
16647 \emph on
16648 crtstart.rst
16649 \emph default
16650  is generated.
16651 \end_layout
16652
16653 \begin_layout Standard
16654 \begin_inset VSpace bigskip
16655 \end_inset
16656
16657
16658 \end_layout
16659
16660 \begin_layout Subsection
16661 HC08 Startup Code
16662 \end_layout
16663
16664 \begin_layout Standard
16665 The HC08
16666 \begin_inset LatexCommand \index{HC08}
16667
16668 \end_inset
16669
16670  startup code follows the same scheme as the MCS51 startup code.
16671 \begin_inset VSpace bigskip
16672 \end_inset
16673
16674
16675 \end_layout
16676
16677 \begin_layout Subsection
16678 Z80 Startup Code
16679 \end_layout
16680
16681 \begin_layout Standard
16682 On the Z80
16683 \begin_inset LatexCommand \index{Z80}
16684
16685 \end_inset
16686
16687  the startup code is inserted by linking with crt0.o which is generated from
16688  sdcc/device/lib/z80/crt0.s.
16689  If you need a different startup code you can use the compiler option 
16690 \emph on
16691 -
16692 \series bold
16693 \emph default
16694
16695 \begin_inset ERT
16696 status collapsed
16697
16698 \begin_layout Standard
16699
16700
16701 \backslash
16702 /
16703 \end_layout
16704
16705 \end_inset
16706
16707
16708 \series default
16709 \emph on
16710 -no-std-crt0
16711 \emph default
16712
16713 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16714
16715 \end_inset
16716
16717  and provide your own crt0.o.
16718  
16719 \begin_inset VSpace bigskip
16720 \end_inset
16721
16722
16723 \end_layout
16724
16725 \begin_layout Section
16726 Inline Assembler Code
16727 \begin_inset LatexCommand \index{Assembler routines}
16728
16729 \end_inset
16730
16731
16732 \end_layout
16733
16734 \begin_layout Subsection
16735 A Step by Step Introduction
16736 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16737
16738 \end_inset
16739
16740
16741 \end_layout
16742
16743 \begin_layout Standard
16744 Starting from a small snippet of c-code this example shows for the MCS51
16745  how to use inline assembly, access variables, a function parameter and
16746  an array in xdata memory.
16747  The example uses an MCS51 here but is easily adapted for other architectures.
16748  This is a buffer routine which should be optimized:
16749 \end_layout
16750
16751 \begin_layout Verse
16752
16753 \family typewriter
16754 \size footnotesize
16755 unsigned char __far
16756 \begin_inset LatexCommand \index{far (storage class)}
16757
16758 \end_inset
16759
16760
16761 \begin_inset LatexCommand \index{\_\_far (storage class)}
16762
16763 \end_inset
16764
16765  __at
16766 \begin_inset LatexCommand \index{at}
16767
16768 \end_inset
16769
16770
16771 \begin_inset LatexCommand \index{\_\_at}
16772
16773 \end_inset
16774
16775 (0x7f00) buf[0x100];
16776 \begin_inset LatexCommand \index{Aligned array}
16777
16778 \end_inset
16779
16780
16781 \newline
16782 unsigned char head, tail;\InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 /* if interrupts
16800 \begin_inset LatexCommand \index{interrupt}
16801
16802 \end_inset
16803
16804  are involved see
16805 \newline
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
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 section 
16852 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16853
16854 \end_inset
16855
16856  about
16857 \series bold
16858  volatile
16859 \series default
16860  */
16861 \newline
16862
16863 \newline
16864 void to_buffer( unsigned char c ) 
16865 \newline
16866 {
16867 \newline
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 if( head != (unsigned char)(tail-1)
16873  )\InsetSpace ~
16874 /* cast 
16875 \series bold
16876 needed
16877 \series default
16878  to avoid promotion
16879 \begin_inset LatexCommand \index{promotion to signed int}
16880
16881 \end_inset
16882
16883
16884 \begin_inset LatexCommand \index{type promotion}
16885
16886 \end_inset
16887
16888  to integer */
16889 \begin_inset Marginal
16890 status collapsed
16891
16892 \begin_layout Standard
16893
16894 \series bold
16895 \InsetSpace ~
16896 !
16897 \end_layout
16898
16899 \end_inset
16900
16901
16902 \newline
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 buf[ head++ ] = c;\InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 /* access to a 256 byte aligned array */
16928 \newline
16929
16930 \end_layout
16931
16932 \begin_layout Standard
16933 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16934  then a corresponding buffer.asm file is generated.
16935  We define a new function 
16936 \family typewriter
16937 to_buffer_asm()
16938 \family default
16939  in file buffer.c in which we cut and paste the generated code, removing
16940  unwanted comments and some ':'.
16941  Then add 
16942 \begin_inset Quotes sld
16943 \end_inset
16944
16945
16946 \series bold
16947 _asm
16948 \series default
16949
16950 \begin_inset Quotes srd
16951 \end_inset
16952
16953  and 
16954 \begin_inset Quotes sld
16955 \end_inset
16956
16957
16958 \series bold
16959 _endasm;
16960 \series default
16961
16962 \begin_inset Quotes srd
16963 \end_inset
16964
16965
16966 \begin_inset Foot
16967 status open
16968
16969 \begin_layout Standard
16970 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16971  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16972  has to be used.
16973  The latter is also used in the library functions.
16974 \end_layout
16975
16976 \end_inset
16977
16978  to the beginning and the end of the function body:
16979 \end_layout
16980
16981 \begin_layout Verse
16982
16983 \family typewriter
16984 \size footnotesize
16985 /* With a cut and paste from the .asm file, we have something to start with.
16986 \newline
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 The
16991  function is not yet OK! (registers aren't saved) */ 
16992 \newline
16993 void to_buffer_asm(
16994  unsigned char c ) 
16995 \newline
16996
16997 \newline
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 _asm
17003 \begin_inset LatexCommand \index{\_asm}
17004
17005 \end_inset
17006
17007
17008 \begin_inset LatexCommand \index{\_\_asm}
17009
17010 \end_inset
17011
17012
17013 \newline
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 mov\InsetSpace ~
17019 \InsetSpace ~
17020 r2,dpl 
17021 \newline
17022 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17023 /* cast 
17024 \series bold
17025 needed
17026 \series default
17027  to avoid promotion
17028 \begin_inset LatexCommand \index{promotion to signed int}
17029
17030 \end_inset
17031
17032
17033 \begin_inset LatexCommand \index{type promotion}
17034
17035 \end_inset
17036
17037  to integer */
17038 \newline
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 mov\InsetSpace ~
17044 \InsetSpace ~
17045 a,_tail 
17046 \newline
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 dec\InsetSpace ~
17052 \InsetSpace ~
17053
17054 \newline
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 mov\InsetSpace ~
17060 \InsetSpace ~
17061 r3,a 
17062 \newline
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 mov\InsetSpace ~
17068 \InsetSpace ~
17069 a,_head 
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 cjne a,ar3,00106$ 
17076 \newline
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 ret
17082 \newline
17083 00106$:
17084  
17085 \newline
17086 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17087 \begin_inset LatexCommand \index{Aligned array}
17088
17089 \end_inset
17090
17091
17092 \newline
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 mov\InsetSpace ~
17098 \InsetSpace ~
17099 r3,_head 
17100 \newline
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 inc\InsetSpace ~
17106 \InsetSpace ~
17107 _head 
17108 \newline
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 mov\InsetSpace ~
17114 \InsetSpace ~
17115 dpl,r3 
17116 \newline
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 mov\InsetSpace ~
17122 \InsetSpace ~
17123 dph,#(_buf >> 8) 
17124 \newline
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 mov\InsetSpace ~
17130 \InsetSpace ~
17131 a,r2 
17132 \newline
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 movx @dptr,a
17138  
17139 \newline
17140 00103$: 
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 ret
17147 \newline
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 _endasm
17153 \begin_inset LatexCommand \index{\_endasm}
17154
17155 \end_inset
17156
17157
17158 \begin_inset LatexCommand \index{\_\_endasm}
17159
17160 \end_inset
17161
17162 ;
17163 \newline
17164
17165 \end_layout
17166
17167 \begin_layout Standard
17168 The new file buffer.c should compile with only one warning about the unreferenced
17169  function argument 'c'.
17170  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17171  (1) and finally have:
17172 \end_layout
17173
17174 \begin_layout Verse
17175
17176 \family typewriter
17177 \size footnotesize
17178 unsigned char __far __at(0x7f00) buf[0x100];
17179 \newline
17180 unsigned char head, tail;
17181 \newline
17182 #define
17183  USE_ASSEMBLY (1)
17184 \newline
17185
17186 \newline
17187 #if !USE_ASSEMBLY
17188 \newline
17189
17190 \newline
17191 void to_buffer( unsigned char c )
17192 \newline
17193 {
17194 \newline
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 if(
17200  head != (unsigned char)(tail-1) )
17201 \newline
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 buf[ head++ ] = c;
17211 \newline
17212 }
17213 \newline
17214
17215 \newline
17216 #else
17217 \newline
17218
17219 \newline
17220 void to_buffer(
17221  unsigned char c )
17222 \newline
17223 {
17224 \newline
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 c; // to avoid warning: unreferenced function argument
17230 \newline
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 _asm
17236 \begin_inset LatexCommand \index{\_asm}
17237
17238 \end_inset
17239
17240
17241 \begin_inset LatexCommand \index{\_\_asm}
17242
17243 \end_inset
17244
17245
17246 \newline
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 ; save used registers here.
17256  
17257 \newline
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 ; If we were still using r2,r3 we would have to push them here.
17267  
17268 \newline
17269 ; if( head != (unsigned char)(tail-1) )
17270 \newline
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 mov\InsetSpace ~
17280  a,_tail
17281 \newline
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 dec\InsetSpace ~
17291  a
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 xrl\InsetSpace ~
17302  a,_head
17303 \newline
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 ; we
17313  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17314 \newline
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 jz\InsetSpace ~
17324 \InsetSpace ~
17325  t_b_end$
17326 \newline
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 ;
17336 \newline
17337 ;
17338  buf[ head++ ] = c;
17339 \newline
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 \InsetSpace ~
17348 mov\InsetSpace ~
17349  a,dpl \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 ; dpl holds lower byte of function argument
17357 \newline
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 mov\InsetSpace ~
17367
17368  dpl,_head \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 ; buf is 0x100 byte aligned so head can be used directly
17372 \newline
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 mov\InsetSpace ~
17382  dph,#(_bu
17383 f>>8)
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 movx @dptr,a
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 inc \InsetSpace ~
17404 _head
17405 \newline
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 ; we could do an ANL _head,#0x0f here to use a
17415  smaller buffer (see above)
17416 \newline
17417 t_b_end$:
17418 \newline
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 ; restore used registers here 
17428 \newline
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 _endasm
17434 \begin_inset LatexCommand \index{\_endasm}
17435
17436 \end_inset
17437
17438
17439 \begin_inset LatexCommand \index{\_\_endasm}
17440
17441 \end_inset
17442
17443 ;
17444 \newline
17445 }
17446 \newline
17447 #endif
17448 \end_layout
17449
17450 \begin_layout Standard
17451 The inline assembler code can contain any valid code understood by the assembler
17452 , this includes any assembler directives and comment lines.
17453  The assembler does not like some characters like ':' or ''' in comments.
17454  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17455 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17456
17457 \end_inset
17458
17459
17460 \begin_inset LatexCommand \index{Assembler documentation}
17461
17462 \end_inset
17463
17464  or online at 
17465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17466
17467 \end_inset
17468
17469 \InsetSpace ~
17470 .
17471 \end_layout
17472
17473 \begin_layout Standard
17474 The compiler does not do any validation of the code within the 
17475 \family typewriter
17476 _asm
17477 \begin_inset LatexCommand \index{\_asm}
17478
17479 \end_inset
17480
17481
17482 \begin_inset LatexCommand \index{\_\_asm}
17483
17484 \end_inset
17485
17486  ...
17487  _endasm
17488 \size footnotesize
17489
17490 \begin_inset LatexCommand \index{\_endasm}
17491
17492 \end_inset
17493
17494
17495 \begin_inset LatexCommand \index{\_\_endasm}
17496
17497 \end_inset
17498
17499
17500 \size default
17501 ;
17502 \family default
17503  keyword pair.
17504  Specifically it will not know which registers are used and thus register
17505  pushing/popping
17506 \begin_inset LatexCommand \index{push/pop}
17507
17508 \end_inset
17509
17510  has to be done manually.
17511  
17512 \end_layout
17513
17514 \begin_layout Standard
17515 It is recommended that each assembly instruction (including labels) be placed
17516  in a separate line (as the example shows).
17517  When the -
17518 \begin_inset ERT
17519 status collapsed
17520
17521 \begin_layout Standard
17522
17523
17524 \backslash
17525 /
17526 \end_layout
17527
17528 \end_inset
17529
17530 -
17531 \emph on
17532 peep-asm
17533 \begin_inset LatexCommand \index{-\/-peep-asm}
17534
17535 \end_inset
17536
17537
17538 \emph default
17539  command line option is used, the inline assembler code will be passed through
17540  the peephole optimizer
17541 \begin_inset LatexCommand \index{Peephole optimizer}
17542
17543 \end_inset
17544
17545 .
17546  There are only a few (if any) cases where this option makes sense, it might
17547  cause some unexpected changes in the inline assembler code.
17548  Please go through the peephole optimizer rules defined in file 
17549 \emph on
17550 SDCCpeeph.def
17551 \emph default
17552  before using this option.
17553 \end_layout
17554
17555 \begin_layout Subsection
17556 Naked Functions
17557 \begin_inset LatexCommand \label{sub:Naked-Functions}
17558
17559 \end_inset
17560
17561
17562 \begin_inset LatexCommand \index{Naked functions}
17563
17564 \end_inset
17565
17566
17567 \end_layout
17568
17569 \begin_layout Standard
17570 A special keyword may be associated with a function declaring it as 
17571 \emph on
17572 _naked
17573 \begin_inset LatexCommand \index{\_naked}
17574
17575 \end_inset
17576
17577
17578 \begin_inset LatexCommand \index{\_\_naked}
17579
17580 \end_inset
17581
17582 .
17583  
17584 \emph default
17585 The 
17586 \emph on
17587 _naked
17588 \emph default
17589  function modifier attribute prevents the compiler from generating prologue
17590 \begin_inset LatexCommand \index{function prologue}
17591
17592 \end_inset
17593
17594  and epilogue
17595 \begin_inset LatexCommand \index{function epilogue}
17596
17597 \end_inset
17598
17599  code for that function.
17600  This means that the user is entirely responsible for such things as saving
17601  any registers that may need to be preserved, selecting the proper register
17602  bank, generating the 
17603 \emph on
17604 return
17605 \emph default
17606  instruction at the end, etc.
17607  Practically, this means that the contents of the function must be written
17608  in inline assembler.
17609  This is particularly useful for interrupt functions, which can have a large
17610  (and often unnecessary) prologue/epilogue.
17611  For example, compare the code generated by these two functions:
17612 \end_layout
17613
17614 \begin_layout Verse
17615
17616 \family typewriter
17617 volatile
17618 \begin_inset LatexCommand \index{volatile}
17619
17620 \end_inset
17621
17622  data unsigned char counter;
17623 \newline
17624
17625 \newline
17626 void simpleInterrupt(void) __interrupt
17627 \begin_inset LatexCommand \index{interrupt}
17628
17629 \end_inset
17630
17631
17632 \begin_inset LatexCommand \index{\_\_interrupt}
17633
17634 \end_inset
17635
17636  (1)
17637 \newline
17638 {
17639 \newline
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 counter++;
17645 \newline
17646 }
17647 \newline
17648
17649 \newline
17650 void nakedInterrupt(void) __interrupt (2) __naked
17651 \newline
17652 {
17653 \newline
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 _asm
17659 \begin_inset LatexCommand \index{\_asm}
17660
17661 \end_inset
17662
17663
17664 \begin_inset LatexCommand \index{\_\_asm}
17665
17666 \end_inset
17667
17668
17669 \newline
17670 \InsetSpace ~
17671 \InsetSpace ~
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 \InsetSpace ~
17676 inc\InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 \InsetSpace ~
17681 _counter ; does not change flags, no need to save psw
17682 \newline
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 reti\InsetSpace ~
17690 \InsetSpace ~
17691 \InsetSpace ~
17692 \InsetSpace ~
17693 ; MUST explicitly
17694  include ret or reti in _naked function.
17695 \newline
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 _endasm
17701 \begin_inset LatexCommand \index{\_endasm}
17702
17703 \end_inset
17704
17705
17706 \begin_inset LatexCommand \index{\_\_endasm}
17707
17708 \end_inset
17709
17710 ;
17711 \newline
17712 }
17713 \end_layout
17714
17715 \begin_layout Standard
17716 For an 8051 target, the generated simpleInterrupt looks like:
17717 \end_layout
17718
17719 \begin_layout Verse
17720
17721 \family typewriter
17722 Note, this is an 
17723 \emph on
17724 outdated
17725 \emph default
17726  example, recent versions of SDCC generate
17727 \newline
17728 the 
17729 \emph on
17730 same
17731 \emph default
17732  code for simpleInterrupt() and nakedInterrupt()!
17733 \newline
17734
17735 \newline
17736 _simpleInterrupt:
17737 \newline
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 push\InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 acc
17747 \newline
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 push\InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 b
17757 \newline
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 pu
17763 sh\InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 dpl
17768 \newline
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 push\InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 dph
17778 \newline
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 \InsetSpace ~
17783 push\InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 psw
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 mov\InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 \InsetSpace ~
17798 psw,#0x00
17799 \newline
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 inc\InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 _counter
17810 \newline
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 \InsetSpace ~
17815 pop\InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 psw
17821 \newline
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 pop\InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 dph
17832 \newline
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 pop\InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 dpl
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 pop\InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 b
17854 \newline
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 pop\InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 acc
17865 \newline
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 reti
17871 \end_layout
17872
17873 \begin_layout Standard
17874 whereas nakedInterrupt looks like:
17875 \end_layout
17876
17877 \begin_layout Verse
17878
17879 \family typewriter
17880 _nakedInterrupt:
17881 \newline
17882 \InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 inc\InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 _counter ; does not change flags, no need to save psw
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 reti\InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 ;
17909  MUST explicitly include ret or reti in _naked function
17910 \end_layout
17911
17912 \begin_layout Standard
17913 The related directive #pragma exclude
17914 \begin_inset LatexCommand \index{\#pragma exclude}
17915
17916 \end_inset
17917
17918  allows a more fine grained control over pushing & popping
17919 \begin_inset LatexCommand \index{push/pop}
17920
17921 \end_inset
17922
17923  the registers.
17924 \end_layout
17925
17926 \begin_layout Standard
17927 While there is nothing preventing you from writing C code inside a 
17928 \family typewriter
17929 _naked
17930 \family default
17931  function, there are many ways to shoot yourself in the foot doing this,
17932  and it is recommended that you stick to inline assembler.
17933 \end_layout
17934
17935 \begin_layout Subsection
17936 Use of Labels within Inline Assembler
17937 \end_layout
17938
17939 \begin_layout Standard
17940 SDCC allows the use of in-line assembler with a few restrictions regarding
17941  labels.
17942  All labels defined within inline assembler code have to be of the form
17943  
17944 \emph on
17945 nnnnn$
17946 \emph default
17947  where nnnnn is a number less than 100 (which implies a limit of utmost
17948  100 inline assembler labels 
17949 \emph on
17950 per function
17951 \emph default
17952 \noun on
17953 )
17954 \noun default
17955 .
17956 \begin_inset Foot
17957 status open
17958
17959 \begin_layout Standard
17960 This is a slightly more stringent rule than absolutely necessary, but stays
17961  always on the safe side.
17962  Labels in the form of nnnnn$ are local labels in the assembler, locality
17963  of which is confined within two labels of the standard form.
17964  The compiler uses the same form for labels within a function (but starting
17965  from nnnnn=00100); and places always a standard label at the beginning
17966  of a function, thus limiting the locality of labels within the scope of
17967  the function.
17968  So, if the inline assembler part would be embedded into C-code, an improperly
17969  placed non-local label in the assembler would break up the reference space
17970  for labels created by the compiler for the C-code, leading to an assembling
17971  error.
17972 \end_layout
17973
17974 \begin_layout Standard
17975 The numeric part of local labels does not need to have 5 digits (although
17976  this is the form of labels output by the compiler), any valid integer will
17977  do.
17978  Please refer to the assemblers documentation for further details.
17979 \end_layout
17980
17981 \end_inset
17982
17983  
17984 \end_layout
17985
17986 \begin_layout Verse
17987
17988 \family typewriter
17989 _asm
17990 \begin_inset LatexCommand \index{\_asm}
17991
17992 \end_inset
17993
17994
17995 \begin_inset LatexCommand \index{\_\_asm}
17996
17997 \end_inset
17998
17999  
18000 \newline
18001 \InsetSpace ~
18002 \InsetSpace ~
18003 \InsetSpace ~
18004 \InsetSpace ~
18005 mov\InsetSpace ~
18006 \InsetSpace ~
18007 \InsetSpace ~
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 b,#10 
18011 \newline
18012 00001$: 
18013 \newline
18014 \InsetSpace ~
18015 \InsetSpace ~
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 djnz\InsetSpace ~
18019 \InsetSpace ~
18020 \InsetSpace ~
18021 \InsetSpace ~
18022 b,00001$ 
18023 \newline
18024 _endasm
18025 \begin_inset LatexCommand \index{\_endasm}
18026
18027 \end_inset
18028
18029
18030 \begin_inset LatexCommand \index{\_\_endasm}
18031
18032 \end_inset
18033
18034  ;
18035 \end_layout
18036
18037 \begin_layout Standard
18038 Inline assembler code cannot reference any C-labels, however it can reference
18039  labels
18040 \begin_inset LatexCommand \index{Labels}
18041
18042 \end_inset
18043
18044  defined by the inline assembler, e.g.:
18045 \end_layout
18046
18047 \begin_layout Verse
18048
18049 \family typewriter
18050 foo() { 
18051 \newline
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 \InsetSpace ~
18055 \InsetSpace ~
18056 /* some c code */ 
18057 \newline
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 _asm 
18063 \newline
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 ; some assembler code 
18071 \newline
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 ljmp 0003$ 
18079 \newline
18080 \InsetSpace ~
18081 \InsetSpace ~
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 _endasm;
18085  
18086 \newline
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 \InsetSpace ~
18090 \InsetSpace ~
18091 /* some more c code */ 
18092 \newline
18093 clabel:\InsetSpace ~
18094 \InsetSpace ~
18095 /* inline assembler cannot reference this
18096  label */ 
18097 \begin_inset Foot
18098 status open
18099
18100 \begin_layout Standard
18101 Here, the C-label 
18102 \family typewriter
18103 clabel
18104 \family default
18105  is translated by the compiler into a local label, so the locality of labels
18106  within the function is not broken.
18107 \end_layout
18108
18109 \end_inset
18110
18111
18112 \newline
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 _asm
18118 \newline
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 0003$: ;label (can be referenced by inline assembler only) 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 _endasm
18130 \begin_inset LatexCommand \index{\_endasm}
18131
18132 \end_inset
18133
18134
18135 \begin_inset LatexCommand \index{\_\_endasm}
18136
18137 \end_inset
18138
18139  ; 
18140 \newline
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 \InsetSpace ~
18145 /* some more c code */
18146 \newline
18147 }
18148 \end_layout
18149
18150 \begin_layout Standard
18151 In other words inline assembly code can access labels defined in inline
18152  assembly within the scope of the function.
18153  The same goes the other way, i.e.
18154  labels defines in inline assembly can not be accessed by C statements.
18155 \end_layout
18156
18157 \begin_layout Section
18158 Interfacing with Assembler Code
18159 \begin_inset LatexCommand \index{Assembler routines}
18160
18161 \end_inset
18162
18163
18164 \end_layout
18165
18166 \begin_layout Subsection
18167 Global Registers used for Parameter Passing
18168 \begin_inset LatexCommand \index{Parameter passing}
18169
18170 \end_inset
18171
18172
18173 \end_layout
18174
18175 \begin_layout Standard
18176 The compiler always uses the global registers 
18177 \emph on
18178 DPL, DPH
18179 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18180
18181 \end_inset
18182
18183
18184 \begin_inset LatexCommand \index{DPTR}
18185
18186 \end_inset
18187
18188 , B
18189 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18190
18191 \end_inset
18192
18193  
18194 \emph default
18195 and
18196 \emph on
18197  ACC
18198 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18199
18200 \end_inset
18201
18202
18203 \emph default
18204  to pass the first (non-bit) parameter to a function, and also to pass the
18205  return value 
18206 \begin_inset LatexCommand \index{return value}
18207
18208 \end_inset
18209
18210 of function; according to the following scheme: one byte return value in
18211  
18212 \emph on
18213 DPL
18214 \emph default
18215 , two byte value in 
18216 \emph on
18217 DPL
18218 \emph default
18219  (LSB) and 
18220 \emph on
18221 DPH
18222 \emph default
18223  (MSB).
18224  three byte values (generic pointers) in 
18225 \emph on
18226 DPH
18227 \emph default
18228
18229 \emph on
18230 DPL
18231 \emph default
18232  and 
18233 \emph on
18234 B
18235 \emph default
18236 , and four byte values in 
18237 \emph on
18238 DPH
18239 \emph default
18240
18241 \emph on
18242 DPL
18243 \emph default
18244 ,
18245 \emph on
18246  B
18247 \emph default
18248  and 
18249 \emph on
18250 ACC
18251 \emph default
18252 .
18253  Generic pointers
18254 \begin_inset LatexCommand \index{generic pointer}
18255
18256 \end_inset
18257
18258  contain type of accessed memory in 
18259 \emph on
18260 B
18261 \emph default
18262
18263 \series bold
18264 0x00
18265 \series default
18266  -- xdata/far, 
18267 \series bold
18268 0x40
18269 \series default
18270  -- idata/near -- , 
18271 \series bold
18272 0x60
18273 \series default
18274  -- pdata, 
18275 \series bold
18276 0x80
18277 \series default
18278  -- code
18279 \begin_inset Note Note
18280 status collapsed
18281
18282 \begin_layout Standard
18283 This might not be the case of certain memory models (medium???)
18284 \end_layout
18285
18286 \end_inset
18287
18288 .
18289 \end_layout
18290
18291 \begin_layout Standard
18292 The second parameter onwards is either allocated on the stack (for reentrant
18293  routines or if -
18294 \begin_inset ERT
18295 status collapsed
18296
18297 \begin_layout Standard
18298
18299
18300 \backslash
18301 /
18302 \end_layout
18303
18304 \end_inset
18305
18306 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18307 \end_layout
18308
18309 \begin_layout Standard
18310 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18311  space for reentrant functions or allocated directly in bit memory otherwise.
18312 \end_layout
18313
18314 \begin_layout Standard
18315 Functions (with two or more parameters or bit parameters) that are called
18316  through function pointers
18317 \begin_inset LatexCommand \index{function pointers}
18318
18319 \end_inset
18320
18321  must therefor be reentrant so the compiler knows how to pass the parameters.
18322 \end_layout
18323
18324 \begin_layout Subsection
18325 Registers usage
18326 \end_layout
18327
18328 \begin_layout Standard
18329 Unless the called function is declared as 
18330 \family typewriter
18331 _naked
18332 \family default
18333
18334 \begin_inset LatexCommand \index{naked}
18335
18336 \end_inset
18337
18338 , or the -
18339 \begin_inset ERT
18340 status collapsed
18341
18342 \begin_layout Standard
18343
18344
18345 \backslash
18346 /
18347 \end_layout
18348
18349 \end_inset
18350
18351 -callee-saves
18352 \begin_inset LatexCommand \index{-\/-callee-saves}
18353
18354 \end_inset
18355
18356 /-
18357 \begin_inset ERT
18358 status collapsed
18359
18360 \begin_layout Standard
18361
18362
18363 \backslash
18364 /
18365 \end_layout
18366
18367 \end_inset
18368
18369 -all-callee-saves command line option or the corresponding callee_saves
18370  pragma are used, the caller will save the registers (
18371 \emph on
18372 R0-R7
18373 \emph default
18374 ) around the call, so the called function can destroy they content freely.
18375 \end_layout
18376
18377 \begin_layout Standard
18378 If the called function is not declared as 
18379 \family typewriter
18380 _naked
18381 \family default
18382 , the caller will swap register banks around the call, if caller and callee
18383  use different register banks (having them defined by the 
18384 \family typewriter
18385 _using
18386 \family default
18387  modifier).
18388  
18389 \end_layout
18390
18391 \begin_layout Standard
18392 The called function can also use 
18393 \emph on
18394 DPL
18395 \emph default
18396
18397 \emph on
18398 DPH
18399 \emph default
18400
18401 \emph on
18402 B
18403 \emph default
18404  and 
18405 \emph on
18406 ACC
18407 \emph default
18408  observing that they are used for parameter/return value passing.
18409 \end_layout
18410
18411 \begin_layout Subsection
18412 Assembler Routine (non-reentrant)
18413 \end_layout
18414
18415 \begin_layout Standard
18416 In the following example
18417 \begin_inset LatexCommand \index{reentrant}
18418
18419 \end_inset
18420
18421
18422 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18423
18424 \end_inset
18425
18426  the function c_func calls an assembler routine asm_func, which takes two
18427  parameters
18428 \begin_inset LatexCommand \index{function parameter}
18429
18430 \end_inset
18431
18432 .
18433 \end_layout
18434
18435 \begin_layout Verse
18436
18437 \family typewriter
18438 extern int asm_func(unsigned char, unsigned char);
18439 \newline
18440
18441 \newline
18442 int c_func (unsigned char
18443  i, unsigned char j)
18444 \newline
18445 {
18446 \newline
18447 \InsetSpace ~
18448 \InsetSpace ~
18449 \InsetSpace ~
18450 \InsetSpace ~
18451 return asm_func(i,j);
18452 \newline
18453 }
18454 \newline
18455
18456 \newline
18457 int main()
18458 \newline
18459 {
18460 \newline
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 \InsetSpace ~
18465 return c_func(10,9);
18466 \newline
18467 }
18468 \end_layout
18469
18470 \begin_layout Standard
18471 The corresponding assembler function is:
18472 \end_layout
18473
18474 \begin_layout Verse
18475
18476 \family typewriter
18477 .globl _asm_func_PARM_2 
18478 \newline
18479 \InsetSpace ~
18480 \InsetSpace ~
18481 \InsetSpace ~
18482 \InsetSpace ~
18483 \InsetSpace ~
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 .globl _asm_func 
18488 \newline
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 \InsetSpace ~
18497 .area OSEG 
18498 \newline
18499 _asm_func_PARM_2:
18500 \newline
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 \InsetSpace ~
18509 .ds   
18510  1 
18511 \newline
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 .area CSEG 
18521 \newline
18522 _asm_func: 
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 mov\InsetSpace ~
18533 \InsetSpace ~
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 a,dpl 
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 \InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 add\InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 a,_asm_func_PARM_2 
18551 \newline
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 mov\InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 dpl,a 
18565 \newline
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 mov\InsetSpace ~
18575 \InsetSpace ~
18576 \InsetSpace ~
18577 \InsetSpace ~
18578 dph
18579 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18580
18581 \end_inset
18582
18583 ,#0x00 
18584 \newline
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 \InsetSpace ~
18592 \InsetSpace ~
18593 ret
18594 \end_layout
18595
18596 \begin_layout Standard
18597 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18598  the parameter number starting from 1, and counting from the left.
18599  The first parameter is passed in 
18600 \emph on
18601 DPH
18602 \emph default
18603
18604 \emph on
18605 DPL
18606 \emph default
18607
18608 \emph on
18609 B
18610 \emph default
18611  and 
18612 \emph on
18613 ACC
18614 \emph default
18615  according to the description above.
18616  The variable name for the second parameter will be _<function_name>_PARM_2.
18617 \newline
18618
18619 \newline
18620 Assem
18621 ble the assembler routine with the following command:
18622 \newline
18623
18624 \newline
18625
18626 \family sans
18627 \series bold
18628 asx8051 -losg asmfunc.asm
18629 \newline
18630
18631 \newline
18632
18633 \family default
18634 \series default
18635 Then compile and link the assembler routine to the C source file with the
18636  following command:
18637 \newline
18638
18639 \newline
18640
18641 \family sans
18642 \series bold
18643 sdcc cfunc.c asmfunc.rel
18644 \end_layout
18645
18646 \begin_layout Subsection
18647 Assembler Routine (reentrant)
18648 \end_layout
18649
18650 \begin_layout Standard
18651 In this case
18652 \begin_inset LatexCommand \index{reentrant}
18653
18654 \end_inset
18655
18656
18657 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18658
18659 \end_inset
18660
18661  the second parameter
18662 \begin_inset LatexCommand \index{function parameter}
18663
18664 \end_inset
18665
18666  onwards will be passed on the stack, the parameters are pushed from right
18667  to left i.e.
18668  before the call the second leftmost parameter will be on the top of the
18669  stack (the leftmost parameter is passed in registers).
18670  Here is an example:
18671 \end_layout
18672
18673 \begin_layout Verse
18674
18675 \family typewriter
18676 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18677 \newline
18678
18679 \newline
18680 int
18681  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18682 \newline
18683 {
18684  
18685 \newline
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 \InsetSpace ~
18690 return asm_func(i,j,k); 
18691 \newline
18692
18693 \newline
18694
18695 \newline
18696 int main() 
18697 \newline
18698
18699 \newline
18700 \InsetSpace ~
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 return c_func(10,9,8); 
18705 \newline
18706 }
18707 \end_layout
18708
18709 \begin_layout Standard
18710 The corresponding (unoptimized) assembler routine is:
18711 \end_layout
18712
18713 \begin_layout Verse
18714
18715 \family typewriter
18716 .globl _asm_func 
18717 \newline
18718 _asm_func: 
18719 \newline
18720 \InsetSpace ~
18721 \InsetSpace ~
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 push\InsetSpace ~
18725 _bp 
18726 \newline
18727 \InsetSpace ~
18728 \InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 mov\InsetSpace ~
18732 \InsetSpace ~
18733 _bp,sp\InsetSpace ~
18734 \InsetSpace ~
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 ;stack contains: _bp, return
18740  address, second parameter, third parameter
18741 \newline
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 mov\InsetSpace ~
18747 \InsetSpace ~
18748 r2,dpl
18749 \newline
18750 \InsetSpace ~
18751 \InsetSpace ~
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 mov\InsetSpace ~
18755 \InsetSpace ~
18756 a,_bp
18757 \newline
18758 \InsetSpace ~
18759 \InsetSpace ~
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 add\InsetSpace ~
18763 \InsetSpace ~
18764 a,#0xfd\InsetSpace ~
18765 \InsetSpace ~
18766 \InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 ;calculate
18770  pointer to the second parameter
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 mov\InsetSpace ~
18777 \InsetSpace ~
18778 r0,a 
18779 \newline
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 mov\InsetSpace ~
18785 \InsetSpace ~
18786 a,_bp 
18787 \newline
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 add\InsetSpace ~
18793 \InsetSpace ~
18794 a,#0xfc\InsetSpace ~
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 ;calculate pointer
18800  to the rightmost parameter
18801 \newline
18802 \InsetSpace ~
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 mov\InsetSpace ~
18807 \InsetSpace ~
18808 r1,a 
18809 \newline
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 mov\InsetSpace ~
18815 \InsetSpace ~
18816 a,@r0
18817 \newline
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 add\InsetSpace ~
18823 \InsetSpace ~
18824 a,@r1
18825 \newline
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 add\InsetSpace ~
18831 \InsetSpace ~
18832 a,r2\InsetSpace ~
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 \InsetSpace ~
18836 \InsetSpace ~
18837 \InsetSpace ~
18838 \InsetSpace ~
18839 \InsetSpace ~
18840 ;calculate the
18841  result (= sum of all three parameters)
18842 \newline
18843 \InsetSpace ~
18844 \InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 mov\InsetSpace ~
18848 \InsetSpace ~
18849 dpl,a\InsetSpace ~
18850 \InsetSpace ~
18851 \InsetSpace ~
18852 \InsetSpace ~
18853 \InsetSpace ~
18854 \InsetSpace ~
18855 \InsetSpace ~
18856 ;return value goes into dptr
18857  (cast into int)
18858 \newline
18859 \InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 mov\InsetSpace ~
18864 \InsetSpace ~
18865 dph,#0x00 
18866 \newline
18867 \InsetSpace ~
18868 \InsetSpace ~
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 mov\InsetSpace ~
18872 \InsetSpace ~
18873 sp,_bp 
18874 \newline
18875 \InsetSpace ~
18876 \InsetSpace ~
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 pop\InsetSpace ~
18880 \InsetSpace ~
18881 _bp 
18882 \newline
18883 \InsetSpace ~
18884 \InsetSpace ~
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 ret
18888 \end_layout
18889
18890 \begin_layout Standard
18891 The compiling and linking procedure remains the same, however note the extra
18892  entry & exit linkage required for the assembler code, _bp is the stack
18893  frame pointer and is used to compute the offset into the stack for parameters
18894  and local variables.
18895 \begin_inset VSpace bigskip
18896 \end_inset
18897
18898
18899 \end_layout
18900
18901 \begin_layout Section
18902 int (16 bit)
18903 \begin_inset LatexCommand \index{int (16 bit)}
18904
18905 \end_inset
18906
18907  and long (32 bit)
18908 \begin_inset LatexCommand \index{long (32 bit)}
18909
18910 \end_inset
18911
18912  Support
18913 \end_layout
18914
18915 \begin_layout Standard
18916 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18917  multiplication and modulus operations are implemented by support routines.
18918  These support routines are all developed in ANSI-C to facilitate porting
18919  to other MCUs, although some model specific assembler optimizations are
18920  used.
18921  The following files contain the described routines, all of them can be
18922  found in <installdir>/share/sdcc/lib.
18923 \newline
18924
18925 \end_layout
18926
18927 \begin_layout Standard
18928 \align center
18929 \begin_inset Tabular
18930 <lyxtabular version="3" rows="11" columns="2">
18931 <features>
18932 <column alignment="left" valignment="top" leftline="true" width="0">
18933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18934 <row topline="true" bottomline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18936 \begin_inset Text
18937
18938 \begin_layout Standard
18939
18940 \series bold
18941 Function
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18947 \begin_inset Text
18948
18949 \begin_layout Standard
18950
18951 \series bold
18952 Description
18953 \end_layout
18954
18955 \end_inset
18956 </cell>
18957 </row>
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_inset Text
18961
18962 \begin_layout Standard
18963 _mulint.c 
18964 \end_layout
18965
18966 \end_inset
18967 </cell>
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18969 \begin_inset Text
18970
18971 \begin_layout Standard
18972 16 bit multiplication
18973 \end_layout
18974
18975 \end_inset
18976 </cell>
18977 </row>
18978 <row topline="true">
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_inset Text
18981
18982 \begin_layout Standard
18983 _divsint.c 
18984 \end_layout
18985
18986 \end_inset
18987 </cell>
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18989 \begin_inset Text
18990
18991 \begin_layout Standard
18992  signed 16 bit division (calls _divuint)
18993 \end_layout
18994
18995 \end_inset
18996 </cell>
18997 </row>
18998 <row topline="true">
18999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19000 \begin_inset Text
19001
19002 \begin_layout Standard
19003 _divuint.c 
19004 \end_layout
19005
19006 \end_inset
19007 </cell>
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19009 \begin_inset Text
19010
19011 \begin_layout Standard
19012  unsigned 16 bit division
19013 \end_layout
19014
19015 \end_inset
19016 </cell>
19017 </row>
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \begin_layout Standard
19023 _modsint.c
19024 \end_layout
19025
19026 \end_inset
19027 </cell>
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19029 \begin_inset Text
19030
19031 \begin_layout Standard
19032 signed 16 bit modulus (calls _moduint)
19033 \end_layout
19034
19035 \end_inset
19036 </cell>
19037 </row>
19038 <row topline="true">
19039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19040 \begin_inset Text
19041
19042 \begin_layout Standard
19043 _moduint.c
19044 \end_layout
19045
19046 \end_inset
19047 </cell>
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \begin_layout Standard
19052 unsigned 16 bit modulus
19053 \end_layout
19054
19055 \end_inset
19056 </cell>
19057 </row>
19058 <row topline="true">
19059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19060 \begin_inset Text
19061
19062 \begin_layout Standard
19063 _mullong.c
19064 \end_layout
19065
19066 \end_inset
19067 </cell>
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \begin_layout Standard
19072 32 bit multiplication
19073 \end_layout
19074
19075 \end_inset
19076 </cell>
19077 </row>
19078 <row topline="true">
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19080 \begin_inset Text
19081
19082 \begin_layout Standard
19083 _divslong.c 
19084 \end_layout
19085
19086 \end_inset
19087 </cell>
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \begin_layout Standard
19092  signed 32 division (calls _divulong)
19093 \end_layout
19094
19095 \end_inset
19096 </cell>
19097 </row>
19098 <row topline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \begin_layout Standard
19103 _divulong.c 
19104 \end_layout
19105
19106 \end_inset
19107 </cell>
19108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19109 \begin_inset Text
19110
19111 \begin_layout Standard
19112 unsigned 32 division
19113 \end_layout
19114
19115 \end_inset
19116 </cell>
19117 </row>
19118 <row topline="true">
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19120 \begin_inset Text
19121
19122 \begin_layout Standard
19123 _modslong.c
19124 \end_layout
19125
19126 \end_inset
19127 </cell>
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19129 \begin_inset Text
19130
19131 \begin_layout Standard
19132  signed 32 bit modulus (calls _modulong)
19133 \end_layout
19134
19135 \end_inset
19136 </cell>
19137 </row>
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \begin_layout Standard
19143 _modulong.c
19144 \end_layout
19145
19146 \end_inset
19147 </cell>
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19149 \begin_inset Text
19150
19151 \begin_layout Standard
19152 unsigned 32 bit modulus
19153 \end_layout
19154
19155 \end_inset
19156 </cell>
19157 </row>
19158 </lyxtabular>
19159
19160 \end_inset
19161
19162
19163 \newline
19164
19165 \end_layout
19166
19167 \begin_layout Standard
19168 Since they are compiled as 
19169 \emph on
19170 non-reentrant
19171 \emph default
19172
19173 \begin_inset LatexCommand \index{reentrant}
19174
19175 \end_inset
19176
19177 , interrupt
19178 \begin_inset LatexCommand \index{interrupt}
19179
19180 \end_inset
19181
19182  service routines should not do any of the above operations.
19183  If this is unavoidable then the above routines will need to be compiled
19184  with the 
19185 \emph on
19186 -
19187 \begin_inset ERT
19188 status collapsed
19189
19190 \begin_layout Standard
19191
19192
19193 \backslash
19194 /
19195 \end_layout
19196
19197 \end_inset
19198
19199 -stack-auto
19200 \begin_inset LatexCommand \index{-\/-stack-auto}
19201
19202 \end_inset
19203
19204
19205 \emph default
19206  option, after which the source program will have to be compiled with 
19207 \emph on
19208 -
19209 \begin_inset ERT
19210 status collapsed
19211
19212 \begin_layout Standard
19213
19214
19215 \backslash
19216 /
19217 \end_layout
19218
19219 \end_inset
19220
19221 -int-long-reent
19222 \begin_inset LatexCommand \index{-\/-int-long-reent}
19223
19224 \end_inset
19225
19226
19227 \emph default
19228  option.
19229  Notice that you don't have to call these routines directly.
19230  The compiler will use them automatically every time an integer operation
19231  is required.
19232 \end_layout
19233
19234 \begin_layout Section
19235 Floating Point Support
19236 \begin_inset LatexCommand \index{Floating point support}
19237
19238 \end_inset
19239
19240
19241 \end_layout
19242
19243 \begin_layout Standard
19244 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19245  The floating point support routines are derived from gcc's floatlib.c and
19246  consist of the following routines:
19247 \newline
19248
19249 \end_layout
19250
19251 \begin_layout Standard
19252 \align center
19253
19254 \size footnotesize
19255 \begin_inset Tabular
19256 <lyxtabular version="3" rows="17" columns="2">
19257 <features>
19258 <column alignment="left" valignment="top" leftline="true" width="0">
19259 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19260 <row topline="true" bottomline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \begin_layout Standard
19265
19266 \family roman
19267 \series medium
19268 \shape up
19269 \size normal
19270 \emph off
19271 \bar no
19272 \noun off
19273 \color none
19274 Function 
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283 Description
19284 \end_layout
19285
19286 \end_inset
19287 </cell>
19288 </row>
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294
19295 \family roman
19296 \series medium
19297 \shape up
19298 \size normal
19299 \emph off
19300 \bar no
19301 \noun off
19302 \color none
19303 _fsadd.c
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \begin_layout Standard
19312
19313 \family roman
19314 \series medium
19315 \shape up
19316 \size normal
19317 \emph off
19318 \bar no
19319 \noun off
19320 \color none
19321 add floating point numbers
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 </row>
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332
19333 \family roman
19334 \series medium
19335 \shape up
19336 \size normal
19337 \emph off
19338 \bar no
19339 \noun off
19340 \color none
19341 _fssub.c 
19342 \end_layout
19343
19344 \end_inset
19345 </cell>
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19347 \begin_inset Text
19348
19349 \begin_layout Standard
19350
19351 \family roman
19352 \series medium
19353 \shape up
19354 \size normal
19355 \emph off
19356 \bar no
19357 \noun off
19358 \color none
19359 subtract floating point numbers 
19360 \end_layout
19361
19362 \end_inset
19363 </cell>
19364 </row>
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19367 \begin_inset Text
19368
19369 \begin_layout Standard
19370
19371 \family roman
19372 \series medium
19373 \shape up
19374 \size normal
19375 \emph off
19376 \bar no
19377 \noun off
19378 \color none
19379 _fsdiv.c 
19380 \end_layout
19381
19382 \end_inset
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \begin_layout Standard
19388
19389 \family roman
19390 \series medium
19391 \shape up
19392 \size normal
19393 \emph off
19394 \bar no
19395 \noun off
19396 \color none
19397 divide floating point numbers 
19398 \end_layout
19399
19400 \end_inset
19401 </cell>
19402 </row>
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19405 \begin_inset Text
19406
19407 \begin_layout Standard
19408
19409 \family roman
19410 \series medium
19411 \shape up
19412 \size normal
19413 \emph off
19414 \bar no
19415 \noun off
19416 \color none
19417 _fsmul.c 
19418 \end_layout
19419
19420 \end_inset
19421 </cell>
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19423 \begin_inset Text
19424
19425 \begin_layout Standard
19426
19427 \family roman
19428 \series medium
19429 \shape up
19430 \size normal
19431 \emph off
19432 \bar no
19433 \noun off
19434 \color none
19435 multiply floating point numbers 
19436 \end_layout
19437
19438 \end_inset
19439 </cell>
19440 </row>
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19443 \begin_inset Text
19444
19445 \begin_layout Standard
19446
19447 \family roman
19448 \series medium
19449 \shape up
19450 \size normal
19451 \emph off
19452 \bar no
19453 \noun off
19454 \color none
19455 _fs2uchar.c
19456 \end_layout
19457
19458 \end_inset
19459 </cell>
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19461 \begin_inset Text
19462
19463 \begin_layout Standard
19464
19465 \family roman
19466 \series medium
19467 \shape up
19468 \size normal
19469 \emph off
19470 \bar no
19471 \noun off
19472 \color none
19473 convert floating point to unsigned char
19474 \end_layout
19475
19476 \end_inset
19477 </cell>
19478 </row>
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \begin_layout Standard
19484
19485 \family roman
19486 \series medium
19487 \shape up
19488 \size normal
19489 \emph off
19490 \bar no
19491 \noun off
19492 \color none
19493 _fs2char.c
19494 \end_layout
19495
19496 \end_inset
19497 </cell>
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19499 \begin_inset Text
19500
19501 \begin_layout Standard
19502
19503 \family roman
19504 \series medium
19505 \shape up
19506 \size normal
19507 \emph off
19508 \bar no
19509 \noun off
19510 \color none
19511 convert floating point to signed char
19512 \end_layout
19513
19514 \end_inset
19515 </cell>
19516 </row>
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \begin_layout Standard
19522
19523 \family roman
19524 \series medium
19525 \shape up
19526 \size normal
19527 \emph off
19528 \bar no
19529 \noun off
19530 \color none
19531 _fs2uint.c
19532 \end_layout
19533
19534 \end_inset
19535 </cell>
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_inset Text
19538
19539 \begin_layout Standard
19540
19541 \family roman
19542 \series medium
19543 \shape up
19544 \size normal
19545 \emph off
19546 \bar no
19547 \noun off
19548 \color none
19549 convert floating point to unsigned int
19550 \end_layout
19551
19552 \end_inset
19553 </cell>
19554 </row>
19555 <row topline="true">
19556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19557 \begin_inset Text
19558
19559 \begin_layout Standard
19560
19561 \family roman
19562 \series medium
19563 \shape up
19564 \size normal
19565 \emph off
19566 \bar no
19567 \noun off
19568 \color none
19569 _fs2int.c
19570 \end_layout
19571
19572 \end_inset
19573 </cell>
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19575 \begin_inset Text
19576
19577 \begin_layout Standard
19578
19579 \family roman
19580 \series medium
19581 \shape up
19582 \size normal
19583 \emph off
19584 \bar no
19585 \noun off
19586 \color none
19587 convert floating point to signed int
19588 \end_layout
19589
19590 \end_inset
19591 </cell>
19592 </row>
19593 <row topline="true">
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19595 \begin_inset Text
19596
19597 \begin_layout Standard
19598
19599 \family roman
19600 \series medium
19601 \shape up
19602 \size normal
19603 \emph off
19604 \bar no
19605 \noun off
19606 \color none
19607 _fs2ulong.
19608 \family default
19609 \series default
19610 \shape default
19611 \size default
19612 \emph default
19613 \bar default
19614 \noun default
19615 c
19616 \end_layout
19617
19618 \end_inset
19619 </cell>
19620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19621 \begin_inset Text
19622
19623 \begin_layout Standard
19624
19625 \family roman
19626 \series medium
19627 \shape up
19628 \size normal
19629 \emph off
19630 \bar no
19631 \noun off
19632 \color none
19633 convert floating point to unsigned long
19634 \end_layout
19635
19636 \end_inset
19637 </cell>
19638 </row>
19639 <row topline="true">
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19641 \begin_inset Text
19642
19643 \begin_layout Standard
19644
19645 \family roman
19646 \series medium
19647 \shape up
19648 \size normal
19649 \emph off
19650 \bar no
19651 \noun off
19652 \color none
19653 _fs2long.c
19654 \end_layout
19655
19656 \end_inset
19657 </cell>
19658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19659 \begin_inset Text
19660
19661 \begin_layout Standard
19662
19663 \family roman
19664 \series medium
19665 \shape up
19666 \size normal
19667 \emph off
19668 \bar no
19669 \noun off
19670 \color none
19671 convert floating point to signed long
19672 \end_layout
19673
19674 \end_inset
19675 </cell>
19676 </row>
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \begin_layout Standard
19682
19683 \family roman
19684 \series medium
19685 \shape up
19686 \size normal
19687 \emph off
19688 \bar no
19689 \noun off
19690 \color none
19691 _uchar2fs.c
19692 \end_layout
19693
19694 \end_inset
19695 </cell>
19696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19697 \begin_inset Text
19698
19699 \begin_layout Standard
19700
19701 \family roman
19702 \series medium
19703 \shape up
19704 \size normal
19705 \emph off
19706 \bar no
19707 \noun off
19708 \color none
19709 convert unsigned char to floating point
19710 \end_layout
19711
19712 \end_inset
19713 </cell>
19714 </row>
19715 <row topline="true">
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19717 \begin_inset Text
19718
19719 \begin_layout Standard
19720
19721 \family roman
19722 \series medium
19723 \shape up
19724 \size normal
19725 \emph off
19726 \bar no
19727 \noun off
19728 \color none
19729 _char2fs.c
19730 \end_layout
19731
19732 \end_inset
19733 </cell>
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19735 \begin_inset Text
19736
19737 \begin_layout Standard
19738
19739 \family roman
19740 \series medium
19741 \shape up
19742 \size normal
19743 \emph off
19744 \bar no
19745 \noun off
19746 \color none
19747 convert char to floating point number
19748 \end_layout
19749
19750 \end_inset
19751 </cell>
19752 </row>
19753 <row topline="true">
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \begin_layout Standard
19758
19759 \family roman
19760 \series medium
19761 \shape up
19762 \size normal
19763 \emph off
19764 \bar no
19765 \noun off
19766 \color none
19767 _uint2fs.c
19768 \end_layout
19769
19770 \end_inset
19771 </cell>
19772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19773 \begin_inset Text
19774
19775 \begin_layout Standard
19776
19777 \family roman
19778 \series medium
19779 \shape up
19780 \size normal
19781 \emph off
19782 \bar no
19783 \noun off
19784 \color none
19785 convert unsigned int to floating point
19786 \end_layout
19787
19788 \end_inset
19789 </cell>
19790 </row>
19791 <row topline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19793 \begin_inset Text
19794
19795 \begin_layout Standard
19796
19797 \family roman
19798 \series medium
19799 \shape up
19800 \size normal
19801 \emph off
19802 \bar no
19803 \noun off
19804 \color none
19805 _int2fs.c
19806 \end_layout
19807
19808 \end_inset
19809 </cell>
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19811 \begin_inset Text
19812
19813 \begin_layout Standard
19814
19815 \family roman
19816 \series medium
19817 \shape up
19818 \size normal
19819 \emph off
19820 \bar no
19821 \noun off
19822 \color none
19823 convert int to floating point numbers
19824 \end_layout
19825
19826 \end_inset
19827 </cell>
19828 </row>
19829 <row topline="true">
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \begin_layout Standard
19834
19835 \family roman
19836 \series medium
19837 \shape up
19838 \size normal
19839 \emph off
19840 \bar no
19841 \noun off
19842 \color none
19843 _ulong2fs.c
19844 \end_layout
19845
19846 \end_inset
19847 </cell>
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19849 \begin_inset Text
19850
19851 \begin_layout Standard
19852
19853 \family roman
19854 \series medium
19855 \shape up
19856 \size normal
19857 \emph off
19858 \bar no
19859 \noun off
19860 \color none
19861 convert unsigned long to floating point number
19862 \end_layout
19863
19864 \end_inset
19865 </cell>
19866 </row>
19867 <row topline="true" bottomline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872
19873 \family roman
19874 \series medium
19875 \shape up
19876 \size normal
19877 \emph off
19878 \bar no
19879 \noun off
19880 \color none
19881 _long2fs.c
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \begin_layout Standard
19890
19891 \family roman
19892 \series medium
19893 \shape up
19894 \size normal
19895 \emph off
19896 \bar no
19897 \noun off
19898 \color none
19899 convert long to floating point number
19900 \end_layout
19901
19902 \end_inset
19903 </cell>
19904 </row>
19905 </lyxtabular>
19906
19907 \end_inset
19908
19909
19910 \newline
19911
19912 \end_layout
19913
19914 \begin_layout Standard
19915 These support routines are developed in ANSI-C so there is room for space
19916  and speed improvement
19917 \begin_inset Foot
19918 status open
19919
19920 \begin_layout Standard
19921 These floating point routines (
19922 \emph on
19923 not
19924 \emph default
19925  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19926  
19927 \end_layout
19928
19929 \end_inset
19930
19931 .
19932  Note if all these routines are used simultaneously the data space might
19933  overflow.
19934  For serious floating point usage the large model might be needed.
19935  Also notice that you don't have to call this routines directly.
19936  The compiler will use them automatically every time a floating point operation
19937  is required.
19938 \begin_inset VSpace bigskip
19939 \end_inset
19940
19941
19942 \end_layout
19943
19944 \begin_layout Section
19945 Library Routines
19946 \begin_inset LatexCommand \index{Libraries}
19947
19948 \end_inset
19949
19950
19951 \end_layout
19952
19953 \begin_layout Standard
19954
19955 \emph on
19956 <pending: this is messy and incomplete - a little more information is in
19957  sdcc/doc/libdoc.txt
19958 \emph default
19959  >
19960 \end_layout
19961
19962 \begin_layout Subsection
19963 Compiler support routines (_gptrget, _mulint etc.)
19964 \end_layout
19965
19966 \begin_layout Subsection
19967 Stdclib functions (puts, printf, strcat etc.)
19968 \end_layout
19969
19970 \begin_layout Subsubsection
19971 <stdio.h>
19972 \end_layout
19973
19974 \begin_layout Paragraph
19975 getchar(), putchar()
19976 \end_layout
19977
19978 \begin_layout Standard
19979 \begin_inset LatexCommand \index{<stdio.h>}
19980
19981 \end_inset
19982
19983 As usual on embedded systems you have to provide your own 
19984 \family typewriter
19985 getchar()
19986 \begin_inset LatexCommand \index{getchar()}
19987
19988 \end_inset
19989
19990  
19991 \family default
19992 and 
19993 \family typewriter
19994 putchar()
19995 \begin_inset LatexCommand \index{putchar()}
19996
19997 \end_inset
19998
19999
20000 \family default
20001  routines.
20002  SDCC does not know whether the system connects to a serial line with or
20003  without handshake, LCD, keyboard or other device.
20004  And whether a 
20005 \family typewriter
20006 lf
20007 \family default
20008  to 
20009 \family typewriter
20010 crlf
20011 \family default
20012  conversion within 
20013 \family typewriter
20014 putchar()
20015 \family default
20016  is intended.
20017  You'll find examples for serial routines f.e.
20018  in sdcc/device/lib.
20019  For the mcs51 this minimalistic polling 
20020 \family typewriter
20021 putchar()
20022 \family default
20023  routine might be a start:
20024 \end_layout
20025
20026 \begin_layout Verse
20027
20028 \family typewriter
20029 void putchar (char c) { 
20030 \newline
20031 \InsetSpace ~
20032 \InsetSpace ~
20033 \InsetSpace ~
20034 \InsetSpace ~
20035 while (!TI)\InsetSpace ~
20036 \InsetSpace ~
20037 \InsetSpace ~
20038  /* assumes UART is initialized */
20039 \newline
20040 \InsetSpace ~
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 \InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048 ;
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 TI
20055  = 0;
20056 \newline
20057 \InsetSpace ~
20058 \InsetSpace ~
20059 \InsetSpace ~
20060 \InsetSpace ~
20061 SBUF = c;
20062 \newline
20063 }
20064 \end_layout
20065
20066 \begin_layout Paragraph
20067 printf()
20068 \end_layout
20069
20070 \begin_layout Standard
20071 The default
20072 \family typewriter
20073  printf()
20074 \begin_inset LatexCommand \index{printf()}
20075
20076 \end_inset
20077
20078
20079 \family default
20080  implementation in
20081 \family typewriter
20082  printf_large.c
20083 \family default
20084  does not support float (except on ds390).
20085  To enable this recompile it with the option 
20086 \emph on
20087 -
20088 \begin_inset ERT
20089 status collapsed
20090
20091 \begin_layout Standard
20092
20093
20094 \backslash
20095 /
20096 \end_layout
20097
20098 \end_inset
20099
20100 DUSE_FLOATS=1
20101 \begin_inset LatexCommand \index{USE\_FLOATS}
20102
20103 \end_inset
20104
20105
20106 \emph default
20107  on the command line.
20108  Use
20109 \emph on
20110  -
20111 \begin_inset ERT
20112 status collapsed
20113
20114 \begin_layout Standard
20115
20116
20117 \backslash
20118 /
20119 \end_layout
20120
20121 \end_inset
20122
20123 -model-large
20124 \begin_inset LatexCommand \index{-\/-model-large}
20125
20126 \end_inset
20127
20128
20129 \emph default
20130  for the mcs51 port, since this uses a lot of memory.
20131 \end_layout
20132
20133 \begin_layout Standard
20134 If you're short on code memory you might want to use 
20135 \family typewriter
20136 printf_small()
20137 \begin_inset LatexCommand \index{printf\_small()}
20138
20139 \end_inset
20140
20141
20142 \family default
20143  
20144 \emph on
20145 instead
20146 \emph default
20147  of
20148 \family typewriter
20149  printf().
20150
20151 \family default
20152  For the mcs51 there additionally are assembly versions 
20153 \family typewriter
20154 printf_tiny()
20155 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20156
20157 \end_inset
20158
20159
20160 \family default
20161  (subset of printf using less than 270 bytes) and 
20162 \family typewriter
20163 printf_fast()
20164 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20165
20166 \end_inset
20167
20168  
20169 \family default
20170 and
20171 \family typewriter
20172  printf_fast_f()
20173 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20174
20175 \end_inset
20176
20177
20178 \family default
20179  (floating-point aware version of printf_fast) which should fit the requirements
20180  of many embedded systems (printf_fast() can be customized by unsetting
20181  #defines to 
20182 \emph on
20183 not
20184 \emph default
20185  support long variables and field widths).
20186  Be sure to use only one of these printf options within a project.
20187 \newline
20188
20189 \end_layout
20190
20191 \begin_layout Standard
20192 Feature matrix of different 
20193 \emph on
20194 printf
20195 \emph default
20196  options on mcs51.
20197 \end_layout
20198
20199 \begin_layout Standard
20200 \begin_inset Tabular
20201 <lyxtabular version="3" rows="14" columns="7">
20202 <features islongtable="true">
20203 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20204 <column alignment="center" valignment="top" leftline="true" width="0">
20205 <column alignment="center" valignment="top" leftline="true" width="12col%">
20206 <column alignment="center" valignment="top" leftline="true" width="10col%">
20207 <column alignment="center" valignment="top" leftline="true" width="0">
20208 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20209 <column alignment="center" valignment="top" rightline="true" width="0">
20210 <row topline="true" bottomline="true" endhead="true">
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_inset Text
20213
20214 \begin_layout Standard
20215
20216 \series bold
20217 \size large
20218 mcs51
20219 \end_layout
20220
20221 \end_inset
20222 </cell>
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_inset Text
20225
20226 \begin_layout Standard
20227 printf
20228 \begin_inset LatexCommand \index{printf}
20229
20230 \end_inset
20231
20232
20233 \end_layout
20234
20235 \end_inset
20236 </cell>
20237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20238 \begin_inset Text
20239
20240 \begin_layout Standard
20241 printf 
20242 \size scriptsize
20243 USE_FLOATS=1
20244 \end_layout
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \begin_layout Standard
20252 printf_small
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 printf_fast
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 printf_fast_f
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 printf_tiny
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 </row>
20285 <row topline="true" endhead="true">
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20287 \begin_inset Text
20288
20289 \begin_layout Standard
20290 filename
20291 \end_layout
20292
20293 \end_inset
20294 </cell>
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299
20300 \size scriptsize
20301 printf_large.c
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310
20311 \size scriptsize
20312 printf_large.c
20313 \end_layout
20314
20315 \end_inset
20316 </cell>
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_inset Text
20319
20320 \begin_layout Standard
20321
20322 \size scriptsize
20323 printfl.c
20324 \end_layout
20325
20326 \end_inset
20327 </cell>
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_inset Text
20330
20331 \begin_layout Standard
20332
20333 \size scriptsize
20334 printf_fast.c
20335 \end_layout
20336
20337 \end_inset
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \begin_layout Standard
20343
20344 \size scriptsize
20345 printf_fast_f.c
20346 \end_layout
20347
20348 \end_inset
20349 </cell>
20350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_inset Text
20352
20353 \begin_layout Standard
20354
20355 \size scriptsize
20356 printf_tiny.c
20357 \end_layout
20358
20359 \end_inset
20360 </cell>
20361 </row>
20362 <row topline="true" endhead="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 \begin_inset Quotes sld
20368 \end_inset
20369
20370 Hello World
20371 \begin_inset Quotes srd
20372 \end_inset
20373
20374  size
20375 \end_layout
20376
20377 \begin_layout Standard
20378 small / large
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 1.7k / 2.4k
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \begin_layout Standard
20396 4.3k / 5.6k
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \begin_layout Standard
20405 1.2k / 1.8k
20406 \end_layout
20407
20408 \end_inset
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \begin_layout Standard
20414 1.3k / 1.3k
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 1.9k / 1.9k
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 0.44k / 0.44k
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 </row>
20438 <row topline="true" endhead="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \begin_layout Standard
20443 code size
20444 \end_layout
20445
20446 \begin_layout Standard
20447 small / large
20448 \end_layout
20449
20450 \end_inset
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456 1.4k / 2.0k
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 2.8k / 3.7k
20466 \end_layout
20467
20468 \end_inset
20469 </cell>
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474 0.45k / 0.47k (+ _ltoa)
20475 \end_layout
20476
20477 \end_inset
20478 </cell>
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20480 \begin_inset Text
20481
20482 \begin_layout Standard
20483 1.2k / 1.2k
20484 \end_layout
20485
20486 \end_inset
20487 </cell>
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20489 \begin_inset Text
20490
20491 \begin_layout Standard
20492 1.6k / 1.6k
20493 \end_layout
20494
20495 \end_inset
20496 </cell>
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20498 \begin_inset Text
20499
20500 \begin_layout Standard
20501 0.26k / 0.26k
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 </row>
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512 formats
20513 \end_layout
20514
20515 \end_inset
20516 </cell>
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_inset Text
20519
20520 \begin_layout Standard
20521 cdi
20522 \emph on
20523 o
20524 \emph default
20525 psux
20526 \end_layout
20527
20528 \end_inset
20529 </cell>
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20531 \begin_inset Text
20532
20533 \begin_layout Standard
20534
20535 \family roman
20536 \series medium
20537 \shape up
20538 \size normal
20539 \emph off
20540 \bar no
20541 \noun off
20542 \color none
20543 cd
20544 \family default
20545 \series default
20546 \shape default
20547 \size default
20548 \emph default
20549 \bar default
20550 \noun default
20551 f
20552 \family roman
20553 \series medium
20554 \shape up
20555 \size normal
20556 \emph off
20557 \bar no
20558 \noun off
20559 i
20560 \family default
20561 \series default
20562 \shape default
20563 \size default
20564 \emph on
20565 \bar default
20566 \noun default
20567 o
20568 \family roman
20569 \series medium
20570 \shape up
20571 \size normal
20572 \emph off
20573 \bar no
20574 \noun off
20575 psux
20576 \end_layout
20577
20578 \end_inset
20579 </cell>
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20581 \begin_inset Text
20582
20583 \begin_layout Standard
20584 c
20585 \family roman
20586 \series medium
20587 \shape up
20588 \size normal
20589 \emph off
20590 \bar no
20591 \noun off
20592 \color none
20593 d
20594 \family default
20595 \series default
20596 \shape default
20597 \size default
20598 \emph on
20599 \bar default
20600 \noun default
20601 o
20602 \family roman
20603 \series medium
20604 \shape up
20605 \size normal
20606 \emph off
20607 \bar no
20608 \noun off
20609 s
20610 \family default
20611 \series default
20612 \shape default
20613 \size default
20614 \emph default
20615 \bar default
20616 \noun default
20617 x
20618 \end_layout
20619
20620 \end_inset
20621 </cell>
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 \begin_inset Text
20624
20625 \begin_layout Standard
20626 cdsux
20627 \end_layout
20628
20629 \end_inset
20630 </cell>
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20632 \begin_inset Text
20633
20634 \begin_layout Standard
20635 cdfsux
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \begin_layout Standard
20644 cdsux
20645 \end_layout
20646
20647 \end_inset
20648 </cell>
20649 </row>
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 long (32 bit) support
20656 \end_layout
20657
20658 \end_inset
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \begin_layout Standard
20664 x
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \begin_layout Standard
20673 x
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 x
20683 \end_layout
20684
20685 \end_inset
20686 </cell>
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20688 \begin_inset Text
20689
20690 \begin_layout Standard
20691 x
20692 \end_layout
20693
20694 \end_inset
20695 </cell>
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20697 \begin_inset Text
20698
20699 \begin_layout Standard
20700
20701 \family roman
20702 \series medium
20703 \shape up
20704 \size normal
20705 \emph off
20706 \bar no
20707 \noun off
20708 \color none
20709 x
20710 \end_layout
20711
20712 \end_inset
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \begin_layout Standard
20718 -
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 </row>
20724 <row topline="true">
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20726 \begin_inset Text
20727
20728 \begin_layout Standard
20729 byte arguments on stack
20730 \end_layout
20731
20732 \end_inset
20733 </cell>
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20735 \begin_inset Text
20736
20737 \begin_layout Standard
20738 b
20739 \end_layout
20740
20741 \end_inset
20742 </cell>
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20744 \begin_inset Text
20745
20746 \begin_layout Standard
20747 b
20748 \end_layout
20749
20750 \end_inset
20751 </cell>
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20753 \begin_inset Text
20754
20755 \begin_layout Standard
20756 -
20757 \end_layout
20758
20759 \end_inset
20760 </cell>
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20762 \begin_inset Text
20763
20764 \begin_layout Standard
20765 -
20766 \end_layout
20767
20768 \end_inset
20769 </cell>
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20771 \begin_inset Text
20772
20773 \begin_layout Standard
20774 -
20775 \end_layout
20776
20777 \end_inset
20778 </cell>
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20780 \begin_inset Text
20781
20782 \begin_layout Standard
20783 -
20784 \end_layout
20785
20786 \end_inset
20787 </cell>
20788 </row>
20789 <row topline="true">
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20791 \begin_inset Text
20792
20793 \begin_layout Standard
20794 float format
20795 \begin_inset LatexCommand \index{Floating point support}
20796
20797 \end_inset
20798
20799
20800 \end_layout
20801
20802 \end_inset
20803 </cell>
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20805 \begin_inset Text
20806
20807 \begin_layout Standard
20808 -
20809 \end_layout
20810
20811 \end_inset
20812 </cell>
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20814 \begin_inset Text
20815
20816 \begin_layout Standard
20817 %f
20818 \end_layout
20819
20820 \end_inset
20821 </cell>
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \begin_layout Standard
20826 -
20827 \end_layout
20828
20829 \end_inset
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \begin_layout Standard
20835 -
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \begin_layout Standard
20844 %f
20845 \begin_inset Foot
20846 status collapsed
20847
20848 \begin_layout Standard
20849 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20850 \end_layout
20851
20852 \end_inset
20853
20854
20855 \end_layout
20856
20857 \end_inset
20858 </cell>
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20860 \begin_inset Text
20861
20862 \begin_layout Standard
20863 -
20864 \end_layout
20865
20866 \end_inset
20867 </cell>
20868 </row>
20869 <row topline="true">
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20871 \begin_inset Text
20872
20873 \begin_layout Standard
20874 float formats %e %g
20875 \end_layout
20876
20877 \end_inset
20878 </cell>
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20880 \begin_inset Text
20881
20882 \begin_layout Standard
20883 -
20884 \end_layout
20885
20886 \end_inset
20887 </cell>
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20889 \begin_inset Text
20890
20891 \begin_layout Standard
20892 -
20893 \end_layout
20894
20895 \end_inset
20896 </cell>
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20898 \begin_inset Text
20899
20900 \begin_layout Standard
20901 -
20902 \end_layout
20903
20904 \end_inset
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \begin_layout Standard
20910 -
20911 \end_layout
20912
20913 \end_inset
20914 </cell>
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20916 \begin_inset Text
20917
20918 \begin_layout Standard
20919 -
20920 \end_layout
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \begin_layout Standard
20928 -
20929 \end_layout
20930
20931 \end_inset
20932 </cell>
20933 </row>
20934 <row topline="true" bottomline="true">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \begin_layout Standard
20939 field width
20940 \end_layout
20941
20942 \end_inset
20943 </cell>
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \begin_layout Standard
20948 x
20949 \end_layout
20950
20951 \end_inset
20952 </cell>
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20954 \begin_inset Text
20955
20956 \begin_layout Standard
20957 x
20958 \end_layout
20959
20960 \end_inset
20961 </cell>
20962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20963 \begin_inset Text
20964
20965 \begin_layout Standard
20966 -
20967 \end_layout
20968
20969 \end_inset
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \begin_layout Standard
20975 x
20976 \end_layout
20977
20978 \end_inset
20979 </cell>
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20981 \begin_inset Text
20982
20983 \begin_layout Standard
20984 x
20985 \end_layout
20986
20987 \end_inset
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \begin_layout Standard
20993 -
20994 \end_layout
20995
20996 \end_inset
20997 </cell>
20998 </row>
20999 <row bottomline="true">
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_inset Text
21002
21003 \begin_layout Standard
21004 string speed
21005 \begin_inset Foot
21006 status collapsed
21007
21008 \begin_layout Standard
21009 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21010 \backslash
21011 r', '
21012 \backslash
21013 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21014 \end_layout
21015
21016 \end_inset
21017
21018 ,
21019 \end_layout
21020
21021 \begin_layout Standard
21022 small / large
21023 \end_layout
21024
21025 \end_inset
21026 </cell>
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \begin_layout Standard
21031 1.52 / 2.59 ms
21032 \end_layout
21033
21034 \end_inset
21035 </cell>
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_inset Text
21038
21039 \begin_layout Standard
21040 1.53 / 2.62 ms
21041 \end_layout
21042
21043 \end_inset
21044 </cell>
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21046 \begin_inset Text
21047
21048 \begin_layout Standard
21049 0.92 / 0.93 ms
21050 \end_layout
21051
21052 \end_inset
21053 </cell>
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21055 \begin_inset Text
21056
21057 \begin_layout Standard
21058 0.45 / 0.45 ms
21059 \end_layout
21060
21061 \end_inset
21062 </cell>
21063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21064 \begin_inset Text
21065
21066 \begin_layout Standard
21067 0.46 / 0.46 ms
21068 \end_layout
21069
21070 \end_inset
21071 </cell>
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21073 \begin_inset Text
21074
21075 \begin_layout Standard
21076 0.45 / 0.45 ms
21077 \end_layout
21078
21079 \end_inset
21080 </cell>
21081 </row>
21082 <row bottomline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21084 \begin_inset Text
21085
21086 \begin_layout Standard
21087 int speed
21088 \begin_inset Foot
21089 status collapsed
21090
21091 \begin_layout Standard
21092 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21093  putchar()
21094 \end_layout
21095
21096 \end_inset
21097
21098 ,
21099 \end_layout
21100
21101 \begin_layout Standard
21102 small / large
21103 \end_layout
21104
21105 \end_inset
21106 </cell>
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21108 \begin_inset Text
21109
21110 \begin_layout Standard
21111 3.01 / 3.61 ms
21112 \end_layout
21113
21114 \end_inset
21115 </cell>
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21117 \begin_inset Text
21118
21119 \begin_layout Standard
21120 3.01 / 3.61 ms
21121 \end_layout
21122
21123 \end_inset
21124 </cell>
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21126 \begin_inset Text
21127
21128 \begin_layout Standard
21129 3.51 / 18.13 ms
21130 \end_layout
21131
21132 \end_inset
21133 </cell>
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21135 \begin_inset Text
21136
21137 \begin_layout Standard
21138 0.22 / 0.22 ms
21139 \end_layout
21140
21141 \end_inset
21142 </cell>
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21144 \begin_inset Text
21145
21146 \begin_layout Standard
21147 0.23 / 0.23 ms
21148 \end_layout
21149
21150 \end_inset
21151 </cell>
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21153 \begin_inset Text
21154
21155 \begin_layout Standard
21156 0.25 / 0.25 ms
21157 \begin_inset Foot
21158 status collapsed
21159
21160 \begin_layout Standard
21161 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21162 \end_layout
21163
21164 \end_inset
21165
21166
21167 \end_layout
21168
21169 \end_inset
21170 </cell>
21171 </row>
21172 <row bottomline="true">
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21174 \begin_inset Text
21175
21176 \begin_layout Standard
21177 long speed
21178 \begin_inset Foot
21179 status collapsed
21180
21181 \begin_layout Standard
21182 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21183  empty putchar()
21184 \end_layout
21185
21186 \end_inset
21187
21188 ,
21189 \end_layout
21190
21191 \begin_layout Standard
21192 small / large
21193 \end_layout
21194
21195 \end_inset
21196 </cell>
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21198 \begin_inset Text
21199
21200 \begin_layout Standard
21201 5.37 / 6.31 ms
21202 \end_layout
21203
21204 \end_inset
21205 </cell>
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21207 \begin_inset Text
21208
21209 \begin_layout Standard
21210 5.37 / 6.31 ms
21211 \end_layout
21212
21213 \end_inset
21214 </cell>
21215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21216 \begin_inset Text
21217
21218 \begin_layout Standard
21219 8.71 / 40.65 ms
21220 \end_layout
21221
21222 \end_inset
21223 </cell>
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21225 \begin_inset Text
21226
21227 \begin_layout Standard
21228 0.40 / 0.40 ms
21229 \end_layout
21230
21231 \end_inset
21232 </cell>
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21234 \begin_inset Text
21235
21236 \begin_layout Standard
21237 0.40 / 0.40 ms
21238 \end_layout
21239
21240 \end_inset
21241 </cell>
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \begin_layout Standard
21246 -
21247 \end_layout
21248
21249 \end_inset
21250 </cell>
21251 </row>
21252 <row bottomline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_inset Text
21255
21256 \begin_layout Standard
21257 float speed
21258 \begin_inset Foot
21259 status collapsed
21260
21261 \begin_layout Standard
21262 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21263  empty putchar()
21264 \end_layout
21265
21266 \end_inset
21267
21268 ,
21269 \end_layout
21270
21271 \begin_layout Standard
21272 small / large
21273 \end_layout
21274
21275 \end_inset
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \begin_layout Standard
21281 -
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \begin_layout Standard
21290 7.49 / 22.47 ms
21291 \end_layout
21292
21293 \end_inset
21294 </cell>
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21296 \begin_inset Text
21297
21298 \begin_layout Standard
21299 -
21300 \end_layout
21301
21302 \end_inset
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \begin_layout Standard
21308 -
21309 \end_layout
21310
21311 \end_inset
21312 </cell>
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21314 \begin_inset Text
21315
21316 \begin_layout Standard
21317 1.04 / 1.04 ms
21318 \end_layout
21319
21320 \end_inset
21321 </cell>
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21323 \begin_inset Text
21324
21325 \begin_layout Standard
21326 -
21327 \end_layout
21328
21329 \end_inset
21330 </cell>
21331 </row>
21332 </lyxtabular>
21333
21334 \end_inset
21335
21336
21337 \end_layout
21338
21339 \begin_layout Subsubsection
21340 <malloc.h>
21341 \begin_inset LatexCommand \index{malloc.h}
21342
21343 \end_inset
21344
21345
21346 \end_layout
21347
21348 \begin_layout Standard
21349 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21350  using dynamic memory allocation
21351 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21352
21353 \end_inset
21354
21355  and a default heap
21356 \begin_inset LatexCommand \index{heap (malloc)}
21357
21358 \end_inset
21359
21360  space of 1024 bytes is provided for malloc to allocate memory from.
21361  If you need a different heap size you need to recompile _heap.c with the
21362  required size defined in HEAP_SIZE.
21363  It is recommended to make a copy of this file into your project directory
21364  and compile it there with:
21365 \end_layout
21366
21367 \begin_layout Verse
21368
21369 \family typewriter
21370 sdcc -c _heap.c -D HEAD_SIZE=2048
21371 \end_layout
21372
21373 \begin_layout Standard
21374 And then link it with:
21375 \end_layout
21376
21377 \begin_layout Verse
21378
21379 \family typewriter
21380 sdcc main.rel _heap.rel
21381 \end_layout
21382
21383 \begin_layout Subsection
21384 Math functions (sinf, powf, sqrtf etc.)
21385 \end_layout
21386
21387 \begin_layout Subsubsection
21388 <math.h>
21389 \end_layout
21390
21391 \begin_layout Standard
21392 See definitions in file <math.h>.
21393 \end_layout
21394
21395 \begin_layout Subsection
21396 Other libraries
21397 \end_layout
21398
21399 \begin_layout Standard
21400 Libraries
21401 \begin_inset LatexCommand \index{Libraries}
21402
21403 \end_inset
21404
21405  included in SDCC should have a license at least as liberal as the GNU Lesser
21406  General Public License
21407 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21408
21409 \end_inset
21410
21411  
21412 \emph on
21413 LGPL
21414 \emph default
21415 .
21416 \end_layout
21417
21418 \begin_layout Standard
21419 \begin_inset Note Note
21420 status collapsed
21421
21422 \begin_layout Standard
21423 license statements for the libraries are missing.
21424  sdcc/device/lib/ser_ir.c
21425 \end_layout
21426
21427 \begin_layout Standard
21428 or _decdptr f.e.
21429  come with a GPL (as opposed to LGPL) License - this will not be liberal
21430  enough for many embedded programmers.
21431 \end_layout
21432
21433 \end_inset
21434
21435
21436 \end_layout
21437
21438 \begin_layout Standard
21439 If you have ported some library or want to share experience about some code
21440  which f.e.
21441  falls into any of these categories Busses (I
21442 \begin_inset Formula $^{\textrm{2}}$
21443 \end_inset
21444
21445 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21446  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21447  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21448 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21449
21450 \end_inset
21451
21452 \InsetSpace ~
21453 would certainly like to hear about it.
21454 \end_layout
21455
21456 \begin_layout Standard
21457 Programmers coding for embedded systems are not especially famous for being
21458  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21459 e these references are very valuable.
21460  Let's help to create a climate where information is shared.
21461 \begin_inset VSpace bigskip
21462 \end_inset
21463
21464
21465 \end_layout
21466
21467 \begin_layout Section
21468 Memory Models
21469 \end_layout
21470
21471 \begin_layout Subsection
21472 MCS51 Memory Models
21473 \begin_inset LatexCommand \index{Memory model}
21474
21475 \end_inset
21476
21477
21478 \begin_inset LatexCommand \index{MCS51 memory model}
21479
21480 \end_inset
21481
21482
21483 \end_layout
21484
21485 \begin_layout Subsubsection
21486 Small, Medium and Large
21487 \end_layout
21488
21489 \begin_layout Standard
21490 SDCC allows three memory models for MCS51 code, 
21491 \shape slanted
21492 small, medium
21493 \shape default
21494  and 
21495 \shape slanted
21496 large
21497 \shape default
21498 .
21499  Modules compiled with different memory models should 
21500 \emph on
21501 never
21502 \emph default
21503  be combined together or the results would be unpredictable.
21504  The library routines supplied with the compiler are compiled as small,
21505  medium and large.
21506  The compiled library modules are contained in separate directories as small,
21507  medium and large so that you can link to the appropriate set.
21508 \end_layout
21509
21510 \begin_layout Standard
21511 When the medium or large model is used all variables declared without a
21512  storage class will be allocated into the external ram, this includes all
21513  parameters and local variables (for non-reentrant
21514 \begin_inset LatexCommand \index{reentrant}
21515
21516 \end_inset
21517
21518  functions).
21519  When the small model is used variables without storage class are allocated
21520  in the internal ram.
21521 \end_layout
21522
21523 \begin_layout Standard
21524 Judicious usage of the processor specific storage classes
21525 \begin_inset LatexCommand \index{Storage class}
21526
21527 \end_inset
21528
21529  and the 'reentrant' function type will yield much more efficient code,
21530  than using the large model.
21531  Several optimizations are disabled when the program is compiled using the
21532  large model, it is therefore recommended that the small model be used unless
21533  absolutely required.
21534 \end_layout
21535
21536 \begin_layout Subsubsection
21537 External Stack
21538 \begin_inset LatexCommand \label{sub:External-Stack}
21539
21540 \end_inset
21541
21542
21543 \begin_inset LatexCommand \index{stack}
21544
21545 \end_inset
21546
21547
21548 \begin_inset LatexCommand \index{External stack (mcs51)}
21549
21550 \end_inset
21551
21552
21553 \end_layout
21554
21555 \begin_layout Standard
21556 The external stack (-
21557 \begin_inset ERT
21558 status collapsed
21559
21560 \begin_layout Standard
21561
21562
21563 \backslash
21564 /
21565 \end_layout
21566
21567 \end_inset
21568
21569 -xstack option
21570 \begin_inset LatexCommand \index{-\/-xstack}
21571
21572 \end_inset
21573
21574 ) is located in pdata
21575 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21576
21577 \end_inset
21578
21579  memory (usually at the start of the external ram segment) and uses all
21580  unused space in pdata (max.
21581  256 bytes).
21582  When -
21583 \begin_inset ERT
21584 status collapsed
21585
21586 \begin_layout Standard
21587
21588
21589 \backslash
21590 /
21591 \end_layout
21592
21593 \end_inset
21594
21595 -xstack option is used to compile the program, the parameters and local
21596  variables
21597 \begin_inset LatexCommand \index{local variables}
21598
21599 \end_inset
21600
21601  of all reentrant functions are allocated in this area.
21602  This option is provided for programs with large stack space requirements.
21603  When used with the -
21604 \begin_inset ERT
21605 status collapsed
21606
21607 \begin_layout Standard
21608
21609
21610 \backslash
21611 /
21612 \end_layout
21613
21614 \end_inset
21615
21616 -stack-auto
21617 \begin_inset LatexCommand \index{-\/-stack-auto}
21618
21619 \end_inset
21620
21621  option, all parameters and local variables are allocated on the external
21622  stack (note: support libraries will need to be recompiled with the same
21623  options.
21624  There is a predefined target in the library makefile).
21625 \end_layout
21626
21627 \begin_layout Standard
21628 The compiler outputs the higher order address byte of the external ram segment
21629  into port P2
21630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21631
21632 \end_inset
21633
21634  (see also section 
21635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21636
21637 \end_inset
21638
21639 ), therefore when using the External Stack option, this port 
21640 \emph on
21641 may not
21642 \emph default
21643  be used by the application program.
21644 \end_layout
21645
21646 \begin_layout Subsection
21647 DS390 Memory Model
21648 \begin_inset LatexCommand \index{Memory model}
21649
21650 \end_inset
21651
21652
21653 \begin_inset LatexCommand \index{DS390 memory model}
21654
21655 \end_inset
21656
21657
21658 \end_layout
21659
21660 \begin_layout Standard
21661 The only model supported is Flat 24
21662 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21663
21664 \end_inset
21665
21666 .
21667  This generates code for the 24 bit contiguous addressing mode of the Dallas
21668  DS80C390 part.
21669  In this mode, up to four meg of external RAM or code space can be directly
21670  addressed.
21671  See the data sheets at www.dalsemi.com for further information on this part.
21672 \newline
21673
21674 \newline
21675 Note
21676  that the compiler does not generate any code to place the processor into
21677  24 bitmode (although 
21678 \emph on
21679 tinibios
21680 \emph default
21681  in the ds390 libraries will do that for you).
21682  If you don't use 
21683 \emph on
21684 tinibios
21685 \emph default
21686
21687 \begin_inset LatexCommand \index{Tinibios (DS390)}
21688
21689 \end_inset
21690
21691 , the boot loader or similar code must ensure that the processor is in 24
21692  bit contiguous addressing mode before calling the SDCC startup code.
21693 \newline
21694
21695 \newline
21696 Like
21697  the 
21698 \emph on
21699 -
21700 \begin_inset ERT
21701 status collapsed
21702
21703 \begin_layout Standard
21704
21705
21706 \backslash
21707 /
21708 \end_layout
21709
21710 \end_inset
21711
21712 -model-large
21713 \emph default
21714  option, variables will by default be placed into the XDATA segment.
21715  
21716 \newline
21717
21718 \newline
21719 Segments may be placed anywhere in the 4 meg address space using the usual
21720  -
21721 \begin_inset ERT
21722 status collapsed
21723
21724 \begin_layout Standard
21725
21726
21727 \backslash
21728 /
21729 \end_layout
21730
21731 \end_inset
21732
21733 -*-loc options.
21734  Note that if any segments are located above 64K, the -r flag must be passed
21735  to the linker to generate the proper segment relocations, and the Intel
21736  HEX output format must be used.
21737  The -r flag can be passed to the linker by using the option 
21738 \emph on
21739 -Wl-r
21740 \emph default
21741  on the SDCC command line.
21742  However, currently the linker can not handle code segments > 64k.
21743 \end_layout
21744
21745 \begin_layout Section
21746 Pragmas
21747 \begin_inset LatexCommand \label{sec:Pragmas}
21748
21749 \end_inset
21750
21751
21752 \begin_inset LatexCommand \index{Pragmas}
21753
21754 \end_inset
21755
21756
21757 \end_layout
21758
21759 \begin_layout Standard
21760 Pragmas are used to turn on and/or off certain compiler options.
21761  Some of them are closely related to corresponding command-line options
21762  (see section 
21763 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21764
21765 \end_inset
21766
21767 ).
21768 \newline
21769 Pragmas should be placed before and/or after a function, placing pragmas
21770  inside a function body could have unpredictable results.
21771 \newline
21772
21773 \newline
21774 SDCC supports the
21775  following #pragma directives:
21776 \end_layout
21777
21778 \begin_layout Itemize
21779
21780 \series bold
21781 save
21782 \series default
21783
21784 \begin_inset LatexCommand \index{\#pragma save}
21785
21786 \end_inset
21787
21788  - this will save most current options to the save/restore stack.
21789  See #pragma\InsetSpace ~
21790 restore.
21791 \end_layout
21792
21793 \begin_layout Itemize
21794
21795 \series bold
21796 restore
21797 \series default
21798
21799 \begin_inset LatexCommand \index{\#pragma restore}
21800
21801 \end_inset
21802
21803  - will restore saved options from the last save.
21804  saves & restores can be nested.
21805  SDCC uses a save/restore stack: save pushes current options to the stack,
21806  restore pulls current options from the stack.
21807  See #pragma\InsetSpace ~
21808 save.
21809 \newline
21810
21811 \end_layout
21812
21813 \begin_layout Itemize
21814
21815 \series bold
21816 callee_saves
21817 \series default
21818
21819 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21820
21821 \end_inset
21822
21823
21824 \begin_inset LatexCommand \index{function prologue}
21825
21826 \end_inset
21827
21828  function1[,function2[,function3...]] 
21829 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21830
21831 \end_inset
21832
21833 - The compiler by default uses a caller saves convention for register saving
21834  across function calls, however this can cause unnecessary register pushing
21835  and popping
21836 \begin_inset LatexCommand \index{push/pop}
21837
21838 \end_inset
21839
21840  when calling small functions from larger functions.
21841  This option can be used to switch off the register saving convention for
21842  the function names specified.
21843  The compiler will not save registers when calling these functions, extra
21844  code need to be manually inserted at the entry and exit for these functions
21845  to save and restore the registers used by these functions, this can SUBSTANTIAL
21846 LY reduce code and improve run time performance of the generated code.
21847  In the future the compiler (with inter procedural analysis) may be able
21848  to determine the appropriate scheme to use for each function call.
21849  If -
21850 \begin_inset ERT
21851 status collapsed
21852
21853 \begin_layout Standard
21854
21855
21856 \backslash
21857 /
21858 \end_layout
21859
21860 \end_inset
21861
21862 -callee-saves command line option is used (see page 
21863 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21864
21865 \end_inset
21866
21867 ), the function names specified in #pragma\InsetSpace ~
21868 callee_saves
21869 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21870
21871 \end_inset
21872
21873  is appended to the list of functions specified in the command line.
21874 \end_layout
21875
21876 \begin_layout Itemize
21877
21878 \series bold
21879 exclude
21880 \series default
21881
21882 \begin_inset LatexCommand \index{\#pragma exclude}
21883
21884 \end_inset
21885
21886  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21887  of pairs of push/pop
21888 \begin_inset LatexCommand \index{push/pop}
21889
21890 \end_inset
21891
21892  instructions in 
21893 \emph on
21894 I
21895 \emph default
21896 nterrupt
21897 \begin_inset LatexCommand \index{interrupt}
21898
21899 \end_inset
21900
21901  
21902 \emph on
21903 S
21904 \emph default
21905 ervice 
21906 \emph on
21907 R
21908 \emph default
21909 outines.
21910  The directive should be placed immediately before the ISR function definition
21911  and it affects ALL ISR functions following it.
21912  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21913 exclude\InsetSpace ~
21914 none
21915 \begin_inset LatexCommand \index{\#pragma exclude}
21916
21917 \end_inset
21918
21919 .
21920  See also the related keyword _naked
21921 \begin_inset LatexCommand \index{\_naked}
21922
21923 \end_inset
21924
21925
21926 \begin_inset LatexCommand \index{\_\_naked}
21927
21928 \end_inset
21929
21930 .
21931 \end_layout
21932
21933 \begin_layout Itemize
21934
21935 \series bold
21936 less_pedantic
21937 \series default
21938
21939 \begin_inset LatexCommand \index{pedantic}
21940
21941 \end_inset
21942
21943
21944 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21945
21946 \end_inset
21947
21948  
21949 \begin_inset LatexCommand \label{ite:less_pedantic}
21950
21951 \end_inset
21952
21953 - the compiler will not warn you anymore for obvious mistakes, you're on
21954  your own now ;-( .
21955  See also the command line option -
21956 \begin_inset ERT
21957 status collapsed
21958
21959 \begin_layout Standard
21960
21961
21962 \backslash
21963 /
21964 \end_layout
21965
21966 \end_inset
21967
21968 -less-pedantic 
21969 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21970
21971 \end_inset
21972
21973 .
21974  
21975 \newline
21976 More specifically, the following warnings will be disabled: 
21977 \shape italic
21978 comparison is always [true/false] due to limited range of data type
21979 \shape default
21980  (94); 
21981 \shape italic
21982 overflow in implicit constant conversion
21983 \shape default
21984  (158); [the (in)famous] 
21985 \shape italic
21986 conditional flow changed by optimizer: so said EVELYN the modified DOG
21987 \shape default
21988  (110); 
21989 \shape italic
21990 function '[function name]' must return value
21991 \shape default
21992  (59).
21993  
21994 \newline
21995 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21996  level) are disabled, too, namely: 
21997 \shape italic
21998 constant value '[
21999 \begin_inset Note Note
22000 status collapsed
22001
22002 \begin_layout Standard
22003 dunno what comes here - this warning appears to be unused altogether
22004 \end_layout
22005
22006 \end_inset
22007
22008 ]', out of range
22009 \shape default
22010  (81); 
22011 \shape italic
22012 [left/right] shifting more than size of object changed to zero
22013 \shape default
22014  (116); 
22015 \shape italic
22016 unreachable code
22017 \shape default
22018  (126); 
22019 \shape italic
22020 integer overflow in expression
22021 \shape default
22022  (165); 
22023 \shape italic
22024 unmatched #pragma save and #pragma restore
22025 \shape default
22026  (170); 
22027 \shape italic
22028 comparison of 'signed char' with 'unsigned char' requires promotion to int
22029 \shape default
22030  (185); 
22031 \shape italic
22032 ISO C90 does not support flexible array members
22033 \shape default
22034  (187); 
22035 \shape italic
22036 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22037 nam
22038 e]':\InsetSpace ~
22039 [
22040 \begin_inset Note Note
22041 status collapsed
22042
22043 \begin_layout Standard
22044 appears to be always blank - what was supposed to be here?
22045 \end_layout
22046
22047 \end_inset
22048
22049 ]
22050 \shape default
22051  (114); 
22052 \shape italic
22053 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22054  complexity [number]
22055 \shape default
22056  (121).
22057 \end_layout
22058
22059 \begin_layout Itemize
22060
22061 \series bold
22062 disable_warning
22063 \series default
22064  <nnnn>
22065 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22066
22067 \end_inset
22068
22069  - the compiler will not warn you anymore about warning number <nnnn>.
22070 \end_layout
22071
22072 \begin_layout Itemize
22073
22074 \series bold
22075 nogcse
22076 \series default
22077
22078 \begin_inset LatexCommand \index{\#pragma nogcse}
22079
22080 \end_inset
22081
22082  - will stop global common subexpression elimination.
22083 \end_layout
22084
22085 \begin_layout Itemize
22086
22087 \series bold
22088 noinduction
22089 \series default
22090
22091 \begin_inset LatexCommand \index{\#pragma noinduction}
22092
22093 \end_inset
22094
22095  - will stop loop induction optimizations.
22096 \end_layout
22097
22098 \begin_layout Itemize
22099
22100 \series bold
22101 noinvariant
22102 \series default
22103
22104 \begin_inset LatexCommand \index{\#pragma noinvariant}
22105
22106 \end_inset
22107
22108  - will not do loop invariant optimizations.
22109  For more details see Loop Invariants in section
22110 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22111
22112 \end_inset
22113
22114 .
22115 \end_layout
22116
22117 \begin_layout Itemize
22118
22119 \series bold
22120 noiv
22121 \series default
22122
22123 \begin_inset LatexCommand \index{\#pragma noiv}
22124
22125 \end_inset
22126
22127  - Do not generate interrupt
22128 \begin_inset LatexCommand \index{interrupt}
22129
22130 \end_inset
22131
22132  vector table
22133 \begin_inset LatexCommand \index{interrupt vector table}
22134
22135 \end_inset
22136
22137  entries for all ISR functions defined after the pragma.
22138  This is useful in cases where the interrupt vector table must be defined
22139  manually, or when there is a secondary, manually defined interrupt vector
22140  table (e.g.
22141  for the autovector feature of the Cypress EZ-USB FX2).
22142  More elegantly this can be achieved by obmitting the optional interrupt
22143  number after the interrupt keyword, see section 
22144 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22145
22146 \end_inset
22147
22148 \InsetSpace ~
22149 about interrupts.
22150 \end_layout
22151
22152 \begin_layout Itemize
22153
22154 \series bold
22155 nojtbound
22156 \series default
22157
22158 \begin_inset LatexCommand \index{\#pragma nojtbound}
22159
22160 \end_inset
22161
22162  - will not generate code for boundary value checking, when switch statements
22163  are turned into jump-tables (dangerous).
22164  For more details see section 
22165 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22166
22167 \end_inset
22168
22169 .
22170 \end_layout
22171
22172 \begin_layout Itemize
22173
22174 \series bold
22175 noloopreverse
22176 \series default
22177
22178 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22179
22180 \end_inset
22181
22182  - Will not do loop reversal optimization
22183 \end_layout
22184
22185 \begin_layout Itemize
22186
22187 \series bold
22188 nooverlay
22189 \series default
22190
22191 \begin_inset LatexCommand \index{\#pragma nooverlay}
22192
22193 \end_inset
22194
22195  - the compiler will not overlay the parameters and local variables of a
22196  function.
22197 \end_layout
22198
22199 \begin_layout Itemize
22200
22201 \series bold
22202 stackauto
22203 \series default
22204
22205 \begin_inset LatexCommand \index{\#pragma stackauto}
22206
22207 \end_inset
22208
22209 - See option -
22210 \begin_inset ERT
22211 status collapsed
22212
22213 \begin_layout Standard
22214
22215
22216 \backslash
22217 /
22218 \end_layout
22219
22220 \end_inset
22221
22222 -stack-auto
22223 \begin_inset LatexCommand \index{-\/-stack-auto}
22224
22225 \end_inset
22226
22227  and section 
22228 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22229
22230 \end_inset
22231
22232  Parameters and Local Variables.
22233 \end_layout
22234
22235 \begin_layout Itemize
22236
22237 \series bold
22238 opt_code_speed
22239 \series default
22240  
22241 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22242
22243 \end_inset
22244
22245 - The compiler will optimize code generation towards fast code, possibly
22246  at the expense of code size.
22247  Currently this has little effect.
22248 \end_layout
22249
22250 \begin_layout Itemize
22251
22252 \series bold
22253 opt_code_size
22254 \series default
22255  
22256 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22257
22258 \end_inset
22259
22260 - The compiler will optimize code generation towards compact code, possibly
22261  at the expense of code speed.
22262  Currently this has little effect.
22263 \end_layout
22264
22265 \begin_layout Itemize
22266
22267 \series bold
22268 opt_code_balanced
22269 \series default
22270  
22271 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22272
22273 \end_inset
22274
22275 - The compiler will attempt to generate code that is both compact and fast,
22276  as long as meeting one goal is not a detriment to the other (this is the
22277  default).
22278  
22279 \end_layout
22280
22281 \begin_layout Itemize
22282
22283 \series bold
22284 std_sdcc89
22285 \series default
22286  
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22288
22289 \end_inset
22290
22291 - Generally follow the C89 standard, but allow SDCC features that conflict
22292  with the standard (default).
22293 \end_layout
22294
22295 \begin_layout Itemize
22296
22297 \series bold
22298 std_c89
22299 \series default
22300  
22301 \begin_inset LatexCommand \index{\#pragma std\_c89}
22302
22303 \end_inset
22304
22305 - Follow the C89 standard and disable SDCC features that conflict with the
22306  standard.
22307 \end_layout
22308
22309 \begin_layout Itemize
22310
22311 \series bold
22312 std_sdcc99
22313 \series default
22314  
22315 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22316
22317 \end_inset
22318
22319 - Generally follow the C99 standard, but allow SDCC features that conflict
22320  with the standard (incomplete support).
22321 \end_layout
22322
22323 \begin_layout Itemize
22324
22325 \series bold
22326 std_c99
22327 \series default
22328  
22329 \begin_inset LatexCommand \index{\#pragma std\_c99}
22330
22331 \end_inset
22332
22333 - Follow the C99 standard and disable SDCC features that conflict with the
22334  standard (incomplete support).
22335 \end_layout
22336
22337 \begin_layout Itemize
22338
22339 \series bold
22340 codeseg
22341 \series default
22342  <name>
22343 \begin_inset LatexCommand \index{\#pragma codeseg}
22344
22345 \end_inset
22346
22347 - Use this name (max.
22348  8 characters) for the code segment.
22349  See option -
22350 \begin_inset ERT
22351 status collapsed
22352
22353 \begin_layout Standard
22354
22355
22356 \backslash
22357 /
22358 \end_layout
22359
22360 \end_inset
22361
22362 -codeseg.
22363 \end_layout
22364
22365 \begin_layout Itemize
22366
22367 \series bold
22368 constseg
22369 \series default
22370  <name>
22371 \begin_inset LatexCommand \index{\#pragma constseg}
22372
22373 \end_inset
22374
22375 - Use this name (max.
22376  8 characters) for the const segment.
22377  See option -
22378 \begin_inset ERT
22379 status collapsed
22380
22381 \begin_layout Standard
22382
22383
22384 \backslash
22385 /
22386 \end_layout
22387
22388 \end_inset
22389
22390 -constseg.
22391 \end_layout
22392
22393 \begin_layout Standard
22394 The preprocessor SDCPP
22395 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22396
22397 \end_inset
22398
22399  supports the following #pragma directives:
22400 \end_layout
22401
22402 \begin_layout Itemize
22403
22404 \series bold
22405 pedantic_parse_number
22406 \series default
22407
22408 \begin_inset LatexCommand \index{pedantic}
22409
22410 \end_inset
22411
22412
22413 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22414
22415 \end_inset
22416
22417  (+ | -) 
22418 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22419
22420 \end_inset
22421
22422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22423  properly and the macro LO_B(3) gets expanded.
22424  Default is off.
22425  See also the -
22426 \begin_inset ERT
22427 status collapsed
22428
22429 \begin_layout Standard
22430
22431
22432 \backslash
22433 /
22434 \end_layout
22435
22436 \end_inset
22437
22438 -pedantic-parse-number command line option 
22439 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22440
22441 \end_inset
22442
22443 .
22444  
22445 \newline
22446 Below is an example on how to use this pragma.
22447
22448 \emph on
22449  Note: this functionality is not in conformance with standard!
22450 \end_layout
22451
22452 \begin_layout Verse
22453
22454 \family typewriter
22455 #pragma pedantic_parse_number +
22456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22457
22458 \end_inset
22459
22460
22461 \newline
22462
22463 \newline
22464 #define LO_B(x) ((x) & 0xff)
22465 \newline
22466
22467 \newline
22468 unsigned char foo(void)
22469 \newline
22470 {
22471 \newline
22472 \InsetSpace ~
22473 \InsetSpace ~
22474 \InsetSpace ~
22475 unsigned char c=0xfe-LO_B(3)
22476 ;
22477 \newline
22478
22479 \newline
22480 \InsetSpace ~
22481 \InsetSpace ~
22482 \InsetSpace ~
22483 return c;
22484 \newline
22485 }
22486 \newline
22487
22488 \end_layout
22489
22490 \begin_layout Itemize
22491
22492 \series bold
22493 preproc_asm
22494 \series default
22495
22496 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22497
22498 \end_inset
22499
22500  (+ | -) - switch _asm _endasm block preprocessing on / off.
22501  Default is on.
22502  You use this prama to define multilines of assembly code.
22503  This will prevent the preprocessor from changing the formating required
22504  by assembly code.
22505  Below is an example on how to use this pragma.
22506 \end_layout
22507
22508 \begin_layout Verse
22509
22510 \family typewriter
22511 #pragma preproc_asm -
22512 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22513
22514 \end_inset
22515
22516
22517 \newline
22518 #define MYDELAY _asm
22519 \newline
22520 \InsetSpace ~
22521 \InsetSpace ~
22522 \InsetSpace ~
22523 nop ;my assembly comment...
22524 \newline
22525 \InsetSpace ~
22526 \InsetSpace ~
22527 \InsetSpace ~
22528 nop
22529 \newline
22530 \InsetSpace ~
22531 \InsetSpace ~
22532 \InsetSpace ~
22533 nop
22534 \newline
22535 _endasm
22536 \newline
22537 #pragma preproc_asm
22538  +
22539 \newline
22540
22541 \newline
22542 void foo (void) 
22543 \newline
22544
22545 \newline
22546 \InsetSpace ~
22547 \InsetSpace ~
22548 \InsetSpace ~
22549  ...
22550  
22551 \newline
22552 \InsetSpace ~
22553 \InsetSpace ~
22554 \InsetSpace ~
22555  MYDELAY;
22556 \newline
22557 \InsetSpace ~
22558 \InsetSpace ~
22559 \InsetSpace ~
22560  ...
22561  
22562 \newline
22563
22564 \newline
22565
22566 \end_layout
22567
22568 \begin_layout Itemize
22569
22570 \series bold
22571 sdcc_hash
22572 \series default
22573
22574 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22575
22576 \end_inset
22577
22578  (+ | -) - Allow "naked" hash in macro definition, for example:
22579 \newline
22580
22581 \family typewriter
22582 #define DIR_LO(x) #(x & 0xff)
22583 \family default
22584
22585 \newline
22586 Default is off.
22587  Below is an example on how to use this pragma.
22588 \end_layout
22589
22590 \begin_layout Verse
22591
22592 \family typewriter
22593 #pragma preproc_asm +
22594 \newline
22595 #pragma sdcc_hash +
22596 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22597
22598 \end_inset
22599
22600
22601 \newline
22602
22603 \newline
22604 #define ROMCALL(x) 
22605 \backslash
22606
22607 \newline
22608 \InsetSpace ~
22609 \InsetSpace ~
22610 \InsetSpace ~
22611 mov R6_B3, #(x & 0xff) 
22612 \backslash
22613
22614 \newline
22615 \InsetSpace ~
22616 \InsetSpace ~
22617 \InsetSpace ~
22618 mov R7_B3, #((x >> 8) & 0xff) 
22619 \backslash
22620
22621 \newline
22622 \InsetSpace ~
22623 \InsetSpace ~
22624 \InsetSpace ~
22625 lcall __romcall
22626 \newline
22627
22628 \newline
22629 ...
22630 \newline
22631 _asm
22632 \newline
22633 ROMCALL(72)
22634 \newline
22635 _endasm;
22636 \newline
22637 ...
22638 \newline
22639
22640 \end_layout
22641
22642 \begin_layout Standard
22643 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22644 ons which might cause the compiler to generate extra stack and/or data space
22645  to store compiler generated temporary variables.
22646  This usually happens in large functions.
22647  Pragma directives should be used as shown in the following example, they
22648  are used to control options and optimizations for a given function.
22649  
22650 \end_layout
22651
22652 \begin_layout Verse
22653
22654 \family typewriter
22655 #pragma save
22656 \begin_inset LatexCommand \index{\#pragma save}
22657
22658 \end_inset
22659
22660  \InsetSpace ~
22661 \InsetSpace ~
22662 \InsetSpace ~
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 /* save the current settings */ 
22668 \newline
22669 #pragma nogcse
22670 \begin_inset LatexCommand \index{\#pragma nogcse}
22671
22672 \end_inset
22673
22674  \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 /* turnoff global subexpression elimination */ 
22680 \newline
22681 #pragma noinduction
22682 \begin_inset LatexCommand \index{\#pragma noinduction}
22683
22684 \end_inset
22685
22686  /* turn off induction optimizations */ 
22687 \newline
22688 int foo () 
22689 \newline
22690
22691 \newline
22692 \InsetSpace ~
22693  \InsetSpace ~
22694  ...
22695  
22696 \newline
22697 \InsetSpace ~
22698  \InsetSpace ~
22699  /* large code */ 
22700 \newline
22701 \InsetSpace ~
22702  \InsetSpace ~
22703  ...
22704  
22705 \newline
22706
22707 \newline
22708 #pragma restore
22709 \begin_inset LatexCommand \index{\#pragma restore}
22710
22711 \end_inset
22712
22713  /* turn the optimizations back on */
22714 \end_layout
22715
22716 \begin_layout Standard
22717 The compiler will generate a warning message when extra space is allocated.
22718  It is strongly recommended that the save and restore pragmas be used when
22719  changing options for a function.
22720 \newline
22721
22722 \newline
22723
22724 \newline
22725
22726 \end_layout
22727
22728 \begin_layout Section
22729 Defines Created by the Compiler
22730 \end_layout
22731
22732 \begin_layout Standard
22733 The compiler creates the following #defines
22734 \begin_inset LatexCommand \index{\#defines}
22735
22736 \end_inset
22737
22738
22739 \begin_inset LatexCommand \index{Defines created by the compiler}
22740
22741 \end_inset
22742
22743 :
22744 \newline
22745
22746 \end_layout
22747
22748 \begin_layout Standard
22749 \begin_inset Tabular
22750 <lyxtabular version="3" rows="15" columns="2">
22751 <features>
22752 <column alignment="left" valignment="top" leftline="true" width="3in">
22753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22754 <row topline="true" bottomline="true">
22755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22756 \begin_inset Text
22757
22758 \begin_layout Standard
22759
22760 \series bold
22761 #define
22762 \end_layout
22763
22764 \end_inset
22765 </cell>
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22767 \begin_inset Text
22768
22769 \begin_layout Standard
22770
22771 \series bold
22772 Description
22773 \end_layout
22774
22775 \end_inset
22776 </cell>
22777 </row>
22778 <row topline="true">
22779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22780 \begin_inset Text
22781
22782 \begin_layout Standard
22783 SDCC
22784 \begin_inset LatexCommand \index{SDCC}
22785
22786 \end_inset
22787
22788  
22789 \end_layout
22790
22791 \end_inset
22792 </cell>
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22794 \begin_inset Text
22795
22796 \begin_layout Standard
22797 Always defined.
22798  Since version 2.5.6 the version number as an int (ex.
22799  256)
22800 \end_layout
22801
22802 \end_inset
22803 </cell>
22804 </row>
22805 <row topline="true">
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 \begin_inset Text
22808
22809 \begin_layout Standard
22810 SDCC_mcs51
22811 \begin_inset LatexCommand \index{SDCC\_mcs51}
22812
22813 \end_inset
22814
22815  or SDCC_ds390
22816 \begin_inset LatexCommand \index{SDCC\_ds390}
22817
22818 \end_inset
22819
22820  or SDCC_z80
22821 \begin_inset LatexCommand \index{SDCC\_z80}
22822
22823 \end_inset
22824
22825 , etc.
22826 \end_layout
22827
22828 \end_inset
22829 </cell>
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22831 \begin_inset Text
22832
22833 \begin_layout Standard
22834 depending on the model used (e.g.: -mds390)
22835 \end_layout
22836
22837 \end_inset
22838 </cell>
22839 </row>
22840 <row topline="true">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22842 \begin_inset Text
22843
22844 \begin_layout Standard
22845 __mcs51
22846 \begin_inset LatexCommand \index{\_\_mcs51}
22847
22848 \end_inset
22849
22850 , __ds390
22851 \begin_inset LatexCommand \index{\_\_ds390}
22852
22853 \end_inset
22854
22855 , __hc08
22856 \begin_inset LatexCommand \index{\_\_hc08}
22857
22858 \end_inset
22859
22860 , __z80
22861 \begin_inset LatexCommand \index{\_\_z80}
22862
22863 \end_inset
22864
22865 , etc
22866 \end_layout
22867
22868 \end_inset
22869 </cell>
22870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22871 \begin_inset Text
22872
22873 \begin_layout Standard
22874 depending on the model used (e.g.
22875  -mz80)
22876 \end_layout
22877
22878 \end_inset
22879 </cell>
22880 </row>
22881 <row topline="true">
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22883 \begin_inset Text
22884
22885 \begin_layout Standard
22886 SDCC_STACK_AUTO
22887 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22888
22889 \end_inset
22890
22891
22892 \end_layout
22893
22894 \end_inset
22895 </cell>
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22897 \begin_inset Text
22898
22899 \begin_layout Standard
22900 when 
22901 \emph on
22902 -
22903 \begin_inset ERT
22904 status collapsed
22905
22906 \begin_layout Standard
22907
22908
22909 \backslash
22910 /
22911 \end_layout
22912
22913 \end_inset
22914
22915 -stack-auto
22916 \emph default
22917  option is used
22918 \end_layout
22919
22920 \end_inset
22921 </cell>
22922 </row>
22923 <row topline="true">
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22925 \begin_inset Text
22926
22927 \begin_layout Standard
22928 SDCC_MODEL_SMALL
22929 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22930
22931 \end_inset
22932
22933
22934 \end_layout
22935
22936 \end_inset
22937 </cell>
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22939 \begin_inset Text
22940
22941 \begin_layout Standard
22942 when 
22943 \emph on
22944 -
22945 \begin_inset ERT
22946 status collapsed
22947
22948 \begin_layout Standard
22949
22950
22951 \backslash
22952 /
22953 \end_layout
22954
22955 \end_inset
22956
22957 -model-small
22958 \emph default
22959  is used
22960 \end_layout
22961
22962 \end_inset
22963 </cell>
22964 </row>
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22967 \begin_inset Text
22968
22969 \begin_layout Standard
22970 SDCC_MODEL_MEDIUM
22971 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22972
22973 \end_inset
22974
22975
22976 \end_layout
22977
22978 \end_inset
22979 </cell>
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22981 \begin_inset Text
22982
22983 \begin_layout Standard
22984 when 
22985 \emph on
22986 -
22987 \begin_inset ERT
22988 status collapsed
22989
22990 \begin_layout Standard
22991
22992
22993 \backslash
22994 /
22995 \end_layout
22996
22997 \end_inset
22998
22999 -model-medium
23000 \emph default
23001  is used
23002 \end_layout
23003
23004 \end_inset
23005 </cell>
23006 </row>
23007 <row topline="true">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 SDCC_MODEL_LARGE
23013 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23014
23015 \end_inset
23016
23017
23018 \end_layout
23019
23020 \end_inset
23021 </cell>
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23023 \begin_inset Text
23024
23025 \begin_layout Standard
23026 when 
23027 \emph on
23028 -
23029 \begin_inset ERT
23030 status collapsed
23031
23032 \begin_layout Standard
23033
23034
23035 \backslash
23036 /
23037 \end_layout
23038
23039 \end_inset
23040
23041 -model-large
23042 \emph default
23043  is used
23044 \end_layout
23045
23046 \end_inset
23047 </cell>
23048 </row>
23049 <row topline="true">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \begin_layout Standard
23054 SDCC_USE_XSTACK
23055 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23056
23057 \end_inset
23058
23059
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 when 
23069 \emph on
23070 -
23071 \begin_inset ERT
23072 status collapsed
23073
23074 \begin_layout Standard
23075
23076
23077 \backslash
23078 /
23079 \end_layout
23080
23081 \end_inset
23082
23083 -xstack
23084 \emph default
23085  option is used
23086 \end_layout
23087
23088 \end_inset
23089 </cell>
23090 </row>
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 \begin_inset Text
23094
23095 \begin_layout Standard
23096 SDCC_STACK_TENBIT
23097 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23098
23099 \end_inset
23100
23101  
23102 \end_layout
23103
23104 \end_inset
23105 </cell>
23106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23107 \begin_inset Text
23108
23109 \begin_layout Standard
23110 when 
23111 \emph on
23112 -mds390
23113 \emph default
23114  is used
23115 \end_layout
23116
23117 \end_inset
23118 </cell>
23119 </row>
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23122 \begin_inset Text
23123
23124 \begin_layout Standard
23125 SDCC_MODEL_FLAT24
23126 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23127
23128 \end_inset
23129
23130
23131 \end_layout
23132
23133 \end_inset
23134 </cell>
23135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23136 \begin_inset Text
23137
23138 \begin_layout Standard
23139 when 
23140 \emph on
23141 -mds390
23142 \emph default
23143  is used
23144 \end_layout
23145
23146 \end_inset
23147 </cell>
23148 </row>
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_inset Text
23152
23153 \begin_layout Standard
23154 SDCC_REVISION
23155 \begin_inset LatexCommand \index{SDCC\_REVISION}
23156
23157 \end_inset
23158
23159
23160 \end_layout
23161
23162 \end_inset
23163 </cell>
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23165 \begin_inset Text
23166
23167 \begin_layout Standard
23168 Always defined.
23169  SDCC svn revision number
23170 \end_layout
23171
23172 \end_inset
23173 </cell>
23174 </row>
23175 <row topline="true">
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 SDCC_PARMS_IN_BANK1
23181 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23182
23183 \end_inset
23184
23185
23186 \end_layout
23187
23188 \end_inset
23189 </cell>
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23191 \begin_inset Text
23192
23193 \begin_layout Standard
23194 when 
23195 \emph on
23196 -
23197 \begin_inset ERT
23198 status collapsed
23199
23200 \begin_layout Standard
23201
23202
23203 \backslash
23204 /
23205 \end_layout
23206
23207 \end_inset
23208
23209 -parms-in-bank1
23210 \emph default
23211  is used
23212 \end_layout
23213
23214 \end_inset
23215 </cell>
23216 </row>
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23219 \begin_inset Text
23220
23221 \begin_layout Standard
23222 SDCC_FLOAT_REENT
23223 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23224
23225 \end_inset
23226
23227
23228 \end_layout
23229
23230 \end_inset
23231 </cell>
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23233 \begin_inset Text
23234
23235 \begin_layout Standard
23236 when 
23237 \emph on
23238 -
23239 \begin_inset ERT
23240 status collapsed
23241
23242 \begin_layout Standard
23243
23244
23245 \backslash
23246 /
23247 \end_layout
23248
23249 \end_inset
23250
23251 -float-reent
23252 \emph default
23253  is used
23254 \end_layout
23255
23256 \end_inset
23257 </cell>
23258 </row>
23259 <row topline="true" bottomline="true">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \begin_layout Standard
23264 SDCC_INT_LONG_REENT
23265 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23266
23267 \end_inset
23268
23269
23270 \end_layout
23271
23272 \end_inset
23273 </cell>
23274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23275 \begin_inset Text
23276
23277 \begin_layout Standard
23278 when 
23279 \emph on
23280 -
23281 \begin_inset ERT
23282 status collapsed
23283
23284 \begin_layout Standard
23285
23286
23287 \backslash
23288 /
23289 \end_layout
23290
23291 \end_inset
23292
23293 -int-long-reent
23294 \emph default
23295  is used
23296 \end_layout
23297
23298 \end_inset
23299 </cell>
23300 </row>
23301 </lyxtabular>
23302
23303 \end_inset
23304
23305
23306 \end_layout
23307
23308 \begin_layout Chapter
23309 Notes on supported Processors
23310 \end_layout
23311
23312 \begin_layout Section
23313 MCS51 variants
23314 \begin_inset LatexCommand \label{sub:MCS51-variants}
23315
23316 \end_inset
23317
23318
23319 \begin_inset LatexCommand \index{MCS51 variants}
23320
23321 \end_inset
23322
23323
23324 \end_layout
23325
23326 \begin_layout Standard
23327 MCS51 processors are available from many vendors and come in many different
23328  flavours.
23329  While they might differ considerably in respect to Special Function Registers
23330  the core MCS51 is usually not modified or is kept compatible.
23331  
23332 \end_layout
23333
23334 \begin_layout Subsection
23335 pdata access by SFR 
23336 \end_layout
23337
23338 \begin_layout Standard
23339 With the upcome of devices with internal xdata and flash memory devices
23340  using port P2
23341 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23342
23343 \end_inset
23344
23345  as dedicated I/O port is becoming more popular.
23346  Switching the high byte for pdata
23347 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23348
23349 \end_inset
23350
23351  access which was formerly done by port P2 is then achieved by a Special
23352  Function Register
23353 \begin_inset LatexCommand \index{sfr}
23354
23355 \end_inset
23356
23357 .
23358  In well-established MCS51 tradition the address of this 
23359 \emph on
23360 sfr
23361 \emph default
23362  is where the chip designers decided to put it.
23363  Needless to say that they didn't agree on a common name either.
23364  So that the startup code can correctly initialize xdata variables, you
23365  should define an sfr with the name _XPAGE
23366 \family typewriter
23367
23368 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23369
23370 \end_inset
23371
23372
23373 \family default
23374  at the appropriate location if the default, port P2, is not used for this.
23375  Some examples are:
23376 \end_layout
23377
23378 \begin_layout Verse
23379
23380 \family typewriter
23381 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23382  MPAGE */
23383 \end_layout
23384
23385 \begin_layout Verse
23386
23387 \family typewriter
23388 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23389  a.k.a.
23390  MPAGE */
23391 \end_layout
23392
23393 \begin_layout Verse
23394
23395 \family typewriter
23396 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23397  XPAGE */
23398 \end_layout
23399
23400 \begin_layout Verse
23401
23402 \family typewriter
23403 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23404  EMI0CN */
23405 \end_layout
23406
23407 \begin_layout Verse
23408
23409 \family typewriter
23410 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23411  EMI0CN */
23412 \end_layout
23413
23414 \begin_layout Standard
23415 For more exotic implementations further customizations may be needed.
23416  See section 
23417 \begin_inset LatexCommand \ref{sub:Startup-Code}
23418
23419 \end_inset
23420
23421  for other possibilities.
23422 \end_layout
23423
23424 \begin_layout Subsection
23425 Other Features available by SFR
23426 \end_layout
23427
23428 \begin_layout Standard
23429 Some MCS51 variants offer features like Double DPTR
23430 \begin_inset LatexCommand \index{DPTR}
23431
23432 \end_inset
23433
23434 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23435  These are currently not used for the MCS51 port.
23436  If you absolutely need them you can fall back to inline assembly or submit
23437  a patch to SDCC.
23438 \end_layout
23439
23440 \begin_layout Subsection
23441 Bankswitching
23442 \end_layout
23443
23444 \begin_layout Standard
23445 Bankswitching
23446 \begin_inset LatexCommand \index{Bankswitching}
23447
23448 \end_inset
23449
23450  (a.k.a.
23451  code banking
23452 \begin_inset LatexCommand \index{code banking}
23453
23454 \end_inset
23455
23456 ) is a technique to increase the code space above the 64k limit of the 8051.
23457 \end_layout
23458
23459 \begin_layout Subsubsection
23460 Hardware
23461 \end_layout
23462
23463 \begin_layout Standard
23464 \begin_inset Tabular
23465 <lyxtabular version="3" rows="3" columns="4">
23466 <features>
23467 <column alignment="center" valignment="top" width="0">
23468 <column alignment="center" valignment="top" leftline="true" width="0">
23469 <column alignment="center" valignment="top" leftline="true" width="0">
23470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23471 <row topline="true" bottomline="true">
23472 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23473 \begin_inset Text
23474
23475 \begin_layout Standard
23476 \paragraph_spacing other 0.5
23477 8000-FFFF
23478 \end_layout
23479
23480 \end_inset
23481 </cell>
23482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23483 \begin_inset Text
23484
23485 \begin_layout Standard
23486 bank 1
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 bank 2
23496 \end_layout
23497
23498 \end_inset
23499 </cell>
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23501 \begin_inset Text
23502
23503 \begin_layout Standard
23504 bank 3
23505 \end_layout
23506
23507 \end_inset
23508 </cell>
23509 </row>
23510 <row topline="true" bottomline="true">
23511 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23512 \begin_inset Text
23513
23514 \begin_layout Standard
23515 0000-7FFF
23516 \end_layout
23517
23518 \end_inset
23519 </cell>
23520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23521 \begin_inset Text
23522
23523 \begin_layout Standard
23524 common
23525 \end_layout
23526
23527 \end_inset
23528 </cell>
23529 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23530 \begin_inset Text
23531
23532 \begin_layout Standard
23533
23534 \end_layout
23535
23536 \end_inset
23537 </cell>
23538 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23539 \begin_inset Text
23540
23541 \begin_layout Standard
23542
23543 \end_layout
23544
23545 \end_inset
23546 </cell>
23547 </row>
23548 <row>
23549 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23550 \begin_inset Text
23551
23552 \begin_layout Standard
23553 SiLabs C8051F120 example
23554 \end_layout
23555
23556 \end_inset
23557 </cell>
23558 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23559 \begin_inset Text
23560
23561 \begin_layout Standard
23562
23563 \end_layout
23564
23565 \end_inset
23566 </cell>
23567 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" 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 </row>
23586 </lyxtabular>
23587
23588 \end_inset
23589
23590
23591 \newline
23592
23593 \newline
23594 Usually the hardware uses some sfr (an output port or an internal sfr) to
23595  select a bank and put it in the banked area of the memory map.
23596  Because the selected bank usually becomes active immediately you cannot
23597  jump call directly from one bank to another and need to use a so-called
23598  trampoline in the common area.
23599  For SDCC an example trampoline is in crtbank.asm and you may need to change
23600  it to your 8051 derivative or schematic.
23601  The presented code is written for the C8051F120.
23602 \newline
23603
23604 \newline
23605 When calling a banked function
23606  SDCC will put the LSB of the functions address in register R0, the MSB
23607  in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
23608  The current selected bank is saved on the stack, the new bank is selected
23609  and an indirect jump is made.
23610  When the banked function returns it jumps to __sdcc_banked_ret which restores
23611  the previous bank and returns to the caller.
23612 \end_layout
23613
23614 \begin_layout Subsubsection
23615 Software
23616 \end_layout
23617
23618 \begin_layout Standard
23619 When writing banked software using SDCC you need to use some special keywords
23620  and options.
23621  You also need to take over a bit of work from the linker.
23622 \newline
23623
23624 \newline
23625 To create a function
23626  that can be called from another bank it requires the keyword banked.
23627  The caller must see this in the prototype of the callee and the callee
23628  needs it for a proper return.
23629  Called functions within the same bank as the caller do not need the banked
23630  keyword nor do functions in the common area.
23631  Beware: SDCC does not know or check if functions are in the same bank.
23632  This is your responsibility!
23633 \newline
23634
23635 \newline
23636 Normally all functions you write end up in
23637  the segment CSEG.
23638  If you want a function explicitly to reside in the common area put it in
23639  segment HOME.
23640  This applies for instance to interrupt service routines as they should
23641  not be banked.
23642 \end_layout
23643
23644 \begin_layout Standard
23645 Functions that need to be in a switched bank must be put in a named segment.
23646  The name can be mostly anything upto eight characters (e.g.
23647  BANK1).
23648  To do this you either use --codeseg BANK1 on the command line when compiling
23649  or #pragma codeseg BANK1 at the top of the C source file.
23650  The segment name always applies to the whole source file and generated
23651  object so functions for different banks need to be defined in different
23652  source files.
23653 \newline
23654
23655 \newline
23656 When linking your objects you need to tell the linker where
23657  to put your segments.
23658  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23659 00.
23660  This sets the virtual start address of this segment.
23661  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23662  The linker will not check for overflows, again this is your responsibility.
23663 \end_layout
23664
23665 \begin_layout Standard
23666 \begin_inset VSpace bigskip
23667 \end_inset
23668
23669
23670 \end_layout
23671
23672 \begin_layout Section
23673 DS400 port
23674 \end_layout
23675
23676 \begin_layout Standard
23677 The DS80C400
23678 \begin_inset LatexCommand \index{DS80C400}
23679
23680 \end_inset
23681
23682
23683 \begin_inset LatexCommand \index{DS400}
23684
23685 \end_inset
23686
23687  microcontroller has a rich set of peripherals.
23688  In its built-in ROM library it includes functions to access some of the
23689  features, among them is a TCP stack with IP4 and IP6 support.
23690  Library headers (currently in beta status) and other files are provided
23691  at 
23692 \size footnotesize
23693
23694 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23695
23696 \end_inset
23697
23698 .
23699  
23700 \begin_inset VSpace bigskip
23701 \end_inset
23702
23703
23704 \end_layout
23705
23706 \begin_layout Section
23707 The Z80 and gbz80 port
23708 \end_layout
23709
23710 \begin_layout Standard
23711 SDCC can target both the Zilog Z80
23712 \begin_inset LatexCommand \index{Z80}
23713
23714 \end_inset
23715
23716  and the Nintendo Gameboy's Z80-like gbz80
23717 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23718
23719 \end_inset
23720
23721 .
23722  The Z80 port is passed through the same 
23723 \emph on
23724 regressions tests
23725 \begin_inset LatexCommand \index{Regression test}
23726
23727 \end_inset
23728
23729
23730 \emph default
23731  (see section 
23732 \begin_inset LatexCommand \ref{sec:Quality-control}
23733
23734 \end_inset
23735
23736 ) as the MCS51 and DS390 ports, so floating point support, support for long
23737  variables and bitfield support is fine.
23738  See mailing lists and forums about interrupt routines.
23739 \end_layout
23740
23741 \begin_layout Standard
23742 As always, the code is the authoritative reference - see z80/ralloc.c and
23743  z80/gen.c.
23744  The stack
23745 \begin_inset LatexCommand \index{Z80!stack}
23746
23747 \end_inset
23748
23749  frame is similar to that generated by the IAR Z80 compiler.
23750  IX is used as the base pointer, HL and IY are used as a temporary registers,
23751  and BC and DE are available for holding variables.
23752  Return values
23753 \begin_inset LatexCommand \index{Z80!return value}
23754
23755 \end_inset
23756
23757  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23758  bytes).
23759  The gbz80 port use the same set of registers for the return values, but
23760  in a different order of significance: E (one byte), DE (two bytes), or
23761  HLDE (four bytes).
23762 \begin_inset VSpace bigskip
23763 \end_inset
23764
23765
23766 \end_layout
23767
23768 \begin_layout Section
23769 The HC08 port
23770 \end_layout
23771
23772 \begin_layout Standard
23773 The port to the Freescale/Motorola HC08
23774 \begin_inset LatexCommand \index{HC08}
23775
23776 \end_inset
23777
23778  family has been added in October 2003, and is still undergoing some basic
23779  development.
23780  The code generator is complete, but the register allocation is still quite
23781  unoptimized.
23782  Some of the SDCC's standard C library functions have embedded non-HC08
23783  inline assembly and so are not yet usable.
23784 \end_layout
23785
23786 \begin_layout Standard
23787 The HC08 port passes the regression test suite (see section 
23788 \begin_inset LatexCommand \ref{sec:Quality-control}
23789
23790 \end_inset
23791
23792 ).
23793 \begin_inset VSpace bigskip
23794 \end_inset
23795
23796
23797 \newpage
23798
23799 \end_layout
23800
23801 \begin_layout Section
23802 The PIC14
23803 \begin_inset LatexCommand \index{PIC14}
23804
23805 \end_inset
23806
23807  port
23808 \end_layout
23809
23810 \begin_layout Standard
23811 The PIC14 port adds support for Microchip
23812 \begin_inset LatexCommand \index{Microchip}
23813
23814 \end_inset
23815
23816
23817 \begin_inset Formula $^{\text{TM}}$
23818 \end_inset
23819
23820  PIC
23821 \begin_inset LatexCommand \index{PIC14}
23822
23823 \end_inset
23824
23825
23826 \begin_inset Formula $^{\text{TM}}$
23827 \end_inset
23828
23829  MCUs with 14 bit wide instructions.
23830  This port is not yet mature and still lacks many features.
23831  However, it can work for simple code.
23832 \end_layout
23833
23834 \begin_layout Standard
23835 Currently supported devices include:
23836 \end_layout
23837
23838 \begin_layout Standard
23839 12F: 629, 635, 675, 683
23840 \end_layout
23841
23842 \begin_layout Standard
23843 16C: 432, 433
23844 \end_layout
23845
23846 \begin_layout Standard
23847 16C: 554, 557, 558
23848 \end_layout
23849
23850 \begin_layout Standard
23851 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23852 \end_layout
23853
23854 \begin_layout Standard
23855 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23856  781, 782
23857 \end_layout
23858
23859 \begin_layout Standard
23860 16C: 925, 926
23861 \end_layout
23862
23863 \begin_layout Standard
23864 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23865  689, 690
23866 \end_layout
23867
23868 \begin_layout Standard
23869 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23870 \end_layout
23871
23872 \begin_layout Standard
23873 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23874  877, 877a, 88
23875 \end_layout
23876
23877 \begin_layout Standard
23878 16F: 913, 914, 916, 917
23879 \end_layout
23880
23881 \begin_layout Standard
23882 An up-to-date list of currently supported devices can be obtained via 
23883 \family typewriter
23884 sdcc -mpic14 -phelp foo.c
23885 \family default
23886  (foo.c must exist...).
23887 \end_layout
23888
23889 \begin_layout Subsection
23890 PIC Code Pages
23891 \begin_inset LatexCommand \index{code page (pic14)}
23892
23893 \end_inset
23894
23895  and Memory Banks
23896 \begin_inset LatexCommand \index{Memory bank (pic14)}
23897
23898 \end_inset
23899
23900
23901 \end_layout
23902
23903 \begin_layout Standard
23904 The linker organizes allocation for the code page and RAM banks.
23905  It does not have intimate knowledge of the code flow.
23906  It will put all the code section of a single .asm file into a single code
23907  page.
23908  In order to make use of multiple code pages, separate asm files must be
23909  used.
23910  The compiler assigns all 
23911 \emph on
23912 static
23913 \emph default
23914  functions of a single .c file into the same code page.
23915 \newline
23916
23917 \newline
23918 To get the best results,
23919  follow these guidelines:
23920 \end_layout
23921
23922 \begin_layout Enumerate
23923 Make local functions static, as non static functions require code page selection
23924  overhead.
23925 \newline
23926 Due to the way sdcc handles functions, place called functions prior
23927  to calling functions in the file wherever possible: Otherwise sdcc will
23928  insert unneccessary pagesel directives around the call, believing that
23929  the called function is externally defined.
23930 \end_layout
23931
23932 \begin_layout Enumerate
23933 For devices that have multiple code pages it is more efficient to use the
23934  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23935  but only 2 files for the 16F874.
23936  This way the linker can put the code for each file into different code
23937  pages and there will be less page selection overhead.
23938 \end_layout
23939
23940 \begin_layout Enumerate
23941 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23942  instruction set), use `unsigned char' wherever possible instead of `int'.
23943 \end_layout
23944
23945 \begin_layout Subsection
23946 Adding New Devices to the Port 
23947 \end_layout
23948
23949 \begin_layout Standard
23950 Adding support for a new 14
23951 \begin_inset ERT
23952 status open
23953
23954 \begin_layout Standard
23955
23956
23957 \backslash
23958 ,
23959 \end_layout
23960
23961 \end_inset
23962
23963 bit PIC MCU requires the following steps:
23964 \end_layout
23965
23966 \begin_layout Enumerate
23967 Create a new device description.
23968 \newline
23969 Each device is described in two files: pic16f*.h
23970  and pic16f*.c.
23971  These files primarily define SFRs, structs to access their bits, and symbolic
23972  configuration options.
23973  Both files can be generated from gputils' .inc files using the perl script
23974  
23975 \family typewriter
23976 support/scripts/inc2h.pl
23977 \family default
23978 .
23979  This file also contains further instructions on how to proceed.
23980 \end_layout
23981
23982 \begin_layout Enumerate
23983 Copy the .h file into SDCC's include path and either add the .c file to your
23984  project or copy it to 
23985 \family typewriter
23986 device/lib/pic/libdev
23987 \family default
23988 .
23989  Afterwards, rebuild and install the libraries.
23990 \end_layout
23991
23992 \begin_layout Enumerate
23993 Edit pic14devices.txt in SDCC's include path (
23994 \family typewriter
23995 device/include/pic/
23996 \family default
23997  in the source tree or 
23998 \family typewriter
23999 /usr/local/share/sdcc/include/pic
24000 \family default
24001  after installation).
24002 \newline
24003 You need to add a device specification here to make
24004  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24005  the compiler.
24006  Probably you can copy and modify an existing entry.
24007  The file format is documented at the top of the file.
24008 \end_layout
24009
24010 \begin_layout Subsection
24011 Interrupt Code
24012 \end_layout
24013
24014 \begin_layout Standard
24015 For the interrupt function, use the keyword `__interrupt'
24016 \begin_inset LatexCommand \index{PIC14!interrupt}
24017
24018 \end_inset
24019
24020  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24021  there to avoid a syntax error - it ought to be fixed).
24022  E.g.:
24023 \end_layout
24024
24025 \begin_layout Verse
24026
24027 \family typewriter
24028 void Intr(void) __interrupt 0
24029 \newline
24030 {
24031 \newline
24032 \InsetSpace ~
24033 \InsetSpace ~
24034 T0IF = 0; /* Clear timer interrupt */
24035 \newline
24036 }
24037 \end_layout
24038
24039 \begin_layout Subsection
24040 Linking and Assembling
24041 \end_layout
24042
24043 \begin_layout Standard
24044 For assembling you can use either GPUTILS'
24045 \begin_inset LatexCommand \index{gputils (pic tools)}
24046
24047 \end_inset
24048
24049  gpasm.exe or MPLAB's mpasmwin.exe.
24050  GPUTILS are available from 
24051 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24052
24053 \end_inset
24054
24055 .
24056  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24057  If you use MPLAB and an interrupt function then the linker script file
24058  vectors section will need to be enlarged to link with mplink.
24059 \newline
24060
24061 \newline
24062 Here is a 
24063 \family typewriter
24064 Makefile
24065 \family default
24066  using GPUTILS:
24067 \end_layout
24068
24069 \begin_layout Verse
24070
24071 \family typewriter
24072 .c.o:
24073 \newline
24074 \InsetSpace ~
24075 \InsetSpace ~
24076 \InsetSpace ~
24077 \InsetSpace ~
24078 \InsetSpace ~
24079 \InsetSpace ~
24080 \InsetSpace ~
24081 \InsetSpace ~
24082 sdcc -V -mpic14 -p16f877 -c $< 
24083 \newline
24084
24085 \newline
24086 $(PRJ).hex: $(OBJS) 
24087 \newline
24088 \InsetSpace ~
24089 \InsetSpace ~
24090 \InsetSpace ~
24091 \InsetSpace ~
24092 \InsetSpace ~
24093 \InsetSpace ~
24094 \InsetSpace ~
24095 \InsetSpace ~
24096 gplink -m -s $(PRJ).lkr
24097  -o $(PRJ).hex $(OBJS) libsdcc.lib
24098 \end_layout
24099
24100 \begin_layout Standard
24101 Here is a 
24102 \family typewriter
24103 Makefile
24104 \family default
24105  using MPLAB:
24106 \end_layout
24107
24108 \begin_layout Verse
24109
24110 \family typewriter
24111 .c.o: 
24112 \newline
24113 \InsetSpace ~
24114 \InsetSpace ~
24115 \InsetSpace ~
24116 \InsetSpace ~
24117 \InsetSpace ~
24118 \InsetSpace ~
24119 \InsetSpace ~
24120 \InsetSpace ~
24121 sdcc -S -V -mpic14 -p16f877 $< 
24122 \newline
24123 \InsetSpace ~
24124 \InsetSpace ~
24125 \InsetSpace ~
24126 \InsetSpace ~
24127 \InsetSpace ~
24128 \InsetSpace ~
24129 \InsetSpace ~
24130 \InsetSpace ~
24131 mpasmwin /q /o $*.asm
24132 \newline
24133
24134 \newline
24135 $(PRJ).hex: $(OBJS)
24136  
24137 \newline
24138 \InsetSpace ~
24139 \InsetSpace ~
24140 \InsetSpace ~
24141 \InsetSpace ~
24142 \InsetSpace ~
24143 \InsetSpace ~
24144 \InsetSpace ~
24145 \InsetSpace ~
24146 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24147 \end_layout
24148
24149 \begin_layout Standard
24150 Please note that indentations within a
24151 \family typewriter
24152  Makefile
24153 \family default
24154  have to be done with a tabulator character.
24155 \end_layout
24156
24157 \begin_layout Subsection
24158 Command-Line Options
24159 \end_layout
24160
24161 \begin_layout Standard
24162 Besides the switches common to all SDCC backends, the PIC14 port accepts
24163  the following options (for an updated list see sdcc -
24164 \begin_inset ERT
24165 status collapsed
24166
24167 \begin_layout Standard
24168
24169
24170 \backslash
24171 /
24172 \end_layout
24173
24174 \end_inset
24175
24176 -help):
24177 \end_layout
24178
24179 \begin_layout Description
24180 -
24181 \begin_inset ERT
24182 status collapsed
24183
24184 \begin_layout Standard
24185
24186
24187 \backslash
24188 /
24189 \end_layout
24190
24191 \end_inset
24192
24193 -debug-xtra
24194 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24195
24196 \end_inset
24197
24198  emit debug info in assembly output
24199 \end_layout
24200
24201 \begin_layout Description
24202 -
24203 \begin_inset ERT
24204 status collapsed
24205
24206 \begin_layout Standard
24207
24208
24209 \backslash
24210 /
24211 \end_layout
24212
24213 \end_inset
24214
24215 -no-pcode-opt
24216 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24217
24218 \end_inset
24219
24220  disable (slightly faulty) optimization on pCode
24221 \end_layout
24222
24223 \begin_layout Description
24224 -
24225 \begin_inset ERT
24226 status collapsed
24227
24228 \begin_layout Standard
24229
24230
24231 \backslash
24232 /
24233 \end_layout
24234
24235 \end_inset
24236
24237 -stack-loc
24238 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24239
24240 \end_inset
24241
24242  sets the lowest address of the argument passing stack (defaults to a suitably
24243  large shared databank to reduce BANKSEL overhead)
24244 \end_layout
24245
24246 \begin_layout Description
24247 -
24248 \begin_inset ERT
24249 status collapsed
24250
24251 \begin_layout Standard
24252
24253
24254 \backslash
24255 /
24256 \end_layout
24257
24258 \end_inset
24259
24260 -stack-size
24261 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24262
24263 \end_inset
24264
24265  sets the size if the argument passing stack (default: 16, minimum: 4)
24266 \end_layout
24267
24268 \begin_layout Subsection
24269 Environment Variables
24270 \end_layout
24271
24272 \begin_layout Standard
24273 The PIC14 port recognizes the following environment variables:
24274 \end_layout
24275
24276 \begin_layout Description
24277 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24278  register (the ones called r0xNNNN) in a section of its own.
24279  By default (if this variable is unset), sdcc tries to cluster registers
24280  in sections in order to reduce the BANKSEL overhead when accessing them.
24281 \end_layout
24282
24283 \begin_layout Subsection
24284 The Library
24285 \end_layout
24286
24287 \begin_layout Standard
24288 The PIC14 library currently only contains support routines required by the
24289  compiler to implement multiplication, division, and floating point support.
24290  No libc-like replacement is available at the moment, though many of the
24291  common sdcc library sources (in 
24292 \family typewriter
24293 device/lib
24294 \family default
24295 ) should also compile with the PIC14 port.
24296 \end_layout
24297
24298 \begin_layout Subsubsection
24299 error: missing definition for symbol ``__gptrget1''
24300 \end_layout
24301
24302 \begin_layout Standard
24303 The PIC14 port uses library routines to provide more complex operations
24304  like multiplication, division/modulus and (generic) pointer dereferencing.
24305  In order to add these routines to your project, you must link with PIC14's
24306  
24307 \family typewriter
24308 libsdcc.lib
24309 \family default
24310 .
24311  For single source file projects this is done automatically, more complex
24312  projects must add 
24313 \family typewriter
24314 libsdcc.lib
24315 \family default
24316  to the linker's arguments.
24317  Make sure you also add an include path for the library (using the -I switch
24318  to the linker)!
24319 \end_layout
24320
24321 \begin_layout Subsubsection
24322 Processor mismatch in file ``XXX''.
24323 \end_layout
24324
24325 \begin_layout Standard
24326 This warning can usually be ignored due to the very good compatibility amongst
24327  14
24328 \begin_inset ERT
24329 status open
24330
24331 \begin_layout Standard
24332
24333
24334 \backslash
24335 ,
24336 \end_layout
24337
24338 \end_inset
24339
24340 bit PIC
24341 \begin_inset LatexCommand \index{PIC14}
24342
24343 \end_inset
24344
24345  devices.
24346 \end_layout
24347
24348 \begin_layout Standard
24349 You might also consider recompiling the library for your specific device
24350  by changing the ARCH=p16f877 (default target) entry in 
24351 \family typewriter
24352 device/lib/pic/Makefile.in
24353 \family default
24354  and 
24355 \family typewriter
24356 device/lib/pic/Makefile
24357 \family default
24358  to reflect your device.
24359  This might even improve performance for smaller devices as unneccesary
24360  BANKSELs might be removed.
24361 \end_layout
24362
24363 \begin_layout Subsection
24364 Known Bugs
24365 \end_layout
24366
24367 \begin_layout Subsubsection
24368 Function arguments
24369 \end_layout
24370
24371 \begin_layout Standard
24372 Functions with variable argument lists (like printf) are not yet supported.
24373  Similarly, taking the argument of the first argument passed into a function
24374  does not work: It is currently passed in WREG and has no address...
24375 \end_layout
24376
24377 \begin_layout Subsubsection
24378 Regression tests fail
24379 \end_layout
24380
24381 \begin_layout Standard
24382 Though the small subset of regression tests in src/regression passes, SDCC
24383  regression test suite does not, indicating that there are still major bugs
24384  in the port.
24385  However, many smaller projects have successfully used SDCC in the past...
24386 \end_layout
24387
24388 \begin_layout Standard
24389
24390 \size footnotesize
24391
24392 \newpage
24393
24394 \end_layout
24395
24396 \begin_layout Section
24397 The PIC16
24398 \begin_inset LatexCommand \index{PIC16}
24399
24400 \end_inset
24401
24402  port
24403 \end_layout
24404
24405 \begin_layout Standard
24406 The PIC16 port adds support for Microchip
24407 \begin_inset LatexCommand \index{Microchip}
24408
24409 \end_inset
24410
24411
24412 \begin_inset Formula $^{\text{TM}}$
24413 \end_inset
24414
24415  PIC
24416 \begin_inset LatexCommand \index{PIC}
24417
24418 \end_inset
24419
24420
24421 \begin_inset Formula $^{\text{TM}}$
24422 \end_inset
24423
24424  MCUs with 16 bit wide instructions.
24425  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24426 ; devices supported by the port include:
24427 \end_layout
24428
24429 \begin_layout Standard
24430 18F: 242, 248, 252, 258, 442, 448, 452, 458
24431 \end_layout
24432
24433 \begin_layout Standard
24434 18F: 1220, 1320
24435 \end_layout
24436
24437 \begin_layout Standard
24438 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24439  2620
24440 \end_layout
24441
24442 \begin_layout Standard
24443 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24444  45j10, 4620
24445 \end_layout
24446
24447 \begin_layout Standard
24448 18F: 6520, 6620, 6680, 6720
24449 \end_layout
24450
24451 \begin_layout Standard
24452 18F: 8520, 8620, 8680, 8720
24453 \end_layout
24454
24455 \begin_layout Subsection
24456 Global Options
24457 \end_layout
24458
24459 \begin_layout Standard
24460 PIC16 port supports the standard command line arguments as supposed, with
24461  the exception of certain cases that will be mentioned in the following
24462  list:
24463 \end_layout
24464
24465 \begin_layout Description
24466 -
24467 \begin_inset ERT
24468 status collapsed
24469
24470 \begin_layout Standard
24471
24472
24473 \backslash
24474 /
24475 \end_layout
24476
24477 \end_inset
24478
24479 -callee-saves
24480 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24481
24482 \end_inset
24483
24484  See -
24485 \begin_inset ERT
24486 status collapsed
24487
24488 \begin_layout Standard
24489
24490
24491 \backslash
24492 /
24493 \end_layout
24494
24495 \end_inset
24496
24497 -all-callee-saves
24498 \end_layout
24499
24500 \begin_layout Description
24501 -
24502 \begin_inset ERT
24503 status collapsed
24504
24505 \begin_layout Standard
24506
24507
24508 \backslash
24509 /
24510 \end_layout
24511
24512 \end_inset
24513
24514 -fommit-frame-pointer
24515 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24516
24517 \end_inset
24518
24519  Frame pointer will be omitted when the function uses no local variables.
24520 \end_layout
24521
24522 \begin_layout Subsection
24523 Port Specific Options
24524 \begin_inset LatexCommand \index{Options PIC16}
24525
24526 \end_inset
24527
24528
24529 \end_layout
24530
24531 \begin_layout Standard
24532 The port specific options appear after the global options in the sdcc -
24533 \begin_inset ERT
24534 status collapsed
24535
24536 \begin_layout Standard
24537
24538
24539 \backslash
24540 /
24541 \end_layout
24542
24543 \end_inset
24544
24545 -help output.
24546 \end_layout
24547
24548 \begin_layout Subsubsection
24549 Code Generation Options
24550 \end_layout
24551
24552 \begin_layout Standard
24553 These options influence the generated assembler code.
24554 \end_layout
24555
24556 \begin_layout Description
24557 -
24558 \begin_inset ERT
24559 status collapsed
24560
24561 \begin_layout Standard
24562
24563
24564 \backslash
24565 /
24566 \end_layout
24567
24568 \end_inset
24569
24570 -pstack-model=[model] Used in conjuction with the command above.
24571  Defines the stack model to be used, valid stack models are:
24572 \end_layout
24573
24574 \begin_deeper
24575 \begin_layout List
24576 \labelwidthstring 00.00.0000
24577
24578 \emph on
24579 small
24580 \emph default
24581  Selects small stack model.
24582  8 bit stack and frame pointers.
24583  Supports 256 bytes stack size.
24584 \end_layout
24585
24586 \begin_layout List
24587 \labelwidthstring 00.00.0000
24588
24589 \emph on
24590 large
24591 \emph default
24592  Selects large stack model.
24593  16 bit stack and frame pointers.
24594  Supports 65536 bytes stack size.
24595 \end_layout
24596
24597 \end_deeper
24598 \begin_layout Description
24599 -
24600 \begin_inset ERT
24601 status collapsed
24602
24603 \begin_layout Standard
24604
24605
24606 \backslash
24607 /
24608 \end_layout
24609
24610 \end_inset
24611
24612 -pno-banksel Do not generate BANKSEL assembler directives.
24613 \end_layout
24614
24615 \begin_layout Description
24616 -
24617 \begin_inset ERT
24618 status collapsed
24619
24620 \begin_layout Standard
24621
24622
24623 \backslash
24624 /
24625 \end_layout
24626
24627 \end_inset
24628
24629 -extended Enable extended instruction set/literal offset addressing mode.
24630  Use with care!
24631 \end_layout
24632
24633 \begin_layout Subsubsection
24634 Optimization Options
24635 \end_layout
24636
24637 \begin_layout Description
24638 -
24639 \begin_inset ERT
24640 status collapsed
24641
24642 \begin_layout Standard
24643
24644
24645 \backslash
24646 /
24647 \end_layout
24648
24649 \end_inset
24650
24651 -obanksel=n Set optimization level for inserting BANKSELs.
24652 \newline
24653
24654 \end_layout
24655
24656 \begin_deeper
24657 \begin_layout List
24658 \labelwidthstring 00.00.0000
24659 0 no optimization
24660 \end_layout
24661
24662 \begin_layout List
24663 \labelwidthstring 00.00.0000
24664 1 checks previous used register and if it is the same then does not emit
24665  BANKSEL, accounts only for labels.
24666 \end_layout
24667
24668 \begin_layout List
24669 \labelwidthstring 00.00.0000
24670 2 tries to check the location of (even different) symbols and removes BANKSELs
24671  if they are in the same bank.
24672  
24673 \newline
24674
24675 \emph on
24676 Important: There might be problems if the linker script has data sections
24677  across bank borders!
24678 \end_layout
24679
24680 \end_deeper
24681 \begin_layout Description
24682 -
24683 \begin_inset ERT
24684 status collapsed
24685
24686 \begin_layout Standard
24687
24688
24689 \backslash
24690 /
24691 \end_layout
24692
24693 \end_inset
24694
24695 -denable-peeps Force the usage of peepholes.
24696  Use with care.
24697 \end_layout
24698
24699 \begin_layout Description
24700 -
24701 \begin_inset ERT
24702 status collapsed
24703
24704 \begin_layout Standard
24705
24706
24707 \backslash
24708 /
24709 \end_layout
24710
24711 \end_inset
24712
24713 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24714 \end_layout
24715
24716 \begin_layout Description
24717 -
24718 \begin_inset ERT
24719 status collapsed
24720
24721 \begin_layout Standard
24722
24723
24724 \backslash
24725 /
24726 \end_layout
24727
24728 \end_inset
24729
24730 -optimize-cmp Try to optimize some compares.
24731 \end_layout
24732
24733 \begin_layout Description
24734 -
24735 \begin_inset ERT
24736 status collapsed
24737
24738 \begin_layout Standard
24739
24740
24741 \backslash
24742 /
24743 \end_layout
24744
24745 \end_inset
24746
24747 -optimize-df Analyze the dataflow of the generated code and improve it.
24748 \end_layout
24749
24750 \begin_layout Subsubsection
24751 Assembling Options
24752 \end_layout
24753
24754 \begin_layout Description
24755 -
24756 \begin_inset ERT
24757 status collapsed
24758
24759 \begin_layout Standard
24760
24761
24762 \backslash
24763 /
24764 \end_layout
24765
24766 \end_inset
24767
24768 -asm= Sets the full path and name of an external assembler to call.
24769 \end_layout
24770
24771 \begin_layout Description
24772 -
24773 \begin_inset ERT
24774 status collapsed
24775
24776 \begin_layout Standard
24777
24778
24779 \backslash
24780 /
24781 \end_layout
24782
24783 \end_inset
24784
24785 -mplab-comp MPLAB
24786 \begin_inset LatexCommand \index{PIC16!MPLAB}
24787
24788 \end_inset
24789
24790  compatibility option.
24791  Currently only suppresses special gpasm directives.
24792 \end_layout
24793
24794 \begin_layout Subsubsection
24795 Linking Options
24796 \end_layout
24797
24798 \begin_layout Description
24799 -
24800 \begin_inset ERT
24801 status collapsed
24802
24803 \begin_layout Standard
24804
24805
24806 \backslash
24807 /
24808 \end_layout
24809
24810 \end_inset
24811
24812 -link= Sets the full path and name of an external linker to call.
24813 \end_layout
24814
24815 \begin_layout Description
24816 -
24817 \begin_inset ERT
24818 status collapsed
24819
24820 \begin_layout Standard
24821
24822
24823 \backslash
24824 /
24825 \end_layout
24826
24827 \end_inset
24828
24829 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24830  unitialized data variables with [kword].
24831  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
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 -ivt-loc=n Place the interrupt vector table at address 
24849 \emph on
24850 n
24851 \emph default
24852 .
24853  Useful for bootloaders.
24854 \end_layout
24855
24856 \begin_layout Description
24857 -
24858 \begin_inset ERT
24859 status collapsed
24860
24861 \begin_layout Standard
24862
24863
24864 \backslash
24865 /
24866 \end_layout
24867
24868 \end_inset
24869
24870 -nodefaultlibs Do not link default libraries when linking.
24871 \end_layout
24872
24873 \begin_layout Description
24874 -
24875 \begin_inset ERT
24876 status collapsed
24877
24878 \begin_layout Standard
24879
24880
24881 \backslash
24882 /
24883 \end_layout
24884
24885 \end_inset
24886
24887 -use-crt= Use a custom run-time module instead of the defaults.
24888 \end_layout
24889
24890 \begin_layout Description
24891 -
24892 \begin_inset ERT
24893 status collapsed
24894
24895 \begin_layout Standard
24896
24897
24898 \backslash
24899 /
24900 \end_layout
24901
24902 \end_inset
24903
24904 -no-crt Don't link the default run-time modules
24905 \end_layout
24906
24907 \begin_layout Subsubsection
24908 Debugging Options
24909 \end_layout
24910
24911 \begin_layout Standard
24912 Debugging options enable extra debugging information in the output files.
24913 \end_layout
24914
24915 \begin_layout Description
24916 -
24917 \begin_inset ERT
24918 status collapsed
24919
24920 \begin_layout Standard
24921
24922
24923 \backslash
24924 /
24925 \end_layout
24926
24927 \end_inset
24928
24929 -debug-xtra Similar to -
24930 \begin_inset ERT
24931 status collapsed
24932
24933 \begin_layout Standard
24934
24935
24936 \backslash
24937 /
24938 \end_layout
24939
24940 \end_inset
24941
24942 -debug
24943 \begin_inset LatexCommand \index{-\/-debug}
24944
24945 \end_inset
24946
24947 , but dumps more information.
24948 \end_layout
24949
24950 \begin_layout Description
24951 -
24952 \begin_inset ERT
24953 status collapsed
24954
24955 \begin_layout Standard
24956
24957
24958 \backslash
24959 /
24960 \end_layout
24961
24962 \end_inset
24963
24964 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24965  information.
24966  <source> is the name of the file being compiled.
24967 \end_layout
24968
24969 \begin_layout Description
24970 -
24971 \begin_inset ERT
24972 status collapsed
24973
24974 \begin_layout Standard
24975
24976
24977 \backslash
24978 /
24979 \end_layout
24980
24981 \end_inset
24982
24983 -pcode-verbose Enable pcode debugging information in translation.
24984 \end_layout
24985
24986 \begin_layout Description
24987 -
24988 \begin_inset ERT
24989 status collapsed
24990
24991 \begin_layout Standard
24992
24993
24994 \backslash
24995 /
24996 \end_layout
24997
24998 \end_inset
24999
25000 -calltree Dump call tree in .calltree file.
25001 \end_layout
25002
25003 \begin_layout Description
25004 -
25005 \begin_inset ERT
25006 status collapsed
25007
25008 \begin_layout Standard
25009
25010
25011 \backslash
25012 /
25013 \end_layout
25014
25015 \end_inset
25016
25017 -gstack Trace push/pops for stack pointer overflow.
25018 \end_layout
25019
25020 \begin_layout Subsection
25021 Enviroment Variables
25022 \end_layout
25023
25024 \begin_layout Standard
25025 There is a number of enviromental variables that can be used when running
25026  SDCC to enable certain optimizations or force a specific program behaviour.
25027  these variables are primarily for debugging purposes so they can be enabled/dis
25028 abled at will.
25029 \end_layout
25030
25031 \begin_layout Standard
25032 Currently there is only two such variables available:
25033 \end_layout
25034
25035 \begin_layout Description
25036 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25037  bitfields is optimized by directly loading FSR0 with the address of the
25038  bitfield structure.
25039  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25040  then load FSR0.
25041  This step saves data ram and code space for functions that make heavy use
25042  of bitfields.
25043  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25044  option).
25045  
25046 \end_layout
25047
25048 \begin_layout Description
25049 NO_REG_OPT Do not perform pCode registers optimization.
25050  This should be used for debugging purposes.
25051  If bugs in the pcode optimizer are found, users can benefit from temporarily
25052  disabling the optimizer until the bug is fixed.
25053 \end_layout
25054
25055 \begin_layout Subsection
25056 Preprocessor Macros
25057 \end_layout
25058
25059 \begin_layout Standard
25060 PIC16
25061 \begin_inset LatexCommand \index{PIC16}
25062
25063 \end_inset
25064
25065  port defines the following preprocessor macros while translating a source.
25066 \end_layout
25067
25068 \begin_layout Standard
25069 \align center
25070 \begin_inset Tabular
25071 <lyxtabular version="3" rows="6" columns="2">
25072 <features>
25073 <column alignment="center" valignment="top" leftline="true" width="0">
25074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25075 <row topline="true" bottomline="true">
25076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25077 \begin_inset Text
25078
25079 \begin_layout Standard
25080 Macro
25081 \end_layout
25082
25083 \end_inset
25084 </cell>
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25086 \begin_inset Text
25087
25088 \begin_layout Standard
25089 Description
25090 \end_layout
25091
25092 \end_inset
25093 </cell>
25094 </row>
25095 <row topline="true">
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25097 \begin_inset Text
25098
25099 \begin_layout Standard
25100 SDCC_pic16
25101 \end_layout
25102
25103 \end_inset
25104 </cell>
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25106 \begin_inset Text
25107
25108 \begin_layout Standard
25109 Port identification
25110 \end_layout
25111
25112 \end_inset
25113 </cell>
25114 </row>
25115 <row topline="true">
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25117 \begin_inset Text
25118
25119 \begin_layout Standard
25120 _
25121 \begin_inset ERT
25122 status collapsed
25123
25124 \begin_layout Standard
25125
25126
25127 \backslash
25128 /
25129 \end_layout
25130
25131 \end_inset
25132
25133 _pic16
25134 \end_layout
25135
25136 \end_inset
25137 </cell>
25138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25139 \begin_inset Text
25140
25141 \begin_layout Standard
25142 Port identification (same as above)
25143 \end_layout
25144
25145 \end_inset
25146 </cell>
25147 </row>
25148 <row topline="true">
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25150 \begin_inset Text
25151
25152 \begin_layout Standard
25153 pic18fxxxx
25154 \end_layout
25155
25156 \end_inset
25157 </cell>
25158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25159 \begin_inset Text
25160
25161 \begin_layout Standard
25162 MCU Identification.
25163  
25164 \emph on
25165 xxxx
25166 \emph default
25167  is the microcontrol identification number, i.e.
25168  452, 6620, etc
25169 \end_layout
25170
25171 \end_inset
25172 </cell>
25173 </row>
25174 <row topline="true">
25175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25176 \begin_inset Text
25177
25178 \begin_layout Standard
25179 _
25180 \begin_inset ERT
25181 status collapsed
25182
25183 \begin_layout Standard
25184
25185
25186 \backslash
25187 /
25188 \end_layout
25189
25190 \end_inset
25191
25192 _18Fxxxx
25193 \end_layout
25194
25195 \end_inset
25196 </cell>
25197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25198 \begin_inset Text
25199
25200 \begin_layout Standard
25201 MCU Identification (same as above)
25202 \end_layout
25203
25204 \end_inset
25205 </cell>
25206 </row>
25207 <row topline="true" bottomline="true">
25208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25209 \begin_inset Text
25210
25211 \begin_layout Standard
25212 STACK_MODEL_nnn
25213 \end_layout
25214
25215 \end_inset
25216 </cell>
25217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25218 \begin_inset Text
25219
25220 \begin_layout Standard
25221 nnn = SMALL or LARGE respectively according to the stack model used
25222 \end_layout
25223
25224 \end_inset
25225 </cell>
25226 </row>
25227 </lyxtabular>
25228
25229 \end_inset
25230
25231
25232 \end_layout
25233
25234 \begin_layout Standard
25235 In addition the following macros are defined when calling assembler:
25236 \end_layout
25237
25238 \begin_layout Standard
25239 \align center
25240 \begin_inset Tabular
25241 <lyxtabular version="3" rows="4" columns="2">
25242 <features>
25243 <column alignment="center" valignment="top" leftline="true" width="0">
25244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25245 <row topline="true" bottomline="true">
25246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25247 \begin_inset Text
25248
25249 \begin_layout Standard
25250 Macro
25251 \end_layout
25252
25253 \end_inset
25254 </cell>
25255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25256 \begin_inset Text
25257
25258 \begin_layout Standard
25259 Description
25260 \end_layout
25261
25262 \end_inset
25263 </cell>
25264 </row>
25265 <row topline="true">
25266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25267 \begin_inset Text
25268
25269 \begin_layout Standard
25270 __18Fxxxx
25271 \end_layout
25272
25273 \end_inset
25274 </cell>
25275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25276 \begin_inset Text
25277
25278 \begin_layout Standard
25279 MCU Identification.
25280  
25281 \emph on
25282 xxxx
25283 \emph default
25284  is the microcontrol identification number, i.e.
25285  452, 6620, etc
25286 \end_layout
25287
25288 \end_inset
25289 </cell>
25290 </row>
25291 <row topline="true">
25292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25293 \begin_inset Text
25294
25295 \begin_layout Standard
25296 SDCC_MODEL_nnn
25297 \end_layout
25298
25299 \end_inset
25300 </cell>
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25302 \begin_inset Text
25303
25304 \begin_layout Standard
25305 nnn = SMALL or LARGE respectively according to the memory model used for
25306  SDCC
25307 \end_layout
25308
25309 \end_inset
25310 </cell>
25311 </row>
25312 <row topline="true" bottomline="true">
25313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25314 \begin_inset Text
25315
25316 \begin_layout Standard
25317 STACK_MODEL_nnn
25318 \end_layout
25319
25320 \end_inset
25321 </cell>
25322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25323 \begin_inset Text
25324
25325 \begin_layout Standard
25326 nnn = SMALL or LARGE respectively according to the stack model used
25327 \end_layout
25328
25329 \end_inset
25330 </cell>
25331 </row>
25332 </lyxtabular>
25333
25334 \end_inset
25335
25336
25337 \end_layout
25338
25339 \begin_layout Subsection
25340 Directories
25341 \end_layout
25342
25343 \begin_layout Standard
25344 PIC16
25345 \begin_inset LatexCommand \index{PIC16}
25346
25347 \end_inset
25348
25349  port uses the following directories for searching header files and libraries.
25350 \end_layout
25351
25352 \begin_layout Standard
25353 \align center
25354 \begin_inset Tabular
25355 <lyxtabular version="3" rows="3" columns="4">
25356 <features>
25357 <column alignment="center" valignment="top" leftline="true" width="0">
25358 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25359 <column alignment="center" valignment="top" width="0">
25360 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25361 <row topline="true" bottomline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25363 \begin_inset Text
25364
25365 \begin_layout Standard
25366 Directory
25367 \end_layout
25368
25369 \end_inset
25370 </cell>
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25372 \begin_inset Text
25373
25374 \begin_layout Standard
25375 Description
25376 \end_layout
25377
25378 \end_inset
25379 </cell>
25380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25381 \begin_inset Text
25382
25383 \begin_layout Standard
25384 Target
25385 \end_layout
25386
25387 \end_inset
25388 </cell>
25389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25390 \begin_inset Text
25391
25392 \begin_layout Standard
25393 Command prefix
25394 \end_layout
25395
25396 \end_inset
25397 </cell>
25398 </row>
25399 <row topline="true">
25400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25401 \begin_inset Text
25402
25403 \begin_layout Standard
25404 PREFIX/sdcc/include/pic16
25405 \end_layout
25406
25407 \end_inset
25408 </cell>
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25410 \begin_inset Text
25411
25412 \begin_layout Standard
25413 PIC16 specific headers
25414 \end_layout
25415
25416 \end_inset
25417 </cell>
25418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25419 \begin_inset Text
25420
25421 \begin_layout Standard
25422 Compiler
25423 \end_layout
25424
25425 \end_inset
25426 </cell>
25427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25428 \begin_inset Text
25429
25430 \begin_layout Standard
25431 -I
25432 \end_layout
25433
25434 \end_inset
25435 </cell>
25436 </row>
25437 <row topline="true" bottomline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25439 \begin_inset Text
25440
25441 \begin_layout Standard
25442 PREFIX/sdcc/lib/pic16
25443 \end_layout
25444
25445 \end_inset
25446 </cell>
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25448 \begin_inset Text
25449
25450 \begin_layout Standard
25451 PIC16 specific libraries
25452 \end_layout
25453
25454 \end_inset
25455 </cell>
25456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25457 \begin_inset Text
25458
25459 \begin_layout Standard
25460 Linker
25461 \end_layout
25462
25463 \end_inset
25464 </cell>
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25466 \begin_inset Text
25467
25468 \begin_layout Standard
25469 -L
25470 \end_layout
25471
25472 \end_inset
25473 </cell>
25474 </row>
25475 </lyxtabular>
25476
25477 \end_inset
25478
25479
25480 \end_layout
25481
25482 \begin_layout Subsection
25483 Pragmas
25484 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25485
25486 \end_inset
25487
25488
25489 \end_layout
25490
25491 \begin_layout Standard
25492 The PIC16
25493 \begin_inset LatexCommand \index{PIC16}
25494
25495 \end_inset
25496
25497  port currently supports the following pragmas:
25498 \end_layout
25499
25500 \begin_layout Description
25501 stack
25502 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25503
25504 \end_inset
25505
25506  This forces the code generator to initialize the stack & frame pointers
25507  at a specific address.
25508  This is an ad hoc solution for cases where no STACK directive is available
25509  in the linker script or gplink is not instructed to create a stack section.
25510 \newline
25511 The
25512  stack pragma should be used only once in a project.
25513  Multiple pragmas may result in indeterminate behaviour of the program.
25514 \begin_inset Foot
25515 status open
25516
25517 \begin_layout Standard
25518 The old format (ie.
25519  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25520  cross page boundaries (or even exceed the available data RAM) and crash
25521  the program.
25522  Make sure that stack does not cross page boundaries when using the SMALL
25523  stack model.
25524 \end_layout
25525
25526 \end_inset
25527
25528
25529 \newline
25530 The format is as follows:
25531 \newline
25532
25533 \end_layout
25534
25535 \begin_layout LyX-Code
25536 #pragma stack bottom_address [stack_size]
25537 \newline
25538
25539 \end_layout
25540
25541 \begin_layout Standard
25542
25543 \emph on
25544 bottom_address
25545 \emph default
25546  is the lower bound of the stack section.
25547  The stack pointer initially will point at address (bottom_address+stack_size-1).
25548 \end_layout
25549
25550 \begin_layout LyX-Code
25551 Example:
25552 \end_layout
25553
25554 \begin_layout LyX-Code
25555
25556 \end_layout
25557
25558 \begin_layout LyX-Code
25559 /* initializes stack of 100 bytes at RAM address 0x200 */
25560 \end_layout
25561
25562 \begin_layout LyX-Code
25563 #pragma stack 0x200 100
25564 \end_layout
25565
25566 \begin_layout Standard
25567 If the stack_size field is omitted then a stack is created with the default
25568  size of 64.
25569  This size might be enough for most programs, but its not enough for operations
25570  with deep function nesting or excessive stack usage.
25571 \end_layout
25572
25573 \begin_layout Description
25574 code
25575 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25576
25577 \end_inset
25578
25579  Force a function to a static FLASH address.
25580 \end_layout
25581
25582 \begin_layout LyX-Code
25583 Example:
25584 \end_layout
25585
25586 \begin_layout LyX-Code
25587
25588 \end_layout
25589
25590 \begin_layout LyX-Code
25591 /* place function test_func at 0x4000 */
25592 \end_layout
25593
25594 \begin_layout LyX-Code
25595 #pragma code test_func 0x4000
25596 \end_layout
25597
25598 \begin_layout LyX-Code
25599
25600 \end_layout
25601
25602 \begin_layout Description
25603 library instructs the linker to use a library module.
25604 \newline
25605 Usage:
25606 \end_layout
25607
25608 \begin_layout LyX-Code
25609 #pragma library module_name
25610 \end_layout
25611
25612 \begin_layout Standard
25613
25614 \emph on
25615 module_name
25616 \emph default
25617  can be any library or object file (including its path).
25618  Note that there are four reserved keywords which have special meaning.
25619  These are:
25620 \end_layout
25621
25622 \begin_layout Standard
25623 \align center
25624 \begin_inset Tabular
25625 <lyxtabular version="3" rows="6" columns="3">
25626 <features>
25627 <column alignment="center" valignment="top" leftline="true" width="0">
25628 <column alignment="block" valignment="top" leftline="true" width="20page%">
25629 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25630 <row topline="true" bottomline="true">
25631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25632 \begin_inset Text
25633
25634 \begin_layout Standard
25635 Keyword
25636 \end_layout
25637
25638 \end_inset
25639 </cell>
25640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25641 \begin_inset Text
25642
25643 \begin_layout Standard
25644 Description
25645 \end_layout
25646
25647 \end_inset
25648 </cell>
25649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25650 \begin_inset Text
25651
25652 \begin_layout Standard
25653 Module to link
25654 \end_layout
25655
25656 \end_inset
25657 </cell>
25658 </row>
25659 <row topline="true">
25660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25661 \begin_inset Text
25662
25663 \begin_layout Standard
25664
25665 \series bold
25666 ignore
25667 \end_layout
25668
25669 \end_inset
25670 </cell>
25671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25672 \begin_inset Text
25673
25674 \begin_layout Standard
25675 ignore all library pragmas
25676 \end_layout
25677
25678 \end_inset
25679 </cell>
25680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25681 \begin_inset Text
25682
25683 \begin_layout Standard
25684
25685 \emph on
25686 (none)
25687 \end_layout
25688
25689 \end_inset
25690 </cell>
25691 </row>
25692 <row topline="true">
25693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25694 \begin_inset Text
25695
25696 \begin_layout Standard
25697
25698 \series bold
25699 c
25700 \end_layout
25701
25702 \end_inset
25703 </cell>
25704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25705 \begin_inset Text
25706
25707 \begin_layout Standard
25708 link the C library
25709 \end_layout
25710
25711 \end_inset
25712 </cell>
25713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25714 \begin_inset Text
25715
25716 \begin_layout Standard
25717
25718 \emph on
25719 libc18f
25720 \emph default
25721 .lib
25722 \end_layout
25723
25724 \end_inset
25725 </cell>
25726 </row>
25727 <row topline="true">
25728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25729 \begin_inset Text
25730
25731 \begin_layout Standard
25732
25733 \series bold
25734 math
25735 \end_layout
25736
25737 \end_inset
25738 </cell>
25739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25740 \begin_inset Text
25741
25742 \begin_layout Standard
25743 link the Math libarary
25744 \end_layout
25745
25746 \end_inset
25747 </cell>
25748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25749 \begin_inset Text
25750
25751 \begin_layout Standard
25752
25753 \emph on
25754 libm18f
25755 \emph default
25756 .lib
25757 \end_layout
25758
25759 \end_inset
25760 </cell>
25761 </row>
25762 <row topline="true">
25763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25764 \begin_inset Text
25765
25766 \begin_layout Standard
25767
25768 \series bold
25769 io
25770 \end_layout
25771
25772 \end_inset
25773 </cell>
25774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25775 \begin_inset Text
25776
25777 \begin_layout Standard
25778 link the I/O library
25779 \end_layout
25780
25781 \end_inset
25782 </cell>
25783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25784 \begin_inset Text
25785
25786 \begin_layout Standard
25787
25788 \emph on
25789 libio18f*
25790 \emph default
25791 .lib
25792 \end_layout
25793
25794 \end_inset
25795 </cell>
25796 </row>
25797 <row topline="true" bottomline="true">
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802
25803 \series bold
25804 debug
25805 \end_layout
25806
25807 \end_inset
25808 </cell>
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25810 \begin_inset Text
25811
25812 \begin_layout Standard
25813 link the debug library
25814 \end_layout
25815
25816 \end_inset
25817 </cell>
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25819 \begin_inset Text
25820
25821 \begin_layout Standard
25822
25823 \emph on
25824 libdebug
25825 \emph default
25826 .lib
25827 \end_layout
25828
25829 \end_inset
25830 </cell>
25831 </row>
25832 </lyxtabular>
25833
25834 \end_inset
25835
25836
25837 \newline
25838 * is the device number, i.e.
25839  452 for PIC18F452 MCU.
25840 \end_layout
25841
25842 \begin_layout Standard
25843 This feature allows for linking with specific libraries withoug having to
25844  explicit name them in the command line.
25845  Note that the 
25846 \noun on
25847 ignore
25848 \noun default
25849  keyword will reject all modules specified by the library pragma.
25850 \end_layout
25851
25852 \begin_layout Description
25853 udata The pragma udata instructs the compiler to emit code so that linker
25854  will place a variable at a specific memory bank.
25855 \end_layout
25856
25857 \begin_layout LyX-Code
25858 Example:
25859 \end_layout
25860
25861 \begin_layout LyX-Code
25862
25863 \end_layout
25864
25865 \begin_layout LyX-Code
25866 /* places variable foo at bank2 */
25867 \end_layout
25868
25869 \begin_layout LyX-Code
25870 #pragma udata bank2 foo
25871 \end_layout
25872
25873 \begin_layout LyX-Code
25874 char foo;
25875 \end_layout
25876
25877 \begin_layout Standard
25878 In order for this pragma to work extra SECTION directives should be added
25879  in the .lkr script.
25880  In the following example a sample .lkr file is shown:
25881 \end_layout
25882
25883 \begin_layout LyX-Code
25884
25885 \end_layout
25886
25887 \begin_layout LyX-Code
25888 // Sample linker script for the PIC18F452 processor
25889 \end_layout
25890
25891 \begin_layout LyX-Code
25892 LIBPATH .
25893 \end_layout
25894
25895 \begin_layout LyX-Code
25896 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25897 \end_layout
25898
25899 \begin_layout LyX-Code
25900 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25901 \end_layout
25902
25903 \begin_layout LyX-Code
25904 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25905 \end_layout
25906
25907 \begin_layout LyX-Code
25908 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25909 \end_layout
25910
25911 \begin_layout LyX-Code
25912 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25913 \end_layout
25914
25915 \begin_layout LyX-Code
25916 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25917 \end_layout
25918
25919 \begin_layout LyX-Code
25920 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25921 \end_layout
25922
25923 \begin_layout LyX-Code
25924
25925 \end_layout
25926
25927 \begin_layout LyX-Code
25928 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25929 \end_layout
25930
25931 \begin_layout LyX-Code
25932 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25933 \end_layout
25934
25935 \begin_layout LyX-Code
25936 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25937 \end_layout
25938
25939 \begin_layout LyX-Code
25940 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25941 \end_layout
25942
25943 \begin_layout LyX-Code
25944 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25945 \end_layout
25946
25947 \begin_layout LyX-Code
25948 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25949 \end_layout
25950
25951 \begin_layout LyX-Code
25952 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25953 \end_layout
25954
25955 \begin_layout LyX-Code
25956
25957 \end_layout
25958
25959 \begin_layout LyX-Code
25960 SECTION    NAME=CONFIG     ROM=config
25961 \end_layout
25962
25963 \begin_layout LyX-Code
25964
25965 \end_layout
25966
25967 \begin_layout LyX-Code
25968 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25969 \end_layout
25970
25971 \begin_layout LyX-Code
25972 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25973 \end_layout
25974
25975 \begin_layout LyX-Code
25976 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25977 \end_layout
25978
25979 \begin_layout LyX-Code
25980 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25981 \end_layout
25982
25983 \begin_layout LyX-Code
25984 SECTION    NAME=bank4      RAM=gpr4
25985 \end_layout
25986
25987 \begin_layout LyX-Code
25988 SECTION    NAME=bank5      RAM=gpr5
25989 \end_layout
25990
25991 \begin_layout Standard
25992 The linker will recognise the section name set in the pragma statement and
25993  will position the variable at the memory bank set with the RAM field at
25994  the SECTION line in the linker script file.
25995 \end_layout
25996
25997 \begin_layout Subsection
25998 Header Files
25999 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26000
26001 \end_inset
26002
26003
26004 \end_layout
26005
26006 \begin_layout Standard
26007 There is one main header file
26008 \begin_inset LatexCommand \index{PIC16!Header files}
26009
26010 \end_inset
26011
26012  that can be included to the source files using the pic16
26013 \begin_inset LatexCommand \index{PIC16}
26014
26015 \end_inset
26016
26017  port.
26018  That file is the 
26019 \series bold
26020 pic18fregs.h
26021 \series default
26022 .
26023  This header file contains the definitions for the processor special registers,
26024  so it is necessary if the source accesses them.
26025  It can be included by adding the following line in the beginning of the
26026  file:
26027 \end_layout
26028
26029 \begin_layout LyX-Code
26030 #include <pic18fregs.h>
26031 \end_layout
26032
26033 \begin_layout Standard
26034 The specific microcontroller is selected within the pic18fregs.h automatically,
26035  so the same source can be used with a variety of devices.
26036 \end_layout
26037
26038 \begin_layout Subsection
26039 Libraries
26040 \end_layout
26041
26042 \begin_layout Standard
26043 The libraries
26044 \begin_inset LatexCommand \index{PIC16!Libraries}
26045
26046 \end_inset
26047
26048  that PIC16
26049 \begin_inset LatexCommand \index{PIC16}
26050
26051 \end_inset
26052
26053  port depends on are the microcontroller device libraries which contain
26054  the symbol definitions for the microcontroller special function registers.
26055  These libraries have the format pic18fxxxx.lib, where 
26056 \emph on
26057 xxxx
26058 \emph default
26059  is the microcontroller identification number.
26060  The specific library is selected automatically by the compiler at link
26061  stage according to the selected device.
26062 \end_layout
26063
26064 \begin_layout Standard
26065 Libraries are created with gplib which is part of the gputils package 
26066 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26067
26068 \end_inset
26069
26070 .
26071 \end_layout
26072
26073 \begin_layout Subsubsection*
26074 Building the libraries
26075 \end_layout
26076
26077 \begin_layout Standard
26078 Before using SDCC/pic16 there are some libraries that need to be compiled.
26079  This process is not done automatically by SDCC since not all users use
26080  SDCC for pic16 projects.
26081  So each user should compile the libraries separately.
26082 \end_layout
26083
26084 \begin_layout Standard
26085 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26086 \end_layout
26087
26088 \begin_layout LyX-Code
26089 cd device/lib/pic16
26090 \end_layout
26091
26092 \begin_layout LyX-Code
26093 ./configure
26094 \end_layout
26095
26096 \begin_layout LyX-Code
26097 make
26098 \end_layout
26099
26100 \begin_layout LyX-Code
26101 cd ..
26102 \end_layout
26103
26104 \begin_layout LyX-Code
26105 make model-pic16
26106 \end_layout
26107
26108 \begin_layout LyX-Code
26109 su -c 'make install'     # install the libraries, you need the root password
26110 \end_layout
26111
26112 \begin_layout Standard
26113 If you need to install the headers too, do:
26114 \end_layout
26115
26116 \begin_layout LyX-Code
26117 cd device/include
26118 \end_layout
26119
26120 \begin_layout LyX-Code
26121 su -c 'make install'     # install the headers, you need the root password
26122 \end_layout
26123
26124 \begin_layout Standard
26125 There exist a special target to build the I/O libraries.
26126  This target is not automatically build because it will build the I/O library
26127  for 
26128 \emph on
26129 every
26130 \emph default
26131  supported device.
26132  This way building will take quite a lot of time.
26133  Users are advised to edit the 
26134 \series bold
26135 device/lib/pic16/pics.build
26136 \series default
26137  file and then execute:
26138 \end_layout
26139
26140 \begin_layout LyX-Code
26141 make lib-io
26142 \end_layout
26143
26144 \begin_layout Subsection
26145 Adding New Devices to the Port
26146 \end_layout
26147
26148 \begin_layout Standard
26149 Adding support for a new 16
26150 \begin_inset ERT
26151 status open
26152
26153 \begin_layout Standard
26154
26155
26156 \backslash
26157 ,
26158 \end_layout
26159
26160 \end_inset
26161
26162 bit PIC MCU requires the following steps:
26163 \end_layout
26164
26165 \begin_layout Enumerate
26166 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26167 \newline
26168
26169 \family typewriter
26170 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26171 inc
26172 \end_layout
26173
26174 \begin_layout Enumerate
26175
26176 \family typewriter
26177 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26178 \end_layout
26179
26180 \begin_layout Enumerate
26181
26182 \family typewriter
26183 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26184 \end_layout
26185
26186 \begin_layout Enumerate
26187 Add DEVICE to 
26188 \family typewriter
26189 /path/to/sdcc/device/lib/pic16/pics.all
26190 \family default
26191  (and 
26192 \family typewriter
26193 .build
26194 \family default
26195 ).
26196 \newline
26197 Note: No 18f prefix here!
26198 \end_layout
26199
26200 \begin_layout Enumerate
26201 Adjust 
26202 \family typewriter
26203 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26204 \family default
26205
26206 \newline
26207 Add your DEVICE if it does not compile in 
26208 \family typewriter
26209 adc
26210 \family default
26211
26212 \family typewriter
26213 i2c
26214 \family default
26215 , or 
26216 \family typewriter
26217 usart
26218 \family default
26219 .
26220 \end_layout
26221
26222 \begin_layout Enumerate
26223 Edit 
26224 \family typewriter
26225 /path/to/sdcc/device/include/pic16/pic18fregs.h
26226 \family default
26227 .
26228  The file format is self-explanatory, just add
26229 \newline
26230
26231 \family typewriter
26232 #elif defined(picDEVICE)
26233 \newline
26234 # include <picDEVICE.h>
26235 \family default
26236
26237 \newline
26238 at the right place (keep it sorted).
26239 \end_layout
26240
26241 \begin_layout Enumerate
26242 Edit 
26243 \family typewriter
26244 /path/to/sdcc/src/pic16/devices.inc
26245 \family default
26246 .
26247  Copy and modify an existing entry and insert it at the correct place (keep
26248  the file sorted).
26249  The file is hardly documented, look at the entries for the 18f2221...
26250 \end_layout
26251
26252 \begin_layout Enumerate
26253 Recompile SDCC, including the pic16 libraries.
26254 \end_layout
26255
26256 \begin_layout Subsection
26257 Memory Models
26258 \end_layout
26259
26260 \begin_layout Standard
26261 The following memory models are supported by the PIC16 port:
26262 \end_layout
26263
26264 \begin_layout Itemize
26265 small model
26266 \end_layout
26267
26268 \begin_layout Itemize
26269 large model
26270 \end_layout
26271
26272 \begin_layout Standard
26273 Memory model affects the default size of pointers within the source.
26274  The sizes are shown in the next table:
26275 \end_layout
26276
26277 \begin_layout Standard
26278 \align center
26279 \begin_inset Tabular
26280 <lyxtabular version="3" rows="3" columns="3">
26281 <features>
26282 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26283 <column alignment="center" valignment="top" leftline="true" width="0">
26284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26285 <row topline="true" bottomline="true">
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26287 \begin_inset Text
26288
26289 \begin_layout Standard
26290 Pointer sizes according to memory model
26291 \end_layout
26292
26293 \end_inset
26294 </cell>
26295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26296 \begin_inset Text
26297
26298 \begin_layout Standard
26299 small model
26300 \end_layout
26301
26302 \end_inset
26303 </cell>
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \begin_layout Standard
26308 large model
26309 \end_layout
26310
26311 \end_inset
26312 </cell>
26313 </row>
26314 <row topline="true" bottomline="true">
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26316 \begin_inset Text
26317
26318 \begin_layout Standard
26319 code pointers
26320 \end_layout
26321
26322 \end_inset
26323 </cell>
26324 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26325 \begin_inset Text
26326
26327 \begin_layout Standard
26328 16-bits
26329 \end_layout
26330
26331 \end_inset
26332 </cell>
26333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26334 \begin_inset Text
26335
26336 \begin_layout Standard
26337 24-bits
26338 \end_layout
26339
26340 \end_inset
26341 </cell>
26342 </row>
26343 <row topline="true" bottomline="true">
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26345 \begin_inset Text
26346
26347 \begin_layout Standard
26348 data pointers
26349 \end_layout
26350
26351 \end_inset
26352 </cell>
26353 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26354 \begin_inset Text
26355
26356 \begin_layout Standard
26357 16-bits
26358 \end_layout
26359
26360 \end_inset
26361 </cell>
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26363 \begin_inset Text
26364
26365 \begin_layout Standard
26366 16-bits
26367 \end_layout
26368
26369 \end_inset
26370 </cell>
26371 </row>
26372 </lyxtabular>
26373
26374 \end_inset
26375
26376
26377 \end_layout
26378
26379 \begin_layout Standard
26380 It is advisable that all sources within a project are compiled with the
26381  same memory model.
26382  If one wants to override the default memory model, this can be done by
26383  declaring a pointer as 
26384 \series bold
26385 far
26386 \series default
26387  or 
26388 \series bold
26389 near
26390 \series default
26391 .
26392  Far selects large memory model's pointers, while near selects small memory
26393  model's pointers.
26394 \end_layout
26395
26396 \begin_layout Standard
26397 The standard device libraries (see 
26398 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26399
26400 \end_inset
26401
26402 ) contain no reference to pointers, so they can be used with both memory
26403  models.
26404 \end_layout
26405
26406 \begin_layout Subsection
26407 Stack
26408 \end_layout
26409
26410 \begin_layout Standard
26411 The stack
26412 \begin_inset LatexCommand \index{PIC16!stack}
26413
26414 \end_inset
26415
26416  implementation for the PIC16 port uses two indirect registers, FSR1 and
26417  FSR2.
26418 \end_layout
26419
26420 \begin_layout Description
26421 FSR1 is assigned as stack pointer
26422 \end_layout
26423
26424 \begin_layout Description
26425 FSR2 is assigned as frame pointer
26426 \end_layout
26427
26428 \begin_layout Standard
26429 The following stack models are supported by the PIC16 port
26430 \end_layout
26431
26432 \begin_layout Itemize
26433
26434 \noun on
26435 small
26436 \noun default
26437  model
26438 \end_layout
26439
26440 \begin_layout Itemize
26441
26442 \noun on
26443 large
26444 \noun default
26445  model
26446 \end_layout
26447
26448 \begin_layout Standard
26449
26450 \noun on
26451 Small
26452 \noun default
26453  model means that only the FSRxL byte is used to access stack and frame,
26454  while 
26455 \emph on
26456 \noun on
26457 large
26458 \emph default
26459 \noun default
26460  uses both FSRxL and FSRxH registers.
26461  The following table shows the stack/frame pointers sizes according to stack
26462  model and the maximum space they can address:
26463 \end_layout
26464
26465 \begin_layout Standard
26466 \align center
26467 \begin_inset Tabular
26468 <lyxtabular version="3" rows="3" columns="3">
26469 <features>
26470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26471 <column alignment="center" valignment="top" leftline="true" width="0">
26472 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26473 <row topline="true" bottomline="true">
26474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26475 \begin_inset Text
26476
26477 \begin_layout Standard
26478 Stack & Frame pointer sizes according to stack model
26479 \end_layout
26480
26481 \end_inset
26482 </cell>
26483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26484 \begin_inset Text
26485
26486 \begin_layout Standard
26487 small
26488 \end_layout
26489
26490 \end_inset
26491 </cell>
26492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26493 \begin_inset Text
26494
26495 \begin_layout Standard
26496 large
26497 \end_layout
26498
26499 \end_inset
26500 </cell>
26501 </row>
26502 <row topline="true">
26503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26504 \begin_inset Text
26505
26506 \begin_layout Standard
26507 Stack pointer FSR1
26508 \end_layout
26509
26510 \end_inset
26511 </cell>
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26513 \begin_inset Text
26514
26515 \begin_layout Standard
26516 8-bits
26517 \end_layout
26518
26519 \end_inset
26520 </cell>
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26522 \begin_inset Text
26523
26524 \begin_layout Standard
26525 16-bits
26526 \end_layout
26527
26528 \end_inset
26529 </cell>
26530 </row>
26531 <row topline="true" bottomline="true">
26532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26533 \begin_inset Text
26534
26535 \begin_layout Standard
26536 Frame pointer FSR2
26537 \end_layout
26538
26539 \end_inset
26540 </cell>
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26542 \begin_inset Text
26543
26544 \begin_layout Standard
26545 8-bits
26546 \end_layout
26547
26548 \end_inset
26549 </cell>
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26551 \begin_inset Text
26552
26553 \begin_layout Standard
26554 16-bits
26555 \end_layout
26556
26557 \end_inset
26558 </cell>
26559 </row>
26560 </lyxtabular>
26561
26562 \end_inset
26563
26564
26565 \end_layout
26566
26567 \begin_layout Standard
26568
26569 \noun on
26570 Large 
26571 \noun default
26572 stack model is currently not working properly throughout the code generator.
26573  So its use is not advised.
26574  Also there are some other points that need special care:
26575 \newline
26576
26577 \end_layout
26578
26579 \begin_layout Enumerate
26580 Do not create stack sections with size more than one physical bank (that
26581  is 256 bytes)
26582 \end_layout
26583
26584 \begin_layout Enumerate
26585 Stack sections should no cross physical bank limits (i.e.
26586  #pragma stack 0x50 0x100)
26587 \end_layout
26588
26589 \begin_layout Standard
26590 These limitations are caused by the fact that only FSRxL is modified when
26591  using SMALL stack model, so no more than 256 bytes of stack can be used.
26592  This problem will disappear after LARGE model is fully implemented.
26593 \end_layout
26594
26595 \begin_layout Subsection
26596 Functions
26597 \end_layout
26598
26599 \begin_layout Standard
26600 In addition to the standard SDCC function keywords, PIC16
26601 \begin_inset LatexCommand \index{PIC16}
26602
26603 \end_inset
26604
26605  port makes available two more:
26606 \end_layout
26607
26608 \begin_layout Description
26609 wparam
26610 \begin_inset LatexCommand \index{PIC16!wparam}
26611
26612 \end_inset
26613
26614  Use the WREG to pass one byte of the first function argument.
26615  This improves speed but you may not use this for functions with arguments
26616  that are called via function pointers, otherwise the first byte of the
26617  first parameter will get lost.
26618  Usage:
26619 \end_layout
26620
26621 \begin_layout LyX-Code
26622 void func_wparam(int a) wparam
26623 \end_layout
26624
26625 \begin_layout LyX-Code
26626 {
26627 \end_layout
26628
26629 \begin_layout LyX-Code
26630     /* WREG hold the lower part of a */
26631 \end_layout
26632
26633 \begin_layout LyX-Code
26634     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26635  */
26636 \end_layout
26637
26638 \begin_layout LyX-Code
26639 ...
26640 \end_layout
26641
26642 \begin_layout LyX-Code
26643 }
26644 \end_layout
26645
26646 \begin_layout Description
26647 shadowregs
26648 \begin_inset LatexCommand \index{PIC16!shadowregs}
26649
26650 \end_inset
26651
26652  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26653  hardware shadow registers which hold the values of WREG, STATUS and BSR
26654  registers.
26655  This can be done by adding the keyword 
26656 \emph on
26657 shadowregs
26658 \emph default
26659  before the 
26660 \emph on
26661 interrupt
26662 \emph default
26663  keyword in the function's header.
26664 \end_layout
26665
26666 \begin_layout LyX-Code
26667 void isr_shadow(void) shadowregs interrupt 1
26668 \end_layout
26669
26670 \begin_layout LyX-Code
26671 {
26672 \end_layout
26673
26674 \begin_layout LyX-Code
26675 ...
26676 \end_layout
26677
26678 \begin_layout LyX-Code
26679 }
26680 \end_layout
26681
26682 \begin_layout Standard
26683
26684 \emph on
26685 shadowregs
26686 \emph default
26687  instructs the code generator not to store/restore WREG, STATUS, BSR when
26688  entering/exiting the ISR.
26689 \end_layout
26690
26691 \begin_layout Subsection
26692 Function return values
26693 \end_layout
26694
26695 \begin_layout Standard
26696 Return values from functions are placed to the appropriate registers following
26697  a modified Microchip policy optimized for SDCC.
26698  The following table shows these registers:
26699 \end_layout
26700
26701 \begin_layout Standard
26702 \align center
26703 \begin_inset Tabular
26704 <lyxtabular version="3" rows="6" columns="2">
26705 <features>
26706 <column alignment="center" valignment="top" leftline="true" width="0">
26707 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26708 <row topline="true" bottomline="true">
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \begin_layout Standard
26713 size
26714 \end_layout
26715
26716 \end_inset
26717 </cell>
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26719 \begin_inset Text
26720
26721 \begin_layout Standard
26722 destination register
26723 \end_layout
26724
26725 \end_inset
26726 </cell>
26727 </row>
26728 <row topline="true">
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_inset Text
26731
26732 \begin_layout Standard
26733 8 bits
26734 \end_layout
26735
26736 \end_inset
26737 </cell>
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26739 \begin_inset Text
26740
26741 \begin_layout Standard
26742 WREG
26743 \end_layout
26744
26745 \end_inset
26746 </cell>
26747 </row>
26748 <row topline="true">
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_inset Text
26751
26752 \begin_layout Standard
26753 16 bits
26754 \end_layout
26755
26756 \end_inset
26757 </cell>
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26759 \begin_inset Text
26760
26761 \begin_layout Standard
26762 PRODL:WREG
26763 \end_layout
26764
26765 \end_inset
26766 </cell>
26767 </row>
26768 <row topline="true">
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26770 \begin_inset Text
26771
26772 \begin_layout Standard
26773 24 bits
26774 \end_layout
26775
26776 \end_inset
26777 </cell>
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26779 \begin_inset Text
26780
26781 \begin_layout Standard
26782 PRODH:PRODL:WREG
26783 \end_layout
26784
26785 \end_inset
26786 </cell>
26787 </row>
26788 <row topline="true">
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26790 \begin_inset Text
26791
26792 \begin_layout Standard
26793 32 bits
26794 \end_layout
26795
26796 \end_inset
26797 </cell>
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26799 \begin_inset Text
26800
26801 \begin_layout Standard
26802 FSR0L:PRODH:PRODL:WREG
26803 \end_layout
26804
26805 \end_inset
26806 </cell>
26807 </row>
26808 <row topline="true" bottomline="true">
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 >32 bits
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \begin_layout Standard
26822 on stack, FSR0 points to the beginning
26823 \end_layout
26824
26825 \end_inset
26826 </cell>
26827 </row>
26828 </lyxtabular>
26829
26830 \end_inset
26831
26832
26833 \end_layout
26834
26835 \begin_layout Subsection
26836 Interrupts
26837 \end_layout
26838
26839 \begin_layout Standard
26840 An interrupt
26841 \begin_inset LatexCommand \index{PIC16!interrupt}
26842
26843 \end_inset
26844
26845  service routine (ISR) is declared using the 
26846 \emph on
26847 interrupt
26848 \emph default
26849  keyword.
26850 \end_layout
26851
26852 \begin_layout LyX-Code
26853 void isr(void) interrupt 
26854 \emph on
26855 n
26856 \end_layout
26857
26858 \begin_layout LyX-Code
26859 {
26860 \end_layout
26861
26862 \begin_layout LyX-Code
26863 ...
26864 \end_layout
26865
26866 \begin_layout LyX-Code
26867 }
26868 \end_layout
26869
26870 \begin_layout Standard
26871
26872 \emph on
26873 n
26874 \emph default
26875  is the interrupt number, which for PIC18F devices can be:
26876 \end_layout
26877
26878 \begin_layout Standard
26879 \align center
26880 \begin_inset Tabular
26881 <lyxtabular version="3" rows="4" columns="3">
26882 <features>
26883 <column alignment="center" valignment="top" leftline="true" width="0">
26884 <column alignment="center" valignment="top" leftline="true" width="0">
26885 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26886 <row topline="true" bottomline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26888 \begin_inset Text
26889
26890 \begin_layout Standard
26891
26892 \emph on
26893 n
26894 \end_layout
26895
26896 \end_inset
26897 </cell>
26898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26899 \begin_inset Text
26900
26901 \begin_layout Standard
26902 Interrupt Vector
26903 \end_layout
26904
26905 \end_inset
26906 </cell>
26907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26908 \begin_inset Text
26909
26910 \begin_layout Standard
26911 Interrupt Vector Address
26912 \end_layout
26913
26914 \end_inset
26915 </cell>
26916 </row>
26917 <row topline="true">
26918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26919 \begin_inset Text
26920
26921 \begin_layout Standard
26922 0
26923 \end_layout
26924
26925 \end_inset
26926 </cell>
26927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26928 \begin_inset Text
26929
26930 \begin_layout Standard
26931 RESET vector
26932 \end_layout
26933
26934 \end_inset
26935 </cell>
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26937 \begin_inset Text
26938
26939 \begin_layout Standard
26940 0x000000
26941 \end_layout
26942
26943 \end_inset
26944 </cell>
26945 </row>
26946 <row topline="true">
26947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26948 \begin_inset Text
26949
26950 \begin_layout Standard
26951
26952 \family roman
26953 \series medium
26954 \shape up
26955 \size normal
26956 \emph off
26957 \bar no
26958 \noun off
26959 \color none
26960 1
26961 \end_layout
26962
26963 \end_inset
26964 </cell>
26965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26966 \begin_inset Text
26967
26968 \begin_layout Standard
26969
26970 \family roman
26971 \series medium
26972 \shape up
26973 \size normal
26974 \emph off
26975 \bar no
26976 \noun off
26977 \color none
26978 HIGH priority interrupts
26979 \end_layout
26980
26981 \end_inset
26982 </cell>
26983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26984 \begin_inset Text
26985
26986 \begin_layout Standard
26987 0x000008
26988 \end_layout
26989
26990 \end_inset
26991 </cell>
26992 </row>
26993 <row topline="true" bottomline="true">
26994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26995 \begin_inset Text
26996
26997 \begin_layout Standard
26998 2
26999 \end_layout
27000
27001 \end_inset
27002 </cell>
27003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_inset Text
27005
27006 \begin_layout Standard
27007 LOW priority interrupts
27008 \end_layout
27009
27010 \end_inset
27011 </cell>
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27013 \begin_inset Text
27014
27015 \begin_layout Standard
27016 0x000018
27017 \end_layout
27018
27019 \end_inset
27020 </cell>
27021 </row>
27022 </lyxtabular>
27023
27024 \end_inset
27025
27026
27027 \end_layout
27028
27029 \begin_layout Standard
27030 When generating assembly code for ISR the code generator places a 
27031 \noun on
27032 goto 
27033 \noun default
27034 instruction at the 
27035 \emph on
27036 Interrupt Vector Address
27037 \emph default
27038  which points at the genetated ISR.
27039  This single GOTO instruction is part of an automatically generated 
27040 \emph on
27041 interrupt entry point
27042 \emph default
27043  function.
27044  The actuall ISR code is placed as normally would in the code space.
27045  Upon interrupt request, the GOTO instruction is executed which jumps to
27046  the ISR code.
27047  When declaring interrupt functions as _naked this GOTO instruction is 
27048 \series bold
27049 not
27050 \series default
27051  generated.
27052  The whole interrupt functions is therefore placed at the Interrupt Vector
27053  Address of the specific interrupt.
27054  This is not a problem for the LOW priority interrupts, but it is a problem
27055  for the RESET and the HIGH priority interrupts because code may be written
27056  at the next interrupt's vector address and cause undeterminate program
27057  behaviour if that interrupt is raised.
27058 \begin_inset Foot
27059 status open
27060
27061 \begin_layout Standard
27062 This is not a problem when
27063 \end_layout
27064
27065 \begin_layout Enumerate
27066 this is a HIGH interrupt ISR and LOW interrupts are 
27067 \emph on
27068 disabled
27069 \emph default
27070  or not used.
27071 \end_layout
27072
27073 \begin_layout Enumerate
27074 when the ISR is small enough not to reach the next interrupt's vector address.
27075 \end_layout
27076
27077 \end_inset
27078
27079
27080 \end_layout
27081
27082 \begin_layout Standard
27083
27084 \emph on
27085 n
27086 \emph default
27087  may be omitted.
27088  This way a function is generated similar to an ISR, but it is not assigned
27089  to any interrupt.
27090 \end_layout
27091
27092 \begin_layout Standard
27093 When entering an interrupt, currently the PIC16
27094 \begin_inset LatexCommand \index{PIC16}
27095
27096 \end_inset
27097
27098  port automatically saves the following registers:
27099 \end_layout
27100
27101 \begin_layout Itemize
27102 WREG
27103 \end_layout
27104
27105 \begin_layout Itemize
27106 STATUS
27107 \end_layout
27108
27109 \begin_layout Itemize
27110 BSR
27111 \end_layout
27112
27113 \begin_layout Itemize
27114 PROD (PRODL and PRODH)
27115 \end_layout
27116
27117 \begin_layout Itemize
27118 FSR0 (FSR0L and FSR0H)
27119 \end_layout
27120
27121 \begin_layout Standard
27122 These registers are restored upon return from the interrupt routine.
27123 \begin_inset Foot
27124 status open
27125
27126 \begin_layout Standard
27127 NOTE that when the _naked attribute is specified for an interrupt routine,
27128  then NO registers are stored or restored.
27129 \end_layout
27130
27131 \end_inset
27132
27133
27134 \end_layout
27135
27136 \begin_layout Subsection
27137 Generic Pointers
27138 \end_layout
27139
27140 \begin_layout Standard
27141 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27142  There are 3 types of generic pointers currently implemented data, code
27143  and eeprom pointers.
27144  They are differentiated by the value of the 7th and 6th bits of the upper
27145  byte:
27146 \end_layout
27147
27148 \begin_layout Standard
27149 \align center
27150 \begin_inset Tabular
27151 <lyxtabular version="3" rows="5" columns="5">
27152 <features>
27153 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27154 <column alignment="center" valignment="top" width="0">
27155 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27156 <column alignment="center" valignment="top" width="0">
27157 <column alignment="left" valignment="top" rightline="true" width="0">
27158 <row topline="true" bottomline="true">
27159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27160 \begin_inset Text
27161
27162 \begin_layout Standard
27163 pointer type
27164 \end_layout
27165
27166 \end_inset
27167 </cell>
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27169 \begin_inset Text
27170
27171 \begin_layout Standard
27172 7th bit
27173 \end_layout
27174
27175 \end_inset
27176 </cell>
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27178 \begin_inset Text
27179
27180 \begin_layout Standard
27181 6th bit
27182 \end_layout
27183
27184 \end_inset
27185 </cell>
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27187 \begin_inset Text
27188
27189 \begin_layout Standard
27190 rest of the pointer
27191 \end_layout
27192
27193 \end_inset
27194 </cell>
27195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27196 \begin_inset Text
27197
27198 \begin_layout Standard
27199 description
27200 \end_layout
27201
27202 \end_inset
27203 </cell>
27204 </row>
27205 <row topline="true" bottomline="true">
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27207 \begin_inset Text
27208
27209 \begin_layout Standard
27210 data 
27211 \end_layout
27212
27213 \end_inset
27214 </cell>
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27216 \begin_inset Text
27217
27218 \begin_layout Standard
27219 1
27220 \end_layout
27221
27222 \end_inset
27223 </cell>
27224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27225 \begin_inset Text
27226
27227 \begin_layout Standard
27228 0
27229 \end_layout
27230
27231 \end_inset
27232 </cell>
27233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27234 \begin_inset Text
27235
27236 \begin_layout Standard
27237
27238 \family typewriter
27239 \shape slanted
27240 \emph on
27241 uuuuuu uuuuxxxx xxxxxxxx
27242 \end_layout
27243
27244 \end_inset
27245 </cell>
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27247 \begin_inset Text
27248
27249 \begin_layout Standard
27250 a 12-bit data pointer in data RAM memory
27251 \end_layout
27252
27253 \end_inset
27254 </cell>
27255 </row>
27256 <row bottomline="true">
27257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27258 \begin_inset Text
27259
27260 \begin_layout Standard
27261 code
27262 \end_layout
27263
27264 \end_inset
27265 </cell>
27266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27267 \begin_inset Text
27268
27269 \begin_layout Standard
27270 0
27271 \end_layout
27272
27273 \end_inset
27274 </cell>
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27276 \begin_inset Text
27277
27278 \begin_layout Standard
27279 0
27280 \end_layout
27281
27282 \end_inset
27283 </cell>
27284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27285 \begin_inset Text
27286
27287 \begin_layout Standard
27288
27289 \family typewriter
27290 \shape slanted
27291 \emph on
27292 uxxxxx xxxxxxxx xxxxxxxx
27293 \end_layout
27294
27295 \end_inset
27296 </cell>
27297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27298 \begin_inset Text
27299
27300 \begin_layout Standard
27301 a 21-bit code pointer in FLASH memory
27302 \end_layout
27303
27304 \end_inset
27305 </cell>
27306 </row>
27307 <row bottomline="true">
27308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27309 \begin_inset Text
27310
27311 \begin_layout Standard
27312 eeprom
27313 \end_layout
27314
27315 \end_inset
27316 </cell>
27317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27318 \begin_inset Text
27319
27320 \begin_layout Standard
27321 0
27322 \end_layout
27323
27324 \end_inset
27325 </cell>
27326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27327 \begin_inset Text
27328
27329 \begin_layout Standard
27330 1
27331 \end_layout
27332
27333 \end_inset
27334 </cell>
27335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27336 \begin_inset Text
27337
27338 \begin_layout Standard
27339
27340 \family typewriter
27341 \shape slanted
27342 \emph on
27343 uuuuuu uuuuuuxx xxxxxxxx
27344 \end_layout
27345
27346 \end_inset
27347 </cell>
27348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27349 \begin_inset Text
27350
27351 \begin_layout Standard
27352 a 10-bit eeprom pointer in EEPROM memory
27353 \end_layout
27354
27355 \end_inset
27356 </cell>
27357 </row>
27358 <row bottomline="true">
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27360 \begin_inset Text
27361
27362 \begin_layout Standard
27363 (unimplemented)
27364 \end_layout
27365
27366 \end_inset
27367 </cell>
27368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27369 \begin_inset Text
27370
27371 \begin_layout Standard
27372 1
27373 \end_layout
27374
27375 \end_inset
27376 </cell>
27377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27378 \begin_inset Text
27379
27380 \begin_layout Standard
27381 1
27382 \end_layout
27383
27384 \end_inset
27385 </cell>
27386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27387 \begin_inset Text
27388
27389 \begin_layout Standard
27390
27391 \family typewriter
27392 \shape slanted
27393 \emph on
27394 xxxxxx xxxxxxxx xxxxxxxx
27395 \end_layout
27396
27397 \end_inset
27398 </cell>
27399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27400 \begin_inset Text
27401
27402 \begin_layout Standard
27403 unimplemented pointer type
27404 \end_layout
27405
27406 \end_inset
27407 </cell>
27408 </row>
27409 </lyxtabular>
27410
27411 \end_inset
27412
27413
27414 \end_layout
27415
27416 \begin_layout Standard
27417 Generic pointer are read and written with a set of library functions which
27418  read/write 1, 2, 3, 4 bytes.
27419 \end_layout
27420
27421 \begin_layout Subsection
27422 PIC16 C Libraries
27423 \end_layout
27424
27425 \begin_layout Subsubsection
27426 Standard I/O Streams
27427 \end_layout
27428
27429 \begin_layout Standard
27430 In the 
27431 \emph on
27432 stdio.h
27433 \emph default
27434  the type FILE is defined as:
27435 \end_layout
27436
27437 \begin_layout LyX-Code
27438 typedef char * FILE;
27439 \end_layout
27440
27441 \begin_layout Standard
27442 This type is the stream type implemented I/O in the PIC18F devices.
27443  Also the standard input and output streams are declared in stdio.h:
27444 \end_layout
27445
27446 \begin_layout LyX-Code
27447 extern FILE * stdin;
27448 \end_layout
27449
27450 \begin_layout LyX-Code
27451 extern FILE * stdout;
27452 \end_layout
27453
27454 \begin_layout Standard
27455 The FILE type is actually a generic pointer which defines one more type
27456  of generic pointers, the 
27457 \emph on
27458 stream 
27459 \emph default
27460 pointer.
27461  This new type has the format:
27462 \end_layout
27463
27464 \begin_layout Standard
27465 \align center
27466 \begin_inset Tabular
27467 <lyxtabular version="3" rows="2" columns="7">
27468 <features>
27469 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27470 <column alignment="center" valignment="top" width="0">
27471 <column alignment="center" valignment="top" leftline="true" width="0">
27472 <column alignment="center" valignment="top" leftline="true" width="0">
27473 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27474 <column alignment="center" valignment="top" width="0">
27475 <column alignment="left" valignment="top" rightline="true" width="0">
27476 <row topline="true" bottomline="true">
27477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27478 \begin_inset Text
27479
27480 \begin_layout Standard
27481 pointer type
27482 \end_layout
27483
27484 \end_inset
27485 </cell>
27486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27487 \begin_inset Text
27488
27489 \begin_layout Standard
27490 <7:6>
27491 \end_layout
27492
27493 \end_inset
27494 </cell>
27495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27496 \begin_inset Text
27497
27498 \begin_layout Standard
27499 <5>
27500 \end_layout
27501
27502 \end_inset
27503 </cell>
27504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27505 \begin_inset Text
27506
27507 \begin_layout Standard
27508 <4>
27509 \end_layout
27510
27511 \end_inset
27512 </cell>
27513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27514 \begin_inset Text
27515
27516 \begin_layout Standard
27517 <3:0>
27518 \end_layout
27519
27520 \end_inset
27521 </cell>
27522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27523 \begin_inset Text
27524
27525 \begin_layout Standard
27526 rest of the pointer
27527 \end_layout
27528
27529 \end_inset
27530 </cell>
27531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27532 \begin_inset Text
27533
27534 \begin_layout Standard
27535 descrption
27536 \end_layout
27537
27538 \end_inset
27539 </cell>
27540 </row>
27541 <row topline="true" bottomline="true">
27542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27543 \begin_inset Text
27544
27545 \begin_layout Standard
27546 stream
27547 \end_layout
27548
27549 \end_inset
27550 </cell>
27551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27552 \begin_inset Text
27553
27554 \begin_layout Standard
27555 00
27556 \end_layout
27557
27558 \end_inset
27559 </cell>
27560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27561 \begin_inset Text
27562
27563 \begin_layout Standard
27564 1
27565 \end_layout
27566
27567 \end_inset
27568 </cell>
27569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27570 \begin_inset Text
27571
27572 \begin_layout Standard
27573 0
27574 \end_layout
27575
27576 \end_inset
27577 </cell>
27578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27579 \begin_inset Text
27580
27581 \begin_layout Standard
27582 nnnn
27583 \end_layout
27584
27585 \end_inset
27586 </cell>
27587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27588 \begin_inset Text
27589
27590 \begin_layout Standard
27591
27592 \family typewriter
27593 \shape slanted
27594 \emph on
27595 uuuuuuuu uuuuuuuu
27596 \end_layout
27597
27598 \end_inset
27599 </cell>
27600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27601 \begin_inset Text
27602
27603 \begin_layout Standard
27604 upper byte high nubble is 0x2n, the rest are zeroes
27605 \end_layout
27606
27607 \end_inset
27608 </cell>
27609 </row>
27610 </lyxtabular>
27611
27612 \end_inset
27613
27614
27615 \end_layout
27616
27617 \begin_layout Standard
27618 Currently implemented there are 3 types of streams defined:
27619 \end_layout
27620
27621 \begin_layout Standard
27622 \align center
27623 \begin_inset Tabular
27624 <lyxtabular version="3" rows="4" columns="4">
27625 <features>
27626 <column alignment="center" valignment="top" leftline="true" width="0">
27627 <column alignment="center" valignment="top" leftline="true" width="0">
27628 <column alignment="center" valignment="top" leftline="true" width="0">
27629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27630 <row topline="true" bottomline="true">
27631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27632 \begin_inset Text
27633
27634 \begin_layout Standard
27635 stream type
27636 \end_layout
27637
27638 \end_inset
27639 </cell>
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27641 \begin_inset Text
27642
27643 \begin_layout Standard
27644 value
27645 \end_layout
27646
27647 \end_inset
27648 </cell>
27649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27650 \begin_inset Text
27651
27652 \begin_layout Standard
27653 module
27654 \end_layout
27655
27656 \end_inset
27657 </cell>
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27659 \begin_inset Text
27660
27661 \begin_layout Standard
27662 description
27663 \end_layout
27664
27665 \end_inset
27666 </cell>
27667 </row>
27668 <row topline="true">
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27670 \begin_inset Text
27671
27672 \begin_layout Standard
27673 STREAM_USART
27674 \end_layout
27675
27676 \end_inset
27677 </cell>
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27679 \begin_inset Text
27680
27681 \begin_layout Standard
27682
27683 \family typewriter
27684 0x200000UL
27685 \end_layout
27686
27687 \end_inset
27688 </cell>
27689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27690 \begin_inset Text
27691
27692 \begin_layout Standard
27693 USART
27694 \end_layout
27695
27696 \end_inset
27697 </cell>
27698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27699 \begin_inset Text
27700
27701 \begin_layout Standard
27702 Writes/Reads characters via the USART peripheral
27703 \end_layout
27704
27705 \end_inset
27706 </cell>
27707 </row>
27708 <row topline="true">
27709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27710 \begin_inset Text
27711
27712 \begin_layout Standard
27713 STREAM_MSSP
27714 \end_layout
27715
27716 \end_inset
27717 </cell>
27718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27719 \begin_inset Text
27720
27721 \begin_layout Standard
27722
27723 \family typewriter
27724 0x210000UL
27725 \end_layout
27726
27727 \end_inset
27728 </cell>
27729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27730 \begin_inset Text
27731
27732 \begin_layout Standard
27733 MSSP
27734 \end_layout
27735
27736 \end_inset
27737 </cell>
27738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27739 \begin_inset Text
27740
27741 \begin_layout Standard
27742 Writes/Reads characters via the MSSP peripheral
27743 \end_layout
27744
27745 \end_inset
27746 </cell>
27747 </row>
27748 <row topline="true" bottomline="true">
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27750 \begin_inset Text
27751
27752 \begin_layout Standard
27753 STREAM_USER
27754 \end_layout
27755
27756 \end_inset
27757 </cell>
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27759 \begin_inset Text
27760
27761 \begin_layout Standard
27762
27763 \family typewriter
27764 0x2f0000UL
27765 \end_layout
27766
27767 \end_inset
27768 </cell>
27769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27770 \begin_inset Text
27771
27772 \begin_layout Standard
27773 (none)
27774 \end_layout
27775
27776 \end_inset
27777 </cell>
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27779 \begin_inset Text
27780
27781 \begin_layout Standard
27782 Writes/Reads characters via used defined functions
27783 \end_layout
27784
27785 \end_inset
27786 </cell>
27787 </row>
27788 </lyxtabular>
27789
27790 \end_inset
27791
27792
27793 \end_layout
27794
27795 \begin_layout Standard
27796 The stream identifiers are declared as macros in the stdio.h header.
27797 \end_layout
27798
27799 \begin_layout Standard
27800 In the libc library there exist the functions that are used to write to
27801  each of the above streams.
27802  These are
27803 \end_layout
27804
27805 \begin_layout Description
27806 _
27807 \begin_inset ERT
27808 status collapsed
27809
27810 \begin_layout Standard
27811
27812
27813 \backslash
27814 /
27815 \end_layout
27816
27817 \end_inset
27818
27819 _stream_usart_putchar writes a character at the USART stream
27820 \end_layout
27821
27822 \begin_layout Description
27823 _
27824 \begin_inset ERT
27825 status collapsed
27826
27827 \begin_layout Standard
27828
27829
27830 \backslash
27831 /
27832 \end_layout
27833
27834 \end_inset
27835
27836 _stream_mssp_putchar writes a character at the MSSP stream
27837 \end_layout
27838
27839 \begin_layout Description
27840 putchar dummy function.
27841  This writes a character to a user specified manner.
27842 \end_layout
27843
27844 \begin_layout Standard
27845 In order to increase performance 
27846 \emph on
27847 putchar 
27848 \emph default
27849 is declared in stdio.h as having its parameter in WREG (it has the wparam
27850  keyword).
27851  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27852  in a user-friendly way.
27853  
27854 \emph on
27855 arg
27856 \emph default
27857  is the name of the variable that holds the character to print.
27858  An example follows:
27859 \end_layout
27860
27861 \begin_layout LyX-Code
27862 #include <pic18fregs.h>
27863 \newline
27864 #include <stdio.h>
27865 \newline
27866
27867 \newline
27868 PUTCHAR( c )
27869 \end_layout
27870
27871 \begin_layout LyX-Code
27872 {
27873 \end_layout
27874
27875 \begin_layout LyX-Code
27876     PORTA = c;    /* dump character c to PORTA */
27877 \end_layout
27878
27879 \begin_layout LyX-Code
27880
27881 \newline
27882
27883 \newline
27884 void main(void)
27885 \end_layout
27886
27887 \begin_layout LyX-Code
27888 {
27889 \end_layout
27890
27891 \begin_layout LyX-Code
27892     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27893 \end_layout
27894
27895 \begin_layout LyX-Code
27896                               * by default to STREAM_USER */
27897 \end_layout
27898
27899 \begin_layout LyX-Code
27900     printf (
27901 \begin_inset Quotes sld
27902 \end_inset
27903
27904 This is a printf test
27905 \backslash
27906 n
27907 \begin_inset Quotes srd
27908 \end_inset
27909
27910 );
27911 \end_layout
27912
27913 \begin_layout LyX-Code
27914 }
27915 \end_layout
27916
27917 \begin_layout LyX-Code
27918
27919 \end_layout
27920
27921 \begin_layout Subsubsection
27922 Printing functions
27923 \end_layout
27924
27925 \begin_layout Standard
27926 PIC16 contains an implementation of the printf-family of functions.
27927  There exist the following functions:
27928 \end_layout
27929
27930 \begin_layout LyX-Code
27931 extern unsigned int sprintf(char *buf, char *fmt, ...);
27932 \end_layout
27933
27934 \begin_layout LyX-Code
27935 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27936 \end_layout
27937
27938 \begin_layout LyX-Code
27939
27940 \end_layout
27941
27942 \begin_layout LyX-Code
27943 extern unsigned int printf(char *fmt, ...);
27944 \end_layout
27945
27946 \begin_layout LyX-Code
27947 extern unsigned int vprintf(char *fmt, va_lista ap);
27948 \end_layout
27949
27950 \begin_layout LyX-Code
27951
27952 \end_layout
27953
27954 \begin_layout LyX-Code
27955 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27956 \end_layout
27957
27958 \begin_layout LyX-Code
27959 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27960 \end_layout
27961
27962 \begin_layout Standard
27963 For sprintf and vsprintf 
27964 \emph on
27965 buf 
27966 \emph default
27967 should normally be a data pointer where the resulting string will be placed.
27968  No range checking is done so the user should allocate the necessery buffer.
27969  For fprintf and vfprintf 
27970 \emph on
27971 fp
27972 \emph default
27973  should be a stream pointer (i.e.
27974  stdout, STREAM_MSSP, etc...).
27975 \end_layout
27976
27977 \begin_layout Subsubsection
27978 Signals
27979 \end_layout
27980
27981 \begin_layout Standard
27982 The PIC18F family of microcontrollers supports a number of interrupt sources.
27983  A list of these interrupts is shown in the following table:
27984 \end_layout
27985
27986 \begin_layout Standard
27987 \align center
27988 \begin_inset Tabular
27989 <lyxtabular version="3" rows="11" columns="4">
27990 <features>
27991 <column alignment="left" valignment="top" leftline="true" width="0">
27992 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27993 <column alignment="left" valignment="top" leftline="true" width="0">
27994 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27995 <row topline="true" bottomline="true">
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27997 \begin_inset Text
27998
27999 \begin_layout Standard
28000 signal name
28001 \end_layout
28002
28003 \end_inset
28004 </cell>
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28006 \begin_inset Text
28007
28008 \begin_layout Standard
28009 description
28010 \end_layout
28011
28012 \end_inset
28013 </cell>
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28015 \begin_inset Text
28016
28017 \begin_layout Standard
28018 signal name
28019 \end_layout
28020
28021 \end_inset
28022 </cell>
28023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28024 \begin_inset Text
28025
28026 \begin_layout Standard
28027 descritpion
28028 \end_layout
28029
28030 \end_inset
28031 </cell>
28032 </row>
28033 <row topline="true">
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28035 \begin_inset Text
28036
28037 \begin_layout Standard
28038 SIG_RB
28039 \end_layout
28040
28041 \end_inset
28042 </cell>
28043 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28044 \begin_inset Text
28045
28046 \begin_layout Standard
28047 PORTB change interrupt
28048 \end_layout
28049
28050 \end_inset
28051 </cell>
28052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28053 \begin_inset Text
28054
28055 \begin_layout Standard
28056 SIG_EE
28057 \end_layout
28058
28059 \end_inset
28060 </cell>
28061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28062 \begin_inset Text
28063
28064 \begin_layout Standard
28065 EEPROM/FLASH write complete interrupt
28066 \end_layout
28067
28068 \end_inset
28069 </cell>
28070 </row>
28071 <row topline="true">
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28073 \begin_inset Text
28074
28075 \begin_layout Standard
28076 SIG_INT0
28077 \end_layout
28078
28079 \end_inset
28080 </cell>
28081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28082 \begin_inset Text
28083
28084 \begin_layout Standard
28085 INT0 external interrupt
28086 \end_layout
28087
28088 \end_inset
28089 </cell>
28090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28091 \begin_inset Text
28092
28093 \begin_layout Standard
28094 SIG_BCOL
28095 \end_layout
28096
28097 \end_inset
28098 </cell>
28099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28100 \begin_inset Text
28101
28102 \begin_layout Standard
28103 Bus collision interrupt
28104 \end_layout
28105
28106 \end_inset
28107 </cell>
28108 </row>
28109 <row topline="true">
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28111 \begin_inset Text
28112
28113 \begin_layout Standard
28114 SIG_INT1
28115 \end_layout
28116
28117 \end_inset
28118 </cell>
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28120 \begin_inset Text
28121
28122 \begin_layout Standard
28123 INT1 external interrupt
28124 \end_layout
28125
28126 \end_inset
28127 </cell>
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28129 \begin_inset Text
28130
28131 \begin_layout Standard
28132 SIG_LVD
28133 \end_layout
28134
28135 \end_inset
28136 </cell>
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28138 \begin_inset Text
28139
28140 \begin_layout Standard
28141 Low voltage detect interrupt
28142 \end_layout
28143
28144 \end_inset
28145 </cell>
28146 </row>
28147 <row topline="true">
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28149 \begin_inset Text
28150
28151 \begin_layout Standard
28152 SIG_INT2
28153 \end_layout
28154
28155 \end_inset
28156 </cell>
28157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28158 \begin_inset Text
28159
28160 \begin_layout Standard
28161 INT2 external interrupt
28162 \end_layout
28163
28164 \end_inset
28165 </cell>
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28167 \begin_inset Text
28168
28169 \begin_layout Standard
28170 SIG_PSP
28171 \end_layout
28172
28173 \end_inset
28174 </cell>
28175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28176 \begin_inset Text
28177
28178 \begin_layout Standard
28179 Parallel slave port interrupt
28180 \end_layout
28181
28182 \end_inset
28183 </cell>
28184 </row>
28185 <row topline="true">
28186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28187 \begin_inset Text
28188
28189 \begin_layout Standard
28190 SIG_CCP1
28191 \end_layout
28192
28193 \end_inset
28194 </cell>
28195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28196 \begin_inset Text
28197
28198 \begin_layout Standard
28199 CCP1 module interrupt
28200 \end_layout
28201
28202 \end_inset
28203 </cell>
28204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28205 \begin_inset Text
28206
28207 \begin_layout Standard
28208 SIG_AD
28209 \end_layout
28210
28211 \end_inset
28212 </cell>
28213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28214 \begin_inset Text
28215
28216 \begin_layout Standard
28217 AD convertion complete interrupt
28218 \end_layout
28219
28220 \end_inset
28221 </cell>
28222 </row>
28223 <row topline="true">
28224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28225 \begin_inset Text
28226
28227 \begin_layout Standard
28228 SIG_CCP2
28229 \end_layout
28230
28231 \end_inset
28232 </cell>
28233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28234 \begin_inset Text
28235
28236 \begin_layout Standard
28237 CCP2 module interrupt
28238 \end_layout
28239
28240 \end_inset
28241 </cell>
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28243 \begin_inset Text
28244
28245 \begin_layout Standard
28246 SIG_RC
28247 \end_layout
28248
28249 \end_inset
28250 </cell>
28251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28252 \begin_inset Text
28253
28254 \begin_layout Standard
28255 USART receive interrupt
28256 \end_layout
28257
28258 \end_inset
28259 </cell>
28260 </row>
28261 <row topline="true">
28262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28263 \begin_inset Text
28264
28265 \begin_layout Standard
28266 SIG_TMR0
28267 \end_layout
28268
28269 \end_inset
28270 </cell>
28271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28272 \begin_inset Text
28273
28274 \begin_layout Standard
28275 TMR0 overflow interrupt
28276 \end_layout
28277
28278 \end_inset
28279 </cell>
28280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28281 \begin_inset Text
28282
28283 \begin_layout Standard
28284 SIG_TX
28285 \end_layout
28286
28287 \end_inset
28288 </cell>
28289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28290 \begin_inset Text
28291
28292 \begin_layout Standard
28293 USART transmit interrupt
28294 \end_layout
28295
28296 \end_inset
28297 </cell>
28298 </row>
28299 <row topline="true">
28300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28301 \begin_inset Text
28302
28303 \begin_layout Standard
28304 SIG_TMR1
28305 \end_layout
28306
28307 \end_inset
28308 </cell>
28309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28310 \begin_inset Text
28311
28312 \begin_layout Standard
28313 TMR1 overflow interrupt
28314 \end_layout
28315
28316 \end_inset
28317 </cell>
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28319 \begin_inset Text
28320
28321 \begin_layout Standard
28322 SIG_MSSP
28323 \end_layout
28324
28325 \end_inset
28326 </cell>
28327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28328 \begin_inset Text
28329
28330 \begin_layout Standard
28331 SSP receive/transmit interrupt
28332 \end_layout
28333
28334 \end_inset
28335 </cell>
28336 </row>
28337 <row topline="true">
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28339 \begin_inset Text
28340
28341 \begin_layout Standard
28342 SIG_TMR2
28343 \end_layout
28344
28345 \end_inset
28346 </cell>
28347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28348 \begin_inset Text
28349
28350 \begin_layout Standard
28351 TMR2 matches PR2 interrupt
28352 \end_layout
28353
28354 \end_inset
28355 </cell>
28356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28357 \begin_inset Text
28358
28359 \begin_layout Standard
28360
28361 \end_layout
28362
28363 \end_inset
28364 </cell>
28365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28366 \begin_inset Text
28367
28368 \begin_layout Standard
28369
28370 \end_layout
28371
28372 \end_inset
28373 </cell>
28374 </row>
28375 <row topline="true" bottomline="true">
28376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28377 \begin_inset Text
28378
28379 \begin_layout Standard
28380 SIG_TMR3
28381 \end_layout
28382
28383 \end_inset
28384 </cell>
28385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28386 \begin_inset Text
28387
28388 \begin_layout Standard
28389 TMR3 overflow interrupt
28390 \end_layout
28391
28392 \end_inset
28393 </cell>
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28395 \begin_inset Text
28396
28397 \begin_layout Standard
28398
28399 \end_layout
28400
28401 \end_inset
28402 </cell>
28403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28404 \begin_inset Text
28405
28406 \begin_layout Standard
28407
28408 \end_layout
28409
28410 \end_inset
28411 </cell>
28412 </row>
28413 </lyxtabular>
28414
28415 \end_inset
28416
28417
28418 \end_layout
28419
28420 \begin_layout Standard
28421 The prototypes for these names are defined in the header file 
28422 \emph on
28423 signal.h
28424 \emph default
28425  .
28426 \end_layout
28427
28428 \begin_layout Standard
28429 In order to simplify signal handling, a number of macros is provided:
28430 \end_layout
28431
28432 \begin_layout List
28433 \labelwidthstring 00.00.0000
28434 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28435  high priority interrupts.
28436  
28437 \emph on
28438 name
28439 \emph default
28440  is the function name to use.
28441 \end_layout
28442
28443 \begin_layout List
28444 \labelwidthstring 00.00.0000
28445 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28446  low priority interrupt.
28447  
28448 \emph on
28449 name
28450 \emph default
28451  is the function name to use.
28452 \end_layout
28453
28454 \begin_layout List
28455 \labelwidthstring 00.00.0000
28456 DEF_HANDLER(sig,handler) define a handler for signal 
28457 \emph on
28458 sig.
28459 \end_layout
28460
28461 \begin_layout List
28462 \labelwidthstring 00.00.0000
28463 END_DEF end the declaration of the dispatch table.
28464 \end_layout
28465
28466 \begin_layout Standard
28467 Additionally there are two more macros to simplify the declaration of the
28468  signal handler:
28469 \end_layout
28470
28471 \begin_layout List
28472 \labelwidthstring 00.00.0000
28473
28474 \series medium
28475 SIGHANDLER(handler) 
28476 \series default
28477 this declares the function prototype for the 
28478 \emph on
28479 handler
28480 \emph default
28481  function.
28482 \end_layout
28483
28484 \begin_layout List
28485 \labelwidthstring 00.00.0000
28486 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28487 \end_layout
28488
28489 \begin_layout Standard
28490 An example of using the macros above is shown below:
28491 \end_layout
28492
28493 \begin_layout LyX-Code
28494 #include <pic18fregs.h>
28495 \end_layout
28496
28497 \begin_layout LyX-Code
28498 #include <signal.h>
28499 \newline
28500
28501 \newline
28502 DEF_INTHIGH(high_int)
28503 \end_layout
28504
28505 \begin_layout LyX-Code
28506 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28507 \end_layout
28508
28509 \begin_layout LyX-Code
28510 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28511 \end_layout
28512
28513 \begin_layout LyX-Code
28514 END_DEF
28515 \newline
28516
28517 \newline
28518 SIGHANDLER(_tmr0_handler)
28519 \end_layout
28520
28521 \begin_layout LyX-Code
28522 {
28523 \end_layout
28524
28525 \begin_layout LyX-Code
28526   /* action to be taken when timer 0 overflows */
28527 \end_layout
28528
28529 \begin_layout LyX-Code
28530 }
28531 \newline
28532
28533 \newline
28534 SIGHANDLERNAKED(_bcol_handler)
28535 \end_layout
28536
28537 \begin_layout LyX-Code
28538 {
28539 \end_layout
28540
28541 \begin_layout LyX-Code
28542   _asm
28543 \end_layout
28544
28545 \begin_layout LyX-Code
28546     /* action to be taken when bus collision occurs */
28547 \end_layout
28548
28549 \begin_layout LyX-Code
28550     retfie
28551 \end_layout
28552
28553 \begin_layout LyX-Code
28554  _endasm;
28555 \end_layout
28556
28557 \begin_layout LyX-Code
28558 }
28559 \end_layout
28560
28561 \begin_layout Standard
28562
28563 \series bold
28564 NOTES:
28565 \series default
28566  Special care should be taken when using the above scheme:
28567 \end_layout
28568
28569 \begin_layout Itemize
28570 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28571 \end_layout
28572
28573 \begin_layout Itemize
28574 when declaring SIGHANDLERNAKED handler never forget to use 
28575 \emph on
28576 retfie
28577 \emph default
28578  for proper returning.
28579 \end_layout
28580
28581 \begin_layout Subsection
28582 PIC16 Port -- Tips
28583 \end_layout
28584
28585 \begin_layout Standard
28586 Here you can find some general tips for compiling programs with SDCC/pic16.
28587 \end_layout
28588
28589 \begin_layout Subsubsection
28590 Stack size
28591 \end_layout
28592
28593 \begin_layout Standard
28594 The default stack
28595 \begin_inset LatexCommand \index{PIC16!stack}
28596
28597 \end_inset
28598
28599  size (that is 64 bytes) probably is enough for many programs.
28600  One must take care that when there are many levels of function nesting,
28601  or there is excessive usage of stack, its size should be extended.
28602  An example of such a case is the printf/sprintf family of functions.
28603  If you encounter problems like not being able to print integers, then you
28604  need to set the stack size around the maximum (256 for small stack model).
28605  The following diagram shows what happens when calling printf to print an
28606  integer:
28607 \end_layout
28608
28609 \begin_layout LyX-Code
28610 printf () --> ltoa () --> ultoa () --> divschar ()
28611 \end_layout
28612
28613 \begin_layout Standard
28614 It is should be understood that stack is easily consumed when calling complicate
28615 d functions.
28616  Using command line arguments like -
28617 \begin_inset ERT
28618 status collapsed
28619
28620 \begin_layout Standard
28621
28622
28623 \backslash
28624 /
28625 \end_layout
28626
28627 \end_inset
28628
28629 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28630  stack frames.
28631  Other ways to reduce stack usage may exist.
28632 \end_layout
28633
28634 \begin_layout Subsection
28635 Known Bugs
28636 \end_layout
28637
28638 \begin_layout Standard
28639 The PIC16 Port currently does not pass SDCC's regression test
28640 \begin_inset LatexCommand \index{Regression test (PIC16)}
28641
28642 \end_inset
28643
28644  suite (see section 
28645 \begin_inset LatexCommand \ref{sec:Quality-control}
28646
28647 \end_inset
28648
28649 ) and thus the snapshot build regression tests for the PIC16 target are
28650  currently disabled for all hosts
28651 \emph on
28652 .
28653 \end_layout
28654
28655 \begin_layout Chapter
28656 Debugging
28657 \end_layout
28658
28659 \begin_layout Standard
28660 There are several approaches to debugging your code.
28661  This chapter is meant to show your options and to give detail on some of
28662  them:
28663 \newline
28664
28665 \newline
28666 When writing your code:
28667 \end_layout
28668
28669 \begin_layout Itemize
28670 write your code with debugging in mind (avoid duplicating code, put conceptually
28671  similar variables into structs, use structured code, have strategic points
28672  within your code where all variables are consistent, ...)
28673 \end_layout
28674
28675 \begin_layout Itemize
28676 run a syntax-checking tool like splint
28677 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28678
28679 \end_inset
28680
28681
28682 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28683
28684 \end_inset
28685
28686  (see -
28687 \begin_inset ERT
28688 status collapsed
28689
28690 \begin_layout Standard
28691
28692
28693 \backslash
28694 /
28695 \end_layout
28696
28697 \end_inset
28698
28699 -more-pedantic 
28700 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28701
28702 \end_inset
28703
28704 ) over the code.
28705 \end_layout
28706
28707 \begin_layout Itemize
28708 for the high level code use a C-compiler (like f.e.
28709  GCC) to compile run and debug the code on your host.
28710  See (see -
28711 \begin_inset ERT
28712 status collapsed
28713
28714 \begin_layout Standard
28715
28716
28717 \backslash
28718 /
28719 \end_layout
28720
28721 \end_inset
28722
28723 -more-pedantic 
28724 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28725
28726 \end_inset
28727
28728 ) on how to handle syntax extensions like __xdata, __at(), ...
28729  
28730 \end_layout
28731
28732 \begin_layout Itemize
28733 use another C-compiler to compile code for your target.
28734  Always an option but not recommended:) And not very likely to help you.
28735  If you seriously consider walking this path you should at least occasionally
28736  check portability of your code.
28737  Most commercial compiler vendors will offer an evaluation version so you
28738  can test compile your code or snippets of your code.
28739 \end_layout
28740
28741 \begin_layout Standard
28742 Debugging on a simulator:
28743 \end_layout
28744
28745 \begin_layout Itemize
28746 there is a separate section about SDCDB (section 
28747 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28748
28749 \end_inset
28750
28751 ) below.
28752 \end_layout
28753
28754 \begin_layout Itemize
28755 or (8051 specific) use a freeware/commercial simulator which interfaces
28756  to the AOMF
28757 \begin_inset LatexCommand \index{AOMF, AOMF51}
28758
28759 \end_inset
28760
28761  file (see 
28762 \begin_inset LatexCommand \ref{OMF file}
28763
28764 \end_inset
28765
28766 ) optionally generated by SDCC.
28767 \end_layout
28768
28769 \begin_layout Standard
28770 Debugging On-target: 
28771 \end_layout
28772
28773 \begin_layout Itemize
28774 use a MCU port pin to serially output debug data to the RS232 port of your
28775  host.
28776  You'll probably want some level shifting device typically involving a MAX232
28777  or similar IC.
28778  If the hardware serial port of the MCU is not available search for 'Software
28779  UART' in your favourite search machine.
28780 \end_layout
28781
28782 \begin_layout Itemize
28783 use an on-target monitor.
28784  In this context a monitor is a small program which usually accepts commands
28785  via a serial line and allows to set program counter, to single step through
28786  a program and read/write memory locations.
28787  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28788  
28789 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28790
28791 \end_inset
28792
28793 ).
28794 \end_layout
28795
28796 \begin_layout Itemize
28797 toggle MCU port pins at strategic points within your code and use an oscilloscop
28798 e.
28799  A 
28800 \emph on
28801 digital oscilloscope
28802 \emph default
28803
28804 \begin_inset LatexCommand \index{Oscilloscope}
28805
28806 \end_inset
28807
28808  with deep trace memory is really helpful especially if you have to debug
28809  a realtime application.
28810  If you need to monitor more pins than your oscilloscope provides you can
28811  sometimes get away with a small R-2R network.
28812  On a single channel oscilloscope you could f.e.
28813  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28814 k
28815 \begin_inset Formula $\Omega$
28816 \end_inset
28817
28818  resistor and the other one by a 5\InsetSpace ~
28819 k
28820 \begin_inset Formula $\Omega$
28821 \end_inset
28822
28823  resistor to the oscilloscope probe (check output drive capability of the
28824  pins you want to monitor).
28825  If you need to monitor many more pins a 
28826 \emph on
28827 logic analyzer
28828 \emph default
28829  will be handy.
28830 \end_layout
28831
28832 \begin_layout Itemize
28833 use an ICE (
28834 \emph on
28835 i
28836 \emph default
28837
28838 \emph on
28839 c
28840 \emph default
28841 ircuit 
28842 \emph on
28843 e
28844 \emph default
28845 mulator
28846 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28847
28848 \end_inset
28849
28850 ).
28851  Usually very expensive.
28852  And very nice to have too.
28853  And usually locks you (for years...) to the devices the ICE can emulate.
28854  
28855 \end_layout
28856
28857 \begin_layout Itemize
28858 use a remote debugger.
28859  In most 8-bit systems the symbol information is not available on the target,
28860  and a complete debugger is too bulky for the target system.
28861  Therefore usually a debugger on the host system connects to an on-target
28862  debugging stub which accepts only primitive commands.
28863  
28864 \newline
28865 Terms to enter into your favourite search engine could be 'remote debugging',
28866  'gdb stub' or 'inferior debugger'.
28867  (is there one?)
28868 \end_layout
28869
28870 \begin_layout Itemize
28871 use an on target hardware debugger.
28872  Some of the more modern MCUs include hardware support for setting break
28873  points and monitoring/changing variables by using dedicated hardware pins.
28874  This facility doesn't require additional code to run on the target and
28875  
28876 \emph on
28877 usually
28878 \emph default
28879  doesn't affect runtime behaviour until a breakpoint is hit.
28880  For the mcs51 most hardware debuggers use the AOMF
28881 \begin_inset LatexCommand \index{AOMF, AOMF51}
28882
28883 \end_inset
28884
28885  file (see 
28886 \begin_inset LatexCommand \ref{OMF file}
28887
28888 \end_inset
28889
28890 ) as input file.
28891  
28892 \end_layout
28893
28894 \begin_layout Standard
28895 Last not least:
28896 \end_layout
28897
28898 \begin_layout Itemize
28899 if you are not familiar with any of the following terms you're likely to
28900  run into problems rather sooner than later: 
28901 \emph on
28902 volatile
28903 \emph default
28904
28905 \emph on
28906 atomic
28907 \emph default
28908
28909 \emph on
28910 memory map
28911 \emph default
28912
28913 \emph on
28914 overlay
28915 \emph default
28916 .
28917  As an embedded programmer you 
28918 \emph on
28919 have
28920 \emph default
28921  to know them so why not look them up 
28922 \emph on
28923 before
28924 \emph default
28925  you have problems?)
28926 \end_layout
28927
28928 \begin_layout Itemize
28929 tell someone else about your problem (actually this is a surprisingly effective
28930  means to hunt down the bug even if the listener is not familiar with your
28931  environment).
28932  As 'failure to communicate' is probably one of the job-induced deformations
28933  of an embedded programmer this is highly encouraged.
28934 \end_layout
28935
28936 \begin_layout Section
28937 Debugging with SDCDB
28938 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28939
28940 \end_inset
28941
28942
28943 \begin_inset LatexCommand \index{SDCDB (debugger)}
28944
28945 \end_inset
28946
28947  
28948 \end_layout
28949
28950 \begin_layout Standard
28951 SDCC is distributed with a source level debugger
28952 \begin_inset LatexCommand \index{Debugger}
28953
28954 \end_inset
28955
28956 .
28957  The debugger uses a command line interface, the command repertoire of the
28958  debugger has been kept as close to gdb
28959 \begin_inset LatexCommand \index{gdb}
28960
28961 \end_inset
28962
28963  (the GNU debugger) as possible.
28964  The configuration and build process is part of the standard compiler installati
28965 on, which also builds and installs the debugger in the target directory
28966  specified during configuration.
28967  The debugger allows you debug BOTH at the C source and at the ASM source
28968  level.
28969 \end_layout
28970
28971 \begin_layout Subsection
28972 Compiling for Debugging
28973 \end_layout
28974
28975 \begin_layout Standard
28976 The -
28977 \begin_inset ERT
28978 status collapsed
28979
28980 \begin_layout Standard
28981
28982
28983 \backslash
28984 /
28985 \end_layout
28986
28987 \end_inset
28988
28989 -debug
28990 \begin_inset LatexCommand \index{-\/-debug}
28991
28992 \end_inset
28993
28994  option must be specified for all files for which debug information is to
28995  be generated.
28996  The compiler generates a .adb file for each of these files.
28997  The linker creates the .cdb
28998 \begin_inset LatexCommand \index{<file>.cdb}
28999
29000 \end_inset
29001
29002  file from the .adb
29003 \begin_inset LatexCommand \index{<file>.adb}
29004
29005 \end_inset
29006
29007  files and the address information.
29008  This .cdb is used by the debugger.
29009 \end_layout
29010
29011 \begin_layout Subsection
29012 How the Debugger Works
29013 \end_layout
29014
29015 \begin_layout Standard
29016 When the -
29017 \begin_inset ERT
29018 status collapsed
29019
29020 \begin_layout Standard
29021
29022
29023 \backslash
29024 /
29025 \end_layout
29026
29027 \end_inset
29028
29029 -debug option is specified the compiler generates extra symbol information
29030  some of which are put into the assembler source and some are put into the
29031  .adb file.
29032  Then the linker creates the .cdb file from the individual .adb files with
29033  the address information for the symbols.
29034  The debugger reads the symbolic information generated by the compiler &
29035  the address information generated by the linker.
29036  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29037  execution is controlled by the debugger.
29038  When a command is issued for the debugger, it translates it into appropriate
29039  commands for the simulator.
29040  (Currently SDCDM only connects to the simulator but 
29041 \emph on
29042 newcdb
29043 \emph default
29044  at 
29045 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29046
29047 \end_inset
29048
29049  is an effort to connect directly to the hardware.) 
29050 \end_layout
29051
29052 \begin_layout Subsection
29053 Starting the Debugger SDCDB
29054 \end_layout
29055
29056 \begin_layout Standard
29057 The debugger can be started using the following command line.
29058  (Assume the file you are debugging has the file name foo).
29059 \newline
29060
29061 \newline
29062
29063 \family sans
29064 \series bold
29065 sdcdb foo
29066 \newline
29067
29068 \family default
29069 \series default
29070
29071 \newline
29072 The debugger will look for the following files.
29073 \end_layout
29074
29075 \begin_layout Itemize
29076 foo.c - the source file.
29077 \end_layout
29078
29079 \begin_layout Itemize
29080 foo.cdb - the debugger symbol information file.
29081 \end_layout
29082
29083 \begin_layout Itemize
29084 foo.ihx - the Intel hex format
29085 \begin_inset LatexCommand \index{Intel hex format}
29086
29087 \end_inset
29088
29089  object file.
29090 \end_layout
29091
29092 \begin_layout Subsection
29093 SDCDB Command Line Options
29094 \end_layout
29095
29096 \begin_layout Itemize
29097 -
29098 \begin_inset ERT
29099 status collapsed
29100
29101 \begin_layout Standard
29102
29103
29104 \backslash
29105 /
29106 \end_layout
29107
29108 \end_inset
29109
29110 -directory=<source file directory> this option can used to specify the directory
29111  search list.
29112  The debugger will look into the directory list specified for source, cdb
29113  & ihx files.
29114  The items in the directory list must be separated by ':', e.g.
29115  if the source files can be in the directories /home/src1 and /home/src2,
29116  the -
29117 \begin_inset ERT
29118 status collapsed
29119
29120 \begin_layout Standard
29121
29122
29123 \backslash
29124 /
29125 \end_layout
29126
29127 \end_inset
29128
29129 -directory option should be -
29130 \begin_inset ERT
29131 status collapsed
29132
29133 \begin_layout Standard
29134
29135
29136 \backslash
29137 /
29138 \end_layout
29139
29140 \end_inset
29141
29142 -directory=/home/src1:/home/src2.
29143  Note there can be no spaces in the option.
29144  
29145 \end_layout
29146
29147 \begin_layout Itemize
29148 -cd <directory> - change to the <directory>.
29149 \end_layout
29150
29151 \begin_layout Itemize
29152 -fullname - used by GUI front ends.
29153 \end_layout
29154
29155 \begin_layout Itemize
29156 -cpu <cpu-type> - this argument is passed to the simulator please see the
29157  simulator docs for details.
29158 \end_layout
29159
29160 \begin_layout Itemize
29161 -X <Clock frequency > this options is passed to the simulator please see
29162  the simulator docs for details.
29163 \end_layout
29164
29165 \begin_layout Itemize
29166 -s <serial port file> passed to simulator see the simulator docs for details.
29167 \end_layout
29168
29169 \begin_layout Itemize
29170 -S <serial in,out> passed to simulator see the simulator docs for details.
29171 \end_layout
29172
29173 \begin_layout Itemize
29174 -k <port number> passed to simulator see the simulator docs for details.
29175 \end_layout
29176
29177 \begin_layout Subsection
29178 SDCDB Debugger Commands
29179 \end_layout
29180
29181 \begin_layout Standard
29182 As mentioned earlier the command interface for the debugger has been deliberatel
29183 y kept as close the GNU debugger gdb, as possible.
29184  This will help the integration with existing graphical user interfaces
29185  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29186  If you use a graphical user interface for the debugger you can skip this
29187  section.
29188 \end_layout
29189
29190 \begin_layout Subsubsection*
29191 break [line | file:line | function | file:function]
29192 \end_layout
29193
29194 \begin_layout Standard
29195 Set breakpoint at specified line or function:
29196 \newline
29197
29198 \newline
29199
29200 \family sans
29201 \series bold
29202 sdcdb>break 100 
29203 \newline
29204 sdcdb>break foo.c:100
29205 \newline
29206 sdcdb>break funcfoo
29207 \newline
29208 sdcdb>break foo.c:funcfoo
29209 \end_layout
29210
29211 \begin_layout Subsubsection*
29212 clear [line | file:line | function | file:function ]
29213 \end_layout
29214
29215 \begin_layout Standard
29216 Clear breakpoint at specified line or function:
29217 \newline
29218
29219 \newline
29220
29221 \family sans
29222 \series bold
29223 sdcdb>clear 100
29224 \newline
29225 sdcdb>clear foo.c:100
29226 \newline
29227 sdcdb>clear funcfoo
29228 \newline
29229 sdcdb>clear foo.c:funcfoo
29230 \end_layout
29231
29232 \begin_layout Subsubsection*
29233 continue
29234 \end_layout
29235
29236 \begin_layout Standard
29237 Continue program being debugged, after breakpoint.
29238 \end_layout
29239
29240 \begin_layout Subsubsection*
29241 finish
29242 \end_layout
29243
29244 \begin_layout Standard
29245 Execute till the end of the current function.
29246 \end_layout
29247
29248 \begin_layout Subsubsection*
29249 delete [n]
29250 \end_layout
29251
29252 \begin_layout Standard
29253 Delete breakpoint number 'n'.
29254  If used without any option clear ALL user defined break points.
29255 \end_layout
29256
29257 \begin_layout Subsubsection*
29258 info [break | stack | frame | registers ]
29259 \end_layout
29260
29261 \begin_layout Itemize
29262 info break - list all breakpoints
29263 \end_layout
29264
29265 \begin_layout Itemize
29266 info stack - show the function call stack.
29267 \end_layout
29268
29269 \begin_layout Itemize
29270 info frame - show information about the current execution frame.
29271 \end_layout
29272
29273 \begin_layout Itemize
29274 info registers - show content of all registers.
29275 \end_layout
29276
29277 \begin_layout Subsubsection*
29278 step
29279 \end_layout
29280
29281 \begin_layout Standard
29282 Step program until it reaches a different source line.
29283  Note: pressing <return> repeats the last command.
29284 \end_layout
29285
29286 \begin_layout Subsubsection*
29287 next
29288 \end_layout
29289
29290 \begin_layout Standard
29291 Step program, proceeding through subroutine calls.
29292 \end_layout
29293
29294 \begin_layout Subsubsection*
29295 run
29296 \end_layout
29297
29298 \begin_layout Standard
29299 Start debugged program.
29300 \end_layout
29301
29302 \begin_layout Subsubsection*
29303 ptype variable 
29304 \end_layout
29305
29306 \begin_layout Standard
29307 Print type information of the variable.
29308 \end_layout
29309
29310 \begin_layout Subsubsection*
29311 print variable
29312 \end_layout
29313
29314 \begin_layout Standard
29315 print value of variable.
29316 \end_layout
29317
29318 \begin_layout Subsubsection*
29319 file filename
29320 \end_layout
29321
29322 \begin_layout Standard
29323 load the given file name.
29324  Note this is an alternate method of loading file for debugging.
29325 \end_layout
29326
29327 \begin_layout Subsubsection*
29328 frame
29329 \end_layout
29330
29331 \begin_layout Standard
29332 print information about current frame.
29333 \end_layout
29334
29335 \begin_layout Subsubsection*
29336 set srcmode
29337 \end_layout
29338
29339 \begin_layout Standard
29340 Toggle between C source & assembly source.
29341 \end_layout
29342
29343 \begin_layout Subsubsection*
29344 ! simulator command
29345 \end_layout
29346
29347 \begin_layout Standard
29348 Send the string following '!' to the simulator, the simulator response is
29349  displayed.
29350  Note the debugger does not interpret the command being sent to the simulator,
29351  so if a command like 'go' is sent the debugger can loose its execution
29352  context and may display incorrect values.
29353 \end_layout
29354
29355 \begin_layout Subsubsection*
29356 quit
29357 \end_layout
29358
29359 \begin_layout Standard
29360 "Watch me now.
29361  Iam going Down.
29362  My name is Bobby Brown"
29363 \end_layout
29364
29365 \begin_layout Subsection
29366 Interfacing SDCDB with DDD
29367 \end_layout
29368
29369 \begin_layout Standard
29370 \begin_inset Note Note
29371 status collapsed
29372
29373 \begin_layout Standard
29374 The screenshot was converted from png to eps with: 
29375 \begin_inset Quotes sld
29376 \end_inset
29377
29378 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29379 \begin_inset Quotes srd
29380 \end_inset
29381
29382  which produces a pretty compact eps file which is free from compression
29383  artifacts.
29384 \end_layout
29385
29386 \begin_layout Standard
29387 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29388  as this broke the build system on Sourceforge (pdf-file was broken.
29389  pdflatex does not accept eps files).
29390 \end_layout
29391
29392 \end_inset
29393
29394
29395 \end_layout
29396
29397 \begin_layout Standard
29398 The 
29399 \emph on
29400 p
29401 \emph default
29402 ortable 
29403 \emph on
29404 n
29405 \emph default
29406 etwork 
29407 \emph on
29408 g
29409 \emph default
29410 raphics File 
29411 \size footnotesize
29412
29413 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29414
29415 \end_inset
29416
29417
29418 \size default
29419  shows a screenshot of a debugging session with DDD
29420 \begin_inset LatexCommand \index{DDD (debugger)}
29421
29422 \end_inset
29423
29424  (Unix only) on a simulated 8032.
29425  The debugging session might not run as smoothly as the screenshot suggests.
29426  The debugger allows setting of breakpoints, displaying and changing variables,
29427  single stepping through C and assembler code.
29428  
29429 \newline
29430 The source was compiled with 
29431 \family sans
29432 \series bold
29433
29434 \newline
29435
29436 \newline
29437 sdcc -
29438 \family default
29439 \series default
29440
29441 \begin_inset ERT
29442 status collapsed
29443
29444 \begin_layout Standard
29445
29446
29447 \backslash
29448 /
29449 \end_layout
29450
29451 \end_inset
29452
29453
29454 \family sans
29455 \series bold
29456 -debug ddd_example.c
29457 \family default
29458 \series default
29459  
29460 \family sans
29461 \series bold
29462
29463 \newline
29464
29465 \family default
29466 \series default
29467
29468 \newline
29469 and DDD was invoked with 
29470 \family sans
29471 \series bold
29472
29473 \newline
29474
29475 \newline
29476 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29477 \end_layout
29478
29479 \begin_layout Standard
29480 \begin_inset Note Note
29481 status open
29482
29483 \begin_layout Standard
29484 Check that the double quotes or an apostroph within the command line survive
29485  the LyX tool chain.
29486  Previously the apostrophs got slanted in the PDF output so a cut and paste
29487  did not work.
29488 \end_layout
29489
29490 \end_inset
29491
29492
29493 \end_layout
29494
29495 \begin_layout Subsection
29496 Interfacing SDCDB with XEmacs
29497 \begin_inset LatexCommand \index{XEmacs}
29498
29499 \end_inset
29500
29501
29502 \begin_inset LatexCommand \index{Emacs}
29503
29504 \end_inset
29505
29506
29507 \end_layout
29508
29509 \begin_layout Standard
29510 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29511  sdcdb.el and sdcdbsrc.el.
29512  These two files can be found in the $(prefix)/bin directory after the installat
29513 ion is complete.
29514  These files need to be loaded into XEmacs for the interface to work.
29515  This can be done at XEmacs startup time by inserting the following into
29516  your '.xemacs' file (which can be found in your HOME directory): 
29517 \newline
29518
29519 \newline
29520
29521 \family typewriter
29522 (load-file sdcdbsrc.el) 
29523 \family default
29524
29525 \newline
29526
29527 \newline
29528 .xemacs is a lisp file so the () around the command is REQUIRED.
29529  The files can also be loaded dynamically while XEmacs is running, set the
29530  environment variable 'EMACSLOADPATH' to the installation bin directory
29531  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29532  To start the interface enter the following command: 
29533 \newline
29534
29535 \newline
29536
29537 \family sans
29538 \series bold
29539 ESC-x sdcdbsrc
29540 \family default
29541 \series default
29542
29543 \newline
29544
29545 \newline
29546 You will prompted to enter the file name to be debugged.
29547  
29548 \newline
29549
29550 \newline
29551 The command line options that are passed to the simulator directly are
29552  bound to default values in the file sdcdbsrc.el.
29553  The variables are listed below, these values maybe changed as required.
29554 \end_layout
29555
29556 \begin_layout Itemize
29557 sdcdbsrc-cpu-type '51
29558 \end_layout
29559
29560 \begin_layout Itemize
29561 sdcdbsrc-frequency '11059200
29562 \end_layout
29563
29564 \begin_layout Itemize
29565 sdcdbsrc-serial nil
29566 \end_layout
29567
29568 \begin_layout Standard
29569 The following is a list of key mapping for the debugger interface.
29570 \end_layout
29571
29572 \begin_layout Standard
29573 \InsetSpace ~
29574
29575 \family typewriter
29576
29577 \newline
29578 ;;\InsetSpace ~
29579 Current Listing :: 
29580 \newline
29581 ;;key\InsetSpace ~
29582 \InsetSpace ~
29583 \InsetSpace ~
29584 \InsetSpace ~
29585 \InsetSpace ~
29586 \InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 \InsetSpace ~
29592 \InsetSpace ~
29593 \InsetSpace ~
29594 \InsetSpace ~
29595 binding\InsetSpace ~
29596 \InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 Comment 
29618 \newline
29619 ;;---\InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 -------\InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 -------
29656 \newline
29657 ;; 
29658 \newline
29659 ;;\InsetSpace ~
29660 n\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 sdcdb-next-fro
29676 m-src\InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 SDCDB next command 
29687 \newline
29688 ;;\InsetSpace ~
29689 b\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 sdcdb-back-from-src\InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 SDCDB back command 
29715 \newline
29716 ;;\InsetSpace ~
29717 c\InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 \InsetSpace ~
29732 sdcdb-cont-f
29733 rom-src\InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 SDCDB continue command
29744 \newline
29745 ;;\InsetSpace ~
29746 s\InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 \InsetSpace ~
29751 \InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
29761 sdcdb-step-from-src\InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 SDCDB step command 
29772 \newline
29773 ;;\InsetSpace ~
29774 ?\InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 \InsetSpace ~
29781 \InsetSpace ~
29782 \InsetSpace ~
29783 \InsetSpace ~
29784 \InsetSpace ~
29785 \InsetSpace ~
29786 \InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 sdcdb-w
29790 hatis-c-sexp\InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 SDCDB ptypecommand for data at 
29801 \newline
29802 ;;\InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 \InsetSpace ~
29808 \InsetSpace ~
29809 \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 \InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
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 buffer point 
29850 \newline
29851 ;;\InsetSpace ~
29852 x\InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 \InsetSpace ~
29867 sdcdbsrc-delete\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 SDCD
29882 B Delete all breakpoints if no arg 
29883 \newline
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 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 \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 \InsetSpace ~
29931 given or delete arg (C-u arg x) 
29932 \newline
29933 ;;\InsetSpace ~
29934 m\InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 \InsetSpace ~
29945 \InsetSpace ~
29946 \InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 sdcdbsrc
29950 -frame\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 SDCDB Display current frame if no arg, 
29966 \newline
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 \InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 \InsetSpace ~
30013 \InsetSpace ~
30014 given or display frame arg
30015  
30016 \newline
30017 ;;\InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \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 buffer point 
30065 \newline
30066 ;;\InsetSpace ~
30067 !\InsetSpace ~
30068 \InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 sdcdbsrc-goto-sdcdb\InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 Goto the SDCDB output buffer 
30093 \newline
30094 ;;\InsetSpace ~
30095 p\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 sdcdb-prin
30111 t-c-sexp\InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 SDCDB print command for data at 
30123 \newline
30124 ;;\InsetSpace ~
30125 \InsetSpace ~
30126 \InsetSpace ~
30127 \InsetSpace ~
30128 \InsetSpace ~
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 \InsetSpace ~
30146 \InsetSpace ~
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150 \InsetSpace ~
30151 \InsetSpace ~
30152 \InsetSpace ~
30153 \InsetSpace ~
30154 \InsetSpace ~
30155 \InsetSpace ~
30156 \InsetSpace ~
30157 \InsetSpace ~
30158 \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 buffer point 
30172 \newline
30173 ;;\InsetSpace ~
30174 g\InsetSpace ~
30175 \InsetSpace ~
30176 \InsetSpace ~
30177 \InsetSpace ~
30178 \InsetSpace ~
30179 \InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186 \InsetSpace ~
30187 \InsetSpace ~
30188 \InsetSpace ~
30189 sdcdbsrc-goto-sdcdb\InsetSpace ~
30190 \InsetSpace ~
30191 \InsetSpace ~
30192 \InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 \InsetSpace ~
30199 Got
30200 o the SDCDB output buffer 
30201 \newline
30202 ;;\InsetSpace ~
30203 t\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 sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it
30235  off) 
30236 \newline
30237 ;; 
30238 \newline
30239 ;;\InsetSpace ~
30240 C-c\InsetSpace ~
30241 C-f\InsetSpace ~
30242 \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 sdcdb-finish-from-src\InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256 \InsetSpace ~
30257 \InsetSpace ~
30258 SDCDB finish command 
30259 \newline
30260 ;; 
30261 \newline
30262 ;;\InsetSpace ~
30263 C-x\InsetSpace ~
30264 SPC\InsetSpace ~
30265 \InsetSpace ~
30266 \InsetSpace ~
30267 \InsetSpace ~
30268 \InsetSpace ~
30269 \InsetSpace ~
30270 \InsetSpace ~
30271 \InsetSpace ~
30272 \InsetSpace ~
30273 sdcdb-brea
30274 k\InsetSpace ~
30275 \InsetSpace ~
30276 \InsetSpace ~
30277 \InsetSpace ~
30278 \InsetSpace ~
30279 \InsetSpace ~
30280 \InsetSpace ~
30281 \InsetSpace ~
30282 \InsetSpace ~
30283 \InsetSpace ~
30284 \InsetSpace ~
30285 \InsetSpace ~
30286 \InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 Set break for line with point 
30293 \newline
30294 ;;\InsetSpace ~
30295 ESC\InsetSpace ~
30296 t\InsetSpace ~
30297 \InsetSpace ~
30298 \InsetSpace ~
30299 \InsetSpace ~
30300 \InsetSpace ~
30301 \InsetSpace ~
30302 \InsetSpace ~
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306 \InsetSpace ~
30307 sdcdbsrc-mode\InsetSpace ~
30308 \InsetSpace ~
30309 \InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 \InsetSpace ~
30313 \InsetSpace ~
30314 \InsetSpace ~
30315 \InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 \InsetSpace ~
30322 \InsetSpace ~
30323 Toggle Sdcdbsrc mode 
30324 \newline
30325 ;;\InsetSpace ~
30326 ESC\InsetSpace ~
30327 m\InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 \InsetSpace ~
30332 \InsetSpace ~
30333 \InsetSpace ~
30334 \InsetSpace ~
30335 \InsetSpace ~
30336 \InsetSpace ~
30337 \InsetSpace ~
30338 sdc
30339 dbsrc-srcmode\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 Toggle list mode 
30353 \newline
30354 ;; 
30355 \newline
30356
30357 \family default
30358
30359 \newpage
30360
30361 \end_layout
30362
30363 \begin_layout Chapter
30364 TIPS
30365 \end_layout
30366
30367 \begin_layout Standard
30368 Here are a few guidelines that will help the compiler generate more efficient
30369  code, some of the tips are specific to this compiler others are generally
30370  good programming practice.
30371 \end_layout
30372
30373 \begin_layout Itemize
30374 Use the smallest data type to represent your data-value.
30375  If it is known in advance that the value is going to be less than 256 then
30376  use an 'unsigned char' instead of a 'short' or 'int'.
30377  Please note, that ANSI C requires both signed and unsigned chars to be
30378  promoted to 'signed int'
30379 \begin_inset LatexCommand \index{promotion to signed int}
30380
30381 \end_inset
30382
30383
30384 \begin_inset Marginal
30385 status collapsed
30386
30387 \begin_layout Standard
30388
30389 \series bold
30390 \InsetSpace ~
30391 !
30392 \end_layout
30393
30394 \end_inset
30395
30396  before doing any operation.
30397  This promotion
30398 \begin_inset LatexCommand \index{type promotion}
30399
30400 \end_inset
30401
30402
30403 \begin_inset LatexCommand \label{type promotion}
30404
30405 \end_inset
30406
30407  can be omitted, if the result is the same.
30408  The effect of the promotion rules together with the sign-extension is often
30409  surprising:
30410 \end_layout
30411
30412 \begin_deeper
30413 \begin_layout Verse
30414
30415 \family typewriter
30416 unsigned char uc = 0xfe;
30417 \newline
30418 if (uc * uc < 0) /* this is true! */
30419 \newline
30420 {
30421 \newline
30422 \InsetSpace ~
30423 \InsetSpace ~
30424 \InsetSpace ~
30425 \InsetSpace ~
30426 ....
30427 \newline
30428 }
30429 \end_layout
30430
30431 \begin_layout Standard
30432
30433 \family typewriter
30434 uc * uc
30435 \family default
30436  is evaluated as 
30437 \family typewriter
30438 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30439 \family default
30440 .
30441  
30442 \newline
30443 Another one:
30444 \end_layout
30445
30446 \begin_layout Verse
30447
30448 \family typewriter
30449 (unsigned char) -12 / (signed char) -3 = ...
30450 \end_layout
30451
30452 \begin_layout Standard
30453 No, the result is not 4:
30454 \end_layout
30455
30456 \begin_layout Verse
30457
30458 \family typewriter
30459 (int) (unsigned char) -12 / (int) (signed char) -3 =
30460 \newline
30461 (int) (unsigned char)
30462  0xf4 / (int) (signed char) 0xfd =
30463 \newline
30464 (int) 0x00f4 / (int) 0xfffd =
30465 \newline
30466 (int) 0x00f4
30467  / (int) 0xfffd =
30468 \newline
30469 (int) 244 / (int) -3 =
30470 \newline
30471 (int) -81 = (int) 0xffaf;
30472 \end_layout
30473
30474 \begin_layout Standard
30475 Don't complain, that gcc gives you a different result.
30476  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30477  Therefore the results are different.
30478 \newline
30479 From 
30480 \begin_inset Quotes sld
30481 \end_inset
30482
30483 comp.lang.c FAQ
30484 \begin_inset Quotes srd
30485 \end_inset
30486
30487 :
30488 \end_layout
30489
30490 \begin_layout Quote
30491
30492 \emph on
30493 If well-defined overflow characteristics are important and negative values
30494  are not, or if you want to steer clear of sign-extension problems when
30495  manipulating bits or bytes, use one of the corresponding unsigned types.
30496  (Beware when mixing signed and unsigned values in expressions, though.)
30497 \newline
30498 Although
30499  character types (especially unsigned char) can be used as "tiny" integers,
30500  doing so is sometimes more trouble than it's worth, due to unpredictable
30501  sign extension and increased code size.
30502 \end_layout
30503
30504 \end_deeper
30505 \begin_layout Itemize
30506 Use unsigned when it is known in advance that the value is not going to
30507  be negative.
30508  This helps especially if you are doing division or multiplication, bit-shifting
30509  or are using an array index.
30510 \end_layout
30511
30512 \begin_layout Itemize
30513 NEVER jump into a LOOP.
30514 \end_layout
30515
30516 \begin_layout Itemize
30517 Declare the variables to be local
30518 \begin_inset LatexCommand \index{local variables}
30519
30520 \end_inset
30521
30522  whenever possible, especially loop control variables (induction).
30523 \end_layout
30524
30525 \begin_layout Itemize
30526 Have a look at the assembly listing to get a 
30527 \begin_inset Quotes sld
30528 \end_inset
30529
30530 feeling
30531 \begin_inset Quotes srd
30532 \end_inset
30533
30534  for the code generation.
30535 \end_layout
30536
30537 \begin_layout Section
30538 Porting code from or to other compilers
30539 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30540
30541 \end_inset
30542
30543
30544 \end_layout
30545
30546 \begin_layout Itemize
30547 check whether endianness of the compilers differs and adapt where needed.
30548 \end_layout
30549
30550 \begin_layout Itemize
30551 check the device specific header files
30552 \begin_inset LatexCommand \index{Header files}
30553
30554 \end_inset
30555
30556
30557 \begin_inset LatexCommand \index{Include files}
30558
30559 \end_inset
30560
30561  for compiler specific syntax.
30562  Eventually include the file <compiler.h
30563 \begin_inset LatexCommand \index{compiler.h (include file)}
30564
30565 \end_inset
30566
30567
30568 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30569
30570 \end_inset
30571
30572  to allow using common header files.
30573  (see f.e.
30574  cc2510fx.h 
30575 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30576
30577 \end_inset
30578
30579 ).
30580 \end_layout
30581
30582 \begin_layout Itemize
30583 check whether the startup code contains the correct initialization (watchdog,
30584  peripherals).
30585 \end_layout
30586
30587 \begin_layout Itemize
30588 check whether the sizes of short, int, long match.
30589 \end_layout
30590
30591 \begin_layout Itemize
30592 check if some 16 or 32 bit hardware registers require a specific addressing
30593  order (least significant or most significant byte first) and adapt if needed
30594  (
30595 \emph on
30596 first
30597 \emph default
30598  and 
30599 \emph on
30600 last
30601 \emph default
30602  relate to time and not to lower/upper memory location here, so this is
30603  
30604 \emph on
30605 not
30606 \emph default
30607  the same as endianness).
30608 \end_layout
30609
30610 \begin_layout Itemize
30611 check whether the keyword 
30612 \emph on
30613 volatile
30614 \emph default
30615  is used where needed.
30616  The compilers might differ in their optimization characteristics (as different
30617  versions of the same compiler might also use more clever optimizations
30618  this is good idea anyway).
30619  See section 
30620 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30621
30622 \end_inset
30623
30624 .
30625 \end_layout
30626
30627 \begin_layout Itemize
30628 check that the compilers are not told to supress warnings.
30629 \end_layout
30630
30631 \begin_layout Itemize
30632 check and convert compiler specific extensions (interrupts, memory areas,
30633  pragmas etc.).
30634 \end_layout
30635
30636 \begin_layout Itemize
30637 check for differences in type promotion.
30638  Especially check for math operations on 
30639 \family typewriter
30640 char
30641 \family default
30642  or 
30643 \family typewriter
30644 unsigned char
30645 \family default
30646  variables.
30647  For the sake of C99 compatibility SDCC will probably promote these to 
30648 \family typewriter
30649 int
30650 \family default
30651  more often than other compilers.
30652  Eventually insert explicit casts to 
30653 \family typewriter
30654 (char) 
30655 \family default
30656 or
30657 \family typewriter
30658  (unsigned char)
30659 \family default
30660 .
30661  Also check that the ~\InsetSpace ~
30662 operator
30663 \begin_inset LatexCommand \index{\~\/ Operator}
30664
30665 \end_inset
30666
30667  is not used on 
30668 \family typewriter
30669 bit
30670 \begin_inset LatexCommand \index{bit}
30671
30672 \end_inset
30673
30674
30675 \family default
30676  variables, use the !\InsetSpace ~
30677 operator instead.
30678  See sections 
30679 \begin_inset LatexCommand \ref{type promotion}
30680
30681 \end_inset
30682
30683  and 
30684 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30685
30686 \end_inset
30687
30688 .
30689 \end_layout
30690
30691 \begin_layout Itemize
30692 check the assembly code generated for interrupt routines (f.e.
30693  for calls to possibly non-reentrant library functions).
30694 \end_layout
30695
30696 \begin_layout Itemize
30697 check whether timing loops result in proper timing (or preferably consider
30698  a rewrite of the code with timer based delays instead).
30699 \end_layout
30700
30701 \begin_layout Itemize
30702 check for differences in printf parameters (some compilers push (va_arg
30703 \begin_inset LatexCommand \index{vararg, va\_arg}
30704
30705 \end_inset
30706
30707 ) char variables as 
30708 \family typewriter
30709 int
30710 \family default
30711  others push them as 
30712 \family typewriter
30713 char
30714 \family default
30715 .
30716  See section 
30717 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30718
30719 \end_inset
30720
30721 ).
30722 \end_layout
30723
30724 \begin_layout Itemize
30725 check the resulting memory map
30726 \begin_inset LatexCommand \index{Memory map}
30727
30728 \end_inset
30729
30730 .
30731  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30732 ly idata, pdata, xdata).
30733  Eventually check if unexpected library functions are included.
30734 \end_layout
30735
30736 \begin_layout Section
30737 Tools
30738 \begin_inset LatexCommand \index{Tools}
30739
30740 \end_inset
30741
30742  included in the distribution
30743 \end_layout
30744
30745 \begin_layout Standard
30746 \align left
30747 \begin_inset Tabular
30748 <lyxtabular version="3" rows="12" columns="3">
30749 <features>
30750 <column alignment="left" valignment="top" leftline="true" width="0pt">
30751 <column alignment="left" valignment="top" leftline="true" width="0pt">
30752 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30753 <row topline="true" bottomline="true">
30754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30755 \begin_inset Text
30756
30757 \begin_layout Standard
30758
30759 \series bold
30760 Name
30761 \end_layout
30762
30763 \end_inset
30764 </cell>
30765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30766 \begin_inset Text
30767
30768 \begin_layout Standard
30769
30770 \series bold
30771 Purpose
30772 \end_layout
30773
30774 \end_inset
30775 </cell>
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30777 \begin_inset Text
30778
30779 \begin_layout Standard
30780
30781 \series bold
30782 Directory
30783 \end_layout
30784
30785 \end_inset
30786 </cell>
30787 </row>
30788 <row topline="true">
30789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30790 \begin_inset Text
30791
30792 \begin_layout Standard
30793 uCsim
30794 \begin_inset LatexCommand \index{uCsim}
30795
30796 \end_inset
30797
30798
30799 \end_layout
30800
30801 \end_inset
30802 </cell>
30803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30804 \begin_inset Text
30805
30806 \begin_layout Standard
30807 Simulator for various architectures
30808 \end_layout
30809
30810 \end_inset
30811 </cell>
30812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30813 \begin_inset Text
30814
30815 \begin_layout Standard
30816 sdcc/sim/ucsim
30817 \end_layout
30818
30819 \end_inset
30820 </cell>
30821 </row>
30822 <row topline="true">
30823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30824 \begin_inset Text
30825
30826 \begin_layout Standard
30827 keil2sdcc.pl
30828 \end_layout
30829
30830 \end_inset
30831 </cell>
30832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30833 \begin_inset Text
30834
30835 \begin_layout Standard
30836 header file
30837 \begin_inset LatexCommand \index{Header files}
30838
30839 \end_inset
30840
30841
30842 \begin_inset LatexCommand \index{Include files}
30843
30844 \end_inset
30845
30846  conversion
30847 \end_layout
30848
30849 \end_inset
30850 </cell>
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30852 \begin_inset Text
30853
30854 \begin_layout Standard
30855 sdcc/support/scripts
30856 \end_layout
30857
30858 \end_inset
30859 </cell>
30860 </row>
30861 <row topline="true">
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30863 \begin_inset Text
30864
30865 \begin_layout Standard
30866 mh2h.c
30867 \end_layout
30868
30869 \end_inset
30870 </cell>
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30872 \begin_inset Text
30873
30874 \begin_layout Standard
30875 header file conversion
30876 \end_layout
30877
30878 \end_inset
30879 </cell>
30880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30881 \begin_inset Text
30882
30883 \begin_layout Standard
30884 sdcc/support/scripts
30885 \end_layout
30886
30887 \end_inset
30888 </cell>
30889 </row>
30890 <row topline="true">
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30892 \begin_inset Text
30893
30894 \begin_layout Standard
30895 as-gbz80
30896 \end_layout
30897
30898 \end_inset
30899 </cell>
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_inset Text
30902
30903 \begin_layout Standard
30904 Assembler
30905 \end_layout
30906
30907 \end_inset
30908 </cell>
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30910 \begin_inset Text
30911
30912 \begin_layout Standard
30913
30914 \family roman
30915 \series medium
30916 \shape up
30917 \size normal
30918 \emph off
30919 \bar no
30920 \noun off
30921 \color none
30922 sdcc/bin
30923 \end_layout
30924
30925 \end_inset
30926 </cell>
30927 </row>
30928 <row topline="true">
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30930 \begin_inset Text
30931
30932 \begin_layout Standard
30933 as-z80
30934 \end_layout
30935
30936 \end_inset
30937 </cell>
30938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30939 \begin_inset Text
30940
30941 \begin_layout Standard
30942 Assembler
30943 \end_layout
30944
30945 \end_inset
30946 </cell>
30947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30948 \begin_inset Text
30949
30950 \begin_layout Standard
30951
30952 \family roman
30953 \series medium
30954 \shape up
30955 \size normal
30956 \emph off
30957 \bar no
30958 \noun off
30959 \color none
30960 sdcc/bin
30961 \end_layout
30962
30963 \end_inset
30964 </cell>
30965 </row>
30966 <row topline="true">
30967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30968 \begin_inset Text
30969
30970 \begin_layout Standard
30971 asx8051
30972 \end_layout
30973
30974 \end_inset
30975 </cell>
30976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30977 \begin_inset Text
30978
30979 \begin_layout Standard
30980 Assembler
30981 \end_layout
30982
30983 \end_inset
30984 </cell>
30985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30986 \begin_inset Text
30987
30988 \begin_layout Standard
30989
30990 \family roman
30991 \series medium
30992 \shape up
30993 \size normal
30994 \emph off
30995 \bar no
30996 \noun off
30997 \color none
30998 sdcc/bin
30999 \end_layout
31000
31001 \end_inset
31002 </cell>
31003 </row>
31004 <row topline="true">
31005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31006 \begin_inset Text
31007
31008 \begin_layout Standard
31009 SDCDB
31010 \end_layout
31011
31012 \end_inset
31013 </cell>
31014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31015 \begin_inset Text
31016
31017 \begin_layout Standard
31018 Simulator
31019 \end_layout
31020
31021 \end_inset
31022 </cell>
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027
31028 \family roman
31029 \series medium
31030 \shape up
31031 \size normal
31032 \emph off
31033 \bar no
31034 \noun off
31035 \color none
31036 sdcc/bin
31037 \end_layout
31038
31039 \end_inset
31040 </cell>
31041 </row>
31042 <row topline="true">
31043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31044 \begin_inset Text
31045
31046 \begin_layout Standard
31047 aslink
31048 \end_layout
31049
31050 \end_inset
31051 </cell>
31052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_inset Text
31054
31055 \begin_layout Standard
31056 Linker
31057 \end_layout
31058
31059 \end_inset
31060 </cell>
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31062 \begin_inset Text
31063
31064 \begin_layout Standard
31065
31066 \family roman
31067 \series medium
31068 \shape up
31069 \size normal
31070 \emph off
31071 \bar no
31072 \noun off
31073 \color none
31074 sdcc/bin
31075 \end_layout
31076
31077 \end_inset
31078 </cell>
31079 </row>
31080 <row topline="true">
31081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31082 \begin_inset Text
31083
31084 \begin_layout Standard
31085 link-z80
31086 \end_layout
31087
31088 \end_inset
31089 </cell>
31090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31091 \begin_inset Text
31092
31093 \begin_layout Standard
31094 Linker
31095 \end_layout
31096
31097 \end_inset
31098 </cell>
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \begin_layout Standard
31103
31104 \family roman
31105 \series medium
31106 \shape up
31107 \size normal
31108 \emph off
31109 \bar no
31110 \noun off
31111 \color none
31112 sdcc/bin
31113 \end_layout
31114
31115 \end_inset
31116 </cell>
31117 </row>
31118 <row topline="true">
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31120 \begin_inset Text
31121
31122 \begin_layout Standard
31123 link-gbz80
31124 \end_layout
31125
31126 \end_inset
31127 </cell>
31128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31129 \begin_inset Text
31130
31131 \begin_layout Standard
31132 Linker
31133 \end_layout
31134
31135 \end_inset
31136 </cell>
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31138 \begin_inset Text
31139
31140 \begin_layout Standard
31141
31142 \family roman
31143 \series medium
31144 \shape up
31145 \size normal
31146 \emph off
31147 \bar no
31148 \noun off
31149 \color none
31150 sdcc/bin
31151 \end_layout
31152
31153 \end_inset
31154 </cell>
31155 </row>
31156 <row topline="true" bottomline="true">
31157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31158 \begin_inset Text
31159
31160 \begin_layout Standard
31161 packihx
31162 \end_layout
31163
31164 \end_inset
31165 </cell>
31166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31167 \begin_inset Text
31168
31169 \begin_layout Standard
31170 Intel Hex packer 
31171 \begin_inset LatexCommand \index{packihx (tool)}
31172
31173 \end_inset
31174
31175
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184
31185 \family roman
31186 \series medium
31187 \shape up
31188 \size normal
31189 \emph off
31190 \bar no
31191 \noun off
31192 \color none
31193 sdcc/bin
31194 \end_layout
31195
31196 \end_inset
31197 </cell>
31198 </row>
31199 </lyxtabular>
31200
31201 \end_inset
31202
31203
31204 \newline
31205
31206 \end_layout
31207
31208 \begin_layout Section
31209 Documentation
31210 \begin_inset LatexCommand \index{Documentation}
31211
31212 \end_inset
31213
31214  included in the distribution
31215 \end_layout
31216
31217 \begin_layout Standard
31218 \align left
31219 \begin_inset Tabular
31220 <lyxtabular version="3" rows="10" columns="2">
31221 <features>
31222 <column alignment="block" valignment="top" leftline="true" width="40col%">
31223 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31224 <row topline="true" bottomline="true" endhead="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \begin_layout Standard
31229
31230 \series bold
31231 Subject / Title
31232 \end_layout
31233
31234 \end_inset
31235 </cell>
31236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31237 \begin_inset Text
31238
31239 \begin_layout Standard
31240
31241 \series bold
31242 Filename / Where to get
31243 \end_layout
31244
31245 \end_inset
31246 </cell>
31247 </row>
31248 <row topline="true">
31249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31250 \begin_inset Text
31251
31252 \begin_layout Standard
31253 SDCC Compiler User Guide
31254 \end_layout
31255
31256 \end_inset
31257 </cell>
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31259 \begin_inset Text
31260
31261 \begin_layout Standard
31262 You're reading it right now
31263 \emph on
31264  \InsetSpace ~
31265 \InsetSpace ~
31266 \InsetSpace ~
31267
31268 \hfill
31269 online at:
31270 \emph default
31271
31272 \newline
31273
31274 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31275
31276 \end_inset
31277
31278
31279 \end_layout
31280
31281 \end_inset
31282 </cell>
31283 </row>
31284 <row topline="true">
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289 Changelog of SDCC
31290 \end_layout
31291
31292 \end_inset
31293 </cell>
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31295 \begin_inset Text
31296
31297 \begin_layout Standard
31298 sdcc/Changelog
31299 \emph on
31300  \InsetSpace ~
31301 \InsetSpace ~
31302 \InsetSpace ~
31303
31304 \hfill
31305 online at:
31306 \emph default
31307
31308 \newline
31309
31310 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31311
31312 \end_inset
31313
31314
31315 \end_layout
31316
31317 \end_inset
31318 </cell>
31319 </row>
31320 <row topline="true">
31321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31322 \begin_inset Text
31323
31324 \begin_layout Standard
31325 ASXXXX
31326 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31327
31328 \end_inset
31329
31330
31331 \begin_inset LatexCommand \index{Assembler documentation}
31332
31333 \end_inset
31334
31335  Assemblers and
31336 \newline
31337 ASLINK
31338 \begin_inset LatexCommand \index{aslink}
31339
31340 \end_inset
31341
31342
31343 \begin_inset LatexCommand \index{Linker documentation}
31344
31345 \end_inset
31346
31347  Relocating Linker
31348 \end_layout
31349
31350 \end_inset
31351 </cell>
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31353 \begin_inset Text
31354
31355 \begin_layout Standard
31356 sdcc/as/doc/asxhtm.html 
31357 \emph on
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361
31362 \hfill
31363 online at:
31364 \emph default
31365
31366 \newline
31367
31368 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31369
31370 \end_inset
31371
31372
31373 \end_layout
31374
31375 \end_inset
31376 </cell>
31377 </row>
31378 <row topline="true">
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31380 \begin_inset Text
31381
31382 \begin_layout Standard
31383 SDCC regression test
31384 \begin_inset LatexCommand \index{Regression test}
31385
31386 \end_inset
31387
31388
31389 \end_layout
31390
31391 \end_inset
31392 </cell>
31393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31394 \begin_inset Text
31395
31396 \begin_layout Standard
31397 sdcc/doc/test_suite_spec.pdf 
31398 \emph on
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402
31403 \hfill
31404 online at:
31405 \emph default
31406
31407 \newline
31408
31409 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31410
31411 \end_inset
31412
31413
31414 \end_layout
31415
31416 \end_inset
31417 </cell>
31418 </row>
31419 <row topline="true">
31420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31421 \begin_inset Text
31422
31423 \begin_layout Standard
31424 Various notes
31425 \end_layout
31426
31427 \end_inset
31428 </cell>
31429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31430 \begin_inset Text
31431
31432 \begin_layout Standard
31433 sdcc/doc/* 
31434 \emph on
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438
31439 \hfill
31440 online at:
31441 \emph default
31442
31443 \newline
31444
31445 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31446
31447 \end_inset
31448
31449
31450 \end_layout
31451
31452 \end_inset
31453 </cell>
31454 </row>
31455 <row topline="true">
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31457 \begin_inset Text
31458
31459 \begin_layout Standard
31460 Notes on debugging with SDCDB
31461 \begin_inset LatexCommand \index{SDCDB (debugger)}
31462
31463 \end_inset
31464
31465
31466 \end_layout
31467
31468 \end_inset
31469 </cell>
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31471 \begin_inset Text
31472
31473 \begin_layout Standard
31474 sdcc/debugger/README 
31475 \emph on
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479
31480 \hfill
31481 online at
31482 \emph default
31483 :
31484 \newline
31485
31486 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31487
31488 \end_inset
31489
31490
31491 \end_layout
31492
31493 \end_inset
31494 </cell>
31495 </row>
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \begin_layout Standard
31501 uCsim
31502 \begin_inset LatexCommand \index{uCsim}
31503
31504 \end_inset
31505
31506  Software simulator for microcontrollers
31507 \end_layout
31508
31509 \end_inset
31510 </cell>
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31512 \begin_inset Text
31513
31514 \begin_layout Standard
31515
31516 \family roman
31517 \series medium
31518 \shape up
31519 \size normal
31520 \emph off
31521 \bar no
31522 \noun off
31523 \color none
31524 sdcc/sim/ucsim/doc
31525 \family default
31526 \series default
31527 \shape default
31528 \size default
31529 \emph default
31530 \bar default
31531 \noun default
31532 /index.html 
31533 \emph on
31534 \InsetSpace ~
31535 \InsetSpace ~
31536 \InsetSpace ~
31537
31538 \hfill
31539 online at:
31540 \emph default
31541
31542 \newline
31543
31544 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31545
31546 \end_inset
31547
31548
31549 \end_layout
31550
31551 \end_inset
31552 </cell>
31553 </row>
31554 <row topline="true">
31555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31556 \begin_inset Text
31557
31558 \begin_layout Standard
31559 Temporary notes on the pic16
31560 \begin_inset LatexCommand \index{PIC16}
31561
31562 \end_inset
31563
31564  port
31565 \end_layout
31566
31567 \end_inset
31568 </cell>
31569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31570 \begin_inset Text
31571
31572 \begin_layout Standard
31573 sdcc/src/pic16/NOTES 
31574 \emph on
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578
31579 \hfill
31580 online at:
31581 \newline
31582
31583 \emph default
31584
31585 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31586
31587 \end_inset
31588
31589
31590 \end_layout
31591
31592 \end_inset
31593 </cell>
31594 </row>
31595 <row topline="true" bottomline="true">
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31597 \begin_inset Text
31598
31599 \begin_layout Standard
31600 SDCC internal documentation (debugging file format)
31601 \end_layout
31602
31603 \end_inset
31604 </cell>
31605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31606 \begin_inset Text
31607
31608 \begin_layout Standard
31609 sdcc/doc/
31610 \family roman
31611 \series medium
31612 \shape up
31613 \size normal
31614 \emph off
31615 \bar no
31616 \noun off
31617 \color none
31618 cdbfileformat.pd
31619 \family default
31620 \series default
31621 \shape default
31622 \size default
31623 \emph default
31624 \bar default
31625 \noun default
31626 f
31627 \emph on
31628  \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631
31632 \hfill
31633 online at:
31634 \emph default
31635
31636 \newline
31637
31638 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31639
31640 \end_inset
31641
31642
31643 \end_layout
31644
31645 \end_inset
31646 </cell>
31647 </row>
31648 </lyxtabular>
31649
31650 \end_inset
31651
31652
31653 \newline
31654
31655 \end_layout
31656
31657 \begin_layout Section
31658 Related open source tools
31659 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31660
31661 \end_inset
31662
31663
31664 \begin_inset LatexCommand \index{Related tools}
31665
31666 \end_inset
31667
31668
31669 \end_layout
31670
31671 \begin_layout Standard
31672 \align left
31673 \begin_inset Tabular
31674 <lyxtabular version="3" rows="16" columns="3">
31675 <features>
31676 <column alignment="left" valignment="top" leftline="true" width="0pt">
31677 <column alignment="block" valignment="top" leftline="true" width="30line%">
31678 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31679 <row topline="true" bottomline="true">
31680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31681 \begin_inset Text
31682
31683 \begin_layout Standard
31684
31685 \series bold
31686 Name
31687 \end_layout
31688
31689 \end_inset
31690 </cell>
31691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31692 \begin_inset Text
31693
31694 \begin_layout Standard
31695
31696 \series bold
31697 Purpose
31698 \end_layout
31699
31700 \end_inset
31701 </cell>
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31703 \begin_inset Text
31704
31705 \begin_layout Standard
31706
31707 \series bold
31708 Where to get
31709 \end_layout
31710
31711 \end_inset
31712 </cell>
31713 </row>
31714 <row topline="true">
31715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31716 \begin_inset Text
31717
31718 \begin_layout Standard
31719 gpsim
31720 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31721
31722 \end_inset
31723
31724
31725 \end_layout
31726
31727 \end_inset
31728 </cell>
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31730 \begin_inset Text
31731
31732 \begin_layout Standard
31733 PIC simulator
31734 \end_layout
31735
31736 \end_inset
31737 </cell>
31738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31739 \begin_inset Text
31740
31741 \begin_layout Standard
31742 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31743
31744 \end_inset
31745
31746
31747 \end_layout
31748
31749 \end_inset
31750 </cell>
31751 </row>
31752 <row topline="true">
31753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31754 \begin_inset Text
31755
31756 \begin_layout Standard
31757 gputils
31758 \begin_inset LatexCommand \index{gputils (pic tools)}
31759
31760 \end_inset
31761
31762
31763 \end_layout
31764
31765 \end_inset
31766 </cell>
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31768 \begin_inset Text
31769
31770 \begin_layout Standard
31771 GNU PIC utilities
31772 \end_layout
31773
31774 \end_inset
31775 </cell>
31776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31777 \begin_inset Text
31778
31779 \begin_layout Standard
31780 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31781
31782 \end_inset
31783
31784
31785 \end_layout
31786
31787 \end_inset
31788 </cell>
31789 </row>
31790 <row topline="true">
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31792 \begin_inset Text
31793
31794 \begin_layout Standard
31795 flP5
31796 \end_layout
31797
31798 \end_inset
31799 </cell>
31800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31801 \begin_inset Text
31802
31803 \begin_layout Standard
31804 PIC programmer
31805 \end_layout
31806
31807 \end_inset
31808 </cell>
31809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31810 \begin_inset Text
31811
31812 \begin_layout Standard
31813 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31814
31815 \end_inset
31816
31817
31818 \end_layout
31819
31820 \end_inset
31821 </cell>
31822 </row>
31823 <row topline="true">
31824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31825 \begin_inset Text
31826
31827 \begin_layout Standard
31828 ec2drv/newcdb
31829 \end_layout
31830
31831 \end_inset
31832 </cell>
31833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31834 \begin_inset Text
31835
31836 \begin_layout Standard
31837 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31838  (Unix only)
31839 \end_layout
31840
31841 \end_inset
31842 </cell>
31843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31844 \begin_inset Text
31845
31846 \begin_layout Standard
31847 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31848
31849 \end_inset
31850
31851
31852 \end_layout
31853
31854 \end_inset
31855 </cell>
31856 </row>
31857 <row topline="true">
31858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31859 \begin_inset Text
31860
31861 \begin_layout Standard
31862 indent
31863 \begin_inset LatexCommand \index{indent (source formatting tool)}
31864
31865 \end_inset
31866
31867
31868 \end_layout
31869
31870 \end_inset
31871 </cell>
31872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31873 \begin_inset Text
31874
31875 \begin_layout Standard
31876 Formats C source - Master of the white spaces
31877 \end_layout
31878
31879 \end_inset
31880 </cell>
31881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31882 \begin_inset Text
31883
31884 \begin_layout Standard
31885 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31886
31887 \end_inset
31888
31889
31890 \end_layout
31891
31892 \end_inset
31893 </cell>
31894 </row>
31895 <row topline="true">
31896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31897 \begin_inset Text
31898
31899 \begin_layout Standard
31900 srecord
31901 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31902
31903 \end_inset
31904
31905
31906 \end_layout
31907
31908 \end_inset
31909 </cell>
31910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31911 \begin_inset Text
31912
31913 \begin_layout Standard
31914 Object file conversion, checksumming, ...
31915 \end_layout
31916
31917 \end_inset
31918 </cell>
31919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31920 \begin_inset Text
31921
31922 \begin_layout Standard
31923 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31924
31925 \end_inset
31926
31927
31928 \end_layout
31929
31930 \end_inset
31931 </cell>
31932 </row>
31933 <row topline="true">
31934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31935 \begin_inset Text
31936
31937 \begin_layout Standard
31938 objdump
31939 \begin_inset LatexCommand \index{objdump (tool)}
31940
31941 \end_inset
31942
31943
31944 \end_layout
31945
31946 \end_inset
31947 </cell>
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31949 \begin_inset Text
31950
31951 \begin_layout Standard
31952 Object file conversion, ...
31953 \end_layout
31954
31955 \end_inset
31956 </cell>
31957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31958 \begin_inset Text
31959
31960 \begin_layout Standard
31961 Part of binutils (should be there anyway)
31962 \end_layout
31963
31964 \end_inset
31965 </cell>
31966 </row>
31967 <row topline="true">
31968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31969 \begin_inset Text
31970
31971 \begin_layout Standard
31972 cmon51
31973 \end_layout
31974
31975 \end_inset
31976 </cell>
31977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31978 \begin_inset Text
31979
31980 \begin_layout Standard
31981 8051 monitor (hex up-/download, single step, disassemble)
31982 \end_layout
31983
31984 \end_inset
31985 </cell>
31986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31987 \begin_inset Text
31988
31989 \begin_layout Standard
31990 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31991
31992 \end_inset
31993
31994
31995 \end_layout
31996
31997 \end_inset
31998 </cell>
31999 </row>
32000 <row topline="true">
32001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32002 \begin_inset Text
32003
32004 \begin_layout Standard
32005 doxygen
32006 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32007
32008 \end_inset
32009
32010
32011 \end_layout
32012
32013 \end_inset
32014 </cell>
32015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32016 \begin_inset Text
32017
32018 \begin_layout Standard
32019 Source code documentation system
32020 \end_layout
32021
32022 \end_inset
32023 </cell>
32024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32025 \begin_inset Text
32026
32027 \begin_layout Standard
32028 \begin_inset LatexCommand \url{http://www.doxygen.org}
32029
32030 \end_inset
32031
32032
32033 \end_layout
32034
32035 \end_inset
32036 </cell>
32037 </row>
32038 <row topline="true">
32039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32040 \begin_inset Text
32041
32042 \begin_layout Standard
32043 kdevelop
32044 \end_layout
32045
32046 \end_inset
32047 </cell>
32048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32049 \begin_inset Text
32050
32051 \begin_layout Standard
32052 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32053 \end_layout
32054
32055 \end_inset
32056 </cell>
32057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32058 \begin_inset Text
32059
32060 \begin_layout Standard
32061 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32062
32063 \end_inset
32064
32065
32066 \end_layout
32067
32068 \end_inset
32069 </cell>
32070 </row>
32071 <row topline="true">
32072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32073 \begin_inset Text
32074
32075 \begin_layout Standard
32076 paulmon
32077 \end_layout
32078
32079 \end_inset
32080 </cell>
32081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32082 \begin_inset Text
32083
32084 \begin_layout Standard
32085 8051 monitor (hex up-/download, single step, disassemble)
32086 \end_layout
32087
32088 \end_inset
32089 </cell>
32090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32091 \begin_inset Text
32092
32093 \begin_layout Standard
32094 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32095
32096 \end_inset
32097
32098
32099 \end_layout
32100
32101 \end_inset
32102 </cell>
32103 </row>
32104 <row topline="true">
32105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32106 \begin_inset Text
32107
32108 \begin_layout Standard
32109 splint
32110 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32111
32112 \end_inset
32113
32114
32115 \end_layout
32116
32117 \end_inset
32118 </cell>
32119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32120 \begin_inset Text
32121
32122 \begin_layout Standard
32123 Statically checks c sources (see 
32124 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32125
32126 \end_inset
32127
32128 )
32129 \end_layout
32130
32131 \end_inset
32132 </cell>
32133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32134 \begin_inset Text
32135
32136 \begin_layout Standard
32137 \begin_inset LatexCommand \url{http://www.splint.org}
32138
32139 \end_inset
32140
32141
32142 \end_layout
32143
32144 \end_inset
32145 </cell>
32146 </row>
32147 <row topline="true" bottomline="true">
32148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32149 \begin_inset Text
32150
32151 \begin_layout Standard
32152 ddd
32153 \begin_inset LatexCommand \index{DDD (debugger)}
32154
32155 \end_inset
32156
32157
32158 \end_layout
32159
32160 \end_inset
32161 </cell>
32162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32163 \begin_inset Text
32164
32165 \begin_layout Standard
32166 Debugger, serves nicely as GUI to SDCDB
32167 \begin_inset LatexCommand \index{SDCDB (debugger)}
32168
32169 \end_inset
32170
32171  (Unix only)
32172 \end_layout
32173
32174 \end_inset
32175 </cell>
32176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32177 \begin_inset Text
32178
32179 \begin_layout Standard
32180 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32181
32182 \end_inset
32183
32184
32185 \end_layout
32186
32187 \end_inset
32188 </cell>
32189 </row>
32190 <row bottomline="true">
32191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32192 \begin_inset Text
32193
32194 \begin_layout Standard
32195 d52
32196 \begin_inset LatexCommand \index{d52}
32197
32198 \end_inset
32199
32200
32201 \begin_inset LatexCommand \index{d52 (disassembler)}
32202
32203 \end_inset
32204
32205
32206 \end_layout
32207
32208 \end_inset
32209 </cell>
32210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32211 \begin_inset Text
32212
32213 \begin_layout Standard
32214 Disassembler, can count instruction cycles
32215 \begin_inset LatexCommand \index{instruction cycles (count)}
32216
32217 \end_inset
32218
32219 , use with options -pnd
32220 \end_layout
32221
32222 \end_inset
32223 </cell>
32224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32225 \begin_inset Text
32226
32227 \begin_layout Standard
32228 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32229
32230 \end_inset
32231
32232
32233 \end_layout
32234
32235 \end_inset
32236 </cell>
32237 </row>
32238 <row bottomline="true">
32239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32240 \begin_inset Text
32241
32242 \begin_layout Standard
32243 cmake
32244 \begin_inset LatexCommand \index{cmake}
32245
32246 \end_inset
32247
32248
32249 \end_layout
32250
32251 \end_inset
32252 </cell>
32253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32254 \begin_inset Text
32255
32256 \begin_layout Standard
32257 Cross platform build system, generates Makefiles
32258 \begin_inset LatexCommand \index{Makefile}
32259
32260 \end_inset
32261
32262  and project workspaces
32263 \begin_inset LatexCommand \index{project workspace}
32264
32265 \end_inset
32266
32267
32268 \end_layout
32269
32270 \end_inset
32271 </cell>
32272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32273 \begin_inset Text
32274
32275 \begin_layout Standard
32276 \begin_inset LatexCommand \url{http://www.cmake.org}
32277
32278 \end_inset
32279
32280  \InsetSpace ~
32281 \InsetSpace ~
32282 \InsetSpace ~
32283 \InsetSpace ~
32284 and a dedicated wiki entry: 
32285 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32286
32287 \end_inset
32288
32289
32290 \end_layout
32291
32292 \end_inset
32293 </cell>
32294 </row>
32295 </lyxtabular>
32296
32297 \end_inset
32298
32299
32300 \newline
32301
32302 \end_layout
32303
32304 \begin_layout Section
32305 Related documentation / recommended reading
32306 \end_layout
32307
32308 \begin_layout Standard
32309 \align left
32310 \begin_inset Tabular
32311 <lyxtabular version="3" rows="7" columns="3">
32312 <features>
32313 <column alignment="left" valignment="top" leftline="true" width="0pt">
32314 <column alignment="left" valignment="top" leftline="true" width="0">
32315 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32316 <row topline="true" bottomline="true">
32317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32318 \begin_inset Text
32319
32320 \begin_layout Standard
32321
32322 \series bold
32323 Name
32324 \end_layout
32325
32326 \end_inset
32327 </cell>
32328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32329 \begin_inset Text
32330
32331 \begin_layout Standard
32332
32333 \series bold
32334 Subject / Title
32335 \end_layout
32336
32337 \end_inset
32338 </cell>
32339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32340 \begin_inset Text
32341
32342 \begin_layout Standard
32343
32344 \series bold
32345 Where to get
32346 \end_layout
32347
32348 \end_inset
32349 </cell>
32350 </row>
32351 <row topline="true">
32352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32353 \begin_inset Text
32354
32355 \begin_layout Standard
32356
32357 \family roman
32358 \series medium
32359 \shape up
32360 \size normal
32361 \emph off
32362 \bar no
32363 \noun off
32364 \color none
32365 c-refcard.pdf
32366 \end_layout
32367
32368 \end_inset
32369 </cell>
32370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32371 \begin_inset Text
32372
32373 \begin_layout Standard
32374 C Reference Card
32375 \begin_inset LatexCommand \index{C Reference card}
32376
32377 \end_inset
32378
32379 , 2 pages
32380 \end_layout
32381
32382 \end_inset
32383 </cell>
32384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32385 \begin_inset Text
32386
32387 \begin_layout Standard
32388 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32389
32390 \end_inset
32391
32392
32393 \end_layout
32394
32395 \end_inset
32396 </cell>
32397 </row>
32398 <row topline="true">
32399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32400 \begin_inset Text
32401
32402 \begin_layout Standard
32403 c-faq
32404 \end_layout
32405
32406 \end_inset
32407 </cell>
32408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32409 \begin_inset Text
32410
32411 \begin_layout Standard
32412 C-FAQ
32413 \begin_inset LatexCommand \index{C FAQ}
32414
32415 \end_inset
32416
32417
32418 \end_layout
32419
32420 \end_inset
32421 </cell>
32422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32423 \begin_inset Text
32424
32425 \begin_layout Standard
32426 \begin_inset LatexCommand \url{http://www.c-faq.com}
32427
32428 \end_inset
32429
32430
32431 \end_layout
32432
32433 \end_inset
32434 </cell>
32435 </row>
32436 <row topline="true">
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32438 \begin_inset Text
32439
32440 \begin_layout Standard
32441 ISO/IEC 9899:TC2
32442 \end_layout
32443
32444 \end_inset
32445 </cell>
32446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32447 \begin_inset Text
32448
32449 \begin_layout Standard
32450 \begin_inset Quotes sld
32451 \end_inset
32452
32453 C-Standard
32454 \begin_inset Quotes srd
32455 \end_inset
32456
32457
32458 \end_layout
32459
32460 \end_inset
32461 </cell>
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32463 \begin_inset Text
32464
32465 \begin_layout Standard
32466
32467 \size footnotesize
32468 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32469
32470 \end_inset
32471
32472
32473 \end_layout
32474
32475 \end_inset
32476 </cell>
32477 </row>
32478 <row topline="true">
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 \begin_inset Text
32481
32482 \begin_layout Standard
32483 ISO/IEC DTR 18037
32484 \end_layout
32485
32486 \end_inset
32487 </cell>
32488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32489 \begin_inset Text
32490
32491 \begin_layout Standard
32492 \begin_inset Quotes sld
32493 \end_inset
32494
32495 Extensions for Embedded C
32496 \begin_inset Quotes srd
32497 \end_inset
32498
32499
32500 \end_layout
32501
32502 \end_inset
32503 </cell>
32504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32505 \begin_inset Text
32506
32507 \begin_layout Standard
32508
32509 \size footnotesize
32510 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32511
32512 \end_inset
32513
32514
32515 \end_layout
32516
32517 \end_inset
32518 </cell>
32519 </row>
32520 <row topline="true">
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 \begin_inset Text
32523
32524 \begin_layout Standard
32525
32526 \end_layout
32527
32528 \end_inset
32529 </cell>
32530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32531 \begin_inset Text
32532
32533 \begin_layout Standard
32534 Latest datasheet of target CPU
32535 \end_layout
32536
32537 \end_inset
32538 </cell>
32539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32540 \begin_inset Text
32541
32542 \begin_layout Standard
32543 vendor
32544 \end_layout
32545
32546 \end_inset
32547 </cell>
32548 </row>
32549 <row topline="true" bottomline="true">
32550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32551 \begin_inset Text
32552
32553 \begin_layout Standard
32554
32555 \end_layout
32556
32557 \end_inset
32558 </cell>
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32560 \begin_inset Text
32561
32562 \begin_layout Standard
32563 Revision history of datasheet
32564 \end_layout
32565
32566 \end_inset
32567 </cell>
32568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32569 \begin_inset Text
32570
32571 \begin_layout Standard
32572 vendor
32573 \end_layout
32574
32575 \end_inset
32576 </cell>
32577 </row>
32578 </lyxtabular>
32579
32580 \end_inset
32581
32582
32583 \newline
32584
32585 \end_layout
32586
32587 \begin_layout Section
32588 Application notes specifically for SDCC
32589 \end_layout
32590
32591 \begin_layout Standard
32592 SDCC makes no claims about the completeness of this list and about up-to-datenes
32593 s or correctness of the application notes
32594 \begin_inset LatexCommand \index{Application notes}
32595
32596 \end_inset
32597
32598 .
32599 \end_layout
32600
32601 \begin_layout Standard
32602 \align left
32603
32604 \size footnotesize
32605 \begin_inset Tabular
32606 <lyxtabular version="3" rows="7" columns="3">
32607 <features>
32608 <column alignment="block" valignment="top" leftline="true" width="17col%">
32609 <column alignment="block" valignment="top" leftline="true" width="27col%">
32610 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32611 <row topline="true" bottomline="true">
32612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32613 \begin_inset Text
32614
32615 \begin_layout Standard
32616
32617 \series bold
32618 \size footnotesize
32619 Vendor
32620 \end_layout
32621
32622 \end_inset
32623 </cell>
32624 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32625 \begin_inset Text
32626
32627 \begin_layout Standard
32628
32629 \series bold
32630 \size footnotesize
32631 Subject / Title
32632 \end_layout
32633
32634 \end_inset
32635 </cell>
32636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32637 \begin_inset Text
32638
32639 \begin_layout Standard
32640
32641 \series bold
32642 \size footnotesize
32643 Where to get
32644 \end_layout
32645
32646 \end_inset
32647 </cell>
32648 </row>
32649 <row topline="true">
32650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32651 \begin_inset Text
32652
32653 \begin_layout Standard
32654
32655 \size footnotesize
32656 Maxim / Dallas
32657 \end_layout
32658
32659 \end_inset
32660 </cell>
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32662 \begin_inset Text
32663
32664 \begin_layout Standard
32665
32666 \size footnotesize
32667 Using the SDCC Compiler for the DS80C400
32668 \begin_inset LatexCommand \index{DS80C400}
32669
32670 \end_inset
32671
32672
32673 \end_layout
32674
32675 \end_inset
32676 </cell>
32677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32678 \begin_inset Text
32679
32680 \begin_layout Standard
32681
32682 \size footnotesize
32683 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32684
32685 \end_inset
32686
32687
32688 \end_layout
32689
32690 \end_inset
32691 </cell>
32692 </row>
32693 <row topline="true">
32694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32695 \begin_inset Text
32696
32697 \begin_layout Standard
32698
32699 \size footnotesize
32700 Maxim / Dallas
32701 \end_layout
32702
32703 \end_inset
32704 </cell>
32705 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32706 \begin_inset Text
32707
32708 \begin_layout Standard
32709
32710 \size footnotesize
32711 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32712 \begin_inset LatexCommand \index{DS89C4x0}
32713
32714 \end_inset
32715
32716  Family of Microcontrollers
32717 \end_layout
32718
32719 \end_inset
32720 </cell>
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32722 \begin_inset Text
32723
32724 \begin_layout Standard
32725
32726 \size footnotesize
32727 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32728
32729 \end_inset
32730
32731
32732 \end_layout
32733
32734 \end_inset
32735 </cell>
32736 </row>
32737 <row topline="true">
32738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32739 \begin_inset Text
32740
32741 \begin_layout Standard
32742
32743 \size footnotesize
32744 Silicon Laboratories / Cygnal
32745 \end_layout
32746
32747 \end_inset
32748 </cell>
32749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32750 \begin_inset Text
32751
32752 \begin_layout Standard
32753
32754 \size footnotesize
32755 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32756 \begin_inset LatexCommand \index{IDE}
32757
32758 \end_inset
32759
32760
32761 \end_layout
32762
32763 \end_inset
32764 </cell>
32765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32766 \begin_inset Text
32767
32768 \begin_layout Standard
32769
32770 \size footnotesize
32771 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32772
32773 \end_inset
32774
32775
32776 \end_layout
32777
32778 \end_inset
32779 </cell>
32780 </row>
32781 <row topline="true">
32782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32783 \begin_inset Text
32784
32785 \begin_layout Standard
32786
32787 \size footnotesize
32788 Ramtron / Goal Semiconductor
32789 \end_layout
32790
32791 \end_inset
32792 </cell>
32793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32794 \begin_inset Text
32795
32796 \begin_layout Standard
32797
32798 \size footnotesize
32799 Interfacing SDCC to Syn and Textpad
32800 \end_layout
32801
32802 \end_inset
32803 </cell>
32804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32805 \begin_inset Text
32806
32807 \begin_layout Standard
32808
32809 \size footnotesize
32810 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32811
32812 \end_inset
32813
32814
32815 \end_layout
32816
32817 \end_inset
32818 </cell>
32819 </row>
32820 <row topline="true">
32821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32822 \begin_inset Text
32823
32824 \begin_layout Standard
32825
32826 \size footnotesize
32827 Ramtron / Goal Semiconductor
32828 \end_layout
32829
32830 \end_inset
32831 </cell>
32832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32833 \begin_inset Text
32834
32835 \begin_layout Standard
32836
32837 \size footnotesize
32838 Installing and Configuring SDCC and Crimson Editor 
32839 \end_layout
32840
32841 \end_inset
32842 </cell>
32843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32844 \begin_inset Text
32845
32846 \begin_layout Standard
32847
32848 \size footnotesize
32849 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32850
32851 \end_inset
32852
32853
32854 \end_layout
32855
32856 \end_inset
32857 </cell>
32858 </row>
32859 <row topline="true" bottomline="true">
32860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32861 \begin_inset Text
32862
32863 \begin_layout Standard
32864
32865 \size footnotesize
32866 Texas Instruments
32867 \end_layout
32868
32869 \end_inset
32870 </cell>
32871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32872 \begin_inset Text
32873
32874 \begin_layout Standard
32875
32876 \size footnotesize
32877 MSC12xx Programming with SDCC
32878 \end_layout
32879
32880 \end_inset
32881 </cell>
32882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32883 \begin_inset Text
32884
32885 \begin_layout Standard
32886
32887 \size footnotesize
32888 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32889
32890 \end_inset
32891
32892
32893 \end_layout
32894
32895 \end_inset
32896 </cell>
32897 </row>
32898 </lyxtabular>
32899
32900 \end_inset
32901
32902
32903 \end_layout
32904
32905 \begin_layout Section
32906 Some Questions
32907 \end_layout
32908
32909 \begin_layout Standard
32910 Some questions answered, some pointers given - it might be time to in turn
32911  ask 
32912 \emph on
32913 you
32914 \emph default
32915  some questions: 
32916 \end_layout
32917
32918 \begin_layout Itemize
32919 can you solve your project with the selected microcontroller? Would you
32920  find out early or rather late that your target is too small/slow/whatever?
32921  Can you switch to a slightly better device if it doesn't fit?
32922 \end_layout
32923
32924 \begin_layout Itemize
32925 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32926  and/or another programming language be more adequate? Would an operating
32927  system on the target device help?
32928 \end_layout
32929
32930 \begin_layout Itemize
32931 if you solved the problem, will the marketing department be happy?
32932 \end_layout
32933
32934 \begin_layout Itemize
32935 if the marketing department is happy, will customers be happy?
32936 \end_layout
32937
32938 \begin_layout Itemize
32939 if you're the project manager, marketing department and maybe even the customer
32940  in one person, have you tried to see the project from the outside?
32941 \end_layout
32942
32943 \begin_layout Itemize
32944 is the project done if you think it is done? Or is just that other interface/pro
32945 tocol/feature/configuration/option missing? How about website, manual(s),
32946  internationali(z|s)ation, packaging, labels, 2nd source for components,
32947  electromagnetic compatability/interference, documentation for production,
32948  production test software, update mechanism, patent issues?
32949 \end_layout
32950
32951 \begin_layout Itemize
32952 is your project adequately positioned in that magic triangle: fame, fortune,
32953  fun?
32954 \end_layout
32955
32956 \begin_layout Standard
32957 Maybe not all answers to these questions are known and some answers may
32958  even be 
32959 \emph on
32960 no
32961 \emph default
32962 , nevertheless knowing these questions may help you to avoid burnout
32963 \begin_inset Foot
32964 status open
32965
32966 \begin_layout Standard
32967 burnout is bad for electronic devices, programmers and motorcycle tyres
32968 \end_layout
32969
32970 \end_inset
32971
32972 .
32973  Chances are you didn't want to hear some of them...
32974 \end_layout
32975
32976 \begin_layout Chapter
32977 Support
32978 \begin_inset LatexCommand \index{Support}
32979
32980 \end_inset
32981
32982
32983 \end_layout
32984
32985 \begin_layout Standard
32986 SDCC has grown to be a large project.
32987  The compiler alone (without the preprocessor, assembler and linker) is
32988  well over 150,000 lines of code (blank stripped).
32989  The open source nature of this project is a key to its continued growth
32990  and support.
32991  You gain the benefit and support of many active software developers and
32992  end users.
32993  Is SDCC perfect? No, that's why we need your help.
32994  The developers take pride in fixing reported bugs.
32995  You can help by reporting the bugs and helping other SDCC users.
32996  There are lots of ways to contribute, and we encourage you to take part
32997  in making SDCC a great software package.
32998  
32999 \end_layout
33000
33001 \begin_layout Standard
33002 The SDCC project is hosted on the SDCC sourceforge site at 
33003 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33004
33005 \end_inset
33006
33007 .
33008  You'll find the complete set of mailing lists
33009 \begin_inset LatexCommand \index{Mailing list(s)}
33010
33011 \end_inset
33012
33013 , forums, bug reporting system, patch submission
33014 \begin_inset LatexCommand \index{Patch submission}
33015
33016 \end_inset
33017
33018  system, download
33019 \begin_inset LatexCommand \index{download}
33020
33021 \end_inset
33022
33023  area and Subversion code repository
33024 \begin_inset LatexCommand \index{Subversion code repository}
33025
33026 \end_inset
33027
33028  there.
33029 \end_layout
33030
33031 \begin_layout Section
33032 Reporting Bugs
33033 \begin_inset LatexCommand \index{Bug reporting}
33034
33035 \end_inset
33036
33037
33038 \begin_inset LatexCommand \index{Reporting bugs}
33039
33040 \end_inset
33041
33042
33043 \end_layout
33044
33045 \begin_layout Standard
33046 The recommended way of reporting bugs is using the infrastructure of the
33047  sourceforge site.
33048  You can follow the status of bug reports there and have an overview about
33049  the known bugs.
33050 \end_layout
33051
33052 \begin_layout Standard
33053 Bug reports are automatically forwarded to the developer mailing list and
33054  will be fixed ASAP.
33055  When reporting a bug, it is very useful to include a small test program
33056  (the smaller the better) which reproduces the problem.
33057  If you can isolate the problem by looking at the generated assembly code,
33058  this can be very helpful.
33059  Compiling your program with the -
33060 \begin_inset ERT
33061 status collapsed
33062
33063 \begin_layout Standard
33064
33065
33066 \backslash
33067 /
33068 \end_layout
33069
33070 \end_inset
33071
33072 -dumpall
33073 \begin_inset LatexCommand \index{-\/-dumpall}
33074
33075 \end_inset
33076
33077  option can sometimes be useful in locating optimization problems.
33078  When reporting a bug please make sure you:
33079 \end_layout
33080
33081 \begin_layout Enumerate
33082 Attach the code you are compiling with SDCC.
33083  
33084 \end_layout
33085
33086 \begin_layout Enumerate
33087 Specify the exact command you use to run SDCC, or attach your Makefile.
33088  
33089 \end_layout
33090
33091 \begin_layout Enumerate
33092 Specify the SDCC version (type "
33093 \family sans
33094 \series bold
33095 sdcc -v
33096 \family default
33097 \series default
33098 "), your platform, and operating system.
33099  
33100 \end_layout
33101
33102 \begin_layout Enumerate
33103 Provide an exact copy of any error message or incorrect output.
33104  
33105 \end_layout
33106
33107 \begin_layout Enumerate
33108 Put something meaningful in the subject of your message.
33109 \end_layout
33110
33111 \begin_layout Standard
33112 Please attempt to include these 5 important parts, as applicable, in all
33113  requests for support or when reporting any problems or bugs with SDCC.
33114  Though this will make your message lengthy, it will greatly improve your
33115  chance that SDCC users and developers will be able to help you.
33116  Some SDCC developers are frustrated by bug reports without code provided
33117  that they can use to reproduce and ultimately fix the problem, so please
33118  be sure to provide sample code if you are reporting a bug! 
33119 \end_layout
33120
33121 \begin_layout Standard
33122 Please have a short check that you are using a recent version of SDCC and
33123  the bug is not yet known.
33124  This is the link for reporting bugs: 
33125 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33126
33127 \end_inset
33128
33129 .
33130  With SDCC on average having more than 200 downloads
33131 \begin_inset LatexCommand \index{download}
33132
33133 \end_inset
33134
33135  on sourceforge per day
33136 \begin_inset Foot
33137 status open
33138
33139 \begin_layout Standard
33140 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33141  between 2002 and 2005.
33142  This does not include other methods of distribution.
33143 \end_layout
33144
33145 \end_inset
33146
33147  there must be some users.
33148  So it's not exactly easy to find a new bug.
33149  If you find one we need it: 
33150 \emph on
33151 reporting bugs is good
33152 \emph default
33153 .
33154 \end_layout
33155
33156 \begin_layout Section
33157 Requesting Features
33158 \begin_inset LatexCommand \label{sub:Requesting-Features}
33159
33160 \end_inset
33161
33162
33163 \begin_inset LatexCommand \index{Feature request}
33164
33165 \end_inset
33166
33167
33168 \begin_inset LatexCommand \index{Requesting features}
33169
33170 \end_inset
33171
33172
33173 \end_layout
33174
33175 \begin_layout Standard
33176 Like bug reports feature requests are forwarded to the developer mailing
33177  list.
33178  This is the link for requesting features: 
33179 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33180
33181 \end_inset
33182
33183 .
33184 \end_layout
33185
33186 \begin_layout Section
33187 Submitting patches
33188 \end_layout
33189
33190 \begin_layout Standard
33191 Like bug reports contributed patches are forwarded to the developer mailing
33192  list.
33193  This is the link for submitting patches
33194 \begin_inset LatexCommand \index{Patch submission}
33195
33196 \end_inset
33197
33198
33199 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33200
33201 \end_inset
33202
33203 .
33204 \end_layout
33205
33206 \begin_layout Standard
33207 You need to specify some parameters to the 
33208 \family typewriter
33209 diff
33210 \family default
33211  command for the patches to be useful.
33212  If you modified more than one file a patch created f.e.
33213  with 
33214 \family sans
33215 \series bold
33216
33217 \begin_inset Quotes sld
33218 \end_inset
33219
33220 diff -Naur unmodified_directory modified_directory >my_changes.patch
33221 \begin_inset Quotes srd
33222 \end_inset
33223
33224
33225 \family default
33226 \series default
33227  will be fine, otherwise 
33228 \family sans
33229 \series bold
33230
33231 \begin_inset Quotes sld
33232 \end_inset
33233
33234 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33235 \begin_inset Quotes srd
33236 \end_inset
33237
33238
33239 \series default
33240  
33241 \family default
33242 will do.
33243 \end_layout
33244
33245 \begin_layout Section
33246 Getting Help
33247 \end_layout
33248
33249 \begin_layout Standard
33250 These links should take you directly to the 
33251 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33252
33253 \end_inset
33254
33255
33256 \begin_inset Foot
33257 status open
33258
33259 \begin_layout Standard
33260 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33261  automated messages (mid 2003)
33262 \end_layout
33263
33264 \end_inset
33265
33266  and the 
33267 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33268
33269 \end_inset
33270
33271 , lists
33272 \begin_inset LatexCommand \index{Mailing list(s)}
33273
33274 \end_inset
33275
33276  and forums are archived and searchable so if you are lucky someone already
33277  had a similar problem.
33278  While mails to the lists themselves are delivered promptly their web front
33279  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33280  if you're seriously using SDCC please consider subscribing to the lists.
33281 \end_layout
33282
33283 \begin_layout Section
33284 ChangeLog
33285 \end_layout
33286
33287 \begin_layout Standard
33288 You can follow the status of the Subversion version
33289 \begin_inset LatexCommand \index{version}
33290
33291 \end_inset
33292
33293  of SDCC by watching the Changelog
33294 \begin_inset LatexCommand \index{Changelog}
33295
33296 \end_inset
33297
33298  in the Subversion repository
33299 \size footnotesize
33300  
33301 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33302
33303 \end_inset
33304
33305 .
33306 \end_layout
33307
33308 \begin_layout Section
33309 Subversion Source Code Repository
33310 \end_layout
33311
33312 \begin_layout Standard
33313 The output of 
33314 \family sans
33315 \series bold
33316 sdcc -
33317 \family default
33318
33319 \begin_inset ERT
33320 status open
33321
33322 \begin_layout Standard
33323
33324
33325 \backslash
33326 /
33327 \end_layout
33328
33329 \end_inset
33330
33331
33332 \family sans
33333 -version
33334 \family default
33335 \series default
33336  or the filenames of the snapshot versions of SDCC include date and its
33337  Subversion
33338 \begin_inset LatexCommand \index{Subversion code repository}
33339
33340 \end_inset
33341
33342  number.
33343  Subversion allows to download the source of recent or previous versions
33344  
33345 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33346
33347 \end_inset
33348
33349  (by number or by date).
33350  An on-line source code browser and detailled instructions are also available
33351  there.
33352  SDCC versions starting from 1999 up to now are available (currently the
33353  versions prior to the conversion from cvs
33354 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33355
33356 \end_inset
33357
33358  to Subversion (April 2006) are either by accessible by Subversion or by
33359  cvs).
33360 \end_layout
33361
33362 \begin_layout Section
33363 Release policy
33364 \begin_inset LatexCommand \index{Release policy}
33365
33366 \end_inset
33367
33368
33369 \end_layout
33370
33371 \begin_layout Standard
33372 Historically there often were long delays between official releases and
33373  the sourceforge download area tends to get not updated at all.
33374  Excuses in the past might have referred to problems with live range analysis,
33375  but as this was fixed a while ago, the current problem is that another
33376  excuse has to be found.
33377  Kidding aside, we have to get better there! On the other hand there are
33378  daily snapshots available at 
33379 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33380
33381 \end_inset
33382
33383 , and you can always build the very last version (hopefully with many bugs
33384  fixed, and features added) from the source code available at 
33385 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33386
33387 \end_inset
33388
33389 .
33390  The SDCC Wiki
33391 \begin_inset LatexCommand \index{wiki}
33392
33393 \end_inset
33394
33395
33396 \begin_inset LatexCommand \index{SDCC Wiki}
33397
33398 \end_inset
33399
33400  at 
33401 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33402
33403 \end_inset
33404
33405  also holds some information about past and future releases.
33406 \end_layout
33407
33408 \begin_layout Section
33409 Examples
33410 \begin_inset LatexCommand \index{Examples}
33411
33412 \end_inset
33413
33414
33415 \end_layout
33416
33417 \begin_layout Standard
33418 You'll find some small examples in the directory 
33419 \emph on
33420 sdcc/device/examples/.
33421  
33422 \emph default
33423 More examples and libraries are available at
33424 \emph on
33425  The SDCC Open Knowledge Resource 
33426 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33427
33428 \end_inset
33429
33430  
33431 \emph default
33432 web site or at 
33433 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33434
33435 \end_inset
33436
33437 .
33438 \end_layout
33439
33440 \begin_layout Standard
33441 \begin_inset Note Note
33442 status collapsed
33443
33444 \begin_layout Standard
33445 I did insert a reference to Paul's web site here although it seems rather
33446  dedicated to a specific 8032 board (I think it's okay because it f.e.
33447  shows LCD/Harddisc interface and has a free 8051 monitor.
33448  Independent 8032 board vendors face hard competition of heavily subsidized
33449  development boards anyway).
33450 \end_layout
33451
33452 \begin_layout Standard
33453 Maybe we should include some links to real world applications.
33454  Preferably pointer to pointers (one for each architecture) so this stays
33455  manageable here?
33456 \end_layout
33457
33458 \end_inset
33459
33460
33461 \end_layout
33462
33463 \begin_layout Section
33464 Quality control
33465 \begin_inset LatexCommand \label{sec:Quality-control}
33466
33467 \end_inset
33468
33469
33470 \begin_inset LatexCommand \index{Quality control}
33471
33472 \end_inset
33473
33474
33475 \end_layout
33476
33477 \begin_layout Standard
33478 The compiler is passed through snaphot build compile and build checks.
33479  The so called 
33480 \shape italic
33481 regression tests
33482 \shape default
33483
33484 \begin_inset LatexCommand \index{Regression test}
33485
33486 \end_inset
33487
33488  check that SDCC itself compiles flawlessly on several host platforms (i386,
33489  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33490  and checks the quality of the code generated by SDCC by running the code
33491  for several target platforms through simulators.
33492  The regression test suite comprises more than 100 files which expand to
33493  more than 500 test cases which include more than 4500 tests.
33494  The results of these tests are published daily on SDCC's snapshot page
33495  (click on the red or green symbols on the right side of 
33496 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33497
33498 \end_inset
33499
33500 ).
33501 \end_layout
33502
33503 \begin_layout Standard
33504 There is a separate document 
33505 \shape italic
33506 test_suite.pdf 
33507 \begin_inset LatexCommand \index{Test suite}
33508
33509 \end_inset
33510
33511
33512 \shape default
33513  
33514 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33515
33516 \end_inset
33517
33518  about the regression test suite.
33519 \end_layout
33520
33521 \begin_layout Standard
33522 You'll find the test code in the directory 
33523 \shape italic
33524 sdcc/support/regression
33525 \shape default
33526 .
33527  You can run these tests manually by running 
33528 \family sans
33529 make
33530 \family default
33531  in this directory (or f.e.
33532  
33533 \family sans
33534 \series bold
33535
33536 \begin_inset Quotes sld
33537 \end_inset
33538
33539 make test-mcs51
33540 \begin_inset Quotes srd
33541 \end_inset
33542
33543
33544 \family default
33545 \series default
33546  if you don't want to run the complete tests).
33547  The test code might also be interesting if you want to look for examples
33548 \begin_inset LatexCommand \index{Examples}
33549
33550 \end_inset
33551
33552  checking corner cases of SDCC or if you plan to submit patches
33553 \begin_inset LatexCommand \index{Patch submission}
33554
33555 \end_inset
33556
33557 .
33558 \end_layout
33559
33560 \begin_layout Standard
33561 The PIC14 port uses a different set of regression tests 
33562 \begin_inset LatexCommand \index{Regression test (PIC14)}
33563
33564 \end_inset
33565
33566 , you'll find them in the directory 
33567 \shape italic
33568 sdcc/src/regression
33569 \shape default
33570 .
33571 \end_layout
33572
33573 \begin_layout Section
33574 Use of SDCC in Education
33575 \end_layout
33576
33577 \begin_layout Standard
33578 In short: 
33579 \emph on
33580 highly
33581 \emph default
33582  encouraged
33583 \begin_inset Foot
33584 status open
33585
33586 \begin_layout Standard
33587 the phrase "use in education" might evoke the association "
33588 \emph on
33589 only
33590 \emph default
33591  fit for use in education".
33592  This connotation is not intended but nevertheless risked as the licensing
33593  of SDCC makes it difficult to offer educational discounts
33594 \end_layout
33595
33596 \end_inset
33597
33598 .
33599  If your rationales are to:
33600 \end_layout
33601
33602 \begin_layout Enumerate
33603 give students a chance to understand the 
33604 \emph on
33605 complete
33606 \emph default
33607  steps of code generation
33608 \end_layout
33609
33610 \begin_layout Enumerate
33611 have a curriculum that can be extended for years.
33612  Then you could use an fpga board as target and your curriculum will seamlessly
33613  extend from logic synthesis (
33614 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33615
33616 \end_inset
33617
33618
33619 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33620
33621 \end_inset
33622
33623 ), over assembly programming, to C to FPGA compilers (
33624 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33625
33626 \end_inset
33627
33628 ) and to C.
33629 \end_layout
33630
33631 \begin_layout Enumerate
33632 be able to insert excursions about skills like using a revision control
33633  system, submitting/applying patches, using a type-setting (as opposed to
33634  word-processing) engine LyX/LaTeX, using 
33635 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33636
33637 \end_inset
33638
33639 , following some 
33640 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33641
33642 \end_inset
33643
33644 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33645  Source Software, CPU simulation, compiler regression tests
33646 \begin_inset LatexCommand \index{Regression test}
33647
33648 \end_inset
33649
33650 .
33651  
33652 \newline
33653 And if there should be a shortage of ideas then you can always point students
33654  to the ever-growing feature request list 
33655 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33656
33657 \end_inset
33658
33659 .
33660 \end_layout
33661
33662 \begin_layout Enumerate
33663 not tie students to a specific host platform and instead allow them to use
33664  a host platform of 
33665 \emph on
33666 their
33667 \emph default
33668  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33669  and eventually 
33670 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33671
33672 \end_inset
33673
33674 )
33675 \end_layout
33676
33677 \begin_layout Enumerate
33678 not encourage students to use illegal copies of educational software
33679 \end_layout
33680
33681 \begin_layout Enumerate
33682 be immune to licensing/availability/price changes of the chosen tool chain
33683 \end_layout
33684
33685 \begin_layout Enumerate
33686 be able to change to a new target platform without having to adopt a new
33687  tool chain
33688 \end_layout
33689
33690 \begin_layout Enumerate
33691 have complete control over and insight into the tool chain
33692 \end_layout
33693
33694 \begin_layout Enumerate
33695 make your students aware about the pros and cons of open source software
33696  development
33697 \end_layout
33698
33699 \begin_layout Enumerate
33700 give back to the public as you are probably at least partially publically
33701  funded
33702 \end_layout
33703
33704 \begin_layout Enumerate
33705 give students a chance to publically prove their skills and to possibly
33706  see a world wide impact
33707 \end_layout
33708
33709 \begin_layout Standard
33710 then SDCC is probably among the first choices.
33711  Well, probably SDCC might be the only choice.
33712 \newpage
33713
33714 \end_layout
33715
33716 \begin_layout Chapter
33717 SDCC Technical Data
33718 \end_layout
33719
33720 \begin_layout Section
33721 Optimizations
33722 \begin_inset LatexCommand \index{Optimizations}
33723
33724 \end_inset
33725
33726
33727 \end_layout
33728
33729 \begin_layout Standard
33730 SDCC performs a host of standard optimizations in addition to some MCU specific
33731  optimizations.
33732  
33733 \end_layout
33734
33735 \begin_layout Subsection
33736 Sub-expression Elimination
33737 \begin_inset LatexCommand \index{Subexpression elimination}
33738
33739 \end_inset
33740
33741
33742 \end_layout
33743
33744 \begin_layout Standard
33745 The compiler does local and 
33746 \emph on
33747 g
33748 \emph default
33749 lobal 
33750 \emph on
33751 c
33752 \emph default
33753 ommon 
33754 \emph on
33755 s
33756 \emph default
33757 ubexpression 
33758 \emph on
33759 e
33760 \emph default
33761 limination, e.g.: 
33762 \end_layout
33763
33764 \begin_layout Verse
33765
33766 \family typewriter
33767 i = x + y + 1; 
33768 \newline
33769 j = x + y;
33770 \end_layout
33771
33772 \begin_layout Standard
33773 will be translated to
33774 \end_layout
33775
33776 \begin_layout Verse
33777
33778 \family typewriter
33779 iTemp = x + y; 
33780 \newline
33781 i = iTemp + 1; 
33782 \newline
33783 j = iTemp;
33784 \end_layout
33785
33786 \begin_layout Standard
33787 Some subexpressions are not as obvious as the above example, e.g.:
33788 \end_layout
33789
33790 \begin_layout Verse
33791
33792 \family typewriter
33793 a->b[i].c = 10; 
33794 \newline
33795 a->b[i].d = 11;
33796 \end_layout
33797
33798 \begin_layout Standard
33799 In this case the address arithmetic a->b[i] will be computed only once;
33800  the equivalent code in C would be.
33801 \end_layout
33802
33803 \begin_layout Verse
33804
33805 \family typewriter
33806 iTemp = a->b[i]; 
33807 \newline
33808 iTemp.c = 10; 
33809 \newline
33810 iTemp.d = 11;
33811 \end_layout
33812
33813 \begin_layout Standard
33814 The compiler will try to keep these temporary variables in registers.
33815 \end_layout
33816
33817 \begin_layout Subsection
33818 Dead-Code Elimination
33819 \begin_inset LatexCommand \index{Dead-code elimination}
33820
33821 \end_inset
33822
33823
33824 \end_layout
33825
33826 \begin_layout Verse
33827
33828 \family typewriter
33829 int global;
33830 \newline
33831
33832 \newline
33833 void f () { 
33834 \newline
33835 \InsetSpace ~
33836 \InsetSpace ~
33837 int i; 
33838 \newline
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 i = 1; \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 /* dead store */ 
33847 \newline
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 global = 1;\InsetSpace ~
33851 /* dead
33852  store */ 
33853 \newline
33854 \InsetSpace ~
33855 \InsetSpace ~
33856 global = 2; 
33857 \newline
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 return; 
33861 \newline
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 global = 3;\InsetSpace ~
33865 /* unreachable */ 
33866 \newline
33867 }
33868 \end_layout
33869
33870 \begin_layout Standard
33871 will be changed to
33872 \end_layout
33873
33874 \begin_layout Verse
33875
33876 \family typewriter
33877 int global;
33878 \newline
33879
33880 \newline
33881 void f () {
33882 \newline
33883 \InsetSpace ~
33884 \InsetSpace ~
33885 global = 2; 
33886 \newline
33887 }
33888 \end_layout
33889
33890 \begin_layout Subsection
33891 Copy-Propagation
33892 \begin_inset LatexCommand \index{Copy propagation}
33893
33894 \end_inset
33895
33896
33897 \end_layout
33898
33899 \begin_layout Verse
33900
33901 \family typewriter
33902 int f() { 
33903 \newline
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 int i, j; 
33907 \newline
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 i = 10; 
33911 \newline
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 j = i; 
33915 \newline
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 return j; 
33919 \newline
33920 }
33921 \end_layout
33922
33923 \begin_layout Standard
33924 will be changed to 
33925 \end_layout
33926
33927 \begin_layout Verse
33928
33929 \family typewriter
33930 int f() { 
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 int i, j; 
33935 \newline
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 i = 10; 
33939 \newline
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 j = 10; 
33943 \newline
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 return 10; 
33947 \newline
33948 }
33949 \end_layout
33950
33951 \begin_layout Standard
33952 Note: the dead stores created by this copy propagation will be eliminated
33953  by dead-code elimination.
33954 \end_layout
33955
33956 \begin_layout Subsection
33957 Loop Optimizations
33958 \begin_inset LatexCommand \index{Loop optimization}
33959
33960 \end_inset
33961
33962
33963 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33964
33965 \end_inset
33966
33967
33968 \end_layout
33969
33970 \begin_layout Standard
33971 Two types of loop optimizations are done by SDCC 
33972 \emph on
33973 loop invariant
33974 \emph default
33975  lifting and
33976 \emph on
33977  strength reduction
33978 \emph default
33979  of loop induction variables.
33980  In addition to the strength reduction the optimizer marks the induction
33981  variables and the register allocator tries to keep the induction variables
33982  in registers for the duration of the loop.
33983  Because of this preference of the register allocator
33984 \begin_inset LatexCommand \index{Register allocation}
33985
33986 \end_inset
33987
33988 , loop induction optimization causes an increase in register pressure, which
33989  may cause unwanted spilling of other temporary variables into the stack
33990 \begin_inset LatexCommand \index{stack}
33991
33992 \end_inset
33993
33994  / data space.
33995  The compiler will generate a warning message when it is forced to allocate
33996  extra space either on the stack or data space.
33997  If this extra space allocation is undesirable then induction optimization
33998  can be eliminated either for the entire source file (with -
33999 \begin_inset ERT
34000 status collapsed
34001
34002 \begin_layout Standard
34003
34004
34005 \backslash
34006 /
34007 \end_layout
34008
34009 \end_inset
34010
34011 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34012 noinduction
34013 \begin_inset LatexCommand \index{\#pragma noinduction}
34014
34015 \end_inset
34016
34017 .
34018 \newline
34019
34020 \newline
34021 Loop Invariant:
34022 \end_layout
34023
34024 \begin_layout Verse
34025
34026 \family typewriter
34027 for (i = 0 ; i < 100 ; i ++) 
34028 \newline
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 f += k + l;
34034 \end_layout
34035
34036 \begin_layout Standard
34037 changed to
34038 \end_layout
34039
34040 \begin_layout Verse
34041
34042 \family typewriter
34043 itemp = k + l; 
34044 \newline
34045 for (i = 0; i < 100; i++) 
34046 \newline
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 f += itemp;
34052 \end_layout
34053
34054 \begin_layout Standard
34055 As mentioned previously some loop invariants are not as apparent, all static
34056  address computations are also moved out of the loop.
34057 \newline
34058
34059 \newline
34060 Strength Reduction
34061 \begin_inset LatexCommand \index{Strength reduction}
34062
34063 \end_inset
34064
34065 , this optimization substitutes an expression by a cheaper expression:
34066 \end_layout
34067
34068 \begin_layout Verse
34069
34070 \family typewriter
34071 for (i=0;i < 100; i++)
34072 \newline
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 ar[i*5] = i*3;
34078 \end_layout
34079
34080 \begin_layout Standard
34081 changed to
34082 \end_layout
34083
34084 \begin_layout Verse
34085
34086 \family typewriter
34087 itemp1 = 0; 
34088 \newline
34089 itemp2 = 0; 
34090 \newline
34091 for (i=0;i< 100;i++) { 
34092 \newline
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 ar[itemp1] = itemp2; 
34098 \newline
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 itemp1
34104  += 5; 
34105 \newline
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 itemp2 += 3; 
34111 \newline
34112 }
34113 \end_layout
34114
34115 \begin_layout Standard
34116 The more expensive multiplication
34117 \begin_inset LatexCommand \index{Multiplication}
34118
34119 \end_inset
34120
34121  is changed to a less expensive addition.
34122 \end_layout
34123
34124 \begin_layout Subsection
34125 Loop Reversing
34126 \begin_inset LatexCommand \index{Loop reversing}
34127
34128 \end_inset
34129
34130
34131 \end_layout
34132
34133 \begin_layout Standard
34134 This optimization is done to reduce the overhead of checking loop boundaries
34135  for every iteration.
34136  Some simple loops can be reversed and implemented using a 
34137 \begin_inset Quotes eld
34138 \end_inset
34139
34140 decrement and jump if not zero
34141 \begin_inset Quotes erd
34142 \end_inset
34143
34144  instruction.
34145  SDCC checks for the following criterion to determine if a loop is reversible
34146  (note: more sophisticated compilers use data-dependency analysis to make
34147  this determination, SDCC uses a more simple minded analysis).
34148 \end_layout
34149
34150 \begin_layout Itemize
34151 The 'for' loop is of the form 
34152 \newline
34153
34154 \newline
34155
34156 \family typewriter
34157 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34158  += 1])
34159 \newline
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 <for body>
34165 \end_layout
34166
34167 \begin_layout Itemize
34168 The <for body> does not contain 
34169 \begin_inset Quotes eld
34170 \end_inset
34171
34172 continue
34173 \begin_inset Quotes erd
34174 \end_inset
34175
34176  or 'break
34177 \begin_inset Quotes erd
34178 \end_inset
34179
34180 .
34181 \end_layout
34182
34183 \begin_layout Itemize
34184 All goto's are contained within the loop.
34185 \end_layout
34186
34187 \begin_layout Itemize
34188 No function calls within the loop.
34189 \end_layout
34190
34191 \begin_layout Itemize
34192 The loop control variable <sym> is not assigned any value within the loop
34193 \end_layout
34194
34195 \begin_layout Itemize
34196 The loop control variable does NOT participate in any arithmetic operation
34197  within the loop.
34198 \end_layout
34199
34200 \begin_layout Itemize
34201 There are NO switch statements in the loop.
34202 \end_layout
34203
34204 \begin_layout Subsection
34205 Algebraic Simplifications
34206 \end_layout
34207
34208 \begin_layout Standard
34209 SDCC does numerous algebraic simplifications, the following is a small sub-set
34210  of these optimizations.
34211 \end_layout
34212
34213 \begin_layout Verse
34214
34215 \family typewriter
34216 i = j + 0;\InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220  /* changed to: */\InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224  i = j; 
34225 \newline
34226 i /= 2;\InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233  /* changed to: */\InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237  i >>= 1; 
34238 \newline
34239 i
34240  = j - j;\InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244  /* changed to: */\InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248  i = 0; 
34249 \newline
34250 i = j / 1;\InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254  /* changed to: */\InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258  i = j;
34259 \end_layout
34260
34261 \begin_layout Standard
34262 Note the subexpressions
34263 \begin_inset LatexCommand \index{Subexpression}
34264
34265 \end_inset
34266
34267  given above are generally introduced by macro expansions or as a result
34268  of copy/constant propagation.
34269 \end_layout
34270
34271 \begin_layout Subsection
34272 'switch' Statements
34273 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34274
34275 \end_inset
34276
34277
34278 \begin_inset LatexCommand \index{switch statement}
34279
34280 \end_inset
34281
34282
34283 \end_layout
34284
34285 \begin_layout Standard
34286 SDCC can optimize switch statements to jump tables
34287 \begin_inset LatexCommand \index{jump tables}
34288
34289 \end_inset
34290
34291 .
34292  It makes the decision based on an estimate of the generated code size.
34293  SDCC is quite liberal in the requirements for jump table generation: 
34294 \end_layout
34295
34296 \begin_layout Itemize
34297 The labels need not be in order, and the starting number need not be one
34298  or zero, the case labels are in numerical sequence or not too many case
34299  labels are missing.
34300 \end_layout
34301
34302 \begin_deeper
34303 \begin_layout Verse
34304
34305 \family typewriter
34306 switch(i) {\InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 switch (i) { 
34333 \newline
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 case 4: ...\InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 case 0: ...
34364  
34365 \newline
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 case 5: ...\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 case 1: ...
34396  
34397 \newline
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401 case 3: ...\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 \InsetSpace ~
34427
34428 \newline
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 case 6: ...\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 3: ...
34459  
34460 \newline
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 case 7: ...\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 case 4: ...
34491  
34492 \newline
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 case 8: ...\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 \InsetSpace ~
34522 case 5: ...
34523  
34524 \newline
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 case 9: ...\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 \InsetSpace ~
34554 case 6: ...
34555  
34556 \newline
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 case 10: ...\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 7: ...
34586  
34587 \newline
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 case 11: ...\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 case 8: ...
34617  
34618 \newline
34619 }\InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 }
34656 \end_layout
34657
34658 \begin_layout Standard
34659 Both the above switch statements will be implemented using a jump-table.
34660  The example to the right side is slightly more efficient as the check for
34661  the lower boundary of the jump-table is not needed.
34662 \end_layout
34663
34664 \end_deeper
34665 \begin_layout Itemize
34666 The number of case labels is not larger than supported by the target architectur
34667 e.
34668 \end_layout
34669
34670 \begin_layout Itemize
34671 If the case labels are not in numerical sequence ('gaps' between cases)
34672  SDCC checks whether a jump table with additionally inserted dummy cases
34673  is still attractive.
34674  
34675 \end_layout
34676
34677 \begin_layout Itemize
34678 If the starting number is not zero and a check for the lower boundary of
34679  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34680  ...
34681  .
34682 \end_layout
34683
34684 \begin_layout Standard
34685 Switch statements which have large gaps in the numeric sequence or those
34686  that have too many case labels can be split into more than one switch statement
34687  for efficient code generation, e.g.:
34688 \end_layout
34689
34690 \begin_layout Verse
34691
34692 \family typewriter
34693 switch (i) { 
34694 \newline
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 case 1: ...
34698  
34699 \newline
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 case 2: ...
34703  
34704 \newline
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 case 3: ...
34708  
34709 \newline
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 case 4: ...
34713  
34714 \newline
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 case 5: ...
34718  
34719 \newline
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 case 6: ...
34723  
34724 \newline
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 case 7: ...
34728  
34729 \newline
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 case 101: ...
34733  
34734 \newline
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 case 102: ...
34738  
34739 \newline
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 case 103: ...
34743  
34744 \newline
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 case 104: ...
34748  
34749 \newline
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 case 105: ...
34753  
34754 \newline
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 case 106: ...
34758  
34759 \newline
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 case 107: ...
34763  
34764 \newline
34765 }
34766 \end_layout
34767
34768 \begin_layout Standard
34769 If the above switch statement is broken down into two switch statements
34770 \end_layout
34771
34772 \begin_layout Verse
34773
34774 \family typewriter
34775 switch (i) { 
34776 \newline
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 case 1: ...
34780  
34781 \newline
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 case 2: ...
34785  
34786 \newline
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 case 3: ...
34790  
34791 \newline
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 case 4: ...
34795  
34796 \newline
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 case 5: ...
34800  
34801 \newline
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 case 6: ...
34805  
34806 \newline
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 case 7: ...
34810  
34811 \newline
34812 }
34813 \end_layout
34814
34815 \begin_layout Standard
34816 and
34817 \end_layout
34818
34819 \begin_layout Verse
34820
34821 \family typewriter
34822 switch (i) { 
34823 \newline
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 case 101: ...
34827  
34828 \newline
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 case 102: ...
34832  
34833 \newline
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 case 103: ...
34837  
34838 \newline
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 case 104: ...
34842  
34843 \newline
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 case 105: ...
34847  
34848 \newline
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 case 106: ...
34852  
34853 \newline
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 case 107: ...
34857  
34858 \newline
34859 }
34860 \end_layout
34861
34862 \begin_layout Standard
34863 then both the switch statements will be implemented using jump-tables whereas
34864  the unmodified switch statement will not be.
34865 \end_layout
34866
34867 \begin_layout Standard
34868 \begin_inset Note Note
34869 status collapsed
34870
34871 \begin_layout Standard
34872 There might be reasons which SDCC cannot know about to either favour or
34873  not favour jump tables.
34874  If the target system has to be as quick for the last switch case as for
34875  the first (pro jump table), or if the switch argument is known to be zero
34876  in the majority of the cases (contra jump table).
34877 \end_layout
34878
34879 \end_inset
34880
34881
34882 \end_layout
34883
34884 \begin_layout Standard
34885 The pragma nojtbound
34886 \begin_inset LatexCommand \index{\#pragma nojtbound}
34887
34888 \end_inset
34889
34890  can be used to turn off checking the 
34891 \emph on
34892 j
34893 \emph default
34894 ump 
34895 \emph on
34896 t
34897 \emph default
34898 able 
34899 \emph on
34900 bound
34901 \emph default
34902 aries.
34903  It has no effect if a default label is supplied.
34904  Use of this pragma is dangerous: if the switch
34905 \begin_inset LatexCommand \index{switch statement}
34906
34907 \end_inset
34908
34909  argument is not matched by a case statement the processor will happily
34910  jump into Nirvana.
34911 \end_layout
34912
34913 \begin_layout Subsection
34914 Bit-shifting Operations
34915 \begin_inset LatexCommand \index{Bit shifting}
34916
34917 \end_inset
34918
34919 .
34920 \end_layout
34921
34922 \begin_layout Standard
34923 Bit shifting is one of the most frequently used operation in embedded programmin
34924 g.
34925  SDCC tries to implement bit-shift operations in the most efficient way
34926  possible, e.g.:
34927 \end_layout
34928
34929 \begin_layout Verse
34930
34931 \family typewriter
34932 unsigned char i;
34933 \newline
34934 ...
34935  
34936 \newline
34937 i >>= 4; 
34938 \newline
34939 ...
34940 \end_layout
34941
34942 \begin_layout Standard
34943 generates the following code:
34944 \end_layout
34945
34946 \begin_layout Verse
34947
34948 \family typewriter
34949 mov\InsetSpace ~
34950  a,_i 
34951 \newline
34952 swap a 
34953 \newline
34954 anl\InsetSpace ~
34955  a,#0x0f 
34956 \newline
34957 mov\InsetSpace ~
34958  _i,a
34959 \end_layout
34960
34961 \begin_layout Standard
34962 In general SDCC will never setup a loop if the shift count is known.
34963  Another example:
34964 \end_layout
34965
34966 \begin_layout Verse
34967
34968 \family typewriter
34969 unsigned int i; 
34970 \newline
34971 ...
34972  
34973 \newline
34974 i >>= 9; 
34975 \newline
34976 ...
34977 \end_layout
34978
34979 \begin_layout Standard
34980 will generate:
34981 \end_layout
34982
34983 \begin_layout Verse
34984
34985 \family typewriter
34986 mov\InsetSpace ~
34987 \InsetSpace ~
34988 a,(_i + 1) 
34989 \newline
34990 mov\InsetSpace ~
34991 \InsetSpace ~
34992 (_i + 1),#0x00 
34993 \newline
34994 clr\InsetSpace ~
34995 \InsetSpace ~
34996
34997 \newline
34998 rrc\InsetSpace ~
34999 \InsetSpace ~
35000
35001 \newline
35002 mov\InsetSpace ~
35003 \InsetSpace ~
35004 _i,a
35005 \end_layout
35006
35007 \begin_layout Subsection
35008 Bit-rotation
35009 \begin_inset LatexCommand \index{Bit rotation}
35010
35011 \end_inset
35012
35013
35014 \end_layout
35015
35016 \begin_layout Standard
35017 A special case of the bit-shift operation is bit rotation
35018 \begin_inset LatexCommand \index{rotating bits}
35019
35020 \end_inset
35021
35022 , SDCC recognizes the following expression to be a left bit-rotation:
35023 \end_layout
35024
35025 \begin_layout Verse
35026
35027 \family typewriter
35028 \series bold
35029 unsigned
35030 \series default
35031 \InsetSpace ~
35032 \InsetSpace ~
35033 char i;\InsetSpace ~
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 /* unsigned is needed for rotation */ 
35045 \newline
35046 ...
35047  
35048 \newline
35049 i = ((i << 1) | (i >> 7)); 
35050 \family default
35051
35052 \newline
35053
35054 \family typewriter
35055 ...
35056 \end_layout
35057
35058 \begin_layout Standard
35059 will generate the following code:
35060 \end_layout
35061
35062 \begin_layout Verse
35063
35064 \family typewriter
35065 mov\InsetSpace ~
35066 \InsetSpace ~
35067 a,_i 
35068 \newline
35069 rl\InsetSpace ~
35070 \InsetSpace ~
35071 \InsetSpace ~
35072
35073 \newline
35074 mov\InsetSpace ~
35075 \InsetSpace ~
35076 _i,a
35077 \end_layout
35078
35079 \begin_layout Standard
35080 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35081 ns of this case will also be recognized as bit-rotation, i.e.: 
35082 \end_layout
35083
35084 \begin_layout Verse
35085
35086 \family typewriter
35087 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35088 \end_layout
35089
35090 \begin_layout Subsection
35091 Nibble and Byte Swapping
35092 \end_layout
35093
35094 \begin_layout Standard
35095 Other special cases of the bit-shift operations are nibble or byte swapping
35096 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35097
35098 \end_inset
35099
35100 , SDCC recognizes the following expressions:
35101 \end_layout
35102
35103 \begin_layout Verse
35104
35105 \family typewriter
35106 \series bold
35107 unsigned
35108 \series default
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 char i; 
35112 \newline
35113
35114 \series bold
35115 unsigned
35116 \series default
35117 \InsetSpace ~
35118 \InsetSpace ~
35119 int j; 
35120 \newline
35121 ...
35122  
35123 \newline
35124 i = ((i << 4) | (i >> 4)); 
35125 \family default
35126
35127 \newline
35128
35129 \family typewriter
35130 j = ((j << 8) | (j >> 8)); 
35131 \end_layout
35132
35133 \begin_layout Standard
35134 and generates a swap instruction for the nibble swapping
35135 \begin_inset LatexCommand \index{Nibble swapping}
35136
35137 \end_inset
35138
35139  or move instructions for the byte swapping
35140 \begin_inset LatexCommand \index{Byte swapping}
35141
35142 \end_inset
35143
35144 .
35145  The 
35146 \begin_inset Quotes sld
35147 \end_inset
35148
35149 j
35150 \begin_inset Quotes srd
35151 \end_inset
35152
35153  example can be used to convert from little to big-endian or vice versa.
35154  If you want to change the endianness of a 
35155 \emph on
35156 signed
35157 \emph default
35158  integer you have to cast to 
35159 \family typewriter
35160 (unsigned int)
35161 \family default
35162  first.
35163 \end_layout
35164
35165 \begin_layout Standard
35166 Note that SDCC stores numbers in little-endian
35167 \begin_inset Foot
35168 status open
35169
35170 \begin_layout Standard
35171 Usually 8-bit processors don't care much about endianness.
35172  This is not the case for the standard 8051 which only has an instruction
35173  to increment its 
35174 \emph on
35175 dptr
35176 \emph default
35177
35178 \begin_inset LatexCommand \index{DPTR}
35179
35180 \end_inset
35181
35182 -datapointer
35183 \emph on
35184  
35185 \emph default
35186 so little-endian is the more efficient byte order.
35187 \end_layout
35188
35189 \end_inset
35190
35191
35192 \begin_inset LatexCommand \index{little-endian}
35193
35194 \end_inset
35195
35196
35197 \begin_inset LatexCommand \index{Endianness}
35198
35199 \end_inset
35200
35201  format (i.e.
35202  lowest order first).
35203 \end_layout
35204
35205 \begin_layout Subsection
35206 Highest Order Bit
35207 \begin_inset LatexCommand \index{Highest Order Bit}
35208
35209 \end_inset
35210
35211  / Any Order Bit
35212 \begin_inset LatexCommand \index{Any Order Bit}
35213
35214 \end_inset
35215
35216
35217 \end_layout
35218
35219 \begin_layout Standard
35220 It is frequently required to obtain the highest order bit of an integral
35221  type (long, int, short or char types).
35222  Also obtaining any other order bit is not uncommon.
35223  SDCC recognizes the following expressions to yield the highest order bit
35224  and generates optimized code for it, e.g.:
35225 \end_layout
35226
35227 \begin_layout Verse
35228
35229 \family typewriter
35230 unsigned int gint; 
35231 \newline
35232
35233 \newline
35234 foo () { 
35235 \newline
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 unsigned char hob1, aob1; 
35239 \newline
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 bit hob2, hob3, aob2,
35243  aob3; 
35244 \newline
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 ...
35248  
35249 \newline
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 hob1 = (gint >> 15) & 1; 
35253 \newline
35254 \InsetSpace ~
35255 \InsetSpace ~
35256 hob2 = (gint >> 15) & 1; 
35257 \newline
35258 \InsetSpace ~
35259 \InsetSpace ~
35260 hob3 = gint & 0x8000;
35261  
35262 \newline
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 aob1 = (gint >> 9) & 1; 
35266 \newline
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 aob2 = (gint >> 8) & 1; 
35270 \newline
35271 \InsetSpace ~
35272 \InsetSpace ~
35273 aob3 = gint & 0x0800; 
35274 \newline
35275 \InsetSpace ~
35276 \InsetSpace ~
35277 ..
35278  
35279 \newline
35280 }
35281 \end_layout
35282
35283 \begin_layout Standard
35284 will generate the following code:
35285 \end_layout
35286
35287 \begin_layout Verse
35288
35289 \family typewriter
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314 \InsetSpace ~
35315  61 ;\InsetSpace ~
35316  hob.c 7 
35317 \newline
35318 000A E5*01\InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331 \InsetSpace ~
35332 \InsetSpace ~
35333  62\InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 \InsetSpace ~
35340 \InsetSpace ~
35341  mov\InsetSpace ~
35342 \InsetSpace ~
35343  a,(_gint + 1) 
35344 \newline
35345 000C 23\InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363  63\InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 \InsetSpace ~
35371  rl\InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374  a 
35375 \newline
35376 000D 54 01\InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390 \InsetSpace ~
35391
35392  64\InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400  anl\InsetSpace ~
35401 \InsetSpace ~
35402  a,#0x01 
35403 \newline
35404 000F F5*02\InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419  65\InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427  mov\InsetSpace ~
35428 \InsetSpace ~
35429  _foo_hob1_1_1,a 
35430 \newline
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456  66 ;\InsetSpace ~
35457  hob.c 8 
35458 \newline
35459 0011 E5*01\InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474
35475  67\InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483  mov\InsetSpace ~
35484 \InsetSpace ~
35485  a,(_gint + 1) 
35486 \newline
35487 0013 33\InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505  68\InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513  rlc\InsetSpace ~
35514 \InsetSpace ~
35515  a 
35516 \newline
35517 0014 92*00\InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532  69\InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540  mov\InsetSpace ~
35541 \InsetSpace ~
35542  _foo_hob2_1_1,c
35543  
35544 \newline
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570  66 ;\InsetSpace ~
35571  hob.c 9 
35572 \newline
35573 0016 E5*01\InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588  67\InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596  mov\InsetSpace ~
35597 \InsetSpace ~
35598  a,(_gint + 1) 
35599 \newline
35600 0018 33\InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618  68\InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626  rlc\InsetSpace ~
35627 \InsetSpace ~
35628  a 
35629 \newline
35630 0019 92*01\InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644 \InsetSpace ~
35645
35646  69\InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654  mov\InsetSpace ~
35655 \InsetSpace ~
35656  _foo_hob3_1_1,c 
35657 \newline
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661 \InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683  70 ;\InsetSpace ~
35684  hob.c 10 
35685 \newline
35686 001B E5*01\InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701  71\InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709  mov\InsetSpace ~
35710 \InsetSpace ~
35711  a,(_gint + 1) 
35712 \newline
35713 001D
35714  03\InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732  72\InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740  rr\InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743  a 
35744 \newline
35745 001E 54 01\InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760  73\InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765 \InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768  anl\InsetSpace ~
35769 \InsetSpace ~
35770  a,#0x01 
35771 \newline
35772 0020 F5*03\InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787  74\InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795  mov\InsetSpace ~
35796 \InsetSpace ~
35797  _foo_aob1_1_1,a
35798  
35799 \newline
35800 \InsetSpace ~
35801 \InsetSpace ~
35802 \InsetSpace ~
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \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 \InsetSpace ~
35824 \InsetSpace ~
35825  75 ;\InsetSpace ~
35826  hob.c 11 
35827 \newline
35828 0022 E5*01\InsetSpace ~
35829 \InsetSpace ~
35830 \InsetSpace ~
35831 \InsetSpace ~
35832 \InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843  76\InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851  mov\InsetSpace ~
35852 \InsetSpace ~
35853  a,(_gint + 1) 
35854 \newline
35855 0024 13\InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873  77\InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881  rrc\InsetSpace ~
35882 \InsetSpace ~
35883  a 
35884 \newline
35885 0025 92*02\InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900
35901  78\InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909  mov\InsetSpace ~
35910 \InsetSpace ~
35911  _foo_aob2_1_1,c 
35912 \newline
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \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 \InsetSpace ~
35937 \InsetSpace ~
35938  79 ;\InsetSpace ~
35939  hob.c 12 
35940 \newline
35941 0027 E5*01\InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956  80\InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964  mov\InsetSpace ~
35965 \InsetSpace ~
35966  a,(_gint + 1) 
35967 \newline
35968 0029
35969  A2 E3\InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984  81\InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992  mov\InsetSpace ~
35993 \InsetSpace ~
35994  c,acc[3] 
35995 \newline
35996 002B 92*03\InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011  82\InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019  mov\InsetSpace ~
36020 \InsetSpace ~
36021  _foo_aob3_1_1,c 
36022 \end_layout
36023
36024 \begin_layout Standard
36025 Other variations of these cases however will 
36026 \emph on
36027 not
36028 \emph default
36029  be recognized.
36030  They are standard C expressions, so I heartily recommend these be the only
36031  way to get the highest order bit, (it is portable).
36032  Of course it will be recognized even if it is embedded in other expressions,
36033  e.g.:
36034 \end_layout
36035
36036 \begin_layout Verse
36037
36038 \family typewriter
36039 xyz = gint + ((gint >> 15) & 1);
36040 \end_layout
36041
36042 \begin_layout Standard
36043 will still be recognized.
36044 \end_layout
36045
36046 \begin_layout Subsection
36047 Higher Order Byte
36048 \begin_inset LatexCommand \index{Higher Order Byte}
36049
36050 \end_inset
36051
36052  / Higher Order Word
36053 \begin_inset LatexCommand \index{Higher Order Word}
36054
36055 \end_inset
36056
36057
36058 \end_layout
36059
36060 \begin_layout Standard
36061 It is also frequently required to obtain a higher order byte or word of
36062  a larger integral type (long, int or short types).
36063  SDCC recognizes the following expressions to yield the higher order byte
36064  or word and generates optimized code for it, e.g.:
36065 \end_layout
36066
36067 \begin_layout Verse
36068
36069 \family typewriter
36070 unsigned int gint; 
36071 \newline
36072 unsigned long int glong; 
36073 \newline
36074
36075 \newline
36076 foo () { 
36077 \newline
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 unsigned char hob1,
36081  hob2; 
36082 \newline
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 unsigned int how1, how2; 
36086 \newline
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 ...
36090  
36091 \newline
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 hob1 = (gint >> 8) & 0xFF; 
36095 \newline
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 hob2 = glong >> 24; 
36099 \newline
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 how1 = (glong >> 16) & 0xFFFF;
36103  
36104 \newline
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 how2 = glong >> 8; 
36108 \newline
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 ..
36112  
36113 \newline
36114 }
36115 \end_layout
36116
36117 \begin_layout Standard
36118 will generate the following code:
36119 \end_layout
36120
36121 \begin_layout Verse
36122
36123 \family typewriter
36124 \InsetSpace ~
36125 \InsetSpace ~
36126 \InsetSpace ~
36127 \InsetSpace ~
36128 \InsetSpace ~
36129 \InsetSpace ~
36130 \InsetSpace ~
36131 \InsetSpace ~
36132 \InsetSpace ~
36133 \InsetSpace ~
36134 \InsetSpace ~
36135 \InsetSpace ~
36136 \InsetSpace ~
36137 \InsetSpace ~
36138 \InsetSpace ~
36139 \InsetSpace ~
36140 \InsetSpace ~
36141 \InsetSpace ~
36142 \InsetSpace ~
36143 \InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 \InsetSpace ~
36149  91 ;\InsetSpace ~
36150  hob.c 15 
36151 \newline
36152 0037 85*01*06\InsetSpace ~
36153 \InsetSpace ~
36154 \InsetSpace ~
36155 \InsetSpace ~
36156 \InsetSpace ~
36157 \InsetSpace ~
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 \InsetSpace ~
36163 \InsetSpace ~
36164  92\InsetSpace ~
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172  mov\InsetSpace ~
36173 \InsetSpace ~
36174  _foo_hob1_1_1,(_gint + 1) 
36175 \newline
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 \InsetSpace ~
36180 \InsetSpace ~
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 \InsetSpace ~
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  93 ;\InsetSpace ~
36202  hob.c
36203  16 
36204 \newline
36205 003A 85*05*07\InsetSpace ~
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 \InsetSpace ~
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 \InsetSpace ~
36215 \InsetSpace ~
36216 \InsetSpace ~
36217  94\InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225  mov\InsetSpace ~
36226 \InsetSpace ~
36227  _foo_hob2_1_1,(_glong + 3) 
36228 \newline
36229 \InsetSpace ~
36230 \InsetSpace ~
36231 \InsetSpace ~
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 \InsetSpace ~
36235 \InsetSpace ~
36236 \InsetSpace ~
36237 \InsetSpace ~
36238 \InsetSpace ~
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  95 ;\InsetSpace ~
36255  hob.c 17 
36256 \newline
36257 003D 85*04*08\InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268 \InsetSpace ~
36269
36270  96\InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278  mov\InsetSpace ~
36279 \InsetSpace ~
36280  _foo_how1_1_1,(_glong + 2) 
36281 \newline
36282 0040 85*05*09\InsetSpace ~
36283 \InsetSpace ~
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 \InsetSpace ~
36294  97\InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 \InsetSpace ~
36299 \InsetSpace ~
36300 \InsetSpace ~
36301 \InsetSpace ~
36302  mov\InsetSpace ~
36303 \InsetSpace ~
36304  (_foo_how1_1_1 +
36305  1),(_glong + 3) 
36306 \newline
36307 0043 85*03*0A\InsetSpace ~
36308 \InsetSpace ~
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 \InsetSpace ~
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 \InsetSpace ~
36318 \InsetSpace ~
36319  98\InsetSpace ~
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 \InsetSpace ~
36324 \InsetSpace ~
36325 \InsetSpace ~
36326 \InsetSpace ~
36327  mov\InsetSpace ~
36328 \InsetSpace ~
36329  _foo_how2_1_1,(_glong + 1) 
36330 \newline
36331 0046 85*04*0B\InsetSpace ~
36332 \InsetSpace ~
36333 \InsetSpace ~
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 \InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 \InsetSpace ~
36343
36344  99\InsetSpace ~
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348 \InsetSpace ~
36349 \InsetSpace ~
36350 \InsetSpace ~
36351 \InsetSpace ~
36352  mov\InsetSpace ~
36353 \InsetSpace ~
36354  (_foo_how2_1_1 + 1),(_glong + 2) 
36355 \end_layout
36356
36357 \begin_layout Standard
36358 Again, variations of these cases may 
36359 \emph on
36360 not
36361 \emph default
36362  be recognized.
36363  They are standard C expressions, so I heartily recommend these be the only
36364  way to get the higher order byte/word, (it is portable).
36365  Of course it will be recognized even if it is embedded in other expressions,
36366  e.g.:
36367 \end_layout
36368
36369 \begin_layout Verse
36370
36371 \family typewriter
36372 xyz = gint + ((gint >> 8) & 0xFF);
36373 \end_layout
36374
36375 \begin_layout Standard
36376 will still be recognized.
36377 \end_layout
36378
36379 \begin_layout Subsection
36380 Peephole Optimizer
36381 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36382
36383 \end_inset
36384
36385
36386 \begin_inset LatexCommand \index{Peephole optimizer}
36387
36388 \end_inset
36389
36390
36391 \end_layout
36392
36393 \begin_layout Standard
36394 The compiler uses a rule based, pattern matching and re-writing mechanism
36395  for peep-hole optimization.
36396  It is inspired by 
36397 \emph on
36398 copt
36399 \emph default
36400  a peep-hole optimizer by Christopher W.
36401  Fraser (cwfraser\InsetSpace ~
36402 @\InsetSpace ~
36403 microsoft.com).
36404  A default set of rules are compiled into the compiler, additional rules
36405  may be added with the 
36406 \emph on
36407 -
36408 \begin_inset ERT
36409 status collapsed
36410
36411 \begin_layout Standard
36412
36413
36414 \backslash
36415 /
36416 \end_layout
36417
36418 \end_inset
36419
36420 -peep-file
36421 \begin_inset LatexCommand \index{-\/-peep-file}
36422
36423 \end_inset
36424
36425  <filename>
36426 \emph default
36427  option.
36428  The rule language is best illustrated with examples.
36429 \end_layout
36430
36431 \begin_layout Verse
36432
36433 \family typewriter
36434 replace { 
36435 \newline
36436 \InsetSpace ~
36437 \InsetSpace ~
36438 mov %1,a 
36439 \newline
36440 \InsetSpace ~
36441 \InsetSpace ~
36442 mov a,%1
36443 \newline
36444 } by {
36445 \newline
36446 \InsetSpace ~
36447 \InsetSpace ~
36448 mov %1,a
36449 \newline
36450 }
36451 \end_layout
36452
36453 \begin_layout Standard
36454 The above rule will change the following assembly
36455 \begin_inset LatexCommand \index{Assembler routines}
36456
36457 \end_inset
36458
36459  sequence:
36460 \end_layout
36461
36462 \begin_layout Verse
36463
36464 \family typewriter
36465 mov r1,a 
36466 \newline
36467 mov a,r1
36468 \end_layout
36469
36470 \begin_layout Standard
36471 to
36472 \end_layout
36473
36474 \begin_layout Verse
36475
36476 \family typewriter
36477 mov r1,a
36478 \end_layout
36479
36480 \begin_layout Standard
36481 Note: All occurrences of a 
36482 \emph on
36483 %n
36484 \emph default
36485  (pattern variable) must denote the same string.
36486  With the above rule, the assembly sequence:
36487 \end_layout
36488
36489 \begin_layout Verse
36490
36491 \family typewriter
36492 mov r1,a 
36493 \newline
36494 mov a,r2
36495 \end_layout
36496
36497 \begin_layout Standard
36498 will remain unmodified.
36499 \newline
36500
36501 \newline
36502 Other special case optimizations may be added by the
36503  user (via 
36504 \emph on
36505 -
36506 \begin_inset ERT
36507 status collapsed
36508
36509 \begin_layout Standard
36510
36511
36512 \backslash
36513 /
36514 \end_layout
36515
36516 \end_inset
36517
36518 -peep-file option
36519 \emph default
36520 ).
36521  E.g.
36522  some variants of the 8051 MCU
36523 \begin_inset LatexCommand \index{MCS51 variants}
36524
36525 \end_inset
36526
36527  allow only 
36528 \family typewriter
36529 ajmp
36530 \family default
36531  and 
36532 \family typewriter
36533 acall
36534 \family default
36535 .
36536  The following two rules will change all 
36537 \family typewriter
36538 ljmp
36539 \family default
36540  and 
36541 \family typewriter
36542 lcall
36543 \family default
36544  to 
36545 \family typewriter
36546 ajmp
36547 \family default
36548  and 
36549 \family typewriter
36550 acall
36551 \end_layout
36552
36553 \begin_layout Verse
36554
36555 \family typewriter
36556 replace { lcall %1 } by { acall %1 } 
36557 \newline
36558 replace { ljmp %1 } by { ajmp %1 }
36559 \end_layout
36560
36561 \begin_layout Standard
36562 (NOTE: from version 2.7.3 on, you can use option -
36563 \emph on
36564
36565 \begin_inset ERT
36566 status collapsed
36567
36568 \begin_layout Standard
36569
36570
36571 \backslash
36572 /
36573 \end_layout
36574
36575 \end_inset
36576
36577
36578 \emph default
36579 -acall-ajmp
36580 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36581
36582 \end_inset
36583
36584 , which also takes care of aligning the interrupt vectors properly.)
36585 \newline
36586
36587 \end_layout
36588
36589 \begin_layout Standard
36590 The 
36591 \emph on
36592 inline-assembler code
36593 \emph default
36594  is also passed through the peep hole optimizer, thus the peephole optimizer
36595  can also be used as an assembly level macro expander.
36596  The rules themselves are MCU dependent whereas the rule language infra-structur
36597 e is MCU independent.
36598  Peephole optimization rules for other MCU can be easily programmed using
36599  the rule language.
36600 \newline
36601
36602 \newline
36603 The syntax for a rule is as follows:
36604 \end_layout
36605
36606 \begin_layout Verse
36607
36608 \family typewriter
36609 rule := replace [ restart ] '{' <assembly sequence> '
36610 \backslash
36611 n' 
36612 \newline
36613 \InsetSpace ~
36614  \InsetSpace ~
36615  \InsetSpace ~
36616  \InsetSpace ~
36617  \InsetSpace ~
36618  \InsetSpace ~
36619  \InsetSpace ~
36620  \InsetSpace ~
36621  \InsetSpace ~
36622  \InsetSpace ~
36623  \InsetSpace ~
36624  \InsetSpace ~
36625  \InsetSpace ~
36626  \InsetSpace ~
36627  '}' by '{' '
36628 \backslash
36629 n' 
36630 \newline
36631 \InsetSpace ~
36632  \InsetSpace ~
36633  \InsetSpace ~
36634  \InsetSpace ~
36635  \InsetSpace ~
36636  \InsetSpace ~
36637  \InsetSpace ~
36638  \InsetSpace ~
36639  \InsetSpace ~
36640  \InsetSpace ~
36641  \InsetSpace ~
36642  \InsetSpace ~
36643  \InsetSpace ~
36644  \InsetSpace ~
36645  \InsetSpace ~
36646  \InsetSpace ~
36647  <assembly sequence> '
36648 \backslash
36649 n' 
36650 \newline
36651 \InsetSpace ~
36652  \InsetSpace ~
36653  \InsetSpace ~
36654  \InsetSpace ~
36655  \InsetSpace ~
36656  \InsetSpace ~
36657  \InsetSpace ~
36658  \InsetSpace ~
36659  \InsetSpace ~
36660  \InsetSpace ~
36661  \InsetSpace ~
36662  \InsetSpace ~
36663  \InsetSpace ~
36664  \InsetSpace ~
36665  '}' [if <functionName> ] '
36666 \backslash
36667 n' 
36668 \end_layout
36669
36670 \begin_layout Standard
36671 <assembly sequence> := assembly instruction (each instruction including
36672  labels must be on a separate line).
36673 \newline
36674
36675 \newline
36676 The optimizer will apply to the rules
36677  one by one from the top in the sequence of their appearance, it will terminate
36678  when all rules are exhausted.
36679  If the 'restart' option is specified, then the optimizer will start matching
36680  the rules again from the top, this option for a rule is expensive (performance)
36681 , it is intended to be used in situations where a transformation will trigger
36682  the same rule again.
36683  An example of this (not a good one, it has side effects) is the following
36684  rule:
36685 \end_layout
36686
36687 \begin_layout Verse
36688
36689 \family typewriter
36690 replace restart { 
36691 \newline
36692 \InsetSpace ~
36693 \InsetSpace ~
36694 pop %1 
36695 \newline
36696 \InsetSpace ~
36697 \InsetSpace ~
36698 push %1 } by { 
36699 \newline
36700 \InsetSpace ~
36701 \InsetSpace ~
36702 ; nop 
36703 \newline
36704 }
36705 \end_layout
36706
36707 \begin_layout Standard
36708 Note that the replace pattern cannot be a blank, but can be a comment line.
36709  Without the 'restart' option only the innermost 'pop' 'push' pair would
36710  be eliminated, i.e.:
36711 \end_layout
36712
36713 \begin_layout Verse
36714
36715 \family typewriter
36716 pop ar1 
36717 \newline
36718 pop ar2 
36719 \newline
36720 push ar2 
36721 \newline
36722 push ar1
36723 \end_layout
36724
36725 \begin_layout Standard
36726 would result in:
36727 \end_layout
36728
36729 \begin_layout Verse
36730
36731 \family typewriter
36732 pop ar1 
36733 \newline
36734 ; nop 
36735 \newline
36736 push ar1
36737 \end_layout
36738
36739 \begin_layout Standard
36740
36741 \emph on
36742 with
36743 \emph default
36744  the restart option the rule will be applied again to the resulting code
36745  and then all the pop-push pairs will be eliminated to yield:
36746 \end_layout
36747
36748 \begin_layout Verse
36749
36750 \family typewriter
36751 ; nop 
36752 \newline
36753 ; nop
36754 \end_layout
36755
36756 \begin_layout Standard
36757 A conditional function can be attached to a rule.
36758  Attaching rules are somewhat more involved, let me illustrate this with
36759  an example.
36760 \end_layout
36761
36762 \begin_layout Verse
36763
36764 \family typewriter
36765 replace { 
36766 \newline
36767 \InsetSpace ~
36768  \InsetSpace ~
36769  \InsetSpace ~
36770 ljmp %5 
36771 \newline
36772 %2:
36773 \newline
36774 } by { 
36775 \newline
36776 \InsetSpace ~
36777  \InsetSpace ~
36778  \InsetSpace ~
36779 sjmp %5 
36780 \newline
36781 %2:
36782 \newline
36783 } if labelInRange
36784 \end_layout
36785
36786 \begin_layout Standard
36787 The optimizer does a look-up of a function name table defined in function
36788  
36789 \emph on
36790 callFuncByName
36791 \emph default
36792  in the source file SDCCpeeph.c, with the name 
36793 \emph on
36794 labelInRange
36795 \emph default
36796 .
36797  If it finds a corresponding entry the function is called.
36798  Note there can be no parameters specified for these functions, in this
36799  case the use of 
36800 \emph on
36801 %5
36802 \emph default
36803  is crucial, since the function 
36804 \emph on
36805 labelInRange
36806 \emph default
36807  expects to find the label in that particular variable (the hash table containin
36808 g the variable bindings is passed as a parameter).
36809  If you want to code more such functions, take a close look at the function
36810  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36811  Currently implemented are 
36812 \emph on
36813 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36814  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36815 \emph default
36816 and
36817 \emph on
36818  notVolatile
36819 \emph default
36820 .
36821 \end_layout
36822
36823 \begin_layout Standard
36824 I know this whole thing is a little kludgey, but maybe some day we will
36825  have some better means.
36826  If you are looking at this file, you will see the default rules that are
36827  compiled into the compiler, you can add your own rules in the default set
36828  there if you get tired of specifying the -
36829 \begin_inset ERT
36830 status collapsed
36831
36832 \begin_layout Standard
36833
36834
36835 \backslash
36836 /
36837 \end_layout
36838
36839 \end_inset
36840
36841 -peep-file option.
36842 \end_layout
36843
36844 \begin_layout Section
36845 ANSI-Compliance
36846 \begin_inset LatexCommand \index{ANSI-compliance}
36847
36848 \end_inset
36849
36850
36851 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36852
36853 \end_inset
36854
36855
36856 \end_layout
36857
36858 \begin_layout Standard
36859 The latest publically available version of the standard 
36860 \emph on
36861 ISO/IEC 9899 - Programming languages - C
36862 \emph default
36863  should be available at: 
36864 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36865
36866 \end_inset
36867
36868 .
36869 \newline
36870
36871 \end_layout
36872
36873 \begin_layout Standard
36874 Deviations from the compliance:
36875 \end_layout
36876
36877 \begin_layout Itemize
36878 functions are not reentrant
36879 \begin_inset LatexCommand \index{reentrant}
36880
36881 \end_inset
36882
36883  unless explicitly declared as such or the 
36884 \series bold
36885 -
36886 \begin_inset ERT
36887 status collapsed
36888
36889 \begin_layout Standard
36890
36891
36892 \backslash
36893 /
36894 \end_layout
36895
36896 \end_inset
36897
36898 -stack-auto
36899 \begin_inset LatexCommand \index{-\/-stack-auto}
36900
36901 \end_inset
36902
36903
36904 \series default
36905  command line option is specified.
36906 \end_layout
36907
36908 \begin_layout Itemize
36909 structures
36910 \begin_inset LatexCommand \index{struct}
36911
36912 \end_inset
36913
36914  and unions
36915 \begin_inset LatexCommand \index{union}
36916
36917 \end_inset
36918
36919  cannot be assigned values directly, cannot be passed as function parameters
36920  or assigned to each other and cannot be a return value
36921 \begin_inset LatexCommand \index{return value}
36922
36923 \end_inset
36924
36925  from a function, e.g.:
36926 \end_layout
36927
36928 \begin_deeper
36929 \begin_layout Verse
36930
36931 \family typewriter
36932 struct s { ...
36933  }; 
36934 \newline
36935 struct s s1, s2; 
36936 \newline
36937 foo() 
36938 \newline
36939
36940 \newline
36941 \InsetSpace ~
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 \InsetSpace ~
36945 ...
36946  
36947 \newline
36948 \InsetSpace ~
36949 \InsetSpace ~
36950 \InsetSpace ~
36951 \InsetSpace ~
36952 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36953 \newline
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958 ...
36959  
36960 \newline
36961 }
36962 \newline
36963
36964 \series bold
36965 struct
36966 \series default
36967  s foo1 (
36968 \series bold
36969 struct
36970 \series default
36971  s parms) /* invalid in SDCC although allowed in ANSI */
36972 \newline
36973
36974 \newline
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 struct s rets;
36980  
36981 \newline
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 ...
36987  
36988 \newline
36989 \InsetSpace ~
36990 \InsetSpace ~
36991 \InsetSpace ~
36992 \InsetSpace ~
36993 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36994 \newline
36995 }
36996 \end_layout
36997
36998 \end_deeper
36999 \begin_layout Itemize
37000 initialization of structure arrays must be fully braced.
37001 \end_layout
37002
37003 \begin_deeper
37004 \begin_layout Verse
37005
37006 \family typewriter
37007 struct s { char x } a[] = {1, 2};\InsetSpace ~
37008 \InsetSpace ~
37009 \InsetSpace ~
37010 \InsetSpace ~
37011 \InsetSpace ~
37012 /* invalid in SDCC */
37013 \newline
37014 struct s { char x
37015  } a[] = {{1}, {2}}; /* OK */
37016 \end_layout
37017
37018 \end_deeper
37019 \begin_layout Itemize
37020 'long long
37021 \begin_inset LatexCommand \index{long long (not supported)}
37022
37023 \end_inset
37024
37025 ' (64 bit integers
37026 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37027
37028 \end_inset
37029
37030 ) not supported.
37031 \end_layout
37032
37033 \begin_layout Itemize
37034 'double
37035 \begin_inset LatexCommand \index{double (not supported)}
37036
37037 \end_inset
37038
37039 ' precision floating point 
37040 \begin_inset LatexCommand \index{Floating point support}
37041
37042 \end_inset
37043
37044 not supported.
37045 \end_layout
37046
37047 \begin_layout Itemize
37048 Old K&R style
37049 \begin_inset LatexCommand \index{K\&R style}
37050
37051 \end_inset
37052
37053  function declarations are NOT allowed.
37054 \end_layout
37055
37056 \begin_deeper
37057 \begin_layout Verse
37058
37059 \family typewriter
37060 foo(i,j) /* this old style of function declarations */ 
37061 \newline
37062 int i,j; /* is valid
37063  in ANSI but not valid in SDCC */ 
37064 \newline
37065
37066 \newline
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 ...
37072  
37073 \newline
37074 }
37075 \end_layout
37076
37077 \end_deeper
37078 \begin_layout Itemize
37079 Most enhancements in C99 are not supported, e.g.:
37080 \end_layout
37081
37082 \begin_deeper
37083 \begin_layout Verse
37084
37085 \family typewriter
37086 for (
37087 \series bold
37088 int
37089 \series default
37090  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37091 \end_layout
37092
37093 \end_deeper
37094 \begin_layout Itemize
37095 But some have been added recently in SDCC 2.7.0.
37096  They must be considered alpha quality however.
37097 \end_layout
37098
37099 \begin_deeper
37100 \begin_layout Verse
37101
37102 \family typewriter
37103 \series bold
37104 inline
37105 \begin_inset LatexCommand \index{inline (not supported)}
37106
37107 \end_inset
37108
37109
37110 \series default
37111  int increment (int a) { return a+1; } /* inlines the increment without
37112  function call overhead */
37113 \newline
37114 int * 
37115 \series bold
37116 restrict
37117 \begin_inset LatexCommand \index{inline (not supported)}
37118
37119 \end_inset
37120
37121
37122 \series default
37123  p; /* accepted but ignored */
37124 \end_layout
37125
37126 \end_deeper
37127 \begin_layout Itemize
37128 Certain words that are valid identifiers in the standard may be reserved
37129  words in SDCC unless the 
37130 \series bold
37131 -
37132 \begin_inset ERT
37133 status collapsed
37134
37135 \begin_layout Standard
37136
37137
37138 \backslash
37139 /
37140 \end_layout
37141
37142 \end_inset
37143
37144 -std-c89
37145 \begin_inset LatexCommand \index{-\/-std-c89}
37146
37147 \end_inset
37148
37149  
37150 \series default
37151 or
37152 \series bold
37153  -
37154 \begin_inset ERT
37155 status collapsed
37156
37157 \begin_layout Standard
37158
37159
37160 \backslash
37161 /
37162 \end_layout
37163
37164 \end_inset
37165
37166 -std-c99
37167 \begin_inset LatexCommand \index{-\/-std-c99}
37168
37169 \end_inset
37170
37171
37172 \series default
37173  command line options are used.
37174  These may include (depending on the selected processor): 'at', 'banked',
37175  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37176 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37177  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37178  '_naked'.
37179  Compliant equivalents of these keywords are always available in a form
37180  that begin with two underscores
37181 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37182
37183 \end_inset
37184
37185 , f.e.
37186  '__data' instead of 'data'.
37187 \end_layout
37188
37189 \begin_layout Itemize
37190 Integer promotion of variable arguments is not performed if the argument
37191  is explicitly taypecasted unless the
37192 \series bold
37193  -
37194 \begin_inset ERT
37195 status collapsed
37196
37197 \begin_layout Standard
37198
37199
37200 \backslash
37201 /
37202 \end_layout
37203
37204 \end_inset
37205
37206 -std-c89
37207 \begin_inset LatexCommand \index{-\/-std-c89}
37208
37209 \end_inset
37210
37211  
37212 \series default
37213 or
37214 \series bold
37215  -
37216 \begin_inset ERT
37217 status collapsed
37218
37219 \begin_layout Standard
37220
37221
37222 \backslash
37223 /
37224 \end_layout
37225
37226 \end_inset
37227
37228 -std-c99
37229 \begin_inset LatexCommand \index{-\/-std-c99}
37230
37231 \end_inset
37232
37233
37234 \series default
37235  command line options are used.
37236 \end_layout
37237
37238 \begin_deeper
37239 \begin_layout Verse
37240
37241 \family typewriter
37242 void vararg_func (char *str, ...) { str; }
37243 \newline
37244
37245 \newline
37246 void main (void)
37247 \newline
37248 {
37249 \newline
37250 \InsetSpace ~
37251 \InsetSpace ~
37252 char c = 10;
37253 \newline
37254
37255 \newline
37256 \InsetSpace ~
37257 \InsetSpace ~
37258 /* argument
37259  u is promoted to int before
37260 \newline
37261 \InsetSpace ~
37262 \InsetSpace ~
37263 \InsetSpace ~
37264 * passing to function */
37265 \newline
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 vararg_func ("%c", c);
37269 \newline
37270
37271 \newline
37272 \InsetSpace ~
37273 \InsetSpace ~
37274 /*
37275  argument u is not promoted to int,
37276 \newline
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 \InsetSpace ~
37280 * it is passed as char to function
37281 \newline
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 \InsetSpace ~
37285 * if
37286  --std-cXX is not defined;
37287 \newline
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 * is promoted to int before passing
37292 \newline
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 \InsetSpace ~
37296 * to function
37297  if --std-cXX is defined */
37298 \newline
37299 \InsetSpace ~
37300 \InsetSpace ~
37301 vararg_func ("%bc", (char)u);
37302 \newline
37303 }
37304 \end_layout
37305
37306 \end_deeper
37307 \begin_layout Section
37308 Cyclomatic Complexity
37309 \begin_inset LatexCommand \index{Cyclomatic complexity}
37310
37311 \end_inset
37312
37313
37314 \end_layout
37315
37316 \begin_layout Standard
37317 Cyclomatic complexity of a function is defined as the number of independent
37318  paths the program can take during execution of the function.
37319  This is an important number since it defines the number test cases you
37320  have to generate to validate the function.
37321  The accepted industry standard for complexity number is 10, if the cyclomatic
37322  complexity reported by SDCC exceeds 10 you should think about simplification
37323  of the function logic.
37324  Note that the complexity level is not related to the number of lines of
37325  code in a function.
37326  Large functions can have low complexity, and small functions can have large
37327  complexity levels.
37328  
37329 \newline
37330
37331 \newline
37332 SDCC uses the following formula to compute the complexity:
37333 \newline
37334
37335 \end_layout
37336
37337 \begin_layout Standard
37338 complexity = (number of edges in control flow graph) - (number of nodes
37339  in control flow graph) + 2;
37340 \newline
37341
37342 \newline
37343 Having said that the industry standard is 10,
37344  you should be aware that in some cases it be may unavoidable to have a
37345  complexity level of less than 10.
37346  For example if you have switch statement with more than 10 case labels,
37347  each case label adds one to the complexity level.
37348  The complexity level is by no means an absolute measure of the algorithmic
37349  complexity of the function, it does however provide a good starting point
37350  for which functions you might look at for further optimization.
37351 \end_layout
37352
37353 \begin_layout Section
37354 Retargetting for other Processors
37355 \end_layout
37356
37357 \begin_layout Standard
37358 The issues for retargetting the compiler are far too numerous to be covered
37359  by this document.
37360  What follows is a brief description of each of the seven phases of the
37361  compiler and its MCU dependency.
37362 \end_layout
37363
37364 \begin_layout Itemize
37365 Parsing the source and building the annotated parse tree.
37366  This phase is largely MCU independent (except for the language extensions).
37367  Syntax & semantic checks are also done in this phase, along with some initial
37368  optimizations like back patching labels and the pattern matching optimizations
37369  like bit-rotation etc.
37370 \end_layout
37371
37372 \begin_layout Itemize
37373 The second phase involves generating an intermediate code which can be easy
37374  manipulated during the later phases.
37375  This phase is entirely MCU independent.
37376  The intermediate code generation assumes the target machine has unlimited
37377  number of registers, and designates them with the name iTemp.
37378  The compiler can be made to dump a human readable form of the code generated
37379  by using the -
37380 \begin_inset ERT
37381 status collapsed
37382
37383 \begin_layout Standard
37384
37385
37386 \backslash
37387 /
37388 \end_layout
37389
37390 \end_inset
37391
37392 -dumpraw option.
37393 \end_layout
37394
37395 \begin_layout Itemize
37396 This phase does the bulk of the standard optimizations and is also MCU independe
37397 nt.
37398  This phase can be broken down into several sub-phases:
37399 \newline
37400
37401 \newline
37402 Break down intermediate
37403  code (iCode) into basic blocks.
37404 \newline
37405 Do control flow & data flow analysis on the
37406  basic blocks.
37407 \newline
37408 Do local common subexpression elimination, then global subexpressio
37409 n elimination
37410 \newline
37411 Dead code elimination
37412 \newline
37413 Loop optimizations
37414 \newline
37415 If loop optimizations
37416  caused any changes then do 'global subexpression elimination' and 'dead
37417  code elimination' again.
37418 \end_layout
37419
37420 \begin_layout Itemize
37421 This phase determines the live-ranges; by live range I mean those iTemp
37422  variables defined by the compiler that still survive after all the optimization
37423 s.
37424  Live range analysis
37425 \begin_inset LatexCommand \index{Live range analysis}
37426
37427 \end_inset
37428
37429  is essential for register allocation, since these computation determines
37430  which of these iTemps will be assigned to registers, and for how long.
37431 \end_layout
37432
37433 \begin_layout Itemize
37434 Phase five is register allocation.
37435  There are two parts to this process.
37436 \newline
37437
37438 \newline
37439 The first part I call 'register packing'
37440  (for lack of a better term).
37441  In this case several MCU specific expression folding is done to reduce
37442  register pressure.
37443 \newline
37444
37445 \newline
37446 The second part is more MCU independent and deals with
37447  allocating registers to the remaining live ranges.
37448  A lot of MCU specific code does creep into this phase because of the limited
37449  number of index registers available in the 8051.
37450 \end_layout
37451
37452 \begin_layout Itemize
37453 The Code generation phase is (unhappily), entirely MCU dependent and very
37454  little (if any at all) of this code can be reused for other MCU.
37455  However the scheme for allocating a homogenized assembler operand for each
37456  iCode operand may be reused.
37457 \end_layout
37458
37459 \begin_layout Itemize
37460 As mentioned in the optimization section the peep-hole optimizer is rule
37461  based system, which can reprogrammed for other MCUs.
37462 \end_layout
37463
37464 \begin_layout Standard
37465 More information is available on SDCC Wiki
37466 \begin_inset LatexCommand \index{wiki}
37467
37468 \end_inset
37469
37470  (preliminary link 
37471 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37472
37473 \end_inset
37474
37475 ) and in the thread 
37476 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37477
37478 \end_inset
37479
37480  .
37481 \end_layout
37482
37483 \begin_layout Chapter
37484 Compiler internals
37485 \begin_inset LatexCommand \index{Compiler internals}
37486
37487 \end_inset
37488
37489
37490 \end_layout
37491
37492 \begin_layout Section
37493 The anatomy of the compiler
37494 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37495
37496 \end_inset
37497
37498
37499 \end_layout
37500
37501 \begin_layout Standard
37502
37503 \shape italic
37504 This is an excerpt from an article published in Circuit Cellar Magazine
37505  in 
37506 \series bold
37507 August 2000
37508 \series default
37509 .
37510  It's a little outdated (the compiler is much more efficient now and user/develo
37511 per friendly), but pretty well exposes the guts of it all.
37512 \shape default
37513
37514 \newline
37515
37516 \newline
37517 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37518  It is fairly easy to retarget for other 8-bit MCU.
37519  Here we take a look at some of the internals of the compiler.
37520  
37521 \end_layout
37522
37523 \begin_layout Paragraph*
37524 Parsing
37525 \begin_inset LatexCommand \index{Parsing}
37526
37527 \end_inset
37528
37529  
37530 \end_layout
37531
37532 \begin_layout Standard
37533 Parsing the input source file and creating an AST (Annotated Syntax Tree
37534 \begin_inset LatexCommand \index{Annotated syntax tree}
37535
37536 \end_inset
37537
37538 ).
37539  This phase also involves propagating types (annotating each node of the
37540  parse tree with type information) and semantic analysis.
37541  There are some MCU specific parsing rules.
37542  For example the storage classes, the extended storage classes are MCU specific
37543  while there may be a xdata storage class for 8051 there is no such storage
37544  class for z80 or Atmel AVR.
37545  SDCC allows MCU specific storage class extensions, i.e.
37546  xdata will be treated as a storage class specifier when parsing 8051 C
37547  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37548  C code.
37549 \end_layout
37550
37551 \begin_layout Paragraph*
37552 Generating iCode
37553 \begin_inset LatexCommand \index{iCode}
37554
37555 \end_inset
37556
37557
37558 \end_layout
37559
37560 \begin_layout Standard
37561 Intermediate code generation.
37562  In this phase the AST is broken down into three-operand form (iCode).
37563  These three operand forms are represented as doubly linked lists.
37564  ICode is the term given to the intermediate form generated by the compiler.
37565  ICode example section shows some examples of iCode generated for some simple
37566  C source functions.
37567 \end_layout
37568
37569 \begin_layout Paragraph*
37570 Optimizations
37571 \begin_inset LatexCommand \index{Optimizations}
37572
37573 \end_inset
37574
37575 .
37576 \end_layout
37577
37578 \begin_layout Standard
37579 Bulk of the target independent optimizations is performed in this phase.
37580  The optimizations include constant propagation, common sub-expression eliminati
37581 on, loop invariant code movement, strength reduction of loop induction variables
37582  and dead-code elimination.
37583 \end_layout
37584
37585 \begin_layout Paragraph*
37586 Live range analysis
37587 \begin_inset LatexCommand \index{Live range analysis}
37588
37589 \end_inset
37590
37591
37592 \end_layout
37593
37594 \begin_layout Standard
37595 During intermediate code generation phase, the compiler assumes the target
37596  machine has infinite number of registers and generates a lot of temporary
37597  variables.
37598  The live range computation determines the lifetime of each of these compiler-ge
37599 nerated temporaries.
37600  A picture speaks a thousand words.
37601  ICode example sections show the live range annotations for each of the
37602  operand.
37603  It is important to note here, each iCode is assigned a number in the order
37604  of its execution in the function.
37605  The live ranges are computed in terms of these numbers.
37606  The from number is the number of the iCode which first defines the operand
37607  and the to number signifies the iCode which uses this operand last.
37608 \end_layout
37609
37610 \begin_layout Paragraph*
37611 Register Allocation
37612 \begin_inset LatexCommand \index{Register allocation}
37613
37614 \end_inset
37615
37616
37617 \end_layout
37618
37619 \begin_layout Standard
37620 The register allocation determines the type and number of registers needed
37621  by each operand.
37622  In most MCUs only a few registers can be used for indirect addressing.
37623  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37624  address the internal ram and DPTR to indirectly address the external ram.
37625  The compiler will try to allocate the appropriate register to pointer variables
37626  if it can.
37627  ICode example section shows the operands annotated with the registers assigned
37628  to them.
37629  The compiler will try to keep operands in registers as much as possible;
37630  there are several schemes the compiler uses to do achieve this.
37631  When the compiler runs out of registers the compiler will check to see
37632  if there are any live operands which is not used or defined in the current
37633  basic block being processed, if there are any found then it will push that
37634  operand and use the registers in this block, the operand will then be popped
37635  at the end of the basic block.
37636  
37637 \end_layout
37638
37639 \begin_layout Standard
37640 There are other MCU specific considerations in this phase.
37641  Some MCUs have an accumulator; very short-lived operands could be assigned
37642  to the accumulator instead of a general-purpose register.
37643 \end_layout
37644
37645 \begin_layout Paragraph*
37646 Code generation
37647 \end_layout
37648
37649 \begin_layout Standard
37650 Figure II gives a table of iCode
37651 \begin_inset LatexCommand \index{iCode}
37652
37653 \end_inset
37654
37655  operations supported by the compiler.
37656  The code generation involves translating these operations into corresponding
37657  assembly code for the processor.
37658  This sounds overly simple but that is the essence of code generation.
37659  Some of the iCode operations are generated on a MCU specific manner for
37660  example, the z80 port does not use registers to pass parameters so the
37661  SEND and RECV iCode operations will not be generated, and it also does
37662  not support JUMPTABLES.
37663  
37664 \newline
37665
37666 \end_layout
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 Figure II 
37672 \begin_inset Tabular
37673 <lyxtabular version="3" rows="39" columns="4">
37674 <features islongtable="true" headBottomDL="true">
37675 <column alignment="block" valignment="top" leftline="true" width="13col%">
37676 <column alignment="left" valignment="top" leftline="true" width="13col%">
37677 <column alignment="block" valignment="top" leftline="true" width="22col%">
37678 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37679 <row topline="true" bottomline="true" endhead="true">
37680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37681 \begin_inset Text
37682
37683 \begin_layout Standard
37684
37685 \series bold
37686 iCode
37687 \series default
37688
37689 \begin_inset LatexCommand \index{iCode}
37690
37691 \end_inset
37692
37693
37694 \end_layout
37695
37696 \end_inset
37697 </cell>
37698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37699 \begin_inset Text
37700
37701 \begin_layout Standard
37702
37703 \series bold
37704 Operands
37705 \end_layout
37706
37707 \end_inset
37708 </cell>
37709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37710 \begin_inset Text
37711
37712 \begin_layout Standard
37713
37714 \series bold
37715 Description
37716 \end_layout
37717
37718 \end_inset
37719 </cell>
37720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37721 \begin_inset Text
37722
37723 \begin_layout Standard
37724
37725 \series bold
37726 C Equivalent
37727 \end_layout
37728
37729 \end_inset
37730 </cell>
37731 </row>
37732 <row topline="true">
37733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37734 \begin_inset Text
37735
37736 \begin_layout Standard
37737
37738 \size footnotesize
37739 '!'
37740 \end_layout
37741
37742 \end_inset
37743 </cell>
37744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37745 \begin_inset Text
37746
37747 \begin_layout Standard
37748
37749 \size footnotesize
37750 IC_LEFT() IC_RESULT()
37751 \end_layout
37752
37753 \end_inset
37754 </cell>
37755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37756 \begin_inset Text
37757
37758 \begin_layout Standard
37759
37760 \size footnotesize
37761 NOT operation 
37762 \end_layout
37763
37764 \end_inset
37765 </cell>
37766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37767 \begin_inset Text
37768
37769 \begin_layout Standard
37770
37771 \size footnotesize
37772 IC_RESULT = ! IC_LEFT;
37773 \end_layout
37774
37775 \end_inset
37776 </cell>
37777 </row>
37778 <row topline="true">
37779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37780 \begin_inset Text
37781
37782 \begin_layout Standard
37783
37784 \size footnotesize
37785 '~'
37786 \end_layout
37787
37788 \end_inset
37789 </cell>
37790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37791 \begin_inset Text
37792
37793 \begin_layout Standard
37794
37795 \size footnotesize
37796 IC_LEFT() IC_RESULT()
37797 \end_layout
37798
37799 \end_inset
37800 </cell>
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37802 \begin_inset Text
37803
37804 \begin_layout Standard
37805
37806 \size footnotesize
37807 Bitwise complement of 
37808 \end_layout
37809
37810 \end_inset
37811 </cell>
37812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37813 \begin_inset Text
37814
37815 \begin_layout Standard
37816
37817 \size footnotesize
37818 IC_RESULT = ~IC_LEFT;
37819 \end_layout
37820
37821 \end_inset
37822 </cell>
37823 </row>
37824 <row topline="true">
37825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37826 \begin_inset Text
37827
37828 \begin_layout Standard
37829
37830 \size footnotesize
37831 RRC
37832 \end_layout
37833
37834 \end_inset
37835 </cell>
37836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37837 \begin_inset Text
37838
37839 \begin_layout Standard
37840
37841 \size footnotesize
37842 IC_LEFT() IC_RESULT()
37843 \end_layout
37844
37845 \end_inset
37846 </cell>
37847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37848 \begin_inset Text
37849
37850 \begin_layout Standard
37851
37852 \size footnotesize
37853 Rotate right with carry
37854 \end_layout
37855
37856 \end_inset
37857 </cell>
37858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37859 \begin_inset Text
37860
37861 \begin_layout Standard
37862
37863 \size footnotesize
37864 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37865 \end_layout
37866
37867 \end_inset
37868 </cell>
37869 </row>
37870 <row topline="true">
37871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37872 \begin_inset Text
37873
37874 \begin_layout Standard
37875
37876 \size footnotesize
37877 RLC
37878 \end_layout
37879
37880 \end_inset
37881 </cell>
37882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37883 \begin_inset Text
37884
37885 \begin_layout Standard
37886
37887 \size footnotesize
37888 IC_LEFT() IC_RESULT()
37889 \end_layout
37890
37891 \end_inset
37892 </cell>
37893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37894 \begin_inset Text
37895
37896 \begin_layout Standard
37897
37898 \size footnotesize
37899 Rotate left with carry
37900 \end_layout
37901
37902 \end_inset
37903 </cell>
37904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37905 \begin_inset Text
37906
37907 \begin_layout Standard
37908
37909 \size footnotesize
37910 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37911 \end_layout
37912
37913 \end_inset
37914 </cell>
37915 </row>
37916 <row topline="true">
37917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37918 \begin_inset Text
37919
37920 \begin_layout Standard
37921
37922 \size footnotesize
37923 GETHBIT
37924 \end_layout
37925
37926 \end_inset
37927 </cell>
37928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37929 \begin_inset Text
37930
37931 \begin_layout Standard
37932
37933 \size footnotesize
37934 IC_LEFT() IC_RESULT()
37935 \end_layout
37936
37937 \end_inset
37938 </cell>
37939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37940 \begin_inset Text
37941
37942 \begin_layout Standard
37943
37944 \size footnotesize
37945 Get the highest order bit of IC_LEFT
37946 \end_layout
37947
37948 \end_inset
37949 </cell>
37950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37951 \begin_inset Text
37952
37953 \begin_layout Standard
37954
37955 \size footnotesize
37956 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37957 \end_layout
37958
37959 \end_inset
37960 </cell>
37961 </row>
37962 <row topline="true">
37963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37964 \begin_inset Text
37965
37966 \begin_layout Standard
37967
37968 \size footnotesize
37969 UNARYMINUS
37970 \end_layout
37971
37972 \end_inset
37973 </cell>
37974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37975 \begin_inset Text
37976
37977 \begin_layout Standard
37978
37979 \size footnotesize
37980 IC_LEFT() IC_RESULT()
37981 \end_layout
37982
37983 \end_inset
37984 </cell>
37985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37986 \begin_inset Text
37987
37988 \begin_layout Standard
37989
37990 \size footnotesize
37991 Unary minus
37992 \end_layout
37993
37994 \end_inset
37995 </cell>
37996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37997 \begin_inset Text
37998
37999 \begin_layout Standard
38000
38001 \size footnotesize
38002 IC_RESULT = - IC_LEFT;
38003 \end_layout
38004
38005 \end_inset
38006 </cell>
38007 </row>
38008 <row topline="true">
38009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38010 \begin_inset Text
38011
38012 \begin_layout Standard
38013
38014 \size footnotesize
38015 IPUSH
38016 \end_layout
38017
38018 \end_inset
38019 </cell>
38020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38021 \begin_inset Text
38022
38023 \begin_layout Standard
38024
38025 \size footnotesize
38026 IC_LEFT()
38027 \end_layout
38028
38029 \end_inset
38030 </cell>
38031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38032 \begin_inset Text
38033
38034 \begin_layout Standard
38035
38036 \size footnotesize
38037 Push the operand into stack
38038 \end_layout
38039
38040 \end_inset
38041 </cell>
38042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38043 \begin_inset Text
38044
38045 \begin_layout Standard
38046
38047 \size footnotesize
38048 NONE
38049 \end_layout
38050
38051 \end_inset
38052 </cell>
38053 </row>
38054 <row topline="true">
38055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38056 \begin_inset Text
38057
38058 \begin_layout Standard
38059
38060 \size footnotesize
38061 IPOP
38062 \end_layout
38063
38064 \end_inset
38065 </cell>
38066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38067 \begin_inset Text
38068
38069 \begin_layout Standard
38070
38071 \size footnotesize
38072 IC_LEFT()
38073 \end_layout
38074
38075 \end_inset
38076 </cell>
38077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38078 \begin_inset Text
38079
38080 \begin_layout Standard
38081
38082 \size footnotesize
38083 Pop the operand from the stack 
38084 \end_layout
38085
38086 \end_inset
38087 </cell>
38088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38089 \begin_inset Text
38090
38091 \begin_layout Standard
38092
38093 \size footnotesize
38094 NONE
38095 \end_layout
38096
38097 \end_inset
38098 </cell>
38099 </row>
38100 <row topline="true">
38101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38102 \begin_inset Text
38103
38104 \begin_layout Standard
38105
38106 \size footnotesize
38107 CALL
38108 \end_layout
38109
38110 \end_inset
38111 </cell>
38112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38113 \begin_inset Text
38114
38115 \begin_layout Standard
38116
38117 \size footnotesize
38118 IC_LEFT() IC_RESULT()
38119 \end_layout
38120
38121 \end_inset
38122 </cell>
38123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38124 \begin_inset Text
38125
38126 \begin_layout Standard
38127
38128 \size footnotesize
38129 Call the function represented by IC_LEFT 
38130 \end_layout
38131
38132 \end_inset
38133 </cell>
38134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38135 \begin_inset Text
38136
38137 \begin_layout Standard
38138
38139 \size footnotesize
38140 IC_RESULT = IC_LEFT();
38141 \end_layout
38142
38143 \end_inset
38144 </cell>
38145 </row>
38146 <row topline="true">
38147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38148 \begin_inset Text
38149
38150 \begin_layout Standard
38151
38152 \size footnotesize
38153 PCALL
38154 \end_layout
38155
38156 \end_inset
38157 </cell>
38158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38159 \begin_inset Text
38160
38161 \begin_layout Standard
38162
38163 \size footnotesize
38164 IC_LEFT() IC_RESULT()
38165 \end_layout
38166
38167 \end_inset
38168 </cell>
38169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38170 \begin_inset Text
38171
38172 \begin_layout Standard
38173
38174 \size footnotesize
38175 Call via function pointer
38176 \end_layout
38177
38178 \end_inset
38179 </cell>
38180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38181 \begin_inset Text
38182
38183 \begin_layout Standard
38184
38185 \size footnotesize
38186 IC_RESULT = (*IC_LEFT)();
38187 \end_layout
38188
38189 \end_inset
38190 </cell>
38191 </row>
38192 <row topline="true">
38193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38194 \begin_inset Text
38195
38196 \begin_layout Standard
38197
38198 \size footnotesize
38199 RETURN
38200 \end_layout
38201
38202 \end_inset
38203 </cell>
38204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38205 \begin_inset Text
38206
38207 \begin_layout Standard
38208
38209 \size footnotesize
38210 IC_LEFT()
38211 \end_layout
38212
38213 \end_inset
38214 </cell>
38215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38216 \begin_inset Text
38217
38218 \begin_layout Standard
38219
38220 \size footnotesize
38221 Return the value in operand IC_LEFT 
38222 \end_layout
38223
38224 \end_inset
38225 </cell>
38226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38227 \begin_inset Text
38228
38229 \begin_layout Standard
38230
38231 \size footnotesize
38232 return IC_LEFT;
38233 \end_layout
38234
38235 \end_inset
38236 </cell>
38237 </row>
38238 <row topline="true">
38239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38240 \begin_inset Text
38241
38242 \begin_layout Standard
38243
38244 \size footnotesize
38245 LABEL
38246 \end_layout
38247
38248 \end_inset
38249 </cell>
38250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38251 \begin_inset Text
38252
38253 \begin_layout Standard
38254
38255 \size footnotesize
38256 IC_LABEL() 
38257 \end_layout
38258
38259 \end_inset
38260 </cell>
38261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38262 \begin_inset Text
38263
38264 \begin_layout Standard
38265
38266 \size footnotesize
38267 Label
38268 \end_layout
38269
38270 \end_inset
38271 </cell>
38272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38273 \begin_inset Text
38274
38275 \begin_layout Standard
38276
38277 \size footnotesize
38278 IC_LABEL:
38279 \end_layout
38280
38281 \end_inset
38282 </cell>
38283 </row>
38284 <row topline="true">
38285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38286 \begin_inset Text
38287
38288 \begin_layout Standard
38289
38290 \size footnotesize
38291 GOTO
38292 \end_layout
38293
38294 \end_inset
38295 </cell>
38296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38297 \begin_inset Text
38298
38299 \begin_layout Standard
38300
38301 \size footnotesize
38302 IC_LABEL() 
38303 \end_layout
38304
38305 \end_inset
38306 </cell>
38307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38308 \begin_inset Text
38309
38310 \begin_layout Standard
38311
38312 \size footnotesize
38313 Goto label
38314 \end_layout
38315
38316 \end_inset
38317 </cell>
38318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38319 \begin_inset Text
38320
38321 \begin_layout Standard
38322
38323 \size footnotesize
38324 goto IC_LABEL();
38325 \end_layout
38326
38327 \end_inset
38328 </cell>
38329 </row>
38330 <row topline="true">
38331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38332 \begin_inset Text
38333
38334 \begin_layout Standard
38335
38336 \size footnotesize
38337 '+'
38338 \end_layout
38339
38340 \end_inset
38341 </cell>
38342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38343 \begin_inset Text
38344
38345 \begin_layout Standard
38346
38347 \size footnotesize
38348 IC_LEFT() IC_RIGHT() IC_RESULT()
38349 \end_layout
38350
38351 \end_inset
38352 </cell>
38353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38354 \begin_inset Text
38355
38356 \begin_layout Standard
38357
38358 \size footnotesize
38359 Addition
38360 \end_layout
38361
38362 \end_inset
38363 </cell>
38364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38365 \begin_inset Text
38366
38367 \begin_layout Standard
38368
38369 \size footnotesize
38370 IC_RESULT = IC_LEFT + IC_RIGHT
38371 \end_layout
38372
38373 \end_inset
38374 </cell>
38375 </row>
38376 <row topline="true">
38377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38378 \begin_inset Text
38379
38380 \begin_layout Standard
38381
38382 \size footnotesize
38383 '-'
38384 \end_layout
38385
38386 \end_inset
38387 </cell>
38388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38389 \begin_inset Text
38390
38391 \begin_layout Standard
38392
38393 \size footnotesize
38394 IC_LEFT() IC_RIGHT() IC_RESULT()
38395 \end_layout
38396
38397 \end_inset
38398 </cell>
38399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38400 \begin_inset Text
38401
38402 \begin_layout Standard
38403
38404 \size footnotesize
38405 Subtraction
38406 \end_layout
38407
38408 \end_inset
38409 </cell>
38410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38411 \begin_inset Text
38412
38413 \begin_layout Standard
38414
38415 \size footnotesize
38416 IC_RESULT = IC_LEFT - IC_RIGHT 
38417 \end_layout
38418
38419 \end_inset
38420 </cell>
38421 </row>
38422 <row topline="true">
38423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38424 \begin_inset Text
38425
38426 \begin_layout Standard
38427
38428 \size footnotesize
38429 '*'
38430 \end_layout
38431
38432 \end_inset
38433 </cell>
38434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38435 \begin_inset Text
38436
38437 \begin_layout Standard
38438
38439 \size footnotesize
38440 IC_LEFT() IC_RIGHT() IC_RESULT()
38441 \end_layout
38442
38443 \end_inset
38444 </cell>
38445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38446 \begin_inset Text
38447
38448 \begin_layout Standard
38449
38450 \size footnotesize
38451 Multiplication 
38452 \end_layout
38453
38454 \end_inset
38455 </cell>
38456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38457 \begin_inset Text
38458
38459 \begin_layout Standard
38460
38461 \size footnotesize
38462 IC_RESULT = IC_LEFT * IC_RIGHT;
38463 \end_layout
38464
38465 \end_inset
38466 </cell>
38467 </row>
38468 <row topline="true">
38469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38470 \begin_inset Text
38471
38472 \begin_layout Standard
38473
38474 \size footnotesize
38475 '/'
38476 \end_layout
38477
38478 \end_inset
38479 </cell>
38480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38481 \begin_inset Text
38482
38483 \begin_layout Standard
38484
38485 \size footnotesize
38486 IC_LEFT() IC_RIGHT() IC_RESULT()
38487 \end_layout
38488
38489 \end_inset
38490 </cell>
38491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38492 \begin_inset Text
38493
38494 \begin_layout Standard
38495
38496 \size footnotesize
38497 Division
38498 \end_layout
38499
38500 \end_inset
38501 </cell>
38502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38503 \begin_inset Text
38504
38505 \begin_layout Standard
38506
38507 \size footnotesize
38508 IC_RESULT = IC_LEFT / IC_RIGHT;
38509 \end_layout
38510
38511 \end_inset
38512 </cell>
38513 </row>
38514 <row topline="true">
38515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38516 \begin_inset Text
38517
38518 \begin_layout Standard
38519
38520 \size footnotesize
38521 '%'
38522 \end_layout
38523
38524 \end_inset
38525 </cell>
38526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38527 \begin_inset Text
38528
38529 \begin_layout Standard
38530
38531 \size footnotesize
38532 IC_LEFT() IC_RIGHT() IC_RESULT()
38533 \end_layout
38534
38535 \end_inset
38536 </cell>
38537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38538 \begin_inset Text
38539
38540 \begin_layout Standard
38541
38542 \size footnotesize
38543 Modulus
38544 \end_layout
38545
38546 \end_inset
38547 </cell>
38548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38549 \begin_inset Text
38550
38551 \begin_layout Standard
38552
38553 \size footnotesize
38554 IC_RESULT = IC_LEFT % IC_RIGHT;
38555 \end_layout
38556
38557 \end_inset
38558 </cell>
38559 </row>
38560 <row topline="true">
38561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38562 \begin_inset Text
38563
38564 \begin_layout Standard
38565
38566 \size footnotesize
38567 '<'
38568 \end_layout
38569
38570 \end_inset
38571 </cell>
38572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38573 \begin_inset Text
38574
38575 \begin_layout Standard
38576
38577 \size footnotesize
38578 IC_LEFT() IC_RIGHT() IC_RESULT()
38579 \end_layout
38580
38581 \end_inset
38582 </cell>
38583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38584 \begin_inset Text
38585
38586 \begin_layout Standard
38587
38588 \size footnotesize
38589 Less than
38590 \end_layout
38591
38592 \end_inset
38593 </cell>
38594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38595 \begin_inset Text
38596
38597 \begin_layout Standard
38598
38599 \size footnotesize
38600 IC_RESULT = IC_LEFT < IC_RIGHT;
38601 \end_layout
38602
38603 \end_inset
38604 </cell>
38605 </row>
38606 <row topline="true">
38607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38608 \begin_inset Text
38609
38610 \begin_layout Standard
38611
38612 \size footnotesize
38613 '>'
38614 \end_layout
38615
38616 \end_inset
38617 </cell>
38618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38619 \begin_inset Text
38620
38621 \begin_layout Standard
38622
38623 \size footnotesize
38624 IC_LEFT() IC_RIGHT() IC_RESULT()
38625 \end_layout
38626
38627 \end_inset
38628 </cell>
38629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38630 \begin_inset Text
38631
38632 \begin_layout Standard
38633
38634 \size footnotesize
38635 Greater than 
38636 \end_layout
38637
38638 \end_inset
38639 </cell>
38640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38641 \begin_inset Text
38642
38643 \begin_layout Standard
38644
38645 \size footnotesize
38646 IC_RESULT = IC_LEFT > IC_RIGHT;
38647 \end_layout
38648
38649 \end_inset
38650 </cell>
38651 </row>
38652 <row topline="true">
38653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38654 \begin_inset Text
38655
38656 \begin_layout Standard
38657
38658 \size footnotesize
38659 EQ_OP
38660 \end_layout
38661
38662 \end_inset
38663 </cell>
38664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38665 \begin_inset Text
38666
38667 \begin_layout Standard
38668
38669 \size footnotesize
38670 IC_LEFT() IC_RIGHT() IC_RESULT()
38671 \end_layout
38672
38673 \end_inset
38674 </cell>
38675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38676 \begin_inset Text
38677
38678 \begin_layout Standard
38679
38680 \size footnotesize
38681 Equal to 
38682 \end_layout
38683
38684 \end_inset
38685 </cell>
38686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38687 \begin_inset Text
38688
38689 \begin_layout Standard
38690
38691 \size footnotesize
38692 IC_RESULT = IC_LEFT == IC_RIGHT;
38693 \end_layout
38694
38695 \end_inset
38696 </cell>
38697 </row>
38698 <row topline="true">
38699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38700 \begin_inset Text
38701
38702 \begin_layout Standard
38703
38704 \size footnotesize
38705 AND_OP
38706 \end_layout
38707
38708 \end_inset
38709 </cell>
38710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38711 \begin_inset Text
38712
38713 \begin_layout Standard
38714
38715 \size footnotesize
38716 IC_LEFT() IC_RIGHT() IC_RESULT() 
38717 \end_layout
38718
38719 \end_inset
38720 </cell>
38721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38722 \begin_inset Text
38723
38724 \begin_layout Standard
38725
38726 \size footnotesize
38727 Logical and operation
38728 \end_layout
38729
38730 \end_inset
38731 </cell>
38732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38733 \begin_inset Text
38734
38735 \begin_layout Standard
38736
38737 \size footnotesize
38738 IC_RESULT = IC_LEFT && IC_RIGHT; 
38739 \end_layout
38740
38741 \end_inset
38742 </cell>
38743 </row>
38744 <row topline="true">
38745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38746 \begin_inset Text
38747
38748 \begin_layout Standard
38749
38750 \size footnotesize
38751 OR_OP
38752 \end_layout
38753
38754 \end_inset
38755 </cell>
38756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38757 \begin_inset Text
38758
38759 \begin_layout Standard
38760
38761 \size footnotesize
38762 IC_LEFT() IC_RIGHT() IC_RESULT() 
38763 \end_layout
38764
38765 \end_inset
38766 </cell>
38767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38768 \begin_inset Text
38769
38770 \begin_layout Standard
38771
38772 \size footnotesize
38773 Logical or operation 
38774 \end_layout
38775
38776 \end_inset
38777 </cell>
38778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38779 \begin_inset Text
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 IC_RESULT = IC_LEFT || IC_RIGHT; 
38785 \end_layout
38786
38787 \end_inset
38788 </cell>
38789 </row>
38790 <row topline="true">
38791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38792 \begin_inset Text
38793
38794 \begin_layout Standard
38795
38796 \size footnotesize
38797 '^'
38798 \end_layout
38799
38800 \end_inset
38801 </cell>
38802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38803 \begin_inset Text
38804
38805 \begin_layout Standard
38806
38807 \size footnotesize
38808 IC_LEFT() IC_RIGHT() IC_RESULT() 
38809 \end_layout
38810
38811 \end_inset
38812 </cell>
38813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38814 \begin_inset Text
38815
38816 \begin_layout Standard
38817
38818 \size footnotesize
38819 Exclusive OR
38820 \end_layout
38821
38822 \end_inset
38823 </cell>
38824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38825 \begin_inset Text
38826
38827 \begin_layout Standard
38828
38829 \size footnotesize
38830 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38831 \end_layout
38832
38833 \end_inset
38834 </cell>
38835 </row>
38836 <row topline="true">
38837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38838 \begin_inset Text
38839
38840 \begin_layout Standard
38841
38842 \size footnotesize
38843 '|'
38844 \end_layout
38845
38846 \end_inset
38847 </cell>
38848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38849 \begin_inset Text
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 IC_LEFT() IC_RIGHT() IC_RESULT() 
38855 \end_layout
38856
38857 \end_inset
38858 </cell>
38859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38860 \begin_inset Text
38861
38862 \begin_layout Standard
38863
38864 \size footnotesize
38865 Bitwise OR 
38866 \end_layout
38867
38868 \end_inset
38869 </cell>
38870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38871 \begin_inset Text
38872
38873 \begin_layout Standard
38874
38875 \size footnotesize
38876 IC_RESULT = IC_LEFT | IC_RIGHT;
38877 \end_layout
38878
38879 \end_inset
38880 </cell>
38881 </row>
38882 <row topline="true">
38883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38884 \begin_inset Text
38885
38886 \begin_layout Standard
38887
38888 \size footnotesize
38889 BITWISEAND
38890 \end_layout
38891
38892 \end_inset
38893 </cell>
38894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38895 \begin_inset Text
38896
38897 \begin_layout Standard
38898
38899 \size footnotesize
38900 IC_LEFT() IC_RIGHT() IC_RESULT()
38901 \end_layout
38902
38903 \end_inset
38904 </cell>
38905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38906 \begin_inset Text
38907
38908 \begin_layout Standard
38909
38910 \size footnotesize
38911 Bitwise AND 
38912 \end_layout
38913
38914 \end_inset
38915 </cell>
38916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38917 \begin_inset Text
38918
38919 \begin_layout Standard
38920
38921 \size footnotesize
38922 IC_RESULT = IC_LEFT & IC_RIGHT;
38923 \end_layout
38924
38925 \end_inset
38926 </cell>
38927 </row>
38928 <row topline="true">
38929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38930 \begin_inset Text
38931
38932 \begin_layout Standard
38933
38934 \size footnotesize
38935 LEFT_OP
38936 \end_layout
38937
38938 \end_inset
38939 </cell>
38940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38941 \begin_inset Text
38942
38943 \begin_layout Standard
38944
38945 \size footnotesize
38946 IC_LEFT() IC_RIGHT() IC_RESULT()
38947 \end_layout
38948
38949 \end_inset
38950 </cell>
38951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38952 \begin_inset Text
38953
38954 \begin_layout Standard
38955
38956 \size footnotesize
38957 Left shift 
38958 \end_layout
38959
38960 \end_inset
38961 </cell>
38962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38963 \begin_inset Text
38964
38965 \begin_layout Standard
38966
38967 \size footnotesize
38968 IC_RESULT = IC_LEFT << IC_RIGHT 
38969 \end_layout
38970
38971 \end_inset
38972 </cell>
38973 </row>
38974 <row topline="true">
38975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38976 \begin_inset Text
38977
38978 \begin_layout Standard
38979
38980 \size footnotesize
38981 RIGHT_OP
38982 \end_layout
38983
38984 \end_inset
38985 </cell>
38986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38987 \begin_inset Text
38988
38989 \begin_layout Standard
38990
38991 \size footnotesize
38992 IC_LEFT() IC_RIGHT() IC_RESULT()
38993 \end_layout
38994
38995 \end_inset
38996 </cell>
38997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38998 \begin_inset Text
38999
39000 \begin_layout Standard
39001
39002 \size footnotesize
39003 Right shift
39004 \end_layout
39005
39006 \end_inset
39007 </cell>
39008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39009 \begin_inset Text
39010
39011 \begin_layout Standard
39012
39013 \size footnotesize
39014 IC_RESULT = IC_LEFT >> IC_RIGHT 
39015 \end_layout
39016
39017 \end_inset
39018 </cell>
39019 </row>
39020 <row topline="true">
39021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39022 \begin_inset Text
39023
39024 \begin_layout Standard
39025
39026 \size footnotesize
39027 GET_VALUE_
39028 \newline
39029 AT_ ADDRESS
39030 \end_layout
39031
39032 \end_inset
39033 </cell>
39034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39035 \begin_inset Text
39036
39037 \begin_layout Standard
39038
39039 \size footnotesize
39040 IC_LEFT() IC_RESULT()
39041 \end_layout
39042
39043 \end_inset
39044 </cell>
39045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39046 \begin_inset Text
39047
39048 \begin_layout Standard
39049
39050 \size footnotesize
39051 Indirect fetch 
39052 \end_layout
39053
39054 \end_inset
39055 </cell>
39056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39057 \begin_inset Text
39058
39059 \begin_layout Standard
39060
39061 \size footnotesize
39062 IC_RESULT = (*IC_LEFT);
39063 \end_layout
39064
39065 \end_inset
39066 </cell>
39067 </row>
39068 <row topline="true">
39069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39070 \begin_inset Text
39071
39072 \begin_layout Standard
39073
39074 \size footnotesize
39075 POINTER_SET
39076 \end_layout
39077
39078 \end_inset
39079 </cell>
39080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39081 \begin_inset Text
39082
39083 \begin_layout Standard
39084
39085 \size footnotesize
39086 IC_RIGHT() IC_RESULT() 
39087 \end_layout
39088
39089 \end_inset
39090 </cell>
39091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39092 \begin_inset Text
39093
39094 \begin_layout Standard
39095
39096 \size footnotesize
39097 Indirect set
39098 \end_layout
39099
39100 \end_inset
39101 </cell>
39102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39103 \begin_inset Text
39104
39105 \begin_layout Standard
39106
39107 \size footnotesize
39108 (*IC_RESULT) = IC_RIGHT;
39109 \end_layout
39110
39111 \end_inset
39112 </cell>
39113 </row>
39114 <row topline="true">
39115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39116 \begin_inset Text
39117
39118 \begin_layout Standard
39119
39120 \size footnotesize
39121 '='
39122 \end_layout
39123
39124 \end_inset
39125 </cell>
39126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39127 \begin_inset Text
39128
39129 \begin_layout Standard
39130
39131 \size footnotesize
39132 IC_RIGHT() IC_RESULT()
39133 \end_layout
39134
39135 \end_inset
39136 </cell>
39137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39138 \begin_inset Text
39139
39140 \begin_layout Standard
39141
39142 \size footnotesize
39143 Assignment
39144 \end_layout
39145
39146 \end_inset
39147 </cell>
39148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39149 \begin_inset Text
39150
39151 \begin_layout Standard
39152
39153 \size footnotesize
39154 IC_RESULT = IC_RIGHT;
39155 \end_layout
39156
39157 \end_inset
39158 </cell>
39159 </row>
39160 <row topline="true">
39161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39162 \begin_inset Text
39163
39164 \begin_layout Standard
39165
39166 \size footnotesize
39167 IFX
39168 \end_layout
39169
39170 \end_inset
39171 </cell>
39172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39173 \begin_inset Text
39174
39175 \begin_layout Standard
39176
39177 \size footnotesize
39178 IC_COND IC_TRUE IC_LABEL
39179 \end_layout
39180
39181 \end_inset
39182 </cell>
39183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39184 \begin_inset Text
39185
39186 \begin_layout Standard
39187
39188 \size footnotesize
39189 Conditional jump.
39190  If true label is present then jump to true label if condition is true else
39191  jump to false label if condition is false 
39192 \end_layout
39193
39194 \end_inset
39195 </cell>
39196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39197 \begin_inset Text
39198
39199 \begin_layout Standard
39200
39201 \size footnotesize
39202 if (IC_COND) goto IC_TRUE; 
39203 \newline
39204 \InsetSpace ~
39205 \InsetSpace ~
39206 Or 
39207 \newline
39208 If (!IC_COND) goto IC_FALSE;
39209 \end_layout
39210
39211 \end_inset
39212 </cell>
39213 </row>
39214 <row topline="true">
39215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39216 \begin_inset Text
39217
39218 \begin_layout Standard
39219
39220 \size footnotesize
39221 ADDRESS_OF
39222 \end_layout
39223
39224 \end_inset
39225 </cell>
39226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39227 \begin_inset Text
39228
39229 \begin_layout Standard
39230
39231 \size footnotesize
39232 IC_LEFT() IC_RESULT()
39233 \end_layout
39234
39235 \end_inset
39236 </cell>
39237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39238 \begin_inset Text
39239
39240 \begin_layout Standard
39241
39242 \size footnotesize
39243 Address of 
39244 \end_layout
39245
39246 \end_inset
39247 </cell>
39248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39249 \begin_inset Text
39250
39251 \begin_layout Standard
39252
39253 \size footnotesize
39254 IC_RESULT = &IC_LEFT();
39255 \end_layout
39256
39257 \end_inset
39258 </cell>
39259 </row>
39260 <row topline="true">
39261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39262 \begin_inset Text
39263
39264 \begin_layout Standard
39265
39266 \size footnotesize
39267 JUMPTABLE
39268 \end_layout
39269
39270 \end_inset
39271 </cell>
39272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39273 \begin_inset Text
39274
39275 \begin_layout Standard
39276
39277 \size footnotesize
39278 IC_JTCOND IC_JTLABELS
39279 \end_layout
39280
39281 \end_inset
39282 </cell>
39283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39284 \begin_inset Text
39285
39286 \begin_layout Standard
39287
39288 \size footnotesize
39289 Jump to list of labels depending on the value of JTCOND
39290 \end_layout
39291
39292 \end_inset
39293 </cell>
39294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39295 \begin_inset Text
39296
39297 \begin_layout Standard
39298
39299 \size footnotesize
39300 Switch statement
39301 \end_layout
39302
39303 \end_inset
39304 </cell>
39305 </row>
39306 <row topline="true">
39307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39308 \begin_inset Text
39309
39310 \begin_layout Standard
39311
39312 \size footnotesize
39313 CAST
39314 \end_layout
39315
39316 \end_inset
39317 </cell>
39318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39319 \begin_inset Text
39320
39321 \begin_layout Standard
39322
39323 \size footnotesize
39324 IC_RIGHT() IC_LEFT() IC_RESULT()
39325 \end_layout
39326
39327 \end_inset
39328 </cell>
39329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39330 \begin_inset Text
39331
39332 \begin_layout Standard
39333
39334 \size footnotesize
39335 Cast types 
39336 \end_layout
39337
39338 \end_inset
39339 </cell>
39340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39341 \begin_inset Text
39342
39343 \begin_layout Standard
39344
39345 \size footnotesize
39346 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39347 \end_layout
39348
39349 \end_inset
39350 </cell>
39351 </row>
39352 <row topline="true">
39353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39354 \begin_inset Text
39355
39356 \begin_layout Standard
39357
39358 \size footnotesize
39359 SEND
39360 \end_layout
39361
39362 \end_inset
39363 </cell>
39364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39365 \begin_inset Text
39366
39367 \begin_layout Standard
39368
39369 \size footnotesize
39370 IC_LEFT()
39371 \end_layout
39372
39373 \end_inset
39374 </cell>
39375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39376 \begin_inset Text
39377
39378 \begin_layout Standard
39379
39380 \size footnotesize
39381 This is used for passing parameters in registers; 
39382 \newline
39383 move IC_LEFT to the next
39384  available parameter register.
39385 \end_layout
39386
39387 \end_inset
39388 </cell>
39389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39390 \begin_inset Text
39391
39392 \begin_layout Standard
39393
39394 \size footnotesize
39395 None
39396 \end_layout
39397
39398 \end_inset
39399 </cell>
39400 </row>
39401 <row topline="true">
39402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39403 \begin_inset Text
39404
39405 \begin_layout Standard
39406
39407 \size footnotesize
39408 RECV
39409 \end_layout
39410
39411 \end_inset
39412 </cell>
39413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39414 \begin_inset Text
39415
39416 \begin_layout Standard
39417
39418 \size footnotesize
39419 IC_RESULT()
39420 \end_layout
39421
39422 \end_inset
39423 </cell>
39424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39425 \begin_inset Text
39426
39427 \begin_layout Standard
39428
39429 \size footnotesize
39430 This is used for receiving parameters passed in registers;
39431 \newline
39432 Move the values
39433  in the next parameter register to IC_RESULT 
39434 \end_layout
39435
39436 \end_inset
39437 </cell>
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39439 \begin_inset Text
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 None
39445 \end_layout
39446
39447 \end_inset
39448 </cell>
39449 </row>
39450 <row topline="true" bottomline="true">
39451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39452 \begin_inset Text
39453
39454 \begin_layout Standard
39455
39456 \shape slanted
39457 \size footnotesize
39458 (some more have been added)
39459 \end_layout
39460
39461 \end_inset
39462 </cell>
39463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39464 \begin_inset Text
39465
39466 \begin_layout Standard
39467
39468 \end_layout
39469
39470 \end_inset
39471 </cell>
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39473 \begin_inset Text
39474
39475 \begin_layout Standard
39476
39477 \end_layout
39478
39479 \end_inset
39480 </cell>
39481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39482 \begin_inset Text
39483
39484 \begin_layout Standard
39485
39486 \shape slanted
39487 \size footnotesize
39488 see f.e.
39489  
39490 \family typewriter
39491 gen51Code()
39492 \family default
39493  in 
39494 \family typewriter
39495 src/mcs51/gen.c
39496 \end_layout
39497
39498 \end_inset
39499 </cell>
39500 </row>
39501 </lyxtabular>
39502
39503 \end_inset
39504
39505
39506 \end_layout
39507
39508 \begin_layout Standard
39509 \begin_inset Note Note
39510 status collapsed
39511
39512 \begin_layout Standard
39513 In the original article Figure II was announced to be downloadable on 
39514 \shape italic
39515 Circuit Cellar
39516 \shape default
39517 's web site.
39518  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39519 \end_layout
39520
39521 \end_inset
39522
39523
39524 \end_layout
39525
39526 \begin_layout Paragraph*
39527 ICode Example
39528 \begin_inset LatexCommand \index{iCode}
39529
39530 \end_inset
39531
39532
39533 \end_layout
39534
39535 \begin_layout Standard
39536 This section shows some details of iCode.
39537  The example C code does not do anything useful; it is used as an example
39538  to illustrate the intermediate code generated by the compiler.
39539 \end_layout
39540
39541 \begin_layout Verse
39542
39543 \family typewriter
39544 1.\InsetSpace ~
39545 xdata int * p;
39546 \newline
39547 2.\InsetSpace ~
39548 int gint;
39549 \newline
39550 3.\InsetSpace ~
39551 /* This function does nothing useful.
39552  It is used
39553 \newline
39554 4.\InsetSpace ~
39555 \InsetSpace ~
39556 \InsetSpace ~
39557 \InsetSpace ~
39558 for the purpose of explaining iCode */
39559 \newline
39560 5.\InsetSpace ~
39561 short function (data
39562  int *x)
39563 \newline
39564 6.\InsetSpace ~
39565 {
39566 \newline
39567 7.\InsetSpace ~
39568 \InsetSpace ~
39569 \InsetSpace ~
39570 short i=10; \InsetSpace ~
39571 \InsetSpace ~
39572 /* dead initialization eliminated */
39573 \newline
39574 8.\InsetSpace ~
39575 \InsetSpace ~
39576 \InsetSpace ~
39577 short sum=10;
39578  /* dead initialization eliminated */
39579 \newline
39580 9.\InsetSpace ~
39581 \InsetSpace ~
39582 \InsetSpace ~
39583 short mul;
39584 \newline
39585 10.\InsetSpace ~
39586 \InsetSpace ~
39587 int j ;
39588 \newline
39589 11.\InsetSpace ~
39590 \InsetSpace ~
39591 while (*x) *x++
39592  = *p++; 
39593 \newline
39594 12.\InsetSpace ~
39595 \InsetSpace ~
39596 \InsetSpace ~
39597 \InsetSpace ~
39598 sum = 0 ; 
39599 \newline
39600 13.\InsetSpace ~
39601 \InsetSpace ~
39602 mul = 0;
39603 \newline
39604 14.\InsetSpace ~
39605 \InsetSpace ~
39606 /* compiler detects i,j to be induction
39607  variables */
39608 \newline
39609 15.\InsetSpace ~
39610 \InsetSpace ~
39611 for (i = 0, j = 10 ; i < 10 ; i++, j
39612 \family default
39613 -
39614 \begin_inset ERT
39615 status collapsed
39616
39617 \begin_layout Standard
39618
39619
39620 \backslash
39621 /
39622 \end_layout
39623
39624 \end_inset
39625
39626 -
39627 \family typewriter
39628 ) {
39629 \newline
39630 16.\InsetSpace ~
39631 \InsetSpace ~
39632 \InsetSpace ~
39633 \InsetSpace ~
39634 sum += i;
39635 \newline
39636 17.\InsetSpace ~
39637 \InsetSpace ~
39638 \InsetSpace ~
39639 \InsetSpace ~
39640 mul += i * 3; \InsetSpace ~
39641 \InsetSpace ~
39642 /* this multiplication remains */
39643 \newline
39644 18.\InsetSpace ~
39645 \InsetSpace ~
39646 \InsetSpace ~
39647 \InsetSpace ~
39648 gint +=
39649  j * 3;\InsetSpace ~
39650 \InsetSpace ~
39651 /* this multiplication changed to addition */
39652 \newline
39653 19.\InsetSpace ~
39654 \InsetSpace ~
39655 }
39656 \newline
39657 20.\InsetSpace ~
39658 \InsetSpace ~
39659 return sum+mul;
39660 \newline
39661 21.\InsetSpace ~
39662 }
39663 \end_layout
39664
39665 \begin_layout Standard
39666 In addition to the operands each iCode contains information about the filename
39667  and line it corresponds to in the source file.
39668  The first field in the listing should be interpreted as follows:
39669 \newline
39670
39671 \shape italic
39672 \size footnotesize
39673 Filename(linenumber: iCode Execution sequence number : ICode hash table
39674  key : loop depth of the iCode).
39675 \shape default
39676 \size default
39677
39678 \newline
39679 Then follows the human readable form of the ICode operation.
39680  Each operand of this triplet form can be of three basic types a) compiler
39681  generated temporary b) user defined variable c) a constant value.
39682  Note that local variables and parameters are replaced by compiler generated
39683  temporaries.
39684  Live ranges
39685 \begin_inset LatexCommand \index{Live range analysis}
39686
39687 \end_inset
39688
39689  are computed only for temporaries (i.e.
39690  live ranges are not computed for global variables).
39691  Registers
39692 \begin_inset LatexCommand \index{Register allocation}
39693
39694 \end_inset
39695
39696  are allocated for temporaries only.
39697  Operands are formatted in the following manner:
39698 \newline
39699
39700 \shape italic
39701 \size footnotesize
39702 Operand Name [lr live-from : live-to ] { type information } [ registers
39703  allocated ].
39704 \shape default
39705 \size default
39706
39707 \newline
39708 As mentioned earlier the live ranges are computed in terms of the execution
39709  sequence number of the iCodes, for example 
39710 \newline
39711 the iTemp0 is live from (i.e.
39712  first defined in iCode with execution sequence number 3, and is last used
39713  in the iCode with sequence number 5).
39714  For induction variables such as iTemp21 the live range computation extends
39715  the lifetime from the start to the end of the loop.
39716 \newline
39717 The register allocator
39718  used the live range information to allocate registers, the same registers
39719  may be used for different temporaries if their live ranges do not overlap,
39720  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39721  ranges do not overlap.
39722  In addition the allocator also takes into consideration the type and usage
39723  of a temporary, for example itemp6 is a pointer to near space and is used
39724  as to fetch data from (i.e.
39725  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39726  Some short lived temporaries are allocated to special registers which have
39727  meaning to the code generator e.g.
39728  iTemp13 is allocated to a pseudo register CC which tells the back end that
39729  the temporary is used only for a conditional jump the code generation makes
39730  use of this information to optimize a compare and jump ICode.
39731 \newline
39732 There are several
39733  loop optimizations
39734 \begin_inset LatexCommand \index{Loop optimization}
39735
39736 \end_inset
39737
39738  performed by the compiler.
39739  It can detect induction variables iTemp21(i) and iTemp23(j).
39740  Also note the compiler does selective strength reduction
39741 \begin_inset LatexCommand \index{Strength reduction}
39742
39743 \end_inset
39744
39745 , i.e.
39746  the multiplication of an induction variable in line 18 (gint = j * 3) is
39747  changed to addition, a new temporary iTemp17 is allocated and assigned
39748  a initial value, a constant 3 is then added for each iteration of the loop.
39749  The compiler does not change the multiplication
39750 \begin_inset LatexCommand \index{Multiplication}
39751
39752 \end_inset
39753
39754  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39755 \newline
39756
39757 Note the dead code elimination
39758 \begin_inset LatexCommand \index{Dead-code elimination}
39759
39760 \end_inset
39761
39762  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39763  respectively.
39764 \newline
39765
39766 \end_layout
39767
39768 \begin_layout Standard
39769
39770 \size footnotesize
39771 Sample.c (5:1:0:0) _entry($9) :
39772 \end_layout
39773
39774 \begin_layout Standard
39775
39776 \size footnotesize
39777 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39778 \end_layout
39779
39780 \begin_layout Standard
39781
39782 \size footnotesize
39783 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39784 \end_layout
39785
39786 \begin_layout Standard
39787
39788 \size footnotesize
39789 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39790 \end_layout
39791
39792 \begin_layout Standard
39793
39794 \size footnotesize
39795 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39796  * int}[r2]
39797 \end_layout
39798
39799 \begin_layout Standard
39800
39801 \size footnotesize
39802 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39803 \end_layout
39804
39805 \begin_layout Standard
39806
39807 \size footnotesize
39808 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39809  int}[r0]]
39810 \end_layout
39811
39812 \begin_layout Standard
39813
39814 \size footnotesize
39815 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39816 \end_layout
39817
39818 \begin_layout Standard
39819
39820 \size footnotesize
39821 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39822  * int}
39823 \end_layout
39824
39825 \begin_layout Standard
39826
39827 \size footnotesize
39828 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39829  {short}
39830 \end_layout
39831
39832 \begin_layout Standard
39833
39834 \size footnotesize
39835 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39836  * int}[DPTR]]
39837 \end_layout
39838
39839 \begin_layout Standard
39840
39841 \size footnotesize
39842 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39843 }[r2 r3]
39844 \end_layout
39845
39846 \begin_layout Standard
39847
39848 \size footnotesize
39849 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39850  * int}[r0] + 0x2 {short}
39851 \end_layout
39852
39853 \begin_layout Standard
39854
39855 \size footnotesize
39856 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39857 \end_layout
39858
39859 \begin_layout Standard
39860
39861 \size footnotesize
39862 Sample.c(11:17:21:0)_whilebreak_0($3) :
39863 \end_layout
39864
39865 \begin_layout Standard
39866
39867 \size footnotesize
39868 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39869 \end_layout
39870
39871 \begin_layout Standard
39872
39873 \size footnotesize
39874 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39875 \end_layout
39876
39877 \begin_layout Standard
39878
39879 \size footnotesize
39880 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39881 \end_layout
39882
39883 \begin_layout Standard
39884
39885 \size footnotesize
39886 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39887 \end_layout
39888
39889 \begin_layout Standard
39890
39891 \size footnotesize
39892 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39893 \end_layout
39894
39895 \begin_layout Standard
39896
39897 \size footnotesize
39898 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39899 \end_layout
39900
39901 \begin_layout Standard
39902
39903 \size footnotesize
39904 Sample.c(15:24:26:1)_forcond_0($4) :
39905 \end_layout
39906
39907 \begin_layout Standard
39908
39909 \size footnotesize
39910 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39911  < 0xa {short}
39912 \end_layout
39913
39914 \begin_layout Standard
39915
39916 \size footnotesize
39917 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39918 \end_layout
39919
39920 \begin_layout Standard
39921
39922 \size footnotesize
39923 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39924  + ITemp21 [lr21:38]{short}[r4]
39925 \end_layout
39926
39927 \begin_layout Standard
39928
39929 \size footnotesize
39930 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39931  * 0x3 {short}
39932 \end_layout
39933
39934 \begin_layout Standard
39935
39936 \size footnotesize
39937 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39938  + iTemp15 [lr29:30]{short}[r1]
39939 \end_layout
39940
39941 \begin_layout Standard
39942
39943 \size footnotesize
39944 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39945  r0]- 0x3 {short}
39946 \end_layout
39947
39948 \begin_layout Standard
39949
39950 \size footnotesize
39951 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39952 int}[r7 r0]
39953 \end_layout
39954
39955 \begin_layout Standard
39956
39957 \size footnotesize
39958 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39959  + 0x1 {short}
39960 \end_layout
39961
39962 \begin_layout Standard
39963
39964 \size footnotesize
39965 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39966  r6]- 0x1 {short}
39967 \end_layout
39968
39969 \begin_layout Standard
39970
39971 \size footnotesize
39972 Sample.c(19:38:47:1) goto _forcond_0($4)
39973 \end_layout
39974
39975 \begin_layout Standard
39976
39977 \size footnotesize
39978 Sample.c(19:39:48:0)_forbreak_0($7) :
39979 \end_layout
39980
39981 \begin_layout Standard
39982
39983 \size footnotesize
39984 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39985  + ITemp11 [lr19:40]{short}[r3]
39986 \end_layout
39987
39988 \begin_layout Standard
39989
39990 \size footnotesize
39991 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39992 \end_layout
39993
39994 \begin_layout Standard
39995
39996 \size footnotesize
39997 Sample.c(20:42:51:0)_return($8) :
39998 \end_layout
39999
40000 \begin_layout Standard
40001
40002 \size footnotesize
40003 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40004 \size default
40005
40006 \newline
40007
40008 \newline
40009 Finally the code generated for this function:
40010 \newline
40011
40012 \end_layout
40013
40014 \begin_layout Standard
40015
40016 \size footnotesize
40017 .area DSEG (DATA)
40018 \end_layout
40019
40020 \begin_layout Standard
40021
40022 \size footnotesize
40023 _p::
40024 \end_layout
40025
40026 \begin_layout Standard
40027
40028 \size footnotesize
40029 \InsetSpace ~
40030 \InsetSpace ~
40031 .ds 2
40032 \end_layout
40033
40034 \begin_layout Standard
40035
40036 \size footnotesize
40037 _gint::
40038 \end_layout
40039
40040 \begin_layout Standard
40041
40042 \size footnotesize
40043 \InsetSpace ~
40044 \InsetSpace ~
40045 .ds 2
40046 \end_layout
40047
40048 \begin_layout Standard
40049
40050 \size footnotesize
40051 ; sample.c 5
40052 \end_layout
40053
40054 \begin_layout Standard
40055
40056 \size footnotesize
40057 ; ----------------------------------------------
40058 \end_layout
40059
40060 \begin_layout Standard
40061
40062 \size footnotesize
40063 ; function function
40064 \end_layout
40065
40066 \begin_layout Standard
40067
40068 \size footnotesize
40069 ; ----------------------------------------------
40070 \end_layout
40071
40072 \begin_layout Standard
40073
40074 \size footnotesize
40075 _function:
40076 \end_layout
40077
40078 \begin_layout Standard
40079
40080 \size footnotesize
40081 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40082 \end_layout
40083
40084 \begin_layout Standard
40085
40086 \size footnotesize
40087 \InsetSpace ~
40088 \InsetSpace ~
40089 mov r2,dpl
40090 \end_layout
40091
40092 \begin_layout Standard
40093
40094 \size footnotesize
40095 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40096 \end_layout
40097
40098 \begin_layout Standard
40099
40100 \size footnotesize
40101 \InsetSpace ~
40102 \InsetSpace ~
40103 mov ar0,r2
40104 \end_layout
40105
40106 \begin_layout Standard
40107
40108 \size footnotesize
40109 ;_whilecontinue_0($1) :
40110 \end_layout
40111
40112 \begin_layout Standard
40113
40114 \size footnotesize
40115 00101$:
40116 \end_layout
40117
40118 \begin_layout Standard
40119
40120 \size footnotesize
40121 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40122 \end_layout
40123
40124 \begin_layout Standard
40125
40126 \size footnotesize
40127 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40128 \end_layout
40129
40130 \begin_layout Standard
40131
40132 \size footnotesize
40133 \InsetSpace ~
40134 \InsetSpace ~
40135 mov ar2,@r0
40136 \end_layout
40137
40138 \begin_layout Standard
40139
40140 \size footnotesize
40141 \InsetSpace ~
40142 \InsetSpace ~
40143 inc r0
40144 \end_layout
40145
40146 \begin_layout Standard
40147
40148 \size footnotesize
40149 \InsetSpace ~
40150 \InsetSpace ~
40151 mov ar3,@r0
40152 \end_layout
40153
40154 \begin_layout Standard
40155
40156 \size footnotesize
40157 \InsetSpace ~
40158 \InsetSpace ~
40159 dec r0
40160 \end_layout
40161
40162 \begin_layout Standard
40163
40164 \size footnotesize
40165 \InsetSpace ~
40166 \InsetSpace ~
40167 mov a,r2
40168 \end_layout
40169
40170 \begin_layout Standard
40171
40172 \size footnotesize
40173 \InsetSpace ~
40174 \InsetSpace ~
40175 orl a,r3
40176 \end_layout
40177
40178 \begin_layout Standard
40179
40180 \size footnotesize
40181 \InsetSpace ~
40182 \InsetSpace ~
40183 jz 00103$
40184 \end_layout
40185
40186 \begin_layout Standard
40187
40188 \size footnotesize
40189 00114$:
40190 \end_layout
40191
40192 \begin_layout Standard
40193
40194 \size footnotesize
40195 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40196 \end_layout
40197
40198 \begin_layout Standard
40199
40200 \size footnotesize
40201 \InsetSpace ~
40202 \InsetSpace ~
40203 mov dpl,_p
40204 \end_layout
40205
40206 \begin_layout Standard
40207
40208 \size footnotesize
40209 \InsetSpace ~
40210 \InsetSpace ~
40211 mov dph,(_p + 1)
40212 \end_layout
40213
40214 \begin_layout Standard
40215
40216 \size footnotesize
40217 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40218 \end_layout
40219
40220 \begin_layout Standard
40221
40222 \size footnotesize
40223 \InsetSpace ~
40224 \InsetSpace ~
40225 mov a,#0x02
40226 \end_layout
40227
40228 \begin_layout Standard
40229
40230 \size footnotesize
40231 \InsetSpace ~
40232 \InsetSpace ~
40233 add a,_p
40234 \end_layout
40235
40236 \begin_layout Standard
40237
40238 \size footnotesize
40239 \InsetSpace ~
40240 \InsetSpace ~
40241 mov _p,a
40242 \end_layout
40243
40244 \begin_layout Standard
40245
40246 \size footnotesize
40247 \InsetSpace ~
40248 \InsetSpace ~
40249 clr a
40250 \end_layout
40251
40252 \begin_layout Standard
40253
40254 \size footnotesize
40255 \InsetSpace ~
40256 \InsetSpace ~
40257 addc a,(_p + 1)
40258 \end_layout
40259
40260 \begin_layout Standard
40261
40262 \size footnotesize
40263 \InsetSpace ~
40264 \InsetSpace ~
40265 mov (_p + 1),a
40266 \end_layout
40267
40268 \begin_layout Standard
40269
40270 \size footnotesize
40271 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40272 \end_layout
40273
40274 \begin_layout Standard
40275
40276 \size footnotesize
40277 \InsetSpace ~
40278 \InsetSpace ~
40279 movx a,@dptr
40280 \end_layout
40281
40282 \begin_layout Standard
40283
40284 \size footnotesize
40285 \InsetSpace ~
40286 \InsetSpace ~
40287 mov r2,a
40288 \end_layout
40289
40290 \begin_layout Standard
40291
40292 \size footnotesize
40293 \InsetSpace ~
40294 \InsetSpace ~
40295 inc dptr
40296 \end_layout
40297
40298 \begin_layout Standard
40299
40300 \size footnotesize
40301 \InsetSpace ~
40302 \InsetSpace ~
40303 movx a,@dptr
40304 \end_layout
40305
40306 \begin_layout Standard
40307
40308 \size footnotesize
40309 \InsetSpace ~
40310 \InsetSpace ~
40311 mov r3,a
40312 \end_layout
40313
40314 \begin_layout Standard
40315
40316 \size footnotesize
40317 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40318 \end_layout
40319
40320 \begin_layout Standard
40321
40322 \size footnotesize
40323 \InsetSpace ~
40324 \InsetSpace ~
40325 mov @r0,ar2
40326 \end_layout
40327
40328 \begin_layout Standard
40329
40330 \size footnotesize
40331 \InsetSpace ~
40332 \InsetSpace ~
40333 inc r0
40334 \end_layout
40335
40336 \begin_layout Standard
40337
40338 \size footnotesize
40339 \InsetSpace ~
40340 \InsetSpace ~
40341 mov @r0,ar3
40342 \end_layout
40343
40344 \begin_layout Standard
40345
40346 \size footnotesize
40347 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40348 \end_layout
40349
40350 \begin_layout Standard
40351
40352 \size footnotesize
40353 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40354 \end_layout
40355
40356 \begin_layout Standard
40357
40358 \size footnotesize
40359 ; 0x2 {short}
40360 \end_layout
40361
40362 \begin_layout Standard
40363
40364 \size footnotesize
40365 \InsetSpace ~
40366 \InsetSpace ~
40367 inc r0
40368 \end_layout
40369
40370 \begin_layout Standard
40371
40372 \size footnotesize
40373 ; goto _whilecontinue_0($1)
40374 \end_layout
40375
40376 \begin_layout Standard
40377
40378 \size footnotesize
40379 \InsetSpace ~
40380 \InsetSpace ~
40381 sjmp 00101$
40382 \end_layout
40383
40384 \begin_layout Standard
40385
40386 \size footnotesize
40387 ; _whilebreak_0($3) :
40388 \end_layout
40389
40390 \begin_layout Standard
40391
40392 \size footnotesize
40393 00103$:
40394 \end_layout
40395
40396 \begin_layout Standard
40397
40398 \size footnotesize
40399 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40400 \end_layout
40401
40402 \begin_layout Standard
40403
40404 \size footnotesize
40405 \InsetSpace ~
40406 \InsetSpace ~
40407 mov r2,#0x00
40408 \end_layout
40409
40410 \begin_layout Standard
40411
40412 \size footnotesize
40413 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40414 \end_layout
40415
40416 \begin_layout Standard
40417
40418 \size footnotesize
40419 \InsetSpace ~
40420 \InsetSpace ~
40421 mov r3,#0x00
40422 \end_layout
40423
40424 \begin_layout Standard
40425
40426 \size footnotesize
40427 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40428 \end_layout
40429
40430 \begin_layout Standard
40431
40432 \size footnotesize
40433 \InsetSpace ~
40434 \InsetSpace ~
40435 mov r4,#0x00
40436 \end_layout
40437
40438 \begin_layout Standard
40439
40440 \size footnotesize
40441 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40442 \end_layout
40443
40444 \begin_layout Standard
40445
40446 \size footnotesize
40447 \InsetSpace ~
40448 \InsetSpace ~
40449 mov r5,#0x0A
40450 \end_layout
40451
40452 \begin_layout Standard
40453
40454 \size footnotesize
40455 \InsetSpace ~
40456 \InsetSpace ~
40457 mov r6,#0x00
40458 \end_layout
40459
40460 \begin_layout Standard
40461
40462 \size footnotesize
40463 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40464 \end_layout
40465
40466 \begin_layout Standard
40467
40468 \size footnotesize
40469 \InsetSpace ~
40470 \InsetSpace ~
40471 mov r7,#0x1E
40472 \end_layout
40473
40474 \begin_layout Standard
40475
40476 \size footnotesize
40477 \InsetSpace ~
40478 \InsetSpace ~
40479 mov r0,#0x00
40480 \end_layout
40481
40482 \begin_layout Standard
40483
40484 \size footnotesize
40485 ; _forcond_0($4) :
40486 \end_layout
40487
40488 \begin_layout Standard
40489
40490 \size footnotesize
40491 00104$:
40492 \end_layout
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40498 \end_layout
40499
40500 \begin_layout Standard
40501
40502 \size footnotesize
40503 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40504 \end_layout
40505
40506 \begin_layout Standard
40507
40508 \size footnotesize
40509 \InsetSpace ~
40510 \InsetSpace ~
40511 clr c
40512 \end_layout
40513
40514 \begin_layout Standard
40515
40516 \size footnotesize
40517 \InsetSpace ~
40518 \InsetSpace ~
40519 mov a,r4
40520 \end_layout
40521
40522 \begin_layout Standard
40523
40524 \size footnotesize
40525 \InsetSpace ~
40526 \InsetSpace ~
40527 xrl a,#0x80
40528 \end_layout
40529
40530 \begin_layout Standard
40531
40532 \size footnotesize
40533 \InsetSpace ~
40534 \InsetSpace ~
40535 subb a,#0x8a
40536 \end_layout
40537
40538 \begin_layout Standard
40539
40540 \size footnotesize
40541 \InsetSpace ~
40542 \InsetSpace ~
40543 jnc 00107$
40544 \end_layout
40545
40546 \begin_layout Standard
40547
40548 \size footnotesize
40549 00115$:
40550 \end_layout
40551
40552 \begin_layout Standard
40553
40554 \size footnotesize
40555 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40556 \end_layout
40557
40558 \begin_layout Standard
40559
40560 \size footnotesize
40561 ; iTemp21 [lr21:38]{short}[r4]
40562 \end_layout
40563
40564 \begin_layout Standard
40565
40566 \size footnotesize
40567 \InsetSpace ~
40568 \InsetSpace ~
40569 mov a,r4
40570 \end_layout
40571
40572 \begin_layout Standard
40573
40574 \size footnotesize
40575 \InsetSpace ~
40576 \InsetSpace ~
40577 add a,r2
40578 \end_layout
40579
40580 \begin_layout Standard
40581
40582 \size footnotesize
40583 \InsetSpace ~
40584 \InsetSpace ~
40585 mov r2,a
40586 \end_layout
40587
40588 \begin_layout Standard
40589
40590 \size footnotesize
40591 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40592 \end_layout
40593
40594 \begin_layout Standard
40595
40596 \size footnotesize
40597 \InsetSpace ~
40598 \InsetSpace ~
40599 mov b,#0x03
40600 \end_layout
40601
40602 \begin_layout Standard
40603
40604 \size footnotesize
40605 \InsetSpace ~
40606 \InsetSpace ~
40607 mov a,r4
40608 \end_layout
40609
40610 \begin_layout Standard
40611
40612 \size footnotesize
40613 \InsetSpace ~
40614 \InsetSpace ~
40615 mul ab
40616 \end_layout
40617
40618 \begin_layout Standard
40619
40620 \size footnotesize
40621 \InsetSpace ~
40622 \InsetSpace ~
40623 mov r1,a
40624 \end_layout
40625
40626 \begin_layout Standard
40627
40628 \size footnotesize
40629 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40630 \end_layout
40631
40632 \begin_layout Standard
40633
40634 \size footnotesize
40635 ; iTemp15 [lr29:30]{short}[r1]
40636 \end_layout
40637
40638 \begin_layout Standard
40639
40640 \size footnotesize
40641 \InsetSpace ~
40642 \InsetSpace ~
40643 add a,r3
40644 \end_layout
40645
40646 \begin_layout Standard
40647
40648 \size footnotesize
40649 \InsetSpace ~
40650 \InsetSpace ~
40651 mov r3,a
40652 \end_layout
40653
40654 \begin_layout Standard
40655
40656 \size footnotesize
40657 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40658 \end_layout
40659
40660 \begin_layout Standard
40661
40662 \size footnotesize
40663 \InsetSpace ~
40664 \InsetSpace ~
40665 mov a,r7
40666 \end_layout
40667
40668 \begin_layout Standard
40669
40670 \size footnotesize
40671 \InsetSpace ~
40672 \InsetSpace ~
40673 add a,#0xfd
40674 \end_layout
40675
40676 \begin_layout Standard
40677
40678 \size footnotesize
40679 \InsetSpace ~
40680 \InsetSpace ~
40681 mov r7,a
40682 \end_layout
40683
40684 \begin_layout Standard
40685
40686 \size footnotesize
40687 \InsetSpace ~
40688 \InsetSpace ~
40689 mov a,r0
40690 \end_layout
40691
40692 \begin_layout Standard
40693
40694 \size footnotesize
40695 \InsetSpace ~
40696 \InsetSpace ~
40697 addc a,#0xff
40698 \end_layout
40699
40700 \begin_layout Standard
40701
40702 \size footnotesize
40703 \InsetSpace ~
40704 \InsetSpace ~
40705 mov r0,a
40706 \end_layout
40707
40708 \begin_layout Standard
40709
40710 \size footnotesize
40711 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40712 \end_layout
40713
40714 \begin_layout Standard
40715
40716 \size footnotesize
40717 \InsetSpace ~
40718 \InsetSpace ~
40719 mov a,r7
40720 \end_layout
40721
40722 \begin_layout Standard
40723
40724 \size footnotesize
40725 \InsetSpace ~
40726 \InsetSpace ~
40727 add a,_gint
40728 \end_layout
40729
40730 \begin_layout Standard
40731
40732 \size footnotesize
40733 \InsetSpace ~
40734 \InsetSpace ~
40735 mov _gint,a
40736 \end_layout
40737
40738 \begin_layout Standard
40739
40740 \size footnotesize
40741 \InsetSpace ~
40742 \InsetSpace ~
40743 mov a,r0
40744 \end_layout
40745
40746 \begin_layout Standard
40747
40748 \size footnotesize
40749 \InsetSpace ~
40750 \InsetSpace ~
40751 addc a,(_gint + 1)
40752 \end_layout
40753
40754 \begin_layout Standard
40755
40756 \size footnotesize
40757 \InsetSpace ~
40758 \InsetSpace ~
40759 mov (_gint + 1),a
40760 \end_layout
40761
40762 \begin_layout Standard
40763
40764 \size footnotesize
40765 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40766 \end_layout
40767
40768 \begin_layout Standard
40769
40770 \size footnotesize
40771 \InsetSpace ~
40772 \InsetSpace ~
40773 inc r4
40774 \end_layout
40775
40776 \begin_layout Standard
40777
40778 \size footnotesize
40779 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40780 \end_layout
40781
40782 \begin_layout Standard
40783
40784 \size footnotesize
40785 \InsetSpace ~
40786 \InsetSpace ~
40787 dec r5
40788 \end_layout
40789
40790 \begin_layout Standard
40791
40792 \size footnotesize
40793 \InsetSpace ~
40794 \InsetSpace ~
40795 cjne r5,#0xff,00104$
40796 \end_layout
40797
40798 \begin_layout Standard
40799
40800 \size footnotesize
40801 \InsetSpace ~
40802 \InsetSpace ~
40803 dec r6
40804 \end_layout
40805
40806 \begin_layout Standard
40807
40808 \size footnotesize
40809 ; goto _forcond_0($4)
40810 \end_layout
40811
40812 \begin_layout Standard
40813
40814 \size footnotesize
40815 \InsetSpace ~
40816 \InsetSpace ~
40817 sjmp 00104$
40818 \end_layout
40819
40820 \begin_layout Standard
40821
40822 \size footnotesize
40823 ; _forbreak_0($7) :
40824 \end_layout
40825
40826 \begin_layout Standard
40827
40828 \size footnotesize
40829 00107$:
40830 \end_layout
40831
40832 \begin_layout Standard
40833
40834 \size footnotesize
40835 ; ret iTemp24 [lr40:41]{short}
40836 \end_layout
40837
40838 \begin_layout Standard
40839
40840 \size footnotesize
40841 \InsetSpace ~
40842 \InsetSpace ~
40843 mov a,r3
40844 \end_layout
40845
40846 \begin_layout Standard
40847
40848 \size footnotesize
40849 \InsetSpace ~
40850 \InsetSpace ~
40851 add a,r2
40852 \end_layout
40853
40854 \begin_layout Standard
40855
40856 \size footnotesize
40857 \InsetSpace ~
40858 \InsetSpace ~
40859 mov dpl,a
40860 \end_layout
40861
40862 \begin_layout Standard
40863
40864 \size footnotesize
40865 ; _return($8) :
40866 \end_layout
40867
40868 \begin_layout Standard
40869
40870 \size footnotesize
40871 00108$:
40872 \end_layout
40873
40874 \begin_layout Standard
40875
40876 \size footnotesize
40877 \InsetSpace ~
40878 \InsetSpace ~
40879 ret
40880 \newline
40881
40882 \end_layout
40883
40884 \begin_layout Section
40885 A few words about basic block successors, predecessors and dominators
40886 \end_layout
40887
40888 \begin_layout Standard
40889 Successors are basic blocks
40890 \begin_inset LatexCommand \index{Basic blocks}
40891
40892 \end_inset
40893
40894  that might execute after this basic block.
40895 \newline
40896 Predecessors are basic blocks
40897  that might execute before reaching this basic block.
40898 \newline
40899 Dominators are basic
40900  blocks that WILL execute before reaching this basic block.
40901 \newline
40902
40903 \end_layout
40904
40905 \begin_layout Standard
40906 [basic block 1]
40907 \end_layout
40908
40909 \begin_layout Standard
40910 if (something)
40911 \end_layout
40912
40913 \begin_layout Standard
40914 \InsetSpace ~
40915 \InsetSpace ~
40916 \InsetSpace ~
40917 \InsetSpace ~
40918 [basic block 2]
40919 \end_layout
40920
40921 \begin_layout Standard
40922 else
40923 \end_layout
40924
40925 \begin_layout Standard
40926 \InsetSpace ~
40927 \InsetSpace ~
40928 \InsetSpace ~
40929 \InsetSpace ~
40930 [basic block 3]
40931 \end_layout
40932
40933 \begin_layout Standard
40934 [basic block 4]
40935 \newline
40936
40937 \end_layout
40938
40939 \begin_layout Standard
40940 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40941 \end_layout
40942
40943 \begin_layout Standard
40944 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40945 \end_layout
40946
40947 \begin_layout Standard
40948 c) domVect of [BB4] = BB1 ...
40949  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40950  was executed.
40951 \end_layout
40952
40953 \begin_layout Chapter
40954 Acknowledgments
40955 \end_layout
40956
40957 \begin_layout Standard
40958 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40959
40960 \end_inset
40961
40962
40963 \newline
40964
40965 \newline
40966
40967 \emph on
40968 Thanks to all the other volunteer developers who have helped with coding,
40969  testing, web-page creation, distribution sets, etc.
40970  You know who you are :-)
40971 \emph default
40972
40973 \newline
40974
40975 \newline
40976
40977 \emph on
40978 Thanks to Sourceforge 
40979 \begin_inset LatexCommand \url{http://www.sf.net}
40980
40981 \end_inset
40982
40983  which has hosted the project since 1999 and donates significant download
40984  bandwidth.
40985 \emph default
40986
40987 \newline
40988
40989 \newline
40990
40991 \emph on
40992 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40993  cycles and bandwidth for snapshot builds.
40994 \newline
40995
40996 \end_layout
40997
40998 \begin_layout Standard
40999 This document was initially written by Sandeep Dutta
41000 \end_layout
41001
41002 \begin_layout Standard
41003 All product names mentioned herein may be trademarks
41004 \begin_inset LatexCommand \index{Trademarks}
41005
41006 \end_inset
41007
41008  of their respective companies.
41009  
41010 \end_layout
41011
41012 \begin_layout Section*
41013 Alphabetical index
41014 \end_layout
41015
41016 \begin_layout Standard
41017 To avoid confusion, the installation and building options for SDCC itself
41018  (chapter 2) are not part of the index.
41019 \end_layout
41020
41021 \begin_layout Standard
41022 \begin_inset LatexCommand \printindex{}
41023
41024 \end_inset
41025
41026
41027 \end_layout
41028
41029 \end_body
41030 \end_document