* doc/sdccman.lyx: corrected to be able to convert to PDF
[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 8000-FFFF
23477 \end_layout
23478
23479 \end_inset
23480 </cell>
23481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23482 \begin_inset Text
23483
23484 \begin_layout Standard
23485 bank1
23486 \end_layout
23487
23488 \end_inset
23489 </cell>
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23491 \begin_inset Text
23492
23493 \begin_layout Standard
23494 bank2
23495 \end_layout
23496
23497 \end_inset
23498 </cell>
23499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23500 \begin_inset Text
23501
23502 \begin_layout Standard
23503 bank3
23504 \end_layout
23505
23506 \end_inset
23507 </cell>
23508 </row>
23509 <row topline="true" bottomline="true">
23510 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23511 \begin_inset Text
23512
23513 \begin_layout Standard
23514 0000-7FFF
23515 \end_layout
23516
23517 \end_inset
23518 </cell>
23519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23520 \begin_inset Text
23521
23522 \begin_layout Standard
23523 common
23524 \end_layout
23525
23526 \end_inset
23527 </cell>
23528 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23529 \begin_inset Text
23530
23531 \begin_layout Standard
23532
23533 \end_layout
23534
23535 \end_inset
23536 </cell>
23537 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23538 \begin_inset Text
23539
23540 \begin_layout Standard
23541
23542 \end_layout
23543
23544 \end_inset
23545 </cell>
23546 </row>
23547 <row>
23548 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23549 \begin_inset Text
23550
23551 \begin_layout Standard
23552 SiLabs C8051F120 example
23553 \end_layout
23554
23555 \end_inset
23556 </cell>
23557 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23558 \begin_inset Text
23559
23560 \begin_layout Standard
23561
23562 \end_layout
23563
23564 \end_inset
23565 </cell>
23566 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23567 \begin_inset Text
23568
23569 \begin_layout Standard
23570
23571 \end_layout
23572
23573 \end_inset
23574 </cell>
23575 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23576 \begin_inset Text
23577
23578 \begin_layout Standard
23579
23580 \end_layout
23581
23582 \end_inset
23583 </cell>
23584 </row>
23585 </lyxtabular>
23586
23587 \end_inset
23588
23589
23590 \newline
23591
23592 \newline
23593 Usually the hardware uses some sfr (an output port or an internal sfr) to
23594  select a bank and put it in the banked area of the memory map.
23595  Because the selected bank usually becomes active immediately you cannot
23596  jump call directly from one bank to another and need to use a so-called
23597  trampoline in the common area.
23598  For SDCC an example trampoline is in crtbank.asm and you may need to change
23599  it to your 8051 derivative or schematic.
23600  The presented code is written for the C8051F120.
23601 \newline
23602
23603 \newline
23604 When calling a banked function
23605  SDCC will put the LSB of the functions address in register R0, the MSB
23606  in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
23607  The current selected bank is saved on the stack, the new bank is selected
23608  and an indirect jump is made.
23609  When the banked function returns it jumps to __sdcc_banked_ret which restores
23610  the previous bank and returns to the caller.
23611 \end_layout
23612
23613 \begin_layout Subsubsection
23614 Software
23615 \end_layout
23616
23617 \begin_layout Standard
23618 When writing banked software using SDCC you need to use some special keywords
23619  and options.
23620  You also need to take over a bit of work from the linker.
23621 \newline
23622
23623 \newline
23624 To create a function
23625  that can be called from another bank it requires the keyword banked.
23626  The caller must see this in the prototype of the callee and the callee
23627  needs it for a proper return.
23628  Called functions within the same bank as the caller do not need the banked
23629  keyword nor do functions in the common area.
23630  Beware: SDCC does not know or check if functions are in the same bank.
23631  This is your responsibility!
23632 \newline
23633
23634 \newline
23635 Normally all functions you write end up in
23636  the segment CSEG.
23637  If you want a function explicitly to reside in the common area put it in
23638  segment HOME.
23639  This applies for instance to interrupt service routines as they should
23640  not be banked.
23641 \end_layout
23642
23643 \begin_layout Standard
23644 Functions that need to be in a switched bank must be put in a named segment.
23645  The name can be mostly anything upto eight characters (e.g.
23646  BANK1).
23647  To do this you either use --codeseg BANK1 on the command line when compiling
23648  or #pragma codeseg BANK1 at the top of the C source file.
23649  The segment name always applies to the whole source file and generated
23650  object so functions for different banks need to be defined in different
23651  source files.
23652 \newline
23653
23654 \newline
23655 When linking your objects you need to tell the linker where
23656  to put your segments.
23657  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23658 00.
23659  This sets the virtual start address of this segment.
23660  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23661  The linker will not check for overflows, again this is your responsibility.
23662 \end_layout
23663
23664 \begin_layout Standard
23665 \begin_inset VSpace bigskip
23666 \end_inset
23667
23668
23669 \end_layout
23670
23671 \begin_layout Section
23672 DS400 port
23673 \end_layout
23674
23675 \begin_layout Standard
23676 The DS80C400
23677 \begin_inset LatexCommand \index{DS80C400}
23678
23679 \end_inset
23680
23681
23682 \begin_inset LatexCommand \index{DS400}
23683
23684 \end_inset
23685
23686  microcontroller has a rich set of peripherals.
23687  In its built-in ROM library it includes functions to access some of the
23688  features, among them is a TCP stack with IP4 and IP6 support.
23689  Library headers (currently in beta status) and other files are provided
23690  at 
23691 \size footnotesize
23692
23693 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23694
23695 \end_inset
23696
23697 .
23698  
23699 \begin_inset VSpace bigskip
23700 \end_inset
23701
23702
23703 \end_layout
23704
23705 \begin_layout Section
23706 The Z80 and gbz80 port
23707 \end_layout
23708
23709 \begin_layout Standard
23710 SDCC can target both the Zilog Z80
23711 \begin_inset LatexCommand \index{Z80}
23712
23713 \end_inset
23714
23715  and the Nintendo Gameboy's Z80-like gbz80
23716 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23717
23718 \end_inset
23719
23720 .
23721  The Z80 port is passed through the same 
23722 \emph on
23723 regressions tests
23724 \begin_inset LatexCommand \index{Regression test}
23725
23726 \end_inset
23727
23728
23729 \emph default
23730  (see section 
23731 \begin_inset LatexCommand \ref{sec:Quality-control}
23732
23733 \end_inset
23734
23735 ) as the MCS51 and DS390 ports, so floating point support, support for long
23736  variables and bitfield support is fine.
23737  See mailing lists and forums about interrupt routines.
23738 \end_layout
23739
23740 \begin_layout Standard
23741 As always, the code is the authoritative reference - see z80/ralloc.c and
23742  z80/gen.c.
23743  The stack
23744 \begin_inset LatexCommand \index{Z80!stack}
23745
23746 \end_inset
23747
23748  frame is similar to that generated by the IAR Z80 compiler.
23749  IX is used as the base pointer, HL and IY are used as a temporary registers,
23750  and BC and DE are available for holding variables.
23751  Return values
23752 \begin_inset LatexCommand \index{Z80!return value}
23753
23754 \end_inset
23755
23756  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23757  bytes).
23758  The gbz80 port use the same set of registers for the return values, but
23759  in a different order of significance: E (one byte), DE (two bytes), or
23760  HLDE (four bytes).
23761 \begin_inset VSpace bigskip
23762 \end_inset
23763
23764
23765 \end_layout
23766
23767 \begin_layout Section
23768 The HC08 port
23769 \end_layout
23770
23771 \begin_layout Standard
23772 The port to the Freescale/Motorola HC08
23773 \begin_inset LatexCommand \index{HC08}
23774
23775 \end_inset
23776
23777  family has been added in October 2003, and is still undergoing some basic
23778  development.
23779  The code generator is complete, but the register allocation is still quite
23780  unoptimized.
23781  Some of the SDCC's standard C library functions have embedded non-HC08
23782  inline assembly and so are not yet usable.
23783 \end_layout
23784
23785 \begin_layout Standard
23786 The HC08 port passes the regression test suite (see section 
23787 \begin_inset LatexCommand \ref{sec:Quality-control}
23788
23789 \end_inset
23790
23791 ).
23792 \begin_inset VSpace bigskip
23793 \end_inset
23794
23795
23796 \newpage
23797
23798 \end_layout
23799
23800 \begin_layout Section
23801 The PIC14
23802 \begin_inset LatexCommand \index{PIC14}
23803
23804 \end_inset
23805
23806  port
23807 \end_layout
23808
23809 \begin_layout Standard
23810 The PIC14 port adds support for Microchip
23811 \begin_inset LatexCommand \index{Microchip}
23812
23813 \end_inset
23814
23815
23816 \begin_inset Formula $^{\text{TM}}$
23817 \end_inset
23818
23819  PIC
23820 \begin_inset LatexCommand \index{PIC14}
23821
23822 \end_inset
23823
23824
23825 \begin_inset Formula $^{\text{TM}}$
23826 \end_inset
23827
23828  MCUs with 14 bit wide instructions.
23829  This port is not yet mature and still lacks many features.
23830  However, it can work for simple code.
23831 \end_layout
23832
23833 \begin_layout Standard
23834 Currently supported devices include:
23835 \end_layout
23836
23837 \begin_layout Standard
23838 12F: 629, 635, 675, 683
23839 \end_layout
23840
23841 \begin_layout Standard
23842 16C: 432, 433
23843 \end_layout
23844
23845 \begin_layout Standard
23846 16C: 554, 557, 558
23847 \end_layout
23848
23849 \begin_layout Standard
23850 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23851 \end_layout
23852
23853 \begin_layout Standard
23854 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23855  781, 782
23856 \end_layout
23857
23858 \begin_layout Standard
23859 16C: 925, 926
23860 \end_layout
23861
23862 \begin_layout Standard
23863 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23864  689, 690
23865 \end_layout
23866
23867 \begin_layout Standard
23868 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23869 \end_layout
23870
23871 \begin_layout Standard
23872 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23873  877, 877a, 88
23874 \end_layout
23875
23876 \begin_layout Standard
23877 16F: 913, 914, 916, 917
23878 \end_layout
23879
23880 \begin_layout Standard
23881 An up-to-date list of currently supported devices can be obtained via 
23882 \family typewriter
23883 sdcc -mpic14 -phelp foo.c
23884 \family default
23885  (foo.c must exist...).
23886 \end_layout
23887
23888 \begin_layout Subsection
23889 PIC Code Pages
23890 \begin_inset LatexCommand \index{code page (pic14)}
23891
23892 \end_inset
23893
23894  and Memory Banks
23895 \begin_inset LatexCommand \index{Memory bank (pic14)}
23896
23897 \end_inset
23898
23899
23900 \end_layout
23901
23902 \begin_layout Standard
23903 The linker organizes allocation for the code page and RAM banks.
23904  It does not have intimate knowledge of the code flow.
23905  It will put all the code section of a single .asm file into a single code
23906  page.
23907  In order to make use of multiple code pages, separate asm files must be
23908  used.
23909  The compiler assigns all 
23910 \emph on
23911 static
23912 \emph default
23913  functions of a single .c file into the same code page.
23914 \newline
23915
23916 \newline
23917 To get the best results,
23918  follow these guidelines:
23919 \end_layout
23920
23921 \begin_layout Enumerate
23922 Make local functions static, as non static functions require code page selection
23923  overhead.
23924 \newline
23925 Due to the way sdcc handles functions, place called functions prior
23926  to calling functions in the file wherever possible: Otherwise sdcc will
23927  insert unneccessary pagesel directives around the call, believing that
23928  the called function is externally defined.
23929 \end_layout
23930
23931 \begin_layout Enumerate
23932 For devices that have multiple code pages it is more efficient to use the
23933  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23934  but only 2 files for the 16F874.
23935  This way the linker can put the code for each file into different code
23936  pages and there will be less page selection overhead.
23937 \end_layout
23938
23939 \begin_layout Enumerate
23940 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23941  instruction set), use `unsigned char' wherever possible instead of `int'.
23942 \end_layout
23943
23944 \begin_layout Subsection
23945 Adding New Devices to the Port 
23946 \end_layout
23947
23948 \begin_layout Standard
23949 Adding support for a new 14
23950 \begin_inset ERT
23951 status open
23952
23953 \begin_layout Standard
23954
23955
23956 \backslash
23957 ,
23958 \end_layout
23959
23960 \end_inset
23961
23962 bit PIC MCU requires the following steps:
23963 \end_layout
23964
23965 \begin_layout Enumerate
23966 Create a new device description.
23967 \newline
23968 Each device is described in two files: pic16f*.h
23969  and pic16f*.c.
23970  These files primarily define SFRs, structs to access their bits, and symbolic
23971  configuration options.
23972  Both files can be generated from gputils' .inc files using the perl script
23973  
23974 \family typewriter
23975 support/scripts/inc2h.pl
23976 \family default
23977 .
23978  This file also contains further instructions on how to proceed.
23979 \end_layout
23980
23981 \begin_layout Enumerate
23982 Copy the .h file into SDCC's include path and either add the .c file to your
23983  project or copy it to 
23984 \family typewriter
23985 device/lib/pic/libdev
23986 \family default
23987 .
23988  Afterwards, rebuild and install the libraries.
23989 \end_layout
23990
23991 \begin_layout Enumerate
23992 Edit pic14devices.txt in SDCC's include path (
23993 \family typewriter
23994 device/include/pic/
23995 \family default
23996  in the source tree or 
23997 \family typewriter
23998 /usr/local/share/sdcc/include/pic
23999 \family default
24000  after installation).
24001 \newline
24002 You need to add a device specification here to make
24003  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24004  the compiler.
24005  Probably you can copy and modify an existing entry.
24006  The file format is documented at the top of the file.
24007 \end_layout
24008
24009 \begin_layout Subsection
24010 Interrupt Code
24011 \end_layout
24012
24013 \begin_layout Standard
24014 For the interrupt function, use the keyword `__interrupt'
24015 \begin_inset LatexCommand \index{PIC14!interrupt}
24016
24017 \end_inset
24018
24019  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24020  there to avoid a syntax error - it ought to be fixed).
24021  E.g.:
24022 \end_layout
24023
24024 \begin_layout Verse
24025
24026 \family typewriter
24027 void Intr(void) __interrupt 0
24028 \newline
24029 {
24030 \newline
24031 \InsetSpace ~
24032 \InsetSpace ~
24033 T0IF = 0; /* Clear timer interrupt */
24034 \newline
24035 }
24036 \end_layout
24037
24038 \begin_layout Subsection
24039 Linking and Assembling
24040 \end_layout
24041
24042 \begin_layout Standard
24043 For assembling you can use either GPUTILS'
24044 \begin_inset LatexCommand \index{gputils (pic tools)}
24045
24046 \end_inset
24047
24048  gpasm.exe or MPLAB's mpasmwin.exe.
24049  GPUTILS are available from 
24050 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24051
24052 \end_inset
24053
24054 .
24055  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24056  If you use MPLAB and an interrupt function then the linker script file
24057  vectors section will need to be enlarged to link with mplink.
24058 \newline
24059
24060 \newline
24061 Here is a 
24062 \family typewriter
24063 Makefile
24064 \family default
24065  using GPUTILS:
24066 \end_layout
24067
24068 \begin_layout Verse
24069
24070 \family typewriter
24071 .c.o:
24072 \newline
24073 \InsetSpace ~
24074 \InsetSpace ~
24075 \InsetSpace ~
24076 \InsetSpace ~
24077 \InsetSpace ~
24078 \InsetSpace ~
24079 \InsetSpace ~
24080 \InsetSpace ~
24081 sdcc -V -mpic14 -p16f877 -c $< 
24082 \newline
24083
24084 \newline
24085 $(PRJ).hex: $(OBJS) 
24086 \newline
24087 \InsetSpace ~
24088 \InsetSpace ~
24089 \InsetSpace ~
24090 \InsetSpace ~
24091 \InsetSpace ~
24092 \InsetSpace ~
24093 \InsetSpace ~
24094 \InsetSpace ~
24095 gplink -m -s $(PRJ).lkr
24096  -o $(PRJ).hex $(OBJS) libsdcc.lib
24097 \end_layout
24098
24099 \begin_layout Standard
24100 Here is a 
24101 \family typewriter
24102 Makefile
24103 \family default
24104  using MPLAB:
24105 \end_layout
24106
24107 \begin_layout Verse
24108
24109 \family typewriter
24110 .c.o: 
24111 \newline
24112 \InsetSpace ~
24113 \InsetSpace ~
24114 \InsetSpace ~
24115 \InsetSpace ~
24116 \InsetSpace ~
24117 \InsetSpace ~
24118 \InsetSpace ~
24119 \InsetSpace ~
24120 sdcc -S -V -mpic14 -p16f877 $< 
24121 \newline
24122 \InsetSpace ~
24123 \InsetSpace ~
24124 \InsetSpace ~
24125 \InsetSpace ~
24126 \InsetSpace ~
24127 \InsetSpace ~
24128 \InsetSpace ~
24129 \InsetSpace ~
24130 mpasmwin /q /o $*.asm
24131 \newline
24132
24133 \newline
24134 $(PRJ).hex: $(OBJS)
24135  
24136 \newline
24137 \InsetSpace ~
24138 \InsetSpace ~
24139 \InsetSpace ~
24140 \InsetSpace ~
24141 \InsetSpace ~
24142 \InsetSpace ~
24143 \InsetSpace ~
24144 \InsetSpace ~
24145 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24146 \end_layout
24147
24148 \begin_layout Standard
24149 Please note that indentations within a
24150 \family typewriter
24151  Makefile
24152 \family default
24153  have to be done with a tabulator character.
24154 \end_layout
24155
24156 \begin_layout Subsection
24157 Command-Line Options
24158 \end_layout
24159
24160 \begin_layout Standard
24161 Besides the switches common to all SDCC backends, the PIC14 port accepts
24162  the following options (for an updated list see sdcc -
24163 \begin_inset ERT
24164 status collapsed
24165
24166 \begin_layout Standard
24167
24168
24169 \backslash
24170 /
24171 \end_layout
24172
24173 \end_inset
24174
24175 -help):
24176 \end_layout
24177
24178 \begin_layout Description
24179 -
24180 \begin_inset ERT
24181 status collapsed
24182
24183 \begin_layout Standard
24184
24185
24186 \backslash
24187 /
24188 \end_layout
24189
24190 \end_inset
24191
24192 -debug-xtra
24193 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24194
24195 \end_inset
24196
24197  emit debug info in assembly output
24198 \end_layout
24199
24200 \begin_layout Description
24201 -
24202 \begin_inset ERT
24203 status collapsed
24204
24205 \begin_layout Standard
24206
24207
24208 \backslash
24209 /
24210 \end_layout
24211
24212 \end_inset
24213
24214 -no-pcode-opt
24215 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24216
24217 \end_inset
24218
24219  disable (slightly faulty) optimization on pCode
24220 \end_layout
24221
24222 \begin_layout Description
24223 -
24224 \begin_inset ERT
24225 status collapsed
24226
24227 \begin_layout Standard
24228
24229
24230 \backslash
24231 /
24232 \end_layout
24233
24234 \end_inset
24235
24236 -stack-loc
24237 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24238
24239 \end_inset
24240
24241  sets the lowest address of the argument passing stack (defaults to a suitably
24242  large shared databank to reduce BANKSEL overhead)
24243 \end_layout
24244
24245 \begin_layout Description
24246 -
24247 \begin_inset ERT
24248 status collapsed
24249
24250 \begin_layout Standard
24251
24252
24253 \backslash
24254 /
24255 \end_layout
24256
24257 \end_inset
24258
24259 -stack-size
24260 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24261
24262 \end_inset
24263
24264  sets the size if the argument passing stack (default: 16, minimum: 4)
24265 \end_layout
24266
24267 \begin_layout Subsection
24268 Environment Variables
24269 \end_layout
24270
24271 \begin_layout Standard
24272 The PIC14 port recognizes the following environment variables:
24273 \end_layout
24274
24275 \begin_layout Description
24276 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24277  register (the ones called r0xNNNN) in a section of its own.
24278  By default (if this variable is unset), sdcc tries to cluster registers
24279  in sections in order to reduce the BANKSEL overhead when accessing them.
24280 \end_layout
24281
24282 \begin_layout Subsection
24283 The Library
24284 \end_layout
24285
24286 \begin_layout Standard
24287 The PIC14 library currently only contains support routines required by the
24288  compiler to implement multiplication, division, and floating point support.
24289  No libc-like replacement is available at the moment, though many of the
24290  common sdcc library sources (in 
24291 \family typewriter
24292 device/lib
24293 \family default
24294 ) should also compile with the PIC14 port.
24295 \end_layout
24296
24297 \begin_layout Subsubsection
24298 error: missing definition for symbol ``__gptrget1''
24299 \end_layout
24300
24301 \begin_layout Standard
24302 The PIC14 port uses library routines to provide more complex operations
24303  like multiplication, division/modulus and (generic) pointer dereferencing.
24304  In order to add these routines to your project, you must link with PIC14's
24305  
24306 \family typewriter
24307 libsdcc.lib
24308 \family default
24309 .
24310  For single source file projects this is done automatically, more complex
24311  projects must add 
24312 \family typewriter
24313 libsdcc.lib
24314 \family default
24315  to the linker's arguments.
24316  Make sure you also add an include path for the library (using the -I switch
24317  to the linker)!
24318 \end_layout
24319
24320 \begin_layout Subsubsection
24321 Processor mismatch in file ``XXX''.
24322 \end_layout
24323
24324 \begin_layout Standard
24325 This warning can usually be ignored due to the very good compatibility amongst
24326  14
24327 \begin_inset ERT
24328 status open
24329
24330 \begin_layout Standard
24331
24332
24333 \backslash
24334 ,
24335 \end_layout
24336
24337 \end_inset
24338
24339 bit PIC
24340 \begin_inset LatexCommand \index{PIC14}
24341
24342 \end_inset
24343
24344  devices.
24345 \end_layout
24346
24347 \begin_layout Standard
24348 You might also consider recompiling the library for your specific device
24349  by changing the ARCH=p16f877 (default target) entry in 
24350 \family typewriter
24351 device/lib/pic/Makefile.in
24352 \family default
24353  and 
24354 \family typewriter
24355 device/lib/pic/Makefile
24356 \family default
24357  to reflect your device.
24358  This might even improve performance for smaller devices as unneccesary
24359  BANKSELs might be removed.
24360 \end_layout
24361
24362 \begin_layout Subsection
24363 Known Bugs
24364 \end_layout
24365
24366 \begin_layout Subsubsection
24367 Function arguments
24368 \end_layout
24369
24370 \begin_layout Standard
24371 Functions with variable argument lists (like printf) are not yet supported.
24372  Similarly, taking the argument of the first argument passed into a function
24373  does not work: It is currently passed in WREG and has no address...
24374 \end_layout
24375
24376 \begin_layout Subsubsection
24377 Regression tests fail
24378 \end_layout
24379
24380 \begin_layout Standard
24381 Though the small subset of regression tests in src/regression passes, SDCC
24382  regression test suite does not, indicating that there are still major bugs
24383  in the port.
24384  However, many smaller projects have successfully used SDCC in the past...
24385 \end_layout
24386
24387 \begin_layout Standard
24388
24389 \size footnotesize
24390
24391 \newpage
24392
24393 \end_layout
24394
24395 \begin_layout Section
24396 The PIC16
24397 \begin_inset LatexCommand \index{PIC16}
24398
24399 \end_inset
24400
24401  port
24402 \end_layout
24403
24404 \begin_layout Standard
24405 The PIC16 port adds support for Microchip
24406 \begin_inset LatexCommand \index{Microchip}
24407
24408 \end_inset
24409
24410
24411 \begin_inset Formula $^{\text{TM}}$
24412 \end_inset
24413
24414  PIC
24415 \begin_inset LatexCommand \index{PIC}
24416
24417 \end_inset
24418
24419
24420 \begin_inset Formula $^{\text{TM}}$
24421 \end_inset
24422
24423  MCUs with 16 bit wide instructions.
24424  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24425 ; devices supported by the port include:
24426 \end_layout
24427
24428 \begin_layout Standard
24429 18F: 242, 248, 252, 258, 442, 448, 452, 458
24430 \end_layout
24431
24432 \begin_layout Standard
24433 18F: 1220, 1320
24434 \end_layout
24435
24436 \begin_layout Standard
24437 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24438  2620
24439 \end_layout
24440
24441 \begin_layout Standard
24442 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24443  45j10, 4620
24444 \end_layout
24445
24446 \begin_layout Standard
24447 18F: 6520, 6620, 6680, 6720
24448 \end_layout
24449
24450 \begin_layout Standard
24451 18F: 8520, 8620, 8680, 8720
24452 \end_layout
24453
24454 \begin_layout Subsection
24455 Global Options
24456 \end_layout
24457
24458 \begin_layout Standard
24459 PIC16 port supports the standard command line arguments as supposed, with
24460  the exception of certain cases that will be mentioned in the following
24461  list:
24462 \end_layout
24463
24464 \begin_layout Description
24465 -
24466 \begin_inset ERT
24467 status collapsed
24468
24469 \begin_layout Standard
24470
24471
24472 \backslash
24473 /
24474 \end_layout
24475
24476 \end_inset
24477
24478 -callee-saves
24479 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24480
24481 \end_inset
24482
24483  See -
24484 \begin_inset ERT
24485 status collapsed
24486
24487 \begin_layout Standard
24488
24489
24490 \backslash
24491 /
24492 \end_layout
24493
24494 \end_inset
24495
24496 -all-callee-saves
24497 \end_layout
24498
24499 \begin_layout Description
24500 -
24501 \begin_inset ERT
24502 status collapsed
24503
24504 \begin_layout Standard
24505
24506
24507 \backslash
24508 /
24509 \end_layout
24510
24511 \end_inset
24512
24513 -fommit-frame-pointer
24514 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24515
24516 \end_inset
24517
24518  Frame pointer will be omitted when the function uses no local variables.
24519 \end_layout
24520
24521 \begin_layout Subsection
24522 Port Specific Options
24523 \begin_inset LatexCommand \index{Options PIC16}
24524
24525 \end_inset
24526
24527
24528 \end_layout
24529
24530 \begin_layout Standard
24531 The port specific options appear after the global options in the sdcc -
24532 \begin_inset ERT
24533 status collapsed
24534
24535 \begin_layout Standard
24536
24537
24538 \backslash
24539 /
24540 \end_layout
24541
24542 \end_inset
24543
24544 -help output.
24545 \end_layout
24546
24547 \begin_layout Subsubsection
24548 Code Generation Options
24549 \end_layout
24550
24551 \begin_layout Standard
24552 These options influence the generated assembler code.
24553 \end_layout
24554
24555 \begin_layout Description
24556 -
24557 \begin_inset ERT
24558 status collapsed
24559
24560 \begin_layout Standard
24561
24562
24563 \backslash
24564 /
24565 \end_layout
24566
24567 \end_inset
24568
24569 -pstack-model=[model] Used in conjuction with the command above.
24570  Defines the stack model to be used, valid stack models are:
24571 \end_layout
24572
24573 \begin_deeper
24574 \begin_layout List
24575 \labelwidthstring 00.00.0000
24576
24577 \emph on
24578 small
24579 \emph default
24580  Selects small stack model.
24581  8 bit stack and frame pointers.
24582  Supports 256 bytes stack size.
24583 \end_layout
24584
24585 \begin_layout List
24586 \labelwidthstring 00.00.0000
24587
24588 \emph on
24589 large
24590 \emph default
24591  Selects large stack model.
24592  16 bit stack and frame pointers.
24593  Supports 65536 bytes stack size.
24594 \end_layout
24595
24596 \end_deeper
24597 \begin_layout Description
24598 -
24599 \begin_inset ERT
24600 status collapsed
24601
24602 \begin_layout Standard
24603
24604
24605 \backslash
24606 /
24607 \end_layout
24608
24609 \end_inset
24610
24611 -pno-banksel Do not generate BANKSEL assembler directives.
24612 \end_layout
24613
24614 \begin_layout Description
24615 -
24616 \begin_inset ERT
24617 status collapsed
24618
24619 \begin_layout Standard
24620
24621
24622 \backslash
24623 /
24624 \end_layout
24625
24626 \end_inset
24627
24628 -extended Enable extended instruction set/literal offset addressing mode.
24629  Use with care!
24630 \end_layout
24631
24632 \begin_layout Subsubsection
24633 Optimization Options
24634 \end_layout
24635
24636 \begin_layout Description
24637 -
24638 \begin_inset ERT
24639 status collapsed
24640
24641 \begin_layout Standard
24642
24643
24644 \backslash
24645 /
24646 \end_layout
24647
24648 \end_inset
24649
24650 -obanksel=n Set optimization level for inserting BANKSELs.
24651 \newline
24652
24653 \end_layout
24654
24655 \begin_deeper
24656 \begin_layout List
24657 \labelwidthstring 00.00.0000
24658 0 no optimization
24659 \end_layout
24660
24661 \begin_layout List
24662 \labelwidthstring 00.00.0000
24663 1 checks previous used register and if it is the same then does not emit
24664  BANKSEL, accounts only for labels.
24665 \end_layout
24666
24667 \begin_layout List
24668 \labelwidthstring 00.00.0000
24669 2 tries to check the location of (even different) symbols and removes BANKSELs
24670  if they are in the same bank.
24671  
24672 \newline
24673
24674 \emph on
24675 Important: There might be problems if the linker script has data sections
24676  across bank borders!
24677 \end_layout
24678
24679 \end_deeper
24680 \begin_layout Description
24681 -
24682 \begin_inset ERT
24683 status collapsed
24684
24685 \begin_layout Standard
24686
24687
24688 \backslash
24689 /
24690 \end_layout
24691
24692 \end_inset
24693
24694 -denable-peeps Force the usage of peepholes.
24695  Use with care.
24696 \end_layout
24697
24698 \begin_layout Description
24699 -
24700 \begin_inset ERT
24701 status collapsed
24702
24703 \begin_layout Standard
24704
24705
24706 \backslash
24707 /
24708 \end_layout
24709
24710 \end_inset
24711
24712 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24713 \end_layout
24714
24715 \begin_layout Description
24716 -
24717 \begin_inset ERT
24718 status collapsed
24719
24720 \begin_layout Standard
24721
24722
24723 \backslash
24724 /
24725 \end_layout
24726
24727 \end_inset
24728
24729 -optimize-cmp Try to optimize some compares.
24730 \end_layout
24731
24732 \begin_layout Description
24733 -
24734 \begin_inset ERT
24735 status collapsed
24736
24737 \begin_layout Standard
24738
24739
24740 \backslash
24741 /
24742 \end_layout
24743
24744 \end_inset
24745
24746 -optimize-df Analyze the dataflow of the generated code and improve it.
24747 \end_layout
24748
24749 \begin_layout Subsubsection
24750 Assembling Options
24751 \end_layout
24752
24753 \begin_layout Description
24754 -
24755 \begin_inset ERT
24756 status collapsed
24757
24758 \begin_layout Standard
24759
24760
24761 \backslash
24762 /
24763 \end_layout
24764
24765 \end_inset
24766
24767 -asm= Sets the full path and name of an external assembler to call.
24768 \end_layout
24769
24770 \begin_layout Description
24771 -
24772 \begin_inset ERT
24773 status collapsed
24774
24775 \begin_layout Standard
24776
24777
24778 \backslash
24779 /
24780 \end_layout
24781
24782 \end_inset
24783
24784 -mplab-comp MPLAB
24785 \begin_inset LatexCommand \index{PIC16!MPLAB}
24786
24787 \end_inset
24788
24789  compatibility option.
24790  Currently only suppresses special gpasm directives.
24791 \end_layout
24792
24793 \begin_layout Subsubsection
24794 Linking Options
24795 \end_layout
24796
24797 \begin_layout Description
24798 -
24799 \begin_inset ERT
24800 status collapsed
24801
24802 \begin_layout Standard
24803
24804
24805 \backslash
24806 /
24807 \end_layout
24808
24809 \end_inset
24810
24811 -link= Sets the full path and name of an external linker to call.
24812 \end_layout
24813
24814 \begin_layout Description
24815 -
24816 \begin_inset ERT
24817 status collapsed
24818
24819 \begin_layout Standard
24820
24821
24822 \backslash
24823 /
24824 \end_layout
24825
24826 \end_inset
24827
24828 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24829  unitialized data variables with [kword].
24830  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24831 \end_layout
24832
24833 \begin_layout Description
24834 -
24835 \begin_inset ERT
24836 status collapsed
24837
24838 \begin_layout Standard
24839
24840
24841 \backslash
24842 /
24843 \end_layout
24844
24845 \end_inset
24846
24847 -ivt-loc=n Place the interrupt vector table at address 
24848 \emph on
24849 n
24850 \emph default
24851 .
24852  Useful for bootloaders.
24853 \end_layout
24854
24855 \begin_layout Description
24856 -
24857 \begin_inset ERT
24858 status collapsed
24859
24860 \begin_layout Standard
24861
24862
24863 \backslash
24864 /
24865 \end_layout
24866
24867 \end_inset
24868
24869 -nodefaultlibs Do not link default libraries when linking.
24870 \end_layout
24871
24872 \begin_layout Description
24873 -
24874 \begin_inset ERT
24875 status collapsed
24876
24877 \begin_layout Standard
24878
24879
24880 \backslash
24881 /
24882 \end_layout
24883
24884 \end_inset
24885
24886 -use-crt= Use a custom run-time module instead of the defaults.
24887 \end_layout
24888
24889 \begin_layout Description
24890 -
24891 \begin_inset ERT
24892 status collapsed
24893
24894 \begin_layout Standard
24895
24896
24897 \backslash
24898 /
24899 \end_layout
24900
24901 \end_inset
24902
24903 -no-crt Don't link the default run-time modules
24904 \end_layout
24905
24906 \begin_layout Subsubsection
24907 Debugging Options
24908 \end_layout
24909
24910 \begin_layout Standard
24911 Debugging options enable extra debugging information in the output files.
24912 \end_layout
24913
24914 \begin_layout Description
24915 -
24916 \begin_inset ERT
24917 status collapsed
24918
24919 \begin_layout Standard
24920
24921
24922 \backslash
24923 /
24924 \end_layout
24925
24926 \end_inset
24927
24928 -debug-xtra Similar to -
24929 \begin_inset ERT
24930 status collapsed
24931
24932 \begin_layout Standard
24933
24934
24935 \backslash
24936 /
24937 \end_layout
24938
24939 \end_inset
24940
24941 -debug
24942 \begin_inset LatexCommand \index{-\/-debug}
24943
24944 \end_inset
24945
24946 , but dumps more information.
24947 \end_layout
24948
24949 \begin_layout Description
24950 -
24951 \begin_inset ERT
24952 status collapsed
24953
24954 \begin_layout Standard
24955
24956
24957 \backslash
24958 /
24959 \end_layout
24960
24961 \end_inset
24962
24963 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24964  information.
24965  <source> is the name of the file being compiled.
24966 \end_layout
24967
24968 \begin_layout Description
24969 -
24970 \begin_inset ERT
24971 status collapsed
24972
24973 \begin_layout Standard
24974
24975
24976 \backslash
24977 /
24978 \end_layout
24979
24980 \end_inset
24981
24982 -pcode-verbose Enable pcode debugging information in translation.
24983 \end_layout
24984
24985 \begin_layout Description
24986 -
24987 \begin_inset ERT
24988 status collapsed
24989
24990 \begin_layout Standard
24991
24992
24993 \backslash
24994 /
24995 \end_layout
24996
24997 \end_inset
24998
24999 -calltree Dump call tree in .calltree file.
25000 \end_layout
25001
25002 \begin_layout Description
25003 -
25004 \begin_inset ERT
25005 status collapsed
25006
25007 \begin_layout Standard
25008
25009
25010 \backslash
25011 /
25012 \end_layout
25013
25014 \end_inset
25015
25016 -gstack Trace push/pops for stack pointer overflow.
25017 \end_layout
25018
25019 \begin_layout Subsection
25020 Enviroment Variables
25021 \end_layout
25022
25023 \begin_layout Standard
25024 There is a number of enviromental variables that can be used when running
25025  SDCC to enable certain optimizations or force a specific program behaviour.
25026  these variables are primarily for debugging purposes so they can be enabled/dis
25027 abled at will.
25028 \end_layout
25029
25030 \begin_layout Standard
25031 Currently there is only two such variables available:
25032 \end_layout
25033
25034 \begin_layout Description
25035 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25036  bitfields is optimized by directly loading FSR0 with the address of the
25037  bitfield structure.
25038  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25039  then load FSR0.
25040  This step saves data ram and code space for functions that make heavy use
25041  of bitfields.
25042  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25043  option).
25044  
25045 \end_layout
25046
25047 \begin_layout Description
25048 NO_REG_OPT Do not perform pCode registers optimization.
25049  This should be used for debugging purposes.
25050  If bugs in the pcode optimizer are found, users can benefit from temporarily
25051  disabling the optimizer until the bug is fixed.
25052 \end_layout
25053
25054 \begin_layout Subsection
25055 Preprocessor Macros
25056 \end_layout
25057
25058 \begin_layout Standard
25059 PIC16
25060 \begin_inset LatexCommand \index{PIC16}
25061
25062 \end_inset
25063
25064  port defines the following preprocessor macros while translating a source.
25065 \end_layout
25066
25067 \begin_layout Standard
25068 \align center
25069 \begin_inset Tabular
25070 <lyxtabular version="3" rows="6" columns="2">
25071 <features>
25072 <column alignment="center" valignment="top" leftline="true" width="0">
25073 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25074 <row topline="true" bottomline="true">
25075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25076 \begin_inset Text
25077
25078 \begin_layout Standard
25079 Macro
25080 \end_layout
25081
25082 \end_inset
25083 </cell>
25084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25085 \begin_inset Text
25086
25087 \begin_layout Standard
25088 Description
25089 \end_layout
25090
25091 \end_inset
25092 </cell>
25093 </row>
25094 <row topline="true">
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25096 \begin_inset Text
25097
25098 \begin_layout Standard
25099 SDCC_pic16
25100 \end_layout
25101
25102 \end_inset
25103 </cell>
25104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25105 \begin_inset Text
25106
25107 \begin_layout Standard
25108 Port identification
25109 \end_layout
25110
25111 \end_inset
25112 </cell>
25113 </row>
25114 <row topline="true">
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25116 \begin_inset Text
25117
25118 \begin_layout Standard
25119 _
25120 \begin_inset ERT
25121 status collapsed
25122
25123 \begin_layout Standard
25124
25125
25126 \backslash
25127 /
25128 \end_layout
25129
25130 \end_inset
25131
25132 _pic16
25133 \end_layout
25134
25135 \end_inset
25136 </cell>
25137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25138 \begin_inset Text
25139
25140 \begin_layout Standard
25141 Port identification (same as above)
25142 \end_layout
25143
25144 \end_inset
25145 </cell>
25146 </row>
25147 <row topline="true">
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25149 \begin_inset Text
25150
25151 \begin_layout Standard
25152 pic18fxxxx
25153 \end_layout
25154
25155 \end_inset
25156 </cell>
25157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25158 \begin_inset Text
25159
25160 \begin_layout Standard
25161 MCU Identification.
25162  
25163 \emph on
25164 xxxx
25165 \emph default
25166  is the microcontrol identification number, i.e.
25167  452, 6620, etc
25168 \end_layout
25169
25170 \end_inset
25171 </cell>
25172 </row>
25173 <row topline="true">
25174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25175 \begin_inset Text
25176
25177 \begin_layout Standard
25178 _
25179 \begin_inset ERT
25180 status collapsed
25181
25182 \begin_layout Standard
25183
25184
25185 \backslash
25186 /
25187 \end_layout
25188
25189 \end_inset
25190
25191 _18Fxxxx
25192 \end_layout
25193
25194 \end_inset
25195 </cell>
25196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25197 \begin_inset Text
25198
25199 \begin_layout Standard
25200 MCU Identification (same as above)
25201 \end_layout
25202
25203 \end_inset
25204 </cell>
25205 </row>
25206 <row topline="true" bottomline="true">
25207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 \begin_inset Text
25209
25210 \begin_layout Standard
25211 STACK_MODEL_nnn
25212 \end_layout
25213
25214 \end_inset
25215 </cell>
25216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25217 \begin_inset Text
25218
25219 \begin_layout Standard
25220 nnn = SMALL or LARGE respectively according to the stack model used
25221 \end_layout
25222
25223 \end_inset
25224 </cell>
25225 </row>
25226 </lyxtabular>
25227
25228 \end_inset
25229
25230
25231 \end_layout
25232
25233 \begin_layout Standard
25234 In addition the following macros are defined when calling assembler:
25235 \end_layout
25236
25237 \begin_layout Standard
25238 \align center
25239 \begin_inset Tabular
25240 <lyxtabular version="3" rows="4" columns="2">
25241 <features>
25242 <column alignment="center" valignment="top" leftline="true" width="0">
25243 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25244 <row topline="true" bottomline="true">
25245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25246 \begin_inset Text
25247
25248 \begin_layout Standard
25249 Macro
25250 \end_layout
25251
25252 \end_inset
25253 </cell>
25254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25255 \begin_inset Text
25256
25257 \begin_layout Standard
25258 Description
25259 \end_layout
25260
25261 \end_inset
25262 </cell>
25263 </row>
25264 <row topline="true">
25265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25266 \begin_inset Text
25267
25268 \begin_layout Standard
25269 __18Fxxxx
25270 \end_layout
25271
25272 \end_inset
25273 </cell>
25274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25275 \begin_inset Text
25276
25277 \begin_layout Standard
25278 MCU Identification.
25279  
25280 \emph on
25281 xxxx
25282 \emph default
25283  is the microcontrol identification number, i.e.
25284  452, 6620, etc
25285 \end_layout
25286
25287 \end_inset
25288 </cell>
25289 </row>
25290 <row topline="true">
25291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25292 \begin_inset Text
25293
25294 \begin_layout Standard
25295 SDCC_MODEL_nnn
25296 \end_layout
25297
25298 \end_inset
25299 </cell>
25300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25301 \begin_inset Text
25302
25303 \begin_layout Standard
25304 nnn = SMALL or LARGE respectively according to the memory model used for
25305  SDCC
25306 \end_layout
25307
25308 \end_inset
25309 </cell>
25310 </row>
25311 <row topline="true" bottomline="true">
25312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25313 \begin_inset Text
25314
25315 \begin_layout Standard
25316 STACK_MODEL_nnn
25317 \end_layout
25318
25319 \end_inset
25320 </cell>
25321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25322 \begin_inset Text
25323
25324 \begin_layout Standard
25325 nnn = SMALL or LARGE respectively according to the stack model used
25326 \end_layout
25327
25328 \end_inset
25329 </cell>
25330 </row>
25331 </lyxtabular>
25332
25333 \end_inset
25334
25335
25336 \end_layout
25337
25338 \begin_layout Subsection
25339 Directories
25340 \end_layout
25341
25342 \begin_layout Standard
25343 PIC16
25344 \begin_inset LatexCommand \index{PIC16}
25345
25346 \end_inset
25347
25348  port uses the following directories for searching header files and libraries.
25349 \end_layout
25350
25351 \begin_layout Standard
25352 \align center
25353 \begin_inset Tabular
25354 <lyxtabular version="3" rows="3" columns="4">
25355 <features>
25356 <column alignment="center" valignment="top" leftline="true" width="0">
25357 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25358 <column alignment="center" valignment="top" width="0">
25359 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25360 <row topline="true" bottomline="true">
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25362 \begin_inset Text
25363
25364 \begin_layout Standard
25365 Directory
25366 \end_layout
25367
25368 \end_inset
25369 </cell>
25370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25371 \begin_inset Text
25372
25373 \begin_layout Standard
25374 Description
25375 \end_layout
25376
25377 \end_inset
25378 </cell>
25379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25380 \begin_inset Text
25381
25382 \begin_layout Standard
25383 Target
25384 \end_layout
25385
25386 \end_inset
25387 </cell>
25388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25389 \begin_inset Text
25390
25391 \begin_layout Standard
25392 Command prefix
25393 \end_layout
25394
25395 \end_inset
25396 </cell>
25397 </row>
25398 <row topline="true">
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25400 \begin_inset Text
25401
25402 \begin_layout Standard
25403 PREFIX/sdcc/include/pic16
25404 \end_layout
25405
25406 \end_inset
25407 </cell>
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25409 \begin_inset Text
25410
25411 \begin_layout Standard
25412 PIC16 specific headers
25413 \end_layout
25414
25415 \end_inset
25416 </cell>
25417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25418 \begin_inset Text
25419
25420 \begin_layout Standard
25421 Compiler
25422 \end_layout
25423
25424 \end_inset
25425 </cell>
25426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25427 \begin_inset Text
25428
25429 \begin_layout Standard
25430 -I
25431 \end_layout
25432
25433 \end_inset
25434 </cell>
25435 </row>
25436 <row topline="true" bottomline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25438 \begin_inset Text
25439
25440 \begin_layout Standard
25441 PREFIX/sdcc/lib/pic16
25442 \end_layout
25443
25444 \end_inset
25445 </cell>
25446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25447 \begin_inset Text
25448
25449 \begin_layout Standard
25450 PIC16 specific libraries
25451 \end_layout
25452
25453 \end_inset
25454 </cell>
25455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25456 \begin_inset Text
25457
25458 \begin_layout Standard
25459 Linker
25460 \end_layout
25461
25462 \end_inset
25463 </cell>
25464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25465 \begin_inset Text
25466
25467 \begin_layout Standard
25468 -L
25469 \end_layout
25470
25471 \end_inset
25472 </cell>
25473 </row>
25474 </lyxtabular>
25475
25476 \end_inset
25477
25478
25479 \end_layout
25480
25481 \begin_layout Subsection
25482 Pragmas
25483 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25484
25485 \end_inset
25486
25487
25488 \end_layout
25489
25490 \begin_layout Standard
25491 The PIC16
25492 \begin_inset LatexCommand \index{PIC16}
25493
25494 \end_inset
25495
25496  port currently supports the following pragmas:
25497 \end_layout
25498
25499 \begin_layout Description
25500 stack
25501 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25502
25503 \end_inset
25504
25505  This forces the code generator to initialize the stack & frame pointers
25506  at a specific address.
25507  This is an ad hoc solution for cases where no STACK directive is available
25508  in the linker script or gplink is not instructed to create a stack section.
25509 \newline
25510 The
25511  stack pragma should be used only once in a project.
25512  Multiple pragmas may result in indeterminate behaviour of the program.
25513 \begin_inset Foot
25514 status open
25515
25516 \begin_layout Standard
25517 The old format (ie.
25518  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25519  cross page boundaries (or even exceed the available data RAM) and crash
25520  the program.
25521  Make sure that stack does not cross page boundaries when using the SMALL
25522  stack model.
25523 \end_layout
25524
25525 \end_inset
25526
25527
25528 \newline
25529 The format is as follows:
25530 \newline
25531
25532 \end_layout
25533
25534 \begin_layout LyX-Code
25535 #pragma stack bottom_address [stack_size]
25536 \newline
25537
25538 \end_layout
25539
25540 \begin_layout Standard
25541
25542 \emph on
25543 bottom_address
25544 \emph default
25545  is the lower bound of the stack section.
25546  The stack pointer initially will point at address (bottom_address+stack_size-1).
25547 \end_layout
25548
25549 \begin_layout LyX-Code
25550 Example:
25551 \end_layout
25552
25553 \begin_layout LyX-Code
25554
25555 \end_layout
25556
25557 \begin_layout LyX-Code
25558 /* initializes stack of 100 bytes at RAM address 0x200 */
25559 \end_layout
25560
25561 \begin_layout LyX-Code
25562 #pragma stack 0x200 100
25563 \end_layout
25564
25565 \begin_layout Standard
25566 If the stack_size field is omitted then a stack is created with the default
25567  size of 64.
25568  This size might be enough for most programs, but its not enough for operations
25569  with deep function nesting or excessive stack usage.
25570 \end_layout
25571
25572 \begin_layout Description
25573 code
25574 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25575
25576 \end_inset
25577
25578  Force a function to a static FLASH address.
25579 \end_layout
25580
25581 \begin_layout LyX-Code
25582 Example:
25583 \end_layout
25584
25585 \begin_layout LyX-Code
25586
25587 \end_layout
25588
25589 \begin_layout LyX-Code
25590 /* place function test_func at 0x4000 */
25591 \end_layout
25592
25593 \begin_layout LyX-Code
25594 #pragma code test_func 0x4000
25595 \end_layout
25596
25597 \begin_layout LyX-Code
25598
25599 \end_layout
25600
25601 \begin_layout Description
25602 library instructs the linker to use a library module.
25603 \newline
25604 Usage:
25605 \end_layout
25606
25607 \begin_layout LyX-Code
25608 #pragma library module_name
25609 \end_layout
25610
25611 \begin_layout Standard
25612
25613 \emph on
25614 module_name
25615 \emph default
25616  can be any library or object file (including its path).
25617  Note that there are four reserved keywords which have special meaning.
25618  These are:
25619 \end_layout
25620
25621 \begin_layout Standard
25622 \align center
25623 \begin_inset Tabular
25624 <lyxtabular version="3" rows="6" columns="3">
25625 <features>
25626 <column alignment="center" valignment="top" leftline="true" width="0">
25627 <column alignment="block" valignment="top" leftline="true" width="20page%">
25628 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25629 <row topline="true" bottomline="true">
25630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25631 \begin_inset Text
25632
25633 \begin_layout Standard
25634 Keyword
25635 \end_layout
25636
25637 \end_inset
25638 </cell>
25639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25640 \begin_inset Text
25641
25642 \begin_layout Standard
25643 Description
25644 \end_layout
25645
25646 \end_inset
25647 </cell>
25648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25649 \begin_inset Text
25650
25651 \begin_layout Standard
25652 Module to link
25653 \end_layout
25654
25655 \end_inset
25656 </cell>
25657 </row>
25658 <row topline="true">
25659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25660 \begin_inset Text
25661
25662 \begin_layout Standard
25663
25664 \series bold
25665 ignore
25666 \end_layout
25667
25668 \end_inset
25669 </cell>
25670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25671 \begin_inset Text
25672
25673 \begin_layout Standard
25674 ignore all library pragmas
25675 \end_layout
25676
25677 \end_inset
25678 </cell>
25679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25680 \begin_inset Text
25681
25682 \begin_layout Standard
25683
25684 \emph on
25685 (none)
25686 \end_layout
25687
25688 \end_inset
25689 </cell>
25690 </row>
25691 <row topline="true">
25692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25693 \begin_inset Text
25694
25695 \begin_layout Standard
25696
25697 \series bold
25698 c
25699 \end_layout
25700
25701 \end_inset
25702 </cell>
25703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25704 \begin_inset Text
25705
25706 \begin_layout Standard
25707 link the C library
25708 \end_layout
25709
25710 \end_inset
25711 </cell>
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25713 \begin_inset Text
25714
25715 \begin_layout Standard
25716
25717 \emph on
25718 libc18f
25719 \emph default
25720 .lib
25721 \end_layout
25722
25723 \end_inset
25724 </cell>
25725 </row>
25726 <row topline="true">
25727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25728 \begin_inset Text
25729
25730 \begin_layout Standard
25731
25732 \series bold
25733 math
25734 \end_layout
25735
25736 \end_inset
25737 </cell>
25738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25739 \begin_inset Text
25740
25741 \begin_layout Standard
25742 link the Math libarary
25743 \end_layout
25744
25745 \end_inset
25746 </cell>
25747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25748 \begin_inset Text
25749
25750 \begin_layout Standard
25751
25752 \emph on
25753 libm18f
25754 \emph default
25755 .lib
25756 \end_layout
25757
25758 \end_inset
25759 </cell>
25760 </row>
25761 <row topline="true">
25762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25763 \begin_inset Text
25764
25765 \begin_layout Standard
25766
25767 \series bold
25768 io
25769 \end_layout
25770
25771 \end_inset
25772 </cell>
25773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25774 \begin_inset Text
25775
25776 \begin_layout Standard
25777 link the I/O library
25778 \end_layout
25779
25780 \end_inset
25781 </cell>
25782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25783 \begin_inset Text
25784
25785 \begin_layout Standard
25786
25787 \emph on
25788 libio18f*
25789 \emph default
25790 .lib
25791 \end_layout
25792
25793 \end_inset
25794 </cell>
25795 </row>
25796 <row topline="true" bottomline="true">
25797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25798 \begin_inset Text
25799
25800 \begin_layout Standard
25801
25802 \series bold
25803 debug
25804 \end_layout
25805
25806 \end_inset
25807 </cell>
25808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25809 \begin_inset Text
25810
25811 \begin_layout Standard
25812 link the debug library
25813 \end_layout
25814
25815 \end_inset
25816 </cell>
25817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25818 \begin_inset Text
25819
25820 \begin_layout Standard
25821
25822 \emph on
25823 libdebug
25824 \emph default
25825 .lib
25826 \end_layout
25827
25828 \end_inset
25829 </cell>
25830 </row>
25831 </lyxtabular>
25832
25833 \end_inset
25834
25835
25836 \newline
25837 * is the device number, i.e.
25838  452 for PIC18F452 MCU.
25839 \end_layout
25840
25841 \begin_layout Standard
25842 This feature allows for linking with specific libraries withoug having to
25843  explicit name them in the command line.
25844  Note that the 
25845 \noun on
25846 ignore
25847 \noun default
25848  keyword will reject all modules specified by the library pragma.
25849 \end_layout
25850
25851 \begin_layout Description
25852 udata The pragma udata instructs the compiler to emit code so that linker
25853  will place a variable at a specific memory bank.
25854 \end_layout
25855
25856 \begin_layout LyX-Code
25857 Example:
25858 \end_layout
25859
25860 \begin_layout LyX-Code
25861
25862 \end_layout
25863
25864 \begin_layout LyX-Code
25865 /* places variable foo at bank2 */
25866 \end_layout
25867
25868 \begin_layout LyX-Code
25869 #pragma udata bank2 foo
25870 \end_layout
25871
25872 \begin_layout LyX-Code
25873 char foo;
25874 \end_layout
25875
25876 \begin_layout Standard
25877 In order for this pragma to work extra SECTION directives should be added
25878  in the .lkr script.
25879  In the following example a sample .lkr file is shown:
25880 \end_layout
25881
25882 \begin_layout LyX-Code
25883
25884 \end_layout
25885
25886 \begin_layout LyX-Code
25887 // Sample linker script for the PIC18F452 processor
25888 \end_layout
25889
25890 \begin_layout LyX-Code
25891 LIBPATH .
25892 \end_layout
25893
25894 \begin_layout LyX-Code
25895 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25896 \end_layout
25897
25898 \begin_layout LyX-Code
25899 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25900 \end_layout
25901
25902 \begin_layout LyX-Code
25903 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25904 \end_layout
25905
25906 \begin_layout LyX-Code
25907 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25908 \end_layout
25909
25910 \begin_layout LyX-Code
25911 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25912 \end_layout
25913
25914 \begin_layout LyX-Code
25915 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25916 \end_layout
25917
25918 \begin_layout LyX-Code
25919 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25920 \end_layout
25921
25922 \begin_layout LyX-Code
25923
25924 \end_layout
25925
25926 \begin_layout LyX-Code
25927 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25928 \end_layout
25929
25930 \begin_layout LyX-Code
25931 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25932 \end_layout
25933
25934 \begin_layout LyX-Code
25935 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25936 \end_layout
25937
25938 \begin_layout LyX-Code
25939 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25940 \end_layout
25941
25942 \begin_layout LyX-Code
25943 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25944 \end_layout
25945
25946 \begin_layout LyX-Code
25947 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25948 \end_layout
25949
25950 \begin_layout LyX-Code
25951 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25952 \end_layout
25953
25954 \begin_layout LyX-Code
25955
25956 \end_layout
25957
25958 \begin_layout LyX-Code
25959 SECTION    NAME=CONFIG     ROM=config
25960 \end_layout
25961
25962 \begin_layout LyX-Code
25963
25964 \end_layout
25965
25966 \begin_layout LyX-Code
25967 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25968 \end_layout
25969
25970 \begin_layout LyX-Code
25971 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25972 \end_layout
25973
25974 \begin_layout LyX-Code
25975 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25976 \end_layout
25977
25978 \begin_layout LyX-Code
25979 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25980 \end_layout
25981
25982 \begin_layout LyX-Code
25983 SECTION    NAME=bank4      RAM=gpr4
25984 \end_layout
25985
25986 \begin_layout LyX-Code
25987 SECTION    NAME=bank5      RAM=gpr5
25988 \end_layout
25989
25990 \begin_layout Standard
25991 The linker will recognise the section name set in the pragma statement and
25992  will position the variable at the memory bank set with the RAM field at
25993  the SECTION line in the linker script file.
25994 \end_layout
25995
25996 \begin_layout Subsection
25997 Header Files
25998 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25999
26000 \end_inset
26001
26002
26003 \end_layout
26004
26005 \begin_layout Standard
26006 There is one main header file
26007 \begin_inset LatexCommand \index{PIC16!Header files}
26008
26009 \end_inset
26010
26011  that can be included to the source files using the pic16
26012 \begin_inset LatexCommand \index{PIC16}
26013
26014 \end_inset
26015
26016  port.
26017  That file is the 
26018 \series bold
26019 pic18fregs.h
26020 \series default
26021 .
26022  This header file contains the definitions for the processor special registers,
26023  so it is necessary if the source accesses them.
26024  It can be included by adding the following line in the beginning of the
26025  file:
26026 \end_layout
26027
26028 \begin_layout LyX-Code
26029 #include <pic18fregs.h>
26030 \end_layout
26031
26032 \begin_layout Standard
26033 The specific microcontroller is selected within the pic18fregs.h automatically,
26034  so the same source can be used with a variety of devices.
26035 \end_layout
26036
26037 \begin_layout Subsection
26038 Libraries
26039 \end_layout
26040
26041 \begin_layout Standard
26042 The libraries
26043 \begin_inset LatexCommand \index{PIC16!Libraries}
26044
26045 \end_inset
26046
26047  that PIC16
26048 \begin_inset LatexCommand \index{PIC16}
26049
26050 \end_inset
26051
26052  port depends on are the microcontroller device libraries which contain
26053  the symbol definitions for the microcontroller special function registers.
26054  These libraries have the format pic18fxxxx.lib, where 
26055 \emph on
26056 xxxx
26057 \emph default
26058  is the microcontroller identification number.
26059  The specific library is selected automatically by the compiler at link
26060  stage according to the selected device.
26061 \end_layout
26062
26063 \begin_layout Standard
26064 Libraries are created with gplib which is part of the gputils package 
26065 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26066
26067 \end_inset
26068
26069 .
26070 \end_layout
26071
26072 \begin_layout Subsubsection*
26073 Building the libraries
26074 \end_layout
26075
26076 \begin_layout Standard
26077 Before using SDCC/pic16 there are some libraries that need to be compiled.
26078  This process is not done automatically by SDCC since not all users use
26079  SDCC for pic16 projects.
26080  So each user should compile the libraries separately.
26081 \end_layout
26082
26083 \begin_layout Standard
26084 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26085 \end_layout
26086
26087 \begin_layout LyX-Code
26088 cd device/lib/pic16
26089 \end_layout
26090
26091 \begin_layout LyX-Code
26092 ./configure
26093 \end_layout
26094
26095 \begin_layout LyX-Code
26096 make
26097 \end_layout
26098
26099 \begin_layout LyX-Code
26100 cd ..
26101 \end_layout
26102
26103 \begin_layout LyX-Code
26104 make model-pic16
26105 \end_layout
26106
26107 \begin_layout LyX-Code
26108 su -c 'make install'     # install the libraries, you need the root password
26109 \end_layout
26110
26111 \begin_layout Standard
26112 If you need to install the headers too, do:
26113 \end_layout
26114
26115 \begin_layout LyX-Code
26116 cd device/include
26117 \end_layout
26118
26119 \begin_layout LyX-Code
26120 su -c 'make install'     # install the headers, you need the root password
26121 \end_layout
26122
26123 \begin_layout Standard
26124 There exist a special target to build the I/O libraries.
26125  This target is not automatically build because it will build the I/O library
26126  for 
26127 \emph on
26128 every
26129 \emph default
26130  supported device.
26131  This way building will take quite a lot of time.
26132  Users are advised to edit the 
26133 \series bold
26134 device/lib/pic16/pics.build
26135 \series default
26136  file and then execute:
26137 \end_layout
26138
26139 \begin_layout LyX-Code
26140 make lib-io
26141 \end_layout
26142
26143 \begin_layout Subsection
26144 Adding New Devices to the Port
26145 \end_layout
26146
26147 \begin_layout Standard
26148 Adding support for a new 16
26149 \begin_inset ERT
26150 status open
26151
26152 \begin_layout Standard
26153
26154
26155 \backslash
26156 ,
26157 \end_layout
26158
26159 \end_inset
26160
26161 bit PIC MCU requires the following steps:
26162 \end_layout
26163
26164 \begin_layout Enumerate
26165 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26166 \newline
26167
26168 \family typewriter
26169 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26170 inc
26171 \end_layout
26172
26173 \begin_layout Enumerate
26174
26175 \family typewriter
26176 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26177 \end_layout
26178
26179 \begin_layout Enumerate
26180
26181 \family typewriter
26182 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26183 \end_layout
26184
26185 \begin_layout Enumerate
26186 Add DEVICE to 
26187 \family typewriter
26188 /path/to/sdcc/device/lib/pic16/pics.all
26189 \family default
26190  (and 
26191 \family typewriter
26192 .build
26193 \family default
26194 ).
26195 \newline
26196 Note: No 18f prefix here!
26197 \end_layout
26198
26199 \begin_layout Enumerate
26200 Adjust 
26201 \family typewriter
26202 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26203 \family default
26204
26205 \newline
26206 Add your DEVICE if it does not compile in 
26207 \family typewriter
26208 adc
26209 \family default
26210
26211 \family typewriter
26212 i2c
26213 \family default
26214 , or 
26215 \family typewriter
26216 usart
26217 \family default
26218 .
26219 \end_layout
26220
26221 \begin_layout Enumerate
26222 Edit 
26223 \family typewriter
26224 /path/to/sdcc/device/include/pic16/pic18fregs.h
26225 \family default
26226 .
26227  The file format is self-explanatory, just add
26228 \newline
26229
26230 \family typewriter
26231 #elif defined(picDEVICE)
26232 \newline
26233 # include <picDEVICE.h>
26234 \family default
26235
26236 \newline
26237 at the right place (keep it sorted).
26238 \end_layout
26239
26240 \begin_layout Enumerate
26241 Edit 
26242 \family typewriter
26243 /path/to/sdcc/src/pic16/devices.inc
26244 \family default
26245 .
26246  Copy and modify an existing entry and insert it at the correct place (keep
26247  the file sorted).
26248  The file is hardly documented, look at the entries for the 18f2221...
26249 \end_layout
26250
26251 \begin_layout Enumerate
26252 Recompile SDCC, including the pic16 libraries.
26253 \end_layout
26254
26255 \begin_layout Subsection
26256 Memory Models
26257 \end_layout
26258
26259 \begin_layout Standard
26260 The following memory models are supported by the PIC16 port:
26261 \end_layout
26262
26263 \begin_layout Itemize
26264 small model
26265 \end_layout
26266
26267 \begin_layout Itemize
26268 large model
26269 \end_layout
26270
26271 \begin_layout Standard
26272 Memory model affects the default size of pointers within the source.
26273  The sizes are shown in the next table:
26274 \end_layout
26275
26276 \begin_layout Standard
26277 \align center
26278 \begin_inset Tabular
26279 <lyxtabular version="3" rows="3" columns="3">
26280 <features>
26281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26282 <column alignment="center" valignment="top" leftline="true" width="0">
26283 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26284 <row topline="true" bottomline="true">
26285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26286 \begin_inset Text
26287
26288 \begin_layout Standard
26289 Pointer sizes according to memory model
26290 \end_layout
26291
26292 \end_inset
26293 </cell>
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26295 \begin_inset Text
26296
26297 \begin_layout Standard
26298 small model
26299 \end_layout
26300
26301 \end_inset
26302 </cell>
26303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26304 \begin_inset Text
26305
26306 \begin_layout Standard
26307 large model
26308 \end_layout
26309
26310 \end_inset
26311 </cell>
26312 </row>
26313 <row topline="true" bottomline="true">
26314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26315 \begin_inset Text
26316
26317 \begin_layout Standard
26318 code pointers
26319 \end_layout
26320
26321 \end_inset
26322 </cell>
26323 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26324 \begin_inset Text
26325
26326 \begin_layout Standard
26327 16-bits
26328 \end_layout
26329
26330 \end_inset
26331 </cell>
26332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26333 \begin_inset Text
26334
26335 \begin_layout Standard
26336 24-bits
26337 \end_layout
26338
26339 \end_inset
26340 </cell>
26341 </row>
26342 <row topline="true" bottomline="true">
26343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26344 \begin_inset Text
26345
26346 \begin_layout Standard
26347 data pointers
26348 \end_layout
26349
26350 \end_inset
26351 </cell>
26352 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26353 \begin_inset Text
26354
26355 \begin_layout Standard
26356 16-bits
26357 \end_layout
26358
26359 \end_inset
26360 </cell>
26361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26362 \begin_inset Text
26363
26364 \begin_layout Standard
26365 16-bits
26366 \end_layout
26367
26368 \end_inset
26369 </cell>
26370 </row>
26371 </lyxtabular>
26372
26373 \end_inset
26374
26375
26376 \end_layout
26377
26378 \begin_layout Standard
26379 It is advisable that all sources within a project are compiled with the
26380  same memory model.
26381  If one wants to override the default memory model, this can be done by
26382  declaring a pointer as 
26383 \series bold
26384 far
26385 \series default
26386  or 
26387 \series bold
26388 near
26389 \series default
26390 .
26391  Far selects large memory model's pointers, while near selects small memory
26392  model's pointers.
26393 \end_layout
26394
26395 \begin_layout Standard
26396 The standard device libraries (see 
26397 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26398
26399 \end_inset
26400
26401 ) contain no reference to pointers, so they can be used with both memory
26402  models.
26403 \end_layout
26404
26405 \begin_layout Subsection
26406 Stack
26407 \end_layout
26408
26409 \begin_layout Standard
26410 The stack
26411 \begin_inset LatexCommand \index{PIC16!stack}
26412
26413 \end_inset
26414
26415  implementation for the PIC16 port uses two indirect registers, FSR1 and
26416  FSR2.
26417 \end_layout
26418
26419 \begin_layout Description
26420 FSR1 is assigned as stack pointer
26421 \end_layout
26422
26423 \begin_layout Description
26424 FSR2 is assigned as frame pointer
26425 \end_layout
26426
26427 \begin_layout Standard
26428 The following stack models are supported by the PIC16 port
26429 \end_layout
26430
26431 \begin_layout Itemize
26432
26433 \noun on
26434 small
26435 \noun default
26436  model
26437 \end_layout
26438
26439 \begin_layout Itemize
26440
26441 \noun on
26442 large
26443 \noun default
26444  model
26445 \end_layout
26446
26447 \begin_layout Standard
26448
26449 \noun on
26450 Small
26451 \noun default
26452  model means that only the FSRxL byte is used to access stack and frame,
26453  while 
26454 \emph on
26455 \noun on
26456 large
26457 \emph default
26458 \noun default
26459  uses both FSRxL and FSRxH registers.
26460  The following table shows the stack/frame pointers sizes according to stack
26461  model and the maximum space they can address:
26462 \end_layout
26463
26464 \begin_layout Standard
26465 \align center
26466 \begin_inset Tabular
26467 <lyxtabular version="3" rows="3" columns="3">
26468 <features>
26469 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26470 <column alignment="center" valignment="top" leftline="true" width="0">
26471 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26472 <row topline="true" bottomline="true">
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26474 \begin_inset Text
26475
26476 \begin_layout Standard
26477 Stack & Frame pointer sizes according to stack model
26478 \end_layout
26479
26480 \end_inset
26481 </cell>
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26483 \begin_inset Text
26484
26485 \begin_layout Standard
26486 small
26487 \end_layout
26488
26489 \end_inset
26490 </cell>
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \begin_layout Standard
26495 large
26496 \end_layout
26497
26498 \end_inset
26499 </cell>
26500 </row>
26501 <row topline="true">
26502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26503 \begin_inset Text
26504
26505 \begin_layout Standard
26506 Stack pointer FSR1
26507 \end_layout
26508
26509 \end_inset
26510 </cell>
26511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26512 \begin_inset Text
26513
26514 \begin_layout Standard
26515 8-bits
26516 \end_layout
26517
26518 \end_inset
26519 </cell>
26520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26521 \begin_inset Text
26522
26523 \begin_layout Standard
26524 16-bits
26525 \end_layout
26526
26527 \end_inset
26528 </cell>
26529 </row>
26530 <row topline="true" bottomline="true">
26531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26532 \begin_inset Text
26533
26534 \begin_layout Standard
26535 Frame pointer FSR2
26536 \end_layout
26537
26538 \end_inset
26539 </cell>
26540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26541 \begin_inset Text
26542
26543 \begin_layout Standard
26544 8-bits
26545 \end_layout
26546
26547 \end_inset
26548 </cell>
26549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26550 \begin_inset Text
26551
26552 \begin_layout Standard
26553 16-bits
26554 \end_layout
26555
26556 \end_inset
26557 </cell>
26558 </row>
26559 </lyxtabular>
26560
26561 \end_inset
26562
26563
26564 \end_layout
26565
26566 \begin_layout Standard
26567
26568 \noun on
26569 Large 
26570 \noun default
26571 stack model is currently not working properly throughout the code generator.
26572  So its use is not advised.
26573  Also there are some other points that need special care:
26574 \newline
26575
26576 \end_layout
26577
26578 \begin_layout Enumerate
26579 Do not create stack sections with size more than one physical bank (that
26580  is 256 bytes)
26581 \end_layout
26582
26583 \begin_layout Enumerate
26584 Stack sections should no cross physical bank limits (i.e.
26585  #pragma stack 0x50 0x100)
26586 \end_layout
26587
26588 \begin_layout Standard
26589 These limitations are caused by the fact that only FSRxL is modified when
26590  using SMALL stack model, so no more than 256 bytes of stack can be used.
26591  This problem will disappear after LARGE model is fully implemented.
26592 \end_layout
26593
26594 \begin_layout Subsection
26595 Functions
26596 \end_layout
26597
26598 \begin_layout Standard
26599 In addition to the standard SDCC function keywords, PIC16
26600 \begin_inset LatexCommand \index{PIC16}
26601
26602 \end_inset
26603
26604  port makes available two more:
26605 \end_layout
26606
26607 \begin_layout Description
26608 wparam
26609 \begin_inset LatexCommand \index{PIC16!wparam}
26610
26611 \end_inset
26612
26613  Use the WREG to pass one byte of the first function argument.
26614  This improves speed but you may not use this for functions with arguments
26615  that are called via function pointers, otherwise the first byte of the
26616  first parameter will get lost.
26617  Usage:
26618 \end_layout
26619
26620 \begin_layout LyX-Code
26621 void func_wparam(int a) wparam
26622 \end_layout
26623
26624 \begin_layout LyX-Code
26625 {
26626 \end_layout
26627
26628 \begin_layout LyX-Code
26629     /* WREG hold the lower part of a */
26630 \end_layout
26631
26632 \begin_layout LyX-Code
26633     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26634  */
26635 \end_layout
26636
26637 \begin_layout LyX-Code
26638 ...
26639 \end_layout
26640
26641 \begin_layout LyX-Code
26642 }
26643 \end_layout
26644
26645 \begin_layout Description
26646 shadowregs
26647 \begin_inset LatexCommand \index{PIC16!shadowregs}
26648
26649 \end_inset
26650
26651  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26652  hardware shadow registers which hold the values of WREG, STATUS and BSR
26653  registers.
26654  This can be done by adding the keyword 
26655 \emph on
26656 shadowregs
26657 \emph default
26658  before the 
26659 \emph on
26660 interrupt
26661 \emph default
26662  keyword in the function's header.
26663 \end_layout
26664
26665 \begin_layout LyX-Code
26666 void isr_shadow(void) shadowregs interrupt 1
26667 \end_layout
26668
26669 \begin_layout LyX-Code
26670 {
26671 \end_layout
26672
26673 \begin_layout LyX-Code
26674 ...
26675 \end_layout
26676
26677 \begin_layout LyX-Code
26678 }
26679 \end_layout
26680
26681 \begin_layout Standard
26682
26683 \emph on
26684 shadowregs
26685 \emph default
26686  instructs the code generator not to store/restore WREG, STATUS, BSR when
26687  entering/exiting the ISR.
26688 \end_layout
26689
26690 \begin_layout Subsection
26691 Function return values
26692 \end_layout
26693
26694 \begin_layout Standard
26695 Return values from functions are placed to the appropriate registers following
26696  a modified Microchip policy optimized for SDCC.
26697  The following table shows these registers:
26698 \end_layout
26699
26700 \begin_layout Standard
26701 \align center
26702 \begin_inset Tabular
26703 <lyxtabular version="3" rows="6" columns="2">
26704 <features>
26705 <column alignment="center" valignment="top" leftline="true" width="0">
26706 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26707 <row topline="true" bottomline="true">
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26709 \begin_inset Text
26710
26711 \begin_layout Standard
26712 size
26713 \end_layout
26714
26715 \end_inset
26716 </cell>
26717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_inset Text
26719
26720 \begin_layout Standard
26721 destination register
26722 \end_layout
26723
26724 \end_inset
26725 </cell>
26726 </row>
26727 <row topline="true">
26728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26729 \begin_inset Text
26730
26731 \begin_layout Standard
26732 8 bits
26733 \end_layout
26734
26735 \end_inset
26736 </cell>
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26738 \begin_inset Text
26739
26740 \begin_layout Standard
26741 WREG
26742 \end_layout
26743
26744 \end_inset
26745 </cell>
26746 </row>
26747 <row topline="true">
26748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26749 \begin_inset Text
26750
26751 \begin_layout Standard
26752 16 bits
26753 \end_layout
26754
26755 \end_inset
26756 </cell>
26757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26758 \begin_inset Text
26759
26760 \begin_layout Standard
26761 PRODL:WREG
26762 \end_layout
26763
26764 \end_inset
26765 </cell>
26766 </row>
26767 <row topline="true">
26768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26769 \begin_inset Text
26770
26771 \begin_layout Standard
26772 24 bits
26773 \end_layout
26774
26775 \end_inset
26776 </cell>
26777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26778 \begin_inset Text
26779
26780 \begin_layout Standard
26781 PRODH:PRODL:WREG
26782 \end_layout
26783
26784 \end_inset
26785 </cell>
26786 </row>
26787 <row topline="true">
26788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26789 \begin_inset Text
26790
26791 \begin_layout Standard
26792 32 bits
26793 \end_layout
26794
26795 \end_inset
26796 </cell>
26797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26798 \begin_inset Text
26799
26800 \begin_layout Standard
26801 FSR0L:PRODH:PRODL:WREG
26802 \end_layout
26803
26804 \end_inset
26805 </cell>
26806 </row>
26807 <row topline="true" bottomline="true">
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26809 \begin_inset Text
26810
26811 \begin_layout Standard
26812 >32 bits
26813 \end_layout
26814
26815 \end_inset
26816 </cell>
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26818 \begin_inset Text
26819
26820 \begin_layout Standard
26821 on stack, FSR0 points to the beginning
26822 \end_layout
26823
26824 \end_inset
26825 </cell>
26826 </row>
26827 </lyxtabular>
26828
26829 \end_inset
26830
26831
26832 \end_layout
26833
26834 \begin_layout Subsection
26835 Interrupts
26836 \end_layout
26837
26838 \begin_layout Standard
26839 An interrupt
26840 \begin_inset LatexCommand \index{PIC16!interrupt}
26841
26842 \end_inset
26843
26844  service routine (ISR) is declared using the 
26845 \emph on
26846 interrupt
26847 \emph default
26848  keyword.
26849 \end_layout
26850
26851 \begin_layout LyX-Code
26852 void isr(void) interrupt 
26853 \emph on
26854 n
26855 \end_layout
26856
26857 \begin_layout LyX-Code
26858 {
26859 \end_layout
26860
26861 \begin_layout LyX-Code
26862 ...
26863 \end_layout
26864
26865 \begin_layout LyX-Code
26866 }
26867 \end_layout
26868
26869 \begin_layout Standard
26870
26871 \emph on
26872 n
26873 \emph default
26874  is the interrupt number, which for PIC18F devices can be:
26875 \end_layout
26876
26877 \begin_layout Standard
26878 \align center
26879 \begin_inset Tabular
26880 <lyxtabular version="3" rows="4" columns="3">
26881 <features>
26882 <column alignment="center" valignment="top" leftline="true" width="0">
26883 <column alignment="center" valignment="top" leftline="true" width="0">
26884 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26885 <row topline="true" bottomline="true">
26886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26887 \begin_inset Text
26888
26889 \begin_layout Standard
26890
26891 \emph on
26892 n
26893 \end_layout
26894
26895 \end_inset
26896 </cell>
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26898 \begin_inset Text
26899
26900 \begin_layout Standard
26901 Interrupt Vector
26902 \end_layout
26903
26904 \end_inset
26905 </cell>
26906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26907 \begin_inset Text
26908
26909 \begin_layout Standard
26910 Interrupt Vector Address
26911 \end_layout
26912
26913 \end_inset
26914 </cell>
26915 </row>
26916 <row topline="true">
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26918 \begin_inset Text
26919
26920 \begin_layout Standard
26921 0
26922 \end_layout
26923
26924 \end_inset
26925 </cell>
26926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26927 \begin_inset Text
26928
26929 \begin_layout Standard
26930 RESET vector
26931 \end_layout
26932
26933 \end_inset
26934 </cell>
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26936 \begin_inset Text
26937
26938 \begin_layout Standard
26939 0x000000
26940 \end_layout
26941
26942 \end_inset
26943 </cell>
26944 </row>
26945 <row topline="true">
26946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26947 \begin_inset Text
26948
26949 \begin_layout Standard
26950
26951 \family roman
26952 \series medium
26953 \shape up
26954 \size normal
26955 \emph off
26956 \bar no
26957 \noun off
26958 \color none
26959 1
26960 \end_layout
26961
26962 \end_inset
26963 </cell>
26964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26965 \begin_inset Text
26966
26967 \begin_layout Standard
26968
26969 \family roman
26970 \series medium
26971 \shape up
26972 \size normal
26973 \emph off
26974 \bar no
26975 \noun off
26976 \color none
26977 HIGH priority interrupts
26978 \end_layout
26979
26980 \end_inset
26981 </cell>
26982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26983 \begin_inset Text
26984
26985 \begin_layout Standard
26986 0x000008
26987 \end_layout
26988
26989 \end_inset
26990 </cell>
26991 </row>
26992 <row topline="true" bottomline="true">
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26994 \begin_inset Text
26995
26996 \begin_layout Standard
26997 2
26998 \end_layout
26999
27000 \end_inset
27001 </cell>
27002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 \begin_inset Text
27004
27005 \begin_layout Standard
27006 LOW priority interrupts
27007 \end_layout
27008
27009 \end_inset
27010 </cell>
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27012 \begin_inset Text
27013
27014 \begin_layout Standard
27015 0x000018
27016 \end_layout
27017
27018 \end_inset
27019 </cell>
27020 </row>
27021 </lyxtabular>
27022
27023 \end_inset
27024
27025
27026 \end_layout
27027
27028 \begin_layout Standard
27029 When generating assembly code for ISR the code generator places a 
27030 \noun on
27031 goto 
27032 \noun default
27033 instruction at the 
27034 \emph on
27035 Interrupt Vector Address
27036 \emph default
27037  which points at the genetated ISR.
27038  This single GOTO instruction is part of an automatically generated 
27039 \emph on
27040 interrupt entry point
27041 \emph default
27042  function.
27043  The actuall ISR code is placed as normally would in the code space.
27044  Upon interrupt request, the GOTO instruction is executed which jumps to
27045  the ISR code.
27046  When declaring interrupt functions as _naked this GOTO instruction is 
27047 \series bold
27048 not
27049 \series default
27050  generated.
27051  The whole interrupt functions is therefore placed at the Interrupt Vector
27052  Address of the specific interrupt.
27053  This is not a problem for the LOW priority interrupts, but it is a problem
27054  for the RESET and the HIGH priority interrupts because code may be written
27055  at the next interrupt's vector address and cause undeterminate program
27056  behaviour if that interrupt is raised.
27057 \begin_inset Foot
27058 status open
27059
27060 \begin_layout Standard
27061 This is not a problem when
27062 \end_layout
27063
27064 \begin_layout Enumerate
27065 this is a HIGH interrupt ISR and LOW interrupts are 
27066 \emph on
27067 disabled
27068 \emph default
27069  or not used.
27070 \end_layout
27071
27072 \begin_layout Enumerate
27073 when the ISR is small enough not to reach the next interrupt's vector address.
27074 \end_layout
27075
27076 \end_inset
27077
27078
27079 \end_layout
27080
27081 \begin_layout Standard
27082
27083 \emph on
27084 n
27085 \emph default
27086  may be omitted.
27087  This way a function is generated similar to an ISR, but it is not assigned
27088  to any interrupt.
27089 \end_layout
27090
27091 \begin_layout Standard
27092 When entering an interrupt, currently the PIC16
27093 \begin_inset LatexCommand \index{PIC16}
27094
27095 \end_inset
27096
27097  port automatically saves the following registers:
27098 \end_layout
27099
27100 \begin_layout Itemize
27101 WREG
27102 \end_layout
27103
27104 \begin_layout Itemize
27105 STATUS
27106 \end_layout
27107
27108 \begin_layout Itemize
27109 BSR
27110 \end_layout
27111
27112 \begin_layout Itemize
27113 PROD (PRODL and PRODH)
27114 \end_layout
27115
27116 \begin_layout Itemize
27117 FSR0 (FSR0L and FSR0H)
27118 \end_layout
27119
27120 \begin_layout Standard
27121 These registers are restored upon return from the interrupt routine.
27122 \begin_inset Foot
27123 status open
27124
27125 \begin_layout Standard
27126 NOTE that when the _naked attribute is specified for an interrupt routine,
27127  then NO registers are stored or restored.
27128 \end_layout
27129
27130 \end_inset
27131
27132
27133 \end_layout
27134
27135 \begin_layout Subsection
27136 Generic Pointers
27137 \end_layout
27138
27139 \begin_layout Standard
27140 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27141  There are 3 types of generic pointers currently implemented data, code
27142  and eeprom pointers.
27143  They are differentiated by the value of the 7th and 6th bits of the upper
27144  byte:
27145 \end_layout
27146
27147 \begin_layout Standard
27148 \align center
27149 \begin_inset Tabular
27150 <lyxtabular version="3" rows="5" columns="5">
27151 <features>
27152 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27153 <column alignment="center" valignment="top" width="0">
27154 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27155 <column alignment="center" valignment="top" width="0">
27156 <column alignment="left" valignment="top" rightline="true" width="0">
27157 <row topline="true" bottomline="true">
27158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27159 \begin_inset Text
27160
27161 \begin_layout Standard
27162 pointer type
27163 \end_layout
27164
27165 \end_inset
27166 </cell>
27167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27168 \begin_inset Text
27169
27170 \begin_layout Standard
27171 7th bit
27172 \end_layout
27173
27174 \end_inset
27175 </cell>
27176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27177 \begin_inset Text
27178
27179 \begin_layout Standard
27180 6th bit
27181 \end_layout
27182
27183 \end_inset
27184 </cell>
27185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27186 \begin_inset Text
27187
27188 \begin_layout Standard
27189 rest of the pointer
27190 \end_layout
27191
27192 \end_inset
27193 </cell>
27194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27195 \begin_inset Text
27196
27197 \begin_layout Standard
27198 description
27199 \end_layout
27200
27201 \end_inset
27202 </cell>
27203 </row>
27204 <row topline="true" bottomline="true">
27205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27206 \begin_inset Text
27207
27208 \begin_layout Standard
27209 data 
27210 \end_layout
27211
27212 \end_inset
27213 </cell>
27214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27215 \begin_inset Text
27216
27217 \begin_layout Standard
27218 1
27219 \end_layout
27220
27221 \end_inset
27222 </cell>
27223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27224 \begin_inset Text
27225
27226 \begin_layout Standard
27227 0
27228 \end_layout
27229
27230 \end_inset
27231 </cell>
27232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27233 \begin_inset Text
27234
27235 \begin_layout Standard
27236
27237 \family typewriter
27238 \shape slanted
27239 \emph on
27240 uuuuuu uuuuxxxx xxxxxxxx
27241 \end_layout
27242
27243 \end_inset
27244 </cell>
27245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27246 \begin_inset Text
27247
27248 \begin_layout Standard
27249 a 12-bit data pointer in data RAM memory
27250 \end_layout
27251
27252 \end_inset
27253 </cell>
27254 </row>
27255 <row bottomline="true">
27256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27257 \begin_inset Text
27258
27259 \begin_layout Standard
27260 code
27261 \end_layout
27262
27263 \end_inset
27264 </cell>
27265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27266 \begin_inset Text
27267
27268 \begin_layout Standard
27269 0
27270 \end_layout
27271
27272 \end_inset
27273 </cell>
27274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27275 \begin_inset Text
27276
27277 \begin_layout Standard
27278 0
27279 \end_layout
27280
27281 \end_inset
27282 </cell>
27283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27284 \begin_inset Text
27285
27286 \begin_layout Standard
27287
27288 \family typewriter
27289 \shape slanted
27290 \emph on
27291 uxxxxx xxxxxxxx xxxxxxxx
27292 \end_layout
27293
27294 \end_inset
27295 </cell>
27296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27297 \begin_inset Text
27298
27299 \begin_layout Standard
27300 a 21-bit code pointer in FLASH memory
27301 \end_layout
27302
27303 \end_inset
27304 </cell>
27305 </row>
27306 <row bottomline="true">
27307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27308 \begin_inset Text
27309
27310 \begin_layout Standard
27311 eeprom
27312 \end_layout
27313
27314 \end_inset
27315 </cell>
27316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27317 \begin_inset Text
27318
27319 \begin_layout Standard
27320 0
27321 \end_layout
27322
27323 \end_inset
27324 </cell>
27325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27326 \begin_inset Text
27327
27328 \begin_layout Standard
27329 1
27330 \end_layout
27331
27332 \end_inset
27333 </cell>
27334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27335 \begin_inset Text
27336
27337 \begin_layout Standard
27338
27339 \family typewriter
27340 \shape slanted
27341 \emph on
27342 uuuuuu uuuuuuxx xxxxxxxx
27343 \end_layout
27344
27345 \end_inset
27346 </cell>
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27348 \begin_inset Text
27349
27350 \begin_layout Standard
27351 a 10-bit eeprom pointer in EEPROM memory
27352 \end_layout
27353
27354 \end_inset
27355 </cell>
27356 </row>
27357 <row bottomline="true">
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27359 \begin_inset Text
27360
27361 \begin_layout Standard
27362 (unimplemented)
27363 \end_layout
27364
27365 \end_inset
27366 </cell>
27367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27368 \begin_inset Text
27369
27370 \begin_layout Standard
27371 1
27372 \end_layout
27373
27374 \end_inset
27375 </cell>
27376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27377 \begin_inset Text
27378
27379 \begin_layout Standard
27380 1
27381 \end_layout
27382
27383 \end_inset
27384 </cell>
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 \begin_inset Text
27387
27388 \begin_layout Standard
27389
27390 \family typewriter
27391 \shape slanted
27392 \emph on
27393 xxxxxx xxxxxxxx xxxxxxxx
27394 \end_layout
27395
27396 \end_inset
27397 </cell>
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27399 \begin_inset Text
27400
27401 \begin_layout Standard
27402 unimplemented pointer type
27403 \end_layout
27404
27405 \end_inset
27406 </cell>
27407 </row>
27408 </lyxtabular>
27409
27410 \end_inset
27411
27412
27413 \end_layout
27414
27415 \begin_layout Standard
27416 Generic pointer are read and written with a set of library functions which
27417  read/write 1, 2, 3, 4 bytes.
27418 \end_layout
27419
27420 \begin_layout Subsection
27421 PIC16 C Libraries
27422 \end_layout
27423
27424 \begin_layout Subsubsection
27425 Standard I/O Streams
27426 \end_layout
27427
27428 \begin_layout Standard
27429 In the 
27430 \emph on
27431 stdio.h
27432 \emph default
27433  the type FILE is defined as:
27434 \end_layout
27435
27436 \begin_layout LyX-Code
27437 typedef char * FILE;
27438 \end_layout
27439
27440 \begin_layout Standard
27441 This type is the stream type implemented I/O in the PIC18F devices.
27442  Also the standard input and output streams are declared in stdio.h:
27443 \end_layout
27444
27445 \begin_layout LyX-Code
27446 extern FILE * stdin;
27447 \end_layout
27448
27449 \begin_layout LyX-Code
27450 extern FILE * stdout;
27451 \end_layout
27452
27453 \begin_layout Standard
27454 The FILE type is actually a generic pointer which defines one more type
27455  of generic pointers, the 
27456 \emph on
27457 stream 
27458 \emph default
27459 pointer.
27460  This new type has the format:
27461 \end_layout
27462
27463 \begin_layout Standard
27464 \align center
27465 \begin_inset Tabular
27466 <lyxtabular version="3" rows="2" columns="7">
27467 <features>
27468 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27469 <column alignment="center" valignment="top" width="0">
27470 <column alignment="center" valignment="top" leftline="true" width="0">
27471 <column alignment="center" valignment="top" leftline="true" width="0">
27472 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27473 <column alignment="center" valignment="top" width="0">
27474 <column alignment="left" valignment="top" rightline="true" width="0">
27475 <row topline="true" bottomline="true">
27476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27477 \begin_inset Text
27478
27479 \begin_layout Standard
27480 pointer type
27481 \end_layout
27482
27483 \end_inset
27484 </cell>
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27486 \begin_inset Text
27487
27488 \begin_layout Standard
27489 <7:6>
27490 \end_layout
27491
27492 \end_inset
27493 </cell>
27494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27495 \begin_inset Text
27496
27497 \begin_layout Standard
27498 <5>
27499 \end_layout
27500
27501 \end_inset
27502 </cell>
27503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27504 \begin_inset Text
27505
27506 \begin_layout Standard
27507 <4>
27508 \end_layout
27509
27510 \end_inset
27511 </cell>
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27513 \begin_inset Text
27514
27515 \begin_layout Standard
27516 <3:0>
27517 \end_layout
27518
27519 \end_inset
27520 </cell>
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27522 \begin_inset Text
27523
27524 \begin_layout Standard
27525 rest of the pointer
27526 \end_layout
27527
27528 \end_inset
27529 </cell>
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27531 \begin_inset Text
27532
27533 \begin_layout Standard
27534 descrption
27535 \end_layout
27536
27537 \end_inset
27538 </cell>
27539 </row>
27540 <row topline="true" bottomline="true">
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27542 \begin_inset Text
27543
27544 \begin_layout Standard
27545 stream
27546 \end_layout
27547
27548 \end_inset
27549 </cell>
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27551 \begin_inset Text
27552
27553 \begin_layout Standard
27554 00
27555 \end_layout
27556
27557 \end_inset
27558 </cell>
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27560 \begin_inset Text
27561
27562 \begin_layout Standard
27563 1
27564 \end_layout
27565
27566 \end_inset
27567 </cell>
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27569 \begin_inset Text
27570
27571 \begin_layout Standard
27572 0
27573 \end_layout
27574
27575 \end_inset
27576 </cell>
27577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27578 \begin_inset Text
27579
27580 \begin_layout Standard
27581 nnnn
27582 \end_layout
27583
27584 \end_inset
27585 </cell>
27586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27587 \begin_inset Text
27588
27589 \begin_layout Standard
27590
27591 \family typewriter
27592 \shape slanted
27593 \emph on
27594 uuuuuuuu uuuuuuuu
27595 \end_layout
27596
27597 \end_inset
27598 </cell>
27599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27600 \begin_inset Text
27601
27602 \begin_layout Standard
27603 upper byte high nubble is 0x2n, the rest are zeroes
27604 \end_layout
27605
27606 \end_inset
27607 </cell>
27608 </row>
27609 </lyxtabular>
27610
27611 \end_inset
27612
27613
27614 \end_layout
27615
27616 \begin_layout Standard
27617 Currently implemented there are 3 types of streams defined:
27618 \end_layout
27619
27620 \begin_layout Standard
27621 \align center
27622 \begin_inset Tabular
27623 <lyxtabular version="3" rows="4" columns="4">
27624 <features>
27625 <column alignment="center" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
27629 <row topline="true" bottomline="true">
27630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27631 \begin_inset Text
27632
27633 \begin_layout Standard
27634 stream type
27635 \end_layout
27636
27637 \end_inset
27638 </cell>
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27640 \begin_inset Text
27641
27642 \begin_layout Standard
27643 value
27644 \end_layout
27645
27646 \end_inset
27647 </cell>
27648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27649 \begin_inset Text
27650
27651 \begin_layout Standard
27652 module
27653 \end_layout
27654
27655 \end_inset
27656 </cell>
27657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27658 \begin_inset Text
27659
27660 \begin_layout Standard
27661 description
27662 \end_layout
27663
27664 \end_inset
27665 </cell>
27666 </row>
27667 <row topline="true">
27668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27669 \begin_inset Text
27670
27671 \begin_layout Standard
27672 STREAM_USART
27673 \end_layout
27674
27675 \end_inset
27676 </cell>
27677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27678 \begin_inset Text
27679
27680 \begin_layout Standard
27681
27682 \family typewriter
27683 0x200000UL
27684 \end_layout
27685
27686 \end_inset
27687 </cell>
27688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27689 \begin_inset Text
27690
27691 \begin_layout Standard
27692 USART
27693 \end_layout
27694
27695 \end_inset
27696 </cell>
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27698 \begin_inset Text
27699
27700 \begin_layout Standard
27701 Writes/Reads characters via the USART peripheral
27702 \end_layout
27703
27704 \end_inset
27705 </cell>
27706 </row>
27707 <row topline="true">
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27709 \begin_inset Text
27710
27711 \begin_layout Standard
27712 STREAM_MSSP
27713 \end_layout
27714
27715 \end_inset
27716 </cell>
27717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27718 \begin_inset Text
27719
27720 \begin_layout Standard
27721
27722 \family typewriter
27723 0x210000UL
27724 \end_layout
27725
27726 \end_inset
27727 </cell>
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27729 \begin_inset Text
27730
27731 \begin_layout Standard
27732 MSSP
27733 \end_layout
27734
27735 \end_inset
27736 </cell>
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27738 \begin_inset Text
27739
27740 \begin_layout Standard
27741 Writes/Reads characters via the MSSP peripheral
27742 \end_layout
27743
27744 \end_inset
27745 </cell>
27746 </row>
27747 <row topline="true" bottomline="true">
27748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27749 \begin_inset Text
27750
27751 \begin_layout Standard
27752 STREAM_USER
27753 \end_layout
27754
27755 \end_inset
27756 </cell>
27757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27758 \begin_inset Text
27759
27760 \begin_layout Standard
27761
27762 \family typewriter
27763 0x2f0000UL
27764 \end_layout
27765
27766 \end_inset
27767 </cell>
27768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27769 \begin_inset Text
27770
27771 \begin_layout Standard
27772 (none)
27773 \end_layout
27774
27775 \end_inset
27776 </cell>
27777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27778 \begin_inset Text
27779
27780 \begin_layout Standard
27781 Writes/Reads characters via used defined functions
27782 \end_layout
27783
27784 \end_inset
27785 </cell>
27786 </row>
27787 </lyxtabular>
27788
27789 \end_inset
27790
27791
27792 \end_layout
27793
27794 \begin_layout Standard
27795 The stream identifiers are declared as macros in the stdio.h header.
27796 \end_layout
27797
27798 \begin_layout Standard
27799 In the libc library there exist the functions that are used to write to
27800  each of the above streams.
27801  These are
27802 \end_layout
27803
27804 \begin_layout Description
27805 _
27806 \begin_inset ERT
27807 status collapsed
27808
27809 \begin_layout Standard
27810
27811
27812 \backslash
27813 /
27814 \end_layout
27815
27816 \end_inset
27817
27818 _stream_usart_putchar writes a character at the USART stream
27819 \end_layout
27820
27821 \begin_layout Description
27822 _
27823 \begin_inset ERT
27824 status collapsed
27825
27826 \begin_layout Standard
27827
27828
27829 \backslash
27830 /
27831 \end_layout
27832
27833 \end_inset
27834
27835 _stream_mssp_putchar writes a character at the MSSP stream
27836 \end_layout
27837
27838 \begin_layout Description
27839 putchar dummy function.
27840  This writes a character to a user specified manner.
27841 \end_layout
27842
27843 \begin_layout Standard
27844 In order to increase performance 
27845 \emph on
27846 putchar 
27847 \emph default
27848 is declared in stdio.h as having its parameter in WREG (it has the wparam
27849  keyword).
27850  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27851  in a user-friendly way.
27852  
27853 \emph on
27854 arg
27855 \emph default
27856  is the name of the variable that holds the character to print.
27857  An example follows:
27858 \end_layout
27859
27860 \begin_layout LyX-Code
27861 #include <pic18fregs.h>
27862 \newline
27863 #include <stdio.h>
27864 \newline
27865
27866 \newline
27867 PUTCHAR( c )
27868 \end_layout
27869
27870 \begin_layout LyX-Code
27871 {
27872 \end_layout
27873
27874 \begin_layout LyX-Code
27875     PORTA = c;    /* dump character c to PORTA */
27876 \end_layout
27877
27878 \begin_layout LyX-Code
27879
27880 \newline
27881
27882 \newline
27883 void main(void)
27884 \end_layout
27885
27886 \begin_layout LyX-Code
27887 {
27888 \end_layout
27889
27890 \begin_layout LyX-Code
27891     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27892 \end_layout
27893
27894 \begin_layout LyX-Code
27895                               * by default to STREAM_USER */
27896 \end_layout
27897
27898 \begin_layout LyX-Code
27899     printf (
27900 \begin_inset Quotes sld
27901 \end_inset
27902
27903 This is a printf test
27904 \backslash
27905 n
27906 \begin_inset Quotes srd
27907 \end_inset
27908
27909 );
27910 \end_layout
27911
27912 \begin_layout LyX-Code
27913 }
27914 \end_layout
27915
27916 \begin_layout LyX-Code
27917
27918 \end_layout
27919
27920 \begin_layout Subsubsection
27921 Printing functions
27922 \end_layout
27923
27924 \begin_layout Standard
27925 PIC16 contains an implementation of the printf-family of functions.
27926  There exist the following functions:
27927 \end_layout
27928
27929 \begin_layout LyX-Code
27930 extern unsigned int sprintf(char *buf, char *fmt, ...);
27931 \end_layout
27932
27933 \begin_layout LyX-Code
27934 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27935 \end_layout
27936
27937 \begin_layout LyX-Code
27938
27939 \end_layout
27940
27941 \begin_layout LyX-Code
27942 extern unsigned int printf(char *fmt, ...);
27943 \end_layout
27944
27945 \begin_layout LyX-Code
27946 extern unsigned int vprintf(char *fmt, va_lista ap);
27947 \end_layout
27948
27949 \begin_layout LyX-Code
27950
27951 \end_layout
27952
27953 \begin_layout LyX-Code
27954 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27955 \end_layout
27956
27957 \begin_layout LyX-Code
27958 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27959 \end_layout
27960
27961 \begin_layout Standard
27962 For sprintf and vsprintf 
27963 \emph on
27964 buf 
27965 \emph default
27966 should normally be a data pointer where the resulting string will be placed.
27967  No range checking is done so the user should allocate the necessery buffer.
27968  For fprintf and vfprintf 
27969 \emph on
27970 fp
27971 \emph default
27972  should be a stream pointer (i.e.
27973  stdout, STREAM_MSSP, etc...).
27974 \end_layout
27975
27976 \begin_layout Subsubsection
27977 Signals
27978 \end_layout
27979
27980 \begin_layout Standard
27981 The PIC18F family of microcontrollers supports a number of interrupt sources.
27982  A list of these interrupts is shown in the following table:
27983 \end_layout
27984
27985 \begin_layout Standard
27986 \align center
27987 \begin_inset Tabular
27988 <lyxtabular version="3" rows="11" columns="4">
27989 <features>
27990 <column alignment="left" valignment="top" leftline="true" width="0">
27991 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27992 <column alignment="left" valignment="top" leftline="true" width="0">
27993 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27994 <row topline="true" bottomline="true">
27995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27996 \begin_inset Text
27997
27998 \begin_layout Standard
27999 signal name
28000 \end_layout
28001
28002 \end_inset
28003 </cell>
28004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28005 \begin_inset Text
28006
28007 \begin_layout Standard
28008 description
28009 \end_layout
28010
28011 \end_inset
28012 </cell>
28013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28014 \begin_inset Text
28015
28016 \begin_layout Standard
28017 signal name
28018 \end_layout
28019
28020 \end_inset
28021 </cell>
28022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28023 \begin_inset Text
28024
28025 \begin_layout Standard
28026 descritpion
28027 \end_layout
28028
28029 \end_inset
28030 </cell>
28031 </row>
28032 <row topline="true">
28033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28034 \begin_inset Text
28035
28036 \begin_layout Standard
28037 SIG_RB
28038 \end_layout
28039
28040 \end_inset
28041 </cell>
28042 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28043 \begin_inset Text
28044
28045 \begin_layout Standard
28046 PORTB change interrupt
28047 \end_layout
28048
28049 \end_inset
28050 </cell>
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28052 \begin_inset Text
28053
28054 \begin_layout Standard
28055 SIG_EE
28056 \end_layout
28057
28058 \end_inset
28059 </cell>
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28061 \begin_inset Text
28062
28063 \begin_layout Standard
28064 EEPROM/FLASH write complete interrupt
28065 \end_layout
28066
28067 \end_inset
28068 </cell>
28069 </row>
28070 <row topline="true">
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28072 \begin_inset Text
28073
28074 \begin_layout Standard
28075 SIG_INT0
28076 \end_layout
28077
28078 \end_inset
28079 </cell>
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28081 \begin_inset Text
28082
28083 \begin_layout Standard
28084 INT0 external interrupt
28085 \end_layout
28086
28087 \end_inset
28088 </cell>
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28090 \begin_inset Text
28091
28092 \begin_layout Standard
28093 SIG_BCOL
28094 \end_layout
28095
28096 \end_inset
28097 </cell>
28098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28099 \begin_inset Text
28100
28101 \begin_layout Standard
28102 Bus collision interrupt
28103 \end_layout
28104
28105 \end_inset
28106 </cell>
28107 </row>
28108 <row topline="true">
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28110 \begin_inset Text
28111
28112 \begin_layout Standard
28113 SIG_INT1
28114 \end_layout
28115
28116 \end_inset
28117 </cell>
28118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28119 \begin_inset Text
28120
28121 \begin_layout Standard
28122 INT1 external interrupt
28123 \end_layout
28124
28125 \end_inset
28126 </cell>
28127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28128 \begin_inset Text
28129
28130 \begin_layout Standard
28131 SIG_LVD
28132 \end_layout
28133
28134 \end_inset
28135 </cell>
28136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28137 \begin_inset Text
28138
28139 \begin_layout Standard
28140 Low voltage detect interrupt
28141 \end_layout
28142
28143 \end_inset
28144 </cell>
28145 </row>
28146 <row topline="true">
28147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28148 \begin_inset Text
28149
28150 \begin_layout Standard
28151 SIG_INT2
28152 \end_layout
28153
28154 \end_inset
28155 </cell>
28156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28157 \begin_inset Text
28158
28159 \begin_layout Standard
28160 INT2 external interrupt
28161 \end_layout
28162
28163 \end_inset
28164 </cell>
28165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28166 \begin_inset Text
28167
28168 \begin_layout Standard
28169 SIG_PSP
28170 \end_layout
28171
28172 \end_inset
28173 </cell>
28174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28175 \begin_inset Text
28176
28177 \begin_layout Standard
28178 Parallel slave port interrupt
28179 \end_layout
28180
28181 \end_inset
28182 </cell>
28183 </row>
28184 <row topline="true">
28185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28186 \begin_inset Text
28187
28188 \begin_layout Standard
28189 SIG_CCP1
28190 \end_layout
28191
28192 \end_inset
28193 </cell>
28194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28195 \begin_inset Text
28196
28197 \begin_layout Standard
28198 CCP1 module interrupt
28199 \end_layout
28200
28201 \end_inset
28202 </cell>
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28204 \begin_inset Text
28205
28206 \begin_layout Standard
28207 SIG_AD
28208 \end_layout
28209
28210 \end_inset
28211 </cell>
28212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28213 \begin_inset Text
28214
28215 \begin_layout Standard
28216 AD convertion complete interrupt
28217 \end_layout
28218
28219 \end_inset
28220 </cell>
28221 </row>
28222 <row topline="true">
28223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28224 \begin_inset Text
28225
28226 \begin_layout Standard
28227 SIG_CCP2
28228 \end_layout
28229
28230 \end_inset
28231 </cell>
28232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28233 \begin_inset Text
28234
28235 \begin_layout Standard
28236 CCP2 module interrupt
28237 \end_layout
28238
28239 \end_inset
28240 </cell>
28241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28242 \begin_inset Text
28243
28244 \begin_layout Standard
28245 SIG_RC
28246 \end_layout
28247
28248 \end_inset
28249 </cell>
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28251 \begin_inset Text
28252
28253 \begin_layout Standard
28254 USART receive interrupt
28255 \end_layout
28256
28257 \end_inset
28258 </cell>
28259 </row>
28260 <row topline="true">
28261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28262 \begin_inset Text
28263
28264 \begin_layout Standard
28265 SIG_TMR0
28266 \end_layout
28267
28268 \end_inset
28269 </cell>
28270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28271 \begin_inset Text
28272
28273 \begin_layout Standard
28274 TMR0 overflow interrupt
28275 \end_layout
28276
28277 \end_inset
28278 </cell>
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28280 \begin_inset Text
28281
28282 \begin_layout Standard
28283 SIG_TX
28284 \end_layout
28285
28286 \end_inset
28287 </cell>
28288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28289 \begin_inset Text
28290
28291 \begin_layout Standard
28292 USART transmit interrupt
28293 \end_layout
28294
28295 \end_inset
28296 </cell>
28297 </row>
28298 <row topline="true">
28299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28300 \begin_inset Text
28301
28302 \begin_layout Standard
28303 SIG_TMR1
28304 \end_layout
28305
28306 \end_inset
28307 </cell>
28308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28309 \begin_inset Text
28310
28311 \begin_layout Standard
28312 TMR1 overflow interrupt
28313 \end_layout
28314
28315 \end_inset
28316 </cell>
28317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28318 \begin_inset Text
28319
28320 \begin_layout Standard
28321 SIG_MSSP
28322 \end_layout
28323
28324 \end_inset
28325 </cell>
28326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28327 \begin_inset Text
28328
28329 \begin_layout Standard
28330 SSP receive/transmit interrupt
28331 \end_layout
28332
28333 \end_inset
28334 </cell>
28335 </row>
28336 <row topline="true">
28337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28338 \begin_inset Text
28339
28340 \begin_layout Standard
28341 SIG_TMR2
28342 \end_layout
28343
28344 \end_inset
28345 </cell>
28346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28347 \begin_inset Text
28348
28349 \begin_layout Standard
28350 TMR2 matches PR2 interrupt
28351 \end_layout
28352
28353 \end_inset
28354 </cell>
28355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28356 \begin_inset Text
28357
28358 \begin_layout Standard
28359
28360 \end_layout
28361
28362 \end_inset
28363 </cell>
28364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28365 \begin_inset Text
28366
28367 \begin_layout Standard
28368
28369 \end_layout
28370
28371 \end_inset
28372 </cell>
28373 </row>
28374 <row topline="true" bottomline="true">
28375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28376 \begin_inset Text
28377
28378 \begin_layout Standard
28379 SIG_TMR3
28380 \end_layout
28381
28382 \end_inset
28383 </cell>
28384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28385 \begin_inset Text
28386
28387 \begin_layout Standard
28388 TMR3 overflow interrupt
28389 \end_layout
28390
28391 \end_inset
28392 </cell>
28393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28394 \begin_inset Text
28395
28396 \begin_layout Standard
28397
28398 \end_layout
28399
28400 \end_inset
28401 </cell>
28402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28403 \begin_inset Text
28404
28405 \begin_layout Standard
28406
28407 \end_layout
28408
28409 \end_inset
28410 </cell>
28411 </row>
28412 </lyxtabular>
28413
28414 \end_inset
28415
28416
28417 \end_layout
28418
28419 \begin_layout Standard
28420 The prototypes for these names are defined in the header file 
28421 \emph on
28422 signal.h
28423 \emph default
28424  .
28425 \end_layout
28426
28427 \begin_layout Standard
28428 In order to simplify signal handling, a number of macros is provided:
28429 \end_layout
28430
28431 \begin_layout List
28432 \labelwidthstring 00.00.0000
28433 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28434  high priority interrupts.
28435  
28436 \emph on
28437 name
28438 \emph default
28439  is the function name to use.
28440 \end_layout
28441
28442 \begin_layout List
28443 \labelwidthstring 00.00.0000
28444 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28445  low priority interrupt.
28446  
28447 \emph on
28448 name
28449 \emph default
28450  is the function name to use.
28451 \end_layout
28452
28453 \begin_layout List
28454 \labelwidthstring 00.00.0000
28455 DEF_HANDLER(sig,handler) define a handler for signal 
28456 \emph on
28457 sig.
28458 \end_layout
28459
28460 \begin_layout List
28461 \labelwidthstring 00.00.0000
28462 END_DEF end the declaration of the dispatch table.
28463 \end_layout
28464
28465 \begin_layout Standard
28466 Additionally there are two more macros to simplify the declaration of the
28467  signal handler:
28468 \end_layout
28469
28470 \begin_layout List
28471 \labelwidthstring 00.00.0000
28472
28473 \series medium
28474 SIGHANDLER(handler) 
28475 \series default
28476 this declares the function prototype for the 
28477 \emph on
28478 handler
28479 \emph default
28480  function.
28481 \end_layout
28482
28483 \begin_layout List
28484 \labelwidthstring 00.00.0000
28485 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28486 \end_layout
28487
28488 \begin_layout Standard
28489 An example of using the macros above is shown below:
28490 \end_layout
28491
28492 \begin_layout LyX-Code
28493 #include <pic18fregs.h>
28494 \end_layout
28495
28496 \begin_layout LyX-Code
28497 #include <signal.h>
28498 \newline
28499
28500 \newline
28501 DEF_INTHIGH(high_int)
28502 \end_layout
28503
28504 \begin_layout LyX-Code
28505 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28506 \end_layout
28507
28508 \begin_layout LyX-Code
28509 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28510 \end_layout
28511
28512 \begin_layout LyX-Code
28513 END_DEF
28514 \newline
28515
28516 \newline
28517 SIGHANDLER(_tmr0_handler)
28518 \end_layout
28519
28520 \begin_layout LyX-Code
28521 {
28522 \end_layout
28523
28524 \begin_layout LyX-Code
28525   /* action to be taken when timer 0 overflows */
28526 \end_layout
28527
28528 \begin_layout LyX-Code
28529 }
28530 \newline
28531
28532 \newline
28533 SIGHANDLERNAKED(_bcol_handler)
28534 \end_layout
28535
28536 \begin_layout LyX-Code
28537 {
28538 \end_layout
28539
28540 \begin_layout LyX-Code
28541   _asm
28542 \end_layout
28543
28544 \begin_layout LyX-Code
28545     /* action to be taken when bus collision occurs */
28546 \end_layout
28547
28548 \begin_layout LyX-Code
28549     retfie
28550 \end_layout
28551
28552 \begin_layout LyX-Code
28553  _endasm;
28554 \end_layout
28555
28556 \begin_layout LyX-Code
28557 }
28558 \end_layout
28559
28560 \begin_layout Standard
28561
28562 \series bold
28563 NOTES:
28564 \series default
28565  Special care should be taken when using the above scheme:
28566 \end_layout
28567
28568 \begin_layout Itemize
28569 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28570 \end_layout
28571
28572 \begin_layout Itemize
28573 when declaring SIGHANDLERNAKED handler never forget to use 
28574 \emph on
28575 retfie
28576 \emph default
28577  for proper returning.
28578 \end_layout
28579
28580 \begin_layout Subsection
28581 PIC16 Port -- Tips
28582 \end_layout
28583
28584 \begin_layout Standard
28585 Here you can find some general tips for compiling programs with SDCC/pic16.
28586 \end_layout
28587
28588 \begin_layout Subsubsection
28589 Stack size
28590 \end_layout
28591
28592 \begin_layout Standard
28593 The default stack
28594 \begin_inset LatexCommand \index{PIC16!stack}
28595
28596 \end_inset
28597
28598  size (that is 64 bytes) probably is enough for many programs.
28599  One must take care that when there are many levels of function nesting,
28600  or there is excessive usage of stack, its size should be extended.
28601  An example of such a case is the printf/sprintf family of functions.
28602  If you encounter problems like not being able to print integers, then you
28603  need to set the stack size around the maximum (256 for small stack model).
28604  The following diagram shows what happens when calling printf to print an
28605  integer:
28606 \end_layout
28607
28608 \begin_layout LyX-Code
28609 printf () --> ltoa () --> ultoa () --> divschar ()
28610 \end_layout
28611
28612 \begin_layout Standard
28613 It is should be understood that stack is easily consumed when calling complicate
28614 d functions.
28615  Using command line arguments like -
28616 \begin_inset ERT
28617 status collapsed
28618
28619 \begin_layout Standard
28620
28621
28622 \backslash
28623 /
28624 \end_layout
28625
28626 \end_inset
28627
28628 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28629  stack frames.
28630  Other ways to reduce stack usage may exist.
28631 \end_layout
28632
28633 \begin_layout Subsection
28634 Known Bugs
28635 \end_layout
28636
28637 \begin_layout Standard
28638 The PIC16 Port currently does not pass SDCC's regression test
28639 \begin_inset LatexCommand \index{Regression test (PIC16)}
28640
28641 \end_inset
28642
28643  suite (see section 
28644 \begin_inset LatexCommand \ref{sec:Quality-control}
28645
28646 \end_inset
28647
28648 ) and thus the snapshot build regression tests for the PIC16 target are
28649  currently disabled for all hosts
28650 \emph on
28651 .
28652 \end_layout
28653
28654 \begin_layout Chapter
28655 Debugging
28656 \end_layout
28657
28658 \begin_layout Standard
28659 There are several approaches to debugging your code.
28660  This chapter is meant to show your options and to give detail on some of
28661  them:
28662 \newline
28663
28664 \newline
28665 When writing your code:
28666 \end_layout
28667
28668 \begin_layout Itemize
28669 write your code with debugging in mind (avoid duplicating code, put conceptually
28670  similar variables into structs, use structured code, have strategic points
28671  within your code where all variables are consistent, ...)
28672 \end_layout
28673
28674 \begin_layout Itemize
28675 run a syntax-checking tool like splint
28676 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28677
28678 \end_inset
28679
28680
28681 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28682
28683 \end_inset
28684
28685  (see -
28686 \begin_inset ERT
28687 status collapsed
28688
28689 \begin_layout Standard
28690
28691
28692 \backslash
28693 /
28694 \end_layout
28695
28696 \end_inset
28697
28698 -more-pedantic 
28699 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28700
28701 \end_inset
28702
28703 ) over the code.
28704 \end_layout
28705
28706 \begin_layout Itemize
28707 for the high level code use a C-compiler (like f.e.
28708  GCC) to compile run and debug the code on your host.
28709  See (see -
28710 \begin_inset ERT
28711 status collapsed
28712
28713 \begin_layout Standard
28714
28715
28716 \backslash
28717 /
28718 \end_layout
28719
28720 \end_inset
28721
28722 -more-pedantic 
28723 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28724
28725 \end_inset
28726
28727 ) on how to handle syntax extensions like __xdata, __at(), ...
28728  
28729 \end_layout
28730
28731 \begin_layout Itemize
28732 use another C-compiler to compile code for your target.
28733  Always an option but not recommended:) And not very likely to help you.
28734  If you seriously consider walking this path you should at least occasionally
28735  check portability of your code.
28736  Most commercial compiler vendors will offer an evaluation version so you
28737  can test compile your code or snippets of your code.
28738 \end_layout
28739
28740 \begin_layout Standard
28741 Debugging on a simulator:
28742 \end_layout
28743
28744 \begin_layout Itemize
28745 there is a separate section about SDCDB (section 
28746 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28747
28748 \end_inset
28749
28750 ) below.
28751 \end_layout
28752
28753 \begin_layout Itemize
28754 or (8051 specific) use a freeware/commercial simulator which interfaces
28755  to the AOMF
28756 \begin_inset LatexCommand \index{AOMF, AOMF51}
28757
28758 \end_inset
28759
28760  file (see 
28761 \begin_inset LatexCommand \ref{OMF file}
28762
28763 \end_inset
28764
28765 ) optionally generated by SDCC.
28766 \end_layout
28767
28768 \begin_layout Standard
28769 Debugging On-target: 
28770 \end_layout
28771
28772 \begin_layout Itemize
28773 use a MCU port pin to serially output debug data to the RS232 port of your
28774  host.
28775  You'll probably want some level shifting device typically involving a MAX232
28776  or similar IC.
28777  If the hardware serial port of the MCU is not available search for 'Software
28778  UART' in your favourite search machine.
28779 \end_layout
28780
28781 \begin_layout Itemize
28782 use an on-target monitor.
28783  In this context a monitor is a small program which usually accepts commands
28784  via a serial line and allows to set program counter, to single step through
28785  a program and read/write memory locations.
28786  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28787  
28788 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28789
28790 \end_inset
28791
28792 ).
28793 \end_layout
28794
28795 \begin_layout Itemize
28796 toggle MCU port pins at strategic points within your code and use an oscilloscop
28797 e.
28798  A 
28799 \emph on
28800 digital oscilloscope
28801 \emph default
28802
28803 \begin_inset LatexCommand \index{Oscilloscope}
28804
28805 \end_inset
28806
28807  with deep trace memory is really helpful especially if you have to debug
28808  a realtime application.
28809  If you need to monitor more pins than your oscilloscope provides you can
28810  sometimes get away with a small R-2R network.
28811  On a single channel oscilloscope you could f.e.
28812  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28813 k
28814 \begin_inset Formula $\Omega$
28815 \end_inset
28816
28817  resistor and the other one by a 5\InsetSpace ~
28818 k
28819 \begin_inset Formula $\Omega$
28820 \end_inset
28821
28822  resistor to the oscilloscope probe (check output drive capability of the
28823  pins you want to monitor).
28824  If you need to monitor many more pins a 
28825 \emph on
28826 logic analyzer
28827 \emph default
28828  will be handy.
28829 \end_layout
28830
28831 \begin_layout Itemize
28832 use an ICE (
28833 \emph on
28834 i
28835 \emph default
28836
28837 \emph on
28838 c
28839 \emph default
28840 ircuit 
28841 \emph on
28842 e
28843 \emph default
28844 mulator
28845 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28846
28847 \end_inset
28848
28849 ).
28850  Usually very expensive.
28851  And very nice to have too.
28852  And usually locks you (for years...) to the devices the ICE can emulate.
28853  
28854 \end_layout
28855
28856 \begin_layout Itemize
28857 use a remote debugger.
28858  In most 8-bit systems the symbol information is not available on the target,
28859  and a complete debugger is too bulky for the target system.
28860  Therefore usually a debugger on the host system connects to an on-target
28861  debugging stub which accepts only primitive commands.
28862  
28863 \newline
28864 Terms to enter into your favourite search engine could be 'remote debugging',
28865  'gdb stub' or 'inferior debugger'.
28866  (is there one?)
28867 \end_layout
28868
28869 \begin_layout Itemize
28870 use an on target hardware debugger.
28871  Some of the more modern MCUs include hardware support for setting break
28872  points and monitoring/changing variables by using dedicated hardware pins.
28873  This facility doesn't require additional code to run on the target and
28874  
28875 \emph on
28876 usually
28877 \emph default
28878  doesn't affect runtime behaviour until a breakpoint is hit.
28879  For the mcs51 most hardware debuggers use the AOMF
28880 \begin_inset LatexCommand \index{AOMF, AOMF51}
28881
28882 \end_inset
28883
28884  file (see 
28885 \begin_inset LatexCommand \ref{OMF file}
28886
28887 \end_inset
28888
28889 ) as input file.
28890  
28891 \end_layout
28892
28893 \begin_layout Standard
28894 Last not least:
28895 \end_layout
28896
28897 \begin_layout Itemize
28898 if you are not familiar with any of the following terms you're likely to
28899  run into problems rather sooner than later: 
28900 \emph on
28901 volatile
28902 \emph default
28903
28904 \emph on
28905 atomic
28906 \emph default
28907
28908 \emph on
28909 memory map
28910 \emph default
28911
28912 \emph on
28913 overlay
28914 \emph default
28915 .
28916  As an embedded programmer you 
28917 \emph on
28918 have
28919 \emph default
28920  to know them so why not look them up 
28921 \emph on
28922 before
28923 \emph default
28924  you have problems?)
28925 \end_layout
28926
28927 \begin_layout Itemize
28928 tell someone else about your problem (actually this is a surprisingly effective
28929  means to hunt down the bug even if the listener is not familiar with your
28930  environment).
28931  As 'failure to communicate' is probably one of the job-induced deformations
28932  of an embedded programmer this is highly encouraged.
28933 \end_layout
28934
28935 \begin_layout Section
28936 Debugging with SDCDB
28937 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28938
28939 \end_inset
28940
28941
28942 \begin_inset LatexCommand \index{SDCDB (debugger)}
28943
28944 \end_inset
28945
28946  
28947 \end_layout
28948
28949 \begin_layout Standard
28950 SDCC is distributed with a source level debugger
28951 \begin_inset LatexCommand \index{Debugger}
28952
28953 \end_inset
28954
28955 .
28956  The debugger uses a command line interface, the command repertoire of the
28957  debugger has been kept as close to gdb
28958 \begin_inset LatexCommand \index{gdb}
28959
28960 \end_inset
28961
28962  (the GNU debugger) as possible.
28963  The configuration and build process is part of the standard compiler installati
28964 on, which also builds and installs the debugger in the target directory
28965  specified during configuration.
28966  The debugger allows you debug BOTH at the C source and at the ASM source
28967  level.
28968 \end_layout
28969
28970 \begin_layout Subsection
28971 Compiling for Debugging
28972 \end_layout
28973
28974 \begin_layout Standard
28975 The -
28976 \begin_inset ERT
28977 status collapsed
28978
28979 \begin_layout Standard
28980
28981
28982 \backslash
28983 /
28984 \end_layout
28985
28986 \end_inset
28987
28988 -debug
28989 \begin_inset LatexCommand \index{-\/-debug}
28990
28991 \end_inset
28992
28993  option must be specified for all files for which debug information is to
28994  be generated.
28995  The compiler generates a .adb file for each of these files.
28996  The linker creates the .cdb
28997 \begin_inset LatexCommand \index{<file>.cdb}
28998
28999 \end_inset
29000
29001  file from the .adb
29002 \begin_inset LatexCommand \index{<file>.adb}
29003
29004 \end_inset
29005
29006  files and the address information.
29007  This .cdb is used by the debugger.
29008 \end_layout
29009
29010 \begin_layout Subsection
29011 How the Debugger Works
29012 \end_layout
29013
29014 \begin_layout Standard
29015 When the -
29016 \begin_inset ERT
29017 status collapsed
29018
29019 \begin_layout Standard
29020
29021
29022 \backslash
29023 /
29024 \end_layout
29025
29026 \end_inset
29027
29028 -debug option is specified the compiler generates extra symbol information
29029  some of which are put into the assembler source and some are put into the
29030  .adb file.
29031  Then the linker creates the .cdb file from the individual .adb files with
29032  the address information for the symbols.
29033  The debugger reads the symbolic information generated by the compiler &
29034  the address information generated by the linker.
29035  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29036  execution is controlled by the debugger.
29037  When a command is issued for the debugger, it translates it into appropriate
29038  commands for the simulator.
29039  (Currently SDCDM only connects to the simulator but 
29040 \emph on
29041 newcdb
29042 \emph default
29043  at 
29044 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29045
29046 \end_inset
29047
29048  is an effort to connect directly to the hardware.) 
29049 \end_layout
29050
29051 \begin_layout Subsection
29052 Starting the Debugger SDCDB
29053 \end_layout
29054
29055 \begin_layout Standard
29056 The debugger can be started using the following command line.
29057  (Assume the file you are debugging has the file name foo).
29058 \newline
29059
29060 \newline
29061
29062 \family sans
29063 \series bold
29064 sdcdb foo
29065 \newline
29066
29067 \family default
29068 \series default
29069
29070 \newline
29071 The debugger will look for the following files.
29072 \end_layout
29073
29074 \begin_layout Itemize
29075 foo.c - the source file.
29076 \end_layout
29077
29078 \begin_layout Itemize
29079 foo.cdb - the debugger symbol information file.
29080 \end_layout
29081
29082 \begin_layout Itemize
29083 foo.ihx - the Intel hex format
29084 \begin_inset LatexCommand \index{Intel hex format}
29085
29086 \end_inset
29087
29088  object file.
29089 \end_layout
29090
29091 \begin_layout Subsection
29092 SDCDB Command Line Options
29093 \end_layout
29094
29095 \begin_layout Itemize
29096 -
29097 \begin_inset ERT
29098 status collapsed
29099
29100 \begin_layout Standard
29101
29102
29103 \backslash
29104 /
29105 \end_layout
29106
29107 \end_inset
29108
29109 -directory=<source file directory> this option can used to specify the directory
29110  search list.
29111  The debugger will look into the directory list specified for source, cdb
29112  & ihx files.
29113  The items in the directory list must be separated by ':', e.g.
29114  if the source files can be in the directories /home/src1 and /home/src2,
29115  the -
29116 \begin_inset ERT
29117 status collapsed
29118
29119 \begin_layout Standard
29120
29121
29122 \backslash
29123 /
29124 \end_layout
29125
29126 \end_inset
29127
29128 -directory option should be -
29129 \begin_inset ERT
29130 status collapsed
29131
29132 \begin_layout Standard
29133
29134
29135 \backslash
29136 /
29137 \end_layout
29138
29139 \end_inset
29140
29141 -directory=/home/src1:/home/src2.
29142  Note there can be no spaces in the option.
29143  
29144 \end_layout
29145
29146 \begin_layout Itemize
29147 -cd <directory> - change to the <directory>.
29148 \end_layout
29149
29150 \begin_layout Itemize
29151 -fullname - used by GUI front ends.
29152 \end_layout
29153
29154 \begin_layout Itemize
29155 -cpu <cpu-type> - this argument is passed to the simulator please see the
29156  simulator docs for details.
29157 \end_layout
29158
29159 \begin_layout Itemize
29160 -X <Clock frequency > this options is passed to the simulator please see
29161  the simulator docs for details.
29162 \end_layout
29163
29164 \begin_layout Itemize
29165 -s <serial port file> passed to simulator see the simulator docs for details.
29166 \end_layout
29167
29168 \begin_layout Itemize
29169 -S <serial in,out> passed to simulator see the simulator docs for details.
29170 \end_layout
29171
29172 \begin_layout Itemize
29173 -k <port number> passed to simulator see the simulator docs for details.
29174 \end_layout
29175
29176 \begin_layout Subsection
29177 SDCDB Debugger Commands
29178 \end_layout
29179
29180 \begin_layout Standard
29181 As mentioned earlier the command interface for the debugger has been deliberatel
29182 y kept as close the GNU debugger gdb, as possible.
29183  This will help the integration with existing graphical user interfaces
29184  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29185  If you use a graphical user interface for the debugger you can skip this
29186  section.
29187 \end_layout
29188
29189 \begin_layout Subsubsection*
29190 break [line | file:line | function | file:function]
29191 \end_layout
29192
29193 \begin_layout Standard
29194 Set breakpoint at specified line or function:
29195 \newline
29196
29197 \newline
29198
29199 \family sans
29200 \series bold
29201 sdcdb>break 100 
29202 \newline
29203 sdcdb>break foo.c:100
29204 \newline
29205 sdcdb>break funcfoo
29206 \newline
29207 sdcdb>break foo.c:funcfoo
29208 \end_layout
29209
29210 \begin_layout Subsubsection*
29211 clear [line | file:line | function | file:function ]
29212 \end_layout
29213
29214 \begin_layout Standard
29215 Clear breakpoint at specified line or function:
29216 \newline
29217
29218 \newline
29219
29220 \family sans
29221 \series bold
29222 sdcdb>clear 100
29223 \newline
29224 sdcdb>clear foo.c:100
29225 \newline
29226 sdcdb>clear funcfoo
29227 \newline
29228 sdcdb>clear foo.c:funcfoo
29229 \end_layout
29230
29231 \begin_layout Subsubsection*
29232 continue
29233 \end_layout
29234
29235 \begin_layout Standard
29236 Continue program being debugged, after breakpoint.
29237 \end_layout
29238
29239 \begin_layout Subsubsection*
29240 finish
29241 \end_layout
29242
29243 \begin_layout Standard
29244 Execute till the end of the current function.
29245 \end_layout
29246
29247 \begin_layout Subsubsection*
29248 delete [n]
29249 \end_layout
29250
29251 \begin_layout Standard
29252 Delete breakpoint number 'n'.
29253  If used without any option clear ALL user defined break points.
29254 \end_layout
29255
29256 \begin_layout Subsubsection*
29257 info [break | stack | frame | registers ]
29258 \end_layout
29259
29260 \begin_layout Itemize
29261 info break - list all breakpoints
29262 \end_layout
29263
29264 \begin_layout Itemize
29265 info stack - show the function call stack.
29266 \end_layout
29267
29268 \begin_layout Itemize
29269 info frame - show information about the current execution frame.
29270 \end_layout
29271
29272 \begin_layout Itemize
29273 info registers - show content of all registers.
29274 \end_layout
29275
29276 \begin_layout Subsubsection*
29277 step
29278 \end_layout
29279
29280 \begin_layout Standard
29281 Step program until it reaches a different source line.
29282  Note: pressing <return> repeats the last command.
29283 \end_layout
29284
29285 \begin_layout Subsubsection*
29286 next
29287 \end_layout
29288
29289 \begin_layout Standard
29290 Step program, proceeding through subroutine calls.
29291 \end_layout
29292
29293 \begin_layout Subsubsection*
29294 run
29295 \end_layout
29296
29297 \begin_layout Standard
29298 Start debugged program.
29299 \end_layout
29300
29301 \begin_layout Subsubsection*
29302 ptype variable 
29303 \end_layout
29304
29305 \begin_layout Standard
29306 Print type information of the variable.
29307 \end_layout
29308
29309 \begin_layout Subsubsection*
29310 print variable
29311 \end_layout
29312
29313 \begin_layout Standard
29314 print value of variable.
29315 \end_layout
29316
29317 \begin_layout Subsubsection*
29318 file filename
29319 \end_layout
29320
29321 \begin_layout Standard
29322 load the given file name.
29323  Note this is an alternate method of loading file for debugging.
29324 \end_layout
29325
29326 \begin_layout Subsubsection*
29327 frame
29328 \end_layout
29329
29330 \begin_layout Standard
29331 print information about current frame.
29332 \end_layout
29333
29334 \begin_layout Subsubsection*
29335 set srcmode
29336 \end_layout
29337
29338 \begin_layout Standard
29339 Toggle between C source & assembly source.
29340 \end_layout
29341
29342 \begin_layout Subsubsection*
29343 ! simulator command
29344 \end_layout
29345
29346 \begin_layout Standard
29347 Send the string following '!' to the simulator, the simulator response is
29348  displayed.
29349  Note the debugger does not interpret the command being sent to the simulator,
29350  so if a command like 'go' is sent the debugger can loose its execution
29351  context and may display incorrect values.
29352 \end_layout
29353
29354 \begin_layout Subsubsection*
29355 quit
29356 \end_layout
29357
29358 \begin_layout Standard
29359 "Watch me now.
29360  Iam going Down.
29361  My name is Bobby Brown"
29362 \end_layout
29363
29364 \begin_layout Subsection
29365 Interfacing SDCDB with DDD
29366 \end_layout
29367
29368 \begin_layout Standard
29369 \begin_inset Note Note
29370 status collapsed
29371
29372 \begin_layout Standard
29373 The screenshot was converted from png to eps with: 
29374 \begin_inset Quotes sld
29375 \end_inset
29376
29377 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29378 \begin_inset Quotes srd
29379 \end_inset
29380
29381  which produces a pretty compact eps file which is free from compression
29382  artifacts.
29383 \end_layout
29384
29385 \begin_layout Standard
29386 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29387  as this broke the build system on Sourceforge (pdf-file was broken.
29388  pdflatex does not accept eps files).
29389 \end_layout
29390
29391 \end_inset
29392
29393
29394 \end_layout
29395
29396 \begin_layout Standard
29397 The 
29398 \emph on
29399 p
29400 \emph default
29401 ortable 
29402 \emph on
29403 n
29404 \emph default
29405 etwork 
29406 \emph on
29407 g
29408 \emph default
29409 raphics File 
29410 \size footnotesize
29411
29412 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29413
29414 \end_inset
29415
29416
29417 \size default
29418  shows a screenshot of a debugging session with DDD
29419 \begin_inset LatexCommand \index{DDD (debugger)}
29420
29421 \end_inset
29422
29423  (Unix only) on a simulated 8032.
29424  The debugging session might not run as smoothly as the screenshot suggests.
29425  The debugger allows setting of breakpoints, displaying and changing variables,
29426  single stepping through C and assembler code.
29427  
29428 \newline
29429 The source was compiled with 
29430 \family sans
29431 \series bold
29432
29433 \newline
29434
29435 \newline
29436 sdcc -
29437 \family default
29438 \series default
29439
29440 \begin_inset ERT
29441 status collapsed
29442
29443 \begin_layout Standard
29444
29445
29446 \backslash
29447 /
29448 \end_layout
29449
29450 \end_inset
29451
29452
29453 \family sans
29454 \series bold
29455 -debug ddd_example.c
29456 \family default
29457 \series default
29458  
29459 \family sans
29460 \series bold
29461
29462 \newline
29463
29464 \family default
29465 \series default
29466
29467 \newline
29468 and DDD was invoked with 
29469 \family sans
29470 \series bold
29471
29472 \newline
29473
29474 \newline
29475 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29476 \end_layout
29477
29478 \begin_layout Standard
29479 \begin_inset Note Note
29480 status open
29481
29482 \begin_layout Standard
29483 Check that the double quotes or an apostroph within the command line survive
29484  the LyX tool chain.
29485  Previously the apostrophs got slanted in the PDF output so a cut and paste
29486  did not work.
29487 \end_layout
29488
29489 \end_inset
29490
29491
29492 \end_layout
29493
29494 \begin_layout Subsection
29495 Interfacing SDCDB with XEmacs
29496 \begin_inset LatexCommand \index{XEmacs}
29497
29498 \end_inset
29499
29500
29501 \begin_inset LatexCommand \index{Emacs}
29502
29503 \end_inset
29504
29505
29506 \end_layout
29507
29508 \begin_layout Standard
29509 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29510  sdcdb.el and sdcdbsrc.el.
29511  These two files can be found in the $(prefix)/bin directory after the installat
29512 ion is complete.
29513  These files need to be loaded into XEmacs for the interface to work.
29514  This can be done at XEmacs startup time by inserting the following into
29515  your '.xemacs' file (which can be found in your HOME directory): 
29516 \newline
29517
29518 \newline
29519
29520 \family typewriter
29521 (load-file sdcdbsrc.el) 
29522 \family default
29523
29524 \newline
29525
29526 \newline
29527 .xemacs is a lisp file so the () around the command is REQUIRED.
29528  The files can also be loaded dynamically while XEmacs is running, set the
29529  environment variable 'EMACSLOADPATH' to the installation bin directory
29530  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29531  To start the interface enter the following command: 
29532 \newline
29533
29534 \newline
29535
29536 \family sans
29537 \series bold
29538 ESC-x sdcdbsrc
29539 \family default
29540 \series default
29541
29542 \newline
29543
29544 \newline
29545 You will prompted to enter the file name to be debugged.
29546  
29547 \newline
29548
29549 \newline
29550 The command line options that are passed to the simulator directly are
29551  bound to default values in the file sdcdbsrc.el.
29552  The variables are listed below, these values maybe changed as required.
29553 \end_layout
29554
29555 \begin_layout Itemize
29556 sdcdbsrc-cpu-type '51
29557 \end_layout
29558
29559 \begin_layout Itemize
29560 sdcdbsrc-frequency '11059200
29561 \end_layout
29562
29563 \begin_layout Itemize
29564 sdcdbsrc-serial nil
29565 \end_layout
29566
29567 \begin_layout Standard
29568 The following is a list of key mapping for the debugger interface.
29569 \end_layout
29570
29571 \begin_layout Standard
29572 \InsetSpace ~
29573
29574 \family typewriter
29575
29576 \newline
29577 ;;\InsetSpace ~
29578 Current Listing :: 
29579 \newline
29580 ;;key\InsetSpace ~
29581 \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 binding\InsetSpace ~
29595 \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 Comment 
29617 \newline
29618 ;;---\InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 -------\InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 -------
29655 \newline
29656 ;; 
29657 \newline
29658 ;;\InsetSpace ~
29659 n\InsetSpace ~
29660 \InsetSpace ~
29661 \InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 sdcdb-next-fro
29675 m-src\InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 SDCDB next command 
29686 \newline
29687 ;;\InsetSpace ~
29688 b\InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 \InsetSpace ~
29692 \InsetSpace ~
29693 \InsetSpace ~
29694 \InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 sdcdb-back-from-src\InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 SDCDB back command 
29714 \newline
29715 ;;\InsetSpace ~
29716 c\InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 sdcdb-cont-f
29732 rom-src\InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 SDCDB continue command
29743 \newline
29744 ;;\InsetSpace ~
29745 s\InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 \InsetSpace ~
29751 \InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 sdcdb-step-from-src\InsetSpace ~
29761 \InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 SDCDB step command 
29771 \newline
29772 ;;\InsetSpace ~
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 sdcdb-w
29789 hatis-c-sexp\InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 SDCDB ptypecommand for data at 
29800 \newline
29801 ;;\InsetSpace ~
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 buffer point 
29849 \newline
29850 ;;\InsetSpace ~
29851 x\InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 sdcdbsrc-delete\InsetSpace ~
29867 \InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 SDCD
29881 B Delete all breakpoints if no arg 
29882 \newline
29883 ;;\InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \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 given or delete arg (C-u arg x) 
29931 \newline
29932 ;;\InsetSpace ~
29933 m\InsetSpace ~
29934 \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 sdcdbsrc
29949 -frame\InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 SDCDB Display current frame if no arg, 
29965 \newline
29966 ;;\InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 \InsetSpace ~
29975 \InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 \InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \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 given or display frame arg
30014  
30015 \newline
30016 ;;\InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \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 buffer point 
30064 \newline
30065 ;;\InsetSpace ~
30066 !\InsetSpace ~
30067 \InsetSpace ~
30068 \InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 sdcdbsrc-goto-sdcdb\InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 Goto the SDCDB output buffer 
30092 \newline
30093 ;;\InsetSpace ~
30094 p\InsetSpace ~
30095 \InsetSpace ~
30096 \InsetSpace ~
30097 \InsetSpace ~
30098 \InsetSpace ~
30099 \InsetSpace ~
30100 \InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104 \InsetSpace ~
30105 \InsetSpace ~
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109 sdcdb-prin
30110 t-c-sexp\InsetSpace ~
30111 \InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 SDCDB print command for data at 
30122 \newline
30123 ;;\InsetSpace ~
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 buffer point 
30171 \newline
30172 ;;\InsetSpace ~
30173 g\InsetSpace ~
30174 \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 sdcdbsrc-goto-sdcdb\InsetSpace ~
30189 \InsetSpace ~
30190 \InsetSpace ~
30191 \InsetSpace ~
30192 \InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 Got
30199 o the SDCDB output buffer 
30200 \newline
30201 ;;\InsetSpace ~
30202 t\InsetSpace ~
30203 \InsetSpace ~
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 \InsetSpace ~
30208 \InsetSpace ~
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 \InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 sdcdbsrc-mode\InsetSpace ~
30218 \InsetSpace ~
30219 \InsetSpace ~
30220 \InsetSpace ~
30221 \InsetSpace ~
30222 \InsetSpace ~
30223 \InsetSpace ~
30224 \InsetSpace ~
30225 \InsetSpace ~
30226 \InsetSpace ~
30227 \InsetSpace ~
30228 \InsetSpace ~
30229 \InsetSpace ~
30230 \InsetSpace ~
30231 \InsetSpace ~
30232 \InsetSpace ~
30233 Toggles Sdcdbsrc mode (turns it
30234  off) 
30235 \newline
30236 ;; 
30237 \newline
30238 ;;\InsetSpace ~
30239 C-c\InsetSpace ~
30240 C-f\InsetSpace ~
30241 \InsetSpace ~
30242 \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 sdcdb-finish-from-src\InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256 \InsetSpace ~
30257 SDCDB finish command 
30258 \newline
30259 ;; 
30260 \newline
30261 ;;\InsetSpace ~
30262 C-x\InsetSpace ~
30263 SPC\InsetSpace ~
30264 \InsetSpace ~
30265 \InsetSpace ~
30266 \InsetSpace ~
30267 \InsetSpace ~
30268 \InsetSpace ~
30269 \InsetSpace ~
30270 \InsetSpace ~
30271 \InsetSpace ~
30272 sdcdb-brea
30273 k\InsetSpace ~
30274 \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 Set break for line with point 
30292 \newline
30293 ;;\InsetSpace ~
30294 ESC\InsetSpace ~
30295 t\InsetSpace ~
30296 \InsetSpace ~
30297 \InsetSpace ~
30298 \InsetSpace ~
30299 \InsetSpace ~
30300 \InsetSpace ~
30301 \InsetSpace ~
30302 \InsetSpace ~
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306 sdcdbsrc-mode\InsetSpace ~
30307 \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 Toggle Sdcdbsrc mode 
30323 \newline
30324 ;;\InsetSpace ~
30325 ESC\InsetSpace ~
30326 m\InsetSpace ~
30327 \InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 \InsetSpace ~
30332 \InsetSpace ~
30333 \InsetSpace ~
30334 \InsetSpace ~
30335 \InsetSpace ~
30336 \InsetSpace ~
30337 sdc
30338 dbsrc-srcmode\InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 \InsetSpace ~
30344 \InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 \InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 \InsetSpace ~
30351 Toggle list mode 
30352 \newline
30353 ;; 
30354 \newline
30355
30356 \family default
30357
30358 \newpage
30359
30360 \end_layout
30361
30362 \begin_layout Chapter
30363 TIPS
30364 \end_layout
30365
30366 \begin_layout Standard
30367 Here are a few guidelines that will help the compiler generate more efficient
30368  code, some of the tips are specific to this compiler others are generally
30369  good programming practice.
30370 \end_layout
30371
30372 \begin_layout Itemize
30373 Use the smallest data type to represent your data-value.
30374  If it is known in advance that the value is going to be less than 256 then
30375  use an 'unsigned char' instead of a 'short' or 'int'.
30376  Please note, that ANSI C requires both signed and unsigned chars to be
30377  promoted to 'signed int'
30378 \begin_inset LatexCommand \index{promotion to signed int}
30379
30380 \end_inset
30381
30382
30383 \begin_inset Marginal
30384 status collapsed
30385
30386 \begin_layout Standard
30387
30388 \series bold
30389 \InsetSpace ~
30390 !
30391 \end_layout
30392
30393 \end_inset
30394
30395  before doing any operation.
30396  This promotion
30397 \begin_inset LatexCommand \index{type promotion}
30398
30399 \end_inset
30400
30401
30402 \begin_inset LatexCommand \label{type promotion}
30403
30404 \end_inset
30405
30406  can be omitted, if the result is the same.
30407  The effect of the promotion rules together with the sign-extension is often
30408  surprising:
30409 \end_layout
30410
30411 \begin_deeper
30412 \begin_layout Verse
30413
30414 \family typewriter
30415 unsigned char uc = 0xfe;
30416 \newline
30417 if (uc * uc < 0) /* this is true! */
30418 \newline
30419 {
30420 \newline
30421 \InsetSpace ~
30422 \InsetSpace ~
30423 \InsetSpace ~
30424 \InsetSpace ~
30425 ....
30426 \newline
30427 }
30428 \end_layout
30429
30430 \begin_layout Standard
30431
30432 \family typewriter
30433 uc * uc
30434 \family default
30435  is evaluated as 
30436 \family typewriter
30437 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30438 \family default
30439 .
30440  
30441 \newline
30442 Another one:
30443 \end_layout
30444
30445 \begin_layout Verse
30446
30447 \family typewriter
30448 (unsigned char) -12 / (signed char) -3 = ...
30449 \end_layout
30450
30451 \begin_layout Standard
30452 No, the result is not 4:
30453 \end_layout
30454
30455 \begin_layout Verse
30456
30457 \family typewriter
30458 (int) (unsigned char) -12 / (int) (signed char) -3 =
30459 \newline
30460 (int) (unsigned char)
30461  0xf4 / (int) (signed char) 0xfd =
30462 \newline
30463 (int) 0x00f4 / (int) 0xfffd =
30464 \newline
30465 (int) 0x00f4
30466  / (int) 0xfffd =
30467 \newline
30468 (int) 244 / (int) -3 =
30469 \newline
30470 (int) -81 = (int) 0xffaf;
30471 \end_layout
30472
30473 \begin_layout Standard
30474 Don't complain, that gcc gives you a different result.
30475  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30476  Therefore the results are different.
30477 \newline
30478 From 
30479 \begin_inset Quotes sld
30480 \end_inset
30481
30482 comp.lang.c FAQ
30483 \begin_inset Quotes srd
30484 \end_inset
30485
30486 :
30487 \end_layout
30488
30489 \begin_layout Quote
30490
30491 \emph on
30492 If well-defined overflow characteristics are important and negative values
30493  are not, or if you want to steer clear of sign-extension problems when
30494  manipulating bits or bytes, use one of the corresponding unsigned types.
30495  (Beware when mixing signed and unsigned values in expressions, though.)
30496 \newline
30497 Although
30498  character types (especially unsigned char) can be used as "tiny" integers,
30499  doing so is sometimes more trouble than it's worth, due to unpredictable
30500  sign extension and increased code size.
30501 \end_layout
30502
30503 \end_deeper
30504 \begin_layout Itemize
30505 Use unsigned when it is known in advance that the value is not going to
30506  be negative.
30507  This helps especially if you are doing division or multiplication, bit-shifting
30508  or are using an array index.
30509 \end_layout
30510
30511 \begin_layout Itemize
30512 NEVER jump into a LOOP.
30513 \end_layout
30514
30515 \begin_layout Itemize
30516 Declare the variables to be local
30517 \begin_inset LatexCommand \index{local variables}
30518
30519 \end_inset
30520
30521  whenever possible, especially loop control variables (induction).
30522 \end_layout
30523
30524 \begin_layout Itemize
30525 Have a look at the assembly listing to get a 
30526 \begin_inset Quotes sld
30527 \end_inset
30528
30529 feeling
30530 \begin_inset Quotes srd
30531 \end_inset
30532
30533  for the code generation.
30534 \end_layout
30535
30536 \begin_layout Section
30537 Porting code from or to other compilers
30538 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30539
30540 \end_inset
30541
30542
30543 \end_layout
30544
30545 \begin_layout Itemize
30546 check whether endianness of the compilers differs and adapt where needed.
30547 \end_layout
30548
30549 \begin_layout Itemize
30550 check the device specific header files
30551 \begin_inset LatexCommand \index{Header files}
30552
30553 \end_inset
30554
30555
30556 \begin_inset LatexCommand \index{Include files}
30557
30558 \end_inset
30559
30560  for compiler specific syntax.
30561  Eventually include the file <compiler.h
30562 \begin_inset LatexCommand \index{compiler.h (include file)}
30563
30564 \end_inset
30565
30566
30567 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30568
30569 \end_inset
30570
30571  to allow using common header files.
30572  (see f.e.
30573  cc2510fx.h 
30574 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30575
30576 \end_inset
30577
30578 ).
30579 \end_layout
30580
30581 \begin_layout Itemize
30582 check whether the startup code contains the correct initialization (watchdog,
30583  peripherals).
30584 \end_layout
30585
30586 \begin_layout Itemize
30587 check whether the sizes of short, int, long match.
30588 \end_layout
30589
30590 \begin_layout Itemize
30591 check if some 16 or 32 bit hardware registers require a specific addressing
30592  order (least significant or most significant byte first) and adapt if needed
30593  (
30594 \emph on
30595 first
30596 \emph default
30597  and 
30598 \emph on
30599 last
30600 \emph default
30601  relate to time and not to lower/upper memory location here, so this is
30602  
30603 \emph on
30604 not
30605 \emph default
30606  the same as endianness).
30607 \end_layout
30608
30609 \begin_layout Itemize
30610 check whether the keyword 
30611 \emph on
30612 volatile
30613 \emph default
30614  is used where needed.
30615  The compilers might differ in their optimization characteristics (as different
30616  versions of the same compiler might also use more clever optimizations
30617  this is good idea anyway).
30618  See section 
30619 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30620
30621 \end_inset
30622
30623 .
30624 \end_layout
30625
30626 \begin_layout Itemize
30627 check that the compilers are not told to supress warnings.
30628 \end_layout
30629
30630 \begin_layout Itemize
30631 check and convert compiler specific extensions (interrupts, memory areas,
30632  pragmas etc.).
30633 \end_layout
30634
30635 \begin_layout Itemize
30636 check for differences in type promotion.
30637  Especially check for math operations on 
30638 \family typewriter
30639 char
30640 \family default
30641  or 
30642 \family typewriter
30643 unsigned char
30644 \family default
30645  variables.
30646  For the sake of C99 compatibility SDCC will probably promote these to 
30647 \family typewriter
30648 int
30649 \family default
30650  more often than other compilers.
30651  Eventually insert explicit casts to 
30652 \family typewriter
30653 (char) 
30654 \family default
30655 or
30656 \family typewriter
30657  (unsigned char)
30658 \family default
30659 .
30660  Also check that the ~\InsetSpace ~
30661 operator
30662 \begin_inset LatexCommand \index{\~\/ Operator}
30663
30664 \end_inset
30665
30666  is not used on 
30667 \family typewriter
30668 bit
30669 \begin_inset LatexCommand \index{bit}
30670
30671 \end_inset
30672
30673
30674 \family default
30675  variables, use the !\InsetSpace ~
30676 operator instead.
30677  See sections 
30678 \begin_inset LatexCommand \ref{type promotion}
30679
30680 \end_inset
30681
30682  and 
30683 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30684
30685 \end_inset
30686
30687 .
30688 \end_layout
30689
30690 \begin_layout Itemize
30691 check the assembly code generated for interrupt routines (f.e.
30692  for calls to possibly non-reentrant library functions).
30693 \end_layout
30694
30695 \begin_layout Itemize
30696 check whether timing loops result in proper timing (or preferably consider
30697  a rewrite of the code with timer based delays instead).
30698 \end_layout
30699
30700 \begin_layout Itemize
30701 check for differences in printf parameters (some compilers push (va_arg
30702 \begin_inset LatexCommand \index{vararg, va\_arg}
30703
30704 \end_inset
30705
30706 ) char variables as 
30707 \family typewriter
30708 int
30709 \family default
30710  others push them as 
30711 \family typewriter
30712 char
30713 \family default
30714 .
30715  See section 
30716 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30717
30718 \end_inset
30719
30720 ).
30721 \end_layout
30722
30723 \begin_layout Itemize
30724 check the resulting memory map
30725 \begin_inset LatexCommand \index{Memory map}
30726
30727 \end_inset
30728
30729 .
30730  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30731 ly idata, pdata, xdata).
30732  Eventually check if unexpected library functions are included.
30733 \end_layout
30734
30735 \begin_layout Section
30736 Tools
30737 \begin_inset LatexCommand \index{Tools}
30738
30739 \end_inset
30740
30741  included in the distribution
30742 \end_layout
30743
30744 \begin_layout Standard
30745 \align left
30746 \begin_inset Tabular
30747 <lyxtabular version="3" rows="12" columns="3">
30748 <features>
30749 <column alignment="left" valignment="top" leftline="true" width="0pt">
30750 <column alignment="left" valignment="top" leftline="true" width="0pt">
30751 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30752 <row topline="true" bottomline="true">
30753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30754 \begin_inset Text
30755
30756 \begin_layout Standard
30757
30758 \series bold
30759 Name
30760 \end_layout
30761
30762 \end_inset
30763 </cell>
30764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30765 \begin_inset Text
30766
30767 \begin_layout Standard
30768
30769 \series bold
30770 Purpose
30771 \end_layout
30772
30773 \end_inset
30774 </cell>
30775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30776 \begin_inset Text
30777
30778 \begin_layout Standard
30779
30780 \series bold
30781 Directory
30782 \end_layout
30783
30784 \end_inset
30785 </cell>
30786 </row>
30787 <row topline="true">
30788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30789 \begin_inset Text
30790
30791 \begin_layout Standard
30792 uCsim
30793 \begin_inset LatexCommand \index{uCsim}
30794
30795 \end_inset
30796
30797
30798 \end_layout
30799
30800 \end_inset
30801 </cell>
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30803 \begin_inset Text
30804
30805 \begin_layout Standard
30806 Simulator for various architectures
30807 \end_layout
30808
30809 \end_inset
30810 </cell>
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30812 \begin_inset Text
30813
30814 \begin_layout Standard
30815 sdcc/sim/ucsim
30816 \end_layout
30817
30818 \end_inset
30819 </cell>
30820 </row>
30821 <row topline="true">
30822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30823 \begin_inset Text
30824
30825 \begin_layout Standard
30826 keil2sdcc.pl
30827 \end_layout
30828
30829 \end_inset
30830 </cell>
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30832 \begin_inset Text
30833
30834 \begin_layout Standard
30835 header file
30836 \begin_inset LatexCommand \index{Header files}
30837
30838 \end_inset
30839
30840
30841 \begin_inset LatexCommand \index{Include files}
30842
30843 \end_inset
30844
30845  conversion
30846 \end_layout
30847
30848 \end_inset
30849 </cell>
30850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30851 \begin_inset Text
30852
30853 \begin_layout Standard
30854 sdcc/support/scripts
30855 \end_layout
30856
30857 \end_inset
30858 </cell>
30859 </row>
30860 <row topline="true">
30861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30862 \begin_inset Text
30863
30864 \begin_layout Standard
30865 mh2h.c
30866 \end_layout
30867
30868 \end_inset
30869 </cell>
30870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30871 \begin_inset Text
30872
30873 \begin_layout Standard
30874 header file conversion
30875 \end_layout
30876
30877 \end_inset
30878 </cell>
30879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30880 \begin_inset Text
30881
30882 \begin_layout Standard
30883 sdcc/support/scripts
30884 \end_layout
30885
30886 \end_inset
30887 </cell>
30888 </row>
30889 <row topline="true">
30890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30891 \begin_inset Text
30892
30893 \begin_layout Standard
30894 as-gbz80
30895 \end_layout
30896
30897 \end_inset
30898 </cell>
30899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30900 \begin_inset Text
30901
30902 \begin_layout Standard
30903 Assembler
30904 \end_layout
30905
30906 \end_inset
30907 </cell>
30908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30909 \begin_inset Text
30910
30911 \begin_layout Standard
30912
30913 \family roman
30914 \series medium
30915 \shape up
30916 \size normal
30917 \emph off
30918 \bar no
30919 \noun off
30920 \color none
30921 sdcc/bin
30922 \end_layout
30923
30924 \end_inset
30925 </cell>
30926 </row>
30927 <row topline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \begin_layout Standard
30932 as-z80
30933 \end_layout
30934
30935 \end_inset
30936 </cell>
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30938 \begin_inset Text
30939
30940 \begin_layout Standard
30941 Assembler
30942 \end_layout
30943
30944 \end_inset
30945 </cell>
30946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30947 \begin_inset Text
30948
30949 \begin_layout Standard
30950
30951 \family roman
30952 \series medium
30953 \shape up
30954 \size normal
30955 \emph off
30956 \bar no
30957 \noun off
30958 \color none
30959 sdcc/bin
30960 \end_layout
30961
30962 \end_inset
30963 </cell>
30964 </row>
30965 <row topline="true">
30966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30967 \begin_inset Text
30968
30969 \begin_layout Standard
30970 asx8051
30971 \end_layout
30972
30973 \end_inset
30974 </cell>
30975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30976 \begin_inset Text
30977
30978 \begin_layout Standard
30979 Assembler
30980 \end_layout
30981
30982 \end_inset
30983 </cell>
30984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30985 \begin_inset Text
30986
30987 \begin_layout Standard
30988
30989 \family roman
30990 \series medium
30991 \shape up
30992 \size normal
30993 \emph off
30994 \bar no
30995 \noun off
30996 \color none
30997 sdcc/bin
30998 \end_layout
30999
31000 \end_inset
31001 </cell>
31002 </row>
31003 <row topline="true">
31004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31005 \begin_inset Text
31006
31007 \begin_layout Standard
31008 SDCDB
31009 \end_layout
31010
31011 \end_inset
31012 </cell>
31013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31014 \begin_inset Text
31015
31016 \begin_layout Standard
31017 Simulator
31018 \end_layout
31019
31020 \end_inset
31021 </cell>
31022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31023 \begin_inset Text
31024
31025 \begin_layout Standard
31026
31027 \family roman
31028 \series medium
31029 \shape up
31030 \size normal
31031 \emph off
31032 \bar no
31033 \noun off
31034 \color none
31035 sdcc/bin
31036 \end_layout
31037
31038 \end_inset
31039 </cell>
31040 </row>
31041 <row topline="true">
31042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31043 \begin_inset Text
31044
31045 \begin_layout Standard
31046 aslink
31047 \end_layout
31048
31049 \end_inset
31050 </cell>
31051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31052 \begin_inset Text
31053
31054 \begin_layout Standard
31055 Linker
31056 \end_layout
31057
31058 \end_inset
31059 </cell>
31060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31061 \begin_inset Text
31062
31063 \begin_layout Standard
31064
31065 \family roman
31066 \series medium
31067 \shape up
31068 \size normal
31069 \emph off
31070 \bar no
31071 \noun off
31072 \color none
31073 sdcc/bin
31074 \end_layout
31075
31076 \end_inset
31077 </cell>
31078 </row>
31079 <row topline="true">
31080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31081 \begin_inset Text
31082
31083 \begin_layout Standard
31084 link-z80
31085 \end_layout
31086
31087 \end_inset
31088 </cell>
31089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31090 \begin_inset Text
31091
31092 \begin_layout Standard
31093 Linker
31094 \end_layout
31095
31096 \end_inset
31097 </cell>
31098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31099 \begin_inset Text
31100
31101 \begin_layout Standard
31102
31103 \family roman
31104 \series medium
31105 \shape up
31106 \size normal
31107 \emph off
31108 \bar no
31109 \noun off
31110 \color none
31111 sdcc/bin
31112 \end_layout
31113
31114 \end_inset
31115 </cell>
31116 </row>
31117 <row topline="true">
31118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31119 \begin_inset Text
31120
31121 \begin_layout Standard
31122 link-gbz80
31123 \end_layout
31124
31125 \end_inset
31126 </cell>
31127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31128 \begin_inset Text
31129
31130 \begin_layout Standard
31131 Linker
31132 \end_layout
31133
31134 \end_inset
31135 </cell>
31136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31137 \begin_inset Text
31138
31139 \begin_layout Standard
31140
31141 \family roman
31142 \series medium
31143 \shape up
31144 \size normal
31145 \emph off
31146 \bar no
31147 \noun off
31148 \color none
31149 sdcc/bin
31150 \end_layout
31151
31152 \end_inset
31153 </cell>
31154 </row>
31155 <row topline="true" bottomline="true">
31156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31157 \begin_inset Text
31158
31159 \begin_layout Standard
31160 packihx
31161 \end_layout
31162
31163 \end_inset
31164 </cell>
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31166 \begin_inset Text
31167
31168 \begin_layout Standard
31169 Intel Hex packer 
31170 \begin_inset LatexCommand \index{packihx (tool)}
31171
31172 \end_inset
31173
31174
31175 \end_layout
31176
31177 \end_inset
31178 </cell>
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31180 \begin_inset Text
31181
31182 \begin_layout Standard
31183
31184 \family roman
31185 \series medium
31186 \shape up
31187 \size normal
31188 \emph off
31189 \bar no
31190 \noun off
31191 \color none
31192 sdcc/bin
31193 \end_layout
31194
31195 \end_inset
31196 </cell>
31197 </row>
31198 </lyxtabular>
31199
31200 \end_inset
31201
31202
31203 \newline
31204
31205 \end_layout
31206
31207 \begin_layout Section
31208 Documentation
31209 \begin_inset LatexCommand \index{Documentation}
31210
31211 \end_inset
31212
31213  included in the distribution
31214 \end_layout
31215
31216 \begin_layout Standard
31217 \align left
31218 \begin_inset Tabular
31219 <lyxtabular version="3" rows="10" columns="2">
31220 <features>
31221 <column alignment="block" valignment="top" leftline="true" width="40col%">
31222 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31223 <row topline="true" bottomline="true" endhead="true">
31224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31225 \begin_inset Text
31226
31227 \begin_layout Standard
31228
31229 \series bold
31230 Subject / Title
31231 \end_layout
31232
31233 \end_inset
31234 </cell>
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31236 \begin_inset Text
31237
31238 \begin_layout Standard
31239
31240 \series bold
31241 Filename / Where to get
31242 \end_layout
31243
31244 \end_inset
31245 </cell>
31246 </row>
31247 <row topline="true">
31248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31249 \begin_inset Text
31250
31251 \begin_layout Standard
31252 SDCC Compiler User Guide
31253 \end_layout
31254
31255 \end_inset
31256 </cell>
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31258 \begin_inset Text
31259
31260 \begin_layout Standard
31261 You're reading it right now
31262 \emph on
31263  \InsetSpace ~
31264 \InsetSpace ~
31265 \InsetSpace ~
31266
31267 \hfill
31268 online at:
31269 \emph default
31270
31271 \newline
31272
31273 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31274
31275 \end_inset
31276
31277
31278 \end_layout
31279
31280 \end_inset
31281 </cell>
31282 </row>
31283 <row topline="true">
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31285 \begin_inset Text
31286
31287 \begin_layout Standard
31288 Changelog of SDCC
31289 \end_layout
31290
31291 \end_inset
31292 </cell>
31293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31294 \begin_inset Text
31295
31296 \begin_layout Standard
31297 sdcc/Changelog
31298 \emph on
31299  \InsetSpace ~
31300 \InsetSpace ~
31301 \InsetSpace ~
31302
31303 \hfill
31304 online at:
31305 \emph default
31306
31307 \newline
31308
31309 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31310
31311 \end_inset
31312
31313
31314 \end_layout
31315
31316 \end_inset
31317 </cell>
31318 </row>
31319 <row topline="true">
31320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31321 \begin_inset Text
31322
31323 \begin_layout Standard
31324 ASXXXX
31325 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31326
31327 \end_inset
31328
31329
31330 \begin_inset LatexCommand \index{Assembler documentation}
31331
31332 \end_inset
31333
31334  Assemblers and
31335 \newline
31336 ASLINK
31337 \begin_inset LatexCommand \index{aslink}
31338
31339 \end_inset
31340
31341
31342 \begin_inset LatexCommand \index{Linker documentation}
31343
31344 \end_inset
31345
31346  Relocating Linker
31347 \end_layout
31348
31349 \end_inset
31350 </cell>
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31352 \begin_inset Text
31353
31354 \begin_layout Standard
31355 sdcc/as/doc/asxhtm.html 
31356 \emph on
31357 \InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360
31361 \hfill
31362 online at:
31363 \emph default
31364
31365 \newline
31366
31367 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31368
31369 \end_inset
31370
31371
31372 \end_layout
31373
31374 \end_inset
31375 </cell>
31376 </row>
31377 <row topline="true">
31378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31379 \begin_inset Text
31380
31381 \begin_layout Standard
31382 SDCC regression test
31383 \begin_inset LatexCommand \index{Regression test}
31384
31385 \end_inset
31386
31387
31388 \end_layout
31389
31390 \end_inset
31391 </cell>
31392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31393 \begin_inset Text
31394
31395 \begin_layout Standard
31396 sdcc/doc/test_suite_spec.pdf 
31397 \emph on
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401
31402 \hfill
31403 online at:
31404 \emph default
31405
31406 \newline
31407
31408 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31409
31410 \end_inset
31411
31412
31413 \end_layout
31414
31415 \end_inset
31416 </cell>
31417 </row>
31418 <row topline="true">
31419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31420 \begin_inset Text
31421
31422 \begin_layout Standard
31423 Various notes
31424 \end_layout
31425
31426 \end_inset
31427 </cell>
31428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31429 \begin_inset Text
31430
31431 \begin_layout Standard
31432 sdcc/doc/* 
31433 \emph on
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437
31438 \hfill
31439 online at:
31440 \emph default
31441
31442 \newline
31443
31444 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31445
31446 \end_inset
31447
31448
31449 \end_layout
31450
31451 \end_inset
31452 </cell>
31453 </row>
31454 <row topline="true">
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31456 \begin_inset Text
31457
31458 \begin_layout Standard
31459 Notes on debugging with SDCDB
31460 \begin_inset LatexCommand \index{SDCDB (debugger)}
31461
31462 \end_inset
31463
31464
31465 \end_layout
31466
31467 \end_inset
31468 </cell>
31469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31470 \begin_inset Text
31471
31472 \begin_layout Standard
31473 sdcc/debugger/README 
31474 \emph on
31475 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478
31479 \hfill
31480 online at
31481 \emph default
31482 :
31483 \newline
31484
31485 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31486
31487 \end_inset
31488
31489
31490 \end_layout
31491
31492 \end_inset
31493 </cell>
31494 </row>
31495 <row topline="true">
31496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 \begin_inset Text
31498
31499 \begin_layout Standard
31500 uCsim
31501 \begin_inset LatexCommand \index{uCsim}
31502
31503 \end_inset
31504
31505  Software simulator for microcontrollers
31506 \end_layout
31507
31508 \end_inset
31509 </cell>
31510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31511 \begin_inset Text
31512
31513 \begin_layout Standard
31514
31515 \family roman
31516 \series medium
31517 \shape up
31518 \size normal
31519 \emph off
31520 \bar no
31521 \noun off
31522 \color none
31523 sdcc/sim/ucsim/doc
31524 \family default
31525 \series default
31526 \shape default
31527 \size default
31528 \emph default
31529 \bar default
31530 \noun default
31531 /index.html 
31532 \emph on
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 \InsetSpace ~
31536
31537 \hfill
31538 online at:
31539 \emph default
31540
31541 \newline
31542
31543 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31544
31545 \end_inset
31546
31547
31548 \end_layout
31549
31550 \end_inset
31551 </cell>
31552 </row>
31553 <row topline="true">
31554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31555 \begin_inset Text
31556
31557 \begin_layout Standard
31558 Temporary notes on the pic16
31559 \begin_inset LatexCommand \index{PIC16}
31560
31561 \end_inset
31562
31563  port
31564 \end_layout
31565
31566 \end_inset
31567 </cell>
31568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31569 \begin_inset Text
31570
31571 \begin_layout Standard
31572 sdcc/src/pic16/NOTES 
31573 \emph on
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577
31578 \hfill
31579 online at:
31580 \newline
31581
31582 \emph default
31583
31584 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31585
31586 \end_inset
31587
31588
31589 \end_layout
31590
31591 \end_inset
31592 </cell>
31593 </row>
31594 <row topline="true" bottomline="true">
31595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31596 \begin_inset Text
31597
31598 \begin_layout Standard
31599 SDCC internal documentation (debugging file format)
31600 \end_layout
31601
31602 \end_inset
31603 </cell>
31604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31605 \begin_inset Text
31606
31607 \begin_layout Standard
31608 sdcc/doc/
31609 \family roman
31610 \series medium
31611 \shape up
31612 \size normal
31613 \emph off
31614 \bar no
31615 \noun off
31616 \color none
31617 cdbfileformat.pd
31618 \family default
31619 \series default
31620 \shape default
31621 \size default
31622 \emph default
31623 \bar default
31624 \noun default
31625 f
31626 \emph on
31627  \InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630
31631 \hfill
31632 online at:
31633 \emph default
31634
31635 \newline
31636
31637 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31638
31639 \end_inset
31640
31641
31642 \end_layout
31643
31644 \end_inset
31645 </cell>
31646 </row>
31647 </lyxtabular>
31648
31649 \end_inset
31650
31651
31652 \newline
31653
31654 \end_layout
31655
31656 \begin_layout Section
31657 Related open source tools
31658 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31659
31660 \end_inset
31661
31662
31663 \begin_inset LatexCommand \index{Related tools}
31664
31665 \end_inset
31666
31667
31668 \end_layout
31669
31670 \begin_layout Standard
31671 \align left
31672 \begin_inset Tabular
31673 <lyxtabular version="3" rows="16" columns="3">
31674 <features>
31675 <column alignment="left" valignment="top" leftline="true" width="0pt">
31676 <column alignment="block" valignment="top" leftline="true" width="30line%">
31677 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31678 <row topline="true" bottomline="true">
31679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31680 \begin_inset Text
31681
31682 \begin_layout Standard
31683
31684 \series bold
31685 Name
31686 \end_layout
31687
31688 \end_inset
31689 </cell>
31690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31691 \begin_inset Text
31692
31693 \begin_layout Standard
31694
31695 \series bold
31696 Purpose
31697 \end_layout
31698
31699 \end_inset
31700 </cell>
31701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31702 \begin_inset Text
31703
31704 \begin_layout Standard
31705
31706 \series bold
31707 Where to get
31708 \end_layout
31709
31710 \end_inset
31711 </cell>
31712 </row>
31713 <row topline="true">
31714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31715 \begin_inset Text
31716
31717 \begin_layout Standard
31718 gpsim
31719 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31720
31721 \end_inset
31722
31723
31724 \end_layout
31725
31726 \end_inset
31727 </cell>
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31729 \begin_inset Text
31730
31731 \begin_layout Standard
31732 PIC simulator
31733 \end_layout
31734
31735 \end_inset
31736 </cell>
31737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31738 \begin_inset Text
31739
31740 \begin_layout Standard
31741 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31742
31743 \end_inset
31744
31745
31746 \end_layout
31747
31748 \end_inset
31749 </cell>
31750 </row>
31751 <row topline="true">
31752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31753 \begin_inset Text
31754
31755 \begin_layout Standard
31756 gputils
31757 \begin_inset LatexCommand \index{gputils (pic tools)}
31758
31759 \end_inset
31760
31761
31762 \end_layout
31763
31764 \end_inset
31765 </cell>
31766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31767 \begin_inset Text
31768
31769 \begin_layout Standard
31770 GNU PIC utilities
31771 \end_layout
31772
31773 \end_inset
31774 </cell>
31775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31776 \begin_inset Text
31777
31778 \begin_layout Standard
31779 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31780
31781 \end_inset
31782
31783
31784 \end_layout
31785
31786 \end_inset
31787 </cell>
31788 </row>
31789 <row topline="true">
31790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31791 \begin_inset Text
31792
31793 \begin_layout Standard
31794 flP5
31795 \end_layout
31796
31797 \end_inset
31798 </cell>
31799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31800 \begin_inset Text
31801
31802 \begin_layout Standard
31803 PIC programmer
31804 \end_layout
31805
31806 \end_inset
31807 </cell>
31808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31809 \begin_inset Text
31810
31811 \begin_layout Standard
31812 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31813
31814 \end_inset
31815
31816
31817 \end_layout
31818
31819 \end_inset
31820 </cell>
31821 </row>
31822 <row topline="true">
31823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31824 \begin_inset Text
31825
31826 \begin_layout Standard
31827 ec2drv/newcdb
31828 \end_layout
31829
31830 \end_inset
31831 </cell>
31832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31833 \begin_inset Text
31834
31835 \begin_layout Standard
31836 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31837  (Unix only)
31838 \end_layout
31839
31840 \end_inset
31841 </cell>
31842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31843 \begin_inset Text
31844
31845 \begin_layout Standard
31846 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31847
31848 \end_inset
31849
31850
31851 \end_layout
31852
31853 \end_inset
31854 </cell>
31855 </row>
31856 <row topline="true">
31857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31858 \begin_inset Text
31859
31860 \begin_layout Standard
31861 indent
31862 \begin_inset LatexCommand \index{indent (source formatting tool)}
31863
31864 \end_inset
31865
31866
31867 \end_layout
31868
31869 \end_inset
31870 </cell>
31871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31872 \begin_inset Text
31873
31874 \begin_layout Standard
31875 Formats C source - Master of the white spaces
31876 \end_layout
31877
31878 \end_inset
31879 </cell>
31880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31881 \begin_inset Text
31882
31883 \begin_layout Standard
31884 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31885
31886 \end_inset
31887
31888
31889 \end_layout
31890
31891 \end_inset
31892 </cell>
31893 </row>
31894 <row topline="true">
31895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31896 \begin_inset Text
31897
31898 \begin_layout Standard
31899 srecord
31900 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31901
31902 \end_inset
31903
31904
31905 \end_layout
31906
31907 \end_inset
31908 </cell>
31909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31910 \begin_inset Text
31911
31912 \begin_layout Standard
31913 Object file conversion, checksumming, ...
31914 \end_layout
31915
31916 \end_inset
31917 </cell>
31918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31919 \begin_inset Text
31920
31921 \begin_layout Standard
31922 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31923
31924 \end_inset
31925
31926
31927 \end_layout
31928
31929 \end_inset
31930 </cell>
31931 </row>
31932 <row topline="true">
31933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31934 \begin_inset Text
31935
31936 \begin_layout Standard
31937 objdump
31938 \begin_inset LatexCommand \index{objdump (tool)}
31939
31940 \end_inset
31941
31942
31943 \end_layout
31944
31945 \end_inset
31946 </cell>
31947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31948 \begin_inset Text
31949
31950 \begin_layout Standard
31951 Object file conversion, ...
31952 \end_layout
31953
31954 \end_inset
31955 </cell>
31956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31957 \begin_inset Text
31958
31959 \begin_layout Standard
31960 Part of binutils (should be there anyway)
31961 \end_layout
31962
31963 \end_inset
31964 </cell>
31965 </row>
31966 <row topline="true">
31967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31968 \begin_inset Text
31969
31970 \begin_layout Standard
31971 cmon51
31972 \end_layout
31973
31974 \end_inset
31975 </cell>
31976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31977 \begin_inset Text
31978
31979 \begin_layout Standard
31980 8051 monitor (hex up-/download, single step, disassemble)
31981 \end_layout
31982
31983 \end_inset
31984 </cell>
31985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31986 \begin_inset Text
31987
31988 \begin_layout Standard
31989 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31990
31991 \end_inset
31992
31993
31994 \end_layout
31995
31996 \end_inset
31997 </cell>
31998 </row>
31999 <row topline="true">
32000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32001 \begin_inset Text
32002
32003 \begin_layout Standard
32004 doxygen
32005 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32006
32007 \end_inset
32008
32009
32010 \end_layout
32011
32012 \end_inset
32013 </cell>
32014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32015 \begin_inset Text
32016
32017 \begin_layout Standard
32018 Source code documentation system
32019 \end_layout
32020
32021 \end_inset
32022 </cell>
32023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32024 \begin_inset Text
32025
32026 \begin_layout Standard
32027 \begin_inset LatexCommand \url{http://www.doxygen.org}
32028
32029 \end_inset
32030
32031
32032 \end_layout
32033
32034 \end_inset
32035 </cell>
32036 </row>
32037 <row topline="true">
32038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32039 \begin_inset Text
32040
32041 \begin_layout Standard
32042 kdevelop
32043 \end_layout
32044
32045 \end_inset
32046 </cell>
32047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32048 \begin_inset Text
32049
32050 \begin_layout Standard
32051 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32052 \end_layout
32053
32054 \end_inset
32055 </cell>
32056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32057 \begin_inset Text
32058
32059 \begin_layout Standard
32060 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32061
32062 \end_inset
32063
32064
32065 \end_layout
32066
32067 \end_inset
32068 </cell>
32069 </row>
32070 <row topline="true">
32071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32072 \begin_inset Text
32073
32074 \begin_layout Standard
32075 paulmon
32076 \end_layout
32077
32078 \end_inset
32079 </cell>
32080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32081 \begin_inset Text
32082
32083 \begin_layout Standard
32084 8051 monitor (hex up-/download, single step, disassemble)
32085 \end_layout
32086
32087 \end_inset
32088 </cell>
32089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32090 \begin_inset Text
32091
32092 \begin_layout Standard
32093 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32094
32095 \end_inset
32096
32097
32098 \end_layout
32099
32100 \end_inset
32101 </cell>
32102 </row>
32103 <row topline="true">
32104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32105 \begin_inset Text
32106
32107 \begin_layout Standard
32108 splint
32109 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32110
32111 \end_inset
32112
32113
32114 \end_layout
32115
32116 \end_inset
32117 </cell>
32118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32119 \begin_inset Text
32120
32121 \begin_layout Standard
32122 Statically checks c sources (see 
32123 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32124
32125 \end_inset
32126
32127 )
32128 \end_layout
32129
32130 \end_inset
32131 </cell>
32132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32133 \begin_inset Text
32134
32135 \begin_layout Standard
32136 \begin_inset LatexCommand \url{http://www.splint.org}
32137
32138 \end_inset
32139
32140
32141 \end_layout
32142
32143 \end_inset
32144 </cell>
32145 </row>
32146 <row topline="true" bottomline="true">
32147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32148 \begin_inset Text
32149
32150 \begin_layout Standard
32151 ddd
32152 \begin_inset LatexCommand \index{DDD (debugger)}
32153
32154 \end_inset
32155
32156
32157 \end_layout
32158
32159 \end_inset
32160 </cell>
32161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32162 \begin_inset Text
32163
32164 \begin_layout Standard
32165 Debugger, serves nicely as GUI to SDCDB
32166 \begin_inset LatexCommand \index{SDCDB (debugger)}
32167
32168 \end_inset
32169
32170  (Unix only)
32171 \end_layout
32172
32173 \end_inset
32174 </cell>
32175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32176 \begin_inset Text
32177
32178 \begin_layout Standard
32179 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32180
32181 \end_inset
32182
32183
32184 \end_layout
32185
32186 \end_inset
32187 </cell>
32188 </row>
32189 <row bottomline="true">
32190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32191 \begin_inset Text
32192
32193 \begin_layout Standard
32194 d52
32195 \begin_inset LatexCommand \index{d52}
32196
32197 \end_inset
32198
32199
32200 \begin_inset LatexCommand \index{d52 (disassembler)}
32201
32202 \end_inset
32203
32204
32205 \end_layout
32206
32207 \end_inset
32208 </cell>
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32210 \begin_inset Text
32211
32212 \begin_layout Standard
32213 Disassembler, can count instruction cycles
32214 \begin_inset LatexCommand \index{instruction cycles (count)}
32215
32216 \end_inset
32217
32218 , use with options -pnd
32219 \end_layout
32220
32221 \end_inset
32222 </cell>
32223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32224 \begin_inset Text
32225
32226 \begin_layout Standard
32227 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32228
32229 \end_inset
32230
32231
32232 \end_layout
32233
32234 \end_inset
32235 </cell>
32236 </row>
32237 <row bottomline="true">
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32239 \begin_inset Text
32240
32241 \begin_layout Standard
32242 cmake
32243 \begin_inset LatexCommand \index{cmake}
32244
32245 \end_inset
32246
32247
32248 \end_layout
32249
32250 \end_inset
32251 </cell>
32252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32253 \begin_inset Text
32254
32255 \begin_layout Standard
32256 Cross platform build system, generates Makefiles
32257 \begin_inset LatexCommand \index{Makefile}
32258
32259 \end_inset
32260
32261  and project workspaces
32262 \begin_inset LatexCommand \index{project workspace}
32263
32264 \end_inset
32265
32266
32267 \end_layout
32268
32269 \end_inset
32270 </cell>
32271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32272 \begin_inset Text
32273
32274 \begin_layout Standard
32275 \begin_inset LatexCommand \url{http://www.cmake.org}
32276
32277 \end_inset
32278
32279  \InsetSpace ~
32280 \InsetSpace ~
32281 \InsetSpace ~
32282 \InsetSpace ~
32283 and a dedicated wiki entry: 
32284 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32285
32286 \end_inset
32287
32288
32289 \end_layout
32290
32291 \end_inset
32292 </cell>
32293 </row>
32294 </lyxtabular>
32295
32296 \end_inset
32297
32298
32299 \newline
32300
32301 \end_layout
32302
32303 \begin_layout Section
32304 Related documentation / recommended reading
32305 \end_layout
32306
32307 \begin_layout Standard
32308 \align left
32309 \begin_inset Tabular
32310 <lyxtabular version="3" rows="7" columns="3">
32311 <features>
32312 <column alignment="left" valignment="top" leftline="true" width="0pt">
32313 <column alignment="left" valignment="top" leftline="true" width="0">
32314 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32315 <row topline="true" bottomline="true">
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32317 \begin_inset Text
32318
32319 \begin_layout Standard
32320
32321 \series bold
32322 Name
32323 \end_layout
32324
32325 \end_inset
32326 </cell>
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_inset Text
32329
32330 \begin_layout Standard
32331
32332 \series bold
32333 Subject / Title
32334 \end_layout
32335
32336 \end_inset
32337 </cell>
32338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32339 \begin_inset Text
32340
32341 \begin_layout Standard
32342
32343 \series bold
32344 Where to get
32345 \end_layout
32346
32347 \end_inset
32348 </cell>
32349 </row>
32350 <row topline="true">
32351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32352 \begin_inset Text
32353
32354 \begin_layout Standard
32355
32356 \family roman
32357 \series medium
32358 \shape up
32359 \size normal
32360 \emph off
32361 \bar no
32362 \noun off
32363 \color none
32364 c-refcard.pdf
32365 \end_layout
32366
32367 \end_inset
32368 </cell>
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32370 \begin_inset Text
32371
32372 \begin_layout Standard
32373 C Reference Card
32374 \begin_inset LatexCommand \index{C Reference card}
32375
32376 \end_inset
32377
32378 , 2 pages
32379 \end_layout
32380
32381 \end_inset
32382 </cell>
32383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32384 \begin_inset Text
32385
32386 \begin_layout Standard
32387 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32388
32389 \end_inset
32390
32391
32392 \end_layout
32393
32394 \end_inset
32395 </cell>
32396 </row>
32397 <row topline="true">
32398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32399 \begin_inset Text
32400
32401 \begin_layout Standard
32402 c-faq
32403 \end_layout
32404
32405 \end_inset
32406 </cell>
32407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32408 \begin_inset Text
32409
32410 \begin_layout Standard
32411 C-FAQ
32412 \begin_inset LatexCommand \index{C FAQ}
32413
32414 \end_inset
32415
32416
32417 \end_layout
32418
32419 \end_inset
32420 </cell>
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32422 \begin_inset Text
32423
32424 \begin_layout Standard
32425 \begin_inset LatexCommand \url{http://www.c-faq.com}
32426
32427 \end_inset
32428
32429
32430 \end_layout
32431
32432 \end_inset
32433 </cell>
32434 </row>
32435 <row topline="true">
32436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32437 \begin_inset Text
32438
32439 \begin_layout Standard
32440 ISO/IEC 9899:TC2
32441 \end_layout
32442
32443 \end_inset
32444 </cell>
32445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32446 \begin_inset Text
32447
32448 \begin_layout Standard
32449 \begin_inset Quotes sld
32450 \end_inset
32451
32452 C-Standard
32453 \begin_inset Quotes srd
32454 \end_inset
32455
32456
32457 \end_layout
32458
32459 \end_inset
32460 </cell>
32461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32462 \begin_inset Text
32463
32464 \begin_layout Standard
32465
32466 \size footnotesize
32467 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32468
32469 \end_inset
32470
32471
32472 \end_layout
32473
32474 \end_inset
32475 </cell>
32476 </row>
32477 <row topline="true">
32478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 \begin_inset Text
32480
32481 \begin_layout Standard
32482 ISO/IEC DTR 18037
32483 \end_layout
32484
32485 \end_inset
32486 </cell>
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32488 \begin_inset Text
32489
32490 \begin_layout Standard
32491 \begin_inset Quotes sld
32492 \end_inset
32493
32494 Extensions for Embedded C
32495 \begin_inset Quotes srd
32496 \end_inset
32497
32498
32499 \end_layout
32500
32501 \end_inset
32502 </cell>
32503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32504 \begin_inset Text
32505
32506 \begin_layout Standard
32507
32508 \size footnotesize
32509 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32510
32511 \end_inset
32512
32513
32514 \end_layout
32515
32516 \end_inset
32517 </cell>
32518 </row>
32519 <row topline="true">
32520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32521 \begin_inset Text
32522
32523 \begin_layout Standard
32524
32525 \end_layout
32526
32527 \end_inset
32528 </cell>
32529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32530 \begin_inset Text
32531
32532 \begin_layout Standard
32533 Latest datasheet of target CPU
32534 \end_layout
32535
32536 \end_inset
32537 </cell>
32538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32539 \begin_inset Text
32540
32541 \begin_layout Standard
32542 vendor
32543 \end_layout
32544
32545 \end_inset
32546 </cell>
32547 </row>
32548 <row topline="true" bottomline="true">
32549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32550 \begin_inset Text
32551
32552 \begin_layout Standard
32553
32554 \end_layout
32555
32556 \end_inset
32557 </cell>
32558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32559 \begin_inset Text
32560
32561 \begin_layout Standard
32562 Revision history of datasheet
32563 \end_layout
32564
32565 \end_inset
32566 </cell>
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32568 \begin_inset Text
32569
32570 \begin_layout Standard
32571 vendor
32572 \end_layout
32573
32574 \end_inset
32575 </cell>
32576 </row>
32577 </lyxtabular>
32578
32579 \end_inset
32580
32581
32582 \newline
32583
32584 \end_layout
32585
32586 \begin_layout Section
32587 Application notes specifically for SDCC
32588 \end_layout
32589
32590 \begin_layout Standard
32591 SDCC makes no claims about the completeness of this list and about up-to-datenes
32592 s or correctness of the application notes
32593 \begin_inset LatexCommand \index{Application notes}
32594
32595 \end_inset
32596
32597 .
32598 \end_layout
32599
32600 \begin_layout Standard
32601 \align left
32602
32603 \size footnotesize
32604 \begin_inset Tabular
32605 <lyxtabular version="3" rows="7" columns="3">
32606 <features>
32607 <column alignment="block" valignment="top" leftline="true" width="17col%">
32608 <column alignment="block" valignment="top" leftline="true" width="27col%">
32609 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32610 <row topline="true" bottomline="true">
32611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32612 \begin_inset Text
32613
32614 \begin_layout Standard
32615
32616 \series bold
32617 \size footnotesize
32618 Vendor
32619 \end_layout
32620
32621 \end_inset
32622 </cell>
32623 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32624 \begin_inset Text
32625
32626 \begin_layout Standard
32627
32628 \series bold
32629 \size footnotesize
32630 Subject / Title
32631 \end_layout
32632
32633 \end_inset
32634 </cell>
32635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32636 \begin_inset Text
32637
32638 \begin_layout Standard
32639
32640 \series bold
32641 \size footnotesize
32642 Where to get
32643 \end_layout
32644
32645 \end_inset
32646 </cell>
32647 </row>
32648 <row topline="true">
32649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32650 \begin_inset Text
32651
32652 \begin_layout Standard
32653
32654 \size footnotesize
32655 Maxim / Dallas
32656 \end_layout
32657
32658 \end_inset
32659 </cell>
32660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32661 \begin_inset Text
32662
32663 \begin_layout Standard
32664
32665 \size footnotesize
32666 Using the SDCC Compiler for the DS80C400
32667 \begin_inset LatexCommand \index{DS80C400}
32668
32669 \end_inset
32670
32671
32672 \end_layout
32673
32674 \end_inset
32675 </cell>
32676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32677 \begin_inset Text
32678
32679 \begin_layout Standard
32680
32681 \size footnotesize
32682 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32683
32684 \end_inset
32685
32686
32687 \end_layout
32688
32689 \end_inset
32690 </cell>
32691 </row>
32692 <row topline="true">
32693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32694 \begin_inset Text
32695
32696 \begin_layout Standard
32697
32698 \size footnotesize
32699 Maxim / Dallas
32700 \end_layout
32701
32702 \end_inset
32703 </cell>
32704 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32705 \begin_inset Text
32706
32707 \begin_layout Standard
32708
32709 \size footnotesize
32710 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32711 \begin_inset LatexCommand \index{DS89C4x0}
32712
32713 \end_inset
32714
32715  Family of Microcontrollers
32716 \end_layout
32717
32718 \end_inset
32719 </cell>
32720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32721 \begin_inset Text
32722
32723 \begin_layout Standard
32724
32725 \size footnotesize
32726 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32727
32728 \end_inset
32729
32730
32731 \end_layout
32732
32733 \end_inset
32734 </cell>
32735 </row>
32736 <row topline="true">
32737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32738 \begin_inset Text
32739
32740 \begin_layout Standard
32741
32742 \size footnotesize
32743 Silicon Laboratories / Cygnal
32744 \end_layout
32745
32746 \end_inset
32747 </cell>
32748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32749 \begin_inset Text
32750
32751 \begin_layout Standard
32752
32753 \size footnotesize
32754 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32755 \begin_inset LatexCommand \index{IDE}
32756
32757 \end_inset
32758
32759
32760 \end_layout
32761
32762 \end_inset
32763 </cell>
32764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32765 \begin_inset Text
32766
32767 \begin_layout Standard
32768
32769 \size footnotesize
32770 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32771
32772 \end_inset
32773
32774
32775 \end_layout
32776
32777 \end_inset
32778 </cell>
32779 </row>
32780 <row topline="true">
32781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32782 \begin_inset Text
32783
32784 \begin_layout Standard
32785
32786 \size footnotesize
32787 Ramtron / Goal Semiconductor
32788 \end_layout
32789
32790 \end_inset
32791 </cell>
32792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32793 \begin_inset Text
32794
32795 \begin_layout Standard
32796
32797 \size footnotesize
32798 Interfacing SDCC to Syn and Textpad
32799 \end_layout
32800
32801 \end_inset
32802 </cell>
32803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32804 \begin_inset Text
32805
32806 \begin_layout Standard
32807
32808 \size footnotesize
32809 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32810
32811 \end_inset
32812
32813
32814 \end_layout
32815
32816 \end_inset
32817 </cell>
32818 </row>
32819 <row topline="true">
32820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32821 \begin_inset Text
32822
32823 \begin_layout Standard
32824
32825 \size footnotesize
32826 Ramtron / Goal Semiconductor
32827 \end_layout
32828
32829 \end_inset
32830 </cell>
32831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32832 \begin_inset Text
32833
32834 \begin_layout Standard
32835
32836 \size footnotesize
32837 Installing and Configuring SDCC and Crimson Editor 
32838 \end_layout
32839
32840 \end_inset
32841 </cell>
32842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32843 \begin_inset Text
32844
32845 \begin_layout Standard
32846
32847 \size footnotesize
32848 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32849
32850 \end_inset
32851
32852
32853 \end_layout
32854
32855 \end_inset
32856 </cell>
32857 </row>
32858 <row topline="true" bottomline="true">
32859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32860 \begin_inset Text
32861
32862 \begin_layout Standard
32863
32864 \size footnotesize
32865 Texas Instruments
32866 \end_layout
32867
32868 \end_inset
32869 </cell>
32870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32871 \begin_inset Text
32872
32873 \begin_layout Standard
32874
32875 \size footnotesize
32876 MSC12xx Programming with SDCC
32877 \end_layout
32878
32879 \end_inset
32880 </cell>
32881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32882 \begin_inset Text
32883
32884 \begin_layout Standard
32885
32886 \size footnotesize
32887 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32888
32889 \end_inset
32890
32891
32892 \end_layout
32893
32894 \end_inset
32895 </cell>
32896 </row>
32897 </lyxtabular>
32898
32899 \end_inset
32900
32901
32902 \end_layout
32903
32904 \begin_layout Section
32905 Some Questions
32906 \end_layout
32907
32908 \begin_layout Standard
32909 Some questions answered, some pointers given - it might be time to in turn
32910  ask 
32911 \emph on
32912 you
32913 \emph default
32914  some questions: 
32915 \end_layout
32916
32917 \begin_layout Itemize
32918 can you solve your project with the selected microcontroller? Would you
32919  find out early or rather late that your target is too small/slow/whatever?
32920  Can you switch to a slightly better device if it doesn't fit?
32921 \end_layout
32922
32923 \begin_layout Itemize
32924 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32925  and/or another programming language be more adequate? Would an operating
32926  system on the target device help?
32927 \end_layout
32928
32929 \begin_layout Itemize
32930 if you solved the problem, will the marketing department be happy?
32931 \end_layout
32932
32933 \begin_layout Itemize
32934 if the marketing department is happy, will customers be happy?
32935 \end_layout
32936
32937 \begin_layout Itemize
32938 if you're the project manager, marketing department and maybe even the customer
32939  in one person, have you tried to see the project from the outside?
32940 \end_layout
32941
32942 \begin_layout Itemize
32943 is the project done if you think it is done? Or is just that other interface/pro
32944 tocol/feature/configuration/option missing? How about website, manual(s),
32945  internationali(z|s)ation, packaging, labels, 2nd source for components,
32946  electromagnetic compatability/interference, documentation for production,
32947  production test software, update mechanism, patent issues?
32948 \end_layout
32949
32950 \begin_layout Itemize
32951 is your project adequately positioned in that magic triangle: fame, fortune,
32952  fun?
32953 \end_layout
32954
32955 \begin_layout Standard
32956 Maybe not all answers to these questions are known and some answers may
32957  even be 
32958 \emph on
32959 no
32960 \emph default
32961 , nevertheless knowing these questions may help you to avoid burnout
32962 \begin_inset Foot
32963 status open
32964
32965 \begin_layout Standard
32966 burnout is bad for electronic devices, programmers and motorcycle tyres
32967 \end_layout
32968
32969 \end_inset
32970
32971 .
32972  Chances are you didn't want to hear some of them...
32973 \end_layout
32974
32975 \begin_layout Chapter
32976 Support
32977 \begin_inset LatexCommand \index{Support}
32978
32979 \end_inset
32980
32981
32982 \end_layout
32983
32984 \begin_layout Standard
32985 SDCC has grown to be a large project.
32986  The compiler alone (without the preprocessor, assembler and linker) is
32987  well over 150,000 lines of code (blank stripped).
32988  The open source nature of this project is a key to its continued growth
32989  and support.
32990  You gain the benefit and support of many active software developers and
32991  end users.
32992  Is SDCC perfect? No, that's why we need your help.
32993  The developers take pride in fixing reported bugs.
32994  You can help by reporting the bugs and helping other SDCC users.
32995  There are lots of ways to contribute, and we encourage you to take part
32996  in making SDCC a great software package.
32997  
32998 \end_layout
32999
33000 \begin_layout Standard
33001 The SDCC project is hosted on the SDCC sourceforge site at 
33002 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33003
33004 \end_inset
33005
33006 .
33007  You'll find the complete set of mailing lists
33008 \begin_inset LatexCommand \index{Mailing list(s)}
33009
33010 \end_inset
33011
33012 , forums, bug reporting system, patch submission
33013 \begin_inset LatexCommand \index{Patch submission}
33014
33015 \end_inset
33016
33017  system, download
33018 \begin_inset LatexCommand \index{download}
33019
33020 \end_inset
33021
33022  area and Subversion code repository
33023 \begin_inset LatexCommand \index{Subversion code repository}
33024
33025 \end_inset
33026
33027  there.
33028 \end_layout
33029
33030 \begin_layout Section
33031 Reporting Bugs
33032 \begin_inset LatexCommand \index{Bug reporting}
33033
33034 \end_inset
33035
33036
33037 \begin_inset LatexCommand \index{Reporting bugs}
33038
33039 \end_inset
33040
33041
33042 \end_layout
33043
33044 \begin_layout Standard
33045 The recommended way of reporting bugs is using the infrastructure of the
33046  sourceforge site.
33047  You can follow the status of bug reports there and have an overview about
33048  the known bugs.
33049 \end_layout
33050
33051 \begin_layout Standard
33052 Bug reports are automatically forwarded to the developer mailing list and
33053  will be fixed ASAP.
33054  When reporting a bug, it is very useful to include a small test program
33055  (the smaller the better) which reproduces the problem.
33056  If you can isolate the problem by looking at the generated assembly code,
33057  this can be very helpful.
33058  Compiling your program with the -
33059 \begin_inset ERT
33060 status collapsed
33061
33062 \begin_layout Standard
33063
33064
33065 \backslash
33066 /
33067 \end_layout
33068
33069 \end_inset
33070
33071 -dumpall
33072 \begin_inset LatexCommand \index{-\/-dumpall}
33073
33074 \end_inset
33075
33076  option can sometimes be useful in locating optimization problems.
33077  When reporting a bug please make sure you:
33078 \end_layout
33079
33080 \begin_layout Enumerate
33081 Attach the code you are compiling with SDCC.
33082  
33083 \end_layout
33084
33085 \begin_layout Enumerate
33086 Specify the exact command you use to run SDCC, or attach your Makefile.
33087  
33088 \end_layout
33089
33090 \begin_layout Enumerate
33091 Specify the SDCC version (type "
33092 \family sans
33093 \series bold
33094 sdcc -v
33095 \family default
33096 \series default
33097 "), your platform, and operating system.
33098  
33099 \end_layout
33100
33101 \begin_layout Enumerate
33102 Provide an exact copy of any error message or incorrect output.
33103  
33104 \end_layout
33105
33106 \begin_layout Enumerate
33107 Put something meaningful in the subject of your message.
33108 \end_layout
33109
33110 \begin_layout Standard
33111 Please attempt to include these 5 important parts, as applicable, in all
33112  requests for support or when reporting any problems or bugs with SDCC.
33113  Though this will make your message lengthy, it will greatly improve your
33114  chance that SDCC users and developers will be able to help you.
33115  Some SDCC developers are frustrated by bug reports without code provided
33116  that they can use to reproduce and ultimately fix the problem, so please
33117  be sure to provide sample code if you are reporting a bug! 
33118 \end_layout
33119
33120 \begin_layout Standard
33121 Please have a short check that you are using a recent version of SDCC and
33122  the bug is not yet known.
33123  This is the link for reporting bugs: 
33124 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33125
33126 \end_inset
33127
33128 .
33129  With SDCC on average having more than 200 downloads
33130 \begin_inset LatexCommand \index{download}
33131
33132 \end_inset
33133
33134  on sourceforge per day
33135 \begin_inset Foot
33136 status open
33137
33138 \begin_layout Standard
33139 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33140  between 2002 and 2005.
33141  This does not include other methods of distribution.
33142 \end_layout
33143
33144 \end_inset
33145
33146  there must be some users.
33147  So it's not exactly easy to find a new bug.
33148  If you find one we need it: 
33149 \emph on
33150 reporting bugs is good
33151 \emph default
33152 .
33153 \end_layout
33154
33155 \begin_layout Section
33156 Requesting Features
33157 \begin_inset LatexCommand \label{sub:Requesting-Features}
33158
33159 \end_inset
33160
33161
33162 \begin_inset LatexCommand \index{Feature request}
33163
33164 \end_inset
33165
33166
33167 \begin_inset LatexCommand \index{Requesting features}
33168
33169 \end_inset
33170
33171
33172 \end_layout
33173
33174 \begin_layout Standard
33175 Like bug reports feature requests are forwarded to the developer mailing
33176  list.
33177  This is the link for requesting features: 
33178 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33179
33180 \end_inset
33181
33182 .
33183 \end_layout
33184
33185 \begin_layout Section
33186 Submitting patches
33187 \end_layout
33188
33189 \begin_layout Standard
33190 Like bug reports contributed patches are forwarded to the developer mailing
33191  list.
33192  This is the link for submitting patches
33193 \begin_inset LatexCommand \index{Patch submission}
33194
33195 \end_inset
33196
33197
33198 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33199
33200 \end_inset
33201
33202 .
33203 \end_layout
33204
33205 \begin_layout Standard
33206 You need to specify some parameters to the 
33207 \family typewriter
33208 diff
33209 \family default
33210  command for the patches to be useful.
33211  If you modified more than one file a patch created f.e.
33212  with 
33213 \family sans
33214 \series bold
33215
33216 \begin_inset Quotes sld
33217 \end_inset
33218
33219 diff -Naur unmodified_directory modified_directory >my_changes.patch
33220 \begin_inset Quotes srd
33221 \end_inset
33222
33223
33224 \family default
33225 \series default
33226  will be fine, otherwise 
33227 \family sans
33228 \series bold
33229
33230 \begin_inset Quotes sld
33231 \end_inset
33232
33233 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33234 \begin_inset Quotes srd
33235 \end_inset
33236
33237
33238 \series default
33239  
33240 \family default
33241 will do.
33242 \end_layout
33243
33244 \begin_layout Section
33245 Getting Help
33246 \end_layout
33247
33248 \begin_layout Standard
33249 These links should take you directly to the 
33250 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33251
33252 \end_inset
33253
33254
33255 \begin_inset Foot
33256 status open
33257
33258 \begin_layout Standard
33259 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33260  automated messages (mid 2003)
33261 \end_layout
33262
33263 \end_inset
33264
33265  and the 
33266 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33267
33268 \end_inset
33269
33270 , lists
33271 \begin_inset LatexCommand \index{Mailing list(s)}
33272
33273 \end_inset
33274
33275  and forums are archived and searchable so if you are lucky someone already
33276  had a similar problem.
33277  While mails to the lists themselves are delivered promptly their web front
33278  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33279  if you're seriously using SDCC please consider subscribing to the lists.
33280 \end_layout
33281
33282 \begin_layout Section
33283 ChangeLog
33284 \end_layout
33285
33286 \begin_layout Standard
33287 You can follow the status of the Subversion version
33288 \begin_inset LatexCommand \index{version}
33289
33290 \end_inset
33291
33292  of SDCC by watching the Changelog
33293 \begin_inset LatexCommand \index{Changelog}
33294
33295 \end_inset
33296
33297  in the Subversion repository
33298 \size footnotesize
33299  
33300 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33301
33302 \end_inset
33303
33304 .
33305 \end_layout
33306
33307 \begin_layout Section
33308 Subversion Source Code Repository
33309 \end_layout
33310
33311 \begin_layout Standard
33312 The output of 
33313 \family sans
33314 \series bold
33315 sdcc -
33316 \family default
33317
33318 \begin_inset ERT
33319 status open
33320
33321 \begin_layout Standard
33322
33323
33324 \backslash
33325 /
33326 \end_layout
33327
33328 \end_inset
33329
33330
33331 \family sans
33332 -version
33333 \family default
33334 \series default
33335  or the filenames of the snapshot versions of SDCC include date and its
33336  Subversion
33337 \begin_inset LatexCommand \index{Subversion code repository}
33338
33339 \end_inset
33340
33341  number.
33342  Subversion allows to download the source of recent or previous versions
33343  
33344 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33345
33346 \end_inset
33347
33348  (by number or by date).
33349  An on-line source code browser and detailled instructions are also available
33350  there.
33351  SDCC versions starting from 1999 up to now are available (currently the
33352  versions prior to the conversion from cvs
33353 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33354
33355 \end_inset
33356
33357  to Subversion (April 2006) are either by accessible by Subversion or by
33358  cvs).
33359 \end_layout
33360
33361 \begin_layout Section
33362 Release policy
33363 \begin_inset LatexCommand \index{Release policy}
33364
33365 \end_inset
33366
33367
33368 \end_layout
33369
33370 \begin_layout Standard
33371 Historically there often were long delays between official releases and
33372  the sourceforge download area tends to get not updated at all.
33373  Excuses in the past might have referred to problems with live range analysis,
33374  but as this was fixed a while ago, the current problem is that another
33375  excuse has to be found.
33376  Kidding aside, we have to get better there! On the other hand there are
33377  daily snapshots available at 
33378 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33379
33380 \end_inset
33381
33382 , and you can always build the very last version (hopefully with many bugs
33383  fixed, and features added) from the source code available at 
33384 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33385
33386 \end_inset
33387
33388 .
33389  The SDCC Wiki
33390 \begin_inset LatexCommand \index{wiki}
33391
33392 \end_inset
33393
33394
33395 \begin_inset LatexCommand \index{SDCC Wiki}
33396
33397 \end_inset
33398
33399  at 
33400 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33401
33402 \end_inset
33403
33404  also holds some information about past and future releases.
33405 \end_layout
33406
33407 \begin_layout Section
33408 Examples
33409 \begin_inset LatexCommand \index{Examples}
33410
33411 \end_inset
33412
33413
33414 \end_layout
33415
33416 \begin_layout Standard
33417 You'll find some small examples in the directory 
33418 \emph on
33419 sdcc/device/examples/.
33420  
33421 \emph default
33422 More examples and libraries are available at
33423 \emph on
33424  The SDCC Open Knowledge Resource 
33425 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33426
33427 \end_inset
33428
33429  
33430 \emph default
33431 web site or at 
33432 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33433
33434 \end_inset
33435
33436 .
33437 \end_layout
33438
33439 \begin_layout Standard
33440 \begin_inset Note Note
33441 status collapsed
33442
33443 \begin_layout Standard
33444 I did insert a reference to Paul's web site here although it seems rather
33445  dedicated to a specific 8032 board (I think it's okay because it f.e.
33446  shows LCD/Harddisc interface and has a free 8051 monitor.
33447  Independent 8032 board vendors face hard competition of heavily subsidized
33448  development boards anyway).
33449 \end_layout
33450
33451 \begin_layout Standard
33452 Maybe we should include some links to real world applications.
33453  Preferably pointer to pointers (one for each architecture) so this stays
33454  manageable here?
33455 \end_layout
33456
33457 \end_inset
33458
33459
33460 \end_layout
33461
33462 \begin_layout Section
33463 Quality control
33464 \begin_inset LatexCommand \label{sec:Quality-control}
33465
33466 \end_inset
33467
33468
33469 \begin_inset LatexCommand \index{Quality control}
33470
33471 \end_inset
33472
33473
33474 \end_layout
33475
33476 \begin_layout Standard
33477 The compiler is passed through snaphot build compile and build checks.
33478  The so called 
33479 \shape italic
33480 regression tests
33481 \shape default
33482
33483 \begin_inset LatexCommand \index{Regression test}
33484
33485 \end_inset
33486
33487  check that SDCC itself compiles flawlessly on several host platforms (i386,
33488  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33489  and checks the quality of the code generated by SDCC by running the code
33490  for several target platforms through simulators.
33491  The regression test suite comprises more than 100 files which expand to
33492  more than 500 test cases which include more than 4500 tests.
33493  The results of these tests are published daily on SDCC's snapshot page
33494  (click on the red or green symbols on the right side of 
33495 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33496
33497 \end_inset
33498
33499 ).
33500 \end_layout
33501
33502 \begin_layout Standard
33503 There is a separate document 
33504 \shape italic
33505 test_suite.pdf 
33506 \begin_inset LatexCommand \index{Test suite}
33507
33508 \end_inset
33509
33510
33511 \shape default
33512  
33513 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33514
33515 \end_inset
33516
33517  about the regression test suite.
33518 \end_layout
33519
33520 \begin_layout Standard
33521 You'll find the test code in the directory 
33522 \shape italic
33523 sdcc/support/regression
33524 \shape default
33525 .
33526  You can run these tests manually by running 
33527 \family sans
33528 make
33529 \family default
33530  in this directory (or f.e.
33531  
33532 \family sans
33533 \series bold
33534
33535 \begin_inset Quotes sld
33536 \end_inset
33537
33538 make test-mcs51
33539 \begin_inset Quotes srd
33540 \end_inset
33541
33542
33543 \family default
33544 \series default
33545  if you don't want to run the complete tests).
33546  The test code might also be interesting if you want to look for examples
33547 \begin_inset LatexCommand \index{Examples}
33548
33549 \end_inset
33550
33551  checking corner cases of SDCC or if you plan to submit patches
33552 \begin_inset LatexCommand \index{Patch submission}
33553
33554 \end_inset
33555
33556 .
33557 \end_layout
33558
33559 \begin_layout Standard
33560 The PIC14 port uses a different set of regression tests 
33561 \begin_inset LatexCommand \index{Regression test (PIC14)}
33562
33563 \end_inset
33564
33565 , you'll find them in the directory 
33566 \shape italic
33567 sdcc/src/regression
33568 \shape default
33569 .
33570 \end_layout
33571
33572 \begin_layout Section
33573 Use of SDCC in Education
33574 \end_layout
33575
33576 \begin_layout Standard
33577 In short: 
33578 \emph on
33579 highly
33580 \emph default
33581  encouraged
33582 \begin_inset Foot
33583 status open
33584
33585 \begin_layout Standard
33586 the phrase "use in education" might evoke the association "
33587 \emph on
33588 only
33589 \emph default
33590  fit for use in education".
33591  This connotation is not intended but nevertheless risked as the licensing
33592  of SDCC makes it difficult to offer educational discounts
33593 \end_layout
33594
33595 \end_inset
33596
33597 .
33598  If your rationales are to:
33599 \end_layout
33600
33601 \begin_layout Enumerate
33602 give students a chance to understand the 
33603 \emph on
33604 complete
33605 \emph default
33606  steps of code generation
33607 \end_layout
33608
33609 \begin_layout Enumerate
33610 have a curriculum that can be extended for years.
33611  Then you could use an fpga board as target and your curriculum will seamlessly
33612  extend from logic synthesis (
33613 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33614
33615 \end_inset
33616
33617
33618 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33619
33620 \end_inset
33621
33622 ), over assembly programming, to C to FPGA compilers (
33623 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33624
33625 \end_inset
33626
33627 ) and to C.
33628 \end_layout
33629
33630 \begin_layout Enumerate
33631 be able to insert excursions about skills like using a revision control
33632  system, submitting/applying patches, using a type-setting (as opposed to
33633  word-processing) engine LyX/LaTeX, using 
33634 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33635
33636 \end_inset
33637
33638 , following some 
33639 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33640
33641 \end_inset
33642
33643 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33644  Source Software, CPU simulation, compiler regression tests
33645 \begin_inset LatexCommand \index{Regression test}
33646
33647 \end_inset
33648
33649 .
33650  
33651 \newline
33652 And if there should be a shortage of ideas then you can always point students
33653  to the ever-growing feature request list 
33654 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33655
33656 \end_inset
33657
33658 .
33659 \end_layout
33660
33661 \begin_layout Enumerate
33662 not tie students to a specific host platform and instead allow them to use
33663  a host platform of 
33664 \emph on
33665 their
33666 \emph default
33667  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33668  and eventually 
33669 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33670
33671 \end_inset
33672
33673 )
33674 \end_layout
33675
33676 \begin_layout Enumerate
33677 not encourage students to use illegal copies of educational software
33678 \end_layout
33679
33680 \begin_layout Enumerate
33681 be immune to licensing/availability/price changes of the chosen tool chain
33682 \end_layout
33683
33684 \begin_layout Enumerate
33685 be able to change to a new target platform without having to adopt a new
33686  tool chain
33687 \end_layout
33688
33689 \begin_layout Enumerate
33690 have complete control over and insight into the tool chain
33691 \end_layout
33692
33693 \begin_layout Enumerate
33694 make your students aware about the pros and cons of open source software
33695  development
33696 \end_layout
33697
33698 \begin_layout Enumerate
33699 give back to the public as you are probably at least partially publically
33700  funded
33701 \end_layout
33702
33703 \begin_layout Enumerate
33704 give students a chance to publically prove their skills and to possibly
33705  see a world wide impact
33706 \end_layout
33707
33708 \begin_layout Standard
33709 then SDCC is probably among the first choices.
33710  Well, probably SDCC might be the only choice.
33711 \newpage
33712
33713 \end_layout
33714
33715 \begin_layout Chapter
33716 SDCC Technical Data
33717 \end_layout
33718
33719 \begin_layout Section
33720 Optimizations
33721 \begin_inset LatexCommand \index{Optimizations}
33722
33723 \end_inset
33724
33725
33726 \end_layout
33727
33728 \begin_layout Standard
33729 SDCC performs a host of standard optimizations in addition to some MCU specific
33730  optimizations.
33731  
33732 \end_layout
33733
33734 \begin_layout Subsection
33735 Sub-expression Elimination
33736 \begin_inset LatexCommand \index{Subexpression elimination}
33737
33738 \end_inset
33739
33740
33741 \end_layout
33742
33743 \begin_layout Standard
33744 The compiler does local and 
33745 \emph on
33746 g
33747 \emph default
33748 lobal 
33749 \emph on
33750 c
33751 \emph default
33752 ommon 
33753 \emph on
33754 s
33755 \emph default
33756 ubexpression 
33757 \emph on
33758 e
33759 \emph default
33760 limination, e.g.: 
33761 \end_layout
33762
33763 \begin_layout Verse
33764
33765 \family typewriter
33766 i = x + y + 1; 
33767 \newline
33768 j = x + y;
33769 \end_layout
33770
33771 \begin_layout Standard
33772 will be translated to
33773 \end_layout
33774
33775 \begin_layout Verse
33776
33777 \family typewriter
33778 iTemp = x + y; 
33779 \newline
33780 i = iTemp + 1; 
33781 \newline
33782 j = iTemp;
33783 \end_layout
33784
33785 \begin_layout Standard
33786 Some subexpressions are not as obvious as the above example, e.g.:
33787 \end_layout
33788
33789 \begin_layout Verse
33790
33791 \family typewriter
33792 a->b[i].c = 10; 
33793 \newline
33794 a->b[i].d = 11;
33795 \end_layout
33796
33797 \begin_layout Standard
33798 In this case the address arithmetic a->b[i] will be computed only once;
33799  the equivalent code in C would be.
33800 \end_layout
33801
33802 \begin_layout Verse
33803
33804 \family typewriter
33805 iTemp = a->b[i]; 
33806 \newline
33807 iTemp.c = 10; 
33808 \newline
33809 iTemp.d = 11;
33810 \end_layout
33811
33812 \begin_layout Standard
33813 The compiler will try to keep these temporary variables in registers.
33814 \end_layout
33815
33816 \begin_layout Subsection
33817 Dead-Code Elimination
33818 \begin_inset LatexCommand \index{Dead-code elimination}
33819
33820 \end_inset
33821
33822
33823 \end_layout
33824
33825 \begin_layout Verse
33826
33827 \family typewriter
33828 int global;
33829 \newline
33830
33831 \newline
33832 void f () { 
33833 \newline
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 int i; 
33837 \newline
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 i = 1; \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 /* dead store */ 
33846 \newline
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 global = 1;\InsetSpace ~
33850 /* dead
33851  store */ 
33852 \newline
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 global = 2; 
33856 \newline
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 return; 
33860 \newline
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 global = 3;\InsetSpace ~
33864 /* unreachable */ 
33865 \newline
33866 }
33867 \end_layout
33868
33869 \begin_layout Standard
33870 will be changed to
33871 \end_layout
33872
33873 \begin_layout Verse
33874
33875 \family typewriter
33876 int global;
33877 \newline
33878
33879 \newline
33880 void f () {
33881 \newline
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 global = 2; 
33885 \newline
33886 }
33887 \end_layout
33888
33889 \begin_layout Subsection
33890 Copy-Propagation
33891 \begin_inset LatexCommand \index{Copy propagation}
33892
33893 \end_inset
33894
33895
33896 \end_layout
33897
33898 \begin_layout Verse
33899
33900 \family typewriter
33901 int f() { 
33902 \newline
33903 \InsetSpace ~
33904 \InsetSpace ~
33905 int i, j; 
33906 \newline
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 i = 10; 
33910 \newline
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 j = i; 
33914 \newline
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 return j; 
33918 \newline
33919 }
33920 \end_layout
33921
33922 \begin_layout Standard
33923 will be changed to 
33924 \end_layout
33925
33926 \begin_layout Verse
33927
33928 \family typewriter
33929 int f() { 
33930 \newline
33931 \InsetSpace ~
33932 \InsetSpace ~
33933 int i, j; 
33934 \newline
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 i = 10; 
33938 \newline
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 j = 10; 
33942 \newline
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 return 10; 
33946 \newline
33947 }
33948 \end_layout
33949
33950 \begin_layout Standard
33951 Note: the dead stores created by this copy propagation will be eliminated
33952  by dead-code elimination.
33953 \end_layout
33954
33955 \begin_layout Subsection
33956 Loop Optimizations
33957 \begin_inset LatexCommand \index{Loop optimization}
33958
33959 \end_inset
33960
33961
33962 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33963
33964 \end_inset
33965
33966
33967 \end_layout
33968
33969 \begin_layout Standard
33970 Two types of loop optimizations are done by SDCC 
33971 \emph on
33972 loop invariant
33973 \emph default
33974  lifting and
33975 \emph on
33976  strength reduction
33977 \emph default
33978  of loop induction variables.
33979  In addition to the strength reduction the optimizer marks the induction
33980  variables and the register allocator tries to keep the induction variables
33981  in registers for the duration of the loop.
33982  Because of this preference of the register allocator
33983 \begin_inset LatexCommand \index{Register allocation}
33984
33985 \end_inset
33986
33987 , loop induction optimization causes an increase in register pressure, which
33988  may cause unwanted spilling of other temporary variables into the stack
33989 \begin_inset LatexCommand \index{stack}
33990
33991 \end_inset
33992
33993  / data space.
33994  The compiler will generate a warning message when it is forced to allocate
33995  extra space either on the stack or data space.
33996  If this extra space allocation is undesirable then induction optimization
33997  can be eliminated either for the entire source file (with -
33998 \begin_inset ERT
33999 status collapsed
34000
34001 \begin_layout Standard
34002
34003
34004 \backslash
34005 /
34006 \end_layout
34007
34008 \end_inset
34009
34010 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34011 noinduction
34012 \begin_inset LatexCommand \index{\#pragma noinduction}
34013
34014 \end_inset
34015
34016 .
34017 \newline
34018
34019 \newline
34020 Loop Invariant:
34021 \end_layout
34022
34023 \begin_layout Verse
34024
34025 \family typewriter
34026 for (i = 0 ; i < 100 ; i ++) 
34027 \newline
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 f += k + l;
34033 \end_layout
34034
34035 \begin_layout Standard
34036 changed to
34037 \end_layout
34038
34039 \begin_layout Verse
34040
34041 \family typewriter
34042 itemp = k + l; 
34043 \newline
34044 for (i = 0; i < 100; i++) 
34045 \newline
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 f += itemp;
34051 \end_layout
34052
34053 \begin_layout Standard
34054 As mentioned previously some loop invariants are not as apparent, all static
34055  address computations are also moved out of the loop.
34056 \newline
34057
34058 \newline
34059 Strength Reduction
34060 \begin_inset LatexCommand \index{Strength reduction}
34061
34062 \end_inset
34063
34064 , this optimization substitutes an expression by a cheaper expression:
34065 \end_layout
34066
34067 \begin_layout Verse
34068
34069 \family typewriter
34070 for (i=0;i < 100; i++)
34071 \newline
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 ar[i*5] = i*3;
34077 \end_layout
34078
34079 \begin_layout Standard
34080 changed to
34081 \end_layout
34082
34083 \begin_layout Verse
34084
34085 \family typewriter
34086 itemp1 = 0; 
34087 \newline
34088 itemp2 = 0; 
34089 \newline
34090 for (i=0;i< 100;i++) { 
34091 \newline
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 ar[itemp1] = itemp2; 
34097 \newline
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 itemp1
34103  += 5; 
34104 \newline
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 itemp2 += 3; 
34110 \newline
34111 }
34112 \end_layout
34113
34114 \begin_layout Standard
34115 The more expensive multiplication
34116 \begin_inset LatexCommand \index{Multiplication}
34117
34118 \end_inset
34119
34120  is changed to a less expensive addition.
34121 \end_layout
34122
34123 \begin_layout Subsection
34124 Loop Reversing
34125 \begin_inset LatexCommand \index{Loop reversing}
34126
34127 \end_inset
34128
34129
34130 \end_layout
34131
34132 \begin_layout Standard
34133 This optimization is done to reduce the overhead of checking loop boundaries
34134  for every iteration.
34135  Some simple loops can be reversed and implemented using a 
34136 \begin_inset Quotes eld
34137 \end_inset
34138
34139 decrement and jump if not zero
34140 \begin_inset Quotes erd
34141 \end_inset
34142
34143  instruction.
34144  SDCC checks for the following criterion to determine if a loop is reversible
34145  (note: more sophisticated compilers use data-dependency analysis to make
34146  this determination, SDCC uses a more simple minded analysis).
34147 \end_layout
34148
34149 \begin_layout Itemize
34150 The 'for' loop is of the form 
34151 \newline
34152
34153 \newline
34154
34155 \family typewriter
34156 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34157  += 1])
34158 \newline
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 <for body>
34164 \end_layout
34165
34166 \begin_layout Itemize
34167 The <for body> does not contain 
34168 \begin_inset Quotes eld
34169 \end_inset
34170
34171 continue
34172 \begin_inset Quotes erd
34173 \end_inset
34174
34175  or 'break
34176 \begin_inset Quotes erd
34177 \end_inset
34178
34179 .
34180 \end_layout
34181
34182 \begin_layout Itemize
34183 All goto's are contained within the loop.
34184 \end_layout
34185
34186 \begin_layout Itemize
34187 No function calls within the loop.
34188 \end_layout
34189
34190 \begin_layout Itemize
34191 The loop control variable <sym> is not assigned any value within the loop
34192 \end_layout
34193
34194 \begin_layout Itemize
34195 The loop control variable does NOT participate in any arithmetic operation
34196  within the loop.
34197 \end_layout
34198
34199 \begin_layout Itemize
34200 There are NO switch statements in the loop.
34201 \end_layout
34202
34203 \begin_layout Subsection
34204 Algebraic Simplifications
34205 \end_layout
34206
34207 \begin_layout Standard
34208 SDCC does numerous algebraic simplifications, the following is a small sub-set
34209  of these optimizations.
34210 \end_layout
34211
34212 \begin_layout Verse
34213
34214 \family typewriter
34215 i = j + 0;\InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219  /* changed to: */\InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223  i = j; 
34224 \newline
34225 i /= 2;\InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232  /* changed to: */\InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236  i >>= 1; 
34237 \newline
34238 i
34239  = j - j;\InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243  /* changed to: */\InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247  i = 0; 
34248 \newline
34249 i = j / 1;\InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253  /* changed to: */\InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257  i = j;
34258 \end_layout
34259
34260 \begin_layout Standard
34261 Note the subexpressions
34262 \begin_inset LatexCommand \index{Subexpression}
34263
34264 \end_inset
34265
34266  given above are generally introduced by macro expansions or as a result
34267  of copy/constant propagation.
34268 \end_layout
34269
34270 \begin_layout Subsection
34271 'switch' Statements
34272 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34273
34274 \end_inset
34275
34276
34277 \begin_inset LatexCommand \index{switch statement}
34278
34279 \end_inset
34280
34281
34282 \end_layout
34283
34284 \begin_layout Standard
34285 SDCC can optimize switch statements to jump tables
34286 \begin_inset LatexCommand \index{jump tables}
34287
34288 \end_inset
34289
34290 .
34291  It makes the decision based on an estimate of the generated code size.
34292  SDCC is quite liberal in the requirements for jump table generation: 
34293 \end_layout
34294
34295 \begin_layout Itemize
34296 The labels need not be in order, and the starting number need not be one
34297  or zero, the case labels are in numerical sequence or not too many case
34298  labels are missing.
34299 \end_layout
34300
34301 \begin_deeper
34302 \begin_layout Verse
34303
34304 \family typewriter
34305 switch(i) {\InsetSpace ~
34306 \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 switch (i) { 
34332 \newline
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 case 4: ...\InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 case 0: ...
34363  
34364 \newline
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 case 5: ...\InsetSpace ~
34369 \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 case 1: ...
34395  
34396 \newline
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 case 3: ...\InsetSpace ~
34401 \InsetSpace ~
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426
34427 \newline
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 case 6: ...\InsetSpace ~
34432 \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 case 3: ...
34458  
34459 \newline
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 case 7: ...\InsetSpace ~
34464 \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 case 4: ...
34490  
34491 \newline
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 case 8: ...\InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 case 5: ...
34522  
34523 \newline
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 case 9: ...\InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 case 6: ...
34554  
34555 \newline
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 case 10: ...\InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 case 7: ...
34585  
34586 \newline
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 case 11: ...\InsetSpace ~
34591 \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 case 8: ...
34616  
34617 \newline
34618 }\InsetSpace ~
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 }
34655 \end_layout
34656
34657 \begin_layout Standard
34658 Both the above switch statements will be implemented using a jump-table.
34659  The example to the right side is slightly more efficient as the check for
34660  the lower boundary of the jump-table is not needed.
34661 \end_layout
34662
34663 \end_deeper
34664 \begin_layout Itemize
34665 The number of case labels is not larger than supported by the target architectur
34666 e.
34667 \end_layout
34668
34669 \begin_layout Itemize
34670 If the case labels are not in numerical sequence ('gaps' between cases)
34671  SDCC checks whether a jump table with additionally inserted dummy cases
34672  is still attractive.
34673  
34674 \end_layout
34675
34676 \begin_layout Itemize
34677 If the starting number is not zero and a check for the lower boundary of
34678  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34679  ...
34680  .
34681 \end_layout
34682
34683 \begin_layout Standard
34684 Switch statements which have large gaps in the numeric sequence or those
34685  that have too many case labels can be split into more than one switch statement
34686  for efficient code generation, e.g.:
34687 \end_layout
34688
34689 \begin_layout Verse
34690
34691 \family typewriter
34692 switch (i) { 
34693 \newline
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 case 1: ...
34697  
34698 \newline
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 case 2: ...
34702  
34703 \newline
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 case 3: ...
34707  
34708 \newline
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 case 4: ...
34712  
34713 \newline
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 case 5: ...
34717  
34718 \newline
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 case 6: ...
34722  
34723 \newline
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 case 7: ...
34727  
34728 \newline
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 case 101: ...
34732  
34733 \newline
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 case 102: ...
34737  
34738 \newline
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 case 103: ...
34742  
34743 \newline
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 case 104: ...
34747  
34748 \newline
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 case 105: ...
34752  
34753 \newline
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 case 106: ...
34757  
34758 \newline
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 case 107: ...
34762  
34763 \newline
34764 }
34765 \end_layout
34766
34767 \begin_layout Standard
34768 If the above switch statement is broken down into two switch statements
34769 \end_layout
34770
34771 \begin_layout Verse
34772
34773 \family typewriter
34774 switch (i) { 
34775 \newline
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 case 1: ...
34779  
34780 \newline
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 case 2: ...
34784  
34785 \newline
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 case 3: ...
34789  
34790 \newline
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 case 4: ...
34794  
34795 \newline
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 case 5: ...
34799  
34800 \newline
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 case 6: ...
34804  
34805 \newline
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 case 7: ...
34809  
34810 \newline
34811 }
34812 \end_layout
34813
34814 \begin_layout Standard
34815 and
34816 \end_layout
34817
34818 \begin_layout Verse
34819
34820 \family typewriter
34821 switch (i) { 
34822 \newline
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 case 101: ...
34826  
34827 \newline
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 case 102: ...
34831  
34832 \newline
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 case 103: ...
34836  
34837 \newline
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 case 104: ...
34841  
34842 \newline
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 case 105: ...
34846  
34847 \newline
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 case 106: ...
34851  
34852 \newline
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 case 107: ...
34856  
34857 \newline
34858 }
34859 \end_layout
34860
34861 \begin_layout Standard
34862 then both the switch statements will be implemented using jump-tables whereas
34863  the unmodified switch statement will not be.
34864 \end_layout
34865
34866 \begin_layout Standard
34867 \begin_inset Note Note
34868 status collapsed
34869
34870 \begin_layout Standard
34871 There might be reasons which SDCC cannot know about to either favour or
34872  not favour jump tables.
34873  If the target system has to be as quick for the last switch case as for
34874  the first (pro jump table), or if the switch argument is known to be zero
34875  in the majority of the cases (contra jump table).
34876 \end_layout
34877
34878 \end_inset
34879
34880
34881 \end_layout
34882
34883 \begin_layout Standard
34884 The pragma nojtbound
34885 \begin_inset LatexCommand \index{\#pragma nojtbound}
34886
34887 \end_inset
34888
34889  can be used to turn off checking the 
34890 \emph on
34891 j
34892 \emph default
34893 ump 
34894 \emph on
34895 t
34896 \emph default
34897 able 
34898 \emph on
34899 bound
34900 \emph default
34901 aries.
34902  It has no effect if a default label is supplied.
34903  Use of this pragma is dangerous: if the switch
34904 \begin_inset LatexCommand \index{switch statement}
34905
34906 \end_inset
34907
34908  argument is not matched by a case statement the processor will happily
34909  jump into Nirvana.
34910 \end_layout
34911
34912 \begin_layout Subsection
34913 Bit-shifting Operations
34914 \begin_inset LatexCommand \index{Bit shifting}
34915
34916 \end_inset
34917
34918 .
34919 \end_layout
34920
34921 \begin_layout Standard
34922 Bit shifting is one of the most frequently used operation in embedded programmin
34923 g.
34924  SDCC tries to implement bit-shift operations in the most efficient way
34925  possible, e.g.:
34926 \end_layout
34927
34928 \begin_layout Verse
34929
34930 \family typewriter
34931 unsigned char i;
34932 \newline
34933 ...
34934  
34935 \newline
34936 i >>= 4; 
34937 \newline
34938 ...
34939 \end_layout
34940
34941 \begin_layout Standard
34942 generates the following code:
34943 \end_layout
34944
34945 \begin_layout Verse
34946
34947 \family typewriter
34948 mov\InsetSpace ~
34949  a,_i 
34950 \newline
34951 swap a 
34952 \newline
34953 anl\InsetSpace ~
34954  a,#0x0f 
34955 \newline
34956 mov\InsetSpace ~
34957  _i,a
34958 \end_layout
34959
34960 \begin_layout Standard
34961 In general SDCC will never setup a loop if the shift count is known.
34962  Another example:
34963 \end_layout
34964
34965 \begin_layout Verse
34966
34967 \family typewriter
34968 unsigned int i; 
34969 \newline
34970 ...
34971  
34972 \newline
34973 i >>= 9; 
34974 \newline
34975 ...
34976 \end_layout
34977
34978 \begin_layout Standard
34979 will generate:
34980 \end_layout
34981
34982 \begin_layout Verse
34983
34984 \family typewriter
34985 mov\InsetSpace ~
34986 \InsetSpace ~
34987 a,(_i + 1) 
34988 \newline
34989 mov\InsetSpace ~
34990 \InsetSpace ~
34991 (_i + 1),#0x00 
34992 \newline
34993 clr\InsetSpace ~
34994 \InsetSpace ~
34995
34996 \newline
34997 rrc\InsetSpace ~
34998 \InsetSpace ~
34999
35000 \newline
35001 mov\InsetSpace ~
35002 \InsetSpace ~
35003 _i,a
35004 \end_layout
35005
35006 \begin_layout Subsection
35007 Bit-rotation
35008 \begin_inset LatexCommand \index{Bit rotation}
35009
35010 \end_inset
35011
35012
35013 \end_layout
35014
35015 \begin_layout Standard
35016 A special case of the bit-shift operation is bit rotation
35017 \begin_inset LatexCommand \index{rotating bits}
35018
35019 \end_inset
35020
35021 , SDCC recognizes the following expression to be a left bit-rotation:
35022 \end_layout
35023
35024 \begin_layout Verse
35025
35026 \family typewriter
35027 \series bold
35028 unsigned
35029 \series default
35030 \InsetSpace ~
35031 \InsetSpace ~
35032 char i;\InsetSpace ~
35033 \InsetSpace ~
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 /* unsigned is needed for rotation */ 
35044 \newline
35045 ...
35046  
35047 \newline
35048 i = ((i << 1) | (i >> 7)); 
35049 \family default
35050
35051 \newline
35052
35053 \family typewriter
35054 ...
35055 \end_layout
35056
35057 \begin_layout Standard
35058 will generate the following code:
35059 \end_layout
35060
35061 \begin_layout Verse
35062
35063 \family typewriter
35064 mov\InsetSpace ~
35065 \InsetSpace ~
35066 a,_i 
35067 \newline
35068 rl\InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071
35072 \newline
35073 mov\InsetSpace ~
35074 \InsetSpace ~
35075 _i,a
35076 \end_layout
35077
35078 \begin_layout Standard
35079 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35080 ns of this case will also be recognized as bit-rotation, i.e.: 
35081 \end_layout
35082
35083 \begin_layout Verse
35084
35085 \family typewriter
35086 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35087 \end_layout
35088
35089 \begin_layout Subsection
35090 Nibble and Byte Swapping
35091 \end_layout
35092
35093 \begin_layout Standard
35094 Other special cases of the bit-shift operations are nibble or byte swapping
35095 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35096
35097 \end_inset
35098
35099 , SDCC recognizes the following expressions:
35100 \end_layout
35101
35102 \begin_layout Verse
35103
35104 \family typewriter
35105 \series bold
35106 unsigned
35107 \series default
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 char i; 
35111 \newline
35112
35113 \series bold
35114 unsigned
35115 \series default
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 int j; 
35119 \newline
35120 ...
35121  
35122 \newline
35123 i = ((i << 4) | (i >> 4)); 
35124 \family default
35125
35126 \newline
35127
35128 \family typewriter
35129 j = ((j << 8) | (j >> 8)); 
35130 \end_layout
35131
35132 \begin_layout Standard
35133 and generates a swap instruction for the nibble swapping
35134 \begin_inset LatexCommand \index{Nibble swapping}
35135
35136 \end_inset
35137
35138  or move instructions for the byte swapping
35139 \begin_inset LatexCommand \index{Byte swapping}
35140
35141 \end_inset
35142
35143 .
35144  The 
35145 \begin_inset Quotes sld
35146 \end_inset
35147
35148 j
35149 \begin_inset Quotes srd
35150 \end_inset
35151
35152  example can be used to convert from little to big-endian or vice versa.
35153  If you want to change the endianness of a 
35154 \emph on
35155 signed
35156 \emph default
35157  integer you have to cast to 
35158 \family typewriter
35159 (unsigned int)
35160 \family default
35161  first.
35162 \end_layout
35163
35164 \begin_layout Standard
35165 Note that SDCC stores numbers in little-endian
35166 \begin_inset Foot
35167 status open
35168
35169 \begin_layout Standard
35170 Usually 8-bit processors don't care much about endianness.
35171  This is not the case for the standard 8051 which only has an instruction
35172  to increment its 
35173 \emph on
35174 dptr
35175 \emph default
35176
35177 \begin_inset LatexCommand \index{DPTR}
35178
35179 \end_inset
35180
35181 -datapointer
35182 \emph on
35183  
35184 \emph default
35185 so little-endian is the more efficient byte order.
35186 \end_layout
35187
35188 \end_inset
35189
35190
35191 \begin_inset LatexCommand \index{little-endian}
35192
35193 \end_inset
35194
35195
35196 \begin_inset LatexCommand \index{Endianness}
35197
35198 \end_inset
35199
35200  format (i.e.
35201  lowest order first).
35202 \end_layout
35203
35204 \begin_layout Subsection
35205 Highest Order Bit
35206 \begin_inset LatexCommand \index{Highest Order Bit}
35207
35208 \end_inset
35209
35210  / Any Order Bit
35211 \begin_inset LatexCommand \index{Any Order Bit}
35212
35213 \end_inset
35214
35215
35216 \end_layout
35217
35218 \begin_layout Standard
35219 It is frequently required to obtain the highest order bit of an integral
35220  type (long, int, short or char types).
35221  Also obtaining any other order bit is not uncommon.
35222  SDCC recognizes the following expressions to yield the highest order bit
35223  and generates optimized code for it, e.g.:
35224 \end_layout
35225
35226 \begin_layout Verse
35227
35228 \family typewriter
35229 unsigned int gint; 
35230 \newline
35231
35232 \newline
35233 foo () { 
35234 \newline
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 unsigned char hob1, aob1; 
35238 \newline
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 bit hob2, hob3, aob2,
35242  aob3; 
35243 \newline
35244 \InsetSpace ~
35245 \InsetSpace ~
35246 ...
35247  
35248 \newline
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 hob1 = (gint >> 15) & 1; 
35252 \newline
35253 \InsetSpace ~
35254 \InsetSpace ~
35255 hob2 = (gint >> 15) & 1; 
35256 \newline
35257 \InsetSpace ~
35258 \InsetSpace ~
35259 hob3 = gint & 0x8000;
35260  
35261 \newline
35262 \InsetSpace ~
35263 \InsetSpace ~
35264 aob1 = (gint >> 9) & 1; 
35265 \newline
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 aob2 = (gint >> 8) & 1; 
35269 \newline
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 aob3 = gint & 0x0800; 
35273 \newline
35274 \InsetSpace ~
35275 \InsetSpace ~
35276 ..
35277  
35278 \newline
35279 }
35280 \end_layout
35281
35282 \begin_layout Standard
35283 will generate the following code:
35284 \end_layout
35285
35286 \begin_layout Verse
35287
35288 \family typewriter
35289 \InsetSpace ~
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314  61 ;\InsetSpace ~
35315  hob.c 7 
35316 \newline
35317 000A E5*01\InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331 \InsetSpace ~
35332  62\InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 \InsetSpace ~
35340  mov\InsetSpace ~
35341 \InsetSpace ~
35342  a,(_gint + 1) 
35343 \newline
35344 000C 23\InsetSpace ~
35345 \InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362  63\InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370  rl\InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373  a 
35374 \newline
35375 000D 54 01\InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390
35391  64\InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399  anl\InsetSpace ~
35400 \InsetSpace ~
35401  a,#0x01 
35402 \newline
35403 000F F5*02\InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418  65\InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426  mov\InsetSpace ~
35427 \InsetSpace ~
35428  _foo_hob1_1_1,a 
35429 \newline
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455  66 ;\InsetSpace ~
35456  hob.c 8 
35457 \newline
35458 0011 E5*01\InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473
35474  67\InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482  mov\InsetSpace ~
35483 \InsetSpace ~
35484  a,(_gint + 1) 
35485 \newline
35486 0013 33\InsetSpace ~
35487 \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  68\InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512  rlc\InsetSpace ~
35513 \InsetSpace ~
35514  a 
35515 \newline
35516 0014 92*00\InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531  69\InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539  mov\InsetSpace ~
35540 \InsetSpace ~
35541  _foo_hob2_1_1,c
35542  
35543 \newline
35544 \InsetSpace ~
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569  66 ;\InsetSpace ~
35570  hob.c 9 
35571 \newline
35572 0016 E5*01\InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587  67\InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595  mov\InsetSpace ~
35596 \InsetSpace ~
35597  a,(_gint + 1) 
35598 \newline
35599 0018 33\InsetSpace ~
35600 \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  68\InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625  rlc\InsetSpace ~
35626 \InsetSpace ~
35627  a 
35628 \newline
35629 0019 92*01\InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644
35645  69\InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653  mov\InsetSpace ~
35654 \InsetSpace ~
35655  _foo_hob3_1_1,c 
35656 \newline
35657 \InsetSpace ~
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661 \InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682  70 ;\InsetSpace ~
35683  hob.c 10 
35684 \newline
35685 001B E5*01\InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700  71\InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708  mov\InsetSpace ~
35709 \InsetSpace ~
35710  a,(_gint + 1) 
35711 \newline
35712 001D
35713  03\InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731  72\InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739  rr\InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742  a 
35743 \newline
35744 001E 54 01\InsetSpace ~
35745 \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  73\InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765 \InsetSpace ~
35766 \InsetSpace ~
35767  anl\InsetSpace ~
35768 \InsetSpace ~
35769  a,#0x01 
35770 \newline
35771 0020 F5*03\InsetSpace ~
35772 \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  74\InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794  mov\InsetSpace ~
35795 \InsetSpace ~
35796  _foo_aob1_1_1,a
35797  
35798 \newline
35799 \InsetSpace ~
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  75 ;\InsetSpace ~
35825  hob.c 11 
35826 \newline
35827 0022 E5*01\InsetSpace ~
35828 \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  76\InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850  mov\InsetSpace ~
35851 \InsetSpace ~
35852  a,(_gint + 1) 
35853 \newline
35854 0024 13\InsetSpace ~
35855 \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  77\InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880  rrc\InsetSpace ~
35881 \InsetSpace ~
35882  a 
35883 \newline
35884 0025 92*02\InsetSpace ~
35885 \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
35900  78\InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908  mov\InsetSpace ~
35909 \InsetSpace ~
35910  _foo_aob2_1_1,c 
35911 \newline
35912 \InsetSpace ~
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  79 ;\InsetSpace ~
35938  hob.c 12 
35939 \newline
35940 0027 E5*01\InsetSpace ~
35941 \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  80\InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963  mov\InsetSpace ~
35964 \InsetSpace ~
35965  a,(_gint + 1) 
35966 \newline
35967 0029
35968  A2 E3\InsetSpace ~
35969 \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  81\InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991  mov\InsetSpace ~
35992 \InsetSpace ~
35993  c,acc[3] 
35994 \newline
35995 002B 92*03\InsetSpace ~
35996 \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  82\InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018  mov\InsetSpace ~
36019 \InsetSpace ~
36020  _foo_aob3_1_1,c 
36021 \end_layout
36022
36023 \begin_layout Standard
36024 Other variations of these cases however will 
36025 \emph on
36026 not
36027 \emph default
36028  be recognized.
36029  They are standard C expressions, so I heartily recommend these be the only
36030  way to get the highest order bit, (it is portable).
36031  Of course it will be recognized even if it is embedded in other expressions,
36032  e.g.:
36033 \end_layout
36034
36035 \begin_layout Verse
36036
36037 \family typewriter
36038 xyz = gint + ((gint >> 15) & 1);
36039 \end_layout
36040
36041 \begin_layout Standard
36042 will still be recognized.
36043 \end_layout
36044
36045 \begin_layout Subsection
36046 Higher Order Byte
36047 \begin_inset LatexCommand \index{Higher Order Byte}
36048
36049 \end_inset
36050
36051  / Higher Order Word
36052 \begin_inset LatexCommand \index{Higher Order Word}
36053
36054 \end_inset
36055
36056
36057 \end_layout
36058
36059 \begin_layout Standard
36060 It is also frequently required to obtain a higher order byte or word of
36061  a larger integral type (long, int or short types).
36062  SDCC recognizes the following expressions to yield the higher order byte
36063  or word and generates optimized code for it, e.g.:
36064 \end_layout
36065
36066 \begin_layout Verse
36067
36068 \family typewriter
36069 unsigned int gint; 
36070 \newline
36071 unsigned long int glong; 
36072 \newline
36073
36074 \newline
36075 foo () { 
36076 \newline
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 unsigned char hob1,
36080  hob2; 
36081 \newline
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 unsigned int how1, how2; 
36085 \newline
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 ...
36089  
36090 \newline
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 hob1 = (gint >> 8) & 0xFF; 
36094 \newline
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 hob2 = glong >> 24; 
36098 \newline
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 how1 = (glong >> 16) & 0xFFFF;
36102  
36103 \newline
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 how2 = glong >> 8; 
36107 \newline
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 ..
36111  
36112 \newline
36113 }
36114 \end_layout
36115
36116 \begin_layout Standard
36117 will generate the following code:
36118 \end_layout
36119
36120 \begin_layout Verse
36121
36122 \family typewriter
36123 \InsetSpace ~
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  91 ;\InsetSpace ~
36149  hob.c 15 
36150 \newline
36151 0037 85*01*06\InsetSpace ~
36152 \InsetSpace ~
36153 \InsetSpace ~
36154 \InsetSpace ~
36155 \InsetSpace ~
36156 \InsetSpace ~
36157 \InsetSpace ~
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 \InsetSpace ~
36163  92\InsetSpace ~
36164 \InsetSpace ~
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171  mov\InsetSpace ~
36172 \InsetSpace ~
36173  _foo_hob1_1_1,(_gint + 1) 
36174 \newline
36175 \InsetSpace ~
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  93 ;\InsetSpace ~
36201  hob.c
36202  16 
36203 \newline
36204 003A 85*05*07\InsetSpace ~
36205 \InsetSpace ~
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 \InsetSpace ~
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 \InsetSpace ~
36215 \InsetSpace ~
36216  94\InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224  mov\InsetSpace ~
36225 \InsetSpace ~
36226  _foo_hob2_1_1,(_glong + 3) 
36227 \newline
36228 \InsetSpace ~
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  95 ;\InsetSpace ~
36254  hob.c 17 
36255 \newline
36256 003D 85*04*08\InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268
36269  96\InsetSpace ~
36270 \InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277  mov\InsetSpace ~
36278 \InsetSpace ~
36279  _foo_how1_1_1,(_glong + 2) 
36280 \newline
36281 0040 85*05*09\InsetSpace ~
36282 \InsetSpace ~
36283 \InsetSpace ~
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293  97\InsetSpace ~
36294 \InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 \InsetSpace ~
36299 \InsetSpace ~
36300 \InsetSpace ~
36301  mov\InsetSpace ~
36302 \InsetSpace ~
36303  (_foo_how1_1_1 +
36304  1),(_glong + 3) 
36305 \newline
36306 0043 85*03*0A\InsetSpace ~
36307 \InsetSpace ~
36308 \InsetSpace ~
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 \InsetSpace ~
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 \InsetSpace ~
36318  98\InsetSpace ~
36319 \InsetSpace ~
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 \InsetSpace ~
36324 \InsetSpace ~
36325 \InsetSpace ~
36326  mov\InsetSpace ~
36327 \InsetSpace ~
36328  _foo_how2_1_1,(_glong + 1) 
36329 \newline
36330 0046 85*04*0B\InsetSpace ~
36331 \InsetSpace ~
36332 \InsetSpace ~
36333 \InsetSpace ~
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 \InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 \InsetSpace ~
36342
36343  99\InsetSpace ~
36344 \InsetSpace ~
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348 \InsetSpace ~
36349 \InsetSpace ~
36350 \InsetSpace ~
36351  mov\InsetSpace ~
36352 \InsetSpace ~
36353  (_foo_how2_1_1 + 1),(_glong + 2) 
36354 \end_layout
36355
36356 \begin_layout Standard
36357 Again, variations of these cases may 
36358 \emph on
36359 not
36360 \emph default
36361  be recognized.
36362  They are standard C expressions, so I heartily recommend these be the only
36363  way to get the higher order byte/word, (it is portable).
36364  Of course it will be recognized even if it is embedded in other expressions,
36365  e.g.:
36366 \end_layout
36367
36368 \begin_layout Verse
36369
36370 \family typewriter
36371 xyz = gint + ((gint >> 8) & 0xFF);
36372 \end_layout
36373
36374 \begin_layout Standard
36375 will still be recognized.
36376 \end_layout
36377
36378 \begin_layout Subsection
36379 Peephole Optimizer
36380 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36381
36382 \end_inset
36383
36384
36385 \begin_inset LatexCommand \index{Peephole optimizer}
36386
36387 \end_inset
36388
36389
36390 \end_layout
36391
36392 \begin_layout Standard
36393 The compiler uses a rule based, pattern matching and re-writing mechanism
36394  for peep-hole optimization.
36395  It is inspired by 
36396 \emph on
36397 copt
36398 \emph default
36399  a peep-hole optimizer by Christopher W.
36400  Fraser (cwfraser\InsetSpace ~
36401 @\InsetSpace ~
36402 microsoft.com).
36403  A default set of rules are compiled into the compiler, additional rules
36404  may be added with the 
36405 \emph on
36406 -
36407 \begin_inset ERT
36408 status collapsed
36409
36410 \begin_layout Standard
36411
36412
36413 \backslash
36414 /
36415 \end_layout
36416
36417 \end_inset
36418
36419 -peep-file
36420 \begin_inset LatexCommand \index{-\/-peep-file}
36421
36422 \end_inset
36423
36424  <filename>
36425 \emph default
36426  option.
36427  The rule language is best illustrated with examples.
36428 \end_layout
36429
36430 \begin_layout Verse
36431
36432 \family typewriter
36433 replace { 
36434 \newline
36435 \InsetSpace ~
36436 \InsetSpace ~
36437 mov %1,a 
36438 \newline
36439 \InsetSpace ~
36440 \InsetSpace ~
36441 mov a,%1
36442 \newline
36443 } by {
36444 \newline
36445 \InsetSpace ~
36446 \InsetSpace ~
36447 mov %1,a
36448 \newline
36449 }
36450 \end_layout
36451
36452 \begin_layout Standard
36453 The above rule will change the following assembly
36454 \begin_inset LatexCommand \index{Assembler routines}
36455
36456 \end_inset
36457
36458  sequence:
36459 \end_layout
36460
36461 \begin_layout Verse
36462
36463 \family typewriter
36464 mov r1,a 
36465 \newline
36466 mov a,r1
36467 \end_layout
36468
36469 \begin_layout Standard
36470 to
36471 \end_layout
36472
36473 \begin_layout Verse
36474
36475 \family typewriter
36476 mov r1,a
36477 \end_layout
36478
36479 \begin_layout Standard
36480 Note: All occurrences of a 
36481 \emph on
36482 %n
36483 \emph default
36484  (pattern variable) must denote the same string.
36485  With the above rule, the assembly sequence:
36486 \end_layout
36487
36488 \begin_layout Verse
36489
36490 \family typewriter
36491 mov r1,a 
36492 \newline
36493 mov a,r2
36494 \end_layout
36495
36496 \begin_layout Standard
36497 will remain unmodified.
36498 \newline
36499
36500 \newline
36501 Other special case optimizations may be added by the
36502  user (via 
36503 \emph on
36504 -
36505 \begin_inset ERT
36506 status collapsed
36507
36508 \begin_layout Standard
36509
36510
36511 \backslash
36512 /
36513 \end_layout
36514
36515 \end_inset
36516
36517 -peep-file option
36518 \emph default
36519 ).
36520  E.g.
36521  some variants of the 8051 MCU
36522 \begin_inset LatexCommand \index{MCS51 variants}
36523
36524 \end_inset
36525
36526  allow only 
36527 \family typewriter
36528 ajmp
36529 \family default
36530  and 
36531 \family typewriter
36532 acall
36533 \family default
36534 .
36535  The following two rules will change all 
36536 \family typewriter
36537 ljmp
36538 \family default
36539  and 
36540 \family typewriter
36541 lcall
36542 \family default
36543  to 
36544 \family typewriter
36545 ajmp
36546 \family default
36547  and 
36548 \family typewriter
36549 acall
36550 \end_layout
36551
36552 \begin_layout Verse
36553
36554 \family typewriter
36555 replace { lcall %1 } by { acall %1 } 
36556 \newline
36557 replace { ljmp %1 } by { ajmp %1 }
36558 \end_layout
36559
36560 \begin_layout Standard
36561 (NOTE: from version 2.7.3 on, you can use option -
36562 \emph on
36563
36564 \begin_inset ERT
36565 status collapsed
36566
36567 \begin_layout Standard
36568
36569
36570 \backslash
36571 /
36572 \end_layout
36573
36574 \end_inset
36575
36576
36577 \emph default
36578 -acall-ajmp
36579 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36580
36581 \end_inset
36582
36583 , which also takes care of aligning the interrupt vectors properly.)
36584 \newline
36585
36586 \end_layout
36587
36588 \begin_layout Standard
36589 The 
36590 \emph on
36591 inline-assembler code
36592 \emph default
36593  is also passed through the peep hole optimizer, thus the peephole optimizer
36594  can also be used as an assembly level macro expander.
36595  The rules themselves are MCU dependent whereas the rule language infra-structur
36596 e is MCU independent.
36597  Peephole optimization rules for other MCU can be easily programmed using
36598  the rule language.
36599 \newline
36600
36601 \newline
36602 The syntax for a rule is as follows:
36603 \end_layout
36604
36605 \begin_layout Verse
36606
36607 \family typewriter
36608 rule := replace [ restart ] '{' <assembly sequence> '
36609 \backslash
36610 n' 
36611 \newline
36612 \InsetSpace ~
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  '}' by '{' '
36627 \backslash
36628 n' 
36629 \newline
36630 \InsetSpace ~
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  <assembly sequence> '
36647 \backslash
36648 n' 
36649 \newline
36650 \InsetSpace ~
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  '}' [if <functionName> ] '
36665 \backslash
36666 n' 
36667 \end_layout
36668
36669 \begin_layout Standard
36670 <assembly sequence> := assembly instruction (each instruction including
36671  labels must be on a separate line).
36672 \newline
36673
36674 \newline
36675 The optimizer will apply to the rules
36676  one by one from the top in the sequence of their appearance, it will terminate
36677  when all rules are exhausted.
36678  If the 'restart' option is specified, then the optimizer will start matching
36679  the rules again from the top, this option for a rule is expensive (performance)
36680 , it is intended to be used in situations where a transformation will trigger
36681  the same rule again.
36682  An example of this (not a good one, it has side effects) is the following
36683  rule:
36684 \end_layout
36685
36686 \begin_layout Verse
36687
36688 \family typewriter
36689 replace restart { 
36690 \newline
36691 \InsetSpace ~
36692 \InsetSpace ~
36693 pop %1 
36694 \newline
36695 \InsetSpace ~
36696 \InsetSpace ~
36697 push %1 } by { 
36698 \newline
36699 \InsetSpace ~
36700 \InsetSpace ~
36701 ; nop 
36702 \newline
36703 }
36704 \end_layout
36705
36706 \begin_layout Standard
36707 Note that the replace pattern cannot be a blank, but can be a comment line.
36708  Without the 'restart' option only the innermost 'pop' 'push' pair would
36709  be eliminated, i.e.:
36710 \end_layout
36711
36712 \begin_layout Verse
36713
36714 \family typewriter
36715 pop ar1 
36716 \newline
36717 pop ar2 
36718 \newline
36719 push ar2 
36720 \newline
36721 push ar1
36722 \end_layout
36723
36724 \begin_layout Standard
36725 would result in:
36726 \end_layout
36727
36728 \begin_layout Verse
36729
36730 \family typewriter
36731 pop ar1 
36732 \newline
36733 ; nop 
36734 \newline
36735 push ar1
36736 \end_layout
36737
36738 \begin_layout Standard
36739
36740 \emph on
36741 with
36742 \emph default
36743  the restart option the rule will be applied again to the resulting code
36744  and then all the pop-push pairs will be eliminated to yield:
36745 \end_layout
36746
36747 \begin_layout Verse
36748
36749 \family typewriter
36750 ; nop 
36751 \newline
36752 ; nop
36753 \end_layout
36754
36755 \begin_layout Standard
36756 A conditional function can be attached to a rule.
36757  Attaching rules are somewhat more involved, let me illustrate this with
36758  an example.
36759 \end_layout
36760
36761 \begin_layout Verse
36762
36763 \family typewriter
36764 replace { 
36765 \newline
36766 \InsetSpace ~
36767  \InsetSpace ~
36768  \InsetSpace ~
36769 ljmp %5 
36770 \newline
36771 %2:
36772 \newline
36773 } by { 
36774 \newline
36775 \InsetSpace ~
36776  \InsetSpace ~
36777  \InsetSpace ~
36778 sjmp %5 
36779 \newline
36780 %2:
36781 \newline
36782 } if labelInRange
36783 \end_layout
36784
36785 \begin_layout Standard
36786 The optimizer does a look-up of a function name table defined in function
36787  
36788 \emph on
36789 callFuncByName
36790 \emph default
36791  in the source file SDCCpeeph.c, with the name 
36792 \emph on
36793 labelInRange
36794 \emph default
36795 .
36796  If it finds a corresponding entry the function is called.
36797  Note there can be no parameters specified for these functions, in this
36798  case the use of 
36799 \emph on
36800 %5
36801 \emph default
36802  is crucial, since the function 
36803 \emph on
36804 labelInRange
36805 \emph default
36806  expects to find the label in that particular variable (the hash table containin
36807 g the variable bindings is passed as a parameter).
36808  If you want to code more such functions, take a close look at the function
36809  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36810  Currently implemented are 
36811 \emph on
36812 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36813  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36814 \emph default
36815 and
36816 \emph on
36817  notVolatile
36818 \emph default
36819 .
36820 \end_layout
36821
36822 \begin_layout Standard
36823 I know this whole thing is a little kludgey, but maybe some day we will
36824  have some better means.
36825  If you are looking at this file, you will see the default rules that are
36826  compiled into the compiler, you can add your own rules in the default set
36827  there if you get tired of specifying the -
36828 \begin_inset ERT
36829 status collapsed
36830
36831 \begin_layout Standard
36832
36833
36834 \backslash
36835 /
36836 \end_layout
36837
36838 \end_inset
36839
36840 -peep-file option.
36841 \end_layout
36842
36843 \begin_layout Section
36844 ANSI-Compliance
36845 \begin_inset LatexCommand \index{ANSI-compliance}
36846
36847 \end_inset
36848
36849
36850 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36851
36852 \end_inset
36853
36854
36855 \end_layout
36856
36857 \begin_layout Standard
36858 The latest publically available version of the standard 
36859 \emph on
36860 ISO/IEC 9899 - Programming languages - C
36861 \emph default
36862  should be available at: 
36863 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36864
36865 \end_inset
36866
36867 .
36868 \newline
36869
36870 \end_layout
36871
36872 \begin_layout Standard
36873 Deviations from the compliance:
36874 \end_layout
36875
36876 \begin_layout Itemize
36877 functions are not reentrant
36878 \begin_inset LatexCommand \index{reentrant}
36879
36880 \end_inset
36881
36882  unless explicitly declared as such or the 
36883 \series bold
36884 -
36885 \begin_inset ERT
36886 status collapsed
36887
36888 \begin_layout Standard
36889
36890
36891 \backslash
36892 /
36893 \end_layout
36894
36895 \end_inset
36896
36897 -stack-auto
36898 \begin_inset LatexCommand \index{-\/-stack-auto}
36899
36900 \end_inset
36901
36902
36903 \series default
36904  command line option is specified.
36905 \end_layout
36906
36907 \begin_layout Itemize
36908 structures
36909 \begin_inset LatexCommand \index{struct}
36910
36911 \end_inset
36912
36913  and unions
36914 \begin_inset LatexCommand \index{union}
36915
36916 \end_inset
36917
36918  cannot be assigned values directly, cannot be passed as function parameters
36919  or assigned to each other and cannot be a return value
36920 \begin_inset LatexCommand \index{return value}
36921
36922 \end_inset
36923
36924  from a function, e.g.:
36925 \end_layout
36926
36927 \begin_deeper
36928 \begin_layout Verse
36929
36930 \family typewriter
36931 struct s { ...
36932  }; 
36933 \newline
36934 struct s s1, s2; 
36935 \newline
36936 foo() 
36937 \newline
36938
36939 \newline
36940 \InsetSpace ~
36941 \InsetSpace ~
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 ...
36945  
36946 \newline
36947 \InsetSpace ~
36948 \InsetSpace ~
36949 \InsetSpace ~
36950 \InsetSpace ~
36951 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36952 \newline
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 ...
36958  
36959 \newline
36960 }
36961 \newline
36962
36963 \series bold
36964 struct
36965 \series default
36966  s foo1 (
36967 \series bold
36968 struct
36969 \series default
36970  s parms) /* invalid in SDCC although allowed in ANSI */
36971 \newline
36972
36973 \newline
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 struct s rets;
36979  
36980 \newline
36981 \InsetSpace ~
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 ...
36986  
36987 \newline
36988 \InsetSpace ~
36989 \InsetSpace ~
36990 \InsetSpace ~
36991 \InsetSpace ~
36992 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36993 \newline
36994 }
36995 \end_layout
36996
36997 \end_deeper
36998 \begin_layout Itemize
36999 initialization of structure arrays must be fully braced.
37000 \end_layout
37001
37002 \begin_deeper
37003 \begin_layout Verse
37004
37005 \family typewriter
37006 struct s { char x } a[] = {1, 2};\InsetSpace ~
37007 \InsetSpace ~
37008 \InsetSpace ~
37009 \InsetSpace ~
37010 \InsetSpace ~
37011 /* invalid in SDCC */
37012 \newline
37013 struct s { char x
37014  } a[] = {{1}, {2}}; /* OK */
37015 \end_layout
37016
37017 \end_deeper
37018 \begin_layout Itemize
37019 'long long
37020 \begin_inset LatexCommand \index{long long (not supported)}
37021
37022 \end_inset
37023
37024 ' (64 bit integers
37025 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37026
37027 \end_inset
37028
37029 ) not supported.
37030 \end_layout
37031
37032 \begin_layout Itemize
37033 'double
37034 \begin_inset LatexCommand \index{double (not supported)}
37035
37036 \end_inset
37037
37038 ' precision floating point 
37039 \begin_inset LatexCommand \index{Floating point support}
37040
37041 \end_inset
37042
37043 not supported.
37044 \end_layout
37045
37046 \begin_layout Itemize
37047 Old K&R style
37048 \begin_inset LatexCommand \index{K\&R style}
37049
37050 \end_inset
37051
37052  function declarations are NOT allowed.
37053 \end_layout
37054
37055 \begin_deeper
37056 \begin_layout Verse
37057
37058 \family typewriter
37059 foo(i,j) /* this old style of function declarations */ 
37060 \newline
37061 int i,j; /* is valid
37062  in ANSI but not valid in SDCC */ 
37063 \newline
37064
37065 \newline
37066 \InsetSpace ~
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 \InsetSpace ~
37070 ...
37071  
37072 \newline
37073 }
37074 \end_layout
37075
37076 \end_deeper
37077 \begin_layout Itemize
37078 Most enhancements in C99 are not supported, e.g.:
37079 \end_layout
37080
37081 \begin_deeper
37082 \begin_layout Verse
37083
37084 \family typewriter
37085 for (
37086 \series bold
37087 int
37088 \series default
37089  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37090 \end_layout
37091
37092 \end_deeper
37093 \begin_layout Itemize
37094 But some have been added recently in SDCC 2.7.0.
37095  They must be considered alpha quality however.
37096 \end_layout
37097
37098 \begin_deeper
37099 \begin_layout Verse
37100
37101 \family typewriter
37102 \series bold
37103 inline
37104 \begin_inset LatexCommand \index{inline (not supported)}
37105
37106 \end_inset
37107
37108
37109 \series default
37110  int increment (int a) { return a+1; } /* inlines the increment without
37111  function call overhead */
37112 \newline
37113 int * 
37114 \series bold
37115 restrict
37116 \begin_inset LatexCommand \index{inline (not supported)}
37117
37118 \end_inset
37119
37120
37121 \series default
37122  p; /* accepted but ignored */
37123 \end_layout
37124
37125 \end_deeper
37126 \begin_layout Itemize
37127 Certain words that are valid identifiers in the standard may be reserved
37128  words in SDCC unless the 
37129 \series bold
37130 -
37131 \begin_inset ERT
37132 status collapsed
37133
37134 \begin_layout Standard
37135
37136
37137 \backslash
37138 /
37139 \end_layout
37140
37141 \end_inset
37142
37143 -std-c89
37144 \begin_inset LatexCommand \index{-\/-std-c89}
37145
37146 \end_inset
37147
37148  
37149 \series default
37150 or
37151 \series bold
37152  -
37153 \begin_inset ERT
37154 status collapsed
37155
37156 \begin_layout Standard
37157
37158
37159 \backslash
37160 /
37161 \end_layout
37162
37163 \end_inset
37164
37165 -std-c99
37166 \begin_inset LatexCommand \index{-\/-std-c99}
37167
37168 \end_inset
37169
37170
37171 \series default
37172  command line options are used.
37173  These may include (depending on the selected processor): 'at', 'banked',
37174  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37175 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37176  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37177  '_naked'.
37178  Compliant equivalents of these keywords are always available in a form
37179  that begin with two underscores
37180 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37181
37182 \end_inset
37183
37184 , f.e.
37185  '__data' instead of 'data'.
37186 \end_layout
37187
37188 \begin_layout Itemize
37189 Integer promotion of variable arguments is not performed if the argument
37190  is explicitly taypecasted unless the
37191 \series bold
37192  -
37193 \begin_inset ERT
37194 status collapsed
37195
37196 \begin_layout Standard
37197
37198
37199 \backslash
37200 /
37201 \end_layout
37202
37203 \end_inset
37204
37205 -std-c89
37206 \begin_inset LatexCommand \index{-\/-std-c89}
37207
37208 \end_inset
37209
37210  
37211 \series default
37212 or
37213 \series bold
37214  -
37215 \begin_inset ERT
37216 status collapsed
37217
37218 \begin_layout Standard
37219
37220
37221 \backslash
37222 /
37223 \end_layout
37224
37225 \end_inset
37226
37227 -std-c99
37228 \begin_inset LatexCommand \index{-\/-std-c99}
37229
37230 \end_inset
37231
37232
37233 \series default
37234  command line options are used.
37235 \end_layout
37236
37237 \begin_deeper
37238 \begin_layout Verse
37239
37240 \family typewriter
37241 void vararg_func (char *str, ...) { str; }
37242 \newline
37243
37244 \newline
37245 void main (void)
37246 \newline
37247 {
37248 \newline
37249 \InsetSpace ~
37250 \InsetSpace ~
37251 char c = 10;
37252 \newline
37253
37254 \newline
37255 \InsetSpace ~
37256 \InsetSpace ~
37257 /* argument
37258  u is promoted to int before
37259 \newline
37260 \InsetSpace ~
37261 \InsetSpace ~
37262 \InsetSpace ~
37263 * passing to function */
37264 \newline
37265 \InsetSpace ~
37266 \InsetSpace ~
37267 vararg_func ("%c", c);
37268 \newline
37269
37270 \newline
37271 \InsetSpace ~
37272 \InsetSpace ~
37273 /*
37274  argument u is not promoted to int,
37275 \newline
37276 \InsetSpace ~
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 * it is passed as char to function
37280 \newline
37281 \InsetSpace ~
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 * if
37285  --std-cXX is not defined;
37286 \newline
37287 \InsetSpace ~
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 * is promoted to int before passing
37291 \newline
37292 \InsetSpace ~
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 * to function
37296  if --std-cXX is defined */
37297 \newline
37298 \InsetSpace ~
37299 \InsetSpace ~
37300 vararg_func ("%bc", (char)u);
37301 \newline
37302 }
37303 \end_layout
37304
37305 \end_deeper
37306 \begin_layout Section
37307 Cyclomatic Complexity
37308 \begin_inset LatexCommand \index{Cyclomatic complexity}
37309
37310 \end_inset
37311
37312
37313 \end_layout
37314
37315 \begin_layout Standard
37316 Cyclomatic complexity of a function is defined as the number of independent
37317  paths the program can take during execution of the function.
37318  This is an important number since it defines the number test cases you
37319  have to generate to validate the function.
37320  The accepted industry standard for complexity number is 10, if the cyclomatic
37321  complexity reported by SDCC exceeds 10 you should think about simplification
37322  of the function logic.
37323  Note that the complexity level is not related to the number of lines of
37324  code in a function.
37325  Large functions can have low complexity, and small functions can have large
37326  complexity levels.
37327  
37328 \newline
37329
37330 \newline
37331 SDCC uses the following formula to compute the complexity:
37332 \newline
37333
37334 \end_layout
37335
37336 \begin_layout Standard
37337 complexity = (number of edges in control flow graph) - (number of nodes
37338  in control flow graph) + 2;
37339 \newline
37340
37341 \newline
37342 Having said that the industry standard is 10,
37343  you should be aware that in some cases it be may unavoidable to have a
37344  complexity level of less than 10.
37345  For example if you have switch statement with more than 10 case labels,
37346  each case label adds one to the complexity level.
37347  The complexity level is by no means an absolute measure of the algorithmic
37348  complexity of the function, it does however provide a good starting point
37349  for which functions you might look at for further optimization.
37350 \end_layout
37351
37352 \begin_layout Section
37353 Retargetting for other Processors
37354 \end_layout
37355
37356 \begin_layout Standard
37357 The issues for retargetting the compiler are far too numerous to be covered
37358  by this document.
37359  What follows is a brief description of each of the seven phases of the
37360  compiler and its MCU dependency.
37361 \end_layout
37362
37363 \begin_layout Itemize
37364 Parsing the source and building the annotated parse tree.
37365  This phase is largely MCU independent (except for the language extensions).
37366  Syntax & semantic checks are also done in this phase, along with some initial
37367  optimizations like back patching labels and the pattern matching optimizations
37368  like bit-rotation etc.
37369 \end_layout
37370
37371 \begin_layout Itemize
37372 The second phase involves generating an intermediate code which can be easy
37373  manipulated during the later phases.
37374  This phase is entirely MCU independent.
37375  The intermediate code generation assumes the target machine has unlimited
37376  number of registers, and designates them with the name iTemp.
37377  The compiler can be made to dump a human readable form of the code generated
37378  by using the -
37379 \begin_inset ERT
37380 status collapsed
37381
37382 \begin_layout Standard
37383
37384
37385 \backslash
37386 /
37387 \end_layout
37388
37389 \end_inset
37390
37391 -dumpraw option.
37392 \end_layout
37393
37394 \begin_layout Itemize
37395 This phase does the bulk of the standard optimizations and is also MCU independe
37396 nt.
37397  This phase can be broken down into several sub-phases:
37398 \newline
37399
37400 \newline
37401 Break down intermediate
37402  code (iCode) into basic blocks.
37403 \newline
37404 Do control flow & data flow analysis on the
37405  basic blocks.
37406 \newline
37407 Do local common subexpression elimination, then global subexpressio
37408 n elimination
37409 \newline
37410 Dead code elimination
37411 \newline
37412 Loop optimizations
37413 \newline
37414 If loop optimizations
37415  caused any changes then do 'global subexpression elimination' and 'dead
37416  code elimination' again.
37417 \end_layout
37418
37419 \begin_layout Itemize
37420 This phase determines the live-ranges; by live range I mean those iTemp
37421  variables defined by the compiler that still survive after all the optimization
37422 s.
37423  Live range analysis
37424 \begin_inset LatexCommand \index{Live range analysis}
37425
37426 \end_inset
37427
37428  is essential for register allocation, since these computation determines
37429  which of these iTemps will be assigned to registers, and for how long.
37430 \end_layout
37431
37432 \begin_layout Itemize
37433 Phase five is register allocation.
37434  There are two parts to this process.
37435 \newline
37436
37437 \newline
37438 The first part I call 'register packing'
37439  (for lack of a better term).
37440  In this case several MCU specific expression folding is done to reduce
37441  register pressure.
37442 \newline
37443
37444 \newline
37445 The second part is more MCU independent and deals with
37446  allocating registers to the remaining live ranges.
37447  A lot of MCU specific code does creep into this phase because of the limited
37448  number of index registers available in the 8051.
37449 \end_layout
37450
37451 \begin_layout Itemize
37452 The Code generation phase is (unhappily), entirely MCU dependent and very
37453  little (if any at all) of this code can be reused for other MCU.
37454  However the scheme for allocating a homogenized assembler operand for each
37455  iCode operand may be reused.
37456 \end_layout
37457
37458 \begin_layout Itemize
37459 As mentioned in the optimization section the peep-hole optimizer is rule
37460  based system, which can reprogrammed for other MCUs.
37461 \end_layout
37462
37463 \begin_layout Standard
37464 More information is available on SDCC Wiki
37465 \begin_inset LatexCommand \index{wiki}
37466
37467 \end_inset
37468
37469  (preliminary link 
37470 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37471
37472 \end_inset
37473
37474 ) and in the thread 
37475 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37476
37477 \end_inset
37478
37479  .
37480 \end_layout
37481
37482 \begin_layout Chapter
37483 Compiler internals
37484 \begin_inset LatexCommand \index{Compiler internals}
37485
37486 \end_inset
37487
37488
37489 \end_layout
37490
37491 \begin_layout Section
37492 The anatomy of the compiler
37493 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37494
37495 \end_inset
37496
37497
37498 \end_layout
37499
37500 \begin_layout Standard
37501
37502 \shape italic
37503 This is an excerpt from an article published in Circuit Cellar Magazine
37504  in 
37505 \series bold
37506 August 2000
37507 \series default
37508 .
37509  It's a little outdated (the compiler is much more efficient now and user/develo
37510 per friendly), but pretty well exposes the guts of it all.
37511 \shape default
37512
37513 \newline
37514
37515 \newline
37516 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37517  It is fairly easy to retarget for other 8-bit MCU.
37518  Here we take a look at some of the internals of the compiler.
37519  
37520 \end_layout
37521
37522 \begin_layout Paragraph*
37523 Parsing
37524 \begin_inset LatexCommand \index{Parsing}
37525
37526 \end_inset
37527
37528  
37529 \end_layout
37530
37531 \begin_layout Standard
37532 Parsing the input source file and creating an AST (Annotated Syntax Tree
37533 \begin_inset LatexCommand \index{Annotated syntax tree}
37534
37535 \end_inset
37536
37537 ).
37538  This phase also involves propagating types (annotating each node of the
37539  parse tree with type information) and semantic analysis.
37540  There are some MCU specific parsing rules.
37541  For example the storage classes, the extended storage classes are MCU specific
37542  while there may be a xdata storage class for 8051 there is no such storage
37543  class for z80 or Atmel AVR.
37544  SDCC allows MCU specific storage class extensions, i.e.
37545  xdata will be treated as a storage class specifier when parsing 8051 C
37546  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37547  C code.
37548 \end_layout
37549
37550 \begin_layout Paragraph*
37551 Generating iCode
37552 \begin_inset LatexCommand \index{iCode}
37553
37554 \end_inset
37555
37556
37557 \end_layout
37558
37559 \begin_layout Standard
37560 Intermediate code generation.
37561  In this phase the AST is broken down into three-operand form (iCode).
37562  These three operand forms are represented as doubly linked lists.
37563  ICode is the term given to the intermediate form generated by the compiler.
37564  ICode example section shows some examples of iCode generated for some simple
37565  C source functions.
37566 \end_layout
37567
37568 \begin_layout Paragraph*
37569 Optimizations
37570 \begin_inset LatexCommand \index{Optimizations}
37571
37572 \end_inset
37573
37574 .
37575 \end_layout
37576
37577 \begin_layout Standard
37578 Bulk of the target independent optimizations is performed in this phase.
37579  The optimizations include constant propagation, common sub-expression eliminati
37580 on, loop invariant code movement, strength reduction of loop induction variables
37581  and dead-code elimination.
37582 \end_layout
37583
37584 \begin_layout Paragraph*
37585 Live range analysis
37586 \begin_inset LatexCommand \index{Live range analysis}
37587
37588 \end_inset
37589
37590
37591 \end_layout
37592
37593 \begin_layout Standard
37594 During intermediate code generation phase, the compiler assumes the target
37595  machine has infinite number of registers and generates a lot of temporary
37596  variables.
37597  The live range computation determines the lifetime of each of these compiler-ge
37598 nerated temporaries.
37599  A picture speaks a thousand words.
37600  ICode example sections show the live range annotations for each of the
37601  operand.
37602  It is important to note here, each iCode is assigned a number in the order
37603  of its execution in the function.
37604  The live ranges are computed in terms of these numbers.
37605  The from number is the number of the iCode which first defines the operand
37606  and the to number signifies the iCode which uses this operand last.
37607 \end_layout
37608
37609 \begin_layout Paragraph*
37610 Register Allocation
37611 \begin_inset LatexCommand \index{Register allocation}
37612
37613 \end_inset
37614
37615
37616 \end_layout
37617
37618 \begin_layout Standard
37619 The register allocation determines the type and number of registers needed
37620  by each operand.
37621  In most MCUs only a few registers can be used for indirect addressing.
37622  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37623  address the internal ram and DPTR to indirectly address the external ram.
37624  The compiler will try to allocate the appropriate register to pointer variables
37625  if it can.
37626  ICode example section shows the operands annotated with the registers assigned
37627  to them.
37628  The compiler will try to keep operands in registers as much as possible;
37629  there are several schemes the compiler uses to do achieve this.
37630  When the compiler runs out of registers the compiler will check to see
37631  if there are any live operands which is not used or defined in the current
37632  basic block being processed, if there are any found then it will push that
37633  operand and use the registers in this block, the operand will then be popped
37634  at the end of the basic block.
37635  
37636 \end_layout
37637
37638 \begin_layout Standard
37639 There are other MCU specific considerations in this phase.
37640  Some MCUs have an accumulator; very short-lived operands could be assigned
37641  to the accumulator instead of a general-purpose register.
37642 \end_layout
37643
37644 \begin_layout Paragraph*
37645 Code generation
37646 \end_layout
37647
37648 \begin_layout Standard
37649 Figure II gives a table of iCode
37650 \begin_inset LatexCommand \index{iCode}
37651
37652 \end_inset
37653
37654  operations supported by the compiler.
37655  The code generation involves translating these operations into corresponding
37656  assembly code for the processor.
37657  This sounds overly simple but that is the essence of code generation.
37658  Some of the iCode operations are generated on a MCU specific manner for
37659  example, the z80 port does not use registers to pass parameters so the
37660  SEND and RECV iCode operations will not be generated, and it also does
37661  not support JUMPTABLES.
37662  
37663 \newline
37664
37665 \end_layout
37666
37667 \begin_layout Standard
37668
37669 \size footnotesize
37670 Figure II 
37671 \begin_inset Tabular
37672 <lyxtabular version="3" rows="39" columns="4">
37673 <features islongtable="true" headBottomDL="true">
37674 <column alignment="block" valignment="top" leftline="true" width="13col%">
37675 <column alignment="left" valignment="top" leftline="true" width="13col%">
37676 <column alignment="block" valignment="top" leftline="true" width="22col%">
37677 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37678 <row topline="true" bottomline="true" endhead="true">
37679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37680 \begin_inset Text
37681
37682 \begin_layout Standard
37683
37684 \series bold
37685 iCode
37686 \series default
37687
37688 \begin_inset LatexCommand \index{iCode}
37689
37690 \end_inset
37691
37692
37693 \end_layout
37694
37695 \end_inset
37696 </cell>
37697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37698 \begin_inset Text
37699
37700 \begin_layout Standard
37701
37702 \series bold
37703 Operands
37704 \end_layout
37705
37706 \end_inset
37707 </cell>
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37709 \begin_inset Text
37710
37711 \begin_layout Standard
37712
37713 \series bold
37714 Description
37715 \end_layout
37716
37717 \end_inset
37718 </cell>
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37720 \begin_inset Text
37721
37722 \begin_layout Standard
37723
37724 \series bold
37725 C Equivalent
37726 \end_layout
37727
37728 \end_inset
37729 </cell>
37730 </row>
37731 <row topline="true">
37732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37733 \begin_inset Text
37734
37735 \begin_layout Standard
37736
37737 \size footnotesize
37738 '!'
37739 \end_layout
37740
37741 \end_inset
37742 </cell>
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37744 \begin_inset Text
37745
37746 \begin_layout Standard
37747
37748 \size footnotesize
37749 IC_LEFT() IC_RESULT()
37750 \end_layout
37751
37752 \end_inset
37753 </cell>
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37755 \begin_inset Text
37756
37757 \begin_layout Standard
37758
37759 \size footnotesize
37760 NOT operation 
37761 \end_layout
37762
37763 \end_inset
37764 </cell>
37765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37766 \begin_inset Text
37767
37768 \begin_layout Standard
37769
37770 \size footnotesize
37771 IC_RESULT = ! IC_LEFT;
37772 \end_layout
37773
37774 \end_inset
37775 </cell>
37776 </row>
37777 <row topline="true">
37778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37779 \begin_inset Text
37780
37781 \begin_layout Standard
37782
37783 \size footnotesize
37784 '~'
37785 \end_layout
37786
37787 \end_inset
37788 </cell>
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37790 \begin_inset Text
37791
37792 \begin_layout Standard
37793
37794 \size footnotesize
37795 IC_LEFT() IC_RESULT()
37796 \end_layout
37797
37798 \end_inset
37799 </cell>
37800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37801 \begin_inset Text
37802
37803 \begin_layout Standard
37804
37805 \size footnotesize
37806 Bitwise complement of 
37807 \end_layout
37808
37809 \end_inset
37810 </cell>
37811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37812 \begin_inset Text
37813
37814 \begin_layout Standard
37815
37816 \size footnotesize
37817 IC_RESULT = ~IC_LEFT;
37818 \end_layout
37819
37820 \end_inset
37821 </cell>
37822 </row>
37823 <row topline="true">
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37825 \begin_inset Text
37826
37827 \begin_layout Standard
37828
37829 \size footnotesize
37830 RRC
37831 \end_layout
37832
37833 \end_inset
37834 </cell>
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37836 \begin_inset Text
37837
37838 \begin_layout Standard
37839
37840 \size footnotesize
37841 IC_LEFT() IC_RESULT()
37842 \end_layout
37843
37844 \end_inset
37845 </cell>
37846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37847 \begin_inset Text
37848
37849 \begin_layout Standard
37850
37851 \size footnotesize
37852 Rotate right with carry
37853 \end_layout
37854
37855 \end_inset
37856 </cell>
37857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37858 \begin_inset Text
37859
37860 \begin_layout Standard
37861
37862 \size footnotesize
37863 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37864 \end_layout
37865
37866 \end_inset
37867 </cell>
37868 </row>
37869 <row topline="true">
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37871 \begin_inset Text
37872
37873 \begin_layout Standard
37874
37875 \size footnotesize
37876 RLC
37877 \end_layout
37878
37879 \end_inset
37880 </cell>
37881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37882 \begin_inset Text
37883
37884 \begin_layout Standard
37885
37886 \size footnotesize
37887 IC_LEFT() IC_RESULT()
37888 \end_layout
37889
37890 \end_inset
37891 </cell>
37892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37893 \begin_inset Text
37894
37895 \begin_layout Standard
37896
37897 \size footnotesize
37898 Rotate left with carry
37899 \end_layout
37900
37901 \end_inset
37902 </cell>
37903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37904 \begin_inset Text
37905
37906 \begin_layout Standard
37907
37908 \size footnotesize
37909 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37910 \end_layout
37911
37912 \end_inset
37913 </cell>
37914 </row>
37915 <row topline="true">
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37917 \begin_inset Text
37918
37919 \begin_layout Standard
37920
37921 \size footnotesize
37922 GETHBIT
37923 \end_layout
37924
37925 \end_inset
37926 </cell>
37927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37928 \begin_inset Text
37929
37930 \begin_layout Standard
37931
37932 \size footnotesize
37933 IC_LEFT() IC_RESULT()
37934 \end_layout
37935
37936 \end_inset
37937 </cell>
37938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37939 \begin_inset Text
37940
37941 \begin_layout Standard
37942
37943 \size footnotesize
37944 Get the highest order bit of IC_LEFT
37945 \end_layout
37946
37947 \end_inset
37948 </cell>
37949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37950 \begin_inset Text
37951
37952 \begin_layout Standard
37953
37954 \size footnotesize
37955 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37956 \end_layout
37957
37958 \end_inset
37959 </cell>
37960 </row>
37961 <row topline="true">
37962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37963 \begin_inset Text
37964
37965 \begin_layout Standard
37966
37967 \size footnotesize
37968 UNARYMINUS
37969 \end_layout
37970
37971 \end_inset
37972 </cell>
37973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37974 \begin_inset Text
37975
37976 \begin_layout Standard
37977
37978 \size footnotesize
37979 IC_LEFT() IC_RESULT()
37980 \end_layout
37981
37982 \end_inset
37983 </cell>
37984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37985 \begin_inset Text
37986
37987 \begin_layout Standard
37988
37989 \size footnotesize
37990 Unary minus
37991 \end_layout
37992
37993 \end_inset
37994 </cell>
37995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37996 \begin_inset Text
37997
37998 \begin_layout Standard
37999
38000 \size footnotesize
38001 IC_RESULT = - IC_LEFT;
38002 \end_layout
38003
38004 \end_inset
38005 </cell>
38006 </row>
38007 <row topline="true">
38008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38009 \begin_inset Text
38010
38011 \begin_layout Standard
38012
38013 \size footnotesize
38014 IPUSH
38015 \end_layout
38016
38017 \end_inset
38018 </cell>
38019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38020 \begin_inset Text
38021
38022 \begin_layout Standard
38023
38024 \size footnotesize
38025 IC_LEFT()
38026 \end_layout
38027
38028 \end_inset
38029 </cell>
38030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38031 \begin_inset Text
38032
38033 \begin_layout Standard
38034
38035 \size footnotesize
38036 Push the operand into stack
38037 \end_layout
38038
38039 \end_inset
38040 </cell>
38041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38042 \begin_inset Text
38043
38044 \begin_layout Standard
38045
38046 \size footnotesize
38047 NONE
38048 \end_layout
38049
38050 \end_inset
38051 </cell>
38052 </row>
38053 <row topline="true">
38054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38055 \begin_inset Text
38056
38057 \begin_layout Standard
38058
38059 \size footnotesize
38060 IPOP
38061 \end_layout
38062
38063 \end_inset
38064 </cell>
38065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38066 \begin_inset Text
38067
38068 \begin_layout Standard
38069
38070 \size footnotesize
38071 IC_LEFT()
38072 \end_layout
38073
38074 \end_inset
38075 </cell>
38076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38077 \begin_inset Text
38078
38079 \begin_layout Standard
38080
38081 \size footnotesize
38082 Pop the operand from the stack 
38083 \end_layout
38084
38085 \end_inset
38086 </cell>
38087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38088 \begin_inset Text
38089
38090 \begin_layout Standard
38091
38092 \size footnotesize
38093 NONE
38094 \end_layout
38095
38096 \end_inset
38097 </cell>
38098 </row>
38099 <row topline="true">
38100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38101 \begin_inset Text
38102
38103 \begin_layout Standard
38104
38105 \size footnotesize
38106 CALL
38107 \end_layout
38108
38109 \end_inset
38110 </cell>
38111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38112 \begin_inset Text
38113
38114 \begin_layout Standard
38115
38116 \size footnotesize
38117 IC_LEFT() IC_RESULT()
38118 \end_layout
38119
38120 \end_inset
38121 </cell>
38122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38123 \begin_inset Text
38124
38125 \begin_layout Standard
38126
38127 \size footnotesize
38128 Call the function represented by IC_LEFT 
38129 \end_layout
38130
38131 \end_inset
38132 </cell>
38133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38134 \begin_inset Text
38135
38136 \begin_layout Standard
38137
38138 \size footnotesize
38139 IC_RESULT = IC_LEFT();
38140 \end_layout
38141
38142 \end_inset
38143 </cell>
38144 </row>
38145 <row topline="true">
38146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38147 \begin_inset Text
38148
38149 \begin_layout Standard
38150
38151 \size footnotesize
38152 PCALL
38153 \end_layout
38154
38155 \end_inset
38156 </cell>
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38158 \begin_inset Text
38159
38160 \begin_layout Standard
38161
38162 \size footnotesize
38163 IC_LEFT() IC_RESULT()
38164 \end_layout
38165
38166 \end_inset
38167 </cell>
38168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38169 \begin_inset Text
38170
38171 \begin_layout Standard
38172
38173 \size footnotesize
38174 Call via function pointer
38175 \end_layout
38176
38177 \end_inset
38178 </cell>
38179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38180 \begin_inset Text
38181
38182 \begin_layout Standard
38183
38184 \size footnotesize
38185 IC_RESULT = (*IC_LEFT)();
38186 \end_layout
38187
38188 \end_inset
38189 </cell>
38190 </row>
38191 <row topline="true">
38192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38193 \begin_inset Text
38194
38195 \begin_layout Standard
38196
38197 \size footnotesize
38198 RETURN
38199 \end_layout
38200
38201 \end_inset
38202 </cell>
38203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38204 \begin_inset Text
38205
38206 \begin_layout Standard
38207
38208 \size footnotesize
38209 IC_LEFT()
38210 \end_layout
38211
38212 \end_inset
38213 </cell>
38214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38215 \begin_inset Text
38216
38217 \begin_layout Standard
38218
38219 \size footnotesize
38220 Return the value in operand IC_LEFT 
38221 \end_layout
38222
38223 \end_inset
38224 </cell>
38225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38226 \begin_inset Text
38227
38228 \begin_layout Standard
38229
38230 \size footnotesize
38231 return IC_LEFT;
38232 \end_layout
38233
38234 \end_inset
38235 </cell>
38236 </row>
38237 <row topline="true">
38238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38239 \begin_inset Text
38240
38241 \begin_layout Standard
38242
38243 \size footnotesize
38244 LABEL
38245 \end_layout
38246
38247 \end_inset
38248 </cell>
38249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38250 \begin_inset Text
38251
38252 \begin_layout Standard
38253
38254 \size footnotesize
38255 IC_LABEL() 
38256 \end_layout
38257
38258 \end_inset
38259 </cell>
38260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38261 \begin_inset Text
38262
38263 \begin_layout Standard
38264
38265 \size footnotesize
38266 Label
38267 \end_layout
38268
38269 \end_inset
38270 </cell>
38271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38272 \begin_inset Text
38273
38274 \begin_layout Standard
38275
38276 \size footnotesize
38277 IC_LABEL:
38278 \end_layout
38279
38280 \end_inset
38281 </cell>
38282 </row>
38283 <row topline="true">
38284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38285 \begin_inset Text
38286
38287 \begin_layout Standard
38288
38289 \size footnotesize
38290 GOTO
38291 \end_layout
38292
38293 \end_inset
38294 </cell>
38295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38296 \begin_inset Text
38297
38298 \begin_layout Standard
38299
38300 \size footnotesize
38301 IC_LABEL() 
38302 \end_layout
38303
38304 \end_inset
38305 </cell>
38306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38307 \begin_inset Text
38308
38309 \begin_layout Standard
38310
38311 \size footnotesize
38312 Goto label
38313 \end_layout
38314
38315 \end_inset
38316 </cell>
38317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38318 \begin_inset Text
38319
38320 \begin_layout Standard
38321
38322 \size footnotesize
38323 goto IC_LABEL();
38324 \end_layout
38325
38326 \end_inset
38327 </cell>
38328 </row>
38329 <row topline="true">
38330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38331 \begin_inset Text
38332
38333 \begin_layout Standard
38334
38335 \size footnotesize
38336 '+'
38337 \end_layout
38338
38339 \end_inset
38340 </cell>
38341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38342 \begin_inset Text
38343
38344 \begin_layout Standard
38345
38346 \size footnotesize
38347 IC_LEFT() IC_RIGHT() IC_RESULT()
38348 \end_layout
38349
38350 \end_inset
38351 </cell>
38352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38353 \begin_inset Text
38354
38355 \begin_layout Standard
38356
38357 \size footnotesize
38358 Addition
38359 \end_layout
38360
38361 \end_inset
38362 </cell>
38363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38364 \begin_inset Text
38365
38366 \begin_layout Standard
38367
38368 \size footnotesize
38369 IC_RESULT = IC_LEFT + IC_RIGHT
38370 \end_layout
38371
38372 \end_inset
38373 </cell>
38374 </row>
38375 <row topline="true">
38376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38377 \begin_inset Text
38378
38379 \begin_layout Standard
38380
38381 \size footnotesize
38382 '-'
38383 \end_layout
38384
38385 \end_inset
38386 </cell>
38387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38388 \begin_inset Text
38389
38390 \begin_layout Standard
38391
38392 \size footnotesize
38393 IC_LEFT() IC_RIGHT() IC_RESULT()
38394 \end_layout
38395
38396 \end_inset
38397 </cell>
38398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38399 \begin_inset Text
38400
38401 \begin_layout Standard
38402
38403 \size footnotesize
38404 Subtraction
38405 \end_layout
38406
38407 \end_inset
38408 </cell>
38409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38410 \begin_inset Text
38411
38412 \begin_layout Standard
38413
38414 \size footnotesize
38415 IC_RESULT = IC_LEFT - IC_RIGHT 
38416 \end_layout
38417
38418 \end_inset
38419 </cell>
38420 </row>
38421 <row topline="true">
38422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38423 \begin_inset Text
38424
38425 \begin_layout Standard
38426
38427 \size footnotesize
38428 '*'
38429 \end_layout
38430
38431 \end_inset
38432 </cell>
38433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38434 \begin_inset Text
38435
38436 \begin_layout Standard
38437
38438 \size footnotesize
38439 IC_LEFT() IC_RIGHT() IC_RESULT()
38440 \end_layout
38441
38442 \end_inset
38443 </cell>
38444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38445 \begin_inset Text
38446
38447 \begin_layout Standard
38448
38449 \size footnotesize
38450 Multiplication 
38451 \end_layout
38452
38453 \end_inset
38454 </cell>
38455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38456 \begin_inset Text
38457
38458 \begin_layout Standard
38459
38460 \size footnotesize
38461 IC_RESULT = IC_LEFT * IC_RIGHT;
38462 \end_layout
38463
38464 \end_inset
38465 </cell>
38466 </row>
38467 <row topline="true">
38468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38469 \begin_inset Text
38470
38471 \begin_layout Standard
38472
38473 \size footnotesize
38474 '/'
38475 \end_layout
38476
38477 \end_inset
38478 </cell>
38479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38480 \begin_inset Text
38481
38482 \begin_layout Standard
38483
38484 \size footnotesize
38485 IC_LEFT() IC_RIGHT() IC_RESULT()
38486 \end_layout
38487
38488 \end_inset
38489 </cell>
38490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38491 \begin_inset Text
38492
38493 \begin_layout Standard
38494
38495 \size footnotesize
38496 Division
38497 \end_layout
38498
38499 \end_inset
38500 </cell>
38501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38502 \begin_inset Text
38503
38504 \begin_layout Standard
38505
38506 \size footnotesize
38507 IC_RESULT = IC_LEFT / IC_RIGHT;
38508 \end_layout
38509
38510 \end_inset
38511 </cell>
38512 </row>
38513 <row topline="true">
38514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38515 \begin_inset Text
38516
38517 \begin_layout Standard
38518
38519 \size footnotesize
38520 '%'
38521 \end_layout
38522
38523 \end_inset
38524 </cell>
38525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38526 \begin_inset Text
38527
38528 \begin_layout Standard
38529
38530 \size footnotesize
38531 IC_LEFT() IC_RIGHT() IC_RESULT()
38532 \end_layout
38533
38534 \end_inset
38535 </cell>
38536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38537 \begin_inset Text
38538
38539 \begin_layout Standard
38540
38541 \size footnotesize
38542 Modulus
38543 \end_layout
38544
38545 \end_inset
38546 </cell>
38547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38548 \begin_inset Text
38549
38550 \begin_layout Standard
38551
38552 \size footnotesize
38553 IC_RESULT = IC_LEFT % IC_RIGHT;
38554 \end_layout
38555
38556 \end_inset
38557 </cell>
38558 </row>
38559 <row topline="true">
38560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38561 \begin_inset Text
38562
38563 \begin_layout Standard
38564
38565 \size footnotesize
38566 '<'
38567 \end_layout
38568
38569 \end_inset
38570 </cell>
38571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38572 \begin_inset Text
38573
38574 \begin_layout Standard
38575
38576 \size footnotesize
38577 IC_LEFT() IC_RIGHT() IC_RESULT()
38578 \end_layout
38579
38580 \end_inset
38581 </cell>
38582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38583 \begin_inset Text
38584
38585 \begin_layout Standard
38586
38587 \size footnotesize
38588 Less than
38589 \end_layout
38590
38591 \end_inset
38592 </cell>
38593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38594 \begin_inset Text
38595
38596 \begin_layout Standard
38597
38598 \size footnotesize
38599 IC_RESULT = IC_LEFT < IC_RIGHT;
38600 \end_layout
38601
38602 \end_inset
38603 </cell>
38604 </row>
38605 <row topline="true">
38606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38607 \begin_inset Text
38608
38609 \begin_layout Standard
38610
38611 \size footnotesize
38612 '>'
38613 \end_layout
38614
38615 \end_inset
38616 </cell>
38617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38618 \begin_inset Text
38619
38620 \begin_layout Standard
38621
38622 \size footnotesize
38623 IC_LEFT() IC_RIGHT() IC_RESULT()
38624 \end_layout
38625
38626 \end_inset
38627 </cell>
38628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38629 \begin_inset Text
38630
38631 \begin_layout Standard
38632
38633 \size footnotesize
38634 Greater than 
38635 \end_layout
38636
38637 \end_inset
38638 </cell>
38639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38640 \begin_inset Text
38641
38642 \begin_layout Standard
38643
38644 \size footnotesize
38645 IC_RESULT = IC_LEFT > IC_RIGHT;
38646 \end_layout
38647
38648 \end_inset
38649 </cell>
38650 </row>
38651 <row topline="true">
38652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38653 \begin_inset Text
38654
38655 \begin_layout Standard
38656
38657 \size footnotesize
38658 EQ_OP
38659 \end_layout
38660
38661 \end_inset
38662 </cell>
38663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38664 \begin_inset Text
38665
38666 \begin_layout Standard
38667
38668 \size footnotesize
38669 IC_LEFT() IC_RIGHT() IC_RESULT()
38670 \end_layout
38671
38672 \end_inset
38673 </cell>
38674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38675 \begin_inset Text
38676
38677 \begin_layout Standard
38678
38679 \size footnotesize
38680 Equal to 
38681 \end_layout
38682
38683 \end_inset
38684 </cell>
38685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38686 \begin_inset Text
38687
38688 \begin_layout Standard
38689
38690 \size footnotesize
38691 IC_RESULT = IC_LEFT == IC_RIGHT;
38692 \end_layout
38693
38694 \end_inset
38695 </cell>
38696 </row>
38697 <row topline="true">
38698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38699 \begin_inset Text
38700
38701 \begin_layout Standard
38702
38703 \size footnotesize
38704 AND_OP
38705 \end_layout
38706
38707 \end_inset
38708 </cell>
38709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38710 \begin_inset Text
38711
38712 \begin_layout Standard
38713
38714 \size footnotesize
38715 IC_LEFT() IC_RIGHT() IC_RESULT() 
38716 \end_layout
38717
38718 \end_inset
38719 </cell>
38720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38721 \begin_inset Text
38722
38723 \begin_layout Standard
38724
38725 \size footnotesize
38726 Logical and operation
38727 \end_layout
38728
38729 \end_inset
38730 </cell>
38731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38732 \begin_inset Text
38733
38734 \begin_layout Standard
38735
38736 \size footnotesize
38737 IC_RESULT = IC_LEFT && IC_RIGHT; 
38738 \end_layout
38739
38740 \end_inset
38741 </cell>
38742 </row>
38743 <row topline="true">
38744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38745 \begin_inset Text
38746
38747 \begin_layout Standard
38748
38749 \size footnotesize
38750 OR_OP
38751 \end_layout
38752
38753 \end_inset
38754 </cell>
38755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38756 \begin_inset Text
38757
38758 \begin_layout Standard
38759
38760 \size footnotesize
38761 IC_LEFT() IC_RIGHT() IC_RESULT() 
38762 \end_layout
38763
38764 \end_inset
38765 </cell>
38766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38767 \begin_inset Text
38768
38769 \begin_layout Standard
38770
38771 \size footnotesize
38772 Logical or operation 
38773 \end_layout
38774
38775 \end_inset
38776 </cell>
38777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38778 \begin_inset Text
38779
38780 \begin_layout Standard
38781
38782 \size footnotesize
38783 IC_RESULT = IC_LEFT || IC_RIGHT; 
38784 \end_layout
38785
38786 \end_inset
38787 </cell>
38788 </row>
38789 <row topline="true">
38790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38791 \begin_inset Text
38792
38793 \begin_layout Standard
38794
38795 \size footnotesize
38796 '^'
38797 \end_layout
38798
38799 \end_inset
38800 </cell>
38801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38802 \begin_inset Text
38803
38804 \begin_layout Standard
38805
38806 \size footnotesize
38807 IC_LEFT() IC_RIGHT() IC_RESULT() 
38808 \end_layout
38809
38810 \end_inset
38811 </cell>
38812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38813 \begin_inset Text
38814
38815 \begin_layout Standard
38816
38817 \size footnotesize
38818 Exclusive OR
38819 \end_layout
38820
38821 \end_inset
38822 </cell>
38823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38824 \begin_inset Text
38825
38826 \begin_layout Standard
38827
38828 \size footnotesize
38829 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38830 \end_layout
38831
38832 \end_inset
38833 </cell>
38834 </row>
38835 <row topline="true">
38836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38837 \begin_inset Text
38838
38839 \begin_layout Standard
38840
38841 \size footnotesize
38842 '|'
38843 \end_layout
38844
38845 \end_inset
38846 </cell>
38847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38848 \begin_inset Text
38849
38850 \begin_layout Standard
38851
38852 \size footnotesize
38853 IC_LEFT() IC_RIGHT() IC_RESULT() 
38854 \end_layout
38855
38856 \end_inset
38857 </cell>
38858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38859 \begin_inset Text
38860
38861 \begin_layout Standard
38862
38863 \size footnotesize
38864 Bitwise OR 
38865 \end_layout
38866
38867 \end_inset
38868 </cell>
38869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38870 \begin_inset Text
38871
38872 \begin_layout Standard
38873
38874 \size footnotesize
38875 IC_RESULT = IC_LEFT | IC_RIGHT;
38876 \end_layout
38877
38878 \end_inset
38879 </cell>
38880 </row>
38881 <row topline="true">
38882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38883 \begin_inset Text
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 BITWISEAND
38889 \end_layout
38890
38891 \end_inset
38892 </cell>
38893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38894 \begin_inset Text
38895
38896 \begin_layout Standard
38897
38898 \size footnotesize
38899 IC_LEFT() IC_RIGHT() IC_RESULT()
38900 \end_layout
38901
38902 \end_inset
38903 </cell>
38904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38905 \begin_inset Text
38906
38907 \begin_layout Standard
38908
38909 \size footnotesize
38910 Bitwise AND 
38911 \end_layout
38912
38913 \end_inset
38914 </cell>
38915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38916 \begin_inset Text
38917
38918 \begin_layout Standard
38919
38920 \size footnotesize
38921 IC_RESULT = IC_LEFT & IC_RIGHT;
38922 \end_layout
38923
38924 \end_inset
38925 </cell>
38926 </row>
38927 <row topline="true">
38928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38929 \begin_inset Text
38930
38931 \begin_layout Standard
38932
38933 \size footnotesize
38934 LEFT_OP
38935 \end_layout
38936
38937 \end_inset
38938 </cell>
38939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38940 \begin_inset Text
38941
38942 \begin_layout Standard
38943
38944 \size footnotesize
38945 IC_LEFT() IC_RIGHT() IC_RESULT()
38946 \end_layout
38947
38948 \end_inset
38949 </cell>
38950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38951 \begin_inset Text
38952
38953 \begin_layout Standard
38954
38955 \size footnotesize
38956 Left shift 
38957 \end_layout
38958
38959 \end_inset
38960 </cell>
38961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38962 \begin_inset Text
38963
38964 \begin_layout Standard
38965
38966 \size footnotesize
38967 IC_RESULT = IC_LEFT << IC_RIGHT 
38968 \end_layout
38969
38970 \end_inset
38971 </cell>
38972 </row>
38973 <row topline="true">
38974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38975 \begin_inset Text
38976
38977 \begin_layout Standard
38978
38979 \size footnotesize
38980 RIGHT_OP
38981 \end_layout
38982
38983 \end_inset
38984 </cell>
38985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38986 \begin_inset Text
38987
38988 \begin_layout Standard
38989
38990 \size footnotesize
38991 IC_LEFT() IC_RIGHT() IC_RESULT()
38992 \end_layout
38993
38994 \end_inset
38995 </cell>
38996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38997 \begin_inset Text
38998
38999 \begin_layout Standard
39000
39001 \size footnotesize
39002 Right shift
39003 \end_layout
39004
39005 \end_inset
39006 </cell>
39007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39008 \begin_inset Text
39009
39010 \begin_layout Standard
39011
39012 \size footnotesize
39013 IC_RESULT = IC_LEFT >> IC_RIGHT 
39014 \end_layout
39015
39016 \end_inset
39017 </cell>
39018 </row>
39019 <row topline="true">
39020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39021 \begin_inset Text
39022
39023 \begin_layout Standard
39024
39025 \size footnotesize
39026 GET_VALUE_
39027 \newline
39028 AT_ ADDRESS
39029 \end_layout
39030
39031 \end_inset
39032 </cell>
39033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39034 \begin_inset Text
39035
39036 \begin_layout Standard
39037
39038 \size footnotesize
39039 IC_LEFT() IC_RESULT()
39040 \end_layout
39041
39042 \end_inset
39043 </cell>
39044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39045 \begin_inset Text
39046
39047 \begin_layout Standard
39048
39049 \size footnotesize
39050 Indirect fetch 
39051 \end_layout
39052
39053 \end_inset
39054 </cell>
39055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39056 \begin_inset Text
39057
39058 \begin_layout Standard
39059
39060 \size footnotesize
39061 IC_RESULT = (*IC_LEFT);
39062 \end_layout
39063
39064 \end_inset
39065 </cell>
39066 </row>
39067 <row topline="true">
39068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39069 \begin_inset Text
39070
39071 \begin_layout Standard
39072
39073 \size footnotesize
39074 POINTER_SET
39075 \end_layout
39076
39077 \end_inset
39078 </cell>
39079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39080 \begin_inset Text
39081
39082 \begin_layout Standard
39083
39084 \size footnotesize
39085 IC_RIGHT() IC_RESULT() 
39086 \end_layout
39087
39088 \end_inset
39089 </cell>
39090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39091 \begin_inset Text
39092
39093 \begin_layout Standard
39094
39095 \size footnotesize
39096 Indirect set
39097 \end_layout
39098
39099 \end_inset
39100 </cell>
39101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39102 \begin_inset Text
39103
39104 \begin_layout Standard
39105
39106 \size footnotesize
39107 (*IC_RESULT) = IC_RIGHT;
39108 \end_layout
39109
39110 \end_inset
39111 </cell>
39112 </row>
39113 <row topline="true">
39114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39115 \begin_inset Text
39116
39117 \begin_layout Standard
39118
39119 \size footnotesize
39120 '='
39121 \end_layout
39122
39123 \end_inset
39124 </cell>
39125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39126 \begin_inset Text
39127
39128 \begin_layout Standard
39129
39130 \size footnotesize
39131 IC_RIGHT() IC_RESULT()
39132 \end_layout
39133
39134 \end_inset
39135 </cell>
39136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39137 \begin_inset Text
39138
39139 \begin_layout Standard
39140
39141 \size footnotesize
39142 Assignment
39143 \end_layout
39144
39145 \end_inset
39146 </cell>
39147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39148 \begin_inset Text
39149
39150 \begin_layout Standard
39151
39152 \size footnotesize
39153 IC_RESULT = IC_RIGHT;
39154 \end_layout
39155
39156 \end_inset
39157 </cell>
39158 </row>
39159 <row topline="true">
39160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39161 \begin_inset Text
39162
39163 \begin_layout Standard
39164
39165 \size footnotesize
39166 IFX
39167 \end_layout
39168
39169 \end_inset
39170 </cell>
39171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39172 \begin_inset Text
39173
39174 \begin_layout Standard
39175
39176 \size footnotesize
39177 IC_COND IC_TRUE IC_LABEL
39178 \end_layout
39179
39180 \end_inset
39181 </cell>
39182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39183 \begin_inset Text
39184
39185 \begin_layout Standard
39186
39187 \size footnotesize
39188 Conditional jump.
39189  If true label is present then jump to true label if condition is true else
39190  jump to false label if condition is false 
39191 \end_layout
39192
39193 \end_inset
39194 </cell>
39195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39196 \begin_inset Text
39197
39198 \begin_layout Standard
39199
39200 \size footnotesize
39201 if (IC_COND) goto IC_TRUE; 
39202 \newline
39203 \InsetSpace ~
39204 \InsetSpace ~
39205 Or 
39206 \newline
39207 If (!IC_COND) goto IC_FALSE;
39208 \end_layout
39209
39210 \end_inset
39211 </cell>
39212 </row>
39213 <row topline="true">
39214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39215 \begin_inset Text
39216
39217 \begin_layout Standard
39218
39219 \size footnotesize
39220 ADDRESS_OF
39221 \end_layout
39222
39223 \end_inset
39224 </cell>
39225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39226 \begin_inset Text
39227
39228 \begin_layout Standard
39229
39230 \size footnotesize
39231 IC_LEFT() IC_RESULT()
39232 \end_layout
39233
39234 \end_inset
39235 </cell>
39236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39237 \begin_inset Text
39238
39239 \begin_layout Standard
39240
39241 \size footnotesize
39242 Address of 
39243 \end_layout
39244
39245 \end_inset
39246 </cell>
39247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39248 \begin_inset Text
39249
39250 \begin_layout Standard
39251
39252 \size footnotesize
39253 IC_RESULT = &IC_LEFT();
39254 \end_layout
39255
39256 \end_inset
39257 </cell>
39258 </row>
39259 <row topline="true">
39260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39261 \begin_inset Text
39262
39263 \begin_layout Standard
39264
39265 \size footnotesize
39266 JUMPTABLE
39267 \end_layout
39268
39269 \end_inset
39270 </cell>
39271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39272 \begin_inset Text
39273
39274 \begin_layout Standard
39275
39276 \size footnotesize
39277 IC_JTCOND IC_JTLABELS
39278 \end_layout
39279
39280 \end_inset
39281 </cell>
39282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39283 \begin_inset Text
39284
39285 \begin_layout Standard
39286
39287 \size footnotesize
39288 Jump to list of labels depending on the value of JTCOND
39289 \end_layout
39290
39291 \end_inset
39292 </cell>
39293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39294 \begin_inset Text
39295
39296 \begin_layout Standard
39297
39298 \size footnotesize
39299 Switch statement
39300 \end_layout
39301
39302 \end_inset
39303 </cell>
39304 </row>
39305 <row topline="true">
39306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39307 \begin_inset Text
39308
39309 \begin_layout Standard
39310
39311 \size footnotesize
39312 CAST
39313 \end_layout
39314
39315 \end_inset
39316 </cell>
39317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39318 \begin_inset Text
39319
39320 \begin_layout Standard
39321
39322 \size footnotesize
39323 IC_RIGHT() IC_LEFT() IC_RESULT()
39324 \end_layout
39325
39326 \end_inset
39327 </cell>
39328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39329 \begin_inset Text
39330
39331 \begin_layout Standard
39332
39333 \size footnotesize
39334 Cast types 
39335 \end_layout
39336
39337 \end_inset
39338 </cell>
39339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39340 \begin_inset Text
39341
39342 \begin_layout Standard
39343
39344 \size footnotesize
39345 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39346 \end_layout
39347
39348 \end_inset
39349 </cell>
39350 </row>
39351 <row topline="true">
39352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39353 \begin_inset Text
39354
39355 \begin_layout Standard
39356
39357 \size footnotesize
39358 SEND
39359 \end_layout
39360
39361 \end_inset
39362 </cell>
39363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39364 \begin_inset Text
39365
39366 \begin_layout Standard
39367
39368 \size footnotesize
39369 IC_LEFT()
39370 \end_layout
39371
39372 \end_inset
39373 </cell>
39374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39375 \begin_inset Text
39376
39377 \begin_layout Standard
39378
39379 \size footnotesize
39380 This is used for passing parameters in registers; 
39381 \newline
39382 move IC_LEFT to the next
39383  available parameter register.
39384 \end_layout
39385
39386 \end_inset
39387 </cell>
39388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39389 \begin_inset Text
39390
39391 \begin_layout Standard
39392
39393 \size footnotesize
39394 None
39395 \end_layout
39396
39397 \end_inset
39398 </cell>
39399 </row>
39400 <row topline="true">
39401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39402 \begin_inset Text
39403
39404 \begin_layout Standard
39405
39406 \size footnotesize
39407 RECV
39408 \end_layout
39409
39410 \end_inset
39411 </cell>
39412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39413 \begin_inset Text
39414
39415 \begin_layout Standard
39416
39417 \size footnotesize
39418 IC_RESULT()
39419 \end_layout
39420
39421 \end_inset
39422 </cell>
39423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39424 \begin_inset Text
39425
39426 \begin_layout Standard
39427
39428 \size footnotesize
39429 This is used for receiving parameters passed in registers;
39430 \newline
39431 Move the values
39432  in the next parameter register to IC_RESULT 
39433 \end_layout
39434
39435 \end_inset
39436 </cell>
39437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39438 \begin_inset Text
39439
39440 \begin_layout Standard
39441
39442 \size footnotesize
39443 None
39444 \end_layout
39445
39446 \end_inset
39447 </cell>
39448 </row>
39449 <row topline="true" bottomline="true">
39450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39451 \begin_inset Text
39452
39453 \begin_layout Standard
39454
39455 \shape slanted
39456 \size footnotesize
39457 (some more have been added)
39458 \end_layout
39459
39460 \end_inset
39461 </cell>
39462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39463 \begin_inset Text
39464
39465 \begin_layout Standard
39466
39467 \end_layout
39468
39469 \end_inset
39470 </cell>
39471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39472 \begin_inset Text
39473
39474 \begin_layout Standard
39475
39476 \end_layout
39477
39478 \end_inset
39479 </cell>
39480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39481 \begin_inset Text
39482
39483 \begin_layout Standard
39484
39485 \shape slanted
39486 \size footnotesize
39487 see f.e.
39488  
39489 \family typewriter
39490 gen51Code()
39491 \family default
39492  in 
39493 \family typewriter
39494 src/mcs51/gen.c
39495 \end_layout
39496
39497 \end_inset
39498 </cell>
39499 </row>
39500 </lyxtabular>
39501
39502 \end_inset
39503
39504
39505 \end_layout
39506
39507 \begin_layout Standard
39508 \begin_inset Note Note
39509 status collapsed
39510
39511 \begin_layout Standard
39512 In the original article Figure II was announced to be downloadable on 
39513 \shape italic
39514 Circuit Cellar
39515 \shape default
39516 's web site.
39517  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39518 \end_layout
39519
39520 \end_inset
39521
39522
39523 \end_layout
39524
39525 \begin_layout Paragraph*
39526 ICode Example
39527 \begin_inset LatexCommand \index{iCode}
39528
39529 \end_inset
39530
39531
39532 \end_layout
39533
39534 \begin_layout Standard
39535 This section shows some details of iCode.
39536  The example C code does not do anything useful; it is used as an example
39537  to illustrate the intermediate code generated by the compiler.
39538 \end_layout
39539
39540 \begin_layout Verse
39541
39542 \family typewriter
39543 1.\InsetSpace ~
39544 xdata int * p;
39545 \newline
39546 2.\InsetSpace ~
39547 int gint;
39548 \newline
39549 3.\InsetSpace ~
39550 /* This function does nothing useful.
39551  It is used
39552 \newline
39553 4.\InsetSpace ~
39554 \InsetSpace ~
39555 \InsetSpace ~
39556 \InsetSpace ~
39557 for the purpose of explaining iCode */
39558 \newline
39559 5.\InsetSpace ~
39560 short function (data
39561  int *x)
39562 \newline
39563 6.\InsetSpace ~
39564 {
39565 \newline
39566 7.\InsetSpace ~
39567 \InsetSpace ~
39568 \InsetSpace ~
39569 short i=10; \InsetSpace ~
39570 \InsetSpace ~
39571 /* dead initialization eliminated */
39572 \newline
39573 8.\InsetSpace ~
39574 \InsetSpace ~
39575 \InsetSpace ~
39576 short sum=10;
39577  /* dead initialization eliminated */
39578 \newline
39579 9.\InsetSpace ~
39580 \InsetSpace ~
39581 \InsetSpace ~
39582 short mul;
39583 \newline
39584 10.\InsetSpace ~
39585 \InsetSpace ~
39586 int j ;
39587 \newline
39588 11.\InsetSpace ~
39589 \InsetSpace ~
39590 while (*x) *x++
39591  = *p++; 
39592 \newline
39593 12.\InsetSpace ~
39594 \InsetSpace ~
39595 \InsetSpace ~
39596 \InsetSpace ~
39597 sum = 0 ; 
39598 \newline
39599 13.\InsetSpace ~
39600 \InsetSpace ~
39601 mul = 0;
39602 \newline
39603 14.\InsetSpace ~
39604 \InsetSpace ~
39605 /* compiler detects i,j to be induction
39606  variables */
39607 \newline
39608 15.\InsetSpace ~
39609 \InsetSpace ~
39610 for (i = 0, j = 10 ; i < 10 ; i++, j
39611 \family default
39612 -
39613 \begin_inset ERT
39614 status collapsed
39615
39616 \begin_layout Standard
39617
39618
39619 \backslash
39620 /
39621 \end_layout
39622
39623 \end_inset
39624
39625 -
39626 \family typewriter
39627 ) {
39628 \newline
39629 16.\InsetSpace ~
39630 \InsetSpace ~
39631 \InsetSpace ~
39632 \InsetSpace ~
39633 sum += i;
39634 \newline
39635 17.\InsetSpace ~
39636 \InsetSpace ~
39637 \InsetSpace ~
39638 \InsetSpace ~
39639 mul += i * 3; \InsetSpace ~
39640 \InsetSpace ~
39641 /* this multiplication remains */
39642 \newline
39643 18.\InsetSpace ~
39644 \InsetSpace ~
39645 \InsetSpace ~
39646 \InsetSpace ~
39647 gint +=
39648  j * 3;\InsetSpace ~
39649 \InsetSpace ~
39650 /* this multiplication changed to addition */
39651 \newline
39652 19.\InsetSpace ~
39653 \InsetSpace ~
39654 }
39655 \newline
39656 20.\InsetSpace ~
39657 \InsetSpace ~
39658 return sum+mul;
39659 \newline
39660 21.\InsetSpace ~
39661 }
39662 \end_layout
39663
39664 \begin_layout Standard
39665 In addition to the operands each iCode contains information about the filename
39666  and line it corresponds to in the source file.
39667  The first field in the listing should be interpreted as follows:
39668 \newline
39669
39670 \shape italic
39671 \size footnotesize
39672 Filename(linenumber: iCode Execution sequence number : ICode hash table
39673  key : loop depth of the iCode).
39674 \shape default
39675 \size default
39676
39677 \newline
39678 Then follows the human readable form of the ICode operation.
39679  Each operand of this triplet form can be of three basic types a) compiler
39680  generated temporary b) user defined variable c) a constant value.
39681  Note that local variables and parameters are replaced by compiler generated
39682  temporaries.
39683  Live ranges
39684 \begin_inset LatexCommand \index{Live range analysis}
39685
39686 \end_inset
39687
39688  are computed only for temporaries (i.e.
39689  live ranges are not computed for global variables).
39690  Registers
39691 \begin_inset LatexCommand \index{Register allocation}
39692
39693 \end_inset
39694
39695  are allocated for temporaries only.
39696  Operands are formatted in the following manner:
39697 \newline
39698
39699 \shape italic
39700 \size footnotesize
39701 Operand Name [lr live-from : live-to ] { type information } [ registers
39702  allocated ].
39703 \shape default
39704 \size default
39705
39706 \newline
39707 As mentioned earlier the live ranges are computed in terms of the execution
39708  sequence number of the iCodes, for example 
39709 \newline
39710 the iTemp0 is live from (i.e.
39711  first defined in iCode with execution sequence number 3, and is last used
39712  in the iCode with sequence number 5).
39713  For induction variables such as iTemp21 the live range computation extends
39714  the lifetime from the start to the end of the loop.
39715 \newline
39716 The register allocator
39717  used the live range information to allocate registers, the same registers
39718  may be used for different temporaries if their live ranges do not overlap,
39719  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39720  ranges do not overlap.
39721  In addition the allocator also takes into consideration the type and usage
39722  of a temporary, for example itemp6 is a pointer to near space and is used
39723  as to fetch data from (i.e.
39724  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39725  Some short lived temporaries are allocated to special registers which have
39726  meaning to the code generator e.g.
39727  iTemp13 is allocated to a pseudo register CC which tells the back end that
39728  the temporary is used only for a conditional jump the code generation makes
39729  use of this information to optimize a compare and jump ICode.
39730 \newline
39731 There are several
39732  loop optimizations
39733 \begin_inset LatexCommand \index{Loop optimization}
39734
39735 \end_inset
39736
39737  performed by the compiler.
39738  It can detect induction variables iTemp21(i) and iTemp23(j).
39739  Also note the compiler does selective strength reduction
39740 \begin_inset LatexCommand \index{Strength reduction}
39741
39742 \end_inset
39743
39744 , i.e.
39745  the multiplication of an induction variable in line 18 (gint = j * 3) is
39746  changed to addition, a new temporary iTemp17 is allocated and assigned
39747  a initial value, a constant 3 is then added for each iteration of the loop.
39748  The compiler does not change the multiplication
39749 \begin_inset LatexCommand \index{Multiplication}
39750
39751 \end_inset
39752
39753  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39754 \newline
39755
39756 Note the dead code elimination
39757 \begin_inset LatexCommand \index{Dead-code elimination}
39758
39759 \end_inset
39760
39761  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39762  respectively.
39763 \newline
39764
39765 \end_layout
39766
39767 \begin_layout Standard
39768
39769 \size footnotesize
39770 Sample.c (5:1:0:0) _entry($9) :
39771 \end_layout
39772
39773 \begin_layout Standard
39774
39775 \size footnotesize
39776 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39777 \end_layout
39778
39779 \begin_layout Standard
39780
39781 \size footnotesize
39782 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39783 \end_layout
39784
39785 \begin_layout Standard
39786
39787 \size footnotesize
39788 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39789 \end_layout
39790
39791 \begin_layout Standard
39792
39793 \size footnotesize
39794 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39795  * int}[r2]
39796 \end_layout
39797
39798 \begin_layout Standard
39799
39800 \size footnotesize
39801 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39802 \end_layout
39803
39804 \begin_layout Standard
39805
39806 \size footnotesize
39807 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39808  int}[r0]]
39809 \end_layout
39810
39811 \begin_layout Standard
39812
39813 \size footnotesize
39814 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39815 \end_layout
39816
39817 \begin_layout Standard
39818
39819 \size footnotesize
39820 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39821  * int}
39822 \end_layout
39823
39824 \begin_layout Standard
39825
39826 \size footnotesize
39827 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39828  {short}
39829 \end_layout
39830
39831 \begin_layout Standard
39832
39833 \size footnotesize
39834 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39835  * int}[DPTR]]
39836 \end_layout
39837
39838 \begin_layout Standard
39839
39840 \size footnotesize
39841 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39842 }[r2 r3]
39843 \end_layout
39844
39845 \begin_layout Standard
39846
39847 \size footnotesize
39848 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39849  * int}[r0] + 0x2 {short}
39850 \end_layout
39851
39852 \begin_layout Standard
39853
39854 \size footnotesize
39855 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39856 \end_layout
39857
39858 \begin_layout Standard
39859
39860 \size footnotesize
39861 Sample.c(11:17:21:0)_whilebreak_0($3) :
39862 \end_layout
39863
39864 \begin_layout Standard
39865
39866 \size footnotesize
39867 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39868 \end_layout
39869
39870 \begin_layout Standard
39871
39872 \size footnotesize
39873 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39874 \end_layout
39875
39876 \begin_layout Standard
39877
39878 \size footnotesize
39879 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39880 \end_layout
39881
39882 \begin_layout Standard
39883
39884 \size footnotesize
39885 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39886 \end_layout
39887
39888 \begin_layout Standard
39889
39890 \size footnotesize
39891 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39892 \end_layout
39893
39894 \begin_layout Standard
39895
39896 \size footnotesize
39897 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39898 \end_layout
39899
39900 \begin_layout Standard
39901
39902 \size footnotesize
39903 Sample.c(15:24:26:1)_forcond_0($4) :
39904 \end_layout
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39910  < 0xa {short}
39911 \end_layout
39912
39913 \begin_layout Standard
39914
39915 \size footnotesize
39916 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39917 \end_layout
39918
39919 \begin_layout Standard
39920
39921 \size footnotesize
39922 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39923  + ITemp21 [lr21:38]{short}[r4]
39924 \end_layout
39925
39926 \begin_layout Standard
39927
39928 \size footnotesize
39929 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39930  * 0x3 {short}
39931 \end_layout
39932
39933 \begin_layout Standard
39934
39935 \size footnotesize
39936 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39937  + iTemp15 [lr29:30]{short}[r1]
39938 \end_layout
39939
39940 \begin_layout Standard
39941
39942 \size footnotesize
39943 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39944  r0]- 0x3 {short}
39945 \end_layout
39946
39947 \begin_layout Standard
39948
39949 \size footnotesize
39950 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39951 int}[r7 r0]
39952 \end_layout
39953
39954 \begin_layout Standard
39955
39956 \size footnotesize
39957 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39958  + 0x1 {short}
39959 \end_layout
39960
39961 \begin_layout Standard
39962
39963 \size footnotesize
39964 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39965  r6]- 0x1 {short}
39966 \end_layout
39967
39968 \begin_layout Standard
39969
39970 \size footnotesize
39971 Sample.c(19:38:47:1) goto _forcond_0($4)
39972 \end_layout
39973
39974 \begin_layout Standard
39975
39976 \size footnotesize
39977 Sample.c(19:39:48:0)_forbreak_0($7) :
39978 \end_layout
39979
39980 \begin_layout Standard
39981
39982 \size footnotesize
39983 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39984  + ITemp11 [lr19:40]{short}[r3]
39985 \end_layout
39986
39987 \begin_layout Standard
39988
39989 \size footnotesize
39990 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39991 \end_layout
39992
39993 \begin_layout Standard
39994
39995 \size footnotesize
39996 Sample.c(20:42:51:0)_return($8) :
39997 \end_layout
39998
39999 \begin_layout Standard
40000
40001 \size footnotesize
40002 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40003 \size default
40004
40005 \newline
40006
40007 \newline
40008 Finally the code generated for this function:
40009 \newline
40010
40011 \end_layout
40012
40013 \begin_layout Standard
40014
40015 \size footnotesize
40016 .area DSEG (DATA)
40017 \end_layout
40018
40019 \begin_layout Standard
40020
40021 \size footnotesize
40022 _p::
40023 \end_layout
40024
40025 \begin_layout Standard
40026
40027 \size footnotesize
40028 \InsetSpace ~
40029 \InsetSpace ~
40030 .ds 2
40031 \end_layout
40032
40033 \begin_layout Standard
40034
40035 \size footnotesize
40036 _gint::
40037 \end_layout
40038
40039 \begin_layout Standard
40040
40041 \size footnotesize
40042 \InsetSpace ~
40043 \InsetSpace ~
40044 .ds 2
40045 \end_layout
40046
40047 \begin_layout Standard
40048
40049 \size footnotesize
40050 ; sample.c 5
40051 \end_layout
40052
40053 \begin_layout Standard
40054
40055 \size footnotesize
40056 ; ----------------------------------------------
40057 \end_layout
40058
40059 \begin_layout Standard
40060
40061 \size footnotesize
40062 ; function function
40063 \end_layout
40064
40065 \begin_layout Standard
40066
40067 \size footnotesize
40068 ; ----------------------------------------------
40069 \end_layout
40070
40071 \begin_layout Standard
40072
40073 \size footnotesize
40074 _function:
40075 \end_layout
40076
40077 \begin_layout Standard
40078
40079 \size footnotesize
40080 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40081 \end_layout
40082
40083 \begin_layout Standard
40084
40085 \size footnotesize
40086 \InsetSpace ~
40087 \InsetSpace ~
40088 mov r2,dpl
40089 \end_layout
40090
40091 \begin_layout Standard
40092
40093 \size footnotesize
40094 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40095 \end_layout
40096
40097 \begin_layout Standard
40098
40099 \size footnotesize
40100 \InsetSpace ~
40101 \InsetSpace ~
40102 mov ar0,r2
40103 \end_layout
40104
40105 \begin_layout Standard
40106
40107 \size footnotesize
40108 ;_whilecontinue_0($1) :
40109 \end_layout
40110
40111 \begin_layout Standard
40112
40113 \size footnotesize
40114 00101$:
40115 \end_layout
40116
40117 \begin_layout Standard
40118
40119 \size footnotesize
40120 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40121 \end_layout
40122
40123 \begin_layout Standard
40124
40125 \size footnotesize
40126 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40127 \end_layout
40128
40129 \begin_layout Standard
40130
40131 \size footnotesize
40132 \InsetSpace ~
40133 \InsetSpace ~
40134 mov ar2,@r0
40135 \end_layout
40136
40137 \begin_layout Standard
40138
40139 \size footnotesize
40140 \InsetSpace ~
40141 \InsetSpace ~
40142 inc r0
40143 \end_layout
40144
40145 \begin_layout Standard
40146
40147 \size footnotesize
40148 \InsetSpace ~
40149 \InsetSpace ~
40150 mov ar3,@r0
40151 \end_layout
40152
40153 \begin_layout Standard
40154
40155 \size footnotesize
40156 \InsetSpace ~
40157 \InsetSpace ~
40158 dec r0
40159 \end_layout
40160
40161 \begin_layout Standard
40162
40163 \size footnotesize
40164 \InsetSpace ~
40165 \InsetSpace ~
40166 mov a,r2
40167 \end_layout
40168
40169 \begin_layout Standard
40170
40171 \size footnotesize
40172 \InsetSpace ~
40173 \InsetSpace ~
40174 orl a,r3
40175 \end_layout
40176
40177 \begin_layout Standard
40178
40179 \size footnotesize
40180 \InsetSpace ~
40181 \InsetSpace ~
40182 jz 00103$
40183 \end_layout
40184
40185 \begin_layout Standard
40186
40187 \size footnotesize
40188 00114$:
40189 \end_layout
40190
40191 \begin_layout Standard
40192
40193 \size footnotesize
40194 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40195 \end_layout
40196
40197 \begin_layout Standard
40198
40199 \size footnotesize
40200 \InsetSpace ~
40201 \InsetSpace ~
40202 mov dpl,_p
40203 \end_layout
40204
40205 \begin_layout Standard
40206
40207 \size footnotesize
40208 \InsetSpace ~
40209 \InsetSpace ~
40210 mov dph,(_p + 1)
40211 \end_layout
40212
40213 \begin_layout Standard
40214
40215 \size footnotesize
40216 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40217 \end_layout
40218
40219 \begin_layout Standard
40220
40221 \size footnotesize
40222 \InsetSpace ~
40223 \InsetSpace ~
40224 mov a,#0x02
40225 \end_layout
40226
40227 \begin_layout Standard
40228
40229 \size footnotesize
40230 \InsetSpace ~
40231 \InsetSpace ~
40232 add a,_p
40233 \end_layout
40234
40235 \begin_layout Standard
40236
40237 \size footnotesize
40238 \InsetSpace ~
40239 \InsetSpace ~
40240 mov _p,a
40241 \end_layout
40242
40243 \begin_layout Standard
40244
40245 \size footnotesize
40246 \InsetSpace ~
40247 \InsetSpace ~
40248 clr a
40249 \end_layout
40250
40251 \begin_layout Standard
40252
40253 \size footnotesize
40254 \InsetSpace ~
40255 \InsetSpace ~
40256 addc a,(_p + 1)
40257 \end_layout
40258
40259 \begin_layout Standard
40260
40261 \size footnotesize
40262 \InsetSpace ~
40263 \InsetSpace ~
40264 mov (_p + 1),a
40265 \end_layout
40266
40267 \begin_layout Standard
40268
40269 \size footnotesize
40270 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40271 \end_layout
40272
40273 \begin_layout Standard
40274
40275 \size footnotesize
40276 \InsetSpace ~
40277 \InsetSpace ~
40278 movx a,@dptr
40279 \end_layout
40280
40281 \begin_layout Standard
40282
40283 \size footnotesize
40284 \InsetSpace ~
40285 \InsetSpace ~
40286 mov r2,a
40287 \end_layout
40288
40289 \begin_layout Standard
40290
40291 \size footnotesize
40292 \InsetSpace ~
40293 \InsetSpace ~
40294 inc dptr
40295 \end_layout
40296
40297 \begin_layout Standard
40298
40299 \size footnotesize
40300 \InsetSpace ~
40301 \InsetSpace ~
40302 movx a,@dptr
40303 \end_layout
40304
40305 \begin_layout Standard
40306
40307 \size footnotesize
40308 \InsetSpace ~
40309 \InsetSpace ~
40310 mov r3,a
40311 \end_layout
40312
40313 \begin_layout Standard
40314
40315 \size footnotesize
40316 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40317 \end_layout
40318
40319 \begin_layout Standard
40320
40321 \size footnotesize
40322 \InsetSpace ~
40323 \InsetSpace ~
40324 mov @r0,ar2
40325 \end_layout
40326
40327 \begin_layout Standard
40328
40329 \size footnotesize
40330 \InsetSpace ~
40331 \InsetSpace ~
40332 inc r0
40333 \end_layout
40334
40335 \begin_layout Standard
40336
40337 \size footnotesize
40338 \InsetSpace ~
40339 \InsetSpace ~
40340 mov @r0,ar3
40341 \end_layout
40342
40343 \begin_layout Standard
40344
40345 \size footnotesize
40346 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40347 \end_layout
40348
40349 \begin_layout Standard
40350
40351 \size footnotesize
40352 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40353 \end_layout
40354
40355 \begin_layout Standard
40356
40357 \size footnotesize
40358 ; 0x2 {short}
40359 \end_layout
40360
40361 \begin_layout Standard
40362
40363 \size footnotesize
40364 \InsetSpace ~
40365 \InsetSpace ~
40366 inc r0
40367 \end_layout
40368
40369 \begin_layout Standard
40370
40371 \size footnotesize
40372 ; goto _whilecontinue_0($1)
40373 \end_layout
40374
40375 \begin_layout Standard
40376
40377 \size footnotesize
40378 \InsetSpace ~
40379 \InsetSpace ~
40380 sjmp 00101$
40381 \end_layout
40382
40383 \begin_layout Standard
40384
40385 \size footnotesize
40386 ; _whilebreak_0($3) :
40387 \end_layout
40388
40389 \begin_layout Standard
40390
40391 \size footnotesize
40392 00103$:
40393 \end_layout
40394
40395 \begin_layout Standard
40396
40397 \size footnotesize
40398 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40399 \end_layout
40400
40401 \begin_layout Standard
40402
40403 \size footnotesize
40404 \InsetSpace ~
40405 \InsetSpace ~
40406 mov r2,#0x00
40407 \end_layout
40408
40409 \begin_layout Standard
40410
40411 \size footnotesize
40412 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40413 \end_layout
40414
40415 \begin_layout Standard
40416
40417 \size footnotesize
40418 \InsetSpace ~
40419 \InsetSpace ~
40420 mov r3,#0x00
40421 \end_layout
40422
40423 \begin_layout Standard
40424
40425 \size footnotesize
40426 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40427 \end_layout
40428
40429 \begin_layout Standard
40430
40431 \size footnotesize
40432 \InsetSpace ~
40433 \InsetSpace ~
40434 mov r4,#0x00
40435 \end_layout
40436
40437 \begin_layout Standard
40438
40439 \size footnotesize
40440 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40441 \end_layout
40442
40443 \begin_layout Standard
40444
40445 \size footnotesize
40446 \InsetSpace ~
40447 \InsetSpace ~
40448 mov r5,#0x0A
40449 \end_layout
40450
40451 \begin_layout Standard
40452
40453 \size footnotesize
40454 \InsetSpace ~
40455 \InsetSpace ~
40456 mov r6,#0x00
40457 \end_layout
40458
40459 \begin_layout Standard
40460
40461 \size footnotesize
40462 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40463 \end_layout
40464
40465 \begin_layout Standard
40466
40467 \size footnotesize
40468 \InsetSpace ~
40469 \InsetSpace ~
40470 mov r7,#0x1E
40471 \end_layout
40472
40473 \begin_layout Standard
40474
40475 \size footnotesize
40476 \InsetSpace ~
40477 \InsetSpace ~
40478 mov r0,#0x00
40479 \end_layout
40480
40481 \begin_layout Standard
40482
40483 \size footnotesize
40484 ; _forcond_0($4) :
40485 \end_layout
40486
40487 \begin_layout Standard
40488
40489 \size footnotesize
40490 00104$:
40491 \end_layout
40492
40493 \begin_layout Standard
40494
40495 \size footnotesize
40496 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40497 \end_layout
40498
40499 \begin_layout Standard
40500
40501 \size footnotesize
40502 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40503 \end_layout
40504
40505 \begin_layout Standard
40506
40507 \size footnotesize
40508 \InsetSpace ~
40509 \InsetSpace ~
40510 clr c
40511 \end_layout
40512
40513 \begin_layout Standard
40514
40515 \size footnotesize
40516 \InsetSpace ~
40517 \InsetSpace ~
40518 mov a,r4
40519 \end_layout
40520
40521 \begin_layout Standard
40522
40523 \size footnotesize
40524 \InsetSpace ~
40525 \InsetSpace ~
40526 xrl a,#0x80
40527 \end_layout
40528
40529 \begin_layout Standard
40530
40531 \size footnotesize
40532 \InsetSpace ~
40533 \InsetSpace ~
40534 subb a,#0x8a
40535 \end_layout
40536
40537 \begin_layout Standard
40538
40539 \size footnotesize
40540 \InsetSpace ~
40541 \InsetSpace ~
40542 jnc 00107$
40543 \end_layout
40544
40545 \begin_layout Standard
40546
40547 \size footnotesize
40548 00115$:
40549 \end_layout
40550
40551 \begin_layout Standard
40552
40553 \size footnotesize
40554 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40555 \end_layout
40556
40557 \begin_layout Standard
40558
40559 \size footnotesize
40560 ; iTemp21 [lr21:38]{short}[r4]
40561 \end_layout
40562
40563 \begin_layout Standard
40564
40565 \size footnotesize
40566 \InsetSpace ~
40567 \InsetSpace ~
40568 mov a,r4
40569 \end_layout
40570
40571 \begin_layout Standard
40572
40573 \size footnotesize
40574 \InsetSpace ~
40575 \InsetSpace ~
40576 add a,r2
40577 \end_layout
40578
40579 \begin_layout Standard
40580
40581 \size footnotesize
40582 \InsetSpace ~
40583 \InsetSpace ~
40584 mov r2,a
40585 \end_layout
40586
40587 \begin_layout Standard
40588
40589 \size footnotesize
40590 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40591 \end_layout
40592
40593 \begin_layout Standard
40594
40595 \size footnotesize
40596 \InsetSpace ~
40597 \InsetSpace ~
40598 mov b,#0x03
40599 \end_layout
40600
40601 \begin_layout Standard
40602
40603 \size footnotesize
40604 \InsetSpace ~
40605 \InsetSpace ~
40606 mov a,r4
40607 \end_layout
40608
40609 \begin_layout Standard
40610
40611 \size footnotesize
40612 \InsetSpace ~
40613 \InsetSpace ~
40614 mul ab
40615 \end_layout
40616
40617 \begin_layout Standard
40618
40619 \size footnotesize
40620 \InsetSpace ~
40621 \InsetSpace ~
40622 mov r1,a
40623 \end_layout
40624
40625 \begin_layout Standard
40626
40627 \size footnotesize
40628 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40629 \end_layout
40630
40631 \begin_layout Standard
40632
40633 \size footnotesize
40634 ; iTemp15 [lr29:30]{short}[r1]
40635 \end_layout
40636
40637 \begin_layout Standard
40638
40639 \size footnotesize
40640 \InsetSpace ~
40641 \InsetSpace ~
40642 add a,r3
40643 \end_layout
40644
40645 \begin_layout Standard
40646
40647 \size footnotesize
40648 \InsetSpace ~
40649 \InsetSpace ~
40650 mov r3,a
40651 \end_layout
40652
40653 \begin_layout Standard
40654
40655 \size footnotesize
40656 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40657 \end_layout
40658
40659 \begin_layout Standard
40660
40661 \size footnotesize
40662 \InsetSpace ~
40663 \InsetSpace ~
40664 mov a,r7
40665 \end_layout
40666
40667 \begin_layout Standard
40668
40669 \size footnotesize
40670 \InsetSpace ~
40671 \InsetSpace ~
40672 add a,#0xfd
40673 \end_layout
40674
40675 \begin_layout Standard
40676
40677 \size footnotesize
40678 \InsetSpace ~
40679 \InsetSpace ~
40680 mov r7,a
40681 \end_layout
40682
40683 \begin_layout Standard
40684
40685 \size footnotesize
40686 \InsetSpace ~
40687 \InsetSpace ~
40688 mov a,r0
40689 \end_layout
40690
40691 \begin_layout Standard
40692
40693 \size footnotesize
40694 \InsetSpace ~
40695 \InsetSpace ~
40696 addc a,#0xff
40697 \end_layout
40698
40699 \begin_layout Standard
40700
40701 \size footnotesize
40702 \InsetSpace ~
40703 \InsetSpace ~
40704 mov r0,a
40705 \end_layout
40706
40707 \begin_layout Standard
40708
40709 \size footnotesize
40710 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40711 \end_layout
40712
40713 \begin_layout Standard
40714
40715 \size footnotesize
40716 \InsetSpace ~
40717 \InsetSpace ~
40718 mov a,r7
40719 \end_layout
40720
40721 \begin_layout Standard
40722
40723 \size footnotesize
40724 \InsetSpace ~
40725 \InsetSpace ~
40726 add a,_gint
40727 \end_layout
40728
40729 \begin_layout Standard
40730
40731 \size footnotesize
40732 \InsetSpace ~
40733 \InsetSpace ~
40734 mov _gint,a
40735 \end_layout
40736
40737 \begin_layout Standard
40738
40739 \size footnotesize
40740 \InsetSpace ~
40741 \InsetSpace ~
40742 mov a,r0
40743 \end_layout
40744
40745 \begin_layout Standard
40746
40747 \size footnotesize
40748 \InsetSpace ~
40749 \InsetSpace ~
40750 addc a,(_gint + 1)
40751 \end_layout
40752
40753 \begin_layout Standard
40754
40755 \size footnotesize
40756 \InsetSpace ~
40757 \InsetSpace ~
40758 mov (_gint + 1),a
40759 \end_layout
40760
40761 \begin_layout Standard
40762
40763 \size footnotesize
40764 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40765 \end_layout
40766
40767 \begin_layout Standard
40768
40769 \size footnotesize
40770 \InsetSpace ~
40771 \InsetSpace ~
40772 inc r4
40773 \end_layout
40774
40775 \begin_layout Standard
40776
40777 \size footnotesize
40778 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40779 \end_layout
40780
40781 \begin_layout Standard
40782
40783 \size footnotesize
40784 \InsetSpace ~
40785 \InsetSpace ~
40786 dec r5
40787 \end_layout
40788
40789 \begin_layout Standard
40790
40791 \size footnotesize
40792 \InsetSpace ~
40793 \InsetSpace ~
40794 cjne r5,#0xff,00104$
40795 \end_layout
40796
40797 \begin_layout Standard
40798
40799 \size footnotesize
40800 \InsetSpace ~
40801 \InsetSpace ~
40802 dec r6
40803 \end_layout
40804
40805 \begin_layout Standard
40806
40807 \size footnotesize
40808 ; goto _forcond_0($4)
40809 \end_layout
40810
40811 \begin_layout Standard
40812
40813 \size footnotesize
40814 \InsetSpace ~
40815 \InsetSpace ~
40816 sjmp 00104$
40817 \end_layout
40818
40819 \begin_layout Standard
40820
40821 \size footnotesize
40822 ; _forbreak_0($7) :
40823 \end_layout
40824
40825 \begin_layout Standard
40826
40827 \size footnotesize
40828 00107$:
40829 \end_layout
40830
40831 \begin_layout Standard
40832
40833 \size footnotesize
40834 ; ret iTemp24 [lr40:41]{short}
40835 \end_layout
40836
40837 \begin_layout Standard
40838
40839 \size footnotesize
40840 \InsetSpace ~
40841 \InsetSpace ~
40842 mov a,r3
40843 \end_layout
40844
40845 \begin_layout Standard
40846
40847 \size footnotesize
40848 \InsetSpace ~
40849 \InsetSpace ~
40850 add a,r2
40851 \end_layout
40852
40853 \begin_layout Standard
40854
40855 \size footnotesize
40856 \InsetSpace ~
40857 \InsetSpace ~
40858 mov dpl,a
40859 \end_layout
40860
40861 \begin_layout Standard
40862
40863 \size footnotesize
40864 ; _return($8) :
40865 \end_layout
40866
40867 \begin_layout Standard
40868
40869 \size footnotesize
40870 00108$:
40871 \end_layout
40872
40873 \begin_layout Standard
40874
40875 \size footnotesize
40876 \InsetSpace ~
40877 \InsetSpace ~
40878 ret
40879 \newline
40880
40881 \end_layout
40882
40883 \begin_layout Section
40884 A few words about basic block successors, predecessors and dominators
40885 \end_layout
40886
40887 \begin_layout Standard
40888 Successors are basic blocks
40889 \begin_inset LatexCommand \index{Basic blocks}
40890
40891 \end_inset
40892
40893  that might execute after this basic block.
40894 \newline
40895 Predecessors are basic blocks
40896  that might execute before reaching this basic block.
40897 \newline
40898 Dominators are basic
40899  blocks that WILL execute before reaching this basic block.
40900 \newline
40901
40902 \end_layout
40903
40904 \begin_layout Standard
40905 [basic block 1]
40906 \end_layout
40907
40908 \begin_layout Standard
40909 if (something)
40910 \end_layout
40911
40912 \begin_layout Standard
40913 \InsetSpace ~
40914 \InsetSpace ~
40915 \InsetSpace ~
40916 \InsetSpace ~
40917 [basic block 2]
40918 \end_layout
40919
40920 \begin_layout Standard
40921 else
40922 \end_layout
40923
40924 \begin_layout Standard
40925 \InsetSpace ~
40926 \InsetSpace ~
40927 \InsetSpace ~
40928 \InsetSpace ~
40929 [basic block 3]
40930 \end_layout
40931
40932 \begin_layout Standard
40933 [basic block 4]
40934 \newline
40935
40936 \end_layout
40937
40938 \begin_layout Standard
40939 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40940 \end_layout
40941
40942 \begin_layout Standard
40943 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40944 \end_layout
40945
40946 \begin_layout Standard
40947 c) domVect of [BB4] = BB1 ...
40948  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40949  was executed.
40950 \end_layout
40951
40952 \begin_layout Chapter
40953 Acknowledgments
40954 \end_layout
40955
40956 \begin_layout Standard
40957 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40958
40959 \end_inset
40960
40961
40962 \newline
40963
40964 \newline
40965
40966 \emph on
40967 Thanks to all the other volunteer developers who have helped with coding,
40968  testing, web-page creation, distribution sets, etc.
40969  You know who you are :-)
40970 \emph default
40971
40972 \newline
40973
40974 \newline
40975
40976 \emph on
40977 Thanks to Sourceforge 
40978 \begin_inset LatexCommand \url{http://www.sf.net}
40979
40980 \end_inset
40981
40982  which has hosted the project since 1999 and donates significant download
40983  bandwidth.
40984 \emph default
40985
40986 \newline
40987
40988 \newline
40989
40990 \emph on
40991 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40992  cycles and bandwidth for snapshot builds.
40993 \newline
40994
40995 \end_layout
40996
40997 \begin_layout Standard
40998 This document was initially written by Sandeep Dutta
40999 \end_layout
41000
41001 \begin_layout Standard
41002 All product names mentioned herein may be trademarks
41003 \begin_inset LatexCommand \index{Trademarks}
41004
41005 \end_inset
41006
41007  of their respective companies.
41008  
41009 \end_layout
41010
41011 \begin_layout Section*
41012 Alphabetical index
41013 \end_layout
41014
41015 \begin_layout Standard
41016 To avoid confusion, the installation and building options for SDCC itself
41017  (chapter 2) are not part of the index.
41018 \end_layout
41019
41020 \begin_layout Standard
41021 \begin_inset LatexCommand \printindex{}
41022
41023 \end_inset
41024
41025
41026 \end_layout
41027
41028 \end_body
41029 \end_document