* doc/sdccman.lyx: updated the sections on the library build process
[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.4
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 Itemize
1162 in older versions, the preprocessor was always called with -std=c99 regardless
1163  of the --std-xxx setting.
1164  This is no longer true, and can cause compilation failures on code built
1165  with --std-c89 but using c99 preprocessor features, such as one-line (//)
1166  comments
1167 \end_layout
1168
1169 \begin_layout Itemize
1170 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1171  functions supported undocumented and not standard compliant 'b' binary
1172  format specifier ("%b", "%hb" and "%lb").
1173  The 'b' specifier is now disabled by default.
1174  It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1175 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1176 g the library.
1177 \end_layout
1178
1179 \begin_layout Section
1180 System Requirements
1181 \end_layout
1182
1183 \begin_layout Standard
1184 What do you need before you start installation of SDCC? A computer, and
1185  a desire to compute.
1186  The preferred method of installation is to compile SDCC from source using
1187  GNU gcc and make.
1188  For Windows some pre-compiled binary distributions are available for your
1189  convenience.
1190  You should have some experience with command line tools and compiler use.
1191 \end_layout
1192
1193 \begin_layout Section
1194 Other Resources
1195 \end_layout
1196
1197 \begin_layout Standard
1198 The SDCC home page at 
1199 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1200
1201 \end_inset
1202
1203  is a great place to find distribution sets.
1204  You can also find links to the user mailing lists that offer help or discuss
1205  SDCC with other SDCC users.
1206  Web links to other SDCC related sites can also be found here.
1207  This document can be found in the DOC directory of the source package as
1208  a text or HTML file.
1209  A pdf version of this document is available at 
1210 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1211
1212 \end_inset
1213
1214 .
1215  Some of the other tools (simulator and assembler) included with SDCC contain
1216  their own documentation and can be found in the source distribution.
1217  If you want the latest unreleased software, the complete source package
1218  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1219 sdcc/trunk/sdcc.
1220 \end_layout
1221
1222 \begin_layout Section
1223 Wishes for the future
1224 \end_layout
1225
1226 \begin_layout Standard
1227 There are (and always will be) some things that could be done.
1228  Here are some I can think of:
1229 \newline
1230
1231 \end_layout
1232
1233 \begin_layout Standard
1234
1235 \family typewriter
1236 char KernelFunction3(char p) at 0x340;
1237 \newline
1238
1239 \end_layout
1240
1241 \begin_layout Standard
1242
1243 \family typewriter
1244 better code banking
1245 \begin_inset LatexCommand \index{code banking (limited support)}
1246
1247 \end_inset
1248
1249  support for mcs51
1250 \newline
1251
1252 \newline
1253
1254 \family default
1255 If you can think of some more, please see the section 
1256 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1257
1258 \end_inset
1259
1260  about filing feature requests
1261 \begin_inset LatexCommand \index{Requesting features}
1262
1263 \end_inset
1264
1265
1266 \begin_inset LatexCommand \index{Feature request}
1267
1268 \end_inset
1269
1270 .
1271 \newline
1272
1273 \end_layout
1274
1275 \begin_layout Chapter
1276 Installing SDCC
1277 \begin_inset LatexCommand \index{Installation}
1278
1279 \end_inset
1280
1281
1282 \end_layout
1283
1284 \begin_layout Standard
1285 For most users it is sufficient to skip to either section 
1286 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1287
1288 \end_inset
1289
1290  (Unix) or section 
1291 \begin_inset LatexCommand \ref{sub:Windows-Install}
1292
1293 \end_inset
1294
1295  (Windows).
1296  More detailed instructions follow below.
1297 \end_layout
1298
1299 \begin_layout Section
1300 Configure Options
1301 \begin_inset LatexCommand \index{Options SDCC configuration}
1302
1303 \end_inset
1304
1305
1306 \end_layout
1307
1308 \begin_layout Standard
1309 The install paths, search paths and other options are defined when running
1310  'configure'.
1311  The defaults can be overridden by:
1312 \end_layout
1313
1314 \begin_layout List
1315 \labelwidthstring 00.00.0000
1316 -
1317 \begin_inset ERT
1318 status collapsed
1319
1320 \begin_layout Standard
1321
1322
1323 \backslash
1324 /
1325 \end_layout
1326
1327 \end_inset
1328
1329 -prefix see table below
1330 \end_layout
1331
1332 \begin_layout List
1333 \labelwidthstring 00.00.0000
1334 -
1335 \begin_inset ERT
1336 status collapsed
1337
1338 \begin_layout Standard
1339
1340
1341 \backslash
1342 /
1343 \end_layout
1344
1345 \end_inset
1346
1347 -exec_prefix see table below
1348 \end_layout
1349
1350 \begin_layout List
1351 \labelwidthstring 00.00.0000
1352 -
1353 \begin_inset ERT
1354 status collapsed
1355
1356 \begin_layout Standard
1357
1358
1359 \backslash
1360 /
1361 \end_layout
1362
1363 \end_inset
1364
1365 -bindir see table below
1366 \end_layout
1367
1368 \begin_layout List
1369 \labelwidthstring 00.00.0000
1370 -
1371 \begin_inset ERT
1372 status collapsed
1373
1374 \begin_layout Standard
1375
1376
1377 \backslash
1378 /
1379 \end_layout
1380
1381 \end_inset
1382
1383 -datadir see table below
1384 \end_layout
1385
1386 \begin_layout List
1387 \labelwidthstring 00.00.0000
1388 -
1389 \begin_inset ERT
1390 status collapsed
1391
1392 \begin_layout Standard
1393
1394
1395 \backslash
1396 /
1397 \end_layout
1398
1399 \end_inset
1400
1401 -datarootdir see table below
1402 \newline
1403
1404 \end_layout
1405
1406 \begin_layout List
1407 \labelwidthstring 00.00.0000
1408 \InsetSpace ~
1409 \InsetSpace ~
1410 docdir environment variable, see table below
1411 \end_layout
1412
1413 \begin_layout List
1414 \labelwidthstring 00.00.0000
1415 \InsetSpace ~
1416 \InsetSpace ~
1417 include_dir_suffix environment variable, see table below
1418 \end_layout
1419
1420 \begin_layout List
1421 \labelwidthstring 00.00.0000
1422 \InsetSpace ~
1423 \InsetSpace ~
1424 lib_dir_suffix environment variable, see table below
1425 \end_layout
1426
1427 \begin_layout List
1428 \labelwidthstring 00.00.0000
1429 \InsetSpace ~
1430 \InsetSpace ~
1431 sdccconf_h_dir_separator environment variable, either / or 
1432 \backslash
1433
1434 \backslash
1435  makes sense here.
1436  This character will only be used in sdccconf.h; don't forget it's a C-header,
1437  therefore a double-backslash is needed there.
1438 \newline
1439
1440 \end_layout
1441
1442 \begin_layout List
1443 \labelwidthstring 00.00.0000
1444 -
1445 \begin_inset ERT
1446 status collapsed
1447
1448 \begin_layout Standard
1449
1450
1451 \backslash
1452 /
1453 \end_layout
1454
1455 \end_inset
1456
1457 -disable-mcs51-port Excludes the Intel mcs51 port
1458 \end_layout
1459
1460 \begin_layout List
1461 \labelwidthstring 00.00.0000
1462 -
1463 \begin_inset ERT
1464 status collapsed
1465
1466 \begin_layout Standard
1467
1468
1469 \backslash
1470 /
1471 \end_layout
1472
1473 \end_inset
1474
1475 -disable-gbz80-port Excludes the Gameboy gbz80 port
1476 \end_layout
1477
1478 \begin_layout List
1479 \labelwidthstring 00.00.0000
1480 -
1481 \begin_inset ERT
1482 status collapsed
1483
1484 \begin_layout Standard
1485
1486
1487 \backslash
1488 /
1489 \end_layout
1490
1491 \end_inset
1492
1493 -disable-z80-port Excludes the z80 port
1494 \end_layout
1495
1496 \begin_layout List
1497 \labelwidthstring 00.00.0000
1498 -
1499 \begin_inset ERT
1500 status collapsed
1501
1502 \begin_layout Standard
1503
1504
1505 \backslash
1506 /
1507 \end_layout
1508
1509 \end_inset
1510
1511 -disable-avr-port Excludes the AVR port
1512 \end_layout
1513
1514 \begin_layout List
1515 \labelwidthstring 00.00.0000
1516 -
1517 \begin_inset ERT
1518 status collapsed
1519
1520 \begin_layout Standard
1521
1522
1523 \backslash
1524 /
1525 \end_layout
1526
1527 \end_inset
1528
1529 -disable-ds390-port Excludes the DS390 port
1530 \end_layout
1531
1532 \begin_layout List
1533 \labelwidthstring 00.00.0000
1534 -
1535 \begin_inset ERT
1536 status collapsed
1537
1538 \begin_layout Standard
1539
1540
1541 \backslash
1542 /
1543 \end_layout
1544
1545 \end_inset
1546
1547 -disable-hc08-port Excludes the HC08 port
1548 \end_layout
1549
1550 \begin_layout List
1551 \labelwidthstring 00.00.0000
1552 -
1553 \begin_inset ERT
1554 status collapsed
1555
1556 \begin_layout Standard
1557
1558
1559 \backslash
1560 /
1561 \end_layout
1562
1563 \end_inset
1564
1565 -disable-pic-port Excludes the PIC14 port
1566 \end_layout
1567
1568 \begin_layout List
1569 \labelwidthstring 00.00.0000
1570 -
1571 \begin_inset ERT
1572 status collapsed
1573
1574 \begin_layout Standard
1575
1576
1577 \backslash
1578 /
1579 \end_layout
1580
1581 \end_inset
1582
1583 -disable-pic16-port Excludes the PIC16 port
1584 \end_layout
1585
1586 \begin_layout List
1587 \labelwidthstring 00.00.0000
1588 -
1589 \begin_inset ERT
1590 status collapsed
1591
1592 \begin_layout Standard
1593
1594
1595 \backslash
1596 /
1597 \end_layout
1598
1599 \end_inset
1600
1601 -disable-xa51-port Excludes the XA51 port
1602 \end_layout
1603
1604 \begin_layout List
1605 \labelwidthstring 00.00.0000
1606 -
1607 \begin_inset ERT
1608 status collapsed
1609
1610 \begin_layout Standard
1611
1612
1613 \backslash
1614 /
1615 \end_layout
1616
1617 \end_inset
1618
1619 -disable-ucsim Disables configuring and building of ucsim
1620 \end_layout
1621
1622 \begin_layout List
1623 \labelwidthstring 00.00.0000
1624 -
1625 \begin_inset ERT
1626 status collapsed
1627
1628 \begin_layout Standard
1629
1630
1631 \backslash
1632 /
1633 \end_layout
1634
1635 \end_inset
1636
1637 -disable-device-lib Disables automatically building device libraries
1638 \end_layout
1639
1640 \begin_layout List
1641 \labelwidthstring 00.00.0000
1642 -
1643 \begin_inset ERT
1644 status collapsed
1645
1646 \begin_layout Standard
1647
1648
1649 \backslash
1650 /
1651 \end_layout
1652
1653 \end_inset
1654
1655 -disable-packihx Disables building packihx
1656 \newline
1657
1658 \end_layout
1659
1660 \begin_layout List
1661 \labelwidthstring 00.00.0000
1662 -
1663 \begin_inset ERT
1664 status collapsed
1665
1666 \begin_layout Standard
1667
1668
1669 \backslash
1670 /
1671 \end_layout
1672
1673 \end_inset
1674
1675 -enable-doc Build pdf, html and txt files from the lyx sources
1676 \end_layout
1677
1678 \begin_layout List
1679 \labelwidthstring 00.00.0000
1680 -
1681 \begin_inset ERT
1682 status collapsed
1683
1684 \begin_layout Standard
1685
1686
1687 \backslash
1688 /
1689 \end_layout
1690
1691 \end_inset
1692
1693 -enable-libgc Use the Bohem memory allocator.
1694  Lower runtime footprint.
1695 \end_layout
1696
1697 \begin_layout List
1698 \labelwidthstring 00.00.0000
1699 -
1700 \begin_inset ERT
1701 status collapsed
1702
1703 \begin_layout Standard
1704
1705
1706 \backslash
1707 /
1708 \end_layout
1709
1710 \end_inset
1711
1712 -without-ccache Do not use ccache even if available
1713 \end_layout
1714
1715 \begin_layout Standard
1716 Furthermore the environment variables CC, CFLAGS, ...
1717  the tools and their arguments can be influenced.
1718  Please see `configure -
1719 \begin_inset ERT
1720 status collapsed
1721
1722 \begin_layout Standard
1723
1724
1725 \backslash
1726 /
1727 \end_layout
1728
1729 \end_inset
1730
1731 -help' and the man/info pages of `configure' for details.
1732 \newline
1733
1734 \newline
1735 The names of the
1736  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1737 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1738  SDCC_LIB_NAME are defined by `configure' too.
1739  At the moment it's not possible to change the default settings (it was
1740  simply never required).
1741 \newline
1742
1743 \newline
1744 These configure options are compiled into the binaries,
1745  and can only be changed by rerunning 'configure' and recompiling SDCC.
1746  The configure options are written in 
1747 \emph on
1748 italics
1749 \emph default
1750  to distinguish them from run time environment variables (see section search
1751  paths).
1752 \newline
1753
1754 \newline
1755 The settings for 
1756 \begin_inset Quotes sld
1757 \end_inset
1758
1759 Win32 builds
1760 \begin_inset Quotes srd
1761 \end_inset
1762
1763  are used by the SDCC team to build the official Win32 binaries.
1764  The SDCC team uses Mingw32 to build the official Windows binaries, because
1765  it's
1766 \end_layout
1767
1768 \begin_layout Enumerate
1769 open source, 
1770 \end_layout
1771
1772 \begin_layout Enumerate
1773 a gcc compiler and last but not least
1774 \end_layout
1775
1776 \begin_layout Enumerate
1777 the binaries can be built by cross compiling on SDCC Distributed Compile
1778  Farm.
1779 \end_layout
1780
1781 \begin_layout Standard
1782 See the examples, how to pass the Win32 settings to 'configure'.
1783  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1784  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1785  for Win32.
1786 \newline
1787
1788 \newline
1789 These defaults are:
1790 \newline
1791
1792 \end_layout
1793
1794 \begin_layout Standard
1795 \align center
1796 \begin_inset Tabular
1797 <lyxtabular version="3" rows="9" columns="3">
1798 <features>
1799 <column alignment="block" valignment="top" leftline="true" width="0in">
1800 <column alignment="block" valignment="top" leftline="true" width="0in">
1801 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1802 <row topline="true" bottomline="true">
1803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1804 \begin_inset Text
1805
1806 \begin_layout Standard
1807 Variable
1808 \end_layout
1809
1810 \end_inset
1811 </cell>
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1813 \begin_inset Text
1814
1815 \begin_layout Standard
1816 default
1817 \end_layout
1818
1819 \end_inset
1820 </cell>
1821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1822 \begin_inset Text
1823
1824 \begin_layout Standard
1825 Win32 builds
1826 \end_layout
1827
1828 \end_inset
1829 </cell>
1830 </row>
1831 <row topline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_inset Text
1834
1835 \begin_layout Standard
1836
1837 \emph on
1838 PREFIX
1839 \end_layout
1840
1841 \end_inset
1842 </cell>
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \begin_layout Standard
1847 /usr/local
1848 \end_layout
1849
1850 \end_inset
1851 </cell>
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1853 \begin_inset Text
1854
1855 \begin_layout Standard
1856
1857 \backslash
1858 sdcc
1859 \end_layout
1860
1861 \end_inset
1862 </cell>
1863 </row>
1864 <row topline="true">
1865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1866 \begin_inset Text
1867
1868 \begin_layout Standard
1869
1870 \emph on
1871 EXEC_PREFIX
1872 \end_layout
1873
1874 \end_inset
1875 </cell>
1876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1877 \begin_inset Text
1878
1879 \begin_layout Standard
1880
1881 \emph on
1882 $PREFIX
1883 \end_layout
1884
1885 \end_inset
1886 </cell>
1887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1888 \begin_inset Text
1889
1890 \begin_layout Standard
1891
1892 \emph on
1893 $PREFIX
1894 \end_layout
1895
1896 \end_inset
1897 </cell>
1898 </row>
1899 <row topline="true">
1900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1901 \begin_inset Text
1902
1903 \begin_layout Standard
1904
1905 \emph on
1906 BINDIR
1907 \end_layout
1908
1909 \end_inset
1910 </cell>
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 $EXEC_PREFIX
1918 \emph default
1919 /bin
1920 \end_layout
1921
1922 \end_inset
1923 </cell>
1924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1925 \begin_inset Text
1926
1927 \begin_layout Standard
1928
1929 \emph on
1930 $EXEC_PREFIX
1931 \emph default
1932
1933 \backslash
1934 bin
1935 \end_layout
1936
1937 \end_inset
1938 </cell>
1939 </row>
1940 <row topline="true">
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1942 \begin_inset Text
1943
1944 \begin_layout Standard
1945
1946 \emph on
1947 DATADIR
1948 \end_layout
1949
1950 \end_inset
1951 </cell>
1952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1953 \begin_inset Text
1954
1955 \begin_layout Standard
1956
1957 \emph on
1958 $DATAROOTDIR
1959 \end_layout
1960
1961 \end_inset
1962 </cell>
1963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1964 \begin_inset Text
1965
1966 \begin_layout Standard
1967
1968 \emph on
1969 $DATAROOTDIR
1970 \end_layout
1971
1972 \end_inset
1973 </cell>
1974 </row>
1975 <row topline="true">
1976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1977 \begin_inset Text
1978
1979 \begin_layout Standard
1980
1981 \emph on
1982 DATAROOTDIR
1983 \end_layout
1984
1985 \end_inset
1986 </cell>
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1988 \begin_inset Text
1989
1990 \begin_layout Standard
1991
1992 \emph on
1993 $PREFIX
1994 \emph default
1995 /share
1996 \end_layout
1997
1998 \end_inset
1999 </cell>
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2001 \begin_inset Text
2002
2003 \begin_layout Standard
2004
2005 \emph on
2006 $PREFIX
2007 \end_layout
2008
2009 \end_inset
2010 </cell>
2011 </row>
2012 <row topline="true">
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2014 \begin_inset Text
2015
2016 \begin_layout Standard
2017
2018 \emph on
2019 DOCDIR
2020 \end_layout
2021
2022 \end_inset
2023 </cell>
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 $DATAROOTDIR
2031 \emph default
2032 /sdcc/doc
2033 \end_layout
2034
2035 \end_inset
2036 </cell>
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2038 \begin_inset Text
2039
2040 \begin_layout Standard
2041
2042 \emph on
2043 $DATAROOTDIR
2044 \emph default
2045
2046 \backslash
2047 doc
2048 \end_layout
2049
2050 \end_inset
2051 </cell>
2052 </row>
2053 <row topline="true">
2054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2055 \begin_inset Text
2056
2057 \begin_layout Standard
2058
2059 \emph on
2060 INCLUDE_DIR_SUFFIX
2061 \end_layout
2062
2063 \end_inset
2064 </cell>
2065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2066 \begin_inset Text
2067
2068 \begin_layout Standard
2069 sdcc/include
2070 \end_layout
2071
2072 \end_inset
2073 </cell>
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2075 \begin_inset Text
2076
2077 \begin_layout Standard
2078 include
2079 \end_layout
2080
2081 \end_inset
2082 </cell>
2083 </row>
2084 <row topline="true" bottomline="true">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2086 \begin_inset Text
2087
2088 \begin_layout Standard
2089
2090 \emph on
2091 LIB_DIR_SUFFIX
2092 \end_layout
2093
2094 \end_inset
2095 </cell>
2096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2097 \begin_inset Text
2098
2099 \begin_layout Standard
2100 sdcc/lib
2101 \end_layout
2102
2103 \end_inset
2104 </cell>
2105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2106 \begin_inset Text
2107
2108 \begin_layout Standard
2109 lib
2110 \end_layout
2111
2112 \end_inset
2113 </cell>
2114 </row>
2115 </lyxtabular>
2116
2117 \end_inset
2118
2119
2120 \newline
2121
2122 \end_layout
2123
2124 \begin_layout Standard
2125 \noindent
2126 'configure' also computes relative paths.
2127  This is needed for full relocatability of a binary package and to complete
2128  search paths (see section search paths below):
2129 \newline
2130  
2131 \end_layout
2132
2133 \begin_layout Standard
2134 \align center
2135 \begin_inset Tabular
2136 <lyxtabular version="3" rows="4" columns="3">
2137 <features>
2138 <column alignment="block" valignment="top" leftline="true" width="0in">
2139 <column alignment="block" valignment="top" leftline="true" width="0in">
2140 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2141 <row topline="true" bottomline="true">
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2143 \begin_inset Text
2144
2145 \begin_layout Standard
2146 Variable (computed)
2147 \end_layout
2148
2149 \end_inset
2150 </cell>
2151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2152 \begin_inset Text
2153
2154 \begin_layout Standard
2155 default
2156 \end_layout
2157
2158 \end_inset
2159 </cell>
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2161 \begin_inset Text
2162
2163 \begin_layout Standard
2164 Win32 builds
2165 \end_layout
2166
2167 \end_inset
2168 </cell>
2169 </row>
2170 <row topline="true" bottomline="true">
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2172 \begin_inset Text
2173
2174 \begin_layout Standard
2175
2176 \emph on
2177 BIN2DATA_DIR
2178 \end_layout
2179
2180 \end_inset
2181 </cell>
2182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2183 \begin_inset Text
2184
2185 \begin_layout Standard
2186 ../share
2187 \end_layout
2188
2189 \end_inset
2190 </cell>
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2192 \begin_inset Text
2193
2194 \begin_layout Standard
2195 ..
2196 \end_layout
2197
2198 \end_inset
2199 </cell>
2200 </row>
2201 <row bottomline="true">
2202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2203 \begin_inset Text
2204
2205 \begin_layout Standard
2206
2207 \emph on
2208 PREFIX2BIN_DIR
2209 \end_layout
2210
2211 \end_inset
2212 </cell>
2213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2214 \begin_inset Text
2215
2216 \begin_layout Standard
2217 bin
2218 \end_layout
2219
2220 \end_inset
2221 </cell>
2222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2223 \begin_inset Text
2224
2225 \begin_layout Standard
2226 bin
2227 \end_layout
2228
2229 \end_inset
2230 </cell>
2231 </row>
2232 <row bottomline="true">
2233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2234 \begin_inset Text
2235
2236 \begin_layout Standard
2237
2238 \emph on
2239 PREFIX2DATA_DIR
2240 \end_layout
2241
2242 \end_inset
2243 </cell>
2244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2245 \begin_inset Text
2246
2247 \begin_layout Standard
2248 share/sdcc
2249 \end_layout
2250
2251 \end_inset
2252 </cell>
2253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2254 \begin_inset Text
2255
2256 \begin_layout Standard
2257
2258 \end_layout
2259
2260 \end_inset
2261 </cell>
2262 </row>
2263 </lyxtabular>
2264
2265 \end_inset
2266
2267
2268 \newline
2269
2270 \end_layout
2271
2272 \begin_layout Standard
2273 \noindent
2274 Examples:
2275 \end_layout
2276
2277 \begin_layout LyX-Code
2278 ./configure
2279 \newline
2280 ./configure -
2281 \begin_inset ERT
2282 status collapsed
2283
2284 \begin_layout Standard
2285
2286
2287 \backslash
2288 /
2289 \end_layout
2290
2291 \end_inset
2292
2293 -prefix=
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297 /usr/bin
2298 \begin_inset Quotes srd
2299 \end_inset
2300
2301  -
2302 \begin_inset ERT
2303 status collapsed
2304
2305 \begin_layout Standard
2306
2307
2308 \backslash
2309 /
2310 \end_layout
2311
2312 \end_inset
2313
2314 -datarootdir=
2315 \begin_inset Quotes srd
2316 \end_inset
2317
2318 /usr/share
2319 \begin_inset Quotes srd
2320 \end_inset
2321
2322
2323 \newline
2324 ./configure -
2325 \begin_inset ERT
2326 status collapsed
2327
2328 \begin_layout Standard
2329
2330
2331 \backslash
2332 /
2333 \end_layout
2334
2335 \end_inset
2336
2337 -disable-avr-port -
2338 \begin_inset ERT
2339 status collapsed
2340
2341 \begin_layout Standard
2342
2343
2344 \backslash
2345 /
2346 \end_layout
2347
2348 \end_inset
2349
2350 -disable-xa51-port
2351 \end_layout
2352
2353 \begin_layout Standard
2354 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2355 32'):
2356 \end_layout
2357
2358 \begin_layout LyX-Code
2359 ./configure 
2360 \backslash
2361
2362 \newline
2363 CC=
2364 \begin_inset Quotes srd
2365 \end_inset
2366
2367 i586-mingw32msvc-gcc
2368 \begin_inset Quotes srd
2369 \end_inset
2370
2371  CXX=
2372 \begin_inset Quotes srd
2373 \end_inset
2374
2375 i586-mingw32msvc-g++
2376 \begin_inset Quotes srd
2377 \end_inset
2378
2379  
2380 \backslash
2381  
2382 \newline
2383 RANLIB=
2384 \begin_inset Quotes srd
2385 \end_inset
2386
2387 i586-mingw32msvc-ranlib
2388 \begin_inset Quotes srd
2389 \end_inset
2390
2391  
2392 \backslash
2393
2394 \newline
2395 STRIP=
2396 \begin_inset Quotes srd
2397 \end_inset
2398
2399 i586-mingw32msvc-strip
2400 \begin_inset Quotes srd
2401 \end_inset
2402
2403  
2404 \backslash
2405
2406 \newline
2407 -
2408 \begin_inset ERT
2409 status collapsed
2410
2411 \begin_layout Standard
2412
2413
2414 \backslash
2415 /
2416 \end_layout
2417
2418 \end_inset
2419
2420 -prefix=
2421 \begin_inset Quotes srd
2422 \end_inset
2423
2424 /sdcc
2425 \begin_inset Quotes srd
2426 \end_inset
2427
2428  
2429 \backslash
2430
2431 \newline
2432 -
2433 \begin_inset ERT
2434 status collapsed
2435
2436 \begin_layout Standard
2437
2438
2439 \backslash
2440 /
2441 \end_layout
2442
2443 \end_inset
2444
2445 -datarootdir=
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449 /sdcc
2450 \begin_inset Quotes srd
2451 \end_inset
2452
2453  
2454 \backslash
2455
2456 \newline
2457 docdir=
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461
2462 \backslash
2463 ${datarootdir}/doc
2464 \begin_inset Quotes srd
2465 \end_inset
2466
2467  
2468 \backslash
2469
2470 \newline
2471 include_dir_suffix=
2472 \begin_inset Quotes srd
2473 \end_inset
2474
2475 include
2476 \begin_inset Quotes srd
2477 \end_inset
2478
2479  
2480 \backslash
2481
2482 \newline
2483 lib_dir_suffix=
2484 \begin_inset Quotes srd
2485 \end_inset
2486
2487 lib
2488 \begin_inset Quotes srd
2489 \end_inset
2490
2491  
2492 \backslash
2493
2494 \newline
2495 sdccconf_h_dir_separator=
2496 \begin_inset Quotes srd
2497 \end_inset
2498
2499
2500 \backslash
2501
2502 \backslash
2503
2504 \backslash
2505
2506 \backslash
2507
2508 \begin_inset Quotes srd
2509 \end_inset
2510
2511  
2512 \backslash
2513
2514 \newline
2515 -
2516 \begin_inset ERT
2517 status collapsed
2518
2519 \begin_layout Standard
2520
2521
2522 \backslash
2523 /
2524 \end_layout
2525
2526 \end_inset
2527
2528 -disable-device-lib
2529 \backslash
2530
2531 \newline
2532 -
2533 \begin_inset ERT
2534 status collapsed
2535
2536 \begin_layout Standard
2537
2538
2539 \backslash
2540 /
2541 \end_layout
2542
2543 \end_inset
2544
2545 -host=i586-mingw32msvc
2546 \backslash
2547
2548 \newline
2549 -
2550 \begin_inset ERT
2551 status collapsed
2552
2553 \begin_layout Standard
2554
2555
2556 \backslash
2557 /
2558 \end_layout
2559
2560 \end_inset
2561
2562 -build=unknown-unknown-linux-gnu
2563 \end_layout
2564
2565 \begin_layout Standard
2566 To 
2567 \begin_inset Quotes sld
2568 \end_inset
2569
2570 cross
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2575 ):
2576 \end_layout
2577
2578 \begin_layout LyX-Code
2579 ./configure -C 
2580 \backslash
2581
2582 \newline
2583 -
2584 \begin_inset ERT
2585 status collapsed
2586
2587 \begin_layout Standard
2588
2589
2590 \backslash
2591 /
2592 \end_layout
2593
2594 \end_inset
2595
2596 -prefix=
2597 \begin_inset Quotes srd
2598 \end_inset
2599
2600 /sdcc
2601 \begin_inset Quotes srd
2602 \end_inset
2603
2604  
2605 \backslash
2606
2607 \newline
2608 -
2609 \begin_inset ERT
2610 status collapsed
2611
2612 \begin_layout Standard
2613
2614
2615 \backslash
2616 /
2617 \end_layout
2618
2619 \end_inset
2620
2621 -datarootdir=
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625 /sdcc
2626 \begin_inset Quotes srd
2627 \end_inset
2628
2629  
2630 \backslash
2631
2632 \newline
2633 docdir=
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637
2638 \backslash
2639 ${datarootdir}/doc
2640 \begin_inset Quotes srd
2641 \end_inset
2642
2643  
2644 \backslash
2645  
2646 \newline
2647 include_dir_suffix=
2648 \begin_inset Quotes srd
2649 \end_inset
2650
2651 include
2652 \begin_inset Quotes srd
2653 \end_inset
2654
2655  
2656 \backslash
2657
2658 \newline
2659 lib_dir_suffix=
2660 \begin_inset Quotes srd
2661 \end_inset
2662
2663 lib
2664 \begin_inset Quotes srd
2665 \end_inset
2666
2667  
2668 \backslash
2669
2670 \newline
2671 sdccconf_h_dir_separator=
2672 \begin_inset Quotes srd
2673 \end_inset
2674
2675
2676 \backslash
2677
2678 \backslash
2679
2680 \backslash
2681
2682 \backslash
2683
2684 \begin_inset Quotes srd
2685 \end_inset
2686
2687  
2688 \backslash
2689
2690 \newline
2691 CC=
2692 \begin_inset Quotes srd
2693 \end_inset
2694
2695 gcc -mno-cygwin
2696 \begin_inset Quotes srd
2697 \end_inset
2698
2699  
2700 \backslash
2701
2702 \newline
2703 CXX=
2704 \begin_inset Quotes srd
2705 \end_inset
2706
2707 g++ -mno-cygwin
2708 \begin_inset Quotes srd
2709 \end_inset
2710
2711  
2712 \end_layout
2713
2714 \begin_layout Standard
2715 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2716  The option '-
2717 \begin_inset ERT
2718 status collapsed
2719
2720 \begin_layout Standard
2721
2722
2723 \backslash
2724 /
2725 \end_layout
2726
2727 \end_inset
2728
2729 -C' turns on caching, which gives a little bit extra speed.
2730  However if options are changed, it can be necessary to delete the config.cache
2731  file.
2732 \end_layout
2733
2734 \begin_layout Section
2735 Install paths
2736 \begin_inset LatexCommand \label{sub:Install-paths}
2737
2738 \end_inset
2739
2740
2741 \begin_inset LatexCommand \index{Install paths}
2742
2743 \end_inset
2744
2745
2746 \end_layout
2747
2748 \begin_layout Standard
2749 \begin_inset VSpace medskip
2750 \end_inset
2751
2752
2753 \end_layout
2754
2755 \begin_layout Standard
2756 \align center
2757 \begin_inset Tabular
2758 <lyxtabular version="3" rows="5" columns="4">
2759 <features>
2760 <column alignment="left" valignment="top" leftline="true" width="0">
2761 <column alignment="left" valignment="top" leftline="true" width="0">
2762 <column alignment="left" valignment="top" leftline="true" width="0">
2763 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2764 <row topline="true" bottomline="true">
2765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2766 \begin_inset Text
2767
2768 \begin_layout Standard
2769
2770 \series bold
2771 Description
2772 \end_layout
2773
2774 \end_inset
2775 </cell>
2776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2777 \begin_inset Text
2778
2779 \begin_layout Standard
2780
2781 \series bold
2782 Path
2783 \end_layout
2784
2785 \end_inset
2786 </cell>
2787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2788 \begin_inset Text
2789
2790 \begin_layout Standard
2791
2792 \series bold
2793 Default
2794 \end_layout
2795
2796 \end_inset
2797 </cell>
2798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2799 \begin_inset Text
2800
2801 \begin_layout Standard
2802
2803 \series bold
2804 Win32 builds
2805 \end_layout
2806
2807 \end_inset
2808 </cell>
2809 </row>
2810 <row topline="true">
2811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2812 \begin_inset Text
2813
2814 \begin_layout Standard
2815 Binary files*
2816 \end_layout
2817
2818 \end_inset
2819 </cell>
2820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2821 \begin_inset Text
2822
2823 \begin_layout Standard
2824
2825 \emph on
2826 $EXEC_PREFIX
2827 \end_layout
2828
2829 \end_inset
2830 </cell>
2831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2832 \begin_inset Text
2833
2834 \begin_layout Standard
2835 /usr/local/bin
2836 \end_layout
2837
2838 \end_inset
2839 </cell>
2840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2841 \begin_inset Text
2842
2843 \begin_layout Standard
2844
2845 \backslash
2846 sdcc
2847 \backslash
2848 bin
2849 \end_layout
2850
2851 \end_inset
2852 </cell>
2853 </row>
2854 <row topline="true">
2855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2856 \begin_inset Text
2857
2858 \begin_layout Standard
2859 Include files
2860 \end_layout
2861
2862 \end_inset
2863 </cell>
2864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2865 \begin_inset Text
2866
2867 \begin_layout Standard
2868
2869 \emph on
2870 $DATADIR/ $INCLUDE_DIR_SUFFIX
2871 \end_layout
2872
2873 \end_inset
2874 </cell>
2875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2876 \begin_inset Text
2877
2878 \begin_layout Standard
2879 /usr/local/share/sdcc/include
2880 \end_layout
2881
2882 \end_inset
2883 </cell>
2884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2885 \begin_inset Text
2886
2887 \begin_layout Standard
2888
2889 \backslash
2890 sdcc
2891 \backslash
2892 include
2893 \end_layout
2894
2895 \end_inset
2896 </cell>
2897 </row>
2898 <row topline="true">
2899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2900 \begin_inset Text
2901
2902 \begin_layout Standard
2903 Library file**
2904 \end_layout
2905
2906 \end_inset
2907 </cell>
2908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2909 \begin_inset Text
2910
2911 \begin_layout Standard
2912
2913 \emph on
2914 $DATADIR/$LIB_DIR_SUFFIX
2915 \end_layout
2916
2917 \end_inset
2918 </cell>
2919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_inset Text
2921
2922 \begin_layout Standard
2923 /usr/local/share/sdcc/lib
2924 \end_layout
2925
2926 \end_inset
2927 </cell>
2928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2929 \begin_inset Text
2930
2931 \begin_layout Standard
2932
2933 \backslash
2934 sdcc
2935 \backslash
2936 lib
2937 \end_layout
2938
2939 \end_inset
2940 </cell>
2941 </row>
2942 <row topline="true" bottomline="true">
2943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2944 \begin_inset Text
2945
2946 \begin_layout Standard
2947 Documentation
2948 \end_layout
2949
2950 \end_inset
2951 </cell>
2952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2953 \begin_inset Text
2954
2955 \begin_layout Standard
2956
2957 \emph on
2958 $DOCDIR
2959 \end_layout
2960
2961 \end_inset
2962 </cell>
2963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2964 \begin_inset Text
2965
2966 \begin_layout Standard
2967 /usr/local/share/sdcc/doc
2968 \end_layout
2969
2970 \end_inset
2971 </cell>
2972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2973 \begin_inset Text
2974
2975 \begin_layout Standard
2976
2977 \backslash
2978 sdcc
2979 \backslash
2980 doc
2981 \end_layout
2982
2983 \end_inset
2984 </cell>
2985 </row>
2986 </lyxtabular>
2987
2988 \end_inset
2989
2990
2991 \end_layout
2992
2993 \begin_layout Verse
2994
2995 \size footnotesize
2996 *compiler, preprocessor, assembler, and linker
2997 \newline
2998 **the 
2999 \shape italic
3000 model
3001 \shape default
3002  is auto-appended by the compiler, e.g.
3003  small, large, z80, ds390 etc
3004 \end_layout
3005
3006 \begin_layout Standard
3007 \noindent
3008 The install paths can still be changed during `make install' with e.g.:
3009 \end_layout
3010
3011 \begin_layout LyX-Code
3012 make install prefix=$(HOME)/local/sdcc
3013 \end_layout
3014
3015 \begin_layout Standard
3016 Of course this doesn't change the search paths compiled into the binaries.
3017 \newline
3018
3019 \newline
3020 Moreove
3021 r the install path can be changed by defining DESTDIR
3022 \begin_inset LatexCommand \index{DESTDIR}
3023
3024 \end_inset
3025
3026 :
3027 \end_layout
3028
3029 \begin_layout LyX-Code
3030 make install DESTDIR=$(HOME)/sdcc.rpm/
3031 \end_layout
3032
3033 \begin_layout Standard
3034 Please note that DESTDIR must have a trailing slash!
3035 \end_layout
3036
3037 \begin_layout Section
3038 Search Paths
3039 \begin_inset LatexCommand \label{sub:Search-Paths}
3040
3041 \end_inset
3042
3043
3044 \begin_inset LatexCommand \index{Search path}
3045
3046 \end_inset
3047
3048
3049 \end_layout
3050
3051 \begin_layout Standard
3052 Some search paths or parts of them are determined by configure variables
3053  (in 
3054 \emph on
3055 italics
3056 \emph default
3057 , see section above).
3058  Further search paths are determined by environment variables during runtime.
3059  
3060 \newline
3061 The paths searched when running the compiler are as follows (the first
3062  catch wins):
3063 \newline
3064
3065 \newline
3066 1.
3067  Binary files (preprocessor, assembler and linker)
3068 \newline
3069
3070 \end_layout
3071
3072 \begin_layout Standard
3073 \align center
3074 \begin_inset Tabular
3075 <lyxtabular version="3" rows="4" columns="3">
3076 <features>
3077 <column alignment="block" valignment="top" leftline="true" width="0in">
3078 <column alignment="block" valignment="top" leftline="true" width="0in">
3079 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3080 <row topline="true" bottomline="true">
3081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3082 \begin_inset Text
3083
3084 \begin_layout Standard
3085 Search path
3086 \end_layout
3087
3088 \end_inset
3089 </cell>
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3091 \begin_inset Text
3092
3093 \begin_layout Standard
3094 default
3095 \end_layout
3096
3097 \end_inset
3098 </cell>
3099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3100 \begin_inset Text
3101
3102 \begin_layout Standard
3103 Win32 builds
3104 \end_layout
3105
3106 \end_inset
3107 </cell>
3108 </row>
3109 <row topline="true">
3110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3111 \begin_inset Text
3112
3113 \begin_layout Standard
3114 $SDCC_HOME/
3115 \emph on
3116 $PPREFIX2BIN_DIR
3117 \end_layout
3118
3119 \end_inset
3120 </cell>
3121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3122 \begin_inset Text
3123
3124 \begin_layout Standard
3125 $SDCC_HOME/bin
3126 \end_layout
3127
3128 \end_inset
3129 </cell>
3130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3131 \begin_inset Text
3132
3133 \begin_layout Standard
3134 $SDCC_HOME
3135 \backslash
3136 bin
3137 \end_layout
3138
3139 \end_inset
3140 </cell>
3141 </row>
3142 <row topline="true">
3143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3144 \begin_inset Text
3145
3146 \begin_layout Standard
3147 Path of argv[0] (if available)
3148 \end_layout
3149
3150 \end_inset
3151 </cell>
3152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3153 \begin_inset Text
3154
3155 \begin_layout Standard
3156 Path of argv[0]
3157 \end_layout
3158
3159 \end_inset
3160 </cell>
3161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3162 \begin_inset Text
3163
3164 \begin_layout Standard
3165 Path of argv[0]
3166 \end_layout
3167
3168 \end_inset
3169 </cell>
3170 </row>
3171 <row topline="true" bottomline="true">
3172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3173 \begin_inset Text
3174
3175 \begin_layout Standard
3176 $PATH
3177 \end_layout
3178
3179 \end_inset
3180 </cell>
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3182 \begin_inset Text
3183
3184 \begin_layout Standard
3185 $PATH
3186 \end_layout
3187
3188 \end_inset
3189 </cell>
3190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3191 \begin_inset Text
3192
3193 \begin_layout Standard
3194 $PATH
3195 \end_layout
3196
3197 \end_inset
3198 </cell>
3199 </row>
3200 </lyxtabular>
3201
3202 \end_inset
3203
3204  
3205 \newline
3206
3207 \end_layout
3208
3209 \begin_layout Standard
3210 \noindent
3211 2.
3212  Include files
3213 \newline
3214
3215 \end_layout
3216
3217 \begin_layout Standard
3218 \align center
3219 \begin_inset Tabular
3220 <lyxtabular version="3" rows="6" columns="3">
3221 <features>
3222 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3223 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3224 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3225 <row topline="true" bottomline="true">
3226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3227 \begin_inset Text
3228
3229 \begin_layout Standard
3230 Search path
3231 \end_layout
3232
3233 \end_inset
3234 </cell>
3235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \begin_layout Standard
3239 default
3240 \end_layout
3241
3242 \end_inset
3243 </cell>
3244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3245 \begin_inset Text
3246
3247 \begin_layout Standard
3248 Win32 builds
3249 \end_layout
3250
3251 \end_inset
3252 </cell>
3253 </row>
3254 <row topline="true">
3255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3256 \begin_inset Text
3257
3258 \begin_layout Standard
3259 -
3260 \begin_inset ERT
3261 status collapsed
3262
3263 \begin_layout Standard
3264
3265
3266 \backslash
3267 /
3268 \end_layout
3269
3270 \end_inset
3271
3272 -I dir
3273 \end_layout
3274
3275 \end_inset
3276 </cell>
3277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3278 \begin_inset Text
3279
3280 \begin_layout Standard
3281 -
3282 \begin_inset ERT
3283 status collapsed
3284
3285 \begin_layout Standard
3286
3287
3288 \backslash
3289 /
3290 \end_layout
3291
3292 \end_inset
3293
3294 -I dir
3295 \end_layout
3296
3297 \end_inset
3298 </cell>
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3300 \begin_inset Text
3301
3302 \begin_layout Standard
3303 -
3304 \begin_inset ERT
3305 status collapsed
3306
3307 \begin_layout Standard
3308
3309
3310 \backslash
3311 /
3312 \end_layout
3313
3314 \end_inset
3315
3316 -I dir
3317 \end_layout
3318
3319 \end_inset
3320 </cell>
3321 </row>
3322 <row topline="true">
3323 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3324 \begin_inset Text
3325
3326 \begin_layout Standard
3327 $SDCC_INCLUDE
3328 \end_layout
3329
3330 \end_inset
3331 </cell>
3332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3333 \begin_inset Text
3334
3335 \begin_layout Standard
3336 $SDCC_INCLUDE
3337 \end_layout
3338
3339 \end_inset
3340 </cell>
3341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3342 \begin_inset Text
3343
3344 \begin_layout Standard
3345 $SDCC_INCLUDE
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 </row>
3351 <row topline="true">
3352 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3353 \begin_inset Text
3354
3355 \begin_layout Standard
3356 $SDCC_HOME/
3357 \newline
3358
3359 \emph on
3360 $PREFIX2DATA_DIR/
3361 \newline
3362 $INCLUDE_DIR_SUFFIX
3363 \end_layout
3364
3365 \end_inset
3366 </cell>
3367 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3368 \begin_inset Text
3369
3370 \begin_layout Standard
3371 $SDCC_ HOME/
3372 \newline
3373 share/sdcc/
3374 \newline
3375 include
3376 \end_layout
3377
3378 \end_inset
3379 </cell>
3380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3381 \begin_inset Text
3382
3383 \begin_layout Standard
3384 $SDCC_HOME
3385 \backslash
3386 include
3387 \end_layout
3388
3389 \end_inset
3390 </cell>
3391 </row>
3392 <row topline="true">
3393 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3394 \begin_inset Text
3395
3396 \begin_layout Standard
3397 path(argv[0])/
3398 \newline
3399
3400 \emph on
3401 $BIN2DATADIR/
3402 \emph default
3403
3404 \newline
3405
3406 \emph on
3407 $INCLUDE_DIR_SUFFIX
3408 \end_layout
3409
3410 \end_inset
3411 </cell>
3412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3413 \begin_inset Text
3414
3415 \begin_layout Standard
3416 path(argv[0])/
3417 \newline
3418 ../sdcc/include
3419 \newline
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428 \InsetSpace ~
3429 \InsetSpace ~
3430 \InsetSpace ~
3431 \InsetSpace ~
3432 \InsetSpace ~
3433 \InsetSpace ~
3434 \InsetSpace ~
3435 \InsetSpace ~
3436 \InsetSpace ~
3437 \InsetSpace ~
3438 \InsetSpace ~
3439 \InsetSpace ~
3440 \InsetSpace ~
3441 \InsetSpace ~
3442 \InsetSpace ~
3443 \InsetSpace ~
3444 \InsetSpace ~
3445 \InsetSpace ~
3446 \InsetSpace ~
3447 \InsetSpace ~
3448 \InsetSpace ~
3449 \InsetSpace ~
3450 \InsetSpace ~
3451 \InsetSpace ~
3452 \InsetSpace ~
3453 \InsetSpace ~
3454 \InsetSpace ~
3455 \InsetSpace ~
3456 \InsetSpace ~
3457 \InsetSpace ~
3458
3459 \end_layout
3460
3461 \end_inset
3462 </cell>
3463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3464 \begin_inset Text
3465
3466 \begin_layout Standard
3467 path(argv[0])
3468 \backslash
3469 ..
3470 \backslash
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 </row>
3477 <row topline="true" bottomline="true">
3478 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3479 \begin_inset Text
3480
3481 \begin_layout Standard
3482
3483 \emph on
3484 $DATADIR/
3485 \emph default
3486
3487 \newline
3488
3489 \emph on
3490 $INCLUDE_DIR_SUFFIX
3491 \end_layout
3492
3493 \end_inset
3494 </cell>
3495 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3496 \begin_inset Text
3497
3498 \begin_layout Standard
3499 /usr/local/share/sdcc/
3500 \newline
3501 include
3502 \end_layout
3503
3504 \end_inset
3505 </cell>
3506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3507 \begin_inset Text
3508
3509 \begin_layout Standard
3510 (not on Win32)
3511 \end_layout
3512
3513 \end_inset
3514 </cell>
3515 </row>
3516 </lyxtabular>
3517
3518 \end_inset
3519
3520  
3521 \newline
3522
3523 \end_layout
3524
3525 \begin_layout Standard
3526 \noindent
3527 The option -
3528 \begin_inset ERT
3529 status collapsed
3530
3531 \begin_layout Standard
3532
3533
3534 \backslash
3535 /
3536 \end_layout
3537
3538 \end_inset
3539
3540 -nostdinc disables the last two search paths.
3541 \newline
3542
3543 \newline
3544 3.
3545  Library files 
3546 \newline
3547
3548 \end_layout
3549
3550 \begin_layout Standard
3551 With the exception of 
3552 \begin_inset Quotes sld
3553 \end_inset
3554
3555 -
3556 \begin_inset ERT
3557 status collapsed
3558
3559 \begin_layout Standard
3560
3561
3562 \backslash
3563 /
3564 \end_layout
3565
3566 \end_inset
3567
3568 -L dir
3569 \begin_inset Quotes srd
3570 \end_inset
3571
3572  the 
3573 \shape italic
3574 model
3575 \shape default
3576  is auto-appended by the compiler (e.g.
3577  small, large, z80, ds390 etc.).
3578  
3579 \newline
3580
3581 \end_layout
3582
3583 \begin_layout Standard
3584 \align center
3585 \begin_inset Tabular
3586 <lyxtabular version="3" rows="6" columns="3">
3587 <features>
3588 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3589 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3590 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3591 <row topline="true" bottomline="true">
3592 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_inset Text
3594
3595 \begin_layout Standard
3596 Search path
3597 \end_layout
3598
3599 \end_inset
3600 </cell>
3601 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3602 \begin_inset Text
3603
3604 \begin_layout Standard
3605 default
3606 \end_layout
3607
3608 \end_inset
3609 </cell>
3610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3611 \begin_inset Text
3612
3613 \begin_layout Standard
3614 Win32 builds
3615 \end_layout
3616
3617 \end_inset
3618 </cell>
3619 </row>
3620 <row topline="true">
3621 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3622 \begin_inset Text
3623
3624 \begin_layout Standard
3625 -
3626 \begin_inset ERT
3627 status collapsed
3628
3629 \begin_layout Standard
3630
3631
3632 \backslash
3633 /
3634 \end_layout
3635
3636 \end_inset
3637
3638 -L dir
3639 \end_layout
3640
3641 \end_inset
3642 </cell>
3643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3644 \begin_inset Text
3645
3646 \begin_layout Standard
3647 -
3648 \begin_inset ERT
3649 status collapsed
3650
3651 \begin_layout Standard
3652
3653
3654 \backslash
3655 /
3656 \end_layout
3657
3658 \end_inset
3659
3660 -L dir
3661 \end_layout
3662
3663 \end_inset
3664 </cell>
3665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3666 \begin_inset Text
3667
3668 \begin_layout Standard
3669 -
3670 \begin_inset ERT
3671 status collapsed
3672
3673 \begin_layout Standard
3674
3675
3676 \backslash
3677 /
3678 \end_layout
3679
3680 \end_inset
3681
3682 -L dir
3683 \end_layout
3684
3685 \end_inset
3686 </cell>
3687 </row>
3688 <row topline="true">
3689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3690 \begin_inset Text
3691
3692 \begin_layout Standard
3693 $SDCC_LIB/
3694 \newline
3695
3696 \emph on
3697 <model>
3698 \end_layout
3699
3700 \end_inset
3701 </cell>
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_LIB/
3707 \newline
3708
3709 \emph on
3710 <model>
3711 \end_layout
3712
3713 \end_inset
3714 </cell>
3715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3716 \begin_inset Text
3717
3718 \begin_layout Standard
3719 $SDCC_LIB
3720 \backslash
3721
3722 \newline
3723
3724 \emph on
3725 <model>
3726 \end_layout
3727
3728 \end_inset
3729 </cell>
3730 </row>
3731 <row topline="true">
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME/
3737 \newline
3738
3739 \emph on
3740 $PREFIX2DATA_DIR/
3741 \newline
3742 $LIB_DIR_SUFFIX/<model>
3743 \end_layout
3744
3745 \end_inset
3746 </cell>
3747 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3748 \begin_inset Text
3749
3750 \begin_layout Standard
3751 $SDCC_HOME/
3752 \newline
3753 share/sdcc/
3754 \newline
3755 lib/
3756 \emph on
3757 <model>
3758 \end_layout
3759
3760 \end_inset
3761 </cell>
3762 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3763 \begin_inset Text
3764
3765 \begin_layout Standard
3766 $SDCC_HOME
3767 \backslash
3768 lib
3769 \backslash
3770
3771 \emph on
3772
3773 \newline
3774 <model>
3775 \end_layout
3776
3777 \end_inset
3778 </cell>
3779 </row>
3780 <row topline="true">
3781 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3782 \begin_inset Text
3783
3784 \begin_layout Standard
3785 path(argv[0])/
3786 \newline
3787
3788 \emph on
3789 $BIN2DATADIR/
3790 \emph default
3791
3792 \newline
3793
3794 \emph on
3795 $LIB_DIR_SUFFIX/<model>
3796 \end_layout
3797
3798 \end_inset
3799 </cell>
3800 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_inset Text
3802
3803 \begin_layout Standard
3804 path(argv[0])/
3805 \newline
3806 ../sdcc/lib/
3807 \emph on
3808 <model>
3809 \newline
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819 \InsetSpace ~
3820 \InsetSpace ~
3821 \InsetSpace ~
3822 \InsetSpace ~
3823 \InsetSpace ~
3824 \InsetSpace ~
3825 \InsetSpace ~
3826 \InsetSpace ~
3827 \InsetSpace ~
3828 \InsetSpace ~
3829 \InsetSpace ~
3830 \InsetSpace ~
3831 \InsetSpace ~
3832 \InsetSpace ~
3833 \InsetSpace ~
3834 \InsetSpace ~
3835 \InsetSpace ~
3836 \InsetSpace ~
3837 \InsetSpace ~
3838 \InsetSpace ~
3839 \InsetSpace ~
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849
3850 \end_layout
3851
3852 \end_inset
3853 </cell>
3854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3855 \begin_inset Text
3856
3857 \begin_layout Standard
3858 path(argv[0])
3859 \backslash
3860
3861 \newline
3862 ..
3863 \backslash
3864 lib
3865 \backslash
3866
3867 \emph on
3868 <model>
3869 \newline
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875 \InsetSpace ~
3876 \InsetSpace ~
3877 \InsetSpace ~
3878 \InsetSpace ~
3879 \InsetSpace ~
3880 \InsetSpace ~
3881 \InsetSpace ~
3882 \InsetSpace ~
3883 \InsetSpace ~
3884 \InsetSpace ~
3885 \InsetSpace ~
3886 \InsetSpace ~
3887 \InsetSpace ~
3888 \InsetSpace ~
3889 \InsetSpace ~
3890 \InsetSpace ~
3891 \InsetSpace ~
3892 \InsetSpace ~
3893 \InsetSpace ~
3894 \InsetSpace ~
3895 \InsetSpace ~
3896 \InsetSpace ~
3897 \InsetSpace ~
3898 \InsetSpace ~
3899 \InsetSpace ~
3900 \InsetSpace ~
3901 \InsetSpace ~
3902 \InsetSpace ~
3903 \InsetSpace ~
3904 \InsetSpace ~
3905
3906 \end_layout
3907
3908 \end_inset
3909 </cell>
3910 </row>
3911 <row topline="true" bottomline="true">
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3913 \begin_inset Text
3914
3915 \begin_layout Standard
3916
3917 \emph on
3918 $DATADIR/
3919 \newline
3920 $LIB_DIR_SUFFIX/<model>
3921 \end_layout
3922
3923 \end_inset
3924 </cell>
3925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3926 \begin_inset Text
3927
3928 \begin_layout Standard
3929 /usr/local/share/sdcc/
3930 \newline
3931 lib/
3932 \emph on
3933 <model>
3934 \end_layout
3935
3936 \end_inset
3937 </cell>
3938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3939 \begin_inset Text
3940
3941 \begin_layout Standard
3942 (not on Win32)
3943 \end_layout
3944
3945 \end_inset
3946 </cell>
3947 </row>
3948 </lyxtabular>
3949
3950 \end_inset
3951
3952
3953 \newline
3954
3955 \end_layout
3956
3957 \begin_layout Standard
3958 \begin_inset Note Note
3959 status collapsed
3960
3961 \begin_layout Standard
3962 Don't delete any of the stray spaces in the table above without checking
3963  the HTML output (last line)!
3964 \end_layout
3965
3966 \end_inset
3967
3968
3969 \end_layout
3970
3971 \begin_layout Standard
3972 \InsetSpace ~
3973
3974 \newline
3975 The option -
3976 \begin_inset ERT
3977 status collapsed
3978
3979 \begin_layout Standard
3980
3981
3982 \backslash
3983 /
3984 \end_layout
3985
3986 \end_inset
3987
3988 -nostdlib disables the last two search paths.
3989 \end_layout
3990
3991 \begin_layout Section
3992 Building SDCC
3993 \begin_inset LatexCommand \index{Building SDCC}
3994
3995 \end_inset
3996
3997
3998 \end_layout
3999
4000 \begin_layout Subsection
4001 Building SDCC on Linux
4002 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
4003
4004 \end_inset
4005
4006
4007 \end_layout
4008
4009 \begin_layout Enumerate
4010
4011 \series medium
4012 Download the source package
4013 \series default
4014  either from the SDCC Subversion repository or from snapshot builds
4015 \series medium
4016 , it will be named something like sdcc
4017 \series default
4018 -src
4019 \series medium
4020 -yyyymmdd-rrrr.t
4021 \series default
4022 ar.
4023 \series medium
4024 bz2
4025 \series default
4026  
4027 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4028
4029 \end_inset
4030
4031 .
4032 \end_layout
4033
4034 \begin_layout Enumerate
4035
4036 \series medium
4037 Bring up a command line terminal, such as xterm.
4038 \end_layout
4039
4040 \begin_layout Enumerate
4041
4042 \series medium
4043 Unpack the file using a command like: 
4044 \family sans
4045 \series bold
4046 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4047 \begin_inset Quotes srd
4048 \end_inset
4049
4050
4051 \family default
4052 \series medium
4053 , this will create a sub-directory called sdcc with all of the sources.
4054 \end_layout
4055
4056 \begin_layout Enumerate
4057 Change directory into the main SDCC directory, for example type: 
4058 \family sans
4059 \series bold
4060 "cd sdcc
4061 \series default
4062 ".
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "./configure
4072 \family default
4073 \series default
4074 ".
4075  This configures the package for compilation on your system.
4076 \end_layout
4077
4078 \begin_layout Enumerate
4079
4080 \series medium
4081 Type 
4082 \family sans
4083 \series bold
4084 "make
4085 \family default
4086 \series default
4087 "
4088 \series medium
4089 .
4090
4091 \series default
4092  All of the source packages will compile, this can take a while.
4093 \end_layout
4094
4095 \begin_layout Enumerate
4096
4097 \series medium
4098 Type 
4099 \family sans
4100 \series bold
4101 "make install"
4102 \family default
4103 \series default
4104  as root
4105 \series medium
4106 .
4107
4108 \series default
4109  This copies the binary executables, the include files, the libraries and
4110  the documentation to the install directories.
4111  Proceed with section 
4112 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4113
4114 \end_inset
4115
4116 .
4117 \end_layout
4118
4119 \begin_layout Subsection
4120 Building SDCC on Mac OS X
4121 \end_layout
4122
4123 \begin_layout Standard
4124 Follow the instruction for Linux.
4125 \newline
4126
4127 \newline
4128 On Mac OS X 10.2.x it was reported, that the
4129  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4130  Fortunately there's also gcc 2.9.x installed, which works fine.
4131  This compiler can be selected by running 'configure' with:
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 ./configure CC=gcc2 CXX=g++2
4136 \end_layout
4137
4138 \begin_layout Standard
4139 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4140  Xcode.
4141  Run 'configure' with:
4142 \end_layout
4143
4144 \begin_layout LyX-Code
4145 ./configure 
4146 \backslash
4147
4148 \end_layout
4149
4150 \begin_layout LyX-Code
4151 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4152  ppc" 
4153 \backslash
4154
4155 \end_layout
4156
4157 \begin_layout LyX-Code
4158 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4159  ppc" 
4160 \backslash
4161
4162 \end_layout
4163
4164 \begin_layout LyX-Code
4165 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4166 \end_layout
4167
4168 \begin_layout Subsection
4169 Cross compiling SDCC on Linux for Windows
4170 \end_layout
4171
4172 \begin_layout Standard
4173 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4174  See section 'Configure Options'.
4175 \end_layout
4176
4177 \begin_layout Subsection
4178 Building SDCC using Cygwin and Mingw32
4179 \end_layout
4180
4181 \begin_layout Standard
4182 For building and installing a Cygwin executable follow the instructions
4183  for Linux.
4184 \newline
4185
4186 \newline
4187 On Cygwin a 
4188 \begin_inset Quotes sld
4189 \end_inset
4190
4191 native
4192 \begin_inset Quotes srd
4193 \end_inset
4194
4195  Win32-binary can be built, which will not need the Cygwin-DLL.
4196  For the necessary 'configure' options see section 'configure options' or
4197  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4198 \newline
4199
4200 \newline
4201 In order to install
4202  Cygwin on Windows download setup.exe from 
4203 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4204
4205 \end_inset
4206
4207 .
4208  Run it, set the 
4209 \begin_inset Quotes sld
4210 \end_inset
4211
4212 default text file type
4213 \begin_inset Quotes srd
4214 \end_inset
4215
4216  to 
4217 \begin_inset Quotes sld
4218 \end_inset
4219
4220 unix
4221 \begin_inset Quotes srd
4222 \end_inset
4223
4224  and download/install at least the following packages.
4225  Some packages are selected by default, others will be automatically selected
4226  because of dependencies with the manually selected packages.
4227  Never deselect these packages!
4228 \end_layout
4229
4230 \begin_layout Itemize
4231 flex
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 bison
4236 \end_layout
4237
4238 \begin_layout Itemize
4239 gcc ; version 3.x is fine, no need to use the old 2.9x
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 binutils ; selected with gcc
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 make
4248 \end_layout
4249
4250 \begin_layout Itemize
4251 rxvt ; a nice console, which makes life much easier under windoze (see below)
4252 \end_layout
4253
4254 \begin_layout Itemize
4255 man ; not really needed for building SDCC, but you'll miss it sooner or
4256  later
4257 \end_layout
4258
4259 \begin_layout Itemize
4260 less ; not really needed for building SDCC, but you'll miss it sooner or
4261  later
4262 \end_layout
4263
4264 \begin_layout Itemize
4265 svn ; only if you use Subversion access
4266 \end_layout
4267
4268 \begin_layout Standard
4269 If you want to develop something you'll need:
4270 \end_layout
4271
4272 \begin_layout Itemize
4273 python ; for the regression tests
4274 \end_layout
4275
4276 \begin_layout Itemize
4277 gdb ; the gnu debugger, together with the nice GUI 
4278 \begin_inset Quotes sld
4279 \end_inset
4280
4281 insight
4282 \begin_inset Quotes srd
4283 \end_inset
4284
4285
4286 \end_layout
4287
4288 \begin_layout Itemize
4289 openssh ; to access the CF or commit changes
4290 \end_layout
4291
4292 \begin_layout Itemize
4293 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4294  use autoconf-stable!
4295 \end_layout
4296
4297 \begin_layout Standard
4298 rxvt is a nice console with history.
4299  Replace in your cygwin.bat the line
4300 \end_layout
4301
4302 \begin_layout LyX-Code
4303 bash -
4304 \begin_inset ERT
4305 status collapsed
4306
4307 \begin_layout Standard
4308
4309
4310 \backslash
4311 /
4312 \end_layout
4313
4314 \end_inset
4315
4316 -login -i 
4317 \end_layout
4318
4319 \begin_layout Standard
4320 with (one line):
4321 \end_layout
4322
4323 \begin_layout LyX-Code
4324 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4325 \end_layout
4326
4327 \begin_layout LyX-Code
4328      -bg black -fg white -geometry 100x65 -e bash -
4329 \begin_inset ERT
4330 status collapsed
4331
4332 \begin_layout Standard
4333
4334
4335 \backslash
4336 /
4337 \end_layout
4338
4339 \end_inset
4340
4341 -login
4342 \end_layout
4343
4344 \begin_layout Standard
4345 Text selected with the mouse is automatically copied to the clipboard, pasting
4346  works with shift-insert.
4347 \newline
4348
4349 \newline
4350 The other good tip is to make sure you have no //c/-styl
4351 e paths anywhere, use /cygdrive/c/ instead.
4352  Using // invokes a network lookup which is very slow.
4353  If you think 
4354 \begin_inset Quotes sld
4355 \end_inset
4356
4357 cygdrive
4358 \begin_inset Quotes srd
4359 \end_inset
4360
4361  is too long, you can change it with e.g.
4362 \end_layout
4363
4364 \begin_layout LyX-Code
4365 mount -s -u -c /mnt
4366 \end_layout
4367
4368 \begin_layout Standard
4369 SDCC sources use the unix line ending LF.
4370  Life is much easier, if you store the source tree on a drive which is mounted
4371  in binary mode.
4372  And use an editor which can handle LF-only line endings.
4373  Make sure not to commit files with windows line endings.
4374  The tabulator spacing
4375 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4376
4377 \end_inset
4378
4379  used in the project is 8.
4380  Although a tabulator spacing of 8 is a sensible choice for programmers
4381  (it's a power of 2 and allows to display 8/16 bit signed variables without
4382  loosing columns) the plan is to move towards using only spaces in the source.
4383 \end_layout
4384
4385 \begin_layout Subsection
4386 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4387 \end_layout
4388
4389 \begin_layout Standard
4390
4391 \series medium
4392 Download the source package
4393 \series default
4394  either from the SDCC Subversion repository or from the 
4395 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4396
4397 \end_inset
4398
4399
4400 \series medium
4401 , it will be named something like sdcc
4402 \series default
4403 -src
4404 \series medium
4405 -yyyymmdd-rrrr.tar.bz2.
4406
4407 \series default
4408  SDCC is distributed with all the projects, workspaces, and files you need
4409  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4410  The workspace name is 'sdcc.dsw'.
4411  Please note that as it is now, all the executables are created in a folder
4412  called sdcc
4413 \backslash
4414 bin_vc.
4415  Once built you need to copy the executables from sdcc
4416 \backslash
4417 bin_vc to sdcc
4418 \backslash
4419 bin before running SDCC.
4420  
4421 \newline
4422
4423 \newline
4424 WARNING: Visual studio is very picky with line terminations; it expects
4425  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4426  When using the Subversion repository it's easiest to configure the svn
4427  client to convert automatically for you.
4428  If however you are getting a message such as "This makefile was not generated
4429  by Developer Studio etc.
4430  etc.
4431 \begin_inset Quotes srd
4432 \end_inset
4433
4434  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4435  need to convert the Unix style line endings to DOS style line endings.
4436  To do so you can use the 
4437 \begin_inset Quotes sld
4438 \end_inset
4439
4440 unix2dos
4441 \begin_inset Quotes srd
4442 \end_inset
4443
4444  utility freely available on the internet.
4445  Doug Hawkins reported in the sdcc-user list that this works:
4446 \newline
4447
4448 \newline
4449 C:
4450 \backslash
4451 Programming
4452 \backslash
4453 SDCC> unix2dos sdcc.dsw
4454 \newline
4455 C:
4456 \backslash
4457 Programming
4458 \backslash
4459 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4460 \newline
4461
4462 \newline
4463 In order to build SDCC with MSVC
4464  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4465  One good place to get them is 
4466 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4467
4468 \end_inset
4469
4470
4471 \newline
4472
4473 \newline
4474 Download the file UnxUtils
4475 \begin_inset LatexCommand \index{UnxUtils}
4476
4477 \end_inset
4478
4479 .zip.
4480  Now you have to install the utilities and setup MSVC so it can locate the
4481  required programs.
4482  Here there are two alternatives (choose one!):
4483 \end_layout
4484
4485 \begin_layout Enumerate
4486 The easy way:
4487 \newline
4488
4489 \newline
4490 a) Extract UnxUtils.zip to your C:
4491 \backslash
4492  hard disk PRESERVING the original paths, otherwise bison won't work.
4493  (If you are using WinZip make certain that 'Use folder names' is selected)
4494 \newline
4495
4496 \newline
4497 b)
4498  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4499  'Show directories for:' select 'Executable files', and in the directories
4500  window add a new path: 'C:
4501 \backslash
4502 user
4503 \backslash
4504 local
4505 \backslash
4506 wbin', click ok.
4507 \newline
4508
4509 \newline
4510 (As a side effect, you get a bunch of Unix utilities that
4511  could be useful, such as diff and patch.)
4512 \end_layout
4513
4514 \begin_layout Enumerate
4515 A more compact way:
4516 \newline
4517
4518 \newline
4519 This one avoids extracting a bunch of files you may not
4520  use, but requires some extra work:
4521 \newline
4522
4523 \newline
4524 a) Create a directory were to put the
4525  tools needed, or use a directory already present.
4526  Say for example 'C:
4527 \backslash
4528 util'.
4529 \newline
4530
4531 \newline
4532 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4533  gawk.exe to such directory WITHOUT preserving the original paths.
4534  (If you are using WinZip make certain that 'Use folder names' is not selected)
4535 \newline
4536
4537 \newline
4538 c
4539 ) Rename bison.exe to '_bison.exe'.
4540 \newline
4541
4542 \newline
4543 d) Create a batch file 'bison.bat' in 'C:
4544 \backslash
4545 util
4546 \backslash
4547 ' and add these lines: 
4548 \newline
4549 \InsetSpace ~
4550 \InsetSpace ~
4551 set BISON_SIMPLE=C:
4552 \backslash
4553 util
4554 \backslash
4555 bison.simple 
4556 \newline
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 set BISON_HAIRY=C:
4560 \backslash
4561 util
4562 \backslash
4563 bison.hairy
4564 \newline
4565 \InsetSpace ~
4566 \InsetSpace ~
4567 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4568 \newline
4569
4570 \newline
4571 Steps 'c' and 'd' are needed
4572  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4573  reside in some weird Unix directory, '/usr/local/share/' I think.
4574  So it is necessary to tell bison where those files are located if they
4575  are not in such directory.
4576  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4577 \newline
4578
4579 \newline
4580 e
4581 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4582  in 'Show directories for:' select 'Executable files', and in the directories
4583  window add a new path: 'c:
4584 \backslash
4585 util', click ok.
4586  Note that you can use any other path instead of 'c:
4587 \backslash
4588 util', even the path where the Visual C++ tools are, probably: 'C:
4589 \backslash
4590 Program Files
4591 \backslash
4592 Microsoft Visual Studio
4593 \backslash
4594 Common
4595 \backslash
4596 Tools'.
4597  So you don't have to execute step 'e' :)
4598 \end_layout
4599
4600 \begin_layout Standard
4601 That is it.
4602  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4603  the executables from sdcc
4604 \backslash
4605 bin_vc to sdcc
4606 \backslash
4607 bin, and you can compile using SDCC.
4608 \end_layout
4609
4610 \begin_layout Subsection
4611 Building SDCC Using Borland
4612 \end_layout
4613
4614 \begin_layout Enumerate
4615 From the sdcc directory, run the command "make -f Makefile.bcc".
4616  This should regenerate all the .exe files in the bin directory except for
4617  SDCDB and ucSim.
4618 \end_layout
4619
4620 \begin_layout Enumerate
4621 If you modify any source files and need to rebuild, be aware that the dependenci
4622 es may not be correctly calculated.
4623  The safest option is to delete all .obj files and run the build again.
4624  From a Cygwin BASH prompt, this can easily be done with the command (be
4625  sure you are in the sdcc directory):
4626 \newline
4627
4628 \newline
4629
4630 \family sans
4631 \series bold
4632 find .
4633  
4634 \backslash
4635 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4636 \backslash
4637 ) -print -exec rm {} 
4638 \backslash
4639 ;
4640 \family default
4641 \series default
4642
4643 \newline
4644
4645 \newline
4646 or on Windows NT/2000/XP from the command prompt with the command:
4647 \newline
4648
4649 \family sans
4650 \series bold
4651
4652 \newline
4653 del /s *.obj *.lib *.rul
4654 \family default
4655 \series default
4656  from the sdcc directory.
4657 \end_layout
4658
4659 \begin_layout Subsection
4660 Windows Install Using a ZIP Package
4661 \end_layout
4662
4663 \begin_layout Enumerate
4664 Download the binary zip package from 
4665 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4666
4667 \end_inset
4668
4669  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4670  This should unpack to a group of sub-directories.
4671  An example directory structure after unpacking the mingw32 package is:
4672  c:
4673 \backslash
4674 sdcc
4675 \backslash
4676 bin for the executables, c:
4677 \backslash
4678 sdcc
4679 \backslash
4680 include and c:
4681 \backslash
4682 sdcc
4683 \backslash
4684 lib for the include and libraries.
4685 \end_layout
4686
4687 \begin_layout Enumerate
4688 Adjust your environment variable PATH to include the location of the bin
4689  directory or start sdcc using the full path.
4690 \end_layout
4691
4692 \begin_layout Subsection
4693 Windows Install Using the Setup Program
4694 \begin_inset LatexCommand \label{sub:Windows-Install}
4695
4696 \end_inset
4697
4698
4699 \end_layout
4700
4701 \begin_layout Standard
4702 Download the setup program 
4703 \emph on
4704 sdcc-x.y.z-setup.exe
4705 \emph default
4706  for an official release from 
4707 \newline
4708
4709 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4710
4711 \end_inset
4712
4713  or a setup program for one of the snapshots 
4714 \emph on
4715 sdcc-yyyymmdd-xxxx-setup.exe
4716 \emph default
4717  from 
4718 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4719
4720 \end_inset
4721
4722  and execute it.
4723  A windows typical installer will guide you through the installation process.
4724 \end_layout
4725
4726 \begin_layout Subsection
4727 VPATH
4728 \begin_inset LatexCommand \index{VPATH}
4729
4730 \end_inset
4731
4732  feature
4733 \end_layout
4734
4735 \begin_layout Standard
4736 SDCC supports the VPATH feature provided by configure and make.
4737  It allows to separate the source and build trees.
4738  Here's an example:
4739 \end_layout
4740
4741 \begin_layout Standard
4742
4743 \family typewriter
4744 cd ~\InsetSpace ~
4745 \InsetSpace ~
4746 \InsetSpace ~
4747 \InsetSpace ~
4748 \InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 \InsetSpace ~
4758 \InsetSpace ~
4759 \InsetSpace ~
4760 \InsetSpace ~
4761 \InsetSpace ~
4762 \InsetSpace ~
4763 \InsetSpace ~
4764 \InsetSpace ~
4765 # cd $HOME
4766 \end_layout
4767
4768 \begin_layout Standard
4769
4770 \family typewriter
4771 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4772 # extract source to directory sdcc
4773 \end_layout
4774
4775 \begin_layout Standard
4776
4777 \family typewriter
4778 mkdir sdcc.build\InsetSpace ~
4779 \InsetSpace ~
4780 \InsetSpace ~
4781 \InsetSpace ~
4782 \InsetSpace ~
4783 \InsetSpace ~
4784 \InsetSpace ~
4785 \InsetSpace ~
4786 \InsetSpace ~
4787 # put output in sdcc.build
4788 \end_layout
4789
4790 \begin_layout Standard
4791
4792 \family typewriter
4793 cd sdcc.build
4794 \end_layout
4795
4796 \begin_layout Standard
4797
4798 \family typewriter
4799 ../sdcc/configure\InsetSpace ~
4800 \InsetSpace ~
4801 \InsetSpace ~
4802 \InsetSpace ~
4803 \InsetSpace ~
4804 \InsetSpace ~
4805 \InsetSpace ~
4806 \InsetSpace ~
4807 # configure is doing all the magic!
4808 \end_layout
4809
4810 \begin_layout Standard
4811
4812 \family typewriter
4813 make
4814 \end_layout
4815
4816 \begin_layout Standard
4817 \noindent
4818 That's it! 
4819 \series bold
4820 configure
4821 \series default
4822  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4823  It automagically computes the variables srcdir, top_srcdir and top_buildir
4824  for each directory.
4825  After running 
4826 \series bold
4827 make
4828 \series default
4829  the generated files will be in ~/sdcc.build, while the source files stay
4830  in ~/sdcc.
4831 \newline
4832 This is not only usefull for building different binaries, e.g.
4833  when cross compiling.
4834  It also gives you a much better overview in the source tree when all the
4835  generated files are not scattered between the source files.
4836  And the best thing is: if you want to change a file you can leave the original
4837  file untouched in the source directory.
4838  Simply copy it to the build directory, edit it, enter `make clean', `rm
4839  Makefile.dep' and `make'.
4840  
4841 \series bold
4842 make
4843 \series default
4844  will do the rest for you!
4845 \end_layout
4846
4847 \begin_layout Section
4848 Building the Documentation
4849 \end_layout
4850
4851 \begin_layout Standard
4852 Add -
4853 \begin_inset ERT
4854 status collapsed
4855
4856 \begin_layout Standard
4857
4858
4859 \backslash
4860 /
4861 \end_layout
4862
4863 \end_inset
4864
4865 -enable-doc to the configure arguments to build the documentation together
4866  with all the other stuff.
4867  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4868  dvips and makeindex) to get the job done.
4869  Another possibility is to change to the doc directory and to type 
4870 \family sans
4871 \series bold
4872
4873 \begin_inset Quotes srd
4874 \end_inset
4875
4876 make
4877 \begin_inset Quotes srd
4878 \end_inset
4879
4880
4881 \family default
4882 \series default
4883  there.
4884  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4885 x).
4886  Using LyX 
4887 \begin_inset LatexCommand \url{http://www.lyx.org}
4888
4889 \end_inset
4890
4891  as editor is straightforward.
4892  Prebuilt documentation in html and pdf format is available from 
4893 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4894
4895 \end_inset
4896
4897 .
4898 \end_layout
4899
4900 \begin_layout Section
4901 Reading the Documentation
4902 \begin_inset LatexCommand \index{Documentation}
4903
4904 \end_inset
4905
4906
4907 \end_layout
4908
4909 \begin_layout Standard
4910 Currently reading the document in pdf format is recommended, as for unknown
4911  reason the hyperlinks are working there whereas in the html version they
4912  are not
4913 \begin_inset Foot
4914 status open
4915
4916 \begin_layout Standard
4917 If you should know why please drop us a note
4918 \end_layout
4919
4920 \end_inset
4921
4922 .
4923  
4924 \newline
4925 You'll find the pdf version
4926 \begin_inset LatexCommand \index{PDF version of this document}
4927
4928 \end_inset
4929
4930  at 
4931 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4932
4933 \end_inset
4934
4935 .
4936  
4937 \newline
4938 A html version
4939 \begin_inset LatexCommand \index{HTML version of this document}
4940
4941 \end_inset
4942
4943  should be online at 
4944 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4945
4946 \end_inset
4947
4948 .
4949 \newline
4950 This documentation is in some aspects different from a commercial documentation:
4951  
4952 \end_layout
4953
4954 \begin_layout Itemize
4955 It tries to document SDCC for several processor architectures in one document
4956  (commercially these probably would be separate documents/products).
4957  This document
4958 \begin_inset LatexCommand \index{Status of documentation}
4959
4960 \end_inset
4961
4962  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4963 on about f.e.
4964  Z80, PIC14, PIC16 and HC08.
4965 \end_layout
4966
4967 \begin_layout Itemize
4968 There are many references pointing away from this documentation.
4969  Don't let this distract you.
4970  If there f.e.
4971  was a reference like 
4972 \begin_inset LatexCommand \url{http://www.opencores.org}
4973
4974 \end_inset
4975
4976  together with a statement 
4977 \begin_inset Quotes sld
4978 \end_inset
4979
4980 some processors which are targetted by SDCC can be implemented in a 
4981 \emph on
4982 f
4983 \emph default
4984 ield 
4985 \emph on
4986 p
4987 \emph default
4988 rogrammable 
4989 \emph on
4990 g
4991 \emph default
4992 ate 
4993 \emph on
4994 a
4995 \emph default
4996 rray
4997 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4998
4999 \end_inset
5000
5001
5002 \begin_inset Quotes srd
5003 \end_inset
5004
5005  or 
5006 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
5007
5008 \end_inset
5009
5010
5011 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
5012
5013 \end_inset
5014
5015  
5016 \begin_inset Quotes sld
5017 \end_inset
5018
5019 have you ever heard of an open source compiler that compiles a subset of
5020  C for an FPGA?
5021 \begin_inset Quotes srd
5022 \end_inset
5023
5024  we expect you to have a quick look there and come back.
5025  If you read this you are on the right track.
5026 \end_layout
5027
5028 \begin_layout Itemize
5029 Some sections attribute more space to problems, restrictions and warnings
5030  than to the solution.
5031 \end_layout
5032
5033 \begin_layout Itemize
5034 The installation section and the section about the debugger is intimidating.
5035 \end_layout
5036
5037 \begin_layout Itemize
5038 There are still lots of typos and there are more different writing styles
5039  than pictures.
5040 \end_layout
5041
5042 \begin_layout Section
5043 Testing the SDCC Compiler
5044 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5045
5046 \end_inset
5047
5048
5049 \end_layout
5050
5051 \begin_layout Standard
5052 The first thing you should do after installing your SDCC compiler is to
5053  see if it runs.
5054  Type 
5055 \family sans
5056 \series bold
5057 "sdcc -
5058 \begin_inset ERT
5059 status collapsed
5060
5061 \begin_layout Standard
5062
5063
5064 \backslash
5065 /
5066 \end_layout
5067
5068 \end_inset
5069
5070 -version"
5071 \begin_inset LatexCommand \index{version}
5072
5073 \end_inset
5074
5075
5076 \family default
5077 \series default
5078  at the prompt, and the program should run and output its version like:
5079  
5080 \newline
5081
5082 \family typewriter
5083 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5084  (UNIX)
5085 \end_layout
5086
5087 \begin_layout Standard
5088 If it doesn't run, or gives a message about not finding sdcc program, then
5089  you need to check over your installation.
5090  Make sure that the sdcc bin directory is in your executable search path
5091  defined by the PATH environment setting (
5092 \series medium
5093 see 
5094 \series default
5095 section 
5096 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5097
5098 \end_inset
5099
5100 \InsetSpace ~
5101
5102 \series medium
5103 Install trouble-shooting for suggestions
5104 \series default
5105 ).
5106  Make sure that the sdcc program is in the bin folder, if not perhaps something
5107  did not install correctly.
5108 \newline
5109
5110 \newline
5111
5112 \series medium
5113 SDCC 
5114 \series default
5115 is commonly installed as described in section 
5116 \begin_inset Quotes sld
5117 \end_inset
5118
5119 Install and search paths
5120 \begin_inset Quotes srd
5121 \end_inset
5122
5123 .
5124 \newline
5125
5126 \newline
5127
5128 \series medium
5129 Make sure the compiler works on a very simple example.
5130  Type in the following test.c program using your favorite 
5131 \series default
5132 ASCII 
5133 \series medium
5134 editor:
5135 \end_layout
5136
5137 \begin_layout Verse
5138
5139 \family typewriter
5140 char test;
5141 \newline
5142
5143 \newline
5144 void main(void) {
5145 \newline
5146 \InsetSpace ~
5147 \InsetSpace ~
5148 \InsetSpace ~
5149 \InsetSpace ~
5150 test=0;
5151 \newline
5152 }
5153 \end_layout
5154
5155 \begin_layout Standard
5156
5157 \series medium
5158 Compile this using the following command: 
5159 \family sans
5160 \series bold
5161 "sdcc -c test.c".
5162
5163 \family default
5164 \series default
5165  
5166 \series medium
5167 If all goes well, the compiler will generate a test.asm and test.rel file.
5168  Congratulations, you've just compiled your first program with SDCC.
5169  We used the -c option to tell SDCC not to link the generated code, just
5170  to keep things simple for this step.
5171 \series default
5172
5173 \newline
5174
5175 \newline
5176
5177 \series medium
5178 The next step is to try it with the linker.
5179  Type in 
5180 \family sans
5181 \series bold
5182 "sdcc test.c
5183 \family default
5184 \series default
5185 "
5186 \series medium
5187 .
5188  If all goes well the compiler will link with the libraries and produce
5189  a test.ihx output file.
5190  If this step fails
5191 \series default
5192  
5193 \series medium
5194 (no test.ihx, and the linker generates warnings), then the problem is most
5195  likely that 
5196 \series default
5197 SDCC
5198 \series medium
5199  cannot find the 
5200 \series default
5201 /
5202 \series medium
5203 usr/local/share/sdcc/lib directory
5204 \series default
5205  
5206 \series medium
5207 (see 
5208 \series default
5209 section 
5210 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5211
5212 \end_inset
5213
5214 \InsetSpace ~
5215
5216 \series medium
5217 Install trouble-shooting for suggestions).
5218 \series default
5219
5220 \newline
5221
5222 \newline
5223
5224 \series medium
5225 The final test is to ensure 
5226 \series default
5227 SDCC
5228 \series medium
5229  can use the 
5230 \series default
5231 standard
5232 \series medium
5233  header files and libraries.
5234  Edit test.c and change it to the following:
5235 \end_layout
5236
5237 \begin_layout Verse
5238
5239 \family typewriter
5240 #include <string.h>
5241 \newline
5242
5243 \newline
5244 char str1[10];
5245 \newline
5246
5247 \newline
5248 void main(void) {
5249 \newline
5250 \InsetSpace ~
5251 \InsetSpace ~
5252 strcpy(str1, "testing");
5253 \newline
5254 }
5255 \end_layout
5256
5257 \begin_layout Standard
5258
5259 \series medium
5260 Compile this by typing 
5261 \family sans
5262 \series bold
5263 "sdcc test.c"
5264 \family default
5265 \series medium
5266 .
5267  This should generate a test.ihx output file, and it should give no warnings
5268  such as not finding the string.h file.
5269  If it cannot find the string.h file, then the problem is that 
5270 \series default
5271 SDCC
5272 \series medium
5273  cannot find the /usr/local/share/sdcc/include directory
5274 \series default
5275  
5276 \series medium
5277 (see the 
5278 \series default
5279 section 
5280 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5281
5282 \end_inset
5283
5284 \InsetSpace ~
5285
5286 \series medium
5287 Install trouble-shooting section for suggestions).
5288
5289 \series default
5290  Use option 
5291 \series bold
5292 -
5293 \begin_inset ERT
5294 status collapsed
5295
5296 \begin_layout Standard
5297
5298
5299 \backslash
5300 /
5301 \end_layout
5302
5303 \end_inset
5304
5305 -print-search-dirs
5306 \series default
5307
5308 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5309
5310 \end_inset
5311
5312  to find exactly where SDCC is looking for the include and lib files.
5313 \end_layout
5314
5315 \begin_layout Section
5316 Install Trouble-shooting
5317 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5318
5319 \end_inset
5320
5321
5322 \begin_inset LatexCommand \index{Install trouble-shooting}
5323
5324 \end_inset
5325
5326
5327 \end_layout
5328
5329 \begin_layout Subsection
5330 If SDCC does not build correctly
5331 \end_layout
5332
5333 \begin_layout Standard
5334 A thing to try is starting from scratch by unpacking the .tgz source package
5335  again in an empty directory.
5336  Configure it like:
5337 \newline
5338
5339 \newline
5340
5341 \family sans
5342 \series bold
5343 ./configure 2>&1 | tee configure.log
5344 \family default
5345 \series default
5346
5347 \newline
5348
5349 \newline
5350 and build it like:
5351 \newline
5352
5353 \newline
5354
5355 \family sans
5356 \series bold
5357 make 2>&1 | tee make.log
5358 \family default
5359 \series default
5360
5361 \newline
5362
5363 \newline
5364 If anything goes wrong, you can review the log files to locate the problem.
5365  Or a relevant part of this can be attached to an email that could be helpful
5366  when requesting help from the mailing list.
5367 \end_layout
5368
5369 \begin_layout Subsection
5370 What the 
5371 \begin_inset Quotes sld
5372 \end_inset
5373
5374 ./configure
5375 \begin_inset Quotes srd
5376 \end_inset
5377
5378  does
5379 \end_layout
5380
5381 \begin_layout Standard
5382 The 
5383 \begin_inset Quotes sld
5384 \end_inset
5385
5386 ./configure
5387 \begin_inset Quotes srd
5388 \end_inset
5389
5390  command is a script that analyzes your system and performs some configuration
5391  to ensure the source package compiles on your system.
5392  It will take a few minutes to run, and will compile a few tests to determine
5393  what compiler features are installed.
5394 \end_layout
5395
5396 \begin_layout Subsection
5397 What the 
5398 \begin_inset Quotes sld
5399 \end_inset
5400
5401 make
5402 \begin_inset Quotes srd
5403 \end_inset
5404
5405  does
5406 \end_layout
5407
5408 \begin_layout Standard
5409 This runs the GNU make tool, which automatically compiles all the source
5410  packages into the final installed binary executables.
5411 \end_layout
5412
5413 \begin_layout Subsection
5414 What the 
5415 \begin_inset Quotes sld
5416 \end_inset
5417
5418 make install
5419 \begin_inset Quotes erd
5420 \end_inset
5421
5422  command does.
5423 \end_layout
5424
5425 \begin_layout Standard
5426 This will install the compiler, other executables libraries and include
5427  files into the appropriate directories.
5428  See sections 
5429 \begin_inset LatexCommand \ref{sub:Install-paths}
5430
5431 \end_inset
5432
5433 ,\InsetSpace ~
5434
5435 \begin_inset LatexCommand \ref{sub:Search-Paths}
5436
5437 \end_inset
5438
5439 \InsetSpace ~
5440 about install and search paths.
5441 \newline
5442 On most systems you will need super-user privilege
5443 s to do this.
5444 \end_layout
5445
5446 \begin_layout Section
5447 Components of SDCC
5448 \end_layout
5449
5450 \begin_layout Standard
5451 SDCC is not just a compiler, but a collection of tools by various developers.
5452  These include linkers, assemblers, simulators and other components.
5453  Here is a summary of some of the components.
5454  Note that the included simulator and assembler have separate documentation
5455  which you can find in the source package in their respective directories.
5456  As SDCC grows to include support for other processors, other packages from
5457  various developers are included and may have their own sets of documentation.
5458 \newline
5459
5460 \newline
5461 You
5462  might want to look at the files which are installed in <installdir>.
5463  At the time of this writing, we find the following programs for gcc-builds:
5464 \newline
5465
5466  
5467 \newline
5468 In <installdir>/bin:
5469 \end_layout
5470
5471 \begin_layout Itemize
5472 sdcc - The compiler.
5473 \end_layout
5474
5475 \begin_layout Itemize
5476 sdcpp - The C preprocessor.
5477 \end_layout
5478
5479 \begin_layout Itemize
5480 asx8051 - The assembler for 8051 type processors.
5481 \end_layout
5482
5483 \begin_layout Itemize
5484 as-z80
5485 \series bold
5486
5487 \series default
5488 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5489 \end_layout
5490
5491 \begin_layout Itemize
5492 aslink -The linker for 8051 type processors.
5493 \end_layout
5494
5495 \begin_layout Itemize
5496 link-z80
5497 \series bold
5498
5499 \series default
5500 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5501 \end_layout
5502
5503 \begin_layout Itemize
5504 s51 - The ucSim 8051 simulator.
5505 \end_layout
5506
5507 \begin_layout Itemize
5508 sdcdb - The source debugger.
5509 \end_layout
5510
5511 \begin_layout Itemize
5512 packihx - A tool to pack (compress) Intel hex files.
5513 \end_layout
5514
5515 \begin_layout Standard
5516 In <installdir>/share/sdcc/include
5517 \end_layout
5518
5519 \begin_layout Itemize
5520 the include files
5521 \end_layout
5522
5523 \begin_layout Standard
5524 In <installdir>/share/sdcc/lib
5525 \end_layout
5526
5527 \begin_layout Itemize
5528 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5529  relocatables.
5530 \end_layout
5531
5532 \begin_layout Standard
5533 In <installdir>/share/sdcc/doc
5534 \end_layout
5535
5536 \begin_layout Itemize
5537 the documentation
5538 \end_layout
5539
5540 \begin_layout Standard
5541 As development for other processors proceeds, this list will expand to include
5542  executables to support processors like AVR, PIC, etc.
5543 \end_layout
5544
5545 \begin_layout Subsection
5546 sdcc - The Compiler
5547 \end_layout
5548
5549 \begin_layout Standard
5550 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5551  the assembler and linkage editor.
5552 \end_layout
5553
5554 \begin_layout Subsection
5555 sdcpp - The C-Preprocessor
5556 \end_layout
5557
5558 \begin_layout Standard
5559 The preprocessor
5560 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5561
5562 \end_inset
5563
5564  is a modified version of the GNU cpp
5565 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5566
5567 \end_inset
5568
5569  preprocessor 
5570 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5571
5572 \end_inset
5573
5574 .
5575  The C preprocessor is used to pull in #include sources, process #ifdef
5576  statements, #defines and so on.
5577 \end_layout
5578
5579 \begin_layout Subsection
5580 as
5581 \emph on
5582 xxxx
5583 \emph default
5584 , aslink, link-
5585 \emph on
5586 xxx
5587 \emph default
5588  - The Assemblers and Linkage Editors
5589 \end_layout
5590
5591 \begin_layout Standard
5592 This is retargettable assembler & linkage editor, it was developed by Alan
5593  Baldwin.
5594  John Hartman created the version for 8051, and I (Sandeep) have made some
5595  enhancements and bug fixes for it to work properly with SDCC.
5596 \end_layout
5597
5598 \begin_layout Subsection
5599 s51 - The Simulator
5600 \end_layout
5601
5602 \begin_layout Standard
5603 S51
5604 \begin_inset LatexCommand \index{s51}
5605
5606 \end_inset
5607
5608  is a free open source simulator developed by Daniel Drotos.
5609  The simulator is built as part of the build process.
5610  For more information visit Daniel's web site at: 
5611 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5612
5613 \end_inset
5614
5615 .
5616  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5617  XA51 family.
5618 \end_layout
5619
5620 \begin_layout Subsection
5621 sdcdb - Source Level Debugger
5622 \end_layout
5623
5624 \begin_layout Standard
5625 SDCDB
5626 \begin_inset LatexCommand \index{SDCDB (debugger)}
5627
5628 \end_inset
5629
5630  is the companion source level debugger.
5631  More about SDCDB in section 
5632 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5633
5634 \end_inset
5635
5636 .
5637  The current version of the debugger uses Daniel's Simulator S51
5638 \begin_inset LatexCommand \index{s51}
5639
5640 \end_inset
5641
5642 , but can be easily changed to use other simulators.
5643 \end_layout
5644
5645 \begin_layout Chapter
5646 Using SDCC
5647 \end_layout
5648
5649 \begin_layout Section
5650 Compiling
5651 \end_layout
5652
5653 \begin_layout Subsection
5654 Single Source File Projects
5655 \end_layout
5656
5657 \begin_layout Standard
5658 For single source file 8051 projects the process is very simple.
5659  Compile your programs with the following command 
5660 \family sans
5661 \series bold
5662 "sdcc sourcefile.c".
5663
5664 \family default
5665 \series default
5666  This will compile, assemble and link your source file.
5667  Output files are as follows:
5668 \end_layout
5669
5670 \begin_layout Itemize
5671 sourcefile.asm
5672 \begin_inset LatexCommand \index{<file>.asm}
5673
5674 \end_inset
5675
5676  - Assembler source
5677 \begin_inset LatexCommand \index{Assembler source}
5678
5679 \end_inset
5680
5681  file created by the compiler
5682 \end_layout
5683
5684 \begin_layout Itemize
5685 sourcefile.lst
5686 \begin_inset LatexCommand \index{<file>.lst}
5687
5688 \end_inset
5689
5690  - Assembler listing
5691 \begin_inset LatexCommand \index{Assembler listing}
5692
5693 \end_inset
5694
5695  file created by the Assembler
5696 \end_layout
5697
5698 \begin_layout Itemize
5699 sourcefile.rst
5700 \begin_inset LatexCommand \index{<file>.rst}
5701
5702 \end_inset
5703
5704  - Assembler listing
5705 \begin_inset LatexCommand \index{Assembler listing}
5706
5707 \end_inset
5708
5709  file updated with linkedit information, created by linkage editor
5710 \end_layout
5711
5712 \begin_layout Itemize
5713 sourcefile.sym
5714 \begin_inset LatexCommand \index{<file>.sym}
5715
5716 \end_inset
5717
5718  - symbol listing
5719 \begin_inset LatexCommand \index{Symbol listing}
5720
5721 \end_inset
5722
5723  for the sourcefile, created by the assembler
5724 \end_layout
5725
5726 \begin_layout Itemize
5727 sourcefile.rel
5728 \begin_inset LatexCommand \index{<file>.rel}
5729
5730 \end_inset
5731
5732  or sourcefile.o
5733 \begin_inset LatexCommand \index{<file>.o}
5734
5735 \end_inset
5736
5737  - Object file
5738 \begin_inset LatexCommand \index{Object file}
5739
5740 \end_inset
5741
5742  created by the assembler, input to Linkage editor
5743 \end_layout
5744
5745 \begin_layout Itemize
5746 sourcefile.map
5747 \begin_inset LatexCommand \index{<file>.map}
5748
5749 \end_inset
5750
5751  - The memory map
5752 \begin_inset LatexCommand \index{Memory map}
5753
5754 \end_inset
5755
5756  for the load module, created by the Linker
5757 \end_layout
5758
5759 \begin_layout Itemize
5760 sourcefile.mem
5761 \begin_inset LatexCommand \index{<file>.mem}
5762
5763 \end_inset
5764
5765  - A file with a summary of the memory usage
5766 \end_layout
5767
5768 \begin_layout Itemize
5769 sourcefile.ihx
5770 \begin_inset LatexCommand \index{<file>.ihx}
5771
5772 \end_inset
5773
5774  - The load module in Intel hex format
5775 \begin_inset LatexCommand \index{Intel hex format}
5776
5777 \end_inset
5778
5779  (you can select the Motorola S19 format
5780 \begin_inset LatexCommand \index{Motorola S19 format}
5781
5782 \end_inset
5783
5784  with -
5785 \begin_inset ERT
5786 status collapsed
5787
5788 \begin_layout Standard
5789
5790
5791 \backslash
5792 /
5793 \end_layout
5794
5795 \end_inset
5796
5797 -out-fmt-s19
5798 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5799
5800 \end_inset
5801
5802 .
5803  If you need another format you might want to use 
5804 \family sans
5805 \shape italic
5806 objdump
5807 \family default
5808 \shape default
5809
5810 \begin_inset LatexCommand \index{objdump (tool)}
5811
5812 \end_inset
5813
5814  or
5815 \family sans
5816 \shape italic
5817  srecord
5818 \family default
5819 \shape default
5820
5821 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5822
5823 \end_inset
5824
5825
5826 \begin_inset Note Note
5827 status collapsed
5828
5829 \begin_layout Standard
5830 hyperlinks needed
5831 \end_layout
5832
5833 \end_inset
5834
5835  - see also section 
5836 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5837
5838 \end_inset
5839
5840 ).
5841  Both formats are documented in the documentation of srecord
5842 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5843
5844 \end_inset
5845
5846
5847 \end_layout
5848
5849 \begin_layout Itemize
5850 sourcefile.adb
5851 \begin_inset LatexCommand \index{<file>.adb}
5852
5853 \end_inset
5854
5855  - An intermediate file containing debug information needed to create the
5856  .cdb file (with -
5857 \begin_inset ERT
5858 status collapsed
5859
5860 \begin_layout Standard
5861
5862
5863 \backslash
5864 /
5865 \end_layout
5866
5867 \end_inset
5868
5869 -debug
5870 \begin_inset LatexCommand \index{-\/-debug}
5871
5872 \end_inset
5873
5874
5875 \end_layout
5876
5877 \begin_layout Itemize
5878 sourcefile.cdb
5879 \begin_inset LatexCommand \index{<file>.cdb}
5880
5881 \end_inset
5882
5883  - An optional file (with -
5884 \begin_inset ERT
5885 status collapsed
5886
5887 \begin_layout Standard
5888
5889
5890 \backslash
5891 /
5892 \end_layout
5893
5894 \end_inset
5895
5896 -debug) containing debug information.
5897  The format is documented in cdbfileformat.pdf
5898 \end_layout
5899
5900 \begin_layout Itemize
5901 sourcefile.
5902  - (no extension)
5903 \begin_inset LatexCommand \index{<file> (no extension)}
5904
5905 \end_inset
5906
5907  An optional AOMF or AOMF51
5908 \begin_inset LatexCommand \index{AOMF, AOMF51}
5909
5910 \end_inset
5911
5912  
5913 \begin_inset LatexCommand \label{OMF file}
5914
5915 \end_inset
5916
5917 file containing debug information (generated with option -
5918 \begin_inset ERT
5919 status collapsed
5920
5921 \begin_layout Standard
5922
5923
5924 \backslash
5925 /
5926 \end_layout
5927
5928 \end_inset
5929
5930 -debug).
5931  The (Intel)
5932 \emph on
5933  a
5934 \emph default
5935 bsolute 
5936 \emph on
5937 o
5938 \emph default
5939 bject 
5940 \emph on
5941 m
5942 \emph default
5943 odule 
5944 \emph on
5945 f
5946 \emph default
5947 ormat is a subformat of the OMF51 format and is commonly used by third party
5948  tools (debuggers
5949 \begin_inset LatexCommand \index{Debugger}
5950
5951 \end_inset
5952
5953 , simulators, emulators).
5954 \end_layout
5955
5956 \begin_layout Itemize
5957 sourcefile.dump*
5958 \begin_inset LatexCommand \index{<file>.dump*}
5959
5960 \end_inset
5961
5962  - Dump file to debug the compiler it self (generated with option -
5963 \begin_inset ERT
5964 status collapsed
5965
5966 \begin_layout Standard
5967
5968
5969 \backslash
5970 /
5971 \end_layout
5972
5973 \end_inset
5974
5975 -dumpall) (see section 
5976 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5977
5978 \end_inset
5979
5980 \InsetSpace ~
5981  and section 
5982 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5983
5984 \end_inset
5985
5986 \InsetSpace ~
5987
5988 \begin_inset Quotes sld
5989 \end_inset
5990
5991 Anatomy of the compiler
5992 \begin_inset Quotes srd
5993 \end_inset
5994
5995 ).
5996 \end_layout
5997
5998 \begin_layout Subsection
5999 Postprocessing the Intel Hex
6000 \begin_inset LatexCommand \index{Intel hex format}
6001
6002 \end_inset
6003
6004  file
6005 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
6006
6007 \end_inset
6008
6009
6010 \end_layout
6011
6012 \begin_layout Standard
6013 In most cases this won't be needed but the Intel Hex file
6014 \begin_inset LatexCommand \index{<file>.ihx}
6015
6016 \end_inset
6017
6018  which is generated by SDCC might include lines of varying length and the
6019  addresses within the file are not guaranteed to be strictly ascending.
6020  If your toolchain or a bootloader does not like this you can use the tool
6021  
6022 \family typewriter
6023 packihx
6024 \family default
6025
6026 \begin_inset LatexCommand \index{packihx (tool)}
6027
6028 \end_inset
6029
6030  which is part of the SDCC distribution: 
6031 \newline
6032
6033 \newline
6034
6035 \family sans
6036 \series bold
6037  packihx sourcefile.ihx >sourcefile.hex
6038 \family default
6039 \series default
6040
6041 \newline
6042
6043 \newline
6044 The separately available
6045 \emph on
6046  srecord
6047 \emph default
6048
6049 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6050
6051 \end_inset
6052
6053  package additionally allows to set undefined locations to a predefined
6054  value, to insert checksums
6055 \begin_inset LatexCommand \index{checksum}
6056
6057 \end_inset
6058
6059  of various flavours (crc, add, xor) and to perform other manipulations
6060  (convert, split, crop, offset, ...).
6061  
6062 \newline
6063
6064 \newline
6065
6066 \family sans
6067 \series bold
6068 srec_cat\InsetSpace ~
6069 \InsetSpace ~
6070 sourcefile.ihx -intel\InsetSpace ~
6071 \InsetSpace ~
6072 -o sourcefile.hex -intel
6073 \newline
6074
6075 \newline
6076
6077 \family default
6078 \series default
6079 An example for a more complex command line
6080 \begin_inset Foot
6081 status open
6082
6083 \begin_layout Standard
6084 the command backfills
6085 \begin_inset LatexCommand \index{backfill unused memory}
6086
6087 \end_inset
6088
6089  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6090  block is zero.
6091  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6092  will be interpreted as an 
6093 \family typewriter
6094 lcall
6095 \family default
6096  to address 
6097 \family typewriter
6098 0x1212
6099 \family default
6100  (where an emergency routine could sit).
6101 \end_layout
6102
6103 \end_inset
6104
6105  could look like:
6106 \newline
6107
6108 \newline
6109
6110 \family sans
6111 \series bold
6112 \size footnotesize
6113 srec_cat\InsetSpace ~
6114 sourcefile.ihx -intel\InsetSpace ~
6115 \InsetSpace ~
6116 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6117 -little-endian-checksum-nega
6118 tive 0xfffe 0x02 0x02\InsetSpace ~
6119 \InsetSpace ~
6120 -o sourcefile.hex -intel
6121 \size default
6122
6123 \newline
6124
6125 \newline
6126
6127 \family default
6128 \series default
6129 The srecord package is available at 
6130 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6131
6132 \end_inset
6133
6134  .
6135 \end_layout
6136
6137 \begin_layout Subsection
6138 Projects with Multiple Source Files
6139 \end_layout
6140
6141 \begin_layout Standard
6142 SDCC can compile only ONE file at a time.
6143  Let us for example assume that you have a project containing the following
6144  files:
6145 \newline
6146
6147 \newline
6148 foo1.c (contains some functions)
6149 \newline
6150 foo2.c (contains some more functions)
6151 \newline
6152 foomai
6153 n.c (contains more functions and the function main)
6154 \newline
6155
6156 \size footnotesize
6157
6158 \newline
6159
6160 \size default
6161 The first two files will need to be compiled separately with the commands:
6162 \size footnotesize
6163  
6164 \size default
6165
6166 \newline
6167
6168 \newline
6169
6170 \family sans
6171 \series bold
6172 sdcc\InsetSpace ~
6173 -c\InsetSpace ~
6174 foo1.c
6175 \family default
6176 \series default
6177 \size footnotesize
6178
6179 \newline
6180
6181 \family sans
6182 \series bold
6183 \size default
6184 sdcc\InsetSpace ~
6185 -c\InsetSpace ~
6186 foo2.c
6187 \family default
6188 \series default
6189
6190 \newline
6191
6192 \newline
6193 Then compile the source file containing the 
6194 \emph on
6195 main()
6196 \emph default
6197  function and link
6198 \begin_inset LatexCommand \index{Linker}
6199
6200 \end_inset
6201
6202  the files together with the following command: 
6203 \newline
6204
6205 \newline
6206
6207 \family sans
6208 \series bold
6209 sdcc\InsetSpace ~
6210 foomain.c\InsetSpace ~
6211 foo1.rel\InsetSpace ~
6212 foo2.rel
6213 \family default
6214 \series default
6215
6216 \begin_inset LatexCommand \index{<file>.rel}
6217
6218 \end_inset
6219
6220
6221 \newline
6222
6223 \newline
6224 Alternatively, 
6225 \emph on
6226 foomain.c 
6227 \emph default
6228 can be separately compiled as well: 
6229 \family sans
6230 \series bold
6231
6232 \newline
6233
6234 \newline
6235 sdcc\InsetSpace ~
6236 -c\InsetSpace ~
6237 foomain.c
6238 \newline
6239 sdcc foomain.rel foo1.rel foo2.rel
6240 \newline
6241
6242 \newline
6243
6244 \family default
6245 \series default
6246 The file containing the 
6247 \emph on
6248 main()
6249 \emph default
6250  function
6251 \emph on
6252  
6253 \emph default
6254 \noun on
6255 must
6256 \noun default
6257  be the 
6258 \noun on
6259 first
6260 \noun default
6261  file specified in the command line, since the linkage editor processes
6262  file in the order they are presented to it.
6263  The linker is invoked from SDCC using a script file with extension .lnk
6264 \begin_inset LatexCommand \index{<file>.lnk}
6265
6266 \end_inset
6267
6268 .
6269  You can view this file to troubleshoot linking problems such as those arising
6270  from missing libraries.
6271 \end_layout
6272
6273 \begin_layout Subsection
6274 Projects with Additional Libraries
6275 \begin_inset LatexCommand \index{Libraries}
6276
6277 \end_inset
6278
6279
6280 \end_layout
6281
6282 \begin_layout Standard
6283 Some reusable routines may be compiled into a library, see the documentation
6284  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6285  for how to create a 
6286 \emph on
6287 .lib
6288 \begin_inset LatexCommand \index{<file>.lib}
6289
6290 \end_inset
6291
6292
6293 \emph default
6294  library file.
6295  Libraries created in this manner can be included in the command line.
6296  Make sure you include the -L <library-path> option to tell the linker where
6297  to look for these files if they are not in the current directory.
6298  Here is an example, assuming you have the source file 
6299 \emph on
6300 foomain.c
6301 \emph default
6302  and a library
6303 \emph on
6304  foolib.lib
6305 \emph default
6306  in the directory 
6307 \emph on
6308 mylib
6309 \emph default
6310  (if that is not the same as your current project):
6311 \newline
6312
6313 \newline
6314
6315 \family sans
6316 \series bold
6317 sdcc foomain.c foolib.lib -L mylib
6318 \newline
6319
6320 \newline
6321
6322 \family default
6323 \series default
6324 Note here that
6325 \emph on
6326  mylib
6327 \emph default
6328  must be an absolute path name.
6329 \newline
6330
6331 \newline
6332 The most efficient way to use libraries is
6333  to keep separate modules in separate source files.
6334  The lib file now should name all the modules.rel
6335 \begin_inset LatexCommand \index{<file>.rel}
6336
6337 \end_inset
6338
6339  files.
6340  For an example see the standard library file 
6341 \emph on
6342 libsdcc.lib
6343 \emph default
6344  in the directory <installdir>/share/lib/small.
6345 \end_layout
6346
6347 \begin_layout Subsection
6348 Using sdcclib to Create and Manage Libraries
6349 \begin_inset LatexCommand \index{sdcclib}
6350
6351 \end_inset
6352
6353
6354 \end_layout
6355
6356 \begin_layout Standard
6357 Alternatively, instead of having a .rel file for each entry on the library
6358  file as described in the preceding section, sdcclib can be used to embed
6359  all the modules belonging to such library in the library file itself.
6360  This results in a larger library file, but it greatly reduces the number
6361  of disk files accessed by the linker.
6362   Additionally, the packed library file contains an index of all include
6363  modules and symbols that significantly speeds up the linking process.
6364  To display a list of options supported by sdcclib type:
6365 \newline
6366
6367 \end_layout
6368
6369 \begin_layout Standard
6370
6371 \family sans
6372 \series bold
6373 sdcclib -?
6374 \begin_inset LatexCommand \index{sdcclib}
6375
6376 \end_inset
6377
6378
6379 \newline
6380
6381 \newline
6382
6383 \family default
6384 \series default
6385 To create a new library file, start by compiling all the required modules.
6386  For example:
6387 \newline
6388
6389 \end_layout
6390
6391 \begin_layout Standard
6392
6393 \family sans
6394 \series bold
6395 sdcc -c _divsint.c
6396 \end_layout
6397
6398 \begin_layout Standard
6399
6400 \family sans
6401 \series bold
6402 sdcc -c _divuint.c
6403 \end_layout
6404
6405 \begin_layout Standard
6406
6407 \family sans
6408 \series bold
6409 sdcc -c _modsint.c
6410 \end_layout
6411
6412 \begin_layout Standard
6413
6414 \family sans
6415 \series bold
6416 sdcc -c _moduint.c
6417 \end_layout
6418
6419 \begin_layout Standard
6420
6421 \family sans
6422 \series bold
6423 sdcc -c _mulint.c
6424 \newline
6425
6426 \end_layout
6427
6428 \begin_layout Standard
6429 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6430  and _mulint.rel.
6431  The next step is to add the .rel files to the library file:
6432 \newline
6433
6434 \end_layout
6435
6436 \begin_layout Standard
6437
6438 \family sans
6439 \series bold
6440 sdcclib libint.lib _divsint.rel
6441 \family default
6442
6443 \begin_inset LatexCommand \index{sdcclib}
6444
6445 \end_inset
6446
6447
6448 \end_layout
6449
6450 \begin_layout Standard
6451
6452 \family sans
6453 \series bold
6454 sdcclib libint.lib _divuint.rel
6455 \end_layout
6456
6457 \begin_layout Standard
6458
6459 \family sans
6460 \series bold
6461 sdcclib libint.lib _modsint.rel
6462 \end_layout
6463
6464 \begin_layout Standard
6465
6466 \family sans
6467 \series bold
6468 sdcclib libint.lib _moduint.rel
6469 \end_layout
6470
6471 \begin_layout Standard
6472
6473 \family sans
6474 \series bold
6475 sdcclib libint.lib _mulint.rel
6476 \family default
6477 \series default
6478
6479 \newline
6480
6481 \end_layout
6482
6483 \begin_layout Standard
6484 Or, if you preffer:
6485 \family sans
6486 \series bold
6487
6488 \newline
6489
6490 \end_layout
6491
6492 \begin_layout Standard
6493
6494 \family sans
6495 \series bold
6496 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6497 \family default
6498 \series default
6499
6500 \newline
6501
6502 \end_layout
6503
6504 \begin_layout Standard
6505 If the file already exists in the library, it will be replaced.
6506  If a list of .rel files is available, you can tell sdcclib to add those
6507  files to a library.
6508  For example, if the file 'myliblist.txt' contains
6509 \family sans
6510 \series bold
6511
6512 \newline
6513
6514 \end_layout
6515
6516 \begin_layout Standard
6517
6518 \family sans
6519 \series bold
6520 _divsint.rel
6521 \end_layout
6522
6523 \begin_layout Standard
6524
6525 \family sans
6526 \series bold
6527 _divuint.rel
6528 \end_layout
6529
6530 \begin_layout Standard
6531
6532 \family sans
6533 \series bold
6534 _modsint.rel
6535 \end_layout
6536
6537 \begin_layout Standard
6538
6539 \family sans
6540 \series bold
6541 _moduint.rel
6542 \end_layout
6543
6544 \begin_layout Standard
6545
6546 \family sans
6547 \series bold
6548 _mulint.rel
6549 \family default
6550 \series default
6551
6552 \newline
6553
6554 \end_layout
6555
6556 \begin_layout Standard
6557 Use
6558 \family sans
6559 \series bold
6560
6561 \newline
6562
6563 \end_layout
6564
6565 \begin_layout Standard
6566
6567 \family sans
6568 \series bold
6569 sdcclib -l libint.lib myliblist.txt
6570 \family default
6571 \series default
6572
6573 \newline
6574
6575 \end_layout
6576
6577 \begin_layout Standard
6578 Additionally, you can instruct sdcclib to compiles the files before adding
6579  them to the library.
6580  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6581  For example:
6582 \family sans
6583 \series bold
6584
6585 \newline
6586
6587 \end_layout
6588
6589 \begin_layout Standard
6590
6591 \family sans
6592 \series bold
6593 set SDCCLIB_CC=sdcc -c
6594 \end_layout
6595
6596 \begin_layout Standard
6597
6598 \family sans
6599 \series bold
6600 sdcclib -l libint.lib myliblist.txt
6601 \family default
6602 \series default
6603
6604 \newline
6605
6606 \end_layout
6607
6608 \begin_layout Standard
6609 To see what modules and symbols are included in the library, options -s
6610  and -m are available.
6611  For example:
6612 \newline
6613
6614 \newline
6615
6616 \family sans
6617 \series bold
6618 sdcclib -s libint.lib
6619 \family default
6620
6621 \begin_inset LatexCommand \index{sdcclib}
6622
6623 \end_inset
6624
6625
6626 \newline
6627
6628 \family typewriter
6629 \series default
6630 _divsint.rel:
6631 \end_layout
6632
6633 \begin_layout Standard
6634
6635 \family typewriter
6636 __divsint_a_1_1
6637 \end_layout
6638
6639 \begin_layout Standard
6640
6641 \family typewriter
6642 __divsint_PARM_2
6643 \end_layout
6644
6645 \begin_layout Standard
6646
6647 \family typewriter
6648 __divsint
6649 \newline
6650 _divuint.rel:
6651 \end_layout
6652
6653 \begin_layout Standard
6654
6655 \family typewriter
6656 __divuint_a_1_1
6657 \end_layout
6658
6659 \begin_layout Standard
6660
6661 \family typewriter
6662 __divuint_PARM_2
6663 \end_layout
6664
6665 \begin_layout Standard
6666
6667 \family typewriter
6668 __divuint_reste_1_1
6669 \end_layout
6670
6671 \begin_layout Standard
6672
6673 \family typewriter
6674 __divuint_count_1_1
6675 \end_layout
6676
6677 \begin_layout Standard
6678
6679 \family typewriter
6680 __divuint
6681 \newline
6682 _modsint.rel:
6683 \end_layout
6684
6685 \begin_layout Standard
6686
6687 \family typewriter
6688 __modsint_a_1_1
6689 \end_layout
6690
6691 \begin_layout Standard
6692
6693 \family typewriter
6694 __modsint_PARM_2
6695 \end_layout
6696
6697 \begin_layout Standard
6698
6699 \family typewriter
6700 __modsint
6701 \newline
6702 _moduint.rel:
6703 \end_layout
6704
6705 \begin_layout Standard
6706
6707 \family typewriter
6708 __moduint_a_1_1
6709 \end_layout
6710
6711 \begin_layout Standard
6712
6713 \family typewriter
6714 __moduint_PARM_2
6715 \end_layout
6716
6717 \begin_layout Standard
6718
6719 \family typewriter
6720 __moduint_count_1_1
6721 \end_layout
6722
6723 \begin_layout Standard
6724
6725 \family typewriter
6726 __moduint
6727 \newline
6728 _mulint.rel:
6729 \end_layout
6730
6731 \begin_layout Standard
6732
6733 \family typewriter
6734 __mulint_PARM_2
6735 \end_layout
6736
6737 \begin_layout Standard
6738
6739 \family typewriter
6740 __mulint
6741 \family default
6742 \series bold
6743
6744 \newline
6745
6746 \end_layout
6747
6748 \begin_layout Standard
6749 If the source files are compiled using -
6750 \begin_inset ERT
6751 status collapsed
6752
6753 \begin_layout Standard
6754
6755
6756 \backslash
6757 /
6758 \end_layout
6759
6760 \end_inset
6761
6762 -debug
6763 \begin_inset LatexCommand \index{-\/-debug}
6764
6765 \end_inset
6766
6767 , the corresponding debug information file .adb will be include in the library
6768  file as well.
6769  The library files created with sdcclib are plain text files, so they can
6770  be viewed with a text editor.
6771  It is not recomended to modify a library file created with sdcclib using
6772  a text editor, as there are file indexes numbers located accross the file
6773  used by the linker to quickly locate the required module to link.
6774  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6775  it can be safely deleted, since all the information required for linking
6776  is embedded in the library file itself.
6777  Library files created using sdcclib are used as described in the preceding
6778  sections.
6779 \begin_inset VSpace bigskip
6780 \end_inset
6781
6782
6783 \end_layout
6784
6785 \begin_layout Section
6786 Command Line Options
6787 \begin_inset LatexCommand \index{Command Line Options}
6788
6789 \end_inset
6790
6791
6792 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6793
6794 \end_inset
6795
6796
6797 \end_layout
6798
6799 \begin_layout Subsection
6800 Processor Selection Options
6801 \begin_inset LatexCommand \index{Options processor selection}
6802
6803 \end_inset
6804
6805
6806 \begin_inset LatexCommand \index{Processor selection options}
6807
6808 \end_inset
6809
6810
6811 \end_layout
6812
6813 \begin_layout List
6814 \labelwidthstring 00.00.0000
6815
6816 \series bold
6817 -mmcs51
6818 \begin_inset LatexCommand \index{-mmcs51}
6819
6820 \end_inset
6821
6822
6823 \series default
6824  Generate code for the Intel MCS51
6825 \begin_inset LatexCommand \index{MCS51}
6826
6827 \end_inset
6828
6829  family of processors.
6830  This is the default processor target.
6831 \end_layout
6832
6833 \begin_layout List
6834 \labelwidthstring 00.00.0000
6835
6836 \series bold
6837 -mds390
6838 \begin_inset LatexCommand \index{-mds390}
6839
6840 \end_inset
6841
6842
6843 \series default
6844  Generate code for the Dallas DS80C390
6845 \begin_inset LatexCommand \index{DS80C390}
6846
6847 \end_inset
6848
6849  processor.
6850 \end_layout
6851
6852 \begin_layout List
6853 \labelwidthstring 00.00.0000
6854
6855 \series bold
6856 -mds400
6857 \begin_inset LatexCommand \index{-mds400}
6858
6859 \end_inset
6860
6861
6862 \series default
6863  Generate code for the Dallas DS80C400
6864 \begin_inset LatexCommand \index{DS80C400}
6865
6866 \end_inset
6867
6868  processor.
6869 \end_layout
6870
6871 \begin_layout List
6872 \labelwidthstring 00.00.0000
6873
6874 \series bold
6875 -mhc08
6876 \begin_inset LatexCommand \index{-mhc08}
6877
6878 \end_inset
6879
6880
6881 \series default
6882  Generate code for the Freescale/Motorola HC08
6883 \begin_inset LatexCommand \index{HC08}
6884
6885 \end_inset
6886
6887  family of processors.
6888 \end_layout
6889
6890 \begin_layout List
6891 \labelwidthstring 00.00.0000
6892
6893 \series bold
6894 -mz80
6895 \begin_inset LatexCommand \index{-mz80}
6896
6897 \end_inset
6898
6899
6900 \series default
6901  Generate code for the Zilog Z80
6902 \begin_inset LatexCommand \index{Z80}
6903
6904 \end_inset
6905
6906  family of processors.
6907 \end_layout
6908
6909 \begin_layout List
6910 \labelwidthstring 00.00.0000
6911
6912 \series bold
6913 -mgbz80
6914 \begin_inset LatexCommand \index{-mgbz80}
6915
6916 \end_inset
6917
6918
6919 \series default
6920  Generate code for the GameBoy Z80
6921 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6922
6923 \end_inset
6924
6925  processor (Not actively maintained).
6926 \end_layout
6927
6928 \begin_layout List
6929 \labelwidthstring 00.00.0000
6930
6931 \series bold
6932 -mavr
6933 \begin_inset LatexCommand \index{-mavr}
6934
6935 \end_inset
6936
6937
6938 \series default
6939  Generate code for the Atmel AVR
6940 \begin_inset LatexCommand \index{AVR}
6941
6942 \end_inset
6943
6944  processor (Not maintained, not complete).
6945  AVR users should probably have a look at winavr 
6946 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6947
6948 \end_inset
6949
6950  or 
6951 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6952
6953 \end_inset
6954
6955 , which is based on AVR-port of the gcc compiler.
6956 \end_layout
6957
6958 \begin_layout Standard
6959 \begin_inset Note Note
6960 status collapsed
6961
6962 \begin_layout Standard
6963 I think it is fair to direct users there for now.
6964  Open source is also about avoiding unnecessary work .
6965  But I didn't find the 'official' link.
6966 \end_layout
6967
6968 \end_inset
6969
6970
6971 \end_layout
6972
6973 \begin_layout List
6974 \labelwidthstring 00.00.0000
6975
6976 \series bold
6977 -mpic14
6978 \begin_inset LatexCommand \index{-mpic14}
6979
6980 \end_inset
6981
6982
6983 \series default
6984  Generate code for the Microchip PIC 14
6985 \begin_inset LatexCommand \index{PIC14}
6986
6987 \end_inset
6988
6989 -bit processors (p16f84 and variants.
6990  In development, not complete).
6991 \end_layout
6992
6993 \begin_layout Standard
6994 \begin_inset Note Note
6995 status collapsed
6996
6997 \begin_layout Standard
6998 p16f627 p16f628 p16f84 p16f873 p16f877?
6999 \end_layout
7000
7001 \end_inset
7002
7003
7004 \end_layout
7005
7006 \begin_layout List
7007 \labelwidthstring 00.00.0000
7008
7009 \series bold
7010 -mpic16
7011 \begin_inset LatexCommand \index{-mpic16}
7012
7013 \end_inset
7014
7015
7016 \series default
7017  Generate code for the Microchip PIC 16
7018 \begin_inset LatexCommand \index{PIC16}
7019
7020 \end_inset
7021
7022 -bit processors (p18f452 and variants.
7023  In development, not complete).
7024 \end_layout
7025
7026 \begin_layout List
7027 \labelwidthstring 00.00.0000
7028
7029 \series bold
7030 -mtlcs900h
7031 \series default
7032  Generate code for the Toshiba TLCS-900H
7033 \begin_inset LatexCommand \index{TLCS-900H}
7034
7035 \end_inset
7036
7037  processor (Not maintained, not complete).
7038 \end_layout
7039
7040 \begin_layout List
7041 \labelwidthstring 00.00.0000
7042
7043 \series bold
7044 -mxa51
7045 \begin_inset LatexCommand \index{-mxa51}
7046
7047 \end_inset
7048
7049
7050 \series default
7051  Generate code for the Phillips XA51
7052 \begin_inset LatexCommand \index{XA51}
7053
7054 \end_inset
7055
7056  processor (Not maintained, not complete).
7057 \end_layout
7058
7059 \begin_layout Standard
7060 \begin_inset VSpace bigskip
7061 \end_inset
7062
7063
7064 \end_layout
7065
7066 \begin_layout Subsection
7067 Preprocessor Options
7068 \begin_inset LatexCommand \index{Options preprocessor}
7069
7070 \end_inset
7071
7072
7073 \begin_inset LatexCommand \index{Preprocessor options}
7074
7075 \end_inset
7076
7077
7078 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7079
7080 \end_inset
7081
7082
7083 \end_layout
7084
7085 \begin_layout List
7086 \labelwidthstring 00.00.0000
7087
7088 \series bold
7089 -I<path>
7090 \begin_inset LatexCommand \index{-I<path>}
7091
7092 \end_inset
7093
7094
7095 \series default
7096  The additional location where the preprocessor will look for <..h> or 
7097 \begin_inset Quotes eld
7098 \end_inset
7099
7100 ..h
7101 \begin_inset Quotes erd
7102 \end_inset
7103
7104  files.
7105 \end_layout
7106
7107 \begin_layout List
7108 \labelwidthstring 00.00.0000
7109
7110 \series bold
7111 -D<macro[=value]>
7112 \begin_inset LatexCommand \index{-D<macro[=value]>}
7113
7114 \end_inset
7115
7116
7117 \series default
7118  Command line definition of macros.
7119  Passed to the preprocessor.
7120 \end_layout
7121
7122 \begin_layout List
7123 \labelwidthstring 00.00.0000
7124
7125 \series bold
7126 -M
7127 \begin_inset LatexCommand \index{-M}
7128
7129 \end_inset
7130
7131
7132 \series default
7133  Tell the preprocessor to output a rule suitable for make describing the
7134  dependencies of each object file.
7135  For each source file, the preprocessor outputs one make-rule whose target
7136  is the object file name for that source file and whose dependencies are
7137  all the files `#include'd in it.
7138  This rule may be a single line or may be continued with `
7139 \backslash
7140 '-newline if it is long.
7141  The list of rules is printed on standard output instead of the preprocessed
7142  C program.
7143  `-M' implies `-E
7144 \begin_inset LatexCommand \index{-E}
7145
7146 \end_inset
7147
7148 '.
7149 \end_layout
7150
7151 \begin_layout List
7152 \labelwidthstring 00.00.0000
7153
7154 \series bold
7155 -C
7156 \begin_inset LatexCommand \index{-C}
7157
7158 \end_inset
7159
7160
7161 \series default
7162  Tell the preprocessor not to discard comments.
7163  Used with the `-E' option.
7164 \end_layout
7165
7166 \begin_layout List
7167 \labelwidthstring 00.00.0000
7168
7169 \series bold
7170 -MM
7171 \begin_inset LatexCommand \index{-MM}
7172
7173 \end_inset
7174
7175
7176 \size large
7177 \bar under
7178  
7179 \series default
7180 \size default
7181 \bar default
7182 Like `-M' but the output mentions only the user header files included with
7183  `#include 
7184 \begin_inset Quotes eld
7185 \end_inset
7186
7187 file"'.
7188  System header files included with `#include <file>' are omitted.
7189 \end_layout
7190
7191 \begin_layout List
7192 \labelwidthstring 00.00.0000
7193
7194 \series bold
7195 -Aquestion(answer)
7196 \begin_inset LatexCommand \index{-Aquestion(answer)}
7197
7198 \end_inset
7199
7200
7201 \series default
7202  Assert the answer answer for question, in case it is tested with a preprocessor
7203  conditional such as `#if #question(answer)'.
7204  `-A-' disables the standard assertions that normally describe the target
7205  machine.
7206 \end_layout
7207
7208 \begin_layout List
7209 \labelwidthstring 00.00.0000
7210
7211 \series bold
7212 -Umacro
7213 \begin_inset LatexCommand \index{-Umacro}
7214
7215 \end_inset
7216
7217
7218 \series default
7219  Undefine macro macro.
7220  `-U' options are evaluated after all `-D' options, but before any `-include'
7221  and `-imacros' options.
7222 \end_layout
7223
7224 \begin_layout List
7225 \labelwidthstring 00.00.0000
7226
7227 \series bold
7228 -dM
7229 \begin_inset LatexCommand \index{-dM}
7230
7231 \end_inset
7232
7233
7234 \series default
7235  Tell the preprocessor to output only a list of the macro definitions that
7236  are in effect at the end of preprocessing.
7237  Used with the `-E' option.
7238 \end_layout
7239
7240 \begin_layout List
7241 \labelwidthstring 00.00.0000
7242
7243 \series bold
7244 -dD
7245 \begin_inset LatexCommand \index{-dD}
7246
7247 \end_inset
7248
7249
7250 \series default
7251  Tell the preprocessor to pass all macro definitions into the output, in
7252  their proper sequence in the rest of the output.
7253 \end_layout
7254
7255 \begin_layout List
7256 \labelwidthstring 00.00.0000
7257
7258 \series bold
7259 -dN
7260 \begin_inset LatexCommand \index{-dN}
7261
7262 \end_inset
7263
7264
7265 \size large
7266 \bar under
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Like `-dD' except that the macro arguments and contents are omitted.
7272  Only `#define name' is included in the output.
7273 \end_layout
7274
7275 \begin_layout List
7276 \labelwidthstring 00.00.0000
7277
7278 \series bold
7279 -pedantic-parse-number
7280 \begin_inset LatexCommand \index{pedantic}
7281
7282 \end_inset
7283
7284
7285 \begin_inset LatexCommand \index{-pedantic-parse-number}
7286
7287 \end_inset
7288
7289
7290 \size large
7291 \bar under
7292
7293 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7294
7295 \end_inset
7296
7297  
7298 \series default
7299 \size default
7300 \bar default
7301 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7302  and the macro LO_B(3) gets expanded.
7303  See also #pragma pedantic_parse_number 
7304 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7305
7306 \end_inset
7307
7308  in section
7309 \begin_inset LatexCommand \ref{sec:Pragmas}
7310
7311 \end_inset
7312
7313  
7314 \emph on
7315 Note: this functionality is not in conformance with C99 standard!
7316 \end_layout
7317
7318 \begin_layout List
7319 \labelwidthstring 00.00.0000
7320
7321 \series bold
7322 -Wp\InsetSpace ~
7323 preprocessorOption[,preprocessorOption]
7324 \series default
7325
7326 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7327
7328 \end_inset
7329
7330 ...
7331  Pass the preprocessorOption to the preprocessor 
7332 \family typewriter
7333 sdcpp
7334 \family default
7335
7336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7337
7338 \end_inset
7339
7340 .
7341  SDCC uses an adapted version of the preprocessor 
7342 \emph on
7343 cpp
7344 \emph default
7345  of the GNU Compiler Collection
7346 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7347
7348 \end_inset
7349
7350  (
7351 \emph on
7352 gcc
7353 \emph default
7354  
7355 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7356
7357 \end_inset
7358
7359 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7360 4.1.1\InsetSpace ~
7361 CPP\InsetSpace ~
7362 Manual
7363  at 
7364 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7365
7366 \end_inset
7367
7368 .
7369 \end_layout
7370
7371 \begin_layout Standard
7372 \begin_inset VSpace bigskip
7373 \end_inset
7374
7375
7376 \end_layout
7377
7378 \begin_layout Subsection
7379 Linker Options
7380 \begin_inset LatexCommand \index{Options linker}
7381
7382 \end_inset
7383
7384
7385 \begin_inset LatexCommand \index{Linker options}
7386
7387 \end_inset
7388
7389
7390 \end_layout
7391
7392 \begin_layout List
7393 \labelwidthstring 00.00.0000
7394
7395 \series bold
7396 -L\InsetSpace ~
7397 -
7398 \series default
7399
7400 \begin_inset ERT
7401 status collapsed
7402
7403 \begin_layout Standard
7404
7405
7406 \backslash
7407 /
7408 \end_layout
7409
7410 \end_inset
7411
7412
7413 \series bold
7414 -lib-path
7415 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7416
7417 \end_inset
7418
7419
7420 \begin_inset LatexCommand \index{-L -\/-lib-path}
7421
7422 \end_inset
7423
7424
7425 \series default
7426 \InsetSpace ~
7427 <absolute path to additional libraries> This option is passed to the linkage
7428  editor's additional libraries
7429 \begin_inset LatexCommand \index{Libraries}
7430
7431 \end_inset
7432
7433  search path.
7434  The path name must be absolute.
7435  Additional library files may be specified in the command line.
7436  See section Compiling programs for more details.
7437 \end_layout
7438
7439 \begin_layout List
7440 \labelwidthstring 00.00.0000
7441
7442 \series bold
7443 -
7444 \begin_inset ERT
7445 status collapsed
7446
7447 \begin_layout Standard
7448
7449
7450 \backslash
7451 /
7452 \end_layout
7453
7454 \end_inset
7455
7456 -xram-loc
7457 \series default
7458
7459 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7460
7461 \end_inset
7462
7463 \InsetSpace ~
7464 <Value> The start location of the external ram
7465 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7466
7467 \end_inset
7468
7469 , default value is 0.
7470  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7471 \begin_inset ERT
7472 status collapsed
7473
7474 \begin_layout Standard
7475
7476
7477 \backslash
7478 /
7479 \end_layout
7480
7481 \end_inset
7482
7483 -xram-loc 0x8000 or -
7484 \begin_inset ERT
7485 status collapsed
7486
7487 \begin_layout Standard
7488
7489
7490 \backslash
7491 /
7492 \end_layout
7493
7494 \end_inset
7495
7496 -xram-loc 32768.
7497 \end_layout
7498
7499 \begin_layout List
7500 \labelwidthstring 00.00.0000
7501
7502 \series bold
7503 -
7504 \begin_inset ERT
7505 status collapsed
7506
7507 \begin_layout Standard
7508
7509
7510 \backslash
7511 /
7512 \end_layout
7513
7514 \end_inset
7515
7516 -code-loc
7517 \series default
7518
7519 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7520
7521 \end_inset
7522
7523 \InsetSpace ~
7524 <Value> The start location of the code
7525 \begin_inset LatexCommand \index{code}
7526
7527 \end_inset
7528
7529  segment, default value 0.
7530  Note when this option is used the interrupt vector table
7531 \begin_inset LatexCommand \index{interrupt vector table}
7532
7533 \end_inset
7534
7535  is also relocated to the given address.
7536  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7537 \begin_inset ERT
7538 status collapsed
7539
7540 \begin_layout Standard
7541
7542
7543 \backslash
7544 /
7545 \end_layout
7546
7547 \end_inset
7548
7549 -code-loc 0x8000 or -
7550 \begin_inset ERT
7551 status collapsed
7552
7553 \begin_layout Standard
7554
7555
7556 \backslash
7557 /
7558 \end_layout
7559
7560 \end_inset
7561
7562 -code-loc 32768.
7563 \end_layout
7564
7565 \begin_layout List
7566 \labelwidthstring 00.00.0000
7567
7568 \series bold
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
7583 \series default
7584
7585 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7586
7587 \end_inset
7588
7589 \InsetSpace ~
7590 <Value> By default the stack
7591 \begin_inset LatexCommand \index{stack}
7592
7593 \end_inset
7594
7595  is placed after the data segment.
7596  Using this option the stack can be placed anywhere in the internal memory
7597  space of the 8051.
7598  The value entered can be in Hexadecimal or Decimal format, e.g.
7599  -
7600 \begin_inset ERT
7601 status collapsed
7602
7603 \begin_layout Standard
7604
7605
7606 \backslash
7607 /
7608 \end_layout
7609
7610 \end_inset
7611
7612 -stack-loc 0x20 or -
7613 \begin_inset ERT
7614 status collapsed
7615
7616 \begin_layout Standard
7617
7618
7619 \backslash
7620 /
7621 \end_layout
7622
7623 \end_inset
7624
7625 -stack-loc 32.
7626  Since the sp register is incremented before a push or call, the initial
7627  sp will be set to one byte prior the provided value.
7628  The provided value should not overlap any other memory areas such as used
7629  register banks or the data segment and with enough space for the current
7630  application.
7631  The 
7632 \series bold
7633 -
7634 \begin_inset ERT
7635 status collapsed
7636
7637 \begin_layout Standard
7638
7639
7640 \backslash
7641 /
7642 \end_layout
7643
7644 \end_inset
7645
7646 -pack-iram
7647 \series default
7648 \InsetSpace ~
7649
7650 \begin_inset LatexCommand \index{-\/-pack-iram}
7651
7652 \end_inset
7653
7654  option (which is now a default setting) will override this setting, so
7655  you should also specify the 
7656 \series bold
7657 -
7658 \begin_inset ERT
7659 status collapsed
7660
7661 \begin_layout Standard
7662
7663
7664 \backslash
7665 /
7666 \end_layout
7667
7668 \end_inset
7669
7670 -no-pack-iram
7671 \series default
7672 \InsetSpace ~
7673
7674 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7675
7676 \end_inset
7677
7678  option if you need to manually place the stack.
7679 \end_layout
7680
7681 \begin_layout List
7682 \labelwidthstring 00.00.0000
7683
7684 \series bold
7685 -
7686 \begin_inset ERT
7687 status collapsed
7688
7689 \begin_layout Standard
7690
7691
7692 \backslash
7693 /
7694 \end_layout
7695
7696 \end_inset
7697
7698 -xstack-loc
7699 \series default
7700
7701 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7702
7703 \end_inset
7704
7705 \InsetSpace ~
7706 <Value> By default the external stack
7707 \begin_inset LatexCommand \index{xstack}
7708
7709 \end_inset
7710
7711  is placed after the pdata
7712 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7713
7714 \end_inset
7715
7716  segment.
7717  Using this option the xstack can be placed anywhere in the external memory
7718  space of the 8051.
7719  The value entered can be in Hexadecimal or Decimal format, e.g.
7720  -
7721 \begin_inset ERT
7722 status collapsed
7723
7724 \begin_layout Standard
7725
7726
7727 \backslash
7728 /
7729 \end_layout
7730
7731 \end_inset
7732
7733 -xstack-loc 0x8000 or -
7734 \begin_inset ERT
7735 status collapsed
7736
7737 \begin_layout Standard
7738
7739
7740 \backslash
7741 /
7742 \end_layout
7743
7744 \end_inset
7745
7746 -stack-loc 32768.
7747  The provided value should not overlap any other memory areas such as the
7748  pdata or xdata segment and with enough space for the current application.
7749 \end_layout
7750
7751 \begin_layout List
7752 \labelwidthstring 00.00.0000
7753
7754 \series bold
7755 -
7756 \begin_inset ERT
7757 status collapsed
7758
7759 \begin_layout Standard
7760
7761
7762 \backslash
7763 /
7764 \end_layout
7765
7766 \end_inset
7767
7768 -data-loc
7769 \series default
7770
7771 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7772
7773 \end_inset
7774
7775 \InsetSpace ~
7776 <Value> The start location of the internal ram data
7777 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7778
7779 \end_inset
7780
7781  segment.
7782  The value entered can be in Hexadecimal or Decimal format, eg.
7783  -
7784 \begin_inset ERT
7785 status collapsed
7786
7787 \begin_layout Standard
7788
7789
7790 \backslash
7791 /
7792 \end_layout
7793
7794 \end_inset
7795
7796 -data-loc 0x20 or -
7797 \begin_inset ERT
7798 status collapsed
7799
7800 \begin_layout Standard
7801
7802
7803 \backslash
7804 /
7805 \end_layout
7806
7807 \end_inset
7808
7809 -data-loc 32.
7810  (By default, the start location of the internal ram data segment  is set
7811  as low as possible in memory, taking into account the used register banks
7812  and the bit segment at address 0x20.
7813  For example if register banks 0 and 1 are used without bit variables, the
7814  data segment will be set, if -
7815 \begin_inset ERT
7816 status collapsed
7817
7818 \begin_layout Standard
7819
7820
7821 \backslash
7822 /
7823 \end_layout
7824
7825 \end_inset
7826
7827 -data-loc is not used, to location 0x10.)
7828 \end_layout
7829
7830 \begin_layout List
7831 \labelwidthstring 00.00.0000
7832
7833 \series bold
7834 -
7835 \begin_inset ERT
7836 status collapsed
7837
7838 \begin_layout Standard
7839
7840
7841 \backslash
7842 /
7843 \end_layout
7844
7845 \end_inset
7846
7847 -idata-loc
7848 \series default
7849
7850 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7851
7852 \end_inset
7853
7854 \InsetSpace ~
7855 <Value> The start location of the indirectly addressable internal ram
7856 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7857
7858 \end_inset
7859
7860  of the 8051, default value is 0x80.
7861  The value entered can be in Hexadecimal or Decimal format, eg.
7862  -
7863 \begin_inset ERT
7864 status collapsed
7865
7866 \begin_layout Standard
7867
7868
7869 \backslash
7870 /
7871 \end_layout
7872
7873 \end_inset
7874
7875 -idata-loc 0x88 or -
7876 \begin_inset ERT
7877 status collapsed
7878
7879 \begin_layout Standard
7880
7881
7882 \backslash
7883 /
7884 \end_layout
7885
7886 \end_inset
7887
7888 -idata-loc 136.
7889 \end_layout
7890
7891 \begin_layout List
7892 \labelwidthstring 00.00.0000
7893
7894 \series bold
7895 -
7896 \begin_inset ERT
7897 status collapsed
7898
7899 \begin_layout Standard
7900
7901
7902 \backslash
7903 /
7904 \end_layout
7905
7906 \end_inset
7907
7908 -bit-loc
7909 \series default
7910 \InsetSpace ~
7911 <Value> The start location of the bit
7912 \begin_inset LatexCommand \index{bit}
7913
7914 \end_inset
7915
7916  addressable internal ram of the 8051.
7917  This is 
7918 \emph on
7919 not
7920 \emph default
7921  implemented yet.
7922  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7923 -bBSEG=<Value>.
7924 \end_layout
7925
7926 \begin_layout List
7927 \labelwidthstring 00.00.0000
7928
7929 \series bold
7930 -
7931 \begin_inset ERT
7932 status collapsed
7933
7934 \begin_layout Standard
7935
7936
7937 \backslash
7938 /
7939 \end_layout
7940
7941 \end_inset
7942
7943 -out-fmt-ihx
7944 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7945
7946 \end_inset
7947
7948
7949 \bar under
7950  
7951 \series default
7952 \bar default
7953 The linker output (final object code) is in Intel Hex format.
7954 \begin_inset LatexCommand \index{Intel hex format}
7955
7956 \end_inset
7957
7958  This is the default option.
7959  The format itself is documented in the documentation of srecord
7960 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7961
7962 \end_inset
7963
7964 .
7965 \end_layout
7966
7967 \begin_layout List
7968 \labelwidthstring 00.00.0000
7969
7970 \series bold
7971 -
7972 \begin_inset ERT
7973 status collapsed
7974
7975 \begin_layout Standard
7976
7977
7978 \backslash
7979 /
7980 \end_layout
7981
7982 \end_inset
7983
7984 -out-fmt-s19
7985 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7986
7987 \end_inset
7988
7989
7990 \bar under
7991  
7992 \series default
7993 \bar default
7994 The linker output (final object code) is in Motorola S19 format
7995 \begin_inset LatexCommand \index{Motorola S19 format}
7996
7997 \end_inset
7998
7999 .
8000  The format itself is documented in the documentation of srecord.
8001 \end_layout
8002
8003 \begin_layout List
8004 \labelwidthstring 00.00.0000
8005
8006 \series bold
8007 -
8008 \begin_inset ERT
8009 status collapsed
8010
8011 \begin_layout Standard
8012
8013
8014 \backslash
8015 /
8016 \end_layout
8017
8018 \end_inset
8019
8020 -out-fmt-elf
8021 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8022
8023 \end_inset
8024
8025
8026 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8027
8028 \end_inset
8029
8030
8031 \bar under
8032  
8033 \series default
8034 \bar default
8035 The linker output (final object code) is in ELF format
8036 \begin_inset LatexCommand \index{ELF format}
8037
8038 \end_inset
8039
8040 .
8041  (Currently only supported for the HC08
8042 \begin_inset LatexCommand \index{HC08}
8043
8044 \end_inset
8045
8046  processors)
8047 \end_layout
8048
8049 \begin_layout List
8050 \labelwidthstring 00.00.0000
8051
8052 \series bold
8053 -Wl\InsetSpace ~
8054 linkOption[,linkOption]
8055 \series default
8056
8057 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8058
8059 \end_inset
8060
8061
8062 \begin_inset LatexCommand \label{lyx:-Wl option}
8063
8064 \end_inset
8065
8066 ...
8067  Pass the linkOption to the linker.
8068  If a bootloader is used an option like 
8069 \begin_inset Quotes sld
8070 \end_inset
8071
8072 -Wl\InsetSpace ~
8073 -bCSEG=0x1000
8074 \begin_inset Quotes srd
8075 \end_inset
8076
8077  would be typical to set the start of the code segment.
8078  Either use the double quotes around this option or use no space (e.g.
8079  -Wl-bCSEG=0x1000).
8080  See also #pragma constseg and #pragma codeseg in section 
8081 \begin_inset LatexCommand \ref{sec:Pragmas}
8082
8083 \end_inset
8084
8085  .
8086  File sdcc/as/doc/asxhtm.html has more on linker options.
8087 \end_layout
8088
8089 \begin_layout Standard
8090 \begin_inset VSpace bigskip
8091 \end_inset
8092
8093
8094 \end_layout
8095
8096 \begin_layout Subsection
8097 MCS51 Options
8098 \begin_inset LatexCommand \index{Options MCS51}
8099
8100 \end_inset
8101
8102
8103 \begin_inset LatexCommand \index{MCS51 options}
8104
8105 \end_inset
8106
8107
8108 \end_layout
8109
8110 \begin_layout List
8111 \labelwidthstring 00.00.0000
8112
8113 \series bold
8114 -
8115 \begin_inset ERT
8116 status collapsed
8117
8118 \begin_layout Standard
8119
8120
8121 \backslash
8122 /
8123 \end_layout
8124
8125 \end_inset
8126
8127 -model-small
8128 \begin_inset LatexCommand \index{-\/-model-small}
8129
8130 \end_inset
8131
8132
8133 \series default
8134 \size large
8135 \emph on
8136  
8137 \size default
8138 \emph default
8139 Generate code for Small Model programs, see section Memory Models for more
8140  details.
8141  This is the default model.
8142 \end_layout
8143
8144 \begin_layout List
8145 \labelwidthstring 00.00.0000
8146
8147 \series bold
8148 -
8149 \begin_inset ERT
8150 status collapsed
8151
8152 \begin_layout Standard
8153
8154
8155 \backslash
8156 /
8157 \end_layout
8158
8159 \end_inset
8160
8161 -model-medium
8162 \begin_inset LatexCommand \index{-\/-model-medium}
8163
8164 \end_inset
8165
8166
8167 \series default
8168  Generate code for Medium model programs, see section Memory Models for
8169  more details.
8170  If this option is used all source files in the project have to be compiled
8171  with this option.
8172  It must also be used when invoking the linker.
8173 \end_layout
8174
8175 \begin_layout List
8176 \labelwidthstring 00.00.0000
8177
8178 \series bold
8179 -
8180 \begin_inset ERT
8181 status collapsed
8182
8183 \begin_layout Standard
8184
8185
8186 \backslash
8187 /
8188 \end_layout
8189
8190 \end_inset
8191
8192 -model-large
8193 \begin_inset LatexCommand \index{-\/-model-large}
8194
8195 \end_inset
8196
8197
8198 \series default
8199  Generate code for Large model programs, see section Memory Models for more
8200  details.
8201  If this option is used all source files in the project have to be compiled
8202  with this option.
8203  It must also be used when invoking the linker.
8204 \end_layout
8205
8206 \begin_layout List
8207 \labelwidthstring 00.00.0000
8208
8209 \series bold
8210 -
8211 \begin_inset ERT
8212 status collapsed
8213
8214 \begin_layout Standard
8215
8216
8217 \backslash
8218 /
8219 \end_layout
8220
8221 \end_inset
8222
8223 -xstack
8224 \begin_inset LatexCommand \index{-\/-xstack}
8225
8226 \end_inset
8227
8228
8229 \series default
8230  Uses a pseudo stack in the pdata
8231 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8232
8233 \end_inset
8234
8235  area (usually the first 256 bytes in the external ram) for allocating variables
8236  and passing parameters.
8237  See section 
8238 \begin_inset LatexCommand \ref{sub:External-Stack}
8239
8240 \end_inset
8241
8242 \InsetSpace ~
8243  External Stack for more details.
8244 \end_layout
8245
8246 \begin_layout List
8247 \labelwidthstring 00.00.0000
8248
8249 \series bold
8250 -
8251 \begin_inset ERT
8252 status collapsed
8253
8254 \begin_layout Standard
8255
8256
8257 \backslash
8258 /
8259 \end_layout
8260
8261 \end_inset
8262
8263 -iram-size
8264 \series default
8265 \InsetSpace ~
8266 <Value>
8267 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8268
8269 \end_inset
8270
8271  Causes the linker to check if the internal ram usage is within limits of
8272  the given value.
8273 \end_layout
8274
8275 \begin_layout List
8276 \labelwidthstring 00.00.0000
8277
8278 \series bold
8279 -
8280 \begin_inset ERT
8281 status collapsed
8282
8283 \begin_layout Standard
8284
8285
8286 \backslash
8287 /
8288 \end_layout
8289
8290 \end_inset
8291
8292 -xram-size
8293 \series default
8294 \InsetSpace ~
8295 <Value>
8296 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8297
8298 \end_inset
8299
8300  Causes the linker to check if the external ram usage is within limits of
8301  the given value.
8302 \end_layout
8303
8304 \begin_layout List
8305 \labelwidthstring 00.00.0000
8306
8307 \series bold
8308 -
8309 \begin_inset ERT
8310 status collapsed
8311
8312 \begin_layout Standard
8313
8314
8315 \backslash
8316 /
8317 \end_layout
8318
8319 \end_inset
8320
8321 -code-size
8322 \series default
8323 \InsetSpace ~
8324 <Value>
8325 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8326
8327 \end_inset
8328
8329  Causes the linker to check if the code memory usage is within limits of
8330  the given value.
8331 \end_layout
8332
8333 \begin_layout List
8334 \labelwidthstring 00.00.0000
8335
8336 \series bold
8337 -
8338 \begin_inset ERT
8339 status collapsed
8340
8341 \begin_layout Standard
8342
8343
8344 \backslash
8345 /
8346 \end_layout
8347
8348 \end_inset
8349
8350 -stack-size
8351 \series default
8352 \InsetSpace ~
8353 <Value>
8354 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8355
8356 \end_inset
8357
8358  Causes the linker to check if there is at minimum <Value> bytes for stack.
8359 \end_layout
8360
8361 \begin_layout List
8362 \labelwidthstring 00.00.0000
8363
8364 \series bold
8365 -
8366 \begin_inset ERT
8367 status collapsed
8368
8369 \begin_layout Standard
8370
8371
8372 \backslash
8373 /
8374 \end_layout
8375
8376 \end_inset
8377
8378 -pack-iram
8379 \series default
8380 \InsetSpace ~
8381
8382 \begin_inset LatexCommand \index{-\/-pack-iram}
8383
8384 \end_inset
8385
8386  Causes the linker to use unused register banks for data variables and pack
8387  data, idata and stack together.
8388  This is the default now.
8389 \end_layout
8390
8391 \begin_layout List
8392 \labelwidthstring 00.00.0000
8393
8394 \series bold
8395 -
8396 \begin_inset ERT
8397 status collapsed
8398
8399 \begin_layout Standard
8400
8401
8402 \backslash
8403 /
8404 \end_layout
8405
8406 \end_inset
8407
8408 -no-pack-iram
8409 \series default
8410 \InsetSpace ~
8411
8412 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8413
8414 \end_inset
8415
8416  Causes the linker to use old style for allocating memory areas.
8417 \end_layout
8418
8419 \begin_layout List
8420 \labelwidthstring 00.00.0000
8421
8422 \series bold
8423 -
8424 \begin_inset ERT
8425 status collapsed
8426
8427 \begin_layout Standard
8428
8429
8430 \backslash
8431 /
8432 \end_layout
8433
8434 \end_inset
8435
8436 -acall-ajmp
8437 \series default
8438 \InsetSpace ~
8439
8440 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8441
8442 \end_inset
8443
8444  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8445  acall/ajmp.
8446  Only use this option if your code is in the same 2k block of memory.
8447  You may need to use this option for some 8051 derivatives which lack the
8448  lcall/ljmp instructions..
8449 \end_layout
8450
8451 \begin_layout Standard
8452 \begin_inset VSpace bigskip
8453 \end_inset
8454
8455
8456 \end_layout
8457
8458 \begin_layout Subsection
8459 DS390 / DS400 Options
8460 \begin_inset LatexCommand \index{Options DS390}
8461
8462 \end_inset
8463
8464
8465 \begin_inset LatexCommand \index{DS390}
8466
8467 \end_inset
8468
8469
8470 \end_layout
8471
8472 \begin_layout List
8473 \labelwidthstring 00.00.0000
8474
8475 \series bold
8476 -
8477 \begin_inset ERT
8478 status collapsed
8479
8480 \begin_layout Standard
8481
8482
8483 \backslash
8484 /
8485 \end_layout
8486
8487 \end_inset
8488
8489 -model-flat24
8490 \series default
8491
8492 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8493
8494 \end_inset
8495
8496
8497 \size large
8498 \emph on
8499  
8500 \size default
8501 \emph default
8502 Generate 24-bit flat mode code.
8503  This is the one and only that the ds390 code generator supports right now
8504  and is default when using 
8505 \emph on
8506 -mds390
8507 \emph default
8508 .
8509  See section Memory Models for more details.
8510 \end_layout
8511
8512 \begin_layout List
8513 \labelwidthstring 00.00.0000
8514
8515 \series bold
8516 -
8517 \begin_inset ERT
8518 status collapsed
8519
8520 \begin_layout Standard
8521
8522
8523 \backslash
8524 /
8525 \end_layout
8526
8527 \end_inset
8528
8529 -protect-sp-update
8530 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8531
8532 \end_inset
8533
8534
8535 \series default
8536  disable interrupts during ESP:SP updates.
8537 \end_layout
8538
8539 \begin_layout List
8540 \labelwidthstring 00.00.0000
8541
8542 \series bold
8543 -
8544 \begin_inset ERT
8545 status collapsed
8546
8547 \begin_layout Standard
8548
8549
8550 \backslash
8551 /
8552 \end_layout
8553
8554 \end_inset
8555
8556 -stack-10bit
8557 \series default
8558
8559 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8560
8561 \end_inset
8562
8563  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8564  This is the one and only that the ds390 code generator supports right now
8565  and is default when using 
8566 \emph on
8567 -mds390
8568 \emph default
8569 .
8570  In this mode, the stack is located in the lower 1K of the internal RAM,
8571  which is mapped to 0x400000.
8572  Note that the support is incomplete, since it still uses a single byte
8573  as the stack pointer.
8574  This means that only the lower 256 bytes of the potential 1K stack space
8575  will actually be used.
8576  However, this does allow you to reclaim the precious 256 bytes of low RAM
8577  for use for the DATA and IDATA segments.
8578  The compiler will not generate any code to put the processor into 10 bit
8579  stack mode.
8580  It is important to ensure that the processor is in this mode before calling
8581  any re-entrant functions compiled with this option.
8582  In principle, this should work with the 
8583 \emph on
8584 -
8585 \begin_inset ERT
8586 status collapsed
8587
8588 \begin_layout Standard
8589
8590
8591 \backslash
8592 /
8593 \end_layout
8594
8595 \end_inset
8596
8597 -stack-auto
8598 \begin_inset LatexCommand \index{-\/-stack-auto}
8599
8600 \end_inset
8601
8602
8603 \emph default
8604  option, but that has not been tested.
8605  It is incompatible with the 
8606 \emph on
8607 -
8608 \begin_inset ERT
8609 status collapsed
8610
8611 \begin_layout Standard
8612
8613
8614 \backslash
8615 /
8616 \end_layout
8617
8618 \end_inset
8619
8620 -xstack
8621 \begin_inset LatexCommand \index{-\/-xstack}
8622
8623 \end_inset
8624
8625
8626 \emph default
8627  option.
8628  It also only makes sense if the processor is in 24 bit contiguous addressing
8629  mode (see the 
8630 \emph on
8631 -
8632 \begin_inset ERT
8633 status collapsed
8634
8635 \begin_layout Standard
8636
8637
8638 \backslash
8639 /
8640 \end_layout
8641
8642 \end_inset
8643
8644 -model-flat24 option
8645 \emph default
8646 ).
8647 \series bold
8648
8649 \begin_inset Note Note
8650 status collapsed
8651
8652 \begin_layout List
8653 \labelwidthstring 00.00.0000
8654
8655 \series bold
8656 -
8657 \begin_inset ERT
8658 status open
8659
8660 \begin_layout Standard
8661
8662
8663 \backslash
8664 /
8665 \end_layout
8666
8667 \end_inset
8668
8669 -stack-8-bit - switches off the 10-bit mode
8670 \end_layout
8671
8672 \end_inset
8673
8674
8675 \end_layout
8676
8677 \begin_layout List
8678 \labelwidthstring 00.00.0000
8679
8680 \series bold
8681 -
8682 \begin_inset ERT
8683 status collapsed
8684
8685 \begin_layout Standard
8686
8687
8688 \backslash
8689 /
8690 \end_layout
8691
8692 \end_inset
8693
8694 -stack-probe
8695 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8696
8697 \end_inset
8698
8699
8700 \series default
8701  insert call to function __stack_probe at each function prologue.
8702 \end_layout
8703
8704 \begin_layout List
8705 \labelwidthstring 00.00.0000
8706
8707 \series bold
8708 -
8709 \begin_inset ERT
8710 status open
8711
8712 \begin_layout Standard
8713
8714
8715 \backslash
8716 /
8717 \end_layout
8718
8719 \end_inset
8720
8721 -tini-libid
8722 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8723
8724 \end_inset
8725
8726
8727 \series default
8728  <nnnn> LibraryID used in -mTININative.
8729  
8730 \end_layout
8731
8732 \begin_layout List
8733 \labelwidthstring 00.00.0000
8734
8735 \series bold
8736 -
8737 \begin_inset ERT
8738 status collapsed
8739
8740 \begin_layout Standard
8741
8742
8743 \backslash
8744 /
8745 \end_layout
8746
8747 \end_inset
8748
8749 -use-accelerator
8750 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8751
8752 \end_inset
8753
8754
8755 \series default
8756  generate code for DS390 Arithmetic Accelerator.
8757  
8758 \end_layout
8759
8760 \begin_layout Standard
8761 \begin_inset VSpace bigskip
8762 \end_inset
8763
8764
8765 \end_layout
8766
8767 \begin_layout Subsection
8768 Z80 Options
8769 \begin_inset LatexCommand \index{Options Z80}
8770
8771 \end_inset
8772
8773
8774 \begin_inset LatexCommand \index{Z80}
8775
8776 \end_inset
8777
8778
8779 \end_layout
8780
8781 \begin_layout List
8782 \labelwidthstring 00.00.0000
8783
8784 \series bold
8785 -
8786 \begin_inset ERT
8787 status collapsed
8788
8789 \begin_layout Standard
8790
8791
8792 \backslash
8793 /
8794 \end_layout
8795
8796 \end_inset
8797
8798 -callee-saves-bc
8799 \series default
8800
8801 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8802
8803 \end_inset
8804
8805
8806 \size large
8807 \emph on
8808  
8809 \size default
8810 \emph default
8811 Force a called function to always save BC.
8812 \end_layout
8813
8814 \begin_layout List
8815 \labelwidthstring 00.00.0000
8816
8817 \series bold
8818 -
8819 \begin_inset ERT
8820 status collapsed
8821
8822 \begin_layout Standard
8823
8824
8825 \backslash
8826 /
8827 \end_layout
8828
8829 \end_inset
8830
8831 -no-std-crt0
8832 \series default
8833
8834 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8835
8836 \end_inset
8837
8838  When linking, skip the standard crt0.o object file.
8839  You must provide your own crt0.o for your system when linking.
8840 \end_layout
8841
8842 \begin_layout List
8843 \labelwidthstring 00.00.0000
8844
8845 \series bold
8846 -
8847 \begin_inset ERT
8848 status collapsed
8849
8850 \begin_layout Standard
8851
8852
8853 \backslash
8854 /
8855 \end_layout
8856
8857 \end_inset
8858
8859 -portmode=
8860 \series default
8861 <Value>
8862 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8863
8864 \end_inset
8865
8866  Determinate PORT I/O mode (<Value> is z80 or z180).
8867 \end_layout
8868
8869 \begin_layout List
8870 \labelwidthstring 00.00.0000
8871
8872 \series bold
8873 -
8874 \begin_inset ERT
8875 status collapsed
8876
8877 \begin_layout Standard
8878
8879
8880 \backslash
8881 /
8882 \end_layout
8883
8884 \end_inset
8885
8886 -asm=
8887 \series default
8888 <Value>
8889 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8890
8891 \end_inset
8892
8893  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8894 \end_layout
8895
8896 \begin_layout List
8897 \labelwidthstring 00.00.0000
8898
8899 \series bold
8900 -
8901 \begin_inset ERT
8902 status collapsed
8903
8904 \begin_layout Standard
8905
8906
8907 \backslash
8908 /
8909 \end_layout
8910
8911 \end_inset
8912
8913 -codeseg
8914 \series default
8915 \InsetSpace ~
8916 <Value>
8917 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8918
8919 \end_inset
8920
8921  Use <Value> for the code segment name.
8922 \end_layout
8923
8924 \begin_layout List
8925 \labelwidthstring 00.00.0000
8926
8927 \series bold
8928 -
8929 \begin_inset ERT
8930 status collapsed
8931
8932 \begin_layout Standard
8933
8934
8935 \backslash
8936 /
8937 \end_layout
8938
8939 \end_inset
8940
8941 -constseg
8942 \series default
8943 \InsetSpace ~
8944 <Value>
8945 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8946
8947 \end_inset
8948
8949  Use <Value> for the const segment name.
8950 \end_layout
8951
8952 \begin_layout List
8953 \labelwidthstring 00.00.0000
8954 \begin_inset VSpace bigskip
8955 \end_inset
8956
8957
8958 \end_layout
8959
8960 \begin_layout Subsection
8961 GBZ80 Options
8962 \begin_inset LatexCommand \index{Options GBZ80}
8963
8964 \end_inset
8965
8966
8967 \begin_inset LatexCommand \index{GBZ80}
8968
8969 \end_inset
8970
8971
8972 \end_layout
8973
8974 \begin_layout List
8975 \labelwidthstring 00.00.0000
8976
8977 \series bold
8978 -
8979 \begin_inset ERT
8980 status collapsed
8981
8982 \begin_layout Standard
8983
8984
8985 \backslash
8986 /
8987 \end_layout
8988
8989 \end_inset
8990
8991 -callee-saves-bc
8992 \series default
8993
8994 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8995
8996 \end_inset
8997
8998
8999 \size large
9000 \emph on
9001  
9002 \size default
9003 \emph default
9004 Force a called function to always save BC.
9005 \end_layout
9006
9007 \begin_layout List
9008 \labelwidthstring 00.00.0000
9009
9010 \series bold
9011 -
9012 \begin_inset ERT
9013 status collapsed
9014
9015 \begin_layout Standard
9016
9017
9018 \backslash
9019 /
9020 \end_layout
9021
9022 \end_inset
9023
9024 -no-std-crt0
9025 \series default
9026
9027 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9028
9029 \end_inset
9030
9031  When linking, skip the standard crt0.o object file.
9032  You must provide your own crt0.o for your system when linking.
9033 \end_layout
9034
9035 \begin_layout List
9036 \labelwidthstring 00.00.0000
9037
9038 \series bold
9039 -bo
9040 \series default
9041 \InsetSpace ~
9042 <Num>
9043 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9044
9045 \end_inset
9046
9047  Use code bank <Num>.
9048 \end_layout
9049
9050 \begin_layout List
9051 \labelwidthstring 00.00.0000
9052
9053 \series bold
9054 -ba
9055 \series default
9056 \InsetSpace ~
9057 <Num>
9058 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9059
9060 \end_inset
9061
9062  Use data bank <Num>.
9063 \end_layout
9064
9065 \begin_layout List
9066 \labelwidthstring 00.00.0000
9067
9068 \series bold
9069 -
9070 \begin_inset ERT
9071 status collapsed
9072
9073 \begin_layout Standard
9074
9075
9076 \backslash
9077 /
9078 \end_layout
9079
9080 \end_inset
9081
9082 -codeseg
9083 \series default
9084 \InsetSpace ~
9085 <Value>
9086 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9087
9088 \end_inset
9089
9090  Use <Value> for the code segment name.
9091 \end_layout
9092
9093 \begin_layout List
9094 \labelwidthstring 00.00.0000
9095
9096 \series bold
9097 -
9098 \begin_inset ERT
9099 status collapsed
9100
9101 \begin_layout Standard
9102
9103
9104 \backslash
9105 /
9106 \end_layout
9107
9108 \end_inset
9109
9110 -constseg
9111 \series default
9112 \InsetSpace ~
9113 <Value>
9114 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9115
9116 \end_inset
9117
9118  Use <Value> for the const segment name.
9119 \end_layout
9120
9121 \begin_layout Standard
9122 \begin_inset VSpace bigskip
9123 \end_inset
9124
9125
9126 \end_layout
9127
9128 \begin_layout Subsection
9129 Optimization Options
9130 \begin_inset LatexCommand \index{Options optimization}
9131
9132 \end_inset
9133
9134
9135 \begin_inset LatexCommand \index{Optimization options}
9136
9137 \end_inset
9138
9139
9140 \end_layout
9141
9142 \begin_layout List
9143 \labelwidthstring 00.00.0000
9144
9145 \series bold
9146 -
9147 \begin_inset ERT
9148 status collapsed
9149
9150 \begin_layout Standard
9151
9152
9153 \backslash
9154 /
9155 \end_layout
9156
9157 \end_inset
9158
9159 -nogcse
9160 \begin_inset LatexCommand \index{-\/-nogcse}
9161
9162 \end_inset
9163
9164
9165 \series default
9166  Will not do global subexpression elimination, this option may be used when
9167  the compiler creates undesirably large stack/data spaces to store compiler
9168  temporaries (
9169 \emph on
9170 s
9171 \emph default
9172 pill 
9173 \emph on
9174 loc
9175 \emph default
9176 ations, sloc
9177 \begin_inset LatexCommand \index{sloc (spill location)}
9178
9179 \end_inset
9180
9181 ).
9182  A warning message will be generated when this happens and the compiler
9183  will indicate the number of extra bytes it allocated.
9184  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9185 nogcse
9186 \begin_inset LatexCommand \index{\#pragma nogcse}
9187
9188 \end_inset
9189
9190  can be used to turn off global subexpression elimination
9191 \begin_inset LatexCommand \index{Subexpression elimination}
9192
9193 \end_inset
9194
9195  for a given function only.
9196 \end_layout
9197
9198 \begin_layout List
9199 \labelwidthstring 00.00.0000
9200
9201 \series bold
9202 -
9203 \begin_inset ERT
9204 status collapsed
9205
9206 \begin_layout Standard
9207
9208
9209 \backslash
9210 /
9211 \end_layout
9212
9213 \end_inset
9214
9215 -noinvariant
9216 \begin_inset LatexCommand \index{-\/-noinvariant}
9217
9218 \end_inset
9219
9220
9221 \series default
9222  Will not do loop invariant optimizations, this may be turned off for reasons
9223  explained for the previous option.
9224  For more details of loop optimizations performed see Loop Invariants in
9225  section 
9226 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9227
9228 \end_inset
9229
9230 .
9231  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9232 noinvariant
9233 \begin_inset LatexCommand \index{\#pragma noinvariant}
9234
9235 \end_inset
9236
9237  can be used to turn off invariant optimizations for a given function only.
9238 \end_layout
9239
9240 \begin_layout List
9241 \labelwidthstring 00.00.0000
9242
9243 \series bold
9244 -
9245 \begin_inset ERT
9246 status collapsed
9247
9248 \begin_layout Standard
9249
9250
9251 \backslash
9252 /
9253 \end_layout
9254
9255 \end_inset
9256
9257 -noinduction
9258 \begin_inset LatexCommand \index{-\/-noinduction}
9259
9260 \end_inset
9261
9262
9263 \series default
9264  Will not do loop induction optimizations, see section strength reduction
9265  for more details.
9266  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9267 noinduction
9268 \begin_inset LatexCommand \index{\#pragma noinduction}
9269
9270 \end_inset
9271
9272  can be used to turn off induction optimizations for a given function only.
9273 \end_layout
9274
9275 \begin_layout List
9276 \labelwidthstring 00.00.0000
9277
9278 \series bold
9279 -
9280 \begin_inset ERT
9281 status collapsed
9282
9283 \begin_layout Standard
9284
9285
9286 \backslash
9287 /
9288 \end_layout
9289
9290 \end_inset
9291
9292 -nojtbound
9293 \begin_inset LatexCommand \index{-\/-nojtbound}
9294
9295 \end_inset
9296
9297
9298 \size large
9299 \bar under
9300  
9301 \series default
9302 \size default
9303 \bar default
9304  Will not generate boundary condition check when switch statements
9305 \begin_inset LatexCommand \index{switch statement}
9306
9307 \end_inset
9308
9309  are implemented using jump-tables.
9310  See section 
9311 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9312
9313 \end_inset
9314
9315 \InsetSpace ~
9316 Switch Statements for more details.
9317  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9318 nojtbound
9319 \begin_inset LatexCommand \index{\#pragma nojtbound}
9320
9321 \end_inset
9322
9323  can be used to turn off boundary checking for jump tables for a given function
9324  only.
9325 \end_layout
9326
9327 \begin_layout List
9328 \labelwidthstring 00.00.0000
9329
9330 \series bold
9331 -
9332 \begin_inset ERT
9333 status collapsed
9334
9335 \begin_layout Standard
9336
9337
9338 \backslash
9339 /
9340 \end_layout
9341
9342 \end_inset
9343
9344 -noloopreverse
9345 \begin_inset LatexCommand \index{-\/-noloopreverse}
9346
9347 \end_inset
9348
9349
9350 \series default
9351 \size large
9352  
9353 \size default
9354 Will not do loop reversal 
9355 \begin_inset LatexCommand \index{Loop reversing}
9356
9357 \end_inset
9358
9359 optimization.
9360 \end_layout
9361
9362 \begin_layout List
9363 \labelwidthstring 00.00.0000
9364 -
9365 \begin_inset ERT
9366 status collapsed
9367
9368 \begin_layout Standard
9369
9370
9371 \backslash
9372 /
9373 \end_layout
9374
9375 \end_inset
9376
9377 -
9378 \series bold
9379 nolabelopt
9380 \series default
9381  
9382 \begin_inset LatexCommand \index{-\/-nolabelopt }
9383
9384 \end_inset
9385
9386 Will not optimize labels (makes the dumpfiles more readable).
9387 \end_layout
9388
9389 \begin_layout List
9390 \labelwidthstring 00.00.0000
9391
9392 \series bold
9393 -
9394 \begin_inset ERT
9395 status collapsed
9396
9397 \begin_layout Standard
9398
9399
9400 \backslash
9401 /
9402 \end_layout
9403
9404 \end_inset
9405
9406 -no-xinit-opt
9407 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9408
9409 \end_inset
9410
9411
9412 \series default
9413  Will not memcpy initialized data from code space into xdata space.
9414  This saves a few bytes in code space if you don't have initialized data
9415 \begin_inset LatexCommand \index{Variable initialization}
9416
9417 \end_inset
9418
9419 .
9420 \end_layout
9421
9422 \begin_layout List
9423 \labelwidthstring 00.00.0000
9424
9425 \series bold
9426 -
9427 \begin_inset ERT
9428 status collapsed
9429
9430 \begin_layout Standard
9431
9432
9433 \backslash
9434 /
9435 \end_layout
9436
9437 \end_inset
9438
9439 -nooverlay
9440 \begin_inset LatexCommand \index{-\/-nooverlay}
9441
9442 \end_inset
9443
9444
9445 \series default
9446   The compiler will not overlay parameters and local variables of any function,
9447  see section Parameters and local variables for more details.
9448 \end_layout
9449
9450 \begin_layout List
9451 \labelwidthstring 00.00.0000
9452
9453 \series bold
9454 -
9455 \begin_inset ERT
9456 status collapsed
9457
9458 \begin_layout Standard
9459
9460
9461 \backslash
9462 /
9463 \end_layout
9464
9465 \end_inset
9466
9467 -no-peep
9468 \begin_inset LatexCommand \index{-\/-no-peep}
9469
9470 \end_inset
9471
9472
9473 \series default
9474  Disable peep-hole optimization with built-in rules.
9475 \end_layout
9476
9477 \begin_layout List
9478 \labelwidthstring 00.00.0000
9479
9480 \series bold
9481 -
9482 \begin_inset ERT
9483 status collapsed
9484
9485 \begin_layout Standard
9486
9487
9488 \backslash
9489 /
9490 \end_layout
9491
9492 \end_inset
9493
9494 -peep-file
9495 \series default
9496
9497 \begin_inset LatexCommand \index{-\/-peep-file}
9498
9499 \end_inset
9500
9501 \InsetSpace ~
9502 <filename> This option can be used to use additional rules to be used by
9503  the peep hole optimizer.
9504  See section 
9505 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9506
9507 \end_inset
9508
9509 \InsetSpace ~
9510 Peep Hole optimizations for details on how to write these rules.
9511 \end_layout
9512
9513 \begin_layout List
9514 \labelwidthstring 00.00.0000
9515
9516 \series bold
9517 -
9518 \begin_inset ERT
9519 status collapsed
9520
9521 \begin_layout Standard
9522
9523
9524 \backslash
9525 /
9526 \end_layout
9527
9528 \end_inset
9529
9530 -peep-asm
9531 \begin_inset LatexCommand \index{-\/-peep-asm}
9532
9533 \end_inset
9534
9535
9536 \series default
9537  Pass the inline assembler code through the peep hole optimizer.
9538  This can cause unexpected changes to inline assembler code, please go through
9539  the peephole optimizer
9540 \begin_inset LatexCommand \index{Peephole optimizer}
9541
9542 \end_inset
9543
9544  rules defined in the source file tree '<target>/peeph.def' before using
9545  this option.
9546 \end_layout
9547
9548 \begin_layout List
9549 \labelwidthstring 00.00.0000
9550
9551 \series bold
9552 -
9553 \begin_inset ERT
9554 status collapsed
9555
9556 \begin_layout Standard
9557
9558
9559 \backslash
9560 /
9561 \end_layout
9562
9563 \end_inset
9564
9565 -opt-code-speed
9566 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9567
9568 \end_inset
9569
9570
9571 \series default
9572  The compiler will optimize code generation towards fast code, possibly
9573  at the expense of code size.
9574 \end_layout
9575
9576 \begin_layout List
9577 \labelwidthstring 00.00.0000
9578
9579 \series bold
9580 -
9581 \begin_inset ERT
9582 status collapsed
9583
9584 \begin_layout Standard
9585
9586
9587 \backslash
9588 /
9589 \end_layout
9590
9591 \end_inset
9592
9593 -opt-code-size
9594 \begin_inset LatexCommand \index{-\/-opt-code-size}
9595
9596 \end_inset
9597
9598
9599 \series default
9600  The compiler will optimize code generation towards compact code, possibly
9601  at the expense of code speed.
9602 \end_layout
9603
9604 \begin_layout Standard
9605 \begin_inset VSpace bigskip
9606 \end_inset
9607
9608
9609 \end_layout
9610
9611 \begin_layout Subsection
9612 Other Options
9613 \begin_inset LatexCommand \index{Options other}
9614
9615 \end_inset
9616
9617
9618 \end_layout
9619
9620 \begin_layout List
9621 \labelwidthstring 00.00.0000
9622
9623 \series bold
9624 -c\InsetSpace ~
9625 -
9626 \begin_inset ERT
9627 status collapsed
9628
9629 \begin_layout Standard
9630
9631
9632 \backslash
9633 /
9634 \end_layout
9635
9636 \end_inset
9637
9638 -compile-only
9639 \begin_inset LatexCommand \index{-\/-compile-only}
9640
9641 \end_inset
9642
9643
9644 \begin_inset LatexCommand \index{-c -\/-compile-only}
9645
9646 \end_inset
9647
9648
9649 \series default
9650  will compile and assemble the source, but will not call the linkage editor.
9651 \end_layout
9652
9653 \begin_layout List
9654 \labelwidthstring 00.00.0000
9655
9656 \series bold
9657 -
9658 \series default
9659
9660 \begin_inset ERT
9661 status collapsed
9662
9663 \begin_layout Standard
9664
9665
9666 \backslash
9667 /
9668 \end_layout
9669
9670 \end_inset
9671
9672
9673 \series bold
9674 -c1mode
9675 \begin_inset LatexCommand \index{-\/-c1mode}
9676
9677 \end_inset
9678
9679
9680 \series default
9681  reads the preprocessed source from standard input and compiles it.
9682  The file name for the assembler output must be specified using the -o option.
9683 \end_layout
9684
9685 \begin_layout List
9686 \labelwidthstring 00.00.0000
9687
9688 \series bold
9689 -E
9690 \begin_inset LatexCommand \index{-E}
9691
9692 \end_inset
9693
9694
9695 \series default
9696  Run only the C preprocessor.
9697  Preprocess all the C source files specified and output the results to standard
9698  output.
9699 \end_layout
9700
9701 \begin_layout List
9702 \labelwidthstring 00.00.0000
9703
9704 \series bold
9705 -o\InsetSpace ~
9706 <path/file>
9707 \begin_inset LatexCommand \index{-o <path/file>}
9708
9709 \end_inset
9710
9711  
9712 \series default
9713 The output path where everything will be placed or the file name used for
9714  all generated output files.
9715  If the parameter is a path, it must have a trailing slash (or backslash
9716  for the Windows binaries) to be recognized as a path.
9717
9718 \emph on
9719  
9720 \emph default
9721 Note for Windows users: if the path contains spaces, it should be surrounded
9722  by quotes.
9723  The trailing backslash should be doubled in order to prevent escaping the
9724  final quote, for example: 
9725 \emph on
9726 -o 
9727 \begin_inset Quotes sld
9728 \end_inset
9729
9730 F:
9731 \backslash
9732 Projects
9733 \backslash
9734 test3
9735 \backslash
9736 output 1
9737 \backslash
9738
9739 \backslash
9740
9741 \begin_inset Quotes srd
9742 \end_inset
9743
9744
9745 \emph default
9746  or put after the final quote, for example: 
9747 \emph on
9748 -o 
9749 \begin_inset Quotes sld
9750 \end_inset
9751
9752 F:
9753 \backslash
9754 Projects
9755 \backslash
9756 test3
9757 \backslash
9758 output 1
9759 \begin_inset Quotes srd
9760 \end_inset
9761
9762
9763 \backslash
9764
9765 \emph default
9766 .
9767  The path using slashes for directory delimiters can be used too, for example:
9768  
9769 \emph on
9770 -o 
9771 \begin_inset Quotes sld
9772 \end_inset
9773
9774 F:/Projects/test3/output 1/
9775 \begin_inset Quotes srd
9776 \end_inset
9777
9778
9779 \emph default
9780 .
9781 \end_layout
9782
9783 \begin_layout List
9784 \labelwidthstring 00.00.0000
9785
9786 \series bold
9787 -
9788 \begin_inset ERT
9789 status collapsed
9790
9791 \begin_layout Standard
9792
9793
9794 \backslash
9795 /
9796 \end_layout
9797
9798 \end_inset
9799
9800 -stack-auto
9801 \begin_inset LatexCommand \index{-\/-stack-auto}
9802
9803 \end_inset
9804
9805
9806 \series default
9807 \size large
9808 \emph on
9809  
9810 \size default
9811 \emph default
9812 All functions in the source file will be compiled as 
9813 \emph on
9814 reentrant
9815 \emph default
9816
9817 \begin_inset LatexCommand \index{reentrant}
9818
9819 \end_inset
9820
9821 , i.e.
9822  the parameters and local variables will be allocated on the stack
9823 \begin_inset LatexCommand \index{stack}
9824
9825 \end_inset
9826
9827 .
9828  See section 
9829 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9830
9831 \end_inset
9832
9833  Parameters and Local Variables for more details.
9834  If this option is used all source files in the project should be compiled
9835  with this option.
9836  It automatically implies -
9837 \series bold
9838
9839 \begin_inset ERT
9840 status open
9841
9842 \begin_layout Standard
9843
9844
9845 \backslash
9846 /
9847 \end_layout
9848
9849 \end_inset
9850
9851
9852 \series default
9853 -int-long-reent and -
9854 \series bold
9855
9856 \begin_inset ERT
9857 status open
9858
9859 \begin_layout Standard
9860
9861
9862 \backslash
9863 /
9864 \end_layout
9865
9866 \end_inset
9867
9868
9869 \series default
9870 -float-reent.
9871  
9872 \end_layout
9873
9874 \begin_layout List
9875 \labelwidthstring 00.00.0000
9876
9877 \series bold
9878 -
9879 \begin_inset ERT
9880 status collapsed
9881
9882 \begin_layout Standard
9883
9884
9885 \backslash
9886 /
9887 \end_layout
9888
9889 \end_inset
9890
9891 -callee-saves
9892 \begin_inset LatexCommand \index{-\/-callee-saves}
9893
9894 \end_inset
9895
9896  
9897 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9898
9899 \end_inset
9900
9901 function1[,function2][,function3]....
9902
9903 \series default
9904  The compiler by default uses a caller saves convention for register saving
9905  across function calls, however this can cause unnecessary register pushing
9906  and popping when calling small functions from larger functions.
9907  This option can be used to switch the register saving convention for the
9908  function names specified.
9909  The compiler will not save registers when calling these functions, no extra
9910  code will be generated at the entry and exit (function prologue
9911 \series bold
9912
9913 \begin_inset LatexCommand \index{function prologue}
9914
9915 \end_inset
9916
9917
9918 \series default
9919  and epilogue
9920 \series bold
9921
9922 \begin_inset LatexCommand \index{function epilogue}
9923
9924 \end_inset
9925
9926
9927 \series default
9928 ) for these functions to save and restore the registers used by these functions,
9929  this can SUBSTANTIALLY reduce code and improve run time performance of
9930  the generated code.
9931  In the future the compiler (with inter procedural analysis) will be able
9932  to determine the appropriate scheme to use for each function call.
9933  DO NOT use this option for built-in functions such as _mulint..., if this
9934  option is used for a library function the appropriate library function
9935  needs to be recompiled with the same option.
9936  If the project consists of multiple source files then all the source file
9937  should be compiled with the same -
9938 \begin_inset ERT
9939 status collapsed
9940
9941 \begin_layout Standard
9942
9943
9944 \backslash
9945 /
9946 \end_layout
9947
9948 \end_inset
9949
9950 -callee-saves option string.
9951  Also see #pragma\InsetSpace ~
9952 callee_saves 
9953 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9954
9955 \end_inset
9956
9957  
9958 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9959
9960 \end_inset
9961
9962 .
9963 \end_layout
9964
9965 \begin_layout List
9966 \labelwidthstring 00.00.0000
9967
9968 \series bold
9969 -
9970 \begin_inset ERT
9971 status collapsed
9972
9973 \begin_layout Standard
9974
9975
9976 \backslash
9977 /
9978 \end_layout
9979
9980 \end_inset
9981
9982 -all-callee-saves
9983 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9984
9985 \end_inset
9986
9987  
9988 \series default
9989 Function of
9990 \series bold
9991  
9992 \series default
9993 -
9994 \begin_inset ERT
9995 status collapsed
9996
9997 \begin_layout Standard
9998
9999
10000 \backslash
10001 /
10002 \end_layout
10003
10004 \end_inset
10005
10006 -callee-saves will be applied to all functions by default.
10007 \end_layout
10008
10009 \begin_layout List
10010 \labelwidthstring 00.00.0000
10011
10012 \series bold
10013 -
10014 \begin_inset ERT
10015 status collapsed
10016
10017 \begin_layout Standard
10018
10019
10020 \backslash
10021 /
10022 \end_layout
10023
10024 \end_inset
10025
10026 -debug
10027 \begin_inset LatexCommand \index{-\/-debug}
10028
10029 \end_inset
10030
10031
10032 \bar under
10033  
10034 \series default
10035 \bar default
10036 When this option is used the compiler will generate debug information.
10037  The debug information collected in a file with .cdb extension can be used
10038  with the SDCDB.
10039  For more information see documentation for SDCDB.
10040  Another file with no extension contains debug information in AOMF or AOMF51
10041 \begin_inset LatexCommand \index{AOMF, AOMF51}
10042
10043 \end_inset
10044
10045  format which is commonly used by third party tools.
10046 \end_layout
10047
10048 \begin_layout List
10049 \labelwidthstring 00.00.0000
10050
10051 \series bold
10052 -S
10053 \begin_inset LatexCommand \index{-S}
10054
10055 \end_inset
10056
10057
10058 \size large
10059 \bar under
10060  
10061 \series default
10062 \size default
10063 \bar default
10064 Stop after the stage of compilation proper; do not assemble.
10065  The output is an assembler code file for the input file specified.
10066 \end_layout
10067
10068 \begin_layout List
10069 \labelwidthstring 00.00.0000
10070
10071 \series bold
10072 -
10073 \begin_inset ERT
10074 status collapsed
10075
10076 \begin_layout Standard
10077
10078
10079 \backslash
10080 /
10081 \end_layout
10082
10083 \end_inset
10084
10085 -int-long-reent
10086 \begin_inset LatexCommand \index{-\/-int-long-reent}
10087
10088 \end_inset
10089
10090
10091 \series default
10092  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10093  Note by default these libraries are compiled as non-reentrant.
10094  See section Installation for more details.
10095 \end_layout
10096
10097 \begin_layout List
10098 \labelwidthstring 00.00.0000
10099
10100 \series bold
10101 -
10102 \begin_inset ERT
10103 status collapsed
10104
10105 \begin_layout Standard
10106
10107
10108 \backslash
10109 /
10110 \end_layout
10111
10112 \end_inset
10113
10114 -cyclomatic
10115 \begin_inset LatexCommand \index{-\/-cyclomatic}
10116
10117 \end_inset
10118
10119
10120 \bar under
10121  
10122 \series default
10123 \bar default
10124 This option will cause the compiler to generate an information message for
10125  each function in the source file.
10126  The message contains some 
10127 \emph on
10128 important
10129 \emph default
10130  information about the function.
10131  The number of edges and nodes the compiler detected in the control flow
10132  graph of the function, and most importantly the 
10133 \emph on
10134 cyclomatic complexity
10135 \begin_inset LatexCommand \index{Cyclomatic complexity}
10136
10137 \end_inset
10138
10139
10140 \emph default
10141  see section on Cyclomatic Complexity for more details.
10142 \end_layout
10143
10144 \begin_layout List
10145 \labelwidthstring 00.00.0000
10146
10147 \series bold
10148 -
10149 \begin_inset ERT
10150 status collapsed
10151
10152 \begin_layout Standard
10153
10154
10155 \backslash
10156 /
10157 \end_layout
10158
10159 \end_inset
10160
10161 -float-reent
10162 \begin_inset LatexCommand \index{-\/-float-reent}
10163
10164 \end_inset
10165
10166
10167 \series default
10168  Floating point library is compiled as reentrant
10169 \begin_inset LatexCommand \index{reentrant}
10170
10171 \end_inset
10172
10173 .
10174  See section Installation for more details.
10175 \end_layout
10176
10177 \begin_layout List
10178 \labelwidthstring 00.00.0000
10179
10180 \series bold
10181 -
10182 \begin_inset ERT
10183 status collapsed
10184
10185 \begin_layout Standard
10186
10187
10188 \backslash
10189 /
10190 \end_layout
10191
10192 \end_inset
10193
10194 -funsigned-char
10195 \begin_inset LatexCommand \index{-\/-funsigned-char}
10196
10197 \end_inset
10198
10199
10200 \series default
10201  The default signedness for every type is
10202 \family typewriter
10203  signed
10204 \family default
10205 .
10206  In some embedded environments the default signedness of
10207 \family typewriter
10208  char
10209 \family default
10210  is
10211 \family typewriter
10212  unsigned
10213 \family default
10214 .
10215  To set the signess for characters to unsigned, use the option -
10216 \series bold
10217
10218 \begin_inset ERT
10219 status open
10220
10221 \begin_layout Standard
10222
10223
10224 \backslash
10225 /
10226 \end_layout
10227
10228 \end_inset
10229
10230
10231 \series default
10232 -funsigned-char.
10233  If this option is set and no signedness keyword (unsigned/signed) is given,
10234  a char will be signed.
10235  All other types are unaffected.
10236 \end_layout
10237
10238 \begin_layout List
10239 \labelwidthstring 00.00.0000
10240
10241 \series bold
10242 -
10243 \begin_inset ERT
10244 status collapsed
10245
10246 \begin_layout Standard
10247
10248
10249 \backslash
10250 /
10251 \end_layout
10252
10253 \end_inset
10254
10255 -main-return
10256 \begin_inset LatexCommand \index{-\/-main-return}
10257
10258 \end_inset
10259
10260
10261 \series default
10262  This option can be used if the code generated is called by a monitor program
10263  or if the main routine includes an endless loop.
10264  This option results in slightly smaller code and saves two bytes of stack
10265  space.
10266  The return from the 'main'
10267 \begin_inset LatexCommand \index{main return}
10268
10269 \end_inset
10270
10271  function will return to the function calling main.
10272  The default setting is to lock up i.e.
10273  generate a '
10274 \family typewriter
10275 sjmp .
10276 \family default
10277 '.
10278 \end_layout
10279
10280 \begin_layout List
10281 \labelwidthstring 00.00.0000
10282
10283 \series bold
10284 -
10285 \begin_inset ERT
10286 status collapsed
10287
10288 \begin_layout Standard
10289
10290
10291 \backslash
10292 /
10293 \end_layout
10294
10295 \end_inset
10296
10297 -nostdinc
10298 \begin_inset LatexCommand \index{-\/-nostdinc}
10299
10300 \end_inset
10301
10302
10303 \series default
10304  This will prevent the compiler from passing on the default include path
10305  to the preprocessor.
10306 \end_layout
10307
10308 \begin_layout List
10309 \labelwidthstring 00.00.0000
10310
10311 \series bold
10312 -
10313 \begin_inset ERT
10314 status collapsed
10315
10316 \begin_layout Standard
10317
10318
10319 \backslash
10320 /
10321 \end_layout
10322
10323 \end_inset
10324
10325 -nostdlib
10326 \begin_inset LatexCommand \index{-\/-nostdlib}
10327
10328 \end_inset
10329
10330
10331 \series default
10332  This will prevent the compiler from passing on the default library
10333 \begin_inset LatexCommand \index{Libraries}
10334
10335 \end_inset
10336
10337  path to the linker.
10338 \end_layout
10339
10340 \begin_layout List
10341 \labelwidthstring 00.00.0000
10342
10343 \series bold
10344 -
10345 \begin_inset ERT
10346 status collapsed
10347
10348 \begin_layout Standard
10349
10350
10351 \backslash
10352 /
10353 \end_layout
10354
10355 \end_inset
10356
10357 -verbose
10358 \begin_inset LatexCommand \index{-\/-verbose}
10359
10360 \end_inset
10361
10362
10363 \series default
10364  Shows the various actions the compiler is performing.
10365 \end_layout
10366
10367 \begin_layout List
10368 \labelwidthstring 00.00.0000
10369
10370 \series bold
10371 -V
10372 \begin_inset LatexCommand \index{-V}
10373
10374 \end_inset
10375
10376
10377 \series default
10378  Shows the actual commands the compiler is executing.
10379 \end_layout
10380
10381 \begin_layout List
10382 \labelwidthstring 00.00.0000
10383
10384 \series bold
10385 -
10386 \begin_inset ERT
10387 status collapsed
10388
10389 \begin_layout Standard
10390
10391
10392 \backslash
10393 /
10394 \end_layout
10395
10396 \end_inset
10397
10398 -no-c-code-in-asm
10399 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10400
10401 \end_inset
10402
10403
10404 \series default
10405  Hides your ugly and inefficient c-code from the asm file, so you can always
10406  blame the compiler :)
10407 \end_layout
10408
10409 \begin_layout List
10410 \labelwidthstring 00.00.0000
10411
10412 \series bold
10413 -
10414 \begin_inset ERT
10415 status collapsed
10416
10417 \begin_layout Standard
10418
10419
10420 \backslash
10421 /
10422 \end_layout
10423
10424 \end_inset
10425
10426 -fverbose-asm
10427 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10428
10429 \end_inset
10430
10431
10432 \series default
10433  Include code generator and peep-hole comments in the generated asm files.
10434 \end_layout
10435
10436 \begin_layout List
10437 \labelwidthstring 00.00.0000
10438
10439 \series bold
10440 -
10441 \begin_inset ERT
10442 status collapsed
10443
10444 \begin_layout Standard
10445
10446
10447 \backslash
10448 /
10449 \end_layout
10450
10451 \end_inset
10452
10453 -no-peep-comments
10454 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10455
10456 \end_inset
10457
10458
10459 \series default
10460  Don't include peep-hole comments in the generated asm files even if -
10461 \series bold
10462
10463 \begin_inset ERT
10464 status open
10465
10466 \begin_layout Standard
10467
10468
10469 \backslash
10470 /
10471 \end_layout
10472
10473 \end_inset
10474
10475
10476 \series default
10477 -fverbose-asm option is specified.
10478 \end_layout
10479
10480 \begin_layout List
10481 \labelwidthstring 00.00.0000
10482
10483 \series bold
10484 -
10485 \begin_inset ERT
10486 status collapsed
10487
10488 \begin_layout Standard
10489
10490
10491 \backslash
10492 /
10493 \end_layout
10494
10495 \end_inset
10496
10497 -i-code-in-asm
10498 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10499
10500 \end_inset
10501
10502
10503 \series default
10504  Include i-codes in the asm file.
10505  Sounds like noise but is most helpful for debugging the compiler itself.
10506 \end_layout
10507
10508 \begin_layout List
10509 \labelwidthstring 00.00.0000
10510
10511 \series bold
10512 -
10513 \begin_inset ERT
10514 status collapsed
10515
10516 \begin_layout Standard
10517
10518
10519 \backslash
10520 /
10521 \end_layout
10522
10523 \end_inset
10524
10525 -less-pedantic
10526 \begin_inset LatexCommand \index{pedantic}
10527
10528 \end_inset
10529
10530
10531 \begin_inset LatexCommand \index{-\/-less-pedantic}
10532
10533 \end_inset
10534
10535
10536 \series default
10537
10538 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10539
10540 \end_inset
10541
10542  Disable some of the more pedantic warnings
10543 \begin_inset LatexCommand \index{Warnings}
10544
10545 \end_inset
10546
10547 .
10548  For more details, see the less_pedantic pragma 
10549 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10550
10551 \end_inset
10552
10553 .
10554 \end_layout
10555
10556 \begin_layout List
10557 \labelwidthstring 00.00.0000
10558
10559 \series bold
10560 -
10561 \begin_inset ERT
10562 status collapsed
10563
10564 \begin_layout Standard
10565
10566
10567 \backslash
10568 /
10569 \end_layout
10570
10571 \end_inset
10572
10573 -disable-warning\InsetSpace ~
10574 <nnnn>
10575 \begin_inset LatexCommand \index{-\/-disable-warning}
10576
10577 \end_inset
10578
10579
10580 \series default
10581  Disable specific warning with number <nnnn>.
10582 \end_layout
10583
10584 \begin_layout List
10585 \labelwidthstring 00.00.0000
10586
10587 \series bold
10588 -
10589 \begin_inset ERT
10590 status collapsed
10591
10592 \begin_layout Standard
10593
10594
10595 \backslash
10596 /
10597 \end_layout
10598
10599 \end_inset
10600
10601 -Werror
10602 \begin_inset LatexCommand \index{-\/-Werror}
10603
10604 \end_inset
10605
10606
10607 \series default
10608  Treat all warnings as errors.
10609 \end_layout
10610
10611 \begin_layout List
10612 \labelwidthstring 00.00.0000
10613
10614 \series bold
10615 -
10616 \begin_inset ERT
10617 status collapsed
10618
10619 \begin_layout Standard
10620
10621
10622 \backslash
10623 /
10624 \end_layout
10625
10626 \end_inset
10627
10628 -print-search-dirs
10629 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10630
10631 \end_inset
10632
10633
10634 \series default
10635  Display the directories in the compiler's search path
10636 \end_layout
10637
10638 \begin_layout List
10639 \labelwidthstring 00.00.0000
10640
10641 \series bold
10642 -
10643 \begin_inset ERT
10644 status collapsed
10645
10646 \begin_layout Standard
10647
10648
10649 \backslash
10650 /
10651 \end_layout
10652
10653 \end_inset
10654
10655 -vc
10656 \begin_inset LatexCommand \index{-\/-vc}
10657
10658 \end_inset
10659
10660
10661 \series default
10662  Display errors and warnings using MSVC style, so you can use SDCC with
10663  the visual studio IDE
10664 \begin_inset LatexCommand \index{IDE}
10665
10666 \end_inset
10667
10668 .
10669  With SDCC both offering a GCC-like (the default) and a MSVC-like
10670 \begin_inset LatexCommand \index{MSVC output style}
10671
10672 \end_inset
10673
10674  output style, integration into most programming editors should be straightforwa
10675 rd.
10676 \end_layout
10677
10678 \begin_layout List
10679 \labelwidthstring 00.00.0000
10680
10681 \series bold
10682 -
10683 \begin_inset ERT
10684 status collapsed
10685
10686 \begin_layout Standard
10687
10688
10689 \backslash
10690 /
10691 \end_layout
10692
10693 \end_inset
10694
10695 -use-stdout
10696 \begin_inset LatexCommand \index{-\/-use-stdout}
10697
10698 \end_inset
10699
10700
10701 \series default
10702  Send errors and warnings to stdout instead of stderr.
10703 \end_layout
10704
10705 \begin_layout List
10706 \labelwidthstring 00.00.0000
10707
10708 \series bold
10709 -Wa\InsetSpace ~
10710 asmOption[,asmOption]
10711 \series default
10712
10713 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10714
10715 \end_inset
10716
10717 ...
10718  Pass the asmOption to the assembler
10719 \begin_inset LatexCommand \index{Options assembler}
10720
10721 \end_inset
10722
10723
10724 \begin_inset LatexCommand \index{Assembler options}
10725
10726 \end_inset
10727
10728 .
10729  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10730 \end_layout
10731
10732 \begin_layout List
10733 \labelwidthstring 00.00.0000
10734
10735 \series bold
10736 -
10737 \begin_inset ERT
10738 status collapsed
10739
10740 \begin_layout Standard
10741
10742
10743 \backslash
10744 /
10745 \end_layout
10746
10747 \end_inset
10748
10749 -std-sdcc89
10750 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10751
10752 \end_inset
10753
10754
10755 \series default
10756  Generally follow the C89 standard, but allow SDCC features that conflict
10757  with the standard (default).
10758 \end_layout
10759
10760 \begin_layout List
10761 \labelwidthstring 00.00.0000
10762
10763 \series bold
10764 -
10765 \begin_inset ERT
10766 status collapsed
10767
10768 \begin_layout Standard
10769
10770
10771 \backslash
10772 /
10773 \end_layout
10774
10775 \end_inset
10776
10777 -std-c89
10778 \begin_inset LatexCommand \index{-\/-std-c89}
10779
10780 \end_inset
10781
10782
10783 \series default
10784  Follow the C89 standard and disable SDCC features that conflict with the
10785  standard.
10786 \end_layout
10787
10788 \begin_layout List
10789 \labelwidthstring 00.00.0000
10790
10791 \series bold
10792 -
10793 \begin_inset ERT
10794 status collapsed
10795
10796 \begin_layout Standard
10797
10798
10799 \backslash
10800 /
10801 \end_layout
10802
10803 \end_inset
10804
10805 -std-sdcc99
10806 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10807
10808 \end_inset
10809
10810
10811 \series default
10812  Generally follow the C99 standard, but allow SDCC features that conflict
10813  with the standard (incomplete support).
10814 \end_layout
10815
10816 \begin_layout List
10817 \labelwidthstring 00.00.0000
10818
10819 \series bold
10820 -
10821 \begin_inset ERT
10822 status collapsed
10823
10824 \begin_layout Standard
10825
10826
10827 \backslash
10828 /
10829 \end_layout
10830
10831 \end_inset
10832
10833 -std-c99
10834 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10835
10836 \end_inset
10837
10838
10839 \series default
10840  Follow the C99 standard and disable SDCC features that conflict with the
10841  standard (incomplete support).
10842 \end_layout
10843
10844 \begin_layout List
10845 \labelwidthstring 00.00.0000
10846
10847 \series bold
10848 -
10849 \begin_inset ERT
10850 status collapsed
10851
10852 \begin_layout Standard
10853
10854
10855 \backslash
10856 /
10857 \end_layout
10858
10859 \end_inset
10860
10861 -codeseg
10862 \series default
10863
10864 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10865
10866 \end_inset
10867
10868
10869 \begin_inset LatexCommand \label{lyx:-codeseg}
10870
10871 \end_inset
10872
10873 \InsetSpace ~
10874 <Name> The name to be used for the code
10875 \begin_inset LatexCommand \index{code}
10876
10877 \end_inset
10878
10879  segment, default CSEG.
10880  This is useful if you need to tell the compiler to put the code in a special
10881  segment so you can later on tell the linker to put this segment in a special
10882  place in memory.
10883  Can be used for instance when using bank switching to put the code in a
10884  bank.
10885 \end_layout
10886
10887 \begin_layout List
10888 \labelwidthstring 00.00.0000
10889
10890 \series bold
10891 -
10892 \begin_inset ERT
10893 status collapsed
10894
10895 \begin_layout Standard
10896
10897
10898 \backslash
10899 /
10900 \end_layout
10901
10902 \end_inset
10903
10904 -constseg
10905 \series default
10906
10907 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10908
10909 \end_inset
10910
10911 \InsetSpace ~
10912 <Name> The name to be used for the const
10913 \begin_inset LatexCommand \index{const}
10914
10915 \end_inset
10916
10917  segment, default CONST.
10918  This is useful if you need to tell the compiler to put the const data in
10919  a special segment so you can later on tell the linker to put this segment
10920  in a special place in memory.
10921  Can be used for instance when using bank switching to put the const data
10922  in a bank.
10923 \end_layout
10924
10925 \begin_layout List
10926 \labelwidthstring 00.00.0000
10927
10928 \series bold
10929 -
10930 \begin_inset ERT
10931 status collapsed
10932
10933 \begin_layout Standard
10934
10935
10936 \backslash
10937 /
10938 \end_layout
10939
10940 \end_inset
10941
10942 -fdollars-in-identifiers
10943 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10944
10945 \end_inset
10946
10947
10948 \series default
10949  Permit '$' as an identifier character.
10950 \end_layout
10951
10952 \begin_layout List
10953 \labelwidthstring 00.00.0000
10954
10955 \series bold
10956 -
10957 \begin_inset ERT
10958 status collapsed
10959
10960 \begin_layout Standard
10961
10962
10963 \backslash
10964 /
10965 \end_layout
10966
10967 \end_inset
10968
10969 -more-pedantic
10970 \series default
10971
10972 \begin_inset LatexCommand \index{-\/-more-pedantic}
10973
10974 \end_inset
10975
10976
10977 \begin_inset LatexCommand \index{pedantic}
10978
10979 \end_inset
10980
10981  Actually this is 
10982 \series bold
10983 \emph on
10984 not
10985 \series default
10986 \emph default
10987  a SDCC compiler option but if you want 
10988 \emph on
10989 more
10990 \emph default
10991  warnings you can use a separate tool dedicated to syntax checking like
10992  splint
10993 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10994
10995 \end_inset
10996
10997
10998 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10999
11000 \end_inset
11001
11002  
11003 \begin_inset LatexCommand \url{http://www.splint.org}
11004
11005 \end_inset
11006
11007 .
11008  To make your source files parseable by splint you will have to include
11009  
11010 \family sans
11011 lint.h
11012 \family default
11013
11014 \begin_inset LatexCommand \index{splint (syntax checking tool)}
11015
11016 \end_inset
11017
11018  in your source file and add brackets around extended keywords (like 
11019 \family sans
11020
11021 \begin_inset Quotes sld
11022 \end_inset
11023
11024 __at\InsetSpace ~
11025
11026 \series bold
11027 (
11028 \series default
11029 0xab
11030 \series bold
11031 )
11032 \series default
11033
11034 \begin_inset Quotes srd
11035 \end_inset
11036
11037
11038 \family default
11039  and 
11040 \family sans
11041
11042 \begin_inset Quotes sld
11043 \end_inset
11044
11045 __interrupt\InsetSpace ~
11046 (2)
11047 \begin_inset Quotes srd
11048 \end_inset
11049
11050
11051 \family default
11052 ).
11053  
11054 \newline
11055 Splint has an excellent on line manual at 
11056 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11057
11058 \end_inset
11059
11060  and it's capabilities go beyond pure syntax checking.
11061  You'll need to tell splint the location of SDCC's include files so a typical
11062  command line could look like this: 
11063 \newline
11064
11065 \family sans
11066 splint\InsetSpace ~
11067 -I\InsetSpace ~
11068 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11069 \InsetSpace ~
11070 myprogram.c
11071 \end_layout
11072
11073 \begin_layout List
11074 \labelwidthstring 00.00.0000
11075
11076 \series bold
11077 -
11078 \begin_inset ERT
11079 status collapsed
11080
11081 \begin_layout Standard
11082
11083
11084 \backslash
11085 /
11086 \end_layout
11087
11088 \end_inset
11089
11090 -short-is-8bits
11091 \series default
11092
11093 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11094
11095 \end_inset
11096
11097
11098 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11099
11100 \end_inset
11101
11102  Treat short as 8-bit (for backward compatibility with older versions of
11103  compiler - see section 
11104 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11105
11106 \end_inset
11107
11108 )
11109 \end_layout
11110
11111 \begin_layout Standard
11112 \begin_inset VSpace bigskip
11113 \end_inset
11114
11115
11116 \end_layout
11117
11118 \begin_layout Subsection
11119 Intermediate Dump Options
11120 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11121
11122 \end_inset
11123
11124
11125 \begin_inset LatexCommand \index{Options intermediate dump}
11126
11127 \end_inset
11128
11129
11130 \begin_inset LatexCommand \index{Intermediate dump options}
11131
11132 \end_inset
11133
11134
11135 \end_layout
11136
11137 \begin_layout Standard
11138 The following options are provided for the purpose of retargetting and debugging
11139  the compiler.
11140  They provide a means to dump the intermediate code (iCode
11141 \begin_inset LatexCommand \index{iCode}
11142
11143 \end_inset
11144
11145 ) generated by the compiler in human readable form at various stages of
11146  the compilation process.
11147  More on iCodes see chapter 
11148 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11149
11150 \end_inset
11151
11152  
11153 \begin_inset Quotes srd
11154 \end_inset
11155
11156 The anatomy of the compiler
11157 \begin_inset Quotes srd
11158 \end_inset
11159
11160 .
11161 \end_layout
11162
11163 \begin_layout List
11164 \labelwidthstring 00.00.0000
11165
11166 \series bold
11167 -
11168 \begin_inset ERT
11169 status collapsed
11170
11171 \begin_layout Standard
11172
11173
11174 \backslash
11175 /
11176 \end_layout
11177
11178 \end_inset
11179
11180 -dumpraw
11181 \begin_inset LatexCommand \index{-\/-dumpraw}
11182
11183 \end_inset
11184
11185
11186 \series default
11187  This option will cause the compiler to dump the intermediate code into
11188  a file of named 
11189 \emph on
11190 <source filename>.dumpraw
11191 \emph default
11192  just after the intermediate code has been generated for a function, i.e.
11193  before any optimizations are done.
11194  The basic blocks
11195 \begin_inset LatexCommand \index{Basic blocks}
11196
11197 \end_inset
11198
11199  at this stage ordered in the depth first number, so they may not be in
11200  sequence of execution.
11201 \end_layout
11202
11203 \begin_layout List
11204 \labelwidthstring 00.00.0000
11205
11206 \series bold
11207 -
11208 \begin_inset ERT
11209 status collapsed
11210
11211 \begin_layout Standard
11212
11213
11214 \backslash
11215 /
11216 \end_layout
11217
11218 \end_inset
11219
11220 -dumpgcse
11221 \begin_inset LatexCommand \index{-\/-dumpgcse}
11222
11223 \end_inset
11224
11225
11226 \series default
11227  Will create a dump of iCodes, after global subexpression elimination
11228 \begin_inset LatexCommand \index{Global subexpression elimination}
11229
11230 \end_inset
11231
11232 , into a file named 
11233 \emph on
11234 <source filename>.dumpgcse.
11235 \end_layout
11236
11237 \begin_layout List
11238 \labelwidthstring 00.00.0000
11239
11240 \series bold
11241 -
11242 \begin_inset ERT
11243 status collapsed
11244
11245 \begin_layout Standard
11246
11247
11248 \backslash
11249 /
11250 \end_layout
11251
11252 \end_inset
11253
11254 -dumpdeadcode
11255 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11256
11257 \end_inset
11258
11259
11260 \series default
11261  Will create a dump of iCodes, after deadcode elimination
11262 \begin_inset LatexCommand \index{Dead-code elimination}
11263
11264 \end_inset
11265
11266 , into a file named 
11267 \emph on
11268 <source filename>.dumpdeadcode.
11269 \end_layout
11270
11271 \begin_layout List
11272 \labelwidthstring 00.00.0000
11273
11274 \series bold
11275 -
11276 \begin_inset ERT
11277 status collapsed
11278
11279 \begin_layout Standard
11280
11281
11282 \backslash
11283 /
11284 \end_layout
11285
11286 \end_inset
11287
11288 -dumploop
11289 \begin_inset LatexCommand \index{-\/-dumploop}
11290
11291 \end_inset
11292
11293
11294 \series default
11295 \size large
11296  
11297 \size default
11298 Will create a dump of iCodes, after loop optimizations
11299 \begin_inset LatexCommand \index{Loop optimization}
11300
11301 \end_inset
11302
11303 , into a file named 
11304 \emph on
11305 <source filename>.dumploop.
11306 \end_layout
11307
11308 \begin_layout List
11309 \labelwidthstring 00.00.0000
11310
11311 \series bold
11312 -
11313 \begin_inset ERT
11314 status collapsed
11315
11316 \begin_layout Standard
11317
11318
11319 \backslash
11320 /
11321 \end_layout
11322
11323 \end_inset
11324
11325 -dumprange
11326 \begin_inset LatexCommand \index{-\/-dumprange}
11327
11328 \end_inset
11329
11330
11331 \series default
11332 \size large
11333  
11334 \size default
11335 Will create a dump of iCodes, after live range analysis
11336 \begin_inset LatexCommand \index{Live range analysis}
11337
11338 \end_inset
11339
11340 , into a file named 
11341 \emph on
11342 <source filename>.dumprange.
11343 \end_layout
11344
11345 \begin_layout List
11346 \labelwidthstring 00.00.0000
11347
11348 \series bold
11349 -
11350 \begin_inset ERT
11351 status collapsed
11352
11353 \begin_layout Standard
11354
11355
11356 \backslash
11357 /
11358 \end_layout
11359
11360 \end_inset
11361
11362 -dumlrange
11363 \begin_inset LatexCommand \index{-\/-dumlrange}
11364
11365 \end_inset
11366
11367
11368 \series default
11369  Will dump the life ranges
11370 \begin_inset LatexCommand \index{Live range analysis}
11371
11372 \end_inset
11373
11374  for all symbols.
11375 \end_layout
11376
11377 \begin_layout List
11378 \labelwidthstring 00.00.0000
11379
11380 \series bold
11381 -
11382 \begin_inset ERT
11383 status collapsed
11384
11385 \begin_layout Standard
11386
11387
11388 \backslash
11389 /
11390 \end_layout
11391
11392 \end_inset
11393
11394 -dumpregassign
11395 \begin_inset LatexCommand \index{-\/-dumpregassign}
11396
11397 \end_inset
11398
11399
11400 \bar under
11401  
11402 \series default
11403 \bar default
11404 Will create a dump of iCodes, after register assignment
11405 \begin_inset LatexCommand \index{Register assignment}
11406
11407 \end_inset
11408
11409 , into a file named 
11410 \emph on
11411 <source filename>.dumprassgn.
11412 \end_layout
11413
11414 \begin_layout List
11415 \labelwidthstring 00.00.0000
11416
11417 \series bold
11418 -
11419 \begin_inset ERT
11420 status collapsed
11421
11422 \begin_layout Standard
11423
11424
11425 \backslash
11426 /
11427 \end_layout
11428
11429 \end_inset
11430
11431 -dumplrange
11432 \begin_inset LatexCommand \index{-\/-dumplrange}
11433
11434 \end_inset
11435
11436
11437 \series default
11438  Will create a dump of the live ranges of iTemp's
11439 \end_layout
11440
11441 \begin_layout List
11442 \labelwidthstring 00.00.0000
11443
11444 \series bold
11445 -
11446 \begin_inset ERT
11447 status collapsed
11448
11449 \begin_layout Standard
11450
11451
11452 \backslash
11453 /
11454 \end_layout
11455
11456 \end_inset
11457
11458 -dumpall
11459 \begin_inset LatexCommand \index{-\/-dumpall}
11460
11461 \end_inset
11462
11463
11464 \size large
11465 \bar under
11466  
11467 \series default
11468 \size default
11469 \bar default
11470 Will cause all the above mentioned dumps to be created.
11471 \end_layout
11472
11473 \begin_layout Standard
11474 \begin_inset VSpace bigskip
11475 \end_inset
11476
11477
11478 \end_layout
11479
11480 \begin_layout Subsection
11481 Redirecting output on Windows Shells
11482 \end_layout
11483
11484 \begin_layout Standard
11485 By default SDCC writes its error messages to 
11486 \begin_inset Quotes sld
11487 \end_inset
11488
11489 standard error
11490 \begin_inset Quotes srd
11491 \end_inset
11492
11493 .
11494  To force all messages to 
11495 \begin_inset Quotes sld
11496 \end_inset
11497
11498 standard output
11499 \begin_inset Quotes srd
11500 \end_inset
11501
11502  use 
11503 \series bold
11504 -
11505 \series default
11506 \emph on
11507
11508 \begin_inset ERT
11509 status collapsed
11510
11511 \begin_layout Standard
11512
11513
11514 \backslash
11515 /
11516 \end_layout
11517
11518 \end_inset
11519
11520
11521 \series bold
11522 \emph default
11523 -
11524 \series default
11525 use-stdout
11526 \begin_inset LatexCommand \index{-\/-use-stdout}
11527
11528 \end_inset
11529
11530 .
11531  Additionally, if you happen to have visual studio installed in your windows
11532  machine, you can use it to compile your sources using a custom build and
11533  the SDCC -
11534 \emph on
11535
11536 \begin_inset ERT
11537 status collapsed
11538
11539 \begin_layout Standard
11540
11541
11542 \backslash
11543 /
11544 \end_layout
11545
11546 \end_inset
11547
11548
11549 \emph default
11550 -vc
11551 \begin_inset LatexCommand \index{-\/-vc}
11552
11553 \end_inset
11554
11555  option.
11556  Something like this should work:
11557 \newline
11558
11559 \newline
11560
11561 \series bold
11562 c:
11563 \backslash
11564 sdcc
11565 \backslash
11566 bin
11567 \backslash
11568 sdcc.exe -
11569 \series default
11570 \emph on
11571
11572 \begin_inset ERT
11573 status collapsed
11574
11575 \begin_layout Standard
11576
11577
11578 \backslash
11579 /
11580 \end_layout
11581
11582 \end_inset
11583
11584
11585 \series bold
11586 \emph default
11587 -vc -
11588 \series default
11589 \emph on
11590
11591 \begin_inset ERT
11592 status collapsed
11593
11594 \begin_layout Standard
11595
11596
11597 \backslash
11598 /
11599 \end_layout
11600
11601 \end_inset
11602
11603
11604 \series bold
11605 \emph default
11606 -model-large -c $(InputPath)
11607 \series default
11608
11609 \begin_inset VSpace bigskip
11610 \end_inset
11611
11612
11613 \end_layout
11614
11615 \begin_layout Section
11616 Environment variables
11617 \begin_inset LatexCommand \index{Environment variables}
11618
11619 \end_inset
11620
11621
11622 \end_layout
11623
11624 \begin_layout Standard
11625 SDCC recognizes the following environment variables:
11626 \end_layout
11627
11628 \begin_layout List
11629 \labelwidthstring 00.00.0000
11630
11631 \series bold
11632 SDCC_LEAVE_SIGNALS
11633 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11634
11635 \end_inset
11636
11637
11638 \series default
11639  SDCC installs a signal handler
11640 \begin_inset LatexCommand \index{signal handler}
11641
11642 \end_inset
11643
11644  to be able to delete temporary files after an user break (^C) or an exception.
11645  If this environment variable is set, SDCC won't install the signal handler
11646  in order to be able to debug SDCC.
11647 \end_layout
11648
11649 \begin_layout List
11650 \labelwidthstring 00.00.0000
11651
11652 \series bold
11653 TMP,\InsetSpace ~
11654 TEMP,\InsetSpace ~
11655 TMPDIR
11656 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11657
11658 \end_inset
11659
11660
11661 \series default
11662  Path, where temporary files will be created.
11663  The order of the variables is the search order.
11664  In a standard *nix environment these variables are not set, and there's
11665  no need to set them.
11666  On Windows it's recommended to set one of them.
11667 \end_layout
11668
11669 \begin_layout List
11670 \labelwidthstring 00.00.0000
11671
11672 \series bold
11673 SDCC_HOME
11674 \begin_inset LatexCommand \index{SDCC\_HOME}
11675
11676 \end_inset
11677
11678
11679 \series default
11680  Path, see section 
11681 \begin_inset LatexCommand \ref{sub:Install-paths}
11682
11683 \end_inset
11684
11685 \InsetSpace ~
11686
11687 \begin_inset Quotes sld
11688 \end_inset
11689
11690  Install Paths
11691 \begin_inset Quotes srd
11692 \end_inset
11693
11694 .
11695 \end_layout
11696
11697 \begin_layout List
11698 \labelwidthstring 00.00.0000
11699
11700 \series bold
11701 SDCC_INCLUDE
11702 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11703
11704 \end_inset
11705
11706
11707 \series default
11708  Path, see section 
11709 \begin_inset LatexCommand \ref{sub:Search-Paths}
11710
11711 \end_inset
11712
11713 \InsetSpace ~
11714
11715 \begin_inset Quotes sld
11716 \end_inset
11717
11718 Search Paths
11719 \begin_inset Quotes srd
11720 \end_inset
11721
11722 .
11723 \end_layout
11724
11725 \begin_layout List
11726 \labelwidthstring 00.00.0000
11727
11728 \series bold
11729 SDCC_LIB
11730 \begin_inset LatexCommand \index{SDCC\_LIB}
11731
11732 \end_inset
11733
11734
11735 \series default
11736  Path, see section 
11737 \begin_inset LatexCommand \ref{sub:Search-Paths}
11738
11739 \end_inset
11740
11741 \InsetSpace ~
11742
11743 \begin_inset Quotes sld
11744 \end_inset
11745
11746 Search Paths
11747 \begin_inset Quotes srd
11748 \end_inset
11749
11750 ..
11751 \end_layout
11752
11753 \begin_layout Standard
11754 There are some more environment variables recognized by SDCC, but these
11755  are solely used for debugging purposes.
11756  They can change or disappear very quickly, and will never be documented.
11757 \begin_inset VSpace bigskip
11758 \end_inset
11759
11760
11761 \end_layout
11762
11763 \begin_layout Section
11764 Storage Class Language Extensions
11765 \end_layout
11766
11767 \begin_layout Subsection
11768 MCS51/DS390 Storage Class
11769 \begin_inset LatexCommand \index{Storage class}
11770
11771 \end_inset
11772
11773  Language Extensions
11774 \end_layout
11775
11776 \begin_layout Standard
11777 In addition to the ANSI storage classes SDCC allows the following MCS51
11778  specific storage classes:
11779 \end_layout
11780
11781 \begin_layout Subsubsection
11782 data
11783 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11784
11785 \end_inset
11786
11787
11788 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11789
11790 \end_inset
11791
11792  / near
11793 \begin_inset LatexCommand \index{near (storage class)}
11794
11795 \end_inset
11796
11797
11798 \begin_inset LatexCommand \index{\_\_near (storage class)}
11799
11800 \end_inset
11801
11802
11803 \end_layout
11804
11805 \begin_layout Standard
11806 This is the 
11807 \series bold
11808 default
11809 \series default
11810  storage class for the Small Memory model (
11811 \emph on
11812 data
11813 \emph default
11814  and 
11815 \emph on
11816 near
11817 \emph default
11818  or the more ANSI-C compliant forms 
11819 \emph on
11820 __data
11821 \emph default
11822  and 
11823 \emph on
11824 __near
11825 \emph default
11826  can be used synonymously).
11827  Variables declared with this storage class will be allocated in the directly
11828  addressable portion of the internal RAM of a 8051, e.g.:
11829 \end_layout
11830
11831 \begin_layout Verse
11832
11833 \family typewriter
11834 __data unsigned char test_data;
11835 \end_layout
11836
11837 \begin_layout Standard
11838 Writing 0x01 to this variable generates the assembly code:
11839 \end_layout
11840
11841 \begin_layout Verse
11842
11843 \family typewriter
11844 75*00 01\InsetSpace ~
11845 \InsetSpace ~
11846 \InsetSpace ~
11847 mov\InsetSpace ~
11848 \InsetSpace ~
11849 _test_data,#0x01
11850 \end_layout
11851
11852 \begin_layout Subsubsection
11853 xdata
11854 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11855
11856 \end_inset
11857
11858
11859 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11860
11861 \end_inset
11862
11863  / far
11864 \begin_inset LatexCommand \index{far (storage class)}
11865
11866 \end_inset
11867
11868
11869 \begin_inset LatexCommand \index{\_\_far (storage class)}
11870
11871 \end_inset
11872
11873
11874 \end_layout
11875
11876 \begin_layout Standard
11877 Variables declared with this storage class will be placed in the external
11878  RAM.
11879  This is the 
11880 \series bold
11881 default
11882 \series default
11883  storage class for the Large Memory model, e.g.:
11884 \end_layout
11885
11886 \begin_layout Verse
11887
11888 \family typewriter
11889 __xdata unsigned char test_xdata;
11890 \end_layout
11891
11892 \begin_layout Standard
11893 Writing 0x01 to this variable generates the assembly code:
11894 \end_layout
11895
11896 \begin_layout Verse
11897
11898 \family typewriter
11899 90s00r00\InsetSpace ~
11900 \InsetSpace ~
11901 \InsetSpace ~
11902 mov\InsetSpace ~
11903 \InsetSpace ~
11904 dptr,#_test_xdata 
11905 \newline
11906 74\InsetSpace ~
11907 01\InsetSpace ~
11908 \InsetSpace ~
11909 \InsetSpace ~
11910 \InsetSpace ~
11911 \InsetSpace ~
11912 \InsetSpace ~
11913 mov\InsetSpace ~
11914 \InsetSpace ~
11915 a,#0x01 
11916 \newline
11917 F0\InsetSpace ~
11918 \InsetSpace ~
11919 \InsetSpace ~
11920 \InsetSpace ~
11921 \InsetSpace ~
11922 \InsetSpace ~
11923 \InsetSpace ~
11924 \InsetSpace ~
11925 \InsetSpace ~
11926 movx\InsetSpace ~
11927 @dptr,a 
11928 \end_layout
11929
11930 \begin_layout Subsubsection
11931 idata
11932 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11933
11934 \end_inset
11935
11936
11937 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11938
11939 \end_inset
11940
11941
11942 \end_layout
11943
11944 \begin_layout Standard
11945 Variables declared with this storage class will be allocated into the indirectly
11946  addressable portion of the internal ram of a 8051, e.g.:
11947 \end_layout
11948
11949 \begin_layout Verse
11950
11951 \family typewriter
11952 __idata unsigned char test_idata;
11953 \end_layout
11954
11955 \begin_layout Standard
11956 Writing 0x01 to this variable generates the assembly code:
11957 \end_layout
11958
11959 \begin_layout Verse
11960
11961 \family typewriter
11962 78r00\InsetSpace ~
11963 \InsetSpace ~
11964 \InsetSpace ~
11965 \InsetSpace ~
11966 \InsetSpace ~
11967 \InsetSpace ~
11968 \InsetSpace ~
11969 mov\InsetSpace ~
11970 \InsetSpace ~
11971 r0,#_test_idata
11972 \newline
11973 76\InsetSpace ~
11974 01\InsetSpace ~
11975 \InsetSpace ~
11976 \InsetSpace ~
11977 \InsetSpace ~
11978 \InsetSpace ~
11979 \InsetSpace ~
11980 \InsetSpace ~
11981 mov\InsetSpace ~
11982 \InsetSpace ~
11983 @r0,#0x01
11984 \end_layout
11985
11986 \begin_layout Standard
11987 Please note, the first 128 byte of idata physically access the same RAM
11988  as the data memory.
11989  The original 8051 had 128 byte idata memory, nowadays most devices have
11990  256 byte idata memory.
11991  The stack
11992 \begin_inset LatexCommand \index{stack}
11993
11994 \end_inset
11995
11996  is located in idata memory.
11997 \end_layout
11998
11999 \begin_layout Subsubsection
12000 pdata
12001 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
12002
12003 \end_inset
12004
12005
12006 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
12007
12008 \end_inset
12009
12010
12011 \end_layout
12012
12013 \begin_layout Standard
12014 Paged xdata access is just as straightforward as using the other addressing
12015  modes of a 8051.
12016  It is typically located at the start of xdata and has a maximum size of
12017  256 bytes.
12018  The following example writes 0x01 to the pdata variable.
12019  Please note, pdata access physically accesses xdata memory.
12020  The high byte of the address is determined by port P2 
12021 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
12022
12023 \end_inset
12024
12025 (or in case of some 8051 variants by a separate Special Function Register,
12026  see section 
12027 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12028
12029 \end_inset
12030
12031 ).
12032  This is the 
12033 \series bold
12034 default
12035 \series default
12036  storage class for the Medium Memory model, e.g.:
12037 \end_layout
12038
12039 \begin_layout Verse
12040
12041 \family typewriter
12042 __pdata unsigned char test_pdata;
12043 \end_layout
12044
12045 \begin_layout Standard
12046 Writing 0x01 to this variable generates the assembly code:
12047 \end_layout
12048
12049 \begin_layout Verse
12050
12051 \family typewriter
12052 78r00\InsetSpace ~
12053 \InsetSpace ~
12054 \InsetSpace ~
12055 \InsetSpace ~
12056 \InsetSpace ~
12057 \InsetSpace ~
12058 mov r0,#_test_pdata
12059 \newline
12060 74 01\InsetSpace ~
12061 \InsetSpace ~
12062 \InsetSpace ~
12063 \InsetSpace ~
12064 \InsetSpace ~
12065 \InsetSpace ~
12066 mov a,#0x01 
12067 \newline
12068 F2\InsetSpace ~
12069 \InsetSpace ~
12070 \InsetSpace ~
12071 \InsetSpace ~
12072 \InsetSpace ~
12073 \InsetSpace ~
12074 \InsetSpace ~
12075 \InsetSpace ~
12076 \InsetSpace ~
12077 movx @r0,a
12078 \end_layout
12079
12080 \begin_layout Standard
12081 If the -
12082 \begin_inset ERT
12083 status collapsed
12084
12085 \begin_layout Standard
12086
12087
12088 \backslash
12089 /
12090 \end_layout
12091
12092 \end_inset
12093
12094 -xstack
12095 \begin_inset LatexCommand \index{-\/-xstack}
12096
12097 \end_inset
12098
12099  option is used the pdata memory area is followed by the xstack memory area
12100  and the sum of their sizes is limited to 256 bytes.
12101 \end_layout
12102
12103 \begin_layout Subsubsection
12104 code
12105 \begin_inset LatexCommand \index{code}
12106
12107 \end_inset
12108
12109
12110 \begin_inset LatexCommand \index{\_\_code}
12111
12112 \end_inset
12113
12114
12115 \end_layout
12116
12117 \begin_layout Standard
12118 'Variables' declared with this storage class will be placed in the code
12119  memory:
12120 \end_layout
12121
12122 \begin_layout Verse
12123
12124 \family typewriter
12125 __code unsigned char test_code;
12126 \end_layout
12127
12128 \begin_layout Standard
12129 Read access to this variable generates the assembly code:
12130 \end_layout
12131
12132 \begin_layout Verse
12133
12134 \family typewriter
12135 90s00r6F\InsetSpace ~
12136 \InsetSpace ~
12137 \InsetSpace ~
12138 mov dptr,#_test_code
12139 \newline
12140 E4\InsetSpace ~
12141 \InsetSpace ~
12142 \InsetSpace ~
12143 \InsetSpace ~
12144 \InsetSpace ~
12145 \InsetSpace ~
12146 \InsetSpace ~
12147 \InsetSpace ~
12148 \InsetSpace ~
12149 clr a
12150 \newline
12151 93\InsetSpace ~
12152 \InsetSpace ~
12153 \InsetSpace ~
12154 \InsetSpace ~
12155 \InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 \InsetSpace ~
12159 \InsetSpace ~
12160 movc a,@a+dptr 
12161 \end_layout
12162
12163 \begin_layout Standard
12164
12165 \family typewriter
12166 char
12167 \family default
12168  indexed arrays of characters in code memory can be accessed efficiently:
12169 \end_layout
12170
12171 \begin_layout Verse
12172
12173 \family typewriter
12174 __code char test_array[] = {'c','h','e','a','p'}; 
12175 \end_layout
12176
12177 \begin_layout Standard
12178 Read access to this array using an 8-bit unsigned index generates the assembly
12179  code:
12180 \end_layout
12181
12182 \begin_layout Verse
12183
12184 \family typewriter
12185 E5*00\InsetSpace ~
12186 \InsetSpace ~
12187 \InsetSpace ~
12188 \InsetSpace ~
12189 \InsetSpace ~
12190 \InsetSpace ~
12191 mov a,_index 
12192 \end_layout
12193
12194 \begin_layout Verse
12195
12196 \family typewriter
12197 90s00r41\InsetSpace ~
12198 \InsetSpace ~
12199 \InsetSpace ~
12200 mov dptr,#_test_array
12201 \end_layout
12202
12203 \begin_layout Verse
12204
12205 \family typewriter
12206 93\InsetSpace ~
12207 \InsetSpace ~
12208 \InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 \InsetSpace ~
12215 movc a,@a+dptr 
12216 \end_layout
12217
12218 \begin_layout Subsubsection
12219 bit
12220 \begin_inset LatexCommand \index{bit}
12221
12222 \end_inset
12223
12224
12225 \begin_inset LatexCommand \index{\_\_bit}
12226
12227 \end_inset
12228
12229
12230 \end_layout
12231
12232 \begin_layout Standard
12233 This is a data-type and a storage class specifier.
12234  When a variable is declared as a bit, it is allocated into the bit addressable
12235  memory of 8051, e.g.:
12236 \end_layout
12237
12238 \begin_layout Verse
12239
12240 \family typewriter
12241 __bit test_bit;
12242 \end_layout
12243
12244 \begin_layout Standard
12245 Writing 1 to this variable generates the assembly code:
12246 \end_layout
12247
12248 \begin_layout Verse
12249
12250 \family typewriter
12251 D2*00\InsetSpace ~
12252 \InsetSpace ~
12253 \InsetSpace ~
12254 \InsetSpace ~
12255 \InsetSpace ~
12256 \InsetSpace ~
12257 \InsetSpace ~
12258 setb\InsetSpace ~
12259 _test_bit
12260 \end_layout
12261
12262 \begin_layout Standard
12263 The bit addressable memory consists of 128 bits which are located from 0x20
12264  to 0x2f in data memory.
12265  
12266 \newline
12267 Apart from this 8051 specific storage class most architectures support
12268  ANSI-C bitfields
12269 \begin_inset LatexCommand \index{bitfields}
12270
12271 \end_inset
12272
12273
12274 \begin_inset Foot
12275 status open
12276
12277 \begin_layout Standard
12278 Not really meant as examples, but nevertheless showing what bitfields are
12279  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12280 \end_layout
12281
12282 \end_inset
12283
12284 .
12285  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12286  signed modifier are implemented as unsigned.
12287 \end_layout
12288
12289 \begin_layout Subsubsection
12290 sfr
12291 \begin_inset LatexCommand \index{sfr}
12292
12293 \end_inset
12294
12295
12296 \begin_inset LatexCommand \index{\_\_sfr}
12297
12298 \end_inset
12299
12300  / sfr16
12301 \begin_inset LatexCommand \index{sfr16}
12302
12303 \end_inset
12304
12305
12306 \begin_inset LatexCommand \index{\_\_sfr16}
12307
12308 \end_inset
12309
12310  / sfr32
12311 \begin_inset LatexCommand \index{sfr32}
12312
12313 \end_inset
12314
12315
12316 \begin_inset LatexCommand \index{\_\_sfr32}
12317
12318 \end_inset
12319
12320  / sbit
12321 \begin_inset LatexCommand \index{\_\_sbit}
12322
12323 \end_inset
12324
12325
12326 \begin_inset LatexCommand \index{sbit}
12327
12328 \end_inset
12329
12330
12331 \end_layout
12332
12333 \begin_layout Standard
12334 Like the bit keyword, 
12335 \emph on
12336 sfr / sfr16 / sfr32 / sbit 
12337 \emph default
12338 signify both a data-type and storage class, they are used to describe the
12339  
12340 \emph on
12341 s
12342 \emph default
12343 pecial 
12344 \emph on
12345 f
12346 \emph default
12347 unction 
12348 \emph on
12349 r
12350 \emph default
12351 egisters and 
12352 \emph on
12353 s
12354 \emph default
12355 pecial 
12356 \emph on
12357 bit
12358 \emph default
12359  variables of a 8051, eg:
12360 \end_layout
12361
12362 \begin_layout Verse
12363
12364 \family typewriter
12365 __sfr __at
12366 \begin_inset LatexCommand \index{at}
12367
12368 \end_inset
12369
12370
12371 \begin_inset LatexCommand \index{\_\_at}
12372
12373 \end_inset
12374
12375  (0x80) P0;\InsetSpace ~
12376  /* special function register P0 at location 0x80 */
12377 \newline
12378
12379 \newline
12380 /* 16 bit
12381  special function register combination for timer 0
12382 \newline
12383 \InsetSpace ~
12384 \InsetSpace ~
12385  with the high byte at
12386  location 0x8C and the low byte at location 0x8A */
12387 \newline
12388 __sfr16 __at (0x8C8A)
12389  TMR0;
12390 \newline
12391
12392 \newline
12393 __sbit __at
12394 \begin_inset LatexCommand \index{at}
12395
12396 \end_inset
12397
12398
12399 \begin_inset LatexCommand \index{\_\_at}
12400
12401 \end_inset
12402
12403  (0xd7) CY;\InsetSpace ~
12404  /* CY (Carry Flag
12405 \begin_inset LatexCommand \index{Flags}
12406
12407 \end_inset
12408
12409
12410 \begin_inset LatexCommand \index{Carry flag}
12411
12412 \end_inset
12413
12414 ) */
12415 \end_layout
12416
12417 \begin_layout Standard
12418 Special function registers which are located on an address dividable by
12419  8 are bit-addressable, an
12420 \emph on
12421  sbit
12422 \emph default
12423  addresses a specific bit within these sfr.
12424 \newline
12425 16 Bit and 32 bit special function
12426  register combinations which require a certain access order are better not
12427  declared using 
12428 \emph on
12429 sfr16
12430 \emph default
12431  or 
12432 \emph on
12433 sfr32.
12434
12435 \emph default
12436  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12437  this is not guaranteed.
12438 \newline
12439
12440 \end_layout
12441
12442 \begin_layout Standard
12443 Please note, if you use a header file which was written for another compiler
12444  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12445  likely be 
12446 \emph on
12447 not 
12448 \emph default
12449 compatible.
12450  Specifically the syntax 
12451 \family typewriter
12452 \InsetSpace ~
12453 sfr P0 = 0x80;\InsetSpace ~
12454
12455 \family default
12456  is compiled 
12457 \emph on
12458 without warning
12459 \emph default
12460  by SDCC to an assignment of 0x80 to a variable called P0 
12461 \family typewriter
12462
12463 \begin_inset Marginal
12464 status collapsed
12465
12466 \begin_layout Standard
12467
12468 \series bold
12469 \InsetSpace ~
12470 !
12471 \end_layout
12472
12473 \end_inset
12474
12475 .
12476  
12477 \family default
12478 Nevertheless it is possible to write header files
12479 \begin_inset LatexCommand \index{Header files}
12480
12481 \end_inset
12482
12483
12484 \begin_inset LatexCommand \index{Include files}
12485
12486 \end_inset
12487
12488  which can be shared among different compilers (see section 
12489 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12490
12491 \end_inset
12492
12493 ).
12494  
12495 \end_layout
12496
12497 \begin_layout Subsubsection
12498 Pointers
12499 \begin_inset LatexCommand \index{Pointer}
12500
12501 \end_inset
12502
12503  to MCS51/DS390 specific memory spaces
12504 \end_layout
12505
12506 \begin_layout Standard
12507 SDCC allows (via language extensions) pointers to explicitly point to any
12508  of the memory spaces
12509 \begin_inset LatexCommand \index{Memory model}
12510
12511 \end_inset
12512
12513  of the 8051.
12514  In addition to the explicit pointers, the compiler uses (by default) generic
12515  pointers which can be used to point to any of the memory spaces.
12516 \newline
12517
12518 \newline
12519 Pointer
12520  declaration examples:
12521 \end_layout
12522
12523 \begin_layout Verse
12524
12525 \family typewriter
12526 /* pointer physically in internal ram pointing to object in external ram
12527  */ 
12528 \newline
12529 __xdata unsigned char * __data p;
12530 \newline
12531
12532 \newline
12533 /* pointer physically in external ram
12534  pointing to object in internal ram */ 
12535 \newline
12536 __data unsigned char * __xdata p;
12537 \newline
12538
12539 \newline
12540 /*
12541  pointer physically in code rom pointing to data in xdata space */ 
12542 \newline
12543 __xdata
12544  unsigned char * __code p;
12545 \newline
12546
12547 \newline
12548 /* pointer physically in code space pointing to
12549  data in code space */ 
12550 \newline
12551 __code unsigned char * __code p;
12552 \newline
12553
12554 \newline
12555 /* generic pointer
12556  physically located in xdata space */
12557 \newline
12558 unsigned char * __xdata p;
12559 \newline
12560
12561 \newline
12562 /* generic
12563  pointer physically located in default memory space */
12564 \newline
12565 unsigned char * p;
12566 \newline
12567
12568 \newline
12569 /*
12570  the following is a function pointer
12571 \begin_inset LatexCommand \index{function pointer}
12572
12573 \end_inset
12574
12575  physically located in data space */
12576 \newline
12577 char (* __data fp)(void);
12578 \end_layout
12579
12580 \begin_layout Standard
12581 Well you get the idea.
12582  
12583 \newline
12584
12585 \newline
12586 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12587 \emph on
12588 generic
12589 \emph default
12590  pointers.
12591  
12592 \size small
12593
12594 \newline
12595
12596 \newline
12597
12598 \size default
12599 The highest order byte of the 
12600 \emph on
12601 generic
12602 \emph default
12603  pointers contains the data space information.
12604  Assembler support routines are called whenever data is stored or retrieved
12605  using 
12606 \emph on
12607 generic
12608 \emph default
12609  pointers.
12610  These are useful for developing reusable library
12611 \begin_inset LatexCommand \index{Libraries}
12612
12613 \end_inset
12614
12615  routines.
12616  Explicitly specifying the pointer
12617 \begin_inset LatexCommand \index{pointer}
12618
12619 \end_inset
12620
12621  type will generate the most efficient code.
12622 \end_layout
12623
12624 \begin_layout Subsubsection
12625 Notes on MCS51 memory
12626 \begin_inset LatexCommand \index{MCS51 memory}
12627
12628 \end_inset
12629
12630  layout
12631 \end_layout
12632
12633 \begin_layout Standard
12634 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12635  RAM memory which is structured as follows:
12636 \newline
12637
12638 \newline
12639 - Bytes 00-1F - 32 bytes to hold
12640  up to 4 banks of the registers R0 to R7, 
12641 \newline
12642 - Bytes 20-2F - 16 bytes to hold
12643  128 bit
12644 \begin_inset LatexCommand \index{bit}
12645
12646 \end_inset
12647
12648  variables and, 
12649 \newline
12650 - Bytes 30-7F - 80 bytes for general purpose use.
12651 \newline
12652
12653 \end_layout
12654
12655 \begin_layout Standard
12656 Additionally some members of the MCS51 family may have up to 128 bytes of
12657  additional, indirectly addressable, internal RAM memory (
12658 \emph on
12659 idata
12660 \emph default
12661
12662 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12663
12664 \end_inset
12665
12666
12667 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12668
12669 \end_inset
12670
12671 ).
12672  Furthermore, some chips may have some built in external memory (
12673 \emph on
12674 xdata
12675 \emph default
12676
12677 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12678
12679 \end_inset
12680
12681
12682 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12683
12684 \end_inset
12685
12686 ) which should not be confused with the internal, directly addressable RAM
12687  memory (
12688 \emph on
12689 data
12690 \emph default
12691
12692 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12693
12694 \end_inset
12695
12696
12697 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12698
12699 \end_inset
12700
12701 ).
12702  Sometimes this built in 
12703 \emph on
12704 xdata
12705 \emph default
12706  memory has to be activated before using it (you can probably find this
12707  information on the datasheet of the microcontroller your are using, see
12708  also section 
12709 \begin_inset LatexCommand \ref{sub:Startup-Code}
12710
12711 \end_inset
12712
12713 \InsetSpace ~
12714 Startup-Code).
12715 \end_layout
12716
12717 \begin_layout Standard
12718 Normally SDCC will only use the first bank
12719 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12720
12721 \end_inset
12722
12723  of registers (register bank 0), but it is possible to specify that other
12724  banks of registers (keyword 
12725 \emph on
12726 using
12727 \emph default
12728  
12729 \emph on
12730
12731 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12732
12733 \end_inset
12734
12735
12736 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12737
12738 \end_inset
12739
12740
12741 \emph default
12742 ) should be used for example in interrupt
12743 \begin_inset LatexCommand \index{interrupt}
12744
12745 \end_inset
12746
12747
12748 \begin_inset LatexCommand \index{\_\_interrupt}
12749
12750 \end_inset
12751
12752  routines.
12753  By default, the compiler will place the stack after the last byte of allocated
12754  memory for variables.
12755  For example, if the first 2 banks of registers are used, and only four
12756  bytes are used for 
12757 \emph on
12758 data
12759 \emph default
12760  variables, it will position the base of the internal stack at address 20
12761  (0x14).
12762  This implies that as the stack
12763 \begin_inset LatexCommand \index{stack}
12764
12765 \end_inset
12766
12767  grows, it will use up the remaining register banks, and the 16 bytes used
12768  by the 128 bit variables, and 80 bytes for general purpose use.
12769  If any bit variables are used, the data variables will be placed in unused
12770  register banks and after the byte holding the last bit variable.
12771  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12772  (two bytes used), 
12773 \emph on
12774 data
12775 \emph default
12776  variables will be placed starting from address 0x10 to 0x20 and continue
12777  at address 0x22.
12778  You can also use -
12779 \begin_inset ERT
12780 status collapsed
12781
12782 \begin_layout Standard
12783
12784
12785 \backslash
12786 /
12787 \end_layout
12788
12789 \end_inset
12790
12791 -data-loc
12792 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12793
12794 \end_inset
12795
12796  to specify the start address of the 
12797 \emph on
12798 data
12799 \emph default
12800  and -
12801 \begin_inset ERT
12802 status collapsed
12803
12804 \begin_layout Standard
12805
12806
12807 \backslash
12808 /
12809 \end_layout
12810
12811 \end_inset
12812
12813 -iram-size
12814 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12815
12816 \end_inset
12817
12818  to specify the size of the total internal RAM (
12819 \emph on
12820 data
12821 \emph default
12822 +
12823 \emph on
12824 idata
12825 \emph default
12826 ).
12827  
12828 \newline
12829
12830 \end_layout
12831
12832 \begin_layout Standard
12833 By default the 8051 linker will place the stack after the last byte of (i)data
12834  variables.
12835  Option -
12836 \begin_inset ERT
12837 status collapsed
12838
12839 \begin_layout Standard
12840
12841
12842 \backslash
12843 /
12844 \end_layout
12845
12846 \end_inset
12847
12848 -stack-loc
12849 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12850
12851 \end_inset
12852
12853  allows you to specify the start of the stack, i.e.
12854  you could start it after any data in the general purpose area.
12855  If your microcontroller has additional indirectly addressable internal
12856  RAM (
12857 \emph on
12858 idata
12859 \emph default
12860 ) you can place the stack on it.
12861  You may also need to use -
12862 \begin_inset ERT
12863 status collapsed
12864
12865 \begin_layout Standard
12866
12867
12868 \backslash
12869 /
12870 \end_layout
12871
12872 \end_inset
12873
12874 -xdata-loc
12875 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12876
12877 \end_inset
12878
12879  to set the start address of the external RAM (
12880 \emph on
12881 xdata
12882 \emph default
12883 ) and -
12884 \begin_inset ERT
12885 status collapsed
12886
12887 \begin_layout Standard
12888
12889
12890 \backslash
12891 /
12892 \end_layout
12893
12894 \end_inset
12895
12896 -xram-size
12897 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12898
12899 \end_inset
12900
12901  to specify its size.
12902  Same goes for the code memory, using -
12903 \begin_inset ERT
12904 status collapsed
12905
12906 \begin_layout Standard
12907
12908
12909 \backslash
12910 /
12911 \end_layout
12912
12913 \end_inset
12914
12915 -code-loc
12916 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12917
12918 \end_inset
12919
12920  and -
12921 \begin_inset ERT
12922 status collapsed
12923
12924 \begin_layout Standard
12925
12926
12927 \backslash
12928 /
12929 \end_layout
12930
12931 \end_inset
12932
12933 -code-size
12934 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12935
12936 \end_inset
12937
12938 .
12939  If in doubt, don't specify any options and see if the resulting memory
12940  layout is appropriate, then you can adjust it.
12941 \end_layout
12942
12943 \begin_layout Standard
12944 The linker generates two files with memory allocation information.
12945  The first, with extension .map
12946 \begin_inset LatexCommand \index{<file>.map}
12947
12948 \end_inset
12949
12950  shows all the variables and segments.
12951  The second with extension .mem
12952 \begin_inset LatexCommand \index{<file>.mem}
12953
12954 \end_inset
12955
12956  shows the final memory layout.
12957  The linker will complain either if memory segments overlap, there is not
12958  enough memory, or there is not enough space for stack.
12959  If you get any linking warnings and/or errors related to stack or segments
12960  allocation, take a look at either the .map or .mem files to find out what
12961  the problem is.
12962  The .mem file may even suggest a solution to the problem.
12963 \begin_inset VSpace bigskip
12964 \end_inset
12965
12966
12967 \end_layout
12968
12969 \begin_layout Subsection
12970 Z80/Z180 Storage Class
12971 \begin_inset LatexCommand \index{Z80!Storage class}
12972
12973 \end_inset
12974
12975  Language Extensions
12976 \end_layout
12977
12978 \begin_layout Subsubsection
12979 sfr
12980 \begin_inset LatexCommand \index{sfr}
12981
12982 \end_inset
12983
12984
12985 \begin_inset LatexCommand \index{\_\_sfr}
12986
12987 \end_inset
12988
12989  (in/out to 8-bit addresses)
12990 \end_layout
12991
12992 \begin_layout Standard
12993 The Z80
12994 \begin_inset LatexCommand \index{Z80}
12995
12996 \end_inset
12997
12998  family has separate address spaces for memory and 
12999 \emph on
13000 i
13001 \emph default
13002 nput/
13003 \emph on
13004 o
13005 \emph default
13006 utput memory.
13007  I/O memory
13008 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
13009
13010 \end_inset
13011
13012
13013 \begin_inset LatexCommand \index{Z80!I/O memory}
13014
13015 \end_inset
13016
13017
13018 \begin_inset LatexCommand \index{Z180!I/O memory}
13019
13020 \end_inset
13021
13022  is accessed with special instructions, e.g.:
13023 \end_layout
13024
13025 \begin_layout Verse
13026
13027 \family typewriter
13028 sfr at 0x78 IoPort;\InsetSpace ~
13029 \InsetSpace ~
13030 /* define a var in I/O space at 78h called IoPort */
13031  
13032 \end_layout
13033
13034 \begin_layout Standard
13035 Writing 0x01 to this variable generates the assembly code:
13036 \end_layout
13037
13038 \begin_layout Verse
13039
13040 \family typewriter
13041 3E 01\InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 \InsetSpace ~
13046 \InsetSpace ~
13047 ld a,#0x01
13048 \newline
13049 D3 78\InsetSpace ~
13050 \InsetSpace ~
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 out (_IoPort),a 
13056 \end_layout
13057
13058 \begin_layout Subsubsection
13059 banked sfr
13060 \begin_inset LatexCommand \index{sfr}
13061
13062 \end_inset
13063
13064
13065 \begin_inset LatexCommand \index{\_\_sfr}
13066
13067 \end_inset
13068
13069  (in/out to 16-bit addresses)
13070 \end_layout
13071
13072 \begin_layout Standard
13073 The keyword 
13074 \emph on
13075 banked
13076 \emph default
13077  is used to support 16 bit addresses in I/O memory e.g.:
13078 \end_layout
13079
13080 \begin_layout Verse
13081
13082 \family typewriter
13083 sfr banked at
13084 \begin_inset LatexCommand \index{at}
13085
13086 \end_inset
13087
13088
13089 \begin_inset LatexCommand \index{\_\_at}
13090
13091 \end_inset
13092
13093  0x123 IoPort; 
13094 \end_layout
13095
13096 \begin_layout Standard
13097 Writing 0x01 to this variable generates the assembly code:
13098 \end_layout
13099
13100 \begin_layout Verse
13101
13102 \family typewriter
13103 01 23 01\InsetSpace ~
13104 \InsetSpace ~
13105 \InsetSpace ~
13106 ld bc,#_IoPort
13107 \newline
13108 3E 01\InsetSpace ~
13109 \InsetSpace ~
13110 \InsetSpace ~
13111 \InsetSpace ~
13112 \InsetSpace ~
13113 \InsetSpace ~
13114 ld a,#0x01 
13115 \newline
13116 ED 79\InsetSpace ~
13117 \InsetSpace ~
13118 \InsetSpace ~
13119 \InsetSpace ~
13120 \InsetSpace ~
13121 \InsetSpace ~
13122 out (c),a 
13123 \end_layout
13124
13125 \begin_layout Subsubsection
13126 sfr
13127 \begin_inset LatexCommand \index{sfr}
13128
13129 \end_inset
13130
13131
13132 \begin_inset LatexCommand \index{\_\_sfr}
13133
13134 \end_inset
13135
13136  (in0/out0 to 8 bit addresses on Z180
13137 \begin_inset LatexCommand \index{Z180}
13138
13139 \end_inset
13140
13141 /HD64180
13142 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13143
13144 \end_inset
13145
13146 )
13147 \end_layout
13148
13149 \begin_layout Standard
13150 The compiler option -
13151 \begin_inset ERT
13152 status collapsed
13153
13154 \begin_layout Standard
13155
13156
13157 \backslash
13158 /
13159 \end_layout
13160
13161 \end_inset
13162
13163 -portmode
13164 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13165
13166 \end_inset
13167
13168 =180 (80) and a compiler #pragma\InsetSpace ~
13169 portmode
13170 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13171
13172 \end_inset
13173
13174  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13175 ns 
13176 \family typewriter
13177 in0/out0
13178 \family default
13179  instead of 
13180 \family typewriter
13181 in/out
13182 \family default
13183 .
13184  If you include the file z180.h this will be set automatically.
13185 \begin_inset VSpace bigskip
13186 \end_inset
13187
13188
13189 \end_layout
13190
13191 \begin_layout Subsection
13192 HC08 Storage Class
13193 \begin_inset LatexCommand \index{HC08!Storage class}
13194
13195 \end_inset
13196
13197  Language Extensions
13198 \end_layout
13199
13200 \begin_layout Subsubsection
13201 data
13202 \begin_inset LatexCommand \index{data (hc08 storage class)}
13203
13204 \end_inset
13205
13206
13207 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13208
13209 \end_inset
13210
13211  
13212 \end_layout
13213
13214 \begin_layout Standard
13215 The data storage class declares a variable that resides in the first 256
13216  bytes of memory (the direct page).
13217  The HC08
13218 \begin_inset LatexCommand \index{HC08}
13219
13220 \end_inset
13221
13222  is most efficient at accessing variables (especially pointers) stored here.
13223 \end_layout
13224
13225 \begin_layout Subsubsection
13226 xdata
13227 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13228
13229 \end_inset
13230
13231
13232 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13233
13234 \end_inset
13235
13236  
13237 \end_layout
13238
13239 \begin_layout Standard
13240 The xdata storage class declares a variable that can reside anywhere in
13241  memory.
13242  This is the default if no storage class is specified.
13243  
13244 \begin_inset VSpace bigskip
13245 \end_inset
13246
13247
13248 \end_layout
13249
13250 \begin_layout Section
13251 Other SDCC language extensions
13252 \begin_inset LatexCommand \index{Other SDCC language extensions}
13253
13254 \end_inset
13255
13256
13257 \end_layout
13258
13259 \begin_layout Subsection
13260 Binary constants
13261 \end_layout
13262
13263 \begin_layout Standard
13264 SDCC supports the use of binary constants, such as 0b01100010.
13265  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13266 \end_layout
13267
13268 \begin_layout Standard
13269 \begin_inset VSpace bigskip
13270 \end_inset
13271
13272
13273 \end_layout
13274
13275 \begin_layout Section
13276 Absolute Addressing
13277 \begin_inset LatexCommand \index{Absolute addressing}
13278
13279 \end_inset
13280
13281
13282 \end_layout
13283
13284 \begin_layout Standard
13285 Data items can be assigned an absolute address with the 
13286 \emph on
13287 at
13288 \begin_inset LatexCommand \index{at}
13289
13290 \end_inset
13291
13292
13293 \begin_inset LatexCommand \index{\_\_at}
13294
13295 \end_inset
13296
13297  <address>
13298 \emph default
13299  keyword, in addition to a storage class, e.g.:
13300 \end_layout
13301
13302 \begin_layout Verse
13303
13304 \family typewriter
13305 xdata
13306 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13307
13308 \end_inset
13309
13310
13311 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13312
13313 \end_inset
13314
13315  at
13316 \begin_inset LatexCommand \index{at}
13317
13318 \end_inset
13319
13320
13321 \begin_inset LatexCommand \index{\_\_at}
13322
13323 \end_inset
13324
13325  0x7ffe unsigned int chksum;
13326 \end_layout
13327
13328 \begin_layout Standard
13329 or, better conforming to ISO/IEC 9899 C:
13330 \end_layout
13331
13332 \begin_layout Verse
13333
13334 \family typewriter
13335 __xdata __at (0x7ffe) unsigned int chksum;
13336 \end_layout
13337
13338 \begin_layout Standard
13339 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13340  of the external ram.
13341  The compiler does 
13342 \emph on
13343 not
13344 \emph default
13345  reserve any space for variables declared in this way
13346 \begin_inset Marginal
13347 status collapsed
13348
13349 \begin_layout Standard
13350
13351 \series bold
13352 \InsetSpace ~
13353 !
13354 \end_layout
13355
13356 \end_inset
13357
13358  (they are implemented with an equate in the assembler).
13359  Thus it is left to the programmer to make sure there are no overlaps with
13360  other variables that are declared without the absolute address.
13361  The assembler listing file (.lst
13362 \begin_inset LatexCommand \index{<file>.lst}
13363
13364 \end_inset
13365
13366 ) and the linker output files (.rst
13367 \begin_inset LatexCommand \index{<file>.rst}
13368
13369 \end_inset
13370
13371 ) and (.map
13372 \begin_inset LatexCommand \index{<file>.map}
13373
13374 \end_inset
13375
13376 ) are good places to look for such overlaps.
13377 \end_layout
13378
13379 \begin_layout Standard
13380 If however you provide an initializer
13381 \begin_inset LatexCommand \index{Variable initialization}
13382
13383 \end_inset
13384
13385  actual memory allocation will take place and overlaps will be detected
13386  by the linker.
13387  E.g.:
13388 \end_layout
13389
13390 \begin_layout Verse
13391
13392 \family typewriter
13393 __code __at (0x7ff0) char Id[5] = 
13394 \begin_inset Quotes sld
13395 \end_inset
13396
13397 SDCC
13398 \begin_inset Quotes srd
13399 \end_inset
13400
13401 ;
13402 \end_layout
13403
13404 \begin_layout Standard
13405 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13406  in code memory.
13407 \end_layout
13408
13409 \begin_layout Standard
13410 In case of memory mapped I/O devices the keyword 
13411 \emph on
13412 volatile
13413 \emph default
13414  has to be used to tell the compiler that accesses might not be removed:
13415 \end_layout
13416
13417 \begin_layout Verse
13418
13419 \family typewriter
13420 volatile
13421 \begin_inset LatexCommand \index{volatile}
13422
13423 \end_inset
13424
13425  __xdata
13426 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13427
13428 \end_inset
13429
13430  __at
13431 \begin_inset LatexCommand \index{at}
13432
13433 \end_inset
13434
13435  (0x8000) unsigned char PORTA_8255;
13436 \end_layout
13437
13438 \begin_layout Standard
13439 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13440 r) array
13441 \family typewriter
13442 \size footnotesize
13443
13444 \begin_inset LatexCommand \index{Aligned array}
13445
13446 \end_inset
13447
13448
13449 \family default
13450 \size default
13451  starts at a block (256 byte) boundary
13452 \begin_inset LatexCommand \index{block boundary}
13453
13454 \end_inset
13455
13456  (section 
13457 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13458
13459 \end_inset
13460
13461  has an example).
13462 \newline
13463 Absolute addresses can be specified for variables in all
13464  storage classes, e.g.:
13465 \end_layout
13466
13467 \begin_layout Verse
13468
13469 \family typewriter
13470 __bit
13471 \begin_inset LatexCommand \index{bit}
13472
13473 \end_inset
13474
13475  __at
13476 \begin_inset LatexCommand \index{at}
13477
13478 \end_inset
13479
13480  (0x02) bvar;
13481 \end_layout
13482
13483 \begin_layout Standard
13484 The above example will allocate the variable at offset 0x02 in the bit-addressab
13485 le space.
13486  There is no real advantage to assigning absolute addresses to variables
13487  in this manner, unless you want strict control over all the variables allocated.
13488  One possible use would be to write hardware portable code.
13489  For example, if you have a routine that uses one or more of the microcontroller
13490  I/O pins, and such pins are different for two different hardwares, you
13491  can declare the I/O pins in your routine using:
13492 \end_layout
13493
13494 \begin_layout Verse
13495
13496 \family typewriter
13497 extern volatile
13498 \begin_inset LatexCommand \index{volatile}
13499
13500 \end_inset
13501
13502  __bit MOSI;\InsetSpace ~
13503 \InsetSpace ~
13504 \InsetSpace ~
13505 \InsetSpace ~
13506 /* master out, slave in */
13507 \newline
13508 extern volatile __bit MISO;\InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 /* master
13513  in, slave out */
13514 \newline
13515 extern volatile __bit MCLK;\InsetSpace ~
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 /* master clock */
13520 \newline
13521
13522 \newline
13523 /* Input and
13524  Output of a byte on a 3-wire serial bus.
13525 \newline
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 If needed adapt polarity of clock,
13530  polarity of data and bit order
13531 \newline
13532 \InsetSpace ~
13533 */
13534 \newline
13535 unsigned char spi_io(unsigned char out_byte)
13536  
13537 \newline
13538
13539 \newline
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 \InsetSpace ~
13543 \InsetSpace ~
13544 unsigned char i=8;
13545 \newline
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 do { 
13551 \newline
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 \InsetSpace ~
13557 \InsetSpace ~
13558 \InsetSpace ~
13559 \InsetSpace ~
13560 MOSI = out_byte & 0x80; 
13561 \newline
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 \InsetSpace ~
13567 \InsetSpace ~
13568 \InsetSpace ~
13569 \InsetSpace ~
13570 out_byte <<= 1;
13571 \newline
13572 \InsetSpace ~
13573 \InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 \InsetSpace ~
13579 \InsetSpace ~
13580 MCLK =
13581  1; 
13582 \newline
13583 \InsetSpace ~
13584 \InsetSpace ~
13585 \InsetSpace ~
13586 \InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 \InsetSpace ~
13590 \InsetSpace ~
13591 /* _asm nop _endasm; */\InsetSpace ~
13592 \InsetSpace ~
13593 \InsetSpace ~
13594 \InsetSpace ~
13595 \InsetSpace ~
13596 \InsetSpace ~
13597 \InsetSpace ~
13598 \InsetSpace ~
13599 /* for slow peripherals */
13600 \newline
13601 \InsetSpace ~
13602 \InsetSpace ~
13603 \InsetSpace ~
13604 \InsetSpace ~
13605 \InsetSpace ~
13606 \InsetSpace ~
13607 \InsetSpace ~
13608 \InsetSpace ~
13609 if(MISO) 
13610 \newline
13611 \InsetSpace ~
13612 \InsetSpace ~
13613 \InsetSpace ~
13614 \InsetSpace ~
13615 \InsetSpace ~
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 \InsetSpace ~
13619 \InsetSpace ~
13620 \InsetSpace ~
13621 \InsetSpace ~
13622 \InsetSpace ~
13623 out_byte +=
13624  1; 
13625 \newline
13626 \InsetSpace ~
13627 \InsetSpace ~
13628 \InsetSpace ~
13629 \InsetSpace ~
13630 \InsetSpace ~
13631 \InsetSpace ~
13632 \InsetSpace ~
13633 \InsetSpace ~
13634 MCLK = 0; 
13635 \newline
13636 \InsetSpace ~
13637 \InsetSpace ~
13638 \InsetSpace ~
13639 \InsetSpace ~
13640 } while(--i);
13641 \newline
13642 \InsetSpace ~
13643 \InsetSpace ~
13644 \InsetSpace ~
13645 \InsetSpace ~
13646 return out_byte; 
13647 \newline
13648 }
13649 \end_layout
13650
13651 \begin_layout Standard
13652 Then, someplace in the code for the first hardware you would use
13653 \end_layout
13654
13655 \begin_layout Verse
13656
13657 \family typewriter
13658 __bit __at
13659 \begin_inset LatexCommand \index{at}
13660
13661 \end_inset
13662
13663
13664 \begin_inset LatexCommand \index{\_\_at}
13665
13666 \end_inset
13667
13668  (0x80) MOSI;\InsetSpace ~
13669 \InsetSpace ~
13670 \InsetSpace ~
13671 \InsetSpace ~
13672 /* I/O port 0, bit 0 */
13673 \newline
13674 __bit __at (0x81) MISO;\InsetSpace ~
13675 \InsetSpace ~
13676 \InsetSpace ~
13677 \InsetSpace ~
13678 /* I/O port 0,
13679  bit 1 */
13680 \newline
13681 __bit __at (0x82) MCLK;\InsetSpace ~
13682 \InsetSpace ~
13683 \InsetSpace ~
13684 \InsetSpace ~
13685 /* I/O port 0, bit 2 */
13686 \end_layout
13687
13688 \begin_layout Standard
13689 Similarly, for the second hardware you would use
13690 \end_layout
13691
13692 \begin_layout Verse
13693
13694 \family typewriter
13695 __bit __at (0x83) MOSI;\InsetSpace ~
13696 \InsetSpace ~
13697 \InsetSpace ~
13698 \InsetSpace ~
13699 /* I/O port 0, bit 3 */
13700 \newline
13701 __bit __at (0x91) MISO;\InsetSpace ~
13702 \InsetSpace ~
13703 \InsetSpace ~
13704 \InsetSpace ~
13705 /*
13706  I/O port 1, bit 1 */
13707 \newline
13708 __bit
13709 \begin_inset LatexCommand \index{bit}
13710
13711 \end_inset
13712
13713  __at (0x92) MCLK;\InsetSpace ~
13714 \InsetSpace ~
13715 \InsetSpace ~
13716 \InsetSpace ~
13717 /* I/O port 1, bit 2 */
13718 \end_layout
13719
13720 \begin_layout Standard
13721 and you can use the same hardware dependent routine without changes, as
13722  for example in a library.
13723  This is somehow similar to sbit, but only one absolute address has to be
13724  specified in the whole project.
13725 \begin_inset VSpace bigskip
13726 \end_inset
13727
13728
13729 \end_layout
13730
13731 \begin_layout Section
13732 Parameters
13733 \begin_inset LatexCommand \index{Parameters}
13734
13735 \end_inset
13736
13737
13738 \begin_inset LatexCommand \index{function parameter}
13739
13740 \end_inset
13741
13742  & Local Variables
13743 \begin_inset LatexCommand \index{local variables}
13744
13745 \end_inset
13746
13747
13748 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13749
13750 \end_inset
13751
13752
13753 \end_layout
13754
13755 \begin_layout Standard
13756 Automatic (local) variables and parameters to functions can either be placed
13757  on the stack or in data-space.
13758  The default action of the compiler is to place these variables in the internal
13759  RAM (for small model) or external RAM (for medium or large model).
13760  This in fact makes them similar to 
13761 \emph on
13762 static
13763 \begin_inset LatexCommand \index{static}
13764
13765 \end_inset
13766
13767
13768 \emph default
13769  so by default functions are non-reentrant
13770 \begin_inset LatexCommand \index{reentrant}
13771
13772 \end_inset
13773
13774 .
13775  
13776 \newline
13777
13778 \newline
13779 They can be placed on the stack
13780 \begin_inset LatexCommand \index{stack}
13781
13782 \end_inset
13783
13784  by using the
13785 \emph on
13786  -
13787 \begin_inset ERT
13788 status collapsed
13789
13790 \begin_layout Standard
13791
13792
13793 \backslash
13794 /
13795 \end_layout
13796
13797 \end_inset
13798
13799 -stack-auto
13800 \begin_inset LatexCommand \index{-\/-stack-auto}
13801
13802 \end_inset
13803
13804
13805 \emph default
13806  option, by using 
13807 \emph on
13808 #pragma\InsetSpace ~
13809 stackauto
13810 \emph default
13811
13812 \begin_inset LatexCommand \index{\#pragma stackauto}
13813
13814 \end_inset
13815
13816  or by using the 
13817 \emph on
13818 reentrant
13819 \begin_inset LatexCommand \index{reentrant}
13820
13821 \end_inset
13822
13823
13824 \emph default
13825  keyword in the function declaration, e.g.:
13826 \end_layout
13827
13828 \begin_layout Verse
13829
13830 \family typewriter
13831 unsigned char foo(char i) __reentrant 
13832 \newline
13833
13834 \newline
13835 \InsetSpace ~
13836 \InsetSpace ~
13837 \InsetSpace ~
13838 \InsetSpace ~
13839 ...
13840  
13841 \newline
13842 }
13843 \end_layout
13844
13845 \begin_layout Standard
13846 Since stack space on 8051 is limited, the 
13847 \emph on
13848 reentrant 
13849 \emph default
13850 keyword or the
13851 \emph on
13852  -
13853 \begin_inset ERT
13854 status collapsed
13855
13856 \begin_layout Standard
13857
13858
13859 \backslash
13860 /
13861 \end_layout
13862
13863 \end_inset
13864
13865 -stack-auto
13866 \emph default
13867  option should be used sparingly.
13868  Note that the reentrant keyword just means that the parameters & local
13869  variables will be allocated to the stack, it 
13870 \emph on
13871 does not
13872 \emph default
13873  mean that the function is register bank
13874 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13875
13876 \end_inset
13877
13878  independent.
13879 \newline
13880
13881 \newline
13882 Local variables
13883 \begin_inset LatexCommand \index{local variables}
13884
13885 \end_inset
13886
13887  can be assigned storage classes and absolute
13888 \begin_inset LatexCommand \index{Absolute addressing}
13889
13890 \end_inset
13891
13892  addresses, e.g.: 
13893 \end_layout
13894
13895 \begin_layout Verse
13896
13897 \family typewriter
13898 unsigned char foo() 
13899 \newline
13900 {
13901 \newline
13902 \InsetSpace ~
13903 \InsetSpace ~
13904 \InsetSpace ~
13905 \InsetSpace ~
13906 __xdata unsigned char i;
13907 \newline
13908 \InsetSpace ~
13909 \InsetSpace ~
13910 \InsetSpace ~
13911 \InsetSpace ~
13912 __bit bvar;
13913 \newline
13914 \InsetSpace ~
13915 \InsetSpace ~
13916 \InsetSpace ~
13917 \InsetSpace ~
13918 __data __at
13919 \begin_inset LatexCommand \index{at}
13920
13921 \end_inset
13922
13923  (0x31) unsigned char j;
13924 \newline
13925 \InsetSpace ~
13926 \InsetSpace ~
13927 \InsetSpace ~
13928 \InsetSpace ~
13929 ...
13930  
13931 \newline
13932 }
13933 \end_layout
13934
13935 \begin_layout Standard
13936 In the above example the variable 
13937 \emph on
13938 i
13939 \emph default
13940  will be allocated in the external ram, 
13941 \emph on
13942 bvar
13943 \emph default
13944  in bit addressable space and
13945 \emph on
13946  j
13947 \emph default
13948  in internal ram.
13949  When compiled with 
13950 \emph on
13951 -
13952 \begin_inset ERT
13953 status collapsed
13954
13955 \begin_layout Standard
13956
13957
13958 \backslash
13959 /
13960 \end_layout
13961
13962 \end_inset
13963
13964 -stack-auto
13965 \emph default
13966  or when a function is declared as 
13967 \emph on
13968 reentrant
13969 \emph default
13970  this should only be done for static variables.
13971 \end_layout
13972
13973 \begin_layout Standard
13974 Parameters
13975 \begin_inset LatexCommand \index{function parameter}
13976
13977 \end_inset
13978
13979  however are not allowed any storage class
13980 \begin_inset LatexCommand \index{Storage class}
13981
13982 \end_inset
13983
13984 , (storage classes for parameters will be ignored), their allocation is
13985  governed by the memory model in use, and the reentrancy options.
13986 \end_layout
13987
13988 \begin_layout Standard
13989 It is however allowed to use bit parameters in reentrant functions and also
13990  non-static local bit variables are supported.
13991  Efficient use is limited to 8 semi-bitregisters in bit space.
13992  They are pushed and popped to stack
13993 \begin_inset LatexCommand \index{stack}
13994
13995 \end_inset
13996
13997  as a single byte just like the normal registers.
13998 \end_layout
13999
14000 \begin_layout Section
14001 Overlaying
14002 \begin_inset LatexCommand \label{sub:Overlaying}
14003
14004 \end_inset
14005
14006
14007 \begin_inset LatexCommand \index{Overlaying}
14008
14009 \end_inset
14010
14011
14012 \end_layout
14013
14014 \begin_layout Standard
14015 For non-reentrant
14016 \begin_inset LatexCommand \index{reentrant}
14017
14018 \end_inset
14019
14020  functions SDCC will try to reduce internal ram space usage by overlaying
14021  parameters and local variables of a function (if possible).
14022  Parameters and local variables
14023 \begin_inset LatexCommand \index{local variables}
14024
14025 \end_inset
14026
14027  of a function will be allocated to an overlayable segment if the function
14028  has 
14029 \emph on
14030 no other function calls and the function is non-reentrant and the memory
14031  model
14032 \begin_inset LatexCommand \index{Memory model}
14033
14034 \end_inset
14035
14036  is small.
14037
14038 \emph default
14039  If an explicit storage class
14040 \begin_inset LatexCommand \index{Storage class}
14041
14042 \end_inset
14043
14044  is specified for a local variable, it will NOT be overlayed.
14045 \end_layout
14046
14047 \begin_layout Standard
14048 Note that the compiler (not the linkage editor) makes the decision for overlayin
14049 g the data items.
14050  Functions that are called from an interrupt service routine
14051 \begin_inset Marginal
14052 status collapsed
14053
14054 \begin_layout Standard
14055
14056 \series bold
14057 !
14058 \end_layout
14059
14060 \end_inset
14061
14062  should be preceded by a #pragma\InsetSpace ~
14063 nooverlay
14064 \begin_inset LatexCommand \index{\#pragma nooverlay}
14065
14066 \end_inset
14067
14068  if they are not reentrant.
14069 \end_layout
14070
14071 \begin_layout Standard
14072 Also note that the compiler does not do any processing of inline assembler
14073  code, so the compiler might incorrectly assign local variables and parameters
14074  of a function into the overlay segment if the inline assembler code calls
14075  other c-functions that might use the overlay.
14076  In that case the #pragma\InsetSpace ~
14077 nooverlay should be used.
14078 \end_layout
14079
14080 \begin_layout Standard
14081 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14082 tion
14083 \begin_inset LatexCommand \index{Multiplication}
14084
14085 \end_inset
14086
14087  or division
14088 \begin_inset LatexCommand \index{Division}
14089
14090 \end_inset
14091
14092  will NOT be overlayed since these are implemented using external functions,
14093  e.g.:
14094 \end_layout
14095
14096 \begin_layout Verse
14097
14098 \family typewriter
14099 #pragma save 
14100 \newline
14101 #pragma nooverlay
14102 \begin_inset LatexCommand \index{\#pragma nooverlay}
14103
14104 \end_inset
14105
14106  
14107 \newline
14108 void set_error(unsigned char errcd) 
14109 \newline
14110 {
14111 \newline
14112 \InsetSpace ~
14113 \InsetSpace ~
14114 \InsetSpace ~
14115 \InsetSpace ~
14116 P3 = errcd;
14117 \newline
14118
14119 \newline
14120 #pragma restore 
14121 \newline
14122
14123 \newline
14124 void
14125  some_isr () __interrupt
14126 \begin_inset LatexCommand \index{interrupt}
14127
14128 \end_inset
14129
14130  (2)
14131 \newline
14132 {
14133 \newline
14134 \InsetSpace ~
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 ...
14139 \newline
14140 \InsetSpace ~
14141 \InsetSpace ~
14142 \InsetSpace ~
14143 \InsetSpace ~
14144 set_error(10);
14145 \newline
14146 \InsetSpace ~
14147 \InsetSpace ~
14148 \InsetSpace ~
14149 \InsetSpace ~
14150 ...
14151  
14152 \newline
14153 }
14154 \end_layout
14155
14156 \begin_layout Standard
14157 In the above example the parameter 
14158 \emph on
14159 errcd
14160 \emph default
14161  for the function 
14162 \emph on
14163 set_error
14164 \emph default
14165  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14166 nooverlay was
14167  not present, this could cause unpredictable runtime behavior when called
14168  from an interrupt service routine.
14169  The #pragma\InsetSpace ~
14170 nooverlay ensures that the parameters and local variables for
14171  the function are NOT overlayed.
14172 \begin_inset VSpace bigskip
14173 \end_inset
14174
14175
14176 \end_layout
14177
14178 \begin_layout Section
14179 Interrupt Service Routines
14180 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14181
14182 \end_inset
14183
14184
14185 \end_layout
14186
14187 \begin_layout Subsection
14188 General Information
14189 \end_layout
14190
14191 \begin_layout Standard
14192 SDCC allows 
14193 \emph on
14194 i
14195 \emph default
14196 nterrupt 
14197 \emph on
14198 s
14199 \emph default
14200 ervice 
14201 \emph on
14202 r
14203 \emph default
14204 outines to be coded in C, with some extended keywords.
14205 \end_layout
14206
14207 \begin_layout Verse
14208
14209 \family typewriter
14210 void timer_isr (void) __interrupt (1) __using (1) 
14211 \newline
14212
14213 \newline
14214 \InsetSpace ~
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 \InsetSpace ~
14218 ...
14219  
14220 \newline
14221 }
14222 \end_layout
14223
14224 \begin_layout Standard
14225 The optional number following the 
14226 \emph on
14227 interrupt
14228 \begin_inset LatexCommand \index{interrupt}
14229
14230 \end_inset
14231
14232
14233 \begin_inset LatexCommand \index{\_\_interrupt}
14234
14235 \end_inset
14236
14237
14238 \emph default
14239  keyword is the interrupt number this routine will service.
14240  When present, the compiler will insert a call to this routine in the interrupt
14241  vector table
14242 \begin_inset LatexCommand \index{interrupt vector table}
14243
14244 \end_inset
14245
14246  for the interrupt number specified.
14247  If you have multiple source files in your project, interrupt service routines
14248  can be present in any of them, but a prototype of the isr MUST be present
14249  or included in the file that contains the function 
14250 \emph on
14251 main
14252 \emph default
14253 .
14254  The optional (8051 specific) keyword 
14255 \emph on
14256 using
14257 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14258
14259 \end_inset
14260
14261
14262 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14263
14264 \end_inset
14265
14266
14267 \emph default
14268  can be used to tell the compiler to use the specified register bank when
14269  generating code for this function.
14270  
14271 \newline
14272 Interrupt service routines open the door for some very interesting bugs:
14273 \end_layout
14274
14275 \begin_layout Subsubsection
14276 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14277
14278 \end_inset
14279
14280 Common interrupt pitfall: variable not declared 
14281 \emph on
14282 volatile
14283 \end_layout
14284
14285 \begin_layout Standard
14286 If an interrupt service routine changes variables which are accessed by
14287  other functions these variables have to be declared 
14288 \emph on
14289 volatile
14290 \emph default
14291
14292 \begin_inset LatexCommand \index{volatile}
14293
14294 \end_inset
14295
14296 .
14297  See 
14298 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14299
14300 \end_inset
14301
14302  .
14303 \end_layout
14304
14305 \begin_layout Subsubsection
14306 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14307
14308 \end_inset
14309
14310 Common interrupt pitfall: 
14311 \emph on
14312 non-atomic access
14313 \end_layout
14314
14315 \begin_layout Standard
14316 If the access to these variables is not 
14317 \emph on
14318 atomic
14319 \begin_inset LatexCommand \index{atomic}
14320
14321 \end_inset
14322
14323
14324 \emph default
14325  (i.e.
14326  the processor needs more than one instruction for the access and could
14327  be interrupted while accessing the variable) the interrupt must be disabled
14328  during the access to avoid inconsistent data.
14329  
14330 \newline
14331 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14332  and should be protected by disabling interrupts.
14333  You're not automatically on the safe side if you use 8 bit variables though.
14334  We need an example here: f.e.
14335  on the 8051 the harmless looking 
14336 \begin_inset Quotes srd
14337 \end_inset
14338
14339
14340 \family typewriter
14341 flags\InsetSpace ~
14342 |=\InsetSpace ~
14343 0x80;
14344 \family default
14345
14346 \begin_inset Quotes sld
14347 \end_inset
14348
14349  is not atomic if 
14350 \family typewriter
14351 flags
14352 \family default
14353  resides in xdata.
14354  Setting 
14355 \begin_inset Quotes srd
14356 \end_inset
14357
14358
14359 \family typewriter
14360 flags\InsetSpace ~
14361 |=\InsetSpace ~
14362 0x40;
14363 \family default
14364
14365 \begin_inset Quotes sld
14366 \end_inset
14367
14368  from within an interrupt routine might get lost if the interrupt occurs
14369  at the wrong time.
14370  
14371 \begin_inset Quotes sld
14372 \end_inset
14373
14374
14375 \family typewriter
14376 counter\InsetSpace ~
14377 +=\InsetSpace ~
14378 8;
14379 \family default
14380
14381 \begin_inset Quotes srd
14382 \end_inset
14383
14384  is not atomic on the 8051 even if 
14385 \family typewriter
14386 counter
14387 \family default
14388  is located in data memory.
14389 \newline
14390 Bugs like these are hard to reproduce and can
14391  cause a lot of trouble.
14392  
14393 \end_layout
14394
14395 \begin_layout Subsubsection
14396 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14397
14398 \end_inset
14399
14400 Common interrupt pitfall: 
14401 \emph on
14402 stack overflow
14403 \end_layout
14404
14405 \begin_layout Standard
14406 The return address and the registers used in the interrupt service routine
14407  are saved on the stack
14408 \begin_inset LatexCommand \index{stack}
14409
14410 \end_inset
14411
14412  so there must be sufficient stack space.
14413  If there isn't variables or registers (or even the return address itself)
14414  will be corrupted.
14415  This 
14416 \emph on
14417 stack overflow
14418 \emph default
14419
14420 \begin_inset LatexCommand \index{stack overflow}
14421
14422 \end_inset
14423
14424  is most likely to happen if the interrupt occurs during the 
14425 \begin_inset Quotes sld
14426 \end_inset
14427
14428 deepest
14429 \begin_inset Quotes srd
14430 \end_inset
14431
14432  subroutine when the stack is already in use for f.e.
14433  many return addresses.
14434 \end_layout
14435
14436 \begin_layout Subsubsection
14437 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14438
14439 \end_inset
14440
14441 Common interrupt pitfall: 
14442 \emph on
14443 use of non-reentrant functions
14444 \end_layout
14445
14446 \begin_layout Standard
14447 A special note here, int (16 bit) and long (32 bit) integer division
14448 \begin_inset LatexCommand \index{Division}
14449
14450 \end_inset
14451
14452 , multiplication
14453 \begin_inset LatexCommand \index{Multiplication}
14454
14455 \end_inset
14456
14457  & modulus
14458 \begin_inset LatexCommand \index{Modulus}
14459
14460 \end_inset
14461
14462  and floating-point
14463 \begin_inset LatexCommand \index{Floating point support}
14464
14465 \end_inset
14466
14467  operations are implemented using external support routines.
14468  If an interrupt service routine needs to do any of these operations then
14469  the support routines (as mentioned in a following section) will have to
14470  be recompiled using the
14471 \emph on
14472  -
14473 \begin_inset ERT
14474 status collapsed
14475
14476 \begin_layout Standard
14477
14478
14479 \backslash
14480 /
14481 \end_layout
14482
14483 \end_inset
14484
14485 -stack-auto
14486 \begin_inset LatexCommand \index{-\/-stack-auto}
14487
14488 \end_inset
14489
14490
14491 \emph default
14492  option and the source file will need to be compiled using the 
14493 \emph on
14494 -
14495 \begin_inset ERT
14496 status collapsed
14497
14498 \begin_layout Standard
14499
14500
14501 \backslash
14502 /
14503 \end_layout
14504
14505 \end_inset
14506
14507 -int-long-reent
14508 \emph default
14509
14510 \begin_inset LatexCommand \index{-\/-int-long-reent}
14511
14512 \end_inset
14513
14514  compiler option.
14515  
14516 \newline
14517 Note, the type promotion
14518 \begin_inset LatexCommand \index{type promotion}
14519
14520 \end_inset
14521
14522  required by ANSI C can cause 16 bit routines to be used
14523 \begin_inset Marginal
14524 status collapsed
14525
14526 \begin_layout Standard
14527
14528 \series bold
14529 \InsetSpace ~
14530 !
14531 \end_layout
14532
14533 \end_inset
14534
14535  without the programmer being aware of it.
14536  See f.e.
14537  the cast 
14538 \family typewriter
14539 (unsigned char)(tail-1)
14540 \family default
14541  within the if clause in section 
14542 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14543
14544 \end_inset
14545
14546 .
14547 \end_layout
14548
14549 \begin_layout Standard
14550 Calling other functions from an interrupt service routine is not recommended,
14551  avoid it if possible.
14552  Note that when some function is called from an interrupt service routine
14553  it should be preceded by a #pragma\InsetSpace ~
14554 nooverlay
14555 \begin_inset LatexCommand \index{\#pragma nooverlay}
14556
14557 \end_inset
14558
14559  if it is not reentrant.
14560  Furthermore nonreentrant functions should not be called from the main program
14561  while the interrupt service routine might be active.
14562  They also must not be called from low priority interrupt service routines
14563  while a high priority interrupt service routine might be active.
14564  You could use semaphores or make the function
14565 \emph on
14566  critical
14567 \emph default
14568  if all parameters are passed in registers.
14569 \newline
14570  Also see section 
14571 \begin_inset LatexCommand \ref{sub:Overlaying}
14572
14573 \end_inset
14574
14575 \InsetSpace ~
14576 about Overlaying and section 
14577 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14578
14579 \end_inset
14580
14581 \InsetSpace ~
14582 about Functions using private register banks.
14583 \begin_inset VSpace bigskip
14584 \end_inset
14585
14586
14587 \end_layout
14588
14589 \begin_layout Subsection
14590 MCS51/DS390 Interrupt Service Routines
14591 \end_layout
14592
14593 \begin_layout Standard
14594 Interrupt
14595 \begin_inset LatexCommand \index{interrupt}
14596
14597 \end_inset
14598
14599  numbers and the corresponding address & descriptions for the Standard 8051/8052
14600  are listed below.
14601  SDCC will automatically adjust the 
14602 \begin_inset LatexCommand \index{interrupt vector table}
14603
14604 \end_inset
14605
14606  to the maximum interrupt number specified.
14607 \newline
14608
14609 \end_layout
14610
14611 \begin_layout Standard
14612 \align center
14613 \begin_inset Tabular
14614 <lyxtabular version="3" rows="9" columns="3">
14615 <features>
14616 <column alignment="center" valignment="top" leftline="true" width="0in">
14617 <column alignment="left" valignment="top" leftline="true" width="0in">
14618 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14619 <row topline="true" bottomline="true">
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14621 \begin_inset Text
14622
14623 \begin_layout Standard
14624 Interrupt #
14625 \end_layout
14626
14627 \end_inset
14628 </cell>
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14630 \begin_inset Text
14631
14632 \begin_layout Standard
14633 Description
14634 \end_layout
14635
14636 \end_inset
14637 </cell>
14638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14639 \begin_inset Text
14640
14641 \begin_layout Standard
14642 Vector Address
14643 \end_layout
14644
14645 \end_inset
14646 </cell>
14647 </row>
14648 <row topline="true">
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14650 \begin_inset Text
14651
14652 \begin_layout Standard
14653 0
14654 \end_layout
14655
14656 \end_inset
14657 </cell>
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14659 \begin_inset Text
14660
14661 \begin_layout Standard
14662 External 0
14663 \end_layout
14664
14665 \end_inset
14666 </cell>
14667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14668 \begin_inset Text
14669
14670 \begin_layout Standard
14671 0x0003
14672 \end_layout
14673
14674 \end_inset
14675 </cell>
14676 </row>
14677 <row topline="true">
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14679 \begin_inset Text
14680
14681 \begin_layout Standard
14682 1
14683 \end_layout
14684
14685 \end_inset
14686 </cell>
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14688 \begin_inset Text
14689
14690 \begin_layout Standard
14691 Timer 0
14692 \end_layout
14693
14694 \end_inset
14695 </cell>
14696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14697 \begin_inset Text
14698
14699 \begin_layout Standard
14700 0x000b
14701 \end_layout
14702
14703 \end_inset
14704 </cell>
14705 </row>
14706 <row topline="true">
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14708 \begin_inset Text
14709
14710 \begin_layout Standard
14711 2
14712 \end_layout
14713
14714 \end_inset
14715 </cell>
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14717 \begin_inset Text
14718
14719 \begin_layout Standard
14720 External 1
14721 \end_layout
14722
14723 \end_inset
14724 </cell>
14725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14726 \begin_inset Text
14727
14728 \begin_layout Standard
14729 0x0013
14730 \end_layout
14731
14732 \end_inset
14733 </cell>
14734 </row>
14735 <row topline="true">
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14737 \begin_inset Text
14738
14739 \begin_layout Standard
14740 3
14741 \end_layout
14742
14743 \end_inset
14744 </cell>
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14746 \begin_inset Text
14747
14748 \begin_layout Standard
14749 Timer 1
14750 \end_layout
14751
14752 \end_inset
14753 </cell>
14754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14755 \begin_inset Text
14756
14757 \begin_layout Standard
14758 0x001b
14759 \end_layout
14760
14761 \end_inset
14762 </cell>
14763 </row>
14764 <row topline="true">
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14766 \begin_inset Text
14767
14768 \begin_layout Standard
14769 4
14770 \end_layout
14771
14772 \end_inset
14773 </cell>
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14775 \begin_inset Text
14776
14777 \begin_layout Standard
14778 Serial
14779 \end_layout
14780
14781 \end_inset
14782 </cell>
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14784 \begin_inset Text
14785
14786 \begin_layout Standard
14787 0x0023
14788 \end_layout
14789
14790 \end_inset
14791 </cell>
14792 </row>
14793 <row topline="true">
14794 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14795 \begin_inset Text
14796
14797 \begin_layout Standard
14798 5
14799 \end_layout
14800
14801 \end_inset
14802 </cell>
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14804 \begin_inset Text
14805
14806 \begin_layout Standard
14807 Timer 2 (8052)
14808 \end_layout
14809
14810 \end_inset
14811 </cell>
14812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14813 \begin_inset Text
14814
14815 \begin_layout Standard
14816 0x002b
14817 \end_layout
14818
14819 \end_inset
14820 </cell>
14821 </row>
14822 <row topline="true">
14823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14824 \begin_inset Text
14825
14826 \begin_layout Standard
14827 ...
14828 \end_layout
14829
14830 \end_inset
14831 </cell>
14832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14833 \begin_inset Text
14834
14835 \begin_layout Standard
14836
14837 \end_layout
14838
14839 \end_inset
14840 </cell>
14841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14842 \begin_inset Text
14843
14844 \begin_layout Standard
14845 ...
14846 \end_layout
14847
14848 \end_inset
14849 </cell>
14850 </row>
14851 <row topline="true" bottomline="true">
14852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14853 \begin_inset Text
14854
14855 \begin_layout Standard
14856 n
14857 \end_layout
14858
14859 \end_inset
14860 </cell>
14861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14862 \begin_inset Text
14863
14864 \begin_layout Standard
14865
14866 \end_layout
14867
14868 \end_inset
14869 </cell>
14870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14871 \begin_inset Text
14872
14873 \begin_layout Standard
14874 0x0003 + 8*n
14875 \end_layout
14876
14877 \end_inset
14878 </cell>
14879 </row>
14880 </lyxtabular>
14881
14882 \end_inset
14883
14884
14885 \newline
14886
14887 \end_layout
14888
14889 \begin_layout Standard
14890 If the interrupt service routine is defined without 
14891 \emph on
14892 using
14893 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14894
14895 \end_inset
14896
14897
14898 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14899
14900 \end_inset
14901
14902
14903 \emph default
14904  a register bank or with register bank 0 (
14905 \emph on
14906 using
14907 \emph default
14908  0), the compiler will save the registers used by itself on the stack upon
14909  entry and restore them at exit, however if such an interrupt service routine
14910  calls another function then the entire register bank will be saved on the
14911  stack.
14912  This scheme may be advantageous for small interrupt service routines which
14913  have low register usage.
14914 \end_layout
14915
14916 \begin_layout Standard
14917 If the interrupt service routine is defined to be using a specific register
14918  bank then only 
14919 \emph on
14920 a, b, dptr
14921 \emph default
14922  & psw are saved and restored, if such an interrupt service routine calls
14923  another function (using another register bank) then the entire register
14924  bank of the called function will be saved on the stack
14925 \begin_inset LatexCommand \index{stack}
14926
14927 \end_inset
14928
14929 .
14930  This scheme is recommended for larger interrupt service routines.
14931 \begin_inset VSpace bigskip
14932 \end_inset
14933
14934
14935 \end_layout
14936
14937 \begin_layout Subsection
14938 HC08
14939 \begin_inset LatexCommand \index{HC08}
14940
14941 \end_inset
14942
14943  Interrupt Service Routines
14944 \end_layout
14945
14946 \begin_layout Standard
14947 Since the number of interrupts
14948 \begin_inset LatexCommand \index{HC08!interrupt}
14949
14950 \end_inset
14951
14952  available is chip specific and the interrupt vector table always ends at
14953  the last byte of memory, the interrupt numbers corresponds to the interrupt
14954  vectors in reverse order of address.
14955  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14956  2 will use the interrupt vector at 0xfffa, and so on.
14957  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14958  this way; instead see section 
14959 \begin_inset LatexCommand \ref{sub:Startup-Code}
14960
14961 \end_inset
14962
14963  for details on customizing startup.
14964 \begin_inset VSpace bigskip
14965 \end_inset
14966
14967
14968 \end_layout
14969
14970 \begin_layout Subsection
14971 Z80 Interrupt Service Routines
14972 \end_layout
14973
14974 \begin_layout Standard
14975 The Z80
14976 \begin_inset LatexCommand \index{Z80}
14977
14978 \end_inset
14979
14980  uses several different methods for determining the correct interrupt
14981 \begin_inset LatexCommand \index{Z80!interrupt}
14982
14983 \end_inset
14984
14985  vector depending on the hardware implementation.
14986  Therefore, SDCC ignores the optional interrupt number and does not attempt
14987  to generate an interrupt vector table.
14988 \end_layout
14989
14990 \begin_layout Standard
14991 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14992  instruction to return from the interrupt.
14993  To write an interrupt handler for the non-maskable interrupt, which needs
14994  a RETN instruction instead, add the 
14995 \emph on
14996 critical
14997 \emph default
14998  keyword:
14999 \end_layout
15000
15001 \begin_layout Verse
15002
15003 \family typewriter
15004 void nmi_isr (void) critical interrupt
15005 \newline
15006
15007 \newline
15008 \InsetSpace ~
15009 \InsetSpace ~
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 ...
15013  
15014 \newline
15015 }
15016 \end_layout
15017
15018 \begin_layout Standard
15019 However if you need to create a non-interruptable interrupt service routine
15020  you would also require the 
15021 \emph on
15022 critical
15023 \emph default
15024  keyword.
15025  To distinguish between this and an nmi_isr you must provide an interrupt
15026  number.
15027 \begin_inset VSpace bigskip
15028 \end_inset
15029
15030
15031 \end_layout
15032
15033 \begin_layout Section
15034 Enabling and Disabling Interrupts
15035 \end_layout
15036
15037 \begin_layout Subsection
15038 Critical Functions and Critical Statements
15039 \end_layout
15040
15041 \begin_layout Standard
15042 A special keyword may be associated with a block or a function declaring
15043  it as 
15044 \emph on
15045 critical
15046 \emph default
15047 .
15048  SDCC will generate code to disable all interrupts
15049 \begin_inset LatexCommand \index{interrupt}
15050
15051 \end_inset
15052
15053  upon entry to a critical function and restore the interrupt enable to the
15054  previous state before returning.
15055  Nesting critical functions will need one additional byte on the stack
15056 \begin_inset LatexCommand \index{stack}
15057
15058 \end_inset
15059
15060  for each call.
15061 \end_layout
15062
15063 \begin_layout Verse
15064
15065 \family typewriter
15066 int foo () __critical
15067 \begin_inset LatexCommand \index{critical}
15068
15069 \end_inset
15070
15071
15072 \begin_inset LatexCommand \index{\_\_critical}
15073
15074 \end_inset
15075
15076  
15077 \newline
15078
15079 \newline
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 ...
15085  
15086 \newline
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 ...
15092  
15093 \newline
15094 }
15095 \end_layout
15096
15097 \begin_layout Standard
15098 The critical attribute maybe used with other attributes like 
15099 \emph on
15100 reentrant.
15101 \emph default
15102
15103 \newline
15104 The keyword 
15105 \emph on
15106 critical
15107 \emph default
15108  may also be used to disable interrupts more locally:
15109 \end_layout
15110
15111 \begin_layout Verse
15112
15113 \family typewriter
15114 __critical{ i++; }
15115 \end_layout
15116
15117 \begin_layout Standard
15118 More than one statement could have been included in the block.
15119 \end_layout
15120
15121 \begin_layout Subsection
15122 Enabling and Disabling Interrupts directly
15123 \end_layout
15124
15125 \begin_layout Standard
15126 Interrupts
15127 \begin_inset LatexCommand \index{interrupt}
15128
15129 \end_inset
15130
15131  can also be disabled and enabled directly (8051):
15132 \end_layout
15133
15134 \begin_layout Verse
15135
15136 \family typewriter
15137 EA = 0;\InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 or:\InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 EA_SAVE = EA;
15161 \end_layout
15162
15163 \begin_layout Verse
15164
15165 \family typewriter
15166 ...\InsetSpace ~
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 EA = 0;
15197 \end_layout
15198
15199 \begin_layout Verse
15200
15201 \family typewriter
15202 EA = 1;\InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 ...
15229 \end_layout
15230
15231 \begin_layout Verse
15232
15233 \family typewriter
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 \InsetSpace ~
15241 \InsetSpace ~
15242 \InsetSpace ~
15243 \InsetSpace ~
15244 \InsetSpace ~
15245 \InsetSpace ~
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 \InsetSpace ~
15249 \InsetSpace ~
15250 \InsetSpace ~
15251 \InsetSpace ~
15252 \InsetSpace ~
15253 \InsetSpace ~
15254 \InsetSpace ~
15255 \InsetSpace ~
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 \InsetSpace ~
15265 \InsetSpace ~
15266 \InsetSpace ~
15267 EA = EA_SAVE;
15268 \end_layout
15269
15270 \begin_layout Standard
15271 On other architectures which have seperate opcodes for enabling and disabling
15272  interrupts you might want to make use of defines with inline assembly
15273 \begin_inset LatexCommand \index{Assembler routines}
15274
15275 \end_inset
15276
15277  (HC08
15278 \begin_inset LatexCommand \index{HC08!interrupt}
15279
15280 \end_inset
15281
15282 ):
15283 \end_layout
15284
15285 \begin_layout Verse
15286
15287 \family typewriter
15288 #define CLI _asm
15289 \begin_inset LatexCommand \index{\_asm}
15290
15291 \end_inset
15292
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 cli\InsetSpace ~
15296 \InsetSpace ~
15297 _endasm
15298 \begin_inset LatexCommand \index{\_endasm}
15299
15300 \end_inset
15301
15302
15303 \end_layout
15304
15305 \begin_layout Verse
15306
15307 \family typewriter
15308 #define SEI _asm\InsetSpace ~
15309 \InsetSpace ~
15310 sei\InsetSpace ~
15311 \InsetSpace ~
15312 _endasm; 
15313 \end_layout
15314
15315 \begin_layout Verse
15316
15317 \family typewriter
15318 ...
15319 \end_layout
15320
15321 \begin_layout Standard
15322 Note: it is sometimes sufficient to disable only a specific interrupt source
15323  like f.e.
15324  a timer or serial interrupt by manipulating an 
15325 \emph on
15326 interrupt mask
15327 \begin_inset LatexCommand \index{interrupt mask}
15328
15329 \end_inset
15330
15331
15332 \emph default
15333  register.
15334  
15335 \end_layout
15336
15337 \begin_layout Standard
15338 Usually the time during which interrupts are disabled should be kept as
15339  short as possible.
15340  This minimizes both 
15341 \emph on
15342 interrupt latency
15343 \emph default
15344
15345 \begin_inset LatexCommand \index{interrupt latency}
15346
15347 \end_inset
15348
15349  (the time between the occurrence of the interrupt and the execution of
15350  the first code in the interrupt routine) and 
15351 \emph on
15352 interrupt jitter
15353 \emph default
15354
15355 \begin_inset LatexCommand \index{interrupt jitter}
15356
15357 \end_inset
15358
15359  (the difference between the shortest and the longest interrupt latency).
15360  These really are something different, f.e.
15361  a serial interrupt has to be served before its buffer overruns so it cares
15362  for the maximum interrupt latency, whereas it does not care about jitter.
15363  On a loudspeaker driven via a digital to analog converter which is fed
15364  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15365  a much smaller jitter will be very audible.
15366 \end_layout
15367
15368 \begin_layout Standard
15369 You can reenable interrupts within an interrupt routine and on some architecture
15370 s you can make use of two (or more) levels of 
15371 \emph on
15372 interrupt priorities
15373 \emph default
15374
15375 \begin_inset LatexCommand \index{interrupt priority}
15376
15377 \end_inset
15378
15379 .
15380  On some architectures which don't support interrupt priorities these can
15381  be implemented by manipulating the interrupt mask and reenabling interrupts
15382  within the interrupt routine.
15383  Check there is sufficient space on the stack
15384 \begin_inset LatexCommand \index{stack}
15385
15386 \end_inset
15387
15388  and don't add complexity unless you have to.
15389  
15390 \end_layout
15391
15392 \begin_layout Subsection
15393 Semaphore
15394 \begin_inset LatexCommand \index{semaphore}
15395
15396 \end_inset
15397
15398  locking (mcs51/ds390)
15399 \end_layout
15400
15401 \begin_layout Standard
15402 Some architectures (mcs51/ds390) have an atomic
15403 \begin_inset LatexCommand \index{atomic}
15404
15405 \end_inset
15406
15407  bit test and
15408 \emph on
15409  
15410 \emph default
15411 clear
15412 \emph on
15413  
15414 \emph default
15415 instruction.
15416  These type of instructions are typically used in preemptive multitasking
15417  systems, where a routine f.e.
15418  claims the use of a data structure ('acquires a lock
15419 \begin_inset LatexCommand \index{lock}
15420
15421 \end_inset
15422
15423  on it'), makes some modifications and then releases the lock when the data
15424  structure is consistent again.
15425  The instruction may also be used if interrupt and non-interrupt code have
15426  to compete for a resource.
15427  With the atomic bit test and clear instruction interrupts
15428 \begin_inset LatexCommand \index{interrupt}
15429
15430 \end_inset
15431
15432  don't have to be disabled for the locking operation.
15433  
15434 \end_layout
15435
15436 \begin_layout Standard
15437 SDCC generates this instruction if the source follows this pattern:
15438 \end_layout
15439
15440 \begin_layout Verse
15441
15442 \family typewriter
15443 volatile
15444 \begin_inset LatexCommand \index{volatile}
15445
15446 \end_inset
15447
15448  bit resource_is_free; 
15449 \newline
15450
15451 \newline
15452 if (resource_is_free) 
15453 \newline
15454 \InsetSpace ~
15455 \InsetSpace ~
15456
15457 \newline
15458 \InsetSpace ~
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 resource_is_free=0; 
15463 \newline
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 \InsetSpace ~
15468 ...
15469  
15470 \newline
15471 \InsetSpace ~
15472 \InsetSpace ~
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 resource_is_free=1;
15476 \newline
15477 \InsetSpace ~
15478 \InsetSpace ~
15479
15480 \end_layout
15481
15482 \begin_layout Standard
15483 Note, mcs51 and ds390 support only an atomic
15484 \begin_inset LatexCommand \index{atomic}
15485
15486 \end_inset
15487
15488  bit test and 
15489 \emph on
15490 clear
15491 \emph default
15492  instruction (as opposed to atomic bit test and 
15493 \emph on
15494 set).
15495 \end_layout
15496
15497 \begin_layout Section
15498 Functions using private register banks
15499 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15500
15501 \end_inset
15502
15503  (mcs51/ds390)
15504 \end_layout
15505
15506 \begin_layout Standard
15507 Some architectures have support for quickly changing register sets.
15508  SDCC supports this feature with the 
15509 \emph on
15510 using
15511 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15512
15513 \end_inset
15514
15515
15516 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15517
15518 \end_inset
15519
15520
15521 \emph default
15522  attribute (which tells the compiler to use a register bank
15523 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15524
15525 \end_inset
15526
15527  other than the default bank zero).
15528  It should only be applied to 
15529 \emph on
15530 interrupt
15531 \begin_inset LatexCommand \index{interrupt}
15532
15533 \end_inset
15534
15535
15536 \emph default
15537  functions (see footnote below).
15538  This will in most circumstances make the generated ISR code more efficient
15539  since it will not have to save registers on the stack.
15540 \end_layout
15541
15542 \begin_layout Standard
15543 The 
15544 \emph on
15545 using
15546 \emph default
15547  attribute will have no effect on the generated code for a 
15548 \emph on
15549 non-interrupt
15550 \emph default
15551  function (but may occasionally be useful anyway
15552 \begin_inset Foot
15553 status open
15554
15555 \begin_layout Standard
15556 possible exception: if a function is called ONLY from 'interrupt' functions
15557  using a particular bank, it can be declared with the same 'using' attribute
15558  as the calling 'interrupt' functions.
15559  For instance, if you have several ISRs using bank one, and all of them
15560  call memcpy(), it might make sense to create a specialized version of memcpy()
15561  'using 1', since this would prevent the ISR from having to save bank zero
15562  to the stack on entry and switch to bank zero before calling the function
15563 \end_layout
15564
15565 \end_inset
15566
15567 ).
15568 \newline
15569
15570 \emph on
15571 (pending: Note, nowadays the 
15572 \emph default
15573 using
15574 \emph on
15575  attribute has an effect on
15576 \emph default
15577  
15578 \emph on
15579 the generated code for a 
15580 \emph default
15581 non-interrupt
15582 \emph on
15583  function
15584 \emph default
15585 .
15586 \emph on
15587 )
15588 \end_layout
15589
15590 \begin_layout Standard
15591 An 
15592 \emph on
15593 interrupt
15594 \emph default
15595  function using a non-zero bank will assume that it can trash that register
15596  bank, and will not save it.
15597  Since high-priority interrupts
15598 \begin_inset LatexCommand \index{interrupts}
15599
15600 \end_inset
15601
15602
15603 \begin_inset LatexCommand \index{interrupt priority}
15604
15605 \end_inset
15606
15607  can interrupt low-priority ones on the 8051 and friends, this means that
15608  if a high-priority ISR 
15609 \emph on
15610 using
15611 \emph default
15612  a particular bank occurs while processing a low-priority ISR 
15613 \emph on
15614 using
15615 \emph default
15616  the same bank, terrible and bad things can happen.
15617  To prevent this, no single register bank should be 
15618 \emph on
15619 used
15620 \emph default
15621  by both a high priority and a low priority ISR.
15622  This is probably most easily done by having all high priority ISRs use
15623  one bank and all low priority ISRs use another.
15624  If you have an ISR which can change priority at runtime, you're on your
15625  own: I suggest using the default bank zero and taking the small performance
15626  hit.
15627 \end_layout
15628
15629 \begin_layout Standard
15630 It is most efficient if your ISR calls no other functions.
15631  If your ISR must call other functions, it is most efficient if those functions
15632  use the same bank as the ISR (see note 1 below); the next best is if the
15633  called functions use bank zero.
15634  It is very inefficient to call a function using a different, non-zero bank
15635  from an ISR.
15636  
15637 \begin_inset VSpace bigskip
15638 \end_inset
15639
15640
15641 \end_layout
15642
15643 \begin_layout Section
15644 Startup Code
15645 \begin_inset LatexCommand \label{sub:Startup-Code}
15646
15647 \end_inset
15648
15649
15650 \begin_inset LatexCommand \index{Startup code}
15651
15652 \end_inset
15653
15654
15655 \end_layout
15656
15657 \begin_layout Subsection
15658 MCS51/DS390 Startup Code
15659 \end_layout
15660
15661 \begin_layout Standard
15662 The compiler triggers the linker to link certain initialization modules
15663  from the runtime library
15664 \begin_inset LatexCommand \index{Runtime library}
15665
15666 \end_inset
15667
15668  called crt<something>.
15669  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15670  GSINIT5) is not linked unless the -
15671 \series bold
15672
15673 \begin_inset ERT
15674 status open
15675
15676 \begin_layout Standard
15677
15678
15679 \backslash
15680 /
15681 \end_layout
15682
15683 \end_inset
15684
15685
15686 \series default
15687 -xstack option is used.
15688  These modules are highly entangled by the use of special segments/areas,
15689  but a common layout is shown below:
15690 \end_layout
15691
15692 \begin_layout Verse
15693
15694 \family typewriter
15695 \series bold
15696 \size footnotesize
15697 (main.asm)
15698 \end_layout
15699
15700 \begin_layout Verse
15701
15702 \family typewriter
15703 \size footnotesize
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 .area HOME (CODE)
15713 \newline
15714 __interrupt_vect:
15715 \newline
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 ljmp __sdcc_gsinit_startup
15725 \end_layout
15726
15727 \begin_layout Verse
15728
15729 \family typewriter
15730 \series bold
15731 \size footnotesize
15732 (crtstart.asm)
15733 \end_layout
15734
15735 \begin_layout Verse
15736
15737 \family typewriter
15738 \size footnotesize
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 .area GSINIT0 (CODE)
15748 \newline
15749 __sdcc_gsinit_startup::
15750 \newline
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 mov sp,#__start__stack - 1
15760 \end_layout
15761
15762 \begin_layout Verse
15763
15764 \family typewriter
15765 \series bold
15766 \size footnotesize
15767 (crtxstack.asm)
15768 \end_layout
15769
15770 \begin_layout Verse
15771
15772 \family typewriter
15773 \size footnotesize
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 .area GSINIT1 (CODE)
15783 \newline
15784 __sdcc_init_xstack::
15785 \newline
15786 ; Need to initialize in GSINIT1 in
15787  case the user's __sdcc_external_startup uses the xstack.
15788 \newline
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 mov __XPAGE,#(__start__x
15798 stack >> 8)
15799 \newline
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 mov _spx,#__start__xstack
15809 \end_layout
15810
15811 \begin_layout Verse
15812
15813 \family typewriter
15814 \series bold
15815 \size footnotesize
15816 (crtstart.asm)
15817 \end_layout
15818
15819 \begin_layout Verse
15820
15821 \family typewriter
15822 \size footnotesize
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 \InsetSpace ~
15831 .area GSINIT2 (CODE)
15832 \newline
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 lcall __sdcc_external_startup
15842 \newline
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 mov a,dpl
15852 \newline
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 jz __sdcc_init_data
15862 \newline
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 ljmp
15872  __sdcc_program_startup
15873 \newline
15874 __sdcc_init_data:
15875 \end_layout
15876
15877 \begin_layout Verse
15878
15879 \family typewriter
15880 \series bold
15881 \size footnotesize
15882 (crtxinit.asm)
15883 \end_layout
15884
15885 \begin_layout Verse
15886
15887 \family typewriter
15888 \size footnotesize
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 .area GSINIT3 (CODE)
15898 \newline
15899 __mcs51_genXINIT::
15900 \newline
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 mov r1,#l_XINIT
15910 \newline
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 mov a,r1
15920 \newline
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 orl a,#(l_XINIT
15930  >> 8)
15931 \newline
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 jz 00003$
15941 \newline
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 mov r2,#((l_XINIT+255) >> 8)
15951 \newline
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 mov dptr,#s_XINIT
15961 \newline
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 mov r0,#s_XISEG
15971 \newline
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 mov
15981  __XPAGE,#(s_XISEG >> 8)
15982 \newline
15983 00001$:\InsetSpace ~
15984 clr a
15985 \newline
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 movc a,@a+dptr
15995 \newline
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 movx @r0,a
16005 \newline
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 inc dptr
16015 \newline
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 inc
16025  r0
16026 \newline
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 cjne r0,#0,00002$
16036 \newline
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 inc __XPAGE
16046 \newline
16047 00002$:\InsetSpace ~
16048 djnz r1,00001$
16049 \newline
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 djnz r2,00001$
16059 \newline
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 \InsetSpace ~
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 mov __XPAGE,#0
16069 xFF
16070 \newline
16071 00003$:
16072 \end_layout
16073
16074 \begin_layout Verse
16075
16076 \family typewriter
16077 \series bold
16078 \size footnotesize
16079 (crtclear.asm)
16080 \end_layout
16081
16082 \begin_layout Verse
16083
16084 \family typewriter
16085 \size footnotesize
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 \InsetSpace ~
16089 \InsetSpace ~
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 .area GSINIT4 (CODE)
16095 \newline
16096 __mcs51_genRAMCLEAR::
16097 \newline
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 \InsetSpace ~
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 clr a
16107 \newline
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 \InsetSpace ~
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 mov r0,#(l_IRAM-1)
16117 \newline
16118 00004$:\InsetSpace ~
16119 mov
16120  @r0,a
16121 \newline
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 djnz r0,00004$
16131 \newline
16132 ; _mcs51_genRAMCLEAR() end
16133 \end_layout
16134
16135 \begin_layout Verse
16136
16137 \family typewriter
16138 \series bold
16139 \size footnotesize
16140 (crtxclear.asm)
16141 \end_layout
16142
16143 \begin_layout Verse
16144
16145 \family typewriter
16146 \size footnotesize
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 \InsetSpace ~
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 .area GSINIT4 (CODE)
16156 \newline
16157 __mcs51_genXRAMCLEAR::
16158 \newline
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 mov r0,#l_PSEG
16168 \newline
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 mov a,r0
16178 \newline
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 orl a,#(l_PSEG
16188  >> 8)
16189 \newline
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 jz 00006$
16199 \newline
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 mov r1,#s_PSEG
16209 \newline
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 mov __XPAGE,#(s_PSEG >> 8)
16219 \newline
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 clr a
16229 \newline
16230 00005$:\InsetSpace ~
16231 movx
16232  @r1,a
16233 \newline
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 inc r1
16243 \newline
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 djnz r0,00005$
16253 \newline
16254 00006$:
16255 \newline
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 mov r0,#l_XSEG
16265 \newline
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 \InsetSpace ~
16274 mov a,r0
16275 \newline
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 orl a,#(l_XSEG >>
16285  8)
16286 \newline
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 jz 00008$
16296 \newline
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 mov r1,#((l_XSEG + 255) >> 8)
16306 \newline
16307 \InsetSpace ~
16308 \InsetSpace ~
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 mov dptr,#s_XSEG
16316 \newline
16317 \InsetSpace ~
16318 \InsetSpace ~
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 clr a
16326 \newline
16327 00007$:\InsetSpace ~
16328 movx
16329  @dptr,a
16330 \newline
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 inc dptr
16340 \newline
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 \InsetSpace ~
16344 \InsetSpace ~
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 djnz r0,00007$
16350 \newline
16351 \InsetSpace ~
16352 \InsetSpace ~
16353 \InsetSpace ~
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 djnz r1,00007$
16360 \newline
16361 00008$:
16362 \end_layout
16363
16364 \begin_layout Verse
16365
16366 \family typewriter
16367 \series bold
16368 \size footnotesize
16369 (crtxstack.asm)
16370 \end_layout
16371
16372 \begin_layout Verse
16373
16374 \family typewriter
16375 \size footnotesize
16376 \InsetSpace ~
16377 \InsetSpace ~
16378 \InsetSpace ~
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 .area GSINIT5 (CODE)
16385 \newline
16386 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16387  modifies __XPAGE
16388 \newline
16389 ; and __mcs51_genRAMCLEAR modifies _spx.
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 mov __XPAGE,#(__start__x
16400 stack >> 8)
16401 \newline
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 \InsetSpace ~
16410 mov _spx,#__start__xstack
16411 \end_layout
16412
16413 \begin_layout Verse
16414
16415 \family typewriter
16416 \series bold
16417 \size footnotesize
16418 (application modules)
16419 \end_layout
16420
16421 \begin_layout Verse
16422
16423 \family typewriter
16424 \size footnotesize
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 .area GSINIT (CODE)
16434 \end_layout
16435
16436 \begin_layout Verse
16437
16438 \family typewriter
16439 \series bold
16440 \size footnotesize
16441 (main.asm)
16442 \end_layout
16443
16444 \begin_layout Verse
16445
16446 \family typewriter
16447 \size footnotesize
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 .area GSFINAL (CODE)
16457 \newline
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 \InsetSpace ~
16463 \InsetSpace ~
16464 \InsetSpace ~
16465 \InsetSpace ~
16466 ljmp __sdcc_program_startup
16467 \newline
16468 ;---------------------------------
16469 -----------------------
16470 \newline
16471 ; Home
16472 \newline
16473 ;--------------------------------------------------
16474 ------
16475 \newline
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 .area HOME (CODE)
16485 \newline
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 .area CSEG (CODE)
16495 \newline
16496 __sdcc_program_startup:
16497 \newline
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 \InsetSpace ~
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 lcall _main
16507 \newline
16508 ;
16509  return from main will lock up
16510 \newline
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 sjmp .
16520 \end_layout
16521
16522 \begin_layout Standard
16523 One of these modules (crtstart.asm) contains a call to the C routine 
16524 \emph on
16525 _sdcc_external_startup()
16526 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16527
16528 \end_inset
16529
16530
16531 \series bold
16532 \emph default
16533  
16534 \series default
16535 at the start of the CODE area.
16536  This routine is also in the runtime library
16537 \begin_inset LatexCommand \index{Runtime library}
16538
16539 \end_inset
16540
16541  and returns 0 by default.
16542  If this routine returns a non-zero value, the static & global variable
16543  initialization will be skipped and the function main will be invoked.
16544  Otherwise static & global variables will be initialized before the function
16545  main is invoked.
16546  You could add an 
16547 \emph on
16548 _sdcc_external_startup()
16549 \emph default
16550  routine to your program to override the default if you need to setup hardware
16551  or perform some other critical operation prior to static & global variable
16552  initialization
16553 \begin_inset LatexCommand \index{Variable initialization}
16554
16555 \end_inset
16556
16557 .
16558  On some mcs51 variants xdata
16559 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16560
16561 \end_inset
16562
16563  memory has to be explicitly enabled before it can be accessed or if the
16564  watchdog
16565 \begin_inset LatexCommand \index{watchdog}
16566
16567 \end_inset
16568
16569  needs to be disabled, this is the place to do it.
16570  The startup code clears all internal data memory, 256 bytes by default,
16571  but from 0 to n-1 if 
16572 \emph on
16573 -
16574 \begin_inset ERT
16575 status collapsed
16576
16577 \begin_layout Standard
16578
16579
16580 \backslash
16581 /
16582 \end_layout
16583
16584 \end_inset
16585
16586 -iram-size
16587 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16588
16589 \end_inset
16590
16591 n
16592 \emph default
16593  is used.
16594  (recommended for Chipcon CC1010).
16595 \end_layout
16596
16597 \begin_layout Standard
16598 See also the compiler options 
16599 \emph on
16600 -
16601 \begin_inset ERT
16602 status collapsed
16603
16604 \begin_layout Standard
16605
16606
16607 \backslash
16608 /
16609 \end_layout
16610
16611 \end_inset
16612
16613 -no-xinit
16614 \emph default
16615 -
16616 \emph on
16617 opt
16618 \emph default
16619
16620 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16621
16622 \end_inset
16623
16624
16625 \emph on
16626 -
16627 \begin_inset ERT
16628 status collapsed
16629
16630 \begin_layout Standard
16631
16632
16633 \backslash
16634 /
16635 \end_layout
16636
16637 \end_inset
16638
16639 -main-return
16640 \emph default
16641
16642 \begin_inset LatexCommand \index{-\/-main-return}
16643
16644 \end_inset
16645
16646  and section 
16647 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16648
16649 \end_inset
16650
16651  about MCS51-variants.
16652 \newline
16653
16654 \end_layout
16655
16656 \begin_layout Standard
16657 While these initialization modules are meant as generic startup code there
16658  might be the need for customization.
16659  Let's assume the return value of 
16660 \emph on
16661 _sdcc_external_startup()
16662 \emph default
16663  in 
16664 \emph on
16665 crtstart.asm
16666 \emph default
16667  should not be checked (or 
16668 \emph on
16669 _sdcc_external_startup()
16670 \emph default
16671  should not be called at all).
16672  The recommended way would be to copy 
16673 \emph on
16674 crtstart.asm
16675 \emph default
16676  (f.e.
16677  from 
16678 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16679
16680 \end_inset
16681
16682 ) into the source directory, adapt it there, then assemble it with 
16683 \emph on
16684 asx8051 -plosgff
16685 \begin_inset Foot
16686 status open
16687
16688 \begin_layout Standard
16689 \begin_inset Quotes sld
16690 \end_inset
16691
16692 -plosgff
16693 \begin_inset Quotes srd
16694 \end_inset
16695
16696  are the assembler options used in 
16697 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16698
16699 \end_inset
16700
16701
16702 \end_layout
16703
16704 \end_inset
16705
16706  crtstart.asm
16707 \emph default
16708  and when linking your project explicitely specify 
16709 \emph on
16710 crtstart.rel
16711 \emph default
16712 .
16713  As a bonus a listing of the relocated object file 
16714 \emph on
16715 crtstart.rst
16716 \emph default
16717  is generated.
16718 \end_layout
16719
16720 \begin_layout Standard
16721 \begin_inset VSpace bigskip
16722 \end_inset
16723
16724
16725 \end_layout
16726
16727 \begin_layout Subsection
16728 HC08 Startup Code
16729 \end_layout
16730
16731 \begin_layout Standard
16732 The HC08
16733 \begin_inset LatexCommand \index{HC08}
16734
16735 \end_inset
16736
16737  startup code follows the same scheme as the MCS51 startup code.
16738 \begin_inset VSpace bigskip
16739 \end_inset
16740
16741
16742 \end_layout
16743
16744 \begin_layout Subsection
16745 Z80 Startup Code
16746 \end_layout
16747
16748 \begin_layout Standard
16749 On the Z80
16750 \begin_inset LatexCommand \index{Z80}
16751
16752 \end_inset
16753
16754  the startup code is inserted by linking with crt0.o which is generated from
16755  sdcc/device/lib/z80/crt0.s.
16756  If you need a different startup code you can use the compiler option 
16757 \emph on
16758 -
16759 \series bold
16760 \emph default
16761
16762 \begin_inset ERT
16763 status collapsed
16764
16765 \begin_layout Standard
16766
16767
16768 \backslash
16769 /
16770 \end_layout
16771
16772 \end_inset
16773
16774
16775 \series default
16776 \emph on
16777 -no-std-crt0
16778 \emph default
16779
16780 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16781
16782 \end_inset
16783
16784  and provide your own crt0.o.
16785  
16786 \begin_inset VSpace bigskip
16787 \end_inset
16788
16789
16790 \end_layout
16791
16792 \begin_layout Section
16793 Inline Assembler Code
16794 \begin_inset LatexCommand \index{Assembler routines}
16795
16796 \end_inset
16797
16798
16799 \end_layout
16800
16801 \begin_layout Subsection
16802 A Step by Step Introduction
16803 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16804
16805 \end_inset
16806
16807
16808 \end_layout
16809
16810 \begin_layout Standard
16811 Starting from a small snippet of c-code this example shows for the MCS51
16812  how to use inline assembly, access variables, a function parameter and
16813  an array in xdata memory.
16814  The example uses an MCS51 here but is easily adapted for other architectures.
16815  This is a buffer routine which should be optimized:
16816 \end_layout
16817
16818 \begin_layout Verse
16819
16820 \family typewriter
16821 \size footnotesize
16822 unsigned char __far
16823 \begin_inset LatexCommand \index{far (storage class)}
16824
16825 \end_inset
16826
16827
16828 \begin_inset LatexCommand \index{\_\_far (storage class)}
16829
16830 \end_inset
16831
16832  __at
16833 \begin_inset LatexCommand \index{at}
16834
16835 \end_inset
16836
16837
16838 \begin_inset LatexCommand \index{\_\_at}
16839
16840 \end_inset
16841
16842 (0x7f00) buf[0x100];
16843 \begin_inset LatexCommand \index{Aligned array}
16844
16845 \end_inset
16846
16847
16848 \newline
16849 unsigned char head, tail;\InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 \InsetSpace ~
16866 /* if interrupts
16867 \begin_inset LatexCommand \index{interrupt}
16868
16869 \end_inset
16870
16871  are involved see
16872 \newline
16873 \InsetSpace ~
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 \InsetSpace ~
16884 \InsetSpace ~
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 section 
16919 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16920
16921 \end_inset
16922
16923  about
16924 \series bold
16925  volatile
16926 \series default
16927  */
16928 \newline
16929
16930 \newline
16931 void to_buffer( unsigned char c ) 
16932 \newline
16933 {
16934 \newline
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 if( head != (unsigned char)(tail-1)
16940  )\InsetSpace ~
16941 /* cast 
16942 \series bold
16943 needed
16944 \series default
16945  to avoid promotion
16946 \begin_inset LatexCommand \index{promotion to signed int}
16947
16948 \end_inset
16949
16950
16951 \begin_inset LatexCommand \index{type promotion}
16952
16953 \end_inset
16954
16955  to integer */
16956 \begin_inset Marginal
16957 status collapsed
16958
16959 \begin_layout Standard
16960
16961 \series bold
16962 \InsetSpace ~
16963 !
16964 \end_layout
16965
16966 \end_inset
16967
16968
16969 \newline
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 buf[ head++ ] = c;\InsetSpace ~
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 \InsetSpace ~
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 \InsetSpace ~
16993 \InsetSpace ~
16994 /* access to a 256 byte aligned array */
16995 \newline
16996
16997 \end_layout
16998
16999 \begin_layout Standard
17000 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17001  then a corresponding buffer.asm file is generated.
17002  We define a new function 
17003 \family typewriter
17004 to_buffer_asm()
17005 \family default
17006  in file buffer.c in which we cut and paste the generated code, removing
17007  unwanted comments and some ':'.
17008  Then add 
17009 \begin_inset Quotes sld
17010 \end_inset
17011
17012
17013 \series bold
17014 _asm
17015 \series default
17016
17017 \begin_inset Quotes srd
17018 \end_inset
17019
17020  and 
17021 \begin_inset Quotes sld
17022 \end_inset
17023
17024
17025 \series bold
17026 _endasm;
17027 \series default
17028
17029 \begin_inset Quotes srd
17030 \end_inset
17031
17032
17033 \begin_inset Foot
17034 status open
17035
17036 \begin_layout Standard
17037 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17038  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17039  has to be used.
17040  The latter is also used in the library functions.
17041 \end_layout
17042
17043 \end_inset
17044
17045  to the beginning and the end of the function body:
17046 \end_layout
17047
17048 \begin_layout Verse
17049
17050 \family typewriter
17051 \size footnotesize
17052 /* With a cut and paste from the .asm file, we have something to start with.
17053 \newline
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 The
17058  function is not yet OK! (registers aren't saved) */ 
17059 \newline
17060 void to_buffer_asm(
17061  unsigned char c ) 
17062 \newline
17063
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 _asm
17070 \begin_inset LatexCommand \index{\_asm}
17071
17072 \end_inset
17073
17074
17075 \begin_inset LatexCommand \index{\_\_asm}
17076
17077 \end_inset
17078
17079
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 mov\InsetSpace ~
17086 \InsetSpace ~
17087 r2,dpl 
17088 \newline
17089 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17090 /* cast 
17091 \series bold
17092 needed
17093 \series default
17094  to avoid promotion
17095 \begin_inset LatexCommand \index{promotion to signed int}
17096
17097 \end_inset
17098
17099
17100 \begin_inset LatexCommand \index{type promotion}
17101
17102 \end_inset
17103
17104  to integer */
17105 \newline
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 mov\InsetSpace ~
17111 \InsetSpace ~
17112 a,_tail 
17113 \newline
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 \InsetSpace ~
17117 \InsetSpace ~
17118 dec\InsetSpace ~
17119 \InsetSpace ~
17120
17121 \newline
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 mov\InsetSpace ~
17127 \InsetSpace ~
17128 r3,a 
17129 \newline
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 mov\InsetSpace ~
17135 \InsetSpace ~
17136 a,_head 
17137 \newline
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 cjne a,ar3,00106$ 
17143 \newline
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 ret
17149 \newline
17150 00106$:
17151  
17152 \newline
17153 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17154 \begin_inset LatexCommand \index{Aligned array}
17155
17156 \end_inset
17157
17158
17159 \newline
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 \InsetSpace ~
17164 mov\InsetSpace ~
17165 \InsetSpace ~
17166 r3,_head 
17167 \newline
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 inc\InsetSpace ~
17173 \InsetSpace ~
17174 _head 
17175 \newline
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 mov\InsetSpace ~
17181 \InsetSpace ~
17182 dpl,r3 
17183 \newline
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 mov\InsetSpace ~
17189 \InsetSpace ~
17190 dph,#(_buf >> 8) 
17191 \newline
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 \InsetSpace ~
17196 mov\InsetSpace ~
17197 \InsetSpace ~
17198 a,r2 
17199 \newline
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 movx @dptr,a
17205  
17206 \newline
17207 00103$: 
17208 \newline
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 \InsetSpace ~
17212 \InsetSpace ~
17213 ret
17214 \newline
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 _endasm
17220 \begin_inset LatexCommand \index{\_endasm}
17221
17222 \end_inset
17223
17224
17225 \begin_inset LatexCommand \index{\_\_endasm}
17226
17227 \end_inset
17228
17229 ;
17230 \newline
17231
17232 \end_layout
17233
17234 \begin_layout Standard
17235 The new file buffer.c should compile with only one warning about the unreferenced
17236  function argument 'c'.
17237  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17238  (1) and finally have:
17239 \end_layout
17240
17241 \begin_layout Verse
17242
17243 \family typewriter
17244 \size footnotesize
17245 unsigned char __far __at(0x7f00) buf[0x100];
17246 \newline
17247 unsigned char head, tail;
17248 \newline
17249 #define
17250  USE_ASSEMBLY (1)
17251 \newline
17252
17253 \newline
17254 #if !USE_ASSEMBLY
17255 \newline
17256
17257 \newline
17258 void to_buffer( unsigned char c )
17259 \newline
17260 {
17261 \newline
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 if(
17267  head != (unsigned char)(tail-1) )
17268 \newline
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 buf[ head++ ] = c;
17278 \newline
17279 }
17280 \newline
17281
17282 \newline
17283 #else
17284 \newline
17285
17286 \newline
17287 void to_buffer(
17288  unsigned char c )
17289 \newline
17290 {
17291 \newline
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 c; // to avoid warning: unreferenced function argument
17297 \newline
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 \InsetSpace ~
17302 _asm
17303 \begin_inset LatexCommand \index{\_asm}
17304
17305 \end_inset
17306
17307
17308 \begin_inset LatexCommand \index{\_\_asm}
17309
17310 \end_inset
17311
17312
17313 \newline
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 ; save used registers here.
17323  
17324 \newline
17325 \InsetSpace ~
17326 \InsetSpace ~
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 ; If we were still using r2,r3 we would have to push them here.
17334  
17335 \newline
17336 ; if( head != (unsigned char)(tail-1) )
17337 \newline
17338 \InsetSpace ~
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 mov\InsetSpace ~
17347  a,_tail
17348 \newline
17349 \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 \InsetSpace ~
17357 dec\InsetSpace ~
17358  a
17359 \newline
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 \InsetSpace ~
17367 \InsetSpace ~
17368 xrl\InsetSpace ~
17369  a,_head
17370 \newline
17371 \InsetSpace ~
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 \InsetSpace ~
17379 ; we
17380  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17381 \newline
17382 \InsetSpace ~
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 jz\InsetSpace ~
17391 \InsetSpace ~
17392  t_b_end$
17393 \newline
17394 \InsetSpace ~
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 ;
17403 \newline
17404 ;
17405  buf[ head++ ] = c;
17406 \newline
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 \InsetSpace ~
17415 mov\InsetSpace ~
17416  a,dpl \InsetSpace ~
17417 \InsetSpace ~
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 ; dpl holds lower byte of function argument
17424 \newline
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 \InsetSpace ~
17428 \InsetSpace ~
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 mov\InsetSpace ~
17434
17435  dpl,_head \InsetSpace ~
17436 \InsetSpace ~
17437 \InsetSpace ~
17438 ; buf is 0x100 byte aligned so head can be used directly
17439 \newline
17440 \InsetSpace ~
17441 \InsetSpace ~
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 \InsetSpace ~
17445 \InsetSpace ~
17446 \InsetSpace ~
17447 \InsetSpace ~
17448 mov\InsetSpace ~
17449  dph,#(_bu
17450 f>>8)
17451 \newline
17452 \InsetSpace ~
17453 \InsetSpace ~
17454 \InsetSpace ~
17455 \InsetSpace ~
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 \InsetSpace ~
17459 \InsetSpace ~
17460 movx @dptr,a
17461 \newline
17462 \InsetSpace ~
17463 \InsetSpace ~
17464 \InsetSpace ~
17465 \InsetSpace ~
17466 \InsetSpace ~
17467 \InsetSpace ~
17468 \InsetSpace ~
17469 \InsetSpace ~
17470 inc \InsetSpace ~
17471 _head
17472 \newline
17473 \InsetSpace ~
17474 \InsetSpace ~
17475 \InsetSpace ~
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 \InsetSpace ~
17479 \InsetSpace ~
17480 \InsetSpace ~
17481 ; we could do an ANL _head,#0x0f here to use a
17482  smaller buffer (see above)
17483 \newline
17484 t_b_end$:
17485 \newline
17486 \InsetSpace ~
17487 \InsetSpace ~
17488 \InsetSpace ~
17489 \InsetSpace ~
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 ; restore used registers here 
17495 \newline
17496 \InsetSpace ~
17497 \InsetSpace ~
17498 \InsetSpace ~
17499 \InsetSpace ~
17500 _endasm
17501 \begin_inset LatexCommand \index{\_endasm}
17502
17503 \end_inset
17504
17505
17506 \begin_inset LatexCommand \index{\_\_endasm}
17507
17508 \end_inset
17509
17510 ;
17511 \newline
17512 }
17513 \newline
17514 #endif
17515 \end_layout
17516
17517 \begin_layout Standard
17518 The inline assembler code can contain any valid code understood by the assembler
17519 , this includes any assembler directives and comment lines.
17520  The assembler does not like some characters like ':' or ''' in comments.
17521  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17522 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17523
17524 \end_inset
17525
17526
17527 \begin_inset LatexCommand \index{Assembler documentation}
17528
17529 \end_inset
17530
17531  or online at 
17532 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17533
17534 \end_inset
17535
17536 \InsetSpace ~
17537 .
17538 \end_layout
17539
17540 \begin_layout Standard
17541 The compiler does not do any validation of the code within the 
17542 \family typewriter
17543 _asm
17544 \begin_inset LatexCommand \index{\_asm}
17545
17546 \end_inset
17547
17548
17549 \begin_inset LatexCommand \index{\_\_asm}
17550
17551 \end_inset
17552
17553  ...
17554  _endasm
17555 \size footnotesize
17556
17557 \begin_inset LatexCommand \index{\_endasm}
17558
17559 \end_inset
17560
17561
17562 \begin_inset LatexCommand \index{\_\_endasm}
17563
17564 \end_inset
17565
17566
17567 \size default
17568 ;
17569 \family default
17570  keyword pair.
17571  Specifically it will not know which registers are used and thus register
17572  pushing/popping
17573 \begin_inset LatexCommand \index{push/pop}
17574
17575 \end_inset
17576
17577  has to be done manually.
17578  
17579 \end_layout
17580
17581 \begin_layout Standard
17582 It is recommended that each assembly instruction (including labels) be placed
17583  in a separate line (as the example shows).
17584  When the -
17585 \begin_inset ERT
17586 status collapsed
17587
17588 \begin_layout Standard
17589
17590
17591 \backslash
17592 /
17593 \end_layout
17594
17595 \end_inset
17596
17597 -
17598 \emph on
17599 peep-asm
17600 \begin_inset LatexCommand \index{-\/-peep-asm}
17601
17602 \end_inset
17603
17604
17605 \emph default
17606  command line option is used, the inline assembler code will be passed through
17607  the peephole optimizer
17608 \begin_inset LatexCommand \index{Peephole optimizer}
17609
17610 \end_inset
17611
17612 .
17613  There are only a few (if any) cases where this option makes sense, it might
17614  cause some unexpected changes in the inline assembler code.
17615  Please go through the peephole optimizer rules defined in file 
17616 \emph on
17617 SDCCpeeph.def
17618 \emph default
17619  before using this option.
17620 \end_layout
17621
17622 \begin_layout Subsection
17623 Naked Functions
17624 \begin_inset LatexCommand \label{sub:Naked-Functions}
17625
17626 \end_inset
17627
17628
17629 \begin_inset LatexCommand \index{Naked functions}
17630
17631 \end_inset
17632
17633
17634 \end_layout
17635
17636 \begin_layout Standard
17637 A special keyword may be associated with a function declaring it as 
17638 \emph on
17639 _naked
17640 \begin_inset LatexCommand \index{\_naked}
17641
17642 \end_inset
17643
17644
17645 \begin_inset LatexCommand \index{\_\_naked}
17646
17647 \end_inset
17648
17649 .
17650  
17651 \emph default
17652 The 
17653 \emph on
17654 _naked
17655 \emph default
17656  function modifier attribute prevents the compiler from generating prologue
17657 \begin_inset LatexCommand \index{function prologue}
17658
17659 \end_inset
17660
17661  and epilogue
17662 \begin_inset LatexCommand \index{function epilogue}
17663
17664 \end_inset
17665
17666  code for that function.
17667  This means that the user is entirely responsible for such things as saving
17668  any registers that may need to be preserved, selecting the proper register
17669  bank, generating the 
17670 \emph on
17671 return
17672 \emph default
17673  instruction at the end, etc.
17674  Practically, this means that the contents of the function must be written
17675  in inline assembler.
17676  This is particularly useful for interrupt functions, which can have a large
17677  (and often unnecessary) prologue/epilogue.
17678  For example, compare the code generated by these two functions:
17679 \end_layout
17680
17681 \begin_layout Verse
17682
17683 \family typewriter
17684 volatile
17685 \begin_inset LatexCommand \index{volatile}
17686
17687 \end_inset
17688
17689  data unsigned char counter;
17690 \newline
17691
17692 \newline
17693 void simpleInterrupt(void) __interrupt
17694 \begin_inset LatexCommand \index{interrupt}
17695
17696 \end_inset
17697
17698
17699 \begin_inset LatexCommand \index{\_\_interrupt}
17700
17701 \end_inset
17702
17703  (1)
17704 \newline
17705 {
17706 \newline
17707 \InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 \InsetSpace ~
17711 counter++;
17712 \newline
17713 }
17714 \newline
17715
17716 \newline
17717 void nakedInterrupt(void) __interrupt (2) __naked
17718 \newline
17719 {
17720 \newline
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 \InsetSpace ~
17725 _asm
17726 \begin_inset LatexCommand \index{\_asm}
17727
17728 \end_inset
17729
17730
17731 \begin_inset LatexCommand \index{\_\_asm}
17732
17733 \end_inset
17734
17735
17736 \newline
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 inc\InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 _counter ; does not change flags, no need to save psw
17749 \newline
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 reti\InsetSpace ~
17757 \InsetSpace ~
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 ; MUST explicitly
17761  include ret or reti in _naked function.
17762 \newline
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 _endasm
17768 \begin_inset LatexCommand \index{\_endasm}
17769
17770 \end_inset
17771
17772
17773 \begin_inset LatexCommand \index{\_\_endasm}
17774
17775 \end_inset
17776
17777 ;
17778 \newline
17779 }
17780 \end_layout
17781
17782 \begin_layout Standard
17783 For an 8051 target, the generated simpleInterrupt looks like:
17784 \end_layout
17785
17786 \begin_layout Verse
17787
17788 \family typewriter
17789 Note, this is an 
17790 \emph on
17791 outdated
17792 \emph default
17793  example, recent versions of SDCC generate
17794 \newline
17795 the 
17796 \emph on
17797 same
17798 \emph default
17799  code for simpleInterrupt() and nakedInterrupt()!
17800 \newline
17801
17802 \newline
17803 _simpleInterrupt:
17804 \newline
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 push\InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 acc
17814 \newline
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 push\InsetSpace ~
17820 \InsetSpace ~
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 b
17824 \newline
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 pu
17830 sh\InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 dpl
17835 \newline
17836 \InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 push\InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 \InsetSpace ~
17844 dph
17845 \newline
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 push\InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 psw
17855 \newline
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 \InsetSpace ~
17860 mov\InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 \InsetSpace ~
17865 psw,#0x00
17866 \newline
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 inc\InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 \InsetSpace ~
17875 \InsetSpace ~
17876 _counter
17877 \newline
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 pop\InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 psw
17888 \newline
17889 \InsetSpace ~
17890 \InsetSpace ~
17891 \InsetSpace ~
17892 \InsetSpace ~
17893 pop\InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 dph
17899 \newline
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 pop\InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 \InsetSpace ~
17909 dpl
17910 \newline
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 pop\InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 b
17921 \newline
17922 \InsetSpace ~
17923 \InsetSpace ~
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 pop\InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 \InsetSpace ~
17931 acc
17932 \newline
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 \InsetSpace ~
17937 reti
17938 \end_layout
17939
17940 \begin_layout Standard
17941 whereas nakedInterrupt looks like:
17942 \end_layout
17943
17944 \begin_layout Verse
17945
17946 \family typewriter
17947 _nakedInterrupt:
17948 \newline
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 inc\InsetSpace ~
17954 \InsetSpace ~
17955 \InsetSpace ~
17956 \InsetSpace ~
17957 _counter ; does not change flags, no need to save psw
17958 \newline
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 \InsetSpace ~
17962 \InsetSpace ~
17963 reti\InsetSpace ~
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 \InsetSpace ~
17969 \InsetSpace ~
17970 \InsetSpace ~
17971 \InsetSpace ~
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 ;
17976  MUST explicitly include ret or reti in _naked function
17977 \end_layout
17978
17979 \begin_layout Standard
17980 The related directive #pragma exclude
17981 \begin_inset LatexCommand \index{\#pragma exclude}
17982
17983 \end_inset
17984
17985  allows a more fine grained control over pushing & popping
17986 \begin_inset LatexCommand \index{push/pop}
17987
17988 \end_inset
17989
17990  the registers.
17991 \end_layout
17992
17993 \begin_layout Standard
17994 While there is nothing preventing you from writing C code inside a 
17995 \family typewriter
17996 _naked
17997 \family default
17998  function, there are many ways to shoot yourself in the foot doing this,
17999  and it is recommended that you stick to inline assembler.
18000 \end_layout
18001
18002 \begin_layout Subsection
18003 Use of Labels within Inline Assembler
18004 \end_layout
18005
18006 \begin_layout Standard
18007 SDCC allows the use of in-line assembler with a few restrictions regarding
18008  labels.
18009  All labels defined within inline assembler code have to be of the form
18010  
18011 \emph on
18012 nnnnn$
18013 \emph default
18014  where nnnnn is a number less than 100 (which implies a limit of utmost
18015  100 inline assembler labels 
18016 \emph on
18017 per function
18018 \emph default
18019 \noun on
18020 )
18021 \noun default
18022 .
18023 \begin_inset Foot
18024 status open
18025
18026 \begin_layout Standard
18027 This is a slightly more stringent rule than absolutely necessary, but stays
18028  always on the safe side.
18029  Labels in the form of nnnnn$ are local labels in the assembler, locality
18030  of which is confined within two labels of the standard form.
18031  The compiler uses the same form for labels within a function (but starting
18032  from nnnnn=00100); and places always a standard label at the beginning
18033  of a function, thus limiting the locality of labels within the scope of
18034  the function.
18035  So, if the inline assembler part would be embedded into C-code, an improperly
18036  placed non-local label in the assembler would break up the reference space
18037  for labels created by the compiler for the C-code, leading to an assembling
18038  error.
18039 \end_layout
18040
18041 \begin_layout Standard
18042 The numeric part of local labels does not need to have 5 digits (although
18043  this is the form of labels output by the compiler), any valid integer will
18044  do.
18045  Please refer to the assemblers documentation for further details.
18046 \end_layout
18047
18048 \end_inset
18049
18050  
18051 \end_layout
18052
18053 \begin_layout Verse
18054
18055 \family typewriter
18056 _asm
18057 \begin_inset LatexCommand \index{\_asm}
18058
18059 \end_inset
18060
18061
18062 \begin_inset LatexCommand \index{\_\_asm}
18063
18064 \end_inset
18065
18066  
18067 \newline
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 \InsetSpace ~
18071 \InsetSpace ~
18072 mov\InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 b,#10 
18078 \newline
18079 00001$: 
18080 \newline
18081 \InsetSpace ~
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 \InsetSpace ~
18085 djnz\InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 b,00001$ 
18090 \newline
18091 _endasm
18092 \begin_inset LatexCommand \index{\_endasm}
18093
18094 \end_inset
18095
18096
18097 \begin_inset LatexCommand \index{\_\_endasm}
18098
18099 \end_inset
18100
18101  ;
18102 \end_layout
18103
18104 \begin_layout Standard
18105 Inline assembler code cannot reference any C-labels, however it can reference
18106  labels
18107 \begin_inset LatexCommand \index{Labels}
18108
18109 \end_inset
18110
18111  defined by the inline assembler, e.g.:
18112 \end_layout
18113
18114 \begin_layout Verse
18115
18116 \family typewriter
18117 foo() { 
18118 \newline
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 /* some c code */ 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 _asm 
18130 \newline
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 \InsetSpace ~
18134 \InsetSpace ~
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 ; some assembler code 
18138 \newline
18139 \InsetSpace ~
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 \InsetSpace ~
18145 ljmp 0003$ 
18146 \newline
18147 \InsetSpace ~
18148 \InsetSpace ~
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 _endasm;
18152  
18153 \newline
18154 \InsetSpace ~
18155 \InsetSpace ~
18156 \InsetSpace ~
18157 \InsetSpace ~
18158 /* some more c code */ 
18159 \newline
18160 clabel:\InsetSpace ~
18161 \InsetSpace ~
18162 /* inline assembler cannot reference this
18163  label */ 
18164 \begin_inset Foot
18165 status open
18166
18167 \begin_layout Standard
18168 Here, the C-label 
18169 \family typewriter
18170 clabel
18171 \family default
18172  is translated by the compiler into a local label, so the locality of labels
18173  within the function is not broken.
18174 \end_layout
18175
18176 \end_inset
18177
18178
18179 \newline
18180 \InsetSpace ~
18181 \InsetSpace ~
18182 \InsetSpace ~
18183 \InsetSpace ~
18184 _asm
18185 \newline
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 0003$: ;label (can be referenced by inline assembler only) 
18191 \newline
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 _endasm
18197 \begin_inset LatexCommand \index{\_endasm}
18198
18199 \end_inset
18200
18201
18202 \begin_inset LatexCommand \index{\_\_endasm}
18203
18204 \end_inset
18205
18206  ; 
18207 \newline
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 \InsetSpace ~
18211 \InsetSpace ~
18212 /* some more c code */
18213 \newline
18214 }
18215 \end_layout
18216
18217 \begin_layout Standard
18218 In other words inline assembly code can access labels defined in inline
18219  assembly within the scope of the function.
18220  The same goes the other way, i.e.
18221  labels defines in inline assembly can not be accessed by C statements.
18222 \end_layout
18223
18224 \begin_layout Section
18225 Interfacing with Assembler Code
18226 \begin_inset LatexCommand \index{Assembler routines}
18227
18228 \end_inset
18229
18230
18231 \end_layout
18232
18233 \begin_layout Subsection
18234 Global Registers used for Parameter Passing
18235 \begin_inset LatexCommand \index{Parameter passing}
18236
18237 \end_inset
18238
18239
18240 \end_layout
18241
18242 \begin_layout Standard
18243 The compiler always uses the global registers 
18244 \emph on
18245 DPL, DPH
18246 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18247
18248 \end_inset
18249
18250
18251 \begin_inset LatexCommand \index{DPTR}
18252
18253 \end_inset
18254
18255 , B
18256 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18257
18258 \end_inset
18259
18260  
18261 \emph default
18262 and
18263 \emph on
18264  ACC
18265 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18266
18267 \end_inset
18268
18269
18270 \emph default
18271  to pass the first (non-bit) parameter to a function, and also to pass the
18272  return value 
18273 \begin_inset LatexCommand \index{return value}
18274
18275 \end_inset
18276
18277 of function; according to the following scheme: one byte return value in
18278  
18279 \emph on
18280 DPL
18281 \emph default
18282 , two byte value in 
18283 \emph on
18284 DPL
18285 \emph default
18286  (LSB) and 
18287 \emph on
18288 DPH
18289 \emph default
18290  (MSB).
18291  three byte values (generic pointers) in 
18292 \emph on
18293 DPH
18294 \emph default
18295
18296 \emph on
18297 DPL
18298 \emph default
18299  and 
18300 \emph on
18301 B
18302 \emph default
18303 , and four byte values in 
18304 \emph on
18305 DPH
18306 \emph default
18307
18308 \emph on
18309 DPL
18310 \emph default
18311 ,
18312 \emph on
18313  B
18314 \emph default
18315  and 
18316 \emph on
18317 ACC
18318 \emph default
18319 .
18320  Generic pointers
18321 \begin_inset LatexCommand \index{generic pointer}
18322
18323 \end_inset
18324
18325  contain type of accessed memory in 
18326 \emph on
18327 B
18328 \emph default
18329
18330 \series bold
18331 0x00
18332 \series default
18333  -- xdata/far, 
18334 \series bold
18335 0x40
18336 \series default
18337  -- idata/near -- , 
18338 \series bold
18339 0x60
18340 \series default
18341  -- pdata, 
18342 \series bold
18343 0x80
18344 \series default
18345  -- code
18346 \begin_inset Note Note
18347 status collapsed
18348
18349 \begin_layout Standard
18350 This might not be the case of certain memory models (medium???)
18351 \end_layout
18352
18353 \end_inset
18354
18355 .
18356 \end_layout
18357
18358 \begin_layout Standard
18359 The second parameter onwards is either allocated on the stack (for reentrant
18360  routines or if -
18361 \begin_inset ERT
18362 status collapsed
18363
18364 \begin_layout Standard
18365
18366
18367 \backslash
18368 /
18369 \end_layout
18370
18371 \end_inset
18372
18373 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18374 \end_layout
18375
18376 \begin_layout Standard
18377 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18378  space for reentrant functions or allocated directly in bit memory otherwise.
18379 \end_layout
18380
18381 \begin_layout Standard
18382 Functions (with two or more parameters or bit parameters) that are called
18383  through function pointers
18384 \begin_inset LatexCommand \index{function pointers}
18385
18386 \end_inset
18387
18388  must therefor be reentrant so the compiler knows how to pass the parameters.
18389 \end_layout
18390
18391 \begin_layout Subsection
18392 Registers usage
18393 \end_layout
18394
18395 \begin_layout Standard
18396 Unless the called function is declared as 
18397 \family typewriter
18398 _naked
18399 \family default
18400
18401 \begin_inset LatexCommand \index{naked}
18402
18403 \end_inset
18404
18405 , or the -
18406 \begin_inset ERT
18407 status collapsed
18408
18409 \begin_layout Standard
18410
18411
18412 \backslash
18413 /
18414 \end_layout
18415
18416 \end_inset
18417
18418 -callee-saves
18419 \begin_inset LatexCommand \index{-\/-callee-saves}
18420
18421 \end_inset
18422
18423 /-
18424 \begin_inset ERT
18425 status collapsed
18426
18427 \begin_layout Standard
18428
18429
18430 \backslash
18431 /
18432 \end_layout
18433
18434 \end_inset
18435
18436 -all-callee-saves command line option or the corresponding callee_saves
18437  pragma are used, the caller will save the registers (
18438 \emph on
18439 R0-R7
18440 \emph default
18441 ) around the call, so the called function can destroy they content freely.
18442 \end_layout
18443
18444 \begin_layout Standard
18445 If the called function is not declared as 
18446 \family typewriter
18447 _naked
18448 \family default
18449 , the caller will swap register banks around the call, if caller and callee
18450  use different register banks (having them defined by the 
18451 \family typewriter
18452 _using
18453 \family default
18454  modifier).
18455  
18456 \end_layout
18457
18458 \begin_layout Standard
18459 The called function can also use 
18460 \emph on
18461 DPL
18462 \emph default
18463
18464 \emph on
18465 DPH
18466 \emph default
18467
18468 \emph on
18469 B
18470 \emph default
18471  and 
18472 \emph on
18473 ACC
18474 \emph default
18475  observing that they are used for parameter/return value passing.
18476 \end_layout
18477
18478 \begin_layout Subsection
18479 Assembler Routine (non-reentrant)
18480 \end_layout
18481
18482 \begin_layout Standard
18483 In the following example
18484 \begin_inset LatexCommand \index{reentrant}
18485
18486 \end_inset
18487
18488
18489 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18490
18491 \end_inset
18492
18493  the function c_func calls an assembler routine asm_func, which takes two
18494  parameters
18495 \begin_inset LatexCommand \index{function parameter}
18496
18497 \end_inset
18498
18499 .
18500 \end_layout
18501
18502 \begin_layout Verse
18503
18504 \family typewriter
18505 extern int asm_func(unsigned char, unsigned char);
18506 \newline
18507
18508 \newline
18509 int c_func (unsigned char
18510  i, unsigned char j)
18511 \newline
18512 {
18513 \newline
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 return asm_func(i,j);
18519 \newline
18520 }
18521 \newline
18522
18523 \newline
18524 int main()
18525 \newline
18526 {
18527 \newline
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 return c_func(10,9);
18533 \newline
18534 }
18535 \end_layout
18536
18537 \begin_layout Standard
18538 The corresponding assembler function is:
18539 \end_layout
18540
18541 \begin_layout Verse
18542
18543 \family typewriter
18544 .globl _asm_func_PARM_2 
18545 \newline
18546 \InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 .globl _asm_func 
18555 \newline
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 \InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 .area OSEG 
18565 \newline
18566 _asm_func_PARM_2:
18567 \newline
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 \InsetSpace ~
18575 \InsetSpace ~
18576 .ds   
18577  1 
18578 \newline
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 \InsetSpace ~
18582 \InsetSpace ~
18583 \InsetSpace ~
18584 \InsetSpace ~
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 .area CSEG 
18588 \newline
18589 _asm_func: 
18590 \newline
18591 \InsetSpace ~
18592 \InsetSpace ~
18593 \InsetSpace ~
18594 \InsetSpace ~
18595 \InsetSpace ~
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 mov\InsetSpace ~
18600 \InsetSpace ~
18601 \InsetSpace ~
18602 \InsetSpace ~
18603 a,dpl 
18604 \newline
18605 \InsetSpace ~
18606 \InsetSpace ~
18607 \InsetSpace ~
18608 \InsetSpace ~
18609 \InsetSpace ~
18610 \InsetSpace ~
18611 \InsetSpace ~
18612 \InsetSpace ~
18613 add\InsetSpace ~
18614 \InsetSpace ~
18615 \InsetSpace ~
18616 \InsetSpace ~
18617 a,_asm_func_PARM_2 
18618 \newline
18619 \InsetSpace ~
18620 \InsetSpace ~
18621 \InsetSpace ~
18622 \InsetSpace ~
18623 \InsetSpace ~
18624 \InsetSpace ~
18625 \InsetSpace ~
18626 \InsetSpace ~
18627 mov\InsetSpace ~
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 dpl,a 
18632 \newline
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 \InsetSpace ~
18637 \InsetSpace ~
18638 \InsetSpace ~
18639 \InsetSpace ~
18640 \InsetSpace ~
18641 mov\InsetSpace ~
18642 \InsetSpace ~
18643 \InsetSpace ~
18644 \InsetSpace ~
18645 dph
18646 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18647
18648 \end_inset
18649
18650 ,#0x00 
18651 \newline
18652 \InsetSpace ~
18653 \InsetSpace ~
18654 \InsetSpace ~
18655 \InsetSpace ~
18656 \InsetSpace ~
18657 \InsetSpace ~
18658 \InsetSpace ~
18659 \InsetSpace ~
18660 ret
18661 \end_layout
18662
18663 \begin_layout Standard
18664 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18665  the parameter number starting from 1, and counting from the left.
18666  The first parameter is passed in 
18667 \emph on
18668 DPH
18669 \emph default
18670
18671 \emph on
18672 DPL
18673 \emph default
18674
18675 \emph on
18676 B
18677 \emph default
18678  and 
18679 \emph on
18680 ACC
18681 \emph default
18682  according to the description above.
18683  The variable name for the second parameter will be _<function_name>_PARM_2.
18684 \newline
18685
18686 \newline
18687 Assem
18688 ble the assembler routine with the following command:
18689 \newline
18690
18691 \newline
18692
18693 \family sans
18694 \series bold
18695 asx8051 -losg asmfunc.asm
18696 \newline
18697
18698 \newline
18699
18700 \family default
18701 \series default
18702 Then compile and link the assembler routine to the C source file with the
18703  following command:
18704 \newline
18705
18706 \newline
18707
18708 \family sans
18709 \series bold
18710 sdcc cfunc.c asmfunc.rel
18711 \end_layout
18712
18713 \begin_layout Subsection
18714 Assembler Routine (reentrant)
18715 \end_layout
18716
18717 \begin_layout Standard
18718 In this case
18719 \begin_inset LatexCommand \index{reentrant}
18720
18721 \end_inset
18722
18723
18724 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18725
18726 \end_inset
18727
18728  the second parameter
18729 \begin_inset LatexCommand \index{function parameter}
18730
18731 \end_inset
18732
18733  onwards will be passed on the stack, the parameters are pushed from right
18734  to left i.e.
18735  before the call the second leftmost parameter will be on the top of the
18736  stack (the leftmost parameter is passed in registers).
18737  Here is an example:
18738 \end_layout
18739
18740 \begin_layout Verse
18741
18742 \family typewriter
18743 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18744 \newline
18745
18746 \newline
18747 int
18748  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18749 \newline
18750 {
18751  
18752 \newline
18753 \InsetSpace ~
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 \InsetSpace ~
18757 return asm_func(i,j,k); 
18758 \newline
18759
18760 \newline
18761
18762 \newline
18763 int main() 
18764 \newline
18765
18766 \newline
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 \InsetSpace ~
18771 return c_func(10,9,8); 
18772 \newline
18773 }
18774 \end_layout
18775
18776 \begin_layout Standard
18777 The corresponding (unoptimized) assembler routine is:
18778 \end_layout
18779
18780 \begin_layout Verse
18781
18782 \family typewriter
18783 .globl _asm_func 
18784 \newline
18785 _asm_func: 
18786 \newline
18787 \InsetSpace ~
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 push\InsetSpace ~
18792 _bp 
18793 \newline
18794 \InsetSpace ~
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 mov\InsetSpace ~
18799 \InsetSpace ~
18800 _bp,sp\InsetSpace ~
18801 \InsetSpace ~
18802 \InsetSpace ~
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 ;stack contains: _bp, return
18807  address, second parameter, third parameter
18808 \newline
18809 \InsetSpace ~
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 mov\InsetSpace ~
18814 \InsetSpace ~
18815 r2,dpl
18816 \newline
18817 \InsetSpace ~
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 mov\InsetSpace ~
18822 \InsetSpace ~
18823 a,_bp
18824 \newline
18825 \InsetSpace ~
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 add\InsetSpace ~
18830 \InsetSpace ~
18831 a,#0xfd\InsetSpace ~
18832 \InsetSpace ~
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 \InsetSpace ~
18836 ;calculate
18837  pointer to the second parameter
18838 \newline
18839 \InsetSpace ~
18840 \InsetSpace ~
18841 \InsetSpace ~
18842 \InsetSpace ~
18843 mov\InsetSpace ~
18844 \InsetSpace ~
18845 r0,a 
18846 \newline
18847 \InsetSpace ~
18848 \InsetSpace ~
18849 \InsetSpace ~
18850 \InsetSpace ~
18851 mov\InsetSpace ~
18852 \InsetSpace ~
18853 a,_bp 
18854 \newline
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 \InsetSpace ~
18858 \InsetSpace ~
18859 add\InsetSpace ~
18860 \InsetSpace ~
18861 a,#0xfc\InsetSpace ~
18862 \InsetSpace ~
18863 \InsetSpace ~
18864 \InsetSpace ~
18865 \InsetSpace ~
18866 ;calculate pointer
18867  to the rightmost parameter
18868 \newline
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 \InsetSpace ~
18872 \InsetSpace ~
18873 mov\InsetSpace ~
18874 \InsetSpace ~
18875 r1,a 
18876 \newline
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 \InsetSpace ~
18880 \InsetSpace ~
18881 mov\InsetSpace ~
18882 \InsetSpace ~
18883 a,@r0
18884 \newline
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 \InsetSpace ~
18889 add\InsetSpace ~
18890 \InsetSpace ~
18891 a,@r1
18892 \newline
18893 \InsetSpace ~
18894 \InsetSpace ~
18895 \InsetSpace ~
18896 \InsetSpace ~
18897 add\InsetSpace ~
18898 \InsetSpace ~
18899 a,r2\InsetSpace ~
18900 \InsetSpace ~
18901 \InsetSpace ~
18902 \InsetSpace ~
18903 \InsetSpace ~
18904 \InsetSpace ~
18905 \InsetSpace ~
18906 \InsetSpace ~
18907 ;calculate the
18908  result (= sum of all three parameters)
18909 \newline
18910 \InsetSpace ~
18911 \InsetSpace ~
18912 \InsetSpace ~
18913 \InsetSpace ~
18914 mov\InsetSpace ~
18915 \InsetSpace ~
18916 dpl,a\InsetSpace ~
18917 \InsetSpace ~
18918 \InsetSpace ~
18919 \InsetSpace ~
18920 \InsetSpace ~
18921 \InsetSpace ~
18922 \InsetSpace ~
18923 ;return value goes into dptr
18924  (cast into int)
18925 \newline
18926 \InsetSpace ~
18927 \InsetSpace ~
18928 \InsetSpace ~
18929 \InsetSpace ~
18930 mov\InsetSpace ~
18931 \InsetSpace ~
18932 dph,#0x00 
18933 \newline
18934 \InsetSpace ~
18935 \InsetSpace ~
18936 \InsetSpace ~
18937 \InsetSpace ~
18938 mov\InsetSpace ~
18939 \InsetSpace ~
18940 sp,_bp 
18941 \newline
18942 \InsetSpace ~
18943 \InsetSpace ~
18944 \InsetSpace ~
18945 \InsetSpace ~
18946 pop\InsetSpace ~
18947 \InsetSpace ~
18948 _bp 
18949 \newline
18950 \InsetSpace ~
18951 \InsetSpace ~
18952 \InsetSpace ~
18953 \InsetSpace ~
18954 ret
18955 \end_layout
18956
18957 \begin_layout Standard
18958 The compiling and linking procedure remains the same, however note the extra
18959  entry & exit linkage required for the assembler code, _bp is the stack
18960  frame pointer and is used to compute the offset into the stack for parameters
18961  and local variables.
18962 \begin_inset VSpace bigskip
18963 \end_inset
18964
18965
18966 \end_layout
18967
18968 \begin_layout Section
18969 int (16 bit)
18970 \begin_inset LatexCommand \index{int (16 bit)}
18971
18972 \end_inset
18973
18974  and long (32 bit)
18975 \begin_inset LatexCommand \index{long (32 bit)}
18976
18977 \end_inset
18978
18979  Support
18980 \end_layout
18981
18982 \begin_layout Standard
18983 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18984  multiplication and modulus operations are implemented by support routines.
18985  These support routines are all developed in ANSI-C to facilitate porting
18986  to other MCUs, although some model specific assembler optimizations are
18987  used.
18988  The following files contain the described routines, all of them can be
18989  found in <installdir>/share/sdcc/lib.
18990 \newline
18991
18992 \end_layout
18993
18994 \begin_layout Standard
18995 \align center
18996 \begin_inset Tabular
18997 <lyxtabular version="3" rows="11" columns="2">
18998 <features>
18999 <column alignment="left" valignment="top" leftline="true" width="0">
19000 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19001 <row topline="true" bottomline="true">
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19003 \begin_inset Text
19004
19005 \begin_layout Standard
19006
19007 \series bold
19008 Function
19009 \end_layout
19010
19011 \end_inset
19012 </cell>
19013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19014 \begin_inset Text
19015
19016 \begin_layout Standard
19017
19018 \series bold
19019 Description
19020 \end_layout
19021
19022 \end_inset
19023 </cell>
19024 </row>
19025 <row topline="true">
19026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19027 \begin_inset Text
19028
19029 \begin_layout Standard
19030 _mulint.c 
19031 \end_layout
19032
19033 \end_inset
19034 </cell>
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19036 \begin_inset Text
19037
19038 \begin_layout Standard
19039 16 bit multiplication
19040 \end_layout
19041
19042 \end_inset
19043 </cell>
19044 </row>
19045 <row topline="true">
19046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19047 \begin_inset Text
19048
19049 \begin_layout Standard
19050 _divsint.c 
19051 \end_layout
19052
19053 \end_inset
19054 </cell>
19055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19056 \begin_inset Text
19057
19058 \begin_layout Standard
19059  signed 16 bit division (calls _divuint)
19060 \end_layout
19061
19062 \end_inset
19063 </cell>
19064 </row>
19065 <row topline="true">
19066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19067 \begin_inset Text
19068
19069 \begin_layout Standard
19070 _divuint.c 
19071 \end_layout
19072
19073 \end_inset
19074 </cell>
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19076 \begin_inset Text
19077
19078 \begin_layout Standard
19079  unsigned 16 bit division
19080 \end_layout
19081
19082 \end_inset
19083 </cell>
19084 </row>
19085 <row topline="true">
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19087 \begin_inset Text
19088
19089 \begin_layout Standard
19090 _modsint.c
19091 \end_layout
19092
19093 \end_inset
19094 </cell>
19095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19096 \begin_inset Text
19097
19098 \begin_layout Standard
19099 signed 16 bit modulus (calls _moduint)
19100 \end_layout
19101
19102 \end_inset
19103 </cell>
19104 </row>
19105 <row topline="true">
19106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19107 \begin_inset Text
19108
19109 \begin_layout Standard
19110 _moduint.c
19111 \end_layout
19112
19113 \end_inset
19114 </cell>
19115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19116 \begin_inset Text
19117
19118 \begin_layout Standard
19119 unsigned 16 bit modulus
19120 \end_layout
19121
19122 \end_inset
19123 </cell>
19124 </row>
19125 <row topline="true">
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19127 \begin_inset Text
19128
19129 \begin_layout Standard
19130 _mullong.c
19131 \end_layout
19132
19133 \end_inset
19134 </cell>
19135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19136 \begin_inset Text
19137
19138 \begin_layout Standard
19139 32 bit multiplication
19140 \end_layout
19141
19142 \end_inset
19143 </cell>
19144 </row>
19145 <row topline="true">
19146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19147 \begin_inset Text
19148
19149 \begin_layout Standard
19150 _divslong.c 
19151 \end_layout
19152
19153 \end_inset
19154 </cell>
19155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19156 \begin_inset Text
19157
19158 \begin_layout Standard
19159  signed 32 division (calls _divulong)
19160 \end_layout
19161
19162 \end_inset
19163 </cell>
19164 </row>
19165 <row topline="true">
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \begin_layout Standard
19170 _divulong.c 
19171 \end_layout
19172
19173 \end_inset
19174 </cell>
19175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19176 \begin_inset Text
19177
19178 \begin_layout Standard
19179 unsigned 32 division
19180 \end_layout
19181
19182 \end_inset
19183 </cell>
19184 </row>
19185 <row topline="true">
19186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19187 \begin_inset Text
19188
19189 \begin_layout Standard
19190 _modslong.c
19191 \end_layout
19192
19193 \end_inset
19194 </cell>
19195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19196 \begin_inset Text
19197
19198 \begin_layout Standard
19199  signed 32 bit modulus (calls _modulong)
19200 \end_layout
19201
19202 \end_inset
19203 </cell>
19204 </row>
19205 <row topline="true" bottomline="true">
19206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19207 \begin_inset Text
19208
19209 \begin_layout Standard
19210 _modulong.c
19211 \end_layout
19212
19213 \end_inset
19214 </cell>
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19216 \begin_inset Text
19217
19218 \begin_layout Standard
19219 unsigned 32 bit modulus
19220 \end_layout
19221
19222 \end_inset
19223 </cell>
19224 </row>
19225 </lyxtabular>
19226
19227 \end_inset
19228
19229
19230 \newline
19231
19232 \end_layout
19233
19234 \begin_layout Standard
19235 Since they are compiled as 
19236 \emph on
19237 non-reentrant
19238 \emph default
19239
19240 \begin_inset LatexCommand \index{reentrant}
19241
19242 \end_inset
19243
19244 , interrupt
19245 \begin_inset LatexCommand \index{interrupt}
19246
19247 \end_inset
19248
19249  service routines should not do any of the above operations.
19250  If this is unavoidable then the above routines will need to be compiled
19251  with the 
19252 \emph on
19253 -
19254 \begin_inset ERT
19255 status collapsed
19256
19257 \begin_layout Standard
19258
19259
19260 \backslash
19261 /
19262 \end_layout
19263
19264 \end_inset
19265
19266 -stack-auto
19267 \begin_inset LatexCommand \index{-\/-stack-auto}
19268
19269 \end_inset
19270
19271
19272 \emph default
19273  option, after which the source program will have to be compiled with 
19274 \emph on
19275 -
19276 \begin_inset ERT
19277 status collapsed
19278
19279 \begin_layout Standard
19280
19281
19282 \backslash
19283 /
19284 \end_layout
19285
19286 \end_inset
19287
19288 -int-long-reent
19289 \begin_inset LatexCommand \index{-\/-int-long-reent}
19290
19291 \end_inset
19292
19293
19294 \emph default
19295  option.
19296  Notice that you don't have to call these routines directly.
19297  The compiler will use them automatically every time an integer operation
19298  is required.
19299 \end_layout
19300
19301 \begin_layout Section
19302 Floating Point Support
19303 \begin_inset LatexCommand \index{Floating point support}
19304
19305 \end_inset
19306
19307
19308 \end_layout
19309
19310 \begin_layout Standard
19311 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19312  The floating point support routines are derived from gcc's floatlib.c and
19313  consist of the following routines:
19314 \newline
19315
19316 \end_layout
19317
19318 \begin_layout Standard
19319 \align center
19320
19321 \size footnotesize
19322 \begin_inset Tabular
19323 <lyxtabular version="3" rows="17" columns="2">
19324 <features>
19325 <column alignment="left" valignment="top" leftline="true" width="0">
19326 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19327 <row topline="true" bottomline="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 Function 
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 Description
19351 \end_layout
19352
19353 \end_inset
19354 </cell>
19355 </row>
19356 <row topline="true">
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19358 \begin_inset Text
19359
19360 \begin_layout Standard
19361
19362 \family roman
19363 \series medium
19364 \shape up
19365 \size normal
19366 \emph off
19367 \bar no
19368 \noun off
19369 \color none
19370 _fsadd.c
19371 \end_layout
19372
19373 \end_inset
19374 </cell>
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19376 \begin_inset Text
19377
19378 \begin_layout Standard
19379
19380 \family roman
19381 \series medium
19382 \shape up
19383 \size normal
19384 \emph off
19385 \bar no
19386 \noun off
19387 \color none
19388 add floating point numbers
19389 \end_layout
19390
19391 \end_inset
19392 </cell>
19393 </row>
19394 <row topline="true">
19395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19396 \begin_inset Text
19397
19398 \begin_layout Standard
19399
19400 \family roman
19401 \series medium
19402 \shape up
19403 \size normal
19404 \emph off
19405 \bar no
19406 \noun off
19407 \color none
19408 _fssub.c 
19409 \end_layout
19410
19411 \end_inset
19412 </cell>
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19414 \begin_inset Text
19415
19416 \begin_layout Standard
19417
19418 \family roman
19419 \series medium
19420 \shape up
19421 \size normal
19422 \emph off
19423 \bar no
19424 \noun off
19425 \color none
19426 subtract floating point numbers 
19427 \end_layout
19428
19429 \end_inset
19430 </cell>
19431 </row>
19432 <row topline="true">
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19434 \begin_inset Text
19435
19436 \begin_layout Standard
19437
19438 \family roman
19439 \series medium
19440 \shape up
19441 \size normal
19442 \emph off
19443 \bar no
19444 \noun off
19445 \color none
19446 _fsdiv.c 
19447 \end_layout
19448
19449 \end_inset
19450 </cell>
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19452 \begin_inset Text
19453
19454 \begin_layout Standard
19455
19456 \family roman
19457 \series medium
19458 \shape up
19459 \size normal
19460 \emph off
19461 \bar no
19462 \noun off
19463 \color none
19464 divide floating point numbers 
19465 \end_layout
19466
19467 \end_inset
19468 </cell>
19469 </row>
19470 <row topline="true">
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19472 \begin_inset Text
19473
19474 \begin_layout Standard
19475
19476 \family roman
19477 \series medium
19478 \shape up
19479 \size normal
19480 \emph off
19481 \bar no
19482 \noun off
19483 \color none
19484 _fsmul.c 
19485 \end_layout
19486
19487 \end_inset
19488 </cell>
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19490 \begin_inset Text
19491
19492 \begin_layout Standard
19493
19494 \family roman
19495 \series medium
19496 \shape up
19497 \size normal
19498 \emph off
19499 \bar no
19500 \noun off
19501 \color none
19502 multiply floating point numbers 
19503 \end_layout
19504
19505 \end_inset
19506 </cell>
19507 </row>
19508 <row topline="true">
19509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19510 \begin_inset Text
19511
19512 \begin_layout Standard
19513
19514 \family roman
19515 \series medium
19516 \shape up
19517 \size normal
19518 \emph off
19519 \bar no
19520 \noun off
19521 \color none
19522 _fs2uchar.c
19523 \end_layout
19524
19525 \end_inset
19526 </cell>
19527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19528 \begin_inset Text
19529
19530 \begin_layout Standard
19531
19532 \family roman
19533 \series medium
19534 \shape up
19535 \size normal
19536 \emph off
19537 \bar no
19538 \noun off
19539 \color none
19540 convert floating point to unsigned char
19541 \end_layout
19542
19543 \end_inset
19544 </cell>
19545 </row>
19546 <row topline="true">
19547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19548 \begin_inset Text
19549
19550 \begin_layout Standard
19551
19552 \family roman
19553 \series medium
19554 \shape up
19555 \size normal
19556 \emph off
19557 \bar no
19558 \noun off
19559 \color none
19560 _fs2char.c
19561 \end_layout
19562
19563 \end_inset
19564 </cell>
19565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19566 \begin_inset Text
19567
19568 \begin_layout Standard
19569
19570 \family roman
19571 \series medium
19572 \shape up
19573 \size normal
19574 \emph off
19575 \bar no
19576 \noun off
19577 \color none
19578 convert floating point to signed char
19579 \end_layout
19580
19581 \end_inset
19582 </cell>
19583 </row>
19584 <row topline="true">
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19586 \begin_inset Text
19587
19588 \begin_layout Standard
19589
19590 \family roman
19591 \series medium
19592 \shape up
19593 \size normal
19594 \emph off
19595 \bar no
19596 \noun off
19597 \color none
19598 _fs2uint.c
19599 \end_layout
19600
19601 \end_inset
19602 </cell>
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19604 \begin_inset Text
19605
19606 \begin_layout Standard
19607
19608 \family roman
19609 \series medium
19610 \shape up
19611 \size normal
19612 \emph off
19613 \bar no
19614 \noun off
19615 \color none
19616 convert floating point to unsigned int
19617 \end_layout
19618
19619 \end_inset
19620 </cell>
19621 </row>
19622 <row topline="true">
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \begin_layout Standard
19627
19628 \family roman
19629 \series medium
19630 \shape up
19631 \size normal
19632 \emph off
19633 \bar no
19634 \noun off
19635 \color none
19636 _fs2int.c
19637 \end_layout
19638
19639 \end_inset
19640 </cell>
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19642 \begin_inset Text
19643
19644 \begin_layout Standard
19645
19646 \family roman
19647 \series medium
19648 \shape up
19649 \size normal
19650 \emph off
19651 \bar no
19652 \noun off
19653 \color none
19654 convert floating point to signed int
19655 \end_layout
19656
19657 \end_inset
19658 </cell>
19659 </row>
19660 <row topline="true">
19661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19662 \begin_inset Text
19663
19664 \begin_layout Standard
19665
19666 \family roman
19667 \series medium
19668 \shape up
19669 \size normal
19670 \emph off
19671 \bar no
19672 \noun off
19673 \color none
19674 _fs2ulong.
19675 \family default
19676 \series default
19677 \shape default
19678 \size default
19679 \emph default
19680 \bar default
19681 \noun default
19682 c
19683 \end_layout
19684
19685 \end_inset
19686 </cell>
19687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19688 \begin_inset Text
19689
19690 \begin_layout Standard
19691
19692 \family roman
19693 \series medium
19694 \shape up
19695 \size normal
19696 \emph off
19697 \bar no
19698 \noun off
19699 \color none
19700 convert floating point to unsigned long
19701 \end_layout
19702
19703 \end_inset
19704 </cell>
19705 </row>
19706 <row topline="true">
19707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19708 \begin_inset Text
19709
19710 \begin_layout Standard
19711
19712 \family roman
19713 \series medium
19714 \shape up
19715 \size normal
19716 \emph off
19717 \bar no
19718 \noun off
19719 \color none
19720 _fs2long.c
19721 \end_layout
19722
19723 \end_inset
19724 </cell>
19725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19726 \begin_inset Text
19727
19728 \begin_layout Standard
19729
19730 \family roman
19731 \series medium
19732 \shape up
19733 \size normal
19734 \emph off
19735 \bar no
19736 \noun off
19737 \color none
19738 convert floating point to signed long
19739 \end_layout
19740
19741 \end_inset
19742 </cell>
19743 </row>
19744 <row topline="true">
19745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19746 \begin_inset Text
19747
19748 \begin_layout Standard
19749
19750 \family roman
19751 \series medium
19752 \shape up
19753 \size normal
19754 \emph off
19755 \bar no
19756 \noun off
19757 \color none
19758 _uchar2fs.c
19759 \end_layout
19760
19761 \end_inset
19762 </cell>
19763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19764 \begin_inset Text
19765
19766 \begin_layout Standard
19767
19768 \family roman
19769 \series medium
19770 \shape up
19771 \size normal
19772 \emph off
19773 \bar no
19774 \noun off
19775 \color none
19776 convert unsigned char to floating point
19777 \end_layout
19778
19779 \end_inset
19780 </cell>
19781 </row>
19782 <row topline="true">
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \begin_layout Standard
19787
19788 \family roman
19789 \series medium
19790 \shape up
19791 \size normal
19792 \emph off
19793 \bar no
19794 \noun off
19795 \color none
19796 _char2fs.c
19797 \end_layout
19798
19799 \end_inset
19800 </cell>
19801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19802 \begin_inset Text
19803
19804 \begin_layout Standard
19805
19806 \family roman
19807 \series medium
19808 \shape up
19809 \size normal
19810 \emph off
19811 \bar no
19812 \noun off
19813 \color none
19814 convert char to floating point number
19815 \end_layout
19816
19817 \end_inset
19818 </cell>
19819 </row>
19820 <row topline="true">
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19822 \begin_inset Text
19823
19824 \begin_layout Standard
19825
19826 \family roman
19827 \series medium
19828 \shape up
19829 \size normal
19830 \emph off
19831 \bar no
19832 \noun off
19833 \color none
19834 _uint2fs.c
19835 \end_layout
19836
19837 \end_inset
19838 </cell>
19839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19840 \begin_inset Text
19841
19842 \begin_layout Standard
19843
19844 \family roman
19845 \series medium
19846 \shape up
19847 \size normal
19848 \emph off
19849 \bar no
19850 \noun off
19851 \color none
19852 convert unsigned int to floating point
19853 \end_layout
19854
19855 \end_inset
19856 </cell>
19857 </row>
19858 <row topline="true">
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19860 \begin_inset Text
19861
19862 \begin_layout Standard
19863
19864 \family roman
19865 \series medium
19866 \shape up
19867 \size normal
19868 \emph off
19869 \bar no
19870 \noun off
19871 \color none
19872 _int2fs.c
19873 \end_layout
19874
19875 \end_inset
19876 </cell>
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19878 \begin_inset Text
19879
19880 \begin_layout Standard
19881
19882 \family roman
19883 \series medium
19884 \shape up
19885 \size normal
19886 \emph off
19887 \bar no
19888 \noun off
19889 \color none
19890 convert int to floating point numbers
19891 \end_layout
19892
19893 \end_inset
19894 </cell>
19895 </row>
19896 <row topline="true">
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19898 \begin_inset Text
19899
19900 \begin_layout Standard
19901
19902 \family roman
19903 \series medium
19904 \shape up
19905 \size normal
19906 \emph off
19907 \bar no
19908 \noun off
19909 \color none
19910 _ulong2fs.c
19911 \end_layout
19912
19913 \end_inset
19914 </cell>
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19916 \begin_inset Text
19917
19918 \begin_layout Standard
19919
19920 \family roman
19921 \series medium
19922 \shape up
19923 \size normal
19924 \emph off
19925 \bar no
19926 \noun off
19927 \color none
19928 convert unsigned long to floating point number
19929 \end_layout
19930
19931 \end_inset
19932 </cell>
19933 </row>
19934 <row topline="true" bottomline="true">
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19936 \begin_inset Text
19937
19938 \begin_layout Standard
19939
19940 \family roman
19941 \series medium
19942 \shape up
19943 \size normal
19944 \emph off
19945 \bar no
19946 \noun off
19947 \color none
19948 _long2fs.c
19949 \end_layout
19950
19951 \end_inset
19952 </cell>
19953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19954 \begin_inset Text
19955
19956 \begin_layout Standard
19957
19958 \family roman
19959 \series medium
19960 \shape up
19961 \size normal
19962 \emph off
19963 \bar no
19964 \noun off
19965 \color none
19966 convert long to floating point number
19967 \end_layout
19968
19969 \end_inset
19970 </cell>
19971 </row>
19972 </lyxtabular>
19973
19974 \end_inset
19975
19976
19977 \newline
19978
19979 \end_layout
19980
19981 \begin_layout Standard
19982 These support routines are developed in ANSI-C so there is room for space
19983  and speed improvement
19984 \begin_inset Foot
19985 status open
19986
19987 \begin_layout Standard
19988 These floating point routines (
19989 \emph on
19990 not
19991 \emph default
19992  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19993  
19994 \end_layout
19995
19996 \end_inset
19997
19998 .
19999  Note if all these routines are used simultaneously the data space might
20000  overflow.
20001  For serious floating point usage the large model might be needed.
20002  Also notice that you don't have to call this routines directly.
20003  The compiler will use them automatically every time a floating point operation
20004  is required.
20005 \begin_inset VSpace bigskip
20006 \end_inset
20007
20008
20009 \end_layout
20010
20011 \begin_layout Section
20012 Library Routines
20013 \begin_inset LatexCommand \index{Libraries}
20014
20015 \end_inset
20016
20017
20018 \end_layout
20019
20020 \begin_layout Standard
20021
20022 \emph on
20023 <pending: this is messy and incomplete - a little more information is in
20024  sdcc/doc/libdoc.txt
20025 \emph default
20026  >
20027 \end_layout
20028
20029 \begin_layout Subsection
20030 Compiler support routines (_gptrget, _mulint etc.)
20031 \end_layout
20032
20033 \begin_layout Subsection
20034 Stdclib functions (puts, printf, strcat etc.)
20035 \end_layout
20036
20037 \begin_layout Subsubsection
20038 <stdio.h>
20039 \end_layout
20040
20041 \begin_layout Paragraph
20042 getchar(), putchar()
20043 \end_layout
20044
20045 \begin_layout Standard
20046 \begin_inset LatexCommand \index{<stdio.h>}
20047
20048 \end_inset
20049
20050 As usual on embedded systems you have to provide your own 
20051 \family typewriter
20052 getchar()
20053 \begin_inset LatexCommand \index{getchar()}
20054
20055 \end_inset
20056
20057  
20058 \family default
20059 and 
20060 \family typewriter
20061 putchar()
20062 \begin_inset LatexCommand \index{putchar()}
20063
20064 \end_inset
20065
20066
20067 \family default
20068  routines.
20069  SDCC does not know whether the system connects to a serial line with or
20070  without handshake, LCD, keyboard or other device.
20071  And whether a 
20072 \family typewriter
20073 lf
20074 \family default
20075  to 
20076 \family typewriter
20077 crlf
20078 \family default
20079  conversion within 
20080 \family typewriter
20081 putchar()
20082 \family default
20083  is intended.
20084  You'll find examples for serial routines f.e.
20085  in sdcc/device/lib.
20086  For the mcs51 this minimalistic polling 
20087 \family typewriter
20088 putchar()
20089 \family default
20090  routine might be a start:
20091 \end_layout
20092
20093 \begin_layout Verse
20094
20095 \family typewriter
20096 void putchar (char c) { 
20097 \newline
20098 \InsetSpace ~
20099 \InsetSpace ~
20100 \InsetSpace ~
20101 \InsetSpace ~
20102 while (!TI)\InsetSpace ~
20103 \InsetSpace ~
20104 \InsetSpace ~
20105  /* assumes UART is initialized */
20106 \newline
20107 \InsetSpace ~
20108 \InsetSpace ~
20109 \InsetSpace ~
20110 \InsetSpace ~
20111 \InsetSpace ~
20112 \InsetSpace ~
20113 \InsetSpace ~
20114 \InsetSpace ~
20115 ;
20116 \newline
20117 \InsetSpace ~
20118 \InsetSpace ~
20119 \InsetSpace ~
20120 \InsetSpace ~
20121 TI
20122  = 0;
20123 \newline
20124 \InsetSpace ~
20125 \InsetSpace ~
20126 \InsetSpace ~
20127 \InsetSpace ~
20128 SBUF = c;
20129 \newline
20130 }
20131 \end_layout
20132
20133 \begin_layout Paragraph
20134 printf()
20135 \end_layout
20136
20137 \begin_layout Standard
20138 The default
20139 \family typewriter
20140  printf()
20141 \begin_inset LatexCommand \index{printf()}
20142
20143 \end_inset
20144
20145
20146 \family default
20147  implementation in
20148 \family typewriter
20149  printf_large.c
20150 \family default
20151  does not support float (except on ds390).
20152  To enable this recompile it with the option 
20153 \emph on
20154 -
20155 \begin_inset ERT
20156 status collapsed
20157
20158 \begin_layout Standard
20159
20160
20161 \backslash
20162 /
20163 \end_layout
20164
20165 \end_inset
20166
20167 DUSE_FLOATS=1
20168 \begin_inset LatexCommand \index{USE\_FLOATS}
20169
20170 \end_inset
20171
20172
20173 \emph default
20174  on the command line.
20175  Use
20176 \emph on
20177  -
20178 \begin_inset ERT
20179 status collapsed
20180
20181 \begin_layout Standard
20182
20183
20184 \backslash
20185 /
20186 \end_layout
20187
20188 \end_inset
20189
20190 -model-large
20191 \begin_inset LatexCommand \index{-\/-model-large}
20192
20193 \end_inset
20194
20195
20196 \emph default
20197  for the mcs51 port, since this uses a lot of memory.
20198 \end_layout
20199
20200 \begin_layout Standard
20201 If you're short on code memory you might want to use 
20202 \family typewriter
20203 printf_small()
20204 \begin_inset LatexCommand \index{printf\_small()}
20205
20206 \end_inset
20207
20208
20209 \family default
20210  
20211 \emph on
20212 instead
20213 \emph default
20214  of
20215 \family typewriter
20216  printf().
20217
20218 \family default
20219  For the mcs51 there additionally are assembly versions 
20220 \family typewriter
20221 printf_tiny()
20222 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20223
20224 \end_inset
20225
20226
20227 \family default
20228  (subset of printf using less than 270 bytes) and 
20229 \family typewriter
20230 printf_fast()
20231 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20232
20233 \end_inset
20234
20235  
20236 \family default
20237 and
20238 \family typewriter
20239  printf_fast_f()
20240 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20241
20242 \end_inset
20243
20244
20245 \family default
20246  (floating-point aware version of printf_fast) which should fit the requirements
20247  of many embedded systems (printf_fast() can be customized by unsetting
20248  #defines to 
20249 \emph on
20250 not
20251 \emph default
20252  support long variables and field widths).
20253  Be sure to use only one of these printf options within a project.
20254 \newline
20255
20256 \end_layout
20257
20258 \begin_layout Standard
20259 Feature matrix of different 
20260 \emph on
20261 printf
20262 \emph default
20263  options on mcs51.
20264 \end_layout
20265
20266 \begin_layout Standard
20267 \begin_inset Tabular
20268 <lyxtabular version="3" rows="14" columns="7">
20269 <features islongtable="true">
20270 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20271 <column alignment="center" valignment="top" leftline="true" width="0">
20272 <column alignment="center" valignment="top" leftline="true" width="12col%">
20273 <column alignment="center" valignment="top" leftline="true" width="10col%">
20274 <column alignment="center" valignment="top" leftline="true" width="0">
20275 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20276 <column alignment="center" valignment="top" rightline="true" width="0">
20277 <row topline="true" bottomline="true" endhead="true">
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20279 \begin_inset Text
20280
20281 \begin_layout Standard
20282
20283 \series bold
20284 \size large
20285 mcs51
20286 \end_layout
20287
20288 \end_inset
20289 </cell>
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20291 \begin_inset Text
20292
20293 \begin_layout Standard
20294 printf
20295 \begin_inset LatexCommand \index{printf}
20296
20297 \end_inset
20298
20299
20300 \end_layout
20301
20302 \end_inset
20303 </cell>
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20305 \begin_inset Text
20306
20307 \begin_layout Standard
20308 printf 
20309 \size scriptsize
20310 USE_FLOATS=1
20311 \end_layout
20312
20313 \end_inset
20314 </cell>
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20316 \begin_inset Text
20317
20318 \begin_layout Standard
20319 printf_small
20320 \end_layout
20321
20322 \end_inset
20323 </cell>
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20325 \begin_inset Text
20326
20327 \begin_layout Standard
20328 printf_fast
20329 \end_layout
20330
20331 \end_inset
20332 </cell>
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20334 \begin_inset Text
20335
20336 \begin_layout Standard
20337 printf_fast_f
20338 \end_layout
20339
20340 \end_inset
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \begin_layout Standard
20346 printf_tiny
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 </row>
20352 <row topline="true" endhead="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20354 \begin_inset Text
20355
20356 \begin_layout Standard
20357 filename
20358 \end_layout
20359
20360 \end_inset
20361 </cell>
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \begin_layout Standard
20366
20367 \size scriptsize
20368 printf_large.c
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377
20378 \size scriptsize
20379 printf_large.c
20380 \end_layout
20381
20382 \end_inset
20383 </cell>
20384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20385 \begin_inset Text
20386
20387 \begin_layout Standard
20388
20389 \size scriptsize
20390 printfl.c
20391 \end_layout
20392
20393 \end_inset
20394 </cell>
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20396 \begin_inset Text
20397
20398 \begin_layout Standard
20399
20400 \size scriptsize
20401 printf_fast.c
20402 \end_layout
20403
20404 \end_inset
20405 </cell>
20406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20407 \begin_inset Text
20408
20409 \begin_layout Standard
20410
20411 \size scriptsize
20412 printf_fast_f.c
20413 \end_layout
20414
20415 \end_inset
20416 </cell>
20417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20418 \begin_inset Text
20419
20420 \begin_layout Standard
20421
20422 \size scriptsize
20423 printf_tiny.c
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 </row>
20429 <row topline="true" endhead="true">
20430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20431 \begin_inset Text
20432
20433 \begin_layout Standard
20434 \begin_inset Quotes sld
20435 \end_inset
20436
20437 Hello World
20438 \begin_inset Quotes srd
20439 \end_inset
20440
20441  size
20442 \end_layout
20443
20444 \begin_layout Standard
20445 small / large
20446 \end_layout
20447
20448 \end_inset
20449 </cell>
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20451 \begin_inset Text
20452
20453 \begin_layout Standard
20454 1.7k / 2.4k
20455 \end_layout
20456
20457 \end_inset
20458 </cell>
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20460 \begin_inset Text
20461
20462 \begin_layout Standard
20463 4.3k / 5.6k
20464 \end_layout
20465
20466 \end_inset
20467 </cell>
20468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20469 \begin_inset Text
20470
20471 \begin_layout Standard
20472 1.2k / 1.8k
20473 \end_layout
20474
20475 \end_inset
20476 </cell>
20477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20478 \begin_inset Text
20479
20480 \begin_layout Standard
20481 1.3k / 1.3k
20482 \end_layout
20483
20484 \end_inset
20485 </cell>
20486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20487 \begin_inset Text
20488
20489 \begin_layout Standard
20490 1.9k / 1.9k
20491 \end_layout
20492
20493 \end_inset
20494 </cell>
20495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20496 \begin_inset Text
20497
20498 \begin_layout Standard
20499 0.44k / 0.44k
20500 \end_layout
20501
20502 \end_inset
20503 </cell>
20504 </row>
20505 <row topline="true" endhead="true">
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20507 \begin_inset Text
20508
20509 \begin_layout Standard
20510 code size
20511 \end_layout
20512
20513 \begin_layout Standard
20514 small / large
20515 \end_layout
20516
20517 \end_inset
20518 </cell>
20519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_inset Text
20521
20522 \begin_layout Standard
20523 1.4k / 2.0k
20524 \end_layout
20525
20526 \end_inset
20527 </cell>
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20529 \begin_inset Text
20530
20531 \begin_layout Standard
20532 2.8k / 3.7k
20533 \end_layout
20534
20535 \end_inset
20536 </cell>
20537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20538 \begin_inset Text
20539
20540 \begin_layout Standard
20541 0.45k / 0.47k (+ _ltoa)
20542 \end_layout
20543
20544 \end_inset
20545 </cell>
20546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20547 \begin_inset Text
20548
20549 \begin_layout Standard
20550 1.2k / 1.2k
20551 \end_layout
20552
20553 \end_inset
20554 </cell>
20555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20556 \begin_inset Text
20557
20558 \begin_layout Standard
20559 1.6k / 1.6k
20560 \end_layout
20561
20562 \end_inset
20563 </cell>
20564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20565 \begin_inset Text
20566
20567 \begin_layout Standard
20568 0.26k / 0.26k
20569 \end_layout
20570
20571 \end_inset
20572 </cell>
20573 </row>
20574 <row topline="true">
20575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20576 \begin_inset Text
20577
20578 \begin_layout Standard
20579 formats
20580 \end_layout
20581
20582 \end_inset
20583 </cell>
20584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20585 \begin_inset Text
20586
20587 \begin_layout Standard
20588 cdi
20589 \emph on
20590 o
20591 \emph default
20592 psux
20593 \end_layout
20594
20595 \end_inset
20596 </cell>
20597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20598 \begin_inset Text
20599
20600 \begin_layout Standard
20601
20602 \family roman
20603 \series medium
20604 \shape up
20605 \size normal
20606 \emph off
20607 \bar no
20608 \noun off
20609 \color none
20610 cd
20611 \family default
20612 \series default
20613 \shape default
20614 \size default
20615 \emph default
20616 \bar default
20617 \noun default
20618 f
20619 \family roman
20620 \series medium
20621 \shape up
20622 \size normal
20623 \emph off
20624 \bar no
20625 \noun off
20626 i
20627 \family default
20628 \series default
20629 \shape default
20630 \size default
20631 \emph on
20632 \bar default
20633 \noun default
20634 o
20635 \family roman
20636 \series medium
20637 \shape up
20638 \size normal
20639 \emph off
20640 \bar no
20641 \noun off
20642 psux
20643 \end_layout
20644
20645 \end_inset
20646 </cell>
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20648 \begin_inset Text
20649
20650 \begin_layout Standard
20651 c
20652 \family roman
20653 \series medium
20654 \shape up
20655 \size normal
20656 \emph off
20657 \bar no
20658 \noun off
20659 \color none
20660 d
20661 \family default
20662 \series default
20663 \shape default
20664 \size default
20665 \emph on
20666 \bar default
20667 \noun default
20668 o
20669 \family roman
20670 \series medium
20671 \shape up
20672 \size normal
20673 \emph off
20674 \bar no
20675 \noun off
20676 s
20677 \family default
20678 \series default
20679 \shape default
20680 \size default
20681 \emph default
20682 \bar default
20683 \noun default
20684 x
20685 \end_layout
20686
20687 \end_inset
20688 </cell>
20689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20690 \begin_inset Text
20691
20692 \begin_layout Standard
20693 cdsux
20694 \end_layout
20695
20696 \end_inset
20697 </cell>
20698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20699 \begin_inset Text
20700
20701 \begin_layout Standard
20702 cdfsux
20703 \end_layout
20704
20705 \end_inset
20706 </cell>
20707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20708 \begin_inset Text
20709
20710 \begin_layout Standard
20711 cdsux
20712 \end_layout
20713
20714 \end_inset
20715 </cell>
20716 </row>
20717 <row topline="true">
20718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20719 \begin_inset Text
20720
20721 \begin_layout Standard
20722 long (32 bit) support
20723 \end_layout
20724
20725 \end_inset
20726 </cell>
20727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20728 \begin_inset Text
20729
20730 \begin_layout Standard
20731 x
20732 \end_layout
20733
20734 \end_inset
20735 </cell>
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20737 \begin_inset Text
20738
20739 \begin_layout Standard
20740 x
20741 \end_layout
20742
20743 \end_inset
20744 </cell>
20745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20746 \begin_inset Text
20747
20748 \begin_layout Standard
20749 x
20750 \end_layout
20751
20752 \end_inset
20753 </cell>
20754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20755 \begin_inset Text
20756
20757 \begin_layout Standard
20758 x
20759 \end_layout
20760
20761 \end_inset
20762 </cell>
20763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20764 \begin_inset Text
20765
20766 \begin_layout Standard
20767
20768 \family roman
20769 \series medium
20770 \shape up
20771 \size normal
20772 \emph off
20773 \bar no
20774 \noun off
20775 \color none
20776 x
20777 \end_layout
20778
20779 \end_inset
20780 </cell>
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20782 \begin_inset Text
20783
20784 \begin_layout Standard
20785 -
20786 \end_layout
20787
20788 \end_inset
20789 </cell>
20790 </row>
20791 <row topline="true">
20792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20793 \begin_inset Text
20794
20795 \begin_layout Standard
20796 byte arguments on stack
20797 \end_layout
20798
20799 \end_inset
20800 </cell>
20801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20802 \begin_inset Text
20803
20804 \begin_layout Standard
20805 b
20806 \end_layout
20807
20808 \end_inset
20809 </cell>
20810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20811 \begin_inset Text
20812
20813 \begin_layout Standard
20814 b
20815 \end_layout
20816
20817 \end_inset
20818 </cell>
20819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20820 \begin_inset Text
20821
20822 \begin_layout Standard
20823 -
20824 \end_layout
20825
20826 \end_inset
20827 </cell>
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_inset Text
20830
20831 \begin_layout Standard
20832 -
20833 \end_layout
20834
20835 \end_inset
20836 </cell>
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20838 \begin_inset Text
20839
20840 \begin_layout Standard
20841 -
20842 \end_layout
20843
20844 \end_inset
20845 </cell>
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20847 \begin_inset Text
20848
20849 \begin_layout Standard
20850 -
20851 \end_layout
20852
20853 \end_inset
20854 </cell>
20855 </row>
20856 <row topline="true">
20857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20858 \begin_inset Text
20859
20860 \begin_layout Standard
20861 float format
20862 \begin_inset LatexCommand \index{Floating point support}
20863
20864 \end_inset
20865
20866
20867 \end_layout
20868
20869 \end_inset
20870 </cell>
20871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20872 \begin_inset Text
20873
20874 \begin_layout Standard
20875 -
20876 \end_layout
20877
20878 \end_inset
20879 </cell>
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 \begin_inset Text
20882
20883 \begin_layout Standard
20884 %f
20885 \end_layout
20886
20887 \end_inset
20888 </cell>
20889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20890 \begin_inset Text
20891
20892 \begin_layout Standard
20893 -
20894 \end_layout
20895
20896 \end_inset
20897 </cell>
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \begin_layout Standard
20902 -
20903 \end_layout
20904
20905 \end_inset
20906 </cell>
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20908 \begin_inset Text
20909
20910 \begin_layout Standard
20911 %f
20912 \begin_inset Foot
20913 status collapsed
20914
20915 \begin_layout Standard
20916 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20917 \end_layout
20918
20919 \end_inset
20920
20921
20922 \end_layout
20923
20924 \end_inset
20925 </cell>
20926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20927 \begin_inset Text
20928
20929 \begin_layout Standard
20930 -
20931 \end_layout
20932
20933 \end_inset
20934 </cell>
20935 </row>
20936 <row topline="true">
20937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20938 \begin_inset Text
20939
20940 \begin_layout Standard
20941 float formats %e %g
20942 \end_layout
20943
20944 \end_inset
20945 </cell>
20946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20947 \begin_inset Text
20948
20949 \begin_layout Standard
20950 -
20951 \end_layout
20952
20953 \end_inset
20954 </cell>
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20956 \begin_inset Text
20957
20958 \begin_layout Standard
20959 -
20960 \end_layout
20961
20962 \end_inset
20963 </cell>
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20965 \begin_inset Text
20966
20967 \begin_layout Standard
20968 -
20969 \end_layout
20970
20971 \end_inset
20972 </cell>
20973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20974 \begin_inset Text
20975
20976 \begin_layout Standard
20977 -
20978 \end_layout
20979
20980 \end_inset
20981 </cell>
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20983 \begin_inset Text
20984
20985 \begin_layout Standard
20986 -
20987 \end_layout
20988
20989 \end_inset
20990 </cell>
20991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20992 \begin_inset Text
20993
20994 \begin_layout Standard
20995 -
20996 \end_layout
20997
20998 \end_inset
20999 </cell>
21000 </row>
21001 <row topline="true" bottomline="true">
21002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21003 \begin_inset Text
21004
21005 \begin_layout Standard
21006 field width
21007 \end_layout
21008
21009 \end_inset
21010 </cell>
21011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21012 \begin_inset Text
21013
21014 \begin_layout Standard
21015 x
21016 \end_layout
21017
21018 \end_inset
21019 </cell>
21020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21021 \begin_inset Text
21022
21023 \begin_layout Standard
21024 x
21025 \end_layout
21026
21027 \end_inset
21028 </cell>
21029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21030 \begin_inset Text
21031
21032 \begin_layout Standard
21033 -
21034 \end_layout
21035
21036 \end_inset
21037 </cell>
21038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21039 \begin_inset Text
21040
21041 \begin_layout Standard
21042 x
21043 \end_layout
21044
21045 \end_inset
21046 </cell>
21047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21048 \begin_inset Text
21049
21050 \begin_layout Standard
21051 x
21052 \end_layout
21053
21054 \end_inset
21055 </cell>
21056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21057 \begin_inset Text
21058
21059 \begin_layout Standard
21060 -
21061 \end_layout
21062
21063 \end_inset
21064 </cell>
21065 </row>
21066 <row bottomline="true">
21067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21068 \begin_inset Text
21069
21070 \begin_layout Standard
21071 string speed
21072 \begin_inset Foot
21073 status collapsed
21074
21075 \begin_layout Standard
21076 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21077 \backslash
21078 r', '
21079 \backslash
21080 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21081 \end_layout
21082
21083 \end_inset
21084
21085 ,
21086 \end_layout
21087
21088 \begin_layout Standard
21089 small / large
21090 \end_layout
21091
21092 \end_inset
21093 </cell>
21094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21095 \begin_inset Text
21096
21097 \begin_layout Standard
21098 1.52 / 2.59 ms
21099 \end_layout
21100
21101 \end_inset
21102 </cell>
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21104 \begin_inset Text
21105
21106 \begin_layout Standard
21107 1.53 / 2.62 ms
21108 \end_layout
21109
21110 \end_inset
21111 </cell>
21112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21113 \begin_inset Text
21114
21115 \begin_layout Standard
21116 0.92 / 0.93 ms
21117 \end_layout
21118
21119 \end_inset
21120 </cell>
21121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21122 \begin_inset Text
21123
21124 \begin_layout Standard
21125 0.45 / 0.45 ms
21126 \end_layout
21127
21128 \end_inset
21129 </cell>
21130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21131 \begin_inset Text
21132
21133 \begin_layout Standard
21134 0.46 / 0.46 ms
21135 \end_layout
21136
21137 \end_inset
21138 </cell>
21139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21140 \begin_inset Text
21141
21142 \begin_layout Standard
21143 0.45 / 0.45 ms
21144 \end_layout
21145
21146 \end_inset
21147 </cell>
21148 </row>
21149 <row bottomline="true">
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21151 \begin_inset Text
21152
21153 \begin_layout Standard
21154 int speed
21155 \begin_inset Foot
21156 status collapsed
21157
21158 \begin_layout Standard
21159 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21160  putchar()
21161 \end_layout
21162
21163 \end_inset
21164
21165 ,
21166 \end_layout
21167
21168 \begin_layout Standard
21169 small / large
21170 \end_layout
21171
21172 \end_inset
21173 </cell>
21174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21175 \begin_inset Text
21176
21177 \begin_layout Standard
21178 3.01 / 3.61 ms
21179 \end_layout
21180
21181 \end_inset
21182 </cell>
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \begin_layout Standard
21187 3.01 / 3.61 ms
21188 \end_layout
21189
21190 \end_inset
21191 </cell>
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21193 \begin_inset Text
21194
21195 \begin_layout Standard
21196 3.51 / 18.13 ms
21197 \end_layout
21198
21199 \end_inset
21200 </cell>
21201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21202 \begin_inset Text
21203
21204 \begin_layout Standard
21205 0.22 / 0.22 ms
21206 \end_layout
21207
21208 \end_inset
21209 </cell>
21210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21211 \begin_inset Text
21212
21213 \begin_layout Standard
21214 0.23 / 0.23 ms
21215 \end_layout
21216
21217 \end_inset
21218 </cell>
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21220 \begin_inset Text
21221
21222 \begin_layout Standard
21223 0.25 / 0.25 ms
21224 \begin_inset Foot
21225 status collapsed
21226
21227 \begin_layout Standard
21228 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21229 \end_layout
21230
21231 \end_inset
21232
21233
21234 \end_layout
21235
21236 \end_inset
21237 </cell>
21238 </row>
21239 <row bottomline="true">
21240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21241 \begin_inset Text
21242
21243 \begin_layout Standard
21244 long speed
21245 \begin_inset Foot
21246 status collapsed
21247
21248 \begin_layout Standard
21249 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21250  empty putchar()
21251 \end_layout
21252
21253 \end_inset
21254
21255 ,
21256 \end_layout
21257
21258 \begin_layout Standard
21259 small / large
21260 \end_layout
21261
21262 \end_inset
21263 </cell>
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21265 \begin_inset Text
21266
21267 \begin_layout Standard
21268 5.37 / 6.31 ms
21269 \end_layout
21270
21271 \end_inset
21272 </cell>
21273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21274 \begin_inset Text
21275
21276 \begin_layout Standard
21277 5.37 / 6.31 ms
21278 \end_layout
21279
21280 \end_inset
21281 </cell>
21282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21283 \begin_inset Text
21284
21285 \begin_layout Standard
21286 8.71 / 40.65 ms
21287 \end_layout
21288
21289 \end_inset
21290 </cell>
21291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21292 \begin_inset Text
21293
21294 \begin_layout Standard
21295 0.40 / 0.40 ms
21296 \end_layout
21297
21298 \end_inset
21299 </cell>
21300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21301 \begin_inset Text
21302
21303 \begin_layout Standard
21304 0.40 / 0.40 ms
21305 \end_layout
21306
21307 \end_inset
21308 </cell>
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21310 \begin_inset Text
21311
21312 \begin_layout Standard
21313 -
21314 \end_layout
21315
21316 \end_inset
21317 </cell>
21318 </row>
21319 <row bottomline="true">
21320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21321 \begin_inset Text
21322
21323 \begin_layout Standard
21324 float speed
21325 \begin_inset Foot
21326 status collapsed
21327
21328 \begin_layout Standard
21329 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21330  empty putchar()
21331 \end_layout
21332
21333 \end_inset
21334
21335 ,
21336 \end_layout
21337
21338 \begin_layout Standard
21339 small / large
21340 \end_layout
21341
21342 \end_inset
21343 </cell>
21344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21345 \begin_inset Text
21346
21347 \begin_layout Standard
21348 -
21349 \end_layout
21350
21351 \end_inset
21352 </cell>
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21354 \begin_inset Text
21355
21356 \begin_layout Standard
21357 7.49 / 22.47 ms
21358 \end_layout
21359
21360 \end_inset
21361 </cell>
21362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21363 \begin_inset Text
21364
21365 \begin_layout Standard
21366 -
21367 \end_layout
21368
21369 \end_inset
21370 </cell>
21371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21372 \begin_inset Text
21373
21374 \begin_layout Standard
21375 -
21376 \end_layout
21377
21378 \end_inset
21379 </cell>
21380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21381 \begin_inset Text
21382
21383 \begin_layout Standard
21384 1.04 / 1.04 ms
21385 \end_layout
21386
21387 \end_inset
21388 </cell>
21389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21390 \begin_inset Text
21391
21392 \begin_layout Standard
21393 -
21394 \end_layout
21395
21396 \end_inset
21397 </cell>
21398 </row>
21399 </lyxtabular>
21400
21401 \end_inset
21402
21403
21404 \end_layout
21405
21406 \begin_layout Subsubsection
21407 <malloc.h>
21408 \begin_inset LatexCommand \index{malloc.h}
21409
21410 \end_inset
21411
21412
21413 \end_layout
21414
21415 \begin_layout Standard
21416 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21417  using dynamic memory allocation
21418 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21419
21420 \end_inset
21421
21422  and a default heap
21423 \begin_inset LatexCommand \index{heap (malloc)}
21424
21425 \end_inset
21426
21427  space of 1024 bytes is provided for malloc to allocate memory from.
21428  If you need a different heap size you need to recompile _heap.c with the
21429  required size defined in HEAP_SIZE.
21430  It is recommended to make a copy of this file into your project directory
21431  and compile it there with:
21432 \end_layout
21433
21434 \begin_layout Verse
21435
21436 \family typewriter
21437 sdcc -c _heap.c -D HEAD_SIZE=2048
21438 \end_layout
21439
21440 \begin_layout Standard
21441 And then link it with:
21442 \end_layout
21443
21444 \begin_layout Verse
21445
21446 \family typewriter
21447 sdcc main.rel _heap.rel
21448 \end_layout
21449
21450 \begin_layout Subsection
21451 Math functions (sinf, powf, sqrtf etc.)
21452 \end_layout
21453
21454 \begin_layout Subsubsection
21455 <math.h>
21456 \end_layout
21457
21458 \begin_layout Standard
21459 See definitions in file <math.h>.
21460 \end_layout
21461
21462 \begin_layout Subsection
21463 Other libraries
21464 \end_layout
21465
21466 \begin_layout Standard
21467 Libraries
21468 \begin_inset LatexCommand \index{Libraries}
21469
21470 \end_inset
21471
21472  included in SDCC should have a license at least as liberal as the GNU Lesser
21473  General Public License
21474 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21475
21476 \end_inset
21477
21478  
21479 \emph on
21480 LGPL
21481 \emph default
21482 .
21483 \end_layout
21484
21485 \begin_layout Standard
21486 \begin_inset Note Note
21487 status collapsed
21488
21489 \begin_layout Standard
21490 license statements for the libraries are missing.
21491  sdcc/device/lib/ser_ir.c
21492 \end_layout
21493
21494 \begin_layout Standard
21495 or _decdptr f.e.
21496  come with a GPL (as opposed to LGPL) License - this will not be liberal
21497  enough for many embedded programmers.
21498 \end_layout
21499
21500 \end_inset
21501
21502
21503 \end_layout
21504
21505 \begin_layout Standard
21506 If you have ported some library or want to share experience about some code
21507  which f.e.
21508  falls into any of these categories Busses (I
21509 \begin_inset Formula $^{\textrm{2}}$
21510 \end_inset
21511
21512 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21513  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21514  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21515 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21516
21517 \end_inset
21518
21519 \InsetSpace ~
21520 would certainly like to hear about it.
21521 \end_layout
21522
21523 \begin_layout Standard
21524 Programmers coding for embedded systems are not especially famous for being
21525  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21526 e these references are very valuable.
21527  Let's help to create a climate where information is shared.
21528 \begin_inset VSpace bigskip
21529 \end_inset
21530
21531
21532 \end_layout
21533
21534 \begin_layout Section
21535 Memory Models
21536 \end_layout
21537
21538 \begin_layout Subsection
21539 MCS51 Memory Models
21540 \begin_inset LatexCommand \index{Memory model}
21541
21542 \end_inset
21543
21544
21545 \begin_inset LatexCommand \index{MCS51 memory model}
21546
21547 \end_inset
21548
21549
21550 \end_layout
21551
21552 \begin_layout Subsubsection
21553 Small, Medium and Large
21554 \end_layout
21555
21556 \begin_layout Standard
21557 SDCC allows three memory models for MCS51 code, 
21558 \shape slanted
21559 small, medium
21560 \shape default
21561  and 
21562 \shape slanted
21563 large
21564 \shape default
21565 .
21566  Modules compiled with different memory models should 
21567 \emph on
21568 never
21569 \emph default
21570  be combined together or the results would be unpredictable.
21571  The library routines supplied with the compiler are compiled as small,
21572  medium and large.
21573  The compiled library modules are contained in separate directories as small,
21574  medium and large so that you can link to the appropriate set.
21575 \end_layout
21576
21577 \begin_layout Standard
21578 When the medium or large model is used all variables declared without a
21579  storage class will be allocated into the external ram, this includes all
21580  parameters and local variables (for non-reentrant
21581 \begin_inset LatexCommand \index{reentrant}
21582
21583 \end_inset
21584
21585  functions).
21586  When the small model is used variables without storage class are allocated
21587  in the internal ram.
21588 \end_layout
21589
21590 \begin_layout Standard
21591 Judicious usage of the processor specific storage classes
21592 \begin_inset LatexCommand \index{Storage class}
21593
21594 \end_inset
21595
21596  and the 'reentrant' function type will yield much more efficient code,
21597  than using the large model.
21598  Several optimizations are disabled when the program is compiled using the
21599  large model, it is therefore recommended that the small model be used unless
21600  absolutely required.
21601 \end_layout
21602
21603 \begin_layout Subsubsection
21604 External Stack
21605 \begin_inset LatexCommand \label{sub:External-Stack}
21606
21607 \end_inset
21608
21609
21610 \begin_inset LatexCommand \index{stack}
21611
21612 \end_inset
21613
21614
21615 \begin_inset LatexCommand \index{External stack (mcs51)}
21616
21617 \end_inset
21618
21619
21620 \end_layout
21621
21622 \begin_layout Standard
21623 The external stack (-
21624 \begin_inset ERT
21625 status collapsed
21626
21627 \begin_layout Standard
21628
21629
21630 \backslash
21631 /
21632 \end_layout
21633
21634 \end_inset
21635
21636 -xstack option
21637 \begin_inset LatexCommand \index{-\/-xstack}
21638
21639 \end_inset
21640
21641 ) is located in pdata
21642 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21643
21644 \end_inset
21645
21646  memory (usually at the start of the external ram segment) and uses all
21647  unused space in pdata (max.
21648  256 bytes).
21649  When -
21650 \begin_inset ERT
21651 status collapsed
21652
21653 \begin_layout Standard
21654
21655
21656 \backslash
21657 /
21658 \end_layout
21659
21660 \end_inset
21661
21662 -xstack option is used to compile the program, the parameters and local
21663  variables
21664 \begin_inset LatexCommand \index{local variables}
21665
21666 \end_inset
21667
21668  of all reentrant functions are allocated in this area.
21669  This option is provided for programs with large stack space requirements.
21670  When used with the -
21671 \begin_inset ERT
21672 status collapsed
21673
21674 \begin_layout Standard
21675
21676
21677 \backslash
21678 /
21679 \end_layout
21680
21681 \end_inset
21682
21683 -stack-auto
21684 \begin_inset LatexCommand \index{-\/-stack-auto}
21685
21686 \end_inset
21687
21688  option, all parameters and local variables are allocated on the external
21689  stack (note: support libraries will need to be recompiled with the same
21690  options.
21691  There is a predefined target in the library makefile).
21692 \end_layout
21693
21694 \begin_layout Standard
21695 The compiler outputs the higher order address byte of the external ram segment
21696  into port P2
21697 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21698
21699 \end_inset
21700
21701  (see also section 
21702 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21703
21704 \end_inset
21705
21706 ), therefore when using the External Stack option, this port 
21707 \emph on
21708 may not
21709 \emph default
21710  be used by the application program.
21711 \end_layout
21712
21713 \begin_layout Subsection
21714 DS390 Memory Model
21715 \begin_inset LatexCommand \index{Memory model}
21716
21717 \end_inset
21718
21719
21720 \begin_inset LatexCommand \index{DS390 memory model}
21721
21722 \end_inset
21723
21724
21725 \end_layout
21726
21727 \begin_layout Standard
21728 The only model supported is Flat 24
21729 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21730
21731 \end_inset
21732
21733 .
21734  This generates code for the 24 bit contiguous addressing mode of the Dallas
21735  DS80C390 part.
21736  In this mode, up to four meg of external RAM or code space can be directly
21737  addressed.
21738  See the data sheets at www.dalsemi.com for further information on this part.
21739 \newline
21740
21741 \newline
21742 Note
21743  that the compiler does not generate any code to place the processor into
21744  24 bitmode (although 
21745 \emph on
21746 tinibios
21747 \emph default
21748  in the ds390 libraries will do that for you).
21749  If you don't use 
21750 \emph on
21751 tinibios
21752 \emph default
21753
21754 \begin_inset LatexCommand \index{Tinibios (DS390)}
21755
21756 \end_inset
21757
21758 , the boot loader or similar code must ensure that the processor is in 24
21759  bit contiguous addressing mode before calling the SDCC startup code.
21760 \newline
21761
21762 \newline
21763 Like
21764  the 
21765 \emph on
21766 -
21767 \begin_inset ERT
21768 status collapsed
21769
21770 \begin_layout Standard
21771
21772
21773 \backslash
21774 /
21775 \end_layout
21776
21777 \end_inset
21778
21779 -model-large
21780 \emph default
21781  option, variables will by default be placed into the XDATA segment.
21782  
21783 \newline
21784
21785 \newline
21786 Segments may be placed anywhere in the 4 meg address space using the usual
21787  -
21788 \begin_inset ERT
21789 status collapsed
21790
21791 \begin_layout Standard
21792
21793
21794 \backslash
21795 /
21796 \end_layout
21797
21798 \end_inset
21799
21800 -*-loc options.
21801  Note that if any segments are located above 64K, the -r flag must be passed
21802  to the linker to generate the proper segment relocations, and the Intel
21803  HEX output format must be used.
21804  The -r flag can be passed to the linker by using the option 
21805 \emph on
21806 -Wl-r
21807 \emph default
21808  on the SDCC command line.
21809  However, currently the linker can not handle code segments > 64k.
21810 \end_layout
21811
21812 \begin_layout Section
21813 Pragmas
21814 \begin_inset LatexCommand \label{sec:Pragmas}
21815
21816 \end_inset
21817
21818
21819 \begin_inset LatexCommand \index{Pragmas}
21820
21821 \end_inset
21822
21823
21824 \end_layout
21825
21826 \begin_layout Standard
21827 Pragmas are used to turn on and/or off certain compiler options.
21828  Some of them are closely related to corresponding command-line options
21829  (see section 
21830 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21831
21832 \end_inset
21833
21834 ).
21835 \newline
21836 Pragmas should be placed before and/or after a function, placing pragmas
21837  inside a function body could have unpredictable results.
21838 \newline
21839
21840 \newline
21841 SDCC supports the
21842  following #pragma directives:
21843 \end_layout
21844
21845 \begin_layout Itemize
21846
21847 \series bold
21848 save
21849 \series default
21850
21851 \begin_inset LatexCommand \index{\#pragma save}
21852
21853 \end_inset
21854
21855  - this will save most current options to the save/restore stack.
21856  See #pragma\InsetSpace ~
21857 restore.
21858 \end_layout
21859
21860 \begin_layout Itemize
21861
21862 \series bold
21863 restore
21864 \series default
21865
21866 \begin_inset LatexCommand \index{\#pragma restore}
21867
21868 \end_inset
21869
21870  - will restore saved options from the last save.
21871  saves & restores can be nested.
21872  SDCC uses a save/restore stack: save pushes current options to the stack,
21873  restore pulls current options from the stack.
21874  See #pragma\InsetSpace ~
21875 save.
21876 \newline
21877
21878 \end_layout
21879
21880 \begin_layout Itemize
21881
21882 \series bold
21883 callee_saves
21884 \series default
21885
21886 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21887
21888 \end_inset
21889
21890
21891 \begin_inset LatexCommand \index{function prologue}
21892
21893 \end_inset
21894
21895  function1[,function2[,function3...]] 
21896 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21897
21898 \end_inset
21899
21900 - The compiler by default uses a caller saves convention for register saving
21901  across function calls, however this can cause unnecessary register pushing
21902  and popping
21903 \begin_inset LatexCommand \index{push/pop}
21904
21905 \end_inset
21906
21907  when calling small functions from larger functions.
21908  This option can be used to switch off the register saving convention for
21909  the function names specified.
21910  The compiler will not save registers when calling these functions, extra
21911  code need to be manually inserted at the entry and exit for these functions
21912  to save and restore the registers used by these functions, this can SUBSTANTIAL
21913 LY reduce code and improve run time performance of the generated code.
21914  In the future the compiler (with inter procedural analysis) may be able
21915  to determine the appropriate scheme to use for each function call.
21916  If -
21917 \begin_inset ERT
21918 status collapsed
21919
21920 \begin_layout Standard
21921
21922
21923 \backslash
21924 /
21925 \end_layout
21926
21927 \end_inset
21928
21929 -callee-saves command line option is used (see page 
21930 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21931
21932 \end_inset
21933
21934 ), the function names specified in #pragma\InsetSpace ~
21935 callee_saves
21936 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21937
21938 \end_inset
21939
21940  is appended to the list of functions specified in the command line.
21941 \end_layout
21942
21943 \begin_layout Itemize
21944
21945 \series bold
21946 exclude
21947 \series default
21948
21949 \begin_inset LatexCommand \index{\#pragma exclude}
21950
21951 \end_inset
21952
21953  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21954  of pairs of push/pop
21955 \begin_inset LatexCommand \index{push/pop}
21956
21957 \end_inset
21958
21959  instructions in 
21960 \emph on
21961 I
21962 \emph default
21963 nterrupt
21964 \begin_inset LatexCommand \index{interrupt}
21965
21966 \end_inset
21967
21968  
21969 \emph on
21970 S
21971 \emph default
21972 ervice 
21973 \emph on
21974 R
21975 \emph default
21976 outines.
21977  The directive should be placed immediately before the ISR function definition
21978  and it affects ALL ISR functions following it.
21979  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21980 exclude\InsetSpace ~
21981 none
21982 \begin_inset LatexCommand \index{\#pragma exclude}
21983
21984 \end_inset
21985
21986 .
21987  See also the related keyword _naked
21988 \begin_inset LatexCommand \index{\_naked}
21989
21990 \end_inset
21991
21992
21993 \begin_inset LatexCommand \index{\_\_naked}
21994
21995 \end_inset
21996
21997 .
21998 \end_layout
21999
22000 \begin_layout Itemize
22001
22002 \series bold
22003 less_pedantic
22004 \series default
22005
22006 \begin_inset LatexCommand \index{pedantic}
22007
22008 \end_inset
22009
22010
22011 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
22012
22013 \end_inset
22014
22015  
22016 \begin_inset LatexCommand \label{ite:less_pedantic}
22017
22018 \end_inset
22019
22020 - the compiler will not warn you anymore for obvious mistakes, you're on
22021  your own now ;-( .
22022  See also the command line option -
22023 \begin_inset ERT
22024 status collapsed
22025
22026 \begin_layout Standard
22027
22028
22029 \backslash
22030 /
22031 \end_layout
22032
22033 \end_inset
22034
22035 -less-pedantic 
22036 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
22037
22038 \end_inset
22039
22040 .
22041  
22042 \newline
22043 More specifically, the following warnings will be disabled: 
22044 \shape italic
22045 comparison is always [true/false] due to limited range of data type
22046 \shape default
22047  (94); 
22048 \shape italic
22049 overflow in implicit constant conversion
22050 \shape default
22051  (158); [the (in)famous] 
22052 \shape italic
22053 conditional flow changed by optimizer: so said EVELYN the modified DOG
22054 \shape default
22055  (110); 
22056 \shape italic
22057 function '[function name]' must return value
22058 \shape default
22059  (59).
22060  
22061 \newline
22062 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22063  level) are disabled, too, namely: 
22064 \shape italic
22065 constant value '[
22066 \begin_inset Note Note
22067 status collapsed
22068
22069 \begin_layout Standard
22070 dunno what comes here - this warning appears to be unused altogether
22071 \end_layout
22072
22073 \end_inset
22074
22075 ]', out of range
22076 \shape default
22077  (81); 
22078 \shape italic
22079 [left/right] shifting more than size of object changed to zero
22080 \shape default
22081  (116); 
22082 \shape italic
22083 unreachable code
22084 \shape default
22085  (126); 
22086 \shape italic
22087 integer overflow in expression
22088 \shape default
22089  (165); 
22090 \shape italic
22091 unmatched #pragma save and #pragma restore
22092 \shape default
22093  (170); 
22094 \shape italic
22095 comparison of 'signed char' with 'unsigned char' requires promotion to int
22096 \shape default
22097  (185); 
22098 \shape italic
22099 ISO C90 does not support flexible array members
22100 \shape default
22101  (187); 
22102 \shape italic
22103 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22104 nam
22105 e]':\InsetSpace ~
22106 [
22107 \begin_inset Note Note
22108 status collapsed
22109
22110 \begin_layout Standard
22111 appears to be always blank - what was supposed to be here?
22112 \end_layout
22113
22114 \end_inset
22115
22116 ]
22117 \shape default
22118  (114); 
22119 \shape italic
22120 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22121  complexity [number]
22122 \shape default
22123  (121).
22124 \end_layout
22125
22126 \begin_layout Itemize
22127
22128 \series bold
22129 disable_warning
22130 \series default
22131  <nnnn>
22132 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22133
22134 \end_inset
22135
22136  - the compiler will not warn you anymore about warning number <nnnn>.
22137 \end_layout
22138
22139 \begin_layout Itemize
22140
22141 \series bold
22142 nogcse
22143 \series default
22144
22145 \begin_inset LatexCommand \index{\#pragma nogcse}
22146
22147 \end_inset
22148
22149  - will stop global common subexpression elimination.
22150 \end_layout
22151
22152 \begin_layout Itemize
22153
22154 \series bold
22155 noinduction
22156 \series default
22157
22158 \begin_inset LatexCommand \index{\#pragma noinduction}
22159
22160 \end_inset
22161
22162  - will stop loop induction optimizations.
22163 \end_layout
22164
22165 \begin_layout Itemize
22166
22167 \series bold
22168 noinvariant
22169 \series default
22170
22171 \begin_inset LatexCommand \index{\#pragma noinvariant}
22172
22173 \end_inset
22174
22175  - will not do loop invariant optimizations.
22176  For more details see Loop Invariants in section
22177 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22178
22179 \end_inset
22180
22181 .
22182 \end_layout
22183
22184 \begin_layout Itemize
22185
22186 \series bold
22187 noiv
22188 \series default
22189
22190 \begin_inset LatexCommand \index{\#pragma noiv}
22191
22192 \end_inset
22193
22194  - Do not generate interrupt
22195 \begin_inset LatexCommand \index{interrupt}
22196
22197 \end_inset
22198
22199  vector table
22200 \begin_inset LatexCommand \index{interrupt vector table}
22201
22202 \end_inset
22203
22204  entries for all ISR functions defined after the pragma.
22205  This is useful in cases where the interrupt vector table must be defined
22206  manually, or when there is a secondary, manually defined interrupt vector
22207  table (e.g.
22208  for the autovector feature of the Cypress EZ-USB FX2).
22209  More elegantly this can be achieved by obmitting the optional interrupt
22210  number after the interrupt keyword, see section 
22211 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22212
22213 \end_inset
22214
22215 \InsetSpace ~
22216 about interrupts.
22217 \end_layout
22218
22219 \begin_layout Itemize
22220
22221 \series bold
22222 nojtbound
22223 \series default
22224
22225 \begin_inset LatexCommand \index{\#pragma nojtbound}
22226
22227 \end_inset
22228
22229  - will not generate code for boundary value checking, when switch statements
22230  are turned into jump-tables (dangerous).
22231  For more details see section 
22232 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22233
22234 \end_inset
22235
22236 .
22237 \end_layout
22238
22239 \begin_layout Itemize
22240
22241 \series bold
22242 noloopreverse
22243 \series default
22244
22245 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22246
22247 \end_inset
22248
22249  - Will not do loop reversal optimization
22250 \end_layout
22251
22252 \begin_layout Itemize
22253
22254 \series bold
22255 nooverlay
22256 \series default
22257
22258 \begin_inset LatexCommand \index{\#pragma nooverlay}
22259
22260 \end_inset
22261
22262  - the compiler will not overlay the parameters and local variables of a
22263  function.
22264 \end_layout
22265
22266 \begin_layout Itemize
22267
22268 \series bold
22269 stackauto
22270 \series default
22271
22272 \begin_inset LatexCommand \index{\#pragma stackauto}
22273
22274 \end_inset
22275
22276 - See option -
22277 \begin_inset ERT
22278 status collapsed
22279
22280 \begin_layout Standard
22281
22282
22283 \backslash
22284 /
22285 \end_layout
22286
22287 \end_inset
22288
22289 -stack-auto
22290 \begin_inset LatexCommand \index{-\/-stack-auto}
22291
22292 \end_inset
22293
22294  and section 
22295 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22296
22297 \end_inset
22298
22299  Parameters and Local Variables.
22300 \end_layout
22301
22302 \begin_layout Itemize
22303
22304 \series bold
22305 opt_code_speed
22306 \series default
22307  
22308 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22309
22310 \end_inset
22311
22312 - The compiler will optimize code generation towards fast code, possibly
22313  at the expense of code size.
22314  Currently this has little effect.
22315 \end_layout
22316
22317 \begin_layout Itemize
22318
22319 \series bold
22320 opt_code_size
22321 \series default
22322  
22323 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22324
22325 \end_inset
22326
22327 - The compiler will optimize code generation towards compact code, possibly
22328  at the expense of code speed.
22329  Currently this has little effect.
22330 \end_layout
22331
22332 \begin_layout Itemize
22333
22334 \series bold
22335 opt_code_balanced
22336 \series default
22337  
22338 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22339
22340 \end_inset
22341
22342 - The compiler will attempt to generate code that is both compact and fast,
22343  as long as meeting one goal is not a detriment to the other (this is the
22344  default).
22345  
22346 \end_layout
22347
22348 \begin_layout Itemize
22349
22350 \series bold
22351 std_sdcc89
22352 \series default
22353  
22354 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22355
22356 \end_inset
22357
22358 - Generally follow the C89 standard, but allow SDCC features that conflict
22359  with the standard (default).
22360 \end_layout
22361
22362 \begin_layout Itemize
22363
22364 \series bold
22365 std_c89
22366 \series default
22367  
22368 \begin_inset LatexCommand \index{\#pragma std\_c89}
22369
22370 \end_inset
22371
22372 - Follow the C89 standard and disable SDCC features that conflict with the
22373  standard.
22374 \end_layout
22375
22376 \begin_layout Itemize
22377
22378 \series bold
22379 std_sdcc99
22380 \series default
22381  
22382 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22383
22384 \end_inset
22385
22386 - Generally follow the C99 standard, but allow SDCC features that conflict
22387  with the standard (incomplete support).
22388 \end_layout
22389
22390 \begin_layout Itemize
22391
22392 \series bold
22393 std_c99
22394 \series default
22395  
22396 \begin_inset LatexCommand \index{\#pragma std\_c99}
22397
22398 \end_inset
22399
22400 - Follow the C99 standard and disable SDCC features that conflict with the
22401  standard (incomplete support).
22402 \end_layout
22403
22404 \begin_layout Itemize
22405
22406 \series bold
22407 codeseg
22408 \series default
22409  <name>
22410 \begin_inset LatexCommand \index{\#pragma codeseg}
22411
22412 \end_inset
22413
22414 - Use this name (max.
22415  8 characters) for the code segment.
22416  See option -
22417 \begin_inset ERT
22418 status collapsed
22419
22420 \begin_layout Standard
22421
22422
22423 \backslash
22424 /
22425 \end_layout
22426
22427 \end_inset
22428
22429 -codeseg.
22430 \end_layout
22431
22432 \begin_layout Itemize
22433
22434 \series bold
22435 constseg
22436 \series default
22437  <name>
22438 \begin_inset LatexCommand \index{\#pragma constseg}
22439
22440 \end_inset
22441
22442 - Use this name (max.
22443  8 characters) for the const segment.
22444  See option -
22445 \begin_inset ERT
22446 status collapsed
22447
22448 \begin_layout Standard
22449
22450
22451 \backslash
22452 /
22453 \end_layout
22454
22455 \end_inset
22456
22457 -constseg.
22458 \end_layout
22459
22460 \begin_layout Standard
22461 The preprocessor SDCPP
22462 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22463
22464 \end_inset
22465
22466  supports the following #pragma directives:
22467 \end_layout
22468
22469 \begin_layout Itemize
22470
22471 \series bold
22472 pedantic_parse_number
22473 \series default
22474
22475 \begin_inset LatexCommand \index{pedantic}
22476
22477 \end_inset
22478
22479
22480 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22481
22482 \end_inset
22483
22484  (+ | -) 
22485 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22486
22487 \end_inset
22488
22489 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22490  properly and the macro LO_B(3) gets expanded.
22491  Default is off.
22492  See also the -
22493 \begin_inset ERT
22494 status collapsed
22495
22496 \begin_layout Standard
22497
22498
22499 \backslash
22500 /
22501 \end_layout
22502
22503 \end_inset
22504
22505 -pedantic-parse-number command line option 
22506 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22507
22508 \end_inset
22509
22510 .
22511  
22512 \newline
22513 Below is an example on how to use this pragma.
22514
22515 \emph on
22516  Note: this functionality is not in conformance with standard!
22517 \end_layout
22518
22519 \begin_layout Verse
22520
22521 \family typewriter
22522 #pragma pedantic_parse_number +
22523 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22524
22525 \end_inset
22526
22527
22528 \newline
22529
22530 \newline
22531 #define LO_B(x) ((x) & 0xff)
22532 \newline
22533
22534 \newline
22535 unsigned char foo(void)
22536 \newline
22537 {
22538 \newline
22539 \InsetSpace ~
22540 \InsetSpace ~
22541 \InsetSpace ~
22542 unsigned char c=0xfe-LO_B(3)
22543 ;
22544 \newline
22545
22546 \newline
22547 \InsetSpace ~
22548 \InsetSpace ~
22549 \InsetSpace ~
22550 return c;
22551 \newline
22552 }
22553 \newline
22554
22555 \end_layout
22556
22557 \begin_layout Itemize
22558
22559 \series bold
22560 preproc_asm
22561 \series default
22562
22563 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22564
22565 \end_inset
22566
22567  (+ | -) - switch _asm _endasm block preprocessing on / off.
22568  Default is on.
22569  You use this prama to define multilines of assembly code.
22570  This will prevent the preprocessor from changing the formating required
22571  by assembly code.
22572  Below is an example on how to use this pragma.
22573 \end_layout
22574
22575 \begin_layout Verse
22576
22577 \family typewriter
22578 #pragma preproc_asm -
22579 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22580
22581 \end_inset
22582
22583
22584 \newline
22585 #define MYDELAY _asm
22586 \newline
22587 \InsetSpace ~
22588 \InsetSpace ~
22589 \InsetSpace ~
22590 nop ;my assembly comment...
22591 \newline
22592 \InsetSpace ~
22593 \InsetSpace ~
22594 \InsetSpace ~
22595 nop
22596 \newline
22597 \InsetSpace ~
22598 \InsetSpace ~
22599 \InsetSpace ~
22600 nop
22601 \newline
22602 _endasm
22603 \newline
22604 #pragma preproc_asm
22605  +
22606 \newline
22607
22608 \newline
22609 void foo (void) 
22610 \newline
22611
22612 \newline
22613 \InsetSpace ~
22614 \InsetSpace ~
22615 \InsetSpace ~
22616  ...
22617  
22618 \newline
22619 \InsetSpace ~
22620 \InsetSpace ~
22621 \InsetSpace ~
22622  MYDELAY;
22623 \newline
22624 \InsetSpace ~
22625 \InsetSpace ~
22626 \InsetSpace ~
22627  ...
22628  
22629 \newline
22630
22631 \newline
22632
22633 \end_layout
22634
22635 \begin_layout Itemize
22636
22637 \series bold
22638 sdcc_hash
22639 \series default
22640
22641 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22642
22643 \end_inset
22644
22645  (+ | -) - Allow "naked" hash in macro definition, for example:
22646 \newline
22647
22648 \family typewriter
22649 #define DIR_LO(x) #(x & 0xff)
22650 \family default
22651
22652 \newline
22653 Default is off.
22654  Below is an example on how to use this pragma.
22655 \end_layout
22656
22657 \begin_layout Verse
22658
22659 \family typewriter
22660 #pragma preproc_asm +
22661 \newline
22662 #pragma sdcc_hash +
22663 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22664
22665 \end_inset
22666
22667
22668 \newline
22669
22670 \newline
22671 #define ROMCALL(x) 
22672 \backslash
22673
22674 \newline
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 mov R6_B3, #(x & 0xff) 
22679 \backslash
22680
22681 \newline
22682 \InsetSpace ~
22683 \InsetSpace ~
22684 \InsetSpace ~
22685 mov R7_B3, #((x >> 8) & 0xff) 
22686 \backslash
22687
22688 \newline
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 lcall __romcall
22693 \newline
22694
22695 \newline
22696 ...
22697 \newline
22698 _asm
22699 \newline
22700 ROMCALL(72)
22701 \newline
22702 _endasm;
22703 \newline
22704 ...
22705 \newline
22706
22707 \end_layout
22708
22709 \begin_layout Standard
22710 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22711 ons which might cause the compiler to generate extra stack and/or data space
22712  to store compiler generated temporary variables.
22713  This usually happens in large functions.
22714  Pragma directives should be used as shown in the following example, they
22715  are used to control options and optimizations for a given function.
22716  
22717 \end_layout
22718
22719 \begin_layout Verse
22720
22721 \family typewriter
22722 #pragma save
22723 \begin_inset LatexCommand \index{\#pragma save}
22724
22725 \end_inset
22726
22727  \InsetSpace ~
22728 \InsetSpace ~
22729 \InsetSpace ~
22730 \InsetSpace ~
22731 \InsetSpace ~
22732 \InsetSpace ~
22733 \InsetSpace ~
22734 /* save the current settings */ 
22735 \newline
22736 #pragma nogcse
22737 \begin_inset LatexCommand \index{\#pragma nogcse}
22738
22739 \end_inset
22740
22741  \InsetSpace ~
22742 \InsetSpace ~
22743 \InsetSpace ~
22744 \InsetSpace ~
22745 \InsetSpace ~
22746 /* turnoff global subexpression elimination */ 
22747 \newline
22748 #pragma noinduction
22749 \begin_inset LatexCommand \index{\#pragma noinduction}
22750
22751 \end_inset
22752
22753  /* turn off induction optimizations */ 
22754 \newline
22755 int foo () 
22756 \newline
22757
22758 \newline
22759 \InsetSpace ~
22760  \InsetSpace ~
22761  ...
22762  
22763 \newline
22764 \InsetSpace ~
22765  \InsetSpace ~
22766  /* large code */ 
22767 \newline
22768 \InsetSpace ~
22769  \InsetSpace ~
22770  ...
22771  
22772 \newline
22773
22774 \newline
22775 #pragma restore
22776 \begin_inset LatexCommand \index{\#pragma restore}
22777
22778 \end_inset
22779
22780  /* turn the optimizations back on */
22781 \end_layout
22782
22783 \begin_layout Standard
22784 The compiler will generate a warning message when extra space is allocated.
22785  It is strongly recommended that the save and restore pragmas be used when
22786  changing options for a function.
22787 \newline
22788
22789 \newline
22790
22791 \newline
22792
22793 \end_layout
22794
22795 \begin_layout Section
22796 Defines Created by the Compiler
22797 \end_layout
22798
22799 \begin_layout Standard
22800 The compiler creates the following #defines
22801 \begin_inset LatexCommand \index{\#defines}
22802
22803 \end_inset
22804
22805
22806 \begin_inset LatexCommand \index{Defines created by the compiler}
22807
22808 \end_inset
22809
22810 :
22811 \newline
22812
22813 \end_layout
22814
22815 \begin_layout Standard
22816 \begin_inset Tabular
22817 <lyxtabular version="3" rows="15" columns="2">
22818 <features>
22819 <column alignment="left" valignment="top" leftline="true" width="3in">
22820 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22821 <row topline="true" bottomline="true">
22822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22823 \begin_inset Text
22824
22825 \begin_layout Standard
22826
22827 \series bold
22828 #define
22829 \end_layout
22830
22831 \end_inset
22832 </cell>
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22834 \begin_inset Text
22835
22836 \begin_layout Standard
22837
22838 \series bold
22839 Description
22840 \end_layout
22841
22842 \end_inset
22843 </cell>
22844 </row>
22845 <row topline="true">
22846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22847 \begin_inset Text
22848
22849 \begin_layout Standard
22850 SDCC
22851 \begin_inset LatexCommand \index{SDCC}
22852
22853 \end_inset
22854
22855  
22856 \end_layout
22857
22858 \end_inset
22859 </cell>
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22861 \begin_inset Text
22862
22863 \begin_layout Standard
22864 Always defined.
22865  Since version 2.5.6 the version number as an int (ex.
22866  256)
22867 \end_layout
22868
22869 \end_inset
22870 </cell>
22871 </row>
22872 <row topline="true">
22873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22874 \begin_inset Text
22875
22876 \begin_layout Standard
22877 SDCC_mcs51
22878 \begin_inset LatexCommand \index{SDCC\_mcs51}
22879
22880 \end_inset
22881
22882  or SDCC_ds390
22883 \begin_inset LatexCommand \index{SDCC\_ds390}
22884
22885 \end_inset
22886
22887  or SDCC_z80
22888 \begin_inset LatexCommand \index{SDCC\_z80}
22889
22890 \end_inset
22891
22892 , etc.
22893 \end_layout
22894
22895 \end_inset
22896 </cell>
22897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22898 \begin_inset Text
22899
22900 \begin_layout Standard
22901 depending on the model used (e.g.: -mds390)
22902 \end_layout
22903
22904 \end_inset
22905 </cell>
22906 </row>
22907 <row topline="true">
22908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22909 \begin_inset Text
22910
22911 \begin_layout Standard
22912 __mcs51
22913 \begin_inset LatexCommand \index{\_\_mcs51}
22914
22915 \end_inset
22916
22917 , __ds390
22918 \begin_inset LatexCommand \index{\_\_ds390}
22919
22920 \end_inset
22921
22922 , __hc08
22923 \begin_inset LatexCommand \index{\_\_hc08}
22924
22925 \end_inset
22926
22927 , __z80
22928 \begin_inset LatexCommand \index{\_\_z80}
22929
22930 \end_inset
22931
22932 , etc
22933 \end_layout
22934
22935 \end_inset
22936 </cell>
22937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22938 \begin_inset Text
22939
22940 \begin_layout Standard
22941 depending on the model used (e.g.
22942  -mz80)
22943 \end_layout
22944
22945 \end_inset
22946 </cell>
22947 </row>
22948 <row topline="true">
22949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22950 \begin_inset Text
22951
22952 \begin_layout Standard
22953 SDCC_STACK_AUTO
22954 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22955
22956 \end_inset
22957
22958
22959 \end_layout
22960
22961 \end_inset
22962 </cell>
22963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22964 \begin_inset Text
22965
22966 \begin_layout Standard
22967 when 
22968 \emph on
22969 -
22970 \begin_inset ERT
22971 status collapsed
22972
22973 \begin_layout Standard
22974
22975
22976 \backslash
22977 /
22978 \end_layout
22979
22980 \end_inset
22981
22982 -stack-auto
22983 \emph default
22984  option is used
22985 \end_layout
22986
22987 \end_inset
22988 </cell>
22989 </row>
22990 <row topline="true">
22991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22992 \begin_inset Text
22993
22994 \begin_layout Standard
22995 SDCC_MODEL_SMALL
22996 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22997
22998 \end_inset
22999
23000
23001 \end_layout
23002
23003 \end_inset
23004 </cell>
23005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23006 \begin_inset Text
23007
23008 \begin_layout Standard
23009 when 
23010 \emph on
23011 -
23012 \begin_inset ERT
23013 status collapsed
23014
23015 \begin_layout Standard
23016
23017
23018 \backslash
23019 /
23020 \end_layout
23021
23022 \end_inset
23023
23024 -model-small
23025 \emph default
23026  is used
23027 \end_layout
23028
23029 \end_inset
23030 </cell>
23031 </row>
23032 <row topline="true">
23033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23034 \begin_inset Text
23035
23036 \begin_layout Standard
23037 SDCC_MODEL_MEDIUM
23038 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
23039
23040 \end_inset
23041
23042
23043 \end_layout
23044
23045 \end_inset
23046 </cell>
23047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23048 \begin_inset Text
23049
23050 \begin_layout Standard
23051 when 
23052 \emph on
23053 -
23054 \begin_inset ERT
23055 status collapsed
23056
23057 \begin_layout Standard
23058
23059
23060 \backslash
23061 /
23062 \end_layout
23063
23064 \end_inset
23065
23066 -model-medium
23067 \emph default
23068  is used
23069 \end_layout
23070
23071 \end_inset
23072 </cell>
23073 </row>
23074 <row topline="true">
23075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23076 \begin_inset Text
23077
23078 \begin_layout Standard
23079 SDCC_MODEL_LARGE
23080 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23081
23082 \end_inset
23083
23084
23085 \end_layout
23086
23087 \end_inset
23088 </cell>
23089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23090 \begin_inset Text
23091
23092 \begin_layout Standard
23093 when 
23094 \emph on
23095 -
23096 \begin_inset ERT
23097 status collapsed
23098
23099 \begin_layout Standard
23100
23101
23102 \backslash
23103 /
23104 \end_layout
23105
23106 \end_inset
23107
23108 -model-large
23109 \emph default
23110  is used
23111 \end_layout
23112
23113 \end_inset
23114 </cell>
23115 </row>
23116 <row topline="true">
23117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23118 \begin_inset Text
23119
23120 \begin_layout Standard
23121 SDCC_USE_XSTACK
23122 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23123
23124 \end_inset
23125
23126
23127 \end_layout
23128
23129 \end_inset
23130 </cell>
23131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23132 \begin_inset Text
23133
23134 \begin_layout Standard
23135 when 
23136 \emph on
23137 -
23138 \begin_inset ERT
23139 status collapsed
23140
23141 \begin_layout Standard
23142
23143
23144 \backslash
23145 /
23146 \end_layout
23147
23148 \end_inset
23149
23150 -xstack
23151 \emph default
23152  option is used
23153 \end_layout
23154
23155 \end_inset
23156 </cell>
23157 </row>
23158 <row topline="true">
23159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23160 \begin_inset Text
23161
23162 \begin_layout Standard
23163 SDCC_STACK_TENBIT
23164 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23165
23166 \end_inset
23167
23168  
23169 \end_layout
23170
23171 \end_inset
23172 </cell>
23173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23174 \begin_inset Text
23175
23176 \begin_layout Standard
23177 when 
23178 \emph on
23179 -mds390
23180 \emph default
23181  is used
23182 \end_layout
23183
23184 \end_inset
23185 </cell>
23186 </row>
23187 <row topline="true">
23188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23189 \begin_inset Text
23190
23191 \begin_layout Standard
23192 SDCC_MODEL_FLAT24
23193 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23194
23195 \end_inset
23196
23197
23198 \end_layout
23199
23200 \end_inset
23201 </cell>
23202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23203 \begin_inset Text
23204
23205 \begin_layout Standard
23206 when 
23207 \emph on
23208 -mds390
23209 \emph default
23210  is used
23211 \end_layout
23212
23213 \end_inset
23214 </cell>
23215 </row>
23216 <row topline="true">
23217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23218 \begin_inset Text
23219
23220 \begin_layout Standard
23221 SDCC_REVISION
23222 \begin_inset LatexCommand \index{SDCC\_REVISION}
23223
23224 \end_inset
23225
23226
23227 \end_layout
23228
23229 \end_inset
23230 </cell>
23231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23232 \begin_inset Text
23233
23234 \begin_layout Standard
23235 Always defined.
23236  SDCC svn revision number
23237 \end_layout
23238
23239 \end_inset
23240 </cell>
23241 </row>
23242 <row topline="true">
23243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23244 \begin_inset Text
23245
23246 \begin_layout Standard
23247 SDCC_PARMS_IN_BANK1
23248 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23249
23250 \end_inset
23251
23252
23253 \end_layout
23254
23255 \end_inset
23256 </cell>
23257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23258 \begin_inset Text
23259
23260 \begin_layout Standard
23261 when 
23262 \emph on
23263 -
23264 \begin_inset ERT
23265 status collapsed
23266
23267 \begin_layout Standard
23268
23269
23270 \backslash
23271 /
23272 \end_layout
23273
23274 \end_inset
23275
23276 -parms-in-bank1
23277 \emph default
23278  is used
23279 \end_layout
23280
23281 \end_inset
23282 </cell>
23283 </row>
23284 <row topline="true">
23285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23286 \begin_inset Text
23287
23288 \begin_layout Standard
23289 SDCC_FLOAT_REENT
23290 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23291
23292 \end_inset
23293
23294
23295 \end_layout
23296
23297 \end_inset
23298 </cell>
23299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23300 \begin_inset Text
23301
23302 \begin_layout Standard
23303 when 
23304 \emph on
23305 -
23306 \begin_inset ERT
23307 status collapsed
23308
23309 \begin_layout Standard
23310
23311
23312 \backslash
23313 /
23314 \end_layout
23315
23316 \end_inset
23317
23318 -float-reent
23319 \emph default
23320  is used
23321 \end_layout
23322
23323 \end_inset
23324 </cell>
23325 </row>
23326 <row topline="true" bottomline="true">
23327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23328 \begin_inset Text
23329
23330 \begin_layout Standard
23331 SDCC_INT_LONG_REENT
23332 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23333
23334 \end_inset
23335
23336
23337 \end_layout
23338
23339 \end_inset
23340 </cell>
23341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23342 \begin_inset Text
23343
23344 \begin_layout Standard
23345 when 
23346 \emph on
23347 -
23348 \begin_inset ERT
23349 status collapsed
23350
23351 \begin_layout Standard
23352
23353
23354 \backslash
23355 /
23356 \end_layout
23357
23358 \end_inset
23359
23360 -int-long-reent
23361 \emph default
23362  is used
23363 \end_layout
23364
23365 \end_inset
23366 </cell>
23367 </row>
23368 </lyxtabular>
23369
23370 \end_inset
23371
23372
23373 \end_layout
23374
23375 \begin_layout Chapter
23376 Notes on supported Processors
23377 \end_layout
23378
23379 \begin_layout Section
23380 MCS51 variants
23381 \begin_inset LatexCommand \label{sub:MCS51-variants}
23382
23383 \end_inset
23384
23385
23386 \begin_inset LatexCommand \index{MCS51 variants}
23387
23388 \end_inset
23389
23390
23391 \end_layout
23392
23393 \begin_layout Standard
23394 MCS51 processors are available from many vendors and come in many different
23395  flavours.
23396  While they might differ considerably in respect to Special Function Registers
23397  the core MCS51 is usually not modified or is kept compatible.
23398  
23399 \end_layout
23400
23401 \begin_layout Subsection
23402 pdata access by SFR 
23403 \end_layout
23404
23405 \begin_layout Standard
23406 With the upcome of devices with internal xdata and flash memory devices
23407  using port P2
23408 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23409
23410 \end_inset
23411
23412  as dedicated I/O port is becoming more popular.
23413  Switching the high byte for pdata
23414 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23415
23416 \end_inset
23417
23418  access which was formerly done by port P2 is then achieved by a Special
23419  Function Register
23420 \begin_inset LatexCommand \index{sfr}
23421
23422 \end_inset
23423
23424 .
23425  In well-established MCS51 tradition the address of this 
23426 \emph on
23427 sfr
23428 \emph default
23429  is where the chip designers decided to put it.
23430  Needless to say that they didn't agree on a common name either.
23431  So that the startup code can correctly initialize xdata variables, you
23432  should define an sfr with the name _XPAGE
23433 \family typewriter
23434
23435 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23436
23437 \end_inset
23438
23439
23440 \family default
23441  at the appropriate location if the default, port P2, is not used for this.
23442  Some examples are:
23443 \end_layout
23444
23445 \begin_layout Verse
23446
23447 \family typewriter
23448 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23449  MPAGE */
23450 \end_layout
23451
23452 \begin_layout Verse
23453
23454 \family typewriter
23455 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23456  a.k.a.
23457  MPAGE */
23458 \end_layout
23459
23460 \begin_layout Verse
23461
23462 \family typewriter
23463 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23464  XPAGE */
23465 \end_layout
23466
23467 \begin_layout Verse
23468
23469 \family typewriter
23470 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23471  EMI0CN */
23472 \end_layout
23473
23474 \begin_layout Verse
23475
23476 \family typewriter
23477 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23478  EMI0CN */
23479 \end_layout
23480
23481 \begin_layout Standard
23482 For more exotic implementations further customizations may be needed.
23483  See section 
23484 \begin_inset LatexCommand \ref{sub:Startup-Code}
23485
23486 \end_inset
23487
23488  for other possibilities.
23489 \end_layout
23490
23491 \begin_layout Subsection
23492 Other Features available by SFR
23493 \end_layout
23494
23495 \begin_layout Standard
23496 Some MCS51 variants offer features like Double DPTR
23497 \begin_inset LatexCommand \index{DPTR}
23498
23499 \end_inset
23500
23501 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23502  These are currently not used for the MCS51 port.
23503  If you absolutely need them you can fall back to inline assembly or submit
23504  a patch to SDCC.
23505 \end_layout
23506
23507 \begin_layout Subsection
23508 Bankswitching
23509 \end_layout
23510
23511 \begin_layout Standard
23512 Bankswitching
23513 \begin_inset LatexCommand \index{Bankswitching}
23514
23515 \end_inset
23516
23517  (a.k.a.
23518  code banking
23519 \begin_inset LatexCommand \index{code banking}
23520
23521 \end_inset
23522
23523 ) is a technique to increase the code space above the 64k limit of the 8051.
23524 \end_layout
23525
23526 \begin_layout Subsubsection
23527 Hardware
23528 \end_layout
23529
23530 \begin_layout Standard
23531 \begin_inset Tabular
23532 <lyxtabular version="3" rows="3" columns="4">
23533 <features>
23534 <column alignment="center" valignment="top" width="0">
23535 <column alignment="center" valignment="top" leftline="true" width="0">
23536 <column alignment="center" valignment="top" leftline="true" width="0">
23537 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23538 <row topline="true" bottomline="true">
23539 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23540 \begin_inset Text
23541
23542 \begin_layout Standard
23543 8000-FFFF
23544 \end_layout
23545
23546 \end_inset
23547 </cell>
23548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23549 \begin_inset Text
23550
23551 \begin_layout Standard
23552 bank1
23553 \end_layout
23554
23555 \end_inset
23556 </cell>
23557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23558 \begin_inset Text
23559
23560 \begin_layout Standard
23561 bank2
23562 \end_layout
23563
23564 \end_inset
23565 </cell>
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23567 \begin_inset Text
23568
23569 \begin_layout Standard
23570 bank3
23571 \end_layout
23572
23573 \end_inset
23574 </cell>
23575 </row>
23576 <row topline="true" bottomline="true">
23577 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23578 \begin_inset Text
23579
23580 \begin_layout Standard
23581 0000-7FFF
23582 \end_layout
23583
23584 \end_inset
23585 </cell>
23586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23587 \begin_inset Text
23588
23589 \begin_layout Standard
23590 common
23591 \end_layout
23592
23593 \end_inset
23594 </cell>
23595 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23596 \begin_inset Text
23597
23598 \begin_layout Standard
23599
23600 \end_layout
23601
23602 \end_inset
23603 </cell>
23604 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23605 \begin_inset Text
23606
23607 \begin_layout Standard
23608
23609 \end_layout
23610
23611 \end_inset
23612 </cell>
23613 </row>
23614 <row>
23615 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23616 \begin_inset Text
23617
23618 \begin_layout Standard
23619 SiLabs C8051F120 example
23620 \end_layout
23621
23622 \end_inset
23623 </cell>
23624 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23625 \begin_inset Text
23626
23627 \begin_layout Standard
23628
23629 \end_layout
23630
23631 \end_inset
23632 </cell>
23633 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23634 \begin_inset Text
23635
23636 \begin_layout Standard
23637
23638 \end_layout
23639
23640 \end_inset
23641 </cell>
23642 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23643 \begin_inset Text
23644
23645 \begin_layout Standard
23646
23647 \end_layout
23648
23649 \end_inset
23650 </cell>
23651 </row>
23652 </lyxtabular>
23653
23654 \end_inset
23655
23656
23657 \newline
23658
23659 \newline
23660 Usually the hardware uses some sfr (an output port or an internal sfr) to
23661  select a bank and put it in the banked area of the memory map.
23662  The selected bank usually becomes active immediately upon assignment to
23663  this sfr and when running inside a bank it will switch out this code it
23664  is currently running.
23665  Therefor you cannot jump or call directly from one bank to another and
23666  need to use a so-called trampoline in the common area.
23667  For SDCC an example trampoline is in crtbank.asm and you may need to change
23668  it to your 8051 derivative or schematic.
23669  The presented code is written for the C8051F120.
23670 \newline
23671
23672 \newline
23673 When calling a banked function
23674  SDCC will put the LSB of the functions address in register R0, the MSB
23675  in R1 and the bank in R2 and then call this trampoline 
23676 \emph on
23677 __sdcc_banked_call
23678 \emph default
23679 .
23680  The current selected bank is saved on the stack, the new bank is selected
23681  and an indirect jump is made.
23682  When the banked function returns it jumps to 
23683 \emph on
23684 __sdcc_banked_ret
23685 \emph default
23686  which restores the previous bank and returns to the caller.
23687 \end_layout
23688
23689 \begin_layout Subsubsection
23690 Software
23691 \end_layout
23692
23693 \begin_layout Standard
23694 When writing banked software using SDCC you need to use some special keywords
23695  and options.
23696  You also need to take over a bit of work from the linker.
23697 \newline
23698
23699 \newline
23700 To create a function
23701  that can be called from another bank it requires the keyword 
23702 \emph on
23703 banked
23704 \emph default
23705
23706 \begin_inset LatexCommand \index{banked}
23707
23708 \end_inset
23709
23710 .
23711  The caller must see this in the prototype of the callee and the callee
23712  needs it for a proper return.
23713  Called functions within the same bank as the caller do not need the 
23714 \emph on
23715 banked
23716 \emph default
23717  keyword nor do functions in the common area.
23718  Beware: SDCC does not know or check if functions are in the same bank.
23719  This is your responsibility!
23720 \newline
23721
23722 \newline
23723 Normally all functions you write end up in
23724  the segment CSEG.
23725  If you want a function explicitly to reside in the common area put it in
23726  segment HOME.
23727  This applies for instance to interrupt service routines as they should
23728  not be banked.
23729 \end_layout
23730
23731 \begin_layout Standard
23732 Functions that need to be in a switched bank must be put in a named segment.
23733  The name can be mostly anything upto eight characters (e.g.
23734  BANK1).
23735  To do this you either use -
23736 \begin_inset ERT
23737 status collapsed
23738
23739 \begin_layout Standard
23740
23741
23742 \backslash
23743 /
23744 \end_layout
23745
23746 \end_inset
23747
23748 -codeseg BANK1 (See 
23749 \begin_inset LatexCommand \ref{lyx:-codeseg}
23750
23751 \end_inset
23752
23753 ) on the command line when compiling or #pragma codeseg BANK1 (See 
23754 \begin_inset LatexCommand \ref{sec:Pragmas}
23755
23756 \end_inset
23757
23758 ) at the top of the C source file.
23759  The segment name always applies to the whole source file and generated
23760  object so functions for different banks need to be defined in different
23761  source files.
23762 \newline
23763
23764 \newline
23765 When linking your objects you need to tell the linker where
23766  to put your segments.
23767  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23768 00 (See 
23769 \begin_inset LatexCommand \ref{lyx:-Wl option}
23770
23771 \end_inset
23772
23773 ).
23774  This sets the virtual start address of this segment.
23775  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23776  The linker will not check for overflows, again this is your responsibility.
23777 \end_layout
23778
23779 \begin_layout Standard
23780 \begin_inset VSpace bigskip
23781 \end_inset
23782
23783
23784 \end_layout
23785
23786 \begin_layout Section
23787 DS400 port
23788 \end_layout
23789
23790 \begin_layout Standard
23791 The DS80C400
23792 \begin_inset LatexCommand \index{DS80C400}
23793
23794 \end_inset
23795
23796
23797 \begin_inset LatexCommand \index{DS400}
23798
23799 \end_inset
23800
23801  microcontroller has a rich set of peripherals.
23802  In its built-in ROM library it includes functions to access some of the
23803  features, among them is a TCP stack with IP4 and IP6 support.
23804  Library headers (currently in beta status) and other files are provided
23805  at 
23806 \size footnotesize
23807
23808 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23809
23810 \end_inset
23811
23812 .
23813  
23814 \begin_inset VSpace bigskip
23815 \end_inset
23816
23817
23818 \end_layout
23819
23820 \begin_layout Section
23821 The Z80 and gbz80 port
23822 \end_layout
23823
23824 \begin_layout Standard
23825 SDCC can target both the Zilog Z80
23826 \begin_inset LatexCommand \index{Z80}
23827
23828 \end_inset
23829
23830  and the Nintendo Gameboy's Z80-like gbz80
23831 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23832
23833 \end_inset
23834
23835 .
23836  The Z80 port is passed through the same 
23837 \emph on
23838 regressions tests
23839 \begin_inset LatexCommand \index{Regression test}
23840
23841 \end_inset
23842
23843
23844 \emph default
23845  (see section 
23846 \begin_inset LatexCommand \ref{sec:Quality-control}
23847
23848 \end_inset
23849
23850 ) as the MCS51 and DS390 ports, so floating point support, support for long
23851  variables and bitfield support is fine.
23852  See mailing lists and forums about interrupt routines.
23853 \end_layout
23854
23855 \begin_layout Standard
23856 As always, the code is the authoritative reference - see z80/ralloc.c and
23857  z80/gen.c.
23858  The stack
23859 \begin_inset LatexCommand \index{Z80!stack}
23860
23861 \end_inset
23862
23863  frame is similar to that generated by the IAR Z80 compiler.
23864  IX is used as the base pointer, HL and IY are used as a temporary registers,
23865  and BC and DE are available for holding variables.
23866  Return values
23867 \begin_inset LatexCommand \index{Z80!return value}
23868
23869 \end_inset
23870
23871  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23872  bytes).
23873  The gbz80 port use the same set of registers for the return values, but
23874  in a different order of significance: E (one byte), DE (two bytes), or
23875  HLDE (four bytes).
23876 \begin_inset VSpace bigskip
23877 \end_inset
23878
23879
23880 \end_layout
23881
23882 \begin_layout Section
23883 The HC08 port
23884 \end_layout
23885
23886 \begin_layout Standard
23887 The port to the Freescale/Motorola HC08
23888 \begin_inset LatexCommand \index{HC08}
23889
23890 \end_inset
23891
23892  family has been added in October 2003, and is still undergoing some basic
23893  development.
23894  The code generator is complete, but the register allocation is still quite
23895  unoptimized.
23896  Some of the SDCC's standard C library functions have embedded non-HC08
23897  inline assembly and so are not yet usable.
23898 \end_layout
23899
23900 \begin_layout Standard
23901 The HC08 port passes the regression test suite (see section 
23902 \begin_inset LatexCommand \ref{sec:Quality-control}
23903
23904 \end_inset
23905
23906 ).
23907 \begin_inset VSpace bigskip
23908 \end_inset
23909
23910
23911 \end_layout
23912
23913 \begin_layout Section
23914 The PIC14
23915 \begin_inset LatexCommand \index{PIC14}
23916
23917 \end_inset
23918
23919  port
23920 \end_layout
23921
23922 \begin_layout Standard
23923 The PIC14 port adds support for Microchip
23924 \begin_inset LatexCommand \index{Microchip}
23925
23926 \end_inset
23927
23928
23929 \begin_inset Formula $^{\text{TM}}$
23930 \end_inset
23931
23932  PIC
23933 \begin_inset LatexCommand \index{PIC14}
23934
23935 \end_inset
23936
23937
23938 \begin_inset Formula $^{\text{TM}}$
23939 \end_inset
23940
23941  MCUs with 14 bit wide instructions.
23942  This port is not yet mature and still lacks many features.
23943  However, it can work for simple code.
23944 \end_layout
23945
23946 \begin_layout Standard
23947 \noindent
23948 Currently supported devices include:
23949 \end_layout
23950
23951 \begin_layout Standard
23952 12F: 629, 635, 675, 683
23953 \end_layout
23954
23955 \begin_layout Standard
23956 16C: 432, 433
23957 \end_layout
23958
23959 \begin_layout Standard
23960 16C: 554, 557, 558
23961 \end_layout
23962
23963 \begin_layout Standard
23964 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23965 \end_layout
23966
23967 \begin_layout Standard
23968 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23969  781, 782
23970 \end_layout
23971
23972 \begin_layout Standard
23973 16C: 925, 926
23974 \end_layout
23975
23976 \begin_layout Standard
23977 16CR: 620a, 73, 74, 76, 77
23978 \end_layout
23979
23980 \begin_layout Standard
23981 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23982  687, 688, 689, 690
23983 \end_layout
23984
23985 \begin_layout Standard
23986 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23987 \end_layout
23988
23989 \begin_layout Standard
23990 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23991  877, 877a, 88, 886, 887
23992 \end_layout
23993
23994 \begin_layout Standard
23995 16F: 913, 914, 916, 917, 946
23996 \end_layout
23997
23998 \begin_layout Standard
23999 26HV: 626, 785
24000 \end_layout
24001
24002 \begin_layout Standard
24003 \noindent
24004 An up-to-date list of currently supported devices can be obtained via 
24005 \family typewriter
24006 sdcc -mpic14 -phelp foo.c
24007 \family default
24008  (foo.c must exist...).
24009 \end_layout
24010
24011 \begin_layout Subsection
24012 PIC Code Pages
24013 \begin_inset LatexCommand \index{code page (pic14)}
24014
24015 \end_inset
24016
24017  and Memory Banks
24018 \begin_inset LatexCommand \index{Memory bank (pic14)}
24019
24020 \end_inset
24021
24022
24023 \end_layout
24024
24025 \begin_layout Standard
24026 The linker organizes allocation for the code page and RAM banks.
24027  It does not have intimate knowledge of the code flow.
24028  It will put all the code section of a single .asm file into a single code
24029  page.
24030  In order to make use of multiple code pages, separate asm files must be
24031  used.
24032  The compiler assigns all 
24033 \emph on
24034 static
24035 \emph default
24036  functions of a single .c file into the same code page.
24037 \newline
24038
24039 \newline
24040 To get the best results,
24041  follow these guidelines:
24042 \end_layout
24043
24044 \begin_layout Enumerate
24045 Make local functions static, as non static functions require code page selection
24046  overhead.
24047 \newline
24048 Due to the way sdcc handles functions, place called functions prior
24049  to calling functions in the file wherever possible: Otherwise sdcc will
24050  insert unneccessary pagesel directives around the call, believing that
24051  the called function is externally defined.
24052 \end_layout
24053
24054 \begin_layout Enumerate
24055 For devices that have multiple code pages it is more efficient to use the
24056  same number of files as pages: Use up to 4 separate .c files for the 16F877,
24057  but only 2 files for the 16F874.
24058  This way the linker can put the code for each file into different code
24059  pages and there will be less page selection overhead.
24060 \end_layout
24061
24062 \begin_layout Enumerate
24063 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24064  instruction set), use `unsigned char' wherever possible instead of `int'.
24065 \end_layout
24066
24067 \begin_layout Subsection
24068 Adding New Devices to the Port 
24069 \end_layout
24070
24071 \begin_layout Standard
24072 Adding support for a new 14
24073 \begin_inset ERT
24074 status open
24075
24076 \begin_layout Standard
24077
24078
24079 \backslash
24080 ,
24081 \end_layout
24082
24083 \end_inset
24084
24085 bit PIC MCU requires the following steps:
24086 \end_layout
24087
24088 \begin_layout Enumerate
24089 Create a new device description.
24090 \newline
24091 Each device is described in two files: pic16f*.h
24092  and pic16f*.c.
24093  These files primarily define SFRs, structs to access their bits, and symbolic
24094  configuration options.
24095  Both files can be generated from gputils' .inc files using the perl script
24096  
24097 \family typewriter
24098 support/scripts/inc2h.pl
24099 \family default
24100 .
24101  This file also contains further instructions on how to proceed.
24102 \end_layout
24103
24104 \begin_layout Enumerate
24105 Copy the .h file into SDCC's include path and either add the .c file to your
24106  project or copy it to 
24107 \family typewriter
24108 device/lib/pic/libdev
24109 \family default
24110 .
24111  Afterwards, rebuild and install the libraries.
24112 \end_layout
24113
24114 \begin_layout Enumerate
24115 Edit pic14devices.txt in SDCC's include path (
24116 \family typewriter
24117 device/include/pic/
24118 \family default
24119  in the source tree or 
24120 \family typewriter
24121 /usr/local/share/sdcc/include/pic
24122 \family default
24123  after installation).
24124 \newline
24125 You need to add a device specification here to make
24126  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24127  the compiler.
24128  Probably you can copy and modify an existing entry.
24129  The file format is documented at the top of the file.
24130 \end_layout
24131
24132 \begin_layout Subsection
24133 Interrupt Code
24134 \end_layout
24135
24136 \begin_layout Standard
24137 For the interrupt function, use the keyword `__interrupt'
24138 \begin_inset LatexCommand \index{PIC14!interrupt}
24139
24140 \end_inset
24141
24142  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24143  there to avoid a syntax error - it ought to be fixed).
24144  E.g.:
24145 \end_layout
24146
24147 \begin_layout Verse
24148
24149 \family typewriter
24150 void Intr(void) __interrupt 0
24151 \newline
24152 {
24153 \newline
24154 \InsetSpace ~
24155 \InsetSpace ~
24156 T0IF = 0; /* Clear timer interrupt */
24157 \newline
24158 }
24159 \end_layout
24160
24161 \begin_layout Subsection
24162 Linking and Assembling
24163 \end_layout
24164
24165 \begin_layout Standard
24166 For assembling you can use either GPUTILS'
24167 \begin_inset LatexCommand \index{gputils (pic tools)}
24168
24169 \end_inset
24170
24171  gpasm.exe or MPLAB's mpasmwin.exe.
24172  GPUTILS are available from 
24173 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24174
24175 \end_inset
24176
24177 .
24178  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24179  If you use MPLAB and an interrupt function then the linker script file
24180  vectors section will need to be enlarged to link with mplink.
24181 \newline
24182
24183 \newline
24184 Here is a 
24185 \family typewriter
24186 Makefile
24187 \family default
24188  using GPUTILS:
24189 \end_layout
24190
24191 \begin_layout Verse
24192
24193 \family typewriter
24194 .c.o:
24195 \newline
24196 \InsetSpace ~
24197 \InsetSpace ~
24198 \InsetSpace ~
24199 \InsetSpace ~
24200 \InsetSpace ~
24201 \InsetSpace ~
24202 \InsetSpace ~
24203 \InsetSpace ~
24204 sdcc -V -mpic14 -p16f877 -c $< 
24205 \newline
24206
24207 \newline
24208 $(PRJ).hex: $(OBJS) 
24209 \newline
24210 \InsetSpace ~
24211 \InsetSpace ~
24212 \InsetSpace ~
24213 \InsetSpace ~
24214 \InsetSpace ~
24215 \InsetSpace ~
24216 \InsetSpace ~
24217 \InsetSpace ~
24218 gplink -m -s $(PRJ).lkr
24219  -o $(PRJ).hex $(OBJS) libsdcc.lib
24220 \end_layout
24221
24222 \begin_layout Standard
24223 Here is a 
24224 \family typewriter
24225 Makefile
24226 \family default
24227  using MPLAB:
24228 \end_layout
24229
24230 \begin_layout Verse
24231
24232 \family typewriter
24233 .c.o: 
24234 \newline
24235 \InsetSpace ~
24236 \InsetSpace ~
24237 \InsetSpace ~
24238 \InsetSpace ~
24239 \InsetSpace ~
24240 \InsetSpace ~
24241 \InsetSpace ~
24242 \InsetSpace ~
24243 sdcc -S -V -mpic14 -p16f877 $< 
24244 \newline
24245 \InsetSpace ~
24246 \InsetSpace ~
24247 \InsetSpace ~
24248 \InsetSpace ~
24249 \InsetSpace ~
24250 \InsetSpace ~
24251 \InsetSpace ~
24252 \InsetSpace ~
24253 mpasmwin /q /o $*.asm
24254 \newline
24255
24256 \newline
24257 $(PRJ).hex: $(OBJS)
24258  
24259 \newline
24260 \InsetSpace ~
24261 \InsetSpace ~
24262 \InsetSpace ~
24263 \InsetSpace ~
24264 \InsetSpace ~
24265 \InsetSpace ~
24266 \InsetSpace ~
24267 \InsetSpace ~
24268 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24269 \end_layout
24270
24271 \begin_layout Standard
24272 Please note that indentations within a
24273 \family typewriter
24274  Makefile
24275 \family default
24276  have to be done with a tabulator character.
24277 \end_layout
24278
24279 \begin_layout Subsection
24280 Command-Line Options
24281 \end_layout
24282
24283 \begin_layout Standard
24284 Besides the switches common to all SDCC backends, the PIC14 port accepts
24285  the following options (for an updated list see sdcc -
24286 \begin_inset ERT
24287 status collapsed
24288
24289 \begin_layout Standard
24290
24291
24292 \backslash
24293 /
24294 \end_layout
24295
24296 \end_inset
24297
24298 -help):
24299 \end_layout
24300
24301 \begin_layout Description
24302 -
24303 \begin_inset ERT
24304 status collapsed
24305
24306 \begin_layout Standard
24307
24308
24309 \backslash
24310 /
24311 \end_layout
24312
24313 \end_inset
24314
24315 -debug-xtra
24316 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24317
24318 \end_inset
24319
24320  emit debug info in assembly output
24321 \end_layout
24322
24323 \begin_layout Description
24324 -
24325 \begin_inset ERT
24326 status collapsed
24327
24328 \begin_layout Standard
24329
24330
24331 \backslash
24332 /
24333 \end_layout
24334
24335 \end_inset
24336
24337 -no-pcode-opt
24338 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24339
24340 \end_inset
24341
24342  disable (slightly faulty) optimization on pCode
24343 \end_layout
24344
24345 \begin_layout Description
24346 -
24347 \begin_inset ERT
24348 status collapsed
24349
24350 \begin_layout Standard
24351
24352
24353 \backslash
24354 /
24355 \end_layout
24356
24357 \end_inset
24358
24359 -stack-loc
24360 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24361
24362 \end_inset
24363
24364  sets the lowest address of the argument passing stack (defaults to a suitably
24365  large shared databank to reduce BANKSEL overhead)
24366 \end_layout
24367
24368 \begin_layout Description
24369 -
24370 \begin_inset ERT
24371 status collapsed
24372
24373 \begin_layout Standard
24374
24375
24376 \backslash
24377 /
24378 \end_layout
24379
24380 \end_inset
24381
24382 -stack-size
24383 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24384
24385 \end_inset
24386
24387  sets the size if the argument passing stack (default: 16, minimum: 4)
24388 \end_layout
24389
24390 \begin_layout Subsection
24391 Environment Variables
24392 \end_layout
24393
24394 \begin_layout Standard
24395 The PIC14 port recognizes the following environment variables:
24396 \end_layout
24397
24398 \begin_layout Description
24399 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24400  register (the ones called r0xNNNN) in a section of its own.
24401  By default (if this variable is unset), sdcc tries to cluster registers
24402  in sections in order to reduce the BANKSEL overhead when accessing them.
24403 \end_layout
24404
24405 \begin_layout Subsection
24406 The Library
24407 \end_layout
24408
24409 \begin_layout Standard
24410 The PIC14 library currently only contains support routines required by the
24411  compiler to implement multiplication, division, and floating point support.
24412  No libc-like replacement is available at the moment, though many of the
24413  common sdcc library sources (in 
24414 \family typewriter
24415 device/lib
24416 \family default
24417 ) should also compile with the PIC14 port.
24418 \end_layout
24419
24420 \begin_layout Subsubsection
24421 error: missing definition for symbol ``__gptrget1''
24422 \end_layout
24423
24424 \begin_layout Standard
24425 The PIC14 port uses library routines to provide more complex operations
24426  like multiplication, division/modulus and (generic) pointer dereferencing.
24427  In order to add these routines to your project, you must link with PIC14's
24428  
24429 \family typewriter
24430 libsdcc.lib
24431 \family default
24432 .
24433  For single source file projects this is done automatically, more complex
24434  projects must add 
24435 \family typewriter
24436 libsdcc.lib
24437 \family default
24438  to the linker's arguments.
24439  Make sure you also add an include path for the library (using the -I switch
24440  to the linker)!
24441 \end_layout
24442
24443 \begin_layout Subsubsection
24444 Processor mismatch in file ``XXX''.
24445 \end_layout
24446
24447 \begin_layout Standard
24448 This warning can usually be ignored due to the very good compatibility amongst
24449  14
24450 \begin_inset ERT
24451 status open
24452
24453 \begin_layout Standard
24454
24455
24456 \backslash
24457 ,
24458 \end_layout
24459
24460 \end_inset
24461
24462 bit PIC
24463 \begin_inset LatexCommand \index{PIC14}
24464
24465 \end_inset
24466
24467  devices.
24468 \end_layout
24469
24470 \begin_layout Standard
24471 You might also consider recompiling the library for your specific device
24472  by changing the ARCH=p16f877 (default target) entry in 
24473 \family typewriter
24474 device/lib/pic/Makefile.in
24475 \family default
24476  and 
24477 \family typewriter
24478 device/lib/pic/Makefile
24479 \family default
24480  to reflect your device.
24481  This might even improve performance for smaller devices as unneccesary
24482  BANKSELs might be removed.
24483 \end_layout
24484
24485 \begin_layout Subsection
24486 Known Bugs
24487 \end_layout
24488
24489 \begin_layout Subsubsection
24490 Function arguments
24491 \end_layout
24492
24493 \begin_layout Standard
24494 Functions with variable argument lists (like printf) are not yet supported.
24495  Similarly, taking the address of the first argument passed into a function
24496  does not work: It is currently passed in WREG and has no address...
24497 \end_layout
24498
24499 \begin_layout Subsubsection
24500 Regression tests fail
24501 \end_layout
24502
24503 \begin_layout Standard
24504 Though the small subset of regression tests in src/regression passes, SDCC
24505  regression test suite does not, indicating that there are still major bugs
24506  in the port.
24507  However, many smaller projects have successfully used SDCC in the past...
24508 \end_layout
24509
24510 \begin_layout Standard
24511
24512 \size footnotesize
24513
24514 \newpage
24515
24516 \end_layout
24517
24518 \begin_layout Section
24519 The PIC16
24520 \begin_inset LatexCommand \index{PIC16}
24521
24522 \end_inset
24523
24524  port
24525 \end_layout
24526
24527 \begin_layout Standard
24528 The PIC16 port adds support for Microchip
24529 \begin_inset LatexCommand \index{Microchip}
24530
24531 \end_inset
24532
24533
24534 \begin_inset Formula $^{\text{TM}}$
24535 \end_inset
24536
24537  PIC
24538 \begin_inset LatexCommand \index{PIC}
24539
24540 \end_inset
24541
24542
24543 \begin_inset Formula $^{\text{TM}}$
24544 \end_inset
24545
24546  MCUs with 16 bit wide instructions.
24547  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24548 ; devices supported by the port include:
24549 \end_layout
24550
24551 \begin_layout Standard
24552 18F: 242, 248, 252, 258, 442, 448, 452, 458
24553 \end_layout
24554
24555 \begin_layout Standard
24556 18F: 1220, 1320
24557 \end_layout
24558
24559 \begin_layout Standard
24560 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
24561  24j10
24562 \end_layout
24563
24564 \begin_layout Standard
24565 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
24566  2680, 2682, 2685
24567 \end_layout
24568
24569 \begin_layout Standard
24570 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
24571  44j10
24572 \end_layout
24573
24574 \begin_layout Standard
24575 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
24576  4680, 4682, 4685
24577 \end_layout
24578
24579 \begin_layout Standard
24580 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
24581 \end_layout
24582
24583 \begin_layout Standard
24584 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
24585 \end_layout
24586
24587 \begin_layout Standard
24588 18F: 96j60, 96j65, 97j60
24589 \end_layout
24590
24591 \begin_layout Standard
24592 \noindent
24593 An up-to-date list of supported devices is also available via '
24594 \family typewriter
24595 sdcc -mpic16 -plist
24596 \family default
24597 '.
24598 \end_layout
24599
24600 \begin_layout Subsection
24601 Global Options
24602 \end_layout
24603
24604 \begin_layout Standard
24605 PIC16 port supports the standard command line arguments as supposed, with
24606  the exception of certain cases that will be mentioned in the following
24607  list:
24608 \end_layout
24609
24610 \begin_layout Description
24611 -
24612 \begin_inset ERT
24613 status collapsed
24614
24615 \begin_layout Standard
24616
24617
24618 \backslash
24619 /
24620 \end_layout
24621
24622 \end_inset
24623
24624 -callee-saves
24625 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24626
24627 \end_inset
24628
24629  See -
24630 \begin_inset ERT
24631 status collapsed
24632
24633 \begin_layout Standard
24634
24635
24636 \backslash
24637 /
24638 \end_layout
24639
24640 \end_inset
24641
24642 -all-callee-saves
24643 \end_layout
24644
24645 \begin_layout Description
24646 -
24647 \begin_inset ERT
24648 status collapsed
24649
24650 \begin_layout Standard
24651
24652
24653 \backslash
24654 /
24655 \end_layout
24656
24657 \end_inset
24658
24659 -fommit-frame-pointer
24660 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24661
24662 \end_inset
24663
24664  Frame pointer will be omitted when the function uses no local variables.
24665 \end_layout
24666
24667 \begin_layout Subsection
24668 Port Specific Options
24669 \begin_inset LatexCommand \index{Options PIC16}
24670
24671 \end_inset
24672
24673
24674 \end_layout
24675
24676 \begin_layout Standard
24677 The port specific options appear after the global options in the sdcc -
24678 \begin_inset ERT
24679 status collapsed
24680
24681 \begin_layout Standard
24682
24683
24684 \backslash
24685 /
24686 \end_layout
24687
24688 \end_inset
24689
24690 -help output.
24691 \end_layout
24692
24693 \begin_layout Subsubsection
24694 Code Generation Options
24695 \end_layout
24696
24697 \begin_layout Standard
24698 These options influence the generated assembler code.
24699 \end_layout
24700
24701 \begin_layout Description
24702 -
24703 \begin_inset ERT
24704 status collapsed
24705
24706 \begin_layout Standard
24707
24708
24709 \backslash
24710 /
24711 \end_layout
24712
24713 \end_inset
24714
24715 -pstack-model=[model] Used in conjuction with the command above.
24716  Defines the stack model to be used, valid stack models are:
24717 \end_layout
24718
24719 \begin_deeper
24720 \begin_layout List
24721 \labelwidthstring 00.00.0000
24722
24723 \emph on
24724 small
24725 \emph default
24726  Selects small stack model.
24727  8 bit stack and frame pointers.
24728  Supports 256 bytes stack size.
24729 \end_layout
24730
24731 \begin_layout List
24732 \labelwidthstring 00.00.0000
24733
24734 \emph on
24735 large
24736 \emph default
24737  Selects large stack model.
24738  16 bit stack and frame pointers.
24739  Supports 65536 bytes stack size.
24740 \end_layout
24741
24742 \end_deeper
24743 \begin_layout Description
24744 -
24745 \begin_inset ERT
24746 status collapsed
24747
24748 \begin_layout Standard
24749
24750
24751 \backslash
24752 /
24753 \end_layout
24754
24755 \end_inset
24756
24757 -pno-banksel Do not generate BANKSEL assembler directives.
24758 \end_layout
24759
24760 \begin_layout Description
24761 -
24762 \begin_inset ERT
24763 status collapsed
24764
24765 \begin_layout Standard
24766
24767
24768 \backslash
24769 /
24770 \end_layout
24771
24772 \end_inset
24773
24774 -extended Enable extended instruction set/literal offset addressing mode.
24775  Use with care!
24776 \end_layout
24777
24778 \begin_layout Subsubsection
24779 Optimization Options
24780 \end_layout
24781
24782 \begin_layout Description
24783 -
24784 \begin_inset ERT
24785 status collapsed
24786
24787 \begin_layout Standard
24788
24789
24790 \backslash
24791 /
24792 \end_layout
24793
24794 \end_inset
24795
24796 -obanksel=n Set optimization level for inserting BANKSELs.
24797 \newline
24798
24799 \end_layout
24800
24801 \begin_deeper
24802 \begin_layout List
24803 \labelwidthstring 00.00.0000
24804 0 no optimization
24805 \end_layout
24806
24807 \begin_layout List
24808 \labelwidthstring 00.00.0000
24809 1 checks previous used register and if it is the same then does not emit
24810  BANKSEL, accounts only for labels.
24811 \end_layout
24812
24813 \begin_layout List
24814 \labelwidthstring 00.00.0000
24815 2 tries to check the location of (even different) symbols and removes BANKSELs
24816  if they are in the same bank.
24817  
24818 \newline
24819
24820 \emph on
24821 Important: There might be problems if the linker script has data sections
24822  across bank borders!
24823 \end_layout
24824
24825 \end_deeper
24826 \begin_layout Description
24827 -
24828 \begin_inset ERT
24829 status collapsed
24830
24831 \begin_layout Standard
24832
24833
24834 \backslash
24835 /
24836 \end_layout
24837
24838 \end_inset
24839
24840 -denable-peeps Force the usage of peepholes.
24841  Use with care.
24842 \end_layout
24843
24844 \begin_layout Description
24845 -
24846 \begin_inset ERT
24847 status collapsed
24848
24849 \begin_layout Standard
24850
24851
24852 \backslash
24853 /
24854 \end_layout
24855
24856 \end_inset
24857
24858 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
24859 \end_layout
24860
24861 \begin_layout Description
24862 -
24863 \begin_inset ERT
24864 status collapsed
24865
24866 \begin_layout Standard
24867
24868
24869 \backslash
24870 /
24871 \end_layout
24872
24873 \end_inset
24874
24875 -optimize-cmp Try to optimize some compares.
24876 \end_layout
24877
24878 \begin_layout Description
24879 -
24880 \begin_inset ERT
24881 status collapsed
24882
24883 \begin_layout Standard
24884
24885
24886 \backslash
24887 /
24888 \end_layout
24889
24890 \end_inset
24891
24892 -optimize-df Analyze the dataflow of the generated code and improve it.
24893 \end_layout
24894
24895 \begin_layout Subsubsection
24896 Assembling Options
24897 \end_layout
24898
24899 \begin_layout Description
24900 -
24901 \begin_inset ERT
24902 status collapsed
24903
24904 \begin_layout Standard
24905
24906
24907 \backslash
24908 /
24909 \end_layout
24910
24911 \end_inset
24912
24913 -asm= Sets the full path and name of an external assembler to call.
24914 \end_layout
24915
24916 \begin_layout Description
24917 -
24918 \begin_inset ERT
24919 status collapsed
24920
24921 \begin_layout Standard
24922
24923
24924 \backslash
24925 /
24926 \end_layout
24927
24928 \end_inset
24929
24930 -mplab-comp MPLAB
24931 \begin_inset LatexCommand \index{PIC16!MPLAB}
24932
24933 \end_inset
24934
24935  compatibility option.
24936  Currently only suppresses special gpasm directives.
24937 \end_layout
24938
24939 \begin_layout Subsubsection
24940 Linking Options
24941 \end_layout
24942
24943 \begin_layout Description
24944 -
24945 \begin_inset ERT
24946 status collapsed
24947
24948 \begin_layout Standard
24949
24950
24951 \backslash
24952 /
24953 \end_layout
24954
24955 \end_inset
24956
24957 -link= Sets the full path and name of an external linker to call.
24958 \end_layout
24959
24960 \begin_layout Description
24961 -
24962 \begin_inset ERT
24963 status collapsed
24964
24965 \begin_layout Standard
24966
24967
24968 \backslash
24969 /
24970 \end_layout
24971
24972 \end_inset
24973
24974 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24975  unitialized data variables with [kword].
24976  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24977 \end_layout
24978
24979 \begin_layout Description
24980 -
24981 \begin_inset ERT
24982 status collapsed
24983
24984 \begin_layout Standard
24985
24986
24987 \backslash
24988 /
24989 \end_layout
24990
24991 \end_inset
24992
24993 -ivt-loc=n Place the interrupt vector table at address 
24994 \emph on
24995 n
24996 \emph default
24997 .
24998  Useful for bootloaders.
24999 \end_layout
25000
25001 \begin_layout Description
25002 -
25003 \begin_inset ERT
25004 status collapsed
25005
25006 \begin_layout Standard
25007
25008
25009 \backslash
25010 /
25011 \end_layout
25012
25013 \end_inset
25014
25015 -nodefaultlibs Do not link default libraries when linking.
25016 \end_layout
25017
25018 \begin_layout Description
25019 -
25020 \begin_inset ERT
25021 status collapsed
25022
25023 \begin_layout Standard
25024
25025
25026 \backslash
25027 /
25028 \end_layout
25029
25030 \end_inset
25031
25032 -use-crt= Use a custom run-time module instead of the defaults.
25033 \end_layout
25034
25035 \begin_layout Description
25036 -
25037 \begin_inset ERT
25038 status collapsed
25039
25040 \begin_layout Standard
25041
25042
25043 \backslash
25044 /
25045 \end_layout
25046
25047 \end_inset
25048
25049 -no-crt Don't link the default run-time modules
25050 \end_layout
25051
25052 \begin_layout Subsubsection
25053 Debugging Options
25054 \end_layout
25055
25056 \begin_layout Standard
25057 Debugging options enable extra debugging information in the output files.
25058 \end_layout
25059
25060 \begin_layout Description
25061 -
25062 \begin_inset ERT
25063 status collapsed
25064
25065 \begin_layout Standard
25066
25067
25068 \backslash
25069 /
25070 \end_layout
25071
25072 \end_inset
25073
25074 -debug-xtra Similar to -
25075 \begin_inset ERT
25076 status collapsed
25077
25078 \begin_layout Standard
25079
25080
25081 \backslash
25082 /
25083 \end_layout
25084
25085 \end_inset
25086
25087 -debug
25088 \begin_inset LatexCommand \index{-\/-debug}
25089
25090 \end_inset
25091
25092 , but dumps more information.
25093 \end_layout
25094
25095 \begin_layout Description
25096 -
25097 \begin_inset ERT
25098 status collapsed
25099
25100 \begin_layout Standard
25101
25102
25103 \backslash
25104 /
25105 \end_layout
25106
25107 \end_inset
25108
25109 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25110  information.
25111  <source> is the name of the file being compiled.
25112 \end_layout
25113
25114 \begin_layout Description
25115 -
25116 \begin_inset ERT
25117 status collapsed
25118
25119 \begin_layout Standard
25120
25121
25122 \backslash
25123 /
25124 \end_layout
25125
25126 \end_inset
25127
25128 -pcode-verbose Enable pcode debugging information in translation.
25129 \end_layout
25130
25131 \begin_layout Description
25132 -
25133 \begin_inset ERT
25134 status collapsed
25135
25136 \begin_layout Standard
25137
25138
25139 \backslash
25140 /
25141 \end_layout
25142
25143 \end_inset
25144
25145 -calltree Dump call tree in .calltree file.
25146 \end_layout
25147
25148 \begin_layout Description
25149 -
25150 \begin_inset ERT
25151 status collapsed
25152
25153 \begin_layout Standard
25154
25155
25156 \backslash
25157 /
25158 \end_layout
25159
25160 \end_inset
25161
25162 -gstack Trace push/pops for stack pointer overflow.
25163 \end_layout
25164
25165 \begin_layout Subsection
25166 Enviroment Variables
25167 \end_layout
25168
25169 \begin_layout Standard
25170 There is a number of enviromental variables that can be used when running
25171  SDCC to enable certain optimizations or force a specific program behaviour.
25172  these variables are primarily for debugging purposes so they can be enabled/dis
25173 abled at will.
25174 \end_layout
25175
25176 \begin_layout Standard
25177 Currently there is only two such variables available:
25178 \end_layout
25179
25180 \begin_layout Description
25181 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25182  bitfields is optimized by directly loading FSR0 with the address of the
25183  bitfield structure.
25184  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25185  then load FSR0.
25186  This step saves data ram and code space for functions that make heavy use
25187  of bitfields.
25188  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25189  option).
25190  
25191 \end_layout
25192
25193 \begin_layout Description
25194 NO_REG_OPT Do not perform pCode registers optimization.
25195  This should be used for debugging purposes.
25196  If bugs in the pcode optimizer are found, users can benefit from temporarily
25197  disabling the optimizer until the bug is fixed.
25198 \end_layout
25199
25200 \begin_layout Subsection
25201 Preprocessor Macros
25202 \end_layout
25203
25204 \begin_layout Standard
25205 PIC16
25206 \begin_inset LatexCommand \index{PIC16}
25207
25208 \end_inset
25209
25210  port defines the following preprocessor macros while translating a source.
25211 \end_layout
25212
25213 \begin_layout Standard
25214 \align center
25215 \begin_inset Tabular
25216 <lyxtabular version="3" rows="6" columns="2">
25217 <features>
25218 <column alignment="center" valignment="top" leftline="true" width="0">
25219 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25220 <row topline="true" bottomline="true">
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25222 \begin_inset Text
25223
25224 \begin_layout Standard
25225 Macro
25226 \end_layout
25227
25228 \end_inset
25229 </cell>
25230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25231 \begin_inset Text
25232
25233 \begin_layout Standard
25234 Description
25235 \end_layout
25236
25237 \end_inset
25238 </cell>
25239 </row>
25240 <row topline="true">
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25242 \begin_inset Text
25243
25244 \begin_layout Standard
25245 SDCC_pic16
25246 \end_layout
25247
25248 \end_inset
25249 </cell>
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25251 \begin_inset Text
25252
25253 \begin_layout Standard
25254 Port identification
25255 \end_layout
25256
25257 \end_inset
25258 </cell>
25259 </row>
25260 <row topline="true">
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \begin_layout Standard
25265 _
25266 \begin_inset ERT
25267 status collapsed
25268
25269 \begin_layout Standard
25270
25271
25272 \backslash
25273 /
25274 \end_layout
25275
25276 \end_inset
25277
25278 _pic16
25279 \end_layout
25280
25281 \end_inset
25282 </cell>
25283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25284 \begin_inset Text
25285
25286 \begin_layout Standard
25287 Port identification (same as above)
25288 \end_layout
25289
25290 \end_inset
25291 </cell>
25292 </row>
25293 <row topline="true">
25294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25295 \begin_inset Text
25296
25297 \begin_layout Standard
25298 pic18fxxxx
25299 \end_layout
25300
25301 \end_inset
25302 </cell>
25303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25304 \begin_inset Text
25305
25306 \begin_layout Standard
25307 MCU Identification.
25308  
25309 \emph on
25310 xxxx
25311 \emph default
25312  is the microcontrol identification number, i.e.
25313  452, 6620, etc
25314 \end_layout
25315
25316 \end_inset
25317 </cell>
25318 </row>
25319 <row topline="true">
25320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25321 \begin_inset Text
25322
25323 \begin_layout Standard
25324 _
25325 \begin_inset ERT
25326 status collapsed
25327
25328 \begin_layout Standard
25329
25330
25331 \backslash
25332 /
25333 \end_layout
25334
25335 \end_inset
25336
25337 _18Fxxxx
25338 \end_layout
25339
25340 \end_inset
25341 </cell>
25342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25343 \begin_inset Text
25344
25345 \begin_layout Standard
25346 MCU Identification (same as above)
25347 \end_layout
25348
25349 \end_inset
25350 </cell>
25351 </row>
25352 <row topline="true" bottomline="true">
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25354 \begin_inset Text
25355
25356 \begin_layout Standard
25357 STACK_MODEL_nnn
25358 \end_layout
25359
25360 \end_inset
25361 </cell>
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25363 \begin_inset Text
25364
25365 \begin_layout Standard
25366 nnn = SMALL or LARGE respectively according to the stack model used
25367 \end_layout
25368
25369 \end_inset
25370 </cell>
25371 </row>
25372 </lyxtabular>
25373
25374 \end_inset
25375
25376
25377 \end_layout
25378
25379 \begin_layout Standard
25380 \noindent
25381 In addition the following macros are defined when calling assembler:
25382 \end_layout
25383
25384 \begin_layout Standard
25385 \align center
25386 \begin_inset Tabular
25387 <lyxtabular version="3" rows="4" columns="2">
25388 <features>
25389 <column alignment="center" valignment="top" leftline="true" width="0">
25390 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25391 <row topline="true" bottomline="true">
25392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25393 \begin_inset Text
25394
25395 \begin_layout Standard
25396 Macro
25397 \end_layout
25398
25399 \end_inset
25400 </cell>
25401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25402 \begin_inset Text
25403
25404 \begin_layout Standard
25405 Description
25406 \end_layout
25407
25408 \end_inset
25409 </cell>
25410 </row>
25411 <row topline="true">
25412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25413 \begin_inset Text
25414
25415 \begin_layout Standard
25416 __18Fxxxx
25417 \end_layout
25418
25419 \end_inset
25420 </cell>
25421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25422 \begin_inset Text
25423
25424 \begin_layout Standard
25425 MCU Identification.
25426  
25427 \emph on
25428 xxxx
25429 \emph default
25430  is the microcontrol identification number, i.e.
25431  452, 6620, etc
25432 \end_layout
25433
25434 \end_inset
25435 </cell>
25436 </row>
25437 <row topline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25439 \begin_inset Text
25440
25441 \begin_layout Standard
25442 SDCC_MODEL_nnn
25443 \end_layout
25444
25445 \end_inset
25446 </cell>
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25448 \begin_inset Text
25449
25450 \begin_layout Standard
25451 nnn = SMALL or LARGE respectively according to the memory model used for
25452  SDCC
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 </row>
25458 <row topline="true" bottomline="true">
25459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25460 \begin_inset Text
25461
25462 \begin_layout Standard
25463 STACK_MODEL_nnn
25464 \end_layout
25465
25466 \end_inset
25467 </cell>
25468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25469 \begin_inset Text
25470
25471 \begin_layout Standard
25472 nnn = SMALL or LARGE respectively according to the stack model used
25473 \end_layout
25474
25475 \end_inset
25476 </cell>
25477 </row>
25478 </lyxtabular>
25479
25480 \end_inset
25481
25482
25483 \end_layout
25484
25485 \begin_layout Subsection
25486 Directories
25487 \end_layout
25488
25489 \begin_layout Standard
25490 PIC16
25491 \begin_inset LatexCommand \index{PIC16}
25492
25493 \end_inset
25494
25495  port uses the following directories for searching header files and libraries.
25496 \end_layout
25497
25498 \begin_layout Standard
25499 \align center
25500 \begin_inset Tabular
25501 <lyxtabular version="3" rows="3" columns="4">
25502 <features>
25503 <column alignment="center" valignment="top" leftline="true" width="0">
25504 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25505 <column alignment="center" valignment="top" width="0">
25506 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25507 <row topline="true" bottomline="true">
25508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25509 \begin_inset Text
25510
25511 \begin_layout Standard
25512 Directory
25513 \end_layout
25514
25515 \end_inset
25516 </cell>
25517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25518 \begin_inset Text
25519
25520 \begin_layout Standard
25521 Description
25522 \end_layout
25523
25524 \end_inset
25525 </cell>
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25527 \begin_inset Text
25528
25529 \begin_layout Standard
25530 Target
25531 \end_layout
25532
25533 \end_inset
25534 </cell>
25535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25536 \begin_inset Text
25537
25538 \begin_layout Standard
25539 Command prefix
25540 \end_layout
25541
25542 \end_inset
25543 </cell>
25544 </row>
25545 <row topline="true">
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25547 \begin_inset Text
25548
25549 \begin_layout Standard
25550 PREFIX/sdcc/include/pic16
25551 \end_layout
25552
25553 \end_inset
25554 </cell>
25555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25556 \begin_inset Text
25557
25558 \begin_layout Standard
25559 PIC16 specific headers
25560 \end_layout
25561
25562 \end_inset
25563 </cell>
25564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25565 \begin_inset Text
25566
25567 \begin_layout Standard
25568 Compiler
25569 \end_layout
25570
25571 \end_inset
25572 </cell>
25573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25574 \begin_inset Text
25575
25576 \begin_layout Standard
25577 -I
25578 \end_layout
25579
25580 \end_inset
25581 </cell>
25582 </row>
25583 <row topline="true" bottomline="true">
25584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25585 \begin_inset Text
25586
25587 \begin_layout Standard
25588 PREFIX/sdcc/lib/pic16
25589 \end_layout
25590
25591 \end_inset
25592 </cell>
25593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25594 \begin_inset Text
25595
25596 \begin_layout Standard
25597 PIC16 specific libraries
25598 \end_layout
25599
25600 \end_inset
25601 </cell>
25602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25603 \begin_inset Text
25604
25605 \begin_layout Standard
25606 Linker
25607 \end_layout
25608
25609 \end_inset
25610 </cell>
25611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25612 \begin_inset Text
25613
25614 \begin_layout Standard
25615 -L
25616 \end_layout
25617
25618 \end_inset
25619 </cell>
25620 </row>
25621 </lyxtabular>
25622
25623 \end_inset
25624
25625
25626 \end_layout
25627
25628 \begin_layout Subsection
25629 Pragmas
25630 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25631
25632 \end_inset
25633
25634
25635 \end_layout
25636
25637 \begin_layout Standard
25638 The PIC16
25639 \begin_inset LatexCommand \index{PIC16}
25640
25641 \end_inset
25642
25643  port currently supports the following pragmas:
25644 \end_layout
25645
25646 \begin_layout Description
25647 stack
25648 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25649
25650 \end_inset
25651
25652  This forces the code generator to initialize the stack & frame pointers
25653  at a specific address.
25654  This is an ad hoc solution for cases where no STACK directive is available
25655  in the linker script or gplink is not instructed to create a stack section.
25656 \newline
25657 The
25658  stack pragma should be used only once in a project.
25659  Multiple pragmas may result in indeterminate behaviour of the program.
25660 \begin_inset Foot
25661 status open
25662
25663 \begin_layout Standard
25664 The old format (ie.
25665  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25666  cross page boundaries (or even exceed the available data RAM) and crash
25667  the program.
25668  Make sure that stack does not cross page boundaries when using the SMALL
25669  stack model.
25670 \end_layout
25671
25672 \end_inset
25673
25674
25675 \newline
25676 The format is as follows:
25677 \newline
25678
25679 \end_layout
25680
25681 \begin_layout LyX-Code
25682 #pragma stack bottom_address [stack_size]
25683 \newline
25684
25685 \end_layout
25686
25687 \begin_layout Standard
25688
25689 \emph on
25690 bottom_address
25691 \emph default
25692  is the lower bound of the stack section.
25693  The stack pointer initially will point at address (bottom_address+stack_size-1).
25694 \end_layout
25695
25696 \begin_layout LyX-Code
25697 Example:
25698 \end_layout
25699
25700 \begin_layout LyX-Code
25701
25702 \end_layout
25703
25704 \begin_layout LyX-Code
25705 /* initializes stack of 100 bytes at RAM address 0x200 */
25706 \end_layout
25707
25708 \begin_layout LyX-Code
25709 #pragma stack 0x200 100
25710 \end_layout
25711
25712 \begin_layout Standard
25713 If the stack_size field is omitted then a stack is created with the default
25714  size of 64.
25715  This size might be enough for most programs, but its not enough for operations
25716  with deep function nesting or excessive stack usage.
25717 \end_layout
25718
25719 \begin_layout Description
25720 code
25721 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25722
25723 \end_inset
25724
25725  Force a function to a static FLASH address.
25726 \end_layout
25727
25728 \begin_layout LyX-Code
25729 Example:
25730 \end_layout
25731
25732 \begin_layout LyX-Code
25733
25734 \end_layout
25735
25736 \begin_layout LyX-Code
25737 /* place function test_func at 0x4000 */
25738 \end_layout
25739
25740 \begin_layout LyX-Code
25741 #pragma code test_func 0x4000
25742 \end_layout
25743
25744 \begin_layout LyX-Code
25745
25746 \end_layout
25747
25748 \begin_layout Description
25749 library instructs the linker to use a library module.
25750 \newline
25751 Usage:
25752 \end_layout
25753
25754 \begin_layout LyX-Code
25755 #pragma library module_name
25756 \end_layout
25757
25758 \begin_layout Standard
25759
25760 \emph on
25761 module_name
25762 \emph default
25763  can be any library or object file (including its path).
25764  Note that there are four reserved keywords which have special meaning.
25765  These are:
25766 \end_layout
25767
25768 \begin_layout Standard
25769 \align center
25770 \begin_inset Tabular
25771 <lyxtabular version="3" rows="6" columns="3">
25772 <features>
25773 <column alignment="center" valignment="top" leftline="true" width="0">
25774 <column alignment="block" valignment="top" leftline="true" width="20page%">
25775 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25776 <row topline="true" bottomline="true">
25777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25778 \begin_inset Text
25779
25780 \begin_layout Standard
25781 Keyword
25782 \end_layout
25783
25784 \end_inset
25785 </cell>
25786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25787 \begin_inset Text
25788
25789 \begin_layout Standard
25790 Description
25791 \end_layout
25792
25793 \end_inset
25794 </cell>
25795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25796 \begin_inset Text
25797
25798 \begin_layout Standard
25799 Module to link
25800 \end_layout
25801
25802 \end_inset
25803 </cell>
25804 </row>
25805 <row topline="true">
25806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25807 \begin_inset Text
25808
25809 \begin_layout Standard
25810
25811 \series bold
25812 ignore
25813 \end_layout
25814
25815 \end_inset
25816 </cell>
25817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25818 \begin_inset Text
25819
25820 \begin_layout Standard
25821 ignore all library pragmas
25822 \end_layout
25823
25824 \end_inset
25825 </cell>
25826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25827 \begin_inset Text
25828
25829 \begin_layout Standard
25830
25831 \emph on
25832 (none)
25833 \end_layout
25834
25835 \end_inset
25836 </cell>
25837 </row>
25838 <row topline="true">
25839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25840 \begin_inset Text
25841
25842 \begin_layout Standard
25843
25844 \series bold
25845 c
25846 \end_layout
25847
25848 \end_inset
25849 </cell>
25850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25851 \begin_inset Text
25852
25853 \begin_layout Standard
25854 link the C library
25855 \end_layout
25856
25857 \end_inset
25858 </cell>
25859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25860 \begin_inset Text
25861
25862 \begin_layout Standard
25863
25864 \emph on
25865 libc18f
25866 \emph default
25867 .lib
25868 \end_layout
25869
25870 \end_inset
25871 </cell>
25872 </row>
25873 <row topline="true">
25874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25875 \begin_inset Text
25876
25877 \begin_layout Standard
25878
25879 \series bold
25880 math
25881 \end_layout
25882
25883 \end_inset
25884 </cell>
25885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25886 \begin_inset Text
25887
25888 \begin_layout Standard
25889 link the Math libarary
25890 \end_layout
25891
25892 \end_inset
25893 </cell>
25894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25895 \begin_inset Text
25896
25897 \begin_layout Standard
25898
25899 \emph on
25900 libm18f
25901 \emph default
25902 .lib
25903 \end_layout
25904
25905 \end_inset
25906 </cell>
25907 </row>
25908 <row topline="true">
25909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25910 \begin_inset Text
25911
25912 \begin_layout Standard
25913
25914 \series bold
25915 io
25916 \end_layout
25917
25918 \end_inset
25919 </cell>
25920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25921 \begin_inset Text
25922
25923 \begin_layout Standard
25924 link the I/O library
25925 \end_layout
25926
25927 \end_inset
25928 </cell>
25929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25930 \begin_inset Text
25931
25932 \begin_layout Standard
25933
25934 \emph on
25935 libio18f*
25936 \emph default
25937 .lib
25938 \end_layout
25939
25940 \end_inset
25941 </cell>
25942 </row>
25943 <row topline="true" bottomline="true">
25944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25945 \begin_inset Text
25946
25947 \begin_layout Standard
25948
25949 \series bold
25950 debug
25951 \end_layout
25952
25953 \end_inset
25954 </cell>
25955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25956 \begin_inset Text
25957
25958 \begin_layout Standard
25959 link the debug library
25960 \end_layout
25961
25962 \end_inset
25963 </cell>
25964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25965 \begin_inset Text
25966
25967 \begin_layout Standard
25968
25969 \emph on
25970 libdebug
25971 \emph default
25972 .lib
25973 \end_layout
25974
25975 \end_inset
25976 </cell>
25977 </row>
25978 </lyxtabular>
25979
25980 \end_inset
25981
25982
25983 \newline
25984 * is the device number, i.e.
25985  452 for PIC18F452 MCU.
25986 \end_layout
25987
25988 \begin_layout Standard
25989 \noindent
25990 This feature allows for linking with specific libraries withoug having to
25991  explicit name them in the command line.
25992  Note that the 
25993 \noun on
25994 ignore
25995 \noun default
25996  keyword will reject all modules specified by the library pragma.
25997 \end_layout
25998
25999 \begin_layout Description
26000 udata The pragma udata instructs the compiler to emit code so that linker
26001  will place a variable at a specific memory bank.
26002 \end_layout
26003
26004 \begin_layout LyX-Code
26005 Example:
26006 \end_layout
26007
26008 \begin_layout LyX-Code
26009
26010 \end_layout
26011
26012 \begin_layout LyX-Code
26013 /* places variable foo at bank2 */
26014 \end_layout
26015
26016 \begin_layout LyX-Code
26017 #pragma udata bank2 foo
26018 \end_layout
26019
26020 \begin_layout LyX-Code
26021 char foo;
26022 \end_layout
26023
26024 \begin_layout Standard
26025 In order for this pragma to work extra SECTION directives should be added
26026  in the .lkr script.
26027  In the following example a sample .lkr file is shown:
26028 \end_layout
26029
26030 \begin_layout LyX-Code
26031
26032 \end_layout
26033
26034 \begin_layout LyX-Code
26035 // Sample linker script for the PIC18F452 processor
26036 \end_layout
26037
26038 \begin_layout LyX-Code
26039 LIBPATH .
26040 \end_layout
26041
26042 \begin_layout LyX-Code
26043 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
26044 \end_layout
26045
26046 \begin_layout LyX-Code
26047 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
26048 \end_layout
26049
26050 \begin_layout LyX-Code
26051 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
26052 \end_layout
26053
26054 \begin_layout LyX-Code
26055 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
26056 \end_layout
26057
26058 \begin_layout LyX-Code
26059 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
26060 \end_layout
26061
26062 \begin_layout LyX-Code
26063 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
26064 \end_layout
26065
26066 \begin_layout LyX-Code
26067 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
26068 \end_layout
26069
26070 \begin_layout LyX-Code
26071
26072 \end_layout
26073
26074 \begin_layout LyX-Code
26075 DATABANK   NAME=gpr0       START=0x80           END=0xFF
26076 \end_layout
26077
26078 \begin_layout LyX-Code
26079 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
26080 \end_layout
26081
26082 \begin_layout LyX-Code
26083 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
26084 \end_layout
26085
26086 \begin_layout LyX-Code
26087 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
26088 \end_layout
26089
26090 \begin_layout LyX-Code
26091 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
26092 \end_layout
26093
26094 \begin_layout LyX-Code
26095 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
26096 \end_layout
26097
26098 \begin_layout LyX-Code
26099 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
26100 \end_layout
26101
26102 \begin_layout LyX-Code
26103
26104 \end_layout
26105
26106 \begin_layout LyX-Code
26107 SECTION    NAME=CONFIG     ROM=config
26108 \end_layout
26109
26110 \begin_layout LyX-Code
26111
26112 \end_layout
26113
26114 \begin_layout LyX-Code
26115 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
26116 \end_layout
26117
26118 \begin_layout LyX-Code
26119 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
26120 \end_layout
26121
26122 \begin_layout LyX-Code
26123 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
26124 \end_layout
26125
26126 \begin_layout LyX-Code
26127 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
26128 \end_layout
26129
26130 \begin_layout LyX-Code
26131 SECTION    NAME=bank4      RAM=gpr4
26132 \end_layout
26133
26134 \begin_layout LyX-Code
26135 SECTION    NAME=bank5      RAM=gpr5
26136 \end_layout
26137
26138 \begin_layout Standard
26139 The linker will recognise the section name set in the pragma statement and
26140  will position the variable at the memory bank set with the RAM field at
26141  the SECTION line in the linker script file.
26142 \end_layout
26143
26144 \begin_layout Subsection
26145 Header Files
26146 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26147
26148 \end_inset
26149
26150
26151 \end_layout
26152
26153 \begin_layout Standard
26154 There is one main header file
26155 \begin_inset LatexCommand \index{PIC16!Header files}
26156
26157 \end_inset
26158
26159  that can be included to the source files using the pic16
26160 \begin_inset LatexCommand \index{PIC16}
26161
26162 \end_inset
26163
26164  port.
26165  That file is the 
26166 \series bold
26167 pic18fregs.h
26168 \series default
26169 .
26170  This header file contains the definitions for the processor special registers,
26171  so it is necessary if the source accesses them.
26172  It can be included by adding the following line in the beginning of the
26173  file:
26174 \end_layout
26175
26176 \begin_layout LyX-Code
26177 #include <pic18fregs.h>
26178 \end_layout
26179
26180 \begin_layout Standard
26181 The specific microcontroller is selected within the pic18fregs.h automatically,
26182  so the same source can be used with a variety of devices.
26183 \end_layout
26184
26185 \begin_layout Subsection
26186 Libraries
26187 \begin_inset LatexCommand \label{sub:pic16Libraries}
26188
26189 \end_inset
26190
26191
26192 \end_layout
26193
26194 \begin_layout Standard
26195 The libraries
26196 \begin_inset LatexCommand \index{PIC16!Libraries}
26197
26198 \end_inset
26199
26200  that PIC16
26201 \begin_inset LatexCommand \index{PIC16}
26202
26203 \end_inset
26204
26205  port depends on are the microcontroller device libraries which contain
26206  the symbol definitions for the microcontroller special function registers.
26207  These libraries have the format pic18fxxxx.lib, where 
26208 \emph on
26209 xxxx
26210 \emph default
26211  is the microcontroller identification number.
26212  The specific library is selected automatically by the compiler at link
26213  stage according to the selected device.
26214 \end_layout
26215
26216 \begin_layout Standard
26217 \noindent
26218 Libraries are created with gplib which is part of the gputils package 
26219 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26220
26221 \end_inset
26222
26223 .
26224 \end_layout
26225
26226 \begin_layout Subsubsection*
26227 Building the libraries
26228 \end_layout
26229
26230 \begin_layout Standard
26231 Before using SDCC/pic16 there are some libraries that need to be compiled.
26232  This process is done automatically if gputils are found at SDCC's compile
26233  time.
26234  Should you require to rebuild the pic16 libraries manually, these are the
26235  steps required to do so under Linux or Mac OS X (cygwin might work as well,
26236  but is untested):
26237 \end_layout
26238
26239 \begin_layout LyX-Code
26240 cd device/lib/pic16
26241 \end_layout
26242
26243 \begin_layout LyX-Code
26244 ./configure.gnu
26245 \end_layout
26246
26247 \begin_layout LyX-Code
26248 cd ..
26249 \end_layout
26250
26251 \begin_layout LyX-Code
26252 make model-pic16
26253 \end_layout
26254
26255 \begin_layout LyX-Code
26256 su -c 'make install'     # install the libraries, you need the root password
26257 \end_layout
26258
26259 \begin_layout LyX-Code
26260 cd ../..
26261 \end_layout
26262
26263 \begin_layout Standard
26264 If you need to install the headers too, do:
26265 \end_layout
26266
26267 \begin_layout LyX-Code
26268 cd device/include
26269 \end_layout
26270
26271 \begin_layout LyX-Code
26272 su -c 'make install'     # install the headers, you need the root password
26273 \end_layout
26274
26275 \begin_layout Subsection
26276 Adding New Devices to the Port
26277 \end_layout
26278
26279 \begin_layout Standard
26280 Adding support for a new 16
26281 \begin_inset ERT
26282 status collapsed
26283
26284 \begin_layout Standard
26285
26286
26287 \backslash
26288 ,
26289 \end_layout
26290
26291 \end_inset
26292
26293 bit PIC MCU requires the following steps:
26294 \end_layout
26295
26296 \begin_layout Enumerate
26297 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26298 \newline
26299
26300 \family typewriter
26301 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26302 inc
26303 \end_layout
26304
26305 \begin_layout Enumerate
26306
26307 \family typewriter
26308 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26309 \end_layout
26310
26311 \begin_layout Enumerate
26312
26313 \family typewriter
26314 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26315 \end_layout
26316
26317 \begin_layout Enumerate
26318 Add DEVICE to 
26319 \family typewriter
26320 /path/to/sdcc/device/lib/pic16/pics.all
26321 \family default
26322
26323 \newline
26324 Note: No 18f prefix here!
26325 \end_layout
26326
26327 \begin_layout Enumerate
26328 Edit 
26329 \family typewriter
26330 /path/to/sdcc/device/include/pic16/adc.h
26331 \newline
26332
26333 \family default
26334 Add the new devices to the correct ADC style class (depending on the number
26335  of ADC channels).
26336 \newline
26337 Do not touch 
26338 \family typewriter
26339 adc.h
26340 \family default
26341  if the device does not offer any ADC at all.
26342 \end_layout
26343
26344 \begin_layout Enumerate
26345 Edit 
26346 \family typewriter
26347 /path/to/sdcc/device/include/pic16/pic18fregs.h
26348 \family default
26349
26350 \newline
26351 The file format is self-explanatory, just add
26352 \newline
26353
26354 \family typewriter
26355 #elif defined(picDEVICE)
26356 \newline
26357 #
26358 \begin_inset ERT
26359 status collapsed
26360
26361 \begin_layout Standard
26362
26363 \family typewriter
26364
26365 \backslash
26366  
26367 \backslash
26368  
26369 \end_layout
26370
26371 \end_inset
26372
26373 include <picDEVICE.h>
26374 \family default
26375
26376 \newline
26377 at the right place (keep the file sorted, please).
26378 \end_layout
26379
26380 \begin_layout Enumerate
26381 Edit 
26382 \family typewriter
26383 /path/to/sdcc/device/include/pic16devices.txt
26384 \newline
26385
26386 \family default
26387 Copy and modify an existing entry or create a new one and insert it at the
26388  correct place (keep the file sorted, please).
26389 \end_layout
26390
26391 \begin_layout Enumerate
26392 Add the device to 
26393 \family typewriter
26394 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
26395 \family default
26396
26397 \newline
26398 Copy an existing entry and adjust the device name.
26399 \end_layout
26400
26401 \begin_layout Enumerate
26402 Add the device to 
26403 \family typewriter
26404 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
26405 \family default
26406
26407 \newline
26408 Copy the record from the 18f2220 and adjust the device name.
26409 \newline
26410 If the new device
26411  does not offer ADC, I
26412 \begin_inset Formula $^{\text{2}}$
26413 \end_inset
26414
26415 C, and/or (E)USART functionality as assumed by the library, remove the lines
26416  with references to 
26417 \family typewriter
26418 adc/*.c
26419 \family default
26420
26421 \family typewriter
26422 usart/*.c
26423 \family default
26424 , or 
26425 \family typewriter
26426 usart/*.c
26427 \family default
26428 , respectively.
26429 \end_layout
26430
26431 \begin_layout Enumerate
26432 Update 
26433 \family typewriter
26434 libdev/Makefile.in
26435 \family default
26436  and 
26437 \family typewriter
26438 libio/Makefile.in
26439 \family default
26440  using
26441 \newline
26442
26443 \family typewriter
26444 ./bootstrap.sh
26445 \family default
26446
26447 \newline
26448 in 
26449 \family typewriter
26450 /path/to/sdcc/device/lib/pic16
26451 \family default
26452 .
26453 \end_layout
26454
26455 \begin_layout Enumerate
26456 Recompile the pic16 libraries as described in 
26457 \begin_inset LatexCommand \ref{sub:pic16Libraries}
26458
26459 \end_inset
26460
26461 .
26462 \end_layout
26463
26464 \begin_layout Subsection
26465 Memory Models
26466 \end_layout
26467
26468 \begin_layout Standard
26469 The following memory models are supported by the PIC16 port:
26470 \end_layout
26471
26472 \begin_layout Itemize
26473 small model
26474 \end_layout
26475
26476 \begin_layout Itemize
26477 large model
26478 \end_layout
26479
26480 \begin_layout Standard
26481 Memory model affects the default size of pointers within the source.
26482  The sizes are shown in the next table:
26483 \end_layout
26484
26485 \begin_layout Standard
26486 \align center
26487 \begin_inset Tabular
26488 <lyxtabular version="3" rows="3" columns="3">
26489 <features>
26490 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26491 <column alignment="center" valignment="top" leftline="true" width="0">
26492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26493 <row topline="true" bottomline="true">
26494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26495 \begin_inset Text
26496
26497 \begin_layout Standard
26498 Pointer sizes according to memory model
26499 \end_layout
26500
26501 \end_inset
26502 </cell>
26503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26504 \begin_inset Text
26505
26506 \begin_layout Standard
26507 small model
26508 \end_layout
26509
26510 \end_inset
26511 </cell>
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26513 \begin_inset Text
26514
26515 \begin_layout Standard
26516 large model
26517 \end_layout
26518
26519 \end_inset
26520 </cell>
26521 </row>
26522 <row topline="true" bottomline="true">
26523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26524 \begin_inset Text
26525
26526 \begin_layout Standard
26527 code pointers
26528 \end_layout
26529
26530 \end_inset
26531 </cell>
26532 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26533 \begin_inset Text
26534
26535 \begin_layout Standard
26536 16-bits
26537 \end_layout
26538
26539 \end_inset
26540 </cell>
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26542 \begin_inset Text
26543
26544 \begin_layout Standard
26545 24-bits
26546 \end_layout
26547
26548 \end_inset
26549 </cell>
26550 </row>
26551 <row topline="true" bottomline="true">
26552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26553 \begin_inset Text
26554
26555 \begin_layout Standard
26556 data pointers
26557 \end_layout
26558
26559 \end_inset
26560 </cell>
26561 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26562 \begin_inset Text
26563
26564 \begin_layout Standard
26565 16-bits
26566 \end_layout
26567
26568 \end_inset
26569 </cell>
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26571 \begin_inset Text
26572
26573 \begin_layout Standard
26574 16-bits
26575 \end_layout
26576
26577 \end_inset
26578 </cell>
26579 </row>
26580 </lyxtabular>
26581
26582 \end_inset
26583
26584
26585 \end_layout
26586
26587 \begin_layout Standard
26588 It is advisable that all sources within a project are compiled with the
26589  same memory model.
26590  If one wants to override the default memory model, this can be done by
26591  declaring a pointer as 
26592 \series bold
26593 far
26594 \series default
26595  or 
26596 \series bold
26597 near
26598 \series default
26599 .
26600  Far selects large memory model's pointers, while near selects small memory
26601  model's pointers.
26602 \end_layout
26603
26604 \begin_layout Standard
26605 The standard device libraries (see 
26606 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26607
26608 \end_inset
26609
26610 ) contain no reference to pointers, so they can be used with both memory
26611  models.
26612 \end_layout
26613
26614 \begin_layout Subsection
26615 Stack
26616 \end_layout
26617
26618 \begin_layout Standard
26619 The stack
26620 \begin_inset LatexCommand \index{PIC16!stack}
26621
26622 \end_inset
26623
26624  implementation for the PIC16 port uses two indirect registers, FSR1 and
26625  FSR2.
26626 \end_layout
26627
26628 \begin_layout Description
26629 FSR1 is assigned as stack pointer
26630 \end_layout
26631
26632 \begin_layout Description
26633 FSR2 is assigned as frame pointer
26634 \end_layout
26635
26636 \begin_layout Standard
26637 The following stack models are supported by the PIC16 port
26638 \end_layout
26639
26640 \begin_layout Itemize
26641
26642 \noun on
26643 small
26644 \noun default
26645  model
26646 \end_layout
26647
26648 \begin_layout Itemize
26649
26650 \noun on
26651 large
26652 \noun default
26653  model
26654 \end_layout
26655
26656 \begin_layout Standard
26657
26658 \noun on
26659 Small
26660 \noun default
26661  model means that only the FSRxL byte is used to access stack and frame,
26662  while 
26663 \emph on
26664 \noun on
26665 large
26666 \emph default
26667 \noun default
26668  uses both FSRxL and FSRxH registers.
26669  The following table shows the stack/frame pointers sizes according to stack
26670  model and the maximum space they can address:
26671 \end_layout
26672
26673 \begin_layout Standard
26674 \align center
26675 \begin_inset Tabular
26676 <lyxtabular version="3" rows="3" columns="3">
26677 <features>
26678 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26679 <column alignment="center" valignment="top" leftline="true" width="0">
26680 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26681 <row topline="true" bottomline="true">
26682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26683 \begin_inset Text
26684
26685 \begin_layout Standard
26686 Stack & Frame pointer sizes according to stack model
26687 \end_layout
26688
26689 \end_inset
26690 </cell>
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26692 \begin_inset Text
26693
26694 \begin_layout Standard
26695 small
26696 \end_layout
26697
26698 \end_inset
26699 </cell>
26700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26701 \begin_inset Text
26702
26703 \begin_layout Standard
26704 large
26705 \end_layout
26706
26707 \end_inset
26708 </cell>
26709 </row>
26710 <row topline="true">
26711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_inset Text
26713
26714 \begin_layout Standard
26715 Stack pointer FSR1
26716 \end_layout
26717
26718 \end_inset
26719 </cell>
26720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26721 \begin_inset Text
26722
26723 \begin_layout Standard
26724 8-bits
26725 \end_layout
26726
26727 \end_inset
26728 </cell>
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_inset Text
26731
26732 \begin_layout Standard
26733 16-bits
26734 \end_layout
26735
26736 \end_inset
26737 </cell>
26738 </row>
26739 <row topline="true" bottomline="true">
26740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26741 \begin_inset Text
26742
26743 \begin_layout Standard
26744 Frame pointer FSR2
26745 \end_layout
26746
26747 \end_inset
26748 </cell>
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_inset Text
26751
26752 \begin_layout Standard
26753 8-bits
26754 \end_layout
26755
26756 \end_inset
26757 </cell>
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26759 \begin_inset Text
26760
26761 \begin_layout Standard
26762 16-bits
26763 \end_layout
26764
26765 \end_inset
26766 </cell>
26767 </row>
26768 </lyxtabular>
26769
26770 \end_inset
26771
26772
26773 \end_layout
26774
26775 \begin_layout Standard
26776 \noindent
26777
26778 \noun on
26779 Large 
26780 \noun default
26781 stack model is currently not working properly throughout the code generator.
26782  So its use is not advised.
26783  Also there are some other points that need special care:
26784 \newline
26785
26786 \end_layout
26787
26788 \begin_layout Enumerate
26789 Do not create stack sections with size more than one physical bank (that
26790  is 256 bytes)
26791 \end_layout
26792
26793 \begin_layout Enumerate
26794 Stack sections should no cross physical bank limits (i.e.
26795  #pragma stack 0x50 0x100)
26796 \end_layout
26797
26798 \begin_layout Standard
26799 These limitations are caused by the fact that only FSRxL is modified when
26800  using SMALL stack model, so no more than 256 bytes of stack can be used.
26801  This problem will disappear after LARGE model is fully implemented.
26802 \end_layout
26803
26804 \begin_layout Subsection
26805 Functions
26806 \end_layout
26807
26808 \begin_layout Standard
26809 In addition to the standard SDCC function keywords, PIC16
26810 \begin_inset LatexCommand \index{PIC16}
26811
26812 \end_inset
26813
26814  port makes available two more:
26815 \end_layout
26816
26817 \begin_layout Description
26818 wparam
26819 \begin_inset LatexCommand \index{PIC16!wparam}
26820
26821 \end_inset
26822
26823  Use the WREG to pass one byte of the first function argument.
26824  This improves speed but you may not use this for functions with arguments
26825  that are called via function pointers, otherwise the first byte of the
26826  first parameter will get lost.
26827  Usage:
26828 \end_layout
26829
26830 \begin_layout LyX-Code
26831 void func_wparam(int a) wparam
26832 \end_layout
26833
26834 \begin_layout LyX-Code
26835 {
26836 \end_layout
26837
26838 \begin_layout LyX-Code
26839     /* WREG hold the lower part of a */
26840 \end_layout
26841
26842 \begin_layout LyX-Code
26843     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26844  */
26845 \end_layout
26846
26847 \begin_layout LyX-Code
26848 ...
26849 \end_layout
26850
26851 \begin_layout LyX-Code
26852 }
26853 \end_layout
26854
26855 \begin_layout Description
26856 shadowregs
26857 \begin_inset LatexCommand \index{PIC16!shadowregs}
26858
26859 \end_inset
26860
26861  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26862  hardware shadow registers which hold the values of WREG, STATUS and BSR
26863  registers.
26864  This can be done by adding the keyword 
26865 \emph on
26866 shadowregs
26867 \emph default
26868  before the 
26869 \emph on
26870 interrupt
26871 \emph default
26872  keyword in the function's header.
26873 \end_layout
26874
26875 \begin_layout LyX-Code
26876 void isr_shadow(void) shadowregs interrupt 1
26877 \end_layout
26878
26879 \begin_layout LyX-Code
26880 {
26881 \end_layout
26882
26883 \begin_layout LyX-Code
26884 ...
26885 \end_layout
26886
26887 \begin_layout LyX-Code
26888 }
26889 \end_layout
26890
26891 \begin_layout Standard
26892
26893 \emph on
26894 shadowregs
26895 \emph default
26896  instructs the code generator not to store/restore WREG, STATUS, BSR when
26897  entering/exiting the ISR.
26898 \end_layout
26899
26900 \begin_layout Subsection
26901 Function return values
26902 \end_layout
26903
26904 \begin_layout Standard
26905 Return values from functions are placed to the appropriate registers following
26906  a modified Microchip policy optimized for SDCC.
26907  The following table shows these registers:
26908 \end_layout
26909
26910 \begin_layout Standard
26911 \align center
26912 \begin_inset Tabular
26913 <lyxtabular version="3" rows="6" columns="2">
26914 <features>
26915 <column alignment="center" valignment="top" leftline="true" width="0">
26916 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26917 <row topline="true" bottomline="true">
26918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26919 \begin_inset Text
26920
26921 \begin_layout Standard
26922 size
26923 \end_layout
26924
26925 \end_inset
26926 </cell>
26927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26928 \begin_inset Text
26929
26930 \begin_layout Standard
26931 destination register
26932 \end_layout
26933
26934 \end_inset
26935 </cell>
26936 </row>
26937 <row topline="true">
26938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26939 \begin_inset Text
26940
26941 \begin_layout Standard
26942 8 bits
26943 \end_layout
26944
26945 \end_inset
26946 </cell>
26947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26948 \begin_inset Text
26949
26950 \begin_layout Standard
26951 WREG
26952 \end_layout
26953
26954 \end_inset
26955 </cell>
26956 </row>
26957 <row topline="true">
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26959 \begin_inset Text
26960
26961 \begin_layout Standard
26962 16 bits
26963 \end_layout
26964
26965 \end_inset
26966 </cell>
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26968 \begin_inset Text
26969
26970 \begin_layout Standard
26971 PRODL:WREG
26972 \end_layout
26973
26974 \end_inset
26975 </cell>
26976 </row>
26977 <row topline="true">
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26979 \begin_inset Text
26980
26981 \begin_layout Standard
26982 24 bits
26983 \end_layout
26984
26985 \end_inset
26986 </cell>
26987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26988 \begin_inset Text
26989
26990 \begin_layout Standard
26991 PRODH:PRODL:WREG
26992 \end_layout
26993
26994 \end_inset
26995 </cell>
26996 </row>
26997 <row topline="true">
26998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26999 \begin_inset Text
27000
27001 \begin_layout Standard
27002 32 bits
27003 \end_layout
27004
27005 \end_inset
27006 </cell>
27007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27008 \begin_inset Text
27009
27010 \begin_layout Standard
27011 FSR0L:PRODH:PRODL:WREG
27012 \end_layout
27013
27014 \end_inset
27015 </cell>
27016 </row>
27017 <row topline="true" bottomline="true">
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27019 \begin_inset Text
27020
27021 \begin_layout Standard
27022 >32 bits
27023 \end_layout
27024
27025 \end_inset
27026 </cell>
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27028 \begin_inset Text
27029
27030 \begin_layout Standard
27031 on stack, FSR0 points to the beginning
27032 \end_layout
27033
27034 \end_inset
27035 </cell>
27036 </row>
27037 </lyxtabular>
27038
27039 \end_inset
27040
27041
27042 \end_layout
27043
27044 \begin_layout Subsection
27045 Interrupts
27046 \end_layout
27047
27048 \begin_layout Standard
27049 An interrupt
27050 \begin_inset LatexCommand \index{PIC16!interrupt}
27051
27052 \end_inset
27053
27054  service routine (ISR) is declared using the 
27055 \emph on
27056 interrupt
27057 \emph default
27058  keyword.
27059 \end_layout
27060
27061 \begin_layout LyX-Code
27062 void isr(void) interrupt 
27063 \emph on
27064 n
27065 \end_layout
27066
27067 \begin_layout LyX-Code
27068 {
27069 \end_layout
27070
27071 \begin_layout LyX-Code
27072 ...
27073 \end_layout
27074
27075 \begin_layout LyX-Code
27076 }
27077 \end_layout
27078
27079 \begin_layout Standard
27080
27081 \emph on
27082 n
27083 \emph default
27084  is the interrupt number, which for PIC18F devices can be:
27085 \end_layout
27086
27087 \begin_layout Standard
27088 \align center
27089 \begin_inset Tabular
27090 <lyxtabular version="3" rows="4" columns="3">
27091 <features>
27092 <column alignment="center" valignment="top" leftline="true" width="0">
27093 <column alignment="center" valignment="top" leftline="true" width="0">
27094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27095 <row topline="true" bottomline="true">
27096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27097 \begin_inset Text
27098
27099 \begin_layout Standard
27100
27101 \emph on
27102 n
27103 \end_layout
27104
27105 \end_inset
27106 </cell>
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27108 \begin_inset Text
27109
27110 \begin_layout Standard
27111 Interrupt Vector
27112 \end_layout
27113
27114 \end_inset
27115 </cell>
27116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27117 \begin_inset Text
27118
27119 \begin_layout Standard
27120 Interrupt Vector Address
27121 \end_layout
27122
27123 \end_inset
27124 </cell>
27125 </row>
27126 <row topline="true">
27127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27128 \begin_inset Text
27129
27130 \begin_layout Standard
27131 0
27132 \end_layout
27133
27134 \end_inset
27135 </cell>
27136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27137 \begin_inset Text
27138
27139 \begin_layout Standard
27140 RESET vector
27141 \end_layout
27142
27143 \end_inset
27144 </cell>
27145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27146 \begin_inset Text
27147
27148 \begin_layout Standard
27149 0x000000
27150 \end_layout
27151
27152 \end_inset
27153 </cell>
27154 </row>
27155 <row topline="true">
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27157 \begin_inset Text
27158
27159 \begin_layout Standard
27160
27161 \family roman
27162 \series medium
27163 \shape up
27164 \size normal
27165 \emph off
27166 \bar no
27167 \noun off
27168 \color none
27169 1
27170 \end_layout
27171
27172 \end_inset
27173 </cell>
27174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27175 \begin_inset Text
27176
27177 \begin_layout Standard
27178
27179 \family roman
27180 \series medium
27181 \shape up
27182 \size normal
27183 \emph off
27184 \bar no
27185 \noun off
27186 \color none
27187 HIGH priority interrupts
27188 \end_layout
27189
27190 \end_inset
27191 </cell>
27192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27193 \begin_inset Text
27194
27195 \begin_layout Standard
27196 0x000008
27197 \end_layout
27198
27199 \end_inset
27200 </cell>
27201 </row>
27202 <row topline="true" bottomline="true">
27203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27204 \begin_inset Text
27205
27206 \begin_layout Standard
27207 2
27208 \end_layout
27209
27210 \end_inset
27211 </cell>
27212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27213 \begin_inset Text
27214
27215 \begin_layout Standard
27216 LOW priority interrupts
27217 \end_layout
27218
27219 \end_inset
27220 </cell>
27221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27222 \begin_inset Text
27223
27224 \begin_layout Standard
27225 0x000018
27226 \end_layout
27227
27228 \end_inset
27229 </cell>
27230 </row>
27231 </lyxtabular>
27232
27233 \end_inset
27234
27235
27236 \end_layout
27237
27238 \begin_layout Standard
27239 When generating assembly code for ISR the code generator places a 
27240 \noun on
27241 goto 
27242 \noun default
27243 instruction at the 
27244 \emph on
27245 Interrupt Vector Address
27246 \emph default
27247  which points at the genetated ISR.
27248  This single GOTO instruction is part of an automatically generated 
27249 \emph on
27250 interrupt entry point
27251 \emph default
27252  function.
27253  The actuall ISR code is placed as normally would in the code space.
27254  Upon interrupt request, the GOTO instruction is executed which jumps to
27255  the ISR code.
27256  When declaring interrupt functions as _naked this GOTO instruction is 
27257 \series bold
27258 not
27259 \series default
27260  generated.
27261  The whole interrupt functions is therefore placed at the Interrupt Vector
27262  Address of the specific interrupt.
27263  This is not a problem for the LOW priority interrupts, but it is a problem
27264  for the RESET and the HIGH priority interrupts because code may be written
27265  at the next interrupt's vector address and cause undeterminate program
27266  behaviour if that interrupt is raised.
27267 \begin_inset Foot
27268 status open
27269
27270 \begin_layout Standard
27271 This is not a problem when
27272 \end_layout
27273
27274 \begin_layout Enumerate
27275 this is a HIGH interrupt ISR and LOW interrupts are 
27276 \emph on
27277 disabled
27278 \emph default
27279  or not used.
27280 \end_layout
27281
27282 \begin_layout Enumerate
27283 when the ISR is small enough not to reach the next interrupt's vector address.
27284 \end_layout
27285
27286 \end_inset
27287
27288
27289 \end_layout
27290
27291 \begin_layout Standard
27292
27293 \emph on
27294 n
27295 \emph default
27296  may be omitted.
27297  This way a function is generated similar to an ISR, but it is not assigned
27298  to any interrupt.
27299 \end_layout
27300
27301 \begin_layout Standard
27302 When entering an interrupt, currently the PIC16
27303 \begin_inset LatexCommand \index{PIC16}
27304
27305 \end_inset
27306
27307  port automatically saves the following registers:
27308 \end_layout
27309
27310 \begin_layout Itemize
27311 WREG
27312 \end_layout
27313
27314 \begin_layout Itemize
27315 STATUS
27316 \end_layout
27317
27318 \begin_layout Itemize
27319 BSR
27320 \end_layout
27321
27322 \begin_layout Itemize
27323 PROD (PRODL and PRODH)
27324 \end_layout
27325
27326 \begin_layout Itemize
27327 FSR0 (FSR0L and FSR0H)
27328 \end_layout
27329
27330 \begin_layout Standard
27331 These registers are restored upon return from the interrupt routine.
27332 \begin_inset Foot
27333 status open
27334
27335 \begin_layout Standard
27336 NOTE that when the _naked attribute is specified for an interrupt routine,
27337  then NO registers are stored or restored.
27338 \end_layout
27339
27340 \end_inset
27341
27342
27343 \end_layout
27344
27345 \begin_layout Subsection
27346 Generic Pointers
27347 \end_layout
27348
27349 \begin_layout Standard
27350 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27351  There are 3 types of generic pointers currently implemented data, code
27352  and eeprom pointers.
27353  They are differentiated by the value of the 7th and 6th bits of the upper
27354  byte:
27355 \end_layout
27356
27357 \begin_layout Standard
27358 \align center
27359 \begin_inset Tabular
27360 <lyxtabular version="3" rows="5" columns="5">
27361 <features>
27362 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27363 <column alignment="center" valignment="top" width="0">
27364 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27365 <column alignment="center" valignment="top" width="0">
27366 <column alignment="left" valignment="top" rightline="true" width="0">
27367 <row topline="true" bottomline="true">
27368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27369 \begin_inset Text
27370
27371 \begin_layout Standard
27372 pointer type
27373 \end_layout
27374
27375 \end_inset
27376 </cell>
27377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27378 \begin_inset Text
27379
27380 \begin_layout Standard
27381 7th bit
27382 \end_layout
27383
27384 \end_inset
27385 </cell>
27386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27387 \begin_inset Text
27388
27389 \begin_layout Standard
27390 6th bit
27391 \end_layout
27392
27393 \end_inset
27394 </cell>
27395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27396 \begin_inset Text
27397
27398 \begin_layout Standard
27399 rest of the pointer
27400 \end_layout
27401
27402 \end_inset
27403 </cell>
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27405 \begin_inset Text
27406
27407 \begin_layout Standard
27408 description
27409 \end_layout
27410
27411 \end_inset
27412 </cell>
27413 </row>
27414 <row topline="true" bottomline="true">
27415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27416 \begin_inset Text
27417
27418 \begin_layout Standard
27419 data 
27420 \end_layout
27421
27422 \end_inset
27423 </cell>
27424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27425 \begin_inset Text
27426
27427 \begin_layout Standard
27428 1
27429 \end_layout
27430
27431 \end_inset
27432 </cell>
27433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27434 \begin_inset Text
27435
27436 \begin_layout Standard
27437 0
27438 \end_layout
27439
27440 \end_inset
27441 </cell>
27442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27443 \begin_inset Text
27444
27445 \begin_layout Standard
27446
27447 \family typewriter
27448 \shape slanted
27449 \emph on
27450 uuuuuu uuuuxxxx xxxxxxxx
27451 \end_layout
27452
27453 \end_inset
27454 </cell>
27455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27456 \begin_inset Text
27457
27458 \begin_layout Standard
27459 a 12-bit data pointer in data RAM memory
27460 \end_layout
27461
27462 \end_inset
27463 </cell>
27464 </row>
27465 <row bottomline="true">
27466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27467 \begin_inset Text
27468
27469 \begin_layout Standard
27470 code
27471 \end_layout
27472
27473 \end_inset
27474 </cell>
27475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27476 \begin_inset Text
27477
27478 \begin_layout Standard
27479 0
27480 \end_layout
27481
27482 \end_inset
27483 </cell>
27484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27485 \begin_inset Text
27486
27487 \begin_layout Standard
27488 0
27489 \end_layout
27490
27491 \end_inset
27492 </cell>
27493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27494 \begin_inset Text
27495
27496 \begin_layout Standard
27497
27498 \family typewriter
27499 \shape slanted
27500 \emph on
27501 uxxxxx xxxxxxxx xxxxxxxx
27502 \end_layout
27503
27504 \end_inset
27505 </cell>
27506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27507 \begin_inset Text
27508
27509 \begin_layout Standard
27510 a 21-bit code pointer in FLASH memory
27511 \end_layout
27512
27513 \end_inset
27514 </cell>
27515 </row>
27516 <row bottomline="true">
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27518 \begin_inset Text
27519
27520 \begin_layout Standard
27521 eeprom
27522 \end_layout
27523
27524 \end_inset
27525 </cell>
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27527 \begin_inset Text
27528
27529 \begin_layout Standard
27530 0
27531 \end_layout
27532
27533 \end_inset
27534 </cell>
27535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27536 \begin_inset Text
27537
27538 \begin_layout Standard
27539 1
27540 \end_layout
27541
27542 \end_inset
27543 </cell>
27544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27545 \begin_inset Text
27546
27547 \begin_layout Standard
27548
27549 \family typewriter
27550 \shape slanted
27551 \emph on
27552 uuuuuu uuuuuuxx xxxxxxxx
27553 \end_layout
27554
27555 \end_inset
27556 </cell>
27557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27558 \begin_inset Text
27559
27560 \begin_layout Standard
27561 a 10-bit eeprom pointer in EEPROM memory
27562 \end_layout
27563
27564 \end_inset
27565 </cell>
27566 </row>
27567 <row bottomline="true">
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27569 \begin_inset Text
27570
27571 \begin_layout Standard
27572 (unimplemented)
27573 \end_layout
27574
27575 \end_inset
27576 </cell>
27577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27578 \begin_inset Text
27579
27580 \begin_layout Standard
27581 1
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 1
27591 \end_layout
27592
27593 \end_inset
27594 </cell>
27595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27596 \begin_inset Text
27597
27598 \begin_layout Standard
27599
27600 \family typewriter
27601 \shape slanted
27602 \emph on
27603 xxxxxx xxxxxxxx xxxxxxxx
27604 \end_layout
27605
27606 \end_inset
27607 </cell>
27608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27609 \begin_inset Text
27610
27611 \begin_layout Standard
27612 unimplemented pointer type
27613 \end_layout
27614
27615 \end_inset
27616 </cell>
27617 </row>
27618 </lyxtabular>
27619
27620 \end_inset
27621
27622
27623 \end_layout
27624
27625 \begin_layout Standard
27626 \noindent
27627 Generic pointer are read and written with a set of library functions which
27628  read/write 1, 2, 3, 4 bytes.
27629 \end_layout
27630
27631 \begin_layout Subsection
27632 PIC16 C Libraries
27633 \end_layout
27634
27635 \begin_layout Subsubsection
27636 Standard I/O Streams
27637 \end_layout
27638
27639 \begin_layout Standard
27640 In the 
27641 \emph on
27642 stdio.h
27643 \emph default
27644  the type FILE is defined as:
27645 \end_layout
27646
27647 \begin_layout LyX-Code
27648 typedef char * FILE;
27649 \end_layout
27650
27651 \begin_layout Standard
27652 This type is the stream type implemented I/O in the PIC18F devices.
27653  Also the standard input and output streams are declared in stdio.h:
27654 \end_layout
27655
27656 \begin_layout LyX-Code
27657 extern FILE * stdin;
27658 \end_layout
27659
27660 \begin_layout LyX-Code
27661 extern FILE * stdout;
27662 \end_layout
27663
27664 \begin_layout Standard
27665 The FILE type is actually a generic pointer which defines one more type
27666  of generic pointers, the 
27667 \emph on
27668 stream 
27669 \emph default
27670 pointer.
27671  This new type has the format:
27672 \end_layout
27673
27674 \begin_layout Standard
27675 \noindent
27676 \align center
27677 \begin_inset Tabular
27678 <lyxtabular version="3" rows="2" columns="7">
27679 <features>
27680 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27681 <column alignment="center" valignment="top" width="0">
27682 <column alignment="center" valignment="top" leftline="true" width="0">
27683 <column alignment="center" valignment="top" leftline="true" width="0">
27684 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27685 <column alignment="center" valignment="top" width="0">
27686 <column alignment="left" valignment="top" rightline="true" width="0">
27687 <row topline="true" bottomline="true">
27688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27689 \begin_inset Text
27690
27691 \begin_layout Standard
27692 pointer type
27693 \end_layout
27694
27695 \end_inset
27696 </cell>
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27698 \begin_inset Text
27699
27700 \begin_layout Standard
27701 <7:6>
27702 \end_layout
27703
27704 \end_inset
27705 </cell>
27706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27707 \begin_inset Text
27708
27709 \begin_layout Standard
27710 <5>
27711 \end_layout
27712
27713 \end_inset
27714 </cell>
27715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27716 \begin_inset Text
27717
27718 \begin_layout Standard
27719 <4>
27720 \end_layout
27721
27722 \end_inset
27723 </cell>
27724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27725 \begin_inset Text
27726
27727 \begin_layout Standard
27728 <3:0>
27729 \end_layout
27730
27731 \end_inset
27732 </cell>
27733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27734 \begin_inset Text
27735
27736 \begin_layout Standard
27737 rest of the pointer
27738 \end_layout
27739
27740 \end_inset
27741 </cell>
27742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27743 \begin_inset Text
27744
27745 \begin_layout Standard
27746 descrption
27747 \end_layout
27748
27749 \end_inset
27750 </cell>
27751 </row>
27752 <row topline="true" bottomline="true">
27753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27754 \begin_inset Text
27755
27756 \begin_layout Standard
27757 stream
27758 \end_layout
27759
27760 \end_inset
27761 </cell>
27762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27763 \begin_inset Text
27764
27765 \begin_layout Standard
27766 00
27767 \end_layout
27768
27769 \end_inset
27770 </cell>
27771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27772 \begin_inset Text
27773
27774 \begin_layout Standard
27775 1
27776 \end_layout
27777
27778 \end_inset
27779 </cell>
27780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27781 \begin_inset Text
27782
27783 \begin_layout Standard
27784 0
27785 \end_layout
27786
27787 \end_inset
27788 </cell>
27789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27790 \begin_inset Text
27791
27792 \begin_layout Standard
27793 nnnn
27794 \end_layout
27795
27796 \end_inset
27797 </cell>
27798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27799 \begin_inset Text
27800
27801 \begin_layout Standard
27802
27803 \family typewriter
27804 \shape slanted
27805 \emph on
27806 uuuuuuuu uuuuuuuu
27807 \end_layout
27808
27809 \end_inset
27810 </cell>
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27812 \begin_inset Text
27813
27814 \begin_layout Standard
27815 upper byte high nubble is 0x2n, the rest are zeroes
27816 \end_layout
27817
27818 \end_inset
27819 </cell>
27820 </row>
27821 </lyxtabular>
27822
27823 \end_inset
27824
27825
27826 \end_layout
27827
27828 \begin_layout Standard
27829 \noindent
27830 Currently implemented there are 3 types of streams defined:
27831 \end_layout
27832
27833 \begin_layout Standard
27834 \noindent
27835 \align center
27836 \begin_inset Tabular
27837 <lyxtabular version="3" rows="4" columns="4">
27838 <features>
27839 <column alignment="center" valignment="top" leftline="true" width="0">
27840 <column alignment="center" valignment="top" leftline="true" width="0">
27841 <column alignment="center" valignment="top" leftline="true" width="0">
27842 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27843 <row topline="true" bottomline="true">
27844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27845 \begin_inset Text
27846
27847 \begin_layout Standard
27848 stream type
27849 \end_layout
27850
27851 \end_inset
27852 </cell>
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27854 \begin_inset Text
27855
27856 \begin_layout Standard
27857 value
27858 \end_layout
27859
27860 \end_inset
27861 </cell>
27862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27863 \begin_inset Text
27864
27865 \begin_layout Standard
27866 module
27867 \end_layout
27868
27869 \end_inset
27870 </cell>
27871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27872 \begin_inset Text
27873
27874 \begin_layout Standard
27875 description
27876 \end_layout
27877
27878 \end_inset
27879 </cell>
27880 </row>
27881 <row topline="true">
27882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27883 \begin_inset Text
27884
27885 \begin_layout Standard
27886 STREAM_USART
27887 \end_layout
27888
27889 \end_inset
27890 </cell>
27891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27892 \begin_inset Text
27893
27894 \begin_layout Standard
27895
27896 \family typewriter
27897 0x200000UL
27898 \end_layout
27899
27900 \end_inset
27901 </cell>
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27903 \begin_inset Text
27904
27905 \begin_layout Standard
27906 USART
27907 \end_layout
27908
27909 \end_inset
27910 </cell>
27911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27912 \begin_inset Text
27913
27914 \begin_layout Standard
27915 Writes/Reads characters via the USART peripheral
27916 \end_layout
27917
27918 \end_inset
27919 </cell>
27920 </row>
27921 <row topline="true">
27922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27923 \begin_inset Text
27924
27925 \begin_layout Standard
27926 STREAM_MSSP
27927 \end_layout
27928
27929 \end_inset
27930 </cell>
27931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27932 \begin_inset Text
27933
27934 \begin_layout Standard
27935
27936 \family typewriter
27937 0x210000UL
27938 \end_layout
27939
27940 \end_inset
27941 </cell>
27942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27943 \begin_inset Text
27944
27945 \begin_layout Standard
27946 MSSP
27947 \end_layout
27948
27949 \end_inset
27950 </cell>
27951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27952 \begin_inset Text
27953
27954 \begin_layout Standard
27955 Writes/Reads characters via the MSSP peripheral
27956 \end_layout
27957
27958 \end_inset
27959 </cell>
27960 </row>
27961 <row topline="true" bottomline="true">
27962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27963 \begin_inset Text
27964
27965 \begin_layout Standard
27966 STREAM_USER
27967 \end_layout
27968
27969 \end_inset
27970 </cell>
27971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27972 \begin_inset Text
27973
27974 \begin_layout Standard
27975
27976 \family typewriter
27977 0x2f0000UL
27978 \end_layout
27979
27980 \end_inset
27981 </cell>
27982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27983 \begin_inset Text
27984
27985 \begin_layout Standard
27986 (none)
27987 \end_layout
27988
27989 \end_inset
27990 </cell>
27991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27992 \begin_inset Text
27993
27994 \begin_layout Standard
27995 Writes/Reads characters via used defined functions
27996 \end_layout
27997
27998 \end_inset
27999 </cell>
28000 </row>
28001 </lyxtabular>
28002
28003 \end_inset
28004
28005
28006 \end_layout
28007
28008 \begin_layout Standard
28009 \noindent
28010 The stream identifiers are declared as macros in the stdio.h header.
28011 \end_layout
28012
28013 \begin_layout Standard
28014 \noindent
28015 In the libc library there exist the functions that are used to write to
28016  each of the above streams.
28017  These are
28018 \end_layout
28019
28020 \begin_layout Description
28021 _
28022 \begin_inset ERT
28023 status collapsed
28024
28025 \begin_layout Standard
28026
28027
28028 \backslash
28029 /
28030 \end_layout
28031
28032 \end_inset
28033
28034 _stream_usart_putchar writes a character at the USART stream
28035 \end_layout
28036
28037 \begin_layout Description
28038 _
28039 \begin_inset ERT
28040 status collapsed
28041
28042 \begin_layout Standard
28043
28044
28045 \backslash
28046 /
28047 \end_layout
28048
28049 \end_inset
28050
28051 _stream_mssp_putchar writes a character at the MSSP stream
28052 \end_layout
28053
28054 \begin_layout Description
28055 putchar dummy function.
28056  This writes a character to a user specified manner.
28057 \end_layout
28058
28059 \begin_layout Standard
28060 In order to increase performance 
28061 \emph on
28062 putchar 
28063 \emph default
28064 is declared in stdio.h as having its parameter in WREG (it has the wparam
28065  keyword).
28066  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
28067  in a user-friendly way.
28068  
28069 \emph on
28070 arg
28071 \emph default
28072  is the name of the variable that holds the character to print.
28073  An example follows:
28074 \end_layout
28075
28076 \begin_layout LyX-Code
28077 #include <pic18fregs.h>
28078 \newline
28079 #include <stdio.h>
28080 \newline
28081
28082 \newline
28083 PUTCHAR( c )
28084 \end_layout
28085
28086 \begin_layout LyX-Code
28087 {
28088 \end_layout
28089
28090 \begin_layout LyX-Code
28091     PORTA = c;    /* dump character c to PORTA */
28092 \end_layout
28093
28094 \begin_layout LyX-Code
28095
28096 \newline
28097
28098 \newline
28099 void main(void)
28100 \end_layout
28101
28102 \begin_layout LyX-Code
28103 {
28104 \end_layout
28105
28106 \begin_layout LyX-Code
28107     stdout = STREAM_USER;    /* this is not necessary, since stdout points
28108 \end_layout
28109
28110 \begin_layout LyX-Code
28111                               * by default to STREAM_USER */
28112 \end_layout
28113
28114 \begin_layout LyX-Code
28115     printf (
28116 \begin_inset Quotes sld
28117 \end_inset
28118
28119 This is a printf test
28120 \backslash
28121 n
28122 \begin_inset Quotes srd
28123 \end_inset
28124
28125 );
28126 \end_layout
28127
28128 \begin_layout LyX-Code
28129 }
28130 \end_layout
28131
28132 \begin_layout LyX-Code
28133
28134 \end_layout
28135
28136 \begin_layout Subsubsection
28137 Printing functions
28138 \end_layout
28139
28140 \begin_layout Standard
28141 PIC16 contains an implementation of the printf-family of functions.
28142  There exist the following functions:
28143 \end_layout
28144
28145 \begin_layout LyX-Code
28146 extern unsigned int sprintf(char *buf, char *fmt, ...);
28147 \end_layout
28148
28149 \begin_layout LyX-Code
28150 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28151 \end_layout
28152
28153 \begin_layout LyX-Code
28154
28155 \end_layout
28156
28157 \begin_layout LyX-Code
28158 extern unsigned int printf(char *fmt, ...);
28159 \end_layout
28160
28161 \begin_layout LyX-Code
28162 extern unsigned int vprintf(char *fmt, va_lista ap);
28163 \end_layout
28164
28165 \begin_layout LyX-Code
28166
28167 \end_layout
28168
28169 \begin_layout LyX-Code
28170 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28171 \end_layout
28172
28173 \begin_layout LyX-Code
28174 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28175 \end_layout
28176
28177 \begin_layout Standard
28178 For sprintf and vsprintf 
28179 \emph on
28180 buf 
28181 \emph default
28182 should normally be a data pointer where the resulting string will be placed.
28183  No range checking is done so the user should allocate the necessery buffer.
28184  For fprintf and vfprintf 
28185 \emph on
28186 fp
28187 \emph default
28188  should be a stream pointer (i.e.
28189  stdout, STREAM_MSSP, etc...).
28190 \end_layout
28191
28192 \begin_layout Subsubsection
28193 Signals
28194 \end_layout
28195
28196 \begin_layout Standard
28197 The PIC18F family of microcontrollers supports a number of interrupt sources.
28198  A list of these interrupts is shown in the following table:
28199 \end_layout
28200
28201 \begin_layout Standard
28202 \align center
28203 \begin_inset Tabular
28204 <lyxtabular version="3" rows="11" columns="4">
28205 <features>
28206 <column alignment="left" valignment="top" leftline="true" width="0">
28207 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28208 <column alignment="left" valignment="top" leftline="true" width="0">
28209 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28210 <row topline="true" bottomline="true">
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28212 \begin_inset Text
28213
28214 \begin_layout Standard
28215 signal name
28216 \end_layout
28217
28218 \end_inset
28219 </cell>
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_inset Text
28222
28223 \begin_layout Standard
28224 description
28225 \end_layout
28226
28227 \end_inset
28228 </cell>
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28230 \begin_inset Text
28231
28232 \begin_layout Standard
28233 signal name
28234 \end_layout
28235
28236 \end_inset
28237 </cell>
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28239 \begin_inset Text
28240
28241 \begin_layout Standard
28242 descritpion
28243 \end_layout
28244
28245 \end_inset
28246 </cell>
28247 </row>
28248 <row topline="true">
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28250 \begin_inset Text
28251
28252 \begin_layout Standard
28253 SIG_RB
28254 \end_layout
28255
28256 \end_inset
28257 </cell>
28258 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28259 \begin_inset Text
28260
28261 \begin_layout Standard
28262 PORTB change interrupt
28263 \end_layout
28264
28265 \end_inset
28266 </cell>
28267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28268 \begin_inset Text
28269
28270 \begin_layout Standard
28271 SIG_EE
28272 \end_layout
28273
28274 \end_inset
28275 </cell>
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28277 \begin_inset Text
28278
28279 \begin_layout Standard
28280 EEPROM/FLASH write complete interrupt
28281 \end_layout
28282
28283 \end_inset
28284 </cell>
28285 </row>
28286 <row topline="true">
28287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28288 \begin_inset Text
28289
28290 \begin_layout Standard
28291 SIG_INT0
28292 \end_layout
28293
28294 \end_inset
28295 </cell>
28296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28297 \begin_inset Text
28298
28299 \begin_layout Standard
28300 INT0 external interrupt
28301 \end_layout
28302
28303 \end_inset
28304 </cell>
28305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28306 \begin_inset Text
28307
28308 \begin_layout Standard
28309 SIG_BCOL
28310 \end_layout
28311
28312 \end_inset
28313 </cell>
28314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28315 \begin_inset Text
28316
28317 \begin_layout Standard
28318 Bus collision interrupt
28319 \end_layout
28320
28321 \end_inset
28322 </cell>
28323 </row>
28324 <row topline="true">
28325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28326 \begin_inset Text
28327
28328 \begin_layout Standard
28329 SIG_INT1
28330 \end_layout
28331
28332 \end_inset
28333 </cell>
28334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28335 \begin_inset Text
28336
28337 \begin_layout Standard
28338 INT1 external interrupt
28339 \end_layout
28340
28341 \end_inset
28342 </cell>
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28344 \begin_inset Text
28345
28346 \begin_layout Standard
28347 SIG_LVD
28348 \end_layout
28349
28350 \end_inset
28351 </cell>
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28353 \begin_inset Text
28354
28355 \begin_layout Standard
28356 Low voltage detect interrupt
28357 \end_layout
28358
28359 \end_inset
28360 </cell>
28361 </row>
28362 <row topline="true">
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28364 \begin_inset Text
28365
28366 \begin_layout Standard
28367 SIG_INT2
28368 \end_layout
28369
28370 \end_inset
28371 </cell>
28372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28373 \begin_inset Text
28374
28375 \begin_layout Standard
28376 INT2 external interrupt
28377 \end_layout
28378
28379 \end_inset
28380 </cell>
28381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28382 \begin_inset Text
28383
28384 \begin_layout Standard
28385 SIG_PSP
28386 \end_layout
28387
28388 \end_inset
28389 </cell>
28390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28391 \begin_inset Text
28392
28393 \begin_layout Standard
28394 Parallel slave port interrupt
28395 \end_layout
28396
28397 \end_inset
28398 </cell>
28399 </row>
28400 <row topline="true">
28401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28402 \begin_inset Text
28403
28404 \begin_layout Standard
28405 SIG_CCP1
28406 \end_layout
28407
28408 \end_inset
28409 </cell>
28410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28411 \begin_inset Text
28412
28413 \begin_layout Standard
28414 CCP1 module interrupt
28415 \end_layout
28416
28417 \end_inset
28418 </cell>
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28420 \begin_inset Text
28421
28422 \begin_layout Standard
28423 SIG_AD
28424 \end_layout
28425
28426 \end_inset
28427 </cell>
28428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28429 \begin_inset Text
28430
28431 \begin_layout Standard
28432 AD convertion complete interrupt
28433 \end_layout
28434
28435 \end_inset
28436 </cell>
28437 </row>
28438 <row topline="true">
28439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28440 \begin_inset Text
28441
28442 \begin_layout Standard
28443 SIG_CCP2
28444 \end_layout
28445
28446 \end_inset
28447 </cell>
28448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28449 \begin_inset Text
28450
28451 \begin_layout Standard
28452 CCP2 module interrupt
28453 \end_layout
28454
28455 \end_inset
28456 </cell>
28457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28458 \begin_inset Text
28459
28460 \begin_layout Standard
28461 SIG_RC
28462 \end_layout
28463
28464 \end_inset
28465 </cell>
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28467 \begin_inset Text
28468
28469 \begin_layout Standard
28470 USART receive interrupt
28471 \end_layout
28472
28473 \end_inset
28474 </cell>
28475 </row>
28476 <row topline="true">
28477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28478 \begin_inset Text
28479
28480 \begin_layout Standard
28481 SIG_TMR0
28482 \end_layout
28483
28484 \end_inset
28485 </cell>
28486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28487 \begin_inset Text
28488
28489 \begin_layout Standard
28490 TMR0 overflow interrupt
28491 \end_layout
28492
28493 \end_inset
28494 </cell>
28495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28496 \begin_inset Text
28497
28498 \begin_layout Standard
28499 SIG_TX
28500 \end_layout
28501
28502 \end_inset
28503 </cell>
28504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28505 \begin_inset Text
28506
28507 \begin_layout Standard
28508 USART transmit interrupt
28509 \end_layout
28510
28511 \end_inset
28512 </cell>
28513 </row>
28514 <row topline="true">
28515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28516 \begin_inset Text
28517
28518 \begin_layout Standard
28519 SIG_TMR1
28520 \end_layout
28521
28522 \end_inset
28523 </cell>
28524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28525 \begin_inset Text
28526
28527 \begin_layout Standard
28528 TMR1 overflow interrupt
28529 \end_layout
28530
28531 \end_inset
28532 </cell>
28533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28534 \begin_inset Text
28535
28536 \begin_layout Standard
28537 SIG_MSSP
28538 \end_layout
28539
28540 \end_inset
28541 </cell>
28542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28543 \begin_inset Text
28544
28545 \begin_layout Standard
28546 SSP receive/transmit interrupt
28547 \end_layout
28548
28549 \end_inset
28550 </cell>
28551 </row>
28552 <row topline="true">
28553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28554 \begin_inset Text
28555
28556 \begin_layout Standard
28557 SIG_TMR2
28558 \end_layout
28559
28560 \end_inset
28561 </cell>
28562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28563 \begin_inset Text
28564
28565 \begin_layout Standard
28566 TMR2 matches PR2 interrupt
28567 \end_layout
28568
28569 \end_inset
28570 </cell>
28571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28572 \begin_inset Text
28573
28574 \begin_layout Standard
28575
28576 \end_layout
28577
28578 \end_inset
28579 </cell>
28580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28581 \begin_inset Text
28582
28583 \begin_layout Standard
28584
28585 \end_layout
28586
28587 \end_inset
28588 </cell>
28589 </row>
28590 <row topline="true" bottomline="true">
28591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28592 \begin_inset Text
28593
28594 \begin_layout Standard
28595 SIG_TMR3
28596 \end_layout
28597
28598 \end_inset
28599 </cell>
28600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28601 \begin_inset Text
28602
28603 \begin_layout Standard
28604 TMR3 overflow interrupt
28605 \end_layout
28606
28607 \end_inset
28608 </cell>
28609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28610 \begin_inset Text
28611
28612 \begin_layout Standard
28613
28614 \end_layout
28615
28616 \end_inset
28617 </cell>
28618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28619 \begin_inset Text
28620
28621 \begin_layout Standard
28622
28623 \end_layout
28624
28625 \end_inset
28626 </cell>
28627 </row>
28628 </lyxtabular>
28629
28630 \end_inset
28631
28632
28633 \end_layout
28634
28635 \begin_layout Standard
28636 \noindent
28637 The prototypes for these names are defined in the header file 
28638 \emph on
28639 signal.h
28640 \emph default
28641  .
28642 \end_layout
28643
28644 \begin_layout Standard
28645 \noindent
28646 In order to simplify signal handling, a number of macros is provided:
28647 \end_layout
28648
28649 \begin_layout List
28650 \labelwidthstring 00.00.0000
28651 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28652  high priority interrupts.
28653  
28654 \emph on
28655 name
28656 \emph default
28657  is the function name to use.
28658 \end_layout
28659
28660 \begin_layout List
28661 \labelwidthstring 00.00.0000
28662 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28663  low priority interrupt.
28664  
28665 \emph on
28666 name
28667 \emph default
28668  is the function name to use.
28669 \end_layout
28670
28671 \begin_layout List
28672 \labelwidthstring 00.00.0000
28673 DEF_HANDLER(sig,handler) define a handler for signal 
28674 \emph on
28675 sig.
28676 \end_layout
28677
28678 \begin_layout List
28679 \labelwidthstring 00.00.0000
28680 END_DEF end the declaration of the dispatch table.
28681 \end_layout
28682
28683 \begin_layout Standard
28684 Additionally there are two more macros to simplify the declaration of the
28685  signal handler:
28686 \end_layout
28687
28688 \begin_layout List
28689 \labelwidthstring 00.00.0000
28690
28691 \series medium
28692 SIGHANDLER(handler) 
28693 \series default
28694 this declares the function prototype for the 
28695 \emph on
28696 handler
28697 \emph default
28698  function.
28699 \end_layout
28700
28701 \begin_layout List
28702 \labelwidthstring 00.00.0000
28703 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28704 \end_layout
28705
28706 \begin_layout Standard
28707 An example of using the macros above is shown below:
28708 \end_layout
28709
28710 \begin_layout LyX-Code
28711 #include <pic18fregs.h>
28712 \end_layout
28713
28714 \begin_layout LyX-Code
28715 #include <signal.h>
28716 \newline
28717
28718 \newline
28719 DEF_INTHIGH(high_int)
28720 \end_layout
28721
28722 \begin_layout LyX-Code
28723 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28724 \end_layout
28725
28726 \begin_layout LyX-Code
28727 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28728 \end_layout
28729
28730 \begin_layout LyX-Code
28731 END_DEF
28732 \newline
28733
28734 \newline
28735 SIGHANDLER(_tmr0_handler)
28736 \end_layout
28737
28738 \begin_layout LyX-Code
28739 {
28740 \end_layout
28741
28742 \begin_layout LyX-Code
28743   /* action to be taken when timer 0 overflows */
28744 \end_layout
28745
28746 \begin_layout LyX-Code
28747 }
28748 \newline
28749
28750 \newline
28751 SIGHANDLERNAKED(_bcol_handler)
28752 \end_layout
28753
28754 \begin_layout LyX-Code
28755 {
28756 \end_layout
28757
28758 \begin_layout LyX-Code
28759   _asm
28760 \end_layout
28761
28762 \begin_layout LyX-Code
28763     /* action to be taken when bus collision occurs */
28764 \end_layout
28765
28766 \begin_layout LyX-Code
28767     retfie
28768 \end_layout
28769
28770 \begin_layout LyX-Code
28771  _endasm;
28772 \end_layout
28773
28774 \begin_layout LyX-Code
28775 }
28776 \end_layout
28777
28778 \begin_layout Standard
28779
28780 \series bold
28781 NOTES:
28782 \series default
28783  Special care should be taken when using the above scheme:
28784 \end_layout
28785
28786 \begin_layout Itemize
28787 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28788 \end_layout
28789
28790 \begin_layout Itemize
28791 when declaring SIGHANDLERNAKED handler never forget to use 
28792 \emph on
28793 retfie
28794 \emph default
28795  for proper returning.
28796 \end_layout
28797
28798 \begin_layout Subsection
28799 PIC16 Port -- Tips
28800 \end_layout
28801
28802 \begin_layout Standard
28803 Here you can find some general tips for compiling programs with SDCC/pic16.
28804 \end_layout
28805
28806 \begin_layout Subsubsection
28807 Stack size
28808 \end_layout
28809
28810 \begin_layout Standard
28811 The default stack
28812 \begin_inset LatexCommand \index{PIC16!stack}
28813
28814 \end_inset
28815
28816  size (that is 64 bytes) probably is enough for many programs.
28817  One must take care that when there are many levels of function nesting,
28818  or there is excessive usage of stack, its size should be extended.
28819  An example of such a case is the printf/sprintf family of functions.
28820  If you encounter problems like not being able to print integers, then you
28821  need to set the stack size around the maximum (256 for small stack model).
28822  The following diagram shows what happens when calling printf to print an
28823  integer:
28824 \end_layout
28825
28826 \begin_layout LyX-Code
28827 printf () --> ltoa () --> ultoa () --> divschar ()
28828 \end_layout
28829
28830 \begin_layout Standard
28831 It is should be understood that stack is easily consumed when calling complicate
28832 d functions.
28833  Using command line arguments like -
28834 \begin_inset ERT
28835 status collapsed
28836
28837 \begin_layout Standard
28838
28839
28840 \backslash
28841 /
28842 \end_layout
28843
28844 \end_inset
28845
28846 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28847  stack frames.
28848  Other ways to reduce stack usage may exist.
28849 \end_layout
28850
28851 \begin_layout Subsection
28852 Known Bugs
28853 \end_layout
28854
28855 \begin_layout Subsubsection
28856 Extended Instruction Set
28857 \end_layout
28858
28859 \begin_layout Standard
28860 The PIC16 port emits code which is incompatible with the extended instruction
28861  set available with many newer devices.
28862  Make sure to always explicitly disable it, usually using
28863 \end_layout
28864
28865 \begin_layout Standard
28866
28867 \family typewriter
28868 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
28869 \end_layout
28870
28871 \begin_layout Standard
28872 \noindent
28873 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
28874  instead of _XINST_OFF_4L.
28875 \end_layout
28876
28877 \begin_layout Subsubsection
28878 Regression Tests
28879 \end_layout
28880
28881 \begin_layout Standard
28882 The PIC16 port currently passes most but not all of the tests in SDCC's
28883  regression test
28884 \begin_inset LatexCommand \index{Regression test (PIC16)}
28885
28886 \end_inset
28887
28888  suite (see section 
28889 \begin_inset LatexCommand \ref{sec:Quality-control}
28890
28891 \end_inset
28892
28893 ), thus no automatic regression tests are currently performed for the PIC16
28894  target.
28895 \end_layout
28896
28897 \begin_layout Chapter
28898 Debugging
28899 \end_layout
28900
28901 \begin_layout Standard
28902 There are several approaches to debugging your code.
28903  This chapter is meant to show your options and to give detail on some of
28904  them:
28905 \newline
28906
28907 \newline
28908 When writing your code:
28909 \end_layout
28910
28911 \begin_layout Itemize
28912 write your code with debugging in mind (avoid duplicating code, put conceptually
28913  similar variables into structs, use structured code, have strategic points
28914  within your code where all variables are consistent, ...)
28915 \end_layout
28916
28917 \begin_layout Itemize
28918 run a syntax-checking tool like splint
28919 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28920
28921 \end_inset
28922
28923
28924 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28925
28926 \end_inset
28927
28928  (see -
28929 \begin_inset ERT
28930 status collapsed
28931
28932 \begin_layout Standard
28933
28934
28935 \backslash
28936 /
28937 \end_layout
28938
28939 \end_inset
28940
28941 -more-pedantic 
28942 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28943
28944 \end_inset
28945
28946 ) over the code.
28947 \end_layout
28948
28949 \begin_layout Itemize
28950 for the high level code use a C-compiler (like f.e.
28951  GCC) to compile run and debug the code on your host.
28952  See (see -
28953 \begin_inset ERT
28954 status collapsed
28955
28956 \begin_layout Standard
28957
28958
28959 \backslash
28960 /
28961 \end_layout
28962
28963 \end_inset
28964
28965 -more-pedantic 
28966 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28967
28968 \end_inset
28969
28970 ) on how to handle syntax extensions like __xdata, __at(), ...
28971  
28972 \end_layout
28973
28974 \begin_layout Itemize
28975 use another C-compiler to compile code for your target.
28976  Always an option but not recommended:) And not very likely to help you.
28977  If you seriously consider walking this path you should at least occasionally
28978  check portability of your code.
28979  Most commercial compiler vendors will offer an evaluation version so you
28980  can test compile your code or snippets of your code.
28981 \end_layout
28982
28983 \begin_layout Standard
28984 Debugging on a simulator:
28985 \end_layout
28986
28987 \begin_layout Itemize
28988 there is a separate section about SDCDB (section 
28989 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28990
28991 \end_inset
28992
28993 ) below.
28994 \end_layout
28995
28996 \begin_layout Itemize
28997 or (8051 specific) use a freeware/commercial simulator which interfaces
28998  to the AOMF
28999 \begin_inset LatexCommand \index{AOMF, AOMF51}
29000
29001 \end_inset
29002
29003  file (see 
29004 \begin_inset LatexCommand \ref{OMF file}
29005
29006 \end_inset
29007
29008 ) optionally generated by SDCC.
29009 \end_layout
29010
29011 \begin_layout Standard
29012 Debugging On-target: 
29013 \end_layout
29014
29015 \begin_layout Itemize
29016 use a MCU port pin to serially output debug data to the RS232 port of your
29017  host.
29018  You'll probably want some level shifting device typically involving a MAX232
29019  or similar IC.
29020  If the hardware serial port of the MCU is not available search for 'Software
29021  UART' in your favourite search machine.
29022 \end_layout
29023
29024 \begin_layout Itemize
29025 use an on-target monitor.
29026  In this context a monitor is a small program which usually accepts commands
29027  via a serial line and allows to set program counter, to single step through
29028  a program and read/write memory locations.
29029  For the 8051 good examples of monitors are paulmon and cmon51 (see section
29030  
29031 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
29032
29033 \end_inset
29034
29035 ).
29036 \end_layout
29037
29038 \begin_layout Itemize
29039 toggle MCU port pins at strategic points within your code and use an oscilloscop
29040 e.
29041  A 
29042 \emph on
29043 digital oscilloscope
29044 \emph default
29045
29046 \begin_inset LatexCommand \index{Oscilloscope}
29047
29048 \end_inset
29049
29050  with deep trace memory is really helpful especially if you have to debug
29051  a realtime application.
29052  If you need to monitor more pins than your oscilloscope provides you can
29053  sometimes get away with a small R-2R network.
29054  On a single channel oscilloscope you could f.e.
29055  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
29056 k
29057 \begin_inset Formula $\Omega$
29058 \end_inset
29059
29060  resistor and the other one by a 5\InsetSpace ~
29061 k
29062 \begin_inset Formula $\Omega$
29063 \end_inset
29064
29065  resistor to the oscilloscope probe (check output drive capability of the
29066  pins you want to monitor).
29067  If you need to monitor many more pins a 
29068 \emph on
29069 logic analyzer
29070 \emph default
29071  will be handy.
29072 \end_layout
29073
29074 \begin_layout Itemize
29075 use an ICE (
29076 \emph on
29077 i
29078 \emph default
29079
29080 \emph on
29081 c
29082 \emph default
29083 ircuit 
29084 \emph on
29085 e
29086 \emph default
29087 mulator
29088 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
29089
29090 \end_inset
29091
29092 ).
29093  Usually very expensive.
29094  And very nice to have too.
29095  And usually locks you (for years...) to the devices the ICE can emulate.
29096  
29097 \end_layout
29098
29099 \begin_layout Itemize
29100 use a remote debugger.
29101  In most 8-bit systems the symbol information is not available on the target,
29102  and a complete debugger is too bulky for the target system.
29103  Therefore usually a debugger on the host system connects to an on-target
29104  debugging stub which accepts only primitive commands.
29105  
29106 \newline
29107 Terms to enter into your favourite search engine could be 'remote debugging',
29108  'gdb stub' or 'inferior debugger'.
29109  (is there one?)
29110 \end_layout
29111
29112 \begin_layout Itemize
29113 use an on target hardware debugger.
29114  Some of the more modern MCUs include hardware support for setting break
29115  points and monitoring/changing variables by using dedicated hardware pins.
29116  This facility doesn't require additional code to run on the target and
29117  
29118 \emph on
29119 usually
29120 \emph default
29121  doesn't affect runtime behaviour until a breakpoint is hit.
29122  For the mcs51 most hardware debuggers use the AOMF
29123 \begin_inset LatexCommand \index{AOMF, AOMF51}
29124
29125 \end_inset
29126
29127  file (see 
29128 \begin_inset LatexCommand \ref{OMF file}
29129
29130 \end_inset
29131
29132 ) as input file.
29133  
29134 \end_layout
29135
29136 \begin_layout Standard
29137 Last not least:
29138 \end_layout
29139
29140 \begin_layout Itemize
29141 if you are not familiar with any of the following terms you're likely to
29142  run into problems rather sooner than later: 
29143 \emph on
29144 volatile
29145 \emph default
29146
29147 \emph on
29148 atomic
29149 \emph default
29150
29151 \emph on
29152 memory map
29153 \emph default
29154
29155 \emph on
29156 overlay
29157 \emph default
29158 .
29159  As an embedded programmer you 
29160 \emph on
29161 have
29162 \emph default
29163  to know them so why not look them up 
29164 \emph on
29165 before
29166 \emph default
29167  you have problems?)
29168 \end_layout
29169
29170 \begin_layout Itemize
29171 tell someone else about your problem (actually this is a surprisingly effective
29172  means to hunt down the bug even if the listener is not familiar with your
29173  environment).
29174  As 'failure to communicate' is probably one of the job-induced deformations
29175  of an embedded programmer this is highly encouraged.
29176 \end_layout
29177
29178 \begin_layout Section
29179 Debugging with SDCDB
29180 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29181
29182 \end_inset
29183
29184
29185 \begin_inset LatexCommand \index{SDCDB (debugger)}
29186
29187 \end_inset
29188
29189  
29190 \end_layout
29191
29192 \begin_layout Standard
29193 SDCC is distributed with a source level debugger
29194 \begin_inset LatexCommand \index{Debugger}
29195
29196 \end_inset
29197
29198 .
29199  The debugger uses a command line interface, the command repertoire of the
29200  debugger has been kept as close to gdb
29201 \begin_inset LatexCommand \index{gdb}
29202
29203 \end_inset
29204
29205  (the GNU debugger) as possible.
29206  The configuration and build process is part of the standard compiler installati
29207 on, which also builds and installs the debugger in the target directory
29208  specified during configuration.
29209  The debugger allows you debug BOTH at the C source and at the ASM source
29210  level.
29211 \end_layout
29212
29213 \begin_layout Subsection
29214 Compiling for Debugging
29215 \end_layout
29216
29217 \begin_layout Standard
29218 The -
29219 \begin_inset ERT
29220 status collapsed
29221
29222 \begin_layout Standard
29223
29224
29225 \backslash
29226 /
29227 \end_layout
29228
29229 \end_inset
29230
29231 -debug
29232 \begin_inset LatexCommand \index{-\/-debug}
29233
29234 \end_inset
29235
29236  option must be specified for all files for which debug information is to
29237  be generated.
29238  The compiler generates a .adb file for each of these files.
29239  The linker creates the .cdb
29240 \begin_inset LatexCommand \index{<file>.cdb}
29241
29242 \end_inset
29243
29244  file from the .adb
29245 \begin_inset LatexCommand \index{<file>.adb}
29246
29247 \end_inset
29248
29249  files and the address information.
29250  This .cdb is used by the debugger.
29251 \end_layout
29252
29253 \begin_layout Subsection
29254 How the Debugger Works
29255 \end_layout
29256
29257 \begin_layout Standard
29258 When the -
29259 \begin_inset ERT
29260 status collapsed
29261
29262 \begin_layout Standard
29263
29264
29265 \backslash
29266 /
29267 \end_layout
29268
29269 \end_inset
29270
29271 -debug option is specified the compiler generates extra symbol information
29272  some of which are put into the assembler source and some are put into the
29273  .adb file.
29274  Then the linker creates the .cdb file from the individual .adb files with
29275  the address information for the symbols.
29276  The debugger reads the symbolic information generated by the compiler &
29277  the address information generated by the linker.
29278  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29279  execution is controlled by the debugger.
29280  When a command is issued for the debugger, it translates it into appropriate
29281  commands for the simulator.
29282  (Currently SDCDM only connects to the simulator but 
29283 \emph on
29284 newcdb
29285 \emph default
29286  at 
29287 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29288
29289 \end_inset
29290
29291  is an effort to connect directly to the hardware.) 
29292 \end_layout
29293
29294 \begin_layout Subsection
29295 Starting the Debugger SDCDB
29296 \end_layout
29297
29298 \begin_layout Standard
29299 The debugger can be started using the following command line.
29300  (Assume the file you are debugging has the file name foo).
29301 \newline
29302
29303 \newline
29304
29305 \family sans
29306 \series bold
29307 sdcdb foo
29308 \newline
29309
29310 \family default
29311 \series default
29312
29313 \newline
29314 The debugger will look for the following files.
29315 \end_layout
29316
29317 \begin_layout Itemize
29318 foo.c - the source file.
29319 \end_layout
29320
29321 \begin_layout Itemize
29322 foo.cdb - the debugger symbol information file.
29323 \end_layout
29324
29325 \begin_layout Itemize
29326 foo.ihx - the Intel hex format
29327 \begin_inset LatexCommand \index{Intel hex format}
29328
29329 \end_inset
29330
29331  object file.
29332 \end_layout
29333
29334 \begin_layout Subsection
29335 SDCDB Command Line Options
29336 \end_layout
29337
29338 \begin_layout Itemize
29339 -
29340 \begin_inset ERT
29341 status collapsed
29342
29343 \begin_layout Standard
29344
29345
29346 \backslash
29347 /
29348 \end_layout
29349
29350 \end_inset
29351
29352 -directory=<source file directory> this option can used to specify the directory
29353  search list.
29354  The debugger will look into the directory list specified for source, cdb
29355  & ihx files.
29356  The items in the directory list must be separated by ':', e.g.
29357  if the source files can be in the directories /home/src1 and /home/src2,
29358  the -
29359 \begin_inset ERT
29360 status collapsed
29361
29362 \begin_layout Standard
29363
29364
29365 \backslash
29366 /
29367 \end_layout
29368
29369 \end_inset
29370
29371 -directory option should be -
29372 \begin_inset ERT
29373 status collapsed
29374
29375 \begin_layout Standard
29376
29377
29378 \backslash
29379 /
29380 \end_layout
29381
29382 \end_inset
29383
29384 -directory=/home/src1:/home/src2.
29385  Note there can be no spaces in the option.
29386  
29387 \end_layout
29388
29389 \begin_layout Itemize
29390 -cd <directory> - change to the <directory>.
29391 \end_layout
29392
29393 \begin_layout Itemize
29394 -fullname - used by GUI front ends.
29395 \end_layout
29396
29397 \begin_layout Itemize
29398 -cpu <cpu-type> - this argument is passed to the simulator please see the
29399  simulator docs for details.
29400 \end_layout
29401
29402 \begin_layout Itemize
29403 -X <Clock frequency > this options is passed to the simulator please see
29404  the simulator docs for details.
29405 \end_layout
29406
29407 \begin_layout Itemize
29408 -s <serial port file> passed to simulator see the simulator docs for details.
29409 \end_layout
29410
29411 \begin_layout Itemize
29412 -S <serial in,out> passed to simulator see the simulator docs for details.
29413 \end_layout
29414
29415 \begin_layout Itemize
29416 -k <port number> passed to simulator see the simulator docs for details.
29417 \end_layout
29418
29419 \begin_layout Subsection
29420 SDCDB Debugger Commands
29421 \end_layout
29422
29423 \begin_layout Standard
29424 As mentioned earlier the command interface for the debugger has been deliberatel
29425 y kept as close the GNU debugger gdb, as possible.
29426  This will help the integration with existing graphical user interfaces
29427  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29428  If you use a graphical user interface for the debugger you can skip this
29429  section.
29430 \end_layout
29431
29432 \begin_layout Subsubsection*
29433 break [line | file:line | function | file:function]
29434 \end_layout
29435
29436 \begin_layout Standard
29437 Set breakpoint at specified line or function:
29438 \newline
29439
29440 \newline
29441
29442 \family sans
29443 \series bold
29444 sdcdb>break 100 
29445 \newline
29446 sdcdb>break foo.c:100
29447 \newline
29448 sdcdb>break funcfoo
29449 \newline
29450 sdcdb>break foo.c:funcfoo
29451 \end_layout
29452
29453 \begin_layout Subsubsection*
29454 clear [line | file:line | function | file:function ]
29455 \end_layout
29456
29457 \begin_layout Standard
29458 Clear breakpoint at specified line or function:
29459 \newline
29460
29461 \newline
29462
29463 \family sans
29464 \series bold
29465 sdcdb>clear 100
29466 \newline
29467 sdcdb>clear foo.c:100
29468 \newline
29469 sdcdb>clear funcfoo
29470 \newline
29471 sdcdb>clear foo.c:funcfoo
29472 \end_layout
29473
29474 \begin_layout Subsubsection*
29475 continue
29476 \end_layout
29477
29478 \begin_layout Standard
29479 Continue program being debugged, after breakpoint.
29480 \end_layout
29481
29482 \begin_layout Subsubsection*
29483 finish
29484 \end_layout
29485
29486 \begin_layout Standard
29487 Execute till the end of the current function.
29488 \end_layout
29489
29490 \begin_layout Subsubsection*
29491 delete [n]
29492 \end_layout
29493
29494 \begin_layout Standard
29495 Delete breakpoint number 'n'.
29496  If used without any option clear ALL user defined break points.
29497 \end_layout
29498
29499 \begin_layout Subsubsection*
29500 info [break | stack | frame | registers ]
29501 \end_layout
29502
29503 \begin_layout Itemize
29504 info break - list all breakpoints
29505 \end_layout
29506
29507 \begin_layout Itemize
29508 info stack - show the function call stack.
29509 \end_layout
29510
29511 \begin_layout Itemize
29512 info frame - show information about the current execution frame.
29513 \end_layout
29514
29515 \begin_layout Itemize
29516 info registers - show content of all registers.
29517 \end_layout
29518
29519 \begin_layout Subsubsection*
29520 step
29521 \end_layout
29522
29523 \begin_layout Standard
29524 Step program until it reaches a different source line.
29525  Note: pressing <return> repeats the last command.
29526 \end_layout
29527
29528 \begin_layout Subsubsection*
29529 next
29530 \end_layout
29531
29532 \begin_layout Standard
29533 Step program, proceeding through subroutine calls.
29534 \end_layout
29535
29536 \begin_layout Subsubsection*
29537 run
29538 \end_layout
29539
29540 \begin_layout Standard
29541 Start debugged program.
29542 \end_layout
29543
29544 \begin_layout Subsubsection*
29545 ptype variable 
29546 \end_layout
29547
29548 \begin_layout Standard
29549 Print type information of the variable.
29550 \end_layout
29551
29552 \begin_layout Subsubsection*
29553 print variable
29554 \end_layout
29555
29556 \begin_layout Standard
29557 print value of variable.
29558 \end_layout
29559
29560 \begin_layout Subsubsection*
29561 file filename
29562 \end_layout
29563
29564 \begin_layout Standard
29565 load the given file name.
29566  Note this is an alternate method of loading file for debugging.
29567 \end_layout
29568
29569 \begin_layout Subsubsection*
29570 frame
29571 \end_layout
29572
29573 \begin_layout Standard
29574 print information about current frame.
29575 \end_layout
29576
29577 \begin_layout Subsubsection*
29578 set srcmode
29579 \end_layout
29580
29581 \begin_layout Standard
29582 Toggle between C source & assembly source.
29583 \end_layout
29584
29585 \begin_layout Subsubsection*
29586 ! simulator command
29587 \end_layout
29588
29589 \begin_layout Standard
29590 Send the string following '!' to the simulator, the simulator response is
29591  displayed.
29592  Note the debugger does not interpret the command being sent to the simulator,
29593  so if a command like 'go' is sent the debugger can loose its execution
29594  context and may display incorrect values.
29595 \end_layout
29596
29597 \begin_layout Subsubsection*
29598 quit
29599 \end_layout
29600
29601 \begin_layout Standard
29602 "Watch me now.
29603  Iam going Down.
29604  My name is Bobby Brown"
29605 \end_layout
29606
29607 \begin_layout Subsection
29608 Interfacing SDCDB with DDD
29609 \end_layout
29610
29611 \begin_layout Standard
29612 \begin_inset Note Note
29613 status collapsed
29614
29615 \begin_layout Standard
29616 The screenshot was converted from png to eps with: 
29617 \begin_inset Quotes sld
29618 \end_inset
29619
29620 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29621 \begin_inset Quotes srd
29622 \end_inset
29623
29624  which produces a pretty compact eps file which is free from compression
29625  artifacts.
29626 \end_layout
29627
29628 \begin_layout Standard
29629 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29630  as this broke the build system on Sourceforge (pdf-file was broken.
29631  pdflatex does not accept eps files).
29632 \end_layout
29633
29634 \end_inset
29635
29636
29637 \end_layout
29638
29639 \begin_layout Standard
29640 The 
29641 \emph on
29642 p
29643 \emph default
29644 ortable 
29645 \emph on
29646 n
29647 \emph default
29648 etwork 
29649 \emph on
29650 g
29651 \emph default
29652 raphics File 
29653 \size footnotesize
29654
29655 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29656
29657 \end_inset
29658
29659
29660 \size default
29661  shows a screenshot of a debugging session with DDD
29662 \begin_inset LatexCommand \index{DDD (debugger)}
29663
29664 \end_inset
29665
29666  (Unix only) on a simulated 8032.
29667  The debugging session might not run as smoothly as the screenshot suggests.
29668  The debugger allows setting of breakpoints, displaying and changing variables,
29669  single stepping through C and assembler code.
29670  
29671 \newline
29672 The source was compiled with 
29673 \family sans
29674 \series bold
29675
29676 \newline
29677
29678 \newline
29679 sdcc -
29680 \family default
29681 \series default
29682
29683 \begin_inset ERT
29684 status collapsed
29685
29686 \begin_layout Standard
29687
29688
29689 \backslash
29690 /
29691 \end_layout
29692
29693 \end_inset
29694
29695
29696 \family sans
29697 \series bold
29698 -debug ddd_example.c
29699 \family default
29700 \series default
29701  
29702 \family sans
29703 \series bold
29704
29705 \newline
29706
29707 \family default
29708 \series default
29709
29710 \newline
29711 and DDD was invoked with 
29712 \family sans
29713 \series bold
29714
29715 \newline
29716
29717 \newline
29718 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29719 \end_layout
29720
29721 \begin_layout Standard
29722 \begin_inset Note Note
29723 status open
29724
29725 \begin_layout Standard
29726 Check that the double quotes or an apostroph within the command line survive
29727  the LyX tool chain.
29728  Previously the apostrophs got slanted in the PDF output so a cut and paste
29729  did not work.
29730 \end_layout
29731
29732 \end_inset
29733
29734
29735 \end_layout
29736
29737 \begin_layout Subsection
29738 Interfacing SDCDB with XEmacs
29739 \begin_inset LatexCommand \index{XEmacs}
29740
29741 \end_inset
29742
29743
29744 \begin_inset LatexCommand \index{Emacs}
29745
29746 \end_inset
29747
29748
29749 \end_layout
29750
29751 \begin_layout Standard
29752 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29753  sdcdb.el and sdcdbsrc.el.
29754  These two files can be found in the $(prefix)/bin directory after the installat
29755 ion is complete.
29756  These files need to be loaded into XEmacs for the interface to work.
29757  This can be done at XEmacs startup time by inserting the following into
29758  your '.xemacs' file (which can be found in your HOME directory): 
29759 \newline
29760
29761 \newline
29762
29763 \family typewriter
29764 (load-file sdcdbsrc.el) 
29765 \family default
29766
29767 \newline
29768
29769 \newline
29770 .xemacs is a lisp file so the () around the command is REQUIRED.
29771  The files can also be loaded dynamically while XEmacs is running, set the
29772  environment variable 'EMACSLOADPATH' to the installation bin directory
29773  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29774  To start the interface enter the following command: 
29775 \newline
29776
29777 \newline
29778
29779 \family sans
29780 \series bold
29781 ESC-x sdcdbsrc
29782 \family default
29783 \series default
29784
29785 \newline
29786
29787 \newline
29788 You will prompted to enter the file name to be debugged.
29789  
29790 \newline
29791
29792 \newline
29793 The command line options that are passed to the simulator directly are
29794  bound to default values in the file sdcdbsrc.el.
29795  The variables are listed below, these values maybe changed as required.
29796 \end_layout
29797
29798 \begin_layout Itemize
29799 sdcdbsrc-cpu-type '51
29800 \end_layout
29801
29802 \begin_layout Itemize
29803 sdcdbsrc-frequency '11059200
29804 \end_layout
29805
29806 \begin_layout Itemize
29807 sdcdbsrc-serial nil
29808 \end_layout
29809
29810 \begin_layout Standard
29811 The following is a list of key mapping for the debugger interface.
29812 \end_layout
29813
29814 \begin_layout Standard
29815 \InsetSpace ~
29816
29817 \family typewriter
29818
29819 \newline
29820 ;;\InsetSpace ~
29821 Current Listing :: 
29822 \newline
29823 ;;key\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 binding\InsetSpace ~
29838 \InsetSpace ~
29839 \InsetSpace ~
29840 \InsetSpace ~
29841 \InsetSpace ~
29842 \InsetSpace ~
29843 \InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 \InsetSpace ~
29847 \InsetSpace ~
29848 \InsetSpace ~
29849 \InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 Comment 
29860 \newline
29861 ;;---\InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 \InsetSpace ~
29867 \InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 -------\InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 -------
29898 \newline
29899 ;; 
29900 \newline
29901 ;;\InsetSpace ~
29902 n\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 sdcdb-next-fro
29918 m-src\InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 SDCDB next command 
29929 \newline
29930 ;;\InsetSpace ~
29931 b\InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 \InsetSpace ~
29945 \InsetSpace ~
29946 sdcdb-back-from-src\InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 SDCDB back command 
29957 \newline
29958 ;;\InsetSpace ~
29959 c\InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 sdcdb-cont-f
29975 rom-src\InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 SDCDB continue command
29986 \newline
29987 ;;\InsetSpace ~
29988 s\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 sdcdb-step-from-src\InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 \InsetSpace ~
30013 SDCDB step command 
30014 \newline
30015 ;;\InsetSpace ~
30016 ?\InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 sdcdb-w
30032 hatis-c-sexp\InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \InsetSpace ~
30040 \InsetSpace ~
30041 \InsetSpace ~
30042 SDCDB ptypecommand for data at 
30043 \newline
30044 ;;\InsetSpace ~
30045 \InsetSpace ~
30046 \InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 \InsetSpace ~
30055 \InsetSpace ~
30056 \InsetSpace ~
30057 \InsetSpace ~
30058 \InsetSpace ~
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 \InsetSpace ~
30063 \InsetSpace ~
30064 \InsetSpace ~
30065 \InsetSpace ~
30066 \InsetSpace ~
30067 \InsetSpace ~
30068 \InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 buffer point 
30092 \newline
30093 ;;\InsetSpace ~
30094 x\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 sdcdbsrc-delete\InsetSpace ~
30110 \InsetSpace ~
30111 \InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 \InsetSpace ~
30123 SDCD
30124 B Delete all breakpoints if no arg 
30125 \newline
30126 ;;\InsetSpace ~
30127 \InsetSpace ~
30128 \InsetSpace ~
30129 \InsetSpace ~
30130 \InsetSpace ~
30131 \InsetSpace ~
30132 \InsetSpace ~
30133 \InsetSpace ~
30134 \InsetSpace ~
30135 \InsetSpace ~
30136 \InsetSpace ~
30137 \InsetSpace ~
30138 \InsetSpace ~
30139 \InsetSpace ~
30140 \InsetSpace ~
30141 \InsetSpace ~
30142 \InsetSpace ~
30143 \InsetSpace ~
30144 \InsetSpace ~
30145 \InsetSpace ~
30146 \InsetSpace ~
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150 \InsetSpace ~
30151 \InsetSpace ~
30152 \InsetSpace ~
30153 \InsetSpace ~
30154 \InsetSpace ~
30155 \InsetSpace ~
30156 \InsetSpace ~
30157 \InsetSpace ~
30158 \InsetSpace ~
30159 \InsetSpace ~
30160 \InsetSpace ~
30161 \InsetSpace ~
30162 \InsetSpace ~
30163 \InsetSpace ~
30164 \InsetSpace ~
30165 \InsetSpace ~
30166 \InsetSpace ~
30167 \InsetSpace ~
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 \InsetSpace ~
30171 \InsetSpace ~
30172 \InsetSpace ~
30173 given or delete arg (C-u arg x) 
30174 \newline
30175 ;;\InsetSpace ~
30176 m\InsetSpace ~
30177 \InsetSpace ~
30178 \InsetSpace ~
30179 \InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186 \InsetSpace ~
30187 \InsetSpace ~
30188 \InsetSpace ~
30189 \InsetSpace ~
30190 \InsetSpace ~
30191 sdcdbsrc
30192 -frame\InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 \InsetSpace ~
30199 \InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203 \InsetSpace ~
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 SDCDB Display current frame if no arg, 
30208 \newline
30209 ;;\InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 \InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 \InsetSpace ~
30218 \InsetSpace ~
30219 \InsetSpace ~
30220 \InsetSpace ~
30221 \InsetSpace ~
30222 \InsetSpace ~
30223 \InsetSpace ~
30224 \InsetSpace ~
30225 \InsetSpace ~
30226 \InsetSpace ~
30227 \InsetSpace ~
30228 \InsetSpace ~
30229 \InsetSpace ~
30230 \InsetSpace ~
30231 \InsetSpace ~
30232 \InsetSpace ~
30233 \InsetSpace ~
30234 \InsetSpace ~
30235 \InsetSpace ~
30236 \InsetSpace ~
30237 \InsetSpace ~
30238 \InsetSpace ~
30239 \InsetSpace ~
30240 \InsetSpace ~
30241 \InsetSpace ~
30242 \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256 given or display frame arg
30257  
30258 \newline
30259 ;;\InsetSpace ~
30260 \InsetSpace ~
30261 \InsetSpace ~
30262 \InsetSpace ~
30263 \InsetSpace ~
30264 \InsetSpace ~
30265 \InsetSpace ~
30266 \InsetSpace ~
30267 \InsetSpace ~
30268 \InsetSpace ~
30269 \InsetSpace ~
30270 \InsetSpace ~
30271 \InsetSpace ~
30272 \InsetSpace ~
30273 \InsetSpace ~
30274 \InsetSpace ~
30275 \InsetSpace ~
30276 \InsetSpace ~
30277 \InsetSpace ~
30278 \InsetSpace ~
30279 \InsetSpace ~
30280 \InsetSpace ~
30281 \InsetSpace ~
30282 \InsetSpace ~
30283 \InsetSpace ~
30284 \InsetSpace ~
30285 \InsetSpace ~
30286 \InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 \InsetSpace ~
30293 \InsetSpace ~
30294 \InsetSpace ~
30295 \InsetSpace ~
30296 \InsetSpace ~
30297 \InsetSpace ~
30298 \InsetSpace ~
30299 \InsetSpace ~
30300 \InsetSpace ~
30301 \InsetSpace ~
30302 \InsetSpace ~
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306 buffer point 
30307 \newline
30308 ;;\InsetSpace ~
30309 !\InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 \InsetSpace ~
30313 \InsetSpace ~
30314 \InsetSpace ~
30315 \InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 \InsetSpace ~
30322 \InsetSpace ~
30323 \InsetSpace ~
30324 sdcdbsrc-goto-sdcdb\InsetSpace ~
30325 \InsetSpace ~
30326 \InsetSpace ~
30327 \InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 \InsetSpace ~
30332 \InsetSpace ~
30333 \InsetSpace ~
30334 Goto the SDCDB output buffer 
30335 \newline
30336 ;;\InsetSpace ~
30337 p\InsetSpace ~
30338 \InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 \InsetSpace ~
30344 \InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 \InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 \InsetSpace ~
30351 \InsetSpace ~
30352 sdcdb-prin
30353 t-c-sexp\InsetSpace ~
30354 \InsetSpace ~
30355 \InsetSpace ~
30356 \InsetSpace ~
30357 \InsetSpace ~
30358 \InsetSpace ~
30359 \InsetSpace ~
30360 \InsetSpace ~
30361 \InsetSpace ~
30362 \InsetSpace ~
30363 \InsetSpace ~
30364 SDCDB print command for data at 
30365 \newline
30366 ;;\InsetSpace ~
30367 \InsetSpace ~
30368 \InsetSpace ~
30369 \InsetSpace ~
30370 \InsetSpace ~
30371 \InsetSpace ~
30372 \InsetSpace ~
30373 \InsetSpace ~
30374 \InsetSpace ~
30375 \InsetSpace ~
30376 \InsetSpace ~
30377 \InsetSpace ~
30378 \InsetSpace ~
30379 \InsetSpace ~
30380 \InsetSpace ~
30381 \InsetSpace ~
30382 \InsetSpace ~
30383 \InsetSpace ~
30384 \InsetSpace ~
30385 \InsetSpace ~
30386 \InsetSpace ~
30387 \InsetSpace ~
30388 \InsetSpace ~
30389 \InsetSpace ~
30390 \InsetSpace ~
30391 \InsetSpace ~
30392 \InsetSpace ~
30393 \InsetSpace ~
30394 \InsetSpace ~
30395 \InsetSpace ~
30396 \InsetSpace ~
30397 \InsetSpace ~
30398 \InsetSpace ~
30399 \InsetSpace ~
30400 \InsetSpace ~
30401 \InsetSpace ~
30402 \InsetSpace ~
30403 \InsetSpace ~
30404 \InsetSpace ~
30405 \InsetSpace ~
30406 \InsetSpace ~
30407 \InsetSpace ~
30408 \InsetSpace ~
30409 \InsetSpace ~
30410 \InsetSpace ~
30411 \InsetSpace ~
30412 \InsetSpace ~
30413 buffer point 
30414 \newline
30415 ;;\InsetSpace ~
30416 g\InsetSpace ~
30417 \InsetSpace ~
30418 \InsetSpace ~
30419 \InsetSpace ~
30420 \InsetSpace ~
30421 \InsetSpace ~
30422 \InsetSpace ~
30423 \InsetSpace ~
30424 \InsetSpace ~
30425 \InsetSpace ~
30426 \InsetSpace ~
30427 \InsetSpace ~
30428 \InsetSpace ~
30429 \InsetSpace ~
30430 \InsetSpace ~
30431 sdcdbsrc-goto-sdcdb\InsetSpace ~
30432 \InsetSpace ~
30433 \InsetSpace ~
30434 \InsetSpace ~
30435 \InsetSpace ~
30436 \InsetSpace ~
30437 \InsetSpace ~
30438 \InsetSpace ~
30439 \InsetSpace ~
30440 \InsetSpace ~
30441 Got
30442 o the SDCDB output buffer 
30443 \newline
30444 ;;\InsetSpace ~
30445 t\InsetSpace ~
30446 \InsetSpace ~
30447 \InsetSpace ~
30448 \InsetSpace ~
30449 \InsetSpace ~
30450 \InsetSpace ~
30451 \InsetSpace ~
30452 \InsetSpace ~
30453 \InsetSpace ~
30454 \InsetSpace ~
30455 \InsetSpace ~
30456 \InsetSpace ~
30457 \InsetSpace ~
30458 \InsetSpace ~
30459 \InsetSpace ~
30460 sdcdbsrc-mode\InsetSpace ~
30461 \InsetSpace ~
30462 \InsetSpace ~
30463 \InsetSpace ~
30464 \InsetSpace ~
30465 \InsetSpace ~
30466 \InsetSpace ~
30467 \InsetSpace ~
30468 \InsetSpace ~
30469 \InsetSpace ~
30470 \InsetSpace ~
30471 \InsetSpace ~
30472 \InsetSpace ~
30473 \InsetSpace ~
30474 \InsetSpace ~
30475 \InsetSpace ~
30476 Toggles Sdcdbsrc mode (turns it
30477  off) 
30478 \newline
30479 ;; 
30480 \newline
30481 ;;\InsetSpace ~
30482 C-c\InsetSpace ~
30483 C-f\InsetSpace ~
30484 \InsetSpace ~
30485 \InsetSpace ~
30486 \InsetSpace ~
30487 \InsetSpace ~
30488 \InsetSpace ~
30489 \InsetSpace ~
30490 \InsetSpace ~
30491 \InsetSpace ~
30492 sdcdb-finish-from-src\InsetSpace ~
30493 \InsetSpace ~
30494 \InsetSpace ~
30495 \InsetSpace ~
30496 \InsetSpace ~
30497 \InsetSpace ~
30498 \InsetSpace ~
30499 \InsetSpace ~
30500 SDCDB finish command 
30501 \newline
30502 ;; 
30503 \newline
30504 ;;\InsetSpace ~
30505 C-x\InsetSpace ~
30506 SPC\InsetSpace ~
30507 \InsetSpace ~
30508 \InsetSpace ~
30509 \InsetSpace ~
30510 \InsetSpace ~
30511 \InsetSpace ~
30512 \InsetSpace ~
30513 \InsetSpace ~
30514 \InsetSpace ~
30515 sdcdb-brea
30516 k\InsetSpace ~
30517 \InsetSpace ~
30518 \InsetSpace ~
30519 \InsetSpace ~
30520 \InsetSpace ~
30521 \InsetSpace ~
30522 \InsetSpace ~
30523 \InsetSpace ~
30524 \InsetSpace ~
30525 \InsetSpace ~
30526 \InsetSpace ~
30527 \InsetSpace ~
30528 \InsetSpace ~
30529 \InsetSpace ~
30530 \InsetSpace ~
30531 \InsetSpace ~
30532 \InsetSpace ~
30533 \InsetSpace ~
30534 Set break for line with point 
30535 \newline
30536 ;;\InsetSpace ~
30537 ESC\InsetSpace ~
30538 t\InsetSpace ~
30539 \InsetSpace ~
30540 \InsetSpace ~
30541 \InsetSpace ~
30542 \InsetSpace ~
30543 \InsetSpace ~
30544 \InsetSpace ~
30545 \InsetSpace ~
30546 \InsetSpace ~
30547 \InsetSpace ~
30548 \InsetSpace ~
30549 sdcdbsrc-mode\InsetSpace ~
30550 \InsetSpace ~
30551 \InsetSpace ~
30552 \InsetSpace ~
30553 \InsetSpace ~
30554 \InsetSpace ~
30555 \InsetSpace ~
30556 \InsetSpace ~
30557 \InsetSpace ~
30558 \InsetSpace ~
30559 \InsetSpace ~
30560 \InsetSpace ~
30561 \InsetSpace ~
30562 \InsetSpace ~
30563 \InsetSpace ~
30564 \InsetSpace ~
30565 Toggle Sdcdbsrc mode 
30566 \newline
30567 ;;\InsetSpace ~
30568 ESC\InsetSpace ~
30569 m\InsetSpace ~
30570 \InsetSpace ~
30571 \InsetSpace ~
30572 \InsetSpace ~
30573 \InsetSpace ~
30574 \InsetSpace ~
30575 \InsetSpace ~
30576 \InsetSpace ~
30577 \InsetSpace ~
30578 \InsetSpace ~
30579 \InsetSpace ~
30580 sdc
30581 dbsrc-srcmode\InsetSpace ~
30582 \InsetSpace ~
30583 \InsetSpace ~
30584 \InsetSpace ~
30585 \InsetSpace ~
30586 \InsetSpace ~
30587 \InsetSpace ~
30588 \InsetSpace ~
30589 \InsetSpace ~
30590 \InsetSpace ~
30591 \InsetSpace ~
30592 \InsetSpace ~
30593 \InsetSpace ~
30594 Toggle list mode 
30595 \newline
30596 ;; 
30597 \newline
30598
30599 \family default
30600
30601 \newpage
30602
30603 \end_layout
30604
30605 \begin_layout Chapter
30606 TIPS
30607 \end_layout
30608
30609 \begin_layout Standard
30610 Here are a few guidelines that will help the compiler generate more efficient
30611  code, some of the tips are specific to this compiler others are generally
30612  good programming practice.
30613 \end_layout
30614
30615 \begin_layout Itemize
30616 Use the smallest data type to represent your data-value.
30617  If it is known in advance that the value is going to be less than 256 then
30618  use an 'unsigned char' instead of a 'short' or 'int'.
30619  Please note, that ANSI C requires both signed and unsigned chars to be
30620  promoted to 'signed int'
30621 \begin_inset LatexCommand \index{promotion to signed int}
30622
30623 \end_inset
30624
30625
30626 \begin_inset Marginal
30627 status collapsed
30628
30629 \begin_layout Standard
30630
30631 \series bold
30632 \InsetSpace ~
30633 !
30634 \end_layout
30635
30636 \end_inset
30637
30638  before doing any operation.
30639  This promotion
30640 \begin_inset LatexCommand \index{type promotion}
30641
30642 \end_inset
30643
30644
30645 \begin_inset LatexCommand \label{type promotion}
30646
30647 \end_inset
30648
30649  can be omitted, if the result is the same.
30650  The effect of the promotion rules together with the sign-extension is often
30651  surprising:
30652 \end_layout
30653
30654 \begin_deeper
30655 \begin_layout Verse
30656
30657 \family typewriter
30658 unsigned char uc = 0xfe;
30659 \newline
30660 if (uc * uc < 0) /* this is true! */
30661 \newline
30662 {
30663 \newline
30664 \InsetSpace ~
30665 \InsetSpace ~
30666 \InsetSpace ~
30667 \InsetSpace ~
30668 ....
30669 \newline
30670 }
30671 \end_layout
30672
30673 \begin_layout Standard
30674
30675 \family typewriter
30676 uc * uc
30677 \family default
30678  is evaluated as 
30679 \family typewriter
30680 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30681 \family default
30682 .
30683  
30684 \newline
30685 Another one:
30686 \end_layout
30687
30688 \begin_layout Verse
30689
30690 \family typewriter
30691 (unsigned char) -12 / (signed char) -3 = ...
30692 \end_layout
30693
30694 \begin_layout Standard
30695 No, the result is not 4:
30696 \end_layout
30697
30698 \begin_layout Verse
30699
30700 \family typewriter
30701 (int) (unsigned char) -12 / (int) (signed char) -3 =
30702 \newline
30703 (int) (unsigned char)
30704  0xf4 / (int) (signed char) 0xfd =
30705 \newline
30706 (int) 0x00f4 / (int) 0xfffd =
30707 \newline
30708 (int) 0x00f4
30709  / (int) 0xfffd =
30710 \newline
30711 (int) 244 / (int) -3 =
30712 \newline
30713 (int) -81 = (int) 0xffaf;
30714 \end_layout
30715
30716 \begin_layout Standard
30717 Don't complain, that gcc gives you a different result.
30718  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30719  Therefore the results are different.
30720 \newline
30721 From 
30722 \begin_inset Quotes sld
30723 \end_inset
30724
30725 comp.lang.c FAQ
30726 \begin_inset Quotes srd
30727 \end_inset
30728
30729 :
30730 \end_layout
30731
30732 \begin_layout Quote
30733
30734 \emph on
30735 If well-defined overflow characteristics are important and negative values
30736  are not, or if you want to steer clear of sign-extension problems when
30737  manipulating bits or bytes, use one of the corresponding unsigned types.
30738  (Beware when mixing signed and unsigned values in expressions, though.)
30739 \newline
30740 Although
30741  character types (especially unsigned char) can be used as "tiny" integers,
30742  doing so is sometimes more trouble than it's worth, due to unpredictable
30743  sign extension and increased code size.
30744 \end_layout
30745
30746 \end_deeper
30747 \begin_layout Itemize
30748 Use unsigned when it is known in advance that the value is not going to
30749  be negative.
30750  This helps especially if you are doing division or multiplication, bit-shifting
30751  or are using an array index.
30752 \end_layout
30753
30754 \begin_layout Itemize
30755 NEVER jump into a LOOP.
30756 \end_layout
30757
30758 \begin_layout Itemize
30759 Declare the variables to be local
30760 \begin_inset LatexCommand \index{local variables}
30761
30762 \end_inset
30763
30764  whenever possible, especially loop control variables (induction).
30765 \end_layout
30766
30767 \begin_layout Itemize
30768 Have a look at the assembly listing to get a 
30769 \begin_inset Quotes sld
30770 \end_inset
30771
30772 feeling
30773 \begin_inset Quotes srd
30774 \end_inset
30775
30776  for the code generation.
30777 \end_layout
30778
30779 \begin_layout Section
30780 Porting code from or to other compilers
30781 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30782
30783 \end_inset
30784
30785
30786 \end_layout
30787
30788 \begin_layout Itemize
30789 check whether endianness of the compilers differs and adapt where needed.
30790 \end_layout
30791
30792 \begin_layout Itemize
30793 check the device specific header files
30794 \begin_inset LatexCommand \index{Header files}
30795
30796 \end_inset
30797
30798
30799 \begin_inset LatexCommand \index{Include files}
30800
30801 \end_inset
30802
30803  for compiler specific syntax.
30804  Eventually include the file <compiler.h
30805 \begin_inset LatexCommand \index{compiler.h (include file)}
30806
30807 \end_inset
30808
30809
30810 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30811
30812 \end_inset
30813
30814  to allow using common header files.
30815  (see f.e.
30816  cc2510fx.h 
30817 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30818
30819 \end_inset
30820
30821 ).
30822 \end_layout
30823
30824 \begin_layout Itemize
30825 check whether the startup code contains the correct initialization (watchdog,
30826  peripherals).
30827 \end_layout
30828
30829 \begin_layout Itemize
30830 check whether the sizes of short, int, long match.
30831 \end_layout
30832
30833 \begin_layout Itemize
30834 check if some 16 or 32 bit hardware registers require a specific addressing
30835  order (least significant or most significant byte first) and adapt if needed
30836  (
30837 \emph on
30838 first
30839 \emph default
30840  and 
30841 \emph on
30842 last
30843 \emph default
30844  relate to time and not to lower/upper memory location here, so this is
30845  
30846 \emph on
30847 not
30848 \emph default
30849  the same as endianness).
30850 \end_layout
30851
30852 \begin_layout Itemize
30853 check whether the keyword 
30854 \emph on
30855 volatile
30856 \emph default
30857  is used where needed.
30858  The compilers might differ in their optimization characteristics (as different
30859  versions of the same compiler might also use more clever optimizations
30860  this is good idea anyway).
30861  See section 
30862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30863
30864 \end_inset
30865
30866 .
30867 \end_layout
30868
30869 \begin_layout Itemize
30870 check that the compilers are not told to supress warnings.
30871 \end_layout
30872
30873 \begin_layout Itemize
30874 check and convert compiler specific extensions (interrupts, memory areas,
30875  pragmas etc.).
30876 \end_layout
30877
30878 \begin_layout Itemize
30879 check for differences in type promotion.
30880  Especially check for math operations on 
30881 \family typewriter
30882 char
30883 \family default
30884  or 
30885 \family typewriter
30886 unsigned char
30887 \family default
30888  variables.
30889  For the sake of C99 compatibility SDCC will probably promote these to 
30890 \family typewriter
30891 int
30892 \family default
30893  more often than other compilers.
30894  Eventually insert explicit casts to 
30895 \family typewriter
30896 (char) 
30897 \family default
30898 or
30899 \family typewriter
30900  (unsigned char)
30901 \family default
30902 .
30903  Also check that the ~\InsetSpace ~
30904 operator
30905 \begin_inset LatexCommand \index{\~\/ Operator}
30906
30907 \end_inset
30908
30909  is not used on 
30910 \family typewriter
30911 bit
30912 \begin_inset LatexCommand \index{bit}
30913
30914 \end_inset
30915
30916
30917 \family default
30918  variables, use the !\InsetSpace ~
30919 operator instead.
30920  See sections 
30921 \begin_inset LatexCommand \ref{type promotion}
30922
30923 \end_inset
30924
30925  and 
30926 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30927
30928 \end_inset
30929
30930 .
30931 \end_layout
30932
30933 \begin_layout Itemize
30934 check the assembly code generated for interrupt routines (f.e.
30935  for calls to possibly non-reentrant library functions).
30936 \end_layout
30937
30938 \begin_layout Itemize
30939 check whether timing loops result in proper timing (or preferably consider
30940  a rewrite of the code with timer based delays instead).
30941 \end_layout
30942
30943 \begin_layout Itemize
30944 check for differences in printf parameters (some compilers push (va_arg
30945 \begin_inset LatexCommand \index{vararg, va\_arg}
30946
30947 \end_inset
30948
30949 ) char variables as 
30950 \family typewriter
30951 int
30952 \family default
30953  others push them as 
30954 \family typewriter
30955 char
30956 \family default
30957 .
30958  See section 
30959 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30960
30961 \end_inset
30962
30963 ).
30964 \end_layout
30965
30966 \begin_layout Itemize
30967 check the resulting memory map
30968 \begin_inset LatexCommand \index{Memory map}
30969
30970 \end_inset
30971
30972 .
30973  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30974 ly idata, pdata, xdata).
30975  Eventually check if unexpected library functions are included.
30976 \end_layout
30977
30978 \begin_layout Section
30979 Tools
30980 \begin_inset LatexCommand \index{Tools}
30981
30982 \end_inset
30983
30984  included in the distribution
30985 \end_layout
30986
30987 \begin_layout Standard
30988 \align left
30989 \begin_inset Tabular
30990 <lyxtabular version="3" rows="12" columns="3">
30991 <features>
30992 <column alignment="left" valignment="top" leftline="true" width="0pt">
30993 <column alignment="left" valignment="top" leftline="true" width="0pt">
30994 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30995 <row topline="true" bottomline="true">
30996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30997 \begin_inset Text
30998
30999 \begin_layout Standard
31000
31001 \series bold
31002 Name
31003 \end_layout
31004
31005 \end_inset
31006 </cell>
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31008 \begin_inset Text
31009
31010 \begin_layout Standard
31011
31012 \series bold
31013 Purpose
31014 \end_layout
31015
31016 \end_inset
31017 </cell>
31018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31019 \begin_inset Text
31020
31021 \begin_layout Standard
31022
31023 \series bold
31024 Directory
31025 \end_layout
31026
31027 \end_inset
31028 </cell>
31029 </row>
31030 <row topline="true">
31031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31032 \begin_inset Text
31033
31034 \begin_layout Standard
31035 uCsim
31036 \begin_inset LatexCommand \index{uCsim}
31037
31038 \end_inset
31039
31040
31041 \end_layout
31042
31043 \end_inset
31044 </cell>
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31046 \begin_inset Text
31047
31048 \begin_layout Standard
31049 Simulator for various architectures
31050 \end_layout
31051
31052 \end_inset
31053 </cell>
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31055 \begin_inset Text
31056
31057 \begin_layout Standard
31058 sdcc/sim/ucsim
31059 \end_layout
31060
31061 \end_inset
31062 </cell>
31063 </row>
31064 <row topline="true">
31065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31066 \begin_inset Text
31067
31068 \begin_layout Standard
31069 keil2sdcc.pl
31070 \end_layout
31071
31072 \end_inset
31073 </cell>
31074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31075 \begin_inset Text
31076
31077 \begin_layout Standard
31078 header file
31079 \begin_inset LatexCommand \index{Header files}
31080
31081 \end_inset
31082
31083
31084 \begin_inset LatexCommand \index{Include files}
31085
31086 \end_inset
31087
31088  conversion
31089 \end_layout
31090
31091 \end_inset
31092 </cell>
31093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31094 \begin_inset Text
31095
31096 \begin_layout Standard
31097 sdcc/support/scripts
31098 \end_layout
31099
31100 \end_inset
31101 </cell>
31102 </row>
31103 <row topline="true">
31104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31105 \begin_inset Text
31106
31107 \begin_layout Standard
31108 mh2h.c
31109 \end_layout
31110
31111 \end_inset
31112 </cell>
31113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_inset Text
31115
31116 \begin_layout Standard
31117 header file conversion
31118 \end_layout
31119
31120 \end_inset
31121 </cell>
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31123 \begin_inset Text
31124
31125 \begin_layout Standard
31126 sdcc/support/scripts
31127 \end_layout
31128
31129 \end_inset
31130 </cell>
31131 </row>
31132 <row topline="true">
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31134 \begin_inset Text
31135
31136 \begin_layout Standard
31137 as-gbz80
31138 \end_layout
31139
31140 \end_inset
31141 </cell>
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31143 \begin_inset Text
31144
31145 \begin_layout Standard
31146 Assembler
31147 \end_layout
31148
31149 \end_inset
31150 </cell>
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \begin_layout Standard
31155
31156 \family roman
31157 \series medium
31158 \shape up
31159 \size normal
31160 \emph off
31161 \bar no
31162 \noun off
31163 \color none
31164 sdcc/bin
31165 \end_layout
31166
31167 \end_inset
31168 </cell>
31169 </row>
31170 <row topline="true">
31171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31172 \begin_inset Text
31173
31174 \begin_layout Standard
31175 as-z80
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184 Assembler
31185 \end_layout
31186
31187 \end_inset
31188 </cell>
31189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31190 \begin_inset Text
31191
31192 \begin_layout Standard
31193
31194 \family roman
31195 \series medium
31196 \shape up
31197 \size normal
31198 \emph off
31199 \bar no
31200 \noun off
31201 \color none
31202 sdcc/bin
31203 \end_layout
31204
31205 \end_inset
31206 </cell>
31207 </row>
31208 <row topline="true">
31209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31210 \begin_inset Text
31211
31212 \begin_layout Standard
31213 asx8051
31214 \end_layout
31215
31216 \end_inset
31217 </cell>
31218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31219 \begin_inset Text
31220
31221 \begin_layout Standard
31222 Assembler
31223 \end_layout
31224
31225 \end_inset
31226 </cell>
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31228 \begin_inset Text
31229
31230 \begin_layout Standard
31231
31232 \family roman
31233 \series medium
31234 \shape up
31235 \size normal
31236 \emph off
31237 \bar no
31238 \noun off
31239 \color none
31240 sdcc/bin
31241 \end_layout
31242
31243 \end_inset
31244 </cell>
31245 </row>
31246 <row topline="true">
31247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31248 \begin_inset Text
31249
31250 \begin_layout Standard
31251 SDCDB
31252 \end_layout
31253
31254 \end_inset
31255 </cell>
31256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31257 \begin_inset Text
31258
31259 \begin_layout Standard
31260 Simulator
31261 \end_layout
31262
31263 \end_inset
31264 </cell>
31265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31266 \begin_inset Text
31267
31268 \begin_layout Standard
31269
31270 \family roman
31271 \series medium
31272 \shape up
31273 \size normal
31274 \emph off
31275 \bar no
31276 \noun off
31277 \color none
31278 sdcc/bin
31279 \end_layout
31280
31281 \end_inset
31282 </cell>
31283 </row>
31284 <row topline="true">
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289 aslink
31290 \end_layout
31291
31292 \end_inset
31293 </cell>
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31295 \begin_inset Text
31296
31297 \begin_layout Standard
31298 Linker
31299 \end_layout
31300
31301 \end_inset
31302 </cell>
31303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31304 \begin_inset Text
31305
31306 \begin_layout Standard
31307
31308 \family roman
31309 \series medium
31310 \shape up
31311 \size normal
31312 \emph off
31313 \bar no
31314 \noun off
31315 \color none
31316 sdcc/bin
31317 \end_layout
31318
31319 \end_inset
31320 </cell>
31321 </row>
31322 <row topline="true">
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31324 \begin_inset Text
31325
31326 \begin_layout Standard
31327 link-z80
31328 \end_layout
31329
31330 \end_inset
31331 </cell>
31332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31333 \begin_inset Text
31334
31335 \begin_layout Standard
31336 Linker
31337 \end_layout
31338
31339 \end_inset
31340 </cell>
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31342 \begin_inset Text
31343
31344 \begin_layout Standard
31345
31346 \family roman
31347 \series medium
31348 \shape up
31349 \size normal
31350 \emph off
31351 \bar no
31352 \noun off
31353 \color none
31354 sdcc/bin
31355 \end_layout
31356
31357 \end_inset
31358 </cell>
31359 </row>
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365 link-gbz80
31366 \end_layout
31367
31368 \end_inset
31369 </cell>
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31371 \begin_inset Text
31372
31373 \begin_layout Standard
31374 Linker
31375 \end_layout
31376
31377 \end_inset
31378 </cell>
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31380 \begin_inset Text
31381
31382 \begin_layout Standard
31383
31384 \family roman
31385 \series medium
31386 \shape up
31387 \size normal
31388 \emph off
31389 \bar no
31390 \noun off
31391 \color none
31392 sdcc/bin
31393 \end_layout
31394
31395 \end_inset
31396 </cell>
31397 </row>
31398 <row topline="true" bottomline="true">
31399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31400 \begin_inset Text
31401
31402 \begin_layout Standard
31403 packihx
31404 \end_layout
31405
31406 \end_inset
31407 </cell>
31408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31409 \begin_inset Text
31410
31411 \begin_layout Standard
31412 Intel Hex packer 
31413 \begin_inset LatexCommand \index{packihx (tool)}
31414
31415 \end_inset
31416
31417
31418 \end_layout
31419
31420 \end_inset
31421 </cell>
31422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31423 \begin_inset Text
31424
31425 \begin_layout Standard
31426
31427 \family roman
31428 \series medium
31429 \shape up
31430 \size normal
31431 \emph off
31432 \bar no
31433 \noun off
31434 \color none
31435 sdcc/bin
31436 \end_layout
31437
31438 \end_inset
31439 </cell>
31440 </row>
31441 </lyxtabular>
31442
31443 \end_inset
31444
31445
31446 \newline
31447
31448 \end_layout
31449
31450 \begin_layout Section
31451 Documentation
31452 \begin_inset LatexCommand \index{Documentation}
31453
31454 \end_inset
31455
31456  included in the distribution
31457 \end_layout
31458
31459 \begin_layout Standard
31460 \align left
31461 \begin_inset Tabular
31462 <lyxtabular version="3" rows="10" columns="2">
31463 <features>
31464 <column alignment="block" valignment="top" leftline="true" width="40col%">
31465 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31466 <row topline="true" bottomline="true" endhead="true">
31467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31468 \begin_inset Text
31469
31470 \begin_layout Standard
31471
31472 \series bold
31473 Subject / Title
31474 \end_layout
31475
31476 \end_inset
31477 </cell>
31478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31479 \begin_inset Text
31480
31481 \begin_layout Standard
31482
31483 \series bold
31484 Filename / Where to get
31485 \end_layout
31486
31487 \end_inset
31488 </cell>
31489 </row>
31490 <row topline="true">
31491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31492 \begin_inset Text
31493
31494 \begin_layout Standard
31495 SDCC Compiler User Guide
31496 \end_layout
31497
31498 \end_inset
31499 </cell>
31500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31501 \begin_inset Text
31502
31503 \begin_layout Standard
31504 You're reading it right now
31505 \emph on
31506  \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509
31510 \hfill
31511 online at:
31512 \emph default
31513
31514 \newline
31515
31516 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31517
31518 \end_inset
31519
31520
31521 \end_layout
31522
31523 \end_inset
31524 </cell>
31525 </row>
31526 <row topline="true">
31527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31528 \begin_inset Text
31529
31530 \begin_layout Standard
31531 Changelog of SDCC
31532 \end_layout
31533
31534 \end_inset
31535 </cell>
31536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31537 \begin_inset Text
31538
31539 \begin_layout Standard
31540 sdcc/Changelog
31541 \emph on
31542  \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545
31546 \hfill
31547 online at:
31548 \emph default
31549
31550 \newline
31551
31552 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31553
31554 \end_inset
31555
31556
31557 \end_layout
31558
31559 \end_inset
31560 </cell>
31561 </row>
31562 <row topline="true">
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31564 \begin_inset Text
31565
31566 \begin_layout Standard
31567 ASXXXX
31568 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31569
31570 \end_inset
31571
31572
31573 \begin_inset LatexCommand \index{Assembler documentation}
31574
31575 \end_inset
31576
31577  Assemblers and
31578 \newline
31579 ASLINK
31580 \begin_inset LatexCommand \index{aslink}
31581
31582 \end_inset
31583
31584
31585 \begin_inset LatexCommand \index{Linker documentation}
31586
31587 \end_inset
31588
31589  Relocating Linker
31590 \end_layout
31591
31592 \end_inset
31593 </cell>
31594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31595 \begin_inset Text
31596
31597 \begin_layout Standard
31598 sdcc/as/doc/asxhtm.html 
31599 \emph on
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603
31604 \hfill
31605 online at:
31606 \emph default
31607
31608 \newline
31609
31610 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31611
31612 \end_inset
31613
31614
31615 \end_layout
31616
31617 \end_inset
31618 </cell>
31619 </row>
31620 <row topline="true">
31621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31622 \begin_inset Text
31623
31624 \begin_layout Standard
31625 SDCC regression test
31626 \begin_inset LatexCommand \index{Regression test}
31627
31628 \end_inset
31629
31630
31631 \end_layout
31632
31633 \end_inset
31634 </cell>
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31636 \begin_inset Text
31637
31638 \begin_layout Standard
31639 sdcc/doc/test_suite_spec.pdf 
31640 \emph on
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644
31645 \hfill
31646 online at:
31647 \emph default
31648
31649 \newline
31650
31651 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31652
31653 \end_inset
31654
31655
31656 \end_layout
31657
31658 \end_inset
31659 </cell>
31660 </row>
31661 <row topline="true">
31662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31663 \begin_inset Text
31664
31665 \begin_layout Standard
31666 Various notes
31667 \end_layout
31668
31669 \end_inset
31670 </cell>
31671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31672 \begin_inset Text
31673
31674 \begin_layout Standard
31675 sdcc/doc/* 
31676 \emph on
31677 \InsetSpace ~
31678 \InsetSpace ~
31679 \InsetSpace ~
31680
31681 \hfill
31682 online at:
31683 \emph default
31684
31685 \newline
31686
31687 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31688
31689 \end_inset
31690
31691
31692 \end_layout
31693
31694 \end_inset
31695 </cell>
31696 </row>
31697 <row topline="true">
31698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31699 \begin_inset Text
31700
31701 \begin_layout Standard
31702 Notes on debugging with SDCDB
31703 \begin_inset LatexCommand \index{SDCDB (debugger)}
31704
31705 \end_inset
31706
31707
31708 \end_layout
31709
31710 \end_inset
31711 </cell>
31712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31713 \begin_inset Text
31714
31715 \begin_layout Standard
31716 sdcc/debugger/README 
31717 \emph on
31718 \InsetSpace ~
31719 \InsetSpace ~
31720 \InsetSpace ~
31721
31722 \hfill
31723 online at
31724 \emph default
31725 :
31726 \newline
31727
31728 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31729
31730 \end_inset
31731
31732
31733 \end_layout
31734
31735 \end_inset
31736 </cell>
31737 </row>
31738 <row topline="true">
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31740 \begin_inset Text
31741
31742 \begin_layout Standard
31743 uCsim
31744 \begin_inset LatexCommand \index{uCsim}
31745
31746 \end_inset
31747
31748  Software simulator for microcontrollers
31749 \end_layout
31750
31751 \end_inset
31752 </cell>
31753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31754 \begin_inset Text
31755
31756 \begin_layout Standard
31757
31758 \family roman
31759 \series medium
31760 \shape up
31761 \size normal
31762 \emph off
31763 \bar no
31764 \noun off
31765 \color none
31766 sdcc/sim/ucsim/doc
31767 \family default
31768 \series default
31769 \shape default
31770 \size default
31771 \emph default
31772 \bar default
31773 \noun default
31774 /index.html 
31775 \emph on
31776 \InsetSpace ~
31777 \InsetSpace ~
31778 \InsetSpace ~
31779
31780 \hfill
31781 online at:
31782 \emph default
31783
31784 \newline
31785
31786 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31787
31788 \end_inset
31789
31790
31791 \end_layout
31792
31793 \end_inset
31794 </cell>
31795 </row>
31796 <row topline="true">
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31798 \begin_inset Text
31799
31800 \begin_layout Standard
31801 Temporary notes on the pic16
31802 \begin_inset LatexCommand \index{PIC16}
31803
31804 \end_inset
31805
31806  port
31807 \end_layout
31808
31809 \end_inset
31810 </cell>
31811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31812 \begin_inset Text
31813
31814 \begin_layout Standard
31815 sdcc/src/pic16/NOTES 
31816 \emph on
31817 \InsetSpace ~
31818 \InsetSpace ~
31819 \InsetSpace ~
31820
31821 \hfill
31822 online at:
31823 \newline
31824
31825 \emph default
31826
31827 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31828
31829 \end_inset
31830
31831
31832 \end_layout
31833
31834 \end_inset
31835 </cell>
31836 </row>
31837 <row topline="true" bottomline="true">
31838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31839 \begin_inset Text
31840
31841 \begin_layout Standard
31842 SDCC internal documentation (debugging file format)
31843 \end_layout
31844
31845 \end_inset
31846 </cell>
31847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31848 \begin_inset Text
31849
31850 \begin_layout Standard
31851 sdcc/doc/
31852 \family roman
31853 \series medium
31854 \shape up
31855 \size normal
31856 \emph off
31857 \bar no
31858 \noun off
31859 \color none
31860 cdbfileformat.pd
31861 \family default
31862 \series default
31863 \shape default
31864 \size default
31865 \emph default
31866 \bar default
31867 \noun default
31868 f
31869 \emph on
31870  \InsetSpace ~
31871 \InsetSpace ~
31872 \InsetSpace ~
31873
31874 \hfill
31875 online at:
31876 \emph default
31877
31878 \newline
31879
31880 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31881
31882 \end_inset
31883
31884
31885 \end_layout
31886
31887 \end_inset
31888 </cell>
31889 </row>
31890 </lyxtabular>
31891
31892 \end_inset
31893
31894
31895 \newline
31896
31897 \end_layout
31898
31899 \begin_layout Section
31900 Related open source tools
31901 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31902
31903 \end_inset
31904
31905
31906 \begin_inset LatexCommand \index{Related tools}
31907
31908 \end_inset
31909
31910
31911 \end_layout
31912
31913 \begin_layout Standard
31914 \align left
31915 \begin_inset Tabular
31916 <lyxtabular version="3" rows="16" columns="3">
31917 <features>
31918 <column alignment="left" valignment="top" leftline="true" width="0pt">
31919 <column alignment="block" valignment="top" leftline="true" width="30line%">
31920 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31921 <row topline="true" bottomline="true">
31922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31923 \begin_inset Text
31924
31925 \begin_layout Standard
31926
31927 \series bold
31928 Name
31929 \end_layout
31930
31931 \end_inset
31932 </cell>
31933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31934 \begin_inset Text
31935
31936 \begin_layout Standard
31937
31938 \series bold
31939 Purpose
31940 \end_layout
31941
31942 \end_inset
31943 </cell>
31944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31945 \begin_inset Text
31946
31947 \begin_layout Standard
31948
31949 \series bold
31950 Where to get
31951 \end_layout
31952
31953 \end_inset
31954 </cell>
31955 </row>
31956 <row topline="true">
31957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31958 \begin_inset Text
31959
31960 \begin_layout Standard
31961 gpsim
31962 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31963
31964 \end_inset
31965
31966
31967 \end_layout
31968
31969 \end_inset
31970 </cell>
31971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31972 \begin_inset Text
31973
31974 \begin_layout Standard
31975 PIC simulator
31976 \end_layout
31977
31978 \end_inset
31979 </cell>
31980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31981 \begin_inset Text
31982
31983 \begin_layout Standard
31984 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31985
31986 \end_inset
31987
31988
31989 \end_layout
31990
31991 \end_inset
31992 </cell>
31993 </row>
31994 <row topline="true">
31995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31996 \begin_inset Text
31997
31998 \begin_layout Standard
31999 gputils
32000 \begin_inset LatexCommand \index{gputils (pic tools)}
32001
32002 \end_inset
32003
32004
32005 \end_layout
32006
32007 \end_inset
32008 </cell>
32009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32010 \begin_inset Text
32011
32012 \begin_layout Standard
32013 GNU PIC utilities
32014 \end_layout
32015
32016 \end_inset
32017 </cell>
32018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32019 \begin_inset Text
32020
32021 \begin_layout Standard
32022 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
32023
32024 \end_inset
32025
32026
32027 \end_layout
32028
32029 \end_inset
32030 </cell>
32031 </row>
32032 <row topline="true">
32033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32034 \begin_inset Text
32035
32036 \begin_layout Standard
32037 flP5
32038 \end_layout
32039
32040 \end_inset
32041 </cell>
32042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32043 \begin_inset Text
32044
32045 \begin_layout Standard
32046 PIC programmer
32047 \end_layout
32048
32049 \end_inset
32050 </cell>
32051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32052 \begin_inset Text
32053
32054 \begin_layout Standard
32055 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
32056
32057 \end_inset
32058
32059
32060 \end_layout
32061
32062 \end_inset
32063 </cell>
32064 </row>
32065 <row topline="true">
32066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32067 \begin_inset Text
32068
32069 \begin_layout Standard
32070 ec2drv/newcdb
32071 \end_layout
32072
32073 \end_inset
32074 </cell>
32075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32076 \begin_inset Text
32077
32078 \begin_layout Standard
32079 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
32080  (Unix only)
32081 \end_layout
32082
32083 \end_inset
32084 </cell>
32085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32086 \begin_inset Text
32087
32088 \begin_layout Standard
32089 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
32090
32091 \end_inset
32092
32093
32094 \end_layout
32095
32096 \end_inset
32097 </cell>
32098 </row>
32099 <row topline="true">
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32101 \begin_inset Text
32102
32103 \begin_layout Standard
32104 indent
32105 \begin_inset LatexCommand \index{indent (source formatting tool)}
32106
32107 \end_inset
32108
32109
32110 \end_layout
32111
32112 \end_inset
32113 </cell>
32114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32115 \begin_inset Text
32116
32117 \begin_layout Standard
32118 Formats C source - Master of the white spaces
32119 \end_layout
32120
32121 \end_inset
32122 </cell>
32123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32124 \begin_inset Text
32125
32126 \begin_layout Standard
32127 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
32128
32129 \end_inset
32130
32131
32132 \end_layout
32133
32134 \end_inset
32135 </cell>
32136 </row>
32137 <row topline="true">
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32139 \begin_inset Text
32140
32141 \begin_layout Standard
32142 srecord
32143 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32144
32145 \end_inset
32146
32147
32148 \end_layout
32149
32150 \end_inset
32151 </cell>
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32153 \begin_inset Text
32154
32155 \begin_layout Standard
32156 Object file conversion, checksumming, ...
32157 \end_layout
32158
32159 \end_inset
32160 </cell>
32161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32162 \begin_inset Text
32163
32164 \begin_layout Standard
32165 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32166
32167 \end_inset
32168
32169
32170 \end_layout
32171
32172 \end_inset
32173 </cell>
32174 </row>
32175 <row topline="true">
32176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32177 \begin_inset Text
32178
32179 \begin_layout Standard
32180 objdump
32181 \begin_inset LatexCommand \index{objdump (tool)}
32182
32183 \end_inset
32184
32185
32186 \end_layout
32187
32188 \end_inset
32189 </cell>
32190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32191 \begin_inset Text
32192
32193 \begin_layout Standard
32194 Object file conversion, ...
32195 \end_layout
32196
32197 \end_inset
32198 </cell>
32199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32200 \begin_inset Text
32201
32202 \begin_layout Standard
32203 Part of binutils (should be there anyway)
32204 \end_layout
32205
32206 \end_inset
32207 </cell>
32208 </row>
32209 <row topline="true">
32210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32211 \begin_inset Text
32212
32213 \begin_layout Standard
32214 cmon51
32215 \end_layout
32216
32217 \end_inset
32218 </cell>
32219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32220 \begin_inset Text
32221
32222 \begin_layout Standard
32223 8051 monitor (hex up-/download, single step, disassemble)
32224 \end_layout
32225
32226 \end_inset
32227 </cell>
32228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32229 \begin_inset Text
32230
32231 \begin_layout Standard
32232 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32233
32234 \end_inset
32235
32236
32237 \end_layout
32238
32239 \end_inset
32240 </cell>
32241 </row>
32242 <row topline="true">
32243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32244 \begin_inset Text
32245
32246 \begin_layout Standard
32247 doxygen
32248 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32249
32250 \end_inset
32251
32252
32253 \end_layout
32254
32255 \end_inset
32256 </cell>
32257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32258 \begin_inset Text
32259
32260 \begin_layout Standard
32261 Source code documentation system
32262 \end_layout
32263
32264 \end_inset
32265 </cell>
32266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32267 \begin_inset Text
32268
32269 \begin_layout Standard
32270 \begin_inset LatexCommand \url{http://www.doxygen.org}
32271
32272 \end_inset
32273
32274
32275 \end_layout
32276
32277 \end_inset
32278 </cell>
32279 </row>
32280 <row topline="true">
32281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32282 \begin_inset Text
32283
32284 \begin_layout Standard
32285 kdevelop
32286 \end_layout
32287
32288 \end_inset
32289 </cell>
32290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32291 \begin_inset Text
32292
32293 \begin_layout Standard
32294 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32295 \end_layout
32296
32297 \end_inset
32298 </cell>
32299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32300 \begin_inset Text
32301
32302 \begin_layout Standard
32303 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32304
32305 \end_inset
32306
32307
32308 \end_layout
32309
32310 \end_inset
32311 </cell>
32312 </row>
32313 <row topline="true">
32314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32315 \begin_inset Text
32316
32317 \begin_layout Standard
32318 paulmon
32319 \end_layout
32320
32321 \end_inset
32322 </cell>
32323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32324 \begin_inset Text
32325
32326 \begin_layout Standard
32327 8051 monitor (hex up-/download, single step, disassemble)
32328 \end_layout
32329
32330 \end_inset
32331 </cell>
32332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32333 \begin_inset Text
32334
32335 \begin_layout Standard
32336 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32337
32338 \end_inset
32339
32340
32341 \end_layout
32342
32343 \end_inset
32344 </cell>
32345 </row>
32346 <row topline="true">
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32348 \begin_inset Text
32349
32350 \begin_layout Standard
32351 splint
32352 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32353
32354 \end_inset
32355
32356
32357 \end_layout
32358
32359 \end_inset
32360 </cell>
32361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32362 \begin_inset Text
32363
32364 \begin_layout Standard
32365 Statically checks c sources (see 
32366 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32367
32368 \end_inset
32369
32370 )
32371 \end_layout
32372
32373 \end_inset
32374 </cell>
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32376 \begin_inset Text
32377
32378 \begin_layout Standard
32379 \begin_inset LatexCommand \url{http://www.splint.org}
32380
32381 \end_inset
32382
32383
32384 \end_layout
32385
32386 \end_inset
32387 </cell>
32388 </row>
32389 <row topline="true" bottomline="true">
32390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32391 \begin_inset Text
32392
32393 \begin_layout Standard
32394 ddd
32395 \begin_inset LatexCommand \index{DDD (debugger)}
32396
32397 \end_inset
32398
32399
32400 \end_layout
32401
32402 \end_inset
32403 </cell>
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32405 \begin_inset Text
32406
32407 \begin_layout Standard
32408 Debugger, serves nicely as GUI to SDCDB
32409 \begin_inset LatexCommand \index{SDCDB (debugger)}
32410
32411 \end_inset
32412
32413  (Unix only)
32414 \end_layout
32415
32416 \end_inset
32417 </cell>
32418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32419 \begin_inset Text
32420
32421 \begin_layout Standard
32422 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32423
32424 \end_inset
32425
32426
32427 \end_layout
32428
32429 \end_inset
32430 </cell>
32431 </row>
32432 <row bottomline="true">
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_inset Text
32435
32436 \begin_layout Standard
32437 d52
32438 \begin_inset LatexCommand \index{d52}
32439
32440 \end_inset
32441
32442
32443 \begin_inset LatexCommand \index{d52 (disassembler)}
32444
32445 \end_inset
32446
32447
32448 \end_layout
32449
32450 \end_inset
32451 </cell>
32452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32453 \begin_inset Text
32454
32455 \begin_layout Standard
32456 Disassembler, can count instruction cycles
32457 \begin_inset LatexCommand \index{instruction cycles (count)}
32458
32459 \end_inset
32460
32461 , use with options -pnd
32462 \end_layout
32463
32464 \end_inset
32465 </cell>
32466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32467 \begin_inset Text
32468
32469 \begin_layout Standard
32470 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32471
32472 \end_inset
32473
32474
32475 \end_layout
32476
32477 \end_inset
32478 </cell>
32479 </row>
32480 <row bottomline="true">
32481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32482 \begin_inset Text
32483
32484 \begin_layout Standard
32485 cmake
32486 \begin_inset LatexCommand \index{cmake}
32487
32488 \end_inset
32489
32490
32491 \end_layout
32492
32493 \end_inset
32494 </cell>
32495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32496 \begin_inset Text
32497
32498 \begin_layout Standard
32499 Cross platform build system, generates Makefiles
32500 \begin_inset LatexCommand \index{Makefile}
32501
32502 \end_inset
32503
32504  and project workspaces
32505 \begin_inset LatexCommand \index{project workspace}
32506
32507 \end_inset
32508
32509
32510 \end_layout
32511
32512 \end_inset
32513 </cell>
32514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32515 \begin_inset Text
32516
32517 \begin_layout Standard
32518 \begin_inset LatexCommand \url{http://www.cmake.org}
32519
32520 \end_inset
32521
32522  \InsetSpace ~
32523 \InsetSpace ~
32524 \InsetSpace ~
32525 \InsetSpace ~
32526 and a dedicated wiki entry: 
32527 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32528
32529 \end_inset
32530
32531
32532 \end_layout
32533
32534 \end_inset
32535 </cell>
32536 </row>
32537 </lyxtabular>
32538
32539 \end_inset
32540
32541
32542 \newline
32543
32544 \end_layout
32545
32546 \begin_layout Section
32547 Related documentation / recommended reading
32548 \end_layout
32549
32550 \begin_layout Standard
32551 \align left
32552 \begin_inset Tabular
32553 <lyxtabular version="3" rows="7" columns="3">
32554 <features>
32555 <column alignment="left" valignment="top" leftline="true" width="0pt">
32556 <column alignment="left" valignment="top" leftline="true" width="0">
32557 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32558 <row topline="true" bottomline="true">
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32560 \begin_inset Text
32561
32562 \begin_layout Standard
32563
32564 \series bold
32565 Name
32566 \end_layout
32567
32568 \end_inset
32569 </cell>
32570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32571 \begin_inset Text
32572
32573 \begin_layout Standard
32574
32575 \series bold
32576 Subject / Title
32577 \end_layout
32578
32579 \end_inset
32580 </cell>
32581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32582 \begin_inset Text
32583
32584 \begin_layout Standard
32585
32586 \series bold
32587 Where to get
32588 \end_layout
32589
32590 \end_inset
32591 </cell>
32592 </row>
32593 <row topline="true">
32594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32595 \begin_inset Text
32596
32597 \begin_layout Standard
32598
32599 \family roman
32600 \series medium
32601 \shape up
32602 \size normal
32603 \emph off
32604 \bar no
32605 \noun off
32606 \color none
32607 c-refcard.pdf
32608 \end_layout
32609
32610 \end_inset
32611 </cell>
32612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32613 \begin_inset Text
32614
32615 \begin_layout Standard
32616 C Reference Card
32617 \begin_inset LatexCommand \index{C Reference card}
32618
32619 \end_inset
32620
32621 , 2 pages
32622 \end_layout
32623
32624 \end_inset
32625 </cell>
32626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32627 \begin_inset Text
32628
32629 \begin_layout Standard
32630 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32631
32632 \end_inset
32633
32634
32635 \end_layout
32636
32637 \end_inset
32638 </cell>
32639 </row>
32640 <row topline="true">
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32642 \begin_inset Text
32643
32644 \begin_layout Standard
32645 c-faq
32646 \end_layout
32647
32648 \end_inset
32649 </cell>
32650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32651 \begin_inset Text
32652
32653 \begin_layout Standard
32654 C-FAQ
32655 \begin_inset LatexCommand \index{C FAQ}
32656
32657 \end_inset
32658
32659
32660 \end_layout
32661
32662 \end_inset
32663 </cell>
32664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32665 \begin_inset Text
32666
32667 \begin_layout Standard
32668 \begin_inset LatexCommand \url{http://www.c-faq.com}
32669
32670 \end_inset
32671
32672
32673 \end_layout
32674
32675 \end_inset
32676 </cell>
32677 </row>
32678 <row topline="true">
32679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32680 \begin_inset Text
32681
32682 \begin_layout Standard
32683 ISO/IEC 9899:TC2
32684 \end_layout
32685
32686 \end_inset
32687 </cell>
32688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32689 \begin_inset Text
32690
32691 \begin_layout Standard
32692 \begin_inset Quotes sld
32693 \end_inset
32694
32695 C-Standard
32696 \begin_inset Quotes srd
32697 \end_inset
32698
32699
32700 \end_layout
32701
32702 \end_inset
32703 </cell>
32704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32705 \begin_inset Text
32706
32707 \begin_layout Standard
32708
32709 \size footnotesize
32710 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32711
32712 \end_inset
32713
32714
32715 \end_layout
32716
32717 \end_inset
32718 </cell>
32719 </row>
32720 <row topline="true">
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32722 \begin_inset Text
32723
32724 \begin_layout Standard
32725 ISO/IEC DTR 18037
32726 \end_layout
32727
32728 \end_inset
32729 </cell>
32730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32731 \begin_inset Text
32732
32733 \begin_layout Standard
32734 \begin_inset Quotes sld
32735 \end_inset
32736
32737 Extensions for Embedded C
32738 \begin_inset Quotes srd
32739 \end_inset
32740
32741
32742 \end_layout
32743
32744 \end_inset
32745 </cell>
32746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32747 \begin_inset Text
32748
32749 \begin_layout Standard
32750
32751 \size footnotesize
32752 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32753
32754 \end_inset
32755
32756
32757 \end_layout
32758
32759 \end_inset
32760 </cell>
32761 </row>
32762 <row topline="true">
32763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32764 \begin_inset Text
32765
32766 \begin_layout Standard
32767
32768 \end_layout
32769
32770 \end_inset
32771 </cell>
32772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32773 \begin_inset Text
32774
32775 \begin_layout Standard
32776 Latest datasheet of target CPU
32777 \end_layout
32778
32779 \end_inset
32780 </cell>
32781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32782 \begin_inset Text
32783
32784 \begin_layout Standard
32785 vendor
32786 \end_layout
32787
32788 \end_inset
32789 </cell>
32790 </row>
32791 <row topline="true" bottomline="true">
32792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32793 \begin_inset Text
32794
32795 \begin_layout Standard
32796
32797 \end_layout
32798
32799 \end_inset
32800 </cell>
32801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32802 \begin_inset Text
32803
32804 \begin_layout Standard
32805 Revision history of datasheet
32806 \end_layout
32807
32808 \end_inset
32809 </cell>
32810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32811 \begin_inset Text
32812
32813 \begin_layout Standard
32814 vendor
32815 \end_layout
32816
32817 \end_inset
32818 </cell>
32819 </row>
32820 </lyxtabular>
32821
32822 \end_inset
32823
32824
32825 \newline
32826
32827 \end_layout
32828
32829 \begin_layout Section
32830 Application notes specifically for SDCC
32831 \end_layout
32832
32833 \begin_layout Standard
32834 SDCC makes no claims about the completeness of this list and about up-to-datenes
32835 s or correctness of the application notes
32836 \begin_inset LatexCommand \index{Application notes}
32837
32838 \end_inset
32839
32840 .
32841 \end_layout
32842
32843 \begin_layout Standard
32844 \align left
32845
32846 \size footnotesize
32847 \begin_inset Tabular
32848 <lyxtabular version="3" rows="7" columns="3">
32849 <features>
32850 <column alignment="block" valignment="top" leftline="true" width="17col%">
32851 <column alignment="block" valignment="top" leftline="true" width="27col%">
32852 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32853 <row topline="true" bottomline="true">
32854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32855 \begin_inset Text
32856
32857 \begin_layout Standard
32858
32859 \series bold
32860 \size footnotesize
32861 Vendor
32862 \end_layout
32863
32864 \end_inset
32865 </cell>
32866 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32867 \begin_inset Text
32868
32869 \begin_layout Standard
32870
32871 \series bold
32872 \size footnotesize
32873 Subject / Title
32874 \end_layout
32875
32876 \end_inset
32877 </cell>
32878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32879 \begin_inset Text
32880
32881 \begin_layout Standard
32882
32883 \series bold
32884 \size footnotesize
32885 Where to get
32886 \end_layout
32887
32888 \end_inset
32889 </cell>
32890 </row>
32891 <row topline="true">
32892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32893 \begin_inset Text
32894
32895 \begin_layout Standard
32896
32897 \size footnotesize
32898 Maxim / Dallas
32899 \end_layout
32900
32901 \end_inset
32902 </cell>
32903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32904 \begin_inset Text
32905
32906 \begin_layout Standard
32907
32908 \size footnotesize
32909 Using the SDCC Compiler for the DS80C400
32910 \begin_inset LatexCommand \index{DS80C400}
32911
32912 \end_inset
32913
32914
32915 \end_layout
32916
32917 \end_inset
32918 </cell>
32919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32920 \begin_inset Text
32921
32922 \begin_layout Standard
32923
32924 \size footnotesize
32925 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32926
32927 \end_inset
32928
32929
32930 \end_layout
32931
32932 \end_inset
32933 </cell>
32934 </row>
32935 <row topline="true">
32936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32937 \begin_inset Text
32938
32939 \begin_layout Standard
32940
32941 \size footnotesize
32942 Maxim / Dallas
32943 \end_layout
32944
32945 \end_inset
32946 </cell>
32947 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32948 \begin_inset Text
32949
32950 \begin_layout Standard
32951
32952 \size footnotesize
32953 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32954 \begin_inset LatexCommand \index{DS89C4x0}
32955
32956 \end_inset
32957
32958  Family of Microcontrollers
32959 \end_layout
32960
32961 \end_inset
32962 </cell>
32963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32964 \begin_inset Text
32965
32966 \begin_layout Standard
32967
32968 \size footnotesize
32969 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32970
32971 \end_inset
32972
32973
32974 \end_layout
32975
32976 \end_inset
32977 </cell>
32978 </row>
32979 <row topline="true">
32980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32981 \begin_inset Text
32982
32983 \begin_layout Standard
32984
32985 \size footnotesize
32986 Silicon Laboratories / Cygnal
32987 \end_layout
32988
32989 \end_inset
32990 </cell>
32991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32992 \begin_inset Text
32993
32994 \begin_layout Standard
32995
32996 \size footnotesize
32997 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32998 \begin_inset LatexCommand \index{IDE}
32999
33000 \end_inset
33001
33002
33003 \end_layout
33004
33005 \end_inset
33006 </cell>
33007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33008 \begin_inset Text
33009
33010 \begin_layout Standard
33011
33012 \size footnotesize
33013 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
33014
33015 \end_inset
33016
33017
33018 \end_layout
33019
33020 \end_inset
33021 </cell>
33022 </row>
33023 <row topline="true">
33024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33025 \begin_inset Text
33026
33027 \begin_layout Standard
33028
33029 \size footnotesize
33030 Ramtron / Goal Semiconductor
33031 \end_layout
33032
33033 \end_inset
33034 </cell>
33035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33036 \begin_inset Text
33037
33038 \begin_layout Standard
33039
33040 \size footnotesize
33041 Interfacing SDCC to Syn and Textpad
33042 \end_layout
33043
33044 \end_inset
33045 </cell>
33046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33047 \begin_inset Text
33048
33049 \begin_layout Standard
33050
33051 \size footnotesize
33052 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33053
33054 \end_inset
33055
33056
33057 \end_layout
33058
33059 \end_inset
33060 </cell>
33061 </row>
33062 <row topline="true">
33063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33064 \begin_inset Text
33065
33066 \begin_layout Standard
33067
33068 \size footnotesize
33069 Ramtron / Goal Semiconductor
33070 \end_layout
33071
33072 \end_inset
33073 </cell>
33074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33075 \begin_inset Text
33076
33077 \begin_layout Standard
33078
33079 \size footnotesize
33080 Installing and Configuring SDCC and Crimson Editor 
33081 \end_layout
33082
33083 \end_inset
33084 </cell>
33085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33086 \begin_inset Text
33087
33088 \begin_layout Standard
33089
33090 \size footnotesize
33091 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
33092
33093 \end_inset
33094
33095
33096 \end_layout
33097
33098 \end_inset
33099 </cell>
33100 </row>
33101 <row topline="true" bottomline="true">
33102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33103 \begin_inset Text
33104
33105 \begin_layout Standard
33106
33107 \size footnotesize
33108 Texas Instruments
33109 \end_layout
33110
33111 \end_inset
33112 </cell>
33113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33114 \begin_inset Text
33115
33116 \begin_layout Standard
33117
33118 \size footnotesize
33119 MSC12xx Programming with SDCC
33120 \end_layout
33121
33122 \end_inset
33123 </cell>
33124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33125 \begin_inset Text
33126
33127 \begin_layout Standard
33128
33129 \size footnotesize
33130 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33131
33132 \end_inset
33133
33134
33135 \end_layout
33136
33137 \end_inset
33138 </cell>
33139 </row>
33140 </lyxtabular>
33141
33142 \end_inset
33143
33144
33145 \end_layout
33146
33147 \begin_layout Section
33148 Some Questions
33149 \end_layout
33150
33151 \begin_layout Standard
33152 Some questions answered, some pointers given - it might be time to in turn
33153  ask 
33154 \emph on
33155 you
33156 \emph default
33157  some questions: 
33158 \end_layout
33159
33160 \begin_layout Itemize
33161 can you solve your project with the selected microcontroller? Would you
33162  find out early or rather late that your target is too small/slow/whatever?
33163  Can you switch to a slightly better device if it doesn't fit?
33164 \end_layout
33165
33166 \begin_layout Itemize
33167 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33168  and/or another programming language be more adequate? Would an operating
33169  system on the target device help?
33170 \end_layout
33171
33172 \begin_layout Itemize
33173 if you solved the problem, will the marketing department be happy?
33174 \end_layout
33175
33176 \begin_layout Itemize
33177 if the marketing department is happy, will customers be happy?
33178 \end_layout
33179
33180 \begin_layout Itemize
33181 if you're the project manager, marketing department and maybe even the customer
33182  in one person, have you tried to see the project from the outside?
33183 \end_layout
33184
33185 \begin_layout Itemize
33186 is the project done if you think it is done? Or is just that other interface/pro
33187 tocol/feature/configuration/option missing? How about website, manual(s),
33188  internationali(z|s)ation, packaging, labels, 2nd source for components,
33189  electromagnetic compatability/interference, documentation for production,
33190  production test software, update mechanism, patent issues?
33191 \end_layout
33192
33193 \begin_layout Itemize
33194 is your project adequately positioned in that magic triangle: fame, fortune,
33195  fun?
33196 \end_layout
33197
33198 \begin_layout Standard
33199 Maybe not all answers to these questions are known and some answers may
33200  even be 
33201 \emph on
33202 no
33203 \emph default
33204 , nevertheless knowing these questions may help you to avoid burnout
33205 \begin_inset Foot
33206 status open
33207
33208 \begin_layout Standard
33209 burnout is bad for electronic devices, programmers and motorcycle tyres
33210 \end_layout
33211
33212 \end_inset
33213
33214 .
33215  Chances are you didn't want to hear some of them...
33216 \end_layout
33217
33218 \begin_layout Chapter
33219 Support
33220 \begin_inset LatexCommand \index{Support}
33221
33222 \end_inset
33223
33224
33225 \end_layout
33226
33227 \begin_layout Standard
33228 SDCC has grown to be a large project.
33229  The compiler alone (without the preprocessor, assembler and linker) is
33230  well over 150,000 lines of code (blank stripped).
33231  The open source nature of this project is a key to its continued growth
33232  and support.
33233  You gain the benefit and support of many active software developers and
33234  end users.
33235  Is SDCC perfect? No, that's why we need your help.
33236  The developers take pride in fixing reported bugs.
33237  You can help by reporting the bugs and helping other SDCC users.
33238  There are lots of ways to contribute, and we encourage you to take part
33239  in making SDCC a great software package.
33240  
33241 \end_layout
33242
33243 \begin_layout Standard
33244 The SDCC project is hosted on the SDCC sourceforge site at 
33245 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33246
33247 \end_inset
33248
33249 .
33250  You'll find the complete set of mailing lists
33251 \begin_inset LatexCommand \index{Mailing list(s)}
33252
33253 \end_inset
33254
33255 , forums, bug reporting system, patch submission
33256 \begin_inset LatexCommand \index{Patch submission}
33257
33258 \end_inset
33259
33260  system, download
33261 \begin_inset LatexCommand \index{download}
33262
33263 \end_inset
33264
33265  area and Subversion code repository
33266 \begin_inset LatexCommand \index{Subversion code repository}
33267
33268 \end_inset
33269
33270  there.
33271 \end_layout
33272
33273 \begin_layout Section
33274 Reporting Bugs
33275 \begin_inset LatexCommand \index{Bug reporting}
33276
33277 \end_inset
33278
33279
33280 \begin_inset LatexCommand \index{Reporting bugs}
33281
33282 \end_inset
33283
33284
33285 \end_layout
33286
33287 \begin_layout Standard
33288 The recommended way of reporting bugs is using the infrastructure of the
33289  sourceforge site.
33290  You can follow the status of bug reports there and have an overview about
33291  the known bugs.
33292 \end_layout
33293
33294 \begin_layout Standard
33295 Bug reports are automatically forwarded to the developer mailing list and
33296  will be fixed ASAP.
33297  When reporting a bug, it is very useful to include a small test program
33298  (the smaller the better) which reproduces the problem.
33299  If you can isolate the problem by looking at the generated assembly code,
33300  this can be very helpful.
33301  Compiling your program with the -
33302 \begin_inset ERT
33303 status collapsed
33304
33305 \begin_layout Standard
33306
33307
33308 \backslash
33309 /
33310 \end_layout
33311
33312 \end_inset
33313
33314 -dumpall
33315 \begin_inset LatexCommand \index{-\/-dumpall}
33316
33317 \end_inset
33318
33319  option can sometimes be useful in locating optimization problems.
33320  When reporting a bug please make sure you:
33321 \end_layout
33322
33323 \begin_layout Enumerate
33324 Attach the code you are compiling with SDCC.
33325  
33326 \end_layout
33327
33328 \begin_layout Enumerate
33329 Specify the exact command you use to run SDCC, or attach your Makefile.
33330  
33331 \end_layout
33332
33333 \begin_layout Enumerate
33334 Specify the SDCC version (type "
33335 \family sans
33336 \series bold
33337 sdcc -v
33338 \family default
33339 \series default
33340 "), your platform, and operating system.
33341  
33342 \end_layout
33343
33344 \begin_layout Enumerate
33345 Provide an exact copy of any error message or incorrect output.
33346  
33347 \end_layout
33348
33349 \begin_layout Enumerate
33350 Put something meaningful in the subject of your message.
33351 \end_layout
33352
33353 \begin_layout Standard
33354 Please attempt to include these 5 important parts, as applicable, in all
33355  requests for support or when reporting any problems or bugs with SDCC.
33356  Though this will make your message lengthy, it will greatly improve your
33357  chance that SDCC users and developers will be able to help you.
33358  Some SDCC developers are frustrated by bug reports without code provided
33359  that they can use to reproduce and ultimately fix the problem, so please
33360  be sure to provide sample code if you are reporting a bug! 
33361 \end_layout
33362
33363 \begin_layout Standard
33364 Please have a short check that you are using a recent version of SDCC and
33365  the bug is not yet known.
33366  This is the link for reporting bugs: 
33367 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33368
33369 \end_inset
33370
33371 .
33372  With SDCC on average having more than 200 downloads
33373 \begin_inset LatexCommand \index{download}
33374
33375 \end_inset
33376
33377  on sourceforge per day
33378 \begin_inset Foot
33379 status open
33380
33381 \begin_layout Standard
33382 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33383  between 2002 and 2005.
33384  This does not include other methods of distribution.
33385 \end_layout
33386
33387 \end_inset
33388
33389  there must be some users.
33390  So it's not exactly easy to find a new bug.
33391  If you find one we need it: 
33392 \emph on
33393 reporting bugs is good
33394 \emph default
33395 .
33396 \end_layout
33397
33398 \begin_layout Section
33399 Requesting Features
33400 \begin_inset LatexCommand \label{sub:Requesting-Features}
33401
33402 \end_inset
33403
33404
33405 \begin_inset LatexCommand \index{Feature request}
33406
33407 \end_inset
33408
33409
33410 \begin_inset LatexCommand \index{Requesting features}
33411
33412 \end_inset
33413
33414
33415 \end_layout
33416
33417 \begin_layout Standard
33418 Like bug reports feature requests are forwarded to the developer mailing
33419  list.
33420  This is the link for requesting features: 
33421 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33422
33423 \end_inset
33424
33425 .
33426 \end_layout
33427
33428 \begin_layout Section
33429 Submitting patches
33430 \end_layout
33431
33432 \begin_layout Standard
33433 Like bug reports contributed patches are forwarded to the developer mailing
33434  list.
33435  This is the link for submitting patches
33436 \begin_inset LatexCommand \index{Patch submission}
33437
33438 \end_inset
33439
33440
33441 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33442
33443 \end_inset
33444
33445 .
33446 \end_layout
33447
33448 \begin_layout Standard
33449 You need to specify some parameters to the 
33450 \family typewriter
33451 diff
33452 \family default
33453  command for the patches to be useful.
33454  If you modified more than one file a patch created f.e.
33455  with 
33456 \family sans
33457 \series bold
33458
33459 \begin_inset Quotes sld
33460 \end_inset
33461
33462 diff -Naur unmodified_directory modified_directory >my_changes.patch
33463 \begin_inset Quotes srd
33464 \end_inset
33465
33466
33467 \family default
33468 \series default
33469  will be fine, otherwise 
33470 \family sans
33471 \series bold
33472
33473 \begin_inset Quotes sld
33474 \end_inset
33475
33476 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33477 \begin_inset Quotes srd
33478 \end_inset
33479
33480
33481 \series default
33482  
33483 \family default
33484 will do.
33485 \end_layout
33486
33487 \begin_layout Section
33488 Getting Help
33489 \end_layout
33490
33491 \begin_layout Standard
33492 These links should take you directly to the 
33493 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33494
33495 \end_inset
33496
33497
33498 \begin_inset Foot
33499 status open
33500
33501 \begin_layout Standard
33502 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33503  automated messages (mid 2003)
33504 \end_layout
33505
33506 \end_inset
33507
33508  and the 
33509 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33510
33511 \end_inset
33512
33513 , lists
33514 \begin_inset LatexCommand \index{Mailing list(s)}
33515
33516 \end_inset
33517
33518  and forums are archived and searchable so if you are lucky someone already
33519  had a similar problem.
33520  While mails to the lists themselves are delivered promptly their web front
33521  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33522  if you're seriously using SDCC please consider subscribing to the lists.
33523 \end_layout
33524
33525 \begin_layout Section
33526 ChangeLog
33527 \end_layout
33528
33529 \begin_layout Standard
33530 You can follow the status of the Subversion version
33531 \begin_inset LatexCommand \index{version}
33532
33533 \end_inset
33534
33535  of SDCC by watching the Changelog
33536 \begin_inset LatexCommand \index{Changelog}
33537
33538 \end_inset
33539
33540  in the Subversion repository
33541 \size footnotesize
33542  
33543 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33544
33545 \end_inset
33546
33547 .
33548 \end_layout
33549
33550 \begin_layout Section
33551 Subversion Source Code Repository
33552 \end_layout
33553
33554 \begin_layout Standard
33555 The output of 
33556 \family sans
33557 \series bold
33558 sdcc -
33559 \family default
33560
33561 \begin_inset ERT
33562 status open
33563
33564 \begin_layout Standard
33565
33566
33567 \backslash
33568 /
33569 \end_layout
33570
33571 \end_inset
33572
33573
33574 \family sans
33575 -version
33576 \family default
33577 \series default
33578  or the filenames of the snapshot versions of SDCC include date and its
33579  Subversion
33580 \begin_inset LatexCommand \index{Subversion code repository}
33581
33582 \end_inset
33583
33584  number.
33585  Subversion allows to download the source of recent or previous versions
33586  
33587 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33588
33589 \end_inset
33590
33591  (by number or by date).
33592  An on-line source code browser and detailled instructions are also available
33593  there.
33594  SDCC versions starting from 1999 up to now are available (currently the
33595  versions prior to the conversion from cvs
33596 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33597
33598 \end_inset
33599
33600  to Subversion (April 2006) are either by accessible by Subversion or by
33601  cvs).
33602 \end_layout
33603
33604 \begin_layout Section
33605 Release policy
33606 \begin_inset LatexCommand \index{Release policy}
33607
33608 \end_inset
33609
33610
33611 \end_layout
33612
33613 \begin_layout Standard
33614 Historically there often were long delays between official releases and
33615  the sourceforge download area tends to get not updated at all.
33616  Excuses in the past might have referred to problems with live range analysis,
33617  but as this was fixed a while ago, the current problem is that another
33618  excuse has to be found.
33619  Kidding aside, we have to get better there! On the other hand there are
33620  daily snapshots available at 
33621 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33622
33623 \end_inset
33624
33625 , and you can always build the very last version (hopefully with many bugs
33626  fixed, and features added) from the source code available at 
33627 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33628
33629 \end_inset
33630
33631 .
33632  The SDCC Wiki
33633 \begin_inset LatexCommand \index{wiki}
33634
33635 \end_inset
33636
33637
33638 \begin_inset LatexCommand \index{SDCC Wiki}
33639
33640 \end_inset
33641
33642  at 
33643 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33644
33645 \end_inset
33646
33647  also holds some information about past and future releases.
33648 \end_layout
33649
33650 \begin_layout Section
33651 Examples
33652 \begin_inset LatexCommand \index{Examples}
33653
33654 \end_inset
33655
33656
33657 \end_layout
33658
33659 \begin_layout Standard
33660 You'll find some small examples in the directory 
33661 \emph on
33662 sdcc/device/examples/.
33663  
33664 \emph default
33665 More examples and libraries are available at
33666 \emph on
33667  The SDCC Open Knowledge Resource 
33668 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33669
33670 \end_inset
33671
33672  
33673 \emph default
33674 web site or at 
33675 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33676
33677 \end_inset
33678
33679 .
33680 \end_layout
33681
33682 \begin_layout Standard
33683 \begin_inset Note Note
33684 status collapsed
33685
33686 \begin_layout Standard
33687 I did insert a reference to Paul's web site here although it seems rather
33688  dedicated to a specific 8032 board (I think it's okay because it f.e.
33689  shows LCD/Harddisc interface and has a free 8051 monitor.
33690  Independent 8032 board vendors face hard competition of heavily subsidized
33691  development boards anyway).
33692 \end_layout
33693
33694 \begin_layout Standard
33695 Maybe we should include some links to real world applications.
33696  Preferably pointer to pointers (one for each architecture) so this stays
33697  manageable here?
33698 \end_layout
33699
33700 \end_inset
33701
33702
33703 \end_layout
33704
33705 \begin_layout Section
33706 Quality control
33707 \begin_inset LatexCommand \label{sec:Quality-control}
33708
33709 \end_inset
33710
33711
33712 \begin_inset LatexCommand \index{Quality control}
33713
33714 \end_inset
33715
33716
33717 \end_layout
33718
33719 \begin_layout Standard
33720 The compiler is passed through snaphot build compile and build checks.
33721  The so called 
33722 \shape italic
33723 regression tests
33724 \shape default
33725
33726 \begin_inset LatexCommand \index{Regression test}
33727
33728 \end_inset
33729
33730  check that SDCC itself compiles flawlessly on several host platforms (i386,
33731  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33732  and checks the quality of the code generated by SDCC by running the code
33733  for several target platforms through simulators.
33734  The regression test suite comprises more than 100 files which expand to
33735  more than 500 test cases which include more than 4500 tests.
33736  The results of these tests are published daily on SDCC's snapshot page
33737  (click on the red or green symbols on the right side of 
33738 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33739
33740 \end_inset
33741
33742 ).
33743 \end_layout
33744
33745 \begin_layout Standard
33746 There is a separate document 
33747 \shape italic
33748 test_suite.pdf 
33749 \begin_inset LatexCommand \index{Test suite}
33750
33751 \end_inset
33752
33753
33754 \shape default
33755  
33756 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33757
33758 \end_inset
33759
33760  about the regression test suite.
33761 \end_layout
33762
33763 \begin_layout Standard
33764 You'll find the test code in the directory 
33765 \shape italic
33766 sdcc/support/regression
33767 \shape default
33768 .
33769  You can run these tests manually by running 
33770 \family sans
33771 make
33772 \family default
33773  in this directory (or f.e.
33774  
33775 \family sans
33776 \series bold
33777
33778 \begin_inset Quotes sld
33779 \end_inset
33780
33781 make test-mcs51
33782 \begin_inset Quotes srd
33783 \end_inset
33784
33785
33786 \family default
33787 \series default
33788  if you don't want to run the complete tests).
33789  The test code might also be interesting if you want to look for examples
33790 \begin_inset LatexCommand \index{Examples}
33791
33792 \end_inset
33793
33794  checking corner cases of SDCC or if you plan to submit patches
33795 \begin_inset LatexCommand \index{Patch submission}
33796
33797 \end_inset
33798
33799 .
33800 \end_layout
33801
33802 \begin_layout Standard
33803 The PIC14 port uses a different set of regression tests 
33804 \begin_inset LatexCommand \index{Regression test (PIC14)}
33805
33806 \end_inset
33807
33808 , you'll find them in the directory 
33809 \shape italic
33810 sdcc/src/regression
33811 \shape default
33812 .
33813 \end_layout
33814
33815 \begin_layout Section
33816 Use of SDCC in Education
33817 \end_layout
33818
33819 \begin_layout Standard
33820 In short: 
33821 \emph on
33822 highly
33823 \emph default
33824  encouraged
33825 \begin_inset Foot
33826 status open
33827
33828 \begin_layout Standard
33829 the phrase "use in education" might evoke the association "
33830 \emph on
33831 only
33832 \emph default
33833  fit for use in education".
33834  This connotation is not intended but nevertheless risked as the licensing
33835  of SDCC makes it difficult to offer educational discounts
33836 \end_layout
33837
33838 \end_inset
33839
33840 .
33841  If your rationales are to:
33842 \end_layout
33843
33844 \begin_layout Enumerate
33845 give students a chance to understand the 
33846 \emph on
33847 complete
33848 \emph default
33849  steps of code generation
33850 \end_layout
33851
33852 \begin_layout Enumerate
33853 have a curriculum that can be extended for years.
33854  Then you could use an fpga board as target and your curriculum will seamlessly
33855  extend from logic synthesis (
33856 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33857
33858 \end_inset
33859
33860
33861 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33862
33863 \end_inset
33864
33865 ), over assembly programming, to C to FPGA compilers (
33866 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33867
33868 \end_inset
33869
33870 ) and to C.
33871 \end_layout
33872
33873 \begin_layout Enumerate
33874 be able to insert excursions about skills like using a revision control
33875  system, submitting/applying patches, using a type-setting (as opposed to
33876  word-processing) engine LyX/LaTeX, using 
33877 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33878
33879 \end_inset
33880
33881 , following some 
33882 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33883
33884 \end_inset
33885
33886 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33887  Source Software, CPU simulation, compiler regression tests
33888 \begin_inset LatexCommand \index{Regression test}
33889
33890 \end_inset
33891
33892 .
33893  
33894 \newline
33895 And if there should be a shortage of ideas then you can always point students
33896  to the ever-growing feature request list 
33897 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33898
33899 \end_inset
33900
33901 .
33902 \end_layout
33903
33904 \begin_layout Enumerate
33905 not tie students to a specific host platform and instead allow them to use
33906  a host platform of 
33907 \emph on
33908 their
33909 \emph default
33910  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33911  and eventually 
33912 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33913
33914 \end_inset
33915
33916 )
33917 \end_layout
33918
33919 \begin_layout Enumerate
33920 not encourage students to use illegal copies of educational software
33921 \end_layout
33922
33923 \begin_layout Enumerate
33924 be immune to licensing/availability/price changes of the chosen tool chain
33925 \end_layout
33926
33927 \begin_layout Enumerate
33928 be able to change to a new target platform without having to adopt a new
33929  tool chain
33930 \end_layout
33931
33932 \begin_layout Enumerate
33933 have complete control over and insight into the tool chain
33934 \end_layout
33935
33936 \begin_layout Enumerate
33937 make your students aware about the pros and cons of open source software
33938  development
33939 \end_layout
33940
33941 \begin_layout Enumerate
33942 give back to the public as you are probably at least partially publically
33943  funded
33944 \end_layout
33945
33946 \begin_layout Enumerate
33947 give students a chance to publically prove their skills and to possibly
33948  see a world wide impact
33949 \end_layout
33950
33951 \begin_layout Standard
33952 then SDCC is probably among the first choices.
33953  Well, probably SDCC might be the only choice.
33954 \newpage
33955
33956 \end_layout
33957
33958 \begin_layout Chapter
33959 SDCC Technical Data
33960 \end_layout
33961
33962 \begin_layout Section
33963 Optimizations
33964 \begin_inset LatexCommand \index{Optimizations}
33965
33966 \end_inset
33967
33968
33969 \end_layout
33970
33971 \begin_layout Standard
33972 SDCC performs a host of standard optimizations in addition to some MCU specific
33973  optimizations.
33974  
33975 \end_layout
33976
33977 \begin_layout Subsection
33978 Sub-expression Elimination
33979 \begin_inset LatexCommand \index{Subexpression elimination}
33980
33981 \end_inset
33982
33983
33984 \end_layout
33985
33986 \begin_layout Standard
33987 The compiler does local and 
33988 \emph on
33989 g
33990 \emph default
33991 lobal 
33992 \emph on
33993 c
33994 \emph default
33995 ommon 
33996 \emph on
33997 s
33998 \emph default
33999 ubexpression 
34000 \emph on
34001 e
34002 \emph default
34003 limination, e.g.: 
34004 \end_layout
34005
34006 \begin_layout Verse
34007
34008 \family typewriter
34009 i = x + y + 1; 
34010 \newline
34011 j = x + y;
34012 \end_layout
34013
34014 \begin_layout Standard
34015 will be translated to
34016 \end_layout
34017
34018 \begin_layout Verse
34019
34020 \family typewriter
34021 iTemp = x + y; 
34022 \newline
34023 i = iTemp + 1; 
34024 \newline
34025 j = iTemp;
34026 \end_layout
34027
34028 \begin_layout Standard
34029 Some subexpressions are not as obvious as the above example, e.g.:
34030 \end_layout
34031
34032 \begin_layout Verse
34033
34034 \family typewriter
34035 a->b[i].c = 10; 
34036 \newline
34037 a->b[i].d = 11;
34038 \end_layout
34039
34040 \begin_layout Standard
34041 In this case the address arithmetic a->b[i] will be computed only once;
34042  the equivalent code in C would be.
34043 \end_layout
34044
34045 \begin_layout Verse
34046
34047 \family typewriter
34048 iTemp = a->b[i]; 
34049 \newline
34050 iTemp.c = 10; 
34051 \newline
34052 iTemp.d = 11;
34053 \end_layout
34054
34055 \begin_layout Standard
34056 The compiler will try to keep these temporary variables in registers.
34057 \end_layout
34058
34059 \begin_layout Subsection
34060 Dead-Code Elimination
34061 \begin_inset LatexCommand \index{Dead-code elimination}
34062
34063 \end_inset
34064
34065
34066 \end_layout
34067
34068 \begin_layout Verse
34069
34070 \family typewriter
34071 int global;
34072 \newline
34073
34074 \newline
34075 void f () { 
34076 \newline
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 int i; 
34080 \newline
34081 \InsetSpace ~
34082 \InsetSpace ~
34083 i = 1; \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 /* dead store */ 
34089 \newline
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 global = 1;\InsetSpace ~
34093 /* dead
34094  store */ 
34095 \newline
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 global = 2; 
34099 \newline
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 return; 
34103 \newline
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 global = 3;\InsetSpace ~
34107 /* unreachable */ 
34108 \newline
34109 }
34110 \end_layout
34111
34112 \begin_layout Standard
34113 will be changed to
34114 \end_layout
34115
34116 \begin_layout Verse
34117
34118 \family typewriter
34119 int global;
34120 \newline
34121
34122 \newline
34123 void f () {
34124 \newline
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 global = 2; 
34128 \newline
34129 }
34130 \end_layout
34131
34132 \begin_layout Subsection
34133 Copy-Propagation
34134 \begin_inset LatexCommand \index{Copy propagation}
34135
34136 \end_inset
34137
34138
34139 \end_layout
34140
34141 \begin_layout Verse
34142
34143 \family typewriter
34144 int f() { 
34145 \newline
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 int i, j; 
34149 \newline
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 i = 10; 
34153 \newline
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 j = i; 
34157 \newline
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 return j; 
34161 \newline
34162 }
34163 \end_layout
34164
34165 \begin_layout Standard
34166 will be changed to 
34167 \end_layout
34168
34169 \begin_layout Verse
34170
34171 \family typewriter
34172 int f() { 
34173 \newline
34174 \InsetSpace ~
34175 \InsetSpace ~
34176 int i, j; 
34177 \newline
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 i = 10; 
34181 \newline
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 j = 10; 
34185 \newline
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 return 10; 
34189 \newline
34190 }
34191 \end_layout
34192
34193 \begin_layout Standard
34194 Note: the dead stores created by this copy propagation will be eliminated
34195  by dead-code elimination.
34196 \end_layout
34197
34198 \begin_layout Subsection
34199 Loop Optimizations
34200 \begin_inset LatexCommand \index{Loop optimization}
34201
34202 \end_inset
34203
34204
34205 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34206
34207 \end_inset
34208
34209
34210 \end_layout
34211
34212 \begin_layout Standard
34213 Two types of loop optimizations are done by SDCC 
34214 \emph on
34215 loop invariant
34216 \emph default
34217  lifting and
34218 \emph on
34219  strength reduction
34220 \emph default
34221  of loop induction variables.
34222  In addition to the strength reduction the optimizer marks the induction
34223  variables and the register allocator tries to keep the induction variables
34224  in registers for the duration of the loop.
34225  Because of this preference of the register allocator
34226 \begin_inset LatexCommand \index{Register allocation}
34227
34228 \end_inset
34229
34230 , loop induction optimization causes an increase in register pressure, which
34231  may cause unwanted spilling of other temporary variables into the stack
34232 \begin_inset LatexCommand \index{stack}
34233
34234 \end_inset
34235
34236  / data space.
34237  The compiler will generate a warning message when it is forced to allocate
34238  extra space either on the stack or data space.
34239  If this extra space allocation is undesirable then induction optimization
34240  can be eliminated either for the entire source file (with -
34241 \begin_inset ERT
34242 status collapsed
34243
34244 \begin_layout Standard
34245
34246
34247 \backslash
34248 /
34249 \end_layout
34250
34251 \end_inset
34252
34253 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34254 noinduction
34255 \begin_inset LatexCommand \index{\#pragma noinduction}
34256
34257 \end_inset
34258
34259 .
34260 \newline
34261
34262 \newline
34263 Loop Invariant:
34264 \end_layout
34265
34266 \begin_layout Verse
34267
34268 \family typewriter
34269 for (i = 0 ; i < 100 ; i ++) 
34270 \newline
34271 \InsetSpace ~
34272 \InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 f += k + l;
34276 \end_layout
34277
34278 \begin_layout Standard
34279 changed to
34280 \end_layout
34281
34282 \begin_layout Verse
34283
34284 \family typewriter
34285 itemp = k + l; 
34286 \newline
34287 for (i = 0; i < 100; i++) 
34288 \newline
34289 \InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 f += itemp;
34294 \end_layout
34295
34296 \begin_layout Standard
34297 As mentioned previously some loop invariants are not as apparent, all static
34298  address computations are also moved out of the loop.
34299 \newline
34300
34301 \newline
34302 Strength Reduction
34303 \begin_inset LatexCommand \index{Strength reduction}
34304
34305 \end_inset
34306
34307 , this optimization substitutes an expression by a cheaper expression:
34308 \end_layout
34309
34310 \begin_layout Verse
34311
34312 \family typewriter
34313 for (i=0;i < 100; i++)
34314 \newline
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 ar[i*5] = i*3;
34320 \end_layout
34321
34322 \begin_layout Standard
34323 changed to
34324 \end_layout
34325
34326 \begin_layout Verse
34327
34328 \family typewriter
34329 itemp1 = 0; 
34330 \newline
34331 itemp2 = 0; 
34332 \newline
34333 for (i=0;i< 100;i++) { 
34334 \newline
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 ar[itemp1] = itemp2; 
34340 \newline
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 itemp1
34346  += 5; 
34347 \newline
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 itemp2 += 3; 
34353 \newline
34354 }
34355 \end_layout
34356
34357 \begin_layout Standard
34358 The more expensive multiplication
34359 \begin_inset LatexCommand \index{Multiplication}
34360
34361 \end_inset
34362
34363  is changed to a less expensive addition.
34364 \end_layout
34365
34366 \begin_layout Subsection
34367 Loop Reversing
34368 \begin_inset LatexCommand \index{Loop reversing}
34369
34370 \end_inset
34371
34372
34373 \end_layout
34374
34375 \begin_layout Standard
34376 This optimization is done to reduce the overhead of checking loop boundaries
34377  for every iteration.
34378  Some simple loops can be reversed and implemented using a 
34379 \begin_inset Quotes eld
34380 \end_inset
34381
34382 decrement and jump if not zero
34383 \begin_inset Quotes erd
34384 \end_inset
34385
34386  instruction.
34387  SDCC checks for the following criterion to determine if a loop is reversible
34388  (note: more sophisticated compilers use data-dependency analysis to make
34389  this determination, SDCC uses a more simple minded analysis).
34390 \end_layout
34391
34392 \begin_layout Itemize
34393 The 'for' loop is of the form 
34394 \newline
34395
34396 \newline
34397
34398 \family typewriter
34399 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34400  += 1])
34401 \newline
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 <for body>
34407 \end_layout
34408
34409 \begin_layout Itemize
34410 The <for body> does not contain 
34411 \begin_inset Quotes eld
34412 \end_inset
34413
34414 continue
34415 \begin_inset Quotes erd
34416 \end_inset
34417
34418  or 'break
34419 \begin_inset Quotes erd
34420 \end_inset
34421
34422 .
34423 \end_layout
34424
34425 \begin_layout Itemize
34426 All goto's are contained within the loop.
34427 \end_layout
34428
34429 \begin_layout Itemize
34430 No function calls within the loop.
34431 \end_layout
34432
34433 \begin_layout Itemize
34434 The loop control variable <sym> is not assigned any value within the loop
34435 \end_layout
34436
34437 \begin_layout Itemize
34438 The loop control variable does NOT participate in any arithmetic operation
34439  within the loop.
34440 \end_layout
34441
34442 \begin_layout Itemize
34443 There are NO switch statements in the loop.
34444 \end_layout
34445
34446 \begin_layout Subsection
34447 Algebraic Simplifications
34448 \end_layout
34449
34450 \begin_layout Standard
34451 SDCC does numerous algebraic simplifications, the following is a small sub-set
34452  of these optimizations.
34453 \end_layout
34454
34455 \begin_layout Verse
34456
34457 \family typewriter
34458 i = j + 0;\InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462  /* changed to: */\InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466  i = j; 
34467 \newline
34468 i /= 2;\InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475  /* changed to: */\InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479  i >>= 1; 
34480 \newline
34481 i
34482  = j - j;\InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486  /* changed to: */\InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490  i = 0; 
34491 \newline
34492 i = j / 1;\InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496  /* changed to: */\InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500  i = j;
34501 \end_layout
34502
34503 \begin_layout Standard
34504 Note the subexpressions
34505 \begin_inset LatexCommand \index{Subexpression}
34506
34507 \end_inset
34508
34509  given above are generally introduced by macro expansions or as a result
34510  of copy/constant propagation.
34511 \end_layout
34512
34513 \begin_layout Subsection
34514 'switch' Statements
34515 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34516
34517 \end_inset
34518
34519
34520 \begin_inset LatexCommand \index{switch statement}
34521
34522 \end_inset
34523
34524
34525 \end_layout
34526
34527 \begin_layout Standard
34528 SDCC can optimize switch statements to jump tables
34529 \begin_inset LatexCommand \index{jump tables}
34530
34531 \end_inset
34532
34533 .
34534  It makes the decision based on an estimate of the generated code size.
34535  SDCC is quite liberal in the requirements for jump table generation: 
34536 \end_layout
34537
34538 \begin_layout Itemize
34539 The labels need not be in order, and the starting number need not be one
34540  or zero, the case labels are in numerical sequence or not too many case
34541  labels are missing.
34542 \end_layout
34543
34544 \begin_deeper
34545 \begin_layout Verse
34546
34547 \family typewriter
34548 switch(i) {\InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \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 switch (i) { 
34575 \newline
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 case 4: ...\InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \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 case 0: ...
34606  
34607 \newline
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 case 5: ...\InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
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 case 1: ...
34638  
34639 \newline
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 case 3: ...\InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669
34670 \newline
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 case 6: ...\InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 case 3: ...
34701  
34702 \newline
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 case 7: ...\InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 case 4: ...
34733  
34734 \newline
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 case 8: ...\InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 case 5: ...
34765  
34766 \newline
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 case 9: ...\InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 case 6: ...
34797  
34798 \newline
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 case 10: ...\InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 case 7: ...
34828  
34829 \newline
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 case 11: ...\InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858 case 8: ...
34859  
34860 \newline
34861 }\InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885 \InsetSpace ~
34886 \InsetSpace ~
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 }
34898 \end_layout
34899
34900 \begin_layout Standard
34901 Both the above switch statements will be implemented using a jump-table.
34902  The example to the right side is slightly more efficient as the check for
34903  the lower boundary of the jump-table is not needed.
34904 \end_layout
34905
34906 \end_deeper
34907 \begin_layout Itemize
34908 The number of case labels is not larger than supported by the target architectur
34909 e.
34910 \end_layout
34911
34912 \begin_layout Itemize
34913 If the case labels are not in numerical sequence ('gaps' between cases)
34914  SDCC checks whether a jump table with additionally inserted dummy cases
34915  is still attractive.
34916  
34917 \end_layout
34918
34919 \begin_layout Itemize
34920 If the starting number is not zero and a check for the lower boundary of
34921  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34922  ...
34923  .
34924 \end_layout
34925
34926 \begin_layout Standard
34927 Switch statements which have large gaps in the numeric sequence or those
34928  that have too many case labels can be split into more than one switch statement
34929  for efficient code generation, e.g.:
34930 \end_layout
34931
34932 \begin_layout Verse
34933
34934 \family typewriter
34935 switch (i) { 
34936 \newline
34937 \InsetSpace ~
34938 \InsetSpace ~
34939 case 1: ...
34940  
34941 \newline
34942 \InsetSpace ~
34943 \InsetSpace ~
34944 case 2: ...
34945  
34946 \newline
34947 \InsetSpace ~
34948 \InsetSpace ~
34949 case 3: ...
34950  
34951 \newline
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 case 4: ...
34955  
34956 \newline
34957 \InsetSpace ~
34958 \InsetSpace ~
34959 case 5: ...
34960  
34961 \newline
34962 \InsetSpace ~
34963 \InsetSpace ~
34964 case 6: ...
34965  
34966 \newline
34967 \InsetSpace ~
34968 \InsetSpace ~
34969 case 7: ...
34970  
34971 \newline
34972 \InsetSpace ~
34973 \InsetSpace ~
34974 case 101: ...
34975  
34976 \newline
34977 \InsetSpace ~
34978 \InsetSpace ~
34979 case 102: ...
34980  
34981 \newline
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 case 103: ...
34985  
34986 \newline
34987 \InsetSpace ~
34988 \InsetSpace ~
34989 case 104: ...
34990  
34991 \newline
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 case 105: ...
34995  
34996 \newline
34997 \InsetSpace ~
34998 \InsetSpace ~
34999 case 106: ...
35000  
35001 \newline
35002 \InsetSpace ~
35003 \InsetSpace ~
35004 case 107: ...
35005  
35006 \newline
35007 }
35008 \end_layout
35009
35010 \begin_layout Standard
35011 If the above switch statement is broken down into two switch statements
35012 \end_layout
35013
35014 \begin_layout Verse
35015
35016 \family typewriter
35017 switch (i) { 
35018 \newline
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 case 1: ...
35022  
35023 \newline
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 case 2: ...
35027  
35028 \newline
35029 \InsetSpace ~
35030 \InsetSpace ~
35031 case 3: ...
35032  
35033 \newline
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 case 4: ...
35037  
35038 \newline
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 case 5: ...
35042  
35043 \newline
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 case 6: ...
35047  
35048 \newline
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 case 7: ...
35052  
35053 \newline
35054 }
35055 \end_layout
35056
35057 \begin_layout Standard
35058 and
35059 \end_layout
35060
35061 \begin_layout Verse
35062
35063 \family typewriter
35064 switch (i) { 
35065 \newline
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 case 101: ...
35069  
35070 \newline
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 case 102: ...
35074  
35075 \newline
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 case 103: ...
35079  
35080 \newline
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 case 104: ...
35084  
35085 \newline
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 case 105: ...
35089  
35090 \newline
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 case 106: ...
35094  
35095 \newline
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 case 107: ...
35099  
35100 \newline
35101 }
35102 \end_layout
35103
35104 \begin_layout Standard
35105 then both the switch statements will be implemented using jump-tables whereas
35106  the unmodified switch statement will not be.
35107 \end_layout
35108
35109 \begin_layout Standard
35110 \begin_inset Note Note
35111 status collapsed
35112
35113 \begin_layout Standard
35114 There might be reasons which SDCC cannot know about to either favour or
35115  not favour jump tables.
35116  If the target system has to be as quick for the last switch case as for
35117  the first (pro jump table), or if the switch argument is known to be zero
35118  in the majority of the cases (contra jump table).
35119 \end_layout
35120
35121 \end_inset
35122
35123
35124 \end_layout
35125
35126 \begin_layout Standard
35127 The pragma nojtbound
35128 \begin_inset LatexCommand \index{\#pragma nojtbound}
35129
35130 \end_inset
35131
35132  can be used to turn off checking the 
35133 \emph on
35134 j
35135 \emph default
35136 ump 
35137 \emph on
35138 t
35139 \emph default
35140 able 
35141 \emph on
35142 bound
35143 \emph default
35144 aries.
35145  It has no effect if a default label is supplied.
35146  Use of this pragma is dangerous: if the switch
35147 \begin_inset LatexCommand \index{switch statement}
35148
35149 \end_inset
35150
35151  argument is not matched by a case statement the processor will happily
35152  jump into Nirvana.
35153 \end_layout
35154
35155 \begin_layout Subsection
35156 Bit-shifting Operations
35157 \begin_inset LatexCommand \index{Bit shifting}
35158
35159 \end_inset
35160
35161 .
35162 \end_layout
35163
35164 \begin_layout Standard
35165 Bit shifting is one of the most frequently used operation in embedded programmin
35166 g.
35167  SDCC tries to implement bit-shift operations in the most efficient way
35168  possible, e.g.:
35169 \end_layout
35170
35171 \begin_layout Verse
35172
35173 \family typewriter
35174 unsigned char i;
35175 \newline
35176 ...
35177  
35178 \newline
35179 i >>= 4; 
35180 \newline
35181 ...
35182 \end_layout
35183
35184 \begin_layout Standard
35185 generates the following code:
35186 \end_layout
35187
35188 \begin_layout Verse
35189
35190 \family typewriter
35191 mov\InsetSpace ~
35192  a,_i 
35193 \newline
35194 swap a 
35195 \newline
35196 anl\InsetSpace ~
35197  a,#0x0f 
35198 \newline
35199 mov\InsetSpace ~
35200  _i,a
35201 \end_layout
35202
35203 \begin_layout Standard
35204 In general SDCC will never setup a loop if the shift count is known.
35205  Another example:
35206 \end_layout
35207
35208 \begin_layout Verse
35209
35210 \family typewriter
35211 unsigned int i; 
35212 \newline
35213 ...
35214  
35215 \newline
35216 i >>= 9; 
35217 \newline
35218 ...
35219 \end_layout
35220
35221 \begin_layout Standard
35222 will generate:
35223 \end_layout
35224
35225 \begin_layout Verse
35226
35227 \family typewriter
35228 mov\InsetSpace ~
35229 \InsetSpace ~
35230 a,(_i + 1) 
35231 \newline
35232 mov\InsetSpace ~
35233 \InsetSpace ~
35234 (_i + 1),#0x00 
35235 \newline
35236 clr\InsetSpace ~
35237 \InsetSpace ~
35238
35239 \newline
35240 rrc\InsetSpace ~
35241 \InsetSpace ~
35242
35243 \newline
35244 mov\InsetSpace ~
35245 \InsetSpace ~
35246 _i,a
35247 \end_layout
35248
35249 \begin_layout Subsection
35250 Bit-rotation
35251 \begin_inset LatexCommand \index{Bit rotation}
35252
35253 \end_inset
35254
35255
35256 \end_layout
35257
35258 \begin_layout Standard
35259 A special case of the bit-shift operation is bit rotation
35260 \begin_inset LatexCommand \index{rotating bits}
35261
35262 \end_inset
35263
35264 , SDCC recognizes the following expression to be a left bit-rotation:
35265 \end_layout
35266
35267 \begin_layout Verse
35268
35269 \family typewriter
35270 \series bold
35271 unsigned
35272 \series default
35273 \InsetSpace ~
35274 \InsetSpace ~
35275 char i;\InsetSpace ~
35276 \InsetSpace ~
35277 \InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283 \InsetSpace ~
35284 \InsetSpace ~
35285 \InsetSpace ~
35286 /* unsigned is needed for rotation */ 
35287 \newline
35288 ...
35289  
35290 \newline
35291 i = ((i << 1) | (i >> 7)); 
35292 \family default
35293
35294 \newline
35295
35296 \family typewriter
35297 ...
35298 \end_layout
35299
35300 \begin_layout Standard
35301 will generate the following code:
35302 \end_layout
35303
35304 \begin_layout Verse
35305
35306 \family typewriter
35307 mov\InsetSpace ~
35308 \InsetSpace ~
35309 a,_i 
35310 \newline
35311 rl\InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314
35315 \newline
35316 mov\InsetSpace ~
35317 \InsetSpace ~
35318 _i,a
35319 \end_layout
35320
35321 \begin_layout Standard
35322 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35323 ns of this case will also be recognized as bit-rotation, i.e.: 
35324 \end_layout
35325
35326 \begin_layout Verse
35327
35328 \family typewriter
35329 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35330 \end_layout
35331
35332 \begin_layout Subsection
35333 Nibble and Byte Swapping
35334 \end_layout
35335
35336 \begin_layout Standard
35337 Other special cases of the bit-shift operations are nibble or byte swapping
35338 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35339
35340 \end_inset
35341
35342 , SDCC recognizes the following expressions:
35343 \end_layout
35344
35345 \begin_layout Verse
35346
35347 \family typewriter
35348 \series bold
35349 unsigned
35350 \series default
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 char i; 
35354 \newline
35355
35356 \series bold
35357 unsigned
35358 \series default
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 int j; 
35362 \newline
35363 ...
35364  
35365 \newline
35366 i = ((i << 4) | (i >> 4)); 
35367 \family default
35368
35369 \newline
35370
35371 \family typewriter
35372 j = ((j << 8) | (j >> 8)); 
35373 \end_layout
35374
35375 \begin_layout Standard
35376 and generates a swap instruction for the nibble swapping
35377 \begin_inset LatexCommand \index{Nibble swapping}
35378
35379 \end_inset
35380
35381  or move instructions for the byte swapping
35382 \begin_inset LatexCommand \index{Byte swapping}
35383
35384 \end_inset
35385
35386 .
35387  The 
35388 \begin_inset Quotes sld
35389 \end_inset
35390
35391 j
35392 \begin_inset Quotes srd
35393 \end_inset
35394
35395  example can be used to convert from little to big-endian or vice versa.
35396  If you want to change the endianness of a 
35397 \emph on
35398 signed
35399 \emph default
35400  integer you have to cast to 
35401 \family typewriter
35402 (unsigned int)
35403 \family default
35404  first.
35405 \end_layout
35406
35407 \begin_layout Standard
35408 Note that SDCC stores numbers in little-endian
35409 \begin_inset Foot
35410 status open
35411
35412 \begin_layout Standard
35413 Usually 8-bit processors don't care much about endianness.
35414  This is not the case for the standard 8051 which only has an instruction
35415  to increment its 
35416 \emph on
35417 dptr
35418 \emph default
35419
35420 \begin_inset LatexCommand \index{DPTR}
35421
35422 \end_inset
35423
35424 -datapointer
35425 \emph on
35426  
35427 \emph default
35428 so little-endian is the more efficient byte order.
35429 \end_layout
35430
35431 \end_inset
35432
35433
35434 \begin_inset LatexCommand \index{little-endian}
35435
35436 \end_inset
35437
35438
35439 \begin_inset LatexCommand \index{Endianness}
35440
35441 \end_inset
35442
35443  format (i.e.
35444  lowest order first).
35445 \end_layout
35446
35447 \begin_layout Subsection
35448 Highest Order Bit
35449 \begin_inset LatexCommand \index{Highest Order Bit}
35450
35451 \end_inset
35452
35453  / Any Order Bit
35454 \begin_inset LatexCommand \index{Any Order Bit}
35455
35456 \end_inset
35457
35458
35459 \end_layout
35460
35461 \begin_layout Standard
35462 It is frequently required to obtain the highest order bit of an integral
35463  type (long, int, short or char types).
35464  Also obtaining any other order bit is not uncommon.
35465  SDCC recognizes the following expressions to yield the highest order bit
35466  and generates optimized code for it, e.g.:
35467 \end_layout
35468
35469 \begin_layout Verse
35470
35471 \family typewriter
35472 unsigned int gint; 
35473 \newline
35474
35475 \newline
35476 foo () { 
35477 \newline
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 unsigned char hob1, aob1; 
35481 \newline
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 bit hob2, hob3, aob2,
35485  aob3; 
35486 \newline
35487 \InsetSpace ~
35488 \InsetSpace ~
35489 ...
35490  
35491 \newline
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 hob1 = (gint >> 15) & 1; 
35495 \newline
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 hob2 = (gint >> 15) & 1; 
35499 \newline
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 hob3 = gint & 0x8000;
35503  
35504 \newline
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 aob1 = (gint >> 9) & 1; 
35508 \newline
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 aob2 = (gint >> 8) & 1; 
35512 \newline
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 aob3 = gint & 0x0800; 
35516 \newline
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 ..
35520  
35521 \newline
35522 }
35523 \end_layout
35524
35525 \begin_layout Standard
35526 will generate the following code:
35527 \end_layout
35528
35529 \begin_layout Verse
35530
35531 \family typewriter
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
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  61 ;\InsetSpace ~
35558  hob.c 7 
35559 \newline
35560 000A E5*01\InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 \InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575  62\InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583  mov\InsetSpace ~
35584 \InsetSpace ~
35585  a,(_gint + 1) 
35586 \newline
35587 000C 23\InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605  63\InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613  rl\InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616  a 
35617 \newline
35618 000D 54 01\InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 \InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633
35634  64\InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642  anl\InsetSpace ~
35643 \InsetSpace ~
35644  a,#0x01 
35645 \newline
35646 000F F5*02\InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 \InsetSpace ~
35656 \InsetSpace ~
35657 \InsetSpace ~
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661  65\InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669  mov\InsetSpace ~
35670 \InsetSpace ~
35671  _foo_hob1_1_1,a 
35672 \newline
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685 \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  66 ;\InsetSpace ~
35699  hob.c 8 
35700 \newline
35701 0011 E5*01\InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716
35717  67\InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725  mov\InsetSpace ~
35726 \InsetSpace ~
35727  a,(_gint + 1) 
35728 \newline
35729 0013 33\InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747  68\InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755  rlc\InsetSpace ~
35756 \InsetSpace ~
35757  a 
35758 \newline
35759 0014 92*00\InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765 \InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773 \InsetSpace ~
35774  69\InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782  mov\InsetSpace ~
35783 \InsetSpace ~
35784  _foo_hob2_1_1,c
35785  
35786 \newline
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
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  66 ;\InsetSpace ~
35813  hob.c 9 
35814 \newline
35815 0016 E5*01\InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830  67\InsetSpace ~
35831 \InsetSpace ~
35832 \InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838  mov\InsetSpace ~
35839 \InsetSpace ~
35840  a,(_gint + 1) 
35841 \newline
35842 0018 33\InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860  68\InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868  rlc\InsetSpace ~
35869 \InsetSpace ~
35870  a 
35871 \newline
35872 0019 92*01\InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887
35888  69\InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 \InsetSpace ~
35896  mov\InsetSpace ~
35897 \InsetSpace ~
35898  _foo_hob3_1_1,c 
35899 \newline
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925  70 ;\InsetSpace ~
35926  hob.c 10 
35927 \newline
35928 001B E5*01\InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943  71\InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951  mov\InsetSpace ~
35952 \InsetSpace ~
35953  a,(_gint + 1) 
35954 \newline
35955 001D
35956  03\InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974  72\InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982  rr\InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985  a 
35986 \newline
35987 001E 54 01\InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002  73\InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010  anl\InsetSpace ~
36011 \InsetSpace ~
36012  a,#0x01 
36013 \newline
36014 0020 F5*03\InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029  74\InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037  mov\InsetSpace ~
36038 \InsetSpace ~
36039  _foo_aob1_1_1,a
36040  
36041 \newline
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067  75 ;\InsetSpace ~
36068  hob.c 11 
36069 \newline
36070 0022 E5*01\InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085  76\InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093  mov\InsetSpace ~
36094 \InsetSpace ~
36095  a,(_gint + 1) 
36096 \newline
36097 0024 13\InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115  77\InsetSpace ~
36116 \InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 \InsetSpace ~
36123  rrc\InsetSpace ~
36124 \InsetSpace ~
36125  a 
36126 \newline
36127 0025 92*02\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
36143  78\InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 \InsetSpace ~
36149 \InsetSpace ~
36150 \InsetSpace ~
36151  mov\InsetSpace ~
36152 \InsetSpace ~
36153  _foo_aob2_1_1,c 
36154 \newline
36155 \InsetSpace ~
36156 \InsetSpace ~
36157 \InsetSpace ~
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 \InsetSpace ~
36163 \InsetSpace ~
36164 \InsetSpace ~
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 \InsetSpace ~
36175 \InsetSpace ~
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 \InsetSpace ~
36180  79 ;\InsetSpace ~
36181  hob.c 12 
36182 \newline
36183 0027 E5*01\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  80\InsetSpace ~
36199 \InsetSpace ~
36200 \InsetSpace ~
36201 \InsetSpace ~
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 \InsetSpace ~
36205 \InsetSpace ~
36206  mov\InsetSpace ~
36207 \InsetSpace ~
36208  a,(_gint + 1) 
36209 \newline
36210 0029
36211  A2 E3\InsetSpace ~
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 \InsetSpace ~
36215 \InsetSpace ~
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225 \InsetSpace ~
36226  81\InsetSpace ~
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 \InsetSpace ~
36230 \InsetSpace ~
36231 \InsetSpace ~
36232 \InsetSpace ~
36233 \InsetSpace ~
36234  mov\InsetSpace ~
36235 \InsetSpace ~
36236  c,acc[3] 
36237 \newline
36238 002B 92*03\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  82\InsetSpace ~
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261  mov\InsetSpace ~
36262 \InsetSpace ~
36263  _foo_aob3_1_1,c 
36264 \end_layout
36265
36266 \begin_layout Standard
36267 Other variations of these cases however will 
36268 \emph on
36269 not
36270 \emph default
36271  be recognized.
36272  They are standard C expressions, so I heartily recommend these be the only
36273  way to get the highest order bit, (it is portable).
36274  Of course it will be recognized even if it is embedded in other expressions,
36275  e.g.:
36276 \end_layout
36277
36278 \begin_layout Verse
36279
36280 \family typewriter
36281 xyz = gint + ((gint >> 15) & 1);
36282 \end_layout
36283
36284 \begin_layout Standard
36285 will still be recognized.
36286 \end_layout
36287
36288 \begin_layout Subsection
36289 Higher Order Byte
36290 \begin_inset LatexCommand \index{Higher Order Byte}
36291
36292 \end_inset
36293
36294  / Higher Order Word
36295 \begin_inset LatexCommand \index{Higher Order Word}
36296
36297 \end_inset
36298
36299
36300 \end_layout
36301
36302 \begin_layout Standard
36303 It is also frequently required to obtain a higher order byte or word of
36304  a larger integral type (long, int or short types).
36305  SDCC recognizes the following expressions to yield the higher order byte
36306  or word and generates optimized code for it, e.g.:
36307 \end_layout
36308
36309 \begin_layout Verse
36310
36311 \family typewriter
36312 unsigned int gint; 
36313 \newline
36314 unsigned long int glong; 
36315 \newline
36316
36317 \newline
36318 foo () { 
36319 \newline
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 unsigned char hob1,
36323  hob2; 
36324 \newline
36325 \InsetSpace ~
36326 \InsetSpace ~
36327 unsigned int how1, how2; 
36328 \newline
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 ...
36332  
36333 \newline
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 hob1 = (gint >> 8) & 0xFF; 
36337 \newline
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 hob2 = glong >> 24; 
36341 \newline
36342 \InsetSpace ~
36343 \InsetSpace ~
36344 how1 = (glong >> 16) & 0xFFFF;
36345  
36346 \newline
36347 \InsetSpace ~
36348 \InsetSpace ~
36349 how2 = glong >> 8; 
36350 \newline
36351 \InsetSpace ~
36352 \InsetSpace ~
36353 ..
36354  
36355 \newline
36356 }
36357 \end_layout
36358
36359 \begin_layout Standard
36360 will generate the following code:
36361 \end_layout
36362
36363 \begin_layout Verse
36364
36365 \family typewriter
36366 \InsetSpace ~
36367 \InsetSpace ~
36368 \InsetSpace ~
36369 \InsetSpace ~
36370 \InsetSpace ~
36371 \InsetSpace ~
36372 \InsetSpace ~
36373 \InsetSpace ~
36374 \InsetSpace ~
36375 \InsetSpace ~
36376 \InsetSpace ~
36377 \InsetSpace ~
36378 \InsetSpace ~
36379 \InsetSpace ~
36380 \InsetSpace ~
36381 \InsetSpace ~
36382 \InsetSpace ~
36383 \InsetSpace ~
36384 \InsetSpace ~
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 \InsetSpace ~
36389 \InsetSpace ~
36390 \InsetSpace ~
36391  91 ;\InsetSpace ~
36392  hob.c 15 
36393 \newline
36394 0037 85*01*06\InsetSpace ~
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 \InsetSpace ~
36398 \InsetSpace ~
36399 \InsetSpace ~
36400 \InsetSpace ~
36401 \InsetSpace ~
36402 \InsetSpace ~
36403 \InsetSpace ~
36404 \InsetSpace ~
36405 \InsetSpace ~
36406  92\InsetSpace ~
36407 \InsetSpace ~
36408 \InsetSpace ~
36409 \InsetSpace ~
36410 \InsetSpace ~
36411 \InsetSpace ~
36412 \InsetSpace ~
36413 \InsetSpace ~
36414  mov\InsetSpace ~
36415 \InsetSpace ~
36416  _foo_hob1_1_1,(_gint + 1) 
36417 \newline
36418 \InsetSpace ~
36419 \InsetSpace ~
36420 \InsetSpace ~
36421 \InsetSpace ~
36422 \InsetSpace ~
36423 \InsetSpace ~
36424 \InsetSpace ~
36425 \InsetSpace ~
36426 \InsetSpace ~
36427 \InsetSpace ~
36428 \InsetSpace ~
36429 \InsetSpace ~
36430 \InsetSpace ~
36431 \InsetSpace ~
36432 \InsetSpace ~
36433 \InsetSpace ~
36434 \InsetSpace ~
36435 \InsetSpace ~
36436 \InsetSpace ~
36437 \InsetSpace ~
36438 \InsetSpace ~
36439 \InsetSpace ~
36440 \InsetSpace ~
36441 \InsetSpace ~
36442 \InsetSpace ~
36443  93 ;\InsetSpace ~
36444  hob.c
36445  16 
36446 \newline
36447 003A 85*05*07\InsetSpace ~
36448 \InsetSpace ~
36449 \InsetSpace ~
36450 \InsetSpace ~
36451 \InsetSpace ~
36452 \InsetSpace ~
36453 \InsetSpace ~
36454 \InsetSpace ~
36455 \InsetSpace ~
36456 \InsetSpace ~
36457 \InsetSpace ~
36458 \InsetSpace ~
36459  94\InsetSpace ~
36460 \InsetSpace ~
36461 \InsetSpace ~
36462 \InsetSpace ~
36463 \InsetSpace ~
36464 \InsetSpace ~
36465 \InsetSpace ~
36466 \InsetSpace ~
36467  mov\InsetSpace ~
36468 \InsetSpace ~
36469  _foo_hob2_1_1,(_glong + 3) 
36470 \newline
36471 \InsetSpace ~
36472 \InsetSpace ~
36473 \InsetSpace ~
36474 \InsetSpace ~
36475 \InsetSpace ~
36476 \InsetSpace ~
36477 \InsetSpace ~
36478 \InsetSpace ~
36479 \InsetSpace ~
36480 \InsetSpace ~
36481 \InsetSpace ~
36482 \InsetSpace ~
36483 \InsetSpace ~
36484 \InsetSpace ~
36485 \InsetSpace ~
36486 \InsetSpace ~
36487 \InsetSpace ~
36488 \InsetSpace ~
36489 \InsetSpace ~
36490 \InsetSpace ~
36491 \InsetSpace ~
36492 \InsetSpace ~
36493 \InsetSpace ~
36494 \InsetSpace ~
36495 \InsetSpace ~
36496  95 ;\InsetSpace ~
36497  hob.c 17 
36498 \newline
36499 003D 85*04*08\InsetSpace ~
36500 \InsetSpace ~
36501 \InsetSpace ~
36502 \InsetSpace ~
36503 \InsetSpace ~
36504 \InsetSpace ~
36505 \InsetSpace ~
36506 \InsetSpace ~
36507 \InsetSpace ~
36508 \InsetSpace ~
36509 \InsetSpace ~
36510 \InsetSpace ~
36511
36512  96\InsetSpace ~
36513 \InsetSpace ~
36514 \InsetSpace ~
36515 \InsetSpace ~
36516 \InsetSpace ~
36517 \InsetSpace ~
36518 \InsetSpace ~
36519 \InsetSpace ~
36520  mov\InsetSpace ~
36521 \InsetSpace ~
36522  _foo_how1_1_1,(_glong + 2) 
36523 \newline
36524 0040 85*05*09\InsetSpace ~
36525 \InsetSpace ~
36526 \InsetSpace ~
36527 \InsetSpace ~
36528 \InsetSpace ~
36529 \InsetSpace ~
36530 \InsetSpace ~
36531 \InsetSpace ~
36532 \InsetSpace ~
36533 \InsetSpace ~
36534 \InsetSpace ~
36535 \InsetSpace ~
36536  97\InsetSpace ~
36537 \InsetSpace ~
36538 \InsetSpace ~
36539 \InsetSpace ~
36540 \InsetSpace ~
36541 \InsetSpace ~
36542 \InsetSpace ~
36543 \InsetSpace ~
36544  mov\InsetSpace ~
36545 \InsetSpace ~
36546  (_foo_how1_1_1 +
36547  1),(_glong + 3) 
36548 \newline
36549 0043 85*03*0A\InsetSpace ~
36550 \InsetSpace ~
36551 \InsetSpace ~
36552 \InsetSpace ~
36553 \InsetSpace ~
36554 \InsetSpace ~
36555 \InsetSpace ~
36556 \InsetSpace ~
36557 \InsetSpace ~
36558 \InsetSpace ~
36559 \InsetSpace ~
36560 \InsetSpace ~
36561  98\InsetSpace ~
36562 \InsetSpace ~
36563 \InsetSpace ~
36564 \InsetSpace ~
36565 \InsetSpace ~
36566 \InsetSpace ~
36567 \InsetSpace ~
36568 \InsetSpace ~
36569  mov\InsetSpace ~
36570 \InsetSpace ~
36571  _foo_how2_1_1,(_glong + 1) 
36572 \newline
36573 0046 85*04*0B\InsetSpace ~
36574 \InsetSpace ~
36575 \InsetSpace ~
36576 \InsetSpace ~
36577 \InsetSpace ~
36578 \InsetSpace ~
36579 \InsetSpace ~
36580 \InsetSpace ~
36581 \InsetSpace ~
36582 \InsetSpace ~
36583 \InsetSpace ~
36584 \InsetSpace ~
36585
36586  99\InsetSpace ~
36587 \InsetSpace ~
36588 \InsetSpace ~
36589 \InsetSpace ~
36590 \InsetSpace ~
36591 \InsetSpace ~
36592 \InsetSpace ~
36593 \InsetSpace ~
36594  mov\InsetSpace ~
36595 \InsetSpace ~
36596  (_foo_how2_1_1 + 1),(_glong + 2) 
36597 \end_layout
36598
36599 \begin_layout Standard
36600 Again, variations of these cases may 
36601 \emph on
36602 not
36603 \emph default
36604  be recognized.
36605  They are standard C expressions, so I heartily recommend these be the only
36606  way to get the higher order byte/word, (it is portable).
36607  Of course it will be recognized even if it is embedded in other expressions,
36608  e.g.:
36609 \end_layout
36610
36611 \begin_layout Verse
36612
36613 \family typewriter
36614 xyz = gint + ((gint >> 8) & 0xFF);
36615 \end_layout
36616
36617 \begin_layout Standard
36618 will still be recognized.
36619 \end_layout
36620
36621 \begin_layout Subsection
36622 Peephole Optimizer
36623 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36624
36625 \end_inset
36626
36627
36628 \begin_inset LatexCommand \index{Peephole optimizer}
36629
36630 \end_inset
36631
36632
36633 \end_layout
36634
36635 \begin_layout Standard
36636 The compiler uses a rule based, pattern matching and re-writing mechanism
36637  for peep-hole optimization.
36638  It is inspired by 
36639 \emph on
36640 copt
36641 \emph default
36642  a peep-hole optimizer by Christopher W.
36643  Fraser (cwfraser\InsetSpace ~
36644 @\InsetSpace ~
36645 microsoft.com).
36646  A default set of rules are compiled into the compiler, additional rules
36647  may be added with the 
36648 \emph on
36649 -
36650 \begin_inset ERT
36651 status collapsed
36652
36653 \begin_layout Standard
36654
36655
36656 \backslash
36657 /
36658 \end_layout
36659
36660 \end_inset
36661
36662 -peep-file
36663 \begin_inset LatexCommand \index{-\/-peep-file}
36664
36665 \end_inset
36666
36667  <filename>
36668 \emph default
36669  option.
36670  The rule language is best illustrated with examples.
36671 \end_layout
36672
36673 \begin_layout Verse
36674
36675 \family typewriter
36676 replace { 
36677 \newline
36678 \InsetSpace ~
36679 \InsetSpace ~
36680 mov %1,a 
36681 \newline
36682 \InsetSpace ~
36683 \InsetSpace ~
36684 mov a,%1
36685 \newline
36686 } by {
36687 \newline
36688 \InsetSpace ~
36689 \InsetSpace ~
36690 mov %1,a
36691 \newline
36692 }
36693 \end_layout
36694
36695 \begin_layout Standard
36696 The above rule will change the following assembly
36697 \begin_inset LatexCommand \index{Assembler routines}
36698
36699 \end_inset
36700
36701  sequence:
36702 \end_layout
36703
36704 \begin_layout Verse
36705
36706 \family typewriter
36707 mov r1,a 
36708 \newline
36709 mov a,r1
36710 \end_layout
36711
36712 \begin_layout Standard
36713 to
36714 \end_layout
36715
36716 \begin_layout Verse
36717
36718 \family typewriter
36719 mov r1,a
36720 \end_layout
36721
36722 \begin_layout Standard
36723 Note: All occurrences of a 
36724 \emph on
36725 %n
36726 \emph default
36727  (pattern variable) must denote the same string.
36728  With the above rule, the assembly sequence:
36729 \end_layout
36730
36731 \begin_layout Verse
36732
36733 \family typewriter
36734 mov r1,a 
36735 \newline
36736 mov a,r2
36737 \end_layout
36738
36739 \begin_layout Standard
36740 will remain unmodified.
36741 \newline
36742
36743 \newline
36744 Other special case optimizations may be added by the
36745  user (via 
36746 \emph on
36747 -
36748 \begin_inset ERT
36749 status collapsed
36750
36751 \begin_layout Standard
36752
36753
36754 \backslash
36755 /
36756 \end_layout
36757
36758 \end_inset
36759
36760 -peep-file option
36761 \emph default
36762 ).
36763  E.g.
36764  some variants of the 8051 MCU
36765 \begin_inset LatexCommand \index{MCS51 variants}
36766
36767 \end_inset
36768
36769  allow only 
36770 \family typewriter
36771 ajmp
36772 \family default
36773  and 
36774 \family typewriter
36775 acall
36776 \family default
36777 .
36778  The following two rules will change all 
36779 \family typewriter
36780 ljmp
36781 \family default
36782  and 
36783 \family typewriter
36784 lcall
36785 \family default
36786  to 
36787 \family typewriter
36788 ajmp
36789 \family default
36790  and 
36791 \family typewriter
36792 acall
36793 \end_layout
36794
36795 \begin_layout Verse
36796
36797 \family typewriter
36798 replace { lcall %1 } by { acall %1 } 
36799 \newline
36800 replace { ljmp %1 } by { ajmp %1 }
36801 \end_layout
36802
36803 \begin_layout Standard
36804 (NOTE: from version 2.7.3 on, you can use option -
36805 \emph on
36806
36807 \begin_inset ERT
36808 status collapsed
36809
36810 \begin_layout Standard
36811
36812
36813 \backslash
36814 /
36815 \end_layout
36816
36817 \end_inset
36818
36819
36820 \emph default
36821 -acall-ajmp
36822 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36823
36824 \end_inset
36825
36826 , which also takes care of aligning the interrupt vectors properly.)
36827 \newline
36828
36829 \end_layout
36830
36831 \begin_layout Standard
36832 The 
36833 \emph on
36834 inline-assembler code
36835 \emph default
36836  is also passed through the peep hole optimizer, thus the peephole optimizer
36837  can also be used as an assembly level macro expander.
36838  The rules themselves are MCU dependent whereas the rule language infra-structur
36839 e is MCU independent.
36840  Peephole optimization rules for other MCU can be easily programmed using
36841  the rule language.
36842 \newline
36843
36844 \newline
36845 The syntax for a rule is as follows:
36846 \end_layout
36847
36848 \begin_layout Verse
36849
36850 \family typewriter
36851 rule := replace [ restart ] '{' <assembly sequence> '
36852 \backslash
36853 n' 
36854 \newline
36855 \InsetSpace ~
36856  \InsetSpace ~
36857  \InsetSpace ~
36858  \InsetSpace ~
36859  \InsetSpace ~
36860  \InsetSpace ~
36861  \InsetSpace ~
36862  \InsetSpace ~
36863  \InsetSpace ~
36864  \InsetSpace ~
36865  \InsetSpace ~
36866  \InsetSpace ~
36867  \InsetSpace ~
36868  \InsetSpace ~
36869  '}' by '{' '
36870 \backslash
36871 n' 
36872 \newline
36873 \InsetSpace ~
36874  \InsetSpace ~
36875  \InsetSpace ~
36876  \InsetSpace ~
36877  \InsetSpace ~
36878  \InsetSpace ~
36879  \InsetSpace ~
36880  \InsetSpace ~
36881  \InsetSpace ~
36882  \InsetSpace ~
36883  \InsetSpace ~
36884  \InsetSpace ~
36885  \InsetSpace ~
36886  \InsetSpace ~
36887  \InsetSpace ~
36888  \InsetSpace ~
36889  <assembly sequence> '
36890 \backslash
36891 n' 
36892 \newline
36893 \InsetSpace ~
36894  \InsetSpace ~
36895  \InsetSpace ~
36896  \InsetSpace ~
36897  \InsetSpace ~
36898  \InsetSpace ~
36899  \InsetSpace ~
36900  \InsetSpace ~
36901  \InsetSpace ~
36902  \InsetSpace ~
36903  \InsetSpace ~
36904  \InsetSpace ~
36905  \InsetSpace ~
36906  \InsetSpace ~
36907  '}' [if <functionName> ] '
36908 \backslash
36909 n' 
36910 \end_layout
36911
36912 \begin_layout Standard
36913 <assembly sequence> := assembly instruction (each instruction including
36914  labels must be on a separate line).
36915 \newline
36916
36917 \newline
36918 The optimizer will apply to the rules
36919  one by one from the top in the sequence of their appearance, it will terminate
36920  when all rules are exhausted.
36921  If the 'restart' option is specified, then the optimizer will start matching
36922  the rules again from the top, this option for a rule is expensive (performance)
36923 , it is intended to be used in situations where a transformation will trigger
36924  the same rule again.
36925  An example of this (not a good one, it has side effects) is the following
36926  rule:
36927 \end_layout
36928
36929 \begin_layout Verse
36930
36931 \family typewriter
36932 replace restart { 
36933 \newline
36934 \InsetSpace ~
36935 \InsetSpace ~
36936 pop %1 
36937 \newline
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 push %1 } by { 
36941 \newline
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 ; nop 
36945 \newline
36946 }
36947 \end_layout
36948
36949 \begin_layout Standard
36950 Note that the replace pattern cannot be a blank, but can be a comment line.
36951  Without the 'restart' option only the innermost 'pop' 'push' pair would
36952  be eliminated, i.e.:
36953 \end_layout
36954
36955 \begin_layout Verse
36956
36957 \family typewriter
36958 pop ar1 
36959 \newline
36960 pop ar2 
36961 \newline
36962 push ar2 
36963 \newline
36964 push ar1
36965 \end_layout
36966
36967 \begin_layout Standard
36968 would result in:
36969 \end_layout
36970
36971 \begin_layout Verse
36972
36973 \family typewriter
36974 pop ar1 
36975 \newline
36976 ; nop 
36977 \newline
36978 push ar1
36979 \end_layout
36980
36981 \begin_layout Standard
36982
36983 \emph on
36984 with
36985 \emph default
36986  the restart option the rule will be applied again to the resulting code
36987  and then all the pop-push pairs will be eliminated to yield:
36988 \end_layout
36989
36990 \begin_layout Verse
36991
36992 \family typewriter
36993 ; nop 
36994 \newline
36995 ; nop
36996 \end_layout
36997
36998 \begin_layout Standard
36999 A conditional function can be attached to a rule.
37000  Attaching rules are somewhat more involved, let me illustrate this with
37001  an example.
37002 \end_layout
37003
37004 \begin_layout Verse
37005
37006 \family typewriter
37007 replace { 
37008 \newline
37009 \InsetSpace ~
37010  \InsetSpace ~
37011  \InsetSpace ~
37012 ljmp %5 
37013 \newline
37014 %2:
37015 \newline
37016 } by { 
37017 \newline
37018 \InsetSpace ~
37019  \InsetSpace ~
37020  \InsetSpace ~
37021 sjmp %5 
37022 \newline
37023 %2:
37024 \newline
37025 } if labelInRange
37026 \end_layout
37027
37028 \begin_layout Standard
37029 The optimizer does a look-up of a function name table defined in function
37030  
37031 \emph on
37032 callFuncByName
37033 \emph default
37034  in the source file SDCCpeeph.c, with the name 
37035 \emph on
37036 labelInRange
37037 \emph default
37038 .
37039  If it finds a corresponding entry the function is called.
37040  Note there can be no parameters specified for these functions, in this
37041  case the use of 
37042 \emph on
37043 %5
37044 \emph default
37045  is crucial, since the function 
37046 \emph on
37047 labelInRange
37048 \emph default
37049  expects to find the label in that particular variable (the hash table containin
37050 g the variable bindings is passed as a parameter).
37051  If you want to code more such functions, take a close look at the function
37052  labelInRange and the calling mechanism in source file SDCCpeeph.c.
37053  Currently implemented are 
37054 \emph on
37055 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
37056  24bitMode, portIsDS390, 24bitModeAndPortDS390 
37057 \emph default
37058 and
37059 \emph on
37060  notVolatile
37061 \emph default
37062 .
37063 \end_layout
37064
37065 \begin_layout Standard
37066 I know this whole thing is a little kludgey, but maybe some day we will
37067  have some better means.
37068  If you are looking at this file, you will see the default rules that are
37069  compiled into the compiler, you can add your own rules in the default set
37070  there if you get tired of specifying the -
37071 \begin_inset ERT
37072 status collapsed
37073
37074 \begin_layout Standard
37075
37076
37077 \backslash
37078 /
37079 \end_layout
37080
37081 \end_inset
37082
37083 -peep-file option.
37084 \end_layout
37085
37086 \begin_layout Section
37087 ANSI-Compliance
37088 \begin_inset LatexCommand \index{ANSI-compliance}
37089
37090 \end_inset
37091
37092
37093 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
37094
37095 \end_inset
37096
37097
37098 \end_layout
37099
37100 \begin_layout Standard
37101 The latest publically available version of the standard 
37102 \emph on
37103 ISO/IEC 9899 - Programming languages - C
37104 \emph default
37105  should be available at: 
37106 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
37107
37108 \end_inset
37109
37110 .
37111 \newline
37112
37113 \end_layout
37114
37115 \begin_layout Standard
37116 Deviations from the compliance:
37117 \end_layout
37118
37119 \begin_layout Itemize
37120 functions are not reentrant
37121 \begin_inset LatexCommand \index{reentrant}
37122
37123 \end_inset
37124
37125  unless explicitly declared as such or the 
37126 \series bold
37127 -
37128 \begin_inset ERT
37129 status collapsed
37130
37131 \begin_layout Standard
37132
37133
37134 \backslash
37135 /
37136 \end_layout
37137
37138 \end_inset
37139
37140 -stack-auto
37141 \begin_inset LatexCommand \index{-\/-stack-auto}
37142
37143 \end_inset
37144
37145
37146 \series default
37147  command line option is specified.
37148 \end_layout
37149
37150 \begin_layout Itemize
37151 structures
37152 \begin_inset LatexCommand \index{struct}
37153
37154 \end_inset
37155
37156  and unions
37157 \begin_inset LatexCommand \index{union}
37158
37159 \end_inset
37160
37161  cannot be assigned values directly, cannot be passed as function parameters
37162  or assigned to each other and cannot be a return value
37163 \begin_inset LatexCommand \index{return value}
37164
37165 \end_inset
37166
37167  from a function, e.g.:
37168 \end_layout
37169
37170 \begin_deeper
37171 \begin_layout Verse
37172
37173 \family typewriter
37174 struct s { ...
37175  }; 
37176 \newline
37177 struct s s1, s2; 
37178 \newline
37179 foo() 
37180 \newline
37181
37182 \newline
37183 \InsetSpace ~
37184 \InsetSpace ~
37185 \InsetSpace ~
37186 \InsetSpace ~
37187 ...
37188  
37189 \newline
37190 \InsetSpace ~
37191 \InsetSpace ~
37192 \InsetSpace ~
37193 \InsetSpace ~
37194 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
37195 \newline
37196 \InsetSpace ~
37197 \InsetSpace ~
37198 \InsetSpace ~
37199 \InsetSpace ~
37200 ...
37201  
37202 \newline
37203 }
37204 \newline
37205
37206 \series bold
37207 struct
37208 \series default
37209  s foo1 (
37210 \series bold
37211 struct
37212 \series default
37213  s parms) /* invalid in SDCC although allowed in ANSI */
37214 \newline
37215
37216 \newline
37217 \InsetSpace ~
37218 \InsetSpace ~
37219 \InsetSpace ~
37220 \InsetSpace ~
37221 struct s rets;
37222  
37223 \newline
37224 \InsetSpace ~
37225 \InsetSpace ~
37226 \InsetSpace ~
37227 \InsetSpace ~
37228 ...
37229  
37230 \newline
37231 \InsetSpace ~
37232 \InsetSpace ~
37233 \InsetSpace ~
37234 \InsetSpace ~
37235 return rets; /* is invalid in SDCC although allowed in ANSI */ 
37236 \newline
37237 }
37238 \end_layout
37239
37240 \end_deeper
37241 \begin_layout Itemize
37242 initialization of structure arrays must be fully braced.
37243 \end_layout
37244
37245 \begin_deeper
37246 \begin_layout Verse
37247
37248 \family typewriter
37249 struct s { char x } a[] = {1, 2};\InsetSpace ~
37250 \InsetSpace ~
37251 \InsetSpace ~
37252 \InsetSpace ~
37253 \InsetSpace ~
37254 /* invalid in SDCC */
37255 \newline
37256 struct s { char x
37257  } a[] = {{1}, {2}}; /* OK */
37258 \end_layout
37259
37260 \end_deeper
37261 \begin_layout Itemize
37262 'long long
37263 \begin_inset LatexCommand \index{long long (not supported)}
37264
37265 \end_inset
37266
37267 ' (64 bit integers
37268 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37269
37270 \end_inset
37271
37272 ) not supported.
37273 \end_layout
37274
37275 \begin_layout Itemize
37276 'double
37277 \begin_inset LatexCommand \index{double (not supported)}
37278
37279 \end_inset
37280
37281 ' precision floating point 
37282 \begin_inset LatexCommand \index{Floating point support}
37283
37284 \end_inset
37285
37286 not supported.
37287 \end_layout
37288
37289 \begin_layout Itemize
37290 Old K&R style
37291 \begin_inset LatexCommand \index{K\&R style}
37292
37293 \end_inset
37294
37295  function declarations are NOT allowed.
37296 \end_layout
37297
37298 \begin_deeper
37299 \begin_layout Verse
37300
37301 \family typewriter
37302 foo(i,j) /* this old style of function declarations */ 
37303 \newline
37304 int i,j; /* is valid
37305  in ANSI but not valid in SDCC */ 
37306 \newline
37307
37308 \newline
37309 \InsetSpace ~
37310 \InsetSpace ~
37311 \InsetSpace ~
37312 \InsetSpace ~
37313 ...
37314  
37315 \newline
37316 }
37317 \end_layout
37318
37319 \end_deeper
37320 \begin_layout Itemize
37321 Most enhancements in C99 are not supported, e.g.:
37322 \end_layout
37323
37324 \begin_deeper
37325 \begin_layout Verse
37326
37327 \family typewriter
37328 for (
37329 \series bold
37330 int
37331 \series default
37332  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37333 \end_layout
37334
37335 \end_deeper
37336 \begin_layout Itemize
37337 But some have been added recently in SDCC 2.7.0.
37338  They must be considered alpha quality however.
37339 \end_layout
37340
37341 \begin_deeper
37342 \begin_layout Verse
37343
37344 \family typewriter
37345 \series bold
37346 inline
37347 \begin_inset LatexCommand \index{inline (not supported)}
37348
37349 \end_inset
37350
37351
37352 \series default
37353  int increment (int a) { return a+1; } /* inlines the increment without
37354  function call overhead */
37355 \newline
37356 int * 
37357 \series bold
37358 restrict
37359 \begin_inset LatexCommand \index{inline (not supported)}
37360
37361 \end_inset
37362
37363
37364 \series default
37365  p; /* accepted but ignored */
37366 \end_layout
37367
37368 \end_deeper
37369 \begin_layout Itemize
37370 Certain words that are valid identifiers in the standard may be reserved
37371  words in SDCC unless the 
37372 \series bold
37373 -
37374 \begin_inset ERT
37375 status collapsed
37376
37377 \begin_layout Standard
37378
37379
37380 \backslash
37381 /
37382 \end_layout
37383
37384 \end_inset
37385
37386 -std-c89
37387 \begin_inset LatexCommand \index{-\/-std-c89}
37388
37389 \end_inset
37390
37391  
37392 \series default
37393 or
37394 \series bold
37395  -
37396 \begin_inset ERT
37397 status collapsed
37398
37399 \begin_layout Standard
37400
37401
37402 \backslash
37403 /
37404 \end_layout
37405
37406 \end_inset
37407
37408 -std-c99
37409 \begin_inset LatexCommand \index{-\/-std-c99}
37410
37411 \end_inset
37412
37413
37414 \series default
37415  command line options are used.
37416  These may include (depending on the selected processor): 'at', 'banked',
37417  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37418 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37419  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37420  '_naked'.
37421  Compliant equivalents of these keywords are always available in a form
37422  that begin with two underscores
37423 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37424
37425 \end_inset
37426
37427 , f.e.
37428  '__data' instead of 'data'.
37429 \end_layout
37430
37431 \begin_layout Itemize
37432 Integer promotion of variable arguments is not performed if the argument
37433  is explicitly taypecasted unless the
37434 \series bold
37435  -
37436 \begin_inset ERT
37437 status collapsed
37438
37439 \begin_layout Standard
37440
37441
37442 \backslash
37443 /
37444 \end_layout
37445
37446 \end_inset
37447
37448 -std-c89
37449 \begin_inset LatexCommand \index{-\/-std-c89}
37450
37451 \end_inset
37452
37453  
37454 \series default
37455 or
37456 \series bold
37457  -
37458 \begin_inset ERT
37459 status collapsed
37460
37461 \begin_layout Standard
37462
37463
37464 \backslash
37465 /
37466 \end_layout
37467
37468 \end_inset
37469
37470 -std-c99
37471 \begin_inset LatexCommand \index{-\/-std-c99}
37472
37473 \end_inset
37474
37475
37476 \series default
37477  command line options are used.
37478 \end_layout
37479
37480 \begin_deeper
37481 \begin_layout Verse
37482
37483 \family typewriter
37484 void vararg_func (char *str, ...) { str; }
37485 \newline
37486
37487 \newline
37488 void main (void)
37489 \newline
37490 {
37491 \newline
37492 \InsetSpace ~
37493 \InsetSpace ~
37494 char c = 10;
37495 \newline
37496
37497 \newline
37498 \InsetSpace ~
37499 \InsetSpace ~
37500 /* argument
37501  u is promoted to int before
37502 \newline
37503 \InsetSpace ~
37504 \InsetSpace ~
37505 \InsetSpace ~
37506 * passing to function */
37507 \newline
37508 \InsetSpace ~
37509 \InsetSpace ~
37510 vararg_func ("%c", c);
37511 \newline
37512
37513 \newline
37514 \InsetSpace ~
37515 \InsetSpace ~
37516 /*
37517  argument u is not promoted to int,
37518 \newline
37519 \InsetSpace ~
37520 \InsetSpace ~
37521 \InsetSpace ~
37522 * it is passed as char to function
37523 \newline
37524 \InsetSpace ~
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 * if
37528  --std-cXX is not defined;
37529 \newline
37530 \InsetSpace ~
37531 \InsetSpace ~
37532 \InsetSpace ~
37533 * is promoted to int before passing
37534 \newline
37535 \InsetSpace ~
37536 \InsetSpace ~
37537 \InsetSpace ~
37538 * to function
37539  if --std-cXX is defined */
37540 \newline
37541 \InsetSpace ~
37542 \InsetSpace ~
37543 vararg_func ("%bc", (char)u);
37544 \newline
37545 }
37546 \end_layout
37547
37548 \end_deeper
37549 \begin_layout Section
37550 Cyclomatic Complexity
37551 \begin_inset LatexCommand \index{Cyclomatic complexity}
37552
37553 \end_inset
37554
37555
37556 \end_layout
37557
37558 \begin_layout Standard
37559 Cyclomatic complexity of a function is defined as the number of independent
37560  paths the program can take during execution of the function.
37561  This is an important number since it defines the number test cases you
37562  have to generate to validate the function.
37563  The accepted industry standard for complexity number is 10, if the cyclomatic
37564  complexity reported by SDCC exceeds 10 you should think about simplification
37565  of the function logic.
37566  Note that the complexity level is not related to the number of lines of
37567  code in a function.
37568  Large functions can have low complexity, and small functions can have large
37569  complexity levels.
37570  
37571 \newline
37572
37573 \newline
37574 SDCC uses the following formula to compute the complexity:
37575 \newline
37576
37577 \end_layout
37578
37579 \begin_layout Standard
37580 complexity = (number of edges in control flow graph) - (number of nodes
37581  in control flow graph) + 2;
37582 \newline
37583
37584 \newline
37585 Having said that the industry standard is 10,
37586  you should be aware that in some cases it be may unavoidable to have a
37587  complexity level of less than 10.
37588  For example if you have switch statement with more than 10 case labels,
37589  each case label adds one to the complexity level.
37590  The complexity level is by no means an absolute measure of the algorithmic
37591  complexity of the function, it does however provide a good starting point
37592  for which functions you might look at for further optimization.
37593 \end_layout
37594
37595 \begin_layout Section
37596 Retargetting for other Processors
37597 \end_layout
37598
37599 \begin_layout Standard
37600 The issues for retargetting the compiler are far too numerous to be covered
37601  by this document.
37602  What follows is a brief description of each of the seven phases of the
37603  compiler and its MCU dependency.
37604 \end_layout
37605
37606 \begin_layout Itemize
37607 Parsing the source and building the annotated parse tree.
37608  This phase is largely MCU independent (except for the language extensions).
37609  Syntax & semantic checks are also done in this phase, along with some initial
37610  optimizations like back patching labels and the pattern matching optimizations
37611  like bit-rotation etc.
37612 \end_layout
37613
37614 \begin_layout Itemize
37615 The second phase involves generating an intermediate code which can be easy
37616  manipulated during the later phases.
37617  This phase is entirely MCU independent.
37618  The intermediate code generation assumes the target machine has unlimited
37619  number of registers, and designates them with the name iTemp.
37620  The compiler can be made to dump a human readable form of the code generated
37621  by using the -
37622 \begin_inset ERT
37623 status collapsed
37624
37625 \begin_layout Standard
37626
37627
37628 \backslash
37629 /
37630 \end_layout
37631
37632 \end_inset
37633
37634 -dumpraw option.
37635 \end_layout
37636
37637 \begin_layout Itemize
37638 This phase does the bulk of the standard optimizations and is also MCU independe
37639 nt.
37640  This phase can be broken down into several sub-phases:
37641 \newline
37642
37643 \newline
37644 Break down intermediate
37645  code (iCode) into basic blocks.
37646 \newline
37647 Do control flow & data flow analysis on the
37648  basic blocks.
37649 \newline
37650 Do local common subexpression elimination, then global subexpressio
37651 n elimination
37652 \newline
37653 Dead code elimination
37654 \newline
37655 Loop optimizations
37656 \newline
37657 If loop optimizations
37658  caused any changes then do 'global subexpression elimination' and 'dead
37659  code elimination' again.
37660 \end_layout
37661
37662 \begin_layout Itemize
37663 This phase determines the live-ranges; by live range I mean those iTemp
37664  variables defined by the compiler that still survive after all the optimization
37665 s.
37666  Live range analysis
37667 \begin_inset LatexCommand \index{Live range analysis}
37668
37669 \end_inset
37670
37671  is essential for register allocation, since these computation determines
37672  which of these iTemps will be assigned to registers, and for how long.
37673 \end_layout
37674
37675 \begin_layout Itemize
37676 Phase five is register allocation.
37677  There are two parts to this process.
37678 \newline
37679
37680 \newline
37681 The first part I call 'register packing'
37682  (for lack of a better term).
37683  In this case several MCU specific expression folding is done to reduce
37684  register pressure.
37685 \newline
37686
37687 \newline
37688 The second part is more MCU independent and deals with
37689  allocating registers to the remaining live ranges.
37690  A lot of MCU specific code does creep into this phase because of the limited
37691  number of index registers available in the 8051.
37692 \end_layout
37693
37694 \begin_layout Itemize
37695 The Code generation phase is (unhappily), entirely MCU dependent and very
37696  little (if any at all) of this code can be reused for other MCU.
37697  However the scheme for allocating a homogenized assembler operand for each
37698  iCode operand may be reused.
37699 \end_layout
37700
37701 \begin_layout Itemize
37702 As mentioned in the optimization section the peep-hole optimizer is rule
37703  based system, which can reprogrammed for other MCUs.
37704 \end_layout
37705
37706 \begin_layout Standard
37707 More information is available on SDCC Wiki
37708 \begin_inset LatexCommand \index{wiki}
37709
37710 \end_inset
37711
37712  (preliminary link 
37713 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37714
37715 \end_inset
37716
37717 ) and in the thread 
37718 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37719
37720 \end_inset
37721
37722  .
37723 \end_layout
37724
37725 \begin_layout Chapter
37726 Compiler internals
37727 \begin_inset LatexCommand \index{Compiler internals}
37728
37729 \end_inset
37730
37731
37732 \end_layout
37733
37734 \begin_layout Section
37735 The anatomy of the compiler
37736 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37737
37738 \end_inset
37739
37740
37741 \end_layout
37742
37743 \begin_layout Standard
37744
37745 \shape italic
37746 This is an excerpt from an article published in Circuit Cellar Magazine
37747  in 
37748 \series bold
37749 August 2000
37750 \series default
37751 .
37752  It's a little outdated (the compiler is much more efficient now and user/develo
37753 per friendly), but pretty well exposes the guts of it all.
37754 \shape default
37755
37756 \newline
37757
37758 \newline
37759 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37760  It is fairly easy to retarget for other 8-bit MCU.
37761  Here we take a look at some of the internals of the compiler.
37762  
37763 \end_layout
37764
37765 \begin_layout Paragraph*
37766 Parsing
37767 \begin_inset LatexCommand \index{Parsing}
37768
37769 \end_inset
37770
37771  
37772 \end_layout
37773
37774 \begin_layout Standard
37775 Parsing the input source file and creating an AST (Annotated Syntax Tree
37776 \begin_inset LatexCommand \index{Annotated syntax tree}
37777
37778 \end_inset
37779
37780 ).
37781  This phase also involves propagating types (annotating each node of the
37782  parse tree with type information) and semantic analysis.
37783  There are some MCU specific parsing rules.
37784  For example the storage classes, the extended storage classes are MCU specific
37785  while there may be a xdata storage class for 8051 there is no such storage
37786  class for z80 or Atmel AVR.
37787  SDCC allows MCU specific storage class extensions, i.e.
37788  xdata will be treated as a storage class specifier when parsing 8051 C
37789  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37790  C code.
37791 \end_layout
37792
37793 \begin_layout Paragraph*
37794 Generating iCode
37795 \begin_inset LatexCommand \index{iCode}
37796
37797 \end_inset
37798
37799
37800 \end_layout
37801
37802 \begin_layout Standard
37803 Intermediate code generation.
37804  In this phase the AST is broken down into three-operand form (iCode).
37805  These three operand forms are represented as doubly linked lists.
37806  ICode is the term given to the intermediate form generated by the compiler.
37807  ICode example section shows some examples of iCode generated for some simple
37808  C source functions.
37809 \end_layout
37810
37811 \begin_layout Paragraph*
37812 Optimizations
37813 \begin_inset LatexCommand \index{Optimizations}
37814
37815 \end_inset
37816
37817 .
37818 \end_layout
37819
37820 \begin_layout Standard
37821 Bulk of the target independent optimizations is performed in this phase.
37822  The optimizations include constant propagation, common sub-expression eliminati
37823 on, loop invariant code movement, strength reduction of loop induction variables
37824  and dead-code elimination.
37825 \end_layout
37826
37827 \begin_layout Paragraph*
37828 Live range analysis
37829 \begin_inset LatexCommand \index{Live range analysis}
37830
37831 \end_inset
37832
37833
37834 \end_layout
37835
37836 \begin_layout Standard
37837 During intermediate code generation phase, the compiler assumes the target
37838  machine has infinite number of registers and generates a lot of temporary
37839  variables.
37840  The live range computation determines the lifetime of each of these compiler-ge
37841 nerated temporaries.
37842  A picture speaks a thousand words.
37843  ICode example sections show the live range annotations for each of the
37844  operand.
37845  It is important to note here, each iCode is assigned a number in the order
37846  of its execution in the function.
37847  The live ranges are computed in terms of these numbers.
37848  The from number is the number of the iCode which first defines the operand
37849  and the to number signifies the iCode which uses this operand last.
37850 \end_layout
37851
37852 \begin_layout Paragraph*
37853 Register Allocation
37854 \begin_inset LatexCommand \index{Register allocation}
37855
37856 \end_inset
37857
37858
37859 \end_layout
37860
37861 \begin_layout Standard
37862 The register allocation determines the type and number of registers needed
37863  by each operand.
37864  In most MCUs only a few registers can be used for indirect addressing.
37865  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37866  address the internal ram and DPTR to indirectly address the external ram.
37867  The compiler will try to allocate the appropriate register to pointer variables
37868  if it can.
37869  ICode example section shows the operands annotated with the registers assigned
37870  to them.
37871  The compiler will try to keep operands in registers as much as possible;
37872  there are several schemes the compiler uses to do achieve this.
37873  When the compiler runs out of registers the compiler will check to see
37874  if there are any live operands which is not used or defined in the current
37875  basic block being processed, if there are any found then it will push that
37876  operand and use the registers in this block, the operand will then be popped
37877  at the end of the basic block.
37878  
37879 \end_layout
37880
37881 \begin_layout Standard
37882 There are other MCU specific considerations in this phase.
37883  Some MCUs have an accumulator; very short-lived operands could be assigned
37884  to the accumulator instead of a general-purpose register.
37885 \end_layout
37886
37887 \begin_layout Paragraph*
37888 Code generation
37889 \end_layout
37890
37891 \begin_layout Standard
37892 Figure II gives a table of iCode
37893 \begin_inset LatexCommand \index{iCode}
37894
37895 \end_inset
37896
37897  operations supported by the compiler.
37898  The code generation involves translating these operations into corresponding
37899  assembly code for the processor.
37900  This sounds overly simple but that is the essence of code generation.
37901  Some of the iCode operations are generated on a MCU specific manner for
37902  example, the z80 port does not use registers to pass parameters so the
37903  SEND and RECV iCode operations will not be generated, and it also does
37904  not support JUMPTABLES.
37905  
37906 \newline
37907
37908 \end_layout
37909
37910 \begin_layout Standard
37911
37912 \size footnotesize
37913 Figure II 
37914 \begin_inset Tabular
37915 <lyxtabular version="3" rows="39" columns="4">
37916 <features islongtable="true" headBottomDL="true">
37917 <column alignment="block" valignment="top" leftline="true" width="13col%">
37918 <column alignment="left" valignment="top" leftline="true" width="13col%">
37919 <column alignment="block" valignment="top" leftline="true" width="22col%">
37920 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37921 <row topline="true" bottomline="true" endhead="true">
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37923 \begin_inset Text
37924
37925 \begin_layout Standard
37926
37927 \series bold
37928 iCode
37929 \series default
37930
37931 \begin_inset LatexCommand \index{iCode}
37932
37933 \end_inset
37934
37935
37936 \end_layout
37937
37938 \end_inset
37939 </cell>
37940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37941 \begin_inset Text
37942
37943 \begin_layout Standard
37944
37945 \series bold
37946 Operands
37947 \end_layout
37948
37949 \end_inset
37950 </cell>
37951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37952 \begin_inset Text
37953
37954 \begin_layout Standard
37955
37956 \series bold
37957 Description
37958 \end_layout
37959
37960 \end_inset
37961 </cell>
37962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37963 \begin_inset Text
37964
37965 \begin_layout Standard
37966
37967 \series bold
37968 C Equivalent
37969 \end_layout
37970
37971 \end_inset
37972 </cell>
37973 </row>
37974 <row topline="true">
37975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37976 \begin_inset Text
37977
37978 \begin_layout Standard
37979
37980 \size footnotesize
37981 '!'
37982 \end_layout
37983
37984 \end_inset
37985 </cell>
37986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37987 \begin_inset Text
37988
37989 \begin_layout Standard
37990
37991 \size footnotesize
37992 IC_LEFT() IC_RESULT()
37993 \end_layout
37994
37995 \end_inset
37996 </cell>
37997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37998 \begin_inset Text
37999
38000 \begin_layout Standard
38001
38002 \size footnotesize
38003 NOT operation 
38004 \end_layout
38005
38006 \end_inset
38007 </cell>
38008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38009 \begin_inset Text
38010
38011 \begin_layout Standard
38012
38013 \size footnotesize
38014 IC_RESULT = ! IC_LEFT;
38015 \end_layout
38016
38017 \end_inset
38018 </cell>
38019 </row>
38020 <row topline="true">
38021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38022 \begin_inset Text
38023
38024 \begin_layout Standard
38025
38026 \size footnotesize
38027 '~'
38028 \end_layout
38029
38030 \end_inset
38031 </cell>
38032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38033 \begin_inset Text
38034
38035 \begin_layout Standard
38036
38037 \size footnotesize
38038 IC_LEFT() IC_RESULT()
38039 \end_layout
38040
38041 \end_inset
38042 </cell>
38043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38044 \begin_inset Text
38045
38046 \begin_layout Standard
38047
38048 \size footnotesize
38049 Bitwise complement of 
38050 \end_layout
38051
38052 \end_inset
38053 </cell>
38054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38055 \begin_inset Text
38056
38057 \begin_layout Standard
38058
38059 \size footnotesize
38060 IC_RESULT = ~IC_LEFT;
38061 \end_layout
38062
38063 \end_inset
38064 </cell>
38065 </row>
38066 <row topline="true">
38067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38068 \begin_inset Text
38069
38070 \begin_layout Standard
38071
38072 \size footnotesize
38073 RRC
38074 \end_layout
38075
38076 \end_inset
38077 </cell>
38078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38079 \begin_inset Text
38080
38081 \begin_layout Standard
38082
38083 \size footnotesize
38084 IC_LEFT() IC_RESULT()
38085 \end_layout
38086
38087 \end_inset
38088 </cell>
38089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38090 \begin_inset Text
38091
38092 \begin_layout Standard
38093
38094 \size footnotesize
38095 Rotate right with carry
38096 \end_layout
38097
38098 \end_inset
38099 </cell>
38100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38101 \begin_inset Text
38102
38103 \begin_layout Standard
38104
38105 \size footnotesize
38106 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
38107 \end_layout
38108
38109 \end_inset
38110 </cell>
38111 </row>
38112 <row topline="true">
38113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38114 \begin_inset Text
38115
38116 \begin_layout Standard
38117
38118 \size footnotesize
38119 RLC
38120 \end_layout
38121
38122 \end_inset
38123 </cell>
38124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38125 \begin_inset Text
38126
38127 \begin_layout Standard
38128
38129 \size footnotesize
38130 IC_LEFT() IC_RESULT()
38131 \end_layout
38132
38133 \end_inset
38134 </cell>
38135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38136 \begin_inset Text
38137
38138 \begin_layout Standard
38139
38140 \size footnotesize
38141 Rotate left with carry
38142 \end_layout
38143
38144 \end_inset
38145 </cell>
38146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38147 \begin_inset Text
38148
38149 \begin_layout Standard
38150
38151 \size footnotesize
38152 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38153 \end_layout
38154
38155 \end_inset
38156 </cell>
38157 </row>
38158 <row topline="true">
38159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38160 \begin_inset Text
38161
38162 \begin_layout Standard
38163
38164 \size footnotesize
38165 GETHBIT
38166 \end_layout
38167
38168 \end_inset
38169 </cell>
38170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38171 \begin_inset Text
38172
38173 \begin_layout Standard
38174
38175 \size footnotesize
38176 IC_LEFT() IC_RESULT()
38177 \end_layout
38178
38179 \end_inset
38180 </cell>
38181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38182 \begin_inset Text
38183
38184 \begin_layout Standard
38185
38186 \size footnotesize
38187 Get the highest order bit of IC_LEFT
38188 \end_layout
38189
38190 \end_inset
38191 </cell>
38192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38193 \begin_inset Text
38194
38195 \begin_layout Standard
38196
38197 \size footnotesize
38198 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38199 \end_layout
38200
38201 \end_inset
38202 </cell>
38203 </row>
38204 <row topline="true">
38205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38206 \begin_inset Text
38207
38208 \begin_layout Standard
38209
38210 \size footnotesize
38211 UNARYMINUS
38212 \end_layout
38213
38214 \end_inset
38215 </cell>
38216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38217 \begin_inset Text
38218
38219 \begin_layout Standard
38220
38221 \size footnotesize
38222 IC_LEFT() IC_RESULT()
38223 \end_layout
38224
38225 \end_inset
38226 </cell>
38227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38228 \begin_inset Text
38229
38230 \begin_layout Standard
38231
38232 \size footnotesize
38233 Unary minus
38234 \end_layout
38235
38236 \end_inset
38237 </cell>
38238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38239 \begin_inset Text
38240
38241 \begin_layout Standard
38242
38243 \size footnotesize
38244 IC_RESULT = - IC_LEFT;
38245 \end_layout
38246
38247 \end_inset
38248 </cell>
38249 </row>
38250 <row topline="true">
38251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38252 \begin_inset Text
38253
38254 \begin_layout Standard
38255
38256 \size footnotesize
38257 IPUSH
38258 \end_layout
38259
38260 \end_inset
38261 </cell>
38262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38263 \begin_inset Text
38264
38265 \begin_layout Standard
38266
38267 \size footnotesize
38268 IC_LEFT()
38269 \end_layout
38270
38271 \end_inset
38272 </cell>
38273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38274 \begin_inset Text
38275
38276 \begin_layout Standard
38277
38278 \size footnotesize
38279 Push the operand into stack
38280 \end_layout
38281
38282 \end_inset
38283 </cell>
38284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38285 \begin_inset Text
38286
38287 \begin_layout Standard
38288
38289 \size footnotesize
38290 NONE
38291 \end_layout
38292
38293 \end_inset
38294 </cell>
38295 </row>
38296 <row topline="true">
38297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38298 \begin_inset Text
38299
38300 \begin_layout Standard
38301
38302 \size footnotesize
38303 IPOP
38304 \end_layout
38305
38306 \end_inset
38307 </cell>
38308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38309 \begin_inset Text
38310
38311 \begin_layout Standard
38312
38313 \size footnotesize
38314 IC_LEFT()
38315 \end_layout
38316
38317 \end_inset
38318 </cell>
38319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38320 \begin_inset Text
38321
38322 \begin_layout Standard
38323
38324 \size footnotesize
38325 Pop the operand from the stack 
38326 \end_layout
38327
38328 \end_inset
38329 </cell>
38330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38331 \begin_inset Text
38332
38333 \begin_layout Standard
38334
38335 \size footnotesize
38336 NONE
38337 \end_layout
38338
38339 \end_inset
38340 </cell>
38341 </row>
38342 <row topline="true">
38343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38344 \begin_inset Text
38345
38346 \begin_layout Standard
38347
38348 \size footnotesize
38349 CALL
38350 \end_layout
38351
38352 \end_inset
38353 </cell>
38354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38355 \begin_inset Text
38356
38357 \begin_layout Standard
38358
38359 \size footnotesize
38360 IC_LEFT() IC_RESULT()
38361 \end_layout
38362
38363 \end_inset
38364 </cell>
38365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38366 \begin_inset Text
38367
38368 \begin_layout Standard
38369
38370 \size footnotesize
38371 Call the function represented by IC_LEFT 
38372 \end_layout
38373
38374 \end_inset
38375 </cell>
38376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38377 \begin_inset Text
38378
38379 \begin_layout Standard
38380
38381 \size footnotesize
38382 IC_RESULT = IC_LEFT();
38383 \end_layout
38384
38385 \end_inset
38386 </cell>
38387 </row>
38388 <row topline="true">
38389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38390 \begin_inset Text
38391
38392 \begin_layout Standard
38393
38394 \size footnotesize
38395 PCALL
38396 \end_layout
38397
38398 \end_inset
38399 </cell>
38400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38401 \begin_inset Text
38402
38403 \begin_layout Standard
38404
38405 \size footnotesize
38406 IC_LEFT() IC_RESULT()
38407 \end_layout
38408
38409 \end_inset
38410 </cell>
38411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38412 \begin_inset Text
38413
38414 \begin_layout Standard
38415
38416 \size footnotesize
38417 Call via function pointer
38418 \end_layout
38419
38420 \end_inset
38421 </cell>
38422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38423 \begin_inset Text
38424
38425 \begin_layout Standard
38426
38427 \size footnotesize
38428 IC_RESULT = (*IC_LEFT)();
38429 \end_layout
38430
38431 \end_inset
38432 </cell>
38433 </row>
38434 <row topline="true">
38435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38436 \begin_inset Text
38437
38438 \begin_layout Standard
38439
38440 \size footnotesize
38441 RETURN
38442 \end_layout
38443
38444 \end_inset
38445 </cell>
38446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38447 \begin_inset Text
38448
38449 \begin_layout Standard
38450
38451 \size footnotesize
38452 IC_LEFT()
38453 \end_layout
38454
38455 \end_inset
38456 </cell>
38457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38458 \begin_inset Text
38459
38460 \begin_layout Standard
38461
38462 \size footnotesize
38463 Return the value in operand IC_LEFT 
38464 \end_layout
38465
38466 \end_inset
38467 </cell>
38468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38469 \begin_inset Text
38470
38471 \begin_layout Standard
38472
38473 \size footnotesize
38474 return IC_LEFT;
38475 \end_layout
38476
38477 \end_inset
38478 </cell>
38479 </row>
38480 <row topline="true">
38481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38482 \begin_inset Text
38483
38484 \begin_layout Standard
38485
38486 \size footnotesize
38487 LABEL
38488 \end_layout
38489
38490 \end_inset
38491 </cell>
38492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38493 \begin_inset Text
38494
38495 \begin_layout Standard
38496
38497 \size footnotesize
38498 IC_LABEL() 
38499 \end_layout
38500
38501 \end_inset
38502 </cell>
38503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38504 \begin_inset Text
38505
38506 \begin_layout Standard
38507
38508 \size footnotesize
38509 Label
38510 \end_layout
38511
38512 \end_inset
38513 </cell>
38514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38515 \begin_inset Text
38516
38517 \begin_layout Standard
38518
38519 \size footnotesize
38520 IC_LABEL:
38521 \end_layout
38522
38523 \end_inset
38524 </cell>
38525 </row>
38526 <row topline="true">
38527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38528 \begin_inset Text
38529
38530 \begin_layout Standard
38531
38532 \size footnotesize
38533 GOTO
38534 \end_layout
38535
38536 \end_inset
38537 </cell>
38538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38539 \begin_inset Text
38540
38541 \begin_layout Standard
38542
38543 \size footnotesize
38544 IC_LABEL() 
38545 \end_layout
38546
38547 \end_inset
38548 </cell>
38549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38550 \begin_inset Text
38551
38552 \begin_layout Standard
38553
38554 \size footnotesize
38555 Goto label
38556 \end_layout
38557
38558 \end_inset
38559 </cell>
38560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38561 \begin_inset Text
38562
38563 \begin_layout Standard
38564
38565 \size footnotesize
38566 goto IC_LABEL();
38567 \end_layout
38568
38569 \end_inset
38570 </cell>
38571 </row>
38572 <row topline="true">
38573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38574 \begin_inset Text
38575
38576 \begin_layout Standard
38577
38578 \size footnotesize
38579 '+'
38580 \end_layout
38581
38582 \end_inset
38583 </cell>
38584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38585 \begin_inset Text
38586
38587 \begin_layout Standard
38588
38589 \size footnotesize
38590 IC_LEFT() IC_RIGHT() IC_RESULT()
38591 \end_layout
38592
38593 \end_inset
38594 </cell>
38595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38596 \begin_inset Text
38597
38598 \begin_layout Standard
38599
38600 \size footnotesize
38601 Addition
38602 \end_layout
38603
38604 \end_inset
38605 </cell>
38606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38607 \begin_inset Text
38608
38609 \begin_layout Standard
38610
38611 \size footnotesize
38612 IC_RESULT = IC_LEFT + IC_RIGHT
38613 \end_layout
38614
38615 \end_inset
38616 </cell>
38617 </row>
38618 <row topline="true">
38619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38620 \begin_inset Text
38621
38622 \begin_layout Standard
38623
38624 \size footnotesize
38625 '-'
38626 \end_layout
38627
38628 \end_inset
38629 </cell>
38630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38631 \begin_inset Text
38632
38633 \begin_layout Standard
38634
38635 \size footnotesize
38636 IC_LEFT() IC_RIGHT() IC_RESULT()
38637 \end_layout
38638
38639 \end_inset
38640 </cell>
38641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38642 \begin_inset Text
38643
38644 \begin_layout Standard
38645
38646 \size footnotesize
38647 Subtraction
38648 \end_layout
38649
38650 \end_inset
38651 </cell>
38652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38653 \begin_inset Text
38654
38655 \begin_layout Standard
38656
38657 \size footnotesize
38658 IC_RESULT = IC_LEFT - IC_RIGHT 
38659 \end_layout
38660
38661 \end_inset
38662 </cell>
38663 </row>
38664 <row topline="true">
38665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38666 \begin_inset Text
38667
38668 \begin_layout Standard
38669
38670 \size footnotesize
38671 '*'
38672 \end_layout
38673
38674 \end_inset
38675 </cell>
38676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38677 \begin_inset Text
38678
38679 \begin_layout Standard
38680
38681 \size footnotesize
38682 IC_LEFT() IC_RIGHT() IC_RESULT()
38683 \end_layout
38684
38685 \end_inset
38686 </cell>
38687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38688 \begin_inset Text
38689
38690 \begin_layout Standard
38691
38692 \size footnotesize
38693 Multiplication 
38694 \end_layout
38695
38696 \end_inset
38697 </cell>
38698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38699 \begin_inset Text
38700
38701 \begin_layout Standard
38702
38703 \size footnotesize
38704 IC_RESULT = IC_LEFT * IC_RIGHT;
38705 \end_layout
38706
38707 \end_inset
38708 </cell>
38709 </row>
38710 <row topline="true">
38711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38712 \begin_inset Text
38713
38714 \begin_layout Standard
38715
38716 \size footnotesize
38717 '/'
38718 \end_layout
38719
38720 \end_inset
38721 </cell>
38722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38723 \begin_inset Text
38724
38725 \begin_layout Standard
38726
38727 \size footnotesize
38728 IC_LEFT() IC_RIGHT() IC_RESULT()
38729 \end_layout
38730
38731 \end_inset
38732 </cell>
38733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38734 \begin_inset Text
38735
38736 \begin_layout Standard
38737
38738 \size footnotesize
38739 Division
38740 \end_layout
38741
38742 \end_inset
38743 </cell>
38744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38745 \begin_inset Text
38746
38747 \begin_layout Standard
38748
38749 \size footnotesize
38750 IC_RESULT = IC_LEFT / IC_RIGHT;
38751 \end_layout
38752
38753 \end_inset
38754 </cell>
38755 </row>
38756 <row topline="true">
38757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38758 \begin_inset Text
38759
38760 \begin_layout Standard
38761
38762 \size footnotesize
38763 '%'
38764 \end_layout
38765
38766 \end_inset
38767 </cell>
38768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38769 \begin_inset Text
38770
38771 \begin_layout Standard
38772
38773 \size footnotesize
38774 IC_LEFT() IC_RIGHT() IC_RESULT()
38775 \end_layout
38776
38777 \end_inset
38778 </cell>
38779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38780 \begin_inset Text
38781
38782 \begin_layout Standard
38783
38784 \size footnotesize
38785 Modulus
38786 \end_layout
38787
38788 \end_inset
38789 </cell>
38790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38791 \begin_inset Text
38792
38793 \begin_layout Standard
38794
38795 \size footnotesize
38796 IC_RESULT = IC_LEFT % IC_RIGHT;
38797 \end_layout
38798
38799 \end_inset
38800 </cell>
38801 </row>
38802 <row topline="true">
38803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38804 \begin_inset Text
38805
38806 \begin_layout Standard
38807
38808 \size footnotesize
38809 '<'
38810 \end_layout
38811
38812 \end_inset
38813 </cell>
38814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38815 \begin_inset Text
38816
38817 \begin_layout Standard
38818
38819 \size footnotesize
38820 IC_LEFT() IC_RIGHT() IC_RESULT()
38821 \end_layout
38822
38823 \end_inset
38824 </cell>
38825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38826 \begin_inset Text
38827
38828 \begin_layout Standard
38829
38830 \size footnotesize
38831 Less than
38832 \end_layout
38833
38834 \end_inset
38835 </cell>
38836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38837 \begin_inset Text
38838
38839 \begin_layout Standard
38840
38841 \size footnotesize
38842 IC_RESULT = IC_LEFT < IC_RIGHT;
38843 \end_layout
38844
38845 \end_inset
38846 </cell>
38847 </row>
38848 <row topline="true">
38849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38850 \begin_inset Text
38851
38852 \begin_layout Standard
38853
38854 \size footnotesize
38855 '>'
38856 \end_layout
38857
38858 \end_inset
38859 </cell>
38860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38861 \begin_inset Text
38862
38863 \begin_layout Standard
38864
38865 \size footnotesize
38866 IC_LEFT() IC_RIGHT() IC_RESULT()
38867 \end_layout
38868
38869 \end_inset
38870 </cell>
38871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38872 \begin_inset Text
38873
38874 \begin_layout Standard
38875
38876 \size footnotesize
38877 Greater than 
38878 \end_layout
38879
38880 \end_inset
38881 </cell>
38882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38883 \begin_inset Text
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 IC_RESULT = IC_LEFT > IC_RIGHT;
38889 \end_layout
38890
38891 \end_inset
38892 </cell>
38893 </row>
38894 <row topline="true">
38895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38896 \begin_inset Text
38897
38898 \begin_layout Standard
38899
38900 \size footnotesize
38901 EQ_OP
38902 \end_layout
38903
38904 \end_inset
38905 </cell>
38906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38907 \begin_inset Text
38908
38909 \begin_layout Standard
38910
38911 \size footnotesize
38912 IC_LEFT() IC_RIGHT() IC_RESULT()
38913 \end_layout
38914
38915 \end_inset
38916 </cell>
38917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38918 \begin_inset Text
38919
38920 \begin_layout Standard
38921
38922 \size footnotesize
38923 Equal to 
38924 \end_layout
38925
38926 \end_inset
38927 </cell>
38928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38929 \begin_inset Text
38930
38931 \begin_layout Standard
38932
38933 \size footnotesize
38934 IC_RESULT = IC_LEFT == IC_RIGHT;
38935 \end_layout
38936
38937 \end_inset
38938 </cell>
38939 </row>
38940 <row topline="true">
38941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38942 \begin_inset Text
38943
38944 \begin_layout Standard
38945
38946 \size footnotesize
38947 AND_OP
38948 \end_layout
38949
38950 \end_inset
38951 </cell>
38952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38953 \begin_inset Text
38954
38955 \begin_layout Standard
38956
38957 \size footnotesize
38958 IC_LEFT() IC_RIGHT() IC_RESULT() 
38959 \end_layout
38960
38961 \end_inset
38962 </cell>
38963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38964 \begin_inset Text
38965
38966 \begin_layout Standard
38967
38968 \size footnotesize
38969 Logical and operation
38970 \end_layout
38971
38972 \end_inset
38973 </cell>
38974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38975 \begin_inset Text
38976
38977 \begin_layout Standard
38978
38979 \size footnotesize
38980 IC_RESULT = IC_LEFT && IC_RIGHT; 
38981 \end_layout
38982
38983 \end_inset
38984 </cell>
38985 </row>
38986 <row topline="true">
38987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38988 \begin_inset Text
38989
38990 \begin_layout Standard
38991
38992 \size footnotesize
38993 OR_OP
38994 \end_layout
38995
38996 \end_inset
38997 </cell>
38998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38999 \begin_inset Text
39000
39001 \begin_layout Standard
39002
39003 \size footnotesize
39004 IC_LEFT() IC_RIGHT() IC_RESULT() 
39005 \end_layout
39006
39007 \end_inset
39008 </cell>
39009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39010 \begin_inset Text
39011
39012 \begin_layout Standard
39013
39014 \size footnotesize
39015 Logical or operation 
39016 \end_layout
39017
39018 \end_inset
39019 </cell>
39020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39021 \begin_inset Text
39022
39023 \begin_layout Standard
39024
39025 \size footnotesize
39026 IC_RESULT = IC_LEFT || IC_RIGHT; 
39027 \end_layout
39028
39029 \end_inset
39030 </cell>
39031 </row>
39032 <row topline="true">
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 '^'
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
39051 \end_layout
39052
39053 \end_inset
39054 </cell>
39055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39056 \begin_inset Text
39057
39058 \begin_layout Standard
39059
39060 \size footnotesize
39061 Exclusive OR
39062 \end_layout
39063
39064 \end_inset
39065 </cell>
39066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39067 \begin_inset Text
39068
39069 \begin_layout Standard
39070
39071 \size footnotesize
39072 IC_RESULT = IC_LEFT ^ IC_RIGHT;
39073 \end_layout
39074
39075 \end_inset
39076 </cell>
39077 </row>
39078 <row topline="true">
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 '|'
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
39097 \end_layout
39098
39099 \end_inset
39100 </cell>
39101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39102 \begin_inset Text
39103
39104 \begin_layout Standard
39105
39106 \size footnotesize
39107 Bitwise OR 
39108 \end_layout
39109
39110 \end_inset
39111 </cell>
39112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39113 \begin_inset Text
39114
39115 \begin_layout Standard
39116
39117 \size footnotesize
39118 IC_RESULT = IC_LEFT | IC_RIGHT;
39119 \end_layout
39120
39121 \end_inset
39122 </cell>
39123 </row>
39124 <row topline="true">
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 BITWISEAND
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 IC_LEFT() IC_RIGHT() IC_RESULT()
39143 \end_layout
39144
39145 \end_inset
39146 </cell>
39147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39148 \begin_inset Text
39149
39150 \begin_layout Standard
39151
39152 \size footnotesize
39153 Bitwise AND 
39154 \end_layout
39155
39156 \end_inset
39157 </cell>
39158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39159 \begin_inset Text
39160
39161 \begin_layout Standard
39162
39163 \size footnotesize
39164 IC_RESULT = IC_LEFT & IC_RIGHT;
39165 \end_layout
39166
39167 \end_inset
39168 </cell>
39169 </row>
39170 <row topline="true">
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 LEFT_OP
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 IC_LEFT() IC_RIGHT() IC_RESULT()
39189 \end_layout
39190
39191 \end_inset
39192 </cell>
39193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39194 \begin_inset Text
39195
39196 \begin_layout Standard
39197
39198 \size footnotesize
39199 Left shift 
39200 \end_layout
39201
39202 \end_inset
39203 </cell>
39204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39205 \begin_inset Text
39206
39207 \begin_layout Standard
39208
39209 \size footnotesize
39210 IC_RESULT = IC_LEFT << IC_RIGHT 
39211 \end_layout
39212
39213 \end_inset
39214 </cell>
39215 </row>
39216 <row topline="true">
39217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39218 \begin_inset Text
39219
39220 \begin_layout Standard
39221
39222 \size footnotesize
39223 RIGHT_OP
39224 \end_layout
39225
39226 \end_inset
39227 </cell>
39228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39229 \begin_inset Text
39230
39231 \begin_layout Standard
39232
39233 \size footnotesize
39234 IC_LEFT() IC_RIGHT() IC_RESULT()
39235 \end_layout
39236
39237 \end_inset
39238 </cell>
39239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39240 \begin_inset Text
39241
39242 \begin_layout Standard
39243
39244 \size footnotesize
39245 Right shift
39246 \end_layout
39247
39248 \end_inset
39249 </cell>
39250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39251 \begin_inset Text
39252
39253 \begin_layout Standard
39254
39255 \size footnotesize
39256 IC_RESULT = IC_LEFT >> IC_RIGHT 
39257 \end_layout
39258
39259 \end_inset
39260 </cell>
39261 </row>
39262 <row topline="true">
39263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39264 \begin_inset Text
39265
39266 \begin_layout Standard
39267
39268 \size footnotesize
39269 GET_VALUE_
39270 \newline
39271 AT_ ADDRESS
39272 \end_layout
39273
39274 \end_inset
39275 </cell>
39276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39277 \begin_inset Text
39278
39279 \begin_layout Standard
39280
39281 \size footnotesize
39282 IC_LEFT() IC_RESULT()
39283 \end_layout
39284
39285 \end_inset
39286 </cell>
39287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39288 \begin_inset Text
39289
39290 \begin_layout Standard
39291
39292 \size footnotesize
39293 Indirect fetch 
39294 \end_layout
39295
39296 \end_inset
39297 </cell>
39298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39299 \begin_inset Text
39300
39301 \begin_layout Standard
39302
39303 \size footnotesize
39304 IC_RESULT = (*IC_LEFT);
39305 \end_layout
39306
39307 \end_inset
39308 </cell>
39309 </row>
39310 <row topline="true">
39311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39312 \begin_inset Text
39313
39314 \begin_layout Standard
39315
39316 \size footnotesize
39317 POINTER_SET
39318 \end_layout
39319
39320 \end_inset
39321 </cell>
39322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39323 \begin_inset Text
39324
39325 \begin_layout Standard
39326
39327 \size footnotesize
39328 IC_RIGHT() IC_RESULT() 
39329 \end_layout
39330
39331 \end_inset
39332 </cell>
39333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39334 \begin_inset Text
39335
39336 \begin_layout Standard
39337
39338 \size footnotesize
39339 Indirect set
39340 \end_layout
39341
39342 \end_inset
39343 </cell>
39344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39345 \begin_inset Text
39346
39347 \begin_layout Standard
39348
39349 \size footnotesize
39350 (*IC_RESULT) = IC_RIGHT;
39351 \end_layout
39352
39353 \end_inset
39354 </cell>
39355 </row>
39356 <row topline="true">
39357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39358 \begin_inset Text
39359
39360 \begin_layout Standard
39361
39362 \size footnotesize
39363 '='
39364 \end_layout
39365
39366 \end_inset
39367 </cell>
39368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39369 \begin_inset Text
39370
39371 \begin_layout Standard
39372
39373 \size footnotesize
39374 IC_RIGHT() IC_RESULT()
39375 \end_layout
39376
39377 \end_inset
39378 </cell>
39379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39380 \begin_inset Text
39381
39382 \begin_layout Standard
39383
39384 \size footnotesize
39385 Assignment
39386 \end_layout
39387
39388 \end_inset
39389 </cell>
39390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39391 \begin_inset Text
39392
39393 \begin_layout Standard
39394
39395 \size footnotesize
39396 IC_RESULT = IC_RIGHT;
39397 \end_layout
39398
39399 \end_inset
39400 </cell>
39401 </row>
39402 <row topline="true">
39403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39404 \begin_inset Text
39405
39406 \begin_layout Standard
39407
39408 \size footnotesize
39409 IFX
39410 \end_layout
39411
39412 \end_inset
39413 </cell>
39414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39415 \begin_inset Text
39416
39417 \begin_layout Standard
39418
39419 \size footnotesize
39420 IC_COND IC_TRUE IC_LABEL
39421 \end_layout
39422
39423 \end_inset
39424 </cell>
39425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39426 \begin_inset Text
39427
39428 \begin_layout Standard
39429
39430 \size footnotesize
39431 Conditional jump.
39432  If true label is present then jump to true label if condition is true else
39433  jump to false label if condition is false 
39434 \end_layout
39435
39436 \end_inset
39437 </cell>
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39439 \begin_inset Text
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 if (IC_COND) goto IC_TRUE; 
39445 \newline
39446 \InsetSpace ~
39447 \InsetSpace ~
39448 Or 
39449 \newline
39450 If (!IC_COND) goto IC_FALSE;
39451 \end_layout
39452
39453 \end_inset
39454 </cell>
39455 </row>
39456 <row topline="true">
39457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39458 \begin_inset Text
39459
39460 \begin_layout Standard
39461
39462 \size footnotesize
39463 ADDRESS_OF
39464 \end_layout
39465
39466 \end_inset
39467 </cell>
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39469 \begin_inset Text
39470
39471 \begin_layout Standard
39472
39473 \size footnotesize
39474 IC_LEFT() IC_RESULT()
39475 \end_layout
39476
39477 \end_inset
39478 </cell>
39479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39480 \begin_inset Text
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 Address of 
39486 \end_layout
39487
39488 \end_inset
39489 </cell>
39490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39491 \begin_inset Text
39492
39493 \begin_layout Standard
39494
39495 \size footnotesize
39496 IC_RESULT = &IC_LEFT();
39497 \end_layout
39498
39499 \end_inset
39500 </cell>
39501 </row>
39502 <row topline="true">
39503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39504 \begin_inset Text
39505
39506 \begin_layout Standard
39507
39508 \size footnotesize
39509 JUMPTABLE
39510 \end_layout
39511
39512 \end_inset
39513 </cell>
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_inset Text
39516
39517 \begin_layout Standard
39518
39519 \size footnotesize
39520 IC_JTCOND IC_JTLABELS
39521 \end_layout
39522
39523 \end_inset
39524 </cell>
39525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39526 \begin_inset Text
39527
39528 \begin_layout Standard
39529
39530 \size footnotesize
39531 Jump to list of labels depending on the value of JTCOND
39532 \end_layout
39533
39534 \end_inset
39535 </cell>
39536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39537 \begin_inset Text
39538
39539 \begin_layout Standard
39540
39541 \size footnotesize
39542 Switch statement
39543 \end_layout
39544
39545 \end_inset
39546 </cell>
39547 </row>
39548 <row topline="true">
39549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39550 \begin_inset Text
39551
39552 \begin_layout Standard
39553
39554 \size footnotesize
39555 CAST
39556 \end_layout
39557
39558 \end_inset
39559 </cell>
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39561 \begin_inset Text
39562
39563 \begin_layout Standard
39564
39565 \size footnotesize
39566 IC_RIGHT() IC_LEFT() IC_RESULT()
39567 \end_layout
39568
39569 \end_inset
39570 </cell>
39571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39572 \begin_inset Text
39573
39574 \begin_layout Standard
39575
39576 \size footnotesize
39577 Cast types 
39578 \end_layout
39579
39580 \end_inset
39581 </cell>
39582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39583 \begin_inset Text
39584
39585 \begin_layout Standard
39586
39587 \size footnotesize
39588 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39589 \end_layout
39590
39591 \end_inset
39592 </cell>
39593 </row>
39594 <row topline="true">
39595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39596 \begin_inset Text
39597
39598 \begin_layout Standard
39599
39600 \size footnotesize
39601 SEND
39602 \end_layout
39603
39604 \end_inset
39605 </cell>
39606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39607 \begin_inset Text
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 IC_LEFT()
39613 \end_layout
39614
39615 \end_inset
39616 </cell>
39617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39618 \begin_inset Text
39619
39620 \begin_layout Standard
39621
39622 \size footnotesize
39623 This is used for passing parameters in registers; 
39624 \newline
39625 move IC_LEFT to the next
39626  available parameter register.
39627 \end_layout
39628
39629 \end_inset
39630 </cell>
39631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39632 \begin_inset Text
39633
39634 \begin_layout Standard
39635
39636 \size footnotesize
39637 None
39638 \end_layout
39639
39640 \end_inset
39641 </cell>
39642 </row>
39643 <row topline="true">
39644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39645 \begin_inset Text
39646
39647 \begin_layout Standard
39648
39649 \size footnotesize
39650 RECV
39651 \end_layout
39652
39653 \end_inset
39654 </cell>
39655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39656 \begin_inset Text
39657
39658 \begin_layout Standard
39659
39660 \size footnotesize
39661 IC_RESULT()
39662 \end_layout
39663
39664 \end_inset
39665 </cell>
39666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39667 \begin_inset Text
39668
39669 \begin_layout Standard
39670
39671 \size footnotesize
39672 This is used for receiving parameters passed in registers;
39673 \newline
39674 Move the values
39675  in the next parameter register to IC_RESULT 
39676 \end_layout
39677
39678 \end_inset
39679 </cell>
39680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39681 \begin_inset Text
39682
39683 \begin_layout Standard
39684
39685 \size footnotesize
39686 None
39687 \end_layout
39688
39689 \end_inset
39690 </cell>
39691 </row>
39692 <row topline="true" bottomline="true">
39693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39694 \begin_inset Text
39695
39696 \begin_layout Standard
39697
39698 \shape slanted
39699 \size footnotesize
39700 (some more have been added)
39701 \end_layout
39702
39703 \end_inset
39704 </cell>
39705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39706 \begin_inset Text
39707
39708 \begin_layout Standard
39709
39710 \end_layout
39711
39712 \end_inset
39713 </cell>
39714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39715 \begin_inset Text
39716
39717 \begin_layout Standard
39718
39719 \end_layout
39720
39721 \end_inset
39722 </cell>
39723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39724 \begin_inset Text
39725
39726 \begin_layout Standard
39727
39728 \shape slanted
39729 \size footnotesize
39730 see f.e.
39731  
39732 \family typewriter
39733 gen51Code()
39734 \family default
39735  in 
39736 \family typewriter
39737 src/mcs51/gen.c
39738 \end_layout
39739
39740 \end_inset
39741 </cell>
39742 </row>
39743 </lyxtabular>
39744
39745 \end_inset
39746
39747
39748 \end_layout
39749
39750 \begin_layout Standard
39751 \begin_inset Note Note
39752 status collapsed
39753
39754 \begin_layout Standard
39755 In the original article Figure II was announced to be downloadable on 
39756 \shape italic
39757 Circuit Cellar
39758 \shape default
39759 's web site.
39760  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39761 \end_layout
39762
39763 \end_inset
39764
39765
39766 \end_layout
39767
39768 \begin_layout Paragraph*
39769 ICode Example
39770 \begin_inset LatexCommand \index{iCode}
39771
39772 \end_inset
39773
39774
39775 \end_layout
39776
39777 \begin_layout Standard
39778 This section shows some details of iCode.
39779  The example C code does not do anything useful; it is used as an example
39780  to illustrate the intermediate code generated by the compiler.
39781 \end_layout
39782
39783 \begin_layout Verse
39784
39785 \family typewriter
39786 1.\InsetSpace ~
39787 xdata int * p;
39788 \newline
39789 2.\InsetSpace ~
39790 int gint;
39791 \newline
39792 3.\InsetSpace ~
39793 /* This function does nothing useful.
39794  It is used
39795 \newline
39796 4.\InsetSpace ~
39797 \InsetSpace ~
39798 \InsetSpace ~
39799 \InsetSpace ~
39800 for the purpose of explaining iCode */
39801 \newline
39802 5.\InsetSpace ~
39803 short function (data
39804  int *x)
39805 \newline
39806 6.\InsetSpace ~
39807 {
39808 \newline
39809 7.\InsetSpace ~
39810 \InsetSpace ~
39811 \InsetSpace ~
39812 short i=10; \InsetSpace ~
39813 \InsetSpace ~
39814 /* dead initialization eliminated */
39815 \newline
39816 8.\InsetSpace ~
39817 \InsetSpace ~
39818 \InsetSpace ~
39819 short sum=10;
39820  /* dead initialization eliminated */
39821 \newline
39822 9.\InsetSpace ~
39823 \InsetSpace ~
39824 \InsetSpace ~
39825 short mul;
39826 \newline
39827 10.\InsetSpace ~
39828 \InsetSpace ~
39829 int j ;
39830 \newline
39831 11.\InsetSpace ~
39832 \InsetSpace ~
39833 while (*x) *x++
39834  = *p++; 
39835 \newline
39836 12.\InsetSpace ~
39837 \InsetSpace ~
39838 \InsetSpace ~
39839 \InsetSpace ~
39840 sum = 0 ; 
39841 \newline
39842 13.\InsetSpace ~
39843 \InsetSpace ~
39844 mul = 0;
39845 \newline
39846 14.\InsetSpace ~
39847 \InsetSpace ~
39848 /* compiler detects i,j to be induction
39849  variables */
39850 \newline
39851 15.\InsetSpace ~
39852 \InsetSpace ~
39853 for (i = 0, j = 10 ; i < 10 ; i++, j
39854 \family default
39855 -
39856 \begin_inset ERT
39857 status collapsed
39858
39859 \begin_layout Standard
39860
39861
39862 \backslash
39863 /
39864 \end_layout
39865
39866 \end_inset
39867
39868 -
39869 \family typewriter
39870 ) {
39871 \newline
39872 16.\InsetSpace ~
39873 \InsetSpace ~
39874 \InsetSpace ~
39875 \InsetSpace ~
39876 sum += i;
39877 \newline
39878 17.\InsetSpace ~
39879 \InsetSpace ~
39880 \InsetSpace ~
39881 \InsetSpace ~
39882 mul += i * 3; \InsetSpace ~
39883 \InsetSpace ~
39884 /* this multiplication remains */
39885 \newline
39886 18.\InsetSpace ~
39887 \InsetSpace ~
39888 \InsetSpace ~
39889 \InsetSpace ~
39890 gint +=
39891  j * 3;\InsetSpace ~
39892 \InsetSpace ~
39893 /* this multiplication changed to addition */
39894 \newline
39895 19.\InsetSpace ~
39896 \InsetSpace ~
39897 }
39898 \newline
39899 20.\InsetSpace ~
39900 \InsetSpace ~
39901 return sum+mul;
39902 \newline
39903 21.\InsetSpace ~
39904 }
39905 \end_layout
39906
39907 \begin_layout Standard
39908 In addition to the operands each iCode contains information about the filename
39909  and line it corresponds to in the source file.
39910  The first field in the listing should be interpreted as follows:
39911 \newline
39912
39913 \shape italic
39914 \size footnotesize
39915 Filename(linenumber: iCode Execution sequence number : ICode hash table
39916  key : loop depth of the iCode).
39917 \shape default
39918 \size default
39919
39920 \newline
39921 Then follows the human readable form of the ICode operation.
39922  Each operand of this triplet form can be of three basic types a) compiler
39923  generated temporary b) user defined variable c) a constant value.
39924  Note that local variables and parameters are replaced by compiler generated
39925  temporaries.
39926  Live ranges
39927 \begin_inset LatexCommand \index{Live range analysis}
39928
39929 \end_inset
39930
39931  are computed only for temporaries (i.e.
39932  live ranges are not computed for global variables).
39933  Registers
39934 \begin_inset LatexCommand \index{Register allocation}
39935
39936 \end_inset
39937
39938  are allocated for temporaries only.
39939  Operands are formatted in the following manner:
39940 \newline
39941
39942 \shape italic
39943 \size footnotesize
39944 Operand Name [lr live-from : live-to ] { type information } [ registers
39945  allocated ].
39946 \shape default
39947 \size default
39948
39949 \newline
39950 As mentioned earlier the live ranges are computed in terms of the execution
39951  sequence number of the iCodes, for example 
39952 \newline
39953 the iTemp0 is live from (i.e.
39954  first defined in iCode with execution sequence number 3, and is last used
39955  in the iCode with sequence number 5).
39956  For induction variables such as iTemp21 the live range computation extends
39957  the lifetime from the start to the end of the loop.
39958 \newline
39959 The register allocator
39960  used the live range information to allocate registers, the same registers
39961  may be used for different temporaries if their live ranges do not overlap,
39962  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39963  ranges do not overlap.
39964  In addition the allocator also takes into consideration the type and usage
39965  of a temporary, for example itemp6 is a pointer to near space and is used
39966  as to fetch data from (i.e.
39967  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39968  Some short lived temporaries are allocated to special registers which have
39969  meaning to the code generator e.g.
39970  iTemp13 is allocated to a pseudo register CC which tells the back end that
39971  the temporary is used only for a conditional jump the code generation makes
39972  use of this information to optimize a compare and jump ICode.
39973 \newline
39974 There are several
39975  loop optimizations
39976 \begin_inset LatexCommand \index{Loop optimization}
39977
39978 \end_inset
39979
39980  performed by the compiler.
39981  It can detect induction variables iTemp21(i) and iTemp23(j).
39982  Also note the compiler does selective strength reduction
39983 \begin_inset LatexCommand \index{Strength reduction}
39984
39985 \end_inset
39986
39987 , i.e.
39988  the multiplication of an induction variable in line 18 (gint = j * 3) is
39989  changed to addition, a new temporary iTemp17 is allocated and assigned
39990  a initial value, a constant 3 is then added for each iteration of the loop.
39991  The compiler does not change the multiplication
39992 \begin_inset LatexCommand \index{Multiplication}
39993
39994 \end_inset
39995
39996  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39997 \newline
39998
39999 Note the dead code elimination
40000 \begin_inset LatexCommand \index{Dead-code elimination}
40001
40002 \end_inset
40003
40004  optimization eliminated the dead assignments in line 7 & 8 to I and sum
40005  respectively.
40006 \newline
40007
40008 \end_layout
40009
40010 \begin_layout Standard
40011
40012 \size footnotesize
40013 Sample.c (5:1:0:0) _entry($9) :
40014 \end_layout
40015
40016 \begin_layout Standard
40017
40018 \size footnotesize
40019 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
40020 \end_layout
40021
40022 \begin_layout Standard
40023
40024 \size footnotesize
40025 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
40026 \end_layout
40027
40028 \begin_layout Standard
40029
40030 \size footnotesize
40031 Sample.c(11:4:53:0) preHeaderLbl0($11) :
40032 \end_layout
40033
40034 \begin_layout Standard
40035
40036 \size footnotesize
40037 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
40038  * int}[r2]
40039 \end_layout
40040
40041 \begin_layout Standard
40042
40043 \size footnotesize
40044 Sample.c(11:6:5:1) _whilecontinue_0($1) :
40045 \end_layout
40046
40047 \begin_layout Standard
40048
40049 \size footnotesize
40050 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
40051  int}[r0]]
40052 \end_layout
40053
40054 \begin_layout Standard
40055
40056 \size footnotesize
40057 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40058 \end_layout
40059
40060 \begin_layout Standard
40061
40062 \size footnotesize
40063 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
40064  * int}
40065 \end_layout
40066
40067 \begin_layout Standard
40068
40069 \size footnotesize
40070 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
40071  {short}
40072 \end_layout
40073
40074 \begin_layout Standard
40075
40076 \size footnotesize
40077 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
40078  * int}[DPTR]]
40079 \end_layout
40080
40081 \begin_layout Standard
40082
40083 \size footnotesize
40084 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
40085 }[r2 r3]
40086 \end_layout
40087
40088 \begin_layout Standard
40089
40090 \size footnotesize
40091 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
40092  * int}[r0] + 0x2 {short}
40093 \end_layout
40094
40095 \begin_layout Standard
40096
40097 \size footnotesize
40098 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
40099 \end_layout
40100
40101 \begin_layout Standard
40102
40103 \size footnotesize
40104 Sample.c(11:17:21:0)_whilebreak_0($3) :
40105 \end_layout
40106
40107 \begin_layout Standard
40108
40109 \size footnotesize
40110 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40111 \end_layout
40112
40113 \begin_layout Standard
40114
40115 \size footnotesize
40116 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40117 \end_layout
40118
40119 \begin_layout Standard
40120
40121 \size footnotesize
40122 Sample.c(15:20:54:0)preHeaderLbl1($13) :
40123 \end_layout
40124
40125 \begin_layout Standard
40126
40127 \size footnotesize
40128 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40129 \end_layout
40130
40131 \begin_layout Standard
40132
40133 \size footnotesize
40134 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40135 \end_layout
40136
40137 \begin_layout Standard
40138
40139 \size footnotesize
40140 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40141 \end_layout
40142
40143 \begin_layout Standard
40144
40145 \size footnotesize
40146 Sample.c(15:24:26:1)_forcond_0($4) :
40147 \end_layout
40148
40149 \begin_layout Standard
40150
40151 \size footnotesize
40152 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40153  < 0xa {short}
40154 \end_layout
40155
40156 \begin_layout Standard
40157
40158 \size footnotesize
40159 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40160 \end_layout
40161
40162 \begin_layout Standard
40163
40164 \size footnotesize
40165 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40166  + ITemp21 [lr21:38]{short}[r4]
40167 \end_layout
40168
40169 \begin_layout Standard
40170
40171 \size footnotesize
40172 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40173  * 0x3 {short}
40174 \end_layout
40175
40176 \begin_layout Standard
40177
40178 \size footnotesize
40179 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40180  + iTemp15 [lr29:30]{short}[r1]
40181 \end_layout
40182
40183 \begin_layout Standard
40184
40185 \size footnotesize
40186 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40187  r0]- 0x3 {short}
40188 \end_layout
40189
40190 \begin_layout Standard
40191
40192 \size footnotesize
40193 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40194 int}[r7 r0]
40195 \end_layout
40196
40197 \begin_layout Standard
40198
40199 \size footnotesize
40200 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40201  + 0x1 {short}
40202 \end_layout
40203
40204 \begin_layout Standard
40205
40206 \size footnotesize
40207 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40208  r6]- 0x1 {short}
40209 \end_layout
40210
40211 \begin_layout Standard
40212
40213 \size footnotesize
40214 Sample.c(19:38:47:1) goto _forcond_0($4)
40215 \end_layout
40216
40217 \begin_layout Standard
40218
40219 \size footnotesize
40220 Sample.c(19:39:48:0)_forbreak_0($7) :
40221 \end_layout
40222
40223 \begin_layout Standard
40224
40225 \size footnotesize
40226 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40227  + ITemp11 [lr19:40]{short}[r3]
40228 \end_layout
40229
40230 \begin_layout Standard
40231
40232 \size footnotesize
40233 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40234 \end_layout
40235
40236 \begin_layout Standard
40237
40238 \size footnotesize
40239 Sample.c(20:42:51:0)_return($8) :
40240 \end_layout
40241
40242 \begin_layout Standard
40243
40244 \size footnotesize
40245 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40246 \size default
40247
40248 \newline
40249
40250 \newline
40251 Finally the code generated for this function:
40252 \newline
40253
40254 \end_layout
40255
40256 \begin_layout Standard
40257
40258 \size footnotesize
40259 .area DSEG (DATA)
40260 \end_layout
40261
40262 \begin_layout Standard
40263
40264 \size footnotesize
40265 _p::
40266 \end_layout
40267
40268 \begin_layout Standard
40269
40270 \size footnotesize
40271 \InsetSpace ~
40272 \InsetSpace ~
40273 .ds 2
40274 \end_layout
40275
40276 \begin_layout Standard
40277
40278 \size footnotesize
40279 _gint::
40280 \end_layout
40281
40282 \begin_layout Standard
40283
40284 \size footnotesize
40285 \InsetSpace ~
40286 \InsetSpace ~
40287 .ds 2
40288 \end_layout
40289
40290 \begin_layout Standard
40291
40292 \size footnotesize
40293 ; sample.c 5
40294 \end_layout
40295
40296 \begin_layout Standard
40297
40298 \size footnotesize
40299 ; ----------------------------------------------
40300 \end_layout
40301
40302 \begin_layout Standard
40303
40304 \size footnotesize
40305 ; function function
40306 \end_layout
40307
40308 \begin_layout Standard
40309
40310 \size footnotesize
40311 ; ----------------------------------------------
40312 \end_layout
40313
40314 \begin_layout Standard
40315
40316 \size footnotesize
40317 _function:
40318 \end_layout
40319
40320 \begin_layout Standard
40321
40322 \size footnotesize
40323 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40324 \end_layout
40325
40326 \begin_layout Standard
40327
40328 \size footnotesize
40329 \InsetSpace ~
40330 \InsetSpace ~
40331 mov r2,dpl
40332 \end_layout
40333
40334 \begin_layout Standard
40335
40336 \size footnotesize
40337 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40338 \end_layout
40339
40340 \begin_layout Standard
40341
40342 \size footnotesize
40343 \InsetSpace ~
40344 \InsetSpace ~
40345 mov ar0,r2
40346 \end_layout
40347
40348 \begin_layout Standard
40349
40350 \size footnotesize
40351 ;_whilecontinue_0($1) :
40352 \end_layout
40353
40354 \begin_layout Standard
40355
40356 \size footnotesize
40357 00101$:
40358 \end_layout
40359
40360 \begin_layout Standard
40361
40362 \size footnotesize
40363 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40364 \end_layout
40365
40366 \begin_layout Standard
40367
40368 \size footnotesize
40369 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40370 \end_layout
40371
40372 \begin_layout Standard
40373
40374 \size footnotesize
40375 \InsetSpace ~
40376 \InsetSpace ~
40377 mov ar2,@r0
40378 \end_layout
40379
40380 \begin_layout Standard
40381
40382 \size footnotesize
40383 \InsetSpace ~
40384 \InsetSpace ~
40385 inc r0
40386 \end_layout
40387
40388 \begin_layout Standard
40389
40390 \size footnotesize
40391 \InsetSpace ~
40392 \InsetSpace ~
40393 mov ar3,@r0
40394 \end_layout
40395
40396 \begin_layout Standard
40397
40398 \size footnotesize
40399 \InsetSpace ~
40400 \InsetSpace ~
40401 dec r0
40402 \end_layout
40403
40404 \begin_layout Standard
40405
40406 \size footnotesize
40407 \InsetSpace ~
40408 \InsetSpace ~
40409 mov a,r2
40410 \end_layout
40411
40412 \begin_layout Standard
40413
40414 \size footnotesize
40415 \InsetSpace ~
40416 \InsetSpace ~
40417 orl a,r3
40418 \end_layout
40419
40420 \begin_layout Standard
40421
40422 \size footnotesize
40423 \InsetSpace ~
40424 \InsetSpace ~
40425 jz 00103$
40426 \end_layout
40427
40428 \begin_layout Standard
40429
40430 \size footnotesize
40431 00114$:
40432 \end_layout
40433
40434 \begin_layout Standard
40435
40436 \size footnotesize
40437 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40438 \end_layout
40439
40440 \begin_layout Standard
40441
40442 \size footnotesize
40443 \InsetSpace ~
40444 \InsetSpace ~
40445 mov dpl,_p
40446 \end_layout
40447
40448 \begin_layout Standard
40449
40450 \size footnotesize
40451 \InsetSpace ~
40452 \InsetSpace ~
40453 mov dph,(_p + 1)
40454 \end_layout
40455
40456 \begin_layout Standard
40457
40458 \size footnotesize
40459 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40460 \end_layout
40461
40462 \begin_layout Standard
40463
40464 \size footnotesize
40465 \InsetSpace ~
40466 \InsetSpace ~
40467 mov a,#0x02
40468 \end_layout
40469
40470 \begin_layout Standard
40471
40472 \size footnotesize
40473 \InsetSpace ~
40474 \InsetSpace ~
40475 add a,_p
40476 \end_layout
40477
40478 \begin_layout Standard
40479
40480 \size footnotesize
40481 \InsetSpace ~
40482 \InsetSpace ~
40483 mov _p,a
40484 \end_layout
40485
40486 \begin_layout Standard
40487
40488 \size footnotesize
40489 \InsetSpace ~
40490 \InsetSpace ~
40491 clr a
40492 \end_layout
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 \InsetSpace ~
40498 \InsetSpace ~
40499 addc a,(_p + 1)
40500 \end_layout
40501
40502 \begin_layout Standard
40503
40504 \size footnotesize
40505 \InsetSpace ~
40506 \InsetSpace ~
40507 mov (_p + 1),a
40508 \end_layout
40509
40510 \begin_layout Standard
40511
40512 \size footnotesize
40513 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40514 \end_layout
40515
40516 \begin_layout Standard
40517
40518 \size footnotesize
40519 \InsetSpace ~
40520 \InsetSpace ~
40521 movx a,@dptr
40522 \end_layout
40523
40524 \begin_layout Standard
40525
40526 \size footnotesize
40527 \InsetSpace ~
40528 \InsetSpace ~
40529 mov r2,a
40530 \end_layout
40531
40532 \begin_layout Standard
40533
40534 \size footnotesize
40535 \InsetSpace ~
40536 \InsetSpace ~
40537 inc dptr
40538 \end_layout
40539
40540 \begin_layout Standard
40541
40542 \size footnotesize
40543 \InsetSpace ~
40544 \InsetSpace ~
40545 movx a,@dptr
40546 \end_layout
40547
40548 \begin_layout Standard
40549
40550 \size footnotesize
40551 \InsetSpace ~
40552 \InsetSpace ~
40553 mov r3,a
40554 \end_layout
40555
40556 \begin_layout Standard
40557
40558 \size footnotesize
40559 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40560 \end_layout
40561
40562 \begin_layout Standard
40563
40564 \size footnotesize
40565 \InsetSpace ~
40566 \InsetSpace ~
40567 mov @r0,ar2
40568 \end_layout
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 \InsetSpace ~
40574 \InsetSpace ~
40575 inc r0
40576 \end_layout
40577
40578 \begin_layout Standard
40579
40580 \size footnotesize
40581 \InsetSpace ~
40582 \InsetSpace ~
40583 mov @r0,ar3
40584 \end_layout
40585
40586 \begin_layout Standard
40587
40588 \size footnotesize
40589 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40590 \end_layout
40591
40592 \begin_layout Standard
40593
40594 \size footnotesize
40595 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40596 \end_layout
40597
40598 \begin_layout Standard
40599
40600 \size footnotesize
40601 ; 0x2 {short}
40602 \end_layout
40603
40604 \begin_layout Standard
40605
40606 \size footnotesize
40607 \InsetSpace ~
40608 \InsetSpace ~
40609 inc r0
40610 \end_layout
40611
40612 \begin_layout Standard
40613
40614 \size footnotesize
40615 ; goto _whilecontinue_0($1)
40616 \end_layout
40617
40618 \begin_layout Standard
40619
40620 \size footnotesize
40621 \InsetSpace ~
40622 \InsetSpace ~
40623 sjmp 00101$
40624 \end_layout
40625
40626 \begin_layout Standard
40627
40628 \size footnotesize
40629 ; _whilebreak_0($3) :
40630 \end_layout
40631
40632 \begin_layout Standard
40633
40634 \size footnotesize
40635 00103$:
40636 \end_layout
40637
40638 \begin_layout Standard
40639
40640 \size footnotesize
40641 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40642 \end_layout
40643
40644 \begin_layout Standard
40645
40646 \size footnotesize
40647 \InsetSpace ~
40648 \InsetSpace ~
40649 mov r2,#0x00
40650 \end_layout
40651
40652 \begin_layout Standard
40653
40654 \size footnotesize
40655 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40656 \end_layout
40657
40658 \begin_layout Standard
40659
40660 \size footnotesize
40661 \InsetSpace ~
40662 \InsetSpace ~
40663 mov r3,#0x00
40664 \end_layout
40665
40666 \begin_layout Standard
40667
40668 \size footnotesize
40669 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40670 \end_layout
40671
40672 \begin_layout Standard
40673
40674 \size footnotesize
40675 \InsetSpace ~
40676 \InsetSpace ~
40677 mov r4,#0x00
40678 \end_layout
40679
40680 \begin_layout Standard
40681
40682 \size footnotesize
40683 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40684 \end_layout
40685
40686 \begin_layout Standard
40687
40688 \size footnotesize
40689 \InsetSpace ~
40690 \InsetSpace ~
40691 mov r5,#0x0A
40692 \end_layout
40693
40694 \begin_layout Standard
40695
40696 \size footnotesize
40697 \InsetSpace ~
40698 \InsetSpace ~
40699 mov r6,#0x00
40700 \end_layout
40701
40702 \begin_layout Standard
40703
40704 \size footnotesize
40705 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40706 \end_layout
40707
40708 \begin_layout Standard
40709
40710 \size footnotesize
40711 \InsetSpace ~
40712 \InsetSpace ~
40713 mov r7,#0x1E
40714 \end_layout
40715
40716 \begin_layout Standard
40717
40718 \size footnotesize
40719 \InsetSpace ~
40720 \InsetSpace ~
40721 mov r0,#0x00
40722 \end_layout
40723
40724 \begin_layout Standard
40725
40726 \size footnotesize
40727 ; _forcond_0($4) :
40728 \end_layout
40729
40730 \begin_layout Standard
40731
40732 \size footnotesize
40733 00104$:
40734 \end_layout
40735
40736 \begin_layout Standard
40737
40738 \size footnotesize
40739 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40740 \end_layout
40741
40742 \begin_layout Standard
40743
40744 \size footnotesize
40745 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40746 \end_layout
40747
40748 \begin_layout Standard
40749
40750 \size footnotesize
40751 \InsetSpace ~
40752 \InsetSpace ~
40753 clr c
40754 \end_layout
40755
40756 \begin_layout Standard
40757
40758 \size footnotesize
40759 \InsetSpace ~
40760 \InsetSpace ~
40761 mov a,r4
40762 \end_layout
40763
40764 \begin_layout Standard
40765
40766 \size footnotesize
40767 \InsetSpace ~
40768 \InsetSpace ~
40769 xrl a,#0x80
40770 \end_layout
40771
40772 \begin_layout Standard
40773
40774 \size footnotesize
40775 \InsetSpace ~
40776 \InsetSpace ~
40777 subb a,#0x8a
40778 \end_layout
40779
40780 \begin_layout Standard
40781
40782 \size footnotesize
40783 \InsetSpace ~
40784 \InsetSpace ~
40785 jnc 00107$
40786 \end_layout
40787
40788 \begin_layout Standard
40789
40790 \size footnotesize
40791 00115$:
40792 \end_layout
40793
40794 \begin_layout Standard
40795
40796 \size footnotesize
40797 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40798 \end_layout
40799
40800 \begin_layout Standard
40801
40802 \size footnotesize
40803 ; iTemp21 [lr21:38]{short}[r4]
40804 \end_layout
40805
40806 \begin_layout Standard
40807
40808 \size footnotesize
40809 \InsetSpace ~
40810 \InsetSpace ~
40811 mov a,r4
40812 \end_layout
40813
40814 \begin_layout Standard
40815
40816 \size footnotesize
40817 \InsetSpace ~
40818 \InsetSpace ~
40819 add a,r2
40820 \end_layout
40821
40822 \begin_layout Standard
40823
40824 \size footnotesize
40825 \InsetSpace ~
40826 \InsetSpace ~
40827 mov r2,a
40828 \end_layout
40829
40830 \begin_layout Standard
40831
40832 \size footnotesize
40833 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40834 \end_layout
40835
40836 \begin_layout Standard
40837
40838 \size footnotesize
40839 \InsetSpace ~
40840 \InsetSpace ~
40841 mov b,#0x03
40842 \end_layout
40843
40844 \begin_layout Standard
40845
40846 \size footnotesize
40847 \InsetSpace ~
40848 \InsetSpace ~
40849 mov a,r4
40850 \end_layout
40851
40852 \begin_layout Standard
40853
40854 \size footnotesize
40855 \InsetSpace ~
40856 \InsetSpace ~
40857 mul ab
40858 \end_layout
40859
40860 \begin_layout Standard
40861
40862 \size footnotesize
40863 \InsetSpace ~
40864 \InsetSpace ~
40865 mov r1,a
40866 \end_layout
40867
40868 \begin_layout Standard
40869
40870 \size footnotesize
40871 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40872 \end_layout
40873
40874 \begin_layout Standard
40875
40876 \size footnotesize
40877 ; iTemp15 [lr29:30]{short}[r1]
40878 \end_layout
40879
40880 \begin_layout Standard
40881
40882 \size footnotesize
40883 \InsetSpace ~
40884 \InsetSpace ~
40885 add a,r3
40886 \end_layout
40887
40888 \begin_layout Standard
40889
40890 \size footnotesize
40891 \InsetSpace ~
40892 \InsetSpace ~
40893 mov r3,a
40894 \end_layout
40895
40896 \begin_layout Standard
40897
40898 \size footnotesize
40899 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40900 \end_layout
40901
40902 \begin_layout Standard
40903
40904 \size footnotesize
40905 \InsetSpace ~
40906 \InsetSpace ~
40907 mov a,r7
40908 \end_layout
40909
40910 \begin_layout Standard
40911
40912 \size footnotesize
40913 \InsetSpace ~
40914 \InsetSpace ~
40915 add a,#0xfd
40916 \end_layout
40917
40918 \begin_layout Standard
40919
40920 \size footnotesize
40921 \InsetSpace ~
40922 \InsetSpace ~
40923 mov r7,a
40924 \end_layout
40925
40926 \begin_layout Standard
40927
40928 \size footnotesize
40929 \InsetSpace ~
40930 \InsetSpace ~
40931 mov a,r0
40932 \end_layout
40933
40934 \begin_layout Standard
40935
40936 \size footnotesize
40937 \InsetSpace ~
40938 \InsetSpace ~
40939 addc a,#0xff
40940 \end_layout
40941
40942 \begin_layout Standard
40943
40944 \size footnotesize
40945 \InsetSpace ~
40946 \InsetSpace ~
40947 mov r0,a
40948 \end_layout
40949
40950 \begin_layout Standard
40951
40952 \size footnotesize
40953 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40954 \end_layout
40955
40956 \begin_layout Standard
40957
40958 \size footnotesize
40959 \InsetSpace ~
40960 \InsetSpace ~
40961 mov a,r7
40962 \end_layout
40963
40964 \begin_layout Standard
40965
40966 \size footnotesize
40967 \InsetSpace ~
40968 \InsetSpace ~
40969 add a,_gint
40970 \end_layout
40971
40972 \begin_layout Standard
40973
40974 \size footnotesize
40975 \InsetSpace ~
40976 \InsetSpace ~
40977 mov _gint,a
40978 \end_layout
40979
40980 \begin_layout Standard
40981
40982 \size footnotesize
40983 \InsetSpace ~
40984 \InsetSpace ~
40985 mov a,r0
40986 \end_layout
40987
40988 \begin_layout Standard
40989
40990 \size footnotesize
40991 \InsetSpace ~
40992 \InsetSpace ~
40993 addc a,(_gint + 1)
40994 \end_layout
40995
40996 \begin_layout Standard
40997
40998 \size footnotesize
40999 \InsetSpace ~
41000 \InsetSpace ~
41001 mov (_gint + 1),a
41002 \end_layout
41003
41004 \begin_layout Standard
41005
41006 \size footnotesize
41007 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
41008 \end_layout
41009
41010 \begin_layout Standard
41011
41012 \size footnotesize
41013 \InsetSpace ~
41014 \InsetSpace ~
41015 inc r4
41016 \end_layout
41017
41018 \begin_layout Standard
41019
41020 \size footnotesize
41021 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
41022 \end_layout
41023
41024 \begin_layout Standard
41025
41026 \size footnotesize
41027 \InsetSpace ~
41028 \InsetSpace ~
41029 dec r5
41030 \end_layout
41031
41032 \begin_layout Standard
41033
41034 \size footnotesize
41035 \InsetSpace ~
41036 \InsetSpace ~
41037 cjne r5,#0xff,00104$
41038 \end_layout
41039
41040 \begin_layout Standard
41041
41042 \size footnotesize
41043 \InsetSpace ~
41044 \InsetSpace ~
41045 dec r6
41046 \end_layout
41047
41048 \begin_layout Standard
41049
41050 \size footnotesize
41051 ; goto _forcond_0($4)
41052 \end_layout
41053
41054 \begin_layout Standard
41055
41056 \size footnotesize
41057 \InsetSpace ~
41058 \InsetSpace ~
41059 sjmp 00104$
41060 \end_layout
41061
41062 \begin_layout Standard
41063
41064 \size footnotesize
41065 ; _forbreak_0($7) :
41066 \end_layout
41067
41068 \begin_layout Standard
41069
41070 \size footnotesize
41071 00107$:
41072 \end_layout
41073
41074 \begin_layout Standard
41075
41076 \size footnotesize
41077 ; ret iTemp24 [lr40:41]{short}
41078 \end_layout
41079
41080 \begin_layout Standard
41081
41082 \size footnotesize
41083 \InsetSpace ~
41084 \InsetSpace ~
41085 mov a,r3
41086 \end_layout
41087
41088 \begin_layout Standard
41089
41090 \size footnotesize
41091 \InsetSpace ~
41092 \InsetSpace ~
41093 add a,r2
41094 \end_layout
41095
41096 \begin_layout Standard
41097
41098 \size footnotesize
41099 \InsetSpace ~
41100 \InsetSpace ~
41101 mov dpl,a
41102 \end_layout
41103
41104 \begin_layout Standard
41105
41106 \size footnotesize
41107 ; _return($8) :
41108 \end_layout
41109
41110 \begin_layout Standard
41111
41112 \size footnotesize
41113 00108$:
41114 \end_layout
41115
41116 \begin_layout Standard
41117
41118 \size footnotesize
41119 \InsetSpace ~
41120 \InsetSpace ~
41121 ret
41122 \newline
41123
41124 \end_layout
41125
41126 \begin_layout Section
41127 A few words about basic block successors, predecessors and dominators
41128 \end_layout
41129
41130 \begin_layout Standard
41131 Successors are basic blocks
41132 \begin_inset LatexCommand \index{Basic blocks}
41133
41134 \end_inset
41135
41136  that might execute after this basic block.
41137 \newline
41138 Predecessors are basic blocks
41139  that might execute before reaching this basic block.
41140 \newline
41141 Dominators are basic
41142  blocks that WILL execute before reaching this basic block.
41143 \newline
41144
41145 \end_layout
41146
41147 \begin_layout Standard
41148 [basic block 1]
41149 \end_layout
41150
41151 \begin_layout Standard
41152 if (something)
41153 \end_layout
41154
41155 \begin_layout Standard
41156 \InsetSpace ~
41157 \InsetSpace ~
41158 \InsetSpace ~
41159 \InsetSpace ~
41160 [basic block 2]
41161 \end_layout
41162
41163 \begin_layout Standard
41164 else
41165 \end_layout
41166
41167 \begin_layout Standard
41168 \InsetSpace ~
41169 \InsetSpace ~
41170 \InsetSpace ~
41171 \InsetSpace ~
41172 [basic block 3]
41173 \end_layout
41174
41175 \begin_layout Standard
41176 [basic block 4]
41177 \newline
41178
41179 \end_layout
41180
41181 \begin_layout Standard
41182 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41183 \end_layout
41184
41185 \begin_layout Standard
41186 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41187 \end_layout
41188
41189 \begin_layout Standard
41190 c) domVect of [BB4] = BB1 ...
41191  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41192  was executed.
41193 \end_layout
41194
41195 \begin_layout Chapter
41196 Acknowledgments
41197 \end_layout
41198
41199 \begin_layout Standard
41200 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41201
41202 \end_inset
41203
41204
41205 \newline
41206
41207 \newline
41208
41209 \emph on
41210 Thanks to all the other volunteer developers who have helped with coding,
41211  testing, web-page creation, distribution sets, etc.
41212  You know who you are :-)
41213 \emph default
41214
41215 \newline
41216
41217 \newline
41218
41219 \emph on
41220 Thanks to Sourceforge 
41221 \begin_inset LatexCommand \url{http://www.sf.net}
41222
41223 \end_inset
41224
41225  which has hosted the project since 1999 and donates significant download
41226  bandwidth.
41227 \emph default
41228
41229 \newline
41230
41231 \newline
41232
41233 \emph on
41234 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41235  cycles and bandwidth for snapshot builds.
41236 \newline
41237
41238 \end_layout
41239
41240 \begin_layout Standard
41241 This document was initially written by Sandeep Dutta
41242 \end_layout
41243
41244 \begin_layout Standard
41245 All product names mentioned herein may be trademarks
41246 \begin_inset LatexCommand \index{Trademarks}
41247
41248 \end_inset
41249
41250  of their respective companies.
41251  
41252 \end_layout
41253
41254 \begin_layout Section*
41255 Alphabetical index
41256 \end_layout
41257
41258 \begin_layout Standard
41259 To avoid confusion, the installation and building options for SDCC itself
41260  (chapter 2) are not part of the index.
41261 \end_layout
41262
41263 \begin_layout Standard
41264 \begin_inset LatexCommand \printindex{}
41265
41266 \end_inset
41267
41268
41269 \end_layout
41270
41271 \end_body
41272 \end_document